GATE Computer ScienceHardGATE CS (PYQ pattern)

The following grammars all generate subsets of {a, b}*, with S as the start symbol. Exactly one of the four grammars is unambiguous; which one?

  1. A. S → A | B; A → aA | ε; B → bB | ε
  2. B. S → aSb | bS | ε
  3. C. S → SS | a
  4. D. S → aS | Sb | ab

Correct answer: B. S → aSb | bS | ε

Every string it generates has a unique parse tree; each other grammar has a string with two parse trees: "ε" in S → A | B; A → aA | ε; B → bB | ε; "aaa" in S → SS | a; "aabb" in S → aS | Sb | ab.

More Theory of Computation questions

Exams that ask this topic