Next: Arithmetic
a - b + c could be parsed as
(a - b) + c or as a - (b + c). To resolve these
conflicts, each operator has two properties: precedence and
association.
Precedence determines whether an operator binds more tightly than
another operator; for instance, a + b * c is equivalent to
a + (b * c) because multiplication has higher precedence than
addition.
Association determines whether operators at the same precedence
level associate left to right or right to left; a - b - c is
equivalent to (a - b) - c because subtraction associates left to
right.
Here is a list of operators grouped by precedence, in order from highest precedence to lowest:
.
[]
! and unary -
* / %
+ -
== != > >= < <=
in
&&
||
?|
&&,
||, and ?| operators, which associate from right to left.
You can always use parentheses (( and )) to specify the
order of evaluation explicitly.