GATE Computer ScienceHardGATE CS (PYQ pattern)
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 = 0; 10: L3: return x, which definitions of x (named by statement number) reach statement 6 (L2), and which reach statement 10 (L3)?
- A. {1, 5, 7} at 6; {1, 7, 9} at 10
- B. {1, 5, 7} at 6; {7, 9} at 10
- C. {5, 7} at 6; {1, 7, 9} at 10
- D. {1, 5, 7} at 6; {1, 5, 7, 9} at 10
Correct answer: A. {1, 5, 7} at 6; {1, 7, 9} at 10
x is defined at 1, 5, 7 and 9. At L1 the definitions 1 (first entry) and 7 (back edge from 8) arrive. Statement 6 is reached from 4 (carrying 1 and 7) and from 5: {1, 5, 7}. L3 is reached from the test at 3 (carrying 1 and 7; 5 is always killed by 7 before the back edge) and from 9: {1, 7, 9}.
More Compiler Design questions
- 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…
- For G: S → A | B; A → a A b | ε; B → a B b b | ε, which of these statements are true? I. Exactly two cells of the LL(1) table, M[S, a] and…
- The grammar S → i S | i S e S | a is ambiguous. How many distinct parse trees does the string "i i i a e a e a" have?
- int A(int m, int n) { if (m == 0) return n + 1; if (n == 0) return A(m - 1, 1); return A(m - 1, A(m, n - 1)); } Each activation record…