2 static const char yysccsid[] = "@(#)yaccpar 1.9 (Berkeley) 02/21/93";
11 #define YYPATCH 20070509
14 #define yyclearin (yychar = YYEMPTY)
15 #define yyerrok (yyerrflag = 0)
16 #define YYRECOVERING (yyerrflag != 0)
18 extern int yyparse(void);
20 static int yygrowstack(void);
24 * Copyright (c) 1998 - 2000 Kungliga Tekniska Högskolan
25 * (Royal Institute of Technology, Stockholm, Sweden).
26 * All rights reserved.
28 * Redistribution and use in source and binary forms, with or without
29 * modification, are permitted provided that the following conditions
32 * 1. Redistributions of source code must retain the above copyright
33 * notice, this list of conditions and the following disclaimer.
35 * 2. Redistributions in binary form must reproduce the above copyright
36 * notice, this list of conditions and the following disclaimer in the
37 * documentation and/or other materials provided with the distribution.
39 * 3. Neither the name of the Institute nor the names of its contributors
40 * may be used to endorse or promote products derived from this software
41 * without specific prior written permission.
43 * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
44 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
45 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
46 * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
47 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
48 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
49 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
50 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
51 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
52 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
56 #include "compile_et.h"
59 void yyerror (char *s);
60 static long name2number(const char *str);
64 /* This is for bison */
66 #if !defined(alloca) && !defined(HAVE_ALLOCA)
67 #define alloca(x) malloc(x)
86 0, 0, 1, 1, 3, 4, 4, 2, 2, 5,
90 0, 2, 2, 1, 2, 2, 3, 1, 2, 2,
93 short yydefred[] = { 0,
94 0, 0, 0, 0, 0, 4, 0, 5, 0, 0,
95 0, 14, 0, 8, 3, 7, 10, 11, 0, 9,
98 short yydgoto[] = { 3,
101 short yysindex[] = { -247,
102 -263, -258, 0, -256, -245, 0, -250, 0, -249, -246,
103 -244, 0, -256, 0, 0, 0, 0, 0, -28, 0,
106 short yyrindex[] = { 18,
107 0, 0, 0, 0, 0, 0, -251, 0, 0, 1,
108 0, 0, 21, 0, 0, 0, 0, 0, 0, 0,
111 short yygindex[] = { 0,
114 #define YYTABLESIZE 263
115 short yytable[] = { 7,
116 12, 9, 10, 11, 8, 12, 6, 6, 6, 1,
117 6, 1, 16, 2, 17, 21, 18, 1, 19, 22,
118 2, 15, 20, 0, 0, 0, 0, 0, 0, 0,
119 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
120 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
121 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
122 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
123 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
124 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
125 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
126 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
127 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
128 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
129 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
130 0, 0, 0, 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, 12, 12,
144 short yycheck[] = { 263,
145 0, 258, 259, 260, 263, 262, 258, 259, 260, 257,
146 262, 257, 263, 261, 264, 44, 263, 0, 263, 263,
147 0, 5, 13, -1, -1, -1, -1, -1, -1, -1,
148 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
149 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
150 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
151 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
152 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
153 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
154 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
155 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
156 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
157 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
158 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
159 -1, -1, -1, -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, 258, 259,
177 #define YYMAXTOKEN 264
180 "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,
181 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,
182 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,
183 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,
184 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,
185 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,
186 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",
187 "ID","END","STRING","NUMBER",
192 "file : header statements",
197 "et : ET STRING STRING",
198 "statements : statement",
199 "statements : statements statement",
200 "statement : INDEX NUMBER",
201 "statement : PREFIX STRING",
202 "statement : PREFIX",
203 "statement : EC STRING ',' STRING",
211 /* define the initial stack-sizes */
214 #define YYMAXDEPTH YYSTACKSIZE
217 #define YYSTACKSIZE YYMAXDEPTH
219 #define YYSTACKSIZE 500
220 #define YYMAXDEPTH 500
224 #define YYINITSTACKSIZE 500
235 /* variables for the parser stack */
237 static short *yysslim;
238 static YYSTYPE *yyvs;
239 static int yystacksize;
243 name2number(const char *str)
247 const char *x = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
248 "abcdefghijklmnopqrstuvwxyz0123456789_";
249 if(strlen(str) > 4) {
250 yyerror("table name too long");
253 for(p = str; *p; p++){
254 char *q = strchr(x, *p);
256 yyerror("invalid character in table name");
259 num = (num << 6) + (q - x) + 1;
263 num = -(0xffffffff - num + 1);
270 error_message ("%s\n", s);
273 /* allocate initial stack or double stack size, up to YYMAXDEPTH */
274 static int yygrowstack(void)
280 if ((newsize = yystacksize) == 0)
281 newsize = YYINITSTACKSIZE;
282 else if (newsize >= YYMAXDEPTH)
284 else if ((newsize *= 2) > YYMAXDEPTH)
285 newsize = YYMAXDEPTH;
289 ? (short *)realloc(yyss, newsize * sizeof(*newss))
290 : (short *)malloc(newsize * sizeof(*newss));
297 ? (YYSTYPE *)realloc(yyvs, newsize * sizeof(*newvs))
298 : (YYSTYPE *)malloc(newsize * sizeof(*newvs));
304 yystacksize = newsize;
305 yysslim = yyss + newsize - 1;
309 #define YYABORT goto yyabort
310 #define YYREJECT goto yyabort
311 #define YYACCEPT goto yyaccept
312 #define YYERROR goto yyerrlab
316 register int yym, yyn, yystate;
318 register const char *yys;
320 if ((yys = getenv("YYDEBUG")) != 0)
323 if (yyn >= '0' && yyn <= '9')
332 if (yyss == NULL && yygrowstack()) goto yyoverflow;
335 *yyssp = yystate = 0;
338 if ((yyn = yydefred[yystate]) != 0) goto yyreduce;
341 if ((yychar = yylex()) < 0) yychar = 0;
346 if (yychar <= YYMAXTOKEN) yys = yyname[yychar];
347 if (!yys) yys = "illegal-symbol";
348 printf("%sdebug: state %d, reading %d (%s)\n",
349 YYPREFIX, yystate, yychar, yys);
353 if ((yyn = yysindex[yystate]) && (yyn += yychar) >= 0 &&
354 yyn <= YYTABLESIZE && yycheck[yyn] == yychar)
358 printf("%sdebug: state %d, shifting to state %d\n",
359 YYPREFIX, yystate, yytable[yyn]);
361 if (yyssp >= yysslim && yygrowstack())
365 *++yyssp = yystate = yytable[yyn];
368 if (yyerrflag > 0) --yyerrflag;
371 if ((yyn = yyrindex[yystate]) && (yyn += yychar) >= 0 &&
372 yyn <= YYTABLESIZE && yycheck[yyn] == yychar)
377 if (yyerrflag) goto yyinrecovery;
379 yyerror("syntax error");
394 if ((yyn = yysindex[*yyssp]) && (yyn += YYERRCODE) >= 0 &&
395 yyn <= YYTABLESIZE && yycheck[yyn] == YYERRCODE)
399 printf("%sdebug: state %d, error recovery shifting\
400 to state %d\n", YYPREFIX, *yyssp, yytable[yyn]);
402 if (yyssp >= yysslim && yygrowstack())
406 *++yyssp = yystate = yytable[yyn];
414 printf("%sdebug: error recovery discarding state %d\n",
417 if (yyssp <= yyss) goto yyabort;
425 if (yychar == 0) goto yyabort;
430 if (yychar <= YYMAXTOKEN) yys = yyname[yychar];
431 if (!yys) yys = "illegal-symbol";
432 printf("%sdebug: state %d, error recovery discards token %d (%s)\n",
433 YYPREFIX, yystate, yychar, yys);
443 printf("%sdebug: state %d, reducing by rule %d (%s)\n",
444 YYPREFIX, yystate, yyn, yyrule[yyn]);
448 yyval = yyvsp[1-yym];
450 memset(&yyval, 0, sizeof yyval);
456 id_str = yyvsp[0].string;
462 base_id = name2number(yyvsp[0].string);
463 strlcpy(name, yyvsp[0].string, sizeof(name));
464 free(yyvsp[0].string);
470 base_id = name2number(yyvsp[-1].string);
471 strlcpy(name, yyvsp[0].string, sizeof(name));
472 free(yyvsp[-1].string);
473 free(yyvsp[0].string);
479 number = yyvsp[0].number;
486 asprintf (&prefix, "%s_", yyvsp[0].string);
489 free(yyvsp[0].string);
495 prefix = realloc(prefix, 1);
504 struct error_code *ec = malloc(sizeof(*ec));
511 if(prefix && *prefix != '\0') {
512 asprintf (&ec->name, "%s%s", prefix, yyvsp[-2].string);
513 if (ec->name == NULL)
515 free(yyvsp[-2].string);
517 ec->name = yyvsp[-2].string;
518 ec->string = yyvsp[0].string;
535 if (yystate == 0 && yym == 0)
539 printf("%sdebug: after reduction, shifting from state 0 to\
540 state %d\n", YYPREFIX, YYFINAL);
547 if ((yychar = yylex()) < 0) yychar = 0;
552 if (yychar <= YYMAXTOKEN) yys = yyname[yychar];
553 if (!yys) yys = "illegal-symbol";
554 printf("%sdebug: state %d, reading %d (%s)\n",
555 YYPREFIX, YYFINAL, yychar, yys);
559 if (yychar == 0) goto yyaccept;
562 if ((yyn = yygindex[yym]) && (yyn += yystate) >= 0 &&
563 yyn <= YYTABLESIZE && yycheck[yyn] == yystate)
564 yystate = yytable[yyn];
566 yystate = yydgoto[yym];
569 printf("%sdebug: after reduction, shifting from state %d \
570 to state %d\n", YYPREFIX, *yyssp, yystate);
572 if (yyssp >= yysslim && yygrowstack())
581 yyerror("yacc stack overflow");