UMBC CMSC431, Compiler Design Principles, Fall 2009
Due: Monday, November 9, 2009, 12:00pm (noon)
In this project students will add procedures and local variables to
their programming language. Here a "procedure" is a function without
a return value.
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:
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
- Definition of procedures with formal parameters passed by value. The
type of each formal parameter can be boolean, integer or floating point.
- Return statements.
- 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
- Local variables: a local variable is allowed to have the same name as
a global variable. The usual lexical scoping rules apply.
- You will need a separate symbol table for each function. If you
hard-coded a single symbol table in your project previously, you need to
fix this first.
- The name of a procedure should go in the global symbol table. You will
need to make up a procedure type to distinguish procedures from variables.
- Each time that a name is used in an expression, your compiler
has to figure out if that name is a local variable, a formal
parameter, or a global variable. Each of these three have a different
- Keep in mind that in Project 6 you will add functions to your
programming language. The difficulty with a function isn't that it
has a return value. The hard part is that when a function is
invoked, an actual parameter might be the return value of another
function call. Thus, your compiler can be in the middle of several
function calls. If you make good design choices for this project,
then the next project is fairly straightforward. OTOH, if you make
poor design choices, then function calls will be difficult to
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.)
- p5test1.c checks that basic parameter
passing works and the lexical scoping rules are followed.
- p5test2.c checks that procedures
can have lots of parameters and that sequences of calls are
- 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).
10 Nov 2009 02:11:40 EST
to Fall 2009 CMSC 431 Homepage