GATE Computer ScienceVery hardGATE CS (PYQ pattern)
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 the LALR(1) automaton?
- A. 3 for G2 and 3 for G3
- B. 3 for G2 and 6 for G3
- C. 3 for G2 and 4 for G3
- D. 4 for G2 and 5 for G3
Correct answer: A. 3 for G2 and 3 for G3
The A-cores (after a, A → b·, A → a A·) split by the lookahead of the A they belong to. In G2 the first A is followed by FIRST(A) = {a, b} and the second by $: two copies of 3 cores, 3 extra. In G3 the first and second A are both followed by {a, b}, so they share the same LR(1) states; only the last A (lookahead $) adds copies: still 3 extra (11 versus 8 states).
More Compiler Design questions
- 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…
- 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?