GATE Computer ScienceVery hardGATE CS (PYQ pattern)

S → A B; A → a | ε; B → A b | c generates exactly five strings, and its LL(1) table has one multiply-defined cell. If that cell is resolved by always choosing A → ε, how many of the five strings does the parser accept? (If it is resolved by choosing A → a instead, call the count k.)

  1. A. 2 (and k = 5)
  2. B. 3 (and k = 5)
  3. C. 2 (and k = 4)
  4. D. 5 (and k = 2)

Correct answer: A. 2 (and k = 5)

L = {b, ab, aab, c, ac}; the clash is M[A, a] (a ∈ FOLLOW(A) via B → A b). Choosing A → ε on lookahead a: for ab the first A gives ε, then B → A b and the inner A again gives ε, so b meets a: rejected; likewise aab and ac. Only b and c pass: 2. Choosing A → a: every string parses (ab as A = a, B = b), so k = 5.

More Compiler Design questions

Exams that ask this topic