GATE Computer ScienceHardGATE CS (PYQ pattern)
Build the SLR(1) table of the ambiguous grammar E → E + E | E * E | id (augmented with S′ → E). How many LR(0) states are there, and how many ACTION cells are multiply defined?
- A. 7 states, 2 cells
- B. 9 states, 4 cells
- C. 7 states, 6 cells
- D. 7 states, 4 cells
Correct answer: D. 7 states, 4 cells
States: I0, S′ → E· (with E → E·+E, E·*E), E → id·, E → E+·E, E → E*·E, E → E+E·, E → E*E·: 7. FOLLOW(E) = {+, *, $}. In E+E· and E*E· the reduce on + and * meets the shifts on + and *: 2 cells in each of those 2 states = 4 (the $ cells are plain reduces).
More Compiler Design questions
- For S → A a A b | B b B a; A → ε; B → ε (augmented), how many ACTION cells are multiply defined in the LR(0), SLR(1) and LALR(1) tables…
- 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…
- 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…