Question: HELP WITH PYTHON! Use Python to evaluate prefix expressions. Your algorithm will be recursive. We must be able to recognize tokens in the expression. Notice
HELP WITH PYTHON!
Use Python to evaluate prefix expressions. Your algorithm will be recursive.
We must be able to recognize tokens in the expression.
Notice that we can't simply split the expression on spaces since "(" and "+" are separate symbols, but are not separated by spaces.
-It must tokenize the expression using Python's regex (use the re module).
-Reset the global current parsing pos to 0
Sample Output:
> (* 2 15)
30
> (- (* 12 2)(* 2 3 ))
18
> (* 5 (/ 5 2))
10
> (or (> 6 13) (< 15 2))
False
> (and (> 13 6) (> 17 3))
True
> (+ 1 (* 12 4 )(* 2 2)
Missing closing ')'
> (/ (+ 3 5))
Incorrect number of operands - must be 2 for '/'
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
