Page 38 of 229 Start Back Next End ZBasic Language Reference 28 ZBasic Microcontrollers The actual precedence level values are of no particular significance. All that matters is whether the precedence value of one operator is higher, equal to or lower than that of another operator. In the example used above, since the multiplication operator has higher precedence than the addition operator, the meaning of the expression is to multiply the value of the variable b by 5 and then add 3 to the result. It happens in this case that the order of application of the operators is left to right but that is not always the case. Consider this slightly different example: b = b + 5 * 3 The meaning of this expression is to multiply 5 by 3 and then add the value of the variable b to the result. The relative precedence level of the operators requires that they be applied in an order that is not left to right. BasicX Compatibility Note In BasicX mode, a different operator precedence set is used, as shown in the table below, in order to be compatible with BasicX. Operator Precedence Precedence Level Operators 5 (highest) ^ 4 +(unary) -(unary) 3 Not 2 * / \ Mod And 1 + - Or Xor & 0 (lowest) = < > <= >= <> 2.4.2 Operator Associativity After studying the precedence table in the preceding section, the obvious question would be what happens when two operators have the same precedence? b = b - 5 + 3 In case of equal precedence, the operators are applied in the order dictated by the associativity of the operator. Except for the exponentiation operator, all operators in ZBasic are left associative. This means that given equal precedence operators they are applied in left to right order. Exponentiation is right associative meaning that they will be applied in right to left order. However, no matter what the precedence levels are you can force the operators to be applied in any order that you wish by utilizing parentheses. Consider the two examples below. b = (b – 5) + 3 b = b – (5 + 3) The parentheses indicate that the expression within should be evaluated first after which the result may be used as an operand in another operation. 2.4.3 Arithmetic Operators The arithmetic operators are listed in the table below along with the permitted operand types. The result is the same type as the operands.