Giter Club home page Giter Club logo

plasma-compiler's Introduction

Plasma-Compiler ⚡

C compiler written in Python. It does not comply with any standards for the C language. Likely Turing complete. It works by transpiling C source to x86 assembly, then leveraging third party tools to assemble and link the program. The code is fully custom, everything from the lexer to the code generation (no libraries used).

NOTE: This project was developed when I was in high school and therefore does not reflect my current expertise. I have made minor updates to the project since then, but the majority of the codebase remains unchanged from the original version.

Features

  • Custom lexer
  • Custom AST representation
  • Machine code generation, represented by assembly language
  • Supported C Language Features:
    • Single line comments
    • Function declaration
    • Variable declaration and assignment
    • Variable Scoping
    • If, else if, and else
    • For loops
    • While loops
    • Break / Continue
    • Recursion
    • Precedence in expressions
    • Ternary operator
    • binary operations: + - * / == != > < >= <= || &&
    • unary operations: - !

Steps for Using

NOTE: The compiler only runs on Windows host machines, and it will only compile win32 binaries.

Dependencies

This project uses the MSVC linker, so you will need to install Visual Studio if you haven't already.

At the time of writing, the latest version is 2019, so I cannot guarantee proper linking for any subsequent versions.

Also note that if your Visual Studio version is different than 2019, you will need to change shell.bat accordingly.

Development Dependencies

If running the compiler via the .py files and a suitable Python Interpreter, some Python dependencies must be installed,

pip install -r requirements.txt

In addition, this project uses Netwide Assembler (NASM). Install the binaries and make sure the bin directory is set in the system environment variables.

Setup

To use the compiler, open a new command prompt and run,

shell.bat

This will setup the MSVC environment, so that link.exe is accessible.

The compiler will not log an error if link.exe is unavailable.

Normal Usage

usage: Plasma Compiler [-h] [-d] [-r] [-t] [filename]

positional arguments:
  filename     The file to process.

options:
  -h, --help   show this help message and exit
  -d, --debug  Enable debug mode.
  -r, --run    Run code after compile.
  -t, --test   Run all tests (ignores positional argument).

plasma-compiler's People

Contributors

blubloos avatar

Stargazers

 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.