2 static const char yysccsid
[] = "@(#)yaccpar 1.9 (Berkeley) 02/21/93";
11 #define YYPATCH 20100216
14 #define yyclearin (yychar = YYEMPTY)
15 #define yyerrok (yyerrflag = 0)
16 #define YYRECOVERING() (yyerrflag != 0)
20 /* compatibility with bison */
22 /* compatibility with FreeBSD */
23 #ifdef YYPARSE_PARAM_TYPE
24 #define YYPARSE_DECL() yyparse(YYPARSE_PARAM_TYPE YYPARSE_PARAM)
26 #define YYPARSE_DECL() yyparse(void *YYPARSE_PARAM)
29 #define YYPARSE_DECL() yyparse(void)
30 #endif /* YYPARSE_PARAM */
32 extern int YYPARSE_DECL();
35 * Copyright (c) 1998 - 2000 Kungliga Tekniska Högskolan
36 * (Royal Institute of Technology, Stockholm, Sweden).
37 * All rights reserved.
39 * Redistribution and use in source and binary forms, with or without
40 * modification, are permitted provided that the following conditions
43 * 1. Redistributions of source code must retain the above copyright
44 * notice, this list of conditions and the following disclaimer.
46 * 2. Redistributions in binary form must reproduce the above copyright
47 * notice, this list of conditions and the following disclaimer in the
48 * documentation and/or other materials provided with the distribution.
50 * 3. Neither the name of the Institute nor the names of its contributors
51 * may be used to endorse or promote products derived from this software
52 * without specific prior written permission.
54 * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
55 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
56 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
57 * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
58 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
59 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
60 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
61 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
62 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
63 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
67 #include "compile_et.h"
70 void yyerror (char *s
);
71 static long name2number(const char *str
);
75 /* This is for bison */
77 #if !defined(alloca) && !defined(HAVE_ALLOCA)
78 #define alloca(x) malloc(x)
81 #define YYMALLOC malloc
97 static const short yylhs
[] = { -1,
98 0, 0, 1, 1, 3, 4, 4, 2, 2, 5,
101 static const short yylen
[] = { 2,
102 0, 2, 2, 1, 2, 2, 3, 1, 2, 2,
105 static const short yydefred
[] = { 0,
106 0, 0, 0, 0, 0, 4, 0, 5, 0, 0,
107 0, 14, 0, 8, 3, 7, 10, 11, 0, 9,
110 static const short yydgoto
[] = { 3,
113 static const short yysindex
[] = { -247,
114 -263, -258, 0, -256, -245, 0, -250, 0, -249, -246,
115 -244, 0, -256, 0, 0, 0, 0, 0, -28, 0,
118 static const short yyrindex
[] = { 18,
119 0, 0, 0, 0, 0, 0, -251, 0, 0, 1,
120 0, 0, 21, 0, 0, 0, 0, 0, 0, 0,
123 static const short yygindex
[] = { 0,
126 #define YYTABLESIZE 263
127 static const short yytable
[] = { 7,
128 12, 9, 10, 11, 8, 12, 6, 6, 6, 1,
129 6, 1, 16, 2, 17, 21, 18, 1, 19, 22,
130 2, 15, 20, 0, 0, 0, 0, 0, 0, 0,
131 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
132 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
133 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
134 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
135 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
136 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
137 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
138 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
139 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
140 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
141 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
142 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
143 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
144 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
145 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
146 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
147 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
148 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
149 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
150 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
151 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
152 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
153 0, 0, 0, 0, 0, 0, 0, 0, 12, 12,
156 static const short yycheck
[] = { 263,
157 0, 258, 259, 260, 263, 262, 258, 259, 260, 257,
158 262, 257, 263, 261, 264, 44, 263, 0, 263, 263,
159 0, 5, 13, -1, -1, -1, -1, -1, -1, -1,
160 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
161 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
162 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
163 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
164 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
165 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
166 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
167 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
168 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
169 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
170 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
171 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
172 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
173 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
174 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
175 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
176 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
177 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
178 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
179 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
180 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
181 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
182 -1, -1, -1, -1, -1, -1, -1, -1, 258, 259,
189 #define YYMAXTOKEN 264
191 static const char *yyname
[] = {
193 "end-of-file",0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
194 0,0,0,0,0,0,0,0,0,0,"','",0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
195 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
196 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
197 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
198 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
199 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,"ET","INDEX","PREFIX","EC",
200 "ID","END","STRING","NUMBER",
202 static const char *yyrule
[] = {
205 "file : header statements",
210 "et : ET STRING STRING",
211 "statements : statement",
212 "statements : statements statement",
213 "statement : INDEX NUMBER",
214 "statement : PREFIX STRING",
215 "statement : PREFIX",
216 "statement : EC STRING ',' STRING",
225 /* define the initial stack-sizes */
228 #define YYMAXDEPTH YYSTACKSIZE
231 #define YYSTACKSIZE YYMAXDEPTH
233 #define YYSTACKSIZE 500
234 #define YYMAXDEPTH 500
238 #define YYINITSTACKSIZE 500
259 /* variables for the parser stack */
260 static YYSTACKDATA yystack
;
263 name2number(const char *str
)
267 const char *x
= "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
268 "abcdefghijklmnopqrstuvwxyz0123456789_";
269 if(strlen(str
) > 4) {
270 yyerror("table name too long");
273 for(p
= str
; *p
; p
++){
274 char *q
= strchr(x
, *p
);
276 yyerror("invalid character in table name");
279 num
= (num
<< 6) + (q
- x
) + 1;
283 num
= -(0xffffffff - num
+ 1);
290 _lex_error_message ("%s\n", s
);
292 /* allocate initial stack or double stack size, up to YYMAXDEPTH */
293 static int yygrowstack(YYSTACKDATA
*data
)
300 if ((newsize
= data
->stacksize
) == 0)
301 newsize
= YYINITSTACKSIZE
;
302 else if (newsize
>= YYMAXDEPTH
)
304 else if ((newsize
*= 2) > YYMAXDEPTH
)
305 newsize
= YYMAXDEPTH
;
307 i
= data
->s_mark
- data
->s_base
;
308 newss
= (data
->s_base
!= 0)
309 ? (short *)realloc(data
->s_base
, newsize
* sizeof(*newss
))
310 : (short *)malloc(newsize
* sizeof(*newss
));
314 data
->s_base
= newss
;
315 data
->s_mark
= newss
+ i
;
317 newvs
= (data
->l_base
!= 0)
318 ? (YYSTYPE
*)realloc(data
->l_base
, newsize
* sizeof(*newvs
))
319 : (YYSTYPE
*)malloc(newsize
* sizeof(*newvs
));
323 data
->l_base
= newvs
;
324 data
->l_mark
= newvs
+ i
;
326 data
->stacksize
= newsize
;
327 data
->s_last
= data
->s_base
+ newsize
- 1;
331 #if YYPURE || defined(YY_NO_LEAKS)
332 static void yyfreestack(YYSTACKDATA
*data
)
336 memset(data
, 0, sizeof(*data
));
339 #define yyfreestack(data) /* nothing */
342 #define YYABORT goto yyabort
343 #define YYREJECT goto yyabort
344 #define YYACCEPT goto yyaccept
345 #define YYERROR goto yyerrlab
350 int yym
, yyn
, yystate
;
354 if ((yys
= getenv("YYDEBUG")) != 0)
357 if (yyn
>= '0' && yyn
<= '9')
368 memset(&yystack
, 0, sizeof(yystack
));
371 if (yystack
.s_base
== NULL
&& yygrowstack(&yystack
)) goto yyoverflow
;
372 yystack
.s_mark
= yystack
.s_base
;
373 yystack
.l_mark
= yystack
.l_base
;
378 if ((yyn
= yydefred
[yystate
]) != 0) goto yyreduce
;
381 if ((yychar
= yylex()) < 0) yychar
= 0;
386 if (yychar
<= YYMAXTOKEN
) yys
= yyname
[yychar
];
387 if (!yys
) yys
= "illegal-symbol";
388 printf("%sdebug: state %d, reading %d (%s)\n",
389 YYPREFIX
, yystate
, yychar
, yys
);
393 if ((yyn
= yysindex
[yystate
]) && (yyn
+= yychar
) >= 0 &&
394 yyn
<= YYTABLESIZE
&& yycheck
[yyn
] == yychar
)
398 printf("%sdebug: state %d, shifting to state %d\n",
399 YYPREFIX
, yystate
, yytable
[yyn
]);
401 if (yystack
.s_mark
>= yystack
.s_last
&& yygrowstack(&yystack
))
405 yystate
= yytable
[yyn
];
406 *++yystack
.s_mark
= yytable
[yyn
];
407 *++yystack
.l_mark
= yylval
;
409 if (yyerrflag
> 0) --yyerrflag
;
412 if ((yyn
= yyrindex
[yystate
]) && (yyn
+= yychar
) >= 0 &&
413 yyn
<= YYTABLESIZE
&& yycheck
[yyn
] == yychar
)
418 if (yyerrflag
) goto yyinrecovery
;
420 yyerror("syntax error");
433 if ((yyn
= yysindex
[*yystack
.s_mark
]) && (yyn
+= YYERRCODE
) >= 0 &&
434 yyn
<= YYTABLESIZE
&& yycheck
[yyn
] == YYERRCODE
)
438 printf("%sdebug: state %d, error recovery shifting\
439 to state %d\n", YYPREFIX
, *yystack
.s_mark
, yytable
[yyn
]);
441 if (yystack
.s_mark
>= yystack
.s_last
&& yygrowstack(&yystack
))
445 yystate
= yytable
[yyn
];
446 *++yystack
.s_mark
= yytable
[yyn
];
447 *++yystack
.l_mark
= yylval
;
454 printf("%sdebug: error recovery discarding state %d\n",
455 YYPREFIX
, *yystack
.s_mark
);
457 if (yystack
.s_mark
<= yystack
.s_base
) goto yyabort
;
465 if (yychar
== 0) goto yyabort
;
470 if (yychar
<= YYMAXTOKEN
) yys
= yyname
[yychar
];
471 if (!yys
) yys
= "illegal-symbol";
472 printf("%sdebug: state %d, error recovery discards token %d (%s)\n",
473 YYPREFIX
, yystate
, yychar
, yys
);
483 printf("%sdebug: state %d, reducing by rule %d (%s)\n",
484 YYPREFIX
, yystate
, yyn
, yyrule
[yyn
]);
488 yyval
= yystack
.l_mark
[1-yym
];
490 memset(&yyval
, 0, sizeof yyval
);
495 id_str
= yystack
.l_mark
[0].string
;
500 base_id
= name2number(yystack
.l_mark
[0].string
);
501 strlcpy(name
, yystack
.l_mark
[0].string
, sizeof(name
));
502 free(yystack
.l_mark
[0].string
);
507 base_id
= name2number(yystack
.l_mark
[-1].string
);
508 strlcpy(name
, yystack
.l_mark
[0].string
, sizeof(name
));
509 free(yystack
.l_mark
[-1].string
);
510 free(yystack
.l_mark
[0].string
);
515 number
= yystack
.l_mark
[0].number
;
521 asprintf (&prefix
, "%s_", yystack
.l_mark
[0].string
);
524 free(yystack
.l_mark
[0].string
);
529 prefix
= realloc(prefix
, 1);
537 struct error_code
*ec
= malloc(sizeof(*ec
));
544 if(prefix
&& *prefix
!= '\0') {
545 asprintf (&ec
->name
, "%s%s", prefix
, yystack
.l_mark
[-2].string
);
546 if (ec
->name
== NULL
)
548 free(yystack
.l_mark
[-2].string
);
550 ec
->name
= yystack
.l_mark
[-2].string
;
551 ec
->string
= yystack
.l_mark
[0].string
;
562 yystack
.s_mark
-= yym
;
563 yystate
= *yystack
.s_mark
;
564 yystack
.l_mark
-= yym
;
566 if (yystate
== 0 && yym
== 0)
570 printf("%sdebug: after reduction, shifting from state 0 to\
571 state %d\n", YYPREFIX
, YYFINAL
);
574 *++yystack
.s_mark
= YYFINAL
;
575 *++yystack
.l_mark
= yyval
;
578 if ((yychar
= yylex()) < 0) yychar
= 0;
583 if (yychar
<= YYMAXTOKEN
) yys
= yyname
[yychar
];
584 if (!yys
) yys
= "illegal-symbol";
585 printf("%sdebug: state %d, reading %d (%s)\n",
586 YYPREFIX
, YYFINAL
, yychar
, yys
);
590 if (yychar
== 0) goto yyaccept
;
593 if ((yyn
= yygindex
[yym
]) && (yyn
+= yystate
) >= 0 &&
594 yyn
<= YYTABLESIZE
&& yycheck
[yyn
] == yystate
)
595 yystate
= yytable
[yyn
];
597 yystate
= yydgoto
[yym
];
600 printf("%sdebug: after reduction, shifting from state %d \
601 to state %d\n", YYPREFIX
, *yystack
.s_mark
, yystate
);
603 if (yystack
.s_mark
>= yystack
.s_last
&& yygrowstack(&yystack
))
607 *++yystack
.s_mark
= (short) yystate
;
608 *++yystack
.l_mark
= yyval
;
612 yyerror("yacc stack overflow");
615 yyfreestack(&yystack
);
619 yyfreestack(&yystack
);