A Compiler for Klein
Translation of Programming Languages
Fall Semester 2017
Your compiler will take as input programs written in Klein,
a language created for this course. Here is
the language specification
for Klein. Know it well!
a directory of Klein programs
that you can use to exercise the stages of your compiler. You
can also download
a compressed file
containing the same directory and programs.
(last update: 2017/12/14
-- added tests-pr07/)
- By convention, .kln is the standard
extension for Klein source files. Please follow this
standard, as it allows other tools to assume the
extension as a default.
- This set of files is not sufficient to test all of the
features of your compiler as you write it. It does not
contain all error cases, nor does it provide a systematic
coverage of Klein features.
- Without a Klein compiler to use as a reference, it is
possible that one or more of these programs contains
an error. As you study the Klein grammar early in the
project, use these programs to verify your understanding.
If you find a Klein program that seems to violate the
language specification, let me know immediately.
This will help us debug the grammar, the program, or your
I will add files to this set over time. Please send me any
interesting Klein programs that you write!
Your compiler will generate as output programs written in the
assembly language of TM, the Tiny Machine created by
the machine specification
for TM and its assembly language.
By convention, .tm is the standard extension
for TM source files.
You can download a software implementation of TM either as
a tarred, gzipped file
or as individual files from
(last update: 2015/11/18 -- fixed bug in simulator
The directory contains four C programs, which ar a sequence of
- a version essentially identical to the machine defined in
with a small change to eliminate a run-time warning.
- a version that takes command-line arguments.
- a version that executes the TM program immediately,
rather than interacting with the user through a menu.
This version of the simulator can be useful when we trust
that our compiler is correct and are most interested in
its performance (and in debugging Klein programs).
- a version that reports the number of clock ticks consumed
by program execution. This version of the simulator can
be useful in comparing implementations and optimizations.
It also contains two versions of a sample TM program from
You will build your compiler in phases. Links are added as
modules are assigned. (The dates are tentative. We may
modify them as we proceed through the semester.)
-- due Friday, September 15
parser, step 1
-- due Friday, September 29
parser, step 2
-- due Friday, October 13
-- due Friday, October 27
code generator, step 1
-- due Friday, November 10
code generator, step 2
-- due Friday, December 1
-- due Friday, December 8
Your six deliverables for the project will consist of
a single project directory
that you grow over the course of the semester.
Your compiler may contain only code written by you, by one
of your teammates, or by a program that you write. It should
contain no code written by any other person or generated by
any program that you did not write.
Based on the information you provided me, I have created the
following teams (old names):
The individuals marked by a * are the team captains.
- The Compiler Defilers:
Adams*, Hilliard, Varma (C++)
- The Dukes:
Holland*, Oswald, Sedlacek (Java)
- Lexically Challenged:
Menke*, Richmond, Rook (Cython and C++)
some management tips
that you can use to organize and run your project. Note that each
team is required to select a team leader, or captain,
who will serve as the primary contact for the team.
Eugene Wallingford .....
October 13, 2017