What is an unambiguous grammar equivalent to to the following ambiguous grammar for a language of expressions with let and addition?
E ⇒ let id = E in E
E ⇒ E + E
E ⇒ num
The ambiguity should be solved so that:
- addition is left associative
- addition has higher precedence than let expressions when it appears on the right
- addition has lower precedence than let expressions when it appears on the left
Using braces to show the grouping of sub-expressions, the following illustrates how expressions should be interpreted:
num + num + num
=> { num + num } + num
let id = num in num + num
=> let id = num in { num + num }
num + let id = num in num
=> num + { let id = num in num }