In this video, we will discussing what is three address code in compiler design.
Three address code is one of the widely used intermediate codes which is easy in terms of creating and converting to target code. It uses three addresses at most and one operator for defining any expression.
Basically, three address codes are used in determining the sequence of actions for the compiler.
In three address codes, any expression is first broken down into such a way that no more than three addresses are required to express the code. These instructions are helpful in translating into assembly language easily.
Three operands are equated with mostly anyone binary operator and an assignment. Generally, Three Address Codes are represented as p = q op r. p, q, and r are operands. Operands can be any constants or temporary variables generated by the compiler. op represents an operator.
Some other examples of Three Address Codes are:
There are three ways to represent three address codes:
Quadruples: This representation consists of four fields: op, arg1, arg2, and result. op stands for operator and arg1, arg2 stands for two arguments or operands and the result is a variable used for storing the expression’s result.
Characteristics:
Triples: It doesn’t use any additional temporary variable for representing a single operation, instead whenever such reference is needed, a pointer is used. So, it is consisting of three fields only: op, arg1, and arg2.
Disadvantage:
Indirect Triples: It also makes use of a pointer to all the references to computations that are made individually and stored. It is quite similar to quadruple representation but it requires less space compared to that. In this, temporary variables are implicit, and rearranging the code is easier.
Three address code:
https://www.geeksforgeeks.org/three-address-code-compiler/