MPE/iX Commands Reference Manual (32650-90864)

742 Appendix B
Expression Evaluator Functions
Expression Evaluator Features
Logical operations: AND, NOT
Logical operations: OR, XOR
The evaluation of string expressions follows a similar hierarchy. However, bit
manipulation, multiplication, division, and modulo operations do not apply to string
expressions. If you attempt to use them with a string expression, an error occurs.
Evaluation is left to right until the evaluation is complete, or until a fatal error has been
detected. If a fatal error is detected, evaluation terminates.
Completion of evaluation in this case means either end of expression or partial evaluation
of expression.
In the latter case (partial evaluation), the result of the evaluation can be determined
without examining the rest of the expressions. For example, when part of an expression
that is evaluated to FALSE is followed by an AND, or is evaluated to TRUE and is followed
by an OR:
(1=2) And (2=2 or 3=4)
FALSE And (whatever) -> FALSE
(1=1) or (2=3 and x=y)
TRUE or (whatever) -> TRUE
NOTE Exponentiation is the one exception to the left-to-right evaluation pattern.
Exponentiation evaluates right to left. For example, 3^2^3 is resolved as 3^8
(=6561) and not as 9^3 (=729).
The logical operators operate only on Boolean expressions, Boolean functions, or Boolean
variables. Boolean expressions are those which contain a comparison operation (< > <=
>= <> =) or a logical operation (AND, OR, NOT, XOR).
Examples:
if 6-5>2 and 'abc'-'a'<=rht('cdbc',2) then
EXPRESSION IS FALSE
endif
if not(1=1 and 'a'<>'b') or 6>7 then
EXPRESSION IS FALSE
endif
calc 6+(7>2)
ERROR ** Invalid Expression: **
** Mixed Numeric and Boolean **
if 1 then
ERROR ** Bad Boolean Expression **
setvar errorflag true
if errorflag then
EXPRESSION IS TRUE
endif
The expression evaluator is sensitive to the position of expression tokens. If an operator is
expected, then an operator must be obtained in that position or a fatal error occurs. If a
number is expected and a valid numeric string is not found, variable management is called
to determine if this token is actually a variable. If the token is a variable with a numeric
value, the variable value is used in the expression. If the token is not a variable or the
variable is not an integer variable, the expression is not valid and an error is returned.