GATE Computer ScienceHardGATE CS (PYQ pattern)
Code: k = 3; m = k * k; k = k + 1; p = k * m; q = p - 36; s = q + z; r = s * 1. Only r is live at the end and z is an input. After constant propagation, folding, algebraic simplification and dead-code elimination (repeated to a fixed point), which instruction sequence is left?
- A. s = z; r = s
- B. s = z + 12; r = s
- C. r = z
- D. q = 0; s = q + z; r = s
Correct answer: C. r = z
k = 3, m = 9, then k is reassigned to 4 (a kill), so p = 4*9 = 36 and q = 0; s = 0 + z = z, and r = s*1 = z. Everything collapses to the copy r = z.
More Compiler Design questions
- A predictive translator uses E → T R; R → + { print('+') } T R | − { print('−') } T R | ε; T → num { print(num.val) }. (The print action…
- The grammar S → X Y Z; X → a X | ε; Y → b Y | X; Z → c | ε is not LL(1). How many distinct parse trees does the string "a a a c" have?
- Construct the SLR(1) parsing table of S → a S b S | b S a S | ε (augmented). In how many states of the SLR(1) automaton does the ACTION…
- G1: S → A B; A → a A | c; B → a B | c. G2: S → A B A; A → a A | c; B → b B | c. For each, how many more states does the canonical LR(1)…
- The grammar S → ( S ) S | ε is both LL(1) and SLR(1). On the input "( ( ) ) ( )", how many times does the LL(1) parser expand S → ε, and…
- 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…