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

Output Formats For Numeric Types Representing Complex Numbers

Types

COMPLEX, LONGCOMPLEX

Syntax

The EBNF for the textual representation of values of types that represent complex numbers is

Values and Value Lists
complexNumberValue :
    compactNotation | expandedNotation | pairNotation ;

complexNumberValueList :
    complexNumberValue ( listSeparator complexNumberValue )* ;

listSeparator :
    defaultListSeparator | userDefinedListSeparator | newline ;

defaultListSeparator :
    defaultListSeparatorForValuesWithCommas |
    defaultListSeparatorForValuesWithoutCommas ;

defaultListSeparatorForValuesWithCommas :
    ';' whitespace ;

defaultListSeparatorForValuesWithoutCommas :
    ',' whitespace ;

userDefinedListSeparator :
    character whitespace? ;
Arrays and Array Lists
complexNumberArray :
     openingArrayDelimiter complexNumberValueList closingArrayDelimiter ;

complexNumberArrayList :
    complexNumberArray ( listSeparator complexNumberArray )* ;

openingArrayDelimiter :
    ( defaultOpeningArrayDelimiter | userDefinedOpeningArrayDelimiter ) whitespace ;

closingArrayDelimiter :
    whitespace ( defaultClosingArrayDelimiter | userDefinedOpeningArrayDelimiter ) ;

defaultOpeningArrayDelimiter :
    '{' ;

defaultClosingArrayDelimiter :
    '}' ;

userDefinedOpeningArrayDelimiter :
    '(' | '[' ;

userDefinedClosingArrayDelimiter :
    ')' | ']' ;
Mathematical Notation
compactNotation :
    compactNotationAllPartsZero | compactNotationImaginaryPartZero |
    compactNotationRealPartZero | compactNotationAllPartsNonZero ;

compactNotationAllPartsZero :
    '0' ;

compactNotationImaginaryPartZero :
    compactRealPart ;

compactNotationRealPartZero ;
    simpleSign? compactImaginaryPart ;

compactNotationAllPartsNonZero :
    compactRealPart simpleSign compactImaginaryPart ;

compactRealPart :
    simpleSign? simpleNonZeroDecimalRealNumber ;

compactImaginaryPart :
    simpleNonZeroDecimalRealNumber imaginaryPartDesignator;

simpleSign :
    '+' | '-' ;

imaginaryPartDesignator :
    'i' | 'j' ;

simpleNonZeroDecimalRealNumber :
    decimalDigit+ ( decimalPoint | decimalComma ) decimalDigit+ ;

expandedNotation :
    expandedRealPart simpleSign expandedImaginaryPart ;

expandedRealPart :
    '0' | simpleNonZeroDecimalRealNumber ;

expandedImaginaryPart :
   ( '0' | simpleNonZeroDecimalRealNumber ) imaginaryPartDesignator ;
Pair Notation
pairNotation :
    unpaddedComplexPair | leftPaddedComplexPair | rightPaddedComplexPair ;

leftPaddedComplexPair :
    whitespace+ unpaddedComplexPair ;

rightPaddedComplexPair :
    unpaddedComplexPair whitespace+ ;

whitespace :
    ' ' ;

unpaddedComplexPair :
    '(' realPart partSeparator imaginaryPart ')' ;

realPart :
    formattedRealNumber ;

imaginaryPart :
    formattedRealNumber ;

partSeparator :
    decimalPointModePartSeparator | decimalCommaModePartSeparator ;

decimalPointModePartSeparator :
    ',' whitespace ;

decimalCommaModePartSeparator :
    ';' whitespace ;

formattedRealNumber :
    realNumberSimpleFormat | realNumberOtherFormats ;

realNumberSimpleFormat :
    negativeSign? decimalDigit decimalPoint decimalDigit+ exponent ;

realNumberOtherFormats :
    sign? fillChar* ( fixedFmtDecimal | engFmtDecimal | expFmtDecimal ) ;

fixedFmtDecimal :
    integralPart ( decimalPoint | decimalComma ) fractionalPart ;

engFmtDecimal :
    engIntegralPart ( decimalPoint | decimalComma ) fractionalPart engExponent ;

expFmtDecimal :
    fixedFmtDecimal exponent ;

sign :
    whitespace | '+' | '-' ;

negativeSign :
    '-' ;

fillChar :
    whitespace | '*' | '0' ;

integralPart :
    decimalDigit decimalDigit? decimalDigit? ( digitSeparator? digitGroup )* ;

engIntegralPart :
    ( ( ( decimalDigit digitSeparator? )? decimalDigit )? decimalDigit )? decimalDigit ;

fractionalPart :
    ( decimalDigit ( decimalDigit ( decimalDigit digitSeparator )? )? )* decimalDigit ;

exponent :
    'E' ( '+' | '-' ) decimalDigit decimalDigit+ ;

engExponent :
    exponent ;

digitSeparator :
    decimalPointModeDigitSeparator | decimalCommaModeDigitSeparator ;

decimalPointModeDigitSeparator :
    whitespace | ',' ;

decimalCommaModeDigitSeparator :
    whitespace | '.' ;

digitGroup :
    decimalDigit decimalDigit decimalDigit ;

decimalPoint :
    '.' ;

decimalComma :
    ',' ;

decimalDigit  :
    '0' .. '9' ;

character :
    <any printable ASCII character> ;

newline :
    <runtime host dependent ASCII control sequence for new line> ;

Static Semantics

  • all values in a list are shown in the same notation.
  • all values in a list are shown with identical formatting.
  • all values in a list are shown with identical imaginary part designators.
  • real and imaginary parts are shown with identical formatting.
  • the numeric value represented by engExponent is always divisible by three.
  • the numeric value represented by simpleNonZeroDecimalRealNumber is never zero.
  • in decimal point mode, decimalPoint is shown instead of decimalComma, decimalPointModePartSeparator is shown instead of decimalCommaModePartSeparator and decimalPointModeDigitSeparator is shown instead of decimalCommaModeDigitSeparator.
  • in decimal comma mode, decimalComma is shown instead of decimalPoint, decimalCommaModePartSeparator is shown instead of decimalPointModePartSeparator and decimalCommaModeDigitSeparator is shown instead of decimalPointModeDigitSeparator.