int main()
{
int r = yyparse();
- int maxdepth = 100;
+ int maxdepth = 10000;
if(r == 0){
printf(" ");
lambda_reduce(result, result, &maxdepth);
lambda_print(result, NULL);
- lambda_free(result);
}
yylex_destroy();
+ lambda_free(result);
decls_free();
return r;
}
void lambda_beta(struct lambda *ident, struct lambda *body, struct lambda *target, struct lambda *total)
{
- struct lambda cpy;
+ struct lambda *cpy;
switch(body->which){
case lambda_ident:
if(lambda_ident_eq(body, ident)){
lambda_print(total, NULL);
printf("β -> ");
- cpy = *copy(target);
+ cpy = copy(target);
free(body->data.identifier.ident);
if(total == body)
- *total = cpy;
- *body = cpy;
+ *total = *cpy;
+ *body = *cpy;
+ free(cpy);
}
break;
case lambda_abs:
case lambda_ident:
break;
case lambda_abs:
- lambda_reduce(t->data.abstraction.expr, total, maxdepth);
+// lambda_reduce(t->data.abstraction.expr, total, maxdepth);
break;
case lambda_app:
t1 = t->data.application.expr1;
lambda_print(total, t);
printf("β -> ");
lambda_beta(t1, t1->data.abstraction.expr, t2, total);
- (*maxdepth)--;
+ lambda_free(t2);
+ t2 = copy(t1->data.abstraction.expr);
if(total == t)
- *total = *t1->data.abstraction.expr;
- *t = *t1->data.abstraction.expr;
+ *total = *t2;
+ lambda_free(t1);
+ *t = *t2;
+ free(t2);
+ (*maxdepth)--;
lambda_reduce(t, total, maxdepth);
}
break;