Boolean operators precedence

I googled and found out this which says that some languages like APL and SmallTalk do not have operator precedence rules and they strictly evaluate expressions from left to right/left to right.

However,relative order of precedence followed is NOT > XOR > AND > OR in most of the languages especially those derived from C


You have seen that when expressions mix && with || that evaluation must be done in the correct order. Parentheses can be used to group operands with their correct operator, just like in arithmetic. Also like arithmetic operators, logical operators have precedence that determines how things are grouped in the absence of parentheses.

In an expression, the operator with the highest precedence is grouped with its operand(s) first, then the next highest operator will be grouped with its operands, and so on. If there are several logical operators of the same precedence, they will be examined left to right.

It is common for programmers to use parentheses to group operands together for readability even when operator precedence alone would work.

enter image description here

Source


There are three basic Boolean operators: NOT, AND, OR. XOR is just a simple version of A AND NOT B OR NOT A AND B or (A OR NOT B) AND (NOT A OR B). So, only these three have common precedence: NOT > AND > OR. XOR has different position in languages, but it has surely not higher precedence than AND and not lower than OR. Most languages (e.g. C/C++/Javascript etc.) have it between AND and OR, but in other ones (e.g. Perl) XOR has the same precedence as OR.

(OR can be expressed using only AND and NOT, but it is still a basic operator: A OR B = NOT(NOT A AND NOT B))


Boolean or bitwise? There is no fixed rule, most languages have similar rules but differ in details. Look it up in the language definition.