CMSC 435: Assignment 8
Overview
Create a symbol table class and use it to process declaration and
“use” nodes in the AST. The declaration nodes are
VarDeclNode, FunDeclNode, and
ParamDeclNode. There are two “use” nodes, which I will
leave for you to determine.
Use SymbolTableVisitor.hh as a
basis for your symbol table visitor, that will use the visitor design
pattern to walk the AST and pair uses with declarations. If necessary,
modify the appropriate AST node definitions in Ast.hh for
this purpose.
Output errors for undeclared variables and multiply-declared variables, including location information.
Input Specification
Take the name of a C- program as a command-line argument. If no
argument is specified read from standard input (this is NECESSARY for
the grading scripts). Use .cm as the extension for C-
source files. You may add zero or more optional flags.
> ./CMinus [ --flags ]* [ <Program.cm> ]
Output Specification
Output “Valid!” if the program is a valid sentence in C- AND it is has no symbol errors. Output the AST to a text file if and only if there are no errors.
If a program is syntactically valid, create a symbol table visitor
(class SymbolTableVisitor) to pair use nodes with
declaration nodes. Report any undeclared variables with “Undeclared
variable ‘var’”, and multiply declared variables with “Redeclaration of
variable ‘var’”. Include location information.
Use PRECISELY the format below with the EXACT same SPACING and SPELLING.
> ./CMinus SymbolTableUndeclaredVar.cm
Compilation Error
Semantic Error [Line 7, Col 3]
Undeclared variable 'y'
> ./CMinus SymbolTableRedeclaredVar.cm
Compilation Error
Semantic Error [Line 7, Col 7]
Redeclaration of variable 'a'
For outputting the AST, use PRECISELY the format below with the EXACT same SPACING and SPELLING.
See InsertionSortTypes.ast. The tree therein corresponds to the program InsertionSort.cm.
Logistics
You may work with a partner. Only ONE team member should submit. Ensure each team member’s name is listed in all submitted files.
Submission
Submit ALL necessary source files and a Makefile. ENSURE
your Makefile is named Makefile, properly builds your
program, and that make clean removes all generated
files.
ALSO, submit a text file Team.txt listing your team
members (even if you’re the only member), each members contributions,
what functionality works, what doesn’t, and the areas with which you
struggled.
Hints
Ensure you insert the I/O functions input and
output into the symbol table.
Gary M. Zoppetti, Ph.D.