btyacc_destroy1.y revision 272955
150476Speter%parse-param { struct parser_param *param , int flag }
228869Swosch
328869Swosch%{
428869Swosch#include <stdlib.h>
528869Swosch
628869Swoschtypedef enum {cGLOBAL, cLOCAL} class;
728869Swoschtypedef enum {tREAL, tINTEGER} type;
828869Swoschtypedef char * name;
9120555Srwatson
10120555Srwatsonstruct symbol { class c; type t; name id; };
1128869Swoschtypedef struct symbol symbol;
1228869Swosch
1328869Swoschstruct namelist { symbol *s; struct namelist *next; };
14typedef struct namelist namelist;
15
16struct parser_param {
17	int *rtrn;
18	symbol ss;
19};
20
21extern symbol *mksymbol(type t, class c, name id);
22
23#ifdef YYBISON
24#define YYLEX_DECL() yylex(void)
25#define YYERROR_DECL() yyerror(const char *s)
26#endif
27%}
28
29%token <cval> GLOBAL LOCAL
30%token <tval> REAL INTEGER
31%token <id>   NAME
32
33%type <nlist> declaration
34%type <nlist> locnamelist
35%type <cval>  class
36%type <tval>  type
37%type <nlist>  namelist
38
39%destructor { if (!param->rtrn) close($$); } <file>
40
41%destructor	{
42		  namelist *p = $$;
43		  while (p != NULL)
44		  { namelist *pp = p;
45		    p = p->next;
46		    free(pp->s); free(pp);
47		  }
48		} declaration
49
50%union
51{
52    class	cval;
53    type	tval;
54    namelist *	nlist;
55    name	id;
56}
57
58%start declaration
59
60%%
61declaration: class type namelist'(' class ',' type ')'
62	{ $$ = $3; }
63	| type locnamelist '(' class ')'
64	{ $$ = $2; }
65	;
66
67class	: GLOBAL { $$ = cGLOBAL; }
68	| LOCAL  { $$ = cLOCAL; }
69	;
70
71type	: REAL    { $$ = tREAL; }
72	| INTEGER { $$ = tINTEGER; }
73	;
74
75namelist: namelist NAME
76	    { $$->s = mksymbol($<tval>0, $<cval>0, $2);
77	      $$->next = $1;
78	    }
79	| NAME
80	    { $$->s = mksymbol(0, 0, $1);
81	      $$->next = NULL;
82	    }
83	;
84
85locnamelist: namelist '(' LOCAL ',' type ')'
86	{ $$ = $1; }
87	;
88%%
89
90extern int YYLEX_DECL();
91extern void YYERROR_DECL();
92