Evaluating expressions

Use of stacks in evaluating expressions:
  1. In the process of creating machine code from source code, compilers translate infix expressions to postfix expressions. Example:
    2*3+4 --> 23*4+
    The rule is that each operator follows its two operands. The algorithm to make this transition uses a stack.
  2. In the process of evaluating a postfix expression, another stack is used.

Translating Infix to Postfix

You can remember the method "heuristically" and also describe it by an algorithm:

Evaluating postfix expressions

Scan the expression left to right, this time stacking operands, then pop operators as needed when the operand that applies to them is reached.