DEC-10-LALMA-A-D ALGOL Programmers Reference Ver 3B Jul74
DEC-10-LALMA-A-D ALGOL Programmers Reference Ver 3B Jul74
~D~DD~D
DEC-10-LALMA-A-D
ALGOL
PROGRAMMER'S REFERENCE MANUAL
The information in this document is subject to change without notice and should not be construed
as a commitment by Digital Equipment Corporation. Digital Equipment Corporation assumes no
responsibility for any errors that may appear in this manual.
The software described in this document is furnished to the purchaser under a license for use on
a single computer system and can be copied {with inclusion of DIGITALis copyright notice} only
for use in such system, except as may otherwise be provided in writing by DIGITAL.
Digital Equipment Corporation assumes no responsibi lity for the use or reliabi lity of its software
on equipment that is not supplied by DIG ITAL.
The postage prepaid READERI S COMMENTS form on the last page of this document requests the
userls critical evaluation to assist us in preparing future documentation.
CHAPTER 1 INTRODUCTION
CHAPTER 4 CONSTANTS
CHAPTER 5 EXPRESSIONS
iii
CONTENTS (Cont)
Page
CHAPTER 9 ARRAYS
iv
CO N TENTS (Cont)
Page
CHAPTER 11 PROCEDURES
CHAPTER 12 SWITCHES
CHAPTER 13 STRINGS
v
CO NTENTS (Cont)
Page
vi
CO NT ENTS (Cont)
Page
e
CHAPTER 18 RUNNING AND DEBUGGING PROGRAMS
TABLES
vii
CHAPTER 1
INTRODUCTION
1.1 GENERAL
Where there is need for interpretation in the Revised Report, such interpretations as seem reasonable
have been made in light of current ALGOL opinion. Where no guidelines exist, ALGOL-68 is used as
a basi s • These po i nts are di scussed in Chapter 19.
The purpose of this manual is to teach the use of DECsystem-10 ALGOL. The manual is written both
for the user who is familiar with ALGOL implementations and for the user who has no knowledge of
ALGOL but is reasonably fluent in a high-level scientific programming language such as FORTRAN IV.
3
This manual is not a primer in high-I evel languages.
111 Revised Report on the Algorithmi c Language ALGOL-60 1l , Backus et al ., Communi cations of the
ACM, 1963, vol. 6, no. 1, pp. 1-17.
211 Report on the Algori thmic Language ALGOL-68 11 , A. Van Wijngaarden (Editor), B. J. Mai Iioux,
J. E. L. Peck, and C. H. A. Koster, Mathematisch Centrum, Amsterdam, MR101, October 1969.
The DECsystem-l0 ALGOL Compiler is that part of the DECsystem-10 ALGOL System that reads pro-
grams written in DECsystem-10 ALGOL and converts them into a form (relocatable binary) that is
acceptable to the DECsystem-10 Linking Loader. The compiler is also responsible for finding errors in
the user's source program and reporting them to the user.
Slight constraints are imposed on the way the user writes his program. These constraints, made to gain
the most desirable feature of a single-pass compiler, concern the order in which the user declares the
identifiers in the program and the use of forward declarations under certain special circumstances.
Such a compiler can process ALGOL programs rapidly and does not require the use of any backing
store. The minor restri ctions imposed wi II not normally affect the user.
The compiler accepts reserved word delimiters in normal mode, but it can also accept programs
using non-reserved delimiter words enclosed in primes. Refer to Chapter 18.
If the user is unfamiliar with any of the following terminology, he should refer to the Revised Report
and to Paragraph 1.5.
Programs compiled by the ALGOL compiler are run in a special operating environment that provides
special services, including input/output facilities for the object program.
a. The ALGOL Library, known as ALGLIB - a set of routi nes, some of whi ch are
incorporated into the user's program by the linking loader.
b. The ALGOL Object Time System, known as ALGOTS - responsible for organizing
the smooth running of the program and providing services such as core manage-
ment, peripheral device allocation, and fault monitoring in case the program
encounters an error condition at run time.
Some of the following words, used in this manual, may be new to the reader. Many have a FORTRAN
equivalent; where such an equivalent exists, it is enclosed in parentheses.
Delimiter Word - a single, English language word that is an inherent part of the
structure of the ALGOL language. Such words cannot normally be used for other
purposes. Example: BEGIN IF ARRAY.
Identifi er - a name, establ ished by user declaration, that represents some quantity
within a program.
Label {Statement Number} - an identifi er used to mark a certain statement in a program.
Control of program execution can be transferred to the statement following the label.
A numeric label {not available in DECsystem-lO ALGOL} is similar to a FORTRAN
statement number.
{continued on next page}
DECsystem-10 ALGOL programs consist of a sequence of symbols from the DECsystem-10 ASCII
character set. The meaning of individual characters, given in Table 2-1, is much the same as in other
high-level languages.
Table 2-1
DECsystem-10 ALGOL Symbols
: Colon; used to indicate labels, and separate lower and upper bounds in
array declarations.
= Equality; used in arithmeti c and string comparisons.
# Nonequality •
Compound symbols consist of two adjacent basic symbols. Any intervening spaces or tabs do not affect
their use. The compound symbols are shown in Table 2-2.
Table 2-2
Compound Symbols
Symbol Usage
Assignment
<= Less than or equal to
>= Greater than or equal to
Certain upper-case letter combinations are reserved as part of the structure of the language and may
not be used as identifiers unless the compiler used is a version accepting delimiter words in single
I quotes. Such an option is selected by using a special switch option (refer to Chapter 18). It is assumed
will always appear in the text of this manual as shown above and cannot be used as an identifier in a
program. If the al ternative method of representation is used, it would appear as
'PECIN"
and
RF G If'1
could be used as an identifier. Table 2-3 contains a list of all the delimiter words used in the language.
Table 2-3
Delimiter Words Used in DECsystem-10 ALGOL
AND 5.2.1
ARRAY 9
BEGIN 10
BOOLEAN 5.2
CHECKOFF 18
CHECKON 18
COMMENT 2.4
DIV 5.1
DO 8
ELSE 7.3
END 10
EQV 5.2.1
EXTERNAL 11.9
FALSE 4.2
FOR 8
FORWARD 11.8
GO 7.2
GOTO 7.2
IF 7.3
IMP 5.2. 1
INTEGER 3.2
LABEL 11
LINE 18
LISTOFF 18
LISTON 18
LONG 3.2
NOT 5.2.1
OR 5.2.1
OWN 15
PROCEDURE 11
REAL 3.2
REM 5. 1
STEP 8
STRING 13
SWITCH 12
THEN 7.3
TRUE 4
UNTIL 8
VALUE 11
WHILE 8
The readability of ALGOL programs can be enhanced greatly by the judicious use of spacing, tab for-
matting, and commentary. Spaces, tabs, and form feeds (page throws) may be used freely in a source
program subject to the following constraints:
a. Spaces, tabs, line feed, or form feed characters may not appear within delimiter
words.
b. Where two delimiter words are adjacent, or where an identifier follows a delimiter
word, they must be separated by one or more spaces and/or tabs.
c. Spaces, tabs etc., are significant within string constants •
•
Comments are introduced by either the word COMMENT or the symbol! (available in DECsystem-10
ALGOL, but not necessarily in other implementations of ALGOL). Such a comment may appear any-
where in a program; the comment text is terminated by a semicolon. Refer to Section 11. 10 for
additional means to add comments to a program.
An identifier must begin with an upper-case letter and optionally be followed by one or more upper-
case letters and/or decimal digits. An identifier may not contain more than 64 characters.
NOTES
1. Unlike FORTRAN, there is no implied type attach-
ed to an identifi er.
2. All identifiers in a program (except labels) have to
be "declared", that is, the use to which they are
to be put must be specified, usually before they are
used.
Examples:
ALPHA
P43
JiJK5
HOllSEHCLDEhTRIDIAGCi\ALII.ATION
3-1
DECsystem-10 ALGOL also permits the use of a decimal point as a "readability symbol II in the alpha-
betic portion of identifiers. These readability symbols can appear between two alphabetic characters
of an identifier and are ignored by the compiler. Thus:
Of\ICE'.AGAIN
and
PI.BY.TI,oJO
OI\!CFAGA IN
and
P J Fl YT ~JC'
respectively.
Note that
ALP h{\.3 .5
and
RFTA.22
are not identifiers, since the decimal point does not appear between two alphabetic characters.
There are five scalar variables, that is, variables which contain a single value:
a. Integer
b. Real
c. Long Real
d. Boolean
e. String
Integer, real, and long real variables are capable of holding numerical values of the appropriate type
(and only of that type). The range of val ues is as follows: integer: -34,359,738,368 through
34,359,738,367; real and long real: approximately -1.7&38 through 1.7&38; values less than approx-
imately 1.4&-39 in magnitude are represented by zero.
3-2
Boolean variables (similar to FORTRAN's Logical variables) can hold a Boolean quantity, which is
I usually one of the states TRUE or FALSE but, in general, can be any pattern of 36 bits.
String variables are somewhat more complicated. A full discussion of their properties is presented in
I Chapter 13. At this point, it is sufficient to say that string variables are really pointers to byte strings.
All of the above variables can be declared for use by preceding a list of the identifiers to be used by
the appropriate delimiter word for their type. Throughout this manual, a "Iist of items" consists of
those items arranged sequenti ally and separated by commas.
Examples:
INTEGER I, J, k;
BOCLEAN I5ITREALLYTRUE;
STRING 5,1;
a. Integer constants
b. Real constants
c. Long Real constants
4. 1 • 1 Integer Constants
Integer constants consist of a number of adjacent decimal digits, subject to the constraint that the
number represented must be in the range 0 through 34,359,738,367.
NOTE
Any preceding sign that appears in the program is not
considered part of the constant.
Examples:
24
92765Lil
Real constants consist of a decimal number (containing either an integral part or a fractional part, or
both) followed by an optional exponent. If the decimal number is unity, it may be omitted. The ex-
ponent consists of either the & or @ symbol followed by an optionally signed integer. This has the
effect of multiplying the decimal number by the power of ten specified in the exponent. If no decimal
number appears, a value of unity is assumed.
4-1
The range of real constants is approximately 1.4&-39 to 1.7&38; numbers less than 1.4&-39 are repre-
sented by zero. Real numbers are stored to a significance of approximately eight and one-half decimal
digits.
Examples:
3.141592653589793 3. 14159265
.0001 0.0001
4.37&5 437000.0
5&-3 0.005
&-6 0.000001
Long real constants are used to represent numeric quantities to approximately twice the precision
available with real numbers: about seventeen decimal digits. Long real constants are formed by
writing a real constant in floating-point form, but replacing the & or @ by && or @@.
The range of long real constants is the same as that of real constants, except numbers below approxi-
mately 3.0&&-30 can only be represented to singl e precision due to hardware considerations.
Examples:
Representation Value
3. 14159265358979323846&&0 3.1415926535897932
12&&-3 0.012
Octal constants consist of the symbol % followed by a number of octal digits. Up to twelve signifi cant
digits may appear {leading zeros are ignored); these digits are right justified.
Examples:
%777777777774
%0470
Boolean constants consist of the words TRUE and FALSE. They are equivalent to the octal constants
%777777777m and %000000000000, respectively.
4-2
4.3 ASCII CONSTANTS
Up to five ASCII symbols can be packed right justified to give an integer-type constant. The format is
a dollar sign ($), followed by up to five ASCII symbols enclosed within a delimiting symbol pair. The
leading delimiter symbol immediately follows the $, and may be a readable character or an invisible
one such as a space. Thus, the user can generate a single ASCII character constant by placing one
space on each side of it, and preceding the triplet by a dollar sign.
Examples:
$A 000000 000101
$/01234/ 160713 516674
String constants allow the user to store any reasonable length string of ASCII characters within a pro-
gram. The length of such a constant is restricted only by the amount of core storage availab Ie to the
user for the execution of the program. String constants may be used, typically, to output a message
during the execution of the program.
The string of symbols is enclosed within quotes (II). There are restrictions on the symbols that may
appear within the string.
Note that [[ and]] are stored as such in the byre string generated by the compi ler. ii and 1111 are
stored as a single i or II, respectively.
Square brackets are used to enc lose symbols that have a specific effect when the string is output.
These are discussed in Paragraph 16.6.2
Examples:
"ABCDEFGH I JKLIV,NOPCRSTUVl.JXYZ"
"(P5C]INPUT DATA:(SC]"
''''''AEE!]] := (i).};;"""
DECsystem-10 ALGOL arithmetic expressions are written in a form similar to that used in FORTRAN and
many other high-level scientific computer languages. The usual algebraic rules concerning precedence
of operators and brackets are followed (see Table 5-1).
Table 5-1
Operator Precedence
Priority
Operator
(decreasing)
parentheses 1
exponentiation 2
multiplication and division 3
addition and subtraction 4
There are two additional operators, DIVand REM, that indicate integer division and remainder,
respectively. They have the same precedence as ordinary division. Within the precedence scheme,
the order of evaluation is always from left to right. For example:
X t Y t L means (X t Y ) t Z
and
Unlike FORTRAN, when ordinary division of one integer by another is performed, the real result is
not rounded to an integer value.'
The integer remainder operator, REM, is defined so that for all integral M, N:
Arithmeti c expressions consist of operands, that is, identifi ers and constants, of the three types,
integer, real and long real, together with the arithmetic operands + - * / plV REM and t and
parentheses where necessary.
Identifiers are used to represent variables whose values are used when they appear in some calculation.
Since automatic conversion takes place as necessary when an expression is evaluated, the user may
freely mix the three different types of identifiers and constants.
Integer quantities may have more precision than can be represented in a real variable. The user must
beware of possible loss of significance in integral quantities used in mixed type expressions.
Three special functions are provided for use in arithmetic expressions. The first is the transfer function,
ENTlER, which converts a real or long real quantity into an integer quantity defined as the largest
integer value not exceeding the argument.
Thus
ENT I ER ( 3 • 5) = 3
and
ENTIER(-3.5) = -4
Thus
ARS ( -3 • S) = 3.5
and
A8S ( -3) = 3
The special function SIG N is the signum function whose argument can be integer, real, or long real.
The result is always integral, being minus one or zero or plus one, depending on whether the argument
is negative, zero, or greater than zero, respectively.
Thus
SIGj\!(-3.5) =-1
SIGN(3.S) =
NOTE
ENTlER, ABS, and SIGN are not reserved words. They
may be used for other purposes ina program.
f...
+ 3
X*Y/Z
P+8/R
X2 + Y
XJ-il
J . + E NT I E'R ( K - 2 )
SIGN(ENTIER(J/K) + 1)
(X + Y) t (-I)
5-3
5.2 BOOLEAN EXPRESSIO NS
Boolean expressions involve Boolean identifi ers, Boolean and octal constants, arithmeti c conditions,
and Boolean operators interspersed in an order similar to that of arithmetic expressions.
NOT is a unary operator that complements a Boolean quantity in the same way that a unary minus sign
negates an arithmetic quantity in an arithmetic expression. In this case, it changes FALSE to TRUE,
and vi ce versa.
Table 5-2 gives the result of A OP B where OP stands for one of the Boolean operators AND, OR,
IMP 1 or EQV, for all values of A and B.
Table 5-2
Function of Boolean Operators
A FALSE TRUE
B FALSE TRUE FALSE TRUE
A AND B FALSE FALSE FALSE TRUE
A ORB FALSE TRUE TRUE TRUE
AIMPB TRUE TRUE FALSE TRUE
A EQVB TRUE FALSE FALSE TRUE
Actually, Boolean variables may have a value consisting of any pattern of bits, rather than be confined
to the values TRUE and FALSE. The logical operations operate on a bit-by-bit basis according to the
preceding rules.
5-4
The actual test employed to determine the truth of a Boolean expression such as
BAND C
is to eval uate it and regard it as true if its value is nonzero, i.e., at I east one bit is set, otherwise it
is false.
This is particularly important when octal constants are used in Boolean expressions. For example, if
the user wishes to test a particular bit in a Boolean variable, an appropriate octal constant can be
used, for example:
BAND %1
is a Boolean expression that is true if and only if the bottom (least significant) bit of B is a one.
Arithmetic conditions are used as operands in Boolean expressions. They consist of two arithmetic ex-
pressions coupled with a comparator. The comparator, which decides the particular type of test to be
performed on the two expressions, is one of the following:
Such an arithmetic condition can be regarded as true or false according to whether the condition speci-
fied by the comparator is met when the arithmetic expressions on each side of it are evaluated. The
resulting condition may form part of a Boolean expression.
The following examples of Boolean expressions, shown in Table 5-3, also involve arithmetic conditions.
An integer quantity can be converted to a Boolean quantity by means of the dummy function BOOl.
Similarly, the dummy function INT converts a Boolean quantity to an integer quantity.
5-5
Table 5~3
Bool ean Expressions
Expression Meaning
NOTB NOT B-
B AND NOT C B AND (NOT C)
A OR B ANDC A OR (B AND C)
B EQV X<Y B EQV (X<Y)
X+Y<Z AND B OR P=Q (((X+Y)< Z) AND B) OR (P=Q)
The value passed by these functions is unchanged: the functions are included for semantic correctness.
Thus:
BOOl(I)
INT(B)
I NT(%400000000000)
as integer operands •
• BOOl and INT are not reserved words. They can be used for other purposes by declaring them as re-
quired. However I this practice should be avoided since it could lead to confusion.
6. 1 STATEMENTS
The statement is the basic operational unit in ALGOL-60. It describes an operation to be performed at
run time, such as an assignment.
6.2 ASSIGNMENTS
Assignments convey the value produced by the execution of an expression to a destination variable of
the appropriate type. This is done by writing the destination identifier, followed first by the symbols
: and = and then by the expression to be eval uated. Thus
X := Y + Z
causes the result of the addition of the values contained in the variables Y and Z to be placed in the
variable X.
When an assignment is made to a variable type differing from that of the result of the expression, a
type conversion is performed. Integer, real and long real expressions may be assigned to variables of
any of these three types, but not to any other types. Bool ean and string expressions can only be
assigned to a variable of their own type.
If a real or long real value is assigned to an integer type variable, a rounding process occurs.
I :::: X
ENTIER(X + 0.5>
being assigned to I.
When an integer expression is assigned to a real or long real variabl e, a conversion to that type is
performed. Real to long real conversion simply consists of zeroing the low-order precision word of
6-1
the long real result after assignment of the real result to the high-order part of the long real variable.
Long real to real assignments truncate the low-order part of the long real expression I after appropriate
rounding.
A value may be assigned simultaneously to several variables of the same type by a multiple assignment.
This takes a form such as
P := R := S := X + y - Z
All identifiers on the left-hand side of a multiple assignment must be of the same type. If the user
wishes to assign a value to two or more different types of variables, the "assignment within expression"
(embedded assignment) feature must be used, as below.
A parenthesized assignment may be substituted for any operand in an expression. For example,
X : = (y : = P +0 ) I Z
This causes the embedded assignment to be made after the inner expression P+Q is evaluated. Where a
type conversion is performed as part of an embedded assignment I the operand type is the same as that
assigned to the variable in the embedded assignment. Thus
X := (I := 3.Ll)
All expressions in DECsystem-10 ALGOL are evaluated observing the normaf algebraic rules of prece-
dence, including bracketing.
Within the precedence structure, expressions are always evaluated from left to right. For example, if
X is a scalar I and F a function procedure (see Chapter 11) that alters X,
X := X+F
X := F+X
6-2
This is known as a "side effect" •
Consider also:
A[IJ := (I := 1+1)
The subscript I is always evaluated before I is incremented, as it is to the left of the embedded assign-
ment, within the statement. Thus the above expression is equival ent to
J := I; I := 1+1; AfJJ := 1
The user can always predict the order of evaluation of an expression and can count on such things as
X := (P := P+Q)/(P+j-O
P : = P +0
x .- P/(P+R);
For exampl e:
REG I [\.1
. - 3; J :="4;
K.- + J;
x •- K
FI'-:D
is a compound statement. Semicolons do not have to appear after the BEGIN or ~efore the END;
BEGIN and END act as a type of bracket.
6-3
CHAPTER 7
CONTROL TRANSFERS, LABELS, AND CONDITIONAL
STATEMENTS
7.1 LABELS
A label is a method of marking a place in a program so that control can be transferred to that point
from elsewhere in the program.
DECsystem-10 ALGOL uses identifiers as labels. These identifiers are placed before statements and are
followed by a colon. Numeric labels are permitted in the Revised Report, but are not implemented in
DECsystem-10 ALGOL. Most implementations of ALGOL-60 do not allow integer labels.
For example:
CO ty'P: X : = X + y
LAB: .- .., := 31
).<:= + J;
GOlO LAB
END
is an example of a somewhat tedious program. Clearly, to write any reasonable program, it is neces-
sary to be able to jump conditionally.
Conditional statements provide a method to make the execution of either a statement or a compound
statement dependent on some condition in the program, such as the value of a variable. The simplest
form of a conditional statement is
IF f-l THFi\' .s
IF X < Vl THEi\' I := I + 1
Here, X <0 is the Boolean expression and I := I + 1 is the statement which is obeyed if and only if the
Boo I ean condition is true, that is, if X is negative.
IF R THF~ 51 ELSE S2
In this case, the statement Sl is obeyed if and only if the Boolean expression B is true, and S2 is obeyed
I
if and only if it is false. In order to eliminate the "dangling ELSE ambiguity" (a construction in which
. an ELSE could be pai red with either of two THENs), S 1 must not be a conditiona I, FOR, or WHILE
statement which ends in an ELSE clause. (Refer to Chapter 14 for more complete information.)
A control transfer, a type of statement, can appear ina condi tional statement. Thus:
HEGJN INTFGEh: I;
•- (/l;
LP.P: + 1;
FND
is a simple way of counting to one hundred. More sophisticated methods are shown in Chapter 14.
The FOR statement enabl es the user to iterate a portion of the program in a fashion similar to, but more
sophisticated than, FORTRAN's DO loop.
FORPST can consist of any number of FOR elements (separated by commas). A FOR element takes one
of the following forms:
a. An expression:
E
I
b. A STEP-UNTIL element taking the form:
E1 STEP E2 UNTIL E3
c. A WHILE element taking the form:
E WHILE B
where B is some Boolean expression.
Any number of FOR elements may appear in a FOR statement; they are executed seria"y. Consider the
following examples:
This particular form deserves closer inspection, because it is not quite as simple as it appears. For
example, consider
The statement S is obeyed with I taking an initial value of 1, and being incremented by I until the final
value N is achieved. The question is, "ls the I after the STEP recalculated during each turn around
the loop, or does it have a constant val ue equal to the initial val ue of I?"
$;
V : = V + E2;
L2 :
(::Jearly, the value of I following the STEP in the previous example is evaluated, if necessary, twice
during each turn around the loop, once in the sign test at L1, and again to update V. ALGOL allows
the user to modi fy V, E1, E2, and E3 freely throughout the loop, and takes account of all these
changes in the evaluation of the loop.
NOTE
DECsystem-10 ALGOL allows the user the abbreviated form
FOR V := E1 UNTIL E3 DO S
instead of
FOR V := E1 STEP 1 UNTIL E3 DO S
FOR V := E WHILE 8 DO S
SJ
GOTOLIJ
L2 :
Once again, the complexity of the loop may be affected by changing Vand E within the loop.
l.rJH ILF.: R DO S
GOTO Ll;
L2:
1. Within a FOR statement of any kind, the user can change the controlling variable
or any other variable appearing within the action of the loop. Such changes pre-
dictably affect the execution of the loop by the rul es given above.
2. On exit from a FOR statement either by jumping out of the loop or by exhausting
the FOR elements, the controlling variable has a well-defined value equal to
the last assigned value of the controlling variable. This may not be true of other
ALGOL-60 implementations. Section 4.6.4 of the Revised Report should be
studied carefu IIy in this connection.
9.1 GENERAL
Arrays are essentially collections of variables of the same type, allowing the user to address them
individually by means of a common name and a unique subscript or subscripts. In the simplest case, an
array is a vector and is known as a one-dimensional array. A matrix is a two-dimensional array, etc.
There is no limit to the number of subscripts allowed, other than those imposed by the ability of the
computer to store the array.
Arrays may be of type integer, real, long real, Boolean, or string. They are declared in a similar
fashion to scalar variables, except the size of the array must be stated. For each subscript that the
array possesses, a lower and an upper bound, call ed the IIbound pair" for that subscript, must be given.
For example, to declare two one-dimensional integer arrays A and B with lower bound 1 and upper
bound 5:
Note that the lower and upper bounds are enclosed in square brackets and separated by a colon.
When there are two or more subscripts, the declaration is similar, and the bound pairs are separated by
commas. Thus
declares three real arrays, P, Q and R, with the first subscript bounded by -5 and 2 and the second
subscript bounded by 0 and 10.
It is possible to declare arrays of different sizes in the same statement provided they are of the same
type:
9-1
Note also that in the case of real arrays, the REAL may be omitted in the declaration, and is assumed
by default, thus:
The bounds in an array need not be stati c, as in the examp Ies above. In general, they may be any
arithmeti c expressions, which are eval uated to give an integral value for the individual bound pairs.
The use of such dynamic array declarations will become apparent later.
An individual element of an array can be referred to by following the name of the array by a list of
subscripts in square brackets. The number of subscripts must be identi cal to the number in the array
declaration. Thus, a typical element of A used in the last declaration might be
A[ 5 J or A(9J or generally, A[ I ]
where I is some integer expression or, in general, any expression whatsoever, with the limitation that
its value when used as a subscript and evaluated as an integer is in the range 1 through 10, the bounds
of the array A.
and suppose that it was required to set F equal to the matrix product of D and E:
FClH llNT I L 1'" 0 0
FOR J . - UNTIL 10 DO
BEG I N X: = {1;
F[I,JJ .- X
END
Note that X is used to accumulate the inner product of the multiplication for all values of I and J.
It would be very inefficient not to use such a variable, because F would otherwise be needlessly in-
volved in the inner loop of the computation.
Also, note that an element of an array of a particular type may be used anywhere that a scalar variable
of the same type may be used, even in such places as the controlling variable in a FOR statement.
10.1 GENERAL
ALGOL program structure is somewhat more complicated than other high-level languages, such as
FORTRAN. An ALGOL program consists of a number of "blocks" arranged hierarchically; a block con-
sists of the words BEGI N and END enclosing declarations and (optionally) statements.
Thus:
BEGIN
BEGIN
END
Hl~(~ 1[\,1
bEGIN
END
E!\'D
The block structure offers the user many interesting features not available in non-block structured
languages. For instance, the user may declare an identifier that appears to conflict with another
identifi er in an enclosing block. Thus:
BEGIN TNTEGEr< I;
END
END
10-1
In fact, there is no conflict as there are two different Is. The only I that statements in the outer block
can IIsee ll is the one in the outer block. Similarly, any statements in the inner block will always use
the I in that block. Such a declaration in an inner block is known as a IIl0cal" variable; it takes
precedence over declarations occurring at an outer or more "global" level. In general, all variables
can be "seen" from any point in a program that is either in the same block as the declaration or in a
block that is enclosed by the block in which the declaration of the variable occurred. Note that a
more local variable is always taken in preference to a relatively global variable. Consider the follow-
ing example:
(1)
[2 ]
END;
kEGIN INTEGEI-'( I, K
[3 ]
END
END
Any statements occurring at point [l] can see the declarations of I and J, whi ch are local, but cannot
see the declarations of J and K in the first inner block, or the declarations of I and K in the second
inner block. At [2], the local variables J and K can be seen, as can the global variable I in the outer
block. The global variable J is not seen because the local variable J takes precedence over it; the
variables I and K in the second inner block are not seen at all. A similar situation occurs at [3];
here both local variables I and K, as well as the global variable J, are seen.
Note that the "scope" of a variable is the set of all places in a program where it can be seen and
therefore used. This term will be used frequently throughout this text.
In general, it is more efficient to use local variables in preference to global ones. This statement is
also true of most ALGOL-60 implementations. Where a non-local variable is used frequently, it is
advisable to assign its value to a local variable and use that in preference. For example:
10-2
f-<FG J (\1 INTFGFh 1;
I : = •••••
F. E G 11\'
II := I;
I I •••••
~ND
Here, in the inner block, a local variable II is used, and assigned the value of the global variable I
for use throughout the local block.
The concept of the scope of a variable can be applied most usefully to arrays. In DECsystem-10
ALGOL, all arrays are constructed at execution time, that is, no fixed space is reserved for them by
the compi! er, irrespective of whether their bounds are stati c or dynamic. 'lYhen a declaration of an
array is encountered within a block, the space required to construct it is obtained and the array is laici
out. 'lYhen the end of the block enclosing the array is reached, that is, the array variable is no longer
within scope, the space utilized by the array is recovered and can be used later for other arrays.
Consider the case of a problem in which the size of an array to be used in a calculation is dependent
on the data to be processed. The programmer has the choice of making the array large enough to cope
with the worst case (in many languages he does not have any choice at all) or constructing the array
with dynamic bounds to suit the size required by the particular data. The first method has the disad-
vantage of wasting space on many occasions; the latter method only has the minor disadvantage of the
overhead needed to construct the array. Such overhead is very small compared to the running time of
most programs; therefore, the second method is more desirabl e.
10-3
Consider the following example:
BEGIN INTEGER N;
E i\'O.;
GOTO l.
FND
A value for N is calculated in this example, possibly dependent on some data read into the program,
and used to declare the array A, which is used to process the data in the inner block. When the end
of the inner block is reached, the space used by A is recovered and control passes to L, where another
val ue for N is cal culated, and the process repeated.
Procedures are similar in concept to the FORTRAN subroutine, al though more sophisti cated and general
in their possible applications.
A "procedure" is a portion of an ALGOL program that is given a name to identify it and can be
"called" from any part of a program which is in the scope of the body of the procedure. A procedure
can execute a number of statements, or it can return a value if it is a function procedure. In addition,
it mayor may not have parameters.
In DECsystem-l0 ALGOL, a procedure can be one of the following types: integer, real, long real,
Boolean or string, or it may be typeless. The formal parameters of a procedure, known as "dummy
variables II in FORTRA N, can be one of the following types: integer, real, long real, Boolean or string,
as scalars, arrays or procedures, or label. There are seventeen different types of parameters. In
addition, all of these parameters may appear in two different modes, neither of which is the same as
FORTRAN's method of handling parameters.
Call ing parameters by "val ue" is the most common and, with the exception of arrays, the most effi ci ent
way to pass a parameter to a procedure. The val ue of the expression presented ina procedure call ,
known as the actual parameter, is evaluated on entry to the procedure and assigned to a formal param-
eter within the procedure. This formal parameter acts exactly as if it were a local variable of the pro-
cedure which is ini tialized with the val ue of the actual parameter suppli ed in the call to the procedure.
I
Since, in the case of arrays or strings, a new copy of the array or string is made, this type of param-
eter-passing for arrays and strings (if they are very long) should be avoided unless it is specifically
requi red.
Calling parameters by "name" is a very sophisticated method of passing a parameter to an ALGOL pro-
cedure. Whenever the formal parameter associated with the actual parameter in a procedure body
A( I )
it would be re-evaluated using the value of I available each time the formal parameter is used, not the
val ue of I at the time the procedure body is entered.
Table 11-1 shows the different types of formal parameters, together with valid actual parameters that
can be substituted in a procedure call.
Table 11-1
Parameters in a Procedure Call
*In the case where the array parameter is called by value, any arithmetic type
(integer, real, or long real) array is allowed as an actual parameter. A type
conversion takes place during the copying process.
11-2
11.3 PROCEDURE HEADINGS
Procedure headings identify the type of procedure and the number and type of its parameters. They
precede the body of the procedure.
The formal parameter specification that follows consists of a list of descriptions of the formal param-
eters, appearing in any order, and a value specification if any of the parameters are to be called by
value. (If this is omitted, the parameters, by default, will be called by name.) For example, the
specifi cation of the formal parameters for the second exampl e above might be:
VAlliE I, J; I I'!TEGEf~ I, J, K;
meaning that all three formal parameters are of type integer (scalars), and I and J are to be call ed by
value, while K is to be called by name. A typical formal parameter specification for the third ex-
ample might be:
The body of a procedure is that part that follows the procedure heading. It consists of a single state-
ment, a compound statement, or a block. In the last-mentioned case, there may be declarations of
local vari abies within the block, and also other blocks or procedures. Consider the following exampl es
of realistic procedures:
July 1974
11-3
a. A real procedure, squareroot, to calculate the square root of a real quantity. The
first parameter is the argument; the second is a label that is used as an escape if
the argument is found to be negative. The result of the procedure is the square
root of the argument. Note how the result of the calculation is assigned to the
procedure by placing the name of the procedure on the left-hand side of an
assignment.
Y : = (1 + X) 12 ;
Y := Z; GOTO IT;
END
The previous example uses the Newton-Rapheson method of finding the square
root of a number: taking an initial approximation (l + X)/2 and iterating until
the difference between successive approximations is less than 1&-6. AI though
this is a very simple procedure, it is more enlightening with the aid of some
commentary. The DECsystem-10 ALGOL alternative method of commentary
(refer to Chapter 2) is used for brevity:
REAL Y"Z;
IT:
11-4
OK:
END
b. This function evaluates the sum of the values of any real procedure G over the
integers 1 ••••• N, where N is also a parameter of the procedure.
FOE I : = 1 UNT I L N DO X •- X + G ( N) ,;
SUM .- X
END
Notice in this example how the formal parameter G is invoked so that the actual
procedure that is substituted for G is called.
In the preceding example, the procedure G was "called". Since G is a function procedure, it is only
necessary for its name to appear in an expression for the procedure to be entered with the actual
parameters speci fied substituted for the formal parameters.
P := SOIlARFROOTCZ + (1).5)
An exampl e of the use of the procedure sum can be used to cal cui ate the sums of the square roots of
the first J integers, with the result squared, as follows:
X := SUMCSQUAREkOOT,J)f2,;
11-5
Here is a further example of a procedure and its calls:
PROCEDURE MATRIX[V'ULT(A.,B,C"N),;
FOR .- UNTIL N DO
FOR J .- UNTIL N DO
B [ I , K] *C [ K., J ] ,;
A[I.,J] .- X
END
END
or
fv'A T R I X tv'' L T ( F ., F " F , N ) ,;
I Since the arrays are called by name, a call such as MA TRIXMUL T(E, E, F, N)i would give rather interest-
i ng resul ts •
This call could be made to work by calling Band C by value. However, this would increase the over-
head of the procedure considerably.
This method of using a procedure exploits the power and flexibility of the call-by-name concept.
Consider the following example:
y : = "'.;
F OR I : = I II NT I L N DO Y • - y + X.;
SUM .- Y
END
On the surface, the procedure appears to cal cui ate the val ue of N*X. However, consider the call
Z := SUM(j,ln,A[j).;
and remember that J and A [J] are parameters call ed by name. Since I and consequently J take new
values, each X in the loop is evaluated as a particular value of A [J], using the value of J just assign-
ed. Hence the above call calculates
11.6.2 Recursion
ALGOL procedures have the inherent abi lity of recursion, that is, they may call themselves, directly
or indirectly, to any reasonable depth. (The only restriction is the amount of core storage available
to the object program.)
An often-quoted and very inefficient method of calculating the factorial function of a small positive
integer N is:
IF N = 1 THEN FACTORIAL := 1
Note that this procedure has only a single statement, but no local variables. Therefore, it can be
written in a very compact form. A call such as
j := FACTORIAL(6);
11-7
causes the procedure to be entered with N equal to 6. The call to FACTORIAL inside FACTORIAL
enters the procedure a second time with N equal to 5, but this N is different from the one to the pre-
vious N, which retains its value of 6, as it is stored in a different space. In this particular case,
FACTORIAL is entered six times, the last time with N equal to 1.
Declarations must always be made at the head of a block, before any assignments, procedure calls,
I etc., in the following order: 1) scalars and arrays and 2) procedures and switches (see Chapter 12).
Any procedure bodies that occur in a block should follow the declarations at the head of the block,
although this is only enforced when necessary. Consider the following example:
REGIN
BEGIN INTEGER JJ
J : = I;
END;
INTEGER I.;
The assignment of I to J within the b~dy of P utilizes the I that is declared following the body of P,
rather than some global I. However, the compi ler has not yet seen this I and, therefore, ca~not take
any rational action. In a case such as this, the user must declare I before the body of P:
BEGIN I NTEGEk I 1
REGlt\l INTEGER J;
J : = I;
END;
If the user neglects to declare I before P, the compiler can easily detect the condition, because either
I is unknown at the time of the assignment to J, or else there is a more global I available, whereupon
an error message will occur when the declaration of I is found following the body of P.
Although most ALGOL-60 compilers operate in two or more passes, the DECsystem-10 ALGOL compiler
operates in one pass. Consequently, it has to make some minor restrictions to ALGOL-60 in order not
to restrict the user in other ways.
A forward reference for a procedure has to be given when a procedure is called (either directly, or in-
directly, by passing its name as an actual parameter in a procedure call) before its body is encountered
by the compiler. In most cases the user can avoid this situation by a minor re-ordering of the program.
t-bwever, in rare cases like the following, where procedure P calls procedure Q, and vice versa, a
forward reference, as shown, must be given.
BEGIN
BEGIN kEPL Y;
Y := oeX);
END;
BE GIN f~ E A L F;
F := pez);
END;
In general, a forward reference consists of the word FORWARD, followed by the type of the procedure
I (omitted if the procedure is typeless), the word PROCEDURE, and the name of the procedure.
For example:
or
I A forward reference has to be given for a label in one of the following rare cases:
a. The label is used as an actual parameter in a procedure call, and has not yet
appeared in the program.
b. A variable of identical name has appeared in the program and is in the scope of
the procedure call •
For example:
BF-GIN REAL L;
BEGIN F"ORHARD L;
P (L);
L:
END;
Such an EXTERNAL declaration can be made in any block within the program, and has the same scope
as if the procedure appeared at that point.
Two further ways of writing commentary are available to the user in addition to COMMENT and
described in Section 2.4.
Following the delimiter word END I the user may add commentary, terminated by a semicolon, with the
following restrictions:
For example:
This method of commentary allows the user to comment formal parameters in a procedure heading. This
is done by enclosing the commentary, which may consist of letters only, between the symbols) and :(
and omitting the comma on the left of the formal parameter. This cannot apply to the first formal
parameter.
In a similar fashion, a call to such a procedure can be commented. The following example uses the
call to SUM in Section 11.6.1:
12.1 GENERAL
Switches enable the user to jump to one of a number of labels, depending on the value of an arithmetic
expression. In addition, they provide an automati c detection when such an expression is out of range
for the switch.
A switch declaration takes the form of the word SWITCH followed by (a) the name of the switch, (b)
an assignment (:=), and (c) a list of label~, called switch elements, all of which must be in the scope
of the switch declaration. For example:
A switch name must fo lIow the usual rul es of scope with regard to its use and, therefore, must not
conflict with any local variable of the same name.
In addition to the example above, a switch element itself may be one of the labels in the switch
declaration.
A jump to a particular label in a switch declaration is made by following the word GOTO with the
name of the switch and an arithmeti c eXFession in square brackets. Thus:
(JOTO SIN[ I )
This causes control to pass to the 11th label in the switch declaration, unl ess I is negative or zero, or is
larger than the number of switches in the switch declaration. In either case, there is no transfer of
control. If the expression in square brackets is not integral, it is evaluated and rounded as usual.
12-1
Consider the following more complicated example:
SWITCH SW .- LAB~Ll~L2~OK~STOP;
SWITCH TW .- L3~SW[JJ~L4;
GOTO TW [ I J;
If I has the value 3, a jump to L4 occurs. If I has the value 2 and J has the value 1, a jump to LAB
occurs, via SW.
12-2
CHAPTER 13
STRINGS
13.1 GENERAL
In D ECsystem-10 ALGOL, the concept of a string has been considerably extended from the somewhat
limited feature of ALGOL-60.
A string is a type of variable that may be scalar, array, or procedure. For example:
STRING S,T;
I String expressions are limited to a single string variable, a string procedure call, or string constant;
there nre no string operators other than the comparison operntors described in Paragraph 13.5. Such a
string expression can only be assigned to another string variable. For example:
S : = T;
SA [ I) •- SA [3 ) ;
SA (2) •- 8 ( Z) ;
T:= "ABCDEFGHIJKLMNOPQRSTUV~'JXYZ";
The function of a string variable is to "possess" (or point to) a byte string. Byte strings are merely
strings of bytes of some particular byte size, between one and thirty-six bits. Byte strings can be
handled very efficiently by DECsystem-10 hardware. They form a flexible storage medium for strings
of bits, characters, or any useful quantity.
Byte strings can be of any reasonable length; in fact, the permissible length is sufficient to allow a
string of one bit bytes to stretch throughout the entire DECsystem-10 core storage. When a string
variable possesses a byte string, the I ength of the byte string, and the size of the bytes in it, are stored
in the string variable.
S := T;
where Sand T are both string variables, S also possesses the byte string that T possessed prior to the
assignment. Note that possession of a byte string is not a monopoly: several string variables can
possess the same byte string and operate on it independently. It is important to remember that the
assignment of one string variable to another does not involve making a copy of the byte string that the
first string variables possesses.
S := "ABeD";
the effect is as if an anonymous string variable had already possessed the byte string and assignment of
this anonymous byte string were made to S.
String variables would not be very useful if it were not possible to access the individual bytes of a byte
string possessed by a string variable. This is done by means of "byte subsc'ripting ll the string variable.
A byte subscript consists of a decimal point, followed by a subscript in square brackets, for example:
S. [ 1 J
This notation means the 11th byte in the byte string that is possessed by the string variable S. I may,
of course, be any expression, and is evaluated in exactly the same way as an array subscript.
A byte-subscripted string variable may appear on the left-hand or right-hand side of an assignment.
When it is on the right-hand side, or generally appears as an operand in an arithmetic expression, it
yields an integral value equal to the value of the particular byte in the byte string. For example,
J := S.[1J
sets J equal to the value of the 11th byte in the byte string possessed by the string variable S.
13-2
When a byte-subscripted string variable appears on the left-hand side of an assignment, it causes the
value of the expression on the right-hand side of the assignment {rounded to an integer if necessary,
and truncated if it is too large for the particular byte size} to be stored as the new value of the partic-
ular byte addressed. For example,
S.[K) := J
causes the KIth byte in the byte string possessed by the string variable S to be set to the value of J.
When a string variable is a particular element of a string array, byte subscripting follows the usual
array subscripts. Thus, assuming the declarations at the start of this chapter, the user can write such
things as
SA [ J ) • ( I + 1) : = S. ( K - 1) + 1
Note that string constants but not string functions may be byte subscripted.
where Sand T are string variables, string constants, or calls to a string procedure. The comparison is
performed by comparing the byte strings that the string variables possess, byte by byte; the IIlesser"
string being the one with the first lower value byte, working from left to right. Thus IIABCD" is less
than IIABCEII, and "ABCD" is less than "ABCDEII.
Note
The following feature wi II be removed from versions
of ALGOL from 4 onwards, and users are recommended
to use the COPY procedure described in 13.6.2.
13.6.1 Concatenation
Strings can be concatenated to form chains, rings, or trees of string variables by forging a link between
one string variable and another. This process is independent of any byte string possessed by the string
variables involved.
Whenever two strings are Iinked together, the byte subscripting of the first extends to the second.
A link between two unattached strings can be made by a call to the procedure LINK or LlNKR
(join to the right). Thus, if Sand T are strings,
LINK(S,T);
S := "ABeD"; T := "EFGH";
13-4
The string procedure TAIL enables the user to move along a structure of strings. Its first parameter is a
string that is taken as the head of the structure. The second parameter is integral and specifies the
number of links to be skipped in the chain. Thus in example b. above,
V := TAILCS,1);
~'J : = T A I L CS , 2 )
If the second parameter is zero, or greater than or equal to the number of non-repetitive links in the
structure, the result is the string at the bottom of the chain; in this case U, as it links to T, which has
already been encountered while searching down the chain S - T - U.
The length of any byte string (excluding any possessed by concatenated strings) is yielded by the integer
procedure LENGTH, that takes a string as its only parameter.
Thus:
I := LENGTHCS);
A new byte string can be generated from an existing byte string by means of the string procedure COPY.
STRING S,T;
T .- "ABCO";
S .- COPYCT);
a new byte string is generated , identi cal to that possessed by T, and assigned to
the string variable S. If any strings are concatenated with T, the byte strings
possessed by these string variables are also copied into the new byte string.
b. If there are two parameters, for example,
S := COPYCT,M);
where M is some arithmetic expression, the 1st through Mth bytes of the byte
stri ng possessed by Tare copi ed •
13-5
c. If there are three parameters I for exampl e I
the Mth through Nth bytes of the byte string possessed by Tare copi ed.
A new byte string can be generated by means of the string procedure NEWSTRING. This procedure has
two parameters: the number of bytes required in the new string and the byte size required. Thus
S := NEWSTkING (100,7»)
causes a byte string consisting of 100 7-bit bytes to be generated and possessed by S. All of the bytes
in the byte string are preset to a value of zero.
A dynamically-created byte string (i .e., one produced by the COpy or NEWSTRING procedure) can
be deleted and the space uti I ized by it retrieved. This is accompl ished by means of the procedure
DELETE I which takes as its single parameter the string which possesses the byte string. For example:
DFLFTF (S);
14.1 GENERAL
Consider, for example, if a user wanted to set a variable I equal to 0 or 1 according to the value of a
Boolean variable B, he could write:
I := 0;
IF B THF (\1 .- I;
Also r consider the case where a user wants to perform some action, depending on the value of B:
ALGOL-60 allows the user to substitute a conditional operand for any operand in an expression by the
use of a construction involving IF ••••• THEN ••••• ELSE.
I := IF B THEN 0 ELSE 1;
Clearly, this is more compact and of great use in cases such as:
Note that the conditional operand must be bracketed. It may be unbracketed only when it forms the
complete expression itself.
In general, a conditional operand may replace an operand in any arithmetic or Boolean expression. It
may also be used in place of a label as the element in a switch list, for example:
Since a conditional operand may replace any operand in an expression, it may also replace operands
in conditional expressions. Consider the following example:
This looks complicated but is really quite simple if brackets are inserted for clarity. Thus:
IF B THEN SI ELSE S2
in Chapter 7. The full power of this type of statement can now be demonstrated.
IF I < 0 TH£N
END ELSE
BEGIN .- I + 1; GOTO L2
END
Second, the whole structure of the IF ••••• THEN ••••• ELSE statement can be made more powerful
by using conditional statements within themselves. For example:
X := 0; GOTO l,2;
GOTO L;
L2 :
Clearly the former method of expression is both briefer and more elegant.
IF R THEN SI ELSE S2
where Sl and S2 may themselves be conditional statements with the provision that if there is ambiguity ,
bracketing using BEGIN and END must be used to remove it. Consider the following illegal example:
or
Y : = Z; GOT 0 L2;
Ll: P : = 0 J
1..2 :
Y .- Z; GOTD L2;
U: P .-0;
L2:
ALGOL-60 forbids such ambiguities by forbidding the sequence THEN IF ••••• THEN ••••• ELSE.
A designational expression is something that acts as an argument in a GOTO statement, either directly
or indirectly, via a formal procedure parameter of type label. It may simply be a label or a switch
el ement. Thus the follow ing are designational expressions:
IF B THEN Ll ELSE L2
Gr'TCI L;
G0TO IF R TH~N Ll FLSE L~;
I GOTO IF' X < V1 THE~J SI,-J[I) [L~E IF ;x.+y >= L THE:!\! 'J"I,HJ) ELSE LJ
15.1 GENERAL
I Own variables are a special kind of ALGOL variable, and may be of type integer, real, long real,
Boolean or string, either scalar or array. They have the following properties:
a. AI though they follow the normal scope rules, they are not recursive, the same
copy of each variable being used in all occurrences of a procedure or block.
b. The values they contain when control passes out of a block are retained and
are sti II available when the block is re-entered.
c. They are initi al ized to zero before execution of the program. (FALSE in the
case of Boolean own variables.) OWN STRINGS are initialized to possess no
byte stri ng •
Own variables are declared by writing the usual declaration with the word OWN preceding it. For
example:
Own arrays are implemented in a completely dynamic fashion in DECsystem-10 ALGOL. The
declaration proceeds according to the following rules.
a. If this is the first time the array is declared, space is obtained and then the array
Iai d out. If the array has been Iai d out before, proceed to Step b.
b. The bounds are examined to see if they are identical to those of the previous con-
struction of this array. If they are the same, the array IS left unaltered; otherwise,
proceed to Step c.
c. A new array is constructed and those elements that it has in common, if any, with
the old array are copied into it; the remaining elements are zeroed. The old array
is then deleted and the space used by it is recovered for future use.
where M = 2 and N = 5 the first time, and M = 1 and N = 4 the second time, the el ements [l ,2J ,
[l,3J and [l,4J are copied over, and the remaining elements of the new array are zeroed.
15-2
CHAPTER 16
OAT A TRANSMISSION
16.1 GENERAL
Data transmission encompasses the input and output of data between the user's program and peripheral
. devices, such as disk, DECtape, magnetic tape, card reader, card punch, and line printer. The
DECsystem-l0 ALGOL object-time system, in conjunction with the ALGOL library, provides the user
with a set of basic procedures for handling data from most DECsystem-l0 devices in a uniform fashion.
The user may also perform input/output operations with virtual peripherals that manifest themselves as
byte strings in the user's program.
All peripheral devi ces that the user requires are under his control completely and can be allocated or
released at any time throughout the execution of the program. The user can handle up to sixteen de-
vices simultaneously (seventeen, if one of them is the terminal attached to his job), any number of
which may be file devices (disk, DECtape) and have an independent file open.
Peripheral devices are allocated to the user's program by calls to the library procedures INPUT or
OUTPUT. A call to one of these procedures usually has two parameters. The first is the channel num-
ber, an integer in the range 0 to 15, on which the device is to operate. Only one device at a time
may be operated on a channel; a channel provides either input or output facilities, except in the case
of a terminal, where the input and output functions are performed simultaneously on the same channel.
The second parameter is either a string or a string constant. The text contained in the string is the
logical name of the device to be allocated to this channel.
The DECsystem-l0 Users Handbook should be consulted for an explanation of what constitutes a logical
device name. In the simplest case, it may be the actual name of the peripheral device. The device
names shown in Table 16-1 are recognized as standard.
DSK Disk
DTA DECtape
MTA Magneti c tape
CDR Card reader
CDP Card punch
LPT Li ne pri nter
PTR Paper-tape reader
PTP Paper-tape punch
PLT Plotter
TTY Terminal
For example, to allocate the card reader for use as an input devi ce on channel 5, the user would use
the statement
I N PUT ( 5 ~ .. C D /\" ) ;
or, if S were a string possessing a byte string that had the characters CDR in it,
INPUT(5~S);
OUTPUT(9,,"DSK");
Note that with the exception of terminals, all devices are allocated to operate in one direction only;
thus, if the user wants input and output from the disk, he must use two separate channels.
Terminals are always allocated bidirectionally, irrespective of whether the user uses INPUT or OUTPUT.
For example,
INPUT(0,,"TTY" ),;
Normally, a device is allocated in ASCII mode, that is, when the user reads a character from the de-
vice it is a 7-bit byte representing readable text, such as a stored source program or data. To allocate
the device in a different mode, a third parameter is specified in the call to the INPUT or OUTPUT pro-
cedure. Thus, to allocate a disk to channel 9 in image binary mode (the mode used for the storage of
binary data on a disk), the user can use
16.2.2 Buffering
The INPUT and OUTPUT procedures normally allocate two buffers for each allocated device; terminals
are allocated two buffers for input and two for output. The user may desire to use either one or more
than one buffer for a device. For example, in a non-compute bound job that uses a lot of disk trans-
fers at odd intervals, four or even eight buffers may be desirable to increase the speed of execution of
the program.
The number of buffers to be used can be controlled by adding a fourth parameter to the procedure call •
Thus, to allocate a disk on channel 14 in mode 0 with eight buffers, the call is
OUTPUT( 14,"DSK",0,S);
Note that the mode must always be specified in this case, otherwise there would be an ambiguity in
the third parameter.
Before a user uses a device to transfer data, assuming that the device has already been allocated to
some channel, the appropriate input or output channel must be "selected ll for use as the input or out-
put channel. All data input and outp.ut always occurs on the currently selected input channel and out-
put channel, respectively. The user may change the sel ection of channels at any time, switching from
one channel to another without loss of data, irrespective of whether complete lines {or records} of data
have been read or not. In fact, the DECsystem-10 input/output system does not assume any structure
I
in the data: all input and output channels are regarded as pipelines through which the user pulls or
pushes data.
To select an input channel, a call to the procedure SELECTINPUT must be made. This has one param-
eter, whi ch is the channel number. Thus
Some peripheral devices, such as disk and DECtape, require the opening of a specifically named file
before any input or output operations can be performed. This optionally may be performed on spooled
I devices (refer to Chapter 3 of DECsystem Operating System Commands for a description of spooling) •
. The opening of this file is performed by means of the procedure OPENFILE, which is called after the
devi ce has been allocated to a channel. The procedure call has two parameters: the channel number
on which the device has been allocated and a string variable possessing a byte string or a string con-
stant, the text of which is the name of the file.
The user can also specify a protection and/or project-programmer number of a file by means of optional
third and fourth Boolean or integer parameters. For example, to open a file with protection <177> on
disk area [11,50] the user could write
When a user has finished with a file, it should be closed. A file is closed by using the procedure
CLOSEFILE, with a parameter that is the channel number on which the file is open. Thus,
CLOSEFILE(9);
The user may also rename or delete existing files: if a file is already open, use of OPENFILE causes
the file to be renamed with the new name supplied. Thus the sequence
OPENFILE (5~"TEST2.DAT");
causes the file with name TESTl • DAT to be renamed TEST2. DAT.
If the string containing the new name is null, the original file is deleted. Thus,
OP EN F I L E (5 ~ I I T EST 3 • 0 AT" ) ;
OP E NFl L E (5 ~ .". ) ;
RELEASE(S);
If an attempt is made to allocate a device to a channel that already has a device allocated, the allo-
cated device is first released and, if a file is open on it, it is closed before releasing the device.
If a user terminates his program without releasing devices on channels, they are automatically released.
The following procedures may be used with any device to handle bytes of any standard size (l to 36
bits). However, because they are normally used with devices supplying or receiving ASCII bytes, they
are "symbol II ori ented.
a. INSYMBOL(S)i - (where S is usually some integer variable) causes the next byte
to be read from the currently sel ected input channel and stored inS.
b. OUTSYMBOL(J)i - (where J is usually some integer expression) causes the value
of J to be output as a byte to the currently sel ected output channel. If J is too
large for the byte size of the device in use, it is truncated to size.
c. NEXTSY MBOL(S)i - acts in exactly the same way as INSYMBOL except that
the byte pointer for the input channel is not advanced to the next available
byte. This gives the user a look-ahead facility of one byte.
d. SKIPSYMBOLi - causes the next byte from the selected input channel to be
read and ignored.
e. BREAKOUTPUTi - causes all bytes in the buffer of a device to be sent immedi-
ately to it. This procedure is normally used to conduct a question-and-answer
dialogue on a terminal, with the question and answer on the same line. Nor-
mally, a block of data is sent to a device only when the buffer is full (the
exception being the terminal, where a break is sent at the end of each line).
A byte string may have its contents transferred to the currently selected output channel by means of
the procedure WRITE, whose single parameter is either a string constant or a string variable that
possesses the string to be output. For example:
WRITE(S)J
or
WRITE("THE MOON IS MADE OF GREEN CHEESE");
16-5
With exceptions explained in the following paragraphs, all of the bytes in the string are output literal-
ly, with the exception, of course, of the quotes in a string constant, which are not in fact stored in
the byte string at all. The important thing to remember is that, unlike some other ALGOL implemen-
tations, spaces and other non-printing symbols in byte strings are meaningful.
Special editing characters are permitted within square brackets within the text of a byte string. These
have a special function:
P Page throw
C or N New line (C stands for carriage return, Iine feed)
T Tab
S Space
B Break output
I
Any combination of these characters, with optional repetition counts preceding them, can appear with-
in square brackets in a byte string and are output as their special interpretation demands. For example:
[ ] II or ;
[[ ]] 1111 or ;;
respectively. Thus
"A [ I J •- 3,;"
to be output.
The procedures SPACE, TAB, PAGE, and NEWLINE cause the appropriate number of spaces, tabs,
page throws, or new lines to be output, depending on their single parameter, which is an integer ex-
pression. If the parameter is omitted a value of one is assumed. Thus
SPAC E;
or
SPACE(l);
Numeric procedures are used to read and print numeric quantities. They will normally be used with a
device that is operating in ASCII mode. They are capable of processing inreger, real, or long real
quantities in fixed-point and floating-point representations.
16.6.4.1 Numeric Input Data - Numeric data for input can be represented in any format that would
be acceptable as a numeric constant in a program, irrespective of the type of variable involved. When
a number is read, an automatic type conversion is performed, giving a result of the same type as if an
assignment of the data represented as a constant in the program had been executed.
There is a minor restriction in that no spaces, tabs, or other non-printing symbols may appear in such
numeri c data except between the exponent sign (& or @ for real, && or @@ for long real} and the
exponent. Otherwise, any symbol that is not itself a part of a numeric quantity may act as a terminator
for such a quantity. It is strongly recommended that spaces, tabs, or new lines be used as separators.
For example:
Note that in reading a numeric quantity, the terminating symbol, that is, the first symbol that is not
part of the number, is lost.
DECsystem-10 ALGOL also allows the user to input floating-point data written in FORTRAN format,
that is, using E for & or @, and D for && or @@. Note, however, that no other special effects
inherent in FORTRAN formatting are introduced.
I The procedure READ is used to input numeric data and also strings. This procedure may have any num-
ber of parameters, of type integer, real, long real, Boolean, or string.
a. For integer, real and long real variables, a number is read and converted to the
type appropriate to the parameter and then assigned to the variable.
b. For Boolean, a number is read as if for an integer variable, and assigned to the
variable.
c. For a string variable, the data text is scanned until a quote (") is found, and the
text following this up to but not including the next free quote is read in and a
byte string generated, which is then possessed by the string variable.
If the sequence 1111 is found, a single II is stored, and reading of the string continues.
16.6.4.2 Numeric Output Data - Numeric data is output by means of the procedure PRINT. This
procedure may have one, two, or three parameters, the first of whi ch is the vari abl e to be printed.
I This variable may be an integer, real, or long real. The second and third parameters determine the
format to be used and are integer expressions. If they are omitted, they are assumed to be zero. The
effect of the various combinations of the format integers, M and N, is as follows:
If only two parameters appear, format M,O is assumed for integer variables, and format O,N for real
and long real quantities, where M and N are, respectively, the values of the second parameter.
If only one parameter appears, the format is interpreted as a,0 which assumes standard printing modes
of 11 ,0 for integer quantiti es, 0,9 for real quantiti es, and 0, 17 for long real quantiti es.
16.6.4.3 Octal Input/Output - The procedures READOCTAL and PRINTOCTAL, respectively, allow
the user to input and output quantities in octal format.
On input, for single precision variables, up to 12 octal digits are read, preceded by the symbol %, the
terminator being any non-numeric symbol. For long real variables, two such octal numbers must be
I presented for input, each preceded by the symbol %.
On output, 12 octal digits, preceded by the symbol %, are printed for single precision variables. For·
long real variables, two quantities each with 12 octal digits are printed, with a space separating them.
The foregoing procedures have one scalar parameter which may be of type integer, real, long real or
Boolean.
If the user does not select any input or output channels, input and output occur via an "invisible"
channel from and to the user's terminal. Thus, for simple programs where the user wishes to input a
few numbers and print a few results, he simply uses READ, types in the data on line through his
terminal, and gets back the results from PRINT.
In addition to the 16 channels used to communicate with peripheral devices, an additional 16 channels,
numbered from 16 to 31, are provided. These are input or output channels that use byte strings as a
means of storage.
By means of the procedures INPUT or OUTPUT, the user can attach a channel to a byte string possessed
by a string variable, and can read and write bytes from and to this byte string, either to or from a
peripheral devi ce, or to and from another byte string.
INPUT(20,S);
or
OUTPUTC20,S);
cause the byte string possessed by the string variable S to be used as logical channel 20; this channel
may subsequently be sel ected for input or output, as appropria te.
These procedures are used on channels assigned to magnetic tapes. They consist of the procedures
BACKSPACE, ENDFILE and REWIND, each having one parameter, i.e., the channel number on which
the operation is to be performed.
Since there is no impl i cit structure on a magnetic tape, these procedures enable the user to build up
formats in any way he chooses.
The status of any input or output channel can be determined at any time by means of the Boolean pro-
cedure 10CHAN, which takes as its single parameter an integer quantity which is the channel number.
The status returned is bit coded as follows:
Some of these bits are of I ittle use to the user, but, for example, if a device is allocated, and the user
does not know whether or not it is a file device, he can use I~CHAN to determine this. The bits of
particular use to the user are the input and output end-of-file (note that end-of-file on output is a
logical status indicating that, for example, a disk quota is exceeded or a DECtape is full ,-or-in-the-----------
case ofa logical device, the byte string is full).
The following example shows how the user would handle an unknown device whose name is given to the
program via the user's terminal:
REG IN
STRING DEVICE, FILE; INTEGEk CHAN~EL;
\-J R I T E ( I I C HAN NE L N(j: " ) ; E, k E A K • 0 l n p l'T ;
READ (CHANNEL);
t·ll"< ITE (" [C JDEV ICE NAt-IE: "); HI'F.M< .OUTPUT;
RFAD (OFVICE);
OUTPUT (CHANNFL, DEVICE);
IF IOCHAN (CHANNFL) AND %200000 THEN
8EGIN
':mITE ("[CJFILE t'JAtv'E: "); br-E{\K.OllTPUT;
HEAD (FILE);
OPENFILE (CHANNF~L, FILE)
END;
END
Once a device has been allocated to an input or an output channel, a complete file of information
may be transferred between them automatically by calling the parameter-less procedure TRANSFILE.
This procedure copies bytes from one device to another from the currently selected input channel to
the currently selected output channel, until an end-of-file status is raised on either the input or out-
• put cha nnel •
The operating environment of DECsystem-10 ALGOL programs consists of those procedures in the
DECsystem-10 ALGOL Library required by the user's program, and the DECsystem-10 ALGOL Object
Time System.
The former are those procedures detailed in Chapters 13 and 16, together with those described below.
These procedures can be thought of as existing in a block surrounding the user's program, and, there-
fore, are available when ca"ed. Their names, however, are in no sense reserved as are words such as
BEGIN.
Note also that these procedures are only present in the user's program when required. They are loaded
by the DECsystem-10 Linking Loader when so directed by the DECsystem-10 ALGOL Compiler. The
user is not required to take any action to include these procedures, other than make a call to them.
A complete list of library procedures is given below.
The following procedures expect one argument, of real type, and yield a real type result.
SIN Sine
COS Cosine
ARCTAN Arctangent
SQRT Square root
EXP Exponential
LN Logarithm (to base e)
TAN Tangent
ARCSIN Arcsine
ARCCOS Arccosine
SINH Sinh
COSH Cosh
TANH Tanh
Note that if arguments of type integer or long real are given in an ALGOL co" to these
procedures, the compi ler plants the appropriate conversion code.
LSIN Sine
LCOS Cosine
LARCTAN Arctangent
LSQRT Square root
LEXP Exponential
LLN Logarithm (to base e)
The functions ENTlER, ABS and SIGN are also available, as described in Section 5.1 .2
For details of the procedures LINK, LlNKR, TAIL, LENGTH, COPY, NEWSTRING and DELETE, see
Paragraph 13.6.
The integer procedure DIM, which takes as its parameter the name of an array of any type, yields a
result that is the number of dimensions of the array. This is most useful when the user passes an array
as a parameter and wishes to check if it is I for example, a matrix.
The integer procedures LB and UB also take as first parameters the name of an array; their second
parameter is the subscript number. The resul t is the lower or upper bound I respectively I of the sub-
scri pt spec i fi ed by the second parameter. The fo \I ow i ng pro cedure uses these to c Iear rea I matri ces •
BEGIN
INTEGER I .. JJ
IF DI~(A) =2 THEN
REG II'J
FOR I := Ll UNTIL UI DO
END
END
The integer procedures IMIN and IMAX, the real procedures RMIN and RMAX, and the long real pro-
cedures LMIN and LMAX are used, respectively, to determine the minimum or maximum of a number
of arguments of the appropriate type. These procedures normally accept up to ten parameters {this
figure may be changed by re-assembling the ALGOL library with a different parameter.
For example:
.- Jj\'II'!(J,dO;
The procedures GFIELD and SFIELD enable the user to manipulate a field within any integer, real,
long real, Boolean or string variable. The integer parameters I and J specify a byte of length J bits
whose leftmost bit is the 11th bit {counting from zero at the left-hand side}. The byte specified may
be from 1 to 36 bits in length and may be at any position in the variable.
For single word variables {integer, real, Boolean}, I may range from 0 to 35, with the constraint
I+J <= 36. For double word variables {long real and string}, I may range from 0 to 71, with the
constraint I + J <= 72.
The integer procedure GFIELD uses I and J as the second and third parameters; the first parameter is
the variable. The result is the value of the byte {right justified} specified by I, J.
Thus
K := GFIELD(A,3,S);
The procedure SFIELD sets a byte specified by the second and third parameters I, J to the value speci-
fied by the fourth parameter, of type integer. Thus
F-40 FORTRAN subroutines may be incorporated in ALGOL object programs by loading these
subroutines with the ALGOL main program (and any other separate ALGOL procedures).
Such FORTRAN subroutines should be specified by an EXTERNAL declaration in thL ;·.:"'~OL program
and can be called by the appropriate use of one of the ALGOL library procedures:
which are used, respectively, to call nontype, integer, real, long real (double precision), and Boolean
(logical) subroutines.
The first parameter in these procedures calls must be the name of the FORTRAN subroutine. Subsequent
parameters are taken as the arguments to the procedures.
CA LL (FOkT, x, y)
is equival ent to
in a FORTRAN program.
P := 0 + ICALL(Z)
NOTE
The parameters of CALL, ICALL, etc., are restricted to
integer, real, long real, or Boolean expressions with the
restriction that if the expression is a single variable, it
must be a local scalar or a formal parameter called by
value.
DECsystem-10 ALGOL programs are compiled by the ALGOL compiler under the standard DECsystem-10
timesharing monitor. The compiler is called by typing
H ALGPL.
The DECsystem-10 ALGOL Compiler responds by typing an asterisk on the user's terminal. The user
then types a command string to the compiler, specifying the source file{s) from which the program is to
be compi led, and the output fi les for Iisting and output of relocatable binary. The command string
rakes the form:
I
OUTPUT-FILE, LISTING-FILE=SOURCE-FILES
or
or
FILE-NAME. FILE-EXTENSION
or
FILE-NAME
DEVICE:
In cases where no FILE-EXTENSIONS are specified, the standard defaults REL for the relocatable
binary output file, LST for the listing file, and ALG forthe source file are assumed.
SOURCE- FILES
consists of one file or a list of files separated by commas. If a DEVICE is specified for the first file,
and not for succeeding files, the second and following files are taken from the same device as the
fi rst •
Example:
EULER,TTY:"EULER
[read source from DSK:EULER.ALG, write relocatable binary on DSK:EULER.REL, and listing on the
user1s terminal] •
[read source from DSK:SIM26.ALG, DSK:PARAM. TST, write relocatable binary on device MTAO,
and listing on file DSK:SIM26.LST].
Certain switches may be set by the user in the command string. These are:
These switches are set by preceding them with a I after a file, for example:
causes file PROD1.ALG to be compiled with listing, file PROD2.ALG to be compiled without listing,
and causes the size of the heap to be set to 1000 words.
DECsystem-l0 ALGOL allows the user to compile procedures independent of programs that call them.
Such procedures may either follow the main program in the source file (but may not appear before it),
or may be in an independent source file either singly or together. The user uses exactly the same
process to compi Ie such fi les.
If the user requires to call those procedures from the main ALGOL program, the appropriate EXTERNAL
dec larati ons must be made (refer to Paragraph 11.9).
ALGOL programs are loaded by means of the DECsystem-l0 Linking Loader in exactly the same way as
programs generated by MACRO-l0 and FORTRAN (for details, refer to the DECsystem-l0 Assembly
Language Handbook).
The loader automatically causes all procedures required from the ALGOL Library (ALGLIB) to be incor-
porated into the user's program.
For example, consider the source file MAIN.ALG which contains the ALGOL main program and
the files SUB 1.ALG and SUB2.ALG which contain free-standing procedures.
The user may compile these files to give one relocatable binary file by typing the following command
string to the ALGOL compiler,
MAIN,MAIN=MAIN,SUBl,SUB2
and loading the resulting program by giving the command string
-i"A IN$
to the loader. Alternatively, the three source fi Ies can be compiled independently by typing three
command strings to the ALGOL compiler, for example:
~lA IN, MA I N=MA I N
SU81,SUBl=SUt31
SUB2,SUB2:SUB2
NAIN,SUbl,SUB2/G
START
or any of its valid abbreviations. If the program executes successfully, it finishes by printing the exe-
cution time statistics (core store used and execution and elapsed times) on the user's terminal, and
returns to monitor command level.
The concise command language (CCL) features in the DECsystem-l0 monitor may be used to facilitate
the compilation and execution of ALGOL programs. They are used in exactly the same way as for
programs written in DECsystem-l0 FORTRAN. For details, refer to the DECsystem-l0 Users Handbook.
If a run-time error occurs during the execution of an ALGOL object program, an error message is pro-
duced, detailing the type of error, and its address within the user's program. Such errors fall into two
categories - fatal and non-fatal.
A mechanism has been provided by which the user can trap non-fatal errors, and, when they occur,
transfer control to a labe I with in the user's program. Each such error has a un ique number, and a
table of these appears below. The Library procedure TRAP, used to trap non-fatal error has the follow-
ing specification:
Where N is the number of the error to be trapped, and L is a label to which control is required to be
passed when the error occurs.
TRAP (N)
Table 18-1
Error Trap Numbers
CHECKON 1
when placed anywhere in a user's program causes all array subscripts from this point onward in the pro-
gram to be checked at run-time for being in range. The directive
CHECKOFF 1
nullifies this action. Note that use of this facility causes the generated program to be slightly larger,
and to run slower.
18.5. 1.2 Contro" ing Listing of the Source Program - Normally, 9 I isting of the source program is
output with the object program during compilation. The user can suppress this listing entirely by means
of the /5 compiler switch. However, if the user wishes to suppress only part of the I isting and then
continue listing, he can control the I isting from within his program by means of the statements
LISTOFF
LISTON
The LISTOFF statement causes listing to be suppressed from the point in the program where LISTOFF
was encountered to either the end of the program or until a LISTON statement is encountered. The
LISTON statement causes listing to continue after it had been suppressed by a LISTOFF statement.
The LISTON and LISTOFF statements have no effect if the /5 switch is included in the compiler com-
mand string.
18.5.1.3 Setting Line Numbers in Listings - Ordinarily, the lines in the listing file are numbered
sequentially starting at 1 and incrementing by 1. The user can, however, change the line numbers by
placing sequence numbers in columns 73 through 80 of the source program and compi Iing with the /E
switch. Another way in which the user can change the line numbers is by means of the LINE statement.
The statement
LINE n
causes the next I ine number to be set to n, which is a decimal integer. The Iine numbers that follow
are incremented by 1 until either another LINE statement is encountered or the program terminates.
These notes concern the authors' particular interpretation of the "Revised Report on the Algorithmic
Language ALGOL-60" and its implementation.
July 1973
'1-3
ALGOL INDEX (Cont)
TAB, 16-6
TAIL, 13-4
TAN, 17-1
TANH, 17-1
Terminology, 1-3
READER'S COMMENTS
Please indicate the type of user/reader that you most nearly represent.
Organization _________________________________________________________________
Street ________________________________________________________________________
FIRST CLASS
PERMIT NO. 33
MAYNARD, MASS.
Software Communications
P. O. Box F
Maynard, Massachusetts 01754