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