]> git.saurik.com Git - bison.git/blob - data/glr.c
173d8c2d0c808f63d3787e6e7aaed776f7702c06
[bison.git] / data / glr.c
1 m4_divert(-1) -*- C -*-
2
3 # GLR skeleton for Bison
4 # Copyright (C) 2002, 2003 Free Software Foundation, Inc.
5
6 # This program is free software; you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation; either version 2 of the License, or
9 # (at your option) any later version.
10
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
15
16 # You should have received a copy of the GNU General Public License
17 # along with this program; if not, write to the Free Software
18 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
19 # 02111-1307 USA
20
21
22 ## ---------------- ##
23 ## Default values. ##
24 ## ---------------- ##
25
26 # Stack parameters.
27 m4_define_default([b4_stack_depth_max], [10000])
28 m4_define_default([b4_stack_depth_init], [200])
29
30
31
32 ## ------------------------ ##
33 ## Pure/impure interfaces. ##
34 ## ------------------------ ##
35
36
37 # b4_lex_param
38 # ------------
39 # Accumule in b4_lex_param all the yylex arguments.
40 # Yes, this is quite ugly...
41 m4_define([b4_lex_param],
42 m4_dquote(b4_pure_if([[[[YYSTYPE *]], [[yylvalp]]][]dnl
43 b4_location_if([, [[YYLTYPE *], [yyllocp]]])])dnl
44 m4_ifdef([b4_lex_param], [, ]b4_lex_param)))
45
46
47 # b4_user_formals
48 # ---------------
49 m4_define([b4_user_formals],
50 [m4_ifset([b4_parse_param], [, b4_c_ansi_formals(b4_parse_param)])])
51
52
53 # b4_yyerror_args
54 # ---------------
55 # Arguments passed to yyerror: user args plus yylloc.
56 m4_define([b4_yyerror_args],
57 [b4_pure_if([b4_location_if([yylocp, ])])dnl
58 m4_ifset([b4_parse_param], [b4_c_args(b4_parse_param), ])])
59
60
61 # b4_lyyerror_args
62 # ----------------
63 # Same as above, but on the lookahead, hence yyllocp instead of yylocp.
64 m4_define([b4_lyyerror_args],
65 [b4_pure_if([b4_location_if([yyllocp, ])])dnl
66 m4_ifset([b4_parse_param], [b4_c_args(b4_parse_param), ])])
67
68
69 # b4_pure_args
70 # ------------
71 # Arguments needed by yyerror: user args plus yylloc.
72 m4_define([b4_pure_args],
73 [b4_pure_if([b4_location_if([, yylocp])])[]b4_user_args])
74
75
76 # b4_pure_formals
77 # ---------------
78 # Arguments passed to yyerror: user formals plus yyllocp.
79 m4_define([b4_pure_formals],
80 [b4_pure_if([b4_location_if([, YYLTYPE *yylocp])])[]b4_user_formals])
81
82
83 # b4_lpure_args
84 # -------------
85 # Same as above, but on the lookahead, hence yyllocp instead of yylocp.
86 m4_define([b4_lpure_args],
87 [b4_pure_if([b4_location_if([, yyllocp])])[]b4_user_args])
88
89
90 # b4_lpure_formals
91 # ----------------
92 # Same as above, but on the lookahead, hence yyllocp instead of yylocp.
93 m4_define([b4_lpure_formals],
94 [b4_pure_if([b4_location_if([YYLTYPE *yyllocp])])[]b4_user_formals])
95
96
97 ## ----------------- ##
98 ## Semantic Values. ##
99 ## ----------------- ##
100
101
102 # b4_lhs_value([TYPE])
103 # --------------------
104 # Expansion of $<TYPE>$.
105 m4_define([b4_lhs_value],
106 [(*yyvalp)[]m4_ifval([$1], [.$1])])
107
108
109 # b4_rhs_value(RULE-LENGTH, NUM, [TYPE])
110 # --------------------------------------
111 # Expansion of $<TYPE>NUM, where the current rule has RULE-LENGTH
112 # symbols on RHS.
113 m4_define([b4_rhs_value],
114 [yyvsp@{YYFILL (m4_eval([$2 - $1]))@}.yystate.yysemantics.yysval[]m4_ifval([$3], [.$3])])
115
116
117
118 ## ----------- ##
119 ## Locations. ##
120 ## ----------- ##
121
122 # b4_lhs_location()
123 # -----------------
124 # Expansion of @$.
125 m4_define([b4_lhs_location],
126 [(*yylocp)])
127
128
129 # b4_rhs_location(RULE-LENGTH, NUM)
130 # ---------------------------------
131 # Expansion of @NUM, where the current rule has RULE-LENGTH symbols
132 # on RHS.
133 m4_define([b4_rhs_location],
134 [yyvsp@{YYFILL (m4_eval([$2 - $1]))@}.yystate.yyloc])
135
136 # We do want M4 expansion after # for CPP macros.
137 m4_changecom()
138 m4_divert(0)dnl
139 @output @output_parser_name@
140 b4_copyright([Skeleton parser for GLR parsing with Bison], [2002, 2003])
141 [
142 /* This is the parser code for GLR (Generalized LR) parser. */
143
144 #include <stdio.h>
145 #include <stdlib.h>
146 #include <string.h>
147 #include <stdarg.h>
148 #include <setjmp.h>
149
150 ]b4_identification
151 m4_if(b4_prefix[], [yy], [],
152 [/* If NAME_PREFIX is specified substitute the variables and functions
153 names. */
154 #define yyparse b4_prefix[]parse
155 #define yylex b4_prefix[]lex
156 #define yyerror b4_prefix[]error
157 #define yylval b4_prefix[]lval
158 #define yychar b4_prefix[]char
159 #define yydebug b4_prefix[]debug
160 #define yynerrs b4_prefix[]nerrs
161 b4_location_if([#define yylloc b4_prefix[]lloc])])
162
163 b4_token_defines(b4_tokens)
164
165 /* Copy the first part of user declarations. */
166 b4_pre_prologue[
167
168 /* Enabling traces. */
169 #ifndef YYDEBUG
170 # define YYDEBUG ]b4_debug[
171 #endif
172
173 /* Enabling verbose error messages. */
174 #ifdef YYERROR_VERBOSE
175 # undef YYERROR_VERBOSE
176 # define YYERROR_VERBOSE 1
177 #else
178 # define YYERROR_VERBOSE ]b4_error_verbose[
179 #endif
180
181 #if ! defined (YYSTYPE) && ! defined (YYSTYPE_IS_DECLARED)
182 ]m4_ifdef([b4_stype],
183 [b4_syncline([b4_stype_line], [b4_filename])
184 typedef union m4_bregexp(b4_stype, [^{], [YYSTYPE ])b4_stype YYSTYPE;
185 /* Line __line__ of glr.c. */
186 b4_syncline([@oline@], [@ofile@])],
187 [typedef int YYSTYPE;])[
188 # define YYSTYPE_IS_DECLARED 1
189 # define YYSTYPE_IS_TRIVIAL 1
190 #endif
191
192 #if ! defined (YYLTYPE) && ! defined (YYLTYPE_IS_DECLARED)
193 typedef struct YYLTYPE
194 {
195 int first_line;
196 int first_column;
197 int last_line;
198 int last_column;
199 } YYLTYPE;
200 # define YYLTYPE_IS_DECLARED 1
201 # define YYLTYPE_IS_TRIVIAL 1
202 #endif
203
204 /* Default (constant) values used for initialization for null
205 right-hand sides. Unlike the standard yacc.c template,
206 here we set the default values of $$ and $@@ to zeroed-out
207 values. Since the default value of these quantities is undefined,
208 this behavior is technically correct. */
209 static YYSTYPE yyval_default;
210 static YYLTYPE yyloc_default;
211
212 /* Copy the second part of user declarations. */
213 ]b4_post_prologue[
214
215 ]/* Line __line__ of glr.c. */
216 b4_syncline([@oline@], [@ofile@])
217 [
218 #ifdef __cplusplus
219 typedef bool yybool;
220 #else
221 typedef unsigned char yybool;
222 #endif
223 #define yytrue 1
224 #define yyfalse 0
225
226 /*-----------------.
227 | GCC extensions. |
228 `-----------------*/
229
230 #ifndef __attribute__
231 /* This feature is available in gcc versions 2.5 and later. */
232 # if !defined (__GNUC__) || __GNUC__ < 2 || \
233 (__GNUC__ == 2 && __GNUC_MINOR__ < 5) || __STRICT_ANSI__
234 # define __attribute__(Spec) /* empty */
235 # endif
236 #endif
237
238 #ifndef ATTRIBUTE_UNUSED
239 # define ATTRIBUTE_UNUSED __attribute__ ((__unused__))
240 #endif
241
242 /* YYFINAL -- State number of the termination state. */
243 #define YYFINAL ]b4_final_state_number[
244 /* YYLAST -- Last index in YYTABLE. */
245 #define YYLAST ]b4_last[
246
247 /* YYNTOKENS -- Number of terminals. */
248 #define YYNTOKENS ]b4_tokens_number[
249 /* YYNNTS -- Number of nonterminals. */
250 #define YYNNTS ]b4_nterms_number[
251 /* YYNRULES -- Number of rules. */
252 #define YYNRULES ]b4_rules_number[
253 /* YYNRULES -- Number of states. */
254 #define YYNSTATES ]b4_states_number[
255 /* YYMAXRHS -- Maximum number of symbols on right-hand side of rule. */
256 #define YYMAXRHS ]b4_r2_max[
257
258 /* YYTRANSLATE(X) -- Bison symbol number corresponding to X. */
259 #define YYUNDEFTOK ]b4_undef_token_number[
260 #define YYMAXUTOK ]b4_user_token_number_max[
261
262 #define YYTRANSLATE(YYX) \
263 ((YYX <= 0) ? YYEOF : \
264 (unsigned)(YYX) <= YYMAXUTOK ? yytranslate[YYX] : YYUNDEFTOK)
265
266 /* YYTRANSLATE[YYLEX] -- Bison symbol number corresponding to YYLEX. */
267 static const ]b4_int_type_for([b4_translate])[ yytranslate[] =
268 {
269 ]b4_translate[
270 };
271
272 #if YYDEBUG
273 /* YYPRHS[YYN] -- Index of the first RHS symbol of rule number YYN in
274 YYRHS. */
275 static const ]b4_int_type_for([b4_prhs])[ yyprhs[] =
276 {
277 ]b4_prhs[
278 };
279
280 /* YYRHS -- A `-1'-separated list of the rules' RHS. */
281 static const ]b4_int_type_for([b4_rhs])[ yyrhs[] =
282 {
283 ]b4_rhs[
284 };
285
286 /* YYRLINE[YYN] -- source line where rule number YYN was defined. */
287 static const ]b4_int_type_for([b4_rline])[ yyrline[] =
288 {
289 ]b4_rline[
290 };
291 #endif
292
293 #if (YYDEBUG) || YYERROR_VERBOSE
294 /* YYTNME[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM.
295 First, the terminals, then, starting at YYNTOKENS, nonterminals. */
296 static const char *const yytname[] =
297 {
298 ]b4_tname[
299 };
300 #endif
301
302 /* YYR1[YYN] -- Symbol number of symbol that rule YYN derives. */
303 static const ]b4_int_type_for([b4_r1])[ yyr1[] =
304 {
305 ]b4_r1[
306 };
307
308 /* YYR2[YYN] -- Number of symbols composing right hand side of rule YYN. */
309 static const ]b4_int_type_for([b4_r2])[ yyr2[] =
310 {
311 ]b4_r2[
312 };
313
314 /* YYDPREC[RULE-NUM] -- Dynamic precedence of rule #RULE-NUM (0 if none). */
315 static const ]b4_int_type_for([b4_dprec])[ yydprec[] =
316 {
317 ]b4_dprec[
318 };
319
320 /* YYMERGER[RULE-NUM] -- Index of merging function for rule #RULE-NUM. */
321 static const ]b4_int_type_for([b4_merger])[ yymerger[] =
322 {
323 ]b4_merger[
324 };
325
326 /* YYDEFACT[S] -- default rule to reduce with in state S when YYTABLE
327 doesn't specify something else to do. Zero means the default is an
328 error. */
329 static const ]b4_int_type_for([b4_defact])[ yydefact[] =
330 {
331 ]b4_defact[
332 };
333
334 /* YYPDEFGOTO[NTERM-NUM]. */
335 static const ]b4_int_type_for([b4_defgoto])[ yydefgoto[] =
336 {
337 ]b4_defgoto[
338 };
339
340 /* YYPACT[STATE-NUM] -- Index in YYTABLE of the portion describing
341 STATE-NUM. */
342 #define YYPACT_NINF ]b4_pact_ninf[
343 static const ]b4_int_type_for([b4_pact])[ yypact[] =
344 {
345 ]b4_pact[
346 };
347
348 /* YYPGOTO[NTERM-NUM]. */
349 static const ]b4_int_type_for([b4_pgoto])[ yypgoto[] =
350 {
351 ]b4_pgoto[
352 };
353
354 /* YYTABLE[YYPACT[STATE-NUM]]. What to do in state STATE-NUM. If
355 positive, shift that token. If negative, reduce the rule which
356 number is the opposite. If zero, do what YYDEFACT says.
357 If YYTABLE_NINF, syntax error. */
358 #define YYTABLE_NINF ]b4_table_ninf[
359 static const ]b4_int_type_for([b4_table])[ yytable[] =
360 {
361 ]b4_table[
362 };
363
364 /* YYCONFLP[YYPACT[STATE-NUM]] -- Pointer into YYCONFL of start of
365 list of conflicting reductions corresponding to action entry for
366 state STATE-NUM in yytable. 0 means no conflicts. The list in
367 yyconfl is terminated by a rule number of 0. */
368 static const ]b4_int_type_for([b4_conflict_list_heads])[ yyconflp[] =
369 {
370 ]b4_conflict_list_heads[
371 };
372
373 /* YYCONFL[I] -- lists of conflicting rule numbers, each terminated by
374 0, pointed into by YYCONFLP. */
375 ]dnl Do not use b4_int_type_for here, since there are places where
376 dnl pointers onto yyconfl are taken, which type is "short *".
377 dnl We probably ought to introduce a type for confl.
378 [static const short yyconfl[] =
379 {
380 ]b4_conflicting_rules[
381 };
382
383 static const ]b4_int_type_for([b4_check])[ yycheck[] =
384 {
385 ]b4_check[
386 };
387
388 /* YYSTOS[STATE-NUM] -- The (internal number of the) accessing
389 symbol of state STATE-NUM. */
390 static const ]b4_int_type_for([b4_stos])[ yystos[] =
391 {
392 ]b4_stos[
393 };
394
395 \f
396 /* Prevent warning if -Wmissing-prototypes. */
397 ]b4_c_ansi_function_decl([yyparse], [int], b4_parse_param)[
398
399 /* Error token number */
400 #define YYTERROR 1
401
402 /* YYLLOC_DEFAULT -- Compute the default location (before the actions
403 are run). */
404
405 #define YYRHSLOC(yyRhs,YYK) (yyRhs[YYK].yystate.yyloc)
406
407 #ifndef YYLLOC_DEFAULT
408 # define YYLLOC_DEFAULT(yyCurrent, yyRhs, YYN) \
409 yyCurrent.first_line = YYRHSLOC(yyRhs,1).first_line; \
410 yyCurrent.first_column = YYRHSLOC(yyRhs,1).first_column; \
411 yyCurrent.last_line = YYRHSLOC(yyRhs,YYN).last_line; \
412 yyCurrent.last_column = YYRHSLOC(yyRhs,YYN).last_column;
413 #endif
414
415 /* YYLEX -- calling `yylex' with the right arguments. */
416 #define YYLEX ]b4_c_function_call([yylex], [int], b4_lex_param)[
417
418 ]b4_pure_if(
419 [
420 #undef yynerrs
421 #define yynerrs (yystack->yyerrcnt)
422 #undef yychar
423 #define yychar (yystack->yyrawchar)],
424 [YYSTYPE yylval;
425
426 YYLTYPE yylloc;
427
428 int yynerrs;
429 int yychar;])[
430
431 static const int YYEOF = 0;
432 static const int YYEMPTY = -2;
433
434 typedef enum { yyok, yyaccept, yyabort, yyerr } YYRESULTTAG;
435
436 #define YYCHK(YYE) \
437 do { YYRESULTTAG yyflag = YYE; if (yyflag != yyok) return yyflag; } \
438 while (0)
439
440 #if YYDEBUG
441
442 #if ! defined (YYFPRINTF)
443 # define YYFPRINTF fprintf
444 #endif
445
446 # define YYDPRINTF(Args) \
447 do { \
448 if (yydebug) \
449 YYFPRINTF Args; \
450 } while (0)
451
452 ]b4_yysymprint_generate([b4_c_ansi_function_def])[
453
454 # define YYDSYMPRINT(Args) \
455 do { \
456 if (yydebug) \
457 yysymprint Args; \
458 } while (0)
459
460 # define YYDSYMPRINTF(Title, Token, Value, Location) \
461 do { \
462 if (yydebug) \
463 { \
464 YYFPRINTF (stderr, "%s ", Title); \
465 yysymprint (stderr, \
466 Token, Value]b4_location_if([, Location])[); \
467 YYFPRINTF (stderr, "\n"); \
468 } \
469 } while (0)
470
471 /* Nonzero means print parse trace. It is left uninitialized so that
472 multiple parsers can coexist. */
473 int yydebug;
474
475 #else /* !YYDEBUG */
476
477 /* Avoid empty `if' bodies. */
478 # define YYDPRINTF(Args)
479 # define YYDSYMPRINT(Args)
480 # define YYDSYMPRINTF(Title, Token, Value, Location)
481
482 #endif /* !YYDEBUG */
483
484 /* YYINITDEPTH -- initial size of the parser's stacks. */
485 #ifndef YYINITDEPTH
486 # define YYINITDEPTH ]b4_stack_depth_init[
487 #endif
488
489 /* YYMAXDEPTH -- maximum size the stacks can grow to (effective only
490 if the built-in stack extension method is used).
491
492 Do not make this value too large; the results are undefined if
493 SIZE_MAX < YYMAXDEPTH * sizeof (GLRStackItem)
494 evaluated with infinite-precision integer arithmetic. */
495
496 #if YYMAXDEPTH == 0
497 # undef YYMAXDEPTH
498 #endif
499
500 #ifndef YYMAXDEPTH
501 # define YYMAXDEPTH ]b4_stack_depth_max[
502 #endif
503
504 /* Minimum number of free items on the stack allowed after an
505 allocation. This is to allow allocation and initialization
506 to be completed by functions that call expandGLRStack before the
507 stack is expanded, thus insuring that all necessary pointers get
508 properly redirected to new data. */
509 #define YYHEADROOM 2
510
511 #if (! defined (YYSTACKEXPANDABLE) \
512 && (! defined (__cplusplus) \
513 || (]b4_location_if([[defined (YYLTYPE_IS_TRIVIAL) && YYLTYPE_IS_TRIVIAL \
514 && ]])[defined (YYSTYPE_IS_TRIVIAL) && YYSTYPE_IS_TRIVIAL)))
515 #define YYSTACKEXPANDABLE 1
516 #else
517 #define YYSTACKEXPANDABLE 0
518 #endif
519
520 /** State numbers, as in LALR(1) machine */
521 typedef int yyStateNum;
522
523 /** Rule numbers, as in LALR(1) machine */
524 typedef int yyRuleNum;
525
526 /** Grammar symbol */
527 typedef short yySymbol;
528
529 /** Item references, as in LALR(1) machine */
530 typedef short yyItemNum;
531
532 typedef struct yyGLRState yyGLRState;
533 typedef struct yySemanticOption yySemanticOption;
534 typedef union yyGLRStackItem yyGLRStackItem;
535 typedef struct yyGLRStack yyGLRStack;
536 typedef struct yyGLRStateSet yyGLRStateSet;
537
538 struct yyGLRState {
539 yybool yyisState;
540 yybool yyresolved;
541 yyStateNum yylrState;
542 yyGLRState* yypred;
543 size_t yyposn;
544 union {
545 yySemanticOption* yyfirstVal;
546 YYSTYPE yysval;
547 } yysemantics;
548 YYLTYPE yyloc;
549 };
550
551 struct yyGLRStateSet {
552 yyGLRState** yystates;
553 size_t yysize, yycapacity;
554 };
555
556 struct yySemanticOption {
557 yybool yyisState;
558 yyRuleNum yyrule;
559 yyGLRState* yystate;
560 yySemanticOption* yynext;
561 };
562
563 union yyGLRStackItem {
564 yyGLRState yystate;
565 yySemanticOption yyoption;
566 };
567
568 struct yyGLRStack {
569 int yyerrflag;
570 int yyerrState;
571 ]b4_pure_if(
572 [
573 int yyerrcnt;
574 int yyrawchar;
575 ])[
576 yySymbol* yytokenp;
577 jmp_buf yyexception_buffer;
578 yyGLRStackItem* yyitems;
579 yyGLRStackItem* yynextFree;
580 int yyspaceLeft;
581 yyGLRState* yysplitPoint;
582 yyGLRState* yylastDeleted;
583 yyGLRStateSet yytops;
584 };
585
586 static void yyinitGLRStack (yyGLRStack* yystack, size_t yysize);
587 static void yyexpandGLRStack (yyGLRStack* yystack]b4_pure_formals[);
588 static void yyfreeGLRStack (yyGLRStack* yystack);
589
590 static void
591 yyFail (yyGLRStack* yystack]b4_pure_formals[, const char* yyformat, ...)
592 {
593 yystack->yyerrflag = 1;
594 if (yyformat != NULL)
595 {
596 char yymsg[256];
597 va_list yyap;
598 va_start (yyap, yyformat);
599 vsprintf (yymsg, yyformat, yyap);
600 yyerror (]b4_yyerror_args[yymsg);
601 }
602 longjmp (yystack->yyexception_buffer, 1);
603 }
604
605 #if YYDEBUG || YYERROR_VERBOSE
606 /** A printable representation of TOKEN. Valid until next call to
607 * tokenName. */
608 static inline const char*
609 yytokenName (yySymbol yytoken)
610 {
611 return yytname[yytoken];
612 }
613 #endif
614
615 /** Fill in YYVSP[YYLOW1 .. YYLOW0-1] from the chain of states starting
616 * at YYVSP[YYLOW0].yystate.yypred. Leaves YYVSP[YYLOW1].yystate.yypred
617 * containing the pointer to the next state in the chain. Assumes
618 * YYLOW1 < YYLOW0. For convenience, returns YYLOW1. */
619 static int
620 yyfill (yyGLRStackItem* yyvsp, int yylow0, int yylow1)
621 {
622 yyGLRState* s;
623 int i;
624 s = yyvsp[yylow0].yystate.yypred;
625 for (i = yylow0-1; i >= yylow1; i -= 1)
626 {
627 if (! s->yyresolved)
628 abort ();
629 yyvsp[i].yystate.yyresolved = yytrue;
630 yyvsp[i].yystate.yysemantics.yysval = s->yysemantics.yysval;
631 yyvsp[i].yystate.yyloc = s->yyloc;
632 s = yyvsp[i].yystate.yypred = s->yypred;
633 }
634 return yylow1;
635 }
636
637 /** Perform user action for rule number YYN, with RHS length YYRHSLEN,
638 * and top stack item YYVSP. YYLVALP points to place to put semantic
639 * value ($$), and yylocp points to place for location information
640 * (@@$). Returns yyok for normal return, yyaccept for YYACCEPT,
641 * yyerr for YYERROR, yyabort for YYABORT. */
642 static YYRESULTTAG
643 yyuserAction (yyRuleNum yyn, int yyrhslen, yyGLRStackItem* yyvsp,
644 YYSTYPE* yyvalp, YYLTYPE* yylocp, yyGLRStack* yystack
645 ]b4_user_formals[)
646 {
647 int yynormal = (yystack->yysplitPoint == NULL);
648 int yylow;
649
650 if (yyrhslen == 0)
651 {
652 *yyvalp = yyval_default;
653 *yylocp = yyloc_default;
654 }
655 else
656 {
657 *yyvalp = yyvsp[1-yyrhslen].yystate.yysemantics.yysval;
658 *yylocp = yyvsp[1-yyrhslen].yystate.yyloc;
659 }
660 # undef yyerrok
661 # define yyerrok (yystack->yyerrState = 0)
662 # undef YYACCEPT
663 # define YYACCEPT return yyaccept
664 # undef YYABORT
665 # define YYABORT return yyabort
666 # undef YYERROR
667 # define YYERROR return yyerr
668 # undef YYRECOVERING
669 # define YYRECOVERING (yystack->yyerrState != 0)
670 # undef yyclearin
671 # define yyclearin (yychar = *(yystack->yytokenp) = YYEMPTY)
672 # undef YYFILL
673 # define YYFILL(N) \
674 ((yynormal || yylow <= (N)) ? (N) : (yylow = yyfill (yyvsp, yylow, N)))
675 # undef YYBACKUP
676 # define YYBACKUP(Token, Value) \
677 do { \
678 yyerror (]b4_yyerror_args["syntax error: cannot back up"); \
679 YYERROR; \
680 } while (0)
681
682 ]
683 yylow = 1;
684 switch (yyn)
685 {
686 b4_actions
687 }
688
689 return yyok;
690 # undef yyerrok
691 # undef YYABORT
692 # undef YYACCEPT
693 # undef YYERROR
694 # undef YYBACKUP
695 # undef yyclearin
696 # undef YYRECOVERING
697 /* Line __line__ of glr.c. */
698 b4_syncline([@oline@], [@ofile@])
699 }
700 \f
701
702 static YYSTYPE
703 yyuserMerge (int yyn, YYSTYPE* yy0, YYSTYPE* yy1)
704 {
705 YYSTYPE yyval = *yy0;
706 /* `Use' the arguments. */
707 (void) yy0;
708 (void) yy1;
709
710 switch (yyn)
711 {
712 b4_mergers
713 }
714 return yyval;
715 }
716 [
717 /* Bison grammar-table manipulation. */
718
719 ]b4_yydestruct_generate([b4_c_ansi_function_def])[
720
721 /** Number of symbols composing the right hand side of rule #RULE. */
722 static inline int
723 yyrhsLength (yyRuleNum yyrule)
724 {
725 return yyr2[yyrule];
726 }
727
728 /** Left-hand-side symbol for rule #RULE. */
729 static inline yySymbol
730 yylhsNonterm (yyRuleNum yyrule)
731 {
732 return yyr1[yyrule];
733 }
734
735 #define yyis_pact_ninf(yystate) \
736 ]m4_if(m4_eval(b4_pact_ninf < b4_pact_min), 1,
737 0,
738 ((yystate) == YYPACT_NINF))[
739
740 /** True iff LR state STATE has only a default reduction (regardless
741 * of token). */
742 static inline yybool
743 yyisDefaultedState (yyStateNum yystate)
744 {
745 return yyis_pact_ninf (yypact[yystate]);
746 }
747
748 /** The default reduction for STATE, assuming it has one. */
749 static inline yyRuleNum
750 yydefaultAction (yyStateNum yystate)
751 {
752 return yydefact[yystate];
753 }
754
755 #define yyis_table_ninf(yytable_value) \
756 ]m4_if(m4_eval(b4_table_ninf < b4_table_min), 1,
757 0,
758 ((yytable_value) == YYTABLE_NINF))[
759
760 /** Set *YYACTION to the action to take in YYSTATE on seeing YYTOKEN.
761 * Result R means
762 * R < 0: Reduce on rule -R.
763 * R = 0: Error.
764 * R > 0: Shift to state R.
765 * Set *CONFLICTS to a pointer into yyconfl to 0-terminated list of
766 * conflicting reductions.
767 */
768 static inline void
769 yygetLRActions (yyStateNum yystate, int yytoken,
770 int* yyaction, const short** yyconflicts)
771 {
772 int yyindex = yypact[yystate] + yytoken;
773 if (yyindex < 0 || YYLAST < yyindex || yycheck[yyindex] != yytoken)
774 {
775 *yyaction = -yydefact[yystate];
776 *yyconflicts = yyconfl;
777 }
778 else if (! yyis_table_ninf (yytable[yyindex]))
779 {
780 *yyaction = yytable[yyindex];
781 *yyconflicts = yyconfl + yyconflp[yyindex];
782 }
783 else
784 {
785 *yyaction = 0;
786 *yyconflicts = yyconfl + yyconflp[yyindex];
787 }
788 }
789
790 static inline yyStateNum
791 yyLRgotoState (yyStateNum yystate, yySymbol yylhs)
792 {
793 int yyr;
794 yyr = yypgoto[yylhs - YYNTOKENS] + yystate;
795 if (0 <= yyr && yyr <= YYLAST && yycheck[yyr] == yystate)
796 return yytable[yyr];
797 else
798 return yydefgoto[yylhs - YYNTOKENS];
799 }
800
801 static inline yybool
802 yyisShiftAction (int yyaction)
803 {
804 return 0 < yyaction;
805 }
806
807 static inline yybool
808 yyisErrorAction (int yyaction)
809 {
810 return yyaction == 0;
811 }
812
813 /* GLRStates */
814
815 static void
816 yyaddDeferredAction (yyGLRStack* yystack, yyGLRState* yystate,
817 yyGLRState* rhs, yyRuleNum yyrule]b4_pure_formals[)
818 {
819 yySemanticOption* yynewItem;
820 yynewItem = &yystack->yynextFree->yyoption;
821 yystack->yyspaceLeft -= 1;
822 yystack->yynextFree += 1;
823 yynewItem->yyisState = yyfalse;
824 yynewItem->yystate = rhs;
825 yynewItem->yyrule = yyrule;
826 yynewItem->yynext = yystate->yysemantics.yyfirstVal;
827 yystate->yysemantics.yyfirstVal = yynewItem;
828 if (yystack->yyspaceLeft < YYHEADROOM)
829 yyexpandGLRStack (yystack]b4_pure_args[);
830 }
831
832 /* GLRStacks */
833
834 /** Initialize SET to a singleton set containing an empty stack. */
835 static void
836 yyinitStateSet (yyGLRStateSet* yyset)
837 {
838 yyset->yysize = 1;
839 yyset->yycapacity = 16;
840 yyset->yystates = (yyGLRState**) malloc (16 * sizeof (yyset->yystates[0]));
841 yyset->yystates[0] = NULL;
842 }
843
844 static void yyfreeStateSet (yyGLRStateSet* yyset)
845 {
846 free (yyset->yystates);
847 }
848
849 /** Initialize STACK to a single empty stack, with total maximum
850 * capacity for all stacks of SIZE. */
851 static void
852 yyinitGLRStack (yyGLRStack* yystack, size_t yysize)
853 {
854 yystack->yyerrflag = 0;
855 yystack->yyerrState = 0;
856 yynerrs = 0;
857 yystack->yyspaceLeft = yysize;
858 yystack->yynextFree = yystack->yyitems =
859 (yyGLRStackItem*) malloc (yysize * sizeof (yystack->yynextFree[0]));
860 yystack->yysplitPoint = NULL;
861 yystack->yylastDeleted = NULL;
862 yyinitStateSet (&yystack->yytops);
863 }
864
865 #define YYRELOC(YYFROMITEMS,YYTOITEMS,YYX,YYTYPE) \
866 &((YYTOITEMS) - ((YYFROMITEMS) - (yyGLRStackItem*) (YYX)))->YYTYPE
867
868 /** If STACK is expandable, extend it. WARNING: Pointers into the
869 stack from outside should be considered invalid after this call.
870 We always expand when there are 1 or fewer items left AFTER an
871 allocation, so that we can avoid having external pointers exist
872 across an allocation. */
873 static void
874 yyexpandGLRStack (yyGLRStack* yystack]b4_pure_formals[)
875 {
876 #if YYSTACKEXPANDABLE
877 yyGLRStack yynewStack;
878 yyGLRStackItem* yyp0, *yyp1;
879 size_t yysize, yynewSize;
880 size_t yyn;
881 yysize = yystack->yynextFree - yystack->yyitems;
882 if (YYMAXDEPTH <= yysize)
883 yyFail (yystack][]b4_pure_args[, "parser stack overflow");
884 yynewSize = 2*yysize;
885 if (YYMAXDEPTH < yynewSize)
886 yynewSize = YYMAXDEPTH;
887 yyinitGLRStack (&yynewStack, yynewSize);
888 for (yyp0 = yystack->yyitems, yyp1 = yynewStack.yyitems, yyn = yysize;
889 0 < yyn;
890 yyn -= 1, yyp0 += 1, yyp1 += 1)
891 {
892 *yyp1 = *yyp0;
893 if (*(yybool *) yyp0)
894 {
895 yyGLRState* yys0 = &yyp0->yystate;
896 yyGLRState* yys1 = &yyp1->yystate;
897 if (yys0->yypred != NULL)
898 yys1->yypred =
899 YYRELOC (yyp0, yyp1, yys0->yypred, yystate);
900 if (! yys0->yyresolved && yys0->yysemantics.yyfirstVal != NULL)
901 yys1->yysemantics.yyfirstVal =
902 YYRELOC(yyp0, yyp1, yys0->yysemantics.yyfirstVal, yyoption);
903 }
904 else
905 {
906 yySemanticOption* yyv0 = &yyp0->yyoption;
907 yySemanticOption* yyv1 = &yyp1->yyoption;
908 if (yyv0->yystate != NULL)
909 yyv1->yystate = YYRELOC (yyp0, yyp1, yyv0->yystate, yystate);
910 if (yyv0->yynext != NULL)
911 yyv1->yynext = YYRELOC (yyp0, yyp1, yyv0->yynext, yyoption);
912 }
913 }
914 if (yystack->yysplitPoint != NULL)
915 yystack->yysplitPoint = YYRELOC (yystack->yyitems, yynewStack.yyitems,
916 yystack->yysplitPoint, yystate);
917
918 for (yyn = 0; yyn < yystack->yytops.yysize; yyn += 1)
919 if (yystack->yytops.yystates[yyn] != NULL)
920 yystack->yytops.yystates[yyn] =
921 YYRELOC (yystack->yyitems, yynewStack.yyitems,
922 yystack->yytops.yystates[yyn], yystate);
923 free (yystack->yyitems);
924 yystack->yyitems = yynewStack.yyitems;
925 yystack->yynextFree = yynewStack.yynextFree + yysize;
926 yystack->yyspaceLeft = yynewStack.yyspaceLeft - yysize;
927
928 #else
929
930 yyFail (yystack][]b4_pure_args[, "parser stack overflow");
931 #endif
932 }
933
934 static void
935 yyfreeGLRStack (yyGLRStack* yystack)
936 {
937 free (yystack->yyitems);
938 yyfreeStateSet (&yystack->yytops);
939 }
940
941 /** Assuming that S is a GLRState somewhere on STACK, update the
942 * splitpoint of STACK, if needed, so that it is at least as deep as
943 * S. */
944 static inline void
945 yyupdateSplit (yyGLRStack* yystack, yyGLRState* yys)
946 {
947 if (yystack->yysplitPoint != NULL && yystack->yysplitPoint > yys)
948 yystack->yysplitPoint = yys;
949 }
950
951 /** Invalidate stack #K in STACK. */
952 static inline void
953 yymarkStackDeleted (yyGLRStack* yystack, int yyk)
954 {
955 if (yystack->yytops.yystates[yyk] != NULL)
956 yystack->yylastDeleted = yystack->yytops.yystates[yyk];
957 yystack->yytops.yystates[yyk] = NULL;
958 }
959
960 /** Undelete the last stack that was marked as deleted. Can only be
961 done once after a deletion, and only when all other stacks have
962 been deleted. */
963 static void
964 yyundeleteLastStack (yyGLRStack* yystack)
965 {
966 if (yystack->yylastDeleted == NULL || yystack->yytops.yysize != 0)
967 return;
968 yystack->yytops.yystates[0] = yystack->yylastDeleted;
969 yystack->yytops.yysize = 1;
970 YYDPRINTF ((stderr, "Restoring last deleted stack as stack #0.\n"));
971 yystack->yylastDeleted = NULL;
972 }
973
974 static inline void
975 yyremoveDeletes (yyGLRStack* yystack)
976 {
977 size_t yyi, yyj;
978 yyi = yyj = 0;
979 while (yyj < yystack->yytops.yysize)
980 {
981 if (yystack->yytops.yystates[yyi] == NULL)
982 {
983 if (yyi == yyj)
984 {
985 YYDPRINTF ((stderr, "Removing dead stacks.\n"));
986 }
987 yystack->yytops.yysize -= 1;
988 }
989 else
990 {
991 yystack->yytops.yystates[yyj] = yystack->yytops.yystates[yyi];
992 if (yyj != yyi)
993 {
994 YYDPRINTF ((stderr, "Rename stack %d -> %d.\n", yyi, yyj));
995 }
996 yyj += 1;
997 }
998 yyi += 1;
999 }
1000 }
1001
1002 /** Shift to a new state on stack #K of STACK, corresponding to LR state
1003 * LRSTATE, at input position POSN, with (resolved) semantic value SVAL. */
1004 static inline void
1005 yyglrShift (yyGLRStack* yystack, int yyk, yyStateNum yylrState, size_t yyposn,
1006 YYSTYPE yysval, YYLTYPE* yylocp]b4_user_formals[)
1007 {
1008 yyGLRStackItem* yynewItem;
1009
1010 yynewItem = yystack->yynextFree;
1011 yystack->yynextFree += 1;
1012 yystack->yyspaceLeft -= 1;
1013 yynewItem->yystate.yyisState = yytrue;
1014 yynewItem->yystate.yylrState = yylrState;
1015 yynewItem->yystate.yyposn = yyposn;
1016 yynewItem->yystate.yyresolved = yytrue;
1017 yynewItem->yystate.yypred = yystack->yytops.yystates[yyk];
1018 yystack->yytops.yystates[yyk] = &yynewItem->yystate;
1019 yynewItem->yystate.yysemantics.yysval = yysval;
1020 yynewItem->yystate.yyloc = *yylocp;
1021 if (yystack->yyspaceLeft < YYHEADROOM)
1022 yyexpandGLRStack (yystack]b4_pure_args[);
1023 }
1024
1025 /** Shift stack #K of YYSTACK, to a new state corresponding to LR
1026 * state YYLRSTATE, at input position YYPOSN, with the (unresolved)
1027 * semantic value of YYRHS under the action for YYRULE. */
1028 static inline void
1029 yyglrShiftDefer (yyGLRStack* yystack, int yyk, yyStateNum yylrState,
1030 size_t yyposn, yyGLRState* rhs, yyRuleNum yyrule]b4_pure_formals[)
1031 {
1032 yyGLRStackItem* yynewItem;
1033
1034 yynewItem = yystack->yynextFree;
1035 yynewItem->yystate.yyisState = yytrue;
1036 yynewItem->yystate.yylrState = yylrState;
1037 yynewItem->yystate.yyposn = yyposn;
1038 yynewItem->yystate.yyresolved = yyfalse;
1039 yynewItem->yystate.yypred = yystack->yytops.yystates[yyk];
1040 yynewItem->yystate.yysemantics.yyfirstVal = NULL;
1041 yystack->yytops.yystates[yyk] = &yynewItem->yystate;
1042 yystack->yynextFree += 1;
1043 yystack->yyspaceLeft -= 1;
1044 yyaddDeferredAction (yystack, &yynewItem->yystate, rhs, yyrule]b4_pure_args[);
1045 }
1046
1047 /** Pop the symbols consumed by reduction #RULE from the top of stack
1048 * #K of STACK, and perform the appropriate semantic action on their
1049 * semantic values. Assumes that all ambiguities in semantic values
1050 * have been previously resolved. Set *VALP to the resulting value,
1051 * and *LOCP to the computed location (if any). Return value is as
1052 * for userAction. */
1053 static inline YYRESULTTAG
1054 yydoAction (yyGLRStack* yystack, int yyk, yyRuleNum yyrule,
1055 YYSTYPE* yyvalp, YYLTYPE* yylocp]b4_user_formals[)
1056 {
1057 int yynrhs = yyrhsLength (yyrule);
1058
1059 if (yystack->yysplitPoint == NULL)
1060 {
1061 /* Standard special case: single stack. */
1062 yyGLRStackItem* rhs = (yyGLRStackItem*) yystack->yytops.yystates[yyk];
1063 if (yyk != 0)
1064 abort ();
1065 yystack->yynextFree -= yynrhs;
1066 yystack->yyspaceLeft += yynrhs;
1067 yystack->yytops.yystates[0] = & yystack->yynextFree[-1].yystate;
1068 if (yynrhs == 0)
1069 {
1070 *yyvalp = yyval_default;
1071 *yylocp = yyloc_default;
1072 }
1073 else
1074 {
1075 *yyvalp = rhs[1-yynrhs].yystate.yysemantics.yysval;
1076 *yylocp = rhs[1-yynrhs].yystate.yyloc;
1077 }
1078 return yyuserAction (yyrule, yynrhs, rhs,
1079 yyvalp, yylocp, yystack]b4_user_args[);
1080 }
1081 else
1082 {
1083 int yyi;
1084 yyGLRState* yys;
1085 yyGLRStackItem yyrhsVals[YYMAXRHS+1];
1086 yys = yyrhsVals[YYMAXRHS].yystate.yypred = yystack->yytops.yystates[yyk];
1087 for (yyi = 0; yyi < yynrhs; yyi += 1)
1088 {
1089 yys = yys->yypred;
1090 if (yys == NULL)
1091 abort ();
1092 }
1093 yyupdateSplit (yystack, yys);
1094 yystack->yytops.yystates[yyk] = yys;
1095 if (yynrhs == 0)
1096 {
1097 *yyvalp = yyval_default;
1098 *yylocp = yyloc_default;
1099 }
1100 else
1101 {
1102 *yyvalp = yyrhsVals[1].yystate.yysemantics.yysval;
1103 *yylocp = yyrhsVals[1].yystate.yyloc;
1104 }
1105 return yyuserAction (yyrule, yynrhs, yyrhsVals + YYMAXRHS - 1,
1106 yyvalp, yylocp, yystack]b4_user_args[);
1107 }
1108 }
1109
1110 #if !YYDEBUG
1111 # define YY_REDUCE_PRINT(K, Rule)
1112 #else
1113 # define YY_REDUCE_PRINT(K, Rule) \
1114 do { \
1115 if (yydebug) \
1116 yy_reduce_print (K, Rule); \
1117 } while (0)
1118
1119 /*----------------------------------------------------------.
1120 | Report that the RULE is going to be reduced on stack #K. |
1121 `----------------------------------------------------------*/
1122
1123 static inline void
1124 yy_reduce_print (size_t yyk, yyRuleNum yyrule)
1125 {
1126 int yyi;
1127 unsigned int yylno = yyrline[yyrule];
1128 YYFPRINTF (stderr, "Reducing stack %d by rule %d (line %u), ",
1129 yyk, yyrule - 1, yylno);
1130 /* Print the symbols being reduced, and their result. */
1131 for (yyi = yyprhs[yyrule]; 0 <= yyrhs[yyi]; yyi++)
1132 YYFPRINTF (stderr, "%s ", yytokenName (yyrhs[yyi]));
1133 YYFPRINTF (stderr, "-> %s\n", yytokenName (yyr1[yyrule]));
1134 }
1135 #endif
1136
1137 /** Pop items off stack #K of STACK according to grammar rule RULE,
1138 * and push back on the resulting nonterminal symbol. Perform the
1139 * semantic action associated with RULE and store its value with the
1140 * newly pushed state, if FORCEEVAL or if STACK is currently
1141 * unambiguous. Otherwise, store the deferred semantic action with
1142 * the new state. If the new state would have an identical input
1143 * position, LR state, and predecessor to an existing state on the stack,
1144 * it is identified with that existing state, eliminating stack #K from
1145 * the STACK. In this case, the (necessarily deferred) semantic value is
1146 * added to the options for the existing state's semantic value.
1147 */
1148 static inline YYRESULTTAG
1149 yyglrReduce (yyGLRStack* yystack, size_t yyk, yyRuleNum yyrule,
1150 yybool yyforceEval]b4_pure_formals[)
1151 {
1152 size_t yyposn = yystack->yytops.yystates[yyk]->yyposn;
1153
1154 if (yyforceEval || yystack->yysplitPoint == NULL)
1155 {
1156 YYSTYPE yysval;
1157 YYLTYPE yyloc;
1158
1159 YY_REDUCE_PRINT (yyk, yyrule);
1160 YYCHK (yydoAction (yystack, yyk, yyrule, &yysval, &yyloc]b4_user_args[));
1161 yyglrShift (yystack, yyk,
1162 yyLRgotoState (yystack->yytops.yystates[yyk]->yylrState,
1163 yylhsNonterm (yyrule)),
1164 yyposn, yysval, &yyloc]b4_user_args[);
1165 }
1166 else
1167 {
1168 size_t yyi;
1169 int yyn;
1170 yyGLRState* yys, *yys0 = yystack->yytops.yystates[yyk];
1171 yyStateNum yynewLRState;
1172
1173 for (yys = yystack->yytops.yystates[yyk], yyn = yyrhsLength (yyrule);
1174 0 < yyn; yyn -= 1)
1175 {
1176 yys = yys->yypred;
1177 if (yys == NULL)
1178 abort ();
1179 }
1180 yyupdateSplit (yystack, yys);
1181 yynewLRState = yyLRgotoState (yys->yylrState, yylhsNonterm (yyrule));
1182 YYDPRINTF ((stderr,
1183 "Reduced stack %d by rule #%d; action deferred. "
1184 "Now in state %d.\n",
1185 yyk, yyrule-1, yynewLRState));
1186 for (yyi = 0; yyi < yystack->yytops.yysize; yyi += 1)
1187 if (yyi != yyk && yystack->yytops.yystates[yyi] != NULL)
1188 {
1189 yyGLRState* yyp, *yysplit = yystack->yysplitPoint;
1190 yyp = yystack->yytops.yystates[yyi];
1191 while (yyp != yys && yyp != yysplit && yyp->yyposn >= yyposn)
1192 {
1193 if (yyp->yylrState == yynewLRState && yyp->yypred == yys)
1194 {
1195 yyaddDeferredAction (yystack, yyp, yys0, yyrule]b4_pure_args[);
1196 yymarkStackDeleted (yystack, yyk);
1197 YYDPRINTF ((stderr, "Merging stack %d into stack %d.\n",
1198 yyk, yyi));
1199 return yyok;
1200 }
1201 yyp = yyp->yypred;
1202 }
1203 }
1204 yystack->yytops.yystates[yyk] = yys;
1205 yyglrShiftDefer (yystack, yyk, yynewLRState, yyposn, yys0, yyrule]b4_pure_args[);
1206 }
1207 return yyok;
1208 }
1209
1210 static int
1211 yysplitStack (yyGLRStack* yystack, int yyk)
1212 {
1213 if (yystack->yysplitPoint == NULL)
1214 {
1215 if (yyk != 0)
1216 abort ();
1217 yystack->yysplitPoint = yystack->yytops.yystates[yyk];
1218 }
1219 if (yystack->yytops.yysize >= yystack->yytops.yycapacity)
1220 {
1221 yystack->yytops.yycapacity *= 2;
1222 yystack->yytops.yystates =
1223 (yyGLRState**) realloc (yystack->yytops.yystates,
1224 yystack->yytops.yycapacity
1225 * sizeof (yyGLRState*));
1226 }
1227 yystack->yytops.yystates[yystack->yytops.yysize]
1228 = yystack->yytops.yystates[yyk];
1229 yystack->yytops.yysize += 1;
1230 return yystack->yytops.yysize-1;
1231 }
1232
1233 /** True iff Y0 and Y1 represent identical options at the top level.
1234 * That is, they represent the same rule applied to RHS symbols
1235 * that produce the same terminal symbols. */
1236 static yybool
1237 yyidenticalOptions (yySemanticOption* yyy0, yySemanticOption* yyy1)
1238 {
1239 if (yyy0->yyrule == yyy1->yyrule)
1240 {
1241 yyGLRState *yys0, *yys1;
1242 int yyn;
1243 for (yys0 = yyy0->yystate, yys1 = yyy1->yystate,
1244 yyn = yyrhsLength (yyy0->yyrule);
1245 yyn > 0;
1246 yys0 = yys0->yypred, yys1 = yys1->yypred, yyn -= 1)
1247 if (yys0->yyposn != yys1->yyposn)
1248 return yyfalse;
1249 return yytrue;
1250 }
1251 else
1252 return yyfalse;
1253 }
1254
1255 /** Assuming identicalOptions (Y0,Y1), (destructively) merge the
1256 * alternative semantic values for the RHS-symbols of Y1 into the
1257 * corresponding semantic value sets of the symbols of Y0. */
1258 static void
1259 yymergeOptionSets (yySemanticOption* yyy0, yySemanticOption* yyy1)
1260 {
1261 yyGLRState *yys0, *yys1;
1262 int yyn;
1263 for (yys0 = yyy0->yystate, yys1 = yyy1->yystate,
1264 yyn = yyrhsLength (yyy0->yyrule);
1265 yyn > 0;
1266 yys0 = yys0->yypred, yys1 = yys1->yypred, yyn -= 1)
1267 if (yys0 == yys1)
1268 break;
1269 else if (! yys0->yyresolved && ! yys1->yyresolved)
1270 {
1271 yySemanticOption* yyz;
1272 for (yyz = yys0->yysemantics.yyfirstVal; yyz->yynext != NULL;
1273 yyz = yyz->yynext)
1274 continue;
1275 yyz->yynext = yys1->yysemantics.yyfirstVal;
1276 }
1277 }
1278
1279 /** Y0 and Y1 represent two possible actions to take in a given
1280 * parsing state; return 0 if no combination is possible,
1281 * 1 if user-mergeable, 2 if Y0 is preferred, 3 if Y1 is preferred. */
1282 static int
1283 yypreference (yySemanticOption* y0, yySemanticOption* y1)
1284 {
1285 yyRuleNum r0 = y0->yyrule, r1 = y1->yyrule;
1286 int p0 = yydprec[r0], p1 = yydprec[r1];
1287
1288 if (p0 == p1)
1289 {
1290 if (yymerger[r0] == 0 || yymerger[r0] != yymerger[r1])
1291 return 0;
1292 else
1293 return 1;
1294 }
1295 if (p0 == 0 || p1 == 0)
1296 return 0;
1297 if (p0 < p1)
1298 return 3;
1299 if (p1 < p0)
1300 return 2;
1301 return 0;
1302 }
1303
1304 static YYRESULTTAG yyresolveValue (yySemanticOption* yyoptionList,
1305 yyGLRStack* yystack, YYSTYPE* yyvalp,
1306 YYLTYPE* yylocp]b4_user_formals[);
1307
1308 static YYRESULTTAG
1309 yyresolveStates (yyGLRState* yys, int yyn, yyGLRStack* yystack]b4_user_formals[)
1310 {
1311 YYRESULTTAG yyflag;
1312 if (0 < yyn)
1313 {
1314 if (yys->yypred == NULL)
1315 abort ();
1316 yyflag = yyresolveStates (yys->yypred, yyn-1, yystack]b4_user_args[);
1317 if (yyflag != yyok)
1318 return yyflag;
1319 if (! yys->yyresolved)
1320 {
1321 yyflag = yyresolveValue (yys->yysemantics.yyfirstVal, yystack,
1322 &yys->yysemantics.yysval, &yys->yyloc
1323 ]b4_user_args[);
1324 if (yyflag != yyok)
1325 return yyflag;
1326 yys->yyresolved = yytrue;
1327 }
1328 }
1329 return yyok;
1330 }
1331
1332 static YYRESULTTAG
1333 yyresolveAction (yySemanticOption* yyopt, yyGLRStack* yystack,
1334 YYSTYPE* yyvalp, YYLTYPE* yylocp]b4_user_formals[)
1335 {
1336 yyGLRStackItem yyrhsVals[YYMAXRHS+1];
1337 int yynrhs;
1338
1339 yynrhs = yyrhsLength (yyopt->yyrule);
1340 YYCHK (yyresolveStates (yyopt->yystate, yynrhs, yystack]b4_user_args[));
1341 yyrhsVals[YYMAXRHS].yystate.yypred = yyopt->yystate;
1342 return yyuserAction (yyopt->yyrule, yynrhs, yyrhsVals + YYMAXRHS - 1,
1343 yyvalp, yylocp, yystack]b4_user_args[);
1344 }
1345
1346 #if YYDEBUG
1347 static void
1348 yyreportTree (yySemanticOption* yyx, int yyindent)
1349 {
1350 int yynrhs = yyrhsLength (yyx->yyrule);
1351 int yyi;
1352 yyGLRState* yys;
1353 yyGLRState* yystates[YYMAXRHS];
1354 yyGLRState yyleftmost_state;
1355
1356 for (yyi = yynrhs, yys = yyx->yystate; 0 < yyi; yyi -= 1, yys = yys->yypred)
1357 yystates[yyi] = yys;
1358 if (yys == NULL)
1359 {
1360 yyleftmost_state.yyposn = 0;
1361 yystates[0] = &yyleftmost_state;
1362 }
1363 else
1364 yystates[0] = yys;
1365
1366 if (yyx->yystate->yyposn < yys->yyposn + 1)
1367 YYFPRINTF (stderr, "%*s%s -> <Rule %d, empty>\n",
1368 yyindent, "", yytokenName (yylhsNonterm (yyx->yyrule)),
1369 yyx->yyrule);
1370 else
1371 YYFPRINTF (stderr, "%*s%s -> <Rule %d, tokens %d .. %d>\n",
1372 yyindent, "", yytokenName (yylhsNonterm (yyx->yyrule)),
1373 yyx->yyrule, yys->yyposn+1, yyx->yystate->yyposn);
1374 for (yyi = 1; yyi <= yynrhs; yyi += 1)
1375 {
1376 if (yystates[yyi]->yyresolved)
1377 {
1378 if (yystates[yyi-1]->yyposn+1 > yystates[yyi]->yyposn)
1379 YYFPRINTF (stderr, "%*s%s <empty>\n", yyindent+2, "",
1380 yytokenName (yyrhs[yyprhs[yyx->yyrule]+yyi-1]));
1381 else
1382 YYFPRINTF (stderr, "%*s%s <tokens %d .. %d>\n", yyindent+2, "",
1383 yytokenName (yyrhs[yyprhs[yyx->yyrule]+yyi-1]),
1384 yystates[yyi-1]->yyposn+1, yystates[yyi]->yyposn);
1385 }
1386 else
1387 yyreportTree (yystates[yyi]->yysemantics.yyfirstVal, yyindent+2);
1388 }
1389 }
1390 #endif
1391
1392 static void
1393 yyreportAmbiguity (yySemanticOption* yyx0, yySemanticOption* yyx1,
1394 yyGLRStack* yystack]b4_pure_formals[)
1395 {
1396 /* `Unused' warnings. */
1397 (void) yyx0;
1398 (void) yyx1;
1399
1400 #if YYDEBUG
1401 YYFPRINTF (stderr, "Ambiguity detected.\n");
1402 YYFPRINTF (stderr, "Option 1,\n");
1403 yyreportTree (yyx0, 2);
1404 YYFPRINTF (stderr, "\nOption 2,\n");
1405 yyreportTree (yyx1, 2);
1406 YYFPRINTF (stderr, "\n");
1407 #endif
1408 yyFail (yystack][]b4_pure_args[, "ambiguity detected");
1409 }
1410
1411
1412 /** Resolve the ambiguity represented by OPTIONLIST, perform the indicated
1413 * actions, and return the result. */
1414 static YYRESULTTAG
1415 yyresolveValue (yySemanticOption* yyoptionList, yyGLRStack* yystack,
1416 YYSTYPE* yyvalp, YYLTYPE* yylocp]b4_user_formals[)
1417 {
1418 yySemanticOption* yybest;
1419 yySemanticOption* yyp;
1420 int yymerge;
1421
1422 yybest = yyoptionList;
1423 yymerge = 0;
1424 for (yyp = yyoptionList->yynext; yyp != NULL; yyp = yyp->yynext)
1425 {
1426 if (yyidenticalOptions (yybest, yyp))
1427 yymergeOptionSets (yybest, yyp);
1428 else
1429 switch (yypreference (yybest, yyp))
1430 {
1431 case 0:
1432 yyreportAmbiguity (yybest, yyp, yystack]b4_pure_args[);
1433 break;
1434 case 1:
1435 yymerge = 1;
1436 break;
1437 case 2:
1438 break;
1439 case 3:
1440 yybest = yyp;
1441 yymerge = 0;
1442 break;
1443 }
1444 }
1445
1446 if (yymerge)
1447 {
1448 int yyprec = yydprec[yybest->yyrule];
1449 YYCHK (yyresolveAction (yybest, yystack, yyvalp, yylocp]b4_user_args[));
1450 for (yyp = yybest->yynext; yyp != NULL; yyp = yyp->yynext)
1451 {
1452 if (yyprec == yydprec[yyp->yyrule])
1453 {
1454 YYSTYPE yyval1;
1455 YYLTYPE yydummy;
1456 YYCHK (yyresolveAction (yyp, yystack, &yyval1, &yydummy]b4_user_args[));
1457 *yyvalp = yyuserMerge (yymerger[yyp->yyrule], yyvalp, &yyval1);
1458 }
1459 }
1460 return yyok;
1461 }
1462 else
1463 return yyresolveAction (yybest, yystack, yyvalp, yylocp]b4_user_args[);
1464 }
1465
1466 static YYRESULTTAG
1467 yyresolveStack (yyGLRStack* yystack]b4_user_formals[)
1468 {
1469 if (yystack->yysplitPoint != NULL)
1470 {
1471 yyGLRState* yys;
1472 int yyn;
1473
1474 for (yyn = 0, yys = yystack->yytops.yystates[0];
1475 yys != yystack->yysplitPoint;
1476 yys = yys->yypred, yyn += 1)
1477 continue;
1478 YYCHK (yyresolveStates (yystack->yytops.yystates[0], yyn, yystack
1479 ]b4_user_args[));
1480 }
1481 return yyok;
1482 }
1483
1484 static void
1485 yycompressStack (yyGLRStack* yystack)
1486 {
1487 yyGLRState* yyp, *yyq, *yyr;
1488
1489 if (yystack->yytops.yysize != 1 || yystack->yysplitPoint == NULL)
1490 return;
1491
1492 for (yyp = yystack->yytops.yystates[0], yyq = yyp->yypred, yyr = NULL;
1493 yyp != yystack->yysplitPoint;
1494 yyr = yyp, yyp = yyq, yyq = yyp->yypred)
1495 yyp->yypred = yyr;
1496
1497 yystack->yyspaceLeft += yystack->yynextFree - yystack->yyitems;
1498 yystack->yynextFree = ((yyGLRStackItem*) yystack->yysplitPoint) + 1;
1499 yystack->yyspaceLeft -= yystack->yynextFree - yystack->yyitems;
1500 yystack->yysplitPoint = NULL;
1501 yystack->yylastDeleted = NULL;
1502
1503 while (yyr != NULL)
1504 {
1505 yystack->yynextFree->yystate = *yyr;
1506 yyr = yyr->yypred;
1507 yystack->yynextFree->yystate.yypred = & yystack->yynextFree[-1].yystate;
1508 yystack->yytops.yystates[0] = &yystack->yynextFree->yystate;
1509 yystack->yynextFree += 1;
1510 yystack->yyspaceLeft -= 1;
1511 }
1512 }
1513
1514 static YYRESULTTAG
1515 yyprocessOneStack (yyGLRStack* yystack, int yyk,
1516 size_t yyposn, YYSTYPE* yylvalp, YYLTYPE* yyllocp
1517 ]b4_user_formals[)
1518 {
1519 int yyaction;
1520 const short* yyconflicts;
1521 yyRuleNum yyrule;
1522 yySymbol* const yytokenp = yystack->yytokenp;
1523
1524 while (yystack->yytops.yystates[yyk] != NULL)
1525 {
1526 yyStateNum yystate = yystack->yytops.yystates[yyk]->yylrState;
1527 YYDPRINTF ((stderr, "Stack %d Entering state %d\n", yyk, yystate));
1528
1529 if (yystate == YYFINAL)
1530 abort ();
1531 if (yyisDefaultedState (yystate))
1532 {
1533 yyrule = yydefaultAction (yystate);
1534 if (yyrule == 0)
1535 {
1536 YYDPRINTF ((stderr, "Stack %d dies.\n", yyk));
1537 yymarkStackDeleted (yystack, yyk);
1538 return yyok;
1539 }
1540 YYCHK (yyglrReduce (yystack, yyk, yyrule, yyfalse]b4_lpure_args[));
1541 }
1542 else
1543 {
1544 if (*yytokenp == YYEMPTY)
1545 {
1546 YYDPRINTF ((stderr, "Reading a token: "));
1547 yychar = YYLEX;
1548 *yytokenp = YYTRANSLATE (yychar);
1549 YYDSYMPRINTF ("Next token is", *yytokenp, yylvalp, yyllocp);
1550 }
1551 yygetLRActions (yystate, *yytokenp, &yyaction, &yyconflicts);
1552
1553 while (*yyconflicts != 0)
1554 {
1555 int yynewStack = yysplitStack (yystack, yyk);
1556 YYDPRINTF ((stderr, "Splitting off stack %d from %d.\n",
1557 yynewStack, yyk));
1558 YYCHK (yyglrReduce (yystack, yynewStack,
1559 *yyconflicts, yyfalse]b4_lpure_args[));
1560 YYCHK (yyprocessOneStack (yystack, yynewStack, yyposn,
1561 yylvalp, yyllocp]b4_user_args[));
1562 yyconflicts += 1;
1563 }
1564
1565 if (yyisShiftAction (yyaction))
1566 {
1567 YYDPRINTF ((stderr, "Shifting token %s on stack %d, ",
1568 yytokenName (*yytokenp), yyk));
1569 yyglrShift (yystack, yyk, yyaction, yyposn+1,
1570 *yylvalp, yyllocp]b4_user_args[);
1571 YYDPRINTF ((stderr, "which is now in state #%d\n",
1572 yystack->yytops.yystates[yyk]->yylrState));
1573 break;
1574 }
1575 else if (yyisErrorAction (yyaction))
1576 {
1577 YYDPRINTF ((stderr, "Stack %d dies.\n", yyk));
1578 yymarkStackDeleted (yystack, yyk);
1579 break;
1580 }
1581 else
1582 YYCHK (yyglrReduce (yystack, yyk, -yyaction, yyfalse]b4_lpure_args[));
1583 }
1584 }
1585 return yyok;
1586 }
1587
1588 static void
1589 yyreportSyntaxError (yyGLRStack* yystack,
1590 YYSTYPE* yylvalp, YYLTYPE* yyllocp]b4_user_formals[)
1591 {
1592 /* `Unused' warnings. */
1593 (void) yylvalp;
1594 (void) yyllocp;
1595
1596 if (yystack->yyerrState == 0)
1597 {
1598 #if YYERROR_VERBOSE
1599 yySymbol* const yytokenp = yystack->yytokenp;
1600 int yyn;
1601 yyn = yypact[yystack->yytops.yystates[0]->yylrState];
1602 if (YYPACT_NINF < yyn && yyn < YYLAST)
1603 {
1604 size_t yysize = 0;
1605 const char* yyprefix;
1606 char* yymsg;
1607 int yyx;
1608
1609 /* Start YYX at -YYN if negative to avoid negative indexes in
1610 YYCHECK. */
1611 int yyxbegin = yyn < 0 ? -yyn : 0;
1612
1613 /* Stay within bounds of both yycheck and yytname. */
1614 int yychecklim = YYLAST - yyn;
1615 int yyxend = yychecklim < YYNTOKENS ? yychecklim : YYNTOKENS;
1616 int yycount = 0;
1617
1618 yyprefix = ", expecting ";
1619 for (yyx = yyxbegin; yyx < yyxend; ++yyx)
1620 if (yycheck[yyx + yyn] == yyx && yyx != YYTERROR)
1621 {
1622 yysize += strlen (yyprefix) + strlen (yytokenName (yyx));
1623 yycount += 1;
1624 if (yycount == 5)
1625 {
1626 yysize = 0;
1627 break;
1628 }
1629 yyprefix = " or ";
1630 }
1631 yysize += (sizeof ("syntax error, unexpected ")
1632 + strlen (yytokenName (*yytokenp)));
1633 yymsg = (char*) malloc (yysize);
1634 if (yymsg != 0)
1635 {
1636 char* yyp = yymsg;
1637 sprintf (yyp, "syntax error, unexpected %s",
1638 yytokenName (*yytokenp));
1639 yyp += strlen (yyp);
1640 if (yycount < 5)
1641 {
1642 yyprefix = ", expecting ";
1643 for (yyx = yyxbegin; yyx < yyxend; ++yyx)
1644 if (yycheck[yyx + yyn] == yyx && yyx != YYTERROR)
1645 {
1646 sprintf (yyp, "%s%s", yyprefix, yytokenName (yyx));
1647 yyp += strlen (yyp);
1648 yyprefix = " or ";
1649 }
1650 }
1651 yyerror (]b4_lyyerror_args[yymsg);
1652 free (yymsg);
1653 }
1654 else
1655 yyerror (]b4_lyyerror_args["syntax error; also virtual memory exhausted");
1656 }
1657 else
1658 #endif /* YYERROR_VERBOSE */
1659 yyerror (]b4_lyyerror_args["syntax error");
1660 yynerrs += 1;
1661 }
1662 }
1663
1664 /* Recover from a syntax error on YYSTACK, assuming that YYTOKENP,
1665 YYLVALP, and YYLLOCP point to the syntactic category, semantic
1666 value, and location of the lookahead. */
1667 static void
1668 yyrecoverSyntaxError (yyGLRStack* yystack,
1669 YYSTYPE* yylvalp, YYLTYPE* yyllocp]b4_user_formals[)
1670 {
1671 yySymbol* const yytokenp = yystack->yytokenp;
1672 size_t yyk;
1673 int yyj;
1674
1675 if (yystack->yyerrState == 0)
1676 yystack->yyerrState = 3;
1677 else if (yystack->yyerrState == 3)
1678 /* We just shifted the error token and (perhaps) took some
1679 reductions. Skip tokens until we can proceed. */
1680 while (yytrue)
1681 {
1682 if (*yytokenp == YYEOF)
1683 {
1684 /* Now pop stack until we find a state that shifts the
1685 error token. */
1686 while (yystack->yytops.yystates[0] != NULL)
1687 {
1688 yyGLRState *yys = yystack->yytops.yystates[0];
1689 YYDSYMPRINTF ("Error: popping",
1690 yystos[yys->yylrState],
1691 &yys->yysemantics.yysval, &yys->yyloc);
1692 yydestruct (yystos[yys->yylrState],
1693 &yys->yysemantics.yysval]b4_location_if([, &yys->yyloc])[);
1694 yystack->yytops.yystates[0] = yys->yypred;
1695 yystack->yynextFree -= 1;
1696 yystack->yyspaceLeft += 1;
1697 }
1698 yyFail (yystack][]b4_lpure_args[, NULL);
1699 }
1700 if (*yytokenp != YYEMPTY)
1701 {
1702 YYDSYMPRINTF ("Error: discarding", *yytokenp, yylvalp, yyllocp);
1703 yydestruct (*yytokenp, yylvalp]b4_location_if([, yyllocp])[);
1704 }
1705 YYDPRINTF ((stderr, "Reading a token: "));
1706 yychar = YYLEX;
1707 *yytokenp = YYTRANSLATE (yychar);
1708 YYDSYMPRINTF ("Next token is", *yytokenp, yylvalp, yyllocp);
1709 yyj = yypact[yystack->yytops.yystates[0]->yylrState];
1710 if (yyis_pact_ninf (yyj))
1711 /* Something's not right; we shouldn't be here. */
1712 yyFail (yystack][]b4_lpure_args[, NULL);
1713 yyj += *yytokenp;
1714 if (yyj < 0 || YYLAST < yyj || yycheck[yyj] != *yytokenp)
1715 {
1716 if (yydefact[yystack->yytops.yystates[0]->yylrState] != 0)
1717 return;
1718 }
1719 else if (yytable[yyj] != 0 && ! yyis_table_ninf (yytable[yyj]))
1720 return;
1721 }
1722
1723 /* Reduce to one stack. */
1724 for (yyk = 0; yyk < yystack->yytops.yysize; yyk += 1)
1725 if (yystack->yytops.yystates[yyk] != NULL)
1726 break;
1727 if (yyk >= yystack->yytops.yysize)
1728 yyFail (yystack][]b4_lpure_args[, NULL);
1729 for (yyk += 1; yyk < yystack->yytops.yysize; yyk += 1)
1730 yymarkStackDeleted (yystack, yyk);
1731 yyremoveDeletes (yystack);
1732 yycompressStack (yystack);
1733
1734 /* Now pop stack until we find a state that shifts the error token. */
1735 while (yystack->yytops.yystates[0] != NULL)
1736 {
1737 yyGLRState *yys = yystack->yytops.yystates[0];
1738 yyj = yypact[yys->yylrState];
1739 if (! yyis_pact_ninf (yyj))
1740 {
1741 yyj += YYTERROR;
1742 if (0 <= yyj && yyj <= YYLAST && yycheck[yyj] == YYTERROR
1743 && yyisShiftAction (yytable[yyj]))
1744 {
1745 YYDPRINTF ((stderr, "Shifting error token, "));
1746 yyglrShift (yystack, 0, yytable[yyj],
1747 yys->yyposn, *yylvalp, yyllocp]b4_user_args[);
1748 break;
1749 }
1750 }
1751 YYDSYMPRINTF ("Error: popping",
1752 yystos[yys->yylrState],
1753 &yys->yysemantics.yysval, &yys->yyloc);
1754 yydestruct (yystos[yys->yylrState],
1755 &yys->yysemantics.yysval]b4_location_if([, &yys->yyloc])[);
1756 yystack->yytops.yystates[0] = yys->yypred;
1757 yystack->yynextFree -= 1;
1758 yystack->yyspaceLeft += 1;
1759 }
1760 if (yystack->yytops.yystates[0] == NULL)
1761 yyFail (yystack][]b4_lpure_args[, NULL);
1762 }
1763
1764 #define YYCHK1(YYE) \
1765 do { \
1766 switch (YYE) { \
1767 default: \
1768 break; \
1769 case yyabort: \
1770 yystack.yyerrflag = 1; \
1771 goto yyDone; \
1772 case yyaccept: \
1773 yystack.yyerrflag = 0; \
1774 goto yyDone; \
1775 case yyerr: \
1776 goto yyuser_error; \
1777 } \
1778 } while (0)
1779
1780
1781 /*----------.
1782 | yyparse. |
1783 `----------*/
1784
1785 ]b4_c_ansi_function_def([yyparse], [int], b4_parse_param)[
1786 {
1787 yySymbol yytoken;
1788 yyGLRStack yystack;
1789 size_t yyposn;
1790 ]b4_pure_if(
1791 [
1792 YYSTYPE yylval;
1793 YYLTYPE yylloc;
1794 #undef yychar
1795 #define yychar (yystack.yyrawchar)
1796 ])[
1797
1798 YYSTYPE* const yylvalp = &yylval;
1799 YYLTYPE* const yyllocp = &yylloc;
1800
1801 yyinitGLRStack (&yystack, YYINITDEPTH);
1802 yystack.yytokenp = &yytoken;
1803
1804 YYDPRINTF ((stderr, "Starting parse\n"));
1805
1806 if (setjmp (yystack.yyexception_buffer) != 0)
1807 goto yyDone;
1808
1809 yyglrShift (&yystack, 0, 0, 0, yyval_default, &yyloc_default]b4_user_args[);
1810 yytoken = YYEMPTY;
1811 yyposn = 0;
1812
1813 while (yytrue)
1814 {
1815 /* For efficiency, we have two loops, the first of which is
1816 specialized to deterministic operation (single stack, no
1817 potential ambiguity). */
1818 /* Standard mode */
1819 while (yytrue)
1820 {
1821 yyRuleNum yyrule;
1822 int yyaction;
1823 const short* yyconflicts;
1824
1825 yyStateNum yystate = yystack.yytops.yystates[0]->yylrState;
1826 YYDPRINTF ((stderr, "Entering state %d\n", yystate));
1827 if (yystate == YYFINAL)
1828 goto yyDone;
1829 if (yyisDefaultedState (yystate))
1830 {
1831 yyrule = yydefaultAction (yystate);
1832 if (yyrule == 0)
1833 {
1834 yyreportSyntaxError (&yystack, yylvalp, yyllocp]b4_user_args[);
1835 goto yyuser_error;
1836 }
1837 YYCHK1 (yyglrReduce (&yystack, 0, yyrule, yytrue]b4_lpure_args[));
1838 }
1839 else
1840 {
1841 if (yytoken == YYEMPTY)
1842 {
1843 YYDPRINTF ((stderr, "Reading a token: "));
1844 yychar = YYLEX;
1845 yytoken = YYTRANSLATE (yychar);
1846 YYDSYMPRINTF ("Next token is", yytoken, yylvalp, yyllocp);
1847 }
1848 yygetLRActions (yystate, yytoken, &yyaction, &yyconflicts);
1849 if (*yyconflicts != 0)
1850 break;
1851 if (yyisShiftAction (yyaction))
1852 {
1853 YYDPRINTF ((stderr, "Shifting token %s, ",
1854 yytokenName (yytoken)));
1855 if (yytoken != YYEOF)
1856 yytoken = YYEMPTY;
1857 yyposn += 1;
1858 yyglrShift (&yystack, 0, yyaction, yyposn,
1859 yylval, yyllocp]b4_user_args[);
1860 if (0 < yystack.yyerrState)
1861 yystack.yyerrState -= 1;
1862 }
1863 else if (yyisErrorAction (yyaction))
1864 {
1865 yyreportSyntaxError (&yystack, yylvalp, yyllocp]b4_user_args[);
1866 goto yyuser_error;
1867 }
1868 else
1869 YYCHK1 (yyglrReduce (&yystack, 0, -yyaction, yytrue]b4_lpure_args[));
1870 }
1871 }
1872
1873 while (yytrue)
1874 {
1875 int yys;
1876 int yyn = yystack.yytops.yysize;
1877 for (yys = 0; yys < yyn; yys += 1)
1878 YYCHK1 (yyprocessOneStack (&yystack, yys, yyposn,
1879 yylvalp, yyllocp]b4_user_args[));
1880 yytoken = YYEMPTY;
1881 yyposn += 1;
1882 yyremoveDeletes (&yystack);
1883 if (yystack.yytops.yysize == 0)
1884 {
1885 yyundeleteLastStack (&yystack);
1886 if (yystack.yytops.yysize == 0)
1887 yyFail (&yystack][]b4_lpure_args[, "syntax error");
1888 YYCHK1 (yyresolveStack (&yystack]b4_user_args[));
1889 YYDPRINTF ((stderr, "Returning to deterministic operation.\n"));
1890 yyreportSyntaxError (&yystack, yylvalp, yyllocp]b4_user_args[);
1891 goto yyuser_error;
1892 }
1893 else if (yystack.yytops.yysize == 1)
1894 {
1895 YYCHK1 (yyresolveStack (&yystack]b4_user_args[));
1896 YYDPRINTF ((stderr, "Returning to deterministic operation.\n"));
1897 yycompressStack (&yystack);
1898 break;
1899 }
1900 }
1901 continue;
1902 yyuser_error:
1903 yyrecoverSyntaxError (&yystack, yylvalp, yyllocp]b4_user_args[);
1904 yyposn = yystack.yytops.yystates[0]->yyposn;
1905 }
1906 yyDone:
1907 ;
1908
1909 yyfreeGLRStack (&yystack);
1910 return yystack.yyerrflag;
1911 }
1912
1913 /* DEBUGGING ONLY */
1914 static void yypstack (yyGLRStack* yystack, int yyk) ATTRIBUTE_UNUSED;
1915 static void yypdumpstack (yyGLRStack* yystack) ATTRIBUTE_UNUSED;
1916
1917 static void
1918 yy_yypstack (yyGLRState* yys)
1919 {
1920 if (yys->yypred)
1921 {
1922 yy_yypstack (yys->yypred);
1923 fprintf (stderr, " -> ");
1924 }
1925 fprintf (stderr, "%d@@%lu", yys->yylrState, (unsigned long) yys->yyposn);
1926 }
1927
1928 static void
1929 yypstates (yyGLRState* yyst)
1930 {
1931 if (yyst == NULL)
1932 fprintf (stderr, "<null>");
1933 else
1934 yy_yypstack (yyst);
1935 fprintf (stderr, "\n");
1936 }
1937
1938 static void
1939 yypstack (yyGLRStack* yystack, int yyk)
1940 {
1941 yypstates (yystack->yytops.yystates[yyk]);
1942 }
1943
1944 #define YYINDEX(YYX) \
1945 ((YYX) == NULL ? -1 : (yyGLRStackItem*) (YYX) - yystack->yyitems)
1946
1947
1948 static void
1949 yypdumpstack (yyGLRStack* yystack)
1950 {
1951 yyGLRStackItem* yyp;
1952 size_t yyi;
1953 for (yyp = yystack->yyitems; yyp < yystack->yynextFree; yyp += 1)
1954 {
1955 fprintf (stderr, "%3lu. ", (unsigned long) (yyp - yystack->yyitems));
1956 if (*(yybool *) yyp)
1957 {
1958 fprintf (stderr, "Res: %d, LR State: %d, posn: %lu, pred: %ld",
1959 yyp->yystate.yyresolved, yyp->yystate.yylrState,
1960 (unsigned long) yyp->yystate.yyposn,
1961 (long) YYINDEX (yyp->yystate.yypred));
1962 if (! yyp->yystate.yyresolved)
1963 fprintf (stderr, ", firstVal: %ld",
1964 (long) YYINDEX (yyp->yystate.yysemantics.yyfirstVal));
1965 }
1966 else
1967 {
1968 fprintf (stderr, "Option. rule: %d, state: %ld, next: %ld",
1969 yyp->yyoption.yyrule,
1970 (long) YYINDEX (yyp->yyoption.yystate),
1971 (long) YYINDEX (yyp->yyoption.yynext));
1972 }
1973 fprintf (stderr, "\n");
1974 }
1975 fprintf (stderr, "Tops:");
1976 for (yyi = 0; yyi < yystack->yytops.yysize; yyi += 1)
1977 fprintf (stderr, "%lu: %ld; ", (unsigned long) yyi,
1978 (long) YYINDEX (yystack->yytops.yystates[yyi]));
1979 fprintf (stderr, "\n");
1980 }
1981 ]
1982
1983 b4_epilogue
1984 m4_if(b4_defines_flag, 0, [],
1985 [@output @output_header_name@
1986 b4_copyright([Skeleton parser for GLR parsing with Bison], [2002, 2003])
1987
1988 b4_token_defines(b4_tokens)
1989
1990 #if ! defined (YYSTYPE) && ! defined (YYSTYPE_IS_DECLARED)
1991 m4_ifdef([b4_stype],
1992 [b4_syncline([b4_stype_line], [b4_filename])
1993 typedef union m4_bregexp(b4_stype, [^{], [YYSTYPE ])b4_stype YYSTYPE;
1994 /* Line __line__ of glr.c. */
1995 b4_syncline([@oline@], [@ofile@])],
1996 [typedef int YYSTYPE;])
1997 # define YYSTYPE_IS_DECLARED 1
1998 # define YYSTYPE_IS_TRIVIAL 1
1999 #endif
2000
2001 b4_pure_if([],
2002 [extern YYSTYPE b4_prefix[]lval;])
2003
2004 b4_location_if(
2005 [#if ! defined (YYLTYPE) && ! defined (YYLTYPE_IS_DECLARED)
2006 typedef struct YYLTYPE
2007 {
2008 int first_line;
2009 int first_column;
2010 int last_line;
2011 int last_column;
2012 } YYLTYPE;
2013 # define YYLTYPE_IS_DECLARED 1
2014 # define YYLTYPE_IS_TRIVIAL 1
2015 #endif
2016
2017 m4_if(b4_pure, [0],
2018 [extern YYLTYPE b4_prefix[]lloc;])
2019 ])
2020 ])