-
Notifications
You must be signed in to change notification settings - Fork 0
Semantic Analyzer
Like the implementation of the parser, we tried to follow as often as possible the prototype approach of the compiler design course. Unfortunately, this not as frequently as in the parser possible. In the next sections, we describe the important modules and after that, a short outline of the use of the semantic analyzer.
There are just a few important classes, whose are quickly described:
- swp_compiler_ss13.javabite.semantic.SemanticAnalyzerJb simply checks for simple division by zero and uses the ASTTypeChecker ( described below) to guarantee type-correctness.
- swp_compiler_ss13.javabite.semantic.ASTTypeChecker is a very simple S-Attributed check. Implemented by traversing and caching.
The best-practice approach would be to create a L-Attributed grammar to check e.g. for invalid break-statement positions. We decided to try it with a less complex approach, since the only semantic errors which cannot be checked by a S-Attributed grammar is the positioning of return and break statements. The implementation is currently under heavy development. We want to take a look at the control flow where it is possible. For example, if a statement exists (unconditional) after a return statement, it's placement is invalid. We try to check this invariant for the whole tree.
A typical application can be drafted as follows:
- Create a SemanticAnalyzer
- analyze the ast of interest with it
- interpret the results and errors thrown by the reportErrorLog.