GATE Computer ScienceHardGATE CS (PYQ pattern)
For S′ → S; S → S ( S ) | ε, LALR(1) merges canonical LR(1) states with equal cores. The LALR state whose only item is S → S ( S ) · is the merge of how many LR(1) states, and what is its lookahead set?
- A. 2 states; {$, (, )}
- B. 1 state; {$, (, )}
- C. 2 states; {(, )}
- D. 3 states; {$, (, )}
Correct answer: A. 2 states; {$, (, )}
An S at the top level is followed by $ or (; an S inside parentheses by ) or (. S ( S ) · is reached in both contexts, giving one LR(1) state with lookaheads {$, (} and one with {), (}. Merging them gives {$, (, )}.
More Compiler Design questions
- In 1: i = 0; 2: L1: if i >= n goto L3; 3: i = i + 1; 4: if i > k goto L1; 5: j = j + i; 6: goto L1; 7: L3: return j, how many back edges…
- An SLR(1) shift-reduce parser for E → T E'; E' → + T E' | ε; T → F T'; T' → F T' | ε; F → ( E ) | id parses "id + id id". Each shift and…
- Backpatching scheme (each relation gives 'if r goto ' and 'goto ', no fall-through optimisation, instruction numbers from 100). How many…
- A basic block compiles to six three-address statements: t1 = a + b; t2 = c d; t3 = a + b; t4 = t1 t2; t5 = t3 − t4; x = t5. Value…
- After applying left factoring repeatedly (each time extracting the longest common prefix of alternatives that share a first symbol…
- Consider the grammar S → A B c, A → a A | ε, B → b B | A d | ε. How many terminals are in FOLLOW(A), and is the grammar LL(1)?