GATE Computer ScienceVery hardGATE CS (PYQ pattern)
A SLR(1) parser for the augmented grammar S → id | id [ E ] | id ( E ); E → id parses "id [ id ]". What is the maximum number of grammar symbols on its stack at any moment (state numbers are not counted, S′ never appears)?
- A. 4
- B. 2
- C. 6
- D. 5
Correct answer: A. 4
Tracking the stack through 4 shifts and 2 reductions, the peak height is 4.
More Compiler Design questions
- Partition into basic blocks (leaders: the first statement, every jump target, every statement right after a jump): 1: i = 0; 2: L1: if i >…
- Consider the strings over {a,b} that start and end with different symbols. How many states does the minimal complete DFA (including a dead…
- A table-driven LL(1) parser for S → a S A | ε; A → b S | c parses "a a b a c c". Each expansion of a non-terminal and each match of a…
- For G: S → a A b | A a; A → a | ε (which generates a, aa, ab and aab), which statements are true? I. G is LL(2). II. G is LL(3). III. G is…
- Let G2: S → A A; A → a A | b and G3: S → A A A; A → a A | b. For each, how many more states does the canonical LR(1) automaton have than…
- 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…