This is a simple demonstration of how to make a language compiler using Python's PLY module. The project implements a lexer, parser and interpreter for Java.
To install locally, do the following:
-
Ensure that the following things have been installed:
a. python (Installed based on your distro)
b. pip (curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py && python get-pip.py)
c. virtualenv
-
Open up a terminal.
-
Create a directory somewhere
mkdir java-compiler-env
andcd
into it. -
Create a python virtual environment
python -m virtualenv .
-
Activate the virtual environment
source bin/activate
-
Navigate to the project's root directory where
setup.py
file is located. -
Do a
pip install .
Once the installation is complete, you can test the compiler by running the java console by running the command: java-console
. Start creating variables and run arithematic commands.
-
Variables:
- Declaration, assignment, access
- Types: int, double, char, strings, bool
- Initialisation and declaration of a variable with the name of a pre existing variable would generate error
- Types of the data and the variable should match while declaring or initialising
-
Array:
- Declaration, assignment, access
- Types: int, double, char, strings, bool
- Access outside the array-size would give an error
-
Arithematic Expressions:
- Operators: (+ , - , / , * , % , ++, --, nested parentheses)
-
Standard Output:
- System.out.print()
- Any variable-type should be displayed
-
Error Handling:
- Mentions the reason for error