A PROPOSED DEFINITION OF THE LANGUAGE B C P L This document sets out a proposal for the definition of a standard BCPL and was prepared by M.D. Middleton in collaboration with R. Firth (HPAC Ltd.) M. Richards (University Cambridge) I. Willers (CERN Geneva) who are members of the BCPL Standards Committee elected at the BCPL User Meeting on 7th March 1979 in Cambridge. M.D. Middleton Das RZ der Universitaet Regensburg Universitaetsstrasse 31 D-8400 Regensburg W.-Germany BCPL Standard 1 Introduction ____________ 1.1 Scope and Purpose _________________ This document has been produced in response to requests at the inaugural meeting of the BCPL Users Group on 7th March 1979. It is a revised version of a previous attempt at standardization (Middleton 1979) which was in turn based on the original BCPL manual (Richards 1969, 1973). It is intended as a specification of the language and its runtime system which will be adopted as a standard at a subsequent BCPL User Group meeting. 1.2 Language Extensions ___________________ The language and runtime system described in the body of this paper is BCPL-level 0 and is intended to form the basis of a standard to which all implementations should adhere. The Appendix gives a number of possible extensions. These are grouped into 'Packets'. None of the packets is mandatory but if any facilities from any given packet described in the appendix are included then the whole packet should be implemented in the form described there. 1.10.1979 1 BCPL Standard 1.3 Meta-Language _____________ For the syntactic definition Backus Naur Form with the following extension is used: [] are metabrackets which mean that the categories between the brackets must occur at least n times but not more than m times. If n or m is omitted the default values are n = 0 and m = . For the semantic definition the following conventions are used unless explicitly qualified in a particular section. E, E1, E2,... stand for arbitrary expressions K, K1, K2,... stand for arbitrary constant expressions and C, C1, C2,... stand for arbitrary commands. 2 1.10.1979 BCPL Standard 2 Data ____ There are no explicit data types in BCPL. The only unit of data is the BCPL word which for any given implementation is a bit string of fixed length not less than 16 bits. A BCPL word may be used to represent values of many different types including integers, characters and truth values. As there are no explicit data types the compiler performs no type checking and always assumes that operands have the required type. The basic unit of storage is a cell which is large enough to hold a BCPL word. Each available cell has an integer address which can be operated upon and stored in the same way as any other BCPL word. Adjacent cells have integer addresses that differ by one. 2.1 Data Storage ____________ A BCPL program has at least three available areas of storage: dynamic, static and global. 1.10.1979 3 BCPL Standard 2.1.1 Dynamic _______ This area is normally a single block of contiguous storage which is used for storage of temporary results and dynamic variables. 2.1.2 Static ______ This is a not necessarily contiguous area of store in which static variables can be stored. 2.1.3 Global ______ This is a block of contiguous store which is used for communication between seperately compiled sections of a BCPL program. The cells of this block are numbered from zero up to some limit and all are available to each section. 2.1.4 Other storage areas ___________________ Other storage areas may (but do not have to) be made available to the program by means of procedure calls. See section A7 in the Appendix. 4 1.10.1979 BCPL Standard 3 Lexical considerations ______________________ The machine representation of a BCPL program is dependent on the character set used. 3.1 Character set _____________ The character set is divided into the following: ::= | includes at least 'space' and 'tab' is any 'carriage control character' such as linefeed, new page etc. includes all upper case letters and, if the implementation allows, lower case letters. Lower case letters have the same meaning as upper case letters except in strings and character constants where they stand for themselves. ::= 0|1|2|3|4|5|6|7|8|9 a set of special characters which are used to build BCPL basic symbols. all other characters in the character set. These may occur only in strings, character constants and comments. 1.10.1979 5 BCPL Standard 3.2 Basic contructions of the language __________________________________ The basic syntactic unit in BCPL is the ::= | . With the exception of a restriction on any number of s may appear between s, but s may not appear within a . It will also be seen from the syntax that s are sometimes necessary to separate s which would otherwise elide, for example and . 3.2.1 Tag, Name, Identifier _____________________ ::= [] where is one of , or '.' (dot). Some implementations also allow the underline character in tags. ::= is a which is not a . 3.2.2 Basic Symbol ____________ A is a symbol made up of either a sequence of letters or a sequence of s. The machine representation of s is implementation dependent and in this document a canonical representation of the s is used. The following 6 1.10.1979 BCPL Standard table gives the set of canonical s together with a list of alternative representations. basic alternative symbol representation(s) TRUE FALSE ? NIL ( [ ) ] @ LV !(monadic) RV !(dyadic) * / REM + - = EQ ~= = NE \= < LT <= LE > GT >= GE << LSHIFT >> RSHIFT NOT ~ \ & /\ LOGAND | \/ LOGOR EQV NEQV -> , TABLE VALOF ; : VEC BE LET AND := BREAK LOOP ENDCASE RETURN FINISH GOTO RESULTIS 1.10.1979 7 BCPL Standard SWITCHON INTO REPEAT REPEATUNTIL REPEATWHILE UNTIL WHILE FOR TO BY IF UNLESS CASE DEFAULT DO THEN ELSE OR ABS GET MANIFEST GLOBAL STATIC Further Symbols _______________ The following character combinations are used in certain BCPL constructions and are given here for completeness. character construction combination $( ) section brackets $) ) '(single quote) character constant "(double quote) string constant # literal // ) comments /* ) */ ) Extended Basic Symbols ______________________ The following list gives basic symbols and character combinations used in recommended extensions. 8 1.10.1979 BCPL Standard symbol alternative representations #+ #- #* #/ #= #EQ #~= #NE # = #\= #< #LT #<= #LE #> #GT #>= #GE #ABS FIX FLOAT SECTION NEEDS EXTERNAL % $$ $< $> 3.2.3 Element _______ ::= | An represents either a variable which at runtime will be bound to some particular cell or a which is treated as a literal. A is a direct representation of a constant. ::= | | | | Number ______ ::= | [] ::= #[O] [] | #B[] | #X[] 1.10.1979 9 BCPL Standard ::= 0 | 1 | ... 7 ::= 0 | 1 ::= 0|1|2|3|4|5|6|7|8|9||A|B|C|D|E|F Semantics _________ A number has some machine representation which is chosen such that the BCPL operators have the expected results. Binary, octal and hexadecimal numbers may be written with leading zeros suppressed and, so long as the cell length of the implementation is not exceeded, the normal rules for conversion between positive numbers in these bases hold. Character constant __________________ ::= '' Any single character may appear within the single quotes except *, ' or . may also be any of the following special representations: special represents representation ** * *' '(single quote) *" "(double quote) *S or *s space *T or *t tab *N or *n newline *P or *p newpage *Xnn or *xnn the hexadecimal character nn *Onnn or *onnn the octal character nnn 10 1.10.1979 BCPL Standard Semantics _________ A character constant is the representation of the given character in an implementation dependent internal code. It occupies a complete BCPL word and is right justified and padded on the left with zeros. String constant _______________ ::= "" Within a string any character represents itself except *, " and . The special representation of character constants (see above) may be used within a string. K is an implementation constant whose value is not less than 127; in most implementations it is 255. In a string the sequence * [] * is ignored. Semantics _________ A string constant is represented by the BCPL-address of the zeroth of a set of contiguous cells which at runtime hold the actual characters of the string together with its length packed. Each cell is divided into a number of 'bytes' (not necessarily of the same size). Byte zero of cell zero of a 1.10.1979 11 BCPL Standard string contains the length and subsequent bytes contain the characters packed contiguously and in the given sequence. The unused bytes of the last cell are filled with binary zeros. See section 10.3 for information about the string handling library procedures. Logical value _____________ ::= TRUE | FALSE The meaning of the values is self explanatory. The machine representation is such that the operators NOT, &, |, EQV, NEQV have the expected results, see section 4.3.1. Thus the representation of FALSE is a bit pattern of all zeros and the representation of TRUE is a bit patern of all ones. Undefined _________ ::= ? The value of this is undefined. 12 1.10.1979 BCPL Standard 3.3 Omission of symbols ___________________ The symbols ; (semicolon), DO and THEN can be omitted when the compiler can tell by context whether one is required or not. There are, however, a few cases where ambiguities can arise and these are resolved by the compiler according to the following two rules: a) The first symbol after a newline character may not be a dyadic operator, or -> or a comma. b) The compiler reads the source program sequentially symbol for symbol without backtracking and while parsing a given construction accepts all symbols which (with the exception of rule (a) could possibly belong to that construction. The first symbol which could not belong to the given construction is taken as the start of a new construction. With these rules in mind the following recommendations are made to programmers over omission of symbols. The following syntactic conventions are safe. a) Semicolon should only be omitted if it is the last non-comment symbol on a line. b) DO or THEN should only be omitted when the following symbol is one that can only start a command. 1.10.1979 13 BCPL Standard 3.4 Tagged brackets _______________ The section brackets $( and $) may be written as $( and $). Each opening section bracket must be matched by an identically tagged closing bracket. However, when the compiler finds a closing section bracket with a non-null tag, if the nearest opening section bracket does not match, that section is closed and the process is repeated until a matching opening section bracket is found. Thus syntactically a tagged opening section bracket is the same as a null-tagged (untagged) one and a tagged closing bracket is the same as one or more untagged closing section brackets. Some implementations generate a warning message if a tagged section bracket is not explicitly closed by a matching one. 3.5 Comments ________ Comments may be introduced by one of the two symbols // or /* The sequence // [>] has the syntactic significance of a The sequence 14 1.10.1979 BCPL Standard /* */ has the syntactic significance of a . 3.6 GET ___ It is possible to include a file in the source text by using the directive GET where is a machine dependent identification of a file. This is usually a string. The GET directive must appear on a line by itself and the effect is to replace this line with the text of the given file. 1.10.1979 15 BCPL Standard 4 Expressions ___________ 4.1 Syntax of expression ____________________ The following syntax defines the form of BCPL expressions. This syntax must be used in conjunction with the binding power of the operators to give an unambiguous parsing of an expression. ::= | () | | [ ] | | | VALOF | TABLE ::= ! | @ | ABS | + | - | NOT ::= ! | * | REM | / | + | - | = | ~= | < | > | <= | >=| << | >> | & | | | EQV | NEQV ::= ::= () | () ::= -> , ::= [,] is defined in section 5. 16 1.10.1979 BCPL Standard 4.2 Operator precedence ___________________ Ambiguities in the above syntax are resolved by the following order of binding power. (highest, most binding) () (bracketed expression) Procedure call ! (dyadic) ! (monadic) @ * / REM + - (monadic and dyadic) = ~= < <= > >= << >> NOT & | EQV NEQV -> , (conditional comma) TABLE , (comma in a table) (lowest, least binding) VALOF Operators of equal precedence associate to the left. VALOF is different from the other operators in that it operates on a rather than on an expression. In so far as this can terminate with an , VALOF is the least binding operator. 4.3 Semantics of expression _______________________ There are five context dependent modes of evaluation of expressions R-mode L-mode assignment mode truth value mode constant. 1.10.1979 17 BCPL Standard 4.3.1 R-mode expressions __________________ The normal mode is R-mode and unless something to the contrary is stated all expressions are evaluated in this mode. All operators are valid in R-mode. Brackets ________ (E) Brackets serve only to affect the grouping of operands of an expression. Function call _____________ E(E1, E2, ...) See procedure call section 6.7 Vector application __________________ E1!E2 The BCPL vector application is a symetrical operation such that: E1!E2 = !(E1+E2) Note that this implies E1!E2 = E2!E1. One interpretation of the expression E1!E2 is that E1 is a pointer to a set of contiguous cells (a vector) and E2 is an index. The result of the operation is the E2th cell of the vector. 18 1.10.1979 BCPL Standard Indirection ___________ !E The ! operator acts as an indirection operator. The expression E is evaluated and is interpreted as the address of a cell whose content is then the result of the whole expression. Address of __________ @E The operator @ causes E to be evaluated as an address. The expression E is evaluated in L-mode and the result of the whole expression is then this value. Arithmetic operators ____________________ The arithmetic operators * / REM + - operate on values as if they were integers. REM is the remainder (modulus) operator: if m/n = q and m REM n = r then q * n + r = m for m, n (except n=0), if m and n are both positive then q is the largest integer which satisfies the above equations for 1.10.1979 19 BCPL Standard positive r. The direction of rounding is undefined for the operator / if either of its operands are negative. For all arithmetic operations the effect of integer overflow is ignored. Relations _________ A relational operator compares the integer values of its two operands and yields a truth-value (TRUE or FALSE) as result. The operators are as follows: = equal ~= not equal < less than <= less than or equal > greater than >= greater than or equal These operators make arithmetic comparisons of their operands. An extended relational expression such as 'A' <= CH <= 'Z' is equivalent to 'A' <= CH & CH <= 'Z' Shift operators _______________ In the expression E1<>E2), E2 should evaluate to yield a non-negative integer. The value is E1, taken as a bit pattern, shifted left (or right) by E2 places. Vacated positions are filled with 0 bits. If the value of E2 is an integer larger than the word length on the implementation number of bits in a word then the then the result of the 20 1.10.1979 BCPL Standard shift operations is undefined. Logical operations __________________ These operate on values considered as bit patterns: the operator NOT causes bit by bit complementation of its operand. The other operators combine their operands bit by bit according to the following table. Operands Operator & | EQV NEQV 0 0 0 0 1 0 0 1 0 1 0 1 1 0 0 1 0 1 1 1 1 1 1 0 Conditional operations ______________________ E1 -> E2, E3 E1 is evaluated in truth-value mode. The result of the expression is the value obtained by either evaluating E2 or E3 depending on whether E1 yields TRUE or FALSE, respectively. If E1 yields neither then the result is undefined. Table _____ The value of the expression TABLE K0, K1, K2, ..., Kn 1.10.1979 21 BCPL Standard is the address of the zeroth element of a static vector of n + 1 cells initialized to the values K0, K1, K2, ..., Kn which must be constant expressions. VALOF expression ________________ The expression VALOF C where C is a command, is evaluated by executing C until a RESULTIS command is encountered. The value of the VALOF expression is then the value of the expression contained in the RESULTIS command and execution of C finishes. 4.3.2 L-mode expressions __________________ L-mode expressions occur in two contexts: a) as operand of the @ operator, or b) on the left hand side of an assignment command. An expression is evaluated in L-mode to give the address of a cell. Therefore only the following constructions are allowed: N where N is an identifier which is the name of a dynamic, static or global cell. The value is the address of the given cell. !E where E is any expression. The value is E E1!E2 where E1 and E2 are any expressions. The value is E1 + E2. 22 1.10.1979 BCPL Standard 4.3.3 Assigment mode ______________ An assignment mode context occurs only on the left hand side of an assignment command. Here the expression is evaluated to give the address of a cell in which a value will be stored. For further details of the assignment command, see section 5.2. 4.3.4 Truth-value mode ________________ A truth-value context occurs whenever the result of the expression will be interpreted immediately as TRUE or FALSE. The expression is evaluated only so long as is necessary to determine whether it is true or false - more precisely: if after parsing (i.e. taking account of brackets and binding power) the least binding operator is &, | or NOT it is evaluated from left to right according to the following rules: Op Form of Evaluation as truth value Expression NOT NOT E1 E1 is evaluated in truth-value mode and if this is TRUE the result is FALSE, otherwise the result is TRUE. & E1&E2 E1 is evaluated in truth-value mode. If this result is FALSE, the whole expression is FALSE, otherwise the expression has the result E2 evaluated in truth-value mode. | E1|E2 E1 is evaluated in truth-value mode. If this result is true then the whole expression is true, otherwise the whole expression has the value of E2 evaluated in truth-value mode. 1.10.1979 23 BCPL Standard In all other cases the expression is evaluated in R-mode and the result is interpreted as TRUE or FALSE. If the result of this evaluation does not actually yield either of the values TRUE or FALSE then the result is undefined. 4.3.5 Constant expressions ____________________ A constant expression is one which must be evaluated at compile time and may include only: declared as MANIFEST constants ABS + - * / REM << >> NOT & | EQV NEQV 24 1.10.1979 BCPL Standard 5 Commands ________ The complete set of commands is given in this section ::= | | | | | | | | | A definition of compound commands and blocks is given in section 7.2. The definition of the remainder of the commands is given in the following subsections. 5.1 Routine call ____________ ::= See procedure call section 6.7. 5.2 Assignment __________ ::= ::= := Semantics _________ There are two basic forms of the assignment command: a) Simple assignment command E1 := E2 The expression E2 is evaluated in R mode to give a BCPL-word and the expression E1 is evaluated in 1.10.1979 25 BCPL Standard assignment mode to give the identity of a place where this should be stored. If E1 is an L-mode expression this is simply a cell in which the result is to be stored. b) Multiple assignment L1, L2, ... := E1, E2, ... The expressions L1, L2, ..., E1, E2, ... are evaluated and assigned to the cells defined by the assignment mode expressions L1, L2, ... in an undefined order. Some assignment may take place before all left and right hand expressions have been evaluated. 5.3 Conditional ___________ Syntax ______ ::= IF THEN | UNLESS THEN | TEST THEN ELSE Semantics _________ The semantic forms of the command are IF E THEN C1 UNLESS E THEN C2 TEST E THEN C1 ELSE C2 E is evaluated in truth-value mode and if the result is true C1 is executed otherwise C2 is executed. 26 1.10.1979 BCPL Standard 5.4 Repetitive commands ___________________ Syntax ______ ::= WHILE DO | UNTIL DO | REPEAT | REPEATWHILE | REPEATUNTIL Semantics _________ The command is executed repeatedly until the condition () becomes true or false as implied by the command. If the condition preceeds the body (WHILE, UNTIL) the test will be made before each execution of the body. If it follows the body (REPEATUNTIL, REPEATWHILE) the test will be made after execution of the body which is therefore executed at least once. The rule that as much as possible is included in the construction being parsed (see section 3.3), applies here. Thus for example WHILE E1 DO C REPEATUNTIL E2 is the same as WHILE E1 DO $( C REPEATUNTIL E2 $) and E := VALOF C REPEAT is the same as E := VALOF $( C REPEAT $) 1.10.1979 27 BCPL Standard 5.5 FOR command ___________ Syntax ______ ::= FOR = TO [BY ] DO Semantics _________ FOR N = E1 TO E2 BY K DO C If the constant K is positive this is equivalent to $( LET N, d = E1, E2 WHILE N <= d DO $( C N := N + K $) $) If the value of K is negative N <= d is replaced by N >= d. If 'BY K' is omitted 'BY 1' is assumed. The declaration LET N, d declares two new variables N and d; d being a new identifier which does not occur in C. On some implementations (particularly 16 bit word addressed machines capable of addressing a segment of more than 32k words) the test is for N-d <= 0 or N-d >= 0 as the case may be. 28 1.10.1979 BCPL Standard 5.5 RESULTIS command ________________ Syntax ______ ::= RESULTIS Semantics _________ This command gives the result of the smallest textually enclosing VALOF expression (see section 4.3.1). It may occur only in the body of a VALOF expression. 5.6 Switchon ________ Syntax ______ ::= SWITCHON INTO where the compound command contains s. Semantics _________ A case label has the form CASE K: or DEFAULT: where K is a constant expression. The switchon command is executed by first evaluating the expression and if a case exists which has a constant with this value, then execution is continued from that label; otherwise if there is a default label execution is continued 1.10.1979 29 BCPL Standard from there; otherwise execution is continued from the point just after the end of the switchon command. 5.7 Transfer ________ Syntax ______ ::= GOTO | FINISH | RETURN | BREAK | LOOP | ENDCASE Semantics _________ a) GOTO E The expression is evaluated and interpreted as an address to which control is transferred. The only meaningful result of the expression is the value associated with a label (see section 6.8). GOTO may occur anywhere in the program where a command is allowed. The label to which control is transferred must be in the same procedure body as the GOTO command. b) FINISH may occur anywhere in the program where a command is allowed and causes an implementation dependent termination of the entire program. c) RETURN causes control to be returned to the caller of the current procedure. 30 1.10.1979 BCPL Standard d) BREAK causes execution of looping command to be terminated. Control is resumed just after the end of the smallest textually enclosing looping command. The resumption point must be in the same procedure body as the BREAK command. A looping command is either a repetitive command or a FOR command. e) LOOP causes execution of a looping command to be repeated. Control is transferred to the point just before the end of the body of the looping command. For a FOR command this is the point where the control variable is incremented and for the repetitive commands it is the point where the condition (if any) is tested. The resumption point must be within the same procedure body as the LOOP command. f) ENDCASE causes control to be transferred to the point just after the end of the smallest textually enclosing switchon command. The resumption point must be within the same procedure body as the ENDCASE command. 1.10.1979 31 BCPL Standard 6 Declarations ____________ Every identifier used in a BCPL program must be declared explicitly. There are 10 distinct declarations in BCPL which fall into two groups. a) Static declaration: Global, Static, Manifest, Function, Routine, Label. b) Dynamic declarations: Dynamic, Vector, Formal-parameter, For-command-control. The declaration of formal parameters is described in section 6.7. and the for-command is described in section 5.5. All other declarations except label declarations occur at the head of a block and are known as block-head-declarations. ::= | | | | | | 6.1 Scope and extent of block-head-declarations ___________________________________________ The scope of an identifier (i.e. the region of the program in which it is known) is the declaration in which the identifier is declared (to allow for recursive definition), the subsequent declarations and commands up to the end of the smallest textually enclosing block, or the end of the program if there is no textually enclosing block; but for dynamic declarations excluding any textually nested procedure bodies. This restriction on dynamic declarations means that no 32 1.10.1979 BCPL Standard reference may be made in a procedure to a dynamically declared identifier which is declared outside the procedure (such quantities are called dynamic free variables). Identifiers declared at the same level must have different names, but an identifier may be declared with the same name as one declared a different level. In this case the two identifiers are normally distinct and the identifier declared at the textually outer level is not directly accessible within the scope of the identifier declared at the inner level. (For exceptions see rule for initializing global cells in sections 6.7 and 6.8). The extent of an identifier (that is the duration at run time when a cell is actually assigned to the identifier) depends on the type of the declaration. There are two possible extents in BCPL. a) Static ______ The identifier is permanently associated with one particular cell and this cell remains available throughout the run. b) Dynamic _______ On each entry to the block containing the declaration a cell is associated with the identifier. This cell remains available until control passes to the end of the block containing the declaration. Note that if the declaration is invoked recursively there may be more than one instance 1.10.1979 33 BCPL Standard of the same identifier existing at any one time. 6.2 Global declaration __________________ The means of communication between separately compiled segments of a program is the global vector. Syntax ______ ::= GLOBAL ::= $( [;] $) ::= : Semantics _________ The declaration GLOBAL $( ; ; ... $) is a syntactic abbreviation of GLOBAL $( $) GLOBAL $( $) ... GLOBAL $( $) The declaration GLOBAL $( N : K $) (where K is a constant expression) associates the identifier N with the Kth cell of the global vector. Thus N identifies a static cell which may be accessed by N or any other identifier associated with the same global vector cell. 34 1.10.1979 BCPL Standard 6.3 Static Declaration __________________ Syntax ______ ::= STATIC ::= $( [; ] $) ::= = Semantics _________ The declaration STATIC $( ; ; ... $) is a syntactic abbreviation of STATIC $( $) STATIC $( $) ... STATIC $( $) The declaration STATIC $( N = K $) where K is a constant expression causes permanent allocation of a cell to the identifier N. This cell will be initialized to the value K prior to execution of the program. 1.10.1979 35 BCPL Standard 6.4 Manifest ________ Syntax ______ ::= MANIFEST sp is defined in section 6.3. Semantics _________ The declaration MANIFEST $( ; ; ... $) is a syntactic abbreviation of MANIFEST $( $) MANIFEST $( $) ... MANIFEST $( $). The declaration MANIFEST $( N = K $ ) causes the name N to be associated with the value given by the constant expression K. This association takes place at compile time and no storage cell is involved at run time. Thus the value associated with the name cannot be changed and the name cannot be used in a L-mode or assignment-mode contexts. 36 1.10.1979 BCPL Standard 6.5 Dynamic declaration ___________________ Syntax ______ ::= LET = ::= [, ] Semantics _________ LET N1, N2, ... Nn = E1, E2, ... En declares identifiers N1, N2, ... Nn. At run time a cell is allocated to each of these identifiers dynamically when control passes through the declaration, and these cells are initialized in an undefined order with the values E1, E2, ... En. The initial value may also be given as undefined (?) in which case no initialization takes place. 6.6 Vector declaration __________________ Syntax ______ ::= LET = VEC Semantics _________ LET N = VEC K declares a variable N which points to a vector of K+1 cells where K is a constant expression. At run time K+1 contiguous 1.10.1979 37 BCPL Standard cells numbered from 0 to K are allocated dynamically and a further cell is allocated with which the identifier is associated. This latter cell is initialized with the address of the zeroth cell of the vector. The cells of the vector are not initialized. 6.7 Procedure _________ There are two types of procedure in BCPL: the function and the routine. Syntax ______ ::= LET = ::= LET BE ::= () | () Semantics _________ Routines and functions are equivalent except that a function yields a result whereas a routine does not. A function may be called as a routine and a routine may be called as a function (returning an undefined value). The declarations LET N(P1, P2, ... Pn) = E LET N(P1, P2, ... Pn) BE C 38 1.10.1979 BCPL Standard declare a function (routine) named N with n parameters. The brackets are required even if n=0. A parameter has the scope of the expression E (command C). If the procedure declaration is in the scope of a global declaration with the same name, then the global cell will be initialized with the entry address of the procedure before execution of the program. Otherwise, a static cell is created, is associated with the identifier N, and is initialized with the entry address. A procedure is invoked by the call E0(E1, E2, ... En) where E0 is evaluated to give the entry address. In particular, within the scope of the identifier N, the procedure N may be invoked by the call N(E1, E2, ... En) provided the value of N has not been changed during execution of the program. Arguments are passed by value. Each argument (Ei) is evaluated and the value is copied into a newly created cell which is then associated with the parameter Pi. The order of evaluation of arguments is undefined. These cells are consecutive in store so that the argument list behaves like an initialized vector. The space allocated to parameters is 1.10.1979 39 BCPL Standard released when evaluation of the procedure is complete. Notice that although arguments are always passed by value, this value may be an address. 6.8 Labels and Prefixes ___________________ Syntax ______ ::=