z/OS TSO/E REXX User's Guide
Previous topic | Next topic | Contents | Contact z/OS | Library | PDF


Priority of Operators

z/OS TSO/E REXX User's Guide
SA32-0982-00

When more than one type of operator appears in an expression, what operation does the language processor do first?
IF (A > 7**B) & (B < 3) | (A||B = C) THEN …

Like the priority of operators within the arithmetic operators, there is an overall priority that includes all operators. The priority of operators is as follows with the highest first.

Overall Operator Priority

\ or ¬ - +
Prefix operators
**
Power® (exponential)
* / % //
Multiply and divide
+ -
Add and subtract
blank || abuttal
Concatenation operators
== = >< etc.
Comparison operators
&
Logical AND
| &&
Inclusive OR and exclusive OR
Thus the previous example presented again below:
IF (A > 7**B) & (B < 3) | (A||B = C) THEN …
given the following values:
  • A = 8
  • B = 2
  • C = 10
would be evaluated as follows:
  1. Convert variables to values
    IF (8 > 7**2) & (2 < 3) | (8||2 = 10) THEN …
  2. Compute operations of higher priority within parentheses
    • Exponential operation
      IF (8 > 7**2) & (2 < 3) | (8||2 = 10)  THEN …
             \____/
               49
    • Concatenation operation
      IF (8 > 49) & (2 < 3) | (8||2 = 10)  THEN …
                              \____/
                                82
  3. Compute all operations within parentheses from left to right
    IF (8 > 49) & (2 < 3) | (82 = 10)  THEN …
        \____/     \___/     \_____/
           0         1          0
  4. Logical AND
    0    &    1    |     0
     \_______/
         0
  5. Inclusive OR
    0         |     0
     \_____________/
            0

Go to the previous page Go to the next page




Copyright IBM Corporation 1990, 2014