| ident | ::= | (letter| _) { letter| 0...9| _| ' } |
| letter | ::= | A ... Z | a ... z |
| integer-literal | ::= | [-] { 0...9 }+ |
| | | [-] (0x| 0X) { 0...9| A...F| a...f }+ | |
| | | [-] (0o| 0O) { 0...7 }+ | |
| | | [-] (0b| 0B) { 0...1 }+ |
| float-literal | ::= | [-] { 0...9 }+ [. { 0...9 }] [(e| E) [+| -] { 0...9 }+] |
| char-literal | ::= | ' regular-char ' |
| | | ' \ (\ | ' | n | t | b | r) ' | |
| | | ' \ (0...9) (0...9) (0...9) ' |
| string-literal | ::= | " { string-character } " |
| string-character | ::= | regular-char |
| | | \ (\ | " | n | t | b | r) | |
| | | \ (0...9) (0...9) (0...9) |
| label | ::= | ~ (a ... z) { letter| 0...9| _| ' } : |
| optlabel | ::= | ? (a ... z) { letter| 0...9| _| ' } : |
| infix-symbol | ::= | (= | < | > | @ | ^ | | | & | + | - | * | / | $ | %) { operator-char } |
| prefix-symbol | ::= | (! | ? | ~) { operator-char } |
| operator-char | ::= | ! | $ | % | & | * | + | - | . | / | : | < | = | > | ? | @ | ^ | | | ~ |
| linenum-directive | ::= | # {0 ... 9}+ |
| | | # {0 ... 9}+ " { string-character } " |
| value-name | ::= | lowercase-ident |
| | | ( operator-name ) | |
| operator-name | ::= | prefix-symbol | infix-symbol | * | = | or | & | := |
| cconstr-name | ::= | capitalized-ident |
| | | false | |
| | | true | |
| | | [ ] | |
| | | ( ) | |
| ncconstr-name | ::= | capitalized-ident |
| | | :: | |
| label-name | ::= | lowercase-ident |
| tag-name | ::= | capitalized-ident |
| typeconstr-name | ::= | lowercase-ident |
| field-name | ::= | lowercase-ident |
| module-name | ::= | capitalized-ident |
| modtype-name | ::= | ident |
| class-name | ::= | lowercase-ident |
| inst-var-name | ::= | lowercase-ident |
| method-name | ::= | lowercase-ident |
| value-path | ::= | value-name |
| | | module-path . lowercase-ident | |
| cconstr | ::= | cconstr-name |
| | | module-path . capitalized-ident | |
| ncconstr | ::= | ncconstr-name |
| | | module-path . capitalized-ident | |
| typeconstr | ::= | typeconstr-name |
| | | extended-module-path . lowercase-ident | |
| field | ::= | field-name |
| | | module-path . lowercase-ident | |
| module-path | ::= | module-name |
| | | module-path . capitalized-ident | |
| extended-module-path | ::= | module-name |
| | | extended-module-path . capitalized-ident | |
| | | extended-module-path ( extended-module-path ) | |
| modtype-path | ::= | modtype-name |
| | | extended-module-path . ident | |
| class-path | ::= | class-name |
| | | module-path . lowercase-ident |
| typexpr | ::= | ' ident |
| | | _ | |
| | | ( typexpr ) | |
| | | [[?]ident:] typexpr -> typexpr | |
| | | typexpr { * typexpr }+ | |
| | | typeconstr | |
| | | typexpr typeconstr | |
| | | ( typexpr { , typexpr } ) typeconstr | |
| | | typexpr as ' ident | |
| | | [ variant-type ] | |
| | | < [..] > | |
| | | < method-type { ; method-type } [; ..] > | |
| | | # class-path | |
| | | typexpr # class-path | |
| | | ( typexpr { , typexpr } ) # class-path | |
| | | # typeconstr-path [ tag-list ] | |
| | | typexpr # typeconstr-path [ tag-list ] | |
| | | ( typexpr { , typexpr } ) # typeconstr-path [ tag-list ] | |
| method-type | ::= | method-name : typexpr |
| tag-list | ::= | [> {`tag-name}+ ] ] |
| variant-type | ::= | [ tag-spec { | tag-spec } ] |
| | | > tag-spec { | tag-spec } | |
| | | < .. | |
| | | < tag-spec-full { | tag-spec-full } [| ..] [ > { `tag-name }+ ] | |
| tag-spec | ::= | `tag-name [ typexpr ] |
| tag-spec-full | ::= | `tag-name [ typexpr ] { & typexpr } |
| constant | ::= | integer-literal |
| | | float-literal | |
| | | char-literal | |
| | | string-literal | |
| | | cconstr | |
| | | `tag-name |
| pattern | ::= | value-name |
| | | _ | |
| | | constant | |
| | | pattern as value-name | |
| | | ( pattern ) | |
| | | ( pattern : typexpr ) | |
| | | pattern | pattern | |
| | | ncconstr pattern | |
| | | `tag-name pattern | |
| | | #typeconstr-name | |
| | | pattern { , pattern } | |
| | | { field = pattern { ; field = pattern } } | |
| | | [ pattern { ; pattern } ] | |
| | | pattern :: pattern |
| expr | ::= | ... |
| | | inst-var-name <- expr | |
| | | {< [ inst-var-name = expr { ; inst-var-name = expr } ] >} |
| expr | ::= | ... |
| | | [< >] | |
| | | [< stream-component { ; stream-component } >] | |
| | | parser [pattern] stream-matching | |
| | | match expr with parser [pattern] stream-matching | |
| stream-component | ::= | ' expr |
| | | expr | |
| stream-matching | ::= | stream-pattern [pattern] -> expr { | stream-pattern [pattern] -> expr } |
| stream-pattern | ::= | [< >] |
| | | [< stream-pat-comp { ; stream-pat-comp [ ?? expr ] }>] | |
| stream-pat-comp | ::= | ' pattern [ when expr ] |
| | | pattern = expr | |
| | | ident |
| type-definition | ::= | type typedef { and typedef } |
| typedef | ::= | [type-params] typeconstr-name [type-information] |
| type-information | ::= | [type-equation] [type-representation] { type-constraint } |
| type-equation | ::= | = typexpr |
| type-representation | ::= | = constr-decl { | constr-decl } |
| | | = { field-decl { ; field-decl } } | |
| type-params | ::= | ' ident |
| | | ( ' ident { , ' ident } ) | |
| constr-decl | ::= | cconstr-name |
| | | ncconstr-name of typexpr | |
| field-decl | ::= | field-name : typexpr |
| | | mutable field-name : typexpr | |
| type-constraint | ::= | constraint ' ident = typexpr |
| exception-definition | ::= | exception constr-decl |
| | | exception cconstr-name = cconstr | |
| | | exception ncconstr-name = ncconstr |
| class-type | ::= | |
| | | class-body-type | |
| | | [[?]label] typexpr -> class-type | |
| class-body-type | ::= | object [( typexpr )] {class-field-spec} end |
| | | class-path | |
| | | [ typexpr {, typexpr} ] class-path | |
| class-field-spec | ::= | inherit class-type |
| | | val [mutable] inst-var-name : typexpr | |
| | | method [private] method-name : typexpr | |
| | | method [private] virtual method-name : typexpr | |
| | | constraint typexpr = typexpr |
| class-expr | ::= | class-path |
| | | [ typexpr {, typexpr} ] class-path | |
| | | ( class-expr ) | |
| | | ( class-expr : class-type ) | |
| | | class-expr {argument}+ | |
| | | fun {parameter}+ -> class-expr | |
| | | let [rec] let-binding {and let-binding} in class-expr | |
| | | object [( pattern [: typexpr] )] { class-field } end | |
| class-field | ::= | inherit class-expr [as value-name] |
| | | val [mutable] inst-var-name = expr | |
| | | method [private] method-name {pattern} = expr | |
| | | method [private] virtual method-name : typexpr | |
| | | constraint typexpr = typexpr | |
| | | initializer expr |
| expr | ::= | ... |
| | | inst-var-name <- expr | |
| | | {< [ inst-var-name = expr { ; inst-var-name = expr } ] >} |
| class-definition | ::= | class class-binding { and class-binding } |
| class-binding | ::= | [virtual] [[ type-parameters ]] class-name { pattern } [: class-type] = class-expr |
| type-parameters | ::= | ' ident { , ' ident } |
| class-specification | ::= | class class-spec { and class-spec } |
| class-spec | ::= | [virtual] [[ type-parameters ]] class-name : class-type |
| classtype-definition | ::= | class type classtype-def { and classtype-def } |
| classtype-def | ::= | [virtual] [[ type-parameters ]] class-name = class-body-type |
| module-type | ::= | modtype-path |
| | | sig { specification [;;] } end | |
| | | functor ( module-name : module-type ) -> module-type | |
| | | module-type with mod-constraint { and mod-constraint } | |
| | | ( module-type ) | |
| specification | ::= | val value-name : typexpr |
| | | external value-name : typexpr = external-declaration | |
| | | type-definition | |
| | | exception-definition | |
| | | class-specification | |
| | | classtype-definition | |
| | | module module-name : module-type | |
| | | module module-name { ( module-name : module-type ) } : module-type | |
| | | module type modtype-name | |
| | | module type modtype-name = module-type | |
| | | open module-path | |
| | | include modtype-path | |
| mod-constraint | ::= | type [type-parameters] typeconstr = typexpr |
| | | module module-path = extended-module-path |
| module-expr | ::= | module-path |
| | | struct { definition [;;] } end | |
| | | functor ( module-name : module-type ) -> module-expr | |
| | | module-expr ( module-expr ) | |
| | | ( module-expr ) | |
| | | ( module-expr : module-type ) | |
| definition | ::= | let [rec] let-binding { and let-binding } |
| | | external value-name : typexpr = external-declaration | |
| | | type-definition | |
| | | exception-definition | |
| | | class-definition | |
| | | classtype-definition | |
| | | module module-name { ( module-name : module-type ) } [ : module-type ] = module-expr | |
| | | module type modtype-name = module-type | |
| | | open module-path |
| unit-interface | ::= | { specification [;;] } |
| unit-implementation | ::= | { definition [;;] } |
| expr | ::= | ... |
| | | [< >] | |
| | | [< stream-component { ; stream-component } >] | |
| | | parser [pattern] stream-matching | |
| | | match expr with parser [pattern] stream-matching | |
| stream-component | ::= | ' expr |
| | | expr | |
| stream-matching | ::= | stream-pattern [pattern] -> expr { | stream-pattern [pattern] -> expr } |
| stream-pattern | ::= | [< >] |
| | | [< stream-pat-comp { ; stream-pat-comp [ ?? expr ] }>] | |
| stream-pat-comp | ::= | ' pattern [ when expr ] |
| | | pattern = expr | |
| | | ident |
| toplevel-input | ::= | { toplevel-phrase } ;; |
| toplevel-phrase | ::= | toplevel-definition |
| | | expr | |
| | | # ident directive-argument | |
| toplevel-definition | ::= | let [rec] let-binding { and let-binding } |
| | | external value-name : typexpr = external-declaration | |
| | | type-definition | |
| | | exception-definition | |
| | | module module-name [ : module-type ] = module-expr | |
| | | module type modtype-name = module-type | |
| | | open module-path | |
| directive-argument | ::= | nothing |
| | | string-literal | |
| | | integer-literal | |
| | | value-path |
| debug-expr | ::= | lowercase-ident |
| | | { capitalized-ident . } lowercase-ident | |
| | | * | |
| | | $ integer | |
| | | debug-expr . lowercase-ident | |
| | | debug-expr .( integer ) | |
| | | debug-expr .[ integer ] | |
| | | ! debug-expr | |
| | | ( debug-expr ) |