*line 1: Unknown output type = >$A include=template_file IMP Core Environment Standard Section 7: "Derived" I/O Procedures The procedures in this section are all expressed as definitions in the IMP language. In addition, all are defined in terms of procedures either in this or the previous sections of this document. * predicate END OF INPUT _________ This predicate is true if and only if examining the next ____ symbol in the currently selected input stream would cause an input ended event (SIG0003; Input Ended) to be signalled. The most common cause of this is that there is no next symbol available, implying that the input stream is positioned after the last available character of data. predicate End Of Input _________ from IMP include Events ____ _______ integer Dummy _______ on Input Ended start __ _____ true ____ finish ______ Dummy = Next Symbol false _____ end ___ * routine READ ( name N ) _______ ____ routine Read ( name X ) _______ ____ from IMP include TYPES {see section 11} ____ _______ integer T = Type Of(X) _______ routine Skip White Space _______ Skip Symbol while Next Symbol <= 32 _____ end ___ if T = String Type start __ _____ Skip White Space if Next Symbol = '"' start __ _____ Skip Symbol {read up to next '"'} else ____ {read up until next symbol = white space} finish ______ {assign or give signal if result is} ______ {too big for destination} else if Its An Integer ____ __ Skip White Space {parse integer value} {assign or give signal if result is} ______ {too big for destination} else if Its A Real ____ __ 7-1 Skip White Space {parse real value} {assign or give signal if too big for destination} ______ else ____ {parameter error: cry for help} signal 5, 3, T {check numbers later} ______ finish ______ end ___ Notes on the above definition of READ: 1) skip white space AFTER check for legal parameter. 2) signal guaranteed if bad parameter type NOT error. ______ 3) signal guaranteed if integer value valid but too big ______ for destination. 4) white space now excludes extended ASCII graphics set. Semi-formal grammar for string case: ______ string body = """", { ?any char?-"""" }, """" | { ?any char > 32? } ; read S format = white space, string body ; Grammar for integer case and real case would be the S TO I _______ ____ grammar and the S TO R grammar, with in each case the trailing white space removed. * routine READ LINE ( string(*) name S ) _______ ______ ____ This procedure reads a text "line" from the currently selected input stream, up to and including its terminating NL character. The parameter is a reference to a string which is built up with this sequence of characters as they are read in, implying that the parameter will contain a valid string even though the READ LINE procedure fails for some reason, for example because the end of the currently selected input stream has been reached. Note that the terminating NL character is not ___ included in the data assigned to the parameter. routine Read Line ( string(*) name S ) _______ ______ ____ integer Sym _______ S = "" cycle _____ Read Symbol(Sym) return if Sym = NL ______ __ signal ... if Length(S) = Size Of(S)-1 ______ __ S = S . To String(Sym) repeat ______ end ___ 7-2 * routine NEW LINE _______ As indicated in the definition below, this procedure is simply a shorthand for a call on the PRINT SYMBOL procedure with the predefined constant NL as parameter. As mentioned in the previous section, the effect of this operation is defined by the stream facility associated with the currently selected output stream. Commonly, for example on streams created using OPEN OUTPUT, this character is defined as indicating the end of a "line" of text output. Other stream facilities, for example OPEN BINARY OUTPUT, will treat the character NL in the same way as any other character, that is simply as an 8-bit data item of a particular value. routine New Line _______ Print Symbol(NL) end ___ * routine NEW LINES ( integer N ) _______ _______ This procedure causes a number 'N' of NL characters to be output to the currently selected output stream. The effect of this, as with NEW LINE above, is dependent on the stream facility with which the output stream was created. Note that, in the definition below, no action is taken if the value of N is less than or equal to 0. routine New Lines ( integer N ) _______ _______ while N > 0 cycle _____ _____ N = N-1 New Line repeat ______ end ___ * routine SKIP SYMBOL _______ routine Skip Symbol _______ integer Dummy _______ Read Symbol(Dummy) end ___ * routine SPACE _______ routine Space _______ Print Symbol(32) end ___ 7-3 * routine SPACES ( integer N ) _______ _______ routine Spaces ( integer N ) _______ _______ while N > 0 cycle _____ _____ N = N-1 Space repeat ______ end ___ * routine PRINT STRING ( string(255) S ) _______ ______ routine Print String ( string(255) S ) _______ ______ integer I _______ for I = 1, 1, Length(S) cycle ___ _____ Print Symbol(Charno(S,I)) repeat ______ end ___ * routine PRINT ( long real R, integer A, B ) _______ ____ ____ _______ routine Print ( long real R, integer A, B ) _______ ____ ____ _______ Print String(RtoS(R,A,B)) end ___ * routine PRINT FLOATING ( long real R, integer A, B ) _______ ____ ____ _______ routine Print Floating ( long real R, integer A, B ) _______ ____ ____ _______ Print String(FtoS(R,A,B)) end ___ * routine PRINT FL ( long real R, integer A ) _______ ____ ____ _______ routine Print Fl ( long real R, integer A ) _______ ____ ____ _______ Print Floating(R,1,A) end ___ * routine WRITE ( integer N, Places ) _______ _______ routine Write ( integer N, Places ) _______ _______ Print String(ItoS(N,Places)) end ___ End of input file Program stopped