keosariel / gabby-lang

A simple programming language using llvmlite in python3
43 stars 9 forks source link
compiler demo language language-syntax lexer llvm llvm-ir llvmlite parser python python3

Programming language in python using llvmlite

This is simply a compiler for a simple language, built with Python 3.6+ and the LLVM framework using the llvmlite library.

Features

Install the requirements

pip install -r requirements.txt

Code examples

These are all working perfectly

Factorial Function

def fact(n:int):int{
    if n <= 1{
        return 1
    }
    return n * fact(n-1)
}

def main():int{
    return fact(6)
}

Conditionals

def main():int{

    age = 18
    if age == 18{
        printf('wow you are 18\n')
    }else{
        printf('i guess you are not 18\n')
    }

    return 0
}

Loops

def main():int{

    printf('while loop\n')
    x = 0
    while x < 10{
        printf('x = %i\n',x)
        x = x+1
    }

    printf('Until loop\n')

    x = 0
    until x > 10{
        printf('x = %i\n',x)
        x = x+1
    }

    return 0
}

You can also run the mandelbrot set program in the test folder

How to run it

python run.py <filename>