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