Last update: Tue May 14 2019 by prins@cs.unc.edu

COMP 520 - Compilers
http://www.cs.unc.edu/~prins/Classes/520/

next offering: Spring 2020
date/time: TBD

Instructor: Jan Prins
FB 334 prins@cs.unc.edu
Office Hours: TBD


Overview

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

Prerequisites

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.

Text

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 (2019), such as the exam dates, the honor code, and the sequence of topics covered in the course can be found in the course syllabus


@ Announcements


@ Reading Assignments


@ Lecture Notes


@ Written Assignments


@ Programming Assignments


@ Examples

Here are two examples implementing scanning/parsing and AST construction that correspond roughly to checkpoints PA1 and PA2 in our miniJava project. To install:
  1. Download the zip file
  2. in Eclipse: File / Import Existing Projects into Workspace / Next
  3. choose "Select Archive File" radio button, browse to zip file and Open / Finish
Scanner and Parser: download http://www.cs.unc.edu/~prins/Classes/520/Examples/simpleScannerParser.zip
Illustrates the package structure and classes for a scanner and parser (mostly following the text), and implements a scanner and parser that recognize (valid/invalid) simple arithmetic expressions using numbers, operators (+,-), and balanced parenthesization.

The top -level pacakage is miniArith contaning the Recognizer mainclass that parses input entered from the keyboard and judges whether it consitutes a valid arithmetic expression. The parse procedures corresponding to nonterminals in the grammar are traced to illustrate how the input was parsed.

The subpackage miniArith.SyntacticAnalyzer contains the Scanner, Parser, Token classes and the TokenKind enumeration.

You can use this example as a starting point for your miniJava compiler, if you wish.


AST construction and AST traversal: download http://www.cs.unc.edu/~prins/Classes/520/Examples/simpleAST.zip
Illustrates AST construction and traversal example using a stratified grammar to parse a simple arithmetic expression entered from the keyboard. It constructs an AST that reflects the associativity and precedence of addition and multiplication operations, and respects 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 display the AST in linear form and to compute its value.


@ Reference Section

MiniJava Project tester

Textbook

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

Java Reference

Additional references

Triangle compiler


This page is maintained by prins@cs.unc.edu. Send mail if you find problems.