Arithmetic Expressions :
Print this page
 

Algorithm for evaluation of an expression E, which is in postfix notation:

  • We assume that the postfix notation specifies end of expression by appending NULL at the end of expression.
  • here next token   function gives us the next occurring element in the expression in a left to right scan.
  • The  PUSH   function adds element x to stack Q which is of maximum length n
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