Operators Priority

Operators have precedence and, in the case of binary operators, associativity.

Precedence can be altered using parentheses (...).

For example, a + b + c is equivalent to (a + b) + c.

In general, Ad Astra's operator precedence is similar to the rules in Rust and many other languages with C-like syntax.

OperatorsPrecedenceAssociativity
Assignment: a = b, a += b, etc1Right-to-Left
Binary disjunction: a || b2Left-to-Right
Binary conjunction: a && b3Left-to-Right
Equality and ordering: a == b, a > b, etc4Left-to-Right
Range operator: 10..205Left-to-Right
Bitwise disjunction: a | b6Left-to-Right
Bitwise exclusive disjunction: a ^ b7Left-to-Right
Bitwise conjunction: a & b8Left-to-Right
Bitwise shift: a << b and a >> b9Left-to-Right
Additive: a + b and a - b10Left-to-Right
Multiplicative: a * b, a / b, and a % b11Left-to-Right
Unary Left: -a, *a, !a12Left-to-Right
Unary Right: a?, a(arg), a[idx], a.field13Left-to-Right
Atomic operand: ident, crate, self, max14Left-to-Right

Operators with a higher precedence number take priority over those with a lower precedence number: a + b * c means a + (b * c), because multiplicative precedence is higher than additive.

Associativity indicates the typical order of operand evaluation. In the expression a = b + c, the b + c expression is evaluated before a.