GATE Computer ScienceVery hardGATE CS (PYQ pattern)
Integer code: a = 4; b = a * 2; c = b + n; d = c * 0; e = d + b; f = e - 8; g = n + f; h = g * 1; r = h. Only r is live at the end. The optimiser repeats constant propagation, constant folding, algebraic simplification (x*0 = 0, x*1 = x, x+0 = x), copy propagation and dead-code elimination until nothing changes. How many instructions remain?
- A. 7
- B. 8
- C. 2
- D. 1
Correct answer: D. 1
a, b fold to constants (4, 8); d = c*0 becomes 0, so e = 8 and f = 0; g = n + 0 becomes n; h = n*1 becomes n; only r = n survives. Without algebraic rules 7 instructions would remain.
More Compiler Design questions
- For S → A | x b; A → a A b | B; B → x (augmented), how many states does the canonical LR(1) automaton have, and in how many states of the…
- A yacc-generated parser for E → E op E | num uses the precedence declarations %left ''; %right '-'; %left '+' (in this order, so + binds…
- Consider strings containing both ab and bb as substrings in either order (overlaps allowed). How many states does the minimal complete DFA…
- G1: L → L , x | x and G2: L → x , L | x generate the same language. A shift-reduce (LR) parser parses "x , x , x , x , x" (five x's) with…
- Productions of the grammar are numbered: (1) E → E + T; (2) E → T; (3) T → T F; (4) T → F; (5) F → ( E ); (6) F → id. An LR parser parses…
- In 1: i = 0; 2: L1: if i >= n goto L3; 3: if i > k goto L2; 4: t = a b; 5: x = t + 1; 6: L2: y = a + b; 7: i = i + 1; 8: goto L1; 9: L3…