How to validate an rpn expression

This is what I have so far. I am just a wee bit confused of how I should go about making sure that these are valid rpn expressions. So if 98++ or 888- is read in from a file, I would present "invalid rpn - too many operands" or vice versa.
Here is my code as of now:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
int main()
{
				//Evaluate the operator 
				if ( opToken == '+' )
				{
					result = a + b;
					RPNExpression.push ( result );
					outFile << "Push " << result << endl;

				}

				else if ( opToken == '-' )
				{
					result = a - b;
					RPNExpression.push ( result );
					outFile << "Push " << result << endl;
				}

				else if ( opToken == '*' )
				{
					result = b * a;
					RPNExpression.push ( result );
					outFile << "Push " << result << endl;
				}

				else if ( opToken == '/' )
				{
					result = b / a;
					RPNExpression.push ( result );
					outFile << "Push " << result << endl;
				}

				else if ( opToken == '%' )
				{
					result = b % a;
					RPNExpression.push ( result );
					outFile << "Push " << result << endl;
				}


}
Last edited on
Topic archived. No new replies allowed.