-
Implement a recursive function evalPolish(
expression) that shall evaluate (calculate) an expression written in the prefix (“Polish”) notation. The expression shall be defined recursively in the Backus-Naur form (BNF): - expression ::= integer_or_floating_point_
number # A number is an expression; its value is the number itself - expression ::= (operator, expression, expression) # A 3-element tuple of an operator and another two expressions is also an expression; its value is the operator applied to the values of the expressions
- operator ::= “+” | “-” | “*” | “/” # The list of supported operators; feel free to extend it
Here is a sample expression and its evaluation:
>>> good = ("+", ("-", 3, 1), ("*", ("/", 3, 4), 7)) # Same as
- expression ::= integer_or_floating_point_