Code Monkey home page Code Monkey logo

ubcc's Introduction

ubcc

A toy C Compiler implemented by Rust.

Usage

# first time
make

# build and testing
make build
make e2e

Able to compile

int literals

int main() {
    return 0;
}
int main() {
    return 42;
}

binary expressions

int main() {
    return 5 + 20 - 4;
}
int main() {
    return 5 * (9 - 6);
}
int main() {
    return 5 + 6 * 7;
}
int main() {
    return (3 + 5) / 2;
}

compare

int main() {
    return 1 > 0;
}
int main() {
    return 1 < 1;
}
int main() {
    return 1 > 2;
}
int main() {
    return 1 >= 2;
}
int main() {
    return 0 != 1;
}
int main() {
    return 2 <= 1;
}
int main() {
    return 42 == 42;
}
int main() {
    return 0 <= 1;
}
int main() {
    return 0 < 1;
}
int main() {
    return 1 <= 1;
}
int main() {
    return 1 >= 0;
}
int main() {
    return 42 != 42;
}
int main() {
    return 2 < 1;
}
int main() {
    return 1 > 1;
}
int main() {
    return 0 == 1;
}
int main() {
    return 1 >= 1;
}

variables

int main() {
    int a = 10;
    a = a + 2;
    return a;
}
int main() {
    int a = 2;
    int z = 5;
    int c = a + z;
    return c;
}
int main() {
    int foo = 2;
    int z = 5;
    return foo + z;
}
int main() {
    int a = 2;
    return a + 2;
}

pointer

int main() {
    int a[2];
    *a = 1;
    *(a + 1) = 2;
    int *p;
    p = a;
    return *p + *(p + 1);
}
int main() {
    int a[2];
    *a = 1;
    return *a;
}
int main() {
    int x = 100;
    int a = 200;
    int b = 300;
    int *p = &x;
    p = p + 2;
    return *p;
}
int main() {
    int x = 3;
    int *y = &x;
    return *y;
}
int main() {
    int x = 100;
    int a = 200;

    int *p = &x;
    p = p + 1;
    return *p;
}
int main() {
    int x = 100;
    int a = 200;

    int *p = &a;
    p = p - 1;

    return *p;
}
int main() {
    int x = 0;
    int *y = &x;
    *y = 3;
    return x;
}
int main() {
    int x = 100;
    int a = 200;

    int *p = &a;
    p = p - 1;

    return *p;
}

collections

int main() {
    int a[2] = {1, 2};
    return a[0];
}
int main() {
    int a[2];
    *a = 1;
    return a[0];
}
int main() {
    int a[10] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
    return a[9];
}
int main() {
    int a[2];
    a[0] = 1;
    return a[0];
}
int main() {
    int a[2];
    *a = 1;
    return *a;
}
int main() {
    int a[2];
    a[0] = 1;
    a[1] = 2;
    return a[1];
}
int main() {
    int a[2];
    a[0] = 1;
    return *a;
}
int main() {
    char a[3] = "abc";
    return 0;
}
int main() {
    char *a = "ABC";
    return *a;
}
int main() {
    char *a = "ABCDEF";
    return a[5];
}

branches

int main() {
    int foo = 10;
    int z = 0;
    if (foo / 2 == 2)
        z = 50;
    else
        z = 100;
    return foo + z;
}
int main() {
    int foo = 4;
    int z = 5;
    if (foo / 2 == 2) z = 50;
    return foo + z;
}
int main() {
    int foo = 100;
    int z;
    if (foo / 2 == 50) {
        z = 50;
    } else {
        z = 100;
    }
    return foo + z;
}

loop

int main() {
    int i = 0;
    while (i < 10) i = i + 1;
    return i;
}
int main() {
    int i = 0;
    for (i = 1; i < 10; i = i + 2) {
        i = i - 1;
    }
    return i;
}

function

int foo(int i) {
    return i;
}

int main() {
    int a = foo(10);
    return 10;
}

builtin function

int main() {
    int x = 0;
    return sizeof(x);
}

comments

int main() {
    /*
     * comment
     */
    return 0;
}
int main() {
    // comment
    return 0;
}

ubcc's People

Contributors

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