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