10SN/A%locations 29177SN/A%{ 30SN/A#include <stdlib.h> 40SN/A 50SN/Atypedef enum {cGLOBAL, cLOCAL} class; 60SN/Atypedef enum {tREAL, tINTEGER} type; 72362SN/Atypedef char * name; 80SN/A 92362SN/Astruct symbol { class c; type t; name id; }; 100SN/Atypedef struct symbol symbol; 110SN/A 120SN/Astruct namelist { symbol *s; struct namelist *next; }; 130SN/Atypedef struct namelist namelist; 140SN/A 150SN/Aextern symbol *mksymbol(type t, class c, name id); 160SN/A 170SN/A#ifdef YYBISON 180SN/A#define YYLEX_DECL() yylex(void) 190SN/A#define YYERROR_DECL() yyerror(const char *s) 200SN/A#endif 212362SN/A%} 222362SN/A 232362SN/A%token <cval> GLOBAL LOCAL 240SN/A%token <tval> REAL INTEGER 250SN/A%token <id> NAME 260SN/A 270SN/A%type <nlist> declaration namelist(<cval>, <tval>) locnamelist(<tval>) 280SN/A%destructor { } <nlist> 290SN/A%type <cval> class 300SN/A%type <tval> type 310SN/A 320SN/A%destructor { 330SN/A namelist *p = $$; 340SN/A while (p != NULL) 350SN/A { namelist *pp = p; 360SN/A p = p->next; 370SN/A free(pp->s); free(pp); 380SN/A } 390SN/A } <nlist> 400SN/A 410SN/A%union 420SN/A{ 430SN/A class cval; 440SN/A type tval; 450SN/A namelist * nlist; 460SN/A name id; 470SN/A} 480SN/A 490SN/A%start declaration 500SN/A 510SN/A%% 520SN/Adeclaration: class type namelist($1, $2) 530SN/A { $$ = $3; } 540SN/A | type locnamelist($1) 550SN/A { $$ = $2; } 569177SN/A ; 570SN/A 580SN/Aclass : GLOBAL { $$ = cGLOBAL; } 590SN/A | LOCAL { $$ = cLOCAL; } 609177SN/A ; 610SN/A 620SN/Atype : REAL { $$ = tREAL; } 630SN/A | INTEGER { $$ = tINTEGER; } 640SN/A ; 650SN/A 660SN/Anamelist($c, $t): namelist NAME 670SN/A { $$->s = mksymbol($t, $c, $2); 680SN/A $$->next = $1; 690SN/A } 700SN/A | NAME 719177SN/A { $$->s = mksymbol($t, $c, $1); 720SN/A $$->next = NULL; 730SN/A } 740SN/A ; 750SN/A 760SN/Alocnamelist($t): namelist 770SN/A { $$ = $1; @$ = @2; } 780SN/A ; 790SN/A%% 800SN/A 810SN/Aextern int YYLEX_DECL(); 820SN/Aextern void YYERROR_DECL(); 830SN/A