DEFINITIONMODULECharClass; (* Classification of values of the typeCHAR*)PROCEDUREIsNumeric (ch:CHAR):BOOLEAN; (* ReturnsTRUEif and only if ch is classified as a numeric character *)PROCEDUREIsLetter (ch:CHAR):BOOLEAN; (* ReturnsTRUEif and only if ch is classified as a letter *)PROCEDUREIsUpper (ch:CHAR):BOOLEAN; (* ReturnsTRUEif and only if ch is classified as an upper case letter *)PROCEDUREIsLower (ch:CHAR):BOOLEAN; (* ReturnsTRUEif and only if ch is classified as a lower case letter *)PROCEDUREIsControl (ch:CHAR):BOOLEAN; (* ReturnsTRUEif and only if ch represents a control function *)PROCEDUREIsWhiteSpace (ch:CHAR):BOOLEAN; (* ReturnsTRUEif and only if ch represents a space character or a format effector *)ENDCharClass.DEFINITIONMODULEStrings; (* Facilities for manipulating strings *)TYPEString1 =ARRAY[0..0]OFCHAR; (* String1 is provided for constructing a value of a single-character string type from a single character value in order to passCHARvalues toARRAYOFCHARparameters. *)PROCEDURELength (stringVal:ARRAYOFCHAR):CARDINAL; (* Returns the length of stringVal (the same value as would be returned by the pervasive function LENGTH). *) (* The following seven procedures construct a string value, and attempt to assign it to a variable parameter. They all have the property that if the length of the constructed string value exceeds the capacity of the variable parameter, a truncated value is assigned, while if the length of the constructed string value is less than the capacity of the variable parameter, a string terminator is appended before assignment is performed. *)PROCEDUREAssign (source:ARRAYOFCHAR;VARdestination:ARRAYOFCHAR); (* Copies source to destination *)PROCEDUREExtract (source:ARRAYOFCHAR; startIndex, numberToExtract:CARDINAL;VARdestination:ARRAYOFCHAR); (* Copies at most numberToExtract characters from source to destination, starting at position startIndex in source. *)PROCEDUREDelete (VARstringVar:ARRAYOFCHAR; startIndex, numberToDelete:CARDINAL); (* Deletes at most numberToDelete characters from stringVar, starting at position startIndex. *)PROCEDUREInsert (source:ARRAYOFCHAR; startIndex:CARDINAL;VARdestination:ARRAYOFCHAR); (* Inserts source into destination at position startIndex *)PROCEDUREReplace (source:ARRAYOFCHAR; startIndex:CARDINAL;VARdestination:ARRAYOFCHAR); (* Copies source into destination, starting at position startIndex. Copying stops when all of source has been copied, or when the last character of the string value in destination has been replaced. *)PROCEDUREAppend (source:ARRAYOFCHAR;VARdestination:ARRAYOFCHAR); (* Appends source to destination. *)PROCEDUREConcat (source1, source2:ARRAYOFCHAR;VARdestination:ARRAYOFCHAR); (* Concatenates source2 onto source1 and copies the result into destination. *) (* The following predicates provide for pre-testing of the operation-completion conditions for the procedures above. *)PROCEDURECanAssignAll (sourceLength:CARDINAL;VARdestination:ARRAYOFCHAR):BOOLEAN; (* Returns TRUE if a number of characters, indicated by sourceLength, will fit into destination; otherwise returns FALSE. *)PROCEDURECanExtractAll (sourceLength, startIndex, numberToExtract:CARDINAL;VARdestination:ARRAYOFCHAR):BOOLEAN; (* Returns TRUE if there are numberToExtract characters starting at startIndex and within the sourceLength of some string, and if the capacity of destination is sufficient to hold numberToExtract characters; otherwise returns FALSE. *)PROCEDURECanDeleteAll (stringLength, startIndex, numberToDelete:CARDINAL):BOOLEAN; (* Returns TRUE if there are numberToDelete characters starting at startIndex and within the stringLength of some string; otherwise returns FALSE. *)PROCEDURECanInsertAll (sourceLength, startIndex:CARDINAL;VARdestination:ARRAYOFCHAR):BOOLEAN; (* Returns TRUE if there is room for the insertion of sourceLength characters from some string into destination starting at startIndex; otherwise returns FALSE. *)PROCEDURECanReplaceAll (sourceLength, startIndex:CARDINAL;VARdestination:ARRAYOFCHAR):BOOLEAN; (* Returns TRUE if there is room for the replacement of sourceLength characters in destination starting at startIndex; otherwise returns FALSE. *)PROCEDURECanAppendAll (sourceLength:CARDINAL;VARdestination:ARRAYOFCHAR):BOOLEAN; (* Returns TRUE if there is sufficient room in destination to append a string of length sourceLength to the string in destination; otherwise returns FALSE. *)PROCEDURECanConcatAll (source1Length, source2Length:CARDINAL;VARdestination:ARRAYOFCHAR):BOOLEAN; (* Returns TRUE if there is sufficient room in destination for a two strings of lengths source1Length and source2Length; otherwise returns FALSE. *) (* The following type and procedures provide for the comparison of string values, and for the location of substrings within strings. *)TYPECompareResults = (less, equal, greater);PROCEDURECompare (stringVal1, stringVal2:ARRAYOFCHAR): CompareResults; (* Returns less, equal, or greater, according as stringVal1 is lexically less than, equal to, or greater than stringVal2. *)PROCEDUREEqual (stringVal1, stringVal2:ARRAYOFCHAR):BOOLEAN; (* Returns Strings.Compare(stringVal1, stringVal2) = Strings.equal *)PROCEDUREFindNext (pattern, stringToSearch:ARRAYOFCHAR; startIndex:CARDINAL;VARpatternFound:BOOLEAN;VARposOfPattern:CARDINAL); (* Looks forward for next occurrence of pattern in stringToSearch, starting the search at position startIndex. If startIndex < LENGTH(stringToSearch) and pattern is found, patternFound is returned as TRUE, and posOfPattern contains the start position in stringToSearch of pattern. Otherwise patternFound is returned as FALSE, and posOfPattern is unchanged. *)PROCEDUREFindPrev (pattern, stringToSearch:ARRAYOFCHAR; startIndex:CARDINAL;VARpatternFound:BOOLEAN;VARposOfPattern:CARDINAL); (* Looks backward for the previous occurrence of pattern in stringToSearch and returns the position of the first character of the pattern if found. The search for the pattern begins at startIndex. If pattern is found, patternFound is returned as TRUE, and posOfPattern contains the start position in stringToSearch of pattern in the range [0..startIndex]. Otherwise patternFound is returned as FALSE, and posOfPattern is unchanged. *)PROCEDUREFindDiff (stringVal1, stringVal2:ARRAYOFCHAR;VARdifferenceFound:BOOLEAN;VARposOfDifference:CARDINAL); (* Compares the string values in stringVal1 and stringVal2 for differences. If they are equal, differenceFound is returned as FALSE, and TRUE otherwise. If differenceFound is TRUE, posOfDifference is set to the position of the first difference; otherwise posOfDifference is unchanged. *)PROCEDURECapitalize (VARstringVar:ARRAYOFCHAR); (* Applies the function CAP to each character of the string value in stringVar. *)ENDStrings.

The modules in this section can be employed to convert strings into the corresponding numeric values. They may (but are not necessarily) be called by routines in WholeIO, RealIO and LongIO to return their values, after (presumed) calls to TextIO.ReadToken.

DEFINITIONMODULEWholeStr; (* Whole-number/string conversions *)IMPORTConvTypes;TYPEConvResults = ConvTypes.ConvResults; (* strAllRight, strOutOfRange, strWrongFormat, strEmpty *) (* the string form of a signed whole number is ["+" | "-"], decimal digit, {decimal digit} *)PROCEDUREStrToInt (str:ARRAYOFCHAR;VARint:INTEGER;VARres: ConvResults); (* Ignores any leading spaces in str. If the subsequent characters in str are in the format of a signed whole number, assigns a corresponding value to int. Assigns a value indicating the format of str to res. *)PROCEDUREIntToStr (int:INTEGER;VARstr:ARRAYOFCHAR); (* Converts the value of int to string form and copies the possibly truncated result to str. *) (* the string form of an unsigned whole number is decimal digit, {decimal digit} *)PROCEDUREStrToCard (str:ARRAYOFCHAR;VARcard:CARDINAL;VARres: ConvResults); (* Ignores any leading spaces in str. If the subsequent characters in str are in the format of an unsigned whole number, assigns a corresponding value to card. Assigns a value indicating the format of str to res. *)PROCEDURECardToStr (card:CARDINAL;VARstr:ARRAYOFCHAR); (* Converts the value of card to string form and copies the possibly truncated result to str. *)ENDWholeStr.

DEFINITIONMODULERealStr; (*REAL/string conversions *)IMPORTConvTypes;TYPEConvResults = ConvTypes.ConvResults; (* strAllRight, strOutOfRange, strWrongFormat, strEmpty *) (* the string form of a signed fixed-point real number is ["+" | "-"], decimal digit, {decimal digit}, [".", {decimal digit}] *) (* the string form of a signed floating-point real number is signed fixed-point real number, "E", ["+" | "-"], decimal digit, {decimal digit} *)PROCEDUREStrToReal (str:ARRAYOFCHAR;VARreal:REAL;VARres: ConvResults); (* Ignores any leading spaces in str. If the subsequent characters in str are in the format of a signed real number, assigns a corresponding value to real. Assigns a value indicating the format of str to res. *)PROCEDURERealToFloat (real:REAL; sigFigs:CARDINAL;VARstr:ARRAYOFCHAR); (* Converts the value of real to floating-point string form, with sigFigs significant figures, and copies the possibly truncated result to str. *)PROCEDURERealToEng (real:REAL; sigFigs:CARDINAL;VARstr:ARRAYOFCHAR); (* Converts the value of real to floating-point string form, with sigFigs significant figures, and copies the possibly truncated result to str. The number is scaled with one to three digits in the whole number part and with an exponent that is a multiple of three. *)PROCEDURERealToFixed (real:REAL; place:INTEGER;VARstr:ARRAYOFCHAR); (* Converts the value of real to fixed-point string form, rounded to the given place relative to the decimal point, and copies the possibly truncated result to str. *)PROCEDURERealToStr (real:REAL;VARstr:ARRAYOFCHAR); (* Converts the value of real as RealToFixed if the sign and magnitude can be shown within the capacity of str, or otherwise as RealToFloat, and copies the possibly truncated result to str. The number of places or significant digits are implementation-defined. *)ENDRealStr.

DEFINITIONMODULELongStr; (*LONGREAL/string conversions *)IMPORTConvTypes;TYPEConvResults = ConvTypes.ConvResults; (* strAllRight, strOutOfRange, strWrongFormat, strEmpty *) (* the string form of a signed fixed-point real number is ["+" | "-"], decimal digit, {decimal digit}, [".", {decimal digit}] *) (* the string form of a signed floating-point real number is signed fixed-point real number, "E", ["+" | "-"], decimal digit, {decimal digit} *)PROCEDUREStrToReal (str:ARRAYOFCHAR;VARreal:LONGREAL;VARres: ConvResults); (* Ignores any leading spaces in str. If the subsequent characters in str are in the format of a signed real number, assigns a corresponding value to real. Assigns a value indicating the format of str to res. *)PROCEDURERealToFloat (real:LONGREAL; sigFigs:CARDINAL;VARstr:ARRAYOFCHAR); (* Converts the value of real to floating-point string form, with sigFigs significant figures, and copies the possibly truncated result to str. *)PROCEDURERealToEng (real:LONGREAL; sigFigs:CARDINAL;VARstr:ARRAYOFCHAR); (* Converts the value of real to floating-point string form, with sigFigs significant figures, and copies the possibly truncated result to str. The number is scaled with one to three digits in the whole number part and with an exponent that is a multiple of three. *)PROCEDURERealToFixed (real:LONGREAL; place:INTEGER;VARstr:ARRAYOFCHAR); (* Converts the value of real to fixed-point string form, rounded to the given place relative to the decimal point, and copies the possibly truncated result to str. *)PROCEDURERealToStr (real:LONGREAL;VARstr:ARRAYOFCHAR); (* Converts the value of real as RealToFixed if the sign and magnitude can be shown within the capacity of str, or otherwise as RealToFloat, and copies the possibly truncated result to str. The number of places or significant digits depend on the capacity of str. *)ENDLongStr.

There is no requirement in the standard that the high level conversion modules above depend on the low level ones presented below. However, they are available for those who wish to write their own string conversion routines.

DEFINITIONMODULEConvTypes; (* Common types used in the string conversion modules *)TYPEConvResults = (* Values of this type are used to express the format of a string *) (strAllRight, (* the string format is correct for the corresponding conversion *) strOutOfRange, (* the string is well-formed but the value cannot be represented *) strWrongFormat, (* the string is in the wrong format for the conversion *) strEmpty (* the given string is empty *) ); ScanClass = (* Values of this type are used to classify input to finite state scanners *) (padding, (* a leading or padding character at this point in the scan - ignore it *) valid, (* a valid character at this point in the scan - accept it *) invalid, (* an invalid character at this point in the scan - reject it *) terminator (* a terminating character at this point in the scan (not part of token) *) ); ScanState = (* The type of lexical scanning control procedures *)PROCEDURE(CHAR,VARScanClass,VARScanState);ENDConvTypes.

DEFINITIONMODULEWholeConv; (* Low-level whole-number/string conversions *)IMPORTConvTypes;TYPEConvResults = ConvTypes.ConvResults; (* strAllRight, strOutOfRange, strWrongFormat, strEmpty *)PROCEDUREScanInt (inputCh:CHAR;VARchClass: ConvTypes.ScanClass;VARnextState: ConvTypes.ScanState); (* Represents the start state of a finite state scanner for signed whole numbers -assigns class of inputCh to chClass and a procedure representing the next state to nextState. *)PROCEDUREFormatInt (str:ARRAYOFCHAR): ConvResults; (* Returns the format of the string value for conversion toINTEGER. *)PROCEDUREValueInt (str:ARRAYOFCHAR):INTEGER; (* Returns the value corresponding to the signed whole number string value str if str is well-formed; otherwise raises the WholeConv exception. *)PROCEDURELengthInt (int:INTEGER):CARDINAL; (* Returns the number of characters in the string representation of int. *)PROCEDUREScanCard (inputCh:CHAR;VARchClass: ConvTypes.ScanClass;VARnextState: ConvTypes.ScanState); (* Represents the start state of a finite state scanner for unsigned whole numbers - assigns class of inputCh to chClass and a procedure representing the next state to nextState. *)PROCEDUREFormatCard (str:ARRAYOFCHAR): ConvResults; (* Returns the format of the string value for conversion toCARDINAL. *)PROCEDUREValueCard (str:ARRAYOFCHAR):CARDINAL; (* Returns the value corresponding to the unsigned whole number string value str if str is well-formed; otherwise raises the WholeConv exception *)PROCEDURELengthCard (card:CARDINAL):CARDINAL; (* Returns the number of characters in the string representation of card. *)PROCEDUREIsWholeConvException ():BOOLEAN; (* ReturnsTRUEif the current coroutine is in the exceptional execution state because of the raising of an exception in a routine from this module; otherwise returnsFALSE. *)ENDWholeConv.

DEFINITIONMODULERealConv; (* Low-levelREAL/string conversions *)IMPORTConvTypes;TYPEConvResults = ConvTypes.ConvResults; (* strAllRight, strOutOfRange, strWrongFormat, strEmpty *)PROCEDUREScanReal (inputCh:CHAR;VARchClass: ConvTypes.ScanClass;VARnextState: ConvTypes.ScanState); (* Represents the start state of a finite state scanner for real numbers - assigns class of inputCh to chClass and a procedure representing the next state to nextState. *)PROCEDUREFormatReal (str:ARRAYOFCHAR): ConvResults; (* Returns the format of the string value for conversion toREAL. *)PROCEDUREValueReal (str:ARRAYOFCHAR):REAL; (* Returns the value corresponding to the real number string value str if str is well-formed; otherwise raises the RealConv exception. *)PROCEDURELengthFloatReal (real:REAL; sigFigs:CARDINAL):CARDINAL; (* Returns the number of characters in the floating-point string representation of real with sigFigs significant figures. *)PROCEDURELengthEngReal (real:REAL; sigFigs:CARDINAL):CARDINAL; (* Returns the number of characters in the floating-point engineering string representation of real with sigFigs significant figures. *)PROCEDURELengthFixedReal (real:REAL; place:INTEGER):CARDINAL; (* Returns the number of characters in the fixed-point string representation of real rounded to the given place relative to the decimal point. *)PROCEDUREIsRConvException ():BOOLEAN; (* ReturnsTRUEif the current coroutine is in the exceptional execution state because of the raising of an exception in a routine from this module; otherwise returnsFALSE. *)ENDRealConv.

DEFINITIONMODULELongConv; (* Low-levelLONGREAL/string conversions *)IMPORTConvTypes;TYPEConvResults = ConvTypes.ConvResults; (* strAllRight, strOutOfRange, strWrongFormat, strEmpty *)PROCEDUREScanReal (inputCh:CHAR;VARchClass: ConvTypes.ScanClass;VARnextState: ConvTypes.ScanState); (* Represents the start state of a finite state scanner for real numbers - assigns class of inputCh to chClass and a procedure representing the next state to nextState. *)PROCEDUREFormatReal (str:ARRAYOFCHAR): ConvResults; (* Returns the format of the string value for conversion toLONGREAL. *)PROCEDUREValueReal (str:ARRAYOFCHAR):LONGREAL; (* Returns the value corresponding to the real number string value str if str is well-formed; otherwise raises the LongConv exception. *)PROCEDURELengthFloatReal (real:LONGREAL; sigFigs:CARDINAL):CARDINAL; (* Returns the number of characters in the floating-point string representation of real with sigFigs significant figures. *)PROCEDURELengthEngReal (real:LONGREAL; sigFigs:CARDINAL):CARDINAL; (* Returns the number of characters in the floating-point engineering string representation of real with sigFigs significant figures. *)PROCEDURELengthFixedReal (real:LONGREAL; place:INTEGER):CARDINAL; (* Returns the number of characters in the fixed-point string representation of real rounded to the given place relative to the decimal point. *)PROCEDUREIsRConvException ():BOOLEAN; (* ReturnsTRUEif the current coroutine is in the exceptional execution state because of the raising of an exception in a routine from this module; otherwise returnsFALSE. *)ENDLongConv.

DEFINITIONMODULESysClock; (* ========================================= Original specification and design of SysClock Copyright © 1990-1991 by R. Sutcliffe Assigned to the BSI for standards work =========================================== *) (* Facilities for accessing a system clock that records the date and time of day *)CONSTmaxSecondParts = <implementation-defined integral value>;TYPEMonth = [1 .. 12]; Day = [1 .. 31]; Hour = [0 .. 23]; Min = [0 .. 59]; Sec = [0 .. 59]; Fraction = [0 .. maxSecondParts]; UTCDiff = [-780 .. 720]; DateTime =RECORDyear:CARDINAL; month: Month; day: Day; hour: Hour; minute: Min; second: Sec; fractions: Fraction; (* parts of a second *) zone: UTCDiff; (* Time zone differential factor which is the number of minutes to add to local time to obtain UTC. *) summerTimeFlag:BOOLEAN; (* Interpretation of flag depends on local usage. *)END;PROCEDURECanGetClock ():BOOLEAN; (* Returns TRUE if a system clock can be read; FALSE otherwise *)PROCEDURECanSetClock ():BOOLEAN; (* Returns TRUE if a system clock can be set; FALSE otherwise *)PROCEDUREIsValidDateTime (userData: DateTime):BOOLEAN; (* Returns TRUE if the value of userData represents a valid date and time; FALSE otherwise *)PROCEDUREGetClock (VARuserData: DateTime); (* If possible, assigns system date and time of day to userData *)PROCEDURESetClock (userData: DateTime); (* If possible, sets the system clock to the values of userData *)ENDSysClock.