GATE Computer ScienceVery hardGATE CS (PYQ pattern)
A SLR(1) parser for the augmented grammar S → x A | y B; A → z S | ε; B → z S | w parses "x z y w". What is the maximum number of grammar symbols on its stack at any moment (state numbers are not counted, S′ never appears)?
- A. 6
- B. 5
- C. 3
- D. 4
Correct answer: D. 4
Tracking the stack through 4 shifts and 4 reductions, the peak height is 4.
More Compiler Design questions
- The control-flow graph of 1: if p > 0 goto L2; 2: L1: x = x + 1; 3: if x > n goto L3; 4: L2: y = y + x; 5: if y < m goto L1; 6: L3: return…
- For S → a S b | a b | ε (augmented), how many multiply-defined ACTION cells do the SLR(1), LALR(1) and canonical LR(1) tables have, in…
- Expressions are compared textually (x + y and y + x are different) and an assignment to an operand kills an expression. For 1: a = x + y…
- For S → A a | b A c | B c | b B a; A → d; B → d (augmented), how many states do the LR(0) and canonical LR(1) automata have, and what does…
- The grammar S → S S S | a is ambiguous. How many distinct parse trees do the strings a⁷ (seven a's) and a⁶ (six a's) have, respectively?
- Build the SLR(1) table of the ambiguous grammar E → E + E | E E | id (augmented with S′ → E). How many LR(0) states are there, and how…