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?
- A. 8 for LL(1), 8 for LR
- B. 6 for LL(1), 6 for LR
- C. 4 for LL(1), 8 for LR
- 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
- Augment S → ( L ) | x; L → S | L , S with S′ → S and build the canonical collection of LR(0) item sets. How many states does it have, and…
- The grammar S → A B; A → a | ε; B → A b | c is not LL(1). Each change below is applied to it on its own. Which of them make the grammar…
- L is the set of strings over {a, b} such that in every prefix the number of a's and the number of b's differ by at most 2. How many states…
- A compiler generates jumping code by backpatching (each relation gives 'if r goto ' then 'goto ', numbering from 100) for: if (!(a < b) &&…
- Compute FIRST of every non-terminal of S → X Y Z; X → a X | ε; Y → b Y | X; Z → c | ε, treating ε as a member of FIRST when the…
- For S → A b B | c; A → a | ε; B → c B | ε (augmented), in how many LR(0) states is there a conflict, and how many reduce entries does the…