Postfix evaluation

Hide text Hide pseudo-code

Infix expressions are often translated into postfix form in which the operators appear after their operands (e.g., 3*(2+4) would be 3 2 4 + *). The task is to evaluate a postfix expression with stack.

This is a tutorial exercise in which you can test your browser environment. See the instructions tab for more information.

Some addditional problems.

1. read postfix expression token by token
2.   if the token is an operand, push it 
     into the stack
3.   if the token is a binary operator, 
3.1    pop the two top most operands 
       from the stack
3.2    apply the binary operator with the 
       two operands
3.3    push the result into the stack
4. finally, the value of the whole postfix 
   expression remains in the stack


  Created Wed Jun 20 16:00:42 EEST 2007 - Powered by SVG-hut