UMBC CMSC431, Compiler Design Principles, Fall 2009


Project 5

Due: Monday, November 9, 2009, 12:00pm (noon)


Objective

In this project students will add procedures and local variables to their programming language. Here a "procedure" is a function without a return value.


Assignment

The assignment for this project is a small departure from the plan outlined in the course description. Originally, local variables was to be assigned in Project 6 rather than Project 5. However, you will need a separate symbol table for each function just to have formal parameters, so you might as well implement local variables at the same time.

Add the following features to your programming language:

  1. Definition of procedures with formal parameters passed by value. The type of each formal parameter can be boolean, integer or floating point.
  2. Return statements.
  3. Procedure invocation with expressions as actual parameters. For this project, you do not have to check that the procedure is invoked with the right number of parameters and that each parameter has the right type. (That will be in Project 6). However, you must allow recursive procedure calls.
  4. Local variables: a local variable is allowed to have the same name as a global variable. The usual lexical scoping rules apply.
Note: your parameter passing scheme must follow the C Function Call Convention (see description). The code for procedures and functions you compile must be compatible and interoperable with the code generated by GNU's gcc.


Implementation Notes


Testing

Translate each of the following C programs to your programming language and check that they work. You must include translated versions of these programs in your submission. (Note: project grading will also use additional programs, so you should also make your own test programs to check the behavior of your compiler.)

  1. p5test1.c checks that basic parameter passing works and the lexical scoping rules are followed.

  2. p5test2.c checks that procedures can have lots of parameters and that sequences of calls are handled properly.

  3. p5test3.c checks that recursive procedures are handled properly.


Submitting Your Project

We will use a new repository for Project 5. You should first use CVS to check-out Project 5. cvs -d /afs/umbc.edu/users/c/h/chang/pub/cs431f09/Proj5 checkout -d MyProj5 user1 Copies of p5test1.c, p5test2.c and p5test3.c will be downloaded in the 'MyProj5' directory (or whatever name you chose).

Use cvs add and cvs commit to check-in any files that you have copied over from Project 4 (and any other files that you want to submit).


Last Modified: 10 Nov 2009 02:11:40 EST by Richard Chang
to Fall 2009 CMSC 431 Homepage