Previous    Next


Design a set of visitors which translate a MiniJava program into intermediate representation trees. Supporting files in $MINIJAVA/chap7 include:

Tree/* Data types for the Tree language.
Tree/ Functions to display trees for debugging.

A simpler translator To simplify the implementation of the translator, you may do without the Ex, Nx, Cx constructors. The entire translation can be done with ordinary value expressions. This means that there is only one Exp class (without subclasses); this class contains one field of type Tree.Exp and only an unEx() method. Instead of Nx(s), use Ex(ESEQ(s, CONST 0)). For conditionals, instead of a Cx, use an expression that just evaluates to 1 or 0.

The intermediate representation trees produced from this kind of naive translation will be bulkier and slower than a "fancy" translation. But they will work correctly, and in principle a fancy back-end optimizer might be able to clean up the clumsiness. In any case, a clumsy but correct translator is better than a fancy one that doesn't work.

JaVaScreenshot Previous    Next