GATE Computer ScienceHardGATE CSE
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 needs 0; an internal node needs max(l,r) if l ≠ r, else l+1), what is the minimum number of registers needed to evaluate (((a + b) * (c - d)) / ((e + f) * (g - h))) without spilling?
- A. 2
- B. 4
- C. 3
- D. 5
Correct answer: C. 3
(a+b) and (c−d) each need 1, so each product needs 2; the two products have equal labels 2, hence the division needs 2+1 = 3.
More Compiler Design questions
- 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?
- Program: int x = 5; int f() { return x; } int g() { int x = 7; return f() + x; } int h() { int x = 11; return g() + f() + x; } main calls…
- The expression ((((a + b) + c) ((a + b) + d)) - ((a + b) ((a + b) + c))) is stored as a DAG with common subexpressions shared (no…
- Control-flow graph: B1: a=1; b=2; c=a+b; then B2: d=c+b; if d<10 goto B4 (else B3); B3: c=d+a; b=c; goto B2; B4: print(c+a). Edges: B1→B2…