3 #include "lambda.tab.h"
8 struct decllist *decls = NULL;
12 void yyerror(const char *str)
14 fprintf(stderr, "parse error: %s\n", str);
22 struct lambda *make_lambda()
24 return malloc(sizeof (struct lambda));
27 struct lambda *make_ident(char *i)
29 struct lambda *r = make_lambda();
30 r->which = lambda_ident;
31 r->data.identifier.ident = strdup(i);
32 r->data.identifier.revision = 0;
36 struct lambda *make_abstraction(char *i, struct lambda *t)
38 struct lambda *r = make_lambda();
39 r->which = lambda_abs;
40 r->data.abstraction.ident = strdup(i);
41 r->data.abstraction.expr = t;
45 struct lambda *make_application(struct lambda *t1, struct lambda *t2)
47 struct lambda *r = make_lambda();
48 r->which = lambda_app;
49 r->data.application.expr1 = t1;
50 r->data.application.expr2 = t2;
54 void decls_prepend(char *ident, struct lambda *value)
56 struct decllist *head = malloc(sizeof (struct decllist));
60 printf("Declared %s as ", ident);
61 lambda_print(value, NULL);
65 struct lambda *decls_lookup(char *ident)
67 struct decllist *c = decls;
69 if(strcmp(c->ident, ident) == 0)
70 return copy(c->value);
73 return make_ident(ident);
78 %token LAMBDA DOT OBRACE CBRACE IDENT FUNC SEMICOLON ASSIGN
87 : FUNC ASSIGN term SEMICOLON
88 { decls_prepend($1->data.identifier.ident, $3); }
91 { $$ = make_application($1, $2); }
97 $$ = decls_lookup($1->data.identifier.ident);
102 $$ = make_ident($1->data.identifier.ident);
112 $$ = make_abstraction($1->data.identifier.ident, $2);