1/* $NetBSD: inherit1.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) 21extern int YYLEX_DECL(); 22extern 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%% 45declaration: class type namelist 46 { $$ = $3; } 47 | type locnamelist 48 { $$ = $2; } 49 ; 50 51class : GLOBAL { $$ = cGLOBAL; } 52 | LOCAL { $$ = cLOCAL; } 53 ; 54 55type : REAL { $$ = tREAL; } 56 | INTEGER { $$ = tINTEGER; } 57 ; 58 59namelist: 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 69locnamelist: 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 77extern int YYLEX_DECL(); 78extern void YYERROR_DECL(); 79