Language Elements and Reference:xpplrm

Precedence of operators Foundation

The operators in Xbase++ are arranged in various categories and each category has a specific precedence. Due to this precedence, it is guaranteed that complex expressions involving different data types are correctly evaluated when the partial expressions they contain are not delimited with parentheses. An example of a complex expression using operators of different categories is shown in the following code:

nValue-- >= 1 .AND. dDate + nValue <= Date() 

In this line, a logical operation is performed between the results of two comparison operations (one comparing numeric and the other comparing date values). The date comparison also performs addition and uses the result of a function call. The numeric comparison uses postfix decrementing. The evaluation of a complex expression such as this follows these rules:

Function calls and special operators are completed before all other operators.
Operators with higher precedence complete their operations before operators with lower precedence.
Operators with equal precedence are processed from left to right, with the exception of a multiple inline assignment (nVal1:=nVal2:=10), which is processed from right to left.

The precedence of the operators within the various categories is performed as follows in descending order (note that operators shown on the same line have the same precedence):

1. Prefix increment and decrement         --++ 
2. Mathematical operators 
2.1 Unary minus and plus               - + 
2.2 Exponentiation                     ** ^ 
2.3 Multiplication, division, modulus  * / % 
2.4 Addition, subtraction              + - 
3. Comparison operators                   > >= = <= != # == $ .IN. 
4. Logical operators 
4.1 Logical negation                   .NOT. ! 
4.2 Logical And                        .AND. 
4.3 Logical Or                         .OR. 
5. Assignment operators                   = := **= ^= *= /= %= += -= 
6. Postfix increment and decrement        -- ++ 

Using the parentheses (), the order in which partial expressions within a complex expression are evaluated can be explicitly specified. Expressions in parentheses are evaluated first, with the evaluation occurring from the deepest to the highest nested levels.

Feedback

If you see anything in the documentation that is not correct, does not match your experience with the particular feature or requires further clarification, please use this form to report a documentation issue.