Technical tags

Research Project Java JTB JavaCC Windows SDK Compiler C Language Assembly Language Eclipse IDE

Publication and Source code


This is a research topic for my undergraduate project related to thesis. The study was awarded "The Outstanding Undergraduate Thesis" at Anhui University. The motivation is to design an object-oriented language as an example to help student understand principles of compiler design. The object-oriented programming languages have been popular for decades. The courses related to the design of compilers do not give comprehensive knowledge in designing an object-oriented compiler. In the study, I was responsible for designing and implementation of a practical Object-Oriented compiler that can be used in teaching. We selected to use MiniJava language, a subset of Java, as our initial study for the practice in teaching. The implemented Minijava language supports these features:
  1. It can process a couple of different primitive data types, including character and integer.
  2. It supports the most important features in Object-Oriented programming: inheritance, polymorphism, and encapsulation.
  3. It provides conditional statements, including if-else, and while statements.
  4. It provides function call, and recursive call.
  5. It has a basic library to support inputting an integer or printing a character, building GUI windows, and drawing on a screen.


We choose to use some existing compiler automatic generation tools, including JavaCC, JTB. The overview of the building steps are shown in the figure.
  1. Write a grammar description file.
  2. Generate abstract syntax tree, based on the grammar description file.
  3. Generate a lexical analyzer and parser.
  4. Semantic analysis and code generating. In this step, we visit the generated tree multiple times to generate valid virtual machine code or x86 assembly code.
These are the supported system functions in the library of MiniJava:
"System.out.println" "(" Exp() ")" ";"
"Minijava.print" "(" Exp() ")" ";"
"Minijava.scanf""(" Identifier() ")"";"
"Minijava.rand" "("  Identifier() ")"";"
"Minijava.srand" "("  Exp() ")"";"
"Minijava.window""(" Exp()"," Exp()"," Exp()"," Exp()")"";"
"Minijava.wait""("  Exp() ")"";"
"Minijava.getkey""(" Exp()"," Identifier() ")"";"
"Minijava.present""("Exp()"," Exp()")"";"
"Minijava.color""(" Exp()"," Exp()"," Exp()","Exp()","Identifier()")"";"
"Minijava.bitblt""(" Exp()"," Exp()"," Exp()"," Exp()"," Exp()")"";"


The result is presented in the video. Check it out now!


Running factorial calculation. [View source code] [View asm code]

Running Greedy Snake video game. [View source code] [View asm code]