Super Prev Next

Declarations and scope rules

Every identifier occurring in a program must be introduced by a declaration, unless it is a predeclared identifier. Declarations also specify certain permanent properties of an object, such as whether it is a constant, a type, a variable, or a procedure. The identifier is then used to refer to the associated object.

The scope of an object x extends textually from the point of its declaration to the end of the block (module, procedure, or record) to which the declaration belongs and hence to which the object is local. It excludes the scopes of equally named objects which are declared in nested blocks. The scope rules are:

  1. No identifier may denote more than one object within a given scope (i.e. no identifier may be declared twice in a block);
  2. An object may only be referenced within its scope;
  3. A type T of the form POINTER TO T1 (see Pointer types) can be declared before the scope of T1. The declaration of T1 must follow in the same block to which T is local;
  4. Identifiers denoting record fields (see Record types) or type-bound procedures (see Type-bound procedures) are valid in record designators only.

An identifier declared in a module block may be followed by an export mark ("*" or "-") in its declaration to indicate that it is exported. An identifier x exported by a module M may be used in other modules, if they import M (see section Modules). The identifier is then denoted as M.x in these modules and is called a qualified identifier. Identifiers marked with "-" in their declaration are read-only in importing modules.

  Qualident = [ident "."]ident.
  IdentDef  = ident [" * " | " - "].

The following identifiers are predeclared; their meaning is defined in the indicated sections:

ABS (Predeclared procedures) LEN (Predeclared procedures)
ASH (Predeclared procedures) LONG (Predeclared procedures)
BOOLEAN (Basic types) LONGINT (Basic types)
CAP (Predeclared procedures) LONGREAL (Basic types)
CHAR (Basic types) MAX (Predeclared procedures)
CHR (Predeclared procedures) MIN (Predeclared procedures)
COPY (Predeclared procedures) NEW (Predeclared procedures)
DEC (Predeclared procedures) ODD (Predeclared procedures)
ENTIER (Predeclared procedures) ORD (Predeclared procedures)
EXCL (Predeclared procedures) REAL (Basic types)
FALSE (Basic types) SET (Basic types)
HALT (Predeclared procedures) SHORT (Predeclared procedures)
INC (Predeclared procedures) SHORTINT (Basic types)
INCL (Predeclared procedures) SIZE (Predeclared procedures)
INTEGER (Basic types) TRUE (Basic types)