/
Algol-68S User Manual.txt
3421 lines (2513 loc) · 122 KB
/
Algol-68S User Manual.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
This document was originally titled:
Algol 68 User Manual
March 8, 1978
It was intended to be a manual for the PDP-11 Algol68S system available for some
Operating Systems for the PDP-11, esp. the C.mmp (Hydra) multiprocessor system, and
Unix Version 6 or 7 systems.
The original manuscript was OCR'd by W.B.Kloke ( klokew@acm.org ). At the present stage
it is missing distinction between roman and italic characters which the original had.
As the system described allows "reserved word" stropping, this is not really
detrimental.
Thanks to Andy Walker from Nottingham, who made the copy available to me, and
who digged out the compiler also to be preserved by PUPS.
At this early stage the best description of this document involves terms like
inaccurate, incomplete and misleading.
Comments on the current document or suggestions for future Algol 68
documentation should be directed to Paul Knueven or sent via MAIL to
ALGOL68@CMUA.
1. Introduction
User, meet Algol 68. Algol 68, meet user. When the bell rings come out fighting,
and may the best of you win.
CMU Algol 68 is an extended version of the IFIP-approved Algol 68 sublanguage.
Disregarding certain features which are in neither official language, the CMU language
is less than the full language and more than the sublanguage.
At this time no complete description of the CMU language is available. Chapter
3 contains the current version of what may some day be such a description. There
are three sources of information which may be of some help in learning the language.
First, for someone familiar with Algol 68, the remaining sections of this chapter
sketch what is available in the CMU language. The differences between the full and
CMU languages are described briefly in sections 2.1 and 2.2. Some understanding
of Algol 68 terminology is necessary to read these sections. The lists of basic symbols
(See 2.3.3), prelude operators (See 2.4.1) and prelude identifiers (See 2.4.2) should
remind the already knowledgeable user of what is possible.
Second, copies of illuminating examples are available from Paul Knueven in
Science Hall 4209.
Third, documents which describe the official languages can serve as a useful
introduction to the CMU language. The "Revised Report on the Algorithmic Language
Algol 68" (published in two journals, Acta Informatica Vol. 5, Fasc. 1-3, and SIGPLAN
Notices, May, 1977; and as a separate volume, call number 510.7844024 R45 in the
Science Hall Library) is the authoritative definition of the full Algol 68 language. This
is normally found to be difficult for the uninitiated reader to understand. Part V may
be helpful since it defines the standard operators and identifiers (mostly in terms of
short programs) and contains some sample programs. The official specification of the
sublanguage is "A Sublanguage of Algol 68" by P.G. Hibbard in May, 1977 SIGPLAN
Notices. It too is difficult to read. A textbook, A Practical Guide to Algol 68 by Frank
Pagan, is usually available in the CMU Bookstore. A survey article, "A Tutorial on Algol
68" by Andrew Tanenbaum, appeared in the June, 1976 Computer Surveys.
2.1. Restrictions
The following sections briefly describe the restrictions placed on the full Algol
68 language in order to define the basic CMU language.
2.1.1 Modes
United-modes may not be specified in a particular-program. However, it is
permitted to call routines defined in the standard prelude which have united-mode
parameters. (Upb and print are examples of such routines.) A multiple value may not
occur as a field of a structured value or as an element of a multiple value. Thus,
modes such as [ ][ ]amode and struct(..., [ ]amode, ...) are not allowed. There are no
flexible names. String is a primitive mode distinct from [ ]char. There are no short
modes. The only long modes are long int, long real, and long compl.
2.1.2 Clauses
Void-collateral-clauses and vacuums are not allowed. A display may not occur in
a position which is not strong, or as the only phrase of a closed-clause.
conformity-clauses are not permitted, since they are only useful in conjunction with
united-modes.
2.1.3 Declarations, Declarers and Indicators
Heap-sample-generators are not permitted, so the heap-symbol may not appear
in a variable-declaration. A lower-bound is required in an actual-rowed-declarer, that
is, the form [u]amode is not permitted as a short version of [1:u]amode. The
flexible-symbol and union-of-symbol are not allowed in declarers.
2.1.4 Units
Local-generators may not occur as operands in formulas, in actual-bounds, or
before the first definition of a local range. A go-to-token is required in a jump. A
jump may not yield a value of mode proc amode. A jump may not by-pass the first
declaration of any local range containing the label which is its target. Strings always
have a lower bound of 1. A slice of a string may not have a revised-lower-bound and
is always dereferenced (i.e. it is not possible to slice out a name which refers to a
substring; this in turn means that it is not possible to assign to a substring).
2.1.5 Coercions
The ref-rowing coercion is not allowed, that is, a value of mode ref amode is not
coerced to ref [ ]amode. A char value may be widened to a string value and a string
value may be widened to a [ ]char value.
2.1.6 Independence and Identification
An applied-mode-indication may not occur in an actual-rower of the
actual-declarer of its mode-definition. The defining occurrence of an indicator (other
than a label-definition) must precede its first applied occurrence. A priority-definition
of a dyadic-operator must precede the first operation-definition of that operator. The
priority of an operator may not be redefined in an inner range. The test for
independence of operator-definitions is more restrictive than it is in the full language.
(Among other things, an operator may not be redefined in an inner range.)
2.1.7 Denotations
There is no void-denotation.
2.1.8 Symbols
A bold tag may not be used as both an operator and a mode-indication in the
same reach. Only the operator-standards defined in the standard prelude may be used
in operation-definitions.
2.1.9 Standard Prelude
Some environment enquiries are not available in a particular-program. (See
2.4.3 for a list of identifiers and values)
2.1.10 Transput
There is no formatted transput. Certain enquiries and operations are not
supported. See 2.4 for a precise statement of which routines are supplied.
2.2. Extensions
2.2.1 Safe-clause and Export-declaration
A safe-clause allows a group of declarations to be encapsulated; that is, the
declarations introduce identifiers which are accessible by each other but are hidden
from the rest of the program. An export-declaration is used inside a safe-clause to
override the hiding capability of the safe-clause. An identifier declared in an
export-declaration in a safe-clause is known in its usual reach.
2.2.2 Module and External-fetch
These two extensions have been introduced to allow the construction of a
program by the linking together of several separately compiled program-texts. The
program of a single compilation may be given a "module name" which can be specified
in an external-fetch in the program of some other compilation. External-fetches are
used to access values which are not created in the program in which they appear
2.2.3 Code Values
A code value is an object which corresponds to a machine language subroutine.
The mode of a code value is code amode, code(amode)bmode or
code(amode,bmode)cmode, that is, a code value may have up to two parameters. A code
value can not be created by an Algol 68 program. The only way to access such a
value with an external-fetch.
2.2.4 New Modes
It is possible to specify new, unique plain modes by writing newsimple or
newpile instead of the actual-declarer in a mode-definition. Actions such as assignation
and ascription may be applied to values of these modes, but there are no actions
which can do more that copy or move such values. By supplying code values which
take values of a new mode as parameters or return one as a result, it is possible to
create a subsystem to manipulate values which may be handled, but not broken apart,
by the user.
2.2.5 Mutually Recursive Modes
Since the language is restricted to force the defining occurrence of an indicator
to precede any applied-occurrence of the indicator, an extension has been made to the
language to permit the introduction of mutually recursive modes.
2.2.6 Eventual Values
An object called an eventual value is designed to allow the easy and natural
specification of parallel processing.
2.3. The Representation Language
2.3.1 Tags and Bold Words
Tags are used as identifiers, labels and field selectors. A tag is represented by
a letter followed by one or more letters or digits. The characters in a tag may be
separated by typographical display features (blank, line feed, form feed). The tags 'on
line end', 'online end' and 'onlineend' are equivalent.
Bold words are the symbols which appear in this document in boldface. There
are two kinds of bold words. Bold tags are used to specify mode indications and
operators. The other bold words are the "reserved words" or "keywords" of the
language; e.g. begin, while, true. Bold words consist of a bold letter followed by one or
more bold letters or digits. Unlike tags, no typographical display features may
separate the characters. Since most computers do not have a boldface character set,
some provision must be made for the representation of these symbols.
A stropping convention is a set of rules specifying how to indicate bold words.
There are currently four stropping conventions available. They are called point,
upper, lower and res. The default is the point convention in which bold words are
indicated by a prefix strop character. This strop character may be either a point (.) or
an apostrophe ('). The use of the strop character is permitted in all stropping
conventions. The occurrence of a strop followed by an alphabetic character always
forces the alphanumeric sequence following the strop to be bold.
The upper convention uses upper case letters to indicate bold letters, while
lower convention uses lower case letters. A strop may be used to override this as
described above. In conventions other than these, upper and lower case characters
for a given letter are considered equivalent.
In res (reserved word) convention, typographical display features may not
appear between the characters of a tag or the symbols of a denotation. A sequence
of alphanumeric characters surrounded by disjunctors (non-alphanumeric characters or
typographical display features) represents a bold word, if one exists, with that
particular spelling; otherwise it represents a tag. The lexically first occurrence of a
user-introduced bold tag must be stropped.
2.3.2 Pragmat Items
The following pragmat items are implemented. They act as compiler directives
when they appear between a pair of matching pragmat symbols (i.e. pragmat, pr, or ::).
listing Enable production of compiler listing
lower Set stropping convention to lower
nolisting Suppress production of compiler listing
nowarnings Suppress output of compiler warning messages
page Skip to top of new page in listing output (not implemented)
res Set stropping convention to res
point Set stropping convention to point
upper Set stropping convention to upper
warnings Enable output of compiler warning messages
2.3.3 Basic Symbols
The following are the non-tag symbols of Algol 68. Those which appear as
boldface must be represented according to some stropping convention. Remember in
res stropping no tag may be spelled the same as any of these. In some cases there
are two representations of a symbol. Where this is so, both representations appear
on the same line.
Symbol Where used
at @ revised-lower-bound of slice
begin closed-clause, collateral-clause
bits declarer
bool declarer
by loop-clause
bytes declarer
case case-clause
channel declarer
char declarer
co comment
code code-declarer
codeop code-operation-declaration
comment comment
compl declarer
do loop-clause
efas safe-clause
elif conditional-clause
else conditional-clause
end closed-clause, collateral-clause
esac case-clause
event eventual-declarer
exit completer in serial-clause
export export-declaration
ext external-fetch
false boolean-denotation
fi conditional-clause
file declarer
for loop-clause
from loop-clause
go with to in jump
goto jump
heap generator
if conditional-clause
in case-clause
int declarer
is :=: identity-relation
isnt :/=: identity-relation
loc generator, variable-declaration
long declarer, denotation
mode mode-declaration
module module-declaration
newsimple mode-declaration
newpile mode-declaration
nil nihil
od loop-clause
of selection
op operation-declaration
ouse case-clause
out case-clause
par parallel-clause
pr pragmat
pragmat pragmat
prio priority-declaration
proc procedure-decl4rer
proctime declarer
real declarer
ref reference-declarer
safe safe-clause
secloc generator
sema declarer
short declarer, denotation
skip skip
string declarer
struct structure-declarer
then Conditional-clause
to loop-clause, with go in jump
true boolean-denotation
void declarer
while loop-clause
( (open symbol) closed-, collateral-, conditional-, case-clauses
) (close symbol) closed-, collateral-, conditional-, case-clauses
, (comma symbol) case-, collateral-clauses, declaration-list
: (colon symbol) label, routine-text, trimmer, bounds
; (semicolon symbol) serial-clause
:= (becomes symbol) assignation
[ (sub symbol) slice, rowed-declarer
] (bus symbol) slice, rowed-declarer
= (equals symbol) identity-, mode-, priority-declarations
# (comment symbol) comment
:: (pragmat symbol) pragmat
! | (stick symbol) brief-conditional-clause, brief-case-clause
!: |: (again symbol) brief-conditional-clause, brief-case-clause
\ e (times ten to the power symbol) real-denotation
" (quote symbol) character-, string-denotations
"" (quote image symbol) character-, string-denotations
The following bold Words are used in the full Algol 68 Revised language and are
not included in the CMU language.
empty
flex
format
union
2.4. Standard and Particular Preludes
2.4.1 Operators
The following is a list of the operators which are defined in the standard and
particular preludes of CMU Algol 68. Two techniques are used here to make the list
sh9rter than it would be otherwise. First, the letter L indicates places where zero or
one occurrence of the symbol long must be inserted. All the L's in a particular entry
of the list must be repeaced by the same number of long's. Second, an asterisk is used
to indicate that a dyadic operator exists both with the parameter modes in the order
shown and with the parameter modes interchanged.
All of the operators are currently available except those which require or return
a value of a long mode.
Operator Modes
abs proc(L int)L int
proc(L real)L real
proc(L compl)L compl
proc(bool)int
proc(bits)int
proc(char)int
and proc(bool,bool)bool
proc(bits,bits)bits
arg proc(L compl)L real
bin proc (int)bits
conj proc(L compl)L compl
down proc (sema)void
/:= divab proc(ref L real,L real)ref L real
proc(ref L real,L int)ref L real
proc(ref L compl,L compl)ref L compl
proc(ref L compl,L real)ref L compl
proc(ref L compl,L int)ref L compl
elem proc(int,bits)bool
proc(int,bytes)char
entier proc(L real)L int
= eq Same as gt plus
proc(L compl,L compl)bool
proc(L int,L compl)bool*
proc(L real,L compl)bool*
proc(bool,bool)bool
proc(bits,bits)bool
>= ge Same as gt plus
proc(bits,bits)bool
> gt proc(L int,L int)bool
proc(L real,L real)bool
proc(L int,L real)bool*
proc(char,char)bool
proc(string,string)bool
proc(char,string)bool*
proc(bytes,bytes)bool
<= le Same as ge
level proc(sema)int
proc(int)sema
leng proc(int)long int
proc(real)long real
proc(compl)long compl
< lt Same as gt
lwb proc(rows)int
proc(string)int
proc(int,rows)int
-:= minusab Same as divab plus
proc(ref L int,L int)ref L int
%* mod proc(L int,L int)L int
%*:= modab proc(ref L int,L int)ref L int
ne Same as eq
not proc(bool)bool
proc(bits)bits
odd proc(L int)bool
or proc(bool,bool)bool
proc(bits,bits)bits
% over proc(L int,L int)L int
%:= overab proc(ref L int,L int)ref L int
+:= plusab Same as minusab plus
proc(ref string,string)ref string
proc(ref string,char)ref string
+=: plusto proc(string,ref string)ref string
proc(char,ref string)ref string
repr proc(int)char
round proc(L real)L int
shl proc(bits,int)bits
shorten proc(long int)int
proc(long real)real
proc(long compl)compl
shr proc(bits,int)bits
sign proc(L int)L int
proc(L real)L int
*:= timesab Same as minusab plus
proc(ref string,int)ref string
up proc(sema)void
upb Same as lwb
- proc(L int)L int
proc(L real)L real
proc(L compl)L compl
proc(L int,L int)L int
proc(L real,L real)L real
proc(L compl,L compl)L compl
proc(L int,L real)L real*
proc(L int,L compl)L compl*
proc(L real,L compl)L compl*
+ Same as - plus
proc(string,string)string
proc(char,char)string
proc(char,string)string*
* proc(L int,L int)L int
proc(L real,L real)L real
proc(L compl,L compl)L compl
proc¼ int,L real)L real*
proc(L int,L coinpl)L compl*
proc(L real,L compl)L compl*
proc(int,char)string*
proc(int,string)string*
/ proc(L int,L int)L real
proc(L real,L real)L real
proc(L compl,L compl)L compl
proc(L int,L real)L real*
proc(L int,L compl)L compl*
proc(L real,L compl)L compl*
^ proc(L int,int)L int
proc(L real,int)L real
proc(L compl,int)L compl
** Same as ^
+* proc(L int,L int)L compl
proc(L real,L real)L compl
2.4.2 Identifiers
All of the following identifiers are available except 'associate', 'stand back', and
'stand back channel'.
Identifier Mode
arccos proc(real)real
arcsin proc(real)real
arctan proc(real)real
associate proc(ref file,ref string)void
bits pack proc([]bool)bits
bytes pack proc([]char)byles
chan proc(ref file)channel
char number proc(ref file)int
close proc(ref file)void
cos proc(real)real
establish proc(ref file,string,channel,int,int,int)int
exp proc(real)real
fixed proc(number,int,int)string
float proc(number,int,int,int)string
get proc (ref file,[]in)void
get bin proc(ref file,[]inbin)void
last random ref int
line number proc(ref file)int
ln proc(real)real
make term proc (ref file,string)void
max abs char int
max int int
max real real
new line proc(ref file)void
new page proc(ref file)void
next random proc(ref int)real
on line end proc (ref file,proc(ref file)bool)
on logical file end proc(ref file,proc(ref file)bool)
on page end proc(ref file,proc(ref file)bool)
on physical file end proc(ref file,proc(ref file)bool)
open proc(ref file,string,channel)int
page number proc (ref file)int
pi real
print proc([]out)void
put proc(ref file,[]out)void
put bin proc(ref file,[]outbin)void
random proc real
read proc([]in)void
read bin proc ([]inbin)void
reset proc(ref file)void
scratch proc(ref file)void
set proc (ref file,int,int,int)void
sin proc (real)real
small real real
space proc (ref file)void
sqrt proc(real)real
stand back ref file
stand back channel channel
stand in ref file
stand in channel channel
stand out ref file
stand out channel channel
tan proc (real )real
whole proc(number,int)string
write proc(ref file,[]out)void
write bin proc(ref file,[]outbin)void
cons in channel channel
cons out channel channel
fixed page channel channel
get proc time code(ref proctime)void
musecs code(proctime)real
on error code(proc(int,int,bits)bool)void
on sys trace code(code(int,bits)void)void
on tick code (proc (int,int)void)void
sos file channel channel
start proc time code void
sys trace code(int,bits)void
var page channel channel
warning level code(int)void
2.4.3 Environment Enquiries
The CMU language does not include all of the environment enquiries. The
following list gives the values of all the environment enquiries; those which are
available in the language are marked by an asterisk
Identifier Value
int lengths 2
int shorths 1
max int* 2**15 - 1 (i.e. 32767)
max long int 2**31 - 1 (i.e. 2147483647)
real lengths 2
real shorths 1
max real* (2 ** 127)-(2 ** 103) (about 1.70141173319o38)
max long real (2 *4 127)-(2 ** 71) (about 1.70l41l8346046922837e38)
small real* (2 ** -23) (about l.l920928955e-7)
small long real (2 ** -55) (about 2.775557561562892351e-17)
bits lengths 1
bits shorths 1
bits width 15 (also upb []bool(8r1) )
bytes lengths 1
bytes shorths 1
bytes width 2 (also upb []char(bytes b = bytes pack(""); b) )
max abs char* 127
null character repr 0
flip "T"
flop "F"
error char "*"
blank repr 32
3. Introduction to CMU Algol 68
This chapter is meant to become a complete description of and introduction to
the Algol 68 language (or, that variety of it which is available at CMU). When this goal
is achieved the preceding chapter will no longer be needed.
As this chapter is being developed the attitude of the authors is that whatever
information has been written will be included in the document. The idea is that
something is better than nothing. This means that at any given moment the contents
may seem incomplete, uneven in style, lack polish, and/or without coherent
organization. We will frequently refer the reader to "more complete documents" in
cases where we have been too hurried or too lazy to supply details. The reader is
asked to be as forgiving as possible.
This tutorial is definitely intended for a reader with some familiarity or prior
experience with other programming languages, be they even as simple as BASIC or as
weird as pure LISP. Non-programmers should give up right here and go off to take a
course in programming. When a new concept is introduced which is called by other
names in other languages, the other names are presented in [brackets] after the Algol
68 name of the concept.
3.1. Preface
The method of exposition used in this chapter is mostly the presentation of
examples--small snatches of program text that illustrate various corners of the
language. In spite of the tutorial nature of the chapter, therefore, we hope that it will
be usable as a reference. Every effort has been made to use examples that are
typical of user programs; most of the larger ones have been copied directly from such
programs.
The order of the sections is such that there is as little forward referencing as
possible, i.e. it is (hopefully) seldom necessary to look at a later section in order to
uqderstand some earlier example. This organization has peculiar consequence: that
certain sections, such as the section on transput (input/output), which you must know
at least a little about in order to write useful programs, are placed near the end. Don't
be disturbed by this; everything you need to know is here, somewhere or other.
Another peculiar practice we have followed, for a variety of good reasons, is the
carrying over of definitions from one example to another. An identifier declaration
may appear in one example, and the identifier so declared may appear in the next few
examples or even reappear a couple of pages later. Since this practice can cause
confusion, we have tried not to overuse it; but be warned.
A note about terminology: pursuing the goals of precision and unambiguousness,
the authors of the Revised Report invented a whole new kind of grammar and a whole
slew of new words, for the description of programming languages in general and Algol
68 in particular. Those two goals were of little interest to us in writing this tutorial,
and we have used a careless mixture of terms from the Revised Report with terms and
concepts from other programming languages and literature to say what we mean.
However, when we have used terms from the Revised Report, we have tried to be
consistent with the original use of those terms.
3.2. Stropping, Upper and Lower Case, and other Perversions
This section describes the rules for using upper and lower case letters, for
using blanks within identifiers, and for distinguishing those things that in other
languages are called "reserved words" or "keywords". In the CMU system there are
four alternative sets of rules; you can choose the one you like best for a program, and
if you are indecisive (or perverse), you can even switch from one set of rules to
another in the middle of a program. Before describing the four alternatives and giving
examples of them, we'll explain why they are the way they are.
The rules of Algol 68 on this subject are more appropriate for programs which
are published (i.e. as algorithms in textbooks or journals) than for programs which
must be input to a computer using some commonly available input device. It is
intended that programs be written using two alphabets: keywords (such as if and end),
operators (mod, abs), and modes (real, bool) are supposed to be written in "bold face",
while identifiers, such as variables and procedure names, are supposed to be written
with the non-bold alphabet (perhaps this should be called "timid face"). If you can use
input devices with both lower and upper case letters, you may find it convenient to
pretend that upper case letters are bold face and lower case letters are timid face, or
vice versa. Many programmers do not even have the luxury of two cases of letters.
To these unfortunates, two options are open. They may either distinguish the words
which are meant to be bold face by putting a dot or an apostrophe before each one;
or they may not. You may ask, "Why should I put a dot in front of each bold face
Word if I don't have to"? The privilege that this allows you, besides compatibility with
other compilers which insist that you use dots or apostrophes, is that you may use
blanks in your timid face words. For instance, the predefined variable "lastrandom"
may be referred to as "last random", "lastran dom", "lastr and om", and so forth,
indiscriminately. (Note that you can never use blanks in bold face words, no matter
what set of rules you use).
Later, in section 3.4, we'll show how to indicate to the compiler which set of
rules you prefer; first, here are samples of all four styles:
#
"Upper" convention: keywords, etc. are in upper case;
all others must be in lower case.
#
IF a THEN b := c FI;
#
#
"Lower" convention: exactly the reverse of "Upper"
if D then E := F fi;
#
"Res" convention: keywords, etc. are reserved" and need
not be specially distinguished. There are some restrictions:
#
if UsingResconvention ThEn iDentiFiersmustBERuntogEthErwithoutblanks fi;
#
"Point" or "Strop" convention: keywords, etc. are distinguished by
starting them with a period or apostrophe. THIS IS THE DEFAULT.
#
if 'Not using res convenTION tHEN IdentiFIERS MAY CONtain blanks 'Fi;
Incidentally, no matter what convention you are using, you may always use a
period or apostrophe to signal the start of a bold face word.
3.3. Comments
We mention the Comment first because it is the simplest and easiest to use
construct in the whole Algol 68 language. The semantics of comments is: you may put
as many as you like anywhere in your program, and it will execute just as if you had
not put in any at all. Those of you who are familiar with program verification will
realize that this leads to a remarkably simple proof rule for this versatile construct.
You will find it helpful to actually strew your program with these useful little
creatures.
A word of caution, however. Like many others, the CMU ALGOL 68 compiler is
considerably less rigorous about checking the correctness of your comments, than
about checking the other constructs in your program. Indeed, errors in your comments
are frequently not caught at run time, even after several runs of the program. Thus
you, the programmer, must be extra careful about such errors; they can be insidious
and extremely damaging.
A comment may begin with the letter # or with either of the keywords co and
comment; it must be ended with the same thing that began it:
# The following code is wrong. #
co The following code cannot possibly be executed. co
comment
"Not only was it difficult to modify the evaluation function --
It was difficutt even to find it in the listing of the program."
David Slate
comment
A comment may occur anywhere in a program (except between the individual
characters of a single word, number, operator, etc.), and may stretch over several
lines. A common mistake is to forget the indication of the end of a comment; see
section 3.9.
3.4. Pragmats [pseudo-comments; directives]
Pragmats are a catch-all language feature, by means of which you can tell the
ALGOL 68 system miscellaneous things about your program and how you would like it
treated. A pragmat may begin with a double colon (::), or with either of the keywords
pr or pragmat, and like a comment it must be ended with the same thing that began it:
:: upper nowarnings ::
COMMENT
"upper" indicates that the program is written in upper convention,
at least until the next pragmat. "nowarnings" tells the compiler not
to print any warning messages that should arise, on the user's terminal
COMMENT
PR point nolisting PR
.Pragmat
lower
listing
.Pragmat
Note that the individual pragmat items are timid face words; also, if a pragmat
item changes the convention for distinguishing bold face from timid face, it does not
take effect until the end of the pragmat. A list of the available pragmat items is in
section 2.3.2.
3.5. Values, Modes, and Actions
In this section we will look at the data structuring and manipulation features of
Algol; in the next two sections we will look at control structures: first for ordinary
sequential control, then for parallel control.
3.5.1 Standard Prelude [Predeclared; built-in] Modes [Types]
We will refer to what you may already know of as "data types", by the name
"modes". We will look at rowed modes [arrays; vectors; matrices] and structured
modes [structures; records] later; but a number of more basic modes are available built
in to the language:
int integer [fixed point]
real real [floating point]
bool boolean [logical]
bits small mask - 15 booleans [set; packed boolean]
char character
string string
bytes short string - 2 characters
compl complex
plus others which we will cover later. Many examples of the use of values of these
modes will appear in subsequent sections
3.5.2 Various Operators
Algol has most of the arithmetic operators you know and love from other
languages. Here are just a few samples:
3 + 4 integer addition proc (int,int) int
a >= b comparison proc (int,int) bool
abs x absolute value proc (int) int
s or t boolean operator proc (bool,bool) bool
There are other operators you may not have seen before:
# Two flavors of division #
3 % 2 yields 1 proc (int,int) int
3 / 2 yields 1.5 proc (int,int) real
# Two flavors of real-to-integer conversion #
round 1.6 yields 2 proc (real) int
entier 1.6 yields 1 proc (real) int
round -1.4 yields -1
entier -1.4 yields -2
# Module #
11 %* 3 yields 2 proc (int,int) int
-11 %* 3 yields 1
11 %* -3 yields 2
-11 %* -3 yields 1
# Exponentiation - ONLY integer exponents, please #
4 ^ 3 yields 64 proc (int,int) int
4 ** 3 means the same
1.5 ^ -2 yields 0.44444... proc (real,int) real
# after the declaration #
compl z (0-0, 1.0);
z ^ 2 yields (-1.0, 0.0) proc (compl,int) compl
# Complex operations #
# after the declaration #
compl a = (3.0, 4.0),
b = (4.9, 3.0);
a + b yields (7.0, 7.0) addition
a - b yields (-1.0, 1.0) subtraction
a * b yields (0.0, 25.0) multiplication
a / b yields (0.96, 0.28) division
- a yields (-3.0, -4.0) negation
conj a yields (3.0, -4.0) conjugation
abs a yields 5.0 magnituda
arg a yields 0.9273 angle in radians
# String & character operations #
"AbC" + "dEf" yields "AbCdEf" concatenation
"X" * 4 yields "XXXX" replication
3 * "zQ" yields "zQzQzQ"
# Bits operations; denotation [representation] of Bits values #
16rf, 8r17, 4r33, 2r1111, all denote the same BITS value
bin 15 yields the same BITS value
16rf0 shr 4 yields 16rf logical shifting
16rf shl 4 yields 16rf0
16rf0 >= 16r70 yields true set inclusion
16rf0 >= 16rf yields false
4 elem 16rf yields true bit extraction
# Various kinds of conversion #
repr 65 yields "a" proc (int) char (ASCII conversion)
abs "a" yields 65 proc (char) int
abs true yields 1 proc (bool) int
abs false yields 0
abs 16rf yields 15 proc (bits) int
bin 15 yields l6rf proc (int) bits
# Miscellany #
odd 3 yields true proc (int) bool
odd 2 yields false
sign -2 yields -1 proc (int) int
sign 0 yields 0
sign 1001 yields 1
3.5.3 Identifiers, Variables, Assignation
In Algol 68, the concepts of variables, pointers (called "references" or "names"),
and assignation have been reorganized and unified, with consequences that are serious
and far-reaching. We will defer discussion of this until section 3.5.7; in this section we
will just present a few simple declarations, such as are likely to be familiar from other
programming languages.
Identifiers must be declared before they are used. Definitions of identifiers
follow "range structure", which is similar to Algol 60 "block structure"; the differences
will be explained in section 3.6.4.
# Identity [constant; Parameter] declarations #
int j = 3;
real a = 2.7818281828;
real a = b + c; # need not be constant #
# variable declarations #
int g;
equivalent to
ref int g = loc int;
# initialized variable declarations #
int k := 3;
equivalent to
ref int k = loc int := 3;
compl i := (0.0, 1.0);
or alternately
compl i := 0.0 +* 1.0; # +* is the "plus i times" operator #
# assignation #
k := 6 + m;
a := b := c := 4.0;
# operations combined with assignation #
k +:= 1
equivalent to
k := k + 1
b %*:= 3
equivalent to
b := b %* 3
n := p +:= q + r
equivalent to
p +:= (q + r);
n := p
special case for strings:
s1 +=: s2
equivalent to
s2 := s1 + s2
as well as the usual
s1 +:= s2
equivalent to
s1 := s1 + s2
3.5.4 Coercions [Conversions]
In Algol 68, as in many languages, it is often possible to use a value of one mode
in a case where a value of some other mode is really required. For instance, in the
following declaration:
compl c = (3, 4);
the int values 3 and 4 are used where real values are required. In cases like this the
system automatically converts the value from the given mode to the required mode;
this is called a coercion. In Algol 68 there are limitations on what coercions are
automatically done where, and you may occasionally find it necessary to explicitly
force a conversion to be done, by means of a "cast":
int i = 1234;
...
real r = real (i) ^ 2;
#
The exponentiation would overflow if it were done as an integer
operation; therefore i is converted to a real, and a real
operation is performed.
#
Most of the time, however, casts are unnecessary.