Questions: Parse Trees, Derivations, and Ambiguity in CFGs

5 questions to test your understanding

Score: 0 / 5
Question 1 Multiple Choice

The grammar E → E + E | E × E | a is used to parse 'a + a × a.' A parser produces two different parse trees for this string. What is the correct conclusion?

AThe grammar has a bug and must be discarded entirely
BThe string is not in the language generated by this grammar
CThe grammar is ambiguous — the same string has more than one valid structural interpretation
DThis is expected and harmless because both parse trees produce the same evaluated result
Question 2 Multiple Choice

What is the key difference between 'an ambiguous grammar' and 'an inherently ambiguous language'?

AThere is no meaningful difference — both describe exactly the same property
BAn ambiguous grammar can sometimes be replaced by an unambiguous grammar for the same language; an inherently ambiguous language has no unambiguous grammar at all
CAn inherently ambiguous language can only be described by a single maximally ambiguous grammar
DInherent ambiguity applies only to regular languages, while grammar ambiguity applies to context-free grammars
Question 3 True / False

A leftmost derivation and a rightmost derivation of the same string can correspond to the same parse tree, because the parse tree captures structural relationships rather than the sequence of rule applications.

TTrue
FFalse
Question 4 True / False

If a grammar is ambiguous, it is extremely difficult to generate an unambiguous grammar for the same language.

TTrue
FFalse
Question 5 Short Answer

Why does ambiguity in a grammar matter for compilers and programming languages? What goes wrong if an ambiguous grammar is used?

Think about your answer, then reveal below.