0% found this document useful (0 votes)
9 views104 pages

DEC-10-LALMA-A-D ALGOL Programmers Reference Ver 3B Jul74

The document is the ALGOL Programmer's Reference Manual for the DECsystem-10 ALGOL System, reflecting Version 3B. It provides comprehensive guidance on using ALGOL, including program structure, identifiers, constants, expressions, statements, and procedures. The manual is intended for both experienced ALGOL users and those familiar with high-level programming languages like FORTRAN IV.

Uploaded by

drforbin666
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views104 pages

DEC-10-LALMA-A-D ALGOL Programmers Reference Ver 3B Jul74

The document is the ALGOL Programmer's Reference Manual for the DECsystem-10 ALGOL System, reflecting Version 3B. It provides comprehensive guidance on using ALGOL, including program structure, identifiers, constants, expressions, statements, and procedures. The manual is intended for both experienced ALGOL users and those familiar with high-level programming languages like FORTRAN IV.

Uploaded by

drforbin666
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 104

ALGOL

~D~DD~D
DEC-10-LALMA-A-D

ALGOL
PROGRAMMER'S REFERENCE MANUAL

This manual reflects Version 3B of the ALGOL System.

DIGITAL EQUIPMENT CORPORATION • MAYNARD, MASSACHUSETTS


1st Edition, September 1971
2nd Edition, December 1971
Update Pages, May 1972
Update Pages, December 1972
Update Pages, July 1973
Update Pages, July 1974

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.

Copyright © 1971, 1972, 1973, 1974 by Digital Equipment Corporation

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.

The following are standard trademarks of Digital Equipment Corporation:

CDP DIGITAL INDAC PS/8


COMPUTER LAB DNC KA10 QUICKPOINT
COMSYST EDGRIN LAB-8 RAD-8
COMTEX EDUSYSTEM LAB-8/e RSTS
DDT FLIP CHIP LAB-K RSX
DEC FOCAL OMNIBUS RTM
DECCOMM GLC-8 OS/8 RT-II
DECTAPE IDAC PDP SABR
DIBOL IDACS PHA TYPESET 8
UNIBUS
CONTENTS
Page

CHAPTER 1 INTRODUCTION

1.1 General 1-1


1.2 DECsystem-1 0 ALGOL 1-1
1.3 The ALGOL Compiler 1-2
1.3.1 Compiler Extensions 1-2
1 .3.2 Compil er Restrictions 1-3
1.4 The ALGOL Operating Environment 1-3
1.5 Terminology 1-3

CHAPTER 2 PROGRAM STRUCTURE

2.1 Basic Symbols 2-1


2.2 Compound Symbol s 2-2
2.3 Delimiter Words 2-2
2.4 Use of Spacing and Commentary 2-4

CHAPTER 3 IDENTIFIERS AND DECLARATIONS

3.1 Identifi ers 3-1


3.2 Scalar Declarations 3-2

CHAPTER 4 CONSTANTS

4.1 Numeric Constants 4-1


4.1.1 Integer Constants 4-1
4.1 .2 Real Constants 4-1
4.1 .3 Long Real Constants 4-2
4.2 Octal and Boolean Constants 4-2
4.3 ASCII Constants 4-3
4.4 String Constants 4-3

CHAPTER 5 EXPRESSIONS

5.1 Arithmetic Expressions 5-1


5.1.1 Identifi ers and Constants 5-2
5.1 .2 Special Functions 5-2

iii
CONTENTS (Cont)
Page

5.2 Bool ean Expressions 5-4


5.2.1 Bool ean Opera tors 5-4
5.2.2 Arithmetic Condi tions 5-5
5.3 Integer and Boolean Conversions 5-5

CHAPTER 6 STATEMENTS AND ASSIGNMENTS

6.1 Statements 6-1


6.2 Assignments 6-1
6.3 Mul tipl e Assignments 6-2
6.4 Eval uati on of Expressions 6-2
6.5 Compound Statements 6-3

CHAPTER 7 CONTROL TRANSFERS, LABELS, AND


CONDITIONAL STATEMENTS

7.1 Label s 7-1


7.2 Uncondi tiona I Control Transfers 7-1
7.3 Conditional Statements 7-2

CHAPTER 8 FOR AND WH ILE STATEMENTS

8.1 FOR· Statements 8-1


8.1.1 STEP-UNTIL EI ement 8-2
8.1 .2 WHILE Element 8-2
8.2 WHILE Statement 8-3
8.3 General Notes 8-3

CHAPTER 9 ARRAYS

9.1 General 9-1


9.2 Array Declarations 9-1
9.3 Array EI ements 9-2

CHAPTER 10 BLOCK STRUCTURE

10. 1 General 10-1 /'

10.2 Arrays with Dynamic Bounds 10-3

iv
CO N TENTS (Cont)
Page

CHAPTER 11 PROCEDURES

11. 1 Parameters Call ed By II Val ue ll 11-1


ll
11.2 Parameters Called By IIName 11-1
11.3 Procedure Headings 11-3
11.4 Procedure Bodies 11-3
11.5 Procedure Calls 11-5
11.6 Advanced Use of Procedures 11-6
11 .6. 1 Jensen's Devi ce 11-6
11.6.2 Recursion 11-7
11.7 Layout of Declarations Within Blocks 11-8
11.8 Forward References 11-9
11.9 External Procedures 11-10
11.10 Additional Methods of Commentary 11-11
11.10.1 Comment After END 11-11
11.10.2 Comments Within Procedure Headings 11-11

CHAPTER 12 SWITCHES

12. 1 General 12-1


12.2 Switch Decl arations 12-1
12.3 Use of Swi tches 12-1

CHAPTER 13 STRINGS

13. 1 General 13-1


13.2 String Expressions and Assignments 13-1
13.3 Byte Strings 13-1
13.4 Byte Subscripting 13-2
13.5 String Comparisons 13-3
13.6 Library Procedures 13-3
13.6. 1 Concatenation 13-3
13.6.2 Byte String Copyi ng 13-5
13.6.3 New Byte Strings 13-6

v
CO NTENTS (Cont)
Page

CHAPTER 14 CONDITIONAL EXPRESSIONS AND STATEMENTS

14. 1 General 14-1


14.2 Condi tiona I Operands 14-1
14.3 Conditional Statements 14-2
14.4 Designational Expressions 14-3

CHAPTER 15 OWN VARIABLES

15. 1 General 15-1


15.2 Own Arrays 15-1

CHAPTER 16 DATA TRANSMISSION

16. 1 General 16-1


16.2 Allocation of Peripheral Devices 16-1
16.2.1 Device f.Aodes 16-2
16.2.2 Buffering 16-3
16.3 Selecting Input/Output Channels 16-3
16.4 File Devices 16-4
16.5 Releasing Devices 16-4
16.6 Basic Input/Output Procedures 16-5
16.6. 1 Byte Processing Procedures 16-5
16.6.2 String Output 16-5
16.6.3 Miscell aneous Symbol Procedures 16-6

I 16.6.4 Numeri c and String Procedures 16-7


16.6.4.1 Numeric Input Data 16-7
16.6.4.2 Numeri c Output Data 16-8
16.6.4.3 Octal Input/Output 16-9
16.7 Defaul t Input/Output 16-9
16.8 Logi cal Input/Output 16-9
16.9 Special Operations 16-10

I 16.10 I/O Channel Status 16-10


16.11 Transferring Files 16-11

vi
CO NT ENTS (Cont)
Page

CHAPTER 17 THE DECsystem-10 OPERATING ENVIRONMENT

17. 1 Mathematical Procedures 17-1


17.2 String Procedure 17-2
17.3 Uti I ity Procedures 17-2
17.3. 1 Array Dimension Procedures 17-2
17.3.2 Minima and Maxima Procedures 17-3
17.3.3 Field Manipulations 17-3
17.4 Data Transmission Procedures 17-3
17.5 FORTRAN Interface Procedures 17-4

e
CHAPTER 18 RUNNING AND DEBUGGING PROGRAMS

18. 1 Compi I ation of ALGOL Programs 18-1


18.1.1 Compilation of Free-Standing Procedures 18-3
18.2 Loading ALGOL Programs 18-3
18.3 Running ALGOL Programs 18-4
18.4 Concise Command Language 18-4
18.5 Run- Time Diagnosti cs and Debugging 18-4
18.5. 1 Facilities to Aid in Program Debugging 18-5
18.5.1.1 Checking 18-5
18.5.1.2 Controlling Listing of the Source Program 18-6
18.5.1.3 Setting Line Numbers in Listings 18-6

CHAPTER 19 TECHNICAL NOTES

TABLES

2-1 DECsystem-l0 ALGOL Symbols 2-1


2-2 Compound Symbols 2-2
2-3 Delimiter Words Used in DECsystem-l0 ALGOL 2-3
5-1 Operator Precedence 5-1
5-2 Function of Boolean Operators 5-4
5-3 Boolean Expressions 5-6
11-1 Parameters in a Procedure Call 11-2
16-1 Standard Device Names 16-2
18-1 Error Trap Numbers 18-4

vii
CHAPTER 1
INTRODUCTION

1.1 GENERAL

DECsystem-10 ALGOL is an implementation of ALGOL-60; ALGOL is an abbreviation of ALGOrithmic


Language, and 1960 is the year it was defined. The authoritative definition of ALGOL-60 is contain-
ed in the :IRevised Report on the Algorithmic Language ALGOL-60 1l , 1 hereafter referred to as the
II Revised Reportll. This report leaves a number of ALGOL-60 features undefined, notably input/output,
and permits the implementer of the language some latitude in interpreting other features. Many of
these features have been discussed extensively since the publi cation of the Revised Report; some have
been given rigorous interpretations in various versions of ALGOL, parti cu larly the ALGOL-68
2
Language.

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.

1.2 DECsystem-10 ALGOL

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.

3 A Primer of ALGOL-60 Programming, E. W. Dijkstra, Academic Press, London, 1962.

1-1 December 1972


Readers not thoroughly familiar with ALGOL should read the entire manual. Readers already familiar
with ALGOL-60 should read all chapters except Chapters 5, 6, 7, 8, 9, 10, 11, 12, and 14, which
need be referred to only bri efly.

1.3 THE ALGOL COMPILER

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.

1 .3. 1 Compi I er Extensions

The fo IIowing ALGOL-60 extensions are allowed by the compi I er:

a. A LONG REAL type, equivalent to FORTRAN's double precision, is added that


gives the user power to handle double-precision real numbers.
b. An EXTERNAL procedure facility allows the user to compile procedures separately
from the main program.
c. A WHILE statement, and an abbreviated form of the FOR statement, allow the
user greater flexibility of iteration.
d. A new type STRING allows the user to mc:mipulate strings of various size bytes.
In addition, the user can individually manipulate the bytes within a string by
means of a byte subscripting facility.
e. An integer remainder function REM, is provided.
f. Assignments are permitted within expressions.
g. Delimiter words may be represented in either reserved word format (upper case) or
as non-reserved words enclosed in singl e quotes (primes).
h. Constants of type REAL may be expressed as an integer
part and a decimal part only as in FORTRAN.

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.

1-2 July 1974


1 .3.2 Compi ler Restri ctions

If the user is unfamiliar with any of the following terminology, he should refer to the Revised Report
and to Paragraph 1.5.

The compiler imposes the following restrictions on ALGOL-60:

a. Numeric labels are not permitted.


b. All formal parameters must be speci fi ed.
c. Identi fi ers are restri cted to 64 characters in length.
d. Arrays and scalars must be declared before switches and procedures.
e. Forward references for procedures and labels must be given under certain circum-
stances.

1.4 THE ALGOL OPERATING ENVIRONMENT

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.

The ALGOL operating environment consists of:

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.

Refer to Chapters 17 and 18 for a description of ALGLIB and ALGOTS.

1.5 TERMI NOLOGY

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}

1-3 July 1974


Procedure (Subroutine, Function) - part of a program, which may be invoked by "calling".
In general, parameters are supplied as arguments and a result may be returned.

J Parameter (Formal Parameter - Dummy Variable, Actual Parameter - Argument) See


Procedure. - A Formal Parameter is an identifier used within the procedure that repre-
sents the argument supplied when the procedure is called.

1-4 December 1971


CHAPTER 2
PROGRAM STRUCTURE

2.1 BASIC SYMBOLS

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

Symbol Meaning or Use

A-Z Used to construct identifi ers and del imiter words.


a-z Lower case letters; are treated as upper case letters except when they
appear in string constants and ASCII constants.
0-9 Decimal digits; used to construct numeric constants and identifiers.
+ Arithmetic addition operator.

- Ari thmeti c subtraction operator.

* Arithmetic multiplication operator.

/ Arithmetic division operator.


t Arithmetic exponentiation operator.

I ( ) Parentheses; used in arithmetic expressions and to enclose parameters


in procedure specifi cations and calls.
[ ] Square brackets; used to enclose subscript bounds in array declarations,
and array subscript lists.
, Comma; general separator, placed between array subscripts, procedure
parameters, i terns in switch lists, etc.
Decimal point; used in numeric constants and byte subscripting. Also,
used as a readability symbol in identifiers.
Semi colon; used to termi nate statements.

(conti nued on next page)

2-1 December 1971


Tabl e 2-1 (Cont)
DECsystem-10 ALGOL Symbols

Symbol Meaning or Use

: Colon; used to indicate labels, and separate lower and upper bounds in
array declarations.
= Equality; used in arithmeti c and string comparisons.
# Nonequality •

< > Less than, greater than.


& @ Introduces exponent in floating-poi nt numbers.
I
Prime, or single quote; used to enclose delimiter words when the non-
reserved word implementation is used.
II
Opening and closing string quotes.
! Comment.
% Introduc~ an octal constant.
$ Introduces an ASCII constant.
.... Alternative to := (refer to Table 2-2) •

2.2 COMPOUND SYMBOLS

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

2.3 DELIMITER WORDS

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

Version 2 ALGOL 2-2 December 1971


throughout this manual that the standard method of delimiter word representation is used, that is,
reserved words.

For example, the delimiter word

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

Reserved Word Chapter Reference

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

(continued on next page)

Version 2A ALGOL 2-3 May 1972


Table 2-3 (Cont)
Delimiter Words Used in DECsystem-10 ALGOL

Reserved Word Chapter Reference

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

2.4 USE OF SPACING AND COMMENTARY

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.

2-4 July 1974


CHAPTER 3
IDENTIFIERS AND DECLARATIONS

3.1 ID ENTIFI ERS

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:

The following are identifi ers:

ALPHA

P43

JiJK5

HOllSEHCLDEhTRIDIAGCi\ALII.ATION

The following are not identifiers:


4P does not begin with letter
8COLFAN unless the non-reserved word delimiter repre-
sentation is used
ONCE AGA I N space not allowed

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

have exactly the same effect as

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.

3.2 SCALAR DECLARATIONS

A declaration reserves an identifier to represent a particular quantity used in a program. Such


declarations are mandatory in ALGOL. At any particular point during program execution, the form of
the variable or quantity associated with the identifier depends on the type of variable. The type of
variable is co·ntro"ed by the type of identifier which represents it.

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;

LONG REAL DOU8LE,P,Q,ELEPHANT;

BOCLEAN I5ITREALLYTRUE;

STRING 5,1;

3-3 December 1971


CHAPTER 4
CONSTANTS

4.1 NUMERIC CONSTANTS

There are three forms of numeri c constants:

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

4.1.2 Real Constants

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:

Represen tati on Value

3.141592653589793 3. 14159265
.0001 0.0001
4.37&5 437000.0
5&-3 0.005
&-6 0.000001

4.1.3 Long Real Constants

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

4.2 OCTAL AND BOOLEAN CONSTANTS

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

Octal constants may only be used in Boolean expressions.

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:

Text Octal Value

$A 000000 000101
$/01234/ 160713 516674

4.4 STRING CONSTANTS

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.

a. [ ] i and II may not appear alone.


b. [and] may appear if theyare properly paired.
c. Single occurrences of [ ] i and II are represented by [[ ]] ii and 1111, respectively.
d. Where a string has to be broken across two or more lines of source, the carriage return
and line feed characters can be ignored by preceeding them with a control-back arrow
character.

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"

"REfYiEtv'RFR THAT SPACES ETC. ARE S lCiNIF ICANT"

"(P5C]INPUT DATA:(SC]"

''''''AEE!]] := (i).};;"""

4-3 July 1974


CHAPTER 5
EXPRESSIONS

5.1 ARITHMETIC EXPRESSIONS

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

I 0 IV J REt-' K means (I D IV J) t~Et"'j K

Unlike FORTRAN, when ordinary division of one integer by another is performed, the real result is
not rounded to an integer value.'

5-1 July 1974


The difference between the various types of division is clarified by the following examples:

7/4 yields a result of 1.75, whereas


7 DIV 4 yields a result of 1, and
7 REM 4 yields a result of 3

The interpretation of integer division for negative integers follows:

Let M, N > 0, then

I -~ DIV N =~ DIV (-N) = -(M DIV N)


-~ DIV (-N) =. IV DIV N

The integer remainder operator, REM, is defined so that for all integral M, N:

M kFM N = M - N*(!V: DIV N)'

5. 1 • 1 Identifi ers and Constants

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.

5.1.2 Special Functions

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

5-2 December 1971


The special function ABS yields the absolute value (also known as the modulus) of its argument. The
argument may be any integer, real, or long real quantity; the result is always of the same type as the
argument.

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.

Examples of simple arithmetic expressions follow:

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.

5.2.1 Boolean Operators

There are five Boolean operators arranged in decreasing order of precedence.

a. NOT (unary operator)


b. AND
c. OR
d. IMP (implication)
e. EQV (equival ence)

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

In addition, the following theorems hold true:

A IMP B is equival ent to NOT A OR B,


A EQV B is equivalent. to A AND B OR NOT A AND NOT B.

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.

5.2.2 Arithmetic Conditions

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:

< less than


<= less than or equal to
equals
> greater than
>= greater than or equal to
# not equal to

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.

5.3 INTEGER AND BOOLEAN CONVERSIONS

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)

may be regarded as a Boolean operand I and

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.

5-6 July 1974


CHAPTER 6
STATEMENTS AND ASSIGNMENTS

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

results in an integral value equal to

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.

6.3 MULTIPLE ASSIGNMENTS

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

where the result of adding Y to X and subtracting Z is assigned to P, R, and S simultaneously.

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)

sets I equal to 3 and X equal to 3.0.

6.4 EVALUATION OF EXPRESSIONS

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

may have a different effect than

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

being evaluated correctly, thus giving the same result as

P : = P +0

x .- P/(P+R);

6.5 COMPOUND STATEMENTS

A compound statement consists of a number of statements, preceded by BEGIN, separated by semi-


colons, and terminated by END. ALGOL statements, unlike those in FORTRAN, are terminated by
a semicolon not by the end of a line of text.

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.

The usefulness of compound statements will become apparent in later chapters.

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

is a statement labeled by CaMP.

More than one label can be attached to a statement if required; thus,

LAR1: LA82: Y := Gil

7.2 UNCONDITIONAL CONTROL TRANSFERS

A transfer of control, or "jump", to a statement in a program is effected by a 'GOTO statement. This


statement consists of the word GOTO followed by the name of the label attached to the relevant state-
, mente The two words GO TO can be used instead of the word GOTO in any statement where GOTO
I can be used. Thus:
BEGIN INTEGER I ",J",).<;

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.

Version 2A ALGOL 7-1 May 1972


7.3 CONDITIONAL STATEMENTS

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

where B is some Boolean expression, and S is a statement. For example:

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.

A more general form of a conditional statement is

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;

IF I < 1~0 THEN G0TO LA8

FND
is a simple way of counting to one hundred. More sophisticated methods are shown in Chapter 14.

7-2 December 1972


CHAPTER 8
FOR AND WHILE STATEMENTS

8.1 FOR STATEMENTS

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.

The general format is

Fe' H V : = F Ch: LIS T DOS

where V is a variable and S is a statement (compound or otherwise).

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:

FOk I • - 3,5, 10 DC •••••

FGR J .- 1,2,5 STEP 5 UNTIL 20 DO •••••

Version 2 ALGOL 8-1 December 1971


8.1 .1 STEP-UNTIL Element

This particular form deserves closer inspection, because it is not quite as simple as it appears. For
example, consider

FOF: I := I STEP I {f!\lTIL N DC S

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?"

The answer is slightly more complicated. Consider the general case

FOR V := El STEP E2 U~TIL E3 DO S

This is defined to have exactly the same effect as


V := E];

L]: IF (V - E3)*SIGN(E2) > 0 THEN GOTO L2;

$;

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

8.1.2 WHILE Element

A FOR statement with a single WHILE element takes the form

FOR V := E WHILE 8 DO S

8-2 December 1972


This is interpreted as follows:
1.I: V := F;

IF NOT 8 THEN GOTO L2;

SJ

GOTOLIJ

L2 :

Once again, the complexity of the loop may be affected by changing Vand E within the loop.

8.2 WHILE STATEMENT

The WHILE statement is an enhancement of ALGOL-60 provided in DECsystem-10 ALGOL. It takes


rhe general form

l.rJH ILF.: R DO S

and is interpreted as follows:


Ll: IF NOT B THEN GOTO L2;

GOTO Ll;

L2:

8.3 GENERAL NOTES

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.

8-3 July 1974


/
CHAPTER 9
ARRAYS

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.

9 .2 ARRAY DECLARA nONS

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:

INTEGER AF-RAY A.lB [1 : 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:

HE A L A 1< RAY A [ 1 : 1 0 ].1 8.1 C ( 1 : 1 0 .I 1 : 12 ]

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:

ARRAY AU :HJJ, B,C[l :1V).,} :12J

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.

9.3 ARRAY ELEMENTS

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.

As an example of the use of arrays, consider the declaration

hEAL ARRAY D,E,F [1 :}(l1,1 :}(i))

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;

FOR K := 1 UNTIL 10 DO X .- X + D[I,KJ*E(K,JJ;

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.

9-2 December 1971


CHAPTER 10
BLOCK STRUCTURE

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

is an ALGOL program, assuming appropriate declarations and statements in the blocks.

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:

BE'G 1(\1 I NTEGEk I;

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:

PE GIN I I'!T E G EJ< I, J;

(1)

BEGIN INTFGEh J,K

[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.

10.2 ARRAYS WITH DYNAMIC BOUNDS

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;

L.: (\1 := •••••

REGIN Akt...:AY AU :N,l :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.

10-4 December 1971


CHAPTER 11
PROCEDURES

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.

11 . 1 PARAMETERS CALLED BY "VALUE"

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.

11.2 PARAMETERS CALLED BY II NAME"

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

Version 2A ALGOL 11-1 May 1972


appears in the body of the procedure, the actual parameter is re-evaluated as if it appeared in the
procedure body at that point. For example, if the actual parameter were an array element such as

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

Formal Parameter Type Permissible Actual Parameter

~:t:lger } Any arithmeti c expression


Long Real
Boolean Any Bool ean expression
String Any string expression (refer to Chapter 13)
Label A label or switch element (refer to Chapter 12 and
Paragraph 14.4)
Switch A switch
Integer Array An array of type integer*
Real Array (or Array) An array of type real *
Long Real Array An array of type long real *
Boolean Array An array of type Boo lean
String Array An array of type stri ng
Procedure A non-type procedure
Integer Procedure }
Real Procedure A procedure of type integer, real, or long real
Long Real Procedure
Boolean Procedure A procedure of type Boolean
Sti-i ng Procedure A proce~ure of type string

*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.

A procedure heading consists of:

a. The type of procedure (omitted in the case of typel ess procedures).


b. The word PROCEDURE followed by the name of the procedure.
c. A semicolon if the procedure has no parameters; otherwise
d. A list of the formal parameters, enclosed in parentheses, and followed by a semi-
colon.
e. Specifi cations of the formal parameters. Omitting formal parameter specifi cations,
this looks like

LONG REAL PROCEDURE LR;

BOOLEAf\i PI-:(lCEDUhE BCICtLCOf\! (I, ,J, k);

pr< (1 CEO Uk E CAL C ( T Hr: T A , X ) ;

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:

REAL PROCFDllRE THETA; ARRAY X;

• 11.4 PROCEDURE BODIES

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.

REAL PROCEDURE SOUAREROOT(X"L);

VALUE x; I<EAL x; LABEL L;

BEGIN REAL Y"Z;

IF X < 0 THEN GOTe L;

Y : = (1 + X) 12 ;

IT: Z .- (X/Y + Y)/2;

IF ABS(Z - Y) < 1&-6 THEN GOTO OK;

Y := Z; GOTO IT;

OK: S (-lIlAk Ek DOT : = Z

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 PROCEDURE SQUAkEROOT(X"L);

VALUE X; REAL X; LABEL L;

REGIN CALCULATES THE VALUE OF SQRT(X)

USING THE NEWTON-RAPHESON ~ETHOD.

L IS USED FOR AN ESCAPE IF X < C);

REAL Y"Z;

IF X < 0 THEN GOTO L; EXIT IF X < 0;

Y .- (l+X)/2; FIRST APPROXI~ATION;

IT:

Z := (X/Y + Y)/2; ITERATE;

IF ABS(Z-Y) < 1&-6

THEN GOTO OK,; TEST FOR CONVERGENCE;

Y : = Z; GOTO IT,; OTHERWISE CONTINUE;


(continued on next page)

11-4
OK:

SQIJAR FR OOT •- L.,; FINAL l'::':ESIIl.T,;

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.

I~EAL PROCEDURE SUtV-(G"I'DJ

VALUE N,; I~EAL PROCEDURE G,; INTEGEr.; i\!,;

BEGIN INTEGER I,; REAL x,;


X : = 0,;

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.

11.5 PROCEDURE CALLS

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.

The procedure squareroot can be called in a similar way, for example:

P := SOIlARFROOTCZ + (1).5)

causes the square root of Z + 0.5 to be calculated.

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),;

VALUE N,; ARRAY A"B.,C ,; INTEGER N,;

BEGIN INTEGER I"J.,K,; REAL x,;

COM~ENT THIS PROCEDURE PERFORMS THE MATRIX

MULTIPLICATION OF BAND C AND PUTS THE RESULT

IN A. THE ARRAYS ARE ASSUMED TO BE SQUARE

AND OF BOUNDS 1 :N.,l :N,;

FOR .- UNTIL N DO

FOR J .- UNTIL N DO

BEGIN X ..-- 0,;

FOR K .- 1 UNTIL N DO X .-- x +

B [ I , K] *C [ K., J ] ,;

A[I.,J] .- X

END

END

A typi cal call for this procedure might be

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.

11.6 ADVANCED USE OF PROCEDURES

11.6.1 Jensen's Device

This method of using a procedure exploits the power and flexibility of the call-by-name concept.
Consider the following example:

11-6 December 1971


REAL. P/-~OCEDURE SlJM( I,N,)O.; VAL.LJf~ ~; INTEGEk I,N.; I:.:EAL I'd

BEGIN REAL Y.;

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

AU] + A[2J + ••••• + A[10].

Similarly, the call

calculates the (I,J)th inner product of A and B.

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:

INTEGER PROCEDURE FACTORIAL(N)'; VALUE N.; INTEGEk NJ

IF N = 1 THEN FACTORIAL := 1

ELSE FACTORIAL := N*FACTORIAL(N-})J

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.

11.7 LAYOUT OF DECLARATIONS WITHIN BLOCKS

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

PROCEDURE P(X); VALUE Xl REAL X;

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

PROCEDURE P(X); VALUE X; REAL X;

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.

Version 2A ALGOL 11-8 May 1972


11.8 FORWARD REFERENCES

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

I FOF~vJARD I~EAL PI,OCEDUI<E Q;

PROCEDURE peX); VALUE x; REAL x;

BEGIN kEPL Y;

Y := oeX);

END;

REAL PROCEDURE QeZ); VALUE Z; REAL Z;

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:

I FORWARD LONG REAL PROCEDURE INTEGRATE

or

FORWARD PROCEDURE PROBLEM

Version 2A ALGOL 11-9 May 1972


Note that the forward reference must occur in the same block as the procedure body to which it refers.

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;

In this case, a forward reference for L must be given.

11.9 EXTERNAL PROCEDURES

If it is required to compile a procedure independently of a program (see Paragraph 18. 1.1), an


EXTERNAL declaration must be made in the program instead of the procedure. The form of this
is the same as that of a FORWARD declaration, but with the word FORWARD replaced by EXTERNAL.
For example:

EXTERNAL INTEGER PkOCEDUkE CALC

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.

11-10 December 1972


11. 10 ADDITIONAL METHODS OF COMMENTARY

Two further ways of writing commentary are available to the user in addition to COMMENT and
described in Section 2.4.

11. 10. 1 Comment After END

Following the delimiter word END I the user may add commentary, terminated by a semicolon, with the
following restrictions:

1. The commentary may only contain letters and digits.


2. If the reserved delimiter word mode of compilation is employed, any words
appearing in the comment may not be delimiter words.

For example:

FND OF Pk0C INVEkT;

11.10.2 Comments Within Procedure Headings

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.

The example in Section 11.6.1 can thus be rewritten:

kFAL. PKCCFDllhE Sll(,-(I) CCI.li\!T:(N) It\ChEfv:Ei\'T:(X);

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:

Z: =S II tv' ( k) C ell I"\T E l~ : (t-~) C k 0"5 S P k 0 DUe T: ( A [ I , k ) :Hi [ K, J ) ) ;

I 11-11 December 1972


CHAPTER 12
SWITCHES

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.

12.2 SWITCH DECLARA nONS

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.

12.3 USE OF SWITCHES

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.

Wore sophisticated switch elements are described in Chapter 14.

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;

STH I NG ARRA Y SA [ 1 : 1 (IJ ] ;

STRlt\!G PROCEDlJF<E R(X); VALUE X; REAL X;

13.2 STRING EXPRESSIONS AND ASSIGNMENTS

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";

13.3 BYTE STRINGS

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.

Version 2 ALGOL 13-1 December 1971


String constants are a particular example of byte strings. They have a byte size of seven and consist
of the ASCII characters of the string constant packed end-to-end.

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.

When one string is assigned to another, for example:

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.

When a string constant is assigned to a string variable, for example,

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.

13.4 BYTE SUBSCRIPTING

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.

13.5 STRING COMPARISONS


Two byte strings can be compared with each other using the usual comparison operators. Thus the user
can write
IF S < T THEN GOTO L

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.

13.6 LIBRARY PROCEDURES

Refer to Chapter 17 for a detailed description of the DECsystem-10 ALGOL Library.

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);

13-3 July 1974


forges a link from 5 to T. If the assignments

S := "ABeD"; T := "EFGH";

are also made, then S. [5] is now the same as T. [1].

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);

sets V to be the same as T, and

~'J : = T A I L CS , 2 )

sets W to be the same as U.

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);

sets I equal to the number of bytes in the byte string possessed by S.

13.6.2 Byte String Copying

A new byte string can be generated from an existing byte string by means of the string procedure COPY.

COpy may have one, two, or three parameters.

a. If there is only one parameter, for example,

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.

13.6.3 New Byte Strings

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);

causes the byte string in the previous exampl e to be deleted.

Version 2 ALGOL 13-6 December 1971


CHAPTER 14
CONDITIONAL EXPRESSIONS AND STATEMENTS

14.1 GENERAL

ALGOL-60 allows great flexibility in the construction of expressions and conditions.

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:

IF 8 THEN Xl := Y; IF !'<OT k THEN ,,2 := y;

14.2 CONDITIONAL OPERANDS

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.

For instance, the first example above can be rewritten

I := IF B THEN 0 ELSE 1;

Clearly, this is more compact and of great use in cases such as:

J := J + (IF K < 1 THEN I-K ELSE K-l);

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:

SWITCH SW := Ll~ IF 8 THEN L2 ELSE L3~ L4;

14-1 December 1971


It is also permitted, of course, in an array subscript (and also in a byte subscript), for example:

X := A[I .. IF L = Ci) THEN J ELSE J+l];

Since a conditional operand may replace any operand in an expression, it may also replace operands
in conditional expressions. Consider the following example:

IF IF F.3 THEr\l HI ELSE 82 THEN I := I + 1;

This looks complicated but is really quite simple if brackets are inserted for clarity. Thus:

IF <IF B THEN 81 EL.SE 82) THEN 1:= 1+ 1;

14.3 CONDITIONAL STATEMENTS

The reader was introduced to conditional statements of the form

IF B THEN SI ELSE S2

in Chapter 7. The full power of this type of statement can now be demonstrated.

First, 51 and 52 can be compound statements or blocks. For example:

IF I < 0 TH£N

BEGIN .- -I; R .- FALSE

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:

IF X < 0 THEN X := 0 ELSE IF B THEN GOTO L;

This is equivalent to the simple sequence of statements:

IF NOT X < 0 THEN GOTO Ll;

X := 0; GOTO l,2;

Ll: IF NOT 8 THEN GOTO L2;

GOTO L;

L2 :

Clearly the former method of expression is both briefer and more elegant.

Version 2A ALGOL 14-2 May 1972


Condi tional statements take the general form

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:

IF R THEN IF X = 0 THFN Y := Z ELSE P .- 0;

This could be interpreted as

IF B THEN BEGIN IF X =0 THEN Y .- Z END ELSE P .- ~;

or

IF B THEN BEGIN IF X =0 THEN Y .- Z ELSE P .- Q END;

The first case is interpreted as:

IF NOT 8 THEN GOTO Ll;

IF NOT X =0 THEN GOTO L2;

Y : = Z; GOT 0 L2;

Ll: P : = 0 J

1..2 :

The second case is interpreted as:

IF NOT B THEN GOTD L2;

IF NOT X =0 THEN GOTO Ll;

Y .- Z; GOTD L2;

U: P .-0;

L2:

ALGOL-60 forbids such ambiguities by forbidding the sequence THEN IF ••••• THEN ••••• ELSE.

14.4 DESIG NATIONAL EXPRESSIONS

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

I IF X < 0 THEN S\H I] ELSE IF X+Y >= Z THEN Tl.H J] ELSE L

Version 2A ALGOL 14-3 May 1972


These designational expressions would be used in the following manner:

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

Version 2A ALGOL 14-4 May 1972


CHAPTER 15
OWN VARIABLES

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 INTEGER I~J~K;

OWN REAL ARRAY THETA[l :MJ

15.2 OWN ARRAYS

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.

15-1 December 1971


For example, if an own array A is declared as follows:

m}N REAL ARRAY AL[1:r>1"t'i:N);

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.

16.2 ALLOCATION OF PERIPHERAL DEVICES

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.

16-1 December 1971


Table 16-1
Standard Devi ce Names

Device Name Peripheral

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);

Similarly, if the disk were to be used as an output device on channel 9:

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" ),;

allocates the user's terminal for input and output on channel O.

16.2.1 Device IVodes

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

OUTPUT (9 ""DSK",, 11 ),;


16-2
The DECsystem-10 Assembly Language Handbook should be consulted for a full explanation of the
different modes used with peripheral devices. The INPUT and OUTPUT procedures allow the user to
allocate any standard peripheral device in any buffered mode.

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.

16.3 SELECTING INPUT/OUTPUT CHANNELS

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

SELECT INPUT (5);

causes input channel 5 to be sel ected.

Similarly, the procedure SELECTOUTPUT is used to select an output channel.

16-3 December 1971


16.4 FILE DEVICES

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

OP E NF I L E (9 ~ " T EST. 0 AT" ~ %1 7 7 ~ %vHi) (Hi) 1 1 ~) 0 (-) (/) 50 ) ;

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);

closes the fi I e that is open on channel 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

OP E NFl L E (5 ~ T EST 1 • 0 AT" ) ;


II

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 ~ .". ) ;

causes the file TEST3.DAT to be deleted.

16.5 RELEASING DEVICES

The procedure RELEASE is used to release a device from a channel. Thus,

RELEASE(S);

Version 26 ALGOL 16-4 December 1972


releases the device allocated to channel 5. If the device is a file device, and a file is still open on
the devi ce, it is automati cally closed. Rei easing a device on a channel causes a channel to become
freei if this channel is currently selected for input or output operations, it is deselected.

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.

16.6 BASIC INPUT/OUTPUT PROCEDURES

16.6.1 Byte Processing Procedures

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).

16.6.2 String Output

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:

':JR ITE ("ABCD (P2C 55 JEFGH"),;

causes the fo Ilowi ng to be output:

a. the symbols ABCD followed by a page throw


b. two new lines and five spaces
c. the symbols EFGH.

In order to output the symbols

[ ] II or ;

they must appear in the form

[[ ]] 1111 or ;;

respectively. Thus

l-JR IT E ( •tt .... A [ ( I )) •- 3,;,;·n tt. ) ;

causes the text

"A [ I J •- 3,;"

to be output.

16.6.3 Miscellaneous Symbol Procedures

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

Version 2A ALGOL 16-6 May 1972


SPAC F ( 5 ) ;

causes five spaces to be output, whereas

SPAC E;

or

SPACE(l);

causes one space to be output.

116.6.4 Numeric and String Procedures

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:

3.4 -9.6 1.36 -52


o 14.9

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.

Version 2 ALGOL 16-7 December 1971


The effect is as follows:

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:

M > 0, N > 0: Fixed-point printing, M places before the decimal


point, N places after. A sign, space if positive,
- if negative appears before the number. Zeros
before the decimal point are replaced by spaces and
the sign moved up to the number.
This format always outputs M+N+2 symbols.
M > 0, N = 0: The same as the preceding except that (a) no frac-
tional part appears, and (b) the decimal point is
suppressed.
This format always outputs M+1 symbols.
M = 0, N >0: Floating-point format, consisting of a sign, a decimal
digit, a decimal point, N more decimal digits, and an
exponent consisti ng of & for real, && for long real
followed by the exponent sign and a two-digit exponent,
zero suppressed from the I eft.
This format outputs N+7 symbols for real and N+8 sym-
bols for long real quantities.

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.

Version 2B ALGOL 16-8 December 1972


If the user requests more digits to be printed than are significant in real or long real numbers, the
appropriate number of zeros follow a properly rounded printing of the number to the maximum precision
available.

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.

16.7 DEFAULT INPUT/OUTPUT

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.

16.8 LOGICAL INPUT/OUTPUT

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.

Version 2 ALGOL 16-9 December 1971


The user is still free, of course, to manipulate the individual bytes within the byte string by means of
the byte-subscripting facilities available. Such facilities enable the user to read a file from a
periphera I device into a string, process it in any way whatsoever, and output it again.

16.9 SPECIAL OPERATIONS

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.

16.10 I/O CHANNEL STATUS

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:

Bit Value Meaning if Set


18 %400000 Device is physical (i .e., not logical)
19 %200000 Directory device
20 %100000 Terminal device
21 %040000 ASCII mode
22 %020000 Magnetic tape
23 %010000 Plotter
24 %004000 Set for default TTY on channel -1
I 25
26
%002000
%001000
Device is spooled
Device can do input
27 %000400 Device is initialized for input
28 %000200 File is open for input
29 %000100 End of file encountered
30 %000040 Input ok status
31 %000020 Device can do output
32 %000010 Device is initialized for output
33 %000004 File is open for output
34 %000002 Device quota (exceeded)
35 %000001 Output status ok

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).

Version 2B ALGOL 16-10 December 1972


When IOCHA N is used, the end-of-file flags are always cleared, if set, so that the user may proceed
to read a magnetic tape after an end-of-file marker is found.

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

16. 11 TRANSFERRING FILES

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 •

Version 3 ALGOL 16-11 July 1973


CHAPTER 17
THE DECsystem-10 OPERATING ENVIRONMENT

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.

17.1 MATHEMATICAL PROCEDURES

The following procedures expect one argument, of real type, and yield a real type result.

Procedure Name Function

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.

17-1 July 1974


The following procedures expect one argument, of long real type, and yield a long real type resul t.
Note that theyare formed by adding an L before the equivalent single precision procedure.
Procedure Name Function

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

17.2 STRING PROCEDURE

For details of the procedures LINK, LlNKR, TAIL, LENGTH, COPY, NEWSTRING and DELETE, see
Paragraph 13.6.

17.3 UTILITY PROCEDURES

17.3.1 Array Dimension Procedures

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 •

PROCEDURE ZERO(A)J ARRAY AJ

BEGIN

INTEGER I .. JJ

IF DI~(A) =2 THEN

REG II'J

Ll .- LH(A .. ! ) ; lJl .- UR(A .. l);

FOR I := Ll UNTIL UI DO

FOR J : = L2 UNT I L U2 DO A[ I .. J) •- '1

END

END

17-2 July 1974


17.3.2 Minima and Maxima Procedures

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;

17.3.3 Field Manipulations

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);

gives the val ue of the byte consisting of bits 3 through 7 of A.

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

SF I ELD (A, 3,5, (-1 ) ;

zeros the byte specified in the' first example.

17.4 DATA TRANSMISSION PROCEDURES

For details of these procedures refer to Chapter 16.

17-3 July 1974


17.5 FORTRAN INTERFACE PROCEDURES

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:

CALL, lCALL, RCALL, DCALL, or LCALL

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.

CALL is used as a single statement, for example:

CA LL (FOkT, x, y)

is equival ent to

CALL FORT (X,Y)

in a FORTRAN program.

lCALL etc. must appear in the appropriate context in an expression, thus

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.

17-4 July 1974


CHAPTER 18
RUNNING AND DEBUGGING PROGRAMS

18.1 COMPILATION OF ALGOL PROGRAMS

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.

at monitor command level.

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

followed by a carriage-return (ALT MODE cannot be used to terminate a command string).


A fi Ie takes one of the forms
DEVICE: FILE- NAME. FILE- EXTENSION

or

DEVI CE: FIL E. NAME

for directory devices (disk and DECtape)

or
FILE-NAME. FILE-EXTENSION

or

FILE-NAME

where DSK is assumed to be a default device.

Version 2A ALGOL 18-1 May 1972


In the case of non-directory devi ces, the format is simply

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:

• E Line numbers are in columns 73 through 80 of the source pro-


gram.
L List the source program (default case).
N Error messages are not printed on the user1s terminal.
Q Delimiter words are in quotes.
S Suppress I isting of the source program.

These switches are set by preceding them with a I after a file, for example:

PRO D, PROD=PRO D1IL, PRO D2/S

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.

18-2 July 1974


The ALGOL compiler reports all source program errors both on the user's ~~rminal and in the listing
device (if it is other than the terminal). After compiling a program, the compiler returns with another
asterisk, whereupon the user may compile another program, or type tc to return to monitor level.

18.1. 1 Compilation of Free-Standing Procedures

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).

18.2 LOADING ALGOL PROGRAMS

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

18-3 July 1974


and giving the loader the command string

NAIN,SUbl,SUB2/G

After a program has been loaded, it may be executed.

18.3 RUNNING ALGOL PROGRAMS

ALGOL programs are executed by typing the console command

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.

18.4 CONCISE COMMAND LANGUAGE

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.

18.5 RUN-TIME DIAGNOSTICS AND DEBUGGING

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:

PROCEDURE TRAP (N, L); VALUE N, L;


INTEGER N; LABEL L;

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.

18-4 July 1974


Once such a trap is set up bt a call to TRAP, it remains in force until another call to TRAP sets a trap
to a different label, or until the trap is turned off by

TRAP (N)

i.e., omitting the label parameter in a trap call.

Note that the trap label is a formal parameter by value.

Table 18-1
Error Trap Numbers

TRAP NO. ERROR

18 FLOATING POINT OVERFLOW


19 FIXED POINT OVERFLOW
32 INPUT OR OUTPUT DEVICE UNAVAILABLE
33 ILLEGAL MODE FOR INPUT OR OUTPUT DEVICE
34 INPUT OR OUTPUT ON UNDEFINED CHANNEL
35 ATTEMPT TO READ OR WRITE ON DIRECTORY DEVICE WITHOUT FILE OPEN

37 FILE NOT AVAILABLE OR RENAME FAILURE


38 ATTEMPT TO READ OR WRITE OVER END-OF-FILE
39 ERROR CONDITION ON INPUT OR OUTPUT
40 ILLEGAL CHARACTER IN NUMERIC DATA
41 OVERFLOW IN NUMERIC DATA
42 ERROR CONDITION ON CLOSING FILE
43 ILLEGAL INPUT-OUTPUT OPERATION
44 1-0 CHANNEL NUMBER OUT OF RANGE
48 SQRT ARGUMENT NEGATIVE
49 LN ARGUMENT ZERO 0 R NEGA TIVE
50 EXP ARGUMENT TOO LARGE
51 INVERSE MATHS FUNCTION ARGUMENT OUT OF RANGE
52 TAN ARG UMENT TOO LARGE

18.5.1 Facilities to Aid in Program Debugging

18.5.1.1 Checking - The directive

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.

Version 3 ALGOL 18-5 July 1973


NOTE
Most inexplicable errors arising during the execution of an
ALGOL program are caused by an array subscript being out
of range. Whenever such errors occur, the program should
be recompiled with the array bound check feature on, and
rerun.

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.

18-6 July 1973


CHAPTER 19
TECHNICAL NOTES

These notes concern the authors' particular interpretation of the "Revised Report on the Algorithmic
Language ALGOL-60" and its implementation.

a. At all times, strict left-to-right evaluation of statements is employed. Section


3.4.6 of the Revised Report has been construed by some experts to mean that
left-to-right evaluation of expressions is not required. However, there are un-
doubtedly many ALGOL-60 programs in existence that rely on this feature.
b. Section 4.3.5 of the Revised Report requires that a GOTO Statement with a
designational expression which is a switch with a subscript out of range be
regarded as a dummy statement. Neither DECsystem-10 ALGOL nor any
other ALGOL-60 implementations, to the knowledge of the authors, follow
I this rule if there is a side-effect involved in the evaluation of the subscript.

19-1 December 1971


ALGOL INDEX

ABS, 5-3 CHECKO FF, 18-4


ALGOL-60, 1-1, 6-1, 7-1 CHECKON, 18-4
ALGOL-68, 1-1 CLOSEFILE, 16-4
AND, 5-4 COMMENT, 2-4
ARCCOS, 17-1 Commentary, 2-4, 11-11
ARCSIN, 17-1 Compiler Commands, 18-1
ARCTAN, 17-1 Compiler Extensions, 1-2
Arithmeti c Conditions, 5-5 Compiler Restrictions, 1-3
Array Elements, 9-2 Compiler Switches, 18-2
Arrays, 9-1 Compound Statements, 6-3
Arrays, OWN, 15-1 Compound Symbols, 2-2
ASCII Constants, 4-3 Concatenate, 13-3
Assignments, 1-2, 6-1 Conditional Expressions, 14-1
Condi tional Statements, 7-2
BA CK SPA C E, 16-1 0 Constants, 4-1 , 4-2, 4-3, 5-2
BEG IN, 6-3, 10-1 Controll ing Listing of the Source Program, 18-5
Block Structure, 10-1 Control Transfers, 7-1
BOOLEAN, 3-2 COPY, 13-5
Boo lean Constan ts, 4- 2 COS, 17-1
Boolean Conversions, 5-5 COSH, 17-1
Boolean Expressions, 5-4, 5-5
Data, 16-7, 16-8
Boo I ean Operators, 5-4
Data Transmission, 16-1
Boolean Variables, 3-3
Debugging, 18-4
Brackets, 4-3, 9-1
Declarations, 3-2
BREAK OUTPUT, 16-5
Buffering, 16-3
Default I/o, 16-9
DELETE, 13-6
Byte manipulations, 17-3
Deleting Rles, 16-4
Byte Processing, 16-5
Delimiter Word, 1-3
Byte String Copying, 13-5
Delimiter Words, 1-2, 2-2
Byte Stri ngs, 13-1
Designational Expressions, 14-3
Byte Subscri pti ng, 13-2
Device Allocation, 16-1
Device modes, 16-2
Channels, 16-3, 16-10
Devices, 16-1
Channel Status, 16- i 0
DIV, 5-1
Checking Array Subscripts, 18-4

1-1 May 1972


ALGOL INDEX (Cont)

DO, 8-1 IMP, 5-4


Dummy Statement, 19-1 INPUT, 16-2
Dynamic Bounds, 10-3 Input Data, 16-7
Input/Output Channels, 16-3
Edi ti ng Characters, 16-6 I NSY MBOL, 16-5
ELSE, 7-2 INTEGER, 3-2, 4-1
END, 6-3, 10-1 Integer Constants, 4-1
End-Of-File, 16-10 Integer Conversions, 5-5
END FIL E, 16- 10 Integer Remainder, 1-2
ENTlER, 5-2 10CHAN, 16-10
EQV, 5-4 I/O Channel Status, 16-10
EXP, 17-1
Exponents, 4-1, 16-7 Jensen's Device, 11-6
Expressions, 6-2
EXTERNAL, 11-10

FALSE, 4-2 LABEL, 11-1


Fault Monitoring, 1-3, 18-5 Label, 1-3, 7-1
Field manipulations, 17-3 LARCTAN, 17-1
File Deletion, 16-4 LCOS, 17-1
File Devices, 16-4 LENGTH, 13-5
File Names, 16-4 LEXP, 17-1
File Protection, 16-4 Library, 1-3, 17-1
FOR & WHILE Statements, 8-1, 8-2 Library Procedures, 13-3
Formal Parameters, 1-3, .1-4, 11-1 LINE. 18-5
Forward References, 1-3, 11-9 LINK, 13-3
L1NKR, 13-3
Line Numbers in Listings, 18-5
GFIELD, 17-3
Linking Loader, 1-2, 18-3
GLOBAL, 10-2
Listing the Source Program, 18-5
GO, 2-3, 7-1
LISTOFF, 18-5
GO TO, 2-3, 7-1
LISTO N, 18-5
LLN,17-1
Identifier, 1-3, 1-4, 3-1, 5-2 LMIN,17-3
IF, 7-2 LN, 17-1
IMAX, 17-3 Loading Procedures, 18-3
IMIN, 17-3 local, 10-2
1-2 May 1972
ALGOL INDEX (Cont)

Logical I/O, 16-9 PAGE, 16-6


LONG REAL, 1-2,3-2,4-2 Parameter, 1-4, 11-1
Long Real Constants, 4-2 Peri pheral s, 16-1
LSIN, 17-1 PRINT, 16-8, 16-9
LSQRT, 17-2 PRINTOCTAL, 16-9
PROCEDURE, 1-4
Procedure Bodies, 11-3
Mathematical Procedures, 17-1
Procedure Call Parameters, 11-2
Matrix, 9-1
Procedure Calls, 11-5
tv'ode, 16-2
Procedure Headings, 11-3
Procedures, 11-1
Procedures, Advanced, 11-6
Name, 11-1
Protection, 16-4
NEWLINE, 16-6
NEWSTRING, 13-6
READ, 16-7
Newton- Rapheson, 11-4
READOCTAL, 16-9
NEXTSYMBOL, 16-5
REAL, 3-2, 4-1
NOT, 5-4
Real Constants, 4-1
Numeric Constants, 4-1
Recursion, 11-7
Numeric Labels, 1-3
RELEASE, 16-4
Numeric Procedures, 16-7
Relocatable Binary, 1-2
REM, 5-1
Object Time System, 17-1, 18-4 Rename, 16-4
Octal Constants, 4-2 Reserved Words, 2-3
Octal I/O, 16-9 Revised Report, 1-1, 19-1
OPENFILE, 16-4 REWIND, 16-10
Operating Environment, 1-3 RMAX, 17-3
OR, 5-4 RMIN, 17-3
OUTPUT, 16-1 Run-time diagnostics, 18-4
Output Data, 16-8
OUTSYMBOL, 16-5 Scalar, 3-2

OWN Arrays, 15-1 Scope, 10-2

OWN Variables, 15-1 Sel ect, 16-3


SELECTINPUT, 16-3

July 1973
'1-3
ALGOL INDEX (Cont)

SELECTOUTPUT, 16-3 TRANS FILE, 16-11


Semicolon, 6-3 Trapping errors, 18-4
Separators, 2-1 T RAP procedure, 18-4
Setting Line Numbers in Listings, 18-5 TRUE, 4-2
SFIELD, 17-3 Type Conversion, 5-2
Side-effect, 19-1
SIGN, 5-3 UNTIL, 8-2
SIN, 17-1
Single-pass Compiler, 1-2 VALUE, 11-1
SINH, 17-1
SKIPSY MBOL, 16-5 WHILE, 1-2,8-2, 8-3
SPACE, 16-6 While Element, 8-3
Spacing, 2-4 WRITE, 16-5
SQRT, 17-1
Statements, 6-1
STEP - UNTIL, 8-2
STRING, 3-3
String Comparisons, 13-3
Stri ng Co nstants, 4-3
String Output, 16-5
String Procedures, 16-7
String Variabl es, 3-3
'Strings, 1-2, 13-1, 13-2, 13-3, 16-5
Strings, Byte, 13-1, 13-5
Subscripting, Byte, 13-2
Switches, 12-1, 14-1
Symbol Procedures, 16-6
Symbols, 2-1
Symbols, Compound, 2-2

TAB, 16-6
TAIL, 13-4
TAN, 17-1
TANH, 17-1
Terminology, 1-3

1-4 July 1973


DECsystem-10 ALGOL Programmer's Reference
DEC-10-LALMA-A-D

READER'S COMMENTS

NOTE: This form is for document corr~ents only. Problems


with software should be reported on a Software
Problem Repcrt (SPR) form (see the HOW TO OBTAIN
SOFTWARE INFOR}ffiTION page) .

Did you find errors in this manual? If so, specify by page.

Did you find this manual understandable, usable, and well-organized?


Please make suggestions for improvement.

Is there sufficient documentation on associated system programs


required for use of the software described in this manual? If not,
what material is missing and where should it be placed?

Please indicate the type of user/reader that you most nearly represent.

[] Assembly language programmer


[] Higher-level language programmer
[] Occasional programmer (experienced)
[] User with little programming experience
[] Student programmer
[] Non-programmer interested in computer concepts and capabilities

Name Date ___________________________

Organization _________________________________________________________________

Street ________________________________________________________________________

City ___________________________ S~ate-------------Zip Code _______________


or
Country

If you do not require a written reply, please check here. []


-------------------------------------------------------------Fold lIere------------------------------------------------------------

.----------------------------------------------- Do Not Tear· Fold lIere and Staple ------------,;.----------------------------------

FIRST CLASS
PERMIT NO. 33
MAYNARD, MASS.

BUSINESS REPLY MAIL


NO POSTAGE STAMP NECESSARY IF MAILED IN THE UNITED STATES

Postage will be paid by:

Software Communications
P. O. Box F
Maynard, Massachusetts 01754

You might also like