1 /* $NetBSD: btyacc_destroy3.y,v 1.1.1.1 2015/01/03 22:58:23 christos Exp $ */ 2 3 %parse-param { 4 struct parser_param *param, 5 int flag 6 } 7 8 %{ 9 #include <stdlib.h> 10 11 typedef enum {cGLOBAL, cLOCAL} class; 12 typedef enum {tREAL, tINTEGER} type; 13 typedef char * name; 14 15 struct symbol { class c; type t; name id; }; 16 typedef struct symbol symbol; 17 18 struct namelist { symbol *s; struct namelist *next; }; 19 typedef struct namelist namelist; 20 21 struct parser_param { 22 int *rtrn; 23 symbol ss; 24 }; 25 26 extern symbol *mksymbol(type t, class c, name id); 27 28 #ifdef YYBISON 29 #define YYLEX_DECL() yylex(void) 30 #define YYERROR_DECL() yyerror(const char *s) 31 #endif 32 %} 33 34 %token <cval> GLOBAL LOCAL 35 %token <tval> REAL INTEGER 36 %token <id> NAME 37 38 %type <nlist> declaration 39 %type <nlist> locnamelist 40 %type <cval> class 41 %type <tval> type 42 %type <nlist> namelist 43 44 %destructor { if (!param->rtrn) close($$); } <file> 45 46 %destructor { 47 namelist *p = $$; 48 while (p != NULL) 49 { namelist *pp = p; 50 p = p->next; 51 free(pp->s); free(pp); 52 } 53 } declaration 54 55 %union 56 { 57 class cval; 58 type tval; 59 namelist * nlist; 60 name id; 61 } 62 63 %start declaration 64 65 %% 66 declaration: class type namelist'(' class ',' type ')' 67 { $$ = $3; } 68 | type locnamelist '(' class ')' 69 { $$ = $2; } 70 ; 71 72 class : GLOBAL { $$ = cGLOBAL; } 73 | LOCAL { $$ = cLOCAL; } 74 ; 75 76 type : REAL { $$ = tREAL; } 77 | INTEGER { $$ = tINTEGER; } 78 ; 79 80 namelist: namelist NAME 81 { $$->s = mksymbol($<tval>0, $<cval>0, $2); 82 $$->next = $1; 83 } 84 | NAME 85 { $$->s = mksymbol(0, 0, $1); 86 $$->next = NULL; 87 } 88 ; 89 90 locnamelist: namelist '(' LOCAL ',' type ')' 91 { $$ = $1; } 92 ; 93 %% 94 95 extern int YYLEX_DECL(); 96 extern void YYERROR_DECL(); 97