Compilation = [UNSAFE] (Interface | Module) | GenInf | GenMod.
Interface = INTERFACE Id ";" {Import} {Decl} END Id "."
| INTERFACE Id "=" Id GenActls END Id ".".
Module = MODULE Id [EXPORTS IdList] ";" {Import} Block Id "."
| MODULE Id [EXPORTS IdList] "=" Id GenActls END Id ".".
GenInf = GENERIC INTERFACE Id GenFmls ";" {Import} {Decl} END Id ".".
GenMod = GENERIC MODULE Id GenFmls ";" {Import} Block Id ".".
Import = AsImport | FromImport.
AsImport = IMPORT ImportItem {"," ImportItem} ";".
FromImport = FROM Id IMPORT IdList ";".
Block = {Decl} BEGIN S END.
Decl = CONST {ConstDecl ";"}
| TYPE {TypeDecl ";"}
| EXCEPTION {ExceptionDecl ";"}
| VAR {VariableDecl ";"}
| ProcedureHead ["=" Block Id] ";"
| REVEAL {QualId ("=" | "<:") Type ";"}.
GenFmls = "(" [IdList] ")".
GenActls = "(" [IdList] ")".
ImportItem = Id | Id AS Id.
ConstDecl = Id [":" Type] "=" ConstExpr.
TypeDecl = Id ("=" | "<:") Type.
ExceptionDecl = Id ["(" Type ")"].
VariableDecl = IdList (":" Type & ":=" Expr).
ProcedureHead = PROCEDURE Id Signature.
Signature = "(" Formals ")" [":" Type] [RAISES Raises].
Formals = [ Formal {";" Formal} [";"] ].
Formal = [Mode] IdList (":" Type & ":=" ConstExpr).
Mode = VALUE | VAR | READONLY.
Raises = "{" [ QualId {"," QualId} ] "}" | ANY.