Implement an Expression Evaluator Our goal is to write a program that is capable of evaluating simple mathematical expressions. An example expression could look like:
+ 1 2
This expression can be read as 1 + 2
and evaluates to 3. We've placed the operator (+) first in our syntax to simplify some things down the road. The + indicates that this is an operator expression, and is evaluated by summing the two following tokens, which in this case are both numbers.
The general rules are:
Expressions can be numbers or operator expressions (4
is an expression and so is - 3 1
)
Numbers evaluate to themselves (4
is 4
)