From 300960def6015f0d0f7e6f649855babe74fd51e9 Mon Sep 17 00:00:00 2001 From: Mart Lubbers Date: Wed, 16 May 2018 14:08:32 +0200 Subject: [PATCH] Change evaluation strategy to normal order --- lambda.y | 3 --- preamble | 4 ++++ reduce.c | 4 ++-- 3 files changed, 6 insertions(+), 5 deletions(-) create mode 100644 preamble diff --git a/lambda.y b/lambda.y index 830fa99..007fb2d 100644 --- 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 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); diff --git a/reduce.c b/reduce.c index 8537a20..7335bfd 100644 --- 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; } } -- 2.20.1