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