Project 8: Implementing the Em Family

The goal of this project is to understand how we can encode a complicated functional language in a smaller language. In this project you will implement the translations among the Em family of languages that we saw in class Monday and Wednesday.

1. Set up

The system for implementing these languages is called EmIly (for Em family). You can copy EmIly from

~tvandrun/Public/cs365/proj8.tar

In this you will see directories for each language (boolem, declem, em, and listem). Also there is a directory of sample test programs. Each language directory has a subdirectory for the parser, the abstract syntax trees, and the visitors. boolem has a visitor for interpretation, and that is finished for you.

All the other languages each have a visitor called TranslatorVisitor. These are the ones you need to complete for this project.

2. Your task

There are nine steps in this project, corresponding to the nine translations we have seen in class:

  1. In declem.astvisitor.TranslatorVisitor.visit(Let), translate let expressions into BoolEm, which does not have lets.
  2. In declem.astvisitor.TranslatorVisitor.visit(Application) translate applications with many actual parameters into BoolEm, where all functions have one parameter.
  3. Similarly, in declem.astvisitor.TranslatorVisitor.visit(Abstraction), translate applications with many formal parameters into BoolEm.
  4. In em.astvisitor.TranslatorVisitor(FunDeclaration), translate recursive functions declarations into DeclEm, which does not have (explicit) recursion.
  5. In listem.astvisitor.TranslatorVisitor(Cons), translate uses of the cons operator.
  6. In listem.astvisitor.TranslatorVisitor(Test), translate tests if a list is null.
  7. In listem.astvisitor.TranslatorVisitor(List), translate explicit lists (e.g., [true, false, false, true]).
  8. In listem.astvisitor.TranslatorVisitor(Car), translate uses of hd.
  9. In listem.astvisitor.TranslatorVisitor(Cdr), translate uses of tl.

3. Practical considerations and testing

To execute a program in any of these languages, use

java em.EmIly programname

The EmIly program will determine which language is being used by the extension (so, name all of your DeclEm tests something that ends in .declem). It will do the appropriate translations and then execute the final BoolEm program. For example,

java em.EmIly rec.em

will...

For debugging purposes, you may want to suppress execution of the program and only print the translation. This can be done by using the -p flag, which prints only the first translation of the program and then stops. Similarly, the -pp flag prints all translations, but does not run the program.

I have given you a few sample programs, but an important part of this project is to write your own tests. It is much better to write many small tests. In particular, you will have best results with tests whose values are a booleans (or very simple abstractions). Since BoolEm has no lists, any ListEm program whose result is a list will appear as a (very complicated) abstraction. Hence it is better to test

hd(tl(true::[true,false,false,true]));

than

true::[true,false,false,true]

Finally, make sure you start with the DeclEm part and progress up the family hierarchy and test as you go If you try to write all the translations first and then execute reverse.listem as your first test, you will almost certainly get unpleasant results.

4. To turn in

Turn in your files declem.astvisitor.TranslatorVisitor, em.astvisitor.TranslatorVisitor, and boolem.astvisitor.TranslatorVisitor to appropriate directories:

/cslab.all/ubuntu/cs365/turnin/xxxxxx/proj8/yyyyy

where "xxxxxx" is [alisa|andrew|becca|cheney|daniel|drew|johncharles|kendall|turk] and "yyyyy" is [declem|em|listem]. I will grade your project by running it against a collection of test files.

DUE: Monday, April 16, 5:00 pm.


Thomas VanDrunen
Last modified: Tue Apr 3 10:37:15 CDT 2012