Consider the following CFG with the eight terminals: true, false, , , !, ==, (, and ).
expr → true | false | expr ∧ expr | expr ∨ expr | !expr | expr == expr | (expr )
Indeed, the starting symbol is expr . Let’s call this grammar tt. This grammar is ambiguous, i.e., there exist at least two parse trees for some expression. For example, consider the following expression: !true ∧ false ∨ true == true
Give two different derivations for this expression such that the corresponding parse trees are differ- ent from each other. (10 points)
Give the corresponding parse trees for each derivation in the previous question. (10 points)
Give the corresponding two ASTs. (10 points) (Hint: Note that operators , , ==, and ! can appear as interior nodes in ASTs1. You may remove the nonterminal expr from ASTs as it does not convey any computational information.)
If you pass the ASTs from the previous question to an evaluator, what would be the final value in each case? (10 points)
Get Answers For Free
Most questions answered within 1 hours.