GATE Computer ScienceHardGATE CS (PYQ pattern)
For S′ → S; S → ( L ) | x; L → S | L , S, LALR(1) is formed by merging canonical LR(1) states with equal cores. The LALR state reached from the start state on ( is the merge of how many LR(1) states, and the state reached from it on L and then , is the merge of how many?
- A. 1 and 1
- B. 2 and 2
- C. 2 and 1
- D. 3 and 1
Correct answer: C. 2 and 1
( can be read at the top level (the parenthesised S is followed by $) or inside another list (followed by ) or ,): two LR(1) states with the core S → (·L), … but different lookaheads. A comma, however, only occurs inside a list, where L is always followed by {), ,}, so the core L → L,·S has a single LR(1) state.
More Compiler Design questions
- int j = 2; int A[0..4] = {0, 3, 1, 4, 2}; int Sum(k, lo, hi, e) { int s = 0; for (k = lo; k <= hi; k++) s = s + e; return s; } All…
- An SLR(1) shift-reduce parser for E → E + T | T; T → T F | F; F → ( E ) | id parses "( id + id ) id". Each shift and each reduce counts as…
- An LR parser for S → S ( S ) | ε parses "( ( ) ) ( )". Each shift and each reduce (including reductions by S → ε) counts as one move. What…
- Minimal SSA form (φ-functions at the iterated dominance frontier of each variable's defining blocks, no pruning) is built for 1: x = 1; 2…
- SSA form is built for 1: i = 0; 2: L1: if i >= n goto L4; 3: if i > k goto L2; 4: x = i 2; 5: goto L3; 6: L2: x = i + 1; 7: y = x; 8: L3…
- Minimal SSA form without liveness pruning (φ-functions at the iterated dominance frontier of every block that assigns the variable) is…