1/* $NetBSD: btyacc_destroy3.y,v 1.1.1.3 2016/01/09 21:59:45 christos Exp $ */ 2 3%parse-param { 4 struct parser_param *param, 5 int flag 6 } 7 8%{ 9#include <stdlib.h> 10 11typedef enum {cGLOBAL, cLOCAL} class; 12typedef enum {tREAL, tINTEGER} type; 13typedef char * name; 14 15struct symbol { class c; type t; name id; }; 16typedef struct symbol symbol; 17 18struct namelist { symbol *s; struct namelist *next; }; 19typedef struct namelist namelist; 20 21struct parser_param { 22 int *rtrn; 23 symbol ss; 24}; 25 26extern 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%% 66declaration: class type namelist'(' class ',' type ')' 67 { $$ = $3; } 68 | type locnamelist '(' class ')' 69 { $$ = $2; } 70 ; 71 72class : GLOBAL { $$ = cGLOBAL; } 73 | LOCAL { $$ = cLOCAL; } 74 ; 75 76type : REAL { $$ = tREAL; } 77 | INTEGER { $$ = tINTEGER; } 78 ; 79 80namelist: 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 90locnamelist: namelist '(' LOCAL ',' type ')' 91 { $$ = $1; } 92 ; 93%% 94 95extern int YYLEX_DECL(); 96extern void YYERROR_DECL(); 97