Modula-2 Reloaded

A Modern Typesafe & Literate Programming Notation

Site Menu

Project

Specification

Implementation

Recommendations

Reference

Needs Updating

Work in Progress

Wastebasket

Wiki Manual

edit SideBar

IO Module LONGREAL

DEFINITION MODULE LONGREAL;

(* I/O Module for Type LONGREAL *)

FROM FileIO IMPORT File;

(* EBNF of the textual representation of LONGREAL values:

    realValue :
        unpaddedRealValue | leftPaddedRealValue | rightPaddedRealValue ;
    leftPaddedRealValue : padding+ unPaddedRealValue ;
    rightPaddedRealValue : unPaddedRealValue padding+ ;
    unPaddedRealValue : simpleFormat | otherFormats ;
    otherFormats : sign? fillChar*
        ( fixedFmtNumeral | engFmtNumeral | expFmtNumeral ) suffix? ;
    simpleFormat : negativeSign? decimalDigit '.' decimalDigit+ exponent ;
    fixedFmtNumeral : integralPart decimalPoint fractionalPart ;
    engFmtNumeral : engIntegralPart decimalPoint fractionalPart engExponent ;
    expFmtNumeral : fixedFmtNumeral exponent ;
    padding : ' ' ;
    sign : " " | "+" | "-" ;
    negativeSign : "-" ;
    fillChar : " " | "*" | "0" ;
    integralPart :
        decimalDigit decimalDigit? decimalDigit? ( separator? digitGroup )* ;
    engIntegralPart :
        ( ( ( decimalDigit separator? )? decimalDigit )? decimalDigit )?
        decimalDigit ;
    fractionalPart :
        ( decimalDigit ( decimalDigit ( decimalDigit separator )? )? )*
        decimalDigit ;
    exponent : "E" ( "+" | "-" ) decimalDigit decimalDigit+ ;
    engExponent : exponent ;
    decimalPoint : "." | "," ;
    separator : " " | "." | "," ;
    digitGroup : decimalDigit decimalDigit decimalDigit ;
    decimalDigit  : "0" .. "9" ;
    suffix : "'" character* "'" ;

   Static semantics:

    decimalPoint and separator must never both use the same symbol
    the value represented by engExponent must always be divisible by three. *)

PROCEDURE Read ( infile : File; VAR r : LONGREAL );
(* Reads the textual representation of a LONGREAL value from stream infile
   - any leading whitespace is skipped
   - any remaining characters that are part of the value being read are
     removed from infile
   - the textual representation of the value read is assigned to r
   - the file status is set to any of:
     success, outOfRange, wrongFormat, endOfLine, or endOfInput. This
   procedure is substituted for invocations of READ with a LONGREAL argument.*)

PROCEDURE Write ( outfile : File; r : LONGREAL );
(* Writes the value of LONGREAL r in simple format to stream outfile. This pro-
   cedure is substituted for invocations of WRITE with a LONGREAL argument. *)

PROCEDURE WriteF ( outfile      : File;
                   CONST fmtStr : ARRAY OF CHAR;
                   items        : VARIADIC OF LONGREAL );
(* Writes a formatted textual representation of one or more LONGREAL values to
   output stream outfile. The output format is determined by fmtStr. This
   procedure is substituted for invocations of WRITEF with one or more
   LONGREAL arguments. *)

END LONGREAL.