Skip to content

MajorAbdullah/K-Compiler

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 

Repository files navigation

K++ Compiler

Overview

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.

Features

  1. Lexical Analysis: Converts source code into tokens.
  2. Parsing: Generates a syntax tree from the tokens.
  3. Syntax Tree Generation: Builds an abstract syntax tree (AST) to represent the program's structure.
  4. Code Generation: Transforms the syntax tree into executable code.
  5. Error Handling: Basic error detection and reporting during lexical analysis and parsing.

Requirements

  • Python 3.x
  • Flex (Fast Lexical Analyzer Generator)
  • Bison (Parser Generator)

How to Run

  1. Clone the repository:
    git clone https://github.com/MajorAbdullah/K-Compiler.git
  2. Navigate to the project directory:
    cd K-Compiler
  3. Install dependencies (if any):
    pip install -r requirements.txt
  4. Run the compiler on a source code file:
    python k_compiler.py <source_code_file>

Usage

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.

File Structure

  • 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.

License

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:

Contact

For any queries or suggestions, feel free to reach out:

Contributing

Contributions are welcome! Please fork this repository and submit a pull request for review.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published