GATE Computer ScienceVery hardGATE CS (PYQ pattern)
For S → X Y Z; X → a X | ε; Y → b Y | X; Z → c | ε (augmented), in how many states is there a conflict in the SLR(1) table, and in how many in the canonical LR(1) table?
- A. 4 in SLR(1), 0 in LR(1)
- B. 4 in SLR(1), 2 in LR(1)
- C. 4 in SLR(1), 4 in LR(1)
- D. 2 in SLR(1), 2 in LR(1)
Correct answer: B. 4 in SLR(1), 2 in LR(1)
The grammar is ambiguous (an a can come from X or, via Y → X, from the second X), so even canonical LR(1) keeps the clash between X → · and shifting a in I0 and in the state after a (a top-level X may stop early). SLR also reduces X → · on all of FOLLOW(X) = {a, b, c, $} in the state after X (S → X·Y Z, Y → ·X …) and in the state after b (Y → b·Y …), where the true lookahead of that X is only {c, $}: those two extra states clash on a and b. Total 4 versus 2
More Compiler Design questions
- In 1: i = 0; 2: c = 2; 3: L1: if i >= n goto L3; 4: d = c 3; 5: if i > k goto L2; 6: c = 2; 7: L2: e = d + 1; 8: f = a b; 9: i = i + 1…
- L1 is the set of strings over {a, b} whose third symbol from the right is a; its minimal DFA has 8 states. L2 = L1 ∩ {strings of even…
- For the augmented grammar S′ → S; S → ( L ) | x; L → S | L , S, how many states does the canonical LR(1) automaton have, and in how many…
- G: S → T | S ; T; T → a | ( S ). Removing the left recursion gives G′: S → T R; R → ; T R | ε; T → a | ( S ). Which statements are true?…
- The grammar A → B a | A a | c; B → B b | A b | d is transformed by the standard algorithm that removes (indirect and immediate) left…
- SDD: D → T L { L.inh = T.type }; T → int { T.type = integer }; L → L1 , id { L1.inh = L.inh; addType(id.entry, L.inh) }; L → id {…