User guide

2 CHAPTER 1. THE SYSTEM OVERVIEW
LET start() = VALOF
is the heading for the declaration of the function start which, by convention, is
the first function to be called when a program is run. The empty parentheses ()
indicate tha t the routine expects no arguments. The text
FOR i = 1 TO 5 DO
introduces a for-loop whose control variable i successively takes t h e values from
1 to 5. The body of the for-loop is a call of the library function writef whose
effect is to out p ut the form a t string after replacing the substitution items %n
and %i4 by appro p r i at el y formatted representations of i and fact(i). Within
the string *n represents the newline char a ct er . The statement RESULTIS 0 exits
from the VALOF construct providing the result of start that indicates the program
completed succes sfu l ly. The text:
AND fact(n) =
introduces the definition of the funct i on fact which take one argument (n) and
yields n factorial. The word AND causes fact to available to the previously defined
function. This progra m can be compiled by using the fo ll owing command:
0.000> bcpl com/fact.b to fact
BCPL (5 Oct 2010)
Code size = 104 bytes
0.030>
This command compiles the source file fact.b creating an executable object
module in the file called fact. The program can then be run by simply typing
the name of this file.
0.030> fact
fact(1) = 1
fact(2) = 2
fact(3) = 6
fact(4) = 24
fact(5) = 120
0.000>
When the BCPL compiler is invoked, it ca n be given additional argum ents
that control the compiler options. One of these (d1) directs the compiler to
output the compiled code in a readable form, as follows:
10> bcpl com/fact.b to fact d1
BCPL (5 Oct 2010)
0: DATAW 0x00000000
4: DATAW 0x0000DFDF