GATE Computer ScienceVery hardGATE CS (PYQ pattern)
For S → A | x b; A → a A b | B; B → x (augmented), how many states does the canonical LR(1) automaton have, and in how many states of the SLR(1) table is there a conflict?
- A. 10 states; 1 conflicting state
- B. 14 states; 1 conflicting state
- C. 14 states; no conflict
- D. 12 states; 2 conflicting states
Correct answer: B. 14 states; 1 conflicting state
LR(0) has 10 states. The cores reached inside a…b (after a, a A, a A b, and x / B there) recur with lookahead b in addition to the top-level copies with $, adding 4 states: 14. SLR: after x at the top, S → x·b and B → x· clash on b because FOLLOW(B) = {b, $}; the LR(1) lookahead there is only $, so the grammar is LALR(1) but not SLR(1).
More Compiler Design questions
- A yacc-generated parser for E → E op E | num uses the precedence declarations %left ''; %right '-'; %left '+' (in this order, so + binds…
- Consider strings containing both ab and bb as substrings in either order (overlaps allowed). How many states does the minimal complete DFA…
- G1: L → L , x | x and G2: L → x , L | x generate the same language. A shift-reduce (LR) parser parses "x , x , x , x , x" (five x's) with…
- Productions of the grammar are numbered: (1) E → E + T; (2) E → T; (3) T → T F; (4) T → F; (5) F → ( E ); (6) F → id. An LR parser parses…
- In 1: i = 0; 2: L1: if i >= n goto L3; 3: if i > k goto L2; 4: t = a b; 5: x = t + 1; 6: L2: y = a + b; 7: i = i + 1; 8: goto L1; 9: L3…
- For the grammar S → X Y Z; X → a X | ε; Y → b Y | X; Z → c | ε, what is FIRST(S)? (ε counts as a member if S is nullable.)