Skip to content
Official PYQ · 2015

GATE CS 2015 Set 1 Q55 — Intermediate Code Generation

Explain with AI
The least number of temporary variables required to create a three-address code in static single assignment form for the expression q+r/3+s−t∗5+u∗v/wq + r / 3 + s - t * 5 + u * v/w is__________________.
View worked solution

Answer: 8

To find the least number of temporary variables required to represent the given expression in Static Single Assignment (SSA) form, we first analyze the expression and its operator precedence:

E=q+r/3+s−t∗5+u∗v/wE = q + r / 3 + s - t * 5 + u * v / w

1. Operator Precedence and Associativity

  • Multiplication (*) and division (/) have higher precedence than addition (+) and subtraction (-), and they associate from left to right.
  • Addition (+) and subtraction (-) associate from left to right.

Parenthesizing the expression according to these rules gives:

E=(((q+(r/3))+s)−(t∗5))+((u∗v)/w)E = (((q + (r / 3)) + s) - (t * 5)) + ((u * v) / w)

2. Three-Address Code in SSA Form

In SSA form, every variable (including temporaries) must be assigned exactly once. Since there are no common subexpressions to eliminate, each of the 88 binary operations requires a unique temporary variable:

  1. t1=r/3t_1 = r / 3
  2. t2=q+t1t_2 = q + t_1
  3. t3=t2+st_3 = t_2 + s
  4. t4=t∗5t_4 = t * 5
  5. t5=t3−t4t_5 = t_3 - t_4
  6. t6=u∗vt_6 = u * v
  7. t7=t6/wt_7 = t_6 / w
  8. t8=t5+t7t_8 = t_5 + t_7

Thus, the minimum number of temporary variables required is 8.

Free practice · Your answers on this page are not saved.

Published
Report a correction
Keep exploringMore Intermediate Code Generation questions