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