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.
- Print your syntax tree if
-tree is given
- If
-symtab is given, print your symbol tables in a human readable
format
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
- your executable must be named k0
- your makefile must compile all your .c files using the -Wall option,
and produce .o files for them.
- your makefile must have a separate link step that builds the k0
executable from .o files only (no .c files in the link)
-
your program should accept and process an arbitrary
number of source filenames on the command line
- write out the name of the file to standard out when you open it
- DO NOT write out the tree, or other debugging information, by default;
you may add command line options to print that info if you want.
- error messages should be written to standard error
(
stderr) not stdout
- if ANY file has a lexical error,
your process exit status should return 1,
for a syntax error 2, for a semantic error 3, and for no errors,
return 0.