All mock tests are FREE till 31 December — register to save your progress

Directions (Q91–95): Consider the following Three Address Code sample for solving the questions:

100: t1 = y + 2
101: initial = x / t1
102: limit = 10
103: if i > j goto 105
104: goto 111
105: if num > b goto 107
106: goto 111
107: num = limit - 1
108: b = y + 2
109: i = i - num
110: goto 103
111: j = i - num
112: k = j + b

Which of the following is the correct high level code for the TAC given in the passage?

Pick an option to check yourself, or open the answer below.

Show answer & explanation

Correct answer: D.

init = x/(y+2);
limit = 10;
while (i>j && num>b)
{
  num = limit-1;
  b = y+2;
  i = i-num;
}
j = i-num;
k = k+b;

Explanation

Statements 103–110 form a loop: control enters the body (107–109) only if i > j (103) AND num > b (105), and 110 jumps back to 103. If either test fails, control goes to 111. That is exactly while (i > j && num > b) { … } followed by j = i − num and the final assignment.

More Theory of Computation and Compilers questions