GATE Computer ScienceVery hardGATE CS (PYQ pattern)

S → ( S ) S | ε is both LL(1) and SLR(1). Both parsers process "( ( ) ( ) )". What is the largest number of grammar symbols on the LL(1) parser's stack (not counting $) and on the LR parser's stack (not counting states) at any moment?

  1. A. 8 for LL(1), 8 for LR
  2. B. 6 for LL(1), 6 for LR
  3. C. 4 for LL(1), 8 for LR
  4. D. 6 for LL(1), 8 for LR

Correct answer: D. 6 for LL(1), 8 for LR

LL(1) (top of stack written first): after matching the first ( the inner S is expanded on top of ) S, giving ( S ) S ) S — 6 symbols; it never grows beyond that. LR: nothing is reduced by S → ( S ) S until the S after a ) is complete, so the right-recursive chain piles up: just before the first such reduction the stack is ( ( S ) ( S ) S — 8 symbols

More Compiler Design questions

Exams that ask this topic