A programming language with an intepreter and a compiler written in a functional style using python for a school assigment.
A short segement about how to use the intepreter and compiler and how to write program supported by example code with comments.
# Install the package
pip install -e .
# Installs For using the compiler output execution (optional)
wsl --install
(wsl) sudo apt-get update
(wsl) sudo apt install qemu-user
(wsl) sudo apt install gcc-arm-linux-gnueabi
#For the interpreter
python ./KarkelLang.py [input file directory] --interpret
#For the compiler, compiles an .asm and .elf file
# It runs the output .elf in arm-qemu emulator
python ./KarkelLang.py [input file directory] --compile [output file]
This function calculates the modulo of 100 % 21
by implementing it's own divide and modulo.
& divide [# left, # right ] X # ~Function Declaration, return int~
<
# quotient <- 0! ~Int assigment~
O left <>> right ~While Loop [left => right]~
<
left <- left - right! ~Minus operator reassignment~
quotient <- quotient + 1! ~Plus operator reassignment~
>
quotient -> ! ~Return Value~
>
& modulo [# left, # right ] X # ~Function Declaration, return int~
<
# decrement <- right * divide[left, right]! ~Multiply operator with function call~
decrement <- left - decrement! ~Minus operator reassignment~
decrement -> ! ~Return Value~
>
& Main[] X # ~Main Function Declaration~
<
# num <- modulo[100, 21]! ~Function call assignment int~
num -> ! ~Return value~
>
- Integers, Chars, Strings(interpreter only) and Arrays(interpreter only)
- If statements (Example in test-if-statement-3.arw, line 3)
- While loops (Example in test-while-loop-2.arw, line 6 and 8)
- Function calls (Example in modulo.arw, line 14 and 21)
- This includes creating your own functions
- And calling functions within functions
- Multiple functions per file
- For the interpreter a theoretical unlimited amount of parameters and for the arm compiler, 3 parameters
- Multiple variable scopes (Example in test-fibonachi.arw, line 4)
- Detailed Error messages
- Classes with inheritance (astNode.py)
- Object printing for all classes using JSON.
- Type annotated
- Uses higher order functions
- map
- compiler.py
- line 432, compileFunctionBody
- line 452, compileFunctionDeclareNode
- line 461, generatePrint
- line 513, compilerRun
- interpreter.py
- line 567, ExecuteFunctionCallNode
- lexer.py
- line 100, lexer
- compiler.py
- reduce
- compiler.py
- lien 496, returnFile
- compiler.py
- zip
- interpreter.py
- line 563, ExecuteFunctionCallNode
- line 566, ExecuteFunctionCallNode
- interpreter.py
- map
- Multiple functions per file exmaple
- Calling functions within functions example
This language has a default flow of control, can store states, has conditional execution and repetition, which makes it able to execute/replicate the results of turing programs which makes it turing complete.