CS712/CS812
Project Phase 2
Spring 2003
Due Sunday March 2


This phase concerns the compilation of C declarations. Your work will be done in the context of the CS712 compiler pcc3. The initial release of the pcc3 source files will be available in ~cs712/public/phase2 on Monday February 10.

At the 70% level, you should implement the function processDeclarator in the file decl2.c.

The function is given a base type and a linked list of declarator modifier nodes. It produces a modified type by applying the declarator type modifiers to the base type. It also sets three output parameters:

See the comments in decl2.c for more information.

When you are done processing a modifier, you should call deleteDeclNode to free the memory for the linked list node.

The function is used to handle variable declarations (the 85% level), struct/union declarations, function definitions, parameter declarations and type names (in casts and sizeof operations). Probably the easiest way to initially test is to compile struct declarations. But be sure to test your code in all contexts that the function is used.

Semantic error detection is a big part of this assignment. The pcc3 compiler implements the 1989 ANSI C standard (on reserve in the Kingsbury library). You should consult the standard to research what combination of types and modifiers are legal and illegal.

At the 85% level, you should also implement the functions processDeclaration, finishLocalDeclaration and finishGlobalDeclaration in the file decl2.c.

Together these functions implement local and global variable declarations.

The function processDeclaration is given a type "bucket" and a linked list of linked lists of declarator modifier nodes. First the base type and storage class are extracted from the type bucket. Then each declarator modifier list is traversed using processDeclarator to get the modified type and the identifier for each variable (or function or typedef) being declared. The processing of each variable (or function or typedef) declaration is "finished" by calling either finishTypedefDeclaration (if the storage class is typedef), finishGlobalDeclaration (if the current symbol table block number is zero), or finishLocalDeclaration.

When you are done processing a declarator, you should call deleteDeclarator to free the memory for the linked list node.

The function finishGlobalDeclaration finishes a global declaration by doing the appropriate semantic checks and by accessing the symbol table. Similarly, the function finishLocalDeclaration finishes a local declaration by doing the appropriate semantic checks and by accessing the symbol table. Note that a local declaration might in fact reference a global variable by use of the extern or static storage class.

The following code generation routines exist in encode.c for generating code for declarations:

You will also want to use these machine-specific routines (also in encode.c) when determining local variable stack frame offsets: You also need to update the global variable gCurrentFunctionOffset as you process the local variables.

At the 100% level, you should also implement enum declarations.

This include processing the enum tag, processing the enum constants and producing an enum type. However, an enum type can be converted to signed int when it is encountered as the base type passed to processDeclarator.

For the 70% and 85% levels, all your code should be placed in decl2.c. For the 100% level you will also need to edit parse.y. These are the only two files you should modify! If bugs are encountered in other files, then you should consult me.

Your code will be graded primarily by testing it for correct functionality. However, you may lose points if your program is not properly structured or adequately documented.

Your code will be graded using turing.unh.edu so be sure to test in that environment.

Your code should be submitted for grading from turing.unh.edu.

To turn in this assignment at the 70% or 85% levels, type:
~cs712/bin/submit phase2 decl2.c

To turn in this assignment at the 100% level, type:
~cs712/bin/submit phase2 decl2.c parse.y

Submissions can be checked by typing (also on turing.unh.edu):
~cs712/bin/scheck phase2

To receive full credit for the assignment, you must turn in your files prior to 8am on Monday March 3. Late submissions will be accepted at the penalty of 5 points per day up to one week late.

Remember: you are expected to do your own work on this assignment!


Last modified on February 7, 2003.

Comments and questions should be directed to hatcher@unh.edu