A Python-based compiler project implementing a lexer and parser for a custom language, using PLY (Python Lex-Yacc). This project demonstrates how to write a full-featured lexer and parser capable of handling declarations, function definitions, control statements, and more.
- Lexical analysis and parsing for a C-like custom language
- Handles variables, functions, types, control flows (if, else, for, etc.), and more
- Based on PLY (Python Lex-Yacc)
-
Python 3.6+
Make sure Python is installed and available in your environment. -
PLY package
Install PLY via pip:pip install ply
-
Clone the repository:
git clone https://github.com/HoomanMoradnia/Compiler.git cd Compiler -
Install dependencies:
pip install ply
-
Run the compiler:
python Compiler.py
You can modify the test input at the bottom of
Compiler.pyor adjust it to take input from a file.
-
Clone the repository:
git clone https://github.com/HoomanMoradnia/Compiler.git cd Compiler -
Install dependencies:
pip3 install ply
-
Run the compiler:
python3 Compiler.py
You can modify the test input at the bottom of
Compiler.pyor redirect input as needed.
- The main file is
Compiler.py. It contains both the lexer and parser logic. - By default, running the script will process sample code defined in the
if __name__ == "__main__":block at the end ofCompiler.py. - To parse your own code, you can replace the
test_inputvariable in the script or refactor the file to accept external input.
This project is licensed under the MIT License. See the LICENSE file for details.
Hooman Moradnia