GATE Computer ScienceVery hardGATE CS (PYQ pattern)
With instructions OP R, R and OP R, M (a leaf that is a right child can be a memory operand), the Sethi-Ullman algorithm labels a left leaf 1 and a right leaf 0, and an interior node max(l1, l2) if l1 ≠ l2, else l1 + 1. What is the least number of registers needed to evaluate (((a - b) * (c + (d * e))) + ((f * g) - (h + (i - j)))) with no spills?
- A. 4
- B. 2
- C. 5
- D. 3
Correct answer: D. 3
Bottom-up labelling gives 3 at the root.
More Compiler Design questions
- 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…
- 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…