Skip to content
/ MiniJava Public

MIPS Compiler for MiniJava using JFlex, Beaver and JastAdd

Notifications You must be signed in to change notification settings

Tetr4/MiniJava

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

MIPS Compiler for MiniJava

Setup

  • Building: Run build.xml with ant.
  • Testing: Run the AllTests.java suite with junit.
  • (optional) JastAdd Syntax Highlighting in Eclipse: JastAdd Eclipse Plugin.
    Then in Preferences under File->Editors->FileAssociations associate "*.beaver" with "JastAdd Parser Editor"

Compilation order

  1. Scan the input via JFlex
  2. Parse the token stream via Beaver
  3. Annotate the Abstract Syntax Tree (AST) via JastAdd
  4. Transform MiniJava AST to Piglet AST
  5. Transform Piglet AST to Simplified Piglet AST
  6. Transform SPiglet AST to Kanga AST
  7. Transform Kanga AST to MIPS AST
  8. Prettyprint MIPS AST

Usage examples

Check for Syntax/Semantic errors:

MJFile file = new MJFile("tests/Factorial.java");
minijava.Program program = file.parse();
for (SemanticError e : program.errors()) {
    System.err.println(e.getMessage());
}

Compilation:

MJFile file = new MJFile("tests/Factorial.java");
mips.Program mips = file.parse().toPiglet().toSpiglet().toKanga().toMips();
String mipsCode = mips.print().getString();

Interpreting:

It is possible to interpret Piglet, Spiglet, Kanga and Mips.

MJFile file = new MJFile("tests/Factorial.java");
spiglet.Program spiglet = file.parse().toPiglet().toSpiglet();
System.out.println(spiglet.interpret());

About

MIPS Compiler for MiniJava using JFlex, Beaver and JastAdd

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published