Construct the three address code for the following expression and represent it in quarter of a triple and indirect triple format a equal to b + c into d - e
Added 2 weeks ago
Active
Viewed 35
Ans

Let's break down the expression and construct Three Address Code (TAC) and represent it in:

1. Quadruple (or "Quartet") format

2. Triple format

3. Indirect triple format

Given Expression: a = b + c * (d - e)

First, inner expression step-by-step:

1. t1 = d - e

2. t2 = c * t1

3. t3 = b + t2

4. a = t3


1. Three Address Code (TAC)

t1 = d - e

t2 = c * t1

t3 = b + t2

a = t3

Each line represents one operation with at most three addresses (two operands and one result).  

2. Quadruple (or Quartet) Representation


IndexOperatorArg1Arg2Result
0-det1
1*ct1t2
2+bt2t3
3=t3-a

In this format:

- Each instruction is stored with four fields.

- Easy to optimize as all results are named (no ambiguity).

3. Triple Representation
IndexOperatorArg1Arg2
0-de
1*c(0)
2+b(1)
3=(2)-

Instead of variable names like t1, t2, etc., this format uses position indexes.

More compact, but harder to modify if instructions are moved.

4. Indirect Triple Representation

An indirect triple maintains a separate list of instruction pointers (indexes), which reference the triple table.

Instruction Pointer Table:

IndexOperator
0->(0)
1->(1)
2->(2)
3->(3)


Triple Table (same as above):


IndexOperatorArg1Arg2
0-de
1*c(0)
2+b(1)
3=(2)-

Indirect triples allow easier code reordering or optimization, since the instruction pointer list can change without modifying the instructions themselves.



Related Questions