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