Last update: Mon Mar 27 2017 by

COMP 520 - Compilers

Spring 2017
(Thu Jan 12 - Thu Apr 27)
TTh 3:30 - 4:45 PM, FB 009

Instructor: Jan Prins
FB 334, Tel: 919-590-6213,
Office hours: Mon 12:30 - 2 PM and by appointment

TA: Shiwei Fang
SN 350,
Office hours: Tue 1:30 - 3:20 PM and by appointment


This is an upper-level undergraduate course (also open to graduate students) covering several areas of program translation, including compilation, interpretation, run-time organization, linking, and loading. Upon completion of the course, you should:


Data Structures (COMP 410), Computer Organization (COMP 411), Automata Theory (COMP 455), and experience with Java programming. A course in programming language concepts (COMP 524) is helpful but not required.


Programming Language Processors in Java: Compilers and Interpreters, by David Watt and Deryck Brown, Prentice Hall, 2000 (ISBN 0-130-25786-9).

Course Syllabus

Administrative details, organization and a list of topics for the course can be found in the syllabus

@ Announcements

@ Reading Assignments

@ Lecture Notes

@ Written Assignments

@ Programming Assignments

@ Examples

  1. Scanner and parser example to recognize simple arithmetic expressions following the package structure used in the Triangle compiler as needed for the miniJava compiler project. You can use this example as a starting point for your miniJava compiler, if you wish.

    The main class Recognizer parses an input expression entered from the keyboard terminated by carriage return (enter). Note that your compiler needs to read the input from a file (with name specified in args[0]) rather than from the keyboard. On termination it sets the System.exit() code as specified in the PA1 requirement: return code 0 for a valid input and return code 4 for an invalid input.

    To import into Eclipse, create a Java project (say simpleScannerParser) and import into the project from General / Archive File the file (if your project has separate src and bin folders, you need to import into the src subdirectory).

    • the top level package is miniArith containing the Recognizer mainclass and the ErrorReporter class.
      • The subpackage miniArith.SyntacticAnalyzer contains the Scanner Parser, Token classes and the TokenKind enumeration.

  2. [NEW] AST construction and traversal example using a stratified grammar to parse a simple arithmetic expression while building an AST reflecting associativity and precedence of addition and multiplication as well as parenthesization.

    The scanner and parser are in the SyntacticAnalysis subpackage and use AST classes provided in the AbstractSyntaxTrees subpackage to construct the AST during parsing. Two traversals of the AST are implemented as visitors in the TraverseAST subpackage: DisplayAST constructs an explicitly parenthesized text representation of the AST and EvalAST evaluates an AST. The top level package is miniArith with main class Evaluator. It uses the scanner and parser to parse an arithmetic expression entered as input from the keyboard and to construct an AST. The two visitors are used to show the AST in linear form and to show its value.

    To import this example into Eclipse, create a new Java project (say simpleAST) and import into this project using the selection General / Archive File the file (if your project has separate src and bin folders, you need to import into the src subdirectory).

@ Reference Section


[Course text] Watt & Brown, Programming Language Processors in Java

Java Reference

Additional references

MiniJava Project tester

Triangle compiler

This page is maintained by Send mail if you find problems.