GATE Computer ScienceHardGATE CS (PYQ pattern)
An LR parser for E → id | E [ E ] | ( E ) parses "id [ ( id [ id ] ) ]". What is the largest number of grammar symbols on its stack at any moment (states not counted)?
- A. 7
- B. 9
- C. 6
- D. 8
Correct answer: A. 7
Each id is reduced to E as soon as it is shifted. The deepest stack occurs at the inner index: E [ ( E [ E ] just before E [ E ] is reduced — 7 symbols. The input has 9 tokens, but they are never all on the stack together.
More Compiler Design questions
- 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)…
- 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…