| Arithmetic Expressions : | |||||||||||||||||
Algorithm for evaluation of an expression E, which is in postfix notation: |
|||||||||||||||||
|
|||||||||||||||||
| Evaluate (E) | |||||||||||||||||
| Else | |||||||||||||||||
| { | |||||||||||||||||
| { | |||||||||||||||||
| Top = 0; | |||||||||||||||||
| If (x = = operand) | |||||||||||||||||
| While (1) | |||||||||||||||||
| PUSH (Q, top, n, x); | |||||||||||||||||
| { | |||||||||||||||||
| If (x = = operator) | |||||||||||||||||
| x= next token (E) | |||||||||||||||||
| { | |||||||||||||||||
| If (x = = infinity) | |||||||||||||||||
| Pop correct number of operands according to the operator (unary/binary)
and then perform the operation and store result onto the stack |
|||||||||||||||||
| { | |||||||||||||||||
| Return (stack [top]); | |||||||||||||||||
| } | |||||||||||||||||
| } | |||||||||||||||||
| } | |||||||||||||||||
| } | |||||||||||||||||
| Prev | |||||||||||||||||