Toy Language '07 Compiler

The TL07 language is based on a very small subset of the Pascal language. It provides a good basis for a simple compiler. The main components of the compiler are:

Here is a really simple TL07 program that reads a number and prints double that number.

TL07 Source program:
PROGRAM simple
    VAR x AS INT ;
BEGIN
    x := READINT ;
    WRITEINT 2 * x ;
END
=>
=>
Syntax Tree (click to expand):
=>
Semantic Tree (green means Integer):
=>
=>
Internal Representation:
=>
General MIPS Assembly Code:
    .data
r1: .word 0
r2: .word 0
r3: .word 0
r4: .word 0
x:  .word 0

    .text
block1:
    li $v0, 5            # READINT
    syscall              # code 5 = read_int
    sw $v0, r1
    lw $a0, r1           # store x
    sw $a0, x
    li $a0, 2            # 2
    sw $a0, r2
    lw $a0, x            # load x
    sw $a0, r3
    lw $a0, r2           # 2 * x
    lw $a1, r3
    mul $a2, $a0, $a1
    sw $a2, r4
    li $v0, 1            # WRITEINT
    lw $a0, r4
    syscall              # code 1 = print_int

    li $v0, 10           # System code for exit
    syscall              #

Here is a robust TL07 program to calculate E = 2.71828+ to 500 digits: e.tl07
And here is the generated MIPS code for it: e.s and it's output: e.out

Compiler.java -- Main
TL07Compiler.java
TL07Parser.java
TL07Scanner.java
TL07Symbol.java
TL07SymbolTable.java

ParseAssignment.java
ParseDeclarations.java
ParseElseClause.java
ParseException.java
ParseExpression.java
ParseExprItem.java
ParseFactor.java
ParseIfStatement.java
ParseItem.java
ParseLiteral.java
ParseMemCell.java
ParseProgram.java
ParseSimpleExpression.java
ParseStatement.java
ParseStatementSequence.java
ParseTerm.java
ParseType.java
ParseWhileStatement.java
ParseWriteInt.java

SyntaxAssignment.java
SyntaxDeclaration.java
SyntaxError.java
SyntaxExpression.java
SyntaxIfElse.java
SyntaxItem.java
SyntaxProgram.java
SyntaxStatement.java
SyntaxTypeChecker.java
SyntaxWhile.java
SyntaxWriteInt.java

IntInstruction.java
IntRepAssignment.java
IntRepExpression.java
IntRepIfElse.java
IntRepresentation.java
IntRepWhile.java
IntRepWriteInt.java

CodeGenerator.java

Email: steve@oharasteve.com