A RPN (Reverse Polish Notation) calculator uses post-fixes operands. For example, to add two numbers, you get one, then the other and, finally, the addition operator:
5 2 -
The previous example is the operation in RPN notation.
In this problem, we want to implement a simple RPN calculator with the four basic arithmetic operators (+, -, * and /) and the assignment. The assignment returns the assigned value.
The tool should read from STDIN an expression by line, and write to STDOUT a result by line. Consider that all lines have the correct syntax.
The input consists of a sequence of expressions. Each expression is contained in a single line. Variables can be defined and used in different lines.
2 2 + 3 - 1 2 3 * + a 10 = a 2 / 2 2 + + -2 -3 + a 10 = b 5 = +
The output contains the results of evaluating each one of the expressions.
1 7 10 9 -5 15