Chapter 8
Expressions

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 (8.1) are used.


Table 8.1: Precedence of operators

Operator Precedence Category
Not, @ Highest (rst)Unary operators
* / div mod and shl shr asSecond Multiplying operators
+ - or xor Third Adding operators
< <> < > <= >= in is Lowest (Last)relational operators

When determining the precedence, the compiler uses the following rules:

  1. In operations with unequal precedences the operands belong to the operater with the highest precedence. For example, in 5*3+7, the multiplication is higher in precedence than the addition, so it is executed rst. The result would be 22.
  2. If parentheses are used in an expression, their contents is evaluated rst. Thus, 5*(3+7) would result in 50.

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 rst should be made in such a case. The compiler will decide which expression to evaluate rst based on optimization rules. Thus, in the following expression:

  a := g(3) + f(2);

f(2) may be executed before g(3). This behaviour is distinctly dierent from Delphior Turbo Pascal.

If one expression must be executed before the other, it is necessary to split up the statement using temporary results:

  e1 := g(3);  
  a  := e1 + f(2);


 8.1 Expression syntax
 8.2 Function calls
 8.3 Set constructors
 8.4 Value typecasts
 8.5 The @ operator
 8.6 Operators
  8.6.1 Arithmetic operators
  8.6.2 Logical operators
  8.6.3 Boolean operators
  8.6.4 String operators
  8.6.5 Set operators
  8.6.6 Relational operators