GATE Computer ScienceVery hardGATE CS (PYQ pattern)
For S → S ( S ) | ε (augmented with S′ → S), how many states do the LR(0) and canonical LR(1) automata have?
- A. 5 and 8
- B. 5 and 10
- C. 6 and 8
- D. 6 and 10
Correct answer: A. 5 and 8
LR(0): I0 {S′ → ·S, S → ·S(S), S → ·}, I1 {S′ → S·, S → S·(S)}, I2 {S → S(·S), S → ·S(S), S → ·}, I3 {S → S(S·), S → S·(S)}, I4 {S → S(S)·}: 5. In LR(1), S at the top level is followed by {$, (} and inside parentheses by {), (}. I2, I3, I4 occur only after a ( but I2 can be entered from the top level and from inside, so each of I2, I3, I4 gets two copies: 5 + 3 = 8.
More Compiler Design questions
- Consider G: S → A | x b; A → a A b | B; B → x. Which statements are true? I. G is LL(1). II. G is LR(0). III. G is SLR(1). IV. G is LALR(1).
- In the code 1: a = 4; 2: b = n 2; 3: i = 0; 4: L1: t1 = a b; 5: t2 = t1 + 8; 6: t3 = i a; 7: t4 = t2 + t3; 8: c = t1 - 3; 9: t5 = c + t2…
- For 1: a = 0; 2: if p > 0 goto L2; 3: L1: a = a + 1; 4: if a < m goto L1; 5: goto L3; 6: L2: b = 1; 7: if q > 0 goto L1; 8: L3: return a…
- For E → id | E [ E ] | ( E ) (augmented with S′ → E), how many more states does the canonical LR(1) automaton have than the LALR(1)…
- For the grammar E → E + T | T; T → T F | F; F → ( E ) | id, the LALR(1) parser is obtained by merging LR(1) states with identical cores…
- How many distinct LR(0) items does the grammar S → X Y Z; X → a X | ε; Y → b Y | X; Z → c | ε have (do not augment it; an ε-production…