1 %define parse.error verbose
4 #include "lambda.tab.h"
9 struct decllist *decls = NULL;
13 void yyerror(const char *str)
15 fprintf(stderr, "parse error: %s\n", str);
23 struct lambda *make_lambda()
25 return malloc(sizeof (struct lambda));
28 struct lambda *make_ident(char *i)
30 struct lambda *r = make_lambda();
31 r->which = lambda_ident;
32 r->data.identifier.ident = strdup(i);
33 r->data.identifier.revision = 0;
37 struct lambda *make_abstraction(char *i, struct lambda *t)
39 struct lambda *r = make_lambda();
40 r->which = lambda_abs;
41 r->data.abstraction.ident = strdup(i);
42 r->data.abstraction.revision = 0;
43 r->data.abstraction.expr = t;
47 struct lambda *make_application(struct lambda *t1, struct lambda *t2)
49 struct lambda *r = make_lambda();
50 r->which = lambda_app;
51 r->data.application.expr1 = t1;
52 r->data.application.expr2 = t2;
56 void decls_prepend(char *ident, struct lambda *value)
58 struct decllist *head = malloc(sizeof (struct decllist));
60 head->ident = strdup(ident);
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 struct decllist *c = decls;
79 unsigned int maxlen = 0, len;
81 len = strlen(c->ident);
82 maxlen = maxlen < len ? len : maxlen;
88 printf("%s ", c->ident);
89 len = strlen(c->ident);
90 for(unsigned int i = 1; i<maxlen-len; i++)
93 lambda_print(c->value, NULL);
101 while(decls != NULL){
103 lambda_free(decls->value);
112 %token LAMBDA DOT OBRACE CBRACE IDENT FUNC SEMICOLON ASSIGN
121 : FUNC ASSIGN term SEMICOLON
123 decls_prepend($1->data.identifier.ident, $3);
128 { $$ = make_application($1, $2); }
134 $$ = decls_lookup($1->data.identifier.ident);
139 $$ = make_ident($1->data.identifier.ident);
149 $$ = make_abstraction($1->data.identifier.ident, $2);