parsing lambdas
[cc1516.git] / grammar / grammar.txt
index 98bb06e..b399311 100644 (file)
@@ -1,4 +1,6 @@
-<Prog>         ::= <FunDecl>+
+<Prog>         ::= <LetDecl>*
+                    <FunDecl>+
+<LetDecl>      ::= 'Let' <type> <id> '=' <Expr> ';'
 <FunDecl>      ::= <id> '(' <Type>* ')' ['::' <FunType] '{' <VarDecl>* <Stmt>+ '}'
 <FunType>      ::= <VoidType> ['->' <FunType>]
                  | '(' <FunType> ')'
@@ -9,6 +11,7 @@
                  | 'return' [<Expr>] ';'
 <VarDecl>      ::= <Type> <id> '=' <Expr> ';'
 <Expr>         ::= <BinOrExpr> [':' <Expr>]
+                 | <LambdaExpr>
 <BinOrExpr>    ::= <BinAndExpr> ['||' <BinOrExpr>]
 <BinAndExpr>   ::= <CompareExpr> ['&&' <BinAndExpr>]
 <CompareExpr>  ::= <PlusMinExpr> [('==' | '<' | '>' | '<=' | '>=' | '!=') <CompareExpr>]
@@ -23,6 +26,8 @@
                  | <FunCall> <FieldSels>
                  | '[]' <Expr>
                  | '(' <Expr> ',' <Expr> ')'
+                 | '"' <char> '"'
+<LamdaExpr>    ::= '\'<id>+ '->' <Expr>
 <FieldSels>    ::= ('.' ('hd'|'tl'|'fst'|'snd))*
 <FunCall>      ::= <id> ['(' <ActArgs>+ ')']
 <ActArgs>      ::= <Expr> [',' ActArgs]