GATE Computer ScienceHardGATE CS (PYQ pattern)
Sethi–Ullman labelling (a leaf is 1 if it is a left child and 0 if it is a right child, since a right operand may come from memory; an interior node gets max(l1, l2) if l1 ≠ l2, else l1 + 1) gives the number of registers needed without spilling. Which expression needs exactly 3 registers?
- A. a + (b + (c + (d + e)))
- B. (a + (b * c)) − (d * (e + f))
- C. ((a − b) + c) * ((d + e) − (f + g))
- D. (a + b) * (c − (d + (e * f)))
Correct answer: B. (a + (b * c)) − (d * (e + f))
(a + (b*c)): a = 1, b*c = 1 → 2. d * (e + f): d = 1, e + f = 1 → 2. Equal labels → 3. The right-deep chain a + (b + (c + (d + e))) is 2 at every level (each inner sum is a right child labelled 1 against a left leaf 1, then 2 against a leaf 1). ((a−b)+c) = 1 and (d+e) − (f+g) = 2 give 2. (a+b) = 1 and c − (…) = 2 give 2.
More Compiler Design questions
- An SDD uses N → B N1 { N.val = B.val + 2 × N1.val } | B { N.val = B.val } and B → 0 { B.val = 0 } | 1 { B.val = 1 }. What is N.val at the…
- A SLR(1) parser for the augmented grammar S → id | id [ E ] | id ( E ); E → id parses "id [ id ]". What is the maximum number of grammar…
- Partition into basic blocks (leaders: the first statement, every jump target, every statement right after a jump): 1: i = 0; 2: L1: if i >…
- Consider the strings over {a,b} that start and end with different symbols. How many states does the minimal complete DFA (including a dead…
- A table-driven LL(1) parser for S → a S A | ε; A → b S | c parses "a a b a c c". Each expansion of a non-terminal and each match of a…
- For G: S → a A b | A a; A → a | ε (which generates a, aa, ab and aab), which statements are true? I. G is LL(2). II. G is LL(3). III. G is…