1 /*        $NetBSD: inherit1.y,v 1.1.1.3 2016/01/09 21:59:45 christos Exp $      */
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 extern 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 extern int YYLEX_DECL();
22 extern void YYERROR_DECL();
23 #endif
24 %}
25 
26 %token <cval> GLOBAL LOCAL
27 %token <tval> REAL INTEGER
28 %token <id>   NAME
29 
30 %type <nlist> declaration namelist locnamelist
31 %type <cval>  class
32 %type <tval>  type
33 
34 %union
35 {
36     class cval;
37     type  tval;
38     namelist *      nlist;
39     name  id;
40 }
41 
42 %start declaration
43 
44 %%
45 declaration: class type namelist
46           { $$ = $3; }
47           | type locnamelist
48           { $$ = $2; }
49           ;
50 
51 class     : GLOBAL { $$ = cGLOBAL; }
52           | LOCAL  { $$ = cLOCAL; }
53           ;
54 
55 type      : REAL    { $$ = tREAL; }
56           | INTEGER { $$ = tINTEGER; }
57           ;
58 
59 namelist: namelist NAME
60               { $$->s = mksymbol($<tval>0, $<cval>-1, $2);
61                 $$->next = $1;
62               }
63           | NAME
64               { $$->s = mksymbol($<tval>0, $<cval>-1, $1);
65                 $$->next = NULL;
66               }
67           ;
68 
69 locnamelist:
70           { $<cval>$ = cLOCAL; }    /* set up semantic stack for <class> = LOCAL */
71           { $<tval>$ = $<tval>-1; } /* copy <type> to where <namelist> expects it */
72           namelist
73           { $$ = $3; }
74           ;
75 %%
76 
77 extern int YYLEX_DECL();
78 extern void YYERROR_DECL();
79