SML# Document

Chapter 18. Expressions

The syntax for expressions (exp) is hierarchically defined below using infix operator expressions (infix), function application expressions (appexp), atomic expressions (appexp).

  • expressions (top-level)

    exp ::= infix
     | exp : ty
     | exp andalso exp
     | exp orelse exp
     | exp handle match
     | raise exp
     | if exp then exp else exp
     | while exp do exp
     | case exp of match
     | fn match
     | _import string : ffity importing C function
     | _sqlserver (appexp)? : ffity SQL servers
     | _sql id => sql SQL queries
    match ::= pat => exp (| match)? pattern matching

    The definitions for ffity and sql are given in Section 18.21 and Chapter 21, respectively.

  • infix operator expressions

    infix ::= appexp
     | infix vid infix
  • function application expressions

    appexp ::= atexp
     | appexp atexp left associative function applications
     | appexp # { exprow } record field updates
  • atomic expressions

    atexp ::= scon constants
     | (op)? longVid identifiers
     | {(exprow)? } records
     | (exp1,,expn) tuples (n2)
     | () unit value
     | #lab record field selector
     | [exp1,,expn] lists (n0)
     | (exp1;;expn) sequential execution
     | let declList in exp1;;expn end local declarations
     | (exp)
    exprow ::= lab = exp (, exprow)? record fields

The above hierarchical definition for expressions represents associatibity among expression constructors. The associatibity of infix operator expressions infix are determined not by syntax but by the infix operator declarations. In the following sections, we first define in the next (18.1) elaboration rules of infix expressions. In the following sections, we define each of expression constructors and their types in the order of associatibity.