GATE Computer ScienceVery hardGATE CS (PYQ pattern)
For the augmented grammar S′ → S; S → a S a | b S b | c, how many states does the canonical LR(1) automaton have, and how many does the LALR(1) automaton have?
- A. 14 and 9
- B. 23 and 12
- C. 17 and 9
- D. 23 and 9
Correct answer: D. 23 and 9
The LR(0) automaton has 9 states: I0, the accept state, and seven cores (after a, after b, after c, after a S, after b S, a S a·, b S b·). In LR(1) each of those seven cores occurs with three different lookaheads: $ (outermost S), a (inside a…a) and b (inside b…b). So 1 + 1 + 7 × 3 = 23 canonical states, which merge back to 9 LALR states.
More Compiler Design questions
- For the grammar G: S → A b | B c; A → a A | ε; B → a B | ε, the LL(1) predictive table is built. Which statement is correct?
- For G: S → a A | b B; A → c A d | ε; B → c B d d | ε, which statements are true? I. G is LL(1). II. G is LR(0). III. The canonical LR(1)…
- A scanner has two token rules, R1 = a b and R2 = b c. It always takes the longest prefix matching some rule and never backtracks over a…
- Register allocation by graph colouring is done on the loop 1: L1: v1 = v4 + 1; 2: v2 = v5 + 1; 3: v3 = v1 + 1; 4: v4 = v2 + 1; 5: v5 = v3…
- An array is declared A[L..10][−4..5] with 4-byte elements and stored in row-major order starting at address 1744. If the address of…
- For S → a A | b B; A → c A d | ε; B → c B d d | ε (augmented with S′ → S), count the reduce entries (state, terminal) in the ACTION…