Current students

COMP207P - Compilers

This database contains 2016-17 versions of the syllabuses. For current versions please see here.

Code COMP207P
Year 2
Term 2
Taught By Earl Barr / Yue Jia
Aims This is a practical course whose primary goal is develop an understanding of the operation of compilers and the development and specification of computer-based languages. The course pulls together threads from underlying theory, most notably from logic and from data structures and algorithms, and builds on these a practical exercise in which students create a compiler of their own using commonly available compiler development tools.
Learning Outcomes To be able to: build lexical analysers and use them in the construction of parsers; express the grammar of a programming language; build syntax analysers and use them in the construction of parsers; perform the operations of semantic analysis; build a code generator; discuss the merits of different optimisation schemes.


Anatomy of a compiler
The importance of compilers
Structure of a compiler
Analysis (lexical, syntax and semantic analysis)
Synthesis (intermediate code generation, optimisation and code generation)
Compilers vs. interpreters

Lexical analysis (scanning)
Regular expressions
Finite state automata (deterministic and non-deterministic)
Translating regular expressions into finite state automata
Automatic lexer generators (JLex/JFlex)

Syntax analysis (parsing)
Context-free grammars
Derivations and (concrete/abstract) syntax trees
Handling ambiguous grammars
Top-down parsing (LL(k) grammars, recursive descent parsers)
Bottom-up parsing (LR(k) grammars, shift-reduce parsers)
Automatic parser generators (CUP)
Syntactic error recovery

Syntax-directed translation
Syntax-directed definitions
Abstract syntax tree construction

Semantic analysis
Symbol table management
Scoping and type checking
Basic implementation techniques (Visitor methodology)

Intermediate code generation
Three address code
IR instructions
Translation methodologies

Code generation and optimisation
Run-time storage organisation
A simple code generation algorithm
Optimisation of intermediate code
Optimisation of target code (Peephole optimisation)

Method of Instruction:

Lecture presentations, problem classes, lab classes.


The course has the following assessment components:

  • Written Examination (2.5 hours, 80%);
  • Coursework Section (20%).

To pass this course, students must:

  • Obtain an overall pass mark of 40% for all components combined;
  • Obtain a minimum mark of 30% in each component worth ≥ 30% of the module as a whole.




'Compilers - Principles, Techniques, and Tools' by A.V. Aho, R. Sethi and J.D. Ullman. Addison-Wesley.

'Modern Compiler Implementation in Java' by A.W. Appel. Cambridge University Press.

'Modern Compiler Design' by D. Grune, H.E. Bal, C.J.H. Jacobs, K.G. Langendoen. Wiley.

JLex: A Lexical Analyzer Generator for Java(TM)

JFlex - The Fast Scanner Generator for Java

CUP Parser Generator for Java

Course Homepage (accessible via IS login/password)