Exercise: Reverse Polish Notation (cont)
Main loop:
- read a line of input, split into tokens (
splitLine() )
- scan tokens, evaluate as RPN to compute result
- print result, and repeat
Evaluate as RPN, can be implemented via a Stack:
- if next token is number: push onto stack
- if next token is operator: pop, pop, apply, push
Error conditions: insufficient numbers, ... ?
|