GATE Computer ScienceVery hardGATE CS (PYQ pattern)

The grammar S → A B; A → a | ε; B → A b | c is not LL(1). Each change below is applied to it on its own. Which of them make the grammar LL(1)? I. Replace B → A b by B → b A. II. Replace B → A b by B → A c and B → c by B → b. III. Add the production B → ε. IV. Replace S → A B by S → B A.

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

Correct answer: C. I and IV only

The original clash is M[A, a]: A → a, and A → ε because FOLLOW(A) ∋ a (from B → A b with A first in B). I: A is now followed only by FOLLOW(B) = {$}, so no clash. II: B → A c still puts FIRST(B) = {a, b, c} after A, so a ∈ FOLLOW(A): clash remains. III: B → ε adds $ to FOLLOW(A) but a is still there: clash remains. IV: A now ends the sentence (FOLLOW(A) = {$, b}), and a ∉ FOLLOW(A): LL(1).

More Compiler Design questions

Exams that ask this topic