Priority of operators

When more than one type of operator appears in an expression, the language processor follows an overall priority that includes all operators.

The priority of operators is as follows with the highest first.

Table 1. Overall operator priority
Operator symbol Operator description
\ or ¬ - + Prefix operators
** Power (exponential)
* / % // Multiply and divide
+ - Add and subtract
blank || abuttal Concatenation operators
== = >< and so on Comparison operators
& Logical AND
| && Inclusive OR and exclusive OR

Example

The following expression contains more than one type of operator:
IF (A > 7**B) & (B < 3)
Given the following values
  • A = 8
  • B = 2
  • C = 10
the language processor would evaluate this example as follows:
  1. Evaluate what is inside the first set of parentheses.
    1. Evaluate A to 8.
    2. Evaluate B to 2.
    3. Evaluate 7**2.
    4. Evaluate 8 > 49 is false ( 0).
  2. Evaluate what is inside the next set of parentheses.
    1. Evaluate B to 2.
    2. Evaluate 2 < 3 is true ( 1).
  3. Evaluate 0 & 1 is 0

Exercises: priority of operators

  1. What are the answers to the following examples?
    1. 22 + (12 * 1)
    2. -6 / -2 > (45 % 7 / 2) - 1
    3. 10 * 2 - (5 + 1) // 5 * 2 + 15 - 1
  2. In the example of the student and the college from the previous exercise in Logical (Boolean) operators, if the parentheses were removed from the student's formula, what would be the outcome for the college?
    IF inexpensive | scholarship & reputable | nearby THEN
       SAY "I'll consider it."
    ELSE
       SAY "Forget it!"

    Remember the college is inexpensive, did not offer a scholarship, is reputable, but is 1000 miles away.

ANSWERS
  1. The results are as follows:
    1. 34 (22 + 12 = 34)
    2. 1 (true) (3 > 3 - 1)
    3. 32 (20 - 2 + 15 - 1)
  2. I'll consider it.
    The & operator has priority, as follows, but the outcome is the same as the previous version with the parentheses.
    IF inexpensive | scholarship & reputable | nearby THEN
                 \_________/   \_________/   \_______/  \____/
                    true          false        true     false
                      \              \___________/        /
                       \                false            /
                        \_________________/             /
                               true                    /
                                 \____________________/
                                         true