User guide

28 CHAPTER 2. THE BCPL LANGUAGE
where N
1
,...,N
n
are names (see Section 2.2.1) and K
1
,...,K
n
are manifest
constant express io n s (see Section 2.2.10). Each na m e is declared to b e a statically
allocated variable initialised to the corresponding manifest expression. If a val u e
specification (=K
i
) is omitted, the a value one larger than the previously defined
manifest constant is imp l i ed , and if =K
1
is omitted, then =0 is assumed. Thus,
the declaration :
STATIC { A; B; C=10; D; E=100 }
declares A, B, C, D and E to be static variables having in i t i al values 0, 1, 10, 11
and 100, respecti vely.
2.4.5 LET Declarations
LET decl a ra t i on s are used to declare local variables, vectors, funct io n s and rou-
tines. The textual scope of names declared in a LET declaration is the right
hand side of its own declaration (to allow the d efinition to be recurs ive), and
subsequent declarations and the commands.
Local var ia b l e, vector, function and routine declarations can be combined
using the word AND. The only effect of this is to extend the scope of names
declared forward to th e word LET, thus allowing the declaration of mutually
recursive functions and routines. AND serves no useful purpose for local variable
and vector declarations.
2.4.6 Local Variable Declarations
A local var i ab l e declaration has the following form:
LET N
1
,..., N
n
= E
1
,..., E
n
where N
1
,...,N
n
are names (see Section 2.2.1) and E
1
,...,E
n
are expressions .
Each name, N
i
, is allocated space in the current stack frame and is initialized
with the value of E
i
. Such variab l es are called dynamic variables since they are
allocated when the declaration is executed and cease to exist when control leaves
their scope. The variables N
1
,...,N
n
are allocated consecutive locations in the
stack and so, for instance, the variable N
i
may be accessed by the expression
(@N
1
)!(i 1). This featur e is a recent addition to the language.
The query expression (?) should be used on the right hand side when a
variable does not need an initial value.
2.4.7 Local Vector Declarations
LET N = VEC K