The specification of the syntax of Standard ML in the Definition of Standard ML (Revised) is spread over multiple chapters, which makes it hard to understand. Furthermore, the grammar allows many non-sensical forms that are of little use to programmers.
The grammar given below collects together all of the various forms into a single collected syntax. Furthermore, the grammar has been refined to make it more regular and to rule out some of the more ridiculous terms allowed by the Definition. Thus, the language defined by this grammar is a subset of that given in the Definition, but it should be more useful to the SML programmer.
The Collected Syntax of Standard ML
::= |
||
|
||
::= |
||
| |
exp ; |
|
|
||
::= |
sigdec ;? |
|
| |
strdec ;? |
|
| |
fundec ;? |
|
|
||
::= |
||
|
||
::= |
sigid = sigexp |
|
|
||
::= |
sig specs end |
|
| |
sigid |
|
| |
||
|
||
::= |
where type wheretypespec ( and wheretypespec )* |
|
|
||
::= |
||
|
||
::= |
empty |
|
| |
tyvar |
|
| |
( tyvar ( , tyvar )* ) |
|
|
||
::= |
||
| |
||
| |
||
| |
||
| |
datatype tycon = datatype longtycon |
|
| |
||
| |
||
| |
include sigexp |
|
| |
include sigid+ |
|
| |
||
|
||
::= |
sharing type longtycon ( = longtycon )+ |
|
| |
sharing longstrid ( = longstrid )+ |
|
|
||
::= |
( spec ;? )* |
|
|
||
::= |
vid : ty |
|
|
||
::= |
tyvarseq tycon |
|
|
||
::= |
||
|
||
::= |
conid ( of ty )? |
|
|
||
::= |
conid ( of ty )? |
|
|
||
::= |
strid : sigexp |
|
|
||
::= |
||
| |
||
| |
||
|
||
::= |
( strdec ; )* |
|
|
||
::= |
strid sigconstraint? = strexp |
|
|
||
::= |
: sigexp |
|
| |
:> sigexp |
|
|
||
::= |
struct strdecs end |
|
| |
longstrid |
|
| |
||
| |
funid ( functorarg ) |
|
| |
||
|
||
::= |
||
| |
||
|
||
::= |
||
|
||
::= |
funid ( functorparam ) sigconstraint? = strexp |
|
|
||
::= |
||
| |
||
|
||
::= |
||
| |
||
| |
||
| |
||
| |
||
| |
datatype tycon = datatype longtycon |
|
| |
||
| |
||
| |
||
| |
open longstrid+ |
|
| |
infix precedence? valid+ |
|
| |
infixr precedence? valid+ |
|
| |
nofix valid+ |
|
|
||
::= |
( dec ;? )* |
|
|
||
::= |
||
|
||
::= |
||
|
||
::= |
||
|
||
::= |
||
| |
||
| |
||
| |
||
|
||
::= |
||
|
||
::= |
||
|
||
::= |
op? vid ( of ty )? |
|
|
||
::= |
||
|
||
::= |
||
| |
vid = longvid |
|
|
||
::= |
||
|
||
::= |
||
|
||
::= |
tyarg+ longtycon |
|
| |
||
|
||
::= |
||
| |
||
|
||
::= |
tyvar |
|
| |
longtycon |
|
| |
( ty ) |
|
| |
{ tyrow? } |
|
|
||
::= |
||
|
||
::= |
||
| |
||
|
||
::= |
||
|
||
::= |
||
| |
||
|
||
::= |
_ |
|
| |
||
| |
op? longvid |
|
| |
{ patrow? } |
|
| |
( patseq? ) |
|
| |
[ patseq? ] |
|
|
||
::= |
... |
|
| |
||
|
||
::= |
||
| |
lab = pat |
|
|
||
::= |
||
|
||
::= |
||
| |
||
| |
||
| |
||
| |
raise exp |
|
| |
||
|
||
::= |
fn match |
|
|
||
::= |
||
|
||
::= |
||
|
||
::= |
||
|
||
::= |
||
|
||
::= |
||
|
||
::= |
||
|
||
::= |
||
| |
op? longvid |
|
| |
# lab |
|
| |
{ exprow? } |
|
| |
( expseq? ) |
|
| |
[ expseq? ] |
|
| |
||
| |
||
|
||
::= |
||
|
||
::= |
||
|
||
::= |
||
|
||
::= |
||
|
||
::= |
chrlit |
|
| |
strlit |
|
| |
wordlit |
|
| |
intlit |
|
|
||
::= |
||
| |
reallit |