GATE Computer ScienceHardGATE CS (PYQ pattern)

Parser generators reject ambiguous grammars. Consider these CFGs (start symbol S). Exactly one of the four grammars is ambiguous; which one?

  1. A. S → aSb | ε
  2. B. S → aSa | bSb | a | b | ε
  3. C. S → SaS | b
  4. D. S → aA | bB; A → aA | a | bB; B → bB | b

Correct answer: C. S → SaS | b

The string "babab" has 2 distinct parse trees under it. In each of the other grammars every string of length ≤ 8 has exactly one parse tree (and each is a standard unambiguous pattern).

More Theory of Computation questions

Exams that ask this topic