GATE Computer ScienceVery hardGATE CS (PYQ pattern)
For G: S → a A c | a B d | B c; A → z; B → z, which statements are true? I. The canonical LR(1) automaton has the same number of states as the LR(0) automaton. II. G is SLR(1). III. G is LALR(1).
- A. I and III only
- B. III only
- C. I, II and III
- D. II and III only
Correct answer: A. I and III only
After a z the state holds A → z· and B → z·. FOLLOW(A) = {c}, FOLLOW(B) = {c, d} overlap in c: SLR fails. The LR(1) lookaheads there are A: c, B: d, no clash; the other B → z· (start, lookahead c) has a different core. No core is ever split by lookaheads, so LR(1) and LR(0) both have 11 states and LALR = LR(1): G is LALR(1).
More Compiler Design questions
- S → a S | b S | c is LR(0). In its LR(0) parsing table the reduce action for a complete item is written in every terminal column including…
- For the production A → B C D (A.i, B.i, C.i, D.i inherited; A.s, B.s, C.s, D.s synthesised), which rule set makes the SDD L-attributed?
- Productions are numbered (1) S → ( L ); (2) S → x; (3) L → S; (4) L → L , S. A shift-reduce parser parses "( x , ( x ) )". In which order…
- A table-driven LL(1) parser for S → A B C; A → a | ε; B → b | ε; C → c | ε parses "a c". Each pop of a non-terminal (expanding it) and…
- For G: S → a E c | a F d | b F c | b E d; E → e; F → e, what is the smallest k for which G is LL(k), and is G LALR(1)?
- Live-variable analysis is used to find dead assignments (target not live immediately after the statement) in 1: x = a + b; 2: if c > 0…