2 static const char yysccsid
[] = "@(#)yaccpar 1.9 (Berkeley) 02/21/93";
8 #define YYPATCH 20101229
11 #define yyclearin (yychar = YYEMPTY)
12 #define yyerrok (yyerrflag = 0)
13 #define YYRECOVERING() (yyerrflag != 0)
20 * Copyright (c) 1998 - 2000 Kungliga Tekniska Högskolan
21 * (Royal Institute of Technology, Stockholm, Sweden).
22 * All rights reserved.
24 * Redistribution and use in source and binary forms, with or without
25 * modification, are permitted provided that the following conditions
28 * 1. Redistributions of source code must retain the above copyright
29 * notice, this list of conditions and the following disclaimer.
31 * 2. Redistributions in binary form must reproduce the above copyright
32 * notice, this list of conditions and the following disclaimer in the
33 * documentation and/or other materials provided with the distribution.
35 * 3. Neither the name of the Institute nor the names of its contributors
36 * may be used to endorse or promote products derived from this software
37 * without specific prior written permission.
39 * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
40 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
42 * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
43 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
44 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
45 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
46 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
47 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
48 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
52 #include "compile_et.h"
55 void yyerror (char *s
);
56 static long name2number(const char *str
);
60 /* This is for bison */
62 #if !defined(alloca) && !defined(HAVE_ALLOCA)
63 #define alloca(x) malloc(x)
66 #define YYMALLOC malloc
70 #undef YYSTYPE_IS_DECLARED
71 #define YYSTYPE_IS_DECLARED 1
73 #ifndef YYSTYPE_IS_DECLARED
74 #define YYSTYPE_IS_DECLARED 1
79 #endif /* !YYSTYPE_IS_DECLARED */
80 /* compatibility with bison */
82 /* compatibility with FreeBSD */
83 # ifdef YYPARSE_PARAM_TYPE
84 # define YYPARSE_DECL() yyparse(YYPARSE_PARAM_TYPE YYPARSE_PARAM)
86 # define YYPARSE_DECL() yyparse(void *YYPARSE_PARAM)
89 # define YYPARSE_DECL() yyparse(void)
92 /* Parameters sent to lex. */
94 # define YYLEX_DECL() yylex(void *YYLEX_PARAM)
95 # define YYLEX yylex(YYLEX_PARAM)
97 # define YYLEX_DECL() yylex(void)
98 # define YYLEX yylex()
101 /* Parameters sent to yyerror. */
102 #define YYERROR_DECL() yyerror(const char *s)
103 #define YYERROR_CALL(msg) yyerror(msg)
105 extern int YYPARSE_DECL();
115 #define YYERRCODE 256
116 static const short yylhs
[] = { -1,
117 0, 0, 1, 1, 3, 4, 4, 2, 2, 5,
120 static const short yylen
[] = { 2,
121 0, 2, 2, 1, 2, 2, 3, 1, 2, 2,
124 static const short yydefred
[] = { 0,
125 0, 0, 0, 0, 0, 4, 0, 5, 0, 0,
126 0, 14, 0, 8, 3, 7, 10, 11, 0, 9,
129 static const short yydgoto
[] = { 3,
132 static const short yysindex
[] = { -247,
133 -263, -258, 0, -256, -245, 0, -250, 0, -249, -246,
134 -244, 0, -256, 0, 0, 0, 0, 0, -28, 0,
137 static const short yyrindex
[] = { 18,
138 0, 0, 0, 0, 0, 0, -251, 0, 0, 1,
139 0, 0, 21, 0, 0, 0, 0, 0, 0, 0,
142 static const short yygindex
[] = { 0,
145 #define YYTABLESIZE 263
146 static const short yytable
[] = { 7,
147 12, 9, 10, 11, 8, 12, 6, 6, 6, 1,
148 6, 1, 16, 2, 17, 21, 18, 1, 19, 22,
149 2, 15, 20, 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, 0, 0,
154 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
155 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
156 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
157 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
158 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
159 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
160 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
161 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
162 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
163 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
164 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
165 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
166 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
167 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
168 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
169 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
170 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
171 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
172 0, 0, 0, 0, 0, 0, 0, 0, 12, 12,
175 static const short yycheck
[] = { 263,
176 0, 258, 259, 260, 263, 262, 258, 259, 260, 257,
177 262, 257, 263, 261, 264, 44, 263, 0, 263, 263,
178 0, 5, 13, -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, -1, -1,
183 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
184 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
185 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
186 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
187 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
188 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
189 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
190 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
191 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
192 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
193 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
194 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
195 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
196 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
197 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
198 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
199 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
200 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
201 -1, -1, -1, -1, -1, -1, -1, -1, 258, 259,
208 #define YYMAXTOKEN 264
210 static const char *yyname
[] = {
212 "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,
213 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,
214 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,
215 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,
216 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,
217 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,
218 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",
219 "ID","END","STRING","NUMBER",
221 static const char *yyrule
[] = {
224 "file : header statements",
229 "et : ET STRING STRING",
230 "statements : statement",
231 "statements : statements statement",
232 "statement : INDEX NUMBER",
233 "statement : PREFIX STRING",
234 "statement : PREFIX",
235 "statement : EC STRING ',' STRING",
240 /* define the initial stack-sizes */
243 #define YYMAXDEPTH YYSTACKSIZE
246 #define YYSTACKSIZE YYMAXDEPTH
248 #define YYSTACKSIZE 500
249 #define YYMAXDEPTH 500
253 #define YYINITSTACKSIZE 500
271 /* variables for the parser stack */
272 static YYSTACKDATA yystack
;
275 name2number(const char *str
)
279 const char *x
= "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
280 "abcdefghijklmnopqrstuvwxyz0123456789_";
281 if(strlen(str
) > 4) {
282 yyerror("table name too long");
285 for(p
= str
; *p
; p
++){
286 char *q
= strchr(x
, *p
);
288 yyerror("invalid character in table name");
291 num
= (num
<< 6) + (q
- x
) + 1;
295 num
= -(0xffffffff - num
+ 1);
302 _lex_error_message ("%s\n", s
);
306 #include <stdio.h> /* needed for printf */
309 #include <stdlib.h> /* needed for malloc, etc */
310 #include <string.h> /* needed for memset */
312 /* allocate initial stack or double stack size, up to YYMAXDEPTH */
313 static int yygrowstack(YYSTACKDATA
*data
)
320 if ((newsize
= data
->stacksize
) == 0)
321 newsize
= YYINITSTACKSIZE
;
322 else if (newsize
>= YYMAXDEPTH
)
324 else if ((newsize
*= 2) > YYMAXDEPTH
)
325 newsize
= YYMAXDEPTH
;
327 i
= data
->s_mark
- data
->s_base
;
328 newss
= (short *)realloc(data
->s_base
, newsize
* sizeof(*newss
));
332 data
->s_base
= newss
;
333 data
->s_mark
= newss
+ i
;
335 newvs
= (YYSTYPE
*)realloc(data
->l_base
, newsize
* sizeof(*newvs
));
339 data
->l_base
= newvs
;
340 data
->l_mark
= newvs
+ i
;
342 data
->stacksize
= newsize
;
343 data
->s_last
= data
->s_base
+ newsize
- 1;
347 #if YYPURE || defined(YY_NO_LEAKS)
348 static void yyfreestack(YYSTACKDATA
*data
)
352 memset(data
, 0, sizeof(*data
));
355 #define yyfreestack(data) /* nothing */
358 #define YYABORT goto yyabort
359 #define YYREJECT goto yyabort
360 #define YYACCEPT goto yyaccept
361 #define YYERROR goto yyerrlab
366 int yym
, yyn
, yystate
;
370 if ((yys
= getenv("YYDEBUG")) != 0)
373 if (yyn
>= '0' && yyn
<= '9')
384 memset(&yystack
, 0, sizeof(yystack
));
387 if (yystack
.s_base
== NULL
&& yygrowstack(&yystack
)) goto yyoverflow
;
388 yystack
.s_mark
= yystack
.s_base
;
389 yystack
.l_mark
= yystack
.l_base
;
394 if ((yyn
= yydefred
[yystate
]) != 0) goto yyreduce
;
397 if ((yychar
= YYLEX
) < 0) yychar
= 0;
402 if (yychar
<= YYMAXTOKEN
) yys
= yyname
[yychar
];
403 if (!yys
) yys
= "illegal-symbol";
404 printf("%sdebug: state %d, reading %d (%s)\n",
405 YYPREFIX
, yystate
, yychar
, yys
);
409 if ((yyn
= yysindex
[yystate
]) && (yyn
+= yychar
) >= 0 &&
410 yyn
<= YYTABLESIZE
&& yycheck
[yyn
] == yychar
)
414 printf("%sdebug: state %d, shifting to state %d\n",
415 YYPREFIX
, yystate
, yytable
[yyn
]);
417 if (yystack
.s_mark
>= yystack
.s_last
&& yygrowstack(&yystack
))
421 yystate
= yytable
[yyn
];
422 *++yystack
.s_mark
= yytable
[yyn
];
423 *++yystack
.l_mark
= yylval
;
425 if (yyerrflag
> 0) --yyerrflag
;
428 if ((yyn
= yyrindex
[yystate
]) && (yyn
+= yychar
) >= 0 &&
429 yyn
<= YYTABLESIZE
&& yycheck
[yyn
] == yychar
)
434 if (yyerrflag
) goto yyinrecovery
;
436 yyerror("syntax error");
449 if ((yyn
= yysindex
[*yystack
.s_mark
]) && (yyn
+= YYERRCODE
) >= 0 &&
450 yyn
<= YYTABLESIZE
&& yycheck
[yyn
] == YYERRCODE
)
454 printf("%sdebug: state %d, error recovery shifting\
455 to state %d\n", YYPREFIX
, *yystack
.s_mark
, yytable
[yyn
]);
457 if (yystack
.s_mark
>= yystack
.s_last
&& yygrowstack(&yystack
))
461 yystate
= yytable
[yyn
];
462 *++yystack
.s_mark
= yytable
[yyn
];
463 *++yystack
.l_mark
= yylval
;
470 printf("%sdebug: error recovery discarding state %d\n",
471 YYPREFIX
, *yystack
.s_mark
);
473 if (yystack
.s_mark
<= yystack
.s_base
) goto yyabort
;
481 if (yychar
== 0) goto yyabort
;
486 if (yychar
<= YYMAXTOKEN
) yys
= yyname
[yychar
];
487 if (!yys
) yys
= "illegal-symbol";
488 printf("%sdebug: state %d, error recovery discards token %d (%s)\n",
489 YYPREFIX
, yystate
, yychar
, yys
);
499 printf("%sdebug: state %d, reducing by rule %d (%s)\n",
500 YYPREFIX
, yystate
, yyn
, yyrule
[yyn
]);
504 yyval
= yystack
.l_mark
[1-yym
];
506 memset(&yyval
, 0, sizeof yyval
);
511 id_str
= yystack
.l_mark
[0].string
;
516 base_id
= name2number(yystack
.l_mark
[0].string
);
517 strlcpy(name
, yystack
.l_mark
[0].string
, sizeof(name
));
518 free(yystack
.l_mark
[0].string
);
523 base_id
= name2number(yystack
.l_mark
[-1].string
);
524 strlcpy(name
, yystack
.l_mark
[0].string
, sizeof(name
));
525 free(yystack
.l_mark
[-1].string
);
526 free(yystack
.l_mark
[0].string
);
531 number
= yystack
.l_mark
[0].number
;
537 asprintf (&prefix
, "%s_", yystack
.l_mark
[0].string
);
540 free(yystack
.l_mark
[0].string
);
545 prefix
= realloc(prefix
, 1);
553 struct error_code
*ec
= malloc(sizeof(*ec
));
560 if(prefix
&& *prefix
!= '\0') {
561 asprintf (&ec
->name
, "%s%s", prefix
, yystack
.l_mark
[-2].string
);
562 if (ec
->name
== NULL
)
564 free(yystack
.l_mark
[-2].string
);
566 ec
->name
= yystack
.l_mark
[-2].string
;
567 ec
->string
= yystack
.l_mark
[0].string
;
578 yystack
.s_mark
-= yym
;
579 yystate
= *yystack
.s_mark
;
580 yystack
.l_mark
-= yym
;
582 if (yystate
== 0 && yym
== 0)
586 printf("%sdebug: after reduction, shifting from state 0 to\
587 state %d\n", YYPREFIX
, YYFINAL
);
590 *++yystack
.s_mark
= YYFINAL
;
591 *++yystack
.l_mark
= yyval
;
594 if ((yychar
= YYLEX
) < 0) yychar
= 0;
599 if (yychar
<= YYMAXTOKEN
) yys
= yyname
[yychar
];
600 if (!yys
) yys
= "illegal-symbol";
601 printf("%sdebug: state %d, reading %d (%s)\n",
602 YYPREFIX
, YYFINAL
, yychar
, yys
);
606 if (yychar
== 0) goto yyaccept
;
609 if ((yyn
= yygindex
[yym
]) && (yyn
+= yystate
) >= 0 &&
610 yyn
<= YYTABLESIZE
&& yycheck
[yyn
] == yystate
)
611 yystate
= yytable
[yyn
];
613 yystate
= yydgoto
[yym
];
616 printf("%sdebug: after reduction, shifting from state %d \
617 to state %d\n", YYPREFIX
, *yystack
.s_mark
, yystate
);
619 if (yystack
.s_mark
>= yystack
.s_last
&& yygrowstack(&yystack
))
623 *++yystack
.s_mark
= (short) yystate
;
624 *++yystack
.l_mark
= yyval
;
628 yyerror("yacc stack overflow");
631 yyfreestack(&yystack
);
635 yyfreestack(&yystack
);