Contents | Prev | Next | Index
With the exception of literal constants, e.g. numbers, strings, and sets, operands are denoted by designators. A designator consists of a (possibly module-qualified) identifier refering to a a constant, variable, or procedure. This identifier may be followed by a list of selectors if the designated item is an element of a structure.
designator ::= designator_id selector_list ::= designator_id designator_id ::= qualident selector_list ::= selector_list selector ::= selector selector ::= . <identifier> ::= [ index_list ] ::= ^ ::= ( qualident ) index_list ::= index_list , index ::= index index ::= expr |
If a designates an array, then index selector a[e] denotes the 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 field selector r.f denotes the field f of r or the procedure f bound to the dynamic type of r.
If p designates a pointer, then reference selector p^ denotes the variable that is referenced by p.
If the language extensions are enabled via a compiler switch or directive then the following applies: A type guard selector v(T) acts like a checked type cast. It makes sure that during runtime designator v is of the dynamic type T or of an extension of T. Program execution is aborted with a runtime exception if the dynamic type of v is neither T nor an extension of T. Within the designator, v is then regarded as if having the static type T. This guard can be applied if:
If the designated object is a constant or a variable, then the designater refers to its current value. Otherwise, if it is a procedure, the designator refers to that procedure, unless it is followed by a (possibly empty) parameter list. If the latter is the case, it means that a function procedure is to be called and that the value returned form that procedure call is the one standing for the designator. As in proper procedure calls, the actual parameters for a function procedure call must correspond to the formal parameters, too.
Here are a few examples of designators (refer to examples in the section about variable declarations):
i | (INTEGER) | |
a[i] | (REAL) | |
w[3].name[i] | (CHAR) | |
t^.left^.right | (Tree) | |
t(CenterTree)^.subnode | (Tree) |
Contents | Prev | Next | Index
Canterbury Modula-2 for Java (Last documentation update
Feb 8, 2000)
Copyright © 1998 Mill Hill &
Canterbury Corporation, Ltd. All rights reserved
Please send any comments or corrections to
mhc@webcom.com