Change evaluation strategy to normal order
authorMart Lubbers <mart@martlubbers.net>
Wed, 16 May 2018 12:08:32 +0000 (14:08 +0200)
committerMart Lubbers <mart@martlubbers.net>
Wed, 16 May 2018 12:08:32 +0000 (14:08 +0200)
lambda.y
preamble [new file with mode: 0644]
reduce.c

index 830fa99..007fb2d 100644 (file)
--- a/lambda.y
+++ b/lambda.y
@@ -51,7 +51,6 @@ struct lambda *make_application(struct lambda *t1, struct lambda *t2)
 
 void decls_prepend(char *ident, struct lambda *value)
 {
-       printf("add: %s\n", ident);
        struct decllist *head = malloc(sizeof (struct decllist));
        head->next = decls;
        head->ident = ident;
@@ -61,14 +60,12 @@ void decls_prepend(char *ident, struct lambda *value)
 
 struct lambda *decls_lookup(char *ident)
 {
-       printf("lookup: %s\n", ident);
        struct decllist *c = decls;
        while(c != NULL){
                if(strcmp(c->ident, ident) == 0)
                        return copy(c->value);
                c = c->next;
        }
-       printf("Notfound\n");
        return make_ident(ident);
 }
 
diff --git a/preamble b/preamble
new file mode 100644 (file)
index 0000000..05ea3ca
--- /dev/null
+++ b/preamble
@@ -0,0 +1,4 @@
+I=\x.x;
+K=\x y.x;
+S=\x y z.x y(x z);
+O=(\x.x x)(\x.x x);
index 8537a20..7335bfd 100644 (file)
--- a/reduce.c
+++ b/reduce.c
@@ -45,8 +45,6 @@ void lambda_reduce(struct lambda *t, struct lambda *total, int *maxdepth)
                //If the first argument is an abstraction, we apply
                t1 = t->data.application.expr1;
                t2 = t->data.application.expr2;
-               lambda_reduce(t1, total, maxdepth);
-               lambda_reduce(t2, total, maxdepth);
                if(t1->which == lambda_abs){
                        subst(t1->data.abstraction.ident, t1->data.abstraction.expr, t2, total);
                        (*maxdepth)--;
@@ -57,6 +55,8 @@ void lambda_reduce(struct lambda *t, struct lambda *total, int *maxdepth)
                        lambda_print(total);
                        lambda_reduce(t, total, maxdepth);
                }
+               lambda_reduce(t1, total, maxdepth);
+               lambda_reduce(t, total, maxdepth);
                break;
        }
 }