Contents | Prev | Next | Index
Formal parameters are identifiers declared in the formal parameter list of a procedure. Each formal parameter corresponds to an actual parameter as specified in the procedure call. This correspondence between formal and actual parameters is established during the procedure call.
There are two kinds of parameters: Value parameters and variable parameters. A variable parameter is indicated in the formal parameter list by the presence of the keyword VAR. This keyword is absent for value parameters. A value parameter is like local variable to which the value of the corresponding actual parameter is assigned as an initial value. Variable parameters correspond to actual parameters which are variable designators, and they stand for these variables. The compiler uses internally a reference to the actual variable for a formal variable parameter.
The scope of a formal parameter is the same as those for other local variables: It extends from its point of declaration to the end of the procedure block in which it is declared.
A function procedure without parameters must have an empty parameter list, and it must be called by a function designator whose actual parameter list is empty, too. The result type can neither be a record nor an array.
Due to Java restrictions, any changes to formal variable parameter of a basic type inside a procedure won't be reflected to the actual parameter variable outside the procedure until completion of the procedure execution.
formal_parameters ::= ( ) ::= ( ) : qualident ::= ( fp_section_list ) ::= ( fp_section_list ) : qualident fp_section_list ::= fp_section_list ; fp_section ::= fp_section fp_section ::= VAR id_list : formal_type ::= id_list : formal_type id_list ::= id_list , <identifier> ::= <identifier> formal_type ::= qualident ::= open_array qualident open_array ::= open_array ARRAY OF ::= ARRAY OF
qualident ::= qualifier_list .
<identifier> |
Note that, unlike other Oberon-2 implementations, Canterbury Oberon-2 for JVM always expects a (possibly qualified) identifier of an already existing type when specifying types in formal parameter lists. Declaring new types in a formal parameter list would almost certainly make them incompatible with the types of actual parameters and was probably originally only allowed because of open arrays. The latter, however, are being dealt with in this compiler separately on the level of the language syntax.
Let Tf be the type of a formal parameter f (not an open array) and Ta the type of the corresponding actual parameter a. For variable parameters, Ta must be the same as Tf, or Tf must be a record type and Ta an extension of Tf. For value parameters, a must be assignment compatible with f.
If Tf is an open array, then a must be array compatible with f. The lengths of f are taken from a.
See also the examples in the previous section about procedure declarations.
Contents | Prev | Next | Index
Canterbury Oberon-2 for JVM (Last documentation update
Jun 2, 2000)
Copyright © 1998 Mill Hill & Canterbury
Corporation, Ltd. All rights reserved
Please send any comments or corrections to
mhc@webcom.com