Translating from POJay to OJay
For project 7---to give both you and me a little bit of a break---you
will not be implementing a translation from POJay to OJay.
Instead, you will be describing, informally but completely,
a translation algorithm or strategy from POJay to OJay.
In class on Monday, you started thinking through a translation of
a specific POJay program.
In this project you need to generalize the process you thought through
to make an algorithm which will translate from any
POJay program to a valid, equivalent OJay program.
Your solution should include answers to
- What information you would need to gather from
the POJay interfaces and classes in order to do the translation?
This might (depending on your algorithm) involve both
information about the interfaces and classes as a set
(for example, a list of all interfaces types)
and information for each class and interface
(for example, for each interface, the list of classes that implement it).
- What OJay classes would your algorithm generate?
Say, if a POJay program had three interfaces and four classes,
how many OJay classes would your translation algorithm generate?
How would they be related to the POJay types?
How would you determine their instance variables and methods?
- For each variable declaration in the POJay program
(including global declarations (static variables), instance variables,
local variables (both in the main method and instance methods),
and parameters),
how would you translate that declaration into the OJay program?
You will probably handle declarations differently based on
whether the variable's type in POJay is
- a primitive type (probably just translate it as is, no change)
- a class type
- an interface type
- For each cast in the POJay program,
how would you translate it into OJay?
(Remember, OJay does not have casts).
- For each assignment in the POJay program,
how would you translate it into OJay?
(Remember, an assignment might have an implicit/automatic cast.)
- For each invocation in the POJay program,
how would you translate it into OJay?
(As with your OJay-to-RecJay project,
the invocation in the output program might be to a renamed method.)
Your solution should also include the translation of
the sample POJay program from class using your strategy,
as an example of how it works.
Here is a clean copy of the program,
plus the grammars for OJay and POJay.
In working on this, you will want to make some examples of
your own.
It is not required to turn these in, but you may if you think
it will help you describe your algorithm.
Turn in your answer on paper to me.
Make sure that your submission is
project quality.
This is not a "short exercise" daily homework problem.
Your algorithms need to be complete and as unambiguous as possible.
Use complete sentences (or grammatically parallel phrases in
bullet lists).
If your handwriting isn't legible, then type your solution.
To give you a big first push, I will say that I can think of three
solutions to this problem.
They can be summarized (or, hinted at) as
- Split variables. A variable of an interface type
is replaced with one variable for each of the classes that implement that
interface.
- Unify types using inlining. Each interface type
becomes a class containing all the information
of all the classes that implement it.
- Unify types using delegation. Each interface type
becomes a class which is a place holder for objects of
the classes that implement it.
DUE: Wednesday, March 31, at 5:00 pm.
Thomas VanDrunen
Last modified: Tue Mar 23 16:44:21 CDT 2010