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