2. Expressions

2.1. Operator precedence

Operator precedence is as follows:

Operator Associativity
! ~ right
* left
+ - left
== != left
&& left
|| left
& left
| left

If there are multiple ways to parse a section of the source code, the precedence rules apply. The operators bind to their arguments in the order they appear in the table. If two operators appear in the same row, they are bound in the order they appear in the source code.

Operators not specified in this table cannot be parsed ambiguously.

2.2. Integer expressions

expression ::=  constant | identifier | binaryop | complement | call

2.2.1. Constants

constant ::=  integer

A constant evaluates to its value.

2.2.2. Identifiers

identifier ::=  identifier

2.2.3. Binary operators

binaryop ::=  expression ("+" | "-" | "*" | "&" | "|" | "^") expression

The standard mathematical operators +, - and * result in left (operator) right.

left & right results in the bitwise AND of left and right.

left | right results in the bitwise OR of left and right.

left ^ right results in the bitwise XOR of left and right.

2.2.4. Unary operators

complement ::=  "~" expression

~expression results in the bitwise complement of expression.

2.2.5. Function calls

call     ::=  identifier "(" callargs? ")"
callargs ::=  datatype identifier ("," callargs)?

The result of a function call is the return value of that function.

foo.bar(123, something) calls foo.bar with 123 and something as arguments.

2.3. Boolean expressions

boolexpr ::=  constant_bool | readbit | comparison | logic | not

2.3.1. Constants

constant_bool ::=  "true" | "false"

2.3.2. Read bit

readbit ::=  expression "@" integer

The result of expression@4 is the fourth bit of the value of expression.

2.3.3. Comparisons

comparison ::=  expression (">" | ">=" | "==" | "<=" | "<" | "!=") expression

2.3.4. Boolean logic

logic ::=  boolexpr ("&&" | "||" | "==" | "!=") boolexpr
not   ::=  "!" boolexpr

left && right results in left AND right.

left || right results in left OR right.

!value results in NOT value.