Skip to content
Elvis Stansvik edited this page May 9, 2014 · 29 revisions

Extensions

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.

Compiler Phases

Lexical Analysis

Handled by SableCC generated lexer.

Parsing

Handled by SableCC generated parser.

Semantic Analysis

Building Symbol Tables

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

Type checking is handled by the TypeChecker class, which takes the AST and symbol table as input and performs the following checks.

  1. Undeclared identifiers.
  2. Class names where variable names are expected.
  3. Assignment (=) type compatibility.
  4. Operand (<, <=, >, >=, ==, !=, +, -, *, ||, &&, !) type compatibility
  5. Array assignment type compatibility, including index type (must be int).
  6. Type of subscript expression in array creation should be int.
  7. Method invocations: Type of actual parameters must match formal parameters.
  8. Method declarations: Returned type must match declared type.
  9. Condition type in while/if/if-else statements should be boolean.
  10. Println only works on integers.
  11. .length only works on array types.
  12. More?
Other Checks
  1. Integer constant sizes.
  2. More?

Code Generation

  1. Visitor class CodeGenerator which outputs Jasmin assembly code files.

Testing

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.