GATE Computer ScienceHardGATE CSE
Statements: 1: a = 1; 2: b = 2; 3: c = a + b; 4: d = c * 2; 5: if d > 10 goto 8; 6: e = a + d; 7: goto 9; 8: e = b + 1; 9: print e. Which variables are live immediately before statement 5?
- A. {a, b, d}
- B. {b, d}
- C. {a, d}
- D. {a, b, c, d}
Correct answer: A. {a, b, d}
Before 5, d is used there; a is used on the path through 6, b on the path through 8 — so the live set is {a, b, d} (c is dead after 4).
More Compiler Design questions
- A C lexer applies the maximal-munch rule (always take the longest possible token). How many tokens does it produce for the input…
- How many basic blocks does this three-address code contain? 1: i = 0; 2: s = 0; 3: if i >= n goto 9; 4: t = a[i]; 5: if t < 0 goto 7; 6: s…
- Using Sethi–Ullman numbering (a leaf that is a left operand needs 1 register, a leaf that is a right operand can be used from memory and…
- Grammar: S → A B D; A → a A | ε; B → b B | A c | ε; D → d D | ε. What is |FOLLOW(A)| + |FOLLOW(B)| + |FOLLOW(D)|? (FOLLOW sets may contain…
- Grammar: E → T X; X → + T X | − T X | ε; T → F Y; Y → F Y | / F Y | ε; F → ( E ) | id | num | − F. How many non-empty cells does its LL(1)…
- How many states does the canonical LR(0) automaton have for the augmented grammar S' → S, S → a S b | a b?