Appendix B: Operators
This document lists ZuzuScript expression operators, ordered from highest precedence to lowest precedence.
Precedence summary table (highest to lowest)
Notes
- Higher rows bind tighter than lower rows.
- Most binary operators are left-associative.
**is right-associative.⊤and⊥are boolean literals, not operators, so they do not appear in the precedence table.?:,? :, and assignment operators are parsed after the Pratt precedence table, so they behave as the lowest-precedence expression forms.- Postfix forms (call/member/index/dict access/postfix
++/--) are parsed immediately after primaries and therefore bind tighter than all infix operators.
| Level | Associativity | Operators |
|---|---|---|
| Postfix | left-to-right chaining | (...) (call), .name, .(expr)(...), [index], [start:length], {key}, postfix ++, postfix -- |
| Prefix | right-to-left nesting | unary +, unary -, !, ¬, unary ~, unary √, unary \\ (reference), not, abs, sqrt, floor, ceil, round, int, uc, lc, length, typeof, prefix ++, prefix -- |
| 13 | right-to-left | ** |
| 12 | left-to-right | *, /, ×, ÷, mod |
| 11 | left-to-right | +, - |
| 10 | left-to-right | _ |
| 9 | left-to-right | union, ⋃, intersection, ⋂, \\, ∖ |
| 8 | left-to-right | & |
| 7 | left-to-right | ^ |
| 6 | left-to-right | | |
| 5 | left-to-right | =, ≠, <, >, <=, ≤, >=, ≥, <=>, ≶, ≷, eq, ne, gt, ge, lt, le, cmp, eqi, nei, gti, gei, lti, lei, cmpi, in, ∈, ∉, subsetof, ⊂, supersetof, ⊃, equivalentof, ⊂⊃, instanceof, does, can, binary ~, @, @?, @@ |
| 4 | left-to-right | ==, ≡, !=, ≢ |
| 3 | left-to-right | and, ⋀, nand, ⊼ |
| 2 | left-to-right | xor, ⊻ |
| 1 | left-to-right | or, ⋁ |
| Ternary | right-to-left grouping in practice | ? :, ?: |
| Assignment | right-to-left grouping in practice | :=, ~=, +=, -=, *=, ×=, /=, ÷=, **=, _=, ?:= |
Detailed table
| Operator | Aliases | Kind | Precedence | Definition |
|---|---|---|---|---|
| Mathematical operators and numeric comparisons | ||||
+ |
Unary prefix | Numeric identity. | ||
- |
Unary prefix | Negative number. | ||
√ |
sqrt |
Unary prefix | Square root. | |
abs |
Unary prefix | Absolute value. | ||
floor |
Unary prefix | Round down to the nearest integer. | ||
ceil |
Unary prefix | Round up to the nearest integer. | ||
round |
Unary prefix | Round to the nearest integer. | ||
int |
Unary prefix | Convert to an integer value. | ||
** |
Binary infix | 13 | Exponentiation. | |
× |
* |
Binary infix | 12 | Multiplication. |
÷ |
/ |
Binary infix | 12 | Division. |
mod |
Binary infix | 12 | Remainder after division. | |
+ |
Binary infix | 11 | Addition. | |
- |
Binary infix | 11 | Subtraction. | |
= |
Binary infix | 5 | Numeric equality. | |
≠ |
Binary infix | 5 | Numeric inequality. | |
< |
Binary infix | 5 | Less than. | |
> |
Binary infix | 5 | Greater than. | |
≤ |
<= |
Binary infix | 5 | Less than or equal to. |
≥ |
>= |
Binary infix | 5 | Greater than or equal to. |
≶ |
<=>, ≷ |
Binary infix | 5 | Numeric three-way comparison. |
| String operators and string comparisons | ||||
uc |
Unary prefix | Uppercase string conversion. | ||
lc |
Unary prefix | Lowercase string conversion. | ||
length |
Unary prefix | String length. | ||
_ |
Binary infix | 10 | String concatenation. | |
eq |
Binary infix | 5 | Case-sensitive string equality. | |
ne |
Binary infix | 5 | Case-sensitive string inequality. | |
gt |
Binary infix | 5 | Case-sensitive string greater-than comparison. | |
ge |
Binary infix | 5 | Case-sensitive string greater-than-or-equal comparison. | |
lt |
Binary infix | 5 | Case-sensitive string less-than comparison. | |
le |
Binary infix | 5 | Case-sensitive string less-than-or-equal comparison. | |
cmp |
Binary infix | 5 | Case-sensitive string three-way comparison. | |
eqi |
Binary infix | 5 | Case-insensitive string equality. | |
nei |
Binary infix | 5 | Case-insensitive string inequality. | |
gti |
Binary infix | 5 | Case-insensitive string greater-than comparison. | |
gei |
Binary infix | 5 | Case-insensitive string greater-than-or-equal comparison. | |
lti |
Binary infix | 5 | Case-insensitive string less-than comparison. | |
lei |
Binary infix | 5 | Case-insensitive string less-than-or-equal comparison. | |
cmpi |
Binary infix | 5 | Case-insensitive string three-way comparison. | |
~ |
Binary infix | 5 | Regexp match. | |
| Bitwise operators | ||||
~ |
Unary prefix | Bitwise NOT. | ||
& |
Binary infix | 8 | Bitwise AND. | |
^ |
Binary infix | 7 | Bitwise XOR. | |
| |
Binary infix | 6 | Bitwise OR. | |
| Logical operators | ||||
! |
Unary prefix | Logical negation. | ||
¬ |
not |
Unary prefix | Logical negation. | |
⋀ |
and |
Binary infix | 3 | Logical AND. |
⊼ |
nand |
Binary infix | 3 | Logical NAND. |
⊻ |
xor |
Binary infix | 2 | Logical XOR. |
⋁ |
or |
Binary infix | 1 | Logical OR. |
| Set operators and set comparisons | ||||
⋃ |
union |
Binary infix | 9 | Set union. |
⋂ |
intersection |
Binary infix | 9 | Set intersection. |
∖ |
\ |
Binary infix | 9 | Set difference. |
∈ |
in |
Binary infix | 5 | Membership test using type-aware equality. |
∉ |
Binary infix | 5 | Negative membership test. | |
⊂ |
subsetof |
Binary infix | 5 | Subset test. |
⊃ |
supersetof |
Binary infix | 5 | Superset test. |
⊂⊃ |
equivalentof |
Binary infix | 5 | Set equivalence test. |
| Path operators | ||||
@ |
Binary infix | 5 | Evaluate a path and return the first match. | |
@@ |
Binary infix | 5 | Evaluate a path and return all matches. | |
@? |
Binary infix | 5 | Check whether a path has at least one match. | |
| OO / type related operators | ||||
typeof |
Unary prefix | Return the runtime type name. | ||
instanceof |
Binary infix | 5 | Inheritance-aware type or class check. | |
does |
Binary infix | 5 | Trait implementation check. | |
can |
Binary infix | 5 | Method availability check. | |
≡ |
== |
Binary infix | 4 | Type-aware equality. |
≢ |
!= |
Binary infix | 4 | Type-aware inequality. |
| Assignment operators | ||||
:= |
Assignment infix | Assign a new value. | ||
~= |
Assignment infix | Regexp-replace assignment. | ||
+= |
Assignment infix | Add and assign. | ||
-= |
Assignment infix | Subtract and assign. | ||
×= |
*= |
Assignment infix | Multiply and assign. | |
÷= |
/= |
Assignment infix | Divide and assign. | |
**= |
Assignment infix | Exponentiate and assign. | ||
_= |
Assignment infix | Concatenate and assign. | ||
?:= |
Assignment infix | Assign only when the current value is undefined or null-like. | ||
| Other operators | ||||
++ |
Postfix | Increment and return the previous value. | ||
-- |
Postfix | Decrement and return the previous value. | ||
++ |
Unary prefix | Increment and return the new value. | ||
-- |
Unary prefix | Decrement and return the new value. | ||
\ |
Unary prefix | Create an lvalue reference. | ||
? : |
Ternary | Conditional expression with true and false branches. | ||
?: |
Ternary | Elvis-style short ternary with a fallback value. | ||
Ambiguous tokens by role
Some tokens are valid in more than one role:
~is both unary bitwise-not (prefix) and binary regexp-match.\\is both unary reference (prefix) and binary set difference.+and-can be unary (prefix) or binary arithmetic.++and--can be prefix or postfix.
When mixing forms, parentheses are recommended for readability.
This matters especially for path lvalues. When applying prefix/postfix ++ or --, or unary reference \\, to data @ path, data @@ path, or data @? path, parenthesize the path expression:
( data @ "/meta/count" )++; ++ ( data @@ "/users/*/age" ); \( data @? "/meta/title" );