Добавил:
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:

Revised report on the algorithmic language Algol-68

.pdf
Скачиваний:
12
Добавлен:
23.08.2013
Размер:
1.4 Mб
Скачать

SectionA3481

van Wijngaarden, et al.

If the mode of V is speci ed by int, if V > 0 and if the number of constituent literals in the praglit-list-pack of Q is at least V,

then

the literal yielded by the V-th literal is staticized and performed; otherwise,

the event routine corresponding to on value error is called;

if this returns false, V is output using put and unde ned is called;

the insertion of P is staticized and performed.

bb)A value is input to a name N using a picture P whose pattern Q was yielded by an integral-choice-pattern Q as follows:

the insertion of Q is staticized and performed,

each of the literals yielded by the constituent literals of the praglit-list-pack of C is staticized and \searched for" (cc) in turn:

If the mode of N is speci ed by ref int and the i-th literal is the rst one present.

then I is assigned to N: otherwise,

the event routine corresponding to on value error is called;

if this returns false, unde ned is called;

the insertion of P is staticized and performed.

cc)A literal is \searched for" by reading characters and matching them against successive characters of the literal. If the end of the current line or the logical end of the le is reached, or if a character fails to match, the search is unsuccessful and the current position is returned to where it started from.

dd)A value V is output using a picture P whose pattern Q was yielded by a boolean-choice-pattern C as follows:

the insertion of Q is staticized and performed:

If the mode of V is speci ed by bool, then

if V is true (false), the literal yielded by the rst (second) constituent literal of C is staticized and performed:

otherwise,

the event routine corresponding to on value error is called;

if this returns false, V is output using put and unde ned is called;

the insertion of P is staticized and performed.

ee)A value is input to a name N using a picture P whose pattern Q was yielded by a boolean-choice-pattern C as follows:

the insertion of Q is staticized and performed;

201

Section

ALGOL 68 Revised Report

A3492

each of the literals yielded by the constituent literals of C is staticized and searched for in turn:

If the mode of N is speci ed by ref bool, and the rst second) insertion is present,

then true (false) is assigned to N: otherwise,

the event routine corresponding to on value error is called;

if this returns false, unde ned is called;

the insertion of P is staticized and performed.g

10.3.4.8.2. Semantics

The yield of a choice-pattern P is a structured value W whose mode isCPATTERN , determined as follows:

let n be the number of constituent NEST-literals of the praglit-list-pack of P;

let Si, i = 1; : : : ; n, be a NEST-insertion akin f1.1.3.2.kg to the i-th of those constituent NEST-literals:

the insertion I of P and all of S1; : : : ; Sn are elaborated collaterally:

the elds of W, taken in order, are

fig the yield of I:

ftypeg 1 (2) if P is a boolean- (integral-) -choice-pattern;

fcg a multiple value whose mode is row of INSERTION , having a descriptor ((1; n)) and n elements, that selected by (i); i = 1; : : : n, being the yield of Si.

10.3.4.9. Format patterns

10.3.4.9.1. Syntax

a) NEST format patternfA341cg :

NEST insertionfA341dg, letter ff94ag symbol, meek FORMAT NEST ENCLOSED clausef31a,34ag, pragmentf92ag sequence option.

fExamples:

f(a)uir j (int): $5d$, (real ): $d.3d$ )

g

fA format-pattern may be used to provide formats dynamically for use in transput. When a format pattern is encountered during a call of get next picture, it is staticized and its insertion is performed. The rst picture of the format returned by the routine of the pattern is supplied as the next picture, and subsequent pictures are taken from that format until it has been exhausted.g

202

SectionA34A1

van Wijngaarden, et al.

10.3.4.9.2. Semantics

The yield, in an environ E, of a NEST-format-pattern P is a structured value whose mode is FPATTERN and whose elds, taken in order, are

fig the yield of its insertion;

fpfg a routine whose mode is procedure yielding FORMAT , composed of a procedure-yielding-FORMAT-NEST-routine-text whose unit U is a new unit akin f1.1.3.2.kg to the meek-FORMAT-ENCLOSED-clause of P, together with the environ necessary for U in E.

10.3.4.10. General patterns

10.3.4.10.1. Syntax

a)NEST general patternfA341cg : NEST insertionfA341dg, letter gf94ag symbol, NEST width speci cationfbg option.

b)NEST width speci cationfag : brief beginf94fg token ;

meek integral NEST unitf32dg, NEST after speci cationfcg option, brief endf94fg token, pragmentf92ag sequence option.

c) NEST after speci cationfbg : and alsof94fg token,

meek integral NEST unitf32dg, NEST exponent speci cationfdg option.

d) NEST exponent speci cationfcg :

and alsof94fg token, meek integral NEST unitf32dg.

fExamples:

a)g g(-18, 12, -3)

b)-18, 12, -3

c), 12, -3

d), -3 g

f aa) A value V is output using a picture P whose pattern Q was yielded by a general-pattern G as follows:

P is staticized;

the insertion of Q is performed;

If Q is not parametrized (i.e., Q contains no width-speci cation). then V is output using put;

otherwise, if the mode of V is speci ed by L int or L real , then

if Q contains one (two, three) parameter(s), V is converted to a string using whole ( xed, oat);

the string is written using put;

otherwise,

203

Section

ALGOL 68 Revised Report

A35

the event routine corresponding to on value error is called;

if this returns false, V is output using put, and unde ned is called;

the insertion of P is performed.

bb)A value is input to a name N using a picture P whose pattern is ageneral pattern as follows:

P is staticized;

(any parameters are ignored and) the value is input to N using get.g

10.3.4.10.2. Semantics

The yield, in an environ E, of a NEST-general-pattern P is a structured value whose mode is GPATTERN and whose elds, taken in order, are

fig the yield of the insertion of P:

fspecg a multiple value W whose mode is row of procedure yielding integral , having a descriptor ((1; n)), where n is the number of constituent meek-integral-units of the width-speci cation-option of P, and n elements determined as follows:

For i = 1 : : : n,

the i-th element of W is a routine, whose mode is procedure yielding integral , composed of a procedure-yielding-integral-NEST-routine- text whose unit U is a new unit akin f1.1.3.2.kg to the i-th of those meek-integral-units, together with the environ necessary for U in E.

10.3.5. Formatted transput

a)mode format = struct( ex [1: 0] piece F);

mode @piece = struct(int cp /c pointer to current collection /c, count /c number of times piece is to be repeated/c,

bp /c back pointer/c,

ex [1:0] collection c);

mode @collection = union(picture, collitem); mode @collitem = struct(insertion i1,

proc int rep; /c replicator /c,

int p /c pointer to another piece /c, insertion i2);

mode @insertion = ex [1:0] struct(proc int rep /c replicator /c, union(string, char) sa);

mode @picture = struct(union(pattern,cpattern,fpattern,gpattern,void)p, insertion i );

mode @pattern = struct(int type /c of pattern /c,ex [1:0] frame frames),

mode @frame = struct(insertion,

204

SectionA35 van Wijngaarden, et al.

proc int rep /c replicator /c,

bool supp /c true if suppressed /c, char marker);

mode @cpattern = struct(insertion i, int type /c boolean or integral /c,

ex [1:0] insertion c);

mode @fpattern = struct(insertion i, proc format pf);

mode @gpattern = struct(insertion i, ex [1:0] proc int spec);

b) proc @get next picture = (ref le , bool read, ref picture picture)void: begin

bool picture found := false, format ended := false; while :picture found

do if forp of f = 0 then if format ended then unde ned

elif :(format mended of f)(f) else format ended :=true

else

ref int forp = forp of f;

ref ex [ ] piece aleph = F of format of f; case (c of aleph [forp])[cp of aleph [forp]] in

(collitem cl):

([1:upb(i1 of cl)] sinsert si;

bp of aleph[p of cl] := forp; forp := skip; (staticize insertion(i1 of cl, si ),

count of aleph [p of cl] := 0;

(aleph :/=: F of format of f j unde ned);

(read j get insertion(f, si ) j put insertion(f, si )); cp of aleph[p of cl] := 0;

forp := p of cl),

(picture pict): (picture found := true; picture := pict) esac;

while

(forp /= 0 j cp of aleph[forp] = upb c of aleph[forp]) j false)

do if (count of aleph[forp] -:= 1) 0 then

if (forp := bp of aleph [forp]) /= 0 then

205

Section

ALGOL 68 Revised Report

A35

insertion extra =

case (c of aleph [forp])[cp of aleph [forp]] in

(collitem cl):

(bp of aleph [p of cl] := 0; i2 of cl), (picture pict):

case p of pict in (fpattern fpatt):

(int k := forp;

while bp of aleph [k ] /= forp do k +:= 1 od; aleph := aleph [:k-1];

i of pict) esac

esac;

int m = upb i of picture, n = upb extra;

[1:m+n] struct(proc int rep, union(string,char) sa)c; c[1:m] := i of picture; c[m+1:m+n] := extra;

i of picture := c

else cp of aleph [forp] := 0

od;

(forp /= 0 j cp of aleph [forp] +:= 1)

od

end;

c)mode @sinsert = struct(int rep, union(string , char) sa);

d)proc @staticize insertion = (insertion ins, ref [ ] sinsert sins)void: /c calls collaterally all the replicators in 'frames' /c

if upb ins = 1 then

rep of sins[1] := rep of ins[1]; sa of sins[1] := so of ins[1]

elif upb ins > 1

then staticize insertion(ins [1], sins [1]), staticize insertion(ins [2:], sins [2:])

;

e)mode @sframe = struct( ex[1:0]sinsert si, int rep, bool supp, char marker);

f)proc @staticize frames =

([ ] frame frames, ref [ ] sframe sframes)void:

/c calls collaterally all the replicators in 'frames' /c

206

SectionA35 van Wijngaarden, et al.

if upb frames = 1 then

[ 1: upb(i of frames [1 ]) ] sinsert si; (staticize insertion(i of frames [1], si ),

rep of sframes [1 ] := rep of frames [1]); si of sframes [1]:= si;

supp of sframes [1] := supp of frames [1]; marker of sframes [1] := marker of frames[1]

elif upb frames > 1

then (staticize frames(frames [1], sframes [1]). staticize frames(frames [2: ], sframes [2: ]))

;

g) proc @put insertion = (ref le f, [ ] sinsert si )void: begin set write mood(f);

for k to upb si do

case sa of si[k ] in

(char a): alignment(f, rep of si [k ], a, false), (string s):

to rep of si[k ] do

for i to upb s

do checkpos(f); putchar(f, s[i ]) od

od

esac

od end;

h) proc @get insertion (ref le f, [ ] sinsert si )void: begin set read mood(f);

for k to upb si do

case sa of si[k ] in

(char a): alignment(f, rep of si [k ], a, true), (string s):

(char c;

to rep of si[k ] do

for i to upb s

do checkpos(f); get char(f, c); (c /= s[i ]

207

Section

ALGOL 68 Revised Report

A35

j (:(char error mended of f)(f, c := s[i ]) j unde ned);

set read mood(f))

od

od)

esac

od end;

i)proc @alignment(ref le f, int r, char a, bool read)void: if a = }x} then to r do space(f) od

elif a = }y} then to r do backspace(f) od elif a = }I} then to r do newline(f) od elif a = }p} then to r do newpage(f) od elif a = }k} then set char number(f, r) elif a = }q}

then to r do

if read

then char c; checkpos(f); get char(f, c); (c /= blank

j (:(char error mended of f)(f, c := blank ) j unde ned); set read mood(f))

else checkpos(f); put char(f, blank )

od

;

j)proc @do fpattern = (ref le f, fpattern fpattern, bool read)void: begin format pf;

[1:upb(i of fpattern)] sinsert si; (staticize insertion(i of fpattern, si ),

pf := pf of fpattern),

(read j get insertion(f, si ) j put insertion(f, si )); ref int forp := forp of f;

ref ex[ ]piece aleph =F of format of f; int m = upb aleph, n = upb(F of pf);

[ 1:m+n] piece c; c[1:m] := aleph; c[m+1:m+n] := F of pf;

aleph := c; bp of aleph [m+1] := forp; forp := m+1; cp of aleph [forp] := 0; count of aleph [forp] := 1;

208

SectionA351

van Wijngaarden, et al.

for i from m+1 to m+n do

for j to upb c of aleph [i ] do

case(c of aleph [i ])[j ] in (collitem cl):

(c of aleph[i ])[j ] :=

collitem(il of cl, rep of cl, p of cl + m, i2 of cl)

esac

od

od end;

k) proc @associate format = (ref le f, format format)void: begin

format of f:=

C a newly created name which is made to refer to the yield of an actual-format-declarer and whose scope is equal to the scope of the value yielded by 'format' C

:= format; forp of f := heap int := 1;

cp of (F of format of f)[1] := 1; count of (F of format of f) [1] := 1; bp of (F of format of f) [1] := 0

end;

10.3.5.1. Formatted output

a) proc putf = (ref le f, [ ] union(outtype, format) x)void: if opened of f then

for k to upb x

do case set write mood(f); set char mood(f); x[k ] in (format format): associate format(f, format), (outtype ot):

begin int j := 0;

picture picture, [ ] simplout y = straightout ot; while (j +:= 1) upb y

do bool incomp := false;

get next picture(f, false, picture); set write mood(f);

[1:upb(i of picture) ] sinsert sinsert; case p of picture in

209

Section

ALGOL 68 Revised Report

A351

 

(pattern pattern):

 

 

 

begin int rep, sfp := 1;

 

 

 

[1:upb(frames of pattern)]sframe sframes;

 

 

staticize frames (frames of pattern, sframes),

 

 

staticize insertion (i of picture, sinsert));

 

 

string s;

 

 

 

op ? = (string s)bool:

 

 

 

/c true if the next marker is one of the elements of 's'

 

and false otherwise /c

 

 

 

if sfp > upb sframes

 

 

 

then false

 

 

 

else sframe sf = sframes [sfp];

 

 

rep := rep of sf:

 

 

 

if char in string(marker of sf, loc int, s)

 

 

then sfp +:= 1; true

 

 

 

else false

 

 

 

 

 

 

 

;

 

 

 

op ? = (char c)bool: ? string (c);

 

 

proc int pattern(ref bool sign mould)int:

 

 

(int l := 0;

 

 

 

while ?}zuv} do (rep 0 j l +:= rep) od;

 

 

sign mould of := ?}+-};

 

 

while ?}zd} do (rep 0 j l +:= rep) od; l);

 

 

:

 

 

 

hproc edit ` int(L int i )void

 

 

 

(bool sign mould; int l := int pattern(sign mould);

 

string t = subwhole(abs i, l);

 

 

if char in string(errorchar, loc int, t) _ l = 0

 

 

_ :sign mould ^ i < L 0

 

 

then incomp := true

 

 

 

else t plusto s;

 

 

 

(l upb t) }0} plusto s;

 

 

(sign mould j (i < L 0 j }-} j }+}) plusto s)

 

 

)i;

:

 

 

hproc edit ` real(L real r)void

 

 

(int b := 0, a := 0, c := 0, exp := 0, L real y := abs r, bool sign1, string point := }};

b := int pattern(sign1);

(?}.} j a := int pattern(loc bool); point := }.}); if ?}c}

210