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