Technical tags
Research Project
Java
JTB
JavaCC
Windows SDK
Compiler
C Language
Assembly Language
Eclipse IDE
Publication and Source code
Introduction
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:
-
It can process a couple of different primitive data types, including character and integer.
-
It supports the most important features in Object-Oriented programming: inheritance, polymorphism, and encapsulation.
-
It provides conditional statements, including if-else, and while statements.
-
It provides function call, and recursive call.
-
It has a basic library to support inputting an integer or printing a character, building GUI windows, and drawing on a screen.
Method
We choose to use some existing compiler automatic generation tools, including JavaCC, JTB.
The overview of the building steps are shown in the figure.
-
Write a grammar description file.
-
Generate abstract syntax tree, based on the grammar description file.
-
Generate a lexical analyzer and parser.
-
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()")"";"
Result
The result is presented in the video. Check it out now!
Screenshots