compiler for python made using lex yacc / GNU's flex bison.
The current version of this code supports defining a function
, defining a class
, calling a function
, various types of expressions
, assignment
statements, and if conditions
, in addition to loops such as for
and while
and some other structures such as try
, match
, yield
, global
, nonlocal
, return
, break
, continue
, INDENT
\ DEDENT
analysis using stack
You will need flex
, bison
, and gcc
installed on your machine
$ chmod +x build.sh clear.sh
$ ./build.sh
compiled: compiler
, parser.tab.c
, parser.tab.h
, lex.yy.c
$ ./compiler test.py
$ ./clear.sh
This program is run using the following commands:
bison -d parser.y
- This instruction produces two files:
- parser.tab.h : We use this to include it inside the flex file to read the token
- parser.tab.c : We use this file to make a compiler with the resulting flex file
flex pycompile.l
- This instruction produces lex.yy.c file: We use this file to make a compiler with the resulting bison file(parser.tab.c)
Finally
, to compile flex and bixon, we write this command:
gcc -o <program file name> parser.tab.c lex.yy.c
- This produces .exe file
Note
: The stack
file is included in order to deal with indentation in a file pycompile.l
test file is : test py
but now is ready to execution ^_____^