A context-free grammar is ambiguous if:
View worked solution
Answer: B
By definition, a context-free grammar (CFG) is ambiguous if there exists at least one string that has more than one distinct parse tree (or equivalently, more than one leftmost derivation or rightmost derivation).
Let's evaluate the given options:
- Option A: Useless non-terminals are symbols that cannot derive any terminal string or cannot be reached from the start symbol. Their presence does not determine whether a grammar is ambiguous.
- Option B: This directly matches the standard definition of ambiguity.
- Option C: Having adjacent non-terminals on the right-hand side (e.g., ) is a standard feature of many unambiguous grammars, such as those in Chomsky Normal Form (CNF). It does not imply ambiguity.
Therefore, the correct option is B.
Free practice · Your answers on this page are not saved.
