Skip to content
Thiago Baptista edited this page Dec 13, 2024 · 6 revisions

Writing code in Check Lang

Naming rules

Names must start with a letter and can only contain letters, numbers and underscores. This language is case sensitive and there is no limit to a name length.

Variable declaration and assignement

There currently are 4 types in Check Lang, those being:

  • Number
  • String
  • Boolean
  • Array

Variables are declared following this syntax "var" name "=" expression ";". For example: var example = 1; or using an expression var example = 2 * (3 - 4);

You can assign a new value to a variable following this syntax name "=" expression ";". For example example = 2; or using an expression var example = 10 + (2 * 3);

Arrays are defined using square brackets, like so: var arr = [1, 2, 3];

Arrays

Arrays are not typed in Check Lang, they can have elements of multiple types inside of them.

You can access an index of an array with following this syntax: ( name | array ){ "[" expression "]" }

Indexes in this language are "0" based.

Some examples are:

[1, 2, 3][0]; /* Gets the value "1" */

var arr = [4, 5, 6];
arr[1]; /* Gets the value "5" */

var 2D_Arr = [[1, 2], [3, 4]];
2D_Arr[1]; /* Gets the value "[3, 4]" */
2D_Arr[1][0]; /* Gets the value "3" */

You can set the value of an index of an array following this syntax: name { "[" expression "]" } "=" expression ";"

Some examples are:

var arr = [4, 5, 6];
arr[1] = 10; /* New array: [4, 10, 6] */

var 2D_Arr = [[1, 2], [3, 4]];
2D_Arr[1] = [30, 40]; /* New array: [[1, 2], [30, 40]] */
2D_Arr[0][0] = 10; /* New array: [[10, 2], [30, 40]] (The array was modified twice, and the changes on the last line stand) */

Conditions

A condition follows this syntax: expression ( logic_operator expression ).

The expression, must result in a boolean value. Some examples of a condition are:

value1 > value2
( value1 / value2 ) < value3
( value1 < value2 ) && ( value1 > value3)

Here are the logic operators for this language:

  • ==
    • Equals
  • !=
    • Not Equals
  • <
    • Less than
  • <=
    • Less than or equals
  • >
    • Greater than
  • >=
    • Greater than or equals
  • ||
    • Or
  • &&
    • And

If statements

In Check Lang, an If Statement is writting following this syntax "if" "(" condition ")" "{" code "}" ( "else" "{" code "}" )?. The Else Statement is optional.

Here are some examples of an If Statement:

var a = 10;
var b = 2;

if(a > b) {
  printLn("a is bigger than b")
} else {
  printLn("a is smaller than b")
}

if(a == (b * 5)) {
  printLn("b is 5x smaller than a")
}

The output of this code is:

a is bigger than b
b is 5x smaller than a

While Loop

A While Loop follows this syntax: "while" "(" condition ")" "{" code "}".

Here's an example of a while loop:

var isBiggerThan10 = false;
var index = 0;

while(isBiggerThan10 != true) {

 index = index + 1;

 if(index > 10) {
  isBiggerThan10 = true;
  printLn("The index is: ", index);
 }

}