GATE Computer ScienceVery hardGATE CS (PYQ pattern)
The statement r = ((x * y) + (y * x)) * ((x * y) − z) + (z − x * y) is turned into a DAG (+ and * commutative, − not), and code is generated with one instruction per interior node plus a separate copy r = t at the end. How many DAG nodes (leaves plus interior) are there, and how many instructions, counting the copy?
- A. 10 nodes, 8 instructions
- B. 19 nodes, 10 instructions
- C. 8 nodes, 7 instructions
- D. 9 nodes, 7 instructions
Correct answer: D. 9 nodes, 7 instructions
Leaves x, y, z. Interior: x*y (y*x is the same node), x*y + x*y (both children the same node), x*y − z, the product of those two, z − x*y, and the final +: 6 interior, 9 nodes. Instructions: 6 + the copy = 7. Without commutativity y*x is a separate node: 10 nodes, 8 instructions; the plain tree has 19 nodes.
More Compiler Design questions
- For the grammar S → a A | A b; A → c | ε, what is FOLLOW(A)?
- For S′ → S; S → A A A; A → a A | b, how many states of the canonical LR(1) automaton contain the complete item A → b · ?
- int f(int k) { if (k <= 0) return 0; return g(k - 1) + 1; } int g(int k) { if (k <= 1) return 1; return f(k - 2) + f(k - 1); } During the…
- After applying left factoring repeatedly (each time extracting the longest common prefix of alternatives that share a first symbol…
- A DAG is built for r = (p − q) (p − q) + (q − p) (p − q) − (p − q), with commutative and − not commutative. How many interior (operator)…
- For the grammar S → C C; C → c C | d (augmented with S′), the canonical LR(1) automaton is built and then the states with identical LR(0)…