Compiler Construction

A course at Oxford Brookes University, February 2018
H. Mössenböck


  • acquire the practical skills to write a simple compiler for an imperative programming language.
  • understand the concepts of scanning, parsing, name management in nested scopes, and code generation.
  • understand attributed grammars and their use for specifying languages and their translation
  • learn to transfer these skills also to general software engineering tasks (e.g. parsing of structured data files or argument lists)
  • learn how to use a compiler generator


The course goes through all phases of a compiler. It shows the theoretical concepts underlying each phase as well as how to implement them efficiently. The students will write a small compiler for a Java-like language. It will translate a source program into the code of virtual machine. The implementation language will be Java.

  • Overview: compilers and interpreters, structure of a compiler, single-pass vs. multi-pass compilers
  • Scanning: finite automata, scanner implementation
  • Parsing: recursive descent parsing, push down automata, terminal start symbols and successors, LL(1) conditions, implementation of a parser
  • Semantic analysis: syntax-directed translation, attributed grammars
  • Symbol table handling: objects, types, scopes
  • Code generation
  • Compiler generators


MicroJava Quick Reference


1. Overview
2. Scanning
3. Parsing
4. Semantic Processing
5. Symbol Table Handling
6. Code Generation
7. Building Compilers with Coco/R


JDK: Java Development Kit from Oracle

The following code templates are necessary for doing the lab described in the handouts.

Level 1: Scanning (skeleton file)
sample.mj: sample MicroJava program
Eratos.mj: sample MicroJava program
BuggyScannerInput.mj: buggy MicroJava program to be tested with TestScanner

Level 1: Parsing (skeleton file)
BuggyParserInput.mj: buggy MicroJava program to be tested with TestParser

Level 2: Symbol table handling (skeleton file)

Level 3: Code generation (skeleton file)
BuggySemanticInput.mj: buggy MicroJava program revealing semantic errors

Level 4: Compiler Generator Coco/R
Coco/R (download and documentation)
QueryForm example from the slides

Text Book

The text book N.Wirth: Compiler Construction. Addison-Wesley 1996 comes close to the contents of this course. Unfortunately, it is out of print, but it can be downloaded from here.