Sections


Main-Menu

header image

Three-Address Code


Three-address code is a sequence of statements of the form:

x := y op z

where x, y, and z are names, constants, or compiler generated temporaries; op is any operator. Three-address code is a linearization of an abstract syntax tree. This approach requires compiler generated temporaries. It is abstract and leaves the hard work of temporary management to the code generator which maps temporaries to registers and generates code to use the registers effectively.

Assignment Statement

x := y op z

x, y, z are names, constants, or compiler generated temporaries; op is any binary operator

x := op y

op is a unary operator

Indexed Assignment

x := y[i]
x[i] := y

x, y, i are data objects

Copy Statement

x := y

x, y

Unconditional jump

goto L

L is the label of the next statement to be executed

Conditional jump

if x relop y goto L

x

Procedure calls and returns

param x

x is a parameter

call p, n

p is the procedure, n is the number of parameters

return y

y is an optional return value

Address and pointer assignments

x := &y
x := *y

*x := y

x is set to the location of y

x is set to the value at the location y
the value pointed to by x is set to the r-value of y

Three-address statements are implemented as records with fields for the operator and operands. A quadruple (quad) is a record with four fields, op, arg1, arg2, result. The contents of the fields may be pointers to entries in the symbol table. Other forms of three-address code are triples and indirect triples. Neither of which are covered here.


Related Articles :



Leave a Comment

Please note: Comment moderation is enabled and may delay your comment. There is no need to resubmit your comment.

Shaadi.com Matrimony - Register for FREE