diff options
author | David Walter Seikel | 2012-01-12 03:14:17 +1000 |
---|---|---|
committer | David Walter Seikel | 2012-01-12 03:14:17 +1000 |
commit | fc5d487de27aa7aa17502008c848d06758223888 (patch) | |
tree | 8f3007f53f49c146ae6c30a100decd3b3a0af1dd /LuaSL/src/btyacc-c.ske | |
parent | Leaf cloner. (diff) | |
download | SledjHamr-fc5d487de27aa7aa17502008c848d06758223888.zip SledjHamr-fc5d487de27aa7aa17502008c848d06758223888.tar.gz SledjHamr-fc5d487de27aa7aa17502008c848d06758223888.tar.bz2 SledjHamr-fc5d487de27aa7aa17502008c848d06758223888.tar.xz |
Switch to the lemon parser.
Diffstat (limited to 'LuaSL/src/btyacc-c.ske')
-rw-r--r-- | LuaSL/src/btyacc-c.ske | 939 |
1 files changed, 0 insertions, 939 deletions
diff --git a/LuaSL/src/btyacc-c.ske b/LuaSL/src/btyacc-c.ske deleted file mode 100644 index 399a25c..0000000 --- a/LuaSL/src/btyacc-c.ske +++ /dev/null | |||
@@ -1,939 +0,0 @@ | |||
1 | /* -*- C -*- | ||
2 | |||
3 | The banner used here should be replaced with an #ident directive if | ||
4 | the target C compiler supports #ident directives. | ||
5 | |||
6 | If the skeleton is changed, the banner should be changed so that | ||
7 | the altered version can easily be distinguished from the original. */ | ||
8 | |||
9 | %% banner | ||
10 | /* -*- C -*- | ||
11 | |||
12 | @(#)btyaccpar, based on byacc 1.8 (Berkeley), modified for rentrant flex. | ||
13 | |||
14 | */ | ||
15 | #define YYBTYACC 1 | ||
16 | |||
17 | #include <stdio.h> | ||
18 | #include <stdlib.h> | ||
19 | #include <string.h> | ||
20 | |||
21 | typedef int Yshort; | ||
22 | |||
23 | %% tables | ||
24 | |||
25 | #ifndef _YACC_EXTERN_ | ||
26 | # define _YACC_EXTERN_ "C" | ||
27 | #endif | ||
28 | |||
29 | extern _YACC_EXTERN_ Yshort yylhs[]; | ||
30 | extern _YACC_EXTERN_ Yshort yylen[]; | ||
31 | |||
32 | /* idx: current state; entry: non-zero if to reduce regardless of lookahead*/ | ||
33 | extern _YACC_EXTERN_ Yshort yydefred[]; | ||
34 | |||
35 | extern _YACC_EXTERN_ Yshort yydgoto[]; | ||
36 | |||
37 | /* idx: current state; entry: non-zero if shifting|reducing possible | ||
38 | in this state - in that case, yycheck[entry + lookahead] indicates | ||
39 | whether to perform the action for this lookahead. */ | ||
40 | extern _YACC_EXTERN_ Yshort yysindex[]; | ||
41 | extern _YACC_EXTERN_ Yshort yyrindex[]; | ||
42 | |||
43 | /* yycindex idx: current state; entry: non-zero if shift/reduce | ||
44 | conflicts for this state - in that case, yycheck[entry + lookahead] | ||
45 | indicates whether there's a conflict for this lookahead */ | ||
46 | extern _YACC_EXTERN_ Yshort yycindex[]; | ||
47 | extern _YACC_EXTERN_ Yshort yycheck[]; | ||
48 | |||
49 | extern _YACC_EXTERN_ Yshort yygindex[]; | ||
50 | extern _YACC_EXTERN_ Yshort yytable[]; | ||
51 | extern _YACC_EXTERN_ Yshort yyctable[]; | ||
52 | |||
53 | #if YYDEBUG | ||
54 | /* idx: token code; entry: spelling of token */ | ||
55 | extern _YACC_EXTERN_ char *yyname[]; | ||
56 | |||
57 | extern _YACC_EXTERN_ char *yyrule[]; | ||
58 | #endif | ||
59 | |||
60 | %% header | ||
61 | |||
62 | /* YYPOSN is user-defined text position type. */ | ||
63 | #ifndef YYPOSN | ||
64 | # define YYPOSN int | ||
65 | #endif | ||
66 | |||
67 | #ifdef YYREDUCEPOSNFUNC | ||
68 | # define YYCALLREDUCEPOSN(e) \ | ||
69 | if(reduce_posn) { \ | ||
70 | YYREDUCEPOSNFUNC(yyps->pos, &(yyps->psp)[1-yym], &(yyps->vsp)[1-yym],\ | ||
71 | yym, yyps->psp - yyps->ps, yychar, yyposn, e); \ | ||
72 | reduce_posn = 0; \ | ||
73 | } | ||
74 | |||
75 | # ifndef YYCALLREDUCEPOSNARG | ||
76 | # define YYCALLREDUCEPOSNARG (yyps->val) | ||
77 | # endif | ||
78 | |||
79 | |||
80 | # define YYPOSNARG(n) ((yyps->psp)[1-yym+(n)-1]) | ||
81 | # define YYPOSNOUT (yyps->pos) | ||
82 | #endif | ||
83 | |||
84 | /* If delete function is not defined by the user, do not delete. */ | ||
85 | #ifndef YYDELETEVAL | ||
86 | # define YYDELETEVAL(v, t) | ||
87 | #endif | ||
88 | |||
89 | /* If delete function is not defined by the user, do not delete. */ | ||
90 | #ifndef YYDELETEPOSN | ||
91 | # define YYDELETEPOSN(v, t) | ||
92 | #endif | ||
93 | |||
94 | #define YYEMPTY (-1) | ||
95 | #define yyclearin (yychar=YYEMPTY) | ||
96 | |||
97 | #define yyerrok (yyps->errflag=0) | ||
98 | |||
99 | #ifndef YYSTACKGROWTH | ||
100 | # define YYSTACKGROWTH 32 | ||
101 | #endif | ||
102 | |||
103 | #ifndef YYDEFSTACKSIZE | ||
104 | # define YYDEFSTACKSIZE 12 | ||
105 | #endif | ||
106 | |||
107 | #ifdef YYDEBUG | ||
108 | int yydebug = 0; | ||
109 | #endif | ||
110 | |||
111 | int yynerrs; | ||
112 | |||
113 | /* These value/posn are taken from the lexer */ | ||
114 | YYSTYPE yylval; | ||
115 | YYPOSN yyposn; | ||
116 | |||
117 | /* These value/posn of the root non-terminal are returned to the caller */ | ||
118 | YYSTYPE yyretlval; | ||
119 | YYPOSN yyretposn; | ||
120 | |||
121 | #define YYABORT goto yyabort | ||
122 | #define YYACCEPT goto yyaccept | ||
123 | #define YYERROR goto yyerrlab | ||
124 | #define YYVALID do { if (yyps->save) goto yyvalid; } while(0) | ||
125 | #define YYVALID_NESTED do { if (yyps->save && \ | ||
126 | yyps->save->save==0) goto yyvalid; } while(0) | ||
127 | |||
128 | struct YYParseState_s { | ||
129 | struct YYParseState_s *save; /* Previously saved parser state */ | ||
130 | int state; | ||
131 | int errflag; | ||
132 | Yshort *ssp; /* state stack pointer */ | ||
133 | YYSTYPE *vsp; /* value stack pointer */ | ||
134 | YYPOSN *psp; /* position stack pointer */ | ||
135 | YYSTYPE val; /* value as returned by actions */ | ||
136 | YYPOSN pos; /* position as returned by universal action */ | ||
137 | Yshort *ss; /* state stack base */ | ||
138 | YYSTYPE *vs; /* values stack base */ | ||
139 | YYPOSN *ps; /* position stack base */ | ||
140 | int lexeme; /* index of conflict lexeme in lexical queue */ | ||
141 | unsigned int stacksize; /* current maximum stack size */ | ||
142 | Yshort ctry; /* index in yyctable[] for this conflict */ | ||
143 | }; | ||
144 | typedef struct YYParseState_s YYParseState; | ||
145 | |||
146 | /* Current parser state */ | ||
147 | static YYParseState *yyps = 0; | ||
148 | |||
149 | /* yypath!=NULL: do the full parse, starting at *yypath parser state. */ | ||
150 | static YYParseState *yypath = 0; | ||
151 | |||
152 | /* Base of the lexical value queue */ | ||
153 | static YYSTYPE *yylvals = 0; | ||
154 | |||
155 | /* Current position at lexical value queue */ | ||
156 | static YYSTYPE *yylvp = 0; | ||
157 | |||
158 | /* End position of lexical value queue */ | ||
159 | static YYSTYPE *yylve = 0; | ||
160 | |||
161 | /* The last allocated position at the lexical value queue */ | ||
162 | static YYSTYPE *yylvlim = 0; | ||
163 | |||
164 | /* Base of the lexical position queue */ | ||
165 | static YYPOSN *yylpsns = 0; | ||
166 | |||
167 | /* Current position at lexical position queue */ | ||
168 | static YYPOSN *yylpp = 0; | ||
169 | |||
170 | /* End position of lexical position queue */ | ||
171 | static YYPOSN *yylpe = 0; | ||
172 | |||
173 | /* The last allocated position at the lexical position queue */ | ||
174 | static YYPOSN *yylplim = 0; | ||
175 | |||
176 | /* Current position at lexical token queue */ | ||
177 | static Yshort *yylexp = 0; | ||
178 | |||
179 | static Yshort *yylexemes = 0; | ||
180 | |||
181 | /* For use in generated program */ | ||
182 | #define yytrial (yyps->save) | ||
183 | #define yyvsp (yyps->vsp) | ||
184 | #define yyval (yyps->val) | ||
185 | #define yydepth (yyps->ssp - yyps->ss) | ||
186 | |||
187 | |||
188 | /* Local prototypes. */ | ||
189 | int yyparse(void *YYPARSE_PARAM); | ||
190 | |||
191 | static int yyLex1(YYSTYPE *yylval, yyscan_t scanner); | ||
192 | static int yyExpand(); | ||
193 | static void yySCopy(YYSTYPE *to, YYSTYPE *from, int size); | ||
194 | static void yyPCopy(YYPOSN *to, YYPOSN *from, int size); | ||
195 | static void yyMoreStack(YYParseState *yyps); | ||
196 | static YYParseState *yyNewState(int size); | ||
197 | static void yyFreeState(YYParseState *p); | ||
198 | |||
199 | |||
200 | %% body | ||
201 | |||
202 | |||
203 | /* Parser function. Roughly looks like this: | ||
204 | int yyparse(void *YYPARSE_PARAM) { | ||
205 | yyloop: | ||
206 | if (reduce_possible) goto yyreduce; | ||
207 | read_token; | ||
208 | if (conflict) { | ||
209 | handle_conflict; | ||
210 | goto yyshift; or goto yyreduce; | ||
211 | } | ||
212 | if (shift_possible) { | ||
213 | yyshift: | ||
214 | do_shift; | ||
215 | goto yyloop; | ||
216 | } | ||
217 | if (reduce_possible) goto yyreduce; | ||
218 | |||
219 | (error handling); | ||
220 | goto yyloop; | ||
221 | |||
222 | yyreduce: | ||
223 | BIG_CHUNK_OF_RULE_ACTIONS; | ||
224 | goto yyloop; | ||
225 | |||
226 | (more error handling); | ||
227 | }*/ | ||
228 | int yyparse(void *YYPARSE_PARAM) { | ||
229 | int yym, yyn, yystate, yychar, yynewerrflag; | ||
230 | YYParseState *yyerrctx = 0; | ||
231 | int reduce_posn; | ||
232 | |||
233 | # if YYDEBUG | ||
234 | char *yys; | ||
235 | |||
236 | if ((yys = getenv("YYDEBUG"))) { | ||
237 | yyn = *yys; | ||
238 | if (yyn >= '0' && yyn <= '9') | ||
239 | yydebug = yyn - '0'; | ||
240 | } | ||
241 | if (yydebug) { | ||
242 | fputs("btyacc[<current state>,<nr of symbols on state stack>]\n", | ||
243 | stderr); | ||
244 | } | ||
245 | # endif | ||
246 | |||
247 | yyps = yyNewState(YYDEFSTACKSIZE); | ||
248 | yyps->save = 0; | ||
249 | yynerrs = 0; | ||
250 | yyps->errflag = 0; | ||
251 | yychar = (YYEMPTY); | ||
252 | |||
253 | yyps->ssp = yyps->ss; | ||
254 | yyps->vsp = yyps->vs; | ||
255 | yyps->psp = yyps->ps; | ||
256 | *(yyps->ssp) = yystate = 0; | ||
257 | |||
258 | |||
259 | /* Main parsing loop */ | ||
260 | yyloop: | ||
261 | if ((yyn = yydefred[yystate])) { | ||
262 | goto yyreduce; | ||
263 | } | ||
264 | |||
265 | /* Read one token */ | ||
266 | if (yychar < 0) { | ||
267 | yychar = yyLex1(&yylval, YYLEX_PARAM); | ||
268 | if (yychar < 0) yychar = 0; | ||
269 | # if YYDEBUG | ||
270 | if (yydebug) { | ||
271 | yys = 0; | ||
272 | if (yychar <= YYMAXTOKEN) yys = yyname[yychar]; | ||
273 | if (!yys) yys = "illegal-symbol"; | ||
274 | fprintf(stderr, "btyacc[%3d,%2d%s]: read token %d (%s)", | ||
275 | yystate, (int) yydepth, (yytrial ? ",trial" : ""), yychar, yys); | ||
276 | # ifdef YYDBPR | ||
277 | fputc('<', stderr); | ||
278 | YYDBPR(yylval); | ||
279 | fputc('>', stderr); | ||
280 | # endif | ||
281 | fputc('\n', stderr); | ||
282 | } | ||
283 | # endif | ||
284 | } | ||
285 | |||
286 | /* Do we have a conflict? */ | ||
287 | yyn = yycindex[yystate]; | ||
288 | if (yyn != 0 && (yyn += yychar) >= 0 | ||
289 | && yyn <= YYTABLESIZE && yycheck[yyn] == yychar) { | ||
290 | int ctry; | ||
291 | |||
292 | if (yypath) { | ||
293 | YYParseState *save; | ||
294 | # if YYDEBUG | ||
295 | if (yydebug) { | ||
296 | fprintf(stderr, "btyacc[%3d,%2d%s]: CONFLICT: following successful " | ||
297 | "trial parse\n", yystate, (int) yydepth, (yytrial ? ",trial" :"")); | ||
298 | } | ||
299 | # endif | ||
300 | /* Switch to the next conflict context */ | ||
301 | save = yypath; | ||
302 | yypath = save->save; | ||
303 | ctry = save->ctry; | ||
304 | if (save->state != yystate) | ||
305 | goto yyabort; | ||
306 | yyFreeState(save); | ||
307 | |||
308 | } else { | ||
309 | |||
310 | /* Unresolved conflict - start/continue trial parse */ | ||
311 | YYParseState *save; | ||
312 | # if YYDEBUG | ||
313 | if (yydebug) { | ||
314 | fprintf(stderr, "btyacc[%3d,%2d%s]: CONFLICT. ", | ||
315 | yystate, (int) yydepth, (yytrial ? ",trial" : "")); | ||
316 | if(yyps->save) | ||
317 | fputs("ALREADY in conflict, continuing trial parse.\n", stderr); | ||
318 | else | ||
319 | fputs("starting trial parse.\n", stderr); | ||
320 | } | ||
321 | # endif | ||
322 | save = yyNewState(yyps->ssp - yyps->ss); | ||
323 | save->save = yyps->save; | ||
324 | save->state = yystate; | ||
325 | save->errflag = yyps->errflag; | ||
326 | save->ssp = save->ss + (yyps->ssp - yyps->ss); | ||
327 | save->vsp = save->vs + (yyps->vsp - yyps->vs); | ||
328 | save->psp = save->ps + (yyps->psp - yyps->ps); | ||
329 | memcpy(save->ss, yyps->ss, (yyps->ssp - yyps->ss + 1)*sizeof(Yshort)); | ||
330 | yySCopy(save->vs, yyps->vs, (yyps->ssp - yyps->ss + 1)); | ||
331 | yyPCopy(save->ps, yyps->ps, (yyps->ssp - yyps->ss + 1)); | ||
332 | ctry = yytable[yyn]; | ||
333 | if (yyctable[ctry] == -1) { | ||
334 | # if YYDEBUG | ||
335 | if (yydebug && yychar >= 0) | ||
336 | fputs("btyacc[trial]: backtracking 1 token\n", stderr); | ||
337 | # endif | ||
338 | ctry++; | ||
339 | } | ||
340 | save->ctry = ctry; | ||
341 | if (yyps->save == 0) { | ||
342 | /* If this is a first conflict in the stack, start saving lexemes */ | ||
343 | if (!yylexemes) { | ||
344 | # ifdef __cplusplus | ||
345 | yylexemes = new Yshort[YYSTACKGROWTH]; | ||
346 | yylvals = new YYSTYPE[YYSTACKGROWTH]; | ||
347 | yylvlim = yylvals + YYSTACKGROWTH; | ||
348 | yylpsns = new YYPOSN[YYSTACKGROWTH]; | ||
349 | yylplim = yylpsns + YYSTACKGROWTH; | ||
350 | # else | ||
351 | yylexemes = (Yshort*)malloc((YYSTACKGROWTH) * sizeof(Yshort)); | ||
352 | yylvals = (YYSTYPE*)malloc((YYSTACKGROWTH) * sizeof(YYSTYPE)); | ||
353 | yylvlim = yylvals + YYSTACKGROWTH; | ||
354 | yylpsns = (YYPOSN*)malloc((YYSTACKGROWTH) * sizeof(YYPOSN)); | ||
355 | yylplim = yylpsns + YYSTACKGROWTH; | ||
356 | # endif | ||
357 | } | ||
358 | if (yylvp == yylve) { | ||
359 | yylvp = yylve = yylvals; | ||
360 | yylpp = yylpe = yylpsns; | ||
361 | yylexp = yylexemes; | ||
362 | if (yychar >= 0) { | ||
363 | *yylve++ = yylval; | ||
364 | *yylpe++ = yyposn; | ||
365 | *yylexp = yychar; | ||
366 | yychar = YYEMPTY; | ||
367 | } | ||
368 | } | ||
369 | } | ||
370 | if (yychar >= 0) { | ||
371 | yylvp--, yylpp--, yylexp--; | ||
372 | yychar = YYEMPTY; | ||
373 | } | ||
374 | save->lexeme = yylvp - yylvals; | ||
375 | yyps->save = save; | ||
376 | } | ||
377 | |||
378 | if (yytable[yyn] == ctry) { | ||
379 | # if YYDEBUG | ||
380 | if (yydebug) | ||
381 | fprintf(stderr, "btyacc[%3d,%2d%s]: shifting to state %d\n", | ||
382 | yystate, (int) yydepth, (yytrial ? ",trial" : ""), yyctable[ctry]); | ||
383 | # endif | ||
384 | if (yychar < 0) { | ||
385 | yylvp++; yylpp++; yylexp++; | ||
386 | } | ||
387 | yychar = YYEMPTY; | ||
388 | if (yyps->errflag > 0) --yyps->errflag; | ||
389 | yystate = yyctable[ctry]; | ||
390 | goto yyshift; | ||
391 | } else { | ||
392 | yyn = yyctable[ctry]; | ||
393 | goto yyreduce; | ||
394 | } | ||
395 | } /* End of code dealing with conflicts */ | ||
396 | |||
397 | |||
398 | /* Is action a shift? */ | ||
399 | yyn = yysindex[yystate]; | ||
400 | if (yyn != 0 && (yyn += yychar) >= 0 | ||
401 | && yyn <= YYTABLESIZE && yycheck[yyn] == yychar) { | ||
402 | # if YYDEBUG | ||
403 | if (yydebug) | ||
404 | fprintf(stderr, "btyacc[%3d,%2d%s]: shifting to state %d\n", | ||
405 | yystate, (int) yydepth, (yytrial ? ",trial" : ""), yytable[yyn]); | ||
406 | # endif | ||
407 | yychar = YYEMPTY; | ||
408 | if (yyps->errflag > 0) --yyps->errflag; | ||
409 | yystate = yytable[yyn]; | ||
410 | |||
411 | yyshift: | ||
412 | if (yyps->ssp >= yyps->ss + yyps->stacksize - 1) { | ||
413 | yyMoreStack(yyps); | ||
414 | } | ||
415 | *++(yyps->ssp) = yystate; | ||
416 | *++(yyps->vsp) = yylval; | ||
417 | *++(yyps->psp) = yyposn; | ||
418 | goto yyloop; | ||
419 | } | ||
420 | if ((yyn = yyrindex[yystate]) && | ||
421 | (yyn += yychar) >= 0 && | ||
422 | yyn <= YYTABLESIZE && | ||
423 | yycheck[yyn] == yychar) { | ||
424 | yyn = yytable[yyn]; | ||
425 | goto yyreduce; | ||
426 | } | ||
427 | |||
428 | /* According to the tables, neither shift nor reduce is OK here - error! */ | ||
429 | if (yyps->errflag) goto yyinrecovery; | ||
430 | yynewerrflag = 1; | ||
431 | goto yyerrhandler; | ||
432 | yyerrlab: | ||
433 | yynewerrflag = 0; | ||
434 | yyerrhandler: | ||
435 | while (yyps->save) { | ||
436 | int ctry; | ||
437 | YYParseState *save = yyps->save; | ||
438 | # if YYDEBUG | ||
439 | if (yydebug) | ||
440 | fprintf(stderr, "btyacc[%3d,%2d%s]: ERROR, " | ||
441 | "CONFLICT BACKTRACKING to state %d, %d tokens\n", | ||
442 | yystate, (int) yydepth, (yytrial ? ",trial" : ""), | ||
443 | yyps->save->state, (int) (yylvp - yylvals - yyps->save->lexeme)); | ||
444 | # endif | ||
445 | /* Memorize most forward-looking error state in case | ||
446 | it's really an error. */ | ||
447 | if(yyerrctx==0 || yyerrctx->lexeme<yylvp-yylvals) { | ||
448 | /* Free old saved error context state */ | ||
449 | if(yyerrctx) yyFreeState(yyerrctx); | ||
450 | /* Create and fill out new saved error context state */ | ||
451 | yyerrctx = yyNewState(yyps->ssp - yyps->ss); | ||
452 | yyerrctx->save = yyps->save; | ||
453 | yyerrctx->state = yystate; | ||
454 | yyerrctx->errflag = yyps->errflag; | ||
455 | yyerrctx->ssp = yyerrctx->ss + (yyps->ssp - yyps->ss); | ||
456 | yyerrctx->vsp = yyerrctx->vs + (yyps->vsp - yyps->vs); | ||
457 | yyerrctx->psp = yyerrctx->ps + (yyps->psp - yyps->ps); | ||
458 | memcpy (yyerrctx->ss, yyps->ss, | ||
459 | (yyps->ssp - yyps->ss + 1) * sizeof(Yshort)); | ||
460 | yySCopy(yyerrctx->vs, yyps->vs, (yyps->ssp - yyps->ss + 1)); | ||
461 | yyPCopy(yyerrctx->ps, yyps->ps, (yyps->ssp - yyps->ss + 1)); | ||
462 | yyerrctx->lexeme = yylvp - yylvals; | ||
463 | } | ||
464 | yylvp = yylvals + save->lexeme; | ||
465 | yylpp = yylpsns + save->lexeme; | ||
466 | yylexp = yylexemes + save->lexeme; | ||
467 | yychar = YYEMPTY; | ||
468 | yyps->ssp = yyps->ss + (save->ssp - save->ss); | ||
469 | yyps->vsp = yyps->vs + (save->vsp - save->vs); | ||
470 | yyps->psp = yyps->ps + (save->psp - save->ps); | ||
471 | memcpy (yyps->ss, save->ss, (yyps->ssp - yyps->ss + 1) * sizeof(Yshort)); | ||
472 | yySCopy(yyps->vs, save->vs, yyps->vsp - yyps->vs + 1); | ||
473 | yyPCopy(yyps->ps, save->ps, yyps->psp - yyps->ps + 1); | ||
474 | ctry = ++save->ctry; | ||
475 | yystate = save->state; | ||
476 | /* We tried shift, try reduce now */ | ||
477 | if ((yyn = yyctable[ctry]) >= 0) { | ||
478 | goto yyreduce; | ||
479 | } | ||
480 | yyps->save = save->save; | ||
481 | yyFreeState(save); | ||
482 | |||
483 | /* Nothing left on the stack -- error */ | ||
484 | if (!yyps->save) { | ||
485 | # if YYDEBUG | ||
486 | if (yydebug) { | ||
487 | fputs("btyacc[trial]: trial parse FAILED, entering ERROR mode\n", | ||
488 | stderr); | ||
489 | } | ||
490 | # endif | ||
491 | /* Restore state as it was in the most forward-advanced error */ | ||
492 | yylvp = yylvals + yyerrctx->lexeme; | ||
493 | yylpp = yylpsns + yyerrctx->lexeme; | ||
494 | yylexp = yylexemes + yyerrctx->lexeme; | ||
495 | yychar = yylexp[-1]; | ||
496 | yylval = yylvp[-1]; | ||
497 | yyposn = yylpp[-1]; | ||
498 | yyps->ssp = yyps->ss + (yyerrctx->ssp - yyerrctx->ss); | ||
499 | yyps->vsp = yyps->vs + (yyerrctx->vsp - yyerrctx->vs); | ||
500 | yyps->psp = yyps->ps + (yyerrctx->psp - yyerrctx->ps); | ||
501 | memcpy (yyps->ss, yyerrctx->ss, | ||
502 | (yyps->ssp - yyps->ss + 1) * sizeof(Yshort)); | ||
503 | yySCopy(yyps->vs, yyerrctx->vs, yyps->vsp - yyps->vs + 1); | ||
504 | yyPCopy(yyps->ps, yyerrctx->ps, yyps->psp - yyps->ps + 1); | ||
505 | yystate = yyerrctx->state; | ||
506 | yyFreeState(yyerrctx); | ||
507 | yyerrctx = 0; | ||
508 | } | ||
509 | yynewerrflag = 1; | ||
510 | } | ||
511 | if (yynewerrflag) { | ||
512 | # ifdef YYERROR_DETAILED | ||
513 | yyerror_detailed("parse error", yychar, yylval, yyposn); | ||
514 | # else | ||
515 | yyerror("parse error"); | ||
516 | # endif | ||
517 | } | ||
518 | ++yynerrs; | ||
519 | yyinrecovery: | ||
520 | if (yyps->errflag < 3) { | ||
521 | yyps->errflag = 3; | ||
522 | for (;;) { | ||
523 | if ((yyn = yysindex[*(yyps->ssp)]) | ||
524 | && (yyn += YYERRCODE) >= 0 | ||
525 | && yyn <= YYTABLESIZE | ||
526 | && yycheck[yyn] == YYERRCODE) { | ||
527 | # if YYDEBUG | ||
528 | if (yydebug) | ||
529 | fprintf(stderr, "btyacc[%3d,%2d%s]: ERROR recovery shifts to " | ||
530 | "state %d\n", | ||
531 | *(yyps->ssp), (int) yydepth, (yytrial ? ",trial" : ""), | ||
532 | yytable[yyn]); | ||
533 | # endif | ||
534 | /* Use label yyerrlab, so that compiler does not warn */ | ||
535 | if(yyps->errflag != yyps->errflag) goto yyerrlab; | ||
536 | yystate = yytable[yyn]; | ||
537 | goto yyshift; | ||
538 | } else { | ||
539 | # if YYDEBUG | ||
540 | if (yydebug) | ||
541 | fprintf(stderr, | ||
542 | "btyacc[%3d,%2d%s]: ERROR recovery discards this state\n", | ||
543 | *(yyps->ssp), (int) yydepth, (yytrial ? ",trial" : "")); | ||
544 | # endif | ||
545 | if (yyps->ssp <= yyps->ss) { | ||
546 | goto yyabort; | ||
547 | } | ||
548 | if(!yytrial) { | ||
549 | YYDELETEVAL(yyps->vsp[0],1); | ||
550 | YYDELETEPOSN(yyps->psp[0],1); | ||
551 | } | ||
552 | --(yyps->ssp); | ||
553 | --(yyps->vsp); | ||
554 | --(yyps->psp); | ||
555 | } | ||
556 | } | ||
557 | } else { | ||
558 | if (yychar == 0) goto yyabort; | ||
559 | # if YYDEBUG | ||
560 | if (yydebug) { | ||
561 | yys = 0; | ||
562 | if (yychar <= YYMAXTOKEN) yys = yyname[yychar]; | ||
563 | if (!yys) yys = "illegal-symbol"; | ||
564 | fprintf(stderr, "btyacc[%3d,%2d%s]: ERROR recovery discards token " | ||
565 | "%d (%s)\n", | ||
566 | yystate, (int) yydepth, (yytrial ? ",trial" : ""), yychar, yys); | ||
567 | } | ||
568 | # endif | ||
569 | if(!yytrial) { | ||
570 | YYDELETEVAL(yylval,0); | ||
571 | YYDELETEPOSN(yyposn,0); | ||
572 | } | ||
573 | yychar = (YYEMPTY); | ||
574 | goto yyloop; | ||
575 | } | ||
576 | |||
577 | /* Reduce the rule */ | ||
578 | yyreduce: | ||
579 | yym = yylen[yyn]; | ||
580 | # if YYDEBUG | ||
581 | if (yydebug) { | ||
582 | fprintf(stderr, "btyacc[%3d,%2d%s]: reducing by rule %d (%s)", | ||
583 | yystate, (int) yydepth, (yytrial ? ",trial" : ""), yyn, yyrule[yyn]); | ||
584 | # ifdef YYDBPR | ||
585 | if (yym) { | ||
586 | int i; | ||
587 | fputc('<', stderr); | ||
588 | for (i=yym; i>0; i--) { | ||
589 | if (i!=yym) printf(", "); | ||
590 | YYDBPR((yyps->vsp)[1-i]); | ||
591 | } | ||
592 | fputc('>', stderr); | ||
593 | } | ||
594 | # endif | ||
595 | fputc('\n', stderr); | ||
596 | } | ||
597 | # endif | ||
598 | if (yyps->ssp + 1 - yym >= yyps->ss + yyps->stacksize) { | ||
599 | yyMoreStack(yyps); | ||
600 | } | ||
601 | |||
602 | # ifdef _YACC_DEFAULT_ACTION_ | ||
603 | /* "$$ = NULL" default action */ | ||
604 | memset(&yyps->val, 0, sizeof(yyps->val)); | ||
605 | # else | ||
606 | /* RA: bison compatibility: default action is '$$ = $1;' */ | ||
607 | if (yym > 0) yyps->val = (yyps->vsp)[1 - yym]; | ||
608 | # endif | ||
609 | |||
610 | /* Default reduced position is NULL -- no position at all. No | ||
611 | position will be assigned at trial time and if no position | ||
612 | handling is present */ | ||
613 | memset(&yyps->pos, 0, sizeof(yyps->pos)); | ||
614 | |||
615 | reduce_posn = 1; | ||
616 | |||
617 | switch (yyn) { | ||
618 | |||
619 | %% trailer | ||
620 | |||
621 | default: | ||
622 | break; | ||
623 | } | ||
624 | |||
625 | # if YYDEBUG && defined(YYDBPR) | ||
626 | if (yydebug) { | ||
627 | fputs("btyacc[trial]: reduced, result is ", stderr); | ||
628 | YYDBPR(yyps->val); | ||
629 | fputc('\n', stderr); | ||
630 | } | ||
631 | # endif | ||
632 | |||
633 | /* Perform user-defined position reduction */ | ||
634 | # ifdef YYREDUCEPOSNFUNC | ||
635 | if(!yytrial) { | ||
636 | YYCALLREDUCEPOSN(YYREDUCEPOSNFUNCARG); | ||
637 | } | ||
638 | # endif | ||
639 | |||
640 | yyps->ssp -= yym; | ||
641 | yystate = *(yyps->ssp); | ||
642 | yyps->vsp -= yym; | ||
643 | yyps->psp -= yym; | ||
644 | |||
645 | yym = yylhs[yyn]; | ||
646 | if (yystate == 0 && yym == 0) { | ||
647 | # if YYDEBUG | ||
648 | if (yydebug) { | ||
649 | fprintf(stderr, | ||
650 | "btyacc[ 0,%2d%s]: reduced, shifting to final state %d\n", | ||
651 | (int) yydepth, (yytrial ? ",trial" : ""), YYFINAL); | ||
652 | } | ||
653 | # endif | ||
654 | yystate = YYFINAL; | ||
655 | *++(yyps->ssp) = YYFINAL; | ||
656 | *++(yyps->vsp) = yyps->val; | ||
657 | yyretlval = yyps->val; /* return value of root non-terminal to yylval */ | ||
658 | *++(yyps->psp) = yyps->pos; | ||
659 | yyretposn = yyps->pos; /* return value of root position to yyposn */ | ||
660 | if (yychar < 0) { | ||
661 | if ((yychar = yyLex1(&yylval, YYLEX_PARAM)) < 0) { | ||
662 | yychar = 0; | ||
663 | } | ||
664 | # if YYDEBUG | ||
665 | if (yydebug) { | ||
666 | yys = 0; | ||
667 | if (yychar <= YYMAXTOKEN) yys = yyname[yychar]; | ||
668 | if (!yys) yys = "illegal-symbol"; | ||
669 | fprintf(stderr, "btyacc[%3d,%2d%s]: read %d (%s)\n", | ||
670 | YYFINAL, (int) yydepth, (yytrial ? ",trial" : ""), yychar, yys); | ||
671 | } | ||
672 | # endif | ||
673 | } | ||
674 | if (yychar == 0) goto yyaccept; | ||
675 | goto yyloop; | ||
676 | } | ||
677 | |||
678 | if ((yyn = yygindex[yym]) && (yyn += yystate) >= 0 && | ||
679 | yyn <= YYTABLESIZE && yycheck[yyn] == yystate) { | ||
680 | yystate = yytable[yyn]; | ||
681 | } else { | ||
682 | yystate = yydgoto[yym]; | ||
683 | } | ||
684 | # if YYDEBUG | ||
685 | if (yydebug) | ||
686 | fprintf(stderr, "btyacc[%3d,%2d%s]: reduced, shifting to state %d\n", | ||
687 | *(yyps->ssp), (int) yydepth, (yytrial ? ",trial" : ""), yystate); | ||
688 | # endif | ||
689 | if (yyps->ssp >= yyps->ss + yyps->stacksize - 1) { | ||
690 | yyMoreStack(yyps); | ||
691 | } | ||
692 | *++(yyps->ssp) = yystate; | ||
693 | *++(yyps->vsp) = yyps->val; | ||
694 | *++(yyps->psp) = yyps->pos; | ||
695 | goto yyloop; | ||
696 | |||
697 | |||
698 | /* Reduction declares that this path is valid. | ||
699 | Set yypath and do a full parse */ | ||
700 | yyvalid: | ||
701 | if (yypath) { | ||
702 | goto yyabort; | ||
703 | } | ||
704 | while (yyps->save) { | ||
705 | YYParseState *save = yyps->save; | ||
706 | yyps->save = save->save; | ||
707 | save->save = yypath; | ||
708 | yypath = save; | ||
709 | } | ||
710 | # if YYDEBUG | ||
711 | if (yydebug) | ||
712 | fprintf(stderr, "btyacc[%3d,%2d%s]: CONFLICT trial successful, " | ||
713 | "backtracking to state %d, %d tokens\n", | ||
714 | yystate, (int) yydepth, (yytrial ? ",trial" : ""), | ||
715 | yypath->state, (int) (yylvp - yylvals - yypath->lexeme)); | ||
716 | # endif | ||
717 | if(yyerrctx) { | ||
718 | yyFreeState(yyerrctx); yyerrctx = 0; | ||
719 | } | ||
720 | yychar = YYEMPTY; | ||
721 | yyps->ssp = yyps->ss + (yypath->ssp - yypath->ss); | ||
722 | yyps->vsp = yyps->vs + (yypath->vsp - yypath->vs); | ||
723 | yyps->psp = yyps->ps + (yypath->psp - yypath->ps); | ||
724 | memcpy (yyps->ss, yypath->ss, (yyps->ssp - yyps->ss + 1) * sizeof(Yshort)); | ||
725 | yySCopy(yyps->vs, yypath->vs, yyps->vsp - yyps->vs + 1); | ||
726 | yyPCopy(yyps->ps, yypath->ps, yyps->psp - yyps->ps + 1); | ||
727 | yylvp = yylvals + yypath->lexeme; | ||
728 | yylpp = yylpsns + yypath->lexeme; | ||
729 | yylexp = yylexemes + yypath->lexeme; | ||
730 | yystate = yypath->state; | ||
731 | goto yyloop; | ||
732 | |||
733 | |||
734 | yyabort: | ||
735 | { | ||
736 | YYSTYPE *pv; | ||
737 | YYPOSN *pp; | ||
738 | |||
739 | if(yyerrctx) { | ||
740 | yyFreeState(yyerrctx); yyerrctx = 0; | ||
741 | } | ||
742 | |||
743 | for(pv=yyps->vs; pv<yyps->vsp; pv++) { | ||
744 | YYDELETEVAL(*pv,2); | ||
745 | } | ||
746 | |||
747 | for(pp=yyps->ps; pp<yyps->psp; pp++) { | ||
748 | YYDELETEPOSN(*pp,2); | ||
749 | } | ||
750 | |||
751 | while (yyps) { | ||
752 | YYParseState *save = yyps; | ||
753 | yyps = save->save; | ||
754 | yyFreeState(save); | ||
755 | } | ||
756 | while (yypath) { | ||
757 | YYParseState *save = yypath; | ||
758 | yypath = save->save; | ||
759 | yyFreeState(save); | ||
760 | } | ||
761 | return (1); | ||
762 | } | ||
763 | |||
764 | yyaccept: | ||
765 | if (yyps->save) goto yyvalid; | ||
766 | if(yyerrctx) { | ||
767 | yyFreeState(yyerrctx); yyerrctx = 0; | ||
768 | } | ||
769 | while (yyps) { | ||
770 | YYParseState *save = yyps; | ||
771 | yyps = save->save; | ||
772 | yyFreeState(save); | ||
773 | } | ||
774 | while (yypath) { | ||
775 | YYParseState *save = yypath; | ||
776 | yypath = save->save; | ||
777 | yyFreeState(save); | ||
778 | } | ||
779 | return (0); | ||
780 | } | ||
781 | |||
782 | |||
783 | /* Call yylex() unless the token has already been read. */ | ||
784 | static int yyLex1(YYSTYPE *yylval, yyscan_t scanner) { | ||
785 | if(yylvp < yylve) { | ||
786 | /* we're currently re-reading tokens */ | ||
787 | *yylval = *yylvp++; | ||
788 | yyposn = *yylpp++; | ||
789 | return *yylexp++; | ||
790 | } else if(yyps->save) { | ||
791 | /* in trial mode; save scanner results for future parse attempts */ | ||
792 | if(yylvp == yylvlim) | ||
793 | yyExpand(); | ||
794 | *yylexp = yylex(yylval, scanner); | ||
795 | *yylvp++ = *yylval; | ||
796 | yylve++; | ||
797 | *yylpp++ = yyposn; | ||
798 | yylpe++; | ||
799 | return *yylexp++; | ||
800 | } else { /* normal operation, no conflict encountered */ | ||
801 | return yylex(yylval, scanner); | ||
802 | } | ||
803 | } | ||
804 | |||
805 | /* Enlarge lexical value queue */ | ||
806 | static int yyExpand() { | ||
807 | int p = yylvp - yylvals; | ||
808 | int s = yylvlim - yylvals; | ||
809 | s += YYSTACKGROWTH; | ||
810 | { | ||
811 | Yshort *tl = yylexemes; | ||
812 | YYSTYPE *tv = yylvals; | ||
813 | YYPOSN *tp = yylpsns; | ||
814 | # ifdef __cplusplus | ||
815 | yylvals = new YYSTYPE[s]; | ||
816 | yylpsns = new YYPOSN[s]; | ||
817 | yylexemes = new Yshort[s]; | ||
818 | memcpy(yylexemes, tl, (s-YYSTACKGROWTH)*sizeof(Yshort)); | ||
819 | yySCopy(yylvals, tv, s-YYSTACKGROWTH); | ||
820 | yyPCopy(yylpsns, tp, s-YYSTACKGROWTH); | ||
821 | delete[] tl; | ||
822 | delete[] tv; | ||
823 | delete[] tp; | ||
824 | # else | ||
825 | yylvals = (YYSTYPE*)malloc(s * sizeof(YYSTYPE)); | ||
826 | yylpsns = (YYPOSN*)malloc(s * sizeof(YYPOSN)); | ||
827 | yylexemes = (Yshort*)malloc(s * sizeof(Yshort)); | ||
828 | memcpy(yylexemes, tl, (s - YYSTACKGROWTH)*sizeof(Yshort)); | ||
829 | yySCopy(yylvals, tv, s - YYSTACKGROWTH); | ||
830 | yyPCopy(yylpsns, tp, s - YYSTACKGROWTH); | ||
831 | free(tl); | ||
832 | free(tv); | ||
833 | free(tp); | ||
834 | # endif | ||
835 | } | ||
836 | yylvp = yylve = yylvals + p; | ||
837 | yylvlim = yylvals + s; | ||
838 | yylpp = yylpe = yylpsns + p; | ||
839 | yylplim = yylpsns + s; | ||
840 | yylexp = yylexemes + p; | ||
841 | return 0; | ||
842 | } | ||
843 | |||
844 | static void yySCopy(YYSTYPE *to, YYSTYPE *from, int size) { | ||
845 | int i; | ||
846 | for (i = size-1; i >= 0; i--) { | ||
847 | to[i] = from[i]; | ||
848 | } | ||
849 | } | ||
850 | |||
851 | static void yyPCopy(YYPOSN *to, YYPOSN *from, int size) { | ||
852 | int i; | ||
853 | for (i = size-1; i >= 0; i--) { | ||
854 | to[i] = from[i]; | ||
855 | } | ||
856 | } | ||
857 | |||
858 | static void yyMoreStack(YYParseState *yyps) { | ||
859 | int p = yyps->ssp - yyps->ss; | ||
860 | Yshort *tss = yyps->ss; | ||
861 | YYSTYPE *tvs = yyps->vs; | ||
862 | YYPOSN *tps = yyps->ps; | ||
863 | int newSize = yyps->stacksize + YYSTACKGROWTH; | ||
864 | |||
865 | # ifdef __cplusplus | ||
866 | yyps->ss = new Yshort [newSize]; | ||
867 | yyps->vs = new YYSTYPE[newSize]; | ||
868 | yyps->ps = new YYPOSN [newSize]; | ||
869 | memcpy(yyps->ss, tss, yyps->stacksize * sizeof(Yshort)); | ||
870 | yySCopy(yyps->vs, tvs, yyps->stacksize); | ||
871 | yyPCopy(yyps->ps, tps, yyps->stacksize); | ||
872 | yyps->stacksize += YYSTACKGROWTH; | ||
873 | delete[] tss; | ||
874 | delete[] tvs; | ||
875 | delete[] tps; | ||
876 | # else | ||
877 | yyps->ss = (Yshort*) malloc(newSize * sizeof(Yshort)); | ||
878 | yyps->vs = (YYSTYPE*)malloc(newSize * sizeof(YYSTYPE)); | ||
879 | yyps->ps = (YYPOSN*) malloc(newSize * sizeof(YYPOSN)); | ||
880 | memcpy(yyps->ss, tss, yyps->stacksize * sizeof(Yshort)); | ||
881 | yySCopy(yyps->vs, tvs, yyps->stacksize); | ||
882 | yyPCopy(yyps->ps, tps, yyps->stacksize); | ||
883 | yyps->stacksize += YYSTACKGROWTH; | ||
884 | free(tss); | ||
885 | free(tvs); | ||
886 | free(tps); | ||
887 | # endif | ||
888 | yyps->ssp = yyps->ss + p; | ||
889 | yyps->vsp = yyps->vs + p; | ||
890 | yyps->psp = yyps->ps + p; | ||
891 | # if YYDEBUG | ||
892 | if (yydebug) | ||
893 | fprintf(stderr, "btyacc: stack size increased to %d\n", yyps->stacksize); | ||
894 | # endif | ||
895 | } | ||
896 | |||
897 | |||
898 | #ifdef __cplusplus | ||
899 | |||
900 | static YYParseState *yyNewState(int size) { | ||
901 | YYParseState *p = new YYParseState; | ||
902 | p->stacksize = size+4; | ||
903 | p->ss = new Yshort [size + 4]; | ||
904 | p->vs = new YYSTYPE[size + 4]; | ||
905 | p->ps = new YYPOSN [size + 4]; | ||
906 | memset(&p->vs[0], 0, (size+4)*sizeof(YYSTYPE)); | ||
907 | memset(&p->ps[0], 0, (size+4)*sizeof(YYPOSN)); | ||
908 | return p; | ||
909 | } | ||
910 | |||
911 | static void yyFreeState(YYParseState *p) { | ||
912 | delete[] p->ss; | ||
913 | delete[] p->vs; | ||
914 | delete[] p->ps; | ||
915 | delete p; | ||
916 | } | ||
917 | |||
918 | #else /* not __cplusplus */ | ||
919 | |||
920 | static YYParseState *yyNewState(int size) { | ||
921 | YYParseState *p = (YYParseState*)malloc(sizeof(YYParseState)); | ||
922 | |||
923 | p->stacksize = size+4; | ||
924 | p->ss = (Yshort*) malloc((size + 4) * sizeof(Yshort)); | ||
925 | p->vs = (YYSTYPE*)malloc((size + 4) * sizeof(YYSTYPE)); | ||
926 | p->ps = (YYPOSN*) malloc((size + 4) * sizeof(YYPOSN)); | ||
927 | memset(&p->vs[0], 0, (size+4)*sizeof(YYSTYPE)); | ||
928 | memset(&p->ps[0], 0, (size+4)*sizeof(YYPOSN)); | ||
929 | return p; | ||
930 | } | ||
931 | |||
932 | static void yyFreeState(YYParseState *p) { | ||
933 | free(p->ss); | ||
934 | free(p->vs); | ||
935 | free(p->ps); | ||
936 | free(p); | ||
937 | } | ||
938 | |||
939 | #endif | ||