CSCI 435: Compiler Construction
Assignment 11

Overview

Create a "SemanticAnalysisVisitor" class that makes one more pass over the AST to detect a larger set of semantic errors.

Detect and report the following errors, including location information.

  1. Subscripting non-arrays.
  2. Operators being applied to non-integer types.
  3. Assigning to array or function names.
  4. Calling non-functions.
  5. Types of arguments and parameters not being compatible.
  6. Too few or too many function arguments.
  7. Returning a value from a void function.
  8. Not returning a value from a non-void function.
  9. Declaring variables or parameters as void.
  10. Not declaring "main" last.

What to Submit

Submit a Makefile and all files needed to build your compiler. Also include a text file (".txt" extension) listing your team members, their contributions, what functionality works, what doesn't, and the areas with which you struggled.

Input Specification

Take the name of a C- program as a command-line argument. If no argument is specified read from standard input. Use ".cm" as the extension for C- source files.

Output Specification

Output errors as in the previous assignment. If a program is syntactically valid, create a symbol table visitor to pair use nodes with declaration nodes. Report any undeclared or multiply-declared variables, along with location information.

If no errors have been detected, perform a semantic analysis pass with your "SemanticAnalysisVisitor". If there are no errors, print the AST as before, but now annotated with type information.

Submission

Submit a Makefile and all files needed to build your compiler ("CMinus"). Also include a text file "Team.txt" listing your team members, their contributions, what functionality works, what doesn't, and the areas with which you struggled.

Hints

You may want to add a dataType field to certain nodes in your AST. You may also want to add enumerators to enum ValueType such as INT_FUNCTION and VOID_FUNCTION.


Gary M. Zoppetti, Ph.D.