Designator = Qualident {"." ident | "[" ExpressionList "]" | "^"
| "(" Qualident ")"}.
ExpressionList = Expression {"," Expression}.
If a designates an array, then a[e] denotes that element of a whose
index is the current value of the expression e. The type of e
must be an integer type. A designator of the form a[e0, e1, ..., en]
stands for a[e0][e1]...[en]. If r designates a record, then
r.f denotes the field f of r or the procedure f
bound to the dynamic type of r (Ch. 10.2). If p designates a
pointer, p^ denotes the variable which is referenced by p.
The designators p^.f and p^[e] may be abbreviated as p.f
and p[e], i.e. record and array selectors imply dereferencing. If
a or r are read-only, then also a[e] and r.f
are read-only.
A type guard v(T) asserts that the dynamic type of v is T (or an extension of T), i.e. program execution is aborted, if the dynamic type of v is not T (or an extension of T). Within the designator, v is then regarded as having the static type T. The guard is applicable, if
Examples of designators (refer to examples in Ch. 7):
i (INTEGER)
a[i] (REAL)
w[3].name[i] (CHAR)
t.left.right (Tree)
t(CenterTree).subnode (Tree)
Expression = SimpleExpression [Relation SimpleExpression].The available operators are listed in the following tables. Some operators are applicable to operands of various types, denoting different operations. In these cases, the actual operation is identified by the type of the operands. The operands must be expression compatible with respect to the operator (see App. A).
SimpleExpression = ["+" | "-"] Term {AddOperator Term}.
Term = Factor {MulOperator Factor}.
Factor = Designator [ActualParameters] |
number | character | string | NIL | Set |
"(" Expression ")" | "~" Factor.
Set = "{" [Element {"," Element}] "}".
Element = Expression [".." Expression].
ActualParameters = "(" [ExpressionList] ")".
Relation = "=" | "#" | "<" | "<=" | ">" | ">=" | IN | IS.
AddOperator = "+" | "-" | OR.
MulOperator = "*" | "/" | DIV | MOD | "&".
OR logical disjunction p OR q "if p then TRUE, else q"These operators apply to BOOLEAN operands and yield a BOOLEAN result.
& logical conjunction p & q "if p then q, else FALSE"
~ negation ~ p "not p"
+ sumThe operators +, -, *, and / apply to operands of numeric types. The type of the result is the type of that operand which includes the type of the other operand, except for division (/), where the result is the smallest real type which includes both operand types. When used as monadic operators, - denotes sign inversion and + denotes the identity operation. The operators DIV and MOD apply to integer operands only. They are related by the following formulas defined for any x and positive divisors y:
- difference
* product
/ real quotient
DIV integer quotient
MOD modulus
x = (x DIV y) * y + (x MOD y)
0 <= (x MOD y) < y
Examples:
x y x DIV y x MOD y
5 3 1 2
-5 3 -2 1
+ unionSet operators apply to operands of type SET and yield a result of type SET. The monadic minus sign denotes the complement of x, i.e. -x denotes the set of integers between 0 and MAX(SET) which are not elements of x. Set operators are not associative ((a+b)-c # a+(b-c)).
- difference (x - y = x * (-y))
* intersection
/ symmetric set difference (x / y = (x-y) + (y-x))
A set constructor defines the value of a set by listing its elements between curly brackets. The elements must be integers in the range 0..MAX(SET). A range a..b denotes all integers in the interval [a, b ].
= equalRelations yield a BOOLEAN result. The relations =, #, <, <=, >, and >= apply to the numeric types, CHAR, strings, and character arrays containing 0X as a terminator. The relations = and # also apply to BOOLEAN and SET, as well as to pointer and procedure types (including the value NIL). x IN s stands for "x is) an element of s ". x must be of an integer type, and s of type SET. v IS T stands for "the dynamic type of v is T (or an extension of T )" and is called a type test. It is applicable if
# unequal
< less
<= less or equal
> greater
>= greater or equal
IN set membership
IS type test
1991 INTEGER
i DIV 3 INTEGER
~p OR q BOOLEAN
(i+j) * (i-j) INTEGER
s - {8, 9, 13} SET
i + x REAL
a[i+j] * a[i-j] REAL
(0<=i) & (i<100) BOOLEAN
t.key = 0 BOOLEAN
k IN {i..j-1} BOOLEAN
w[i].name <= "John" BOOLEAN
t IS CenterTree BOOLEAN