All projects
Java

Java68 Compiler

A complete compiler for Java68, a small imperative language of our own design, that takes a program through every classic phase — lexical, syntax and semantic analysis, three-address code and optimization — down to Motorola 68000 assembly ready to run on a simulator.

View on GitHub
Compilers Language Design Java

Java68 Compiler

Final project for the Compilers course at the Universitat de les Illes Balears, made together with Marc Morlà. A complete compiler for Java68 — a small imperative language we designed ourselves — that translates source code all the way down to Motorola 68000 assembly, ready to assemble and run on the EASy68K simulator.

About

The compiler is a straight pipeline, and every phase is an independent traversal that writes its own artefact to disk, so a whole translation can be followed step by step:

  • Lexical analysis — a scanner generated with JFlex turns the source into a token stream.
  • Syntax analysis — a parser generated with Java CUP builds an explicit syntax tree.
  • Semantic analysis — a symbol table and full type checking over that tree.
  • Intermediate code — three-address code, the representation that makes optimization viable at all.
  • Optimization — a peephole pass that applies a set of rewrites and repeats the whole set until a full pass changes nothing.
  • Code generation — MC68000 assembly. Every block of assembly is annotated with the intermediate instruction it came from.

The Java68 language

Java68 is small but complete enough to write real programs. It has the usual primitive types, constants and multidimensional arrays; global variables and functions that declare their return type explicitly; conditionals and loops; arithmetic, comparison and logical operators; and built-in input and output.