A Python compiler written in C and C++ with the assistance of Lex
and Yacc
, utilizing Flex
, Bison
, Win_Flex
, and Win_Bison
. The project aims to replicate Python's syntax, providing error checking and generating an Abstract Syntax Tree (AST) visualization. GNU's flex bison.
The Python compiler supports a wide range of Python syntax, including defining functions
, classes
, expressions
, assignment statements
, if conditions
, loops (for and while)
, and various other language structures. It handles features like inheritance
, data types
, arrays (lists)
, decorations
, and more. The compiler goes through three phases: scanning the code, parsing for validation, and generating an AST for code visualization.
This project is open to any developer interested in exploring or contributing to a Python compiler implementation.
- C and C++ programming languages
- Lex and Yacc (Flex, Bison, Win_Flex, Win_Bison)
- Graphviz for AST visualization
Before running the project, ensure you have the following installed:
-
GCC and G++ compilers
-
Flex and Bison
-
Win_Flex and Win_Bison
-
Graphviz
-
Clone the repository:
git clone https://github.com/EyasWannous/python-compiler-GNU-flex-bison.git
-
Navigate to the project directory:
cd python-compiler-GNU-flex-bison
-
Run the following commands:
Flex scanner.l bison -d parser.y bison -v parser.y gcc parser.tab.c lex.yy.c win_flex scanner.l -o scanner.cpp win_bison -d parser.y -o parser.cpp g++ ast.cpp scanner.cpp parser.cpp
-
Execute the compiler with a test file:
a.exe < Tests/(testFile.py) > p1.gv
Replace "(testFile.py)" with the desired test file from the "Tests" directory.
-
Generate AST visualization:
dot -Tpng -op1.png p1.gv
To run the compiler on a sample Python file and visualize the AST:
a.exe < Tests/p1.py > p1.gv
dot -Tpng -op1.png p1.gv
Feel free to clone the repository, experiment with the code, and contribute by sending pull requests. Your contributions are welcome!
Let me know if you have any additional information or changes you'd like to make!