Operators, precedence and associativity

Operators in a Rule expression are evaluated based on their order of precedence. For example, * has a higher precedence than + so the expression 1 + 2 * 3 is evaluated as 1 + (2 * 3) which equals 7 rather than it being evaluated as (1 + 2) * 3 which equals 9. If two operators in an expression have the same precedence then they are evaluated based on their associativity. Left associative operators are evaluated from left to right. Right associative operators are evaluated right to left. For example, a * b / c is evaluated as (a * b) / c. Default precendence and associativity can be overridden in an expression using parentheses ( ).

Operator precedence and associativity is identical to most high level languages. The table below lists the operator categories ordered by precedence from highest to lowest.

The alternative column contains an alternative symbol for an operator. As the rules are often used in XML documents the alternative symbol may be useful for operators which would otherwise conflict with the XML markup. The alternative symbols are case-insensitive.

Category Operator Alternative Associativity
Unary !
+
-
not
 
 
Right
Right
Right
Multiplicative *
/

Left
Left
Additive +
-

Left
Left
Relational <
>
<=
>=
lt
gt
le
ge
Left
Left
Left
Left
Equality ==
!=
eq
ne
Left
Left
And && and Left
Or || or Left

The equality operators can be used with boolean operands or numeric operands but both operands must be the same type. That is, a boolean operand cannot be compared with a numeric operand for equality.