Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/fadel-hasan/python-compiler
simple python compiler by using flex\bison
https://github.com/fadel-hasan/python-compiler
bison-flex bison-parser compiler compiler-design flex-bison lex lex-yacc lexer-parser lexical-analysis lexical-analyzer parser parsing python python-compiler python-lex-yacc python-parser python3 yacc
Last synced: 9 days ago
JSON representation
simple python compiler by using flex\bison
- Host: GitHub
- URL: https://github.com/fadel-hasan/python-compiler
- Owner: fadel-hasan
- License: mit
- Created: 2024-01-11T15:51:17.000Z (about 1 year ago)
- Default Branch: main
- Last Pushed: 2024-01-17T18:10:20.000Z (about 1 year ago)
- Last Synced: 2024-11-13T11:42:04.085Z (2 months ago)
- Topics: bison-flex, bison-parser, compiler, compiler-design, flex-bison, lex, lex-yacc, lexer-parser, lexical-analysis, lexical-analyzer, parser, parsing, python, python-compiler, python-lex-yacc, python-parser, python3, yacc
- Language: C++
- Homepage:
- Size: 34.2 KB
- Stars: 2
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
- License: LICENSE
Awesome Lists containing this project
README
# flex-bison python compiler
compiler for python made using lex yacc / [GNU's flex bison](https://www.gnu.org/software/bison/manual/).
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`
## How to make
You will need `flex`, `bison`, and `gcc` installed on your machine#### To change sh script permission:
`$ chmod +x build.sh clear.sh`#### To build:
`$ ./build.sh`
*compiled*: `compiler`, `parser.tab.c`, `parser.tab.h`, `lex.yy.c`#### To run:
`$ ./compiler test.py`#### To clear:
`$ ./clear.sh`### Explaining the operating steps without using the build file
This program is run using the following commands:
```bash
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```bash
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:
```bash
gcc -o 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 pybut now is ready to execution ^_____^
## Authors
- [@fadel-hasan](https://www.github.com/fadel-hasan)
## License
[![MIT License](https://img.shields.io/badge/License-MIT-green.svg)](https://choosealicense.com/licenses/mit/)