Programming Languages

F♭ Interpreter and F♭ Programming

Due on Monday, October 4th at 11:59 PM. This is a team lab. You may work alone or you may work with a partner. If you’d like to work with a partner, make sure to indicate your preferred partner using Teammaker and be familiar with the Partner Etiquette guidelines. You may discuss the concepts of this lab with other classmates, but you may not share your code with anyone other than course staff and your lab partner(s). Do not look at solutions written by students other than your team. If your team needs help, please post on Slack or contact the instructor. If you have any doubts about what is okay and what is not, it’s much safer to ask than to risk violating the Academic Integrity Policy.

Overview

This lab contains two major components. First, you will write an interpreter for the F♭ language. Second, you will write some programs in F♭ to demonstrate your understanding of encodings.

As in the last assignment, we will be using Teammaker to form groups to work on this assignment.

Part I: F♭ Interpreter

Your repository contains starter code for an F♭ interpreter. Most of the components of the interpreter are already provided:

One key component that is (intentionally) missing from this software is the evaluator. The file src/fb/fbinterp.ml contains a simple function eval which is meant to evaluate an F♭ AST into a value. Presently, it just returns the expression in an unevaluated form.

Your task for the first part of the assignment is to implement the eval function according to the language specification provided in Section 2.3 of the book. Your eval function must implement precisely the F♭ language that is defined by the evaluation relation discussed in that section. In cases in which evaluation is undefined, you should raise the TypeMismatch exception declared in that same file.

You are not required to implement Let Rec, but you are encouraged to try and you will receive a small amount of extra credit if you succeed.

Developing the F♭ Interpreter

In order to compile your F♭ interpreter, simply run make from the root of your project. This will produce, among other files, a program fb. Running that program without any arguments will launch the F♭ toploop.

The F♭ toploop is similar to the OCaml toploop in that each valid expression separated by ;; is evaluated and the result is printed. This evaluation is handled by the eval function of src/fb/fbinterp.ml, so it won’t actually evaluate anything until you’ve implemented that function. Unlike the OCaml toploop, there is no declaration syntax (e.g. let x = 4;;); all inputs must be expressions (e.g. Let x = 4 In x) and all expressions are evaluated independently.

Note that, in order to implement your interpreter, you’ll need to write more than just an eval function. You can include as many helpers in fbinterp.ml as you like. One good candidate, for instance, would be a helper function to perform variable substitution.

If you would like to write unit tests for any of your code, you may do so in the file src/tests/tests.ml. You can build your unit tests by running make tests.

Working Binaries

The binaries/ directory contains a working F♭ interpreter. You can run ./binaries/fb.exe to get a sense as to what your implementation should do. Note that this should not be your primary way of understanding how F♭ behaves; if you have any questions about the definition of the F♭ evaluation relation, you should consult the definition in the book. This binary interpreter is meant to permit you to experiment so you can check your understanding.

Part II: Writing F♭ Programs

Your repository also contains a file encodings.fb. This file contains F♭ definitions in the form of a series of Let ... In ... expressions. It also contains a number of comments directing you to write several definitions in F♭. Your task for this part of the assignment is to complete the work described by the encodings.fb file by writing the definitions correctly.

After the last In in the encodings.fb file, there is initially the expression 0. You may replace that expression with whatever test expression you like and then run the entire file by running ./fb encodings.fb from the command line. This provides you a means to test your various definitions without resorting to copying and pasting your code into the F♭ toploop. You will not be graded on anything that appears in that position of the file.

You are strongly encouraged to write and test your encodings.fb definitions one at a time and to commit each definition once you have completed it. Since this is a single large file in a language for which we have poor development tools, finding e.g. a missing parenthesis could be extremely difficult. It’s much easier to find these sorts of problems when you’re making small increments of progress.

Syntax Highlighting

The syntax-highlighting directory of your repository contains some small editor extensions to provide syntax highlighting for the F♭ language. Syntax highlighting is recommended: since the encodings.fb part of your assignment is one large expression, a single syntax error can be quite problematic. To install a syntax highlighting package, follow the instructions in the README.md file of the appropriate subdirectory for your editor.

Submitting

To submit your lab, just commit and push your work. The most recent pushed commit as of the due date will be graded. For more information on when assignments are due, see the Policies page.

Lab Questionnaire

In addition to completing the lab itself, you’ll also need to complete a questionnaire describing your experience in the lab. Under most circumstances, this questionnaire will take only about a minute to complete and is part of your participation grade. Please make sure to do this; the information is useful to develop the course and the credit you get is basically free!

If You Have Trouble…

…then please contact your instructor! Slack is the preferred method, but you can reach out via e-mail as well. Good luck!