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