A program comprises of function definitions, one of which is executed at startup (main by default).
Types may be declared const which means their value may not change.
int- 64-bit signed integer typefloat- IEEE 754 double-precision typestr- text stringfile- file descriptorbool- booleanvoid- type used to mark functions as not value returning
Supported operators for given types are:
- numeric:
- arithmetic
+ - * / - comparative
< > <= >= == !=
- arithmetic
- integer:
- modulo
%
- modulo
- string:
- concatenation
| - comparison
== !=
- concatenation
- boolean:
- logical
not,and,or
- logical
Variables are statically and strongly typed and must have value at all times. The first assignment to the variable must take place on its declaration.
variable_name: type = value;
A variable is visible within a function call context and only inside the code block it was declared in. Variables declared in inner blocks shadow over ones declared in outer ones.
The assignment var1 = var2; means copying contents of var2 and assigning it to var1.
Functions are defined as such:
fun name(parameter1: type, parameter2: type): return_type {
# do stuff...
}
Arguments are passed as references (if possible). If a local copy is needed it may be obtained through copy on assignment.
Constructs analogous to C ones:
- while loop
while(condition) {instructions;} - if instructions:
if(condition){instructions;}if(condition){instructions;} else{other_instructions;}if(condition){instructions;} else if(condition2){other_instructions;}if(condition){instructions;} else if(condition2){other_instructions;} else...etc.
matchinstruction/expression (described below)
Conditions must evaluate to boolean values.
match(expression1, expression2, ...){
pattern1: expression,
pattern2: expression,
(...)
_: default_expression
}
Patterns are composed of special expressions and have as many elements as there are match arguments. A pattern element may be an expression, a single-argument function identifier or a single-sided comparison expression. An element is evaluated into a value and the relation of its and metch argument's types determines the acceptance criterium:
- element value type same as match argument type -> accepted if values are equal
- element value is boolean and argument type is different -> accepted if element value is true
- different combination of types -> no match
Underscore _ indicates that we don't care about a specific match argument in a pattern.
Match statement is also an expression. If no pattern matches arguments when assigning match expression to a variable an error occurs.
Program argument handling:
arguments_number(): int- return number of arguments given to the programargument(index: int): str- returns an argument as a string
Conversion functions:
to_str_int(num: const int): strto_str_float(num: const float): strto_int_float(num: const float): intto_float_int(num: const int): float
Input/output:
print(string: const str): void- printstringto the output streamopen_file(filename: const str): fileclose_file(file_descriptor: file): voidbad_file(file_descriptor: file): bool- returns true if file is opened correctly and can be read fromread_line(file_descriptor: file): str- reads a line from file
Formal specification of the language in EBNF/regex can be found in the language_specification catalog.