For Weekly Programming Challenges
Write a program that acts as a four function calculator that receives its input in Reverse Polish Notation
Valid inputs consist of the following tokens, each separated from the next token by whitespace:
+ character, inicating the addition operation- character, indicating the subtraction operation* character, indicating the multiplication operation/ character, indicating the division operation= character, indicating end of inputFor example:
15 7 1 1 + − / 3 × 2 1 1 + + − =
The result of the calculation, or if the stack is malformed an error message indicating what token was found and what class of token was expected.
From the above example the program should output the following:
5
15 7 1 1 + − / 3 × 2 1 1 + + − =
.333 .333 .333 + + =
.1 .1 + .1 + =
2 2 * 5 5 * =
+ =
1 1 1 1 1 1 1 1 1 1
+ + + + + + + + + =