GATE Computer ScienceHardGATE CS (PYQ pattern)

In the LL(1) table of S → i E t S Z | a; Z → e S | ε; E → b the only multiply-defined cell is M[Z, e]. A parser generator resolves it by always choosing Z → ε. Which of the strings w1 = i b t a, w2 = i b t a e a, w3 = i b t i b t a e a, w4 = i b t i b t a e a e a does the resulting parser accept?

  1. A. w1 and w2 only
  2. B. w1, w2 and w3 only
  3. C. all four strings
  4. D. w1 only

Correct answer: D. w1 only

With Z → ε chosen on lookahead e, no Z ever consumes an e. After the innermost S is parsed, every pending Z on the stack is popped as ε while e is still the lookahead, and finally $ meets e: an error. So any string containing e is rejected; only w1 is accepted. (Choosing Z → e S instead accepts all four, binding each else to the nearest then.)

More Compiler Design questions

Exams that ask this topic