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