GATE Computer ScienceVery hardGATE CS (PYQ pattern)
G1: S → A B; A → a A | c; B → a B | c. G2: S → A B A; A → a A | c; B → b B | c. For each, how many more states does the canonical LR(1) automaton have than the LALR(1) automaton?
- A. 0 for G1, 3 for G2
- B. 3 for G1, 3 for G2
- C. 0 for G1, 6 for G2
- D. 3 for G1, 0 for G2
Correct answer: A. 0 for G1, 3 for G2
A core is duplicated only when the same LR(0) core is reached with different lookaheads. In G1 the A-items (lookahead {a, c}) and the B-items (lookahead $) are different cores, so nothing splits: 0. In G2 A occurs twice, once followed by FIRST(B) = {b, c} and once by $, so A's three cores (after a, A → c·, A → a A·) each get two LR(1) copies: 3 extra states.
More Compiler Design questions
- The grammar S → ( S ) S | ε is both LL(1) and SLR(1). On the input "( ( ) ) ( )", how many times does the LL(1) parser expand S → ε, and…
- Integer code: a = 4; b = a 2; c = b + n; d = c 0; e = d + b; f = e - 8; g = n + f; h = g 1; r = h. Only r is live at the end. The…
- For S → A | x b; A → a A b | B; B → x (augmented), how many states does the canonical LR(1) automaton have, and in how many states of the…
- A yacc-generated parser for E → E op E | num uses the precedence declarations %left ''; %right '-'; %left '+' (in this order, so + binds…
- Consider strings containing both ab and bb as substrings in either order (overlaps allowed). How many states does the minimal complete DFA…
- G1: L → L , x | x and G2: L → x , L | x generate the same language. A shift-reduce (LR) parser parses "x , x , x , x , x" (five x's) with…