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.
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.
There are nine steps in this project, corresponding to the nine translations we have seen in class:
declem.astvisitor.TranslatorVisitor.visit(Let)
,
translate let expressions into BoolEm, which does not have lets.
declem.astvisitor.TranslatorVisitor.visit(Application)
translate applications with many actual parameters into BoolEm,
where all functions have one parameter.
declem.astvisitor.TranslatorVisitor.visit(Abstraction)
,
translate applications with many formal parameters into BoolEm.
em.astvisitor.TranslatorVisitor(FunDeclaration)
,
translate recursive functions declarations into DeclEm, which does not
have (explicit) recursion.
listem.astvisitor.TranslatorVisitor(Cons)
,
translate uses of the cons operator.
listem.astvisitor.TranslatorVisitor(Test)
,
translate tests if a list is null.
listem.astvisitor.TranslatorVisitor(List)
,
translate explicit lists (e.g., [true, false, false, true]
).
listem.astvisitor.TranslatorVisitor(Car)
,
translate uses of hd
.
listem.astvisitor.TranslatorVisitor(Cdr)
,
translate uses of tl
.
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...
rec.em
program.
em.abssyntree.Program
.
em.astvisitor.TranslatorVisitor
to produce a (String) DeclEm program.
declem.abssyntree.Program
.
declem.astvisitor.TranslatorVisitor
to produce a (String) BoolEm program.
boolem.abssyntree.Program
.
boolem.astvisitor.InterpreterVisitor
,
to find the result of that program.
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.
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.