Interpreter, quote

Table of Contents

This portion of the project is a relatively small enhancement of the previous portion, where you add functionality for the special form quote. You should build this assignment as an extension of the work that you did for the previous one.

This is an interpreter project team assignment, which means that if you are working on a team with someone else, you and your partner should do your best to even the workload between you. Strict pair programming is not required, but you should make sure that both team members are contributing to the project. I do recommend that you try to do pair programming if it is convenient to do so.

1 Get started

Hopefully, you’ve got the hang of it by now as to how these projects start. Feel free to go back again to the tokenizer assignment if you want detailed instructions on how to clone the repository to Repl.it. Here is the new GitHub Classroom link that you’ll need to create the repository on GitHub. Use the same teams as you used for the last assignment. Once you have created your repository, its name will have quote as a prefix.

2 Functionality

For this phase of the project, you must additionally support the correct evaluation of the following Scheme expression:

(quote expr)

This is equivalent to 'expr, but you only need to be able to handle the version with quote.

(Handling the single quote is trickier, and is best just turned into a quote back at the parsing stage. We’re not including that as part of the project unless you entirely optionally wish to do so.)

3 Sample output

$ cat test-in-01.scm
(quote a)
(quote (a b c))
(quote (a b (quote (c d e))))
(let ((x (quote a)) (y (quote (a b c))))
  y)

$ ./interpreter < test1-in-01.scm
a
(a b c)
(a b (quote (c d e)))
(a b c)

4 Don’t annotate the parse tree

Do not implement this by trying to somehow wrap up the quoted expression in some sort of enclosure indicating that it is quoted.

Some of you will feel tempted to do otherwise! Some of you may find that you are convinced that somehow storing quote or a single quote somehow explicitly after evaluation will help you in some way. Some of you might even find that by doing so, you can succeed at this task. Don’t do it. It’s a trap. It might help you get this part of the assignment to work, but you’ll get into hot water later. This reflects a common and interesting point of confusion: quote does not tell the interpreter to do something to its arguments; rather, it tells the interpreter to not do something.

If you are feeling a strong urge to somehow specially annotate something indicating that something is quoted, don’t do it. If you are experiencing such compulsions because your tree is not printing properly, past experience has sometimes been that the problem is the code for printing the parse tree, not structuring it in the first place.

5 Capstone work

This assignment is a fairly small addition, so there isn’t additional capstone work on this task.

6 Your repository and your files

Your repository will follow the same structure that it has for the previous assignments. There should be no changes at all in the files that I provide; you’ll then need to add in the files from your previous version, and/or switch over to using my binaries. But note that the binaries I provide only go through part 4 of the project; I am not providing a working if/let interpreter. (The project gets too intermingled at this point for me to be able to supply complete partial work.)

Building and testing your code will work precisely the same as on the previous assignment.

7 What to submit

Make sure that you have added files if necessary, then push to GitHub. (You can leave out your compiled executables as well as the .o object files if you wish.)

Make sure to label your submission as usual via an appropriate commit message, and make sure your tests have run on GitHub.

Have fun interpreting!


This assignment was originally created by David Liben-Nowell and has since been updated by Dave Musicant, Jed Yang, and Laura Effinger-Dean.