List.G4
Antlr4 List project - Transpiler from List to Python3
List Language Definition
types
The list language supports only two types:
- integers
- lists
A list can have many elements of different types (integers or others lists)
Assignment
To create variables do:
a = 1
b = a + 2
c = [1, 2, a]
...
Printing
You can print any literal value or variable using the print statement, in the form: print X
Integer Operations
List supports only one operation for integers, the sum. To sum two or more integers just do:
1+2+5
List Operations
List support two different operation over lists:
- sum, in the form:
[1,2,3] + [1,2,3]
, that gives you another list[2, 4, 6]
- concatenation, in the form:
[1,2,3] . [1,2,3]
, that gives you another list:[1,2,3,1,2,3]
Instalation of transpiler
- Download and install java compilers
- Download and install Python3 interpreter
- Download and install ANTLR4. Exists a script named
get_antlr.sh
to download the tested version of antlr - run
pip install -r requirements.txt
- thats it!
To run programs in List just do:
python main.py my_list_script.list > output.py
This will create a output.py
file that can be run with:
python output.py
If you want to avoid create a new file to run the List script just do:
python main.py my_list_script.list | python