K-Compiler is a simple, educational compiler designed to demonstrate the basics of compiler construction. The project showcases fundamental concepts such as lexical analysis, parsing, syntax tree generation, and code generation, making it a valuable resource for students and educators in computer science.
- Lexical Analysis: Converts source code into tokens.
- Parsing: Generates a syntax tree from the tokens.
- Syntax Tree Generation: Builds an abstract syntax tree (AST) to represent the program's structure.
- Code Generation: Transforms the syntax tree into executable code.
- Error Handling: Basic error detection and reporting during lexical analysis and parsing.
- Python 3.x
- Flex (Fast Lexical Analyzer Generator)
- Bison (Parser Generator)
- Clone the repository:
git clone https://github.com/MajorAbdullah/K-Compiler.git
- Navigate to the project directory:
cd K-Compiler - Install dependencies (if any):
pip install -r requirements.txt
- Run the compiler on a source code file:
python k_compiler.py <source_code_file>
Upon running the program, the K-Compiler will output the generated tokens, syntax tree, and executable code based on the provided source file. Follow the on-screen instructions to navigate through different options.
k_compiler.py: Main compiler driver script.lexer.l: Lexical analyzer definition using Flex.parser.y: Parser definition using Bison.ast.py: Abstract Syntax Tree classes and definitions.code_generator.py: Code generation logic.
This project is licensed under the MIT License. See the LICENSE file for more details. This code is protected under an "All Rights Reserved" license. You must obtain explicit permission from the copyright holder before using, distributing, or modifying this work.
For permissions, please contact:
For any queries or suggestions, feel free to reach out:
- Email: sa.abdullahshah.2001@gmail.com
- LinkedIn: Syed Abdullah Shah
Contributions are welcome! Please fork this repository and submit a pull request for review.