SOLVED:CSC 446 ASSIGN #7

$55.00

Original Work ?
Category: You will Instantly receive a download link for .ZIP solution file upon Payment

Description

5/5 - (3 votes)

Add the appropriate actions to your parser to translate a source program into Three Address Code.  For all variables declared at a depth of 1 use the actual variable name in the three address statement.  For variables declared at depths higher than 1 you must use offset notation.

 

Variables at depths greater than 1 will have offsets starting at 0 and increasing based on the size of the variable.

 

  1. int num, sum;

float ave, limit;

 

num       offset = 0             sum        offset = 2

ave         offset = 4             limit      offset = 8

 

In three address code the variable limit would be referred to as _BP-8, however you may start your offsets at 2 as discussed in class if you like.

 

Parameters to functions will be referred to using positive offsets, for example:

 

int function ( int num1, int num2)

 

num1 would have offset 4 and num2 would have offset 6 and num1 would be referred to by _BP+4 as discussed in class.  Remember the C style pushes parameters from right to left.

 

Add the action to your program that will print an error message if there is not a function named main.

 

Use the same name for the three address code file as the program’s name only change the extension to .tac.  For example if the input file is test.c the TAC file would have the name test.tac.

 

You will need to add the following productions to your parser:

 

AssignStat                          ->           idt = Expr |

idt = FuncCall

 

FunctionCall                      ->           idt ( Params )

 

Params                               ->           idt ParamsTail |

num ParamsTail |

e

 

ParamsTail                         ->           , idt ParamsTail |

, num ParamsTail |

e

Ret_Stat                             ->           returnt Expr ;

 

The statement:

 

num = Func(x,y);

 

Will result in the Three Address Statements:

 

push y

push x

call func

num = _AX