Thanks for this tutorial for help.
The goal of this project is to compile this tiny language into cpp or python code. The syntax of this language is given toro language syntax section.
The input is the input.toro
file and the corresponding cpp code is output in the output.cpp
file and python code is in the output.py
file.
Please look at the UML.pdf
to get the structure of the project.
This project is consisted of three main classes.
- Lexer class :
./lexer/Lexer.cpp
is responsible for lexing the code and output tokens. - Parser class :
./parser/Parser.cpp
is responsible for parsing the tokens generated by the lexer and use the emitter class to emit the compiled code. - emitter class :
./emitter/Emitter.cpp
is responsible for generating the compiled code in cpp language.
For each class there is a tester script that test the functionality of it.
- Lexer tester :
./lexer/main.cpp
to test the lexer - Parser tester :
./parser/main.cpp
to test the parser
There is no tester for the emitter because it is quite intuitive.
The project runs on c++20.
Just use cmake to build it and run.
This will take toro code in the input.toro
file and output cpp code in the output.cpp
file and the python code in the output.py
.
the parser and the lexer has unit tests. You can build and run them using cmake too. Just go to the class directory and check the CMakeLists.txt
.
Our language syntax support :
- Number variables :
let var_name = 3.14
- Printing test :
output "Hello world"
- Printing numbers :
output var_name*4
- Input numbers :
input var_name
- If statement :
let var_name = 3.14
if var_name <= 3.14 then
output "Pi"
endif
- While loop :
let var_name = 10
while var_name > 0 repeat
output var_name
var_name = var_name - 1
endwhile
-
Comments start with #:
#this is comment
-
Toro lang does not support extra lines at the end of the code or extra spaces at the end of each line. please look at the sample at
./input.toro