Lab homework assignments from a class on Compiler Design from the ETHz (spring 2018)
Find a file
Carlos Galindo 0afc86ceeb
Homework 3
2020-01-15 22:32:25 +01:00
.settings Homework 3 2020-01-15 22:32:25 +01:00
HW0 Homework 0 2020-01-15 22:17:50 +01:00
javali_tests Homework 3 2020-01-15 22:32:25 +01:00
src/cd Homework 3 2020-01-15 22:32:25 +01:00
test/cd/test Homework 3 2020-01-15 22:32:25 +01:00
.classpath Homework 3 2020-01-15 22:32:25 +01:00
.gitignore Homework 1 2020-01-15 22:29:20 +01:00
.project Homework 3 2020-01-15 22:32:25 +01:00
build.xml Homework 3 2020-01-15 22:32:25 +01:00
Grade.txt Homework 3 2020-01-15 22:32:25 +01:00
README.md Homework 3 2020-01-15 22:32:25 +01:00
SemanticChecks.md Homework 3 2020-01-15 22:32:25 +01:00
TODO.md Homework 3 2020-01-15 22:32:25 +01:00

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.

  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. 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
  • HW3 statement