literals
[lambda.git] / lambda.y
index b7e51a8..a9b0f14 100644 (file)
--- a/lambda.y
+++ b/lambda.y
@@ -53,6 +53,21 @@ struct lambda *make_application(struct lambda *t1, struct lambda *t2)
        return r;
 }
 
+struct lambda *make_numeral(unsigned int i)
+{
+       struct lambda *body = make_ident("x");
+       while(i-- > 0)
+               body = make_application(make_ident("f"), body);
+       return make_abstraction("f", make_abstraction("x", body));
+}
+
+struct lambda *make_bool(bool b)
+{
+       return b
+               ? make_abstraction("a", make_abstraction("b", make_ident("a")))
+               : make_abstraction("a", make_abstraction("b", make_ident("b")));
+}
+
 void decls_prepend(char *ident, struct lambda *value)
 {
        struct decllist *head = malloc(sizeof (struct decllist));
@@ -109,7 +124,7 @@ void decls_free()
 
 %}
 
-%token LAMBDA DOT OBRACE CBRACE IDENT FUNC SEMICOLON ASSIGN
+%token LAMBDA DOT OBRACE CBRACE IDENT FUNC SEMICOLON ASSIGN LITERAL
 
 %%
 
@@ -129,7 +144,9 @@ term
        | appterm
                { $$ = $1; }
 appterm
-       : FUNC
+       : LITERAL
+               { $$ = $1; }
+       | FUNC
                {
                        $$ = decls_lookup($1->data.identifier.ident);
                        lambda_free($1);