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 = strdup(i);
35 struct lambda *make_abstraction(char *i, struct lambda *t)
37 struct lambda *r = make_lambda();
38 r->which = lambda_abs;
39 r->data.abstraction.ident = strdup(i);
40 r->data.abstraction.expr = t;
44 struct lambda *make_application(struct lambda *t1, struct lambda *t2)
46 struct lambda *r = make_lambda();
47 r->which = lambda_app;
48 r->data.application.expr1 = t1;
49 r->data.application.expr2 = t2;
53 void decls_prepend(char *ident, struct lambda *value)
55 struct decllist *head = malloc(sizeof (struct decllist));
59 printf("Declared %s as ", ident);
64 struct lambda *decls_lookup(char *ident)
66 struct decllist *c = decls;
68 if(strcmp(c->ident, ident) == 0)
69 return copy(c->value);
72 return make_ident(ident);
77 %token LAMBDA DOT OBRACE CBRACE IDENT FUNC SEMICOLON ASSIGN
86 : FUNC ASSIGN term SEMICOLON
87 { decls_prepend($1->data.identifier, $3); }
90 { $$ = make_application($1, $2); }
96 $$ = decls_lookup($1->data.identifier);
101 $$ = make_ident($1->data.identifier);
111 $$ = make_abstraction($1->data.identifier, $2);