User guide

20 CHAPTER 2. THE BCPL LANGUAGE
when a field is updated. Suppose p!3 holds the value #x12345678, then after the
assignment:
(SLCT 12:8:3) OF p := 1 + (SLCT 8:20:3) OF p
the value of p!3 is #x12302478.
An expressions of the form E
1
<<E
2
(or E
1
>>E
2
) evaluates E
1
and E
2
to yield
a bit pattern, w say, and an integer, n say, and returns the result of shifting w
to the left (or right) by n bit positions. Vacated positions are filled with zeroes.
Negative shifts or ones of more than the word length return 0.
Expressions of the form: E
1
*E
2
, E
1
/E
2
, E
1
MOD E
2
, E
1
+E
2
, E
1
-E
2
. E
1
EQV E
2
and E
1
XOR E
2
return the result of applying the g iven operator to the two
operands. The operators are, respectively, integer multiplication, integer divi-
sion, remainder after integer divisi on, integer addition, integer subtra ct io n , bit-
wise equivalent and bitwise not equivalent (exclusive OR). REM and NEQV can be
used as synonyms of MOD and XOR, respecti vely.
Expressions of the form: E
1
&E
2
and E
1
|E
2
return, respectively, the bitwise
AND or OR of their operands u n l ess the expression is being evaluated in a boolean
context such as the condi t io n in a while co m m an d, in which case the oper an ds
are tested from from left to right until the value of the condition is known.
An expr essi o n of the for m : E relop E relop . . . relop E where each relop is one
of =, ~=, <=, >=, < or > returns TRUE if all th e individ u al relation s are satisfied and
FALSE, otherwise. The operands are evalu at ed from left to right, and evaluation
stops as soon as the result can be determined. Operands may be evaluated more
than once, so don’t try ’0’<=rdch()<=’9’.
An expression of the form: E
1
->E
2
,E
3
first evaluates E
1
in a boolea n context,
and, if this yields FALSE, it returns the value of E
3
, ot h er wi se it returns t h e va lue
of E
2
.
The floating point operators #*, #/, #+, #-, #=, \#~=, #<, #>, #<= and #>= are
now allowed. They have the same binding power as the corresponding integer
operators. Beware that, since BCPL has no type checking, it is ea sy make serious
mistakes such as 1.2+3.4 which performs i nteger addition of the bit pat te rns
representing 1.2 and 3.4. The expression should have been written 1.2#+3.4.
2.2.7 Boolean Evaluati on
Expressions that control the flow of execution in coditional constructs, such as
if and while commands, are evaluated in a Boolean context. This effects the
treatment of the operators NOT, & and | whose operands are evaluated in Boolean
contexts. In a Boolean context, the operands of & and | are eval u a t ed from left
to right until the value of the condition is know, and NOT (or ~) negates the
condition.