Giter Site home page Giter Site logo

pycompile's Introduction

PyCompile

PyCompile License

PyCompile is a simple and intuitive compiler for a custom programming language. It takes source code as input, tokenizes it, parses it into a syntax tree, and performs semantic analysis. The project is designed to be educational, demonstrating how a compiler works from source code to execution.

Features

  • Lexical Analysis: Tokenizes the input source code.
  • Syntax Analysis: Parses tokens into a syntax tree.
  • Semantic Analysis: Checks for semantic errors.
  • Intermediate Representation: Generates an intermediate representation of the code.
  • Code Generation: Generates low-level code from the intermediate representation.
  • Assembly Generation: Converts low-level code to assembly instructions.
  • Virtual Machine: Executes the generated assembly instructions.
  • Command-Line Interface: Simple interface to compile and execute source code files.

Table of Contents

Installation

To install and set up PyCompile, follow these steps:

  1. Clone the repository:

    git clone https://github.com/Devansh-46/PyCompile.git
  2. Navigate to the project directory:

    cd PyCompile
  3. Install the required dependencies:

    pip install -r requirements.txt

Usage

To use the compiler, run the main.py script with the path to your source code file as an argument:

python main.py <path_to_source_code>

Examples

Create a file named example.src with the following content:

def add(x, y) {
    x + y
}

z = add(5, 3);
print(z);

Run the compiler:

python main.py example.src

Project Structure

PyCompile/
├── main.py
├── lexer.py
├── parser.py
├── semantic_analyzer.py
├── ir_generator.py
├── code_generator.py
├── assembly_generator.py
├── vm.py
├── node.py
├── mytoken.py
└── tests/
    ├── test_lexer.py
    ├── test_parser.py
    ├── test_semantic_analyzer.py
    ├── test_ir_generator.py
    ├── test_code_generator.py
    ├── test_assembly_generator.py
    └── test_vm.py
  • main.py: Entry point for the compiler. Handles reading input files and orchestrating the compilation process.
  • lexer.py: Handles lexical analysis, converting source code into tokens.
  • parser.py: Handles syntax analysis, converting tokens into a syntax tree.
  • semantic_analyzer.py: Performs semantic checks on the syntax tree.
  • ir_generator.py: Generates an intermediate representation of the code.
  • code_generator.py: Generates low-level code from the intermediate representation.
  • assembly_generator.py: Converts low-level code to assembly instructions.
  • vm.py: A virtual machine to execute the generated assembly instructions.
  • node.py: Defines the Node class used in the syntax tree.
  • mytoken.py: Defines the Token class used in lexical analysis.
  • tests/: Contains test cases for various components of the compiler.

pycompile's People

Contributors

devansh-46 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.