GATE Computer ScienceVery hardGATE CS (PYQ pattern)

For the grammar G: S → A b | B c; A → a A | ε; B → a B | ε, the LL(1) predictive table is built. Which statement is correct?

  1. A. Only M[S, a] is multiply defined; G is not LL(k) for any k, yet L(G) has an LL(1) grammar
  2. B. M[S, a], M[A, a] and M[B, a] are multiply defined, and no LL(1) grammar generates L(G)
  3. C. Only M[S, a] is multiply defined, and G is LL(2) because two symbols separate A b from B c
  4. D. No cell is multiply defined, because FIRST(A b) = {a, b} and FIRST(B c) = {a, c} differ

Correct answer: A. Only M[S, a] is multiply defined; G is not LL(k) for any k, yet L(G) has an LL(1) grammar

FIRST(A b) = {a, b} and FIRST(B c) = {a, c} meet only in a, so M[S, a] holds both S-productions. M[A, a] holds only A → a A (FOLLOW(A) = {b}) and M[B, a] only B → a B (FOLLOW(B) = {c}). Both alternatives of S begin with an unbounded run of a's, so no fixed k of lookahead separates a^k b from a^k c: G is not LL(k). But L(G) = a*b ∪ a*c is generated by the LL(1) grammar S → a S | b | c.

More Compiler Design questions

Exams that ask this topic