GATE Computer ScienceVery hardGATE CS (PYQ pattern)
For S → a S | a S b S | c (augmented), how many states does the canonical LR(1) automaton have, and how many ACTION cells of the canonical LR(1) table are multiply defined?
- A. 7 states, 1 cell
- B. 12 states, 0 cells
- C. 14 states, 2 cells
- D. 12 states, 1 cell
Correct answer: D. 12 states, 1 cell
This is the dangling-else shape: a S b S can be read with the b belonging to an inner or outer a. LR(0) has 7 states; five cores split into two lookahead variants (top level with $, and nested before a b), giving 12. In the copy of {S → a S·, S → a S·b S} where this a S is itself nested before a b (lookaheads {b, $}), reducing on b clashes with shifting b: exactly 1 conflicting cell, so the grammar is not LR(1) (it is ambiguous).
More Compiler Design questions
- For G: S → A | B; A → a A b | ε; B → a B b b | ε, which of these statements are true? I. Exactly two cells of the LL(1) table, M[S, a] and…
- The grammar S → i S | i S e S | a is ambiguous. How many distinct parse trees does the string "i i i a e a e a" have?
- int A(int m, int n) { if (m == 0) return n + 1; if (n == 0) return A(m - 1, 1); return A(m - 1, A(m, n - 1)); } Each activation record…
- For S → id | id [ E ] | id ( E ); E → id (augmented with S′ → S), how many states do the LR(0) and the canonical LR(1) automata have?
- The grammar S → A B; A → a A | a; B → a B | a is ambiguous. How many distinct parse trees does the string "a a a a a a" have?
- For the declaration grammar D → T L; T → int | float; L → L , id | id (augmented with D′ → D), how many states does the LR(0) automaton…