khollang

Introduction

khollang is an educational programming language made in Python. It has simple pseudocode-like syntax and an ability to limit different parts of its functionality

Usage

Locally

You can copy a folder interpreter where you can run a file main.py using Python of version 3.10.x+. This file takes two command line arguments: code file and limits file. The code file is mandatory, limits file — not. Limits file is going to be described further.

Example of running:

python3 main.py code.txt limits.json

Additionally, this main.py you can compress in an executable, if needed

Online

You can access an online Khollang Interpreter

Syntax

Generals:

Basic operations

Basic data types

Operators

If conditions

Example:

if X < 0 then
    output -1
else if X = 0 then
    output 0
else
    output 1
end if

Match conditions

Example:

match X with
    case -1 then
        output -1
    case 0 then
        output 0
    otherwise
        output 1
end match

While loops

Example:

loop while X
    output X
end loop

Until loops

Example:

loop until X
    output X
end loop

For loops

Examples:

loop X from 1 to 10
    output X
end loop
loop for X from 1 to 10
    output X
end loop

Functions

Example:

function X(Y, Z)
    return Y + Z
end function

X(1, 2) // returns 3

Procedures

Example:

procedure X(Y, Z)
    output Y + Z
end procedure

X(1, 2) // outputs 3

Data structures

Custom structures

Example:

structure X
    A
    Number B
    C = "Value"
end structure

D = X()
output D.A // none
output D.B // 0
output D.C // "Value"

E = X(1, 2, "Value2")
output E.A // 1
output E.B // 2
output E.C // "Value2"

F = X(1, 2)
output F.A // 1
output F.B // 2
output F.C // "Value"

Limits and limits files

One of key features khollang is an ability to limit different parts of its functionality. It can be done by either providing a limits file locally or inserting limits online in an interpreter.

Local limits file

Local limits file can be either a JSON file or a text file. If it is JSON it has to follow this format:

{
    "limit1": value1, // integer or null
    "limit2": value2, // integer or null,
    ...
}

If it is a text file it has to follow this format:

limit1: value1 // integer or null
limit2: value2 // integer or null
...

Name of possible limits is listed further in this chapter.

Online limits

In an online interpreter there is an ability to insert limits. It can be done either by providing a limits file (the same as local file) or insert them in a text format directly

Available limits

All limits by default are assigned null