Transpiler made with Rayancris for the graduation year of our bachelor's degree.
Explore the world of lexical analysis with ASTs, semantic analysis with type checker and compilation.
- Lexical analysis using Flex
- Synataxical analysis using Yacc (Bison)
- Custom semantic analysis with symbol table and type checkers
- I/O interactions written in Assembly
- Transpile TPC into Assembly
For further explanation of the TPC language, see this file.
You can simply donwload this repository using git commands
git clone https://github.com/GouruRK/compilation
cd compilation
To compile, use the make command which produces bin/tpcc
make
Once compiled, use ./bin/tpcc --help
to display how to use it
Usage: ./tpcc [OPTION...] FILE
Check if syntax of given file is valid, according to the grammar defined in parser.y
With no FILE, FILE is the standard input
-t, --tree print abstract tree of the given file
-s, --symbols print associated symbol tables
-h, --help display this help message and exit
Take for example the following TPC file example.tpc
.
int main(void) {
return 5;
}
The command ./bin/tpcc example.tpc
produces an assembly file called example.asm
which can be compiled as so :
nasm -f elf64 -o example.o example.asm
gcc -o example example.o -nostartfiles -no-pie
to produce the executable ./example
A test collection of more than 430 tests have been created. This contains tests from friends on the same project.
To run them, just use make test