logo

Show HN: A toy compiler I built in high school (runs in browser)

Posted by xeouz |2 hours ago |1 comments

xeouz an hour ago

OP here! If anyone is curious about the syntax without opening the demo, here is an implementation of insertion sort:

extern puti(n: int);

func sort(arr: int[5]) {

    let i=0;
    let key=0;
    let j=0;

    for(i=0; i<5; ++i)
    {
        key = arr[i];
        j = i-1;

        while(j>=0)
        {
            if(arr[j] < key)
            {
                break;
            }

            arr[j + 1] = arr[j];
            j-=1;
        }

        arr[j + 1] = key;
    }
}

let arr=[61,86,53,19,61];

sort(arr);

for(let i=0; i<5; ++i) {

    puti(arr[i]);

}