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 REAL

DEFINITION MODULE REAL;

(* I/O Module for Type REAL *)

FROM FileIO IMPORT File;

(* EBNF of the textual representation of REAL 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 : REAL );
(* Reads the textual representation of a REAL 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 REAL argument. *)

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

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

END REAL.