GATE Computer ScienceHardGATE CS (PYQ pattern)
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 have, and is the grammar LR(0)?
- A. 9 states; yes, no state mixes items
- B. 8 states; no — T → int· clashes with id
- C. 9 states; no — D → T L· clashes with shifting ,
- D. 10 states; yes, no state mixes items
Correct answer: C. 9 states; no — D → T L· clashes with shifting ,
States: I0, D′ → D·, T → int·, T → float·, D → T·L (with L-items), D → T L· together with L → L·, id, L → id·, L → L ,·id, L → L , id·: 9. The state after T L holds the complete item D → T L· and the item L → L·, id, which shifts ',': an LR(0) shift-reduce conflict. SLR resolves it since FOLLOW(D) = {$}.
More Compiler Design questions
- Build the SLR(1) table of S → A a | b A c | d c | b d a; A → d (augmented). Which option describes all of its conflicts?
- Compute FIRST of every non-terminal of S → A B | B C; A → a A | ε; B → b B | ε; C → c C | c, treating ε as a member of FIRST when the…
- With int i = 2 and the array A = [0, 3, 5, 7, 9, 11, 13] (indices from 0), the call f(A[i], i) is made to void f(p, q) { i = i + 1; p = p…
- How many states does the minimal complete DFA (dead state included) for the regular expression (ab | aba) over {a, b} have?
- For E → T R; R → + T R | − T R | ε; T → F P; P → ^ T | ε; F → ( E ) | id, compute FOLLOW of every non-terminal ( counts as a member). What…
- A basic block is converted to a DAG using value numbering, treating + and as commutative, reusing an existing node when the same operator…