Compiling python to c language using python language, lex and yacc
Lex in compiler design is a program used to generate scanners or lexical analyzers, also called tokenizers. These tokenizers identify the lexical pattern in the input program and convert the input text into the sequence of tokens. It is used with the YACC parser generator.
YACC (yet another compiler compiler) is a grammar parser and parser generator. That is, it is a program that reads a grammar specification and generates code that is able to organize input tokens in a syntactic tree in accordance with the grammar.
In this project we are using these concepts and convert python file to c file.
- Implementation all in python langauge so you don't need other softwares
- Clean code
The project follows a specific structure to organize its files and directories:
├── README.md
├── TokList.txt
├── c.txt
├── lex.py
├── p.txt
├── parser.out
├── parsetab.py
├── yacc.py
README.md
: Documentation file providing information about the project.TokList.txt
: Tokens are stored in this file after lexical analysis.c.txt
: Output file in c language will be stored here.lex.py
: Script for lexical analysis that read input file and tokenize it.p.txt
: Input python file.parser.out
andparsetab.py
: Auto generated file after parsing.yac.py
: Script for yacc handling.
To run the x86 assembler, you need to have the following installed on your system:
- Python (version 3.0 or higher)
- PLY package
- Git command line tool (or Git GUI client) to clone the repository.
- Open a terminal and clone this repository:
git clone https://github.com/hoseinmrh/Python-to-C-compliler
- Write your python file in
p.txt
then runyac.py
. Output will be stored inc.txt
.