.settings | ||
HW0 | ||
javali_tests | ||
src/cd | ||
test/cd/test | ||
.classpath | ||
.gitignore | ||
.project | ||
build.xml | ||
Grade.txt | ||
README.md | ||
SemanticChecks.md | ||
TODO.md |
Compiler design
Parser and syntactic analysis
See repo containing Homework #2.
Semantic analysis
This project checks a list class declaration as trees of Ast nodes for possible semantic errors.
Design
The semantic checks described here are implemented in three phases.
- Circular inheritance check (just with the names, and checking for non-existent
types) to avoid stack overflow problems in the main analysis. May throw a
NO_SUCH_TYPE
error if the parent of a given class doesn't exist. - Main semantic analysis, performed by
StmtAnalyzer
andExprAnalyzer
, two visitors that traverse eachClassDecl
and all of its contents looking for semantic errors. Some types and methods may not have been discovered when they are accessed, and to that end the functionsfindType(String)
andfindMethod(String,ClassSymbol)
lookup both, searching unvisited class and method declarations in order to find the corresponding symbol. - Lookup of start point (method
void main()
inMain
class)
Testing
A set of test cases (Javali programs, valid and invalid) are provided. The ones
designed specifically for this homework assignment are located in
javali_tests/HW3_nop90
, and they cover all the code in the cd.frontend.semantic
and cd.ir
packages. They cover all the kinds of errors that can arise
from a semantic analysis of Javali programs. As the order of the errors
is not determined, each test case only checks one failing condition, and
therefore many more test cases are needed for this homework than for
previous ones.
The test files are organized in folders, with names ending in Tests or Errors, the latter only contain test cases that result in semantic errors.
To run the tests that exist in the javali_tests
folder you can simply run
$ ant clean clean-test compile test
Development environment
This project is designed for Eclipse and GNU/Linux, but it can be run
in other environments, as long as they have a 32bit IA 86x assembly
compiler
and a JVM
. Check the Config
class for more information.
Documentation
Available as javadoc. It is generated running the following command:
$ ant clean-doc generate-doc
Important files
TODO.md
: contains tasks to completeSemanticChecks.md
: contains the semantic checks numbered for quick reference- Javali Grammar
- HW3 statement