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 TranslaterVisitor
(It turns out that I misspelled translator as translater
throughout this project.
Very embarrassing. But I don't have time to go back and change it.)
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.TranslaterVisitor.visit(Let)
,
translate let expressions into BoolEm, which does not have lets.
declem.astvisitor.TranslaterVisitor.visit(Application)
translate applications with many actual parameters into BoolEm,
where all functions have one parameter.
declem.astvisitor.TranslaterVisitor.visit(Abstraction)
,
translate applications with many formal parameters into BoolEm.
em.astvisitor.TranslaterVisitor(FunDeclaration)
,
translate recursive functions declarations into DeclEm, which does not
have (explicit) recursion.
lsitem.astvisitor.TranslaterVisitor(Cons)
,
translate uses of the cons operator.
lsitem.astvisitor.TranslaterVisitor(Test)
,
translate tests if a list is null.
lsitem.astvisitor.TranslaterVisitor(List)
,
translate explicit lists (e.g., [true, false, false, true]
).
lsitem.astvisitor.TranslaterVisitor(Car)
,
translate uses of hd
.
lsitem.astvisitor.TranslaterVisitor(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.TranslaterVisitor
to produce a (String) DeclEm program.
declem.abssyntree.Program
.
declem.astvisitor.TranslaterVisitor
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.TranslaterVisitor
,
em.astvisitor.TranslaterVisitor
, and
boolem.astvisitor.TranslaterVisitor
to appropriate directories:
/cslab/class/cs365/turnin/proj8/xxxxxx/yyyyy
where "xxxxxx" is [lily|chet|christopher|tim|david|ben|caleb] and "yyyyy" is [declem|em|listem]. I will grade your project by running it against a collection of test files.
DUE: Wednesday, April 21, 5:00 pm. However, be advised that project 9 will be posted on Monday, April 19. You should make an effor to have this project done by the 19th. (Think of the 21st duedate as two free late days.)