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