All phases of a compiler for Python Language have been implemented using C language. The constructs 'if-else' and 'while' have been handled.
The proj.l lex file and proj1.y yacc file work together to parse the Python code in the inp.py file and generate tokens to output a symbol table and create an abstract syntax tree and hence, generate the optimised intermediate code. This optimised intermediate code is saved in the file IntermediateCode.txt which is then accessed in the TargetCodeGenerator.c file. This file converts this optimised intermediate code to the target code for a hypothetic machine model which will be discussed further.
- Install Flex (to make lex program work)
sudo apt-get upgrade
sudo apt-get install flex
- Install Bison (to make yacc program work)
sudo apt-get upgrade
sudo apt-get install bison
- Run the lex and yacc files
lex proj.l && yacc -d -v proj1.y && gcc lex.yy.c y.tab.c -ll -lm -w
- Run the TargetCodeGenerator.c file
gcc -o TargetCodeGenerator .\TargetCodeGenerator.c
.\TargetCodeGenerator.exe
For any comments or questions, please email at [email protected] / [email protected] / [email protected]