Question

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 _____.

Official answer and solution
Official answer
8
From
Official GATE 2015 answer key

Solution

Convert the arithmetic expression into Static Single Assignment three-address code by assigning each binary operation to a unique temporary variable.

Expression: q+r/3+s−t∗5+u∗v/wq + r / 3 + s - t * 5 + u * v / w.

In Static Single Assignment (SSA) form, every temporary variable is defined exactly once.
Evaluating operations adhering to standard operator precedence and left-to-right associativity:

  1. Multiplications and Divisions (higher precedence):

    • t1=r/3t_1 = r / 3
    • t2=t∗5t_2 = t * 5
    • t3=u∗vt_3 = u * v
    • t4=t3/wt_4 = t_3 / w
  2. Additions and Subtractions (evaluated left-to-right):

    • t5=q+t1t_5 = q + t_1
    • t6=t5+st_6 = t_5 + s
    • t7=t6−t2t_7 = t_6 - t_2
    • t8=t7+t4t_8 = t_7 + t_4

There are 8 distinct binary operations in the expression: two divisions, two multiplications, three additions, and one subtraction.
Each three-address code instruction computes one binary operator, requiring a distinct temporary variable under SSA rules (t1,t2,t3,t4,t5,t6,t7,t8t_1, t_2, t_3, t_4, t_5, t_6, t_7, t_8).

Therefore, the least number of temporary variables required is 88.

Final answer

8

Common trap

Reusing temporary variables (e.g., t1 = t1 + s) which violates the SSA property that every variable must be assigned exactly once.

The answer is the one in the official GATE answer key. The solution is this site's own explanation.

Source

Paper
GATE 2015 Computer Science and Information Technology (CS) Session 1
Question
65 of 65, printed as CS Q.55
Section
Computer Science and Information Technology

Report an error in this question

GATE questions are the work of the organising institutes. This site is independent and is not affiliated with them.