Skip to content

Language Features

Cuber01 edited this page Oct 7, 2025 · 4 revisions

Language Features

Expressions

Binary

Supported operators: +, -, *, :

1 + 1; // 2
"str" + "ing"; // string

1 - 1; // 0
2 * 4; // 8
4 / 2; // 2

Logical

Supported operators: ||, &&

true || false; // true
true && false; // false

Unary

-1; // -1
!true; // false

Literal

// Numbers
1;
2.3;

// True and false
true;
false;

// Strings
"Hello World!"

Grouped

(2 + 2) * 4; // 16

Ternary

1 == 1 ? true : false; // If 1 == 1 then true else false (Expected: true) 

Variables

Variables can hold value of any of the following types:

  • number (double)
  • string
  • boolean
  • null
  • instance
  • function/method
  • class
var a; // null
var b = 1; // 1
var a = 3; // Error: Redefining is illegal

b = 4;

Functions

Function can return any valid value via the return statement. If unspecified or there's no return, they return null.

function betterPrint(text)
{
    print(text);
}

betterPrint("Hello World!");

function nothing()
{
}

function nothingButBetter()
{
    return null;
}

function something()
{
    return true;
}

var a = nothing(); // null
a = nothingButBetter(); // null
a = something(); // true

Control flow

If

if(true)
{
    print("Truth!");
} 
else if (false)
{
    print("Unreachable");
}

Loops

Finite

var i = 10;

while(i > 0)
{
    print(i);
    i--;
}

for (var i = 1; i < 100; i++)
{
    print(i);
}

Infinite

while(true)
{

}

for(;;)
{

}

Break and Switch

while(true)
{
    continue;
    print("Unreachable.");
}
while(true)
{
    break;
}

print("Reachable.");

Syntax sugar

var a = 5;

a++; // 6
a += 2; // 8
a -= 3; // 5
a *= 2; // 10
a /= 2; // 5
a--; // 4

Arrays

var a = [0, 1, 2];

a[0] = "str";

var i = 0;
while(i < 6)
{
    print(a[i]);
    i++;
}

// Expect: str
// Expect: 1
// Expect: 2

Classes and instances

Class Declarations

Class declarations can contain methods and a constructor - init(). init() is called during the creation of an instance from a class. It returns the newly created instance and therefore cannot return a custom value.

class Human
{
    init() 
    {
        print("I am alive!");
    }

    quote() // Method declaration
    {
        print("Bla bla");   
    }
}

Instances

class Human
{
    init()
    {
        print("I am alive!");
        this.dialogue = "I have nothing interesting to say.";
    }

    talk()
    {
        print("Hi, I am " + this.name ".");
    }
}

var person = Human(); // Print: I am alive!
person.name = "Billy";
person.talk(); // Print: Hi, I am Billy.

this.dialogue; // "I have nothing interesting to say."

Inheritance

Inherit methods from other classes. Overriden methods are available using base.method() syntax.

class Artificer
{
    constructStuff()
    {
        print("I made a drill using scrap from the wall!");
    }

    yell()
    {
        print("I am an artificer!");
    }    
}

class Alchemist : Artificer
{
    brew()
    {
        print("I made a potion!");
    }

    yell()
    {
        print("I am an alchemist!");
        base.yell();
    }    
}

var a = Alchemist();
a.brew(); // Print: "I made a potion!"
a.constructStuff(); // Print: "I made a drill using scrap from the wall!"
a.yell(); // Print: "I am an alchemist!" "I am an artificer!"