From Java to MIPS in Five Nifty Steps

UCLA CS 132 Project

Jens Palsberg

The Hundred Hour Wood



MiniJava grammar minijava.jj specification [javac+java] programs Factorial.java
Piglet grammar piglet.jj specification interpreter programs Factorial.pg
Spiglet grammar spiglet.jj specification interpreter programs Factorial.spg
Kanga grammar kanga.jj specification interpreter programs Factorial.kg
MIPS grammar mips.jj specification [SPIM] programs Factorial.s

The grammars for MiniJava, Piglet, Spiglet, Kanga, and MIPS are needed for Homeworks 2-6. Notice that the grammars are available both in html and in JavaCC notation.

The compiler project consists of Homeworks 2-6. Solutions to Homeworks 2-6 can be combined into a Java-to-MIPS compiler.

Homework 2: Type checking of MiniJava

Use JTB and JavaCC and write in Java one or more visitors which type check a MiniJava program. Your main file should be called Typecheck.java, and if P.java contains a program to be type checked, then

java Typecheck < P.java

should print either "Program type checked successfully" or "Type error".

Homework 3: MiniJava -> Piglet

Use JTB and JavaCC and write in Java one or more visitors which compile a MiniJava program to Piglet. Your main file should be called J2P.java, and if P.java contains a syntactically correct MiniJava program, then

java J2P < P.java > P.pg

creates a Piglet program P.pg with the same behavior as P.java.

Homework 4: Piglet -> Spiglet

Use JTB and JavaCC and write in Java one or more visitors which compile a Piglet program to Spiglet. Your main file should be called P2S.java, and if P.pg contains a syntactically correct Piglet program, then

java P2S < P.pg > P.spg

creates a Spiglet program P.spg with the same behavior as P.pg.

Homework 5: Spiglet -> Kanga

Use JTB and JavaCC and write in Java one or more visitors which compile a Spiglet program to Kanga. Your main file should be called S2K.java, and if P.spg contains a syntactically correct Spiglet program, then

java S2K < P.spg > P.kg

creates a Kanga program P.kg with the same behavior as P.spg.

Homework 6: Kanga -> MIPS

Use JTB and JavaCC and write in Java one or more visitors which compile a Kanga program to MIPS. Your main file should be called K2M.java, and if P.kg contains a syntactically correct Kanga program, then

java K2M < P.kg > P.s

creates a MIPS program P.s with the same behavior as P.kg.