Skip to content

Statements

A function or control structure body consists of a potentially empty list of statements. There are 2 kinds of statements, and one statement modifier (labels).

Block         = '{' { Statement } '}'
ControlBlock  = Statement | Block

Statement     = VarDecl | AssignStmt | ControlStmt | ExpressionStmt ;

Variable Declarations

A variable declaration binds variable names to their associated type without an initialization expression.

VarDecl  = "var" Identifier [ { ',' Identifier } ] ':' Type ';' ;

Assignment Statements

Assign statements consist of left-hand side target variables and a right-hand side expression. In the case of multiple return values, more than one target variable must be present. Target variable may either be declared with their respective types or assigned.

AssignStmt  = VarList '=' Expression ';' ;

VarList     = Var { ',' Var } ;
Var         = Identifier [ ':' Type ] | Identifier '.' Identifier ;

Assignments copy the right-hand side if necessary (may be omitted if the expression is a function call).

Control Statements

Both structured an unstructured control-flow are supported for conditional execution and jumps.

ControlStmt  = IfStmt    | WhileStmt | RepeatStmt | ReturnStmt |
               BreakStmt | ContinueStmt ;

Condition    = Operand ;

The condition of a control-flow statement must be a scalar value (i.e. a vector of 1 element). For convenience, two built-in functions @any and @all reduce a vector to a single value for conditional execution:

  • @any returns true if any value in a vector is true
  • @all returns true only if all values in a vector are true

If-ElseIf-Else

An if-elseif-else statement provides conditional execution of blocks of code. The condition must be a boolean scalar, and the else-if and else clauses are optional.

IfStmt  = "if" '(' Condition ')' ControlBlock [ "else" ControlBlock ]

While and Repeat

A while loop executes its body until its condition evaluates to false. The condition must be a boolean scalar. A repeat statement executes the body a fixed number of iterations. The condition must be an integer scalar.

WhileStmt   = "while" '(' Condition ')' ControlBlock ;
RepeatStmt  = "repeat" '(' Condition ')' ControlBlock ;

Return

A return statement exits the function and optionally returns a list of values to its calling context.

ReturnStmt  = "return" [ { Operand { ',' Operand } ] ';' ;

Break and Continue

A break statement exits a loop, whereas a continue statement jumps to the next iteration. Break and continue statements may optionally specify a label corresponding to a conditional statement.

BreakStmt     = "break" ';' ;
ContinueStmt  = "continue" ';' ;

:::info NOTES: - break or continue can only appear inside a loop body (i.e. while and repeat) :::

Expression Statements

An expression statement evaluates a non-value expression. Either a built-in or user-defined function that has return value.

ExpressionStmt  = Expression ';'