struct lambda *make_ident(char *);
struct lambda *make_abstraction(char *, struct lambda *);
struct lambda *make_application(struct lambda *, struct lambda *);
+void decls_free();
#define YYSTYPE struct lambda *
#endif
\. return DOT;
\( return OBRACE;
\) return CBRACE;
-[a-z]+ yylval = make_ident(strdup(yytext)); return IDENT;
-[A-Z]+ yylval = make_ident(strdup(yytext)); return FUNC;
+[a-z]+ yylval = make_ident(yytext); return IDENT;
+[A-Z]+ yylval = make_ident(yytext); return FUNC;
%%
struct lambda *r = make_lambda();
r->which = lambda_abs;
r->data.abstraction.ident = strdup(i);
+ r->data.abstraction.revision = 0;
r->data.abstraction.expr = t;
return r;
}
{
struct decllist *head = malloc(sizeof (struct decllist));
head->next = decls;
- head->ident = ident;
+ head->ident = strdup(ident);
head->value = value;
printf("Declared %s as ", ident);
lambda_print(value, NULL);
return make_ident(ident);
}
+void decls_free()
+{
+ struct decllist *t;
+ while(decls != NULL){
+ free(decls->ident);
+ lambda_free(decls->value);
+ t = decls->next;
+ free(decls);
+ decls = t;
+ }
+}
+
%}
%token LAMBDA DOT OBRACE CBRACE IDENT FUNC SEMICOLON ASSIGN
{ result = $$; }
decl
: FUNC ASSIGN term SEMICOLON
- { decls_prepend($1->data.identifier.ident, $3); }
+ {
+ decls_prepend($1->data.identifier.ident, $3);
+ lambda_free($1);
+ }
term
: term appterm
{ $$ = make_application($1, $2); }