GATE Computer ScienceVery hardGATE CS (PYQ pattern)

For G: S → A | B; A → a A b | ε; B → a B b b | ε, which of these statements are true? I. Exactly two cells of the LL(1) table, M[S, a] and M[S, $], are multiply defined. II. G is ambiguous. III. Some LR(1) grammar generates L(G).

  1. A. I and II only
  2. B. I only
  3. C. I and III only
  4. D. I, II and III

Correct answer: A. I and II only

FIRST(A) = FIRST(B) = {a, ε} and both are nullable, so S → A and S → B both go to M[S, a] and M[S, $]; the A- and B-rows have no clash (a versus FOLLOW = {b, $}). The empty string has two parse trees (S → A → ε and S → B → ε), so G is ambiguous. L(G) = {aⁿbⁿ} ∪ {aⁿb²ⁿ} is the standard inherently non-deterministic CFL: no DPDA accepts it, so no LR(1) grammar generates it.

More Compiler Design questions

Exams that ask this topic