parsing lambdas
[cc1516.git] / grammar / grammar.txt
index 4325c92..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>]
@@ -24,6 +27,7 @@
                  | '[]' <Expr>
                  | '(' <Expr> ',' <Expr> ')'
                  | '"' <char> '"'
+<LamdaExpr>    ::= '\'<id>+ '->' <Expr>
 <FieldSels>    ::= ('.' ('hd'|'tl'|'fst'|'snd))*
 <FunCall>      ::= <id> ['(' <ActArgs>+ ')']
 <ActArgs>      ::= <Expr> [',' ActArgs]