8.26 Operator Precedence

Operator precedence in falling priority:

:
#
Unary + - bnot not
/ * div rem band andLeft associative
+ - bor bxor bsl bsr or xorLeft 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:

  1. 6 + 5 * 4 - 3 / 2 evaluates to
  2. 6 + 20 - 1.5 evaluates to
  3. 26 - 1.5 evaluates to
  4. 24.5