Java Compiler Simulator
A project for Principles of Programming Language course 2021
(International University - Vietnam National University HCMC)
- Primitive data types: int, float, double, string, boolean
- Java type inference using the var keyword
- Simple function call
- Single file compilation
- Comments, both singleline and multiline
- Type inference using
var
keyword
Python version 3.8
- pipenv
- pydot
- pyinstaller
- autopep8
C
There are 8 modules in the system:
Each of the modules is responsible for a different phase in the compilation process.
All of these 8 modules are wrapped inside the main jcosim
container, which is responsible for initializing, calling and dependency injection between the modules.
The structure of the who system is similar to that of a standard compiler
As we have discussed above, the intermediate form we choose here is the C language
Target language here is native binary code.
The difference here is that JCOSIM will not support steps that are related to code optimization like machine-independent code improvement and machine-specific code improvement.
Users do not need to install any software to use most of the features of JCOSIM.
The only thing that requires an external package is the option to visualize parse trees, which depends on Graphviz, a very popular software made specifically for visualizing graphs grammatically. Graphviz is supported on a lot of platforms, users can get a copy of graphviz here
Compile simple Java source file to C then to executables.
Usage: jcosim -i <file> [OPTIONS]
Options:
-i <file>, --input <file> input source file path and name
-o <file>, --output <file> output executable path and name
-s, --symtable generate symtable only
-t, --token generate tokens only
-p, --parsetree generate parse tree only
-a, --analyzedtree generate analyzed parse tree only
-g, --gencode generate generated C code only
-c <path>, --clean <path> clean all outputs in <path>
-u, --use-gcc use gcc compiler specified in jcosim.config.json
-v, --verbose generate all intermediate output
-h, --help display this help and exit
* NOTE: to generate parse tree, graphviz needs to be installed on the system
Examples:
- Compile a file to exe with no intermediate output:
jcosim -i Main.java -o Main
jcosim --input Main.java --output Main
- Compile a file to exe with intermediate output:
jcosim -i Main.java -o Main -v
jcosim --input Main.java --output Main --verbose
- Show symtable:
jcosim -i Main.java -s
jcosim --input Main.java --symtable
- Show tokens:
jcosim -i Main.java -t
jcosim --input Main.java --token
- Show parse tree:
jcosim -i Main.java -p
jcosim --input Main.java --parsetree
- Show analyzed parse tree:
jcosim -i Main.java -a
jcosim --input Main.java --analyzedtree
- Show generated C code:
jcosim -i Main.java -g
jcosim --input Main.java --gencode
- Clean outputs
jcosim -c .
jcosim --clean .
git clone https://github.com/tidunguyen/PPL-2021
cd PPL-2021
pipenv shell
pipenv install
pipenv install --dev
python src/jcosim.py -i <file> [OPTIONS]
Please follow instructions in the manual
Make sure that all pipenv dependencies (including dev ones) are installed before continue.
pipenv run build-unix
pipenv run build-win
./dist/jcosim -i <file> [OPTIONS]
Please follow instructions in the manual
You may replace forward slash with backslash on Windows in case of path errors
python test/organized_tests/run.py
You can customize test runs as you want inside that file
Click Here
Apache-2.0