A compiler for MiniJava, a fully object-oriented language and a subset of the language Java. MiniJava is designed so that its programs can be compiled by a full Java compiler like javac
. The BNF version of MiniJava can be found here. The MiniJava compiler converts the MiniJava code into the intermediate representation used by the LLVM compiler project. It then uses clang
(version 4.0 and newer) to generate the executable file.
To get the MiniJava compiler up and running on your local machine, simply follow the following instructions.
First, you need to download clang
(version 4.0 and newer) using the following command:
sudo apt install clang-4.0
To download the source code of the MiniJava compiler use the following command:
git clone https://github.com/vsakkas/minijava-compiler.git
And to enter the directory of the downloaded project, simply type:
cd minijava-compiler
To build the compiler, type the command below:
make
Finally, to run the MiniJava compiler, use the following command:
java Minijava <yourfile>.java
The example above will generate 2 new files in the same directory as <yourfile>.java
is:
<yourfile>.ll
which contains the LLVM IR code that was generated by the compiler.<yourfile>
which is the executable produced byclang
and can be run by using the command./<yourfile>
.
The above example compiles only one file. However, multiple files can be used. In this case, the compiler will generate 2 new files for each of the input files that were given. (Note: the source files do not need to be in the same path as the compiler. Full and relative paths can also be used.)
This project is licensed under the MIT License - see the LICENSE file for details