55 lines
2.7 KiB
Markdown
55 lines
2.7 KiB
Markdown
|
# Compiler design
|
||
|
## Parser and syntactic analysis
|
||
|
See repo containing [Homework #2](https://svn.inf.ethz.ch/svn/trg/cd_students/ss18/teams/nop90/HW2).
|
||
|
|
||
|
## Semantic analysis
|
||
|
This project checks a list class declaration as trees of Ast nodes for
|
||
|
possible semantic errors.
|
||
|
|
||
|
### Design
|
||
|
The semantic checks described [here](./SemanticChecks.md) are implemented in three
|
||
|
phases.
|
||
|
|
||
|
1. 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.
|
||
|
2. Main semantic analysis, performed by `StmtAnalyzer` and `ExprAnalyzer`,
|
||
|
two visitors that traverse each `ClassDecl` 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 functions `findType(String)`
|
||
|
and `findMethod(String,ClassSymbol)` lookup both, searching unvisited class
|
||
|
and method declarations in order to find the corresponding symbol.
|
||
|
3. Lookup of start point (method `void main()` in `Main` 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](javadoc/index.html). It is generated running the following command:
|
||
|
|
||
|
$ ant clean-doc generate-doc
|
||
|
|
||
|
### Important files
|
||
|
* `TODO.md`: contains tasks to complete
|
||
|
* `SemanticChecks.md`: contains the semantic checks numbered for quick reference
|
||
|
* [Javali Grammar](https://www.ethz.ch/content/dam/ethz/special-interest/infk/inst-cs/lst-dam/documents/Education/Classes/Spring2018/210_Compiler_Design/Homework/javali.pdf)
|
||
|
* [HW3 statement](https://www.ethz.ch/content/dam/ethz/special-interest/infk/inst-cs/lst-dam/documents/Education/Classes/Spring2018/210_Compiler_Design/Homework/hw3.pdf)
|