Consider the following grammar for a language L:

  S → V = E
  | S ; S
  | if B then S
  | if B then S else S
V → x | y | z
E → V | 0 | 1 | 2 | 3 | 4
B → E === E

where, like in JavaScript, = is the assignment operator and === is the equality testing operator.
Now consider the following candidate for a statement S in the language L:

if x === 1 then if y === z then z = 2 else z = 3 else z = 4

Which one of the following propositions best characterizes the above statement?

It is parsed in L with a unique parse tree.
  • It is parsed ambiguously in L.
  • It is not a statement in L.

Try to build the whole parse tree(s) for this statement with pencil and paper.

Review the definition of an ambiguous grammar.