CS 3723 Programming Languages -- Spring 2000
Project Overview
The main work for the semester is a continuing project,
working on a small compiler for a simple (very small) subset of C/C++,
mostly contained in Java also.
Languages to Use:
There are three languages at issue here, and the situation can
be confusing. The implementation language is the programming
language you use to write the project. The source language
is the language to be translated by the compiler, and the target
laguage is the language into which your compiler is translating
the source.
For this course the implementation language can
be either C, C++, or Java. (Or even C with C++ features like I/O.)
I assume that most of you will use C. You should pick a language
you are reasonably well familiar with.
As mentioned above, the target language will be a subset C or C++.
We will start just with simple arithmetic expressions and assignments,
and then add features. There is no requirement that we implement the
semantics (= meaning) of C++, even if we have some of C++'s
syntax (= appearance).
The initial target language will be an intermediate language known as
quadruples, named this because each machine instruction
has 4 parts: the operator, up to two operands, and one result.
This is an intermediate language in the same sense that Java
byte code is also one, those these two intermediate languages
are only similar in that they both are halfway to machine code.
See Quadruple Machine for a formal
description of quadruples.
The final target language will be MIPS assembly code. We will
either rewrite the compiler to target MIPS directly or will write
a translator from quadruples to MIPS. (One can also write software
that will directly execute the quadruples -- this is similar to
the way the Java virtual machine directly executes Java byte code.)
Details about Assignments:
-
0. Quadruple Translator/Interpreter
Two programs, one to translate quads and one to interpret them.
Half the class will write a program to translate a simple subset
of quadruples to Java or C, and half will write a quadruple
interpreter for the subset.
-
I. Initial Scanner
A scanner or tokenizer for the language of the course project.
This program will convert the sequence of source characters
to a sequence of tokens, where tokens are the basic
building blocks of a language. Typical tokens include
keywords, identifiers, constants (integer, double, character,
string, boolean), special symbols (operators and other language
elements).
-
II. Initial Parser
A parser for the language of the course project.
The parser unravels the syntax of the language in a way
that allows for analysis and translation. Compared with a
scanner, the parser is quite a bit more sophisticated.
We will be writing a recursive-descent parser (the simplest
type of parser).
-
III. Translate Arithmetic Expressions to Quadruples
Initial translation of arithmetics expressions to the quadruple
intermediate language.
Initially, our translator will work with a sequence of simple
assignment statements involving variables and constants.
These will be translated to an equivalent sequence of
quadruples, though a given source statement may be translated
into many quadruples.
-
IV. Translate Control Structures
Extending the project to handle simple control structures, using
a goto quadruple.
For this part we will add the control structures of
if-then, if-then-else and while, each implemented using
goto (or jump) quadruples.
-
V. Translate Functions and Parameters
Extending the project to handle functions and parameters, as
well as local variables.
For this part we will translate simple functions with
parameters.
-
VI. Final project: Target MIPS Assembly Language
Extending the project by writing a translator from quadruples
to MIPS assembly language.
The final targetting of MIPS can also be accomplished by
writing a quadruple interpreter, as in the first homework
project.
Revision Date: 12/28/99