GATE Computer ScienceVery hardGATE CS (PYQ pattern)

The standard algorithm removes all left recursion from S → A a | b; A → A c | S d | e, taking the non-terminals in the order S, A (substitute S into A, then remove A's immediate left recursion with a new A′). What are the A′-productions of the result, and is the result LL(1)?

  1. A. A′ → c A′ | a d A′ | ε; LL(1)
  2. B. A′ → c A′ | a d A′ | ε; not LL(1)
  3. C. A′ → c A′ | d A′ | ε; not LL(1)
  4. D. A′ → c A′ | ε; LL(1)

Correct answer: B. A′ → c A′ | a d A′ | ε; not LL(1)

Substituting S gives A → A c | A a d | b d | e. Removing immediate recursion: A → b d A′ | e A′; A′ → c A′ | a d A′ | ε (7 productions in all with S → A a | b). It is still not LL(1): S → A a and S → b both start with b (A → b d A′), and FOLLOW(A′) = FOLLOW(A) ∋ a clashes with A′ → a d A′.

More Compiler Design questions

Exams that ask this topic