
Revised report on the algorithmic language Algol-68
.pdfSectionA351 van Wijngaarden, et al.
then standardize(y, b, a, exp); edit int(exp);
}10} plusto s
;
string t = sub xed(y, b + a + (a /= 0 j 1 j 0 ), a ); if char in string(errorchar, loc int, t) _ a + b = 0
_ :sign1 ^ r < L 0 then incomp := true
else t[:b] + point + t[b+2:] plusto s;
(b + a + (a /= 0 j 1 j 0) - upb t) }0} plusto s; (sign1 j (r < L 0 j }-} j }+}) plusto s)
)i;
h proc edit ` compl =(L compl z)void:
(while :?}i} do sfp +:= 1 od; edit ` real(im z); }I} plusto s; sfp := 1; edit ` real(re z))i;
h proc edit ` bits(L bits lb, int radix)void:
(L int n := abs lb; ?}r}; int l := intpattern(loc bool); while dig char(S (n mod K radix)) plusto s;
n %:= K radix; n /= L 0 do skip od;
if upb s l
then (l - upb s) }0} plusto s else incomp := true
)i;
proc charcount = int: (int l := 0;
while ?}a} do (rep 0 j l +:= rep) od; l); case type of pattern in
/c integral /c (y[j ] j
h(L int i ): edit ` int(i )i j incomp := true),
/c real /c (y[j ] j
h (L real r): edit ` real(r)i, h(L int i ): edit ` real(i )i
j incomp := true), /c boolean /c
(y[j ] j
(bool b): s := (b j ip j op) j incomp := true),
211
Section |
ALGOL 68 Revised Report |
A351 |
/c complex /c (y[j ] j
h (L complex z): edit ` complex(z)i, h (L real r): edit ` complex(r)i,
h (L int i ): edit ` complex(i ) i j incomp := true),
/c string /c (y[j ] j
(char c): (charcount = 1 j s := c j incomp := true),
([ ] char t):
(charcount = upb t - lwb t + 1
js := t[@1]
jincomp := true) j incomp := true)
out
/c bits /c (y[j ] j
h (L bits lb): edit ` bits(lb, type of pattern - 4)i j incomp := true)
esac;
if :incomp
then edit string(f, s, sframes)
end,
(cpattern choice): begin
[ 1: upb (i of choice)j sinsert si; staticize insertion(i of choice, si ); put insertion(f, ci );
int l =
case type of choice in /c boolean /c
(y [j ] j
(bool b): (b j 1 j 2) j incomp := true; skip),
/c integral /c (y [j ] j
(int i ): i
j incomp := true; skip) 212
SectionA351 |
van Wijngaarden, et al. |
esac; if :incomp then
if l > upb(c of choice) _ l 0 then incomp := true
else
[ 1: upb((c of choice) [l])) sinsert ci; staticize insertion((c of choice)[l], ci ); put insertion(f, ci )
;
staticize insertion(i of picture, sinsert) end,
(fpattern fpattern): begin
do fpattern(f, fpattern, false);
for to upb sinsert do sinsert [i ] := (0, }} ) od; end,
(gpattern gpattern): begin
[1:upb(i of gpattern)] sinsert si;
[ ] proc int spec = spec of gpattern; int n = upb spec;
[ 1: n] int s;
(staticize insertion(i of gpattern, si ), staticize insertion(i of picture, sinsert), s := (n j spec[1], (spec[1], spec[2]),
(spec [1], spec [2], spec [3]) j ())); put insertion(f, si );
if n = 0 then put(f, y[j ]) else
number yj =
(y[j ] j h(L int i ): ii, h(L real r): ri j incomp := true; skip);
if :incomp then case n in
put(f, whole(yj, s[1])), put(f, xed(yj, [1], s[2 ])),
put(f, oat(yj, s[1], s[2], s[3])) esac
213
Section |
ALGOL 68 Revised Report |
A351 |
end, (void):
(j -:= 1; staticize insertion(i of picture, sinsert))
esac;
if :incomp
then set write mood(f);
(:(value error mended of f)(f) j put(f, y [j ]): j unde ned)
;
put insertion(f, sinsert)
od end
esac od
else unde ned
;
b)proc @edit string(ref le f, string s, [ ] sframe sf)void:
begin bool supp, zs := true, signput := false, again, int j := 0, sign; proc copy(char c)void:
(:supp j check pos(f): put char(f, c)); for k to upb sf
do sframe sfk = sf[k ]; supp := supp of sfk: put insertion(f, si of sfk );
to rep of sfk
do again := true; while again
do j+:= 1; again := false;
char sj = s[j ], marker = marker of sfk; if marker = }d}
then copy(sj ); zs := true elif marker = }z} then
(sj = }0} j copy((zs j } } j sj )) j: sj = }+} j again := true
j zs := false; copy(sj ))
elif marker = }u} _ marker = }v} then (sj = }+} j sign := 1; again := true j: sj = }-} j sign := 2; again := true j: sj = }0} j copy((zs j } } j sj ))
j (:signput j
copy((sign j(marker=}u}j}+}j } }), }-})); 214
SectionA352 |
van Wijngaarden, et al. |
|
signput := true); |
|
copy(sj ); zs := false) |
|
elif marker = }+} then |
|
(sj = }+} _ sj = }-} j copy(sj ) |
|
j (:signput j copy((sign j }+}, }-}))); |
|
j -:= 1) |
|
elif marker = }-} then |
|
(sj = }+} j copy(} }) |
|
j: sj = }-} j copy(sj ) |
|
j (:signput j copy((sign j } }, }-}))); |
|
j -:= 1) |
|
elif marker = }.} then copy(}.}) |
|
elif marker = }e} _ marker = }i} |
|
_ marker = }a} _ marker = }b} |
|
then copy(sj ); zs := true; signput := false |
|
elif marker = }r} |
|
then j -:= 1 |
|
|
|
od |
|
od |
od |
|
end; |
|
10.3.5.2. Formatted input
a) proc getf = (ref le f, [ ] union(intype, format)x)void: if opened of f then
for k to upb x
do case set read mood(f); set char mood(f); x[k ] in (format format): associate format(f, format), (intype it):
begin int j := 0;
picture picture, [ ] simplin y = straightin it; while(j +:=- 1) upb y
do bool incomp := false;
get next picture(f, true, picture); set read mood(f); [ 1: upb(i of picture)] sinsert sinsert;
case p of pidec in (pattern pattern): begin
[ 1: upb(frames of pattern)] sframe sframes; 215
Section |
ALGOL 68 Revised Report |
A352 |
(staticize frames(frames of pattern, sframes). staticize insertion(i of picture, sinsert));
string s; int radix =
(type of pattern 6 j type of pattern - 4 j 10); indit string(f, s, sframes, radix);
case type of pattern in /c integral /c
(y[j ] j
h (ref L int ii ):
incomp := string to ` int(s, 10, ii ) i j incomp := true),
/c real/c (y[j ] j
h (ref L real rr):
incomp := string to ` real(s, rr) i j incomp := true),
/c boolean/c (y[j ] j
(ref bool bb): bb := s = ip j incomp := true),
/c complex /c (y[j ] j
h (ref L compl zz):
(int i, bool bi, b2; char in string(}I}, i, s); b1 := string to ` real(s [:i-1], re of zz); b2 := string to ` real(s [i+1:], im of zz); incomp := :(b1 ^ b2 ))i
j incomp := true), /c string /c
(y[j ] j
(ref char cc):
(upb s = 1 j cc := s [1] j incomp := true), (ref [ ] char ss):
(upb ss - lwb ss + 1 = upb s j ss [@1] := s j incomp := true),
(ref string ss): ss := s j incomp := true)
out
/c bits /c
216
SectionA352 |
van Wijngaarden, et al. |
|
(y[j ] j |
|
h (ref L bits lb): |
|
if L int i; string to ` int(s, radix, i ) |
|
then lb := bin i |
|
else incomp := true |
|
i |
|
j incomp := true) |
|
esac |
|
end, |
|
(cpattern choice): |
|
begin |
|
[ 1: upb(i of choice)]sinsert si; |
|
staticize insertion(i of choice, si ); |
|
get insertion(f, si ); |
|
int c = c of cpos of f, char kk; |
|
int k := 0, bool found := false; |
|
while k < upb(c of choice) ^ :found |
do k +:= 1;
[ 1: upb((c of choice) [k ])] sinsert si; bool bool := true;
staticize insertion((c of choice)[k ], si ); string s;
for i to upb s do s plusab
(sa of si[i ] j (string ss): ss) rep of si[i ]
od;
for jj to upb s
while bool := bool ^ :line ended(f) ^ :logical le ended(f)
do get char(f, kk ); bool := kk = s[jj ] od; (:(found = bool) j set char number(f, c))
od;
if :found then incomp := true else
case type of choice in /c boolean /c
(y [j ] j
(ref bool b): b := k = 1 j incomp := true),
/c integral /c 217
Section ALGOL 68 Revised Report A352
(y [j ] j
(ref int i ): i := k j incomp := true)
esac
;
staticize insertion(i of picture, sinsert) end,
(fpattern fpattern):
begin do fpattern(f, fpattern, true);
for i to upb sinsert do sinsert [i ] := (0, }}) od; j -:= 1
end,
(gpattern gpattern):
([1: upb(i of gpattern) ] sinsert si; (staticize insertion(i of gpattern, si ),
staticize insertion(i of picture, sinsert)); get insertion(f, si );
get(f, y [j ])),
(void):
(j -:= 1; staticize insertion(i of picture, sinsert)) esac;
if incomp
then set read mood(f);
(:(value error mended of f)(f) j unde ned)
;
get insertion(f, sinsert)
od end
esac od
else unde ned
;
b) proc @indit string = (ref le f, ref string s, [ ] sframe sf, int radix)void: begin
bool supp, zs := true, sign found := false, space found := false, nosign := false, int sp:=1, rep;
prio ! = 8;
op ! = (string s, char c)char:
/c expects a character contained in 's'; if the character read is not in 's', the event routine corresponding to 'on char error' is called with the suggestion 'c' /c
218
SectionA352 van Wijngaarden, et al.
if char k; checkpos(f); get char(f, k ); char in string(k, loc int , s)
then k
else char sugg := c;
char cc = if (char error mended of f)(f, sugg) then (char in string(sugg, loc int , s) j sugg j unde ned; c) else unde ned; c
;
set read mood(f); cc
;
op ! = (char s, c)char: string(s) ! c;
[ ] char good digits = }0123456789abcdef} [:radix]; s := }+};
for k to upb sf
do sframe sfk =sf[k ]; supp := supp of fsk; get insertion(f, si of sfk );
to rep of sfk
do char marker = marker of sfk; if marker = }d} then
s plusab(supp j }0} j good digits! }0}); zs := true elif marker = }a} then
s plusab(supp j }0}
j char c = ((zs j } } j }} )+gooddigits)!}0}; (c /= } } j zs := false); c)
elif marker = }u} _ marker = }+} then if sign found
then zs := false; a plusab(}0123456789}! }0})
else char c = (}+-}+(marker = }u} j } } j }} ))! }+}; (c = }+} _ c = }-} j sign found := true; s[sp] := c)
elif marker = }v} _ marker = }-} then if sign found
then zs := false; z plusab(}0123456789}! }0}) elif char c; space found
then c := }+- 0123456789}!}+};
(c = }+} _ c = }-} j sign found := true; s[sp] := c j:c /= } } j zs := false;sign found := true; s plusab c)
else c := }+- }! }+};
(c = }+} _ c = }-} j sign found := true; s[sp] := c j space found := true)
219
Section |
ALGOL 68 Revised Report |
A36 |
|
|
|
|
elif marker =}.} then |
|
|
s plusab(supp j }.} j }.}! }.}) |
|
|
elif marker = }e} then |
|
|
s plusab(supp j }10} j }10\e} ! }10} ; }10}); |
|
|
sign found := false; |
|
|
zs := true; s plusab }+}; sp := upb s |
|
|
elif marker = }i} then |
|
|
s plusab(supp j }I} j }iI} ! }I}; }I}); |
|
|
sign found := false; zs := true; s plusab }+}; sp := upb s |
|
|
elif marker = }b} then |
|
|
s plusab( ip + op) ! op; no sign := true |
|
|
elif marker = }a} then |
|
|
s plusab(supp j } } j |
|
char c; check pos(f); get char(f, c); c); no sign := true
elif marker = }r} then skip
od
od;
if no sign then s := s[2: ] end;
10.3.6. Binary transput
fIn binary transput, the values obtained by straightening the elements of a data list (cf. 10.3.3) are transput, via the speci ed le, one after the other. The manner in which such a value is stored in the book is de ned only to the extent that a value of mode M (being some mode from which that speci ed by simplout is united) output at a given position may subsequently be reinput from that same position to a name of mode reference to M . Note that, during input to the name referring to a multiple value, the number of elements read will be the existing number of elements referred to by that name.
The current position is advanced after each value by a suitable amount and, at the end of each line or page, the appropriate event routine is called, and next, if this returns false, the next good character position of the book is found (cf. 10.3.3).
For binary output, put bin (10.3.6.1.a) and write bin (10.5.1.h) may be used and, for binary input, get bin (10.3.6.2.a) and read bin (10.5.1.i).g
220