Operator Precedence¶
Postfix operations bind most tightly. Binary groups then bind in the order shown below, from tightest to loosest.
| Binding order | Forms |
|---|---|
| Postfix | calls, .member, [], [&], ->, <-, ??, !?, ++, --, !!, #!! |
| Bitwise | #&&, #!&, #^^, #!|, #||, #^>, #^<, #!^, #++, #--, #+%, #-% |
| Multiplication | * |
| Addition and subtraction | +, - |
| Division and remainder | /, % |
| Conversion | AS with an optional conversion mode |
| Type or option test | ISA Type, IS option |
| Comparison | <=>, ==, !=, <, >, <=, >= |
| Logical | &&, !&, ^^, !|, ||, ^>, ^<, !^ |
| Assignment and swap | :=, <->, and compound assignments |
The current grammar gives * tighter binding than + and -, but gives +
and - tighter binding than / and %. It also gives bitwise operators
tighter binding than arithmetic. These choices differ from C-family
precedence, so parenthesize mixed expressions when the intended grouping is not
immediately visible:
VAR quotient I32 := (left + right) / divisor;
VAR masked I32 := (value + offset) #&& mask;
VAR selected BOOL := (left < right) && enabled;
Postfix chains¶
Calls, member selection, indexing, and pointer operations can form one chain:
AS, ISA, and IS bind after a complete higher-precedence operand.
Parentheses specify the grouping when a cast or fusion test participates in
additional arithmetic or member access.
Operator overloads use the same table as built-in operations; a type cannot define a new precedence. See User-defined operators, Arithmetic operators, Comparison operators, Logical operators, and Bitwise operators.
Range suffixes¶
The checked ? and assumed-in-range ! variants of arithmetic, shifts, and
rotations retain the precedence of their ordinary operator. Their compound
assignment forms, such as +=? and #++=!, have assignment precedence.