-
Notifications
You must be signed in to change notification settings - Fork 2
Planning Document
Elvis Stansvik edited this page May 9, 2014
·
29 revisions
We have decided to implement the following compiler extensions:
Code | Description |
---|---|
JVM | JVM backend (using the jasmin "assembler") (30 p) |
IWE | 'if' statements with or without 'else' (15 p) |
NBD | nested blocks with new variable declarations (20 p) |
ABC | array bounds checks (0 p) |
CLE CGT CGE CEQ CNE | comparison operators (5 p) |
BDJ | logical OR connective (2 p) |
Which gives us 100 + 30 + 15 + 20 + 0 + 5 + 2 = 172 p.
Handled by SableCC generated lexer.
Handled by SableCC generated parser.
This is handled by the SymbolTableBuilder
class. The symbol table itself is represented by SymbolTable
, ClassInfo
, MethodInfo
and VariableInfo
, and the type classes Type
, BuiltInType
, ClassType
, UndefinedType
and UnsupportedType
.
Type checking is handled by the TypeChecker
class, which takes the AST and symbol table as input and performs the following checks.
- Undeclared identifiers.
- Class names where variable names are expected.
- Assignment (=) type compatibility.
- Operand (<, <=, >, >=, ==, !=, +, -, *, ||, &&, !) type compatibility
- Array assignment type compatibility, including index type (must be int).
- Type of subscript expression in array creation should be int.
- Method invocations: Type of actual parameters must match formal parameters.
- Method declarations: Returned type must match declared type.
- Condition type in while/if/if-else statements should be boolean.
- Println only works on integers.
- .length only works on array types.
- More?
- Integer constant sizes.
- More?
- Visitor class
CodeGenerator
which outputs Jasmin assembly code files.
This is an ongoing effort throughout the project. We already have unit tests for the lexer, parser, symbol table builder and type checker. The tests uses various input files from src/test/resources
.