## 23.3 (cont.) - `stack` Example

Reverse Polish Notation (RPN, or postfix) calculator

- Arguments written before operators
  - `3 + 4 * 7` would be `3 4 7 * +`
- Calculation is easy:

- Each argument read is pushed onto a stack
- If a (binary) operator is read:
  - Pop top two values
  - Perform appropriate operation
  - Push result back onto stack
- Add 2 commands:
  1. `p` - print the top of the stack
  2. `q` - quit the program

prev |top |next