Expressions occur in assignments or in tests. Expressions produce a value of a certain type. Expressions are built with two components: operators and their operands. Usually an operator is binary, i.e. it requires 2 operands. Binary operators occur always between the operands (as in X/Y). Sometimes an operator is unary, i.e. it requires only one argument. A unary operator occurs always before the operand, as in -X.
When using multiple operands in an expression, the precedence rules of table (12.1) are used.
Operator | Precedence | Category |
Not, @ | Highest (first) | Unary operators |
* / div mod and shl shr as << >> | Second | Multiplying operators |
+ - or xor | Third | Adding operators |
= <> < > <= >= in is | Lowest (Last) | relational operators |
When determining the precedence, the compiler uses the following rules:
Remark: The order in which expressions of the same precedence are evaluated is not guaranteed to be left-to-right. In general, no assumptions on which expression is evaluated first should be made in such a case. The compiler will decide which expression to evaluate first based on optimization rules. Thus, in the following expression:
f(2) may be executed before g(3). This behaviour is distinctly different from Delphi or Turbo Pascal.
If one expression must be executed before the other, it is necessary to split up the statement using temporary results:
Remark: The exponentiation operator (**) is available for overloading, but is not defined on any of the standard Pascal types (floats and/or integers).