Operator priority is evaluated in two steps: firstly, by the order of precedence of operator types; secondly, within an operator type by the order of precedence for operators.
Order of precedence for “operator types”:
Sign, negation
Arithmetic operators
Concatenation operator
Relational operators
Logical operators
Order of precedence for arithmetic operators (“Dot operations before line operations”):
Multiplication, division, modulo operation (*, /, MOD)
Addition, subtraction (+, -)
Order of precedence for logical operators:
AND operation (AND)
OR operation (OR, XOR)
Relational operators:
All relational operators have the same order of precedence.
Example
Complex logical expressions are often used in IF blocks in the CONDITION operand of the IF command. If the condition determined by the expression is true, the command that follows the IF command is processed. If the condition is false, the next ELSE-IF or ELSE command is processed (for more information on IF, ELSE-IF, and ELSE commands, see chapter “Creating S procedures” or chapter “SDF-P commands” ).
For example, an IF command could contain the following condition:
A + B / C > D + C MOD E AND A + D * E < D * C OR F // G > H
At the time of the IF query, variables A to H have the following values:
/A = 4 /B = 29 /C = 9 /D = 3 /E = 5 /F = 'ABC' /G = 'DEF' /H = 'ABCDE'
The expression is evaluated in the following steps:
Arithmetic operators: Multiplication / division
Operation
Corresponds to
Result
B / C
29 / 9
3
C MOD E
9 MOD 5
4
D * E
3 * 5
15
D * C
3 * 9
27
Results of step 1:
A + 3 > D + 4 AND A + 15 < 27 OR F // G > H
Arithmetic operators: Addition
Operation
Corresponds to
Result
A + 3
4 + 3
7
D + 4
3 + 4
7
A + 15
4 + 15
19
Results of step 2:
7 > 7 AND 19 < 27 OR F // G > H
Concatenation operator
Operation
Corresponds to
Result
F // G
'ABC' // 'DEF'
'ABCDEF'
Results of step 3:
7 > 7 AND 19 < 27 OR 'ABCDEF' > H
Relational operators
Operation
Result
7 > 7
FALSE
19 < 27
TRUE
'ABCDEF' > 'ABCDE'
TRUE
Results of step 4:
FALSE AND TRUE OR TRUE
Logical operators: AND
Operation
Result
FALSE AND TRUE
FALSE
Results of step 5:
FALSE OR TRUE
Logical operators: OR
Operation
Result
FALSE OR TRUE
TRUE
Results of step 6:
TRUE
Thus, the condition is fulfilled.
Order of evaluation
The order of evaluation is not defined for any operands. It can occur that the right operand of an AND operation is evaluated first.
Example
/DECLARE-VARIABLE I(TYPE = INTEGER)
/IF IS-INITIALIZED ('I') AND (I < 10)
Since, at this time, I is not yet initialized, evaluating I < 10 results in an error.