GATE Computer ScienceVery hardGATE CS (PYQ pattern)
For S → A b | B c; A → a A | ε; B → a B | ε (augmented), in how many LR(0) states is there a conflict, how many ACTION cells of the LR(0) table are multiply defined (reductions written in every column, including $), and how many in the SLR(1) table?
- A. 2 states, 2 cells; SLR(1): 0
- B. 1 state, 4 cells; SLR(1): 1
- C. 2 states, 8 cells; SLR(1): 0
- D. 2 states, 8 cells; SLR(1): 2
Correct answer: C. 2 states, 8 cells; SLR(1): 0
I0 and the state after a both contain A → · and B → · (and a shift on a): LR(0) writes both reductions in all 4 columns a, b, c, $ — 4 clashes per state, 8 in all. SLR uses FOLLOW(A) = {b} and FOLLOW(B) = {c}, which are disjoint and do not contain a, so there is no clash. (The grammar is SLR(1) though it is not LL(k) for any k.)
More Compiler Design questions
- How many distinct LR(0) items does the grammar S → i E t S Z | a; Z → e S | ε; E → b have (do not augment it; an ε-production gives…
- Only the lower triangle (i ≥ j) of a 10 × 10 matrix A[1..10][1..10] of 4-byte elements is stored, packed into consecutive words starting…
- For G: S → A A; A → a A | b | ε, which statements are true? I. FOLLOW(A) = {a, b, }. II. G is LL(1). III. G is ambiguous. IV. G is LR(1).
- A DFA reads a binary number most-significant bit first (leading zeros allowed; the empty string counts as 0). How many states does the…
- The grammar S → S a b | S c | A S | x; A → A d | S y | z is transformed by the standard algorithm that removes (indirect and immediate)…
- For the code 1: i = 0; 2: s = 0; 3: L1: if i >= n goto L4; 4: t = a + i; 5: if t > m goto L2; 6: s = s + t; 7: goto L3; 8: L2: a = a - 1…