GATE Computer ScienceHardGATE CS (PYQ pattern)

Consider the grammar S → A B c, A → a A | ε, B → b B | A d | ε. How many terminals are in FOLLOW(A), and is the grammar LL(1)?

  1. A. 3; not LL(1)
  2. B. 4; not LL(1)
  3. C. 4; LL(1)
  4. D. 2; LL(1)

Correct answer: B. 4; not LL(1)

FOLLOW(A) gets FIRST(B) − ε = {a, b, d}, plus c because B is nullable, plus d from B → A d; so it is {a, b, c, d}. Since A → ε must be chosen on a and A → a A also starts with a, the table has a conflict and the grammar is not LL(1).

More Compiler Design questions

Exams that ask this topic