User guide

Appendix A
BCPL Syntax Diagrams
The syntax of standard B CPL is specified using the transition diagrams given in fig-
ures A.1, A.2, A.3 and A.4. In extended BCPL the floating point operators have
the same precedence as the corresponding integer ones, and the op:= operators are
syntactically identical to the := operator. The syntax of the more binding sequenc-
ing operator (<>) requi r e s some new diagr ams to be drawn. This wi l l be done i n
due c our se . It is sufficient to know that <> is more binding than DO, THEN, ELSE,
REPEAT, REPEATWHILE, REPEATUNTIL, and colon. Within the diagrams the syntactic
categories program, secti o n , declaration, command and expression
n
are represented
by the rounded boxes:
program
,
section
,
D
,
C
and
En
, respec-
tively.
The rectangular boxes are called test boxes and can only be traversed if the c on-
dition labelling the box matches the current input. When the label is a token, as in
WHILE
and
:=
, it must match the next input token for the test t o succeed. The
test box
eof
is only satisfied if the end of file has been reached. Sometimes the
test box contains a side condition, as in
REM n<6
, in which case the side condition
must also be satisfied. The only other test boxes are
is call
and
is name
which
are only satisfied i f the most recently read expressi on is syntactically a function call
or a name, respectively. By setting n successively from 0 to 8 in the definition of the
category
En
, we obtain the definitions of
E0
to
E8
. Starting from the
definition of
program
, we can construct an infinite transition diagram containing
only test b oxes by simply replacing all rounded boxes by their definitions, recursively.
The parsing algorithm searches through this infinite diagram for a path with the same
sequence of tokens as the program being parsed. In order to eliminate ambiguities,
the left hand branch at a branch point is tried first. Notic e how this rule cause s the
command
IF i>10 DO i := i/2 REPEATUNTIL i<5
to be equivale nt to
IF i>10 DO { i := i/2 REPEATUNTIL i<5 }
225