Syntax of Standard ML

Tobias Nipkow and Larry Paulson

PROGRAMS AND MODULES

Program

TopLevelDeclaration

                     ;

[figure]

TopLevelDeclaration Expression ObjectDeclaration SignatureDeclaration FunctorDeclaration

ObjectDeclaration Declaration

   structure

[figure] Ident

                             :

[figure] Signature

                                                =

[figure]

Structure

                                      and

[figure]

   local

[figure] ObjectDeclaration

                              in

[figure] ObjectDeclaration

                                                      end

[figure]

   ;

[figure] SignatureDeclaration

[figure: signature; Ident; =; Signature; and; ;]

FunctorDeclaration

   functor

[figure] FunctorBinding

                     and

[figure]

   ;

[figure]

FunctorBinding

Ident

     (

[figure] FunctorArguments

                            )

[figure]

                                    :

[figure] Signature

                                                       =

[figure]

Structure

FunctorArguments

Ident

        :

[figure]

Signature

Specification

Structure

struct

[figure] ObjectDeclaration

                            end

[figure] CompoundIdent Ident

        (

[figure] Structure ObjectDeclaration

                                     )

[figure]

let

[figure] ObjectDeclaration

                         in

[figure] Structure

                                         end

[figure]

Signature

sig

[figure] Specification

                    end

[figure] Ident Specification

 val

[figure] Ident

                  :

[figure]

Type

                 and

[figure]

    type

[figure]

    eqtype

[figure] TypeVarList

Ident

                           and

[figure]

 datatype

[figure] DatatypeBinding

                     and

[figure]

 exception

[figure] Ident

                           of

[figure]

Type

                          and

[figure]

 structure

[figure] Ident

                        :

[figure]

Signature

                         and

[figure]

 sharing

[figure]

                 type

[figure] CompoundIdent

                                     =

[figure]

                             and

[figure]

 local

[figure] Specification

                       in

[figure] Specification

                                          end

[figure]

 open

[figure]

CompoundIdent

 include

[figure]

Ident

 ;

[figure]

DECLARATIONS

Declaration

 val

[figure]

             rec

[figure] Pattern

                                =

[figure]

Expression

                           and

[figure]

 fun

[figure] FunHeading

                              :

[figure] Type

                                             =

[figure]

Expression

                                   |

[figure]

                                  and

[figure]

 type

[figure]

TypeBinding

 datatype

[figure] DatatypeBinding

                                 withtype

[figure]

TypeBinding

 abstype

[figure] DatatypeBinding

                                withtype

[figure]

TypeBinding

  with

[figure] Declaration

                       end

[figure]

 exception

[figure] Name

                           of

[figure]

Type

                            =

[figure] CompoundName

                               and

[figure]

 local

[figure] Declaration

                      in

[figure] Declaration

                                        end

[figure]

 open

[figure]

CompoundIdent

       infix

[figure]

       infixr

[figure]

Digit

    nonfix

[figure]

Ident

 ;

[figure] FunHeading

Name

AtomicPattern

        (

[figure] AtomicPattern InfixOperator AtomicPattern

                                                           )

[figure]

AtomicPattern AtomicPattern InfixOperator AtomicPattern

TypeBinding

[figure: TypeVarList; Ident; =; Type; and]

DatatypeBinding

[figure: TypeVarList; Ident; =; Ident; of; Type; |; and]

TypeVarList

[figure: TypeVar; (; TypeVar; ,; )]

EXPRESSIONS

Expression InfixExpression Expression

            :

[figure]

Type

Expression

               andalso

[figure]

               orelse

[figure]

Expression

Expression

            handle

[figure]

Match

raise

[figure]

Expression

if

[figure] Expression

                  then

[figure] Expression

                                     else

[figure]

Expression

while

[figure] Expression

                     do

[figure]

Expression

case

[figure] Expression

                    of

[figure]

Match

fn

[figure]

Match

InfixExpression AtomicExpression

InfixExpression InfixOperator InfixExpression AtomicExpression

CompoundName Constant

(

[figure] Expression

               ,

[figure]

                             )

[figure]

[

[figure] Expression

               ,

[figure]

                             ]

[figure] {

[figure] Label

                   =

[figure]

Expression

                     ,

[figure] }

[figure]

#

[figure]

Label

(

[figure] Expression

            ;

[figure]

                       )

[figure]

let

[figure] Declaration

                   in

[figure] Expression

                                ;

[figure]

                                           end

[figure]

MATCHES AND PATTERNS

Match

[figure: Pattern; =>; Expression; |]

Pattern AtomicPattern CompoundName AtomicPattern Pattern InfixOperator

Pattern

Pattern

          :

[figure]

Type

Name

           :

[figure] Type

                          as

[figure] Pattern AtomicPattern

 _

[figure] CompoundName Constant

 (

[figure] Pattern

              ,

[figure]

                            )

[figure]

 [

[figure] Pattern

              ,

[figure]

                            ]

[figure] { [figure] FieldPattern

} [figure]

FieldPattern

 ...

[figure] Label

            =

[figure]

Pattern

Ident

               :

[figure] Type

                                 as

[figure]

Pattern

      ,

[figure] FieldPattern

TYPES

Type TypeVar

Type

      (

[figure] Type

               ,

[figure]

                         )

[figure]

CompoundIdent

Type

           *

[figure]

Type

Type

        ->

[figure]

Type

{

[figure] Label

                   :

[figure]

Type

                   ,

[figure] }

[figure]

(

[figure] Type

            )

[figure]

LEXICAL MATTERS: IDENTIFIERS, CONSTANTS, COMMENTS

CompoundIdent

[figure: Ident; .]

CompoundName CompoundIdent

op

[figure]

InfixOperator

Name Ident

op

[figure]

InfixOperator

InfixOperator

[figure: any Ident that has been declared to be infix]

Constant

Numeral

                      .

[figure] Digit

                                              E

[figure]

Numeral

        "

[figure] any printable character except \ and " [figure] StringEscape

                                 \

[figure]

                                                             "

[figure]

StringEscape

[figure: n; t; ^; one of @ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_; Digit; Digit; Digit; "; \; Space; Tab; Newline; Formfeed; \]

Numeral

[figure: ~; Digit]

TypeVar

        '

[figure]

                   _

[figure] AlphanumericIdent Ident

AlphanumericIdent

           one of !%&$#+-/:<=>?@\~`^|*

[figure]

Label

[figure: Ident; Digit]

AlphanumericIdent

[figure: Letter; Letter; Digit; _; ']

Digit

    [figure: one of 0123456789]

Letter

    [figure: one of ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz]

Comment

[figure: (*; any text that does not include (* or *) as a substring; Comment; *)]