Contents | Prev | Next | Index


Compilation Units

A compilation unit consists of a Pascal program or a Pascal unit. A program consists of a program heading, an optional USES-clause, and a block. A unit consists of a unit heading, an interface part and an implementation part. Units are the basis of modular programming in Canterbury Pascal. They are used to create libraries which can be included in various programs or other units. The following language grammar shows Java-specific directives in red color.

compilation_unit   ::= unit_module
                   ::= program_module
unit_module        ::= def_module imp_module
program_module     ::= program_heading import_list block .
def_module         ::= unit_heading INTERFACE import_list def_list
unit_heading       ::= unit <identifier> ; package
unit               ::= foreign UNIT
foreign            ::= java_foreign
                   ::= <empty>
package            ::= java_package
                   ::= <empty>
imp_module         ::= IMPLEMENTATION import_list imp_block .
imp_block          ::= decl_list END
                   ::= decl_list
                       INITIALIZATION stmt_seq END
                   ::= decl_list
                       INITIALIZATION stmt_seq
                       FINALIZATION stmt_seq END
program_heading    ::= PROGRAM program_id ; package
                   ::= PROGRAM program_id program_parameters ; package
                   ::= LIBRARY program_id ; package
                   ::= <empty>
program_id         ::= <identifier>
program_parameters ::= ( ident_list )

import_list       ::= USES item_list ;
                  ::= <empty>
item_list         ::= item_list , item
                  ::= item
item              ::= <identifier>

The SYSTEM unit is always used automatically. SYSTEM implements all low-level, runtime routines to support such features as file input and output, string-handling, floating point, dynamic memory aloocation, and others. Any other units needed must be included in a USES-clause list. The order of the units listed in the USES-clause determines the order of their initialization.

The UNIT heading specifies the unit's name. The latter is used when refering to the unit in a USES clause. The must be unique.

The INTERFACE part of a unit declares constants, variables, procedures, and functions that are public, that is, available to other programs or units using that unit. These other programs or units can access the public entities as of they were declared in a block that encloses the host. The interface part only lists procedure or function headings, not their bodies. The bodies are specified in the implementation part.

The IMPLEMENTATION part defines the blocks of all public procedures and functions. It also declares constants, types, variables, procedures and functions that are private, that is, not available to other programs or units. In effect, the procedure and function declarations in the interface part are like forward declarations, although the FORWARD directive isn't specified. The procedures and function heading can be duplicated from the interface part, with or without the parameter list. If the parameter list is repeated the compiler will issue an error message if the interface and implementation declarations don't match. If the parameter list is not repeated in the implementation part, it is internally repeated from the interface part.

The INITIALIZATION part is optional. If there, it specifies a statement sequence which intialize the unit. The intialization parts of units used by a program or unit are executed in the same order the units appear in the USES-clause. They are mapped to Java main methods.

The FINALIZATION part is optional, too, and can only appear if a unit also has an initialization part. The finalization part specifies a statement sequence which finalize the unit. Finalization is the counterpart of initialization and is useful for releasing resources such as files. The order of execution for finalization parts is undefined and solely depends on how Java executes them. They are mapped to Java classFinalize methods.

The USES clause in a module (program or unit) need only name the units used directly by that module e.g. for identifiers exported by the units. USES-clauses in INTEFACE parts should not circularly reference each other's units.


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