GATE Computer ScienceVery hardGATE CS (PYQ pattern)
For S → a S b | a b | ε (augmented), how many multiply-defined ACTION cells do the SLR(1), LALR(1) and canonical LR(1) tables have, in that order?
- A. 1, 1 and 1
- B. 1, 1 and 2
- C. 1, 0 and 0
- D. 3, 1 and 2
Correct answer: B. 1, 1 and 2
The grammar is ambiguous (a b = S → a b, or S → a S b with S → ε), so no LR table is conflict-free. After a, the items S → a·S b, S → a·b and S → · clash on b (shift b vs reduce S → ε, since b ∈ FOLLOW(S)). SLR and LALR have one such state. Canonical LR(1) splits the after-a state into the outermost copy and the nested copy; S → · has lookahead b in both, so the clash appears twice: 2 cells. Merging cores can thus lower the conflict count.
More Compiler Design questions
- Expressions are compared textually (x + y and y + x are different) and an assignment to an operand kills an expression. For 1: a = x + y…
- For S → A a | b A c | B c | b B a; A → d; B → d (augmented), how many states do the LR(0) and canonical LR(1) automata have, and what does…
- The grammar S → S S S | a is ambiguous. How many distinct parse trees do the strings a⁷ (seven a's) and a⁶ (six a's) have, respectively?
- Build the SLR(1) table of the ambiguous grammar E → E + E | E E | id (augmented with S′ → E). How many LR(0) states are there, and how…
- For S → A a A b | B b B a; A → ε; B → ε (augmented), how many ACTION cells are multiply defined in the LR(0), SLR(1) and LALR(1) tables…
- For G: S → a A c | a B d | B c; A → z; B → z, which statements are true? I. The canonical LR(1) automaton has the same number of states as…