<program> ::=
        <program element> <sep>..1..<program element> ;

<program element> ::=
        <module> |
        <context command> |
        <statement>

<sep> ::=
        ;

<module> ::=
        module <module name> <sep>  <statement> <sep> ..0.. <statement> end

<statement> ::=
        <system command>  |
        <syntax declaration> |
        <scope command> |
        <interface declaration> |
        <type-variable declaration> |
        <defined-object declaration> |
        <type definition statement> |
        <equation> |
        <comment>

<system command> ::=
        load <file name> |
        exit |
        echo <onoff parameter> |
        trace <trace parameter> |
        notrace <notrace parameter> |
        save <file name> |
        time <onoff parameter> |
        system |
        help |
        display <display parameter> |
        ^C

<display parameter> ::=
        data |
        functions |
        <identifier> |
        <identifier> * |
        <empty>

<trace parameter> ::=
        <identifier> *? |
        on |
        off |
        all

<notrace parameter> ::=
        <identifier> *? |
        all

<onoff parameter> ::=


>

<empty> :=

<syntax declaration> ::=
<identifier> , ..1.. <identifier> : <precedence>

<precedence> ::=
        <natural number>

<interface declaration> ::=
        <export declaration> |
        <import declaration>

<export declaration> ::=
        <export declaration kind> <identifier> , ..1.. <identifier>

<export declaration kind> ::=
        pubtype |
        pubconst

<import declaration> ::=
        uses <identifier> , ..1.. <identifier>

<type-variable declaration> ::=
        typevar <identifier> , ..1.. <identifier>

<defined-object declaration> ::=
        dec <identifier> , ..1.. <identifier> : <type expression>

<type definition statement> ::=
        data <primitive type definition> with ..1.. <primitive type definition> |
        type <derived type definition>

<primitive type definition> ::=
        <formal type term> == <type summand> ++ ..1.. <type summand>

<derived type definition> ::=
        <formal type term> == <type expression>

<formal type term> ::=
        <type constant> |
        <non-operator type constructor> <type variable> |
        <non-operator type constructor> ( <type variable> , ..0.. <type variable> ) |
        <prefix type constructor> <type variable> |
        <type variable> <infix type constructor> <type variable> |
        ( <formal type term> )


<type summand> ::=
        <data constant> |
        <non-operator data constructor> <type expression> |
        <prefix data constructor> <type expression> |
        <type expression> <infix data constructor> <type expression> |
        ( <type summand> )

<type expression> ::=
        <simple type expression> |
        <constructor type expression> |
        <function type expression> |
        <tuple type expression> |
        ( <type expression> )

<simple type expression>::=
        <type variable> |
        <type constant>

<constructor type expression> ::=
        <non-operator type constructor> <type expression> |
        <non-operator type constructor> ( <type expression> , ..1.. <type expression> ) |
        <prefix type constructor> <type expression> |
        <type expression> <infix type constructor> |
        <type expression>

<function type expression> ::=
        <type expression> -> <type expression>

<tuple type expression> ::=
        <type expression> # ..2.. <type expression> |
        void

<equation> ::=
        --- <formal defined-object term> <= <expression>

<formal defined-object term> ::=
        <simple formal defined-object term> |
        <application formal defined-object term>

<simple formal defined-object term> ::=
        <non-operator defined-object>

<application formal defined-object term> ::=
        <non-operator defined-object> <pattern> |
        <prefix defined-object> <pattern> |
        <pattern> <infix defined-object> <pattern>

<pattern> ::=
        <simple pattern> |
        <pattern tuple> |
        <data constructor pattern |
        <non-operator variable> & <pattern> |
        ( <pattern> )

<simple pattern> ::=
        <literal> |
        <non-operator variable> |
        <data constant> |
        _

<pattern tuple> ::=
        <pattern> , ..0.. <pattern> |
        ( )

<data constructor pattern> ::=
        <non-operator data constructor> <pattern> |
        <prefix data constructor> <pattern> |
        <pattern> <infix data constructor> <pattern>

<expression> ::=
        <simple expression> |
        <application expression> |
        <conditional expression> |
        <qualified expression> |
        <lambda expression> |
        <tuple expression> |
        <list expression> |
        <set expression> |
        ( <expression> )

<simple expression> ::=
        <literal> |
        <non-operator variable> |
        <data constant> |
        <non-operator data constructor> |
        <non-operator defined-object>

<application expression> ::=
        <expression> <expression> |
        <prefix operator> <expression> |
        <expression> <infix operator> <expression>

<conditional expression> ::=
        <cond pair> else <expression>

<cond pair> ::=
        <expression> if <boolean expression> |
        <boolean expression> then <expression> |
        if <boolean expression> then <expression>

<boolean expression> ::=
        <expression>

<qualified expression> ::=
        let <pattern> == <expression> in <expression> |
        <expression> where <pattern> == <expression>

<lambda expression> ::=
        <lambda mark> <lambda rule> | ..1.. <lambda rule>

<lambda rule> ::=
        <pattern> => <expression>

<lambda mark > :: =
        lambda

<tuple expression> ::=
        <expression> , ..0.. <expression> |
        ( )
<list expression> ::=
        [ <expression> , ..0.. <expression> ]

<set expression> ::=
        { <expression> , ..0.. <expression> }

<non-operator type constructor> ::=
        <non-operator identifier phrase>

<prefix type constructor> ::=
        <prefix identifier>

<infix type constructor> ::=
        <infix identifier>

<type constant> ::=
        <non-operator identifier>

<type variable> ::=
        <non-operator identifier>

<prefix operator> ::=
        <prefix data constructor> |
        <prefix defined-object> |
        <prefix variable>

<infix operator> ::=
        <infix data constructor> |
        <infix defined-object> |
        <infix variable>

<non-operator data constructor> ::=
        <non-operator identifier phrase>

<prefix data constructor> ::=
        <prefix identifier>

<infix data constructor> ::=
        <infix identifier>

<data constant> ::=
        <non-operator identifier>

<non-operator defined-object> ::=
        <non-operator identifier phrase>

<prefix defined-object> ::=
        <prefix identifier>

<infix defined-object> ::=
        <infix identifier>

<module name> ::=
        <identifier>

<file name> ::=
        <alphanumeric identifier> |
        "<system file identifier>"

operator identifier phrase> ::=
        <non-operator identifier> |
        nonop <operator identifier>

<non-operator identifier> ::=
        <identifier>

<operator identifier> ::=
        <prefix identifier> |
        <infix identifier>

<prefix identifier> ::=
        <identifier>

<infix identifier> ::=
        <identifier>

<literal> ::=
        <natural number literal> |
        <boolean literal> |
        <character literal> |
        <character list literal>

<natural number literal> ::=
        <natural number>

<boolean literal> ::=
        true |
        false

<character literal> ::=
        '<any ASCII character>' |
        crlf

<character list literal> ::=
        "<any ASCII character (except use  \n to denote crlf; use \\ to denote \'>"

<comment> ::=
        ! <any sequence of printable ASCII characters terminated by ! or the end of line>

<non-keyword text item> ::=
        <any <text item> that is not a <keyword>>

<keyword> ::=
        module | end | infix | prefix |
        pubtype | pubconst  | uses |
        typevar | dec | var | data | type | --- | let  |
        exit  | echo  | trace  | notrace | load | display | system

<text item> ::=
        <identifier> |
        <natural number> |
        <punctuation sign>

<identifier> ::=
        <alphanumeric identifier> |
        <compound sign identifier>

<alphanumeric identifier> ::=
        <letter> <alphanumeric *?>

<compound sign identifier> ::=
        <compoundable sign *>

<natural number> ::=
        <digit *>

<alphanumeric> ::=
        <letter> |
        <digit>

<letter> ::=
        A .. Z |
        a .. z |
        _

<digit> ::=
        0 .. 9

<compoundable sign> ::=
        #  |  $  |  |  |  &  |  *  |  +  |  -  |  .  |  /  |  :  |  <  |  =  |  >  |  ?  |  \

<punctuation sign> ::=
        (  |  )  |  ,  |  ;  |  [  |  ]  |  {  |  }
