CSE 423 HW#4

Due: Sunday March 16, 11:59pm

Perform the first part of semantic analysis for your compiler. This consists of the following items. Please turnin an electronic copy of your whole project in a .zip file on Canvas. Please create your .zip file in such a way that it unpacks into the current directory, rather than a subdirectory.

Symbol tables
Build a symbol table data type that you can instantiate for each scope: one "global" scope, one scope per package/file and per class type for that type's members, and one scope per function for parameters and locals. You do not have to support nested local scopes. For each symbol, you should insert a symbol table entry, which is a struct consisting of enough information to support the semantic analysis. Typically this will include symbol name, reference to which scope (containing symbol table) the symbol is defined in, declared data type (required in the next homework), and any auxiliary flags, e.g. const. For full credit, implement a hash table; a binary tree would be a fine alternative (90% credit); a linked list would work but not be as good (80% credit).
Predefined symbol tables
In addition to the symbol tables for user code, we need to allow the little toy k0 programs to use predefined objects/classes mentioned in the k0 specification.
Variable declarations
Report errors for undeclared and redeclared variables.

Output

For this Assignment, you should implement the following command-line options. The symbol table output should look like:
--- symbol table for: package main ---
    x
    y
    f
---
--- symbol table for: func f ---
    a
    b
---
In the absence of the -symtab command line option, you should just print messages for any errors encountered, or "No errors". If any errors are encountered when invoked with -symtab, you do not have to print symbol tables.

Notes