Digital Equipment ALGOL 4K ALGOL compiler User manual
PDF
Документ
Реклама
Реклама
us
t,IBF-lARV
OECUSNO.
TITLE
AUTHOR
8-213
AK ALGOL
·University of Grenoble
Submitted -By:
COMPANY
DATE
SOURCE LANGUAGE
Charles Conley
Digital ;Equipment Corporation
Maynard, Massachusetts
April 11, 1969
ALGOL
AI though this program has been tested by the contributor, no warranty, express or implied, is made by the contributor,
Digital Equipment Camputer Users Society or Digital Equipment Corporation as to the accuracy or functioning of the
program or related program material, and no responsibility is assumed by these parties in connection therewith.
!.DENTI FI CATION
Product COde.
DEC-OB-KAYA-D
Product Name.
ALGOL-B
Date Created.
March 31,1969
PREFACE
This manual has been written for ALGOL users with a 4K
or larger PDP-8.
Th~
subset of ALGOL compiled by the system is SUBSET ALGOL
60 (IFIP)* with additional restrictions which are described in
Appendix B.
The manual is essentially a user's handbook and is not
intended as a ALGOL Primer.
introduction to ALGOL-8.
Chapter 1 is included as a general
The reader who wishes to learn the
ALGOL language in greater depth should refer to one of the
several texts on the subject,' such as "A Guide to ALGOL programming"
by Daniel D. McCracken (published by John Wiley and Sons, New
york) •
This compiler was written by J. C. Boussard, D. Clauzel,
and X. Nguyen Dinh of IMAG (Institute of Applied Mathematics,
University of Grenoble).
This manual is preliminary and subject to change without
notice.
*Comrnunications of the ACM volume 7, No. 10, October 1964
pp 626-628 "Report on Subset Algol 60 (IFIP).
COIrl1llunications of the ACM volume 6, No.1, January 1963,
pp 1-17 "Revised Report on the Algorithmic Language, ALGOL 60."
ii
CONTENTS
CHAPTER 1
INTRODUCTION
1.1
ALGOL-8 Program Fonn
1-1
1.2
ALGOL-8 Input/Output
1-3
1.3
Sample Programs
1-3
1.3.1
Arithmetic Operators
1-3
1.3.2
Compound Statements
1-7
1.3.3
Blocks
1-10
CHAPTER 2
REPRESENTATION OF ELEMENTS .
2.1
Integers
2·1
2.2
Real Numbers
2-1
2.3
Basic Symbols
2-2
2.3.1
Long Basic Symbols
2-2
203.2
Short Basic Symbols
2-2
2.4
Identifiers
2-3
2.5
Constants
2-3
2.6
Variables
2-3
2.7
Subscripted Variables and Arrays·
2-4
2.8
Statements
2-4
2.9
Labels
2-4
iii
CHAPTER 3
EXPRESSIONS
3.1
A1:'itlunetic Expressions
3-1
3.1.1
Constants
3-1
3.1.'2
Variables
3-1
3.1.3
operators
3-2
3.1.4
Mixed Mode Expressions
3-3
3.1.5
Standard Functions
3-4
3.2
Boolean Expressions
3-4
3.2.1
Forms
3-6
3.2.2
Limitations
3-7
CHAPTER 4
DECLARATIONS
4.1
variables
4-1
4.2
Arrays
4-1
4.3
Switches
4-2
4.4
Procedures
4-3
CHAPTER 5
STATEMENTS
5.1
Assigned Statements
5-1
5.2
GOTO Statements
5-2
5.3
FOR Statements
5-2
5.4
COnditional Statements
5-4
5.5
Dummy Statements
5-5
5.6
Comments
5-5
5.7
Sample Program
5-7
iv
CHAPTER 6
INPUT/OUTPUT STATEMENTS
6.1
I/o Statement Form
6-1
6.2
Output Format
6-2
6.3
Input Format
6-2
6.4
Text OUtput
6-2
6.5
New Line
6-3
CHAPTER 7
DIAGNOSTICS
7.1
Compile Time Diagnostics
7-1
7.2
Execution Time Diagnostics
7-6
CHAPTER 8
OPERATING INSTRUCTIONS
8.1
Compiler
8-1
8 0 1.1
Operation
8-1
8.1.2
Memory Usage
8-4
8.2
Operating System
8-4
8.2.1
Operation - No Functions Required
8-4
8.2.2
Operation - Functions Required
8-5
8.2.3
Memory Usage
8-5
8.3
Paper Tape Input Format
8-6
8.3.1
Compiler Input
8-6
8.302
Ope,ra ting
Sys~em
Input
v
8-6
APPENDIX A
ALGOL-8 BASIC SYMBOLS
APPENDIX B
RESTRICTIONS
APPENDIX C
TABLE OF ERRORS
APPENDIX 0
ALGOL-8 SUMMARY OF COMMANDS
APPENDIX E
NOTES ON ALGOL
vi
chapter 1
INTRODUCTION
An ALGOL-S program includes elements (numbers and symbols),
expressions (arithmetic and Boolean), statements, and declarations.
precise definitions of these parts of an ALGOL-8 program are contained in later chapters.
Those elements which are needed to
write simple ALGOL-8 programs are introduced in the following
discussion.
l.'!~"~. ~W.9~,,:,~" fr9gr8!!l-.~g,!!l1~.
ALGOL-8 programs start with a • BEGIN , statement and conclude
with an 'END' statement followed by a $ as shown below.
Body of ALGOL-8 Program
The body of the ALGOL-8 program specifies the action to be
perfonaed.
For example, the body of the program could contain
statements to accept the input of data, perform some calculation,
and output the results.
The type of. data (integer or real numbers) must be. specified
before it may be used in an ALGOL-8 program.
The declarations
'INTEGER' and 'REAL' are used to specify the type of number which
is represented by a sy.mbol, as seen below.
1-1
'BEGXN'
'REAL' A,B,CJ
. 'XNTEGER' X,J,KJ
•
•
'END'
•
$
The 'XNTEGER' and 'REAL' statements, as well as all other ALGOL-8
statements are terminated by a semicolon.
Once the variables are declared they may be used in ALGOL-8
program calculations.
For example the following ALGOL-8 program
adds three numbers.
'BEGXN'
'XNTEGER' A,B,C,SUMJ
AI=5J
BI=27J
Ca=15J
SUM.=A+B+CJ
'END'
$
Notice in the above program the difference between the variables
A, Band C and the variable SUM.
A, Band C are integer constants
given an explicit value by an assignment statement, such as AI=5J.
(The colon must be used with the equal sign in an assignment
statement.)
SUM is an integer variable whose value is determined
by running the program.
The constants of the previous program need not be aSSigned
the identifiers A, Band C.
The same result could be achieved
through the following program where only SUM is declared as a
variable.
'BEGXN'
'XNTEGER' SUM a
SUMa= 5+27+l5J
'END'
$
1-2
The preceding programs do not provide for the output of
results or for the substitution of input by the user.
This may
be accomplished in ALGOL-8 through the READ and WRITE procedure
statements.
1,· 2~_.~mQ.l;c~.J:E.p!!~1Ql1~~l!l:! 1:.
ALGOL-8 programs may use either the Teletype console or
the high-speed reader/punch as the input/output device for READ
or WRITE statements.
The device to be used and the inforrration
to be read or written is specified within parentheses after the
input/output procedure statement.
The integer 1 specifies the
ASR 33 Teletype, 2 specifies the high-speed paper tape unit, as
seen in the following examples.
READ (1,1)
The ALGOL-8 program will accept a value
for the variable I from· the Teletype keyboard or paper tape reader.
WRITE (2,A,B,C)
The ALGOL-8 program will punch the values
for the variables A, Band C on the
high-speed paper tape punch.
The variables must be declared before they are used in a READ or
WRITE Procedure Statenlent.
h~~ ~~pl~_J>~~rCl!tl~.
The following sample programs are provided to illustrate
some of the features of ALGOL-8, and to acquaint the reader with
the language in general.
1,,}-.~--- _~.r~ ~~~!:~9- ..O!?,e.r!l..t?!:.~.
ALGOL-8 programs may contain the arithmetic operators for
addition (+), subtraction (-), multiplication (*), division (/),
and exponentiation (f).
The following program combines the READ
1-3
'BEGIN'
'COMMENT' ARITHMETIC DEMOJ
'REAL' AIBIRSUMIRDIFIRPRDIRQUOJ
'INTEGER' IIJIISUMIIDIFIIPRDIIQUOJ
WRITE <11 "TYPE TWO REAL NUMBERS")JSKIPJ
READ (11 AIB)JSKIPJ
RSUM:=A+BJ WRITE <1IAI" PLUS
"IBI"="IRSUM)JSKIPJ
RDIF:=A-BJ WRITE <1IAI" MINUS
"IBI"="IRDIF>;SKIPJ
RPRD:=A*BJ WRITE <1IAI" TIMES
"IBI"="IRPRD>;SKIPJ
RQUO:=A/BJ WRITE <1IAI" DIVIDED BY"IBI"="IRQUO)JSKIPJ
WRITE ClI "TYPE TWO INTEGERS">;SKIPJ
READ (11 IIJ)JSKIPJ
ISUM:=I+JJ WRITE (1111" PLUS
"IJI"="IISUM)JSKIPJ
IDIF:=I-JJ WRITE <1111" MINUS
"IJI"="IIDIF)JSKIPJ
IPRD:=I*JJ WRITE (1111" TIMES
"IJI"="IIPRD)JSKIPJ
IQUO:=I/JJ WRITE <1111" DIVIDED BY"IJI"="IIQUO)JSKIPJ
'END'
$
Example A
TYPE TWO REAL NUMBERS
213
13.21313131313 $+131 PLUS
13.21313131313$+131 MINUS
13 .21313131313 $+131 TIMES
13 .21313131313 $+13 1 DIVIDED BY
TYPE TWO INTEGERS
213
2
2
2
2
PLUS
MINUS
TIMES
DIVIDED BY
3=
3=
3=
3=
13.31313131313 $+131 =
13 • 31313131313 $+131 =
13.31313131313 $+131 =
13.31313131313$+131=
13 .51313131313 $+131
-13 .11313131313 $+131
13 • 61313131313 $+131
13 • 666666$+1313
5
-1.
6
1
Example B
TYPE TWO REAL NUMBERS
891765
13.889999$+132 PLUS
13.889999$+132 MINUS
13 .889999 $+13 2 TIMES
13.889999$+132 DIVIDED BY
TYPE TWO INTEGERS
891765
89
89
89
89
PLUS
MINUS
TIMES
DIVIDED BY
Jr1.qure 1-1
13.765131313$+133=
13.765131313$+133=
13.765131313$+133=
13.765131313$+133=
765=
854
765=
-676
765= -1547
765=
13
AI..GOL-S Arithmetic Program
1-4
13 .853999$+133
-13 .675999$+133
13.6813849$+135
13 .116339$+130
and WRITE statements with arithmetic operators.
program output are also included.
TwO
exa~ples
of
Following the listing the pro-
gram is described line by line.
Line 1
The 'BEGIN' statement must be the first element
of the ALGOL-8 program.
The • COMMENT , statement
may be used to include comments to identify the
program in the source listing.
comments are not
typed during the running of the program.
Line 2
All of the real number variables which are used
within the ALGOL-8 program are declared with the
'REAL' statement.
Line 3
The integer variables are declared with the
statement 'INTEGER'o
Line 4
The WRITE procedure statement is used to
user input.
req~est
Any text included within double
quotes is typed during the
r~nning
of the program.
The SKIP procedure statement is used to generate a
new line for typed output.
(It is equivalent to
a carriage return and line feed on the Teletype
console. )
Line 5
The READ procedure statement accepts the user
input to the ALGOL-8 program.
The program will
not continue until the user types two real
numbers on the Teletype keyboard.
Real number
input may be tenllina ted by typing any keyboard
character other than a number, plus or minus
Sign, period, or dollar sign.
1-5
Lines 6,7,8,9
Once the input of two numbers is received,
the ALGOL-8 program computes the various
arithmetic combinations and types the results.
The output of results is formatted by combining
output of text (included within double quotes)
and variables.
Variables and text are separated
within the WRITE statement by commas.
Each line
is tenainated with a SKIP to allow the next
output to start on a new line.
Line 10
The WRITE procedure statement on line 10 requests
the user to input two integers.
The SKIP
generates a new line on which the input may be
typed.
Line 11
The READ procedure statement accepts the user
input of two integers.
The integers may be
tenninated with any character other than a number.
Lines 12,13,
14,15
The arithmetic comb.inations of the integers are
computed and typed in a stmilar manner to that
for the real numbers above.
Line 16
The 'END' statement concludes the ALGOL-8 program statements.
Line 17
The ALGOL-8 program must be followed by a dollar
sign as the first character on a line.
The running of the program produces the output shown in
examples A and B of figure 1-1.
The examples illustrate the
differences in ALGOL-8 representation of real numbers and integers.
1-6
The input of values was in all cases terminated by a carriage
return.
Real numbers are output in an exponential notation with the
number separated by a dollar sign ($) from the exponential power
(base 10) by which it is multiplied.
Examples I
-j. 2jjjj~$
~l
equals
j. 2~jjj~$-~5
equals
-~.2~~~~~Xl~1
,. 2~'J6J6J6Xlr5
equals
-2.J6j~'J6
equals
j.~j~~j2
Integers are output as whole numbers, with up to four digits,
and a minus sign if the number is negative.
Eq~ivalent
results for integer or real number input are ob-
tained for the operations of addition and subtraction.
Integer
multiplication does not check for overflow, and as evident in
example B, can yield incorrect results (e.g. 89 x 765
= -1547).
Integer division differs from real division in that, since the
result is not always an integer, the answer is always rounded off
to the nearest integer.
As evident in example B, real number representations in
ALGOL-8 are not always exact.
For example, the number 89 is
approximated as a real number in ALGOL-8 by the number 88.9999.
1.~..!.,~ __... C~!ld~~e]lt~.
The example of figure 1-2 uses the multiplication operator
to generate the first ten powers of a number.
The program
employs a FOR statement to allow repeated execution of a
grouping of ALGOL-8 statements.
1-7
FOR statements have the forma
'FOR' E 'STEP' I •UNTIL' F
'oo's
where E is an assignment statement (e.g. VI=l)
I is an increment (e.g. 1)
F is a final value (e.g. 10)
S is a statement, compound statement, or block.
The expression after 'FOR' assigns an initial value to the
variable.
The statement following 'DO' is then executed for this
assigned value.
Once the statement is executed the variable is
incremented by the value following 'STEP' and the statement following '00' is executed for the new value of the variable.
The vari-
able is repeatedly incremented and the statement is repeatedly
executed for all values up to, and including, the value following
'UNTIL'
0
In the program of figure 1-2, the '00' is followed by a
compound statement.
A compound statement is simply two or more
ALGOL-8 statements enclosed in
'END').
s~A.t,.~~!!.-~_~,e:r~~~e~s
('BEGIN' and
This group of statements is executed as if it were one
statement following the 'DO'
There must be an equal number of
•BEGIN' symbols and 'END' symbols in every ALGOL-8 program.
The program simply requests a real number input and then
repeatedly executes the compound statement which computes the
powers of A.
The statement XI=A*X computes the next power of A
because X always equals the last power computed.
Notice that X
had to be set equal to 1 before the compound statament was executed.
1-8
'BEGIN'
'COMMENT' COMPUTE POWERS OF AJ
'INTEGER'VJ 'REAL' AIXJ
WRITEClI"FOR WHAT NUMBER WOULD YOU LIKE THE FIRST TEN POWERS?")J
X:=lJ
READ <IIA)J SKIPJ
'FOR' V:=I 'STEP' 1 'UNTIL'10 'DO'
'BEGIN'
X:=A*XJ
WRITE <IIAI" TO THE"I VI" EQUALS"IX)J
SKIPJ
'END'
SKIPJSKIPJ
'END'
$
FOR WHAT NUMBER WOULD YOU LIKE THE FIRST TEN POWERS? 45.
0.449999 $+02
0.449999 $+0 2
0.449999 $+02
0.449999$+02
0.449999$+02
0.449999 $+02
0.449999 $+02
0.449999$+02
0.449999$+02
0.449999$+02
TO
TO
TO
TO
TO
TO
TO
TO
TO
TO
THE
THE
THE
THE
THE
THE
THE
THE
THE
THE
1
2
3
4
5
6
7
8
9
10
EQUALS
EQUALS
EQUALS
EQUALS
EQUALS
EQUALS
EQUALS
EQUALS
EQUALS
EQUALS
0.449999 $+02
0.202500$+04
o .91 1249 $+0 5
0.410062$+07
0.184528$+09
0.830376$+10
0.373669$+12
o • 1 68 1 51 $+ 1 4
0.756680$+15
0.340505$+17
FOR WHAT NUMBER WOULD yOU LIKE THE FIRST TEN POWERS? 987.
0.986999$+03
0.986999$+03
0.986999 $+0 3
0.986999$+03
0.986999$+03
0.986999$+03
0.986999$+03
0.986999$+03
0.986999$+03
0.986999$+03
TO
TO
TO
TO
TO
TO
TO
TO
TO
TO
Figure 1-2
THE
THE
THE
THE
THE
THE
THE
THE
THE
THE
1
2
3
4
5
6
7
8
9
10
EQUALS
EQUALS
EQUALS
EQUALS
EQUALS
EQUALS
EQUALS
EQUALS
EQUALS
EQUALS
0.986999$+03
o .9741 69 $+0 6
0.961504$+09
0.949005$+12
0.936668$+15
0.924491$+18
0.912472$+21
o .90061~$+24
0.888902$+27
0.877347$+30
Program to ,Compute First Ten Powers
1-9
1.!..3_~~ __~_1<?g~!l.
The following sample program plots linear equations using a
El_~
to perfona the actual plotting.
An ALGOL-8 block is simply
a compound statement which contains declarations.
•
•
•
'BEGIN'
'INTEGER' I,J,KJ
'REAL' A,B,CJ
'BOOLEMt' N,MJ
•
•
•
Statement
Statement
•
•
'END'
•
•
•
•
The declarations made within a block are not applicable
outside the block.
Thus local variables may be assigned which
have a value while the program is executing a given block but which
are not defined in an outer block.
The use of the
b~ock
is
illustrated in the program example of figure 1-3.
The first part of the program requests and accepts the real
coefficient and the real constant ternl of the linear equation
using WRITE and READ procedure statements.
The horizontal axis
for the values of the eqaation is established with four WRITE
statements.
The FOR statement is then used to plot the equation
using values of X from -10 to 10.
The block begins by declaring the variables which are used
exclusively within the block.
The use of local variables in large
1-10
pr~rams
allows the ALGOL-8 programmer to efficiently use the
finite number of variables allowed in ALGOL-8, by freeing them
upon exit from the bloCk.
Boolean variables are used to test for points which are
outside the range of the values.
Since the solution of the equation is a real number and the
number of spaces must be an integer (the upper bound of a FOR
statement must be an integer), the function ENTlER is used.
ENTlER
converts a real number, N, to the greatest integer, I (positive
or negative), such that I is less than or equal to N ~.g. ENTlER
(+5.9) =5J ENTlER
(+6.~)
=6, ENTlER (-4.32)
= -5).
The reader
should note that ENTlER is neither truncation nor rounding off,
although in some cases they will produce the same results.
A FOR statement within the block is used to plot the number
of spaces up to the point.
In this case, the upper limit of the
FOR statement is an integer variable, rather than a specific
integer, allowing different spacing for each pOint plotted.
The program loops to its beginning with a GOTO statement which
penuits the program to plot a series of equations without being
restarted.
A sample running of the program is also shown in figure 1-3.
Notice that although the equation is linear, in this case the.
graph only approximates linearity because "partial spaces" cannot be plotted.
'BEGIN'
'COMMENT' LINEAR PLOT PROGRAMJ
'INTEGER' XJ
'REAL' Al~BJ
LIN: WRITE C1~ "I'LL PLOT YOUR LINEAR EQUATION FOR YOU!")JSKIPJ
WRITE(I~"WHAT IS THE COEFFICIENT OF X?")JSKIPJ
READ (l~Al)JSKIPJ
WRITE C1~"WHAT IS THE CONSTANT TERM?")JSKIP;
READ (l~B)J
SKIPJSKIP;SKIPJ
WRITE C1~"
-30
-20
-10
0");
WRI TE (1 ~"
10
20
30"); SKIP;
WRITE (1~"
t
t
t");
WRITE C1~"
t
t
t">JSKIP;
'FOR'X:=-10 'STEP'l 'UNTIL'10 'DO'
'BEGIN' 'COMMENT' PLOT BLOCK;
'I NTEGER' V~PLOT;.
'REAL' CONST;
'BOOLEAN' Bl~82;
WRITE C1~X);
CONST:=X*Al+8+34;
PLOT:=ENTIER (CONST);
Bl:=PLOT<2; 82:=PLOT>65;
'IF' 81 'THEN' 'GOTO' POINT'ELSE'
'IF' 82 'THEN'PLOT:=66;
'FOR'V:=1 'STEP'1 'UNTIL'PLOT 'OO'WRITE C1~" ")J
POINT:WRITE (1,"*");SKIP;
'END'
SKIP; SKIP; SKIP; 'GOTO 'LI N
'END'
$
I'LL PLOT YOUR LINEAR EQUATION FOR YOU!
WHAT IS THE COEFFICIENT OF X?
0.66667
WHAT IS THE CONSTANT TERM?
2
-30
-20
-10
t
-10
0
10
t
t
*
*
-9
-8
-7
-6
-5
-4
-3
-2
*
*
*
*
*
*
*
-1
*
o
*
*
1
2
*
3
4
*
*
5
*
6
7
8
9
10
*
*
*
*
*
I'LL PLOT YOUR LINEAR EQUATION FOR YOU!
WHAT IS THE COEFFICIENT OF X?
F;!qure 1-3
Linear P1 ot Program
1-12
20
30
t
Chapter 2
REPRESENTATION OF ELEMENTS
2 •.L
I~teg:~r!
Integers are signed numbers (the positive sign is not always
expressed). written without a dectmal point. in the range % 2040.
Division between integers produces a real result.
division between integers yields the closest integer.
In ALGOL-8.
For ey.amplc,
if J=8 and K=3. the division of J by K gives 2.6666 and the result
in ALGOL-8 is 3.
Integers are represented with one 12-bit word.
The first bit
(bit ¢) is the sign bit and bits 1 through 11 contain the integer
magnitude.
Bit¢
= Sign
~L.B~~!~~1.?!.;-~~
Real numbers are signed numbers (the positive sign is not
always expressed) of the decimal exponent form in the range
±
0.32$617 to
±
0.31$-616 ($ indicates the multiplication by a
power of 10).
The forms represented by the following examples are allowed
in ALGOL-8 programs.
-0.1234
5.0
.5
1.2$-2
-2.3
-0.1$10
2-1
(=.012)
(=-1,000,000,000)
Real numbers are represented by three l2-bit words.
first word represents the exponent and its sign.
The
The second
word represents the higher order bits of the mantissa, and
the sign of the mantissa.
The third word represents the lower
order bits of the mantissa.
[~f~~F~·~ Exponent =~~~-=~-~~_-J~-'~
fA 1
•••
Bit fA
= Sign
11
I'-i~_' -~igh-O~d~; Ma~ti~~~~~~l Bit fA = Sign
_-t.~j
- ~ . ~-•••. _ ..... --...-"._-fA 1
11
~ .. -~~~-~~~'; o~de;~~~-~i~-S-~··=;=-~t
L_J~t
_ ,,_..
_.._
•••
__..1 ____ ,
1
~.•.'!}_.__ )3.ctsi_c_ EYF'1l:>91e;.
fA
Basic
program.
sx~~ols
11
are the predefined elements of an ALGOL-8
Long basic symbols are typed enclosed in single quotes,
while short baSic symbols stand alone.
Appendix A contains all
the penaitted Basic synlbols and their representation in
~OL-8.
h3_~l~_ .I.er,tg .J~e!lJ·~_.SY!!lbQ1.-_s.
Some symbols and logical operators are represented by a
string of two or more letters enclosed in single quotes.
They
are identified by their first two letters only, e.g., 'BEl and
'BEGIN' are equivalent.
Examples.
'BEGIN'
'INTEGER'
'SWITCH'
'£'~!~?.._.§})C)E!:P_~_~ _~g.§)'!l}~.l.~
other baSic syrrtbols are represented by a single character
or, exceptionally, by two successive characters (a character
followed by an equals sign).
2-2
EXamples I
*
i
multiplication
<. :.:
less than or equal to
exponentiation
2. 4._h~entifiers
An identifier is a name given to a variable in an ALGOL-S
program.
An identifier must begin with a letter and may contain
only letters and numerals.
The. length of an identifier is not
limited but only the first four alphanumeric characters are
significant.
For example, CARlS, CARlS and CARl are interpreted·
as the same identifier.
For this reason it is good practice to
limit identifiers to four characters.
~.!1".~ gon_s~~~ll.ts
Integer constants (and the whole number· part of real constants),
must have an absolute valae less than. or equal to 2040, when their
value is given explicitly in an ALGOL-S program.
Examples I
Real Numbers
-T.O.
I~_!:e.9:.~E~
27
-2035
235.0$50
-2.48
5
~§~_~.!Ja.l:)!~~.
ALGOL-8 variables are quantities which are referred to by
name (by its identifier) and are able to take on different values.
Variables may be Boolean, integer or real type.
may not be subscripted.
Boolean variables
The possible values of a Boolean variable
are true and false.
Integer or real variables may be subscripted.
variable is
.&
(A subscripted
real or integer one-dimensional array., as described
in paragraph 2.7.)
2-3
Simple variables (not subscripted) have identifiers as
described in paragraph 2.4 (e.go A, SUM, INT5).
2. 7 ~ ~"!.P.!!.crJ.E.~!9Yi3:.:r i~~~=~!}~~~.~F-:r;_~'y_f!
Subscripted variables permit the representation of many
quantities with one identifier.
A
subscripted variable is one
dimensional array (the only type of array allowed in ALGOL-8).
It
may be an array of integers or real numbers.
Subscripted variables have identifiers folllwed by brackets
enclosing the subscript (e.g. SUM [IJ, X[J]).
integer and its lowest value must be either
NOTE.
¢
The subscript is an
or 1.
[= shift/K
The brackets
and
] = shift/M
on the ASR 33 Teletype Keyboard o
Statements are commands to the computer to carry out
operations.
ALGOL-8 statements must be tenainated with a semicolon.
Examples a
START;
'GOTO'
'IF' A=B
'THl~a~' XI=l
'EV;;E' Xa=¢;
compound statements are several statements grouped together and
enclosed between the statement brackets 'BEGIN' and 'END'.
b2~ . ~.Ie~l:!I.
A label is used in an ALGOL-8 program to reference or identify
statements in a program.
It must be an identifier and must be
followed by a colon.
Example,
START a
RE~n
(1, I)J
2-4
Chapter 3
EXPRESSIONS
~~~~it~~tic~~ssion~
Arithmetic expressions may include constants, variables,
operators and functions.
For example, the arithmetic expression.
may be written as an ALGOL-8 arithmetic expression
(-B + SQRT (B t 2-4*A*C»/(2*A)
where 2 and 4 are constantsJ A, B, and Care variablesJ *,
+,
-, and + are operators, and SQRT is a function •
.~..!,kJ·_"".. ,C~~J;a~.1::f3.
Constants used in arithmetic expressions may be either
integer or real.
Integers may be of the following forms (i. e. I
-7
5
~
2040) •
2018
Real numPers of the following form may be used in arithmetic
expressions.
± a.b$±c
b
= whole number part (~2040)
= fractional part (6 digits or
c
= exponent,
where a
less)
base 10 (-616 ~ c 6617)
.!~..!!~?~"",.~Y~~l~~!~~,
A variable used in an arithmetic expression is one or more
alphanumeric characters which obey the following rules.
3-1
a)
The first character must be a letter.
b)
Spaces are ignored.
3)
Only the first four characters are significant, and
therefore must be unique.
~ 1 •. 3~ ..__~~~or!.
The operators in arithmetic expressions are symbols representing the common arithmetic operations, plus left and right
parentheses which serve as delimiters.
Arithmetic expressions in ALGOL-8 are evaluated from left
to right with an an additional priority rule for operators.
~bo~~
prAQF.~ty.
,
1
(
2
+
3
*, /
4
+,
)
-
Thus exponentiation ( t ) is perfOrTIled before either multiplication
or division, which are performed before addition or subtraction.
parentheses have the highest priority and may be used to give
priority to lower operators.
Operations of the same level are perfonaed left to right.
Examples
A *B + C/D -
=
E*F + G
(A*B) + (C/D) - (E* (F of' G»
Two arithmetic operators must not be written side by side.
A/-B is not a legal ALGOL-8 arithmetic expression while
legal.
AI
Thus
(-B) is
All signed exponents must be enclosed in parentheses to
3-2
·separate the exponentiation sign ( t ) from the sign of the
. exponent (+ or -).
Division (I) and exponentiation (
+) are
considered real
For small powers of a variable such as X t 2, or X t 3,
operators.
it is preferable to use X*X, or X*X*X, so that the functions
need not be loaded (see paragraph 8.2).
The exponentiation operator
( f ) in ALGOL-9 is undefined when the variable is zero or a
The programmer must therefore specially treat such cases.
fra~tion.
The
following examples demonstrate the importance of correctly
writing the arithmetic expression.
Different placements of
parentheses can yield very different results.
ALGOL EXPRESSION
ALGEBRAIC EQUIVALENT
A+B*X-c/x12
*
(A + B)
(A + B)
X -(C/X)'" 2
* ex -
C)
Ix"
2
C
=
A + BX -
=
AX + BX - c2
=
xi
X2"
~ :-Ag~-=~C
X2
A
+ (B* X-C) I X + 2
=
A+.!L.
X
_C
i2'
~.1_.~. "~i~~~E..lt<?.d~_.~~_;-~~"!p.!!!
Variables of real and integer type may be mixed in an
expression.
Integers are converted to reals before calculations.
The form of the expression may affect the result.
Exqrnplea
(A is real, I and J are integers)
a)
A+I+J
I is converted to real and added to A, then J
is converted to real and added to the sum.
b)
A+(I+J)
I and J are added as integers converted to real
and added to A.
3-3
3.1.5
Standard Functions
The following standard functions are provided in ALGOL-S.
The argument must be a non-dimensioned real - variable except
the argument of REAL.
(e.g.:
Constants are
~~~.
allowed as arguments
YI=SIN (.5); is illegal, but PHI=.5;
Y:=SIN (PHI); is
legal) •
Square Root of x
Sine of x in radians
Cosine of x in radians
Arctangen t of x
Exponential of x
Logaritrud (natural) of x
Largest integer not greater than x
Converts integer I to a real number
1 for positive x
Integer [ 0 for zero x
-1 for negative x
Absolute value, or modulus of x
SQRT (x)
SIN (x)
COS (x)
ARCT (x)
EXP (x)
LN (x)
ENTlER (x)
REAL (I)
SIGN (x)
ABS
(x)
The program of figure 3-1 illustrates one use of functions
in ALGOL-S, to generate a listing of values.
A later example
(paragraph 5.3) uses functions to generate a table of values.
AI,GOL-S functions may be used within expressions and calculations
as well, as long as the argument of the function is a real variable
and not a constant.
2. ~c?'~~a..!L-~X£:~e~J.l,!.o~,s,
ALGOL-S programs may use the following Boolean operators to
form Boolean expressions.
'TRUE'
used to assign a logical value to a Boolean variable.
'FALSE'
used to assign a logical value to a Boolean variable.
'NOT'
used to negate a Boolean variable
'AND'
used to combine Boolean variables
'OR'
used to combine Boolean variables
'IMP'
implies - used to combine Boolean variables
'EQU'
equivalence - used to combine Boolean variables.
3-4
'BEGIN' 'COMMENT' FUNCTION COMPUTERJ
'REAL' A.. BJ 'I NTEGER' I)
SKIP)
START: READ Cl .. A»)SKIPJ
WRITE Cl .. "FOR A VALUE OF'" .. A)JSKIP;
WRITE <1 .. II
SINE
COSINE
B:= SINCA)J WRITE Cl .. B>J
B:= COSCA») WRITE Cl .. B»)
B:= ARCTCA)J WRITE Cl .. B)JSKIP)
WRITE 0 .. II
NAT LOG
EXPONENTIAL
B:=LNCA); WRITE Cl .. B);
B:=EXP CA») WRITE: Cl .. B),;
B:= SQRT CA)'; WRITE <1 .. B)JSKIP;
WRITE <1 .. "
INTEGER PART
REAL PART
WRITE (1 .. "
ABSOLUTE VALUE");SKIPJ
I:=ENTIER (A); WRITE (1 .. 1);
B:=REAL (I)J WRITE (1 .. " "
" .. B),;
B:=SIGN (A)J WRITE <1 .. B>J
B:=ABS (A); WRITE (I .. B);SKIP;SKIP;
'GOTO' START
'END'
ARCTANGE:NT"») SKIP;
SQR ROOT")JSKIP';
SIGN")J
.$
F'OR A VALUE OF'
SINE
0.100000 $-01
ARCTANGENT
COSINE
0.999982$-02
0.999949$+00
EXPONENTI AL
NAT LOG
-0.460516$+01
0.101004$+01
INTEGER PART
o
0.000000$+00
REAL PART
0.999965$-02
SQR ROOT
0.999999$-01
ABSOLUTE VALUE
SI GN
0. 100000 $+01
0.100000$-01
-12.5731
F"OR A VALUE OF"
SINE
-0.125731$+02
ARCTANGENT
COSINE
-0.672908$'-02
NAT LOG
0.999977$+00
EXPONENTI AL
0.253155$+01
INTEGER PART
-13
0.346395$-05
RE:AL PART
-0.129999$+02
-0.149142$+01
SQR ROOT
0.354585$+01
ABSOLUTE VALUE
SIGN
-0.100000 $+01
0.125731$+02
1.0$-610
F"OR A VALUE OF"
SINE
0.999961$-610
COSINE
0.309548 $- 563
NAT LOG
ARCTANGENT
0.999999$+00
EXPONENTI AL
-0.140457$+04
I NTEGE:R PA"RT
o
0.400000$+612
REAL PART
0.000000$+00
0.238813$-610
SQR ROOT
0.999980 $- 30 5
SIGN
0.100000 $+01
ABSOLUTE VALUE
0.999961$-610
3.141592
F"OR A VALUE OF"
SINE
0.314159$+01
COSINE
0.000000$+00
NAT LOG
EXPONENTI AL
0.114472$+01
INTEGER PART
3
ARCTANGENT
-0.999999 $+00
0.231406$+02
REAL PART
0.300000$+01
Figure 3-1
0.126262$+01
SQR ROOT
0.177245$+01
SIGN
0.100000$+01
ABSOLUTE VALUE
0.314159$+01
Function computerProqram
3-5
For all combinations of values for Boolean variables Bl
and B2, the following table gives the values of the above
combinations.
Bl
.=::::-=::::::::=-
B2
['NOT 'Bll Bl' AND'B2
~::::~:::~~,::-.:;;;::::.
-:,;:. :=~:-~_:::::::-
':.=:L':':::~: :::~,
::- ,:::-.:,::::-':"-
Bl' OR 'B2 Bl'IMP'B2
~
:'-; -:::'-'--;:, -:_: .: -~",:-
.::::::::::.:::,:::::;:':-::--.::_=-.::
Bl'EQU'B2
true
true
false
true
trlle
true
true
true
false
false
false
true
false
false
false
true
false
true
true
false
false
false
false
false
true
true
true
___fo~~~~.
b..?_~
Boolean expressions may be of the following formsl
a)
A single Boolean variable optionally preceded by
the basic symbol 'NOT'.
where Bl is declared Boolean
'NOT'Bl
b)
TWO Boolean variables connected by one of the four
logical operators ('AND', 'OR', 'IMP', or 'BQU').
B3.=Bl 'AND' B2;
B4.=Bl 'OR'
B3;
B5.=Bl 'DiP' B2;
B61=B4 'EQU' B21
where Bl, B2, B3, B4,
c)
as, and B6 are declared Booleans.
A relation comprising two simple integer arithmetic
expressions connected by one of the six relational
operators =, #, -,..=,
x+y+z>=
A:H:B
.£
=, >, or
It.. •
S
where A,B,X,y, and Z are integers.
3-6
d)
A relation compriS.ing two simple real arithmetic
expressions connected by one of the two relational
opera tors
L
or::> •
X+y+Z> 5
A~5+1
where A,B,X,Y, and Z may be integers
or real numbers.
A Boolean expression can be used directly in a conditional
statement or can be used to assign a logical value to a Boolean
variable as seen in the two following examples.
'IF' I-J>K 'THEN'
BII=I-J~
5*KJ
'GOTO'
STARTJ
'IF' BI 'THEN'
'GOTO'
STARTJ
In the second example above, BI is true when I-J £ 5*KJ.
false otherwise o
BI is
The GOTO statement is performed when BI is true.
l.!~;!~ .Lim!mJ.on~_c~
a)
There are no Boolean arrays in ALGOL-B.
b)
The multiple assignment of a Boolean expresston value
to a number of Boolean variables is not'allowed.
example, "Bl.=I>JJ
.. Bl. =B2 1=1> J
c)
J II
For
B2.=I>JJ" is acceptable while
is not acceptable.
The logical values 'TRUE' and 'FALSE' can be used only
to assign logical values to Boolean variables.
51. = •TRUE' J
is penni tted, while
I-J> K.= 'FALSE'
is not penllitted.
3-7
Chapter 4
DECLARATIONS
Declarations are used to specify the properties of quantities
used in an ALGOL-8 program and to associate these quantities with
identifiers.
Declarations must appear at the beginning of a
block (i.e. before any statements which cause operations to be
performed by the block).
hl~sV~A~}?.1~~.
Variables may be real numbers, integers or Boolean.
Multiple
variables of the same type may be declared in one statement by
separating the variables by commas and terminating the statement
by a semicolon.
Example.
'BEGIN'
'INTEGER' NJ
'REAL' A,B,CJ
'BOOLEAN' Bl,B2;
•
'END'
•
$
ALGOL-8 arrays may be either real arrays or integer arrays.
(The type of array, integer or real, must be declared also.)
lower bound of the array must be either
¢ or 1.
The
The upper bound
must be an unsigned integer or a simple integer variable, as seen
in the example below.
The bounds of the array are enclosed in
square brackets and separated by a colon.
4-1
Example a
'BEGIN'
'INTEGER' NJ
'REAL' 'ARRAY'
•
AX[l,lOl, AY~112] J
•
•
'BEI:;IN'
, INTEGER'
'ARRAY'
INTX [11 N] J
•
•
•
'END'
'END'
$
As illustrated in the preceding example, if the upper bound of
an array is an integer variable it must be declared and assigned
a value in a preceding block prior to its use as an array bound.
4·1 ......E.!!itches
Switches may be used in an ALGOL-8 program to conditionally
transfer control to other areas of the program.
established by the declaration 'SWITCH'.
The switch is
The switch is used to
conditionally transfer control with a GOTO statement·.
EXample.
'BEGIN'
'INTEGER' IJ
'SWITCH' CHANGEa=BPOS,BNEG,BZERO;
•
•
•
• GOTO ' CHANGE [I] J
BPOSlstatement pI,
Statement p2;
•
•
•
BNEGlstatement Nl;
Statement N2,
•
•
•
BZEROaStatement ZlJ
statement Z2J
•
•
•
'END •
$
4-2
The statements identified by the labels included in the switch
declaration are executed depending upon the value of I.
If 1=1,
the statements beginning with pl (labeled SPOS) are executed.
If 1=2, the statements beginning with Nl (labeled SNEG) are
executed.
If 1=3, the statements beginning with Z1 (labeled
BZERO) are executed.
The statements to which control is transferred may be simple
statements, compound statements or blocks.
If 1;/1,2, or 3, the statement 'GOTO' CHANGE Cr.]; is undefiilecl.
There are no usel" procedures in ALGOL-8.
4-3
Chapter 5
STATEMENTS
The units of operation within the language are called
statements.
Statements may be of the following typesl
1)
Assignment statements
2)
GOTO statements
3)
Conditional statements
4)
FOR statements
5)
DUmmy statements
~~~iqnrnent statemen~
An assignment statement relates a variable V to an arithmetic expression E by means of the symbol.=, as in the following
example.
VI= EJ
The al)ove statement means that the value of expression E replaces
the value of variable V.
Multiple assignment statements can be done when more than
one variable is to be given the value of the same expression.
You may write.
Vl.= V2.= V3.= E;
If the type of the variable (i.e. integer or real) is not the
same as the expression, the result of this expression will be
converted into the type of the variable.
5-1
~_2..,
__ Q.OTO..-.!.t:.~ t;ements
A GOTO statement may be of the following forms.
a)
'GOTO' IABELJ
b)
'OOTO' SWITCH [INDEX] J
where LABEL is used to reference a point in the ALGOL program
either within the block of the GOTO statement or in an outer
block, SWITCH is a declared switch designator, and INDEX must
be a simple integer variable or an unsigned integer.
Example I
, BEG IN ' , Cm.1r-1ENT' BLOCK l.
'INTEGER' I.
START I READ (1,1);
'BEGIN' 'COMMENT' BLOCK 2.
'SWITCH' POINT 1= LOOP, EXIT;
'GOTO' POINT [11.
LOOPIWRITE (l,"LOOPII)JSKIP;
'GOTO' START
'END' BLOCK 2;
EXITIWRITE (l,"EXIT");SKIP;
'END' BLOCK 1
$
In this example, 'GOTO' START leads from the inner block (2)
into the outer block (1) 'GOTO' POINT [I] is equivalent to
'GOTO' LOOP for 1=1, or 'GOTO' EXIT for 1=2.
If the value of
I is less than 1 or greater than 2, the 'GOTO' POINT [I]
statement is undefined.
hl-_
F01L!!1~t:~~~Ete!!t~.
The FOR statement is in the following fornll
'FOR' VI= A 'STEP' B 'UNTIL' C '00' S
where the controlled variable
V~ust
be a simple integer
variable, the elements A, B, and C can be in the following
forms I
5-2
a)
a signed (minus only) or unsigned integer
b)
a simple integer variable
and S is a statement
The FOR statement can be self-imbedded since the statement
S may itself be a FOR statement.
NOTE I
'BEGIN'
The 'WHILE' basic symbol of the ALGOL
language is not permitted in ALGOL-8.
Thus ALGOL-8 programs may not use
'WHILE t to terminate FOR statements.
'INTEGER' I,; 'REAL' F,R,C,S,;
WRITE (1,"
DEG
SIN
SKIP';SKIP';
F:=3.14159/180,;
'FOR' 1:=0 'STEP' 1121 'UNTIL' 9121
'BEGIN' R:=I*F,;
C:=COS(R)';
S:=SIN(R)';
COS"),;
'~O'
'END'
'END'
$
DEG
121
10
2121
30
40
5121
6121
70
80
90
Figure 5-1
SIN
COS
0.12100000$+0121
121.173648$+1210
121 .342(i)19$+00
0.499999$+00
0.642787$+121121 .
o .766043$+(10
121.86612124$+1210
0.939692$+0121
0.98481217$+121121
0.999999$+00
0.999999$+121121
o .9848121 7$ +00
0.939692$+0121
121.86612125$+00
121 .76612144$+00
0.642787$+121121
0.5121000121$+121121
0.342020$+121121
0.173648$+1210
0.953673$-06
A FOR statement used in a
5-3
Progr~m
5.4._"_condition~.!:~e~~
A conditional statement may be of the following formsl
a)
'IF' B1 'THEN' Sl
b)
'IF' B1 'THEN I Sl 'EISEl S
c)
'IFI B1 'THEN' S2
where B1 is a Boolean expression of one of the forms given in
chapter 3.
Sl is an unconditional statement, S2 is a FOR statement,
S is a statement.
The conditional statement can be self-embedded since the
statement s may itself be a conditional statement.
The embedding levels of FOR statements and conditional
statements are interdependent (controlled by the same stack).
The total number of conditional and FOR statements that can be
accommodated at one time is 18.
'BEGIN'
'COMMENT' CONDITIONAL DEMO;
'INTEGER'I,J;
START:READ (l,I,J);
'IF'I>J 'THEN'WRITE (l,"FIRST NUMBER IS GREATER.");
'IF'I<J 'THEN' l-JRITE <l,"SECOND NUMBER IS GREATER.") 'ELSE'
WRITE <l,"THEY ARE EQUAL.");
'GOTO' START;
'END'
$
Figure 5-2
A Conditional Statement used in a Program
5-4
~._.Dummy
statements
A dummy statement produces no executable code.
It may
be used to place a label.
The dummy statement is allowed just before the baSic symbol
lEND' to label it or to end the last statement of a compound
statement or a block, by a semicolon.
Example.
'BEGIN'
'REALI A,B,
'INTEGER' I,J.
READ (l,A,I)J
•
I
lEND'
BEGIN ,
lIP' I=J 'THEN I 'GOTO I EXIT;
•
•
•
B.=A*A*A;
~~~~: ~-------.------~oummy statements
In this example, there are dummy statements before each baSic
symbol 'END'.
and
The semicolon after "B.=A*A*A" is unnecessary
is considered a dummy statement.
The last baSic symbol
'END' is labeled by the dummy statement EXIT •
.2..-Ji",~...£Qmmen>~~
Comments are added to ALGOL-8 programs for the userls
convenience.
They may be used to identify the function of
statements, blocks, etc., w:tthin anALGOL-8 program.
duce no
executab~e
code.
There are two fonas of comments.
5-5
They pro-
a)
Comments may be introduced between declarations
or statements by using the basic symbol 'COMMENT'.
These comments may have any length and may contain
all characters except the semicolon, which necessarily stops
the comment.
b)
Comments may be introduced after the basic symbol
'END' without using the symbol 'COHMENT'.
These comments are ended by one of the following
three basic symbolsl
J ,
'END'
or I ELSE ,
or the dollar sign at the end of t.he program.
The comment length is also unlimited but, in addition to
the semicolon, the single quote is not an allowed
charac~er.
(it serves to form the basic symbol 'END I or IELSEI which
stops the comment).
Example.
'BEGIN'
'COMMENT' TEST DYNAMIC ARRAY;
'INTEGER'I,J,K;
READ (l,I,J);
'COMMENT' C~LCULATION OF SIZE;
K:I+J;
'BEGI N' 'COMMENT' K I S USED t\,S THE;
'COMMENT' UPPER BOUND OF THE ARRAY;
'ARRAY' TABLE [0:K];
'FOR' J:=O! 'STEP' 1 'UNTIL' K '00'
'END' BLOCK 2
'END' TEST;
$
The semicolon which stops the cownent following the last
basic symbol 'ENDI of the program is optional.
5-6
5 • ~_. sample program
The following sample program illustrates all of the
statements introduced in this chapter.
The program is designed
to plot linear, quadratic, and cubic equations.
A switch is
used to handle the three different cases.
A conditional statement with Boolean variables is used to
determine that the equation can be plotted by the program, i.e.
it is linear, quadratic, or cubic.
A FOR statement controls
the number of executions of the block which plots the equation.
I vJILL PLOT YOlJk [£QIJATION FROM X=-10 TO X=10.
WHAT IS THE HIGHEST POWER OF Xl
3
I'LL PLOT YOUR CUBIC EQUATION!
vJHAT IS THE COEFFICIENT OF X CURED
f?) •
?
I
hlHAT IS THE COEFF'I ClENT OF
X
SQUARED
?
01.5
WHAT IS THE COEFFICIENT OF
X?
-5.
WHAT IS THE CONSTANT TERM?
-2.
-30
-20
-I~
~
I~
21il
301
f
f
f
f
f
f
f
-10
*
-9
-8
*
*
-7
*
*
*
-6
-5
-4
-3
-2
- I
0
I
2
3
*
*
4
5
*
*
*
*
6
7
8
9
10
Figure 5-3
Sample Program OUtput
5-7
*
*
*
*
*
*
*
*
*
'BEGIN'
'COMMENT' PLOt PROGRAMJ
'INTEGER' XHIGH~ XJ
'REAL'Al~A2~A3~BJ
'BOOLEAN'HIGH~LOWJ
'SWITCH'CONTROL:=LIN~QUAD~CUBIC;SKIP;
WRITE <1~"I WILL PLOT YOUR EQUATION fROM X=-10 TO X=10.")J SKIP;
ASK: WRITE <1~"WHAT IS THE HIGHEST POWER Of X?")JSKIPJ
READ (I~XHIGH)JSKIPJ
HIGH:=XHIGH>3J LOW:=XHIGH<I;
'If'HIGH 'OR' LOW 'THEN'
'8EqIN'
WRITE (1~"I 'M SORRY~ I'M NOT SMART ENOUGH TO ")JSKIP;
WRITE <1~"?LOT"~ XHIGH~"TH DEGREE EQUATIONS!")JSKIPJ
WRITE C1~"WOULD YOU LIKE TO TRY AGAIN?")JSKIPJ
'GOTO' ASKJ
'END'
'ELSE' 'GOTO'CONTROL [XHIGHJ;
LIN: WRITE (1~ "I'LL PLOT YOUR LINEAR EQUATION fOR YOU!")JSKIP;
A2:=A3:=0.0J
'GOTO' ONE;
QUAD: WRITE <1~"1 'LL PLOT YOUR QUADRATIC EQUATION fOR YOU")JSKIPJ
A3:=0.0J
, GOTO' TWO;
CUBIC:WRITE (1~ "I'LL PLOT YOUR CUBIC EQUATION!")JSKIP;
WRITE (1,,"WHAT IS THE COEffICIENT Of X CUBED ?");SKIPJ
READ (1" A3);SKIPJ
.
TWO: WRITE (1" "WHAT IS THE COEffICIENT Of X SQUARED ?")JSKIPJ
READ (1" A2);SKIP;
ONE: WRITE<1,,"WHAT IS THE COEffICIENT Of X?");SKIP;
READ (I"Al);SKIPJ
WRITE (1,,"WHAT IS THE CONSTANT TERM?");SKIP;
READ (1" B);
GRAPH: SKIPJSKIPJSKIPJ
WRITE (1,,"
-30
-20
-10
0");
WRITE <1,,"
10
20
30");SKJPJ
WRITE (1,,"
t
t
t
t")J
WRITE (1,,"
t
t
t");SKIPJ
'fOR'X:=-l0 'STEP'l 'UNTIL'l0 'DO'
'BEGIN"COMMENT' PLOT BLOCK (NO. SPACES TO ORIGIN=34);
'INTEGER' V"PLOT;
'REAL' CONST;
'BOOLEAN' 81,,82;
WRI TE (1 ~ X) J
CONST:=X*X*X*A3+X*X*A2+X*Al+8+34;
PLOT:=ENTIER (CONST);
Bl:=PLOT<2J B2:=PLOT>65J
' I f ' 81 'THEN' 'GOTO' POINT'ELSE'
'If'
82 'THEN'PLOT:=66;
'fOR'V:=1 'STEP'} 'UNTIL'PLOT 'DO'WRITE (l,," ")J
POINT:WRITE (1,,"*");SKIPJ
'END'
SKIPJSKIP;SKIP; 'GOTO'ASK
'END'
$
Figure 5-4
sample ALGOL-8 Program
5-8
Chapter 6
INPUT/OUTPUT STATEMENTS
ALGOL-B programs may use ei"ther the ASR-33 Teletype or a
high speed paper tape reader/punch as an input/output device.
~._l
I/O statement Form
Input/output statements in ALGOL-8 are of the form.
Function (Unit, Variable List)
where
unit
= READ or WRITE
= 1 (ASR-33 Teletype)
variable List
= One
Function
reader/punch) •
or 2 (high speed
or more simple or subscripted
variables, separated by commas.
Example.
'BEGIN'
, INTEGER' S J ' INTEGER I IARRAY I A [11 1$!1] J
•
•
•
'FOR' Sa=l ISTEpll IUNTIL' 10 100'
READ (2, A[S]) J
•
•
•
'END I
The above READ statement means that the 10 values of the
integer array A will be read from paper tape on the high speed
reader.
The ALGOL-8 program which executes this statement will
advance the paper tape and accept the values of these 10
variables in the USA-SCIl code.
6-1
h.L-2U~'!t Form~
There are no ALGOL-8
fo~at
statements.
The output formats
for integers and real numbers are as follows.
Integers - space, sign and up to 4 digits.
e.g.
-1234
Real numbers - 2 spaces, sign (if negative), _,decimal
point, 6 digits, $, sign, 2 or 3 digits
-~.123456$+_7
e.g.
§"d._~*npJ!!:.L~at:
The input fonnat for ALGOL-8 programs is free form (a number.
may be typed in any form as long as it does not exceed the range
of the variable type).
Input to the operating system may be in
parity or non-parity USASCII format (paper tape or keyboard
initiated).
ignored.
Blank tape, rubout and line-feed characters are
Spaces are also ignored except in text strings (see 6.4
Text output).
Input of data to the operating system in response to a
READ procedure statement may be terminated by any character which
is not a
numbe~
the exponent).
sign, decimal point or dollar sign (indicating
A ...... (SHIFT/O) typed
~_~~E~.,
a tenninator deletes
':.he item being input.
Alphanumeric characters included within double quotes may
be elements of the variable list of a WRITE statement.
The
WRITE statement will type all characters which are included in
the double quotes.
Thus the·WRITE statement may output text
6-2
or format data by supplying spaces within quotes.
Example.
WRITE (1, "X= ", X,
II
XPRIME= .. , XP) J
&,!2_. New Line
The output of text and data may be formatted on separate
lines by the SKIP statement, which causes the Teletype carriage
to be returned and a new line of output supplied.
The following
example prints the values of X, y, and Z under their respective
headings.
Example.
WRITE (1, II X
Y
SKIP;
WRITE (1 , X, y, 8)J
6-3
Chapter 7
DIAGNOSTICS
.I.!.!..._,~2!!l.Eile
,.!.ime
9-J:~9:!l0illcS
Whenever an error is detected during the compilation of an
ALGOL-8 program, the compiler prints an error message.
After this detection, no recovery is possible.
The user
must correct the error, reinitialize the compiler, and restart.
An error message is printed as follows.
xx
yy
zz
xx is the diagnostics code, yy is the line number where the error
has been detected and zz is the character number in this line.
Generally, line numbers and character numbers will quickly
detenuine the origin of an error.
di§gQy~a
But it happens that the
of an error may occur after the latter.
For example, in
the following linea
'BEGIN'
'INTEGER I, J, K,;
'REAL' A, B, CJ
A quote is missing after INTEGER but it would not be found before
the detection of a second quote after REAL.
Thus the character
number would indicate an error after REAL, rather than the actual
ey-ror after INTEGER.
The following is a list of the error codes typed by ALGOL
during compilation.
¢
Lon~~~Cts !_9__ §iT:~9.!_~r;-.9!:
*The first single quote of a long basic symbol is not found.
*The long basic symbol is not found.
7-1
1
Identif~~~Q~
*An identifier is not declared in a statement.
*An identifier does not begin with a letter.
*A left bracket is omitted in a subscript variable of a
statement.
2
Dec~2:!,~~!.qt:l.J~!:ror
*A declaration is not ended by a semicolon.
*The long basic symbol 'REALI or I INTEGER I is followed by
a long basic symbol other than 'ARRAyl.
*The program contains a Boolean array declaration which
is not allowed in ALGOL-8.
*A left bracket or a right bracket is omitted in an array
declaration.
*The colon separating the lower and upper bounds is
omitted.
*The upper bound is an integer variable which is declared
in the same block of the array identifier.
*The lower bound is neither ¢ nor 1.
*The same identifier is declared more than once in the
same block.
4
~~!:Cl<!:~!!:l~nt_ ~X~9£
*The long basic symbol beginning a statement is not one
of these following long basic symbols.
I BEGIN
IIF.'t
IFOR I
I GOTO I
IENDI
I,
(compound statement or block)
(conditional statement
(for statement)
(go to statement)
(dummy statement)
7-2
*The input-output procedure statement READ, WRITE, or
SKIP is not found.
*A conditional statement is found just after the long basic
symbol 'THEN'.
*The statement following the long basic symbol 'ELSE' does
not correspond with the unconditional statement following
the long basic syrrmol 'THEN'.
5
Statel!!~!-~_.~EE9!:
*A statement is not ended by one of the following basic
symbols 1
Either
6
J
or 'END'
or'ELSE'
C9.!.Q~ . .e,l?·~(~t.~~l.~__ ~ i.SL~.. ~f.J:S?X
*The colon and equals sign representing the basic symbol
1=
are omitted in the following casesl
*In a switch declaration, after the switch identifier.
*In a FOR statement, after the controlled variable.
7
!!lde'!..~f.;-2..;.
*In an array declaration, the upper bound is neither an
integer variable nor an unsigned integer a
*In a statement, a subscript .Ls n€!ither an integer variable
nor an unsigned integer.
*In a GOTO statement with a switch designator, the subscript
is neither an integer variable nor an unsigned integer.
*A right
br~"'.cket
is omitted after the subscript.
*In a FOR statement, the controlled variable is not an
integer variable.
7-3
*In a FOR statement, the initial value, the step value or
the final value is neither an integer variable nor a signed
(minus only) or unsigned integer.
8
Consta~_9.ut,~.!-<1~_R~nSL~.
*The value of an unsigned integer is grea.ter than 2040
when used explicitly as an ALGOL-8 program constant.
*The integer part of a real number is greater than 2040
when used explicitly as an ALGOL-8 program constant.
9
~iml?~ogl~~~!LJL~E.!'~.ssion
Error
*One of the simple arithmetic expressions of a relation
is not an integer type.
*In a Boolean aSSignment statement, the long basic symbol
beginning the Boolean expreSSion is not one of the
following.
'TRUE',
'FALSE',
or
'NOT'
*The variable following a logical operator ('NOT', 'AND',
'ORI, lIMP', 'EQU') is not a Boolean variable.
*In a relation, a relational operator is omitted.
10
GOTQ....~.~~ill~}·~!:_ E:';-.~£;:.
*The identifier following the long baSic symbol I GOTO I
is neither a label nor a switch identifier.
*Labels referenced by the program remain undefined at the
end of the program.
11
BEG1!L~,:,~~NJ:).J~!!,!9";:.
*There are too many long basic symbols lEND'.
Each
I BEGIN I must be paired with an IENDI.
12
~~c::J.-tt 9"y'~!.Q~L.~.:r;E2£
*One of the limitations described in Appendix B is exceeded.
7-4
*More than 18 conditional and FOR statements were in use
at one time in the user program.
*The arithmetic expression being compiled is too complex
for ALGOL-8 (stack overflow).
13
ASS~l'!!!!.~!lt St~,t~m~l!t~_.~;-F2r.
*The assignment operator (1=) is found in the middle of
an arithmetic expression.
*The equals sign is not found after a colon in a multiple
assignment statement.
14
Be~~1?§r.._E~f.t;pr.
*The exponent of a real number is not properly written.
15
Rea.~L.2F~~J:"i ~~. . . E~.!,.of.
*The procedure statement with parameters is neither READ
nor WRITE.
*The first parameter of READ or WRITE is neither 1 nor 2.
*A comma which separates parameters is omitted.
*One of the READ parameters is not an identifier.
*One of the WRITE parameters is neither an identifier nor
a character string enclosed between double quotes.
*The identifier parameter of a READ or WRITE procedure
statement is neither real nor integer.
*A left bracket is omitted in a subscripted variable.
*The right parenthesis which ends the READ or WRITE procedure
statement is omitted.
*An operator is missing between two operands.
*Two operands are found consecutively.
*The number of left parentheses 1s not equal to the number
7-5
of right parentheses in an arithmetic expression.
18
standard
FUnc~ion A~tivation ~r!£E
*The parameter of the standard function is not a simple
variable.
*The left or right parenthesis is missing.
*The parameter is not a real number except for the
function REAL.
7 • ~,,_. Execu.t i £p._...1'.~~_.Di a.sLI1.os tic s.
Errors detected at the time of program execution in ALGOL-8
cause the following error message on the Teletype printer.
OPS
n
The error codes (n) are given below.
When an error condition is
encountered at execution time, the ALGOL-8 program will halt.
If recoveJ:Y is possible (as noted below), the user may press the·
CONT switch of the computer console and the program will resume
execution.
7-6. ..
Error
Code
Condition
Recovery
1
user array size exceeds the available space.
No recovery
possible.
2
Division by zero has been attempted
in the user program
Division is
performed •.
3
Integer input outside acceptable
range
Input ignored.
4
Attempt to convert a real number
to an integer which is outside the
acceptable integer range.
The real number
is converted to
zero
5
Attempt to take square root of a
negative n~~b~r.
square root is
taken of the
modulus.
6
Attempt to take logarithm of a
negative number.
Logarithm is
taken of the
modulus.
7
Switch index in users program is
undefined.
Index is taken
as 1.
8
Users program demands functions
which have not been loaded.
No recovery
possible.
7-7
Chapter 8
OPERATING INSTRUCTIONS
8 !.J-_, C0n:t.£!..t~F
The compiler consists of 2 paper tapes ALGOL Compiler
DEC-08-KALA-PB
ALGOL Compiler Reinitialization
DEC-08-KA2A-PB
The compiler will only run in Field
program interrupt facility.
%,
since it uses the
The compiler must be reini t1?lized
with the second tape, after each compilation, before another
compilation is attempted.
,§.!_~,.J_.~._9E~r,CI:~ i o~
The operation of the compiler is given in the following
steps which are summarized in the accompanying flow chart
(figure 8-1).
a.
load compiler with binary loader
b.
load address 400 and start
c.
the program types OPT The options are,
R - Input/OUtput on high speed reader/punch
T - Input/OUtput on low speed reader/punch
d.
place the source program in the appropriate reader,
turn on the appropriate punch and type R or T.
e.
start Low Speed Teletype reader (if T has been typed)
f.
the program halts at loc. 262 after compilation is
complete
g.
error messages are typed on the Teletype console and
the program halts at loc. 3142.
h.
re-initialize the compiler if a further compilation
8-1
·~.~
STO.P
_.-,
G.
Load-""-.=----~:J_·
.
.,._,
ALGOL-8 Compil er
·---"1"'"··. ·-««·--
'-
_. -
ii
th~'BI;~ay
Loader - Loa
i~~~!.~d ~
0-'-"~1D~;-r-e-s-'s-s~-~-,}----[s~_~-~to_~~~]
[~~~:='::L;A;-~~~'-j
G:rn:~:-~~~::l
[D~p~e~s_~:~~~]
High-Speed Reader
Low-Speed Reader
[;u~-;ou:S:;~;~~:~=I----- -. ..- <-[~p~~~;~~~~-;~~e-~~L~;l
-'[;~:r~--'~'-r- - - -..
-~~p~es~I~::~~ ~;::I--
r
.
..
.... - ... - ""-'-"-'-"" ---- '1
-,--~--,--
No
Figure 8-1 Compiling an ALGOL-8
program
,.."'_"_"-'
_..____ . _.__L~:~:~J_S:-~~Tl
8-2
-=~~.,.,,~-.,~
~~:-d' c~~~~~e~_____ JWith Binary j
~
ALGOL-8 Program
-.".------~-
-.".<.~-,.
Loader
~--- .......
-.,-,,---....
High-Speed
Reader
Yes
.. _._... _ .. _...
""'1
Set SR=3400
____
~.
~,~-_
-_~._~_'L."_
0_
,~~"""",
No
NO
!
Yes
['T~a'pe ~'s top s
[. . I I
Load FUnction J
"oadereerlay
Hi9h-Spr_d_~~..._. . . h -
Low=St'~~d .!'.~~I
C
...
CDep;ess nSFi
Coep-re::
~s;~;1
-. -- ---[s"et -~·~=0400.r.- -__.________
NOTE:
The function loader and functions
must be used \'lhenever an ALGOL-8
program uses the povler (t) operator or any of the standard functions, SIN, COS, ARCT, LN, EXP,
and SQRT.
[DepreSS;;~~-~DD· J
[DeEr~.ss~~~-TARi]
ou.·.t.p~.t i. ·; -
[ of
....
Resu..1.
~
ALGOLr_;.Q.9l:~1'.!L_
~/
.'.1
1
. "-....
Yes
~~-.
Figure 8-2
Running an ALGOL-8 Program.
8-3
. e_ _
is
by loading the second tape with the
re~~ired,
Binary Loader •
.~.!.!!}_,J:1~1!Q!,Y~ q!c:q~
The compiler uses all memory locations from
double input buffer is at loc.
The
and the single output buffer
74~~.
is at
8.2
4~~
~-7577.
Operating
System
..,. .....
---'-""~""~---"--'-<:-~"""-'--""'->"",-.-
~-
There are 3 tapes which makeup the ALGOL-8 operating system
ALGOL OPERATING
DEC-08-KA3A-PB
SYSTItM
ALGOL OPERATING SYSTEM, FUNCTION LOADER
AND FUNCTIONS
DEC-08-KA4A-PB
ALGOL FUNCTION LOADER OVERLAY
DEC-08-KASA-PB
The system is based on the fleating point package (DEC-8-S-S).
It will run in any memory field, but will not use more than one
field.
The standard functions (SIN, COS, ARCT, LN, EXP, and SQRT)
are loaded only if they are required by the compiled program.
They must be loaded if the program calls them explicitly or if
the exponentiation
(+ ) operator
is used.
There are two alternative operating proceduresl
.§~,~~~!",~Qp~ra,tion,= N~_, F'uncJ:~(),n_?_~~~A:t:'~_g.
a.
Load compiler output with Binary Loader.
b.
Load Operating System (KA3A-PB) with Binary Loader.
c.
Input data must be in the appropriate reader if
required and, if punched output is reqUired, the
appropriate punch must be on.
8-4
d.
Load address 400 and start.
e.
The program may be restarted at location 400.
!!.!_2 •.2_._.QE~z:atio!1 -
Functi()p':sR~gul~,ec;
a.
Load compiler output with Binary Loader.
b.
Load Operating System, Function Loader and FunctiQns
(KA4A-PB) with Binary Loader.
c.
The Binary Loader loads the operating system and the
Function Loader.
The tape will stop before the
functions are loaded.
d.
TO load the functions, load address 7400, set bit
~
for appropriate reader (as in the Binary Loader) and
start.
e.
The necessary functions will be loaded and the reader
will halt at location 7424.
(A checksum error will
cause the loader to halt at location 7511 with the
checksum difference in the AC.)
The reader will load
only the needed functions and, in general, the reader
will halt with the function tape only partly read.
f.
Load the Function Loader overlay (KA5A-PB) with the
Binary Loader.
g.
Go to stop c of paragraph 8.2.1.
8 ,.?,!.~ ,!1.9!ll0.ry. usage,
The Operating System uses locations 0-377 and 4600-7577.
FUnctions are loaded by page, downwards (towards G) from
location 4600.
The compiled program is loaded from 400 upwards.
The pages
between the compiled program and the functions (or location 4600,
if no functions are required) are'used for array storage.
8-5
8 !.?._>Y~!,,~,!~J)~~,.!!lPY:.!:~..fprm~ 'to
Input to the compiler and data input to the operating system
may be in parity or nun-parity ASCII fonaat paper tape.
tape, rubout and line-feed characters are ignored.
Blank
Spaces are
ignored except in text strings.
8 !l..!1>~... Co~_~.!;_.!P'P~~.
A source program must be terminated by a $, which must be
the first character of a line, followed by a carriage return.
8 •.c~,!..2_'7. QE~r~t.:f,!lE__ §y~!:-eI1l.Inpu 1:,
Input of a data item to the operating system i.e. by a RMD
procedure statement is terminated by any character which is not
a number, sign, decimal pOint or $ (indicating the exponent).
8-6
APPENDIX A
ALGOL-8 BASIC SYMBOLS
r----------r----.----_.--.
-------.------,.------~---
Long
Basic Symbols
Short
Corresponding
ALGOL-8
Representation
Basic Symbols
Corresponding
ALGOL-8
Representation
+
+
'REJ!oL'
x
*
i~t:~c;f.e_r
'INTEGER'
/
/
boolean
-----... --
'BOOLEAN'
t
t
arE~X
'ARRAY'
:!:
=
switch
-.. . --.. .
if
'Sl'7ITCH'
:/
#
'IF'
<
<
then
'THEN'
>
>
else
'ELSE'
~
for
'FOR'
st.~.E.
'STEP'
until
-. ..
'UNTIL'
do
'DO'
go.!~.
'GOTO'
begi~_
'BEGIN'
end
'END'
real
"~
~
~>-
-~
comment
'COMMENT'
true
'TRUE'
-~--"'.--.~.-
=
=
<
>
~
,
;
:=
:=
---~.-
false
--..---- .•.•.._--- .._--_., -
Power of 10
(
(
'FALSE'
...
-
A-I
$
..
""'~
- . ---................ -~
_._0
APPENDIX A
(cont'd)
ALGOL-8 BASIC SYMBOLS
Long
Basic Symbols
Corresponding
ALGOL-8
Representation
Short
Basic Symbols
Correspondinq
ALGOL-8
Representation
'NOT'
)
)
1\
'AND'
[
[
V
'OR'
]
~
'IMP'
,J
--
'EQU'
---
It
It
*NOTE
Shift K= C
Shift M=J
A-2
APPENDIX B
RESTRICTIONS
Limitations of the
Lan~~age
1.
There are no user procedures.
2.
There are no Boolean arrays.
3.
An integer or real array must be one dimensional.
The lower bound must be either the digit
~
or the
digit 1.
The upper bound must be a simple integer variable
or an unsigned integer.
4.
The subscript of an array variable or of a switch
designator must be a simple integer variable or' an
unsigned integer.
5.
Variable identifiers are differentiated by the first
four
6.
alphanum~ric
characters only.
A switch list must be a label list, the labels of which
must be declared in the same block in which the switch
declaration appears, or in an outer block.
7.
The
~hile.
long basic symbol is not recognized.
Limitations of Program Size and Form
1.
50 identifiers simultaneously valid.
Identifiers are
defined as simple variables, subscripted variables,
switch designators and declared labels.
2.
10 arrays (real or integer).
3.
7 nested blocks
4.
18 undeclared labels.
a
Undeclared labels are those labels
whose declaration occurs in the same block after their usc,
or in an outer block.
Hence, labels of a switch list
undeclared labels.
a-I
ar~
APPENDDC C
TABLE OF ERRORS
o
Long basic symbol error
1
Identifier Error
2
Declaration Error
3
11U1tip1e Declaration error
4
Statement error
5
statement end error
6
Colon and equals sign error
7
Index error
8
Constant outside range
9
Simple Boolean expression error
statement error
10
G·OTO
11
Begin-End error
12
capacity overflow error
13
Assignment statement error
14
Real number error
15
Read or write error
16
Arithmetic expression error
17
parenthesis number error
18
Standard function error
C-l
APPENDIX D
OF COMHANDS
SUlIl1ARY
Opening statement parenthesis -
'BEGn~1
used to start a program, compound
statement or block.
closing statement parenthesis -
'END'
llSec1 to terr:-.inate a prot;;raj'l,
compound
stab~~ent
or block.
Real number variable declaraticn -
'REAL' A,B,C;
used to identify the real nl.llilber
variables used within a program
or block; in this case A, Band C
ar~
real variables.
Integ~r
'INTEGER' I, J , K;
variable declaration -
used to identify the integer variables
used within a program or block;
this case I,
J
in
and K are integer
variables.
'BOOLEAN' BI, B2;
Boolean variable declaration used to identify the Boolean variables
used within a program or block.
this case Bl and B2 are Boolean
variables.
'ARRAY' A [1110]
I
B (.~IN]
;
Array declaration used to specify the arrays used
within a program or block.
D-1
This
In
symbol should be prececled by
'INTEGER' or 'REAL' to identify
the t-ype of array.
In ALGOL-S, the
lower limit must be , or 1, and the
upper limit must be an unsigned
integer (e.g. 10, above) or a
simple integer variable (e.g. N,
above) 0
Only one-dimensional
arrays are allowed in ALGOL-8.
'SWITCH' SI=Ll, S2,STOPJ
switch declaration used with 'GOTO' S [I) to branch
an ALGOL-S program, based on the
value of an integer index, I.
The
index I may be an expresSion but its
values must range from 1 upward.
In
the example given, the possible
values for I must be 1, 2 and 3.
'GOTO'
LJ
GCTO statement specifies that the statement to
be
executed next is the one identified
by the label L.
(L is an identifier
which is separated from the statement
which it precedes by a colono)
'COMMENT' TEXT.
Comment statement
provides a means of including
comments in a program to identify
D -2
parts and to clarify procedures.
All characters typed after the
'COMMENT' and before the semicolon
are included in the program listing.
They are not typed during the running
of a program.
IF statement R is a relation, such as
X~
y+5,
S is a statement, such as IGOTO'
BIG,.
If the relation R is true, the statement S will be executed.
If the
relation R is false, S is Skipped and
the next statement in sequence is
executed. . S may be a compound statement, bracketed by 'BEGIN' and 'END'.
'IF'
R tTHEN' Sl 'EISE' S2
J
Conditional statement if relation R is true, statement Sl
is executed and S2 is Skipped; if
R is false statement Sl is Skipped
and S2 is executed.
S1 must not be
a conditional statement, however, S2
may be conditional, thus establishing
nested conditional statementso
tFOR' VIa= AI, A2, A3 '00 1 Sl,
FOR statementstatement S1 is executed repeatedly
with the controlled variable VI
taking on each of the values of AI,
A2, and A3.
For example, Sl could
be a block to compute the sine of an
D -3
angle VI, where AI, A2,
and A3 are the desired
values of VI.
'FOR'Vll=Xl 'STEP'X2 'UNrIL'X3 'DO'Sl;
Step-until statement statement Sl is executed
repeatedly with the control
variable VI taking on
values of Xl initially, and
increasing to X3 by adding
on the increment X2.
For
example, if 81 computes the
sine of an angle, Xl
(initial) could be
¢ degrees,
X2· (increment) could be 10
degrees, X3 (final) could
be 90 degrees.
D-4
APPENDIX E
NOTES ON ALGOL
COMPILER
The ALGOL-8 compiler is analyzed with emphasis on the implementation, performance,
and error diagnosis.
(1) The ALGOL-8 compiler will halt with every syntex error and does not continue to scan
the rest of the source. This is typical of many ALGOL compilers.
(2) After each compilation load the first part of RE-INIT to type out the symbol table and
load the second part of "RE-INIT to reinitialize the compiler. This is only necessary if
the identifier printout is desired.
(3) Error diagnosis performed by the compiler is fairly good with the exception that the
message typed out may sometimes appear vague and as a result becomes unclear, each error
code covers many different messages. This results from the complexity of the programming
language and the obi Iity of the program to be contained in 4K.
The fol lowing observations were made during compilation time.
(1) Boolean expressions must be written as specified in section 3.2.1 of the manual
(2) I/O of Boolean identifiers and mixed mode constructions with Boolean mode identifiers
are not allowed . .
(3) All "END" statements .!!l.tJ..sL be terminated by (;).
(4) The following refers to dummy statements.
'BEGIN '
'BEGIN '
1= J'THEN ' 'GOTO ' EXIT;
IIF'
'END'
EXIT:
'END'
$
The above situation will always cause BAD IGOTO I error message, because 'EXIT ' is
outside the block where 'GOTO ' statement tries to link.
E-1
The correct form is as fotlows:
'BEGIN '
'IF' I=J 'TH,EN "GOTO ' EXIT;
EXIT:
'END'
(5) With regards to "GOTO" statement by referencing' ALGOL-8 Manual page 5-2,
Section 5.2 GOTO examples have shown different result.
GOTO example 1
O. K~
GOTO example 2
error 10 during compilation
refer to the attached sheet.
OPERATING SYSTEM
(1) DOT (.)- is not allowed for integer input. It does not give any error message but simply
treats it as a nu II data.
(2) WRITE (1, "I NPUT-.J wu u u U LJ COSINE"); SKIP; will occasionally print out as:
INPUTCOSINE. The seven spaces between the two words are not printed out.
(3) In the statement 'FOR ' V: = 1 I •••• IUNTILI N 1001
if N has value a of 0 or a negative number, all the statements within the range of 1001 will be
ignored, but no error message will appear.
(4) "VARIABLE ARRAY" program is attached for reference, because the "WRITE"
statement under the control of "FOR II yie Ids on Iy 1 line resu It so that most of them will
not be readable. The resu It is also attached.
ALGOL Functions including both Basic and Standard.
(1) "E~IIER" function testresult~ ore attached at the end of this section.
(2) Boolean operator ~~!>I does not function properly at all times for example:
T = true
F = false
Correct
T IANDI T.... T
T 'AND' F-+T
Wrong, should be F
Wrong, should be F
F IAND' F....r
, Refer to results of Boole 1A & 2A.
E-2
(3) SINE function:
let x;arg~men-t-'
.001 < x < .05
Then error E for all the arguments in the range above is .0000001
3/50 yields 5-digit accuracy.
47/50 yields 6-digit accuracy.
< E < .00001
The range for argument x where .001 < x < .025 almost half have 6-digit accuracy and the
other hal f have 5-digit accuracy with--. 000001 as error. For other arguments of other ranges, the perctage which guarantees 6-digit accuracy improves
and the error is seldom greater than .000001 •
The range for argument x where .001 < x < .025 few had an error of -.000001 and
guarantee of 6-digit accuracy is given. (~)
Exponential function:
The
for the argument x where 0 < x < 14 produced excellent results with the
following exceptions:
ef9. yields 8103.07 instead of 8103.08 The error is -.01.
range
e1'11. yields 59873.9 instead of 59874.1 with error 1.2.
et13 yields 442412. instead of 442413. with error -1.0.
(7) ASS function operates accurate Iy.
(8) ~Cltural log function;
The range of the argument x where 1. < x < 1.030. One sixth yield 6-digit -accuracy,
whereas most of them yield only 5-digTt aZcuracy and one tenth yield approximately 4-digit
accuracy.
The range of argument where 1 • .::: x,::: 40. All results have a 6-digit accuracy.
E=3
USERS ' MANUAL CHANGES
(1) Page 1-2. 'INTEGER ' SUM: (colon should be changed to semicolon after sum).
(2) Page 1-8. 'FOR ' E 'STEP' I 'UNTlL ' F IDOls. It would be much better and less
confusing if A semicolon (;) is inserted after S.
(3) Page 3-3. Division (I) is considered as Real Operator. (Integer division is
allowed. )
(4) Page 4-1. Chapter 4. All declarat.ion statements should be listed before their
explanation, because all declaration statements must appear at the beginning of
a block.
(5) Page 5-2.
Section 5.3
Treat 'FOR ' V:
= A ....
as 2.
(6) Page 5-4. The total number of conditional and FOR statements that can be
accommodated at one time is eighteen.
This parti cu lar combination is not tested.
However, its equivalent:
'IF' . . . 'THEN' . • . . 'ELSE ' was tested and it can accommodate at one time 9.
(7) Page 5-5. Section 5.5
B:
= A*A*A;
is a dummy statement.
(8) Page 5-6. In the example:
K: I + J; shou Id be K:
= I + J;
(9) Appendix B: At no time can a single" ALGOL program contain more than 1.0 (TEN) different
dimensioned variables.
Ex:
A (1 :N), B(l :N) . . • .
E-4
VARIABLE ARRAY
'BEGIN'
'COMMENT' ARRARY STATEMENT TEST;
'INTEGER' N, V;
'REAL' 'ARRAY' AXel :N!BXC1 :NJ;
WRITE (1, "TEST FOR ARRAY STATEMENT") iSKIP;
WRITE (1, "TYPE A NUMBER IN, MAX=1,fJ") ;SKIPi
READ (1, N) iSKIPi
'FOR' V:=l 'STEP' 1 'UNTIL' N '~O'
'BEGIN'
READ (2,AXCV1);SKIPi
BXCVJ:=1/AXMiS KIPi
'END';
'FOR'V:=l 'STEP' 1 'UNTIL' N '~O'
WRITE (1 ,A~a. BXIYl) iSKIPi
'FOR' V:=l 'STEP' 1 'UNTIL' N '~O'
WRITE (2,A'Xf.V1, BxrvJ iSKIP;
'END'
$
E-5
GOTO, EXAMPLE 1
OK:
EXIT:
'BEGIN '
'INTEGER' 1, J;
WRITE (1, "GOTO TEST");SKIP;
READ (1, I~.J);SKIP;
'BEGIN '
'IF' I=J 'THEN' 'GOTO' OK;
WRITE (1, "NOT TOO GOOD") ;SKIP;
'GOTO' EXIT;
WRITE (1, "0. K. ") ;SKIPi
'END';
WRITE (1, "EXIT") ;SKIP;
'END'
$
GOTO, EXAMPLE 2
*L
OK:
EXIT:
'BEGIN '
'INTEGER ' I,J;.
WRITE (1, "GOTO TEST ") ;SKIP;
READ (1, I, J) ;SKIP;
'BEGIN '
'IF' 1= J 'THEN' 'GOTO' . OK;
WRITE (1, "NOT TOO GOOD") jSKIPj
'GOTO ' EXIT;
WRITE (1 "0. K. ") ·SKlp·
tt~j'
"
WRITE (1, "EXIT") ;SKIP;
'END'
$
*
E-6
'BEGIN '
'REAL' A,Bj
'INTEGER'I,Jj
WRITE (1, "DUMMY TEST ") jSKIPjSKIPj
READ (1, A, I, J. jSKIPj
WRITE (1, "A, B, I, J ARE NOT DECLARED IN THE NEXT BLOCK") jSKIPj
WRITE (1, "NEXT IS A NEW BLOCK") jSKIPj
'BEGIN '
'IF' 1= J 'THEN' 'GOTO' EXITj
WRITE (1, "WRITE 5 SKIPS") jSKIPjSKIPjSKIPj
SKIPjSKIPj
B: =A*A*Aj
EXIT:
'END'
'END'
$
*
E-7
'BEGIN '
'REAL' A B·I.
'INTEGERI I, Ji
WRITE (1, "DUMMY TEST") ;SKIPiSKIPi
READ (1, A, I);
WRITE (1, "A, B, I, J ARE NOT DECLARED IN THE NEXT BLOCK") ;SKIP;
WRITE (1, "NEXT IS A NEW BLOCK") ;SKIP;
'BEGIN I
'IF' 1= J 'THENI IGOTO I EXIT;
WRITE (1, "WRITE 5 SKIPS") ;SKIP;SKIP;SKIP;
SKIP;SKIP;
B: =A*A*A;
'ENDI
~
EXIT:
IENDI
$
*
E-8
">
/
Изтегляне
Само приятелско напомняне. Можете да видите документа точно тук. Но най-важното е, че нашият AI вече го е прочел. Той може да обясни сложни неща на прости термини, да отговори на вашите въпроси на всеки език и да ви помогне бързо да навигирате дори в най-дългите или най-сложните документи.
Реклама