8.26 Operator Precedence
Operator precedence in falling priority:
: | |
# | |
Unary + - bnot not | |
/ * div rem band and | Left associative |
+ - bor bxor bsl bsr or xor | Left associative |
++ — | Right associative |
== /= =< < >= > =:= =/= | |
andalso | |
orelse | |
= ! | Right associative |
catch |
Table 8.6: Operator Precedence
When evaluating an expression, the operator with the highest priority is evaluated first. Operators with the same priority are evaluated according to their associativity.
Example:
The left associative arithmetic operators are evaluated left to right:
- 6 + 5 * 4 - 3 / 2 evaluates to
- 6 + 20 - 1.5 evaluates to
- 26 - 1.5 evaluates to
- 24.5