GATE Computer ScienceVery hardGATE CS (PYQ pattern)
For E → id | E [ E ] | ( E ) (augmented with S′ → E), how many more states does the canonical LR(1) automaton have than the LALR(1) automaton?
- A. 7
- B. 14
- C. 0
- D. 12
Correct answer: B. 14
An E occurs in three contexts with different follow sets: at the top ({$, [}), inside [ ] ({], [}) and inside ( ) ({), [}). Apart from I0 and the accept state, each of the 7 LR(0) cores (after id, after [, after (, E[E·], E[E]·, (E·), (E)· and so on) is reachable in all three contexts, so it appears three times: LR(1) has 2 + 7 × 3 = 23 states against 9, a difference of 14.
More Compiler Design questions
- For the grammar E → E + T | T; T → T F | F; F → ( E ) | id, the LALR(1) parser is obtained by merging LR(1) states with identical cores…
- How many distinct LR(0) items does the grammar S → X Y Z; X → a X | ε; Y → b Y | X; Z → c | ε have (do not augment it; an ε-production…
- Which of the following is/are true? I. Every S-attributed definition is L-attributed. II. Every L-attributed definition can be evaluated…
- For S → S ( S ) | ε (augmented), count the reduce entries ( column included, accept excluded) in the SLR(1) and in the LALR(1) ACTION…
- A table-driven LL(1) parser for S → ( S ) S | ε parses "( ) ( )". Each pop of a non-terminal (expanding it) and each match of a terminal…
- An array A[1..4], [0..5], [1..6] of 8-byte elements is stored in row-major order starting at address 500. What is the address of A[3][2][5]?