]> CyberLeo.Net >> Repos - FreeBSD/releng/10.2.git/blob - contrib/byacc/test/err_inherit1.y
- Copy stable/10@285827 to releng/10.2 in preparation for 10.2-RC1
[FreeBSD/releng/10.2.git] / contrib / byacc / test / err_inherit1.y
1 %{
2 #include <stdlib.h>
3
4 typedef enum {cGLOBAL, cLOCAL} class;
5 typedef enum {tREAL, tINTEGER} type;
6 typedef char * name;
7
8 struct symbol { class c; type t; name id; };
9 typedef struct symbol symbol;
10
11 struct namelist { symbol *s; struct namelist *next; };
12 typedef struct namelist namelist;
13
14 extern 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)
19 #endif
20 %}
21
22 %token <cval> GLOBAL LOCAL
23 %token <tval> REAL INTEGER
24 %token <id>   NAME
25
26 %type <nlist> declaration namelist(<cval>, <tval>) locnamelist(<tval>)
27 %type <cval>  class
28 %type <tval>  type
29
30 %destructor     {
31                   namelist *p = $$;
32                   while (p != NULL)
33                   { namelist *pp = p;
34                     p = p->next;
35                     free(pp->s); free(pp);
36                   }
37                 } <nlist>
38
39 %union
40 {
41     class       cval;
42     type        tval;
43     namelist *  nlist;
44     name        id;
45 }
46
47 %start declaration
48
49 %%
50 declaration: class type namelist($1, $2)
51         { $$ = $3; }
52         | type locnamelist($1)
53         { $$ = $2; }
54         ;
55
56 class   : GLOBAL { $$ = cGLOBAL; }
57         | LOCAL  { $$ = cLOCAL; }
58         ;
59
60 type    : REAL    { $$ = tREAL; }
61         | INTEGER { $$ = tINTEGER; }
62         ;
63
64 namelist($c, $t