Giter Site home page Giter Site logo

simple-compiler's Introduction

simple-compiler

A simple compiler written in C++. Can be configured to interpret to C++, or compile source code to machine code and execute. Supports a subset of the C programming language.

Features

  • integers
  • cout statements
  • endl for a newline character
  • line and block comments
  • basic comparision operators (>, <, <=, >=, ==)
  • logical && and || operators
  • bitwise & operator
  • nested statements with PEMDAS (4 + (4 * 2) / (1 & 1))
  • += and -=

Here is an example of some source code it currently supports:

void main()
{
    // integers and math
    int sum;
    sum = (35 + 1) / (36 * 1) * (1 & 1);
    cout << sum << endl;

    // cout statements
    cout << endl << 0 << sum << 0 << endl;

    // plus equals & minus equals
    int test;
    test = 0;
    cout << test << endl;
    test += 99;
    cout << test << endl;
    test -= 99;
    cout << test << endl;

    // while loops
    int max;
    max = 10;
    while (max >= 0)
    {
        cout << max << endl;
        max -= 1;
    }
}

Running

Your input file must be named INPUT.c and be in the projects root directory. You can then run

$ make interpret

in order to interpret the source code to C++, and

$ make compile

in order to compile the source code into machine code and execute. (currently this is only available with g++-9 on <= ubuntu 16)

simple-compiler's People

Contributors

human37 avatar

Stargazers

Jessica Cserepes avatar Torstein Øvstedal 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.