Compiler Design and Construction - Old Questions

8.  What do you mean by three address code? Write the syntax directed definition for following grammar to produce the three address codes for assignments

    S -> id = E

    E -> id

6 marks | Asked in 2070

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.

For e.g. 

The three-address code for a+b*c-d/(b*c) is


Given grammar;

    S -> id = E

    E -> id

Syntax directed definition for given grammar to produce the three address codes is:

Production

Sematic Rules

S → id = E

S.place = newtemp();

S.code = E.code || gen (id.place ‘=’ E.place);

E → id

E .place = id.entry

E.code = null