GATE Computer ScienceHardGATE CS (PYQ pattern)

The grammar S → X Y Z; X → a X | ε; Y → b Y | X; Z → c | ε is not LL(1). How many distinct parse trees does the string "a a a c" have?

  1. A. 3
  2. B. 4
  3. C. 1
  4. D. 8

Correct answer: B. 4

Y derives b*a*, so with no b in the string X derives a^i and Y (through Y → X) derives a^(3−i), Z → c. i can be 0, 1, 2 or 3, giving 4 trees; the ambiguity is why M[X, a] holds both X → a X and X → ε.

More Compiler Design questions

Exams that ask this topic