GATE Computer ScienceHardGATE CS (PYQ pattern)
For the code 1: i = 0; 2: s = 0; 3: L1: if i >= n goto L4; 4: t = a + i; 5: if t > m goto L2; 6: s = s + t; 7: goto L3; 8: L2: a = a - 1; 9: L3: i = i + 1; 10: goto L1; 11: L4: return s (only s is used after the return), which set is exactly the set of variables live on entry to statement 1?
- A. {a, m, n}
- B. {m, n}
- C. {a, m, n, s}
- D. {a, i, m, n}
Correct answer: A. {a, m, n}
Live on entry = used before being defined along some path. i, s and t are all assigned before any use (statements 1, 2, 4). a is read in statement 4 before statement 8 can assign it, m in statement 5, n in statement 3. So {a, m, n}; the assignment a = a − 1 does not stop a from being live, because a is read first.
More Compiler Design questions
- For G: S → a B | a C d; B → b | ε; C → b c, which statements are true? I. G is LL(2). II. G is LL(3). III. G is LR(0). IV. G is SLR(1).
- Construct the LL(1) table of S → A B c | B d; A → a A | ε; B → b B | A. Which option lists exactly the multiply-defined cells?
- An ε-NFA over {a, b} has states 0–4, start state 0 and accepting state 3, with moves δ(0, a) = {1}, δ(1, b) = {2}, δ(2, a) = {0, 3}, δ(3…
- For the code 1: i = 0; 2: s = 0; 3: L1: if i >= n goto L4; 4: t = a + i; 5: if t > m goto L2; 6: s = s + t; 7: goto L3; 8: L2: a = a - 1…
- An LR parser for S → ( L ) | x; L → S | L , S parses "( ( x , x ) , x , ( x ) )". How many reductions does it perform (accept not…
- Sethi–Ullman labelling: a leaf is 1 as a left child and 0 as a right child (a right operand may be a memory operand); an interior node is…