Contents | Prev | Next | Index


Declarations and Scope Rules

Pascal requires every identifier occuring in a program to be either introduced by a declaration or to be imported. The only exception from this rule are the standard identifiers which can be regarded as automatically imported. Declarations also specify certain permanent properties of an item, such as whether it is a constant, type, variable or procedure. The identifier is then used to refer to the associated item.

The scope of an item extends textually from the point of its declaration to the end of the block. That is, it is local within its program, unit, procedure or record according to which its declaration belongs to. The visibility of an item also extends to nested scopes unless it is hidden there by another declaration of the same identifier. Here are the scope rules:

  1. No identifier may refer to more than one item within a given scope. That means an item cannot be declared twice in the in the same block.
  2. An item may only be referenced within its (possibly nested) scope.
  3. A type T of the form ^T1 (see pointer types) can be declared before the scope of T1. In this case, the declaration of T1 must follow in the same block to which T is local.
  4. If an identifier is defined in the interface part of a Pascal unit M1, it scope extends to all those Pascal units or programs which use M1 (see compilation units).
  5. Identifiers designating record fields (see record types) are valid only in record designators and in with statements referring to a variable of that record type.
  6. The class scope of a component identifier declared in a class type extends from the point of declaration to the end of the class-type definition, and it also extends over all descendants of the class type and the blocks of all method declarations of the class type. Also, the scope of component identifiers includes field and method designators, and with statements that operate on variables of the given class type.

An identifier may be qualified. In this case it is prefixed by another identifier which designates the Pascal unit in which the qualified identifier is defined. The prefix and the identifier are separated by a period.

qualident ::= qualident . <identifier>
          ::= <identifier>

Pascal also has a number of standard identifiers. These are automatically imported, as if a USES SYSTEM clause was specified. Though not being reserved words, standard identifiers should not be redeclared.


Contents | Prev | Next | Index

Canterbury Pascal for JVM  (Last documentation update Sep 02, 2004)
Copyright © 1999-2004 J.Neuhoff - mhccorp.com  . All rights reserved.
Please send any comments or corrections to neuhoff@mhccorp.com