Download as pdf or txt
Download as pdf or txt
You are on page 1of 1

 Compiler Design: Widely used as an intermediate representation during code generation.

 Dataflow Analysis: TAC's structure simplifies analysis of data dependencies within a program.
 Code Optimization: TAC instructions can be easily manipulated to optimize the program's execution.

In conclusion, TAC plays a significant role in compiler design by providing a simple and efficient intermediate
representation for code analysis, optimization, and generation of machine code for different target platforms.

Q4: Implementation of three address statements (Quadruples, Triples, lndirect triples)

Ans: Three-address code (TAC) can be implemented in different ways, each with its own advantages and trade-offs. Here's
a breakdown of three common implementations:

1. Quadruples:

 Uses a four-element structure to represent each TAC statement.


 Structure: (operator, arg1, arg2, result)
 Each element is typically a string or an index referencing a symbol table entry.
 Advantages:
o Explicit representation of all operands and the result.
o Easy to understand and implement.
 Disadvantages:
o Can be more memory-intensive compared to other representations due to the extra element.

Example (Quadruples):

(+, x, y, temp1)
(*, temp1, 2, z)
(/, z, 3, a)

2. Triples:

 Uses a three-element structure to represent each TAC statement.


 Structure: (operator, arg1, arg2)
 The result is often implicit, stored in a temporary variable or the leftmost operand.
 Requires keeping track of the temporary variable being used for the result.
 Advantages:
o More memory-efficient than quadruples.
o Simpler representation for some operations (e.g., assignments).
 Disadvantages:
o Implicit result can make code slightly less readable.
o Might require additional bookkeeping for temporary variables.

Example (Triples):

(+, x, y) // result stored in left operand (x)


(*, x, 2) // result stored in x (previously modified)
(/, x, 3, a) // exception: result explicitly assigned to 'a'

3. Indirect Triples:

 Uses a separate data structure (often an array) to store the actual TAC instructions.
 Each element in the main data structure is an index pointing to the corresponding TAC instruction in the separate
array.
 This approach reduces redundancy when multiple statements use the same result.
 Advantages:
o Most memory-efficient representation.
o Avoids redundant storage of common subexpressions.

You might also like