Assignment 3: Conditionals: the Cond language
Overview
In this assignment, you will be extending the "Var" language compiler from the last assignment and adding the following features:
- conditionals (
if
statements) - boolean values (true or false, written as
#t
and#f
) - type checking (although you don't have to write the type checking code)
Textbook coverage
This assignment is based on chapter 4 of Essentials of Compilation.
Due date
This assignment is due on Friday, November 8th at 6 PM.
Starting code base
The starting code base is the zipfile ch4.zip
,
which is posted on the course Canvas site.
You should unzip this file in your Github repo,
inside the src/
directory.
It contains partial implementations of all the code for the assignment.
Inside the ch4
directory will be these familiar subdirectories:
-
The
tests/
subdirectory contains the test programs for the compiler. -
The
reference/
subdirectory contains the output from the instructor's version of the compiler. -
The
scripts/
subdirectory contains scripts for testing your code.
README
or README.md
file
Create a README
or README.md
file in your ch4
directory,
and in it, identify which person wrote which passes.
(If both partners worked on a pass, indicate that too.)
Also, if you used any late days on the assignment,
indicate how many late days you used.
New language features
The new language features are described in the textbook and the lectures, but in brief, they are:
- a
Boolean
type - boolean values: true (
#t
) and false (#f
) - relational operators (operators that return boolean values):
eq?
,<
,<=
,>
, and>=
-
new expressions:
and
(boolean AND)or
(boolean OR)if
(conditionals)
In addition, there is a boolean not
operator,
the relational operators <
, <=
, >
, and >=
which all take two integer operands and return a boolean,
and the eq?
(equality comparison) operator
which takes either two integers or two booleans,
and returns a boolean.
Operators no longer have separate intermediate language constructors
like Add
and Negate
from the Var language compiler;
all of these have been combined together into the Prim
constructor
(which stands for "primitive operation")
which can take any number of arguments.
Checking that each operator receives the right number of arguments
is the responsibility of the type checkers.
Type checking
Since this language has two types (Integer
and Boolean
),
it needs a type checker.
In fact, two intermediate languages have type checkers:
the AST language ("Lif")
and the C-like intermediate language ("Cif").
The type checkers are supplied to you in the Type_check
,
Type_check_lif
, and Type_check_cif
modules.
You will only notice them if your code fails to type check.