Adding Parentheses to the Evaluation Method
Example:
(evaluate "(3+2)*4-40/5")
Note that the expression is represented as a
string because of the special meaning that
parentheses have in Scheme.
A parenthesized (sub-)expression must be
fully reduced before continuing the
left-to-right scan.
This is accomplished by:
- If a ( is encountered, simply shift it
onto the stack.
- If a ) is encountered:
- act like it was a $ and reduce
everything between the ( and the top
of the stack to a number N
- shift the ) onto the stack, and
- reduce the ( N ) on the stack to
just N.