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:
Understand the theory and practice of compilers, interpreters,
assemblers, linkers, and loaders, and be able to work effectively with
such programs.
Be able to design and implement parsers and language translators
for simple languages.
Appreciate the effects of decisions in programming language and
computer architecture design on the translation process and run-time
systems.
Have experience with the design and implementation of large and complex
programs using Java.
Retain knowledge of compilation and interpretation techniques
in preparation for advanced courses in compilers and/or comprehensive
computer science studies.
Prerequisites
Data Structures (COMP 410), Computer Organization (COMP 411), and
experience with Java programming. Courses in programming language
concepts (COMP 524) and Automata Theory (COMP 455) are 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 overview
Administrative details, organization and a syllabus for the course
can be found in the
course information handout.
(for Thu Jan 17) PLPJ
Skim Chapter 3 - Organization of Compilers and Compilation (pp 55 - 70).
We will come back to Chapter 2 later.
Start reading Chapter 4 - Grammars, Secns 4.1 - 4.2 (pp 73 - 83)
A very simple expression parser
with single character terminals, parsing expressions over +, * and
integer literals 0-9.
An improved
expression parser with scanner that illustrates the
Parser, Scanner, and Token classes. By including a scanner,
we can now parse expressions with multidigit numbers and
white space e.g. "12 * 7 - 83".
The MIPS instruction set is summarized in section A.10 from
Appendix A
of Hennessy and Patterson,
Computer Organization and Design: The Hardware/Software Interface.
Each checkpoint in the compiler project will be evaluated by a series of tests.
You can run the tests from past checkpoints in Eclipse to check that
you have fixed errors. Note that earlier tests may not be valid later in the
project.
Instructions to install the tester
Create a new package called tester within your
miniJava project. So the tester package sits next to your
miniJava package, and not in your miniJava package.
Create a new project (so not a Java project) called tests
in your Eclipse workspace (so tests and your miniJava project are completely
separate projects).
Instructions to use the tester
Import or copy a checkpoint tester, e.g. Checkpoint1.java,
into the tester package.
Import the matching folder of tests, e.g. pa1_tests,
into the the tests project.
Run the tests, e.g. run Checkpoint1. It will apply all tests
and show you a report of their outcome.
Triangle compiler
Instructions for installing and running the Triangle compiler tools in Linux.
Make sure you have a working java runtime and compiler with the following
commands: which java -- this should be /usr/bin/java java -version -- this should be 1.7 currently javac -version -- this should be 1.7 currently
If you encounter problems check that /usr/bin is on your PATH.
Install the TriangleTools directory: curl "http://www.cs.unc.edu/~prins/Classes/520/Examples/TriangleTools.tgz" | tar -xz
Change into the TriangleTools directory and compile the Triangle language tools: cd TriangleTools javac Triangle/Compiler.java javac TAM/Interpreter.java javac TAM/Disassember.java
Run the Triangle compiler on a sample input program p1.tri: java Triangle/Compiler p1.tri
Run the interpreter on the object code generated in file obj.tam: java TAM/Interpreter obj.tam
Run the disassembler on the object code generated in file obj.tam: java TAM/Disassembler obj.tam
Instructions for installing and running the Triangle compiler using Eclipse
In Eclipse, select the Java perspective and create a new Java project TriangleTools
(File/New/Java Project, enter "TriangleTools" in the Project Name,
important: choose "Use project folder as root for sources and class files" and select "Finish").
Import the jar file TriangleTools.jar into the project
(File/Import/General/Archive, browse to the jar file, verify the project it will be imported into is
"TriangleTools", and select "Finish").
Create run configurations in the project for the three Java Applications: Triangle.Compiler,
TAM.Interpreter, and TAM.Disassembler (Run/Run Configurations ... then create three new instances
of a run configuration for a Java Application, each with the appropriate main.
Edit the run configuration for the Triangle compiler to include argument "p1.tri").
Run the configurations in order: compiler, interpreter, and disassembler.
This page is maintained by
prins@cs.unc.edu.
Send mail if you find problems.