Programming Languages assignment 3
Due: Monday March 14th
- Write an interpreter for F♭ as defined in the book. You need to implement all features
except for
Let Rec, which is for extra
credit only. - Answer the problems in hw3.ml.
The F♭ Development Kit
(FbDK)
We have provided you with the FbDK to make your job easier.
- The FbDK distribution is here in
both source and binary form. The FbDK is described in detail in Appendix A
of the book.
- The FbDK
source distribution includes code and scripts to build a standalone F♭
interpreter, a F♭ top loop in analogy to the
ocaml top
loop. It includes a parser and pretty printer. All you need to do is write an
eval function in the file .../src/Fb/fbinterp.ml.
- The distribution file
.../src/Fb/fbast.ml
is a variant that defines the grammar to be used for F♭.
- The FbDK also contains a complete BOOL interpreter
for the little boolean language in the subdir
.../src/BOOL/.
The complete source for the BOOL evaluator is also given.
- The FbDK
binary distribution includes bytecodes for a correct F♭ interpreter
fb.byte
- executed as ocamlrun fb.byte - that you can test your
interpreter against.
- You may find it handy to debug your interpreter with help of the
interactive
ocaml top loop.
Once you have make'd all the files, run ocaml from the src/Fb/ directory
and #use "fbdktoploop.ml";; which loads the .../src/Fb/fbdktoploop.ml
file -- this will load the
F♭ interpreter structures. Look at the source of this file for
the functions it contains.
- The F♭DK distribution also contains the source of all F♭ code examples in
the book,
.../src/Fb/fbexamples.ml
Hints
- For OcaIDE and Eclipse configuration instructions, see the course OcaIDE page.
- Use the F♭ operational semantics rules as the guidepost: all you
are doing is implementing those rules.
- For a warm-up, get the numbers and booleans to evaluate
properly,
then tackle functions.
- You will need to write several auxiliary functions for
performing substitution, etc.
- Declare and raise appropriate exceptions.
- The file .../src/Fb/fbexamples.ml
in the distribution includes many F♭ examples.
-
You will probably want to write at least three functions:
- eval, a stub for which is provided,
- subst, a function implementing variable substitution
- check_closed, a function which determines whether or not an expression is closed
Remember that you must raise an exception if you are provided an expression which is not closed, such as Function x -> y.
Submission
For this part of the assignment, submit only the
fbinterp.ml file that will "plug in" to the FbDK and
build the interpreter and the
hw3.ml file containing your F♭ answers. Use Blackboard for submission as usual.