170/van Wijngaarden, etal.ALGOL <strong>68</strong> Revised Report 171else undefined; cfi;set read mood (f)fi;op ! = (char s, c) char: string (s) ! c;proc skip initial spaces = void :while (k empty I next pos (f)); .9 ,.,, do skip od;proc skip spaces = void :while ? "." do skip od;proc read dig = string :(string t := "0123456789"! "0";while ? "0123456?89" do t plusab k od; t);proc read sign = char :(char t = (skip spaces; ? "+-"1 k I "+");skip spaces; t);proc read num = string :(char t = read sign; t + read dig);proc read real = string :(string t : = read sign;(" ? "."t t plusab read dig I k empty : = false);(.9 "."1 t plusab "." + read dig);(? "lo\e" l t plusab "1o" + read num); t);for) to upb ydo bool incomp : = false; k empty : = true;case y [j ] in~ (ref L int ii):(skip initial spaces;incomp := - string to Lint (read num, 10, ii))~ ,(ret L real rr):(skip initial spaces;incomp : = - string to L real (read real, rr)) 2 ,(ref L compl zz):(skip initial spaces;incomp := - string to L real (read real, re of zz);skip spaces; "i_L " ! ".L ";incomp : = incomp vstring to L real (read real, im of zz)) ~ ,(ref bool bb):(skip initial spaces;bb := (flip + flop) ! flop = flip),~ (ref L bits lb):for i to L bits widthdo get (f, (L F of lb) [ i]) od~ ,(ref char cc): (next pos (f); get char (f, cc)) ,(ref [ ] char ss):b)for i from Iwb ss to upb ssdo next pos (f); get char (f, ss [ i ]) od ,(ref string ss):begin string t;while check pos (f);if line ended (f) v logical file ended (f)then falseelse get char (f, k);k empty := - char in string (k, Ioc int, term off)fldo t plusab k od;SS :=tendesac;(- k empty l backspace (f));if incompthen (- (value error mended off) (f) I undefined);set read mood (f)fiodendesac odelse undefinedfl;proc .~ get char = (ref file f, ref char char) void :if opened off ^ - line ended (f) ^ - logical file ended (f)then ref pos cpos = cpos off;set char mood (f); set read mood (f);int p = p of cpos, l = l of cpos, c = c of cpos;c of cpos + : = 1;char : = case text of fin(lexttl): tl [p] [lJ [cJ,(flextext t2):(chark := t2 lP] Ill lcl;bool found : = false;for i to upb F of conv off while - founddo struct (char internal, external) key = (F of cony of f) [ i ];(external of key = k I k : = internal of key; found : = true)od;if found then kelse k := ". ";if(char error mended off) (f, k)then kelse undefined; "."fi;
172 van Wijngaarden, etal.ALGOL <strong>68</strong> Revised Report173set read mood (f)fi)esacelse undefinedfi ¢ read mood is still set ¢ ;c) proc ~ check pos = (ref file D void :begin bool reading = read mood off;bool not ended : = true;while not ended : = not ended ^ get good page (f, reading);line ended (f) ^ not endeddo not ended : = (line mended off) (f) odend;{The routine check pos is used in formatted transput before each call ofput char or get char. If the position is not good (10.3.1.6.dd), it calls theappropriate event routine, and may call further event routines if true isreturned. If the event routine corresponding to on page end returns false,newpage is called but, if any other event routine returns false, no defaultaction is taken and no more event routines are called. On exit, theread/write mood is as on entry, but the current position may not be good,in which case undefined will be called in the following put char or getchar. However, check pos is also called when getting strings (hh), in whichcase the string is then terminated if the current position is not good.}10.3.4. Format texts{In formatted transput, each straightened value from a data list(cf. 10.3.3) is matched against a constituent picture of a format-textprovided by the user. A picture specifies how a value is to be converted toor from a sequence of characters and prescribes the layout of thosecharacters in the book. Features which may be specified include thenumber of digits, the position of the decimal point and of the sign, if any,suppression of zeroes and the insertion of arbitrary strings. For example,using the picture -d.3d "." 3d "." e z+d, the value 1234.567 would betransput as the string ".1.234.567.1o.+3".A "format" is a structured value (i.e., an internal object) of mode'FORMAT', which mirrors the hierarchical structure of a format-text(which is an external object). In this section are given the syntax offormat-texts and the semantics for obtaining their corresponding formats.The actual formatted transput is performed by the routines given insection 10.3.5 but, for convenience, a description of their operation is givenhere, in association with the corresponding syntax.}10.3.4.1. Collections and pictures10.3.4.1.1. Syntax{The following mode-declarations (taken from 10.3.5.a) are reflected inthe metaproduction rules A to K below.A) mode format = struct (flex [1 : O ] piece F) ;B) mode piece = struct (int cp, count, bp, flex [ 1 : 0 ] collection c) ;C) mode collection =union (picture, collitem) ;D) mode collitem =struct (insertion il, proc int rep, int p, insertion i2);E) mode insertion =flex [1 : O] struct (proc int rep, union (string, char) sa) ;F) mode picture = struct(union (pattern, cpattern, fpattern, gpattern, void) p, insertion i);G) mode pattern = struct (int type, flex [1 : O] frame frames);H) mode frame =struct (Insertion i, proc int rep, bool supp, char marker) ;I) mode cpattern =struct (insertion i, int type, flex [1 : O] insertion c);J) mode fpattern = struct (insertion i, proc format pf) ;K) mode gpattern = struct (inserUon i, flex [1 : O] proc int spec) ; }A) FORMAT :: structured with row of PIECE field letter aleph mode.B) PIECE :: structured with integral field letter c letter pintegral field letter c letter o letter u letter n letter tintegral field letter b letter prow of COLLECTION field letter c mode.C) COLLECTION :: union of PICTURE COLLITEM mode.D) COLLITEM :: structured with INSERTION field letter i digit oneprocedure yielding integral field letter r letter e letter pintegral field letter pINSERTION field letter i digit two mode.E) INSERTION :: row of structured with procedure yielding integralfield letter r letter e letter punion of row of character character mode fieldletter s letter a mode.F) PICTURE :: structured with union ofPATTERN CPATTERN FPATTERN GPATTERN void modefield letter p INSERTION field letter i mode.G) PATTERN :: structured withintegral field letter t letter y letter p letter erow of FRAME fieldletter f letter r letter a letter m letter e letter s mode.H) FRAME :: structured with INSERTION field letter iprocedure yielding integral field letter r letter e letter pboolean field letter s letter u letter p letter p character fieldletter m letter a letter r letter k letter e letter r mode.I) CPATTERN :: structured with INSERTION field letter iintegral field letter t letter y letter p letter erow of INSERTION field letter c mode.
- Page 2 and 3:
van Wijngaarden, et al.1.1.4.2. Par
- Page 4:
Acknowledgements{Habent sua fata li
- Page 8 and 9:
14 van Wijngaarden, et al.0.3.4. Mo
- Page 10 and 11:
. . . . . . . 4 " ' 0 . . . . . . .
- Page 12 and 13:
22 van Wijngaarden, et al.• let P
- Page 14 and 15:
26 van Wijngaarden, et al.{Since so
- Page 16 and 17:
30 van Wijngaarden, et aLloperandfo
- Page 18 and 19:
34 van Wijngaarden, et al.j) WHETHE
- Page 20 and 21:
38 van Wijngaarden, et al.A protono
- Page 22 and 23:
42 van Wijngaarden, et al.d) If N i
- Page 24 and 25:
46 van Wijngaarden, et al.c) {There
- Page 26 and 27:
50 van Wijngaarden, et al.c) The ph
- Page 28 and 29:
54 van Wijngaarden, et al.3.1.1. Sy
- Page 30 and 31:
58 van Wijngaarden, et al.where (RO
- Page 32 and 33:
62 van Wijngaarden, et al.1) SOlD N
- Page 34 and 35:
66 van Wijngaarden, et al.ALGOL 68
- Page 36 and 37: 70 van Wijngaarden, et el.For each
- Page 38 and 39: 74 van Wijngaarden, et al.If 'MODE"
- Page 40 and 41: 78 J van Wijngaarden, et al.C) SECO
- Page 42 and 43: 82 van Wijngaarden, et al.ALGOL 68
- Page 44 and 45: 86 van Wijngaarden. et al.ALGOL 68
- Page 46 and 47: 90 van Wijngaarden, et al.5.4.4.1.
- Page 48 and 49: 94van Wijngaarden, et al.ALGOL 68 R
- Page 50 and 51: 98 van Wijngaarden, et al.Assignati
- Page 52 and 53: 102 van Wijngaarden, et at.{A nest,
- Page 54 and 55: 106 van Wijngaarden, et al.'HEAD's
- Page 56 and 57: 110 van Wijngaarden, et al.ALGOL 68
- Page 58 and 59: 114van Wijngaarden, et al.ALGOL 68
- Page 60 and 61: 118 van Wijngaarden, et al.ALGOL 68
- Page 62 and 63: 122 van Wijngaarden, et al.style ii
- Page 64 and 65: 126 van Wijngaarden, et al.b) The c
- Page 66 and 67: 130van Wijngaarden, et al.ALGOL 68
- Page 68 and 69: 134van Wijngaarden, et al.ALGOL 68
- Page 70 and 71: 138d)e)f)g)h)i)J)k)1)m)n)van Wijnga
- Page 72 and 73: 142 van Wijngaarden, et al.physics
- Page 74 and 75: 146 van Wijngaarden, et al.gg) On s
- Page 76 and 77: 150van Wijngaarden, et al.ALGOL 68
- Page 78 and 79: 154/van Wijngaarden, et al.ALGOL 68
- Page 80 and 81: 158 van Wijngaarden, et el.fi;ref p
- Page 82 and 83: 162van Wijngaarden, et al.ALGOL 68
- Page 84 and 85: 166van Wijngaarden, et al.ALGOL 68
- Page 88 and 89: 174J)K)L)M)N)O)P)a)b)c)d)e)van Wijn
- Page 90 and 91: 178/van Wijngaarden, et al.ALGOL 68
- Page 92 and 93: 182 van Wijngaarden, et al.• let
- Page 94 and 95: 186van Wijngaarden, et al./ALGOL 68
- Page 96 and 97: 190 van Wijngaarden, etal.composed
- Page 98 and 99: 194h)i)J)van Wijngaa(rden, et al.pr
- Page 100 and 101: 198 van Wijngaarden, et al.¢ strin
- Page 102 and 103: 202tvan Wijngaarden, et al.ALGOL 68
- Page 104 and 105: 206 van Wijngaa~den. et al.10.3.6.1
- Page 106 and 107: 210 van Wijngaarden, et al.!ALGOL 6
- Page 108 and 109: 214 van Wijngaarden, et al.inoperat
- Page 110 and 111: 218fvan Wijngaarden, et al.¢ move
- Page 112 and 113: 222 van Wijngaarden, etaL{overflow}
- Page 114 and 115: 226 van Wijngaarden, et al.ALGOL 68
- Page 116 and 117: 230max int 10.2.1.cmax real 10.2.l.
- Page 118 and 119: 234 van Wijngaarden, et al.ALGOL 68