Operators are used to perform operations on labels in expressions.
Remarks
Operators are evaluated in a particular order, referred to as operator precedence. Brass uses the same order of precedence that C# uses, documented in the following table. The higher up the table an operator is, the sooner it is evaluated.
| Label Access | : |
|---|---|
| Unary | +, -, !, ~, ++x, --x |
| Power | ** |
| Multiplicative | *, /, % |
| Additive | +, - |
| Shift | <<, >> |
| Relational | <, >, <=, >= |
| Equality | ==, != |
| Logical | & |
| ^ | |
| | | |
| Conditional | && |
| || | |
| Assignment | =, +=, -=, *=, /=, %=, &=, |=, ^=, <<=, >>= |
| Indexing | a[x] |
If two operators in the same group appear in the expression, the order in which they are evaluated depends on their associativity. Most operators are left-associative; that is they are evaluated in order from left to right. However, the assignment operators are right-associative and are thus evaluated in order from right to left.
You can use parentheses to cause an inner expression to be evaluated before its peers.
WarningSome assemblers do not take operator precedence into account and simply evaluate from left to right.
Example
Using parentheses to boost the precedence of an operator.
.echoln 2 + 3 * 2 ; Outputs 8.
.echoln (2 + 3) * 2 ; Outputs 10.
Some assemblers do not take operator precedence into account and simply evaluate from left to right.