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.
expression ::= constant | identifier | binaryop | complement | call
identifier ::= identifier
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.
complement ::= "~" expression
~expression results in the bitwise complement of expression.
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.
boolexpr ::= constant_bool | readbit | comparison | logic | not
constant_bool ::= "true" | "false"
readbit ::= expression "@" integer
The result of expression@4 is the fourth bit of the value of expression.
comparison ::= expression (">" | ">=" | "==" | "<=" | "<" | "!=") expression