1Parses simple lambda expressions to combinators 2 3> { 4 5> module Parser where 6 7> import Lexer 8> import Convert 9> import PreludeGlaArray 10 11> } 12 13> %name parse 14> %tokentype { Token } 15> %token idT { Ident $$ } 16> numT { Number $$ } 17> boolT { Boolean $$ } 18> "(" { LeftBracket } 19> ")" { RightBracket } 20> "[" { LeftSquare } 21> "]" { RightSquare } 22> "[]" { EmptyList } 23> ";" { SemiColon } 24> ":" { Colon } 25> "+" { Infix "+" } 26> "-" { Infix "-" } 27> "/" { Infix "/" } 28> "*" { Infix "*" } 29> "==" { Infix "==" } 30> "/=" { Infix "/=" } 31> ">" { Infix ">" } 32> "<" { Infix "<" } 33> ">=" { Infix ">=" } 34> "<=" { Infix "<=" } 35> "=" { Builtin "=" } 36> "else" { Builtin "else" } 37> "if" { Builtin "if" } 38> "in" { Builtin "in" } 39> "let" { Builtin "let" } 40> "then" { Builtin "then" } 41> "end" { Builtin "end" } 42> %% 43 44> P : "let" Dec "in" B { mkLet $2 $4} 45> | "if" B "then" B "else" B { mkIf $2 $4 $6} 46> | B { $1 } 47 48> B :: { Seq (Ptr Exp) } 49> B : E "==" E { mkOp $1 Equ $3 } 50> | E "/=" E { mkOp $1 NEq $3 } 51> | E ">" E { mkOp $1 GT $3 } 52> | E "<" E { mkOp $1 LT $3 } 53> | E ">=" E { mkOp $1 GTE $3 } 54> | E "<=" E { mkOp $1 LTE $3 } 55> | E { $1 } 56 57> E :: { Seq (Ptr Exp) } 58> E : E "+" T { mkOp $1 Add $3} 59> | E "-" T { mkOp $1 Sub $3} 60> | T { $1 } 61 62> T :: { Seq (Ptr Exp) } 63> T : T "*" F { mkOp $1 Mul $3 } 64> | T "/" F { mkOp $1 Quo $3 } 65> | F { $1 } 66 67> F :: { Seq (Ptr Exp) } 68> F : "(" B ")" { $2 } 69> | numT { mkNum $1 } 70> | boolT { mkBool $1 } 71> | idT { newPtr (mkVar $1) } 72> | Apps { mkApps $1 } 73 74> Apps :: { Seq [Ptr Exp] } 75> Apps : F Apps { mkApp $1 $2 } 76> | F { mkAtom $1 } 77 78> Dec :: { (Token,Seq (Ptr Exp)) } 79> Dec : idT Args "=" B { ($1, mkFun $1 $2 $4) } 80 81> Args :: { [Exp] } 82> Args : idT Args { mkVar $1 : $2} 83> | { [] } 84 85> { 86 87> happyError :: Text a => a -> b 88> happyError x = error ("Parse error, line " ++ show x ++ "\n") 89 90> } 91