Skip to content

thdemarty/transpiler

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

40 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

MiniJava Transpiler

mini-java is an educational transpiler from MiniJava, which is a subset of Java, to C.\

Tasks

  • Operators:
    • Greater than (>)
    • Or (||)
    • Division (/)
    • Equal (==) (working not-only for primitive types)
    • Less than or equals (<=)
    • Greater than or equals (>=)
    • Not equals (!=)
    • Modulus (%)
    • Bitwise and (&)
    • Bitwise or (|)
    • Bitwise xor (^)
    • Bitwise not (~)
    • Bitwise left shift (<<)
    • Bitwise right shift (>>)
  • Syso:
    • Print boolean
    • Print string
    • Print float
  • Control Flow:
    • If without else
    • For loop
  • Others:
    • String support
    • String array support
    • Float support
    • Float array support
    • Multiple instructions in main
    • Declaration and initialization at the same time

Install Dependencies

Linux (Ubuntu)

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

Mac OS X

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

Download, Compile and Run

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

About

A transpiler from minijava to C written in OCaml

Resources

Stars

Watchers

Forks

Contributors 2

  •  
  •