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