SYNTAX OF STANDARD ML ...|... shows alternative phrases (...) encloses a phrase to allow use of ...|... [...] encloses an optional phrase {A^B} encloses a repetitive phrase of the form ABABA...BA -- 1 or more repetitions of A, separated by B Corrections by Dave Berry, Simon Finn, Kent Karlsson and David N. Turner. **Items below may be separated by spaces, newlines, and comments. **Consecutive keywords and identifiers of the same sort (alphanumeric/symbolic) must be separated to avoid ambiguity. PROGRAMS AND MODULES Program = {TopLevelDeclaration ";" ^} TopLevelDeclaration = Expression | ObjectDeclaration | SignatureDeclaration | FunctorDeclaration ObjectDeclaration = Empty | Declaration | "structure" { Ident [":" Signature] "=" Structure ^"and" } | "local" ObjectDeclaration "in" ObjectDeclaration "end" | ObjectDeclaration [";"] ObjectDeclaration SignatureDeclaration = Empty | "signature" {Ident "=" Signature ^"and"} | SignatureDeclaration [";"] SignatureDeclaration FunctorDeclaration = Empty | "functor" {FunctorBinding ^"and"} | FunctorDeclaration [";"] FunctorDeclaration FunctorBinding = Ident "(" FunctorArguments ")" [":" Signature] "=" Structure FunctorArguments = Ident ":" Signature | Specification Structure = "struct" ObjectDeclaration "end" | CompoundIdent | Ident "(" Structure ")" | Ident "(" ObjectDeclaration ")" | "let" ObjectDeclaration "in" Structure "end" Signature = "sig" Specification "end" | Ident Specification = Empty | "val" {Ident ":" Type ^"and"} | ("type" | "eqtype") {TypeVarList Ident ^"and"} | "datatype" {DatatypeBinding ^"and"} | "exception" { Ident ["of" Type] ^"and" } | "structure" {Ident ":" Signature ^"and"} | "sharing" { ["type"] CompoundIdent {"=" CompoundIdent ^} ^"and" } | "local" Specification "in" Specification "end" | "open" {CompoundIdent ^} | "include" {Ident ^} | Specification [";"] Specification DECLARATIONS Declaration = Empty | "val" { ["rec"] Pattern "=" Expression ^"and" } | "fun" { {FunctionHeading [":" Type] "=" Expression ^"|"} ^"and"} | "type" TypeBinding | "datatype" DatatypeBinding ["withtype" TypeBinding] | "abstype" DatatypeBinding ["withtype" TypeBinding] "with" Declaration "end" | "exception" { Name [ "of" Type | "=" CompoundName ] ^"and" } | "local" Declaration "in" Declaration "end" | "open" {CompoundIdent ^} | ("infix" | "infixr") [Digit] {Ident ^} | "nonfix" {Ident ^} | Declaration [";"] Declaration FunctionHeading = Name {AtomicPattern^} | "(" AtomicPattern InfixOperator AtomicPattern ")" {^AtomicPattern} | AtomicPattern InfixOperator AtomicPattern TypeBinding = {TypeVarList Ident "=" Type ^"and"} DatatypeBinding = { TypeVarList Ident "=" { Ident ["of" Type] ^"|" } ^"and" } TypeVarList = Empty | TypeVar | "(" {TypeVar ^","} ")" EXPRESSIONS Expression = InfixExpression | Expression ":" Type | Expression ("andalso" | "orelse") Expression | Expression "handle" Match | "raise" Expression | "if" Expression "then" Expression "else" Expression | "while" Expression "do" Expression | "case" Expression "of" Match | "fn" Match InfixExpression = {AtomicExpression ^} | InfixExpression InfixOperator InfixExpression AtomicExpression = CompoundName | Constant | "(" [ {Expression ^","} ] ")" | "[" [ {Expression ^","} ] "]" | "{" [ {Label "=" Expression ^","} ] "}" | "#" Label | "(" {Expression ^";"} ")" | "let" Declaration "in" {Expression ^";"} "end" MATCHES AND PATTERNS Match = {Pattern "=>" Expression ^"|"} Pattern = AtomicPattern | CompoundName AtomicPattern | Pattern InfixOperator Pattern | Pattern ":" Type | Name [":" Type] "as" Pattern AtomicPattern = "_" | CompoundName | Constant | "(" [ {Pattern ^","} ] ")" | "[" [ {Pattern ^","} ] "]" | "{" [FieldPattern] "}" FieldPattern = "..." | Label "=" Pattern ["," FieldPattern] | Ident [":" Type] ["as" Pattern] ["," FieldPattern] TYPES Type = TypeVar | TypeList CompoundIdent | Type {"*" Type^} | Type "->" Type | "{" [ { Label ":" Type ^","} ] "}" | "(" Type ")" TypeList = Empty | Type | "(" {Type ^","} ")" LEXICAL MATTERS: IDENTIFIERS, CONSTANTS, COMMENTS CompoundIdent = {Ident ^ "."} CompoundName = CompoundIdent | "op" InfixOperator Name = Ident | "op" InfixOperator InfixOperator = any identifier that has been declared to be infix Constant = Numeral [ "." {Digit ^} ] ["E" Numeral] | """ { ^ any printable character except \ or " | "\" StringEscape } """ StringEscape = "n" | "t" | "^" one of @ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_ | Digit Digit Digit | """ | "\" | { Space | Tab | Newline | Formfeed ^} "\" Numeral = ["~"] {Digit ^} TypeVar = "'" ["'"] ["_"] AlphanumericIdent Ident = AlphanumericIdent | {Symbol^} Label = Ident | {Digit^} AlphanumericIdent = Letter {^ Letter | Digit | "_" | "'"} Digit = one of 0123456789 Letter = one of ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz Symbol = one of !%&$#+-/:<=>?@\~`^|* Comment = "(*" {Commentary^Comment} "*)" Commentary = any text that does not include (* or *) as a substring