Compiler Design and Construction - Old Questions

7.  Define three address codes. Write three address codes for

        S --> do m=n-p while a<=b

6 marks | Asked in 2075

The address code that uses at most three addresses, two for operands and one for result is called three address code. Each instruction in three address code can be described as a 4-tuple: (operator, operand1, operand2, result).

A quadruple (Three address code) is of the form: x = y op z where x, y and z are names, constants or compiler-generated temporaries and op is any operator.

Followings are the 3-address code statements for different statements.

  • Assignment statement:

            x = y op z ( binary operator op)

             x = op y ( unary operator op)

  • Copy statement: x = z 
  • Unconditional jump: goto L ( jump to label L)
  • Conditional jump: if x relop y goto L
  • Procedure call:

            param x1

            param x2

            . .

            ..

            param xn

            call p, n i.e. call procedure P(x1,x2,….. xn)

  • Indexed assignment:

            x = y[i]

            x[i] = y

  • Address and pointer assignments:

            x = &y

            x = *y

            *x = y


Given expression;

   S --> do m=n-p while a<=b

Three address code for given expression:

1. m = n-p

2. if a<b goto (1)

3. if a=b goto (1)

4. stop