Chapter 3. Scoping

Table of Contents
3.1. Block Structure
3.2. Clashing of Names
3.3. Globals
3.4. Labels
3.5. Restrictions Connected with Scoping

A named object can be brought into existence for part of a program and may have no existence elsewhere (but see Section 4.7). The part of the program in which it is declared to exist is known as its scope. One effect of scoping is to increase the freedom of choosing names for objects whose scopes do not overlap. The other effect is economy of computer storage space. The scope of an object is settled by the block structure as described below.

3.1. Block Structure

A block is a statement consisting, internally, of a sequence of declarations followed by a sequence of statements punctuated by semi-colons and all bracketed by a BEGIN and END. Formally,

Block ::= 
     BEGIN  Declist ;  Statementlist  END 

Declist ::= 
     Dec
     Dec ;  Declist 

Dec ::= 
     Datadec
     Overlaydec
     Switchdec
     Proceduredec 

Datadec ::= 
     Numberdec
     Arraydec
     Tabledec 

The declarations have the purpose of fully classifying new objects and providing them with names (identifiers). As a statement can be itself a block merely by having the right form, blocks may be nested to an arbitrary depth. Except for global objects (see Section 3.3), the scope of an object is the block in which it is declared, and within this block the object is said to be local. The scope penetrates inner blocks, where the object is said to be non-local.