Exercise 12:

Parenthesized expressions over binary +, -, *, /, and ^ (^ with lower precedence than * and /)
The set of tokens of the language is {+,-,*,/,^,(,),NUMBER}. The token NUMBER represents unsigned integers, i.e., non-empty sequences of digits. Examples of correct expressions are “9”, “1+2^3/1”, “0^(0+0)/2-3”, “1/2^3”, whereas “1+”, “/3”, “1 2”, “^6”, “5/4*3+” are not. The generated AST must correspond to an interpretation of all operators as left-associative, except exponentiation, which is right-associative. The precedence is different than usual, with exponentiation having less priority than products and divisions (but more than additions and subtractions), the rest being as usual. As an example, for input
1+2*3^4/5-6
the resulting AST must be
-(+(1,^(*(2,3),/(4,5)),6),7)
i.e., as if the implicit parenthesization was
(1+((2*3)^(4/5))-6
Authors: Pau Fernández / Documentation:
To be able to submit you need to either log in, register, or become a guest.