Operator
From ObjectVision
An Operator is a symbolic representation of a function to be applied on operands. This application is called an operation. Operands can be data items or literals.
In expressions with multiple operators, the precedence of the evaluation is based on the precedence order and the associativity within this order. Operators with lower orders are evaluated first.
Examples:
- -3^2 is evaluated as (-3)^2 or pow(neg(3), 2) due to the higher precedence order of the unary sub operator.
- a / b * c is evaluated as (a / b) * c or mul(div(a,b), c) due to the equal order and left to right associativity of the multiply and divide operator.
- a?b:c?d:e is evaluated as a?b:(c?d:e) due to the right to left associativity of the immediate if operators.
- a || b && c is evaluated as a || (b && c) or or(a, and(b, c) due to the higher precedence order of the and operator.
Use brackets to overrule the precedence rules.
Operator | Name | Order Precedence | Associativity | Description | Equivalent Function |
+ (unary) | plus | 0 | right to left | +a means a | |
- (unary) | minus | 0 | right to left | -a means -a | |
# | nrofrows | 0 | - | #u means number of rows of unit u | |
^ | power | 1 | left to right | a ^ b means a to the b-th power | |
! | subitem | 1 | left to right | a!b means subitem(a, b) | |
[..] | array access | 1 | left to right | a[b] means lookup(b, a) if b is a data item | lookup |
[..] | value | 1 | left to right | a[b] means value(a,b) if b is a unit | |
* | multiply | 2 | left to right | a * b means a multiplied with b | |
/ | divide | 2 | left to right | a / b means a divided by b (spaces are necessary) | |
% | modulo | 2 | left to right | a % b means a modulo b | |
+(binary) | plus | 3 | left to right | a + b means a plus b | |
- (binary) | minus | 3 | left to right | a - b means a minus b | |
== | equal to | 4 | left to right | a == b means a equals b | |
!= | not equal to | 4 | left to right | a b means a not equals b | |
< | less than | 4 | left to right | a < b means a less than b | |
<= | less than or equal to | 4 | left to right | a <= b means a less than or equal to b | |
> | greater than | 4 | left to right | a > b means a greater than b | |
>= | greater than or equal to | 4 | left to right | a >= b means a greater than or equal to b | |
! (unary) | not | 5 | right to left | !a means not a | |
&& | and | 6 | left to right | a && b means a and b | |
|| | or | 7 | left to right | a || b means a or b | |
? : | then else (in an iif expression) | 8 | right to left | cond-expr ? then-expr : else-expr |