------------------------------------------------------------------------------- -- * PROGRAM ------------------------------------------------------------------------------- Program. Program ::= [Def] ; ------------------------------------------------------------------------------- -- * TOP-LEVEL ------------------------------------------------------------------------------- DBind. Def ::= Bind ; DSig. Def ::= Sig ; DData. Def ::= Data ; Sig. Sig ::= LIdent ":" Type ; Bind. Bind ::= LIdent [LIdent] "=" Exp ; ------------------------------------------------------------------------------- -- * TYPES ------------------------------------------------------------------------------- TLit. Type2 ::= UIdent ; TVar. Type2 ::= TVar ; TAll. Type1 ::= "forall" TVar "." Type ; TData. Type1 ::= UIdent "(" [Type] ")" ; internal TEVar. Type1 ::= TEVar ; TFun. Type ::= Type1 "->" Type ; MkTVar. TVar ::= LIdent ; internal MkTEVar. TEVar ::= LIdent ; ------------------------------------------------------------------------------- -- * DATA TYPES ------------------------------------------------------------------------------- Constructor. Constructor ::= UIdent ":" Type ; Data. Data ::= "data" Type "where" "{" [Constructor] "}" ; ------------------------------------------------------------------------------- -- * EXPRESSIONS ------------------------------------------------------------------------------- EAnn. Exp5 ::= "(" Exp ":" Type ")" ; EVar. Exp4 ::= LIdent ; EInj. Exp4 ::= UIdent ; ELit. Exp4 ::= Lit ; EApp. Exp3 ::= Exp3 Exp4 ; EAdd. Exp1 ::= Exp1 "+" Exp2 ; ELet. Exp ::= "let" Bind "in" Exp ; EAbs. Exp ::= "\\" LIdent "." Exp ; ECase. Exp ::= "case" Exp "of" "{" [Branch] "}"; ------------------------------------------------------------------------------- -- * LITERALS ------------------------------------------------------------------------------- LInt. Lit ::= Integer ; LChar. Lit ::= Char ; ------------------------------------------------------------------------------- -- * CASE ------------------------------------------------------------------------------- Branch. Branch ::= Pattern "=>" Exp ; PVar. Pattern ::= LIdent ; PLit. Pattern ::= Lit ; PInj. Pattern ::= UIdent [Pattern] ; PCatch. Pattern ::= "_" ; ------------------------------------------------------------------------------- -- * AUX ------------------------------------------------------------------------------- separator Def ";" ; separator nonempty Constructor "" ; separator Type " " ; separator Pattern " " ; separator Branch "," ; separator Ident " "; separator LIdent " "; separator TVar " " ; coercions Exp 5 ; coercions Type 2 ; token UIdent (upper (letter | digit | '_')*) ; token LIdent (lower (letter | digit | '_')*) ; comment "--" ; comment "{-" "-}" ;