-
Notifications
You must be signed in to change notification settings - Fork 0
Builtin
Basic integer type. It's guaranteed to be at least 32 bit.
Type which supports only two values: true and false. Those values are globally defined constants.
Literal represented by number literal lexical element. The only allowed characters are digits (0 - 9).
Implicitly convertible to Int type and type deduction yields Int type.
Declare a variable with given name for current scope. Symbol name (identifier) must be unique within declaration scope. It can be same as another symbol in parent scope but it hides the parent symbol.
The variable can have specified type and optionally initial value. If variable type is not specified there is no restriction on type which can the variable hold, otherwise the variable cannot hold value of other type.
variable_declaration:
'var' identifier [ : typename ] [ '=' expression ] ';'
var foo = 10;
foo = "Hello"; // Ok
var bar: Int;
bar = 10; // Ok
bar = "Hello"; // Error
Declare a constant with given name for current scope. Symbol name (identifier) must be unique within declaration scope. It can be same as another symbol in parent scope but it hides the parent symbol.
The constant can have specified type but it's not required since the type is deduced from expression. If specified constant type is not same as expression result type the program is invalid.
constant_declaration:
'const' identifier [ : typename ] '=' expression ';'
Declares a function available under given symbol name (identifier). It's possible to declare another function with same name but it must have different list of parameter types (function overloading).
Function must always return some value according to the return type using return statement. Only exception is special return type void in which case the function doesn't return anything - the return statement still can be used without expression to left the function execution.
It's possible to leave function body execution early using return statement.
function_declaration:
'func' identifier parameters [ : return_type ] function_body
return_type:
typename
'void'
parameters:
'(' ')'
'(' parameter_list ')'
parameter_list:
parameter
parameter_list ',' parameter
parameter:
identifier [ : typename ]
function_body:
compound_statement
Statement for branching. It consists condition expression (boolean), statement which is executed in case when condition expression is evaluated to true and optional else statement executed in case of false condition.
if_statement:
'if' '(' expression ')' statement [ 'else' statement ]
The basic loop type when the expression is evaluated and when the result is true the statement is executed.
while_statement:
'while' '(' expression ')' statement
Statement which allows to leave function and return optional result. The result value is result of the evaluated expression. The return value type must match the evaluated expression type.
When no expression is provided there is no return value.
return_statement:
'return' [ expression ] ';'