t3x.org / t3x / t3x-manual / 2B.html
 
T3X - A Minimum Procedural Language
Version 8.1.5, Online Edition
Copyright(C) 1996-2004
Nils M Holm
 
Previous:
2.10.3 A Sample Interface
TOC | Index | Back Next:
2.11.1 Scoping Conflicts

2.11 Scoping Rules

Scoping rules define the contexts in which symbols are valid and the conditions under which they may be redefined. In T3X, there are five different contexts and very strict and simple redefinition rules apply.

  1. The public context contains public classes and the public entities defined in their contexts. It contains all public elements exported by a set of modules. The public context is persistent. It is not even destroyed when the compilation of a program ends. The public context may contain any number of class contexts. (*)
  2. The global context covers a complete file or module. Its declarations are located in the space between procedures and class definitions. Each global context may contain any number of class contexts or procedure contexts.
  3. A class context contains all symbols which belong to a specific class. They are delimited by a class header (CLASS ... or ICLASS ...) and the keyword END. Each class context may contain any number of procedure contexts.
  4. A procedure context is equal to the argument list of a procedure plus the statement forming the body of the procedure. The argument list is a list of implicit atomic variable declarations. No other entities may be defined in this context. A single block context (forming the body of the procedure) may be embedded in each procedure context.
  5. A block context begins with the keyword DO and ends with the keyword END. Each block context may contain any number of nested block contexts. Notice that this defintion is recursive, so that blocks may be nested to any level. A block context is called blockn context, if there are n enclosing blocks.

(*) Technical remark: To purge the public symbol table, the storage holding the table (usually a file) must be cleared (eg by deleting the file).

The following redefinition rules apply:

  1. Each public class and the entities defined in its context may be redefined once in the module containing the original definition. (*)
  2. Each symbol used in a forward declaration (DECL statement) may be redefined by a one single matching procedure definition.
  3. Except for forward declarations and public entities, no symbol may be redeclared or shadowed ever.

(*) This happens when a module containing public classes is recompiled. In this case, the definition in the public context is silently updated.

+-- Public ------------------------------------+
| +-- Global --------------------------------+ |
| | +-- Class -----------------------------+ | |
| | | +-- Procedure ---------------------+ | | |
| | | | +-- Block**0 ------------------+ | | | |
| | | | | +--- ... ------------------+ | | | | |
| | | | | |                          | | | | | |
| | | | | | +-- Block**N ----------+ | | | | | |
| | | | | | |                      | | | | | | |
| | | | | | |                      | | | | | | |
| | | | | | |                      | | | | | | |
| | | | | | +----------------------+ | | | | | |
| | | | | +--------------------------+ | | | | |
| | | | +------------------------------+ | | | |
| | | +----------------------------------+ | | |
| | +--------------------------------------+ | |
| +------------------------------------------+ |
+----------------------------------------------+
Fig.4 Scopes (overview)
Previous:
2.10.3 A Sample Interface
TOC | Index | Back Next:
2.11.1 Scoping Conflicts