GATE Computer ScienceHardGATE CS (PYQ pattern)
Each assignment is a definition named by its statement number. In 1: s = 0; 2: i = 0; 3: L1: if i >= n goto L4; 4: if a > 0 goto L2; 5: s = s + i; 6: goto L3; 7: L2: s = s - i; 8: a = a - 1; 9: L3: i = i + 1; 10: goto L1; 11: L4: return s, how many definitions reach the entry of statement 9 (L3), and how many reach statement 11 (L4)?
- A. 6 and 6
- B. 4 and 5
- C. 5 and 6
- D. 5 and 5
Correct answer: C. 5 and 6
At L3: s comes from 5 or 7 (s = 0 at 1 is killed on both paths into L3); i from 2 (first iteration) and 9 (around the loop); a from 8 (on the L2 path): {2, 5, 7, 8, 9} = 5. At L4 the loop may run zero times, so s = 0 (1) also reaches, together with 2, 5, 7, 8, 9: 6.
More Compiler Design questions
- A basic block is converted to a DAG using value numbering, treating + and as commutative, reusing an existing node when the same operator…
- A web of a variable is a maximal union of def-use chains that share a definition or a use; a register allocator gives each web its own…
- In 1: x = 1; 2: y = 0; 3: L1: if y > n goto L3; 4: if x > 5 goto L2; 5: x = x 2; 6: L2: y = y + x; 7: x = y - 1; 8: if y < m goto L1; 9: x…
- Using the standard backpatching scheme (each relational test yields 'if a<b goto ' followed by 'goto ', with no fall-through optimisation…
- For S → a A | A b; A → c | ε (augmented), how many non-blank ACTION entries does the initial state I0 have in the SLR(1) table, and in the…
- For S → a S | a S b S | c (augmented), how many states does the canonical LR(1) automaton have, and how many ACTION cells of the canonical…