8 void subst(char *ident
, struct lambda
*t1
, struct lambda
*t2
, struct lambda
*total
)
13 if(strcmp(t1
->data
.identifier
, ident
) == 0){
15 free(t1
->data
.identifier
);
22 if(strcmp(t1
->data
.abstraction
.ident
, ident
) != 0)
23 subst(ident
, t1
->data
.abstraction
.expr
, t2
, total
);
26 subst(ident
, t1
->data
.application
.expr1
, t2
, total
);
27 subst(ident
, t1
->data
.application
.expr2
, t2
, total
);
33 void lambda_reduce(struct lambda
*t
, struct lambda
*total
, int *maxdepth
)
37 struct lambda
*t1
, *t2
;
42 lambda_reduce(t
->data
.abstraction
.expr
, total
, maxdepth
);
45 //If the first argument is an abstraction, we apply
46 t1
= t
->data
.application
.expr1
;
47 t2
= t
->data
.application
.expr2
;
48 lambda_reduce(t1
, total
, maxdepth
);
49 if(t1
->which
== lambda_abs
){
50 subst(t1
->data
.abstraction
.ident
, t1
->data
.abstraction
.expr
, t2
, total
);
53 *total
= *t1
->data
.abstraction
.expr
;
54 *t
= *t1
->data
.abstraction
.expr
;
57 lambda_reduce(t
, total
, maxdepth
);
59 lambda_reduce(t2
, total
, maxdepth
);