GATE Computer ScienceHardGATE CS (PYQ pattern)
Augment S → ( L ) | x; L → S | L , S with S′ → S and build the canonical collection of LR(0) item sets. How many states does it have, and is the grammar LR(0)?
- A. 9 states; no, there is a shift-reduce clash on ,
- B. 8 states; yes, it is LR(0)
- C. 9 states; yes, it is LR(0)
- D. 10 states; no, there is a reduce-reduce clash
Correct answer: C. 9 states; yes, it is LR(0)
States: I0, S′ → S·, S → x·, S → (·L), L → S·, S → (L·) with L → L·,S, S → (L)·, L → L,·S, L → L,S·: 9. Every complete item sits alone in its state (L → L·, S shares a state with S → (L·), but neither is complete), so there is no conflict: LR(0).
More Compiler Design questions
- The grammar S → A B; A → a | ε; B → A b | c is not LL(1). Each change below is applied to it on its own. Which of them make the grammar…
- L is the set of strings over {a, b} such that in every prefix the number of a's and the number of b's differ by at most 2. How many states…
- A compiler generates jumping code by backpatching (each relation gives 'if r goto ' then 'goto ', numbering from 100) for: if (!(a < b) &&…
- Compute FIRST of every non-terminal of S → X Y Z; X → a X | ε; Y → b Y | X; Z → c | ε, treating ε as a member of FIRST when the…
- For S → A b B | c; A → a | ε; B → c B | ε (augmented), in how many LR(0) states is there a conflict, and how many reduce entries does the…
- For S → A B | B C; A → a A | ε; B → b B | ε; C → c C | d, which statement is FALSE?