mini-java
is an educational transpiler from MiniJava, which is a subset of Java,
to C.
The construction of this transpiler is documented on www.mrcoder.org.
sudo apt-get install ocaml opam
opam init -a -y
eval `opam config env`
opam switch -y 4.07.0
eval `opam config env`
opam install -y ocamlbuild ocamlfind menhir
brew install gpatch m4 ocaml opam
opam init -a -y
eval `opam config env`
opam switch -y 4.07.0
eval `opam config env`
opam install -y ocamlbuild ocamlfind menhir
Once you have the dependencies (see above), run the following commands in your terminal.
git clone --recurse-submodules https://github.com/lascar-pacagi/MiniJava.git
make
./mini-java file.java
./file
The default C compiler is cc
. if you want to use another compiler, you should give the name of the compiler as follow.
./mini-java --c-compiler clang file.java
If you want to launch mini-java
from any directory, you should give the path to the tgc
directory.
./mini-java --tgc-path "path to tgc directory" file.java
If you want to use mini-java
without a garbage collector, and so without dependencies to tgc
, you can
checkout the version 1.0. In this version, the transpiler doesn't use a garbage collector and only produces
the generated C file.
git checkout v1.0
make
./mini-java file.java
gcc file.c -o file
./file
If you want to modify the version 1.0, you can create a new branch from version 1.0 (for example from_v1.0
).
git checkout -b from_v1.0 v1.0
to go back to the version with a garbage collector do the following.
git checkout master
make
The branch ast_typed
has an abstract syntax tree decorated with type information. This tree is produced by the typechecker and it can be useful if you want to augment MiniJava
.