236 views
1 1 vote

Consider the following C-style code segment:

while (a < b) {
    if (c < d) x = y + z;
    else x = y - z;
}


Assume this code is translated into Three-Address Code (TAC) using the minimum number of labels required to ensure:

  1. The $\verb|while|$ condition is evaluated at the start of every iteration.
     
  2. The $\verb|if-else|$ control flow correctly branches to either the $\verb|if|$ block or the $\verb|else|$ block.
     
  3. Control returns to the $\verb|while|$ condition check after the $\verb|if-else|$ statement finishes.
     
  4. There is a single exit label immediately following the loop.
     

What is the minimum number of labels required to represent this control flow?

1 Answer

1 1 vote
L1: if a < b goto L2   // Label 1: Loop Header
    goto L4           // Label 4: Loop Exit

L2: if c < d goto L3  // Label 2: If-Condition
    x = y - z         // Fall-through for 'else'
    goto L1

L3: x = y + z         // Label 3: If-True block
    goto L1

L4: ...               // End of Loop


$\text { Minimum number of labels required is } 4$

Answer:
Position:
Show:

Related questions

0 0 votes
2 2 answers
287
287 views
GO Classes asked Jan 20
287 views
Consider the following basic block consisting of three-address code instructions. Assume that only the variable $\verb|x|$ is "live" at the exit of this basic block.1. a ...
1 1 vote
1 1 answer
274
274 views
GO Classes asked Jan 20
274 views
In a compiler's optimization phase, a Directed Acyclic Graph (DAG) is constructed for the following basic block:1. t1 = a + b 2. t2 = c * d 3. t3 = t1 + t2 4. t4 = a + b ...
3 3 votes
2 2 answers
336
336 views
GO Classes asked Jan 20
336 views
Consider the following regular expression over the alphabet $\Sigma=\{a, b\}$ that represents a specific class of tokens in a new programming language:$$r=(a+b)^* a b b$$...
1 1 vote
1 1 answer
265
265 views
GO Classes asked Jan 20
265 views
Consider the following S-attributed SDT scheme used to calculate the value of an expression. The grammar generates simple arithmetic additions and is suitable for an LR p...