Skip to content

Peter-Schenkels/KarkelLang---HU-ATP

Repository files navigation

KarkelLang

A programming language with an intepreter and a compiler written in a functional style using python for a school assigment.

How to use it

A short segement about how to use the intepreter and compiler and how to write program supported by example code with comments.

Compiler and Interpeter usage

# 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]

Example code

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~
>

Language features

Requirements

  • 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
    • reduce
    • zip
      • interpreter.py
        • line 563, ExecuteFunctionCallNode
        • line 566, ExecuteFunctionCallNode
  • Multiple functions per file exmaple
  • Calling functions within functions example

Turing completeness

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.

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published