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

Terminals

<< Non Terminals | Ignore Symbols >>

#1 Reserved Words
ResWord :=
  ALIAS | AND | ARGLIST | ARRAY | BEGIN | BLUEPRINT | BY | CASE | CONST | COPY |
  DEFINITION | DIV | DO | ELSE | ELSIF | END | EXIT | FOR | FROM | GENLIB | IF |
  IMPLEMENTATION | IMPORT | IN | LOOP | MOD | MODULE | NEW | NONE | NOT | OF |
  OPAQUE | OR | POINTER | PROCEDURE | RECORD | REFERENTIAL | RELEASE | REPEAT |
  RETAIN | RETURN | SET | THEN | TO | TYPE | UNTIL | VAR | WHILE | YIELD
  ;

#2 Dual-Use Identifiers
(Schrödinger's Tokens)
DualUseIdent :=
  ABS | ADDRESS | APPEND | CAST | COUNT | COROUTINE | EXISTS | INSERT |
  LENGTH | OCTET | READ | READNEW | REMOVE | SEEK | STORE | SUBSET | SXF |
  TDYN | TFLAGS | TLIMIT | TLITERAL | TMAX | TMIN | TORDERED | TREFC |
  TSCALAR | TSORTED | UNSAFE | VAL | VALUE | WRITE | WRITEF
  ;

#3 Special Symbols
SpecialSymbol :=
  '.' | ',' | ':' | ';' | '|' | '~' | '..' | ':=' | '++' | '--' |
  '::' | '+' | '-' | '*' | '/' | '\' | '&' | '^' |
  '=' | '#' | '>' | '>=' | '<' | '<=' | '==' |
  '->' | '<>' | '><' | '+/-' |
  '(' | ')' | '[' | ']' | '{' | '}'
  ;
#3.1 Quoted Text Delimiters

'   "   <<   >>  

#3.2 Comment Delimiters

!   (*   *)  

#3.3 Pragma Punctuation and Delimiters

?   <*   *>  

#3.4 Template Language Symbols

##   <#   #>   @@   //   /*   */  

#3.5 Reserved Symbols

`   for use as a token by Objective Modula-2
@   for use as a lead character in identifiers and reserved words by language supersets
%   for use as a character in identifiers and reserved words by implementations targetingOpenVMS

#4 Identifier   syntax diagram
Ident :=
  ( Letter | ForeignIdentChar+ LetterOrDigit+ ) IdentTailChar*
  ;

#4.1 Standard Library Identifier   syntax diagram
StdLibIdent :=
  Letter LetterOrDigit*
  ;

#4.2 Letter Or Digit   syntax diagram
LetterOrDigit :=
  Letter | Digit
  ;

#4.3 Foreign Identifier Character   syntax diagram
ForeignIdentChar :=
  '_' | '$'
  ;

#4.4 Identifier Tail Character   syntax diagram
IdentTailChar :=
  LetterOrDigit | ForeignIdentChar
  ;

#5 Number Literal   syntax diagram
NumberLiteral :=
  /* number literals starting with digit 0 ... */
  '0' (
    /* without prefix are real numbers */
    RealNumberTail |
    /* with prefix 0b are base-2 numbers */
    'b' Base2DigitSeq |
    /* with prefix 0x are base-16 numbers */
    'x' Base16DigitSeq |
    /* with prefix 0u are unicode code points */
    'u' Base16DigitSeq
  )?
  /* number literals starting with digits 1 to 9 ... */
  | '1'..'9' DecimalNumberTail? /* are always decimal numbers */
  ;

#5.1 Decimal Number Tail   syntax diagram
DecimalNumberTail :=
  DigitSep? DigitSeq RealNumberTail? | RealNumberTail
  ;

#5.2 Real Number Tail   syntax diagram
RealNumberTail :=
  '.' DigitSeq ( 'e' ( '+' | '-' )? DigitSeq )?
  ;

#5.3 Digit Sequence   syntax diagram
DigitSeq :=
  Digit+ ( DigitSep Digit+ )*
  ;

#5.4 Base-16 Digit Sequence   syntax diagram
Base16DigitSeq :=
    Base16Digit+ ( DigitSep Base16Digit+ )*
    ;

#5.5 Base-2 Digit Sequence   syntax diagram
Base2DigitSeq :=
  Base2Digit+ ( DigitSep Base2Digit+ )*
  ;

#5.6 Digit   syntax diagram
Digit :=
  Base2Digit | '2' | '3' | '4' | '5' | '6' | '7' | '8' | '9'
  ;

#5.7 Base-16 Digit   syntax diagram
Base16Digit :=
  Digit | 'A' | 'B' | 'C' | 'D' | 'E' | 'F'
  ;

#5.8 Base-2 Digit   syntax diagram
Base2Digit :=
  '0' | '1'
  ;

#5.9 Digit Separator
DigitSep := "'" ;

#6 String Literal   syntax diagram
StringLiteral :=
  SingleQuotedString | DoubleQuotedString
  ;

#6.1 Single Quoted String   syntax diagram
SingleQuotedString :=
  "'" ( QuotableCharacter | '"' )* "'"
  ;

#6.2 Double Quoted String   syntax diagram
DoubleQuotedString :=
  '"' ( QuotableCharacter | "'" )* '"'
  ;

#6.3 Quotable Character   syntax diagram
QuotableCharacter :=
  Digit | Letter | Space | NonAlphaNumQuotable | EscapedCharacter
  ;

#6.4 Letter   syntax diagram
Letter :=
  'A' .. 'Z' | 'a' .. 'z'
  ;

#6.5 Space
Space := ' ' ;

#6.6 Non-Alphanumeric Quotable   syntax diagram
NonAlphaNumQuotable :=
  '!' | '#' | '$' | '%' | '&' | '(' | ')' | '*' | '+' | ',' |
  '-' | '.' | '/' | ':' | ';' | '<' | '=' | '>' | '?' | '@' |
  '[' | ']' | '^' | '_' | '`' | '{' | '|' | '}' | '~'

#6.7 Escaped Character   syntax diagram
EscapedCharacter :=
  '\' ( 'n' | 't' | '\' )
  ;

#7 Chevron Text   syntax diagram
ChevronText :=
  '<<' ( QuotableCharacter | "'" | '"' )* '>>'
  ;