GATE Computer ScienceVery hardGATE CS (PYQ pattern)
For S → a A | b B; A → c A d | ε; B → c B d d | ε (augmented with S′ → S), count the reduce entries (state, terminal) in the ACTION tables, $ column included, accept excluded. What are the counts for the SLR(1), LALR(1) and canonical LR(1) tables, in that order?
- A. 14, 14 and 12
- B. 14, 10 and 12
- C. 10, 10 and 12
- D. 14, 10 and 10
Correct answer: B. 14, 10 and 12
FOLLOW(A) = FOLLOW(B) = {d, $}. SLR: six complete-item states for A/B (two ε-states and one c…d state per non-terminal) get 2 entries each = 12, plus S → a A· and S → b B· on $ = 14. LALR: the ε-state right after a (or b) has lookahead $ only and the one after a c (or b c) has d only, saving 4: 10. LR(1) splits A → c A d· and B → c B d d· into a $-copy and a d-copy, and also has a separate ε-state for deeper nesting (lookahead d): 12.
More Compiler Design questions
- S → C C; C → c C | d is LR(0). In its LR(0) parsing table the reduce action for a complete item is written in every terminal column…
- 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)…
- 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…