Next: 6.1 Expression syntax
Up: 1. The Pascal language
Previous: 5.4 Properties
6. 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 (OperatorPrecedence) are used.
Table:
Precedence of operators
Operator |
Precedence |
Category |
Not, @ |
Highest |
Unary operators |
* / div mod and shl shr as |
Second |
Multiplying operators |
+ - or xor |
Third |
Adding operators |
< <> < > <= >= in is |
Lowest (Fourth) |
relational operators |
When determining the precedence, te compiler uses the following rules:
- Operations with equal precedence are executed from left to right.
- In operations with unequal precedence 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 first. The result would be 22.
- If parentheses are used in an epression, their contents is evaluated
first. Thus, 5*(3+7) would result in 50.
An expression is a sequence of terms and factors. A factor is an operand of
a multiplication operator. A term is an operand of an adding operator.
Subsections
root
1999-06-10