]> git.saurik.com Git - bison.git/blob - data/glr.c
* data/c.m4 (b4_yydestruct_generate, b4_symbol_actions): New.
[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 ((YYX <= 0) ? YYEOF : \
272 (unsigned)(YYX) <= YYMAXUTOK ? yytranslate[YYX] : YYUNDEFTOK)
273
274 /* YYTRANSLATE[YYLEX] -- Bison symbol number corresponding to YYLEX. */
275 static const ]b4_int_type_for([b4_translate])[ yytranslate[] =
276 {
277 ]b4_translate[
278 };
279
280 #if YYDEBUG
281 /* YYPRHS[YYN] -- Index of the first RHS symbol of rule number YYN in
282 YYRHS. */
283 static const ]b4_int_type_for([b4_prhs])[ yyprhs[] =
284 {
285 ]b4_prhs[
286 };
287
288 /* YYRHS -- A `-1'-separated list of the rules' RHS. */
289 static const ]b4_int_type_for([b4_rhs])[ yyrhs[] =
290 {
291 ]b4_rhs[
292 };
293
294 /* YYRLINE[YYN] -- source line where rule number YYN was defined. */
295 static const ]b4_int_type_for([b4_rline])[ yyrline[] =
296 {
297 ]b4_rline[
298 };
299 #endif
300
301 #if (YYDEBUG) || YYERROR_VERBOSE
302 /* YYTNME[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM.
303 First, the terminals, then, starting at YYNTOKENS, nonterminals. */
304 static const char *const yytname[] =
305 {
306 ]b4_tname[
307 };
308
309 #define yytname_size ((int) (sizeof (yytname) / sizeof (yytname[0])))
310 #endif
311
312 /* YYR1[YYN] -- Symbol number of symbol that rule YYN derives. */
313 static const ]b4_int_type_for([b4_r1])[ yyr1[] =
314 {
315 ]b4_r1[
316 };
317
318 /* YYR2[YYN] -- Number of symbols composing right hand side of rule YYN. */
319 static const ]b4_int_type_for([b4_r2])[ yyr2[] =
320 {
321 ]b4_r2[
322 };
323
324 /* YYDPREC[RULE-NUM] -- Dynamic precedence of rule #RULE-NUM (0 if none). */
325 static const ]b4_int_type_for([b4_dprec])[ yydprec[] =
326 {
327 ]b4_dprec[
328 };
329
330 /* YYMERGER[RULE-NUM] -- Index of merging function for rule #RULE-NUM. */
331 static const ]b4_int_type_for([b4_merger])[ yymerger[] =
332 {
333 ]b4_merger[
334 };
335
336 /* YYDEFACT[S] -- default rule to reduce with in state S when YYTABLE
337 doesn't specify something else to do. Zero means the default is an
338 error. */
339 static const ]b4_int_type_for([b4_defact])[ yydefact[] =
340 {
341 ]b4_defact[
342 };
343
344 /* YYPDEFGOTO[NTERM-NUM]. */
345 static const ]b4_int_type_for([b4_defgoto])[ yydefgoto[] =
346 {
347 ]b4_defgoto[
348 };
349
350 /* YYPACT[STATE-NUM] -- Index in YYTABLE of the portion describing
351 STATE-NUM. */
352 #define YYPACT_NINF ]b4_pact_ninf[
353 static const ]b4_int_type_for([b4_pact])[ yypact[] =
354 {
355 ]b4_pact[
356 };
357
358 /* YYPGOTO[NTERM-NUM]. */
359 static const ]b4_int_type_for([b4_pgoto])[ yypgoto[] =
360 {
361 ]b4_pgoto[
362 };
363
364 /* YYTABLE[YYPACT[STATE-NUM]]. What to do in state STATE-NUM. If
365 positive, shift that token. If negative, reduce the rule which
366 number is the opposite. If zero, do what YYDEFACT says.
367 If YYTABLE_NINF, parse error. */
368 #define YYTABLE_NINF ]b4_table_ninf[
369 static const ]b4_int_type_for([b4_table])[ yytable[] =
370 {
371 ]b4_table[
372 };
373
374 /* YYCONFLP[YYPACT[STATE-NUM]] -- Pointer into YYCONFL of start of
375 list of conflicting reductions corresponding to action entry for
376 state STATE-NUM in yytable. 0 means no conflicts. The list in
377 yyconfl is terminated by a rule number of 0. */
378 static const ]b4_int_type_for([b4_conflict_list_heads])[ yyconflp[] =
379 {
380 ]b4_conflict_list_heads[
381 };
382
383 /* YYCONFL[I] -- lists of conflicting rule numbers, each terminated by
384 0, pointed into by YYCONFLP. */
385 ]dnl Do not use b4_int_type_for here, since there are places where
386 dnl pointers onto yyconfl are taken, which type is "short *".
387 dnl We probably ought to introduce a type for confl.
388 [static const short yyconfl[] =
389 {
390 ]b4_conflicting_rules[
391 };
392
393 static const ]b4_int_type_for([b4_check])[ yycheck[] =
394 {
395 ]b4_check[
396 };
397
398 \f
399 /* Prevent warning if -Wmissing-prototypes. */
400 ]b4_c_ansi_function_decl([yyparse], [int], b4_parse_param)[
401
402 /* Error token number */
403 #define YYTERROR 1
404
405 /* YYLLOC_DEFAULT -- Compute the default location (before the actions
406 are run). */
407
408 #define YYRHSLOC(yyRhs,YYK) (yyRhs[YYK].yystate.yyloc)
409
410 #ifndef YYLLOC_DEFAULT
411 # define YYLLOC_DEFAULT(yyCurrent, yyRhs, YYN) \
412 yyCurrent.first_line = YYRHSLOC(yyRhs,1).first_line; \
413 yyCurrent.first_column = YYRHSLOC(yyRhs,1).first_column; \
414 yyCurrent.last_line = YYRHSLOC(yyRhs,YYN).last_line; \
415 yyCurrent.last_column = YYRHSLOC(yyRhs,YYN).last_column;
416 #endif
417
418 /* YYLEX -- calling `yylex' with the right arguments. */
419 #define YYLEX ]b4_c_function_call([yylex], [int], b4_lex_param)[
420
421 ]b4_pure_if(
422 [
423 #undef yynerrs
424 #define yynerrs (yystack->yyerrcnt)
425 #undef yychar
426 #define yychar (yystack->yyrawchar)],
427 [YYSTYPE yylval;
428
429 YYLTYPE yylloc;
430
431 int yynerrs;
432 int yychar;])[
433
434 static const int YYEOF = 0;
435 static const int YYEMPTY = -2;
436
437 typedef enum { yyok, yyaccept, yyabort, yyerr } YYRESULTTAG;
438
439 #define YYCHK(YYE) \
440 do { YYRESULTTAG yyflag = YYE; if (yyflag != yyok) return yyflag; } \
441 while (0)
442
443 #if YYDEBUG
444
445 #if ! defined (YYFPRINTF)
446 # define YYFPRINTF fprintf
447 #endif
448
449 # define YYDPRINTF(Args) \
450 do { \
451 if (yydebug) \
452 YYFPRINTF Args; \
453 } while (0)
454 /* Nonzero means print parse trace. It is left uninitialized so that
455 multiple parsers can coexist. */
456 int yydebug;
457 #else /* !YYDEBUG */
458 /* Avoid empty `if' bodies. */
459 # define YYDPRINTF(Args) {}
460 #endif /* !YYDEBUG */
461
462 /* YYINITDEPTH -- initial size of the parser's stacks. */
463 #ifndef YYINITDEPTH
464 # define YYINITDEPTH ]b4_stack_depth_init[
465 #endif
466
467 /* YYMAXDEPTH -- maximum size the stacks can grow to (effective only
468 if the built-in stack extension method is used).
469
470 Do not make this value too large; the results are undefined if
471 SIZE_MAX < YYMAXDEPTH * sizeof (GLRStackItem)
472 evaluated with infinite-precision integer arithmetic. */
473
474 #if YYMAXDEPTH == 0
475 # undef YYMAXDEPTH
476 #endif
477
478 #ifndef YYMAXDEPTH
479 # define YYMAXDEPTH ]b4_stack_depth_max[
480 #endif
481
482 /* Minimum number of free items on the stack allowed after an
483 allocation. This is to allow allocation and initialization
484 to be completed by functions that call expandGLRStack before the
485 stack is expanded, thus insuring that all necessary pointers get
486 properly redirected to new data. */
487 #define YYHEADROOM 2
488
489 #if ! defined (YYSTACKEXPANDABLE) \
490 && (! defined (__cplusplus) || (YYLTYPE_IS_TRIVIAL && YYSTYPE_IS_TRIVIAL))
491 #define YYSTACKEXPANDABLE 1
492 #else
493 #define YYSTACKEXPANDABLE 0
494 #endif
495
496 /** State numbers, as in LALR(1) machine */
497 typedef int yyStateNum;
498
499 /** Rule numbers, as in LALR(1) machine */
500 typedef int yyRuleNum;
501
502 /** Grammar symbol */
503 typedef short yySymbol;
504
505 /** Item references, as in LALR(1) machine */
506 typedef short yyItemNum;
507
508 typedef struct yyGLRState yyGLRState;
509 typedef struct yySemanticOption yySemanticOption;
510 typedef union yyGLRStackItem yyGLRStackItem;
511 typedef struct yyGLRStack yyGLRStack;
512 typedef struct yyGLRStateSet yyGLRStateSet;
513
514 struct yyGLRState {
515 bool yyisState;
516 bool yyresolved;
517 yyStateNum yylrState;
518 yyGLRState* yypred;
519 size_t yyposn;
520 union {
521 yySemanticOption* yyfirstVal;
522 YYSTYPE yysval;
523 } yysemantics;
524 YYLTYPE yyloc;
525 };
526
527 struct yyGLRStateSet {
528 yyGLRState** yystates;
529 size_t yysize, yycapacity;
530 };
531
532 struct yySemanticOption {
533 bool yyisState;
534 yyRuleNum yyrule;
535 yyGLRState* yystate;
536 yySemanticOption* yynext;
537 };
538
539 union yyGLRStackItem {
540 yyGLRState yystate;
541 yySemanticOption yyoption;
542 };
543
544 struct yyGLRStack {
545 int yyerrflag;
546 int yyerrState;
547 ]b4_pure_if(
548 [
549 int yyerrcnt;
550 int yyrawchar;
551 ])[
552 yySymbol* yytokenp;
553 jmp_buf yyexception_buffer;
554 yyGLRStackItem* yyitems;
555 yyGLRStackItem* yynextFree;
556 int yyspaceLeft;
557 yyGLRState* yysplitPoint;
558 yyGLRState* yylastDeleted;
559 yyGLRStateSet yytops;
560 };
561
562 static void yyinitGLRStack (yyGLRStack* yystack, size_t yysize);
563 static void yyexpandGLRStack (yyGLRStack* yystack]b4_pure_formals[);
564 static void yyfreeGLRStack (yyGLRStack* yystack);
565
566 static void
567 yyFail (yyGLRStack* yystack]b4_pure_formals[, const char* yyformat, ...)
568 {
569 if (yyformat != NULL)
570 {
571 char yymsg[256];
572 va_list yyap;
573 va_start (yyap, yyformat);
574 yystack->yyerrflag = 1;
575 vsprintf (yymsg, yyformat, yyap);
576 yyerror (]b4_yyerror_args[yymsg);
577 }
578 longjmp (yystack->yyexception_buffer, 1);
579 }
580
581 #if YYDEBUG || YYERROR_VERBOSE
582 /** A printable representation of TOKEN. Valid until next call to
583 * tokenName. */
584 static inline const char*
585 yytokenName (yySymbol yytoken)
586 {
587 return yytname[yytoken];
588 }
589 #endif
590
591 /** Perform user action for rule number YYN, with RHS length YYRHSLEN,
592 * and top stack item YYVSP. YYLVALP points to place to put semantic
593 * value ($$), and yylocp points to place for location information
594 * (@@$). Returns yyok for normal return, yyaccept for YYACCEPT,
595 * yyerr for YYERROR, yyabort for YYABORT. */
596 static YYRESULTTAG
597 yyuserAction (yyRuleNum yyn, int yyrhslen, yyGLRStackItem* yyvsp,
598 YYSTYPE* yyvalp, YYLTYPE* yylocp, yyGLRStack* yystack
599 ]b4_user_formals[)
600 {
601 /* Avoid `unused' warnings in there are no $n. */
602 (void) yystack;
603
604 if (yyrhslen == 0)
605 {
606 *yyvalp = yyval_default;
607 *yylocp = yyloc_default;
608 }
609 else
610 {
611 *yyvalp = yyvsp[1-yyrhslen].yystate.yysemantics.yysval;
612 *yylocp = yyvsp[1-yyrhslen].yystate.yyloc;
613 }
614 # undef yyval
615 # define yyval (*yyvalp)
616 # undef yyerrok
617 # define yyerrok (yystack->yyerrState = 0)
618 # undef YYACCEPT
619 # define YYACCEPT return yyaccept
620 # undef YYABORT
621 # define YYABORT return yyabort
622 # undef YYERROR
623 # define YYERROR return yyerr
624 # undef YYRECOVERING
625 # define YYRECOVERING (yystack->yyerrState != 0)
626 # undef yyclearin
627 # define yyclearin (yychar = *(yystack->yytokenp) = YYEMPTY)
628 # undef YYBACKUP
629 # define YYBACKUP(Token, Value) \
630 do { \
631 yyerror (]b4_yyerror_args["syntax error: cannot back up"); \
632 YYERROR; \
633 } while (0)
634
635 ]
636 switch (yyn)
637 {
638 b4_actions
639 }
640
641 return yyok;
642 # undef yyval
643 # undef yyerrok
644 # undef YYABORT
645 # undef YYACCEPT
646 # undef YYERROR
647 # undef YYBACKUP
648 # undef yyclearin
649 # undef YYRECOVERING
650 /* Line __line__ of __file__. */
651 b4_syncline([@oline@], [@ofile@])
652 }
653 \f
654
655 static YYSTYPE
656 yyuserMerge (int yyn, YYSTYPE* yy0, YYSTYPE* yy1)
657 {
658 YYSTYPE yyval = *yy0;
659 /* `Use' the arguments. */
660 (void) yy0;
661 (void) yy1;
662
663 switch (yyn)
664 {
665 b4_mergers
666 }
667 return yyval;
668 }
669 [
670 /* Bison grammar-table manipulation. */
671
672 /** Number of symbols composing the right hand side of rule #RULE. */
673 static inline int
674 yyrhsLength (yyRuleNum yyrule)
675 {
676 return yyr2[yyrule];
677 }
678
679 /** Left-hand-side symbol for rule #RULE. */
680 static inline yySymbol
681 yylhsNonterm (yyRuleNum yyrule)
682 {
683 return yyr1[yyrule];
684 }
685
686 #define yyis_pact_ninf(yystate) \
687 ]m4_if(m4_eval(b4_pact_ninf < b4_pact_min), 1,
688 0,
689 ((yystate) == YYPACT_NINF))[
690
691 /** True iff LR state STATE has only a default reduction (regardless
692 * of token). */
693 static inline bool
694 yyisDefaultedState (yyStateNum yystate)
695 {
696 return yyis_pact_ninf (yypact[yystate]);
697 }
698
699 /** The default reduction for STATE, assuming it has one. */
700 static inline yyRuleNum
701 yydefaultAction (yyStateNum yystate)
702 {
703 return yydefact[yystate];
704 }
705
706 #define yyis_table_ninf(yyindex) \
707 ]m4_if(m4_eval(b4_table_ninf < b4_table_min), 1,
708 0,
709 ((yyindex) == YYTABLE_NINF))[
710
711 /** Set *YYACTION to the action to take in YYSTATE on seeing YYTOKEN.
712 * Result R means
713 * R < 0: Reduce on rule -R.
714 * R = 0: Error.
715 * R > 0: Shift to state R.
716 * Set *CONFLICTS to a pointer into yyconfl to 0-terminated list of
717 * conflicting reductions.
718 */
719 static inline void
720 yygetLRActions (yyStateNum yystate, int yytoken,
721 int* yyaction, const short** yyconflicts)
722 {
723 int yyindex = yypact[yystate] + yytoken;
724 if (yyindex < 0 || YYLAST < yyindex || yycheck[yyindex] != yytoken)
725 {
726 *yyaction = -yydefact[yystate];
727 *yyconflicts = yyconfl;
728 }
729 else if (! yyis_table_ninf (yyindex))
730 {
731 *yyaction = yytable[yyindex];
732 *yyconflicts = yyconfl + yyconflp[yyindex];
733 }
734 else
735 {
736 *yyaction = 0;
737 *yyconflicts = yyconfl + yyconflp[yyindex];
738 }
739 }
740
741 static inline yyStateNum
742 yyLRgotoState (yyStateNum yystate, yySymbol yylhs)
743 {
744 int yyr;
745 yyr = yypgoto[yylhs - YYNTOKENS] + yystate;
746 if (0 <= yyr && yyr <= YYLAST && yycheck[yyr] == yystate)
747 return yytable[yyr];
748 else
749 return yydefgoto[yylhs - YYNTOKENS];
750 }
751
752 static inline bool
753 yyisShiftAction (int yyaction)
754 {
755 return 0 < yyaction;
756 }
757
758 static inline bool
759 yyisErrorAction (int yyaction)
760 {
761 return yyaction == 0;
762 }
763
764 /* GLRStates */
765
766 /** True iff the semantic value of the edge leading to STATE is
767 * resolved. */
768 static inline bool
769 yyhasResolvedValue (yyGLRState* yystate)
770 {
771 return yystate->yyresolved;
772 }
773
774 static void
775 yyaddDeferredAction (yyGLRStack* yystack, yyGLRState* yystate,
776 yyGLRState* rhs, yyRuleNum yyrule]b4_pure_formals[)
777 {
778 yySemanticOption* yynewItem;
779 yynewItem = &yystack->yynextFree->yyoption;
780 yystack->yyspaceLeft -= 1;
781 yystack->yynextFree += 1;
782 yynewItem->yyisState = yyfalse;
783 yynewItem->yystate = rhs;
784 yynewItem->yyrule = yyrule;
785 yynewItem->yynext = yystate->yysemantics.yyfirstVal;
786 yystate->yysemantics.yyfirstVal = yynewItem;
787 if (yystack->yyspaceLeft < YYHEADROOM)
788 yyexpandGLRStack (yystack]b4_pure_args[);
789 }
790
791 /* GLRStacks */
792
793 /** Initialize SET to a singleton set containing an empty stack. */
794 static void
795 yyinitStateSet (yyGLRStateSet* yyset)
796 {
797 yyset->yysize = 1;
798 yyset->yycapacity = 16;
799 yyset->yystates = (yyGLRState**) malloc (16 * sizeof (yyset->yystates[0]));
800 yyset->yystates[0] = NULL;
801 }
802
803 static void yyfreeStateSet (yyGLRStateSet* yyset)
804 {
805 free (yyset->yystates);
806 }
807
808 /** Initialize STACK to a single empty stack, with total maximum
809 * capacity for all stacks of SIZE. */
810 static void
811 yyinitGLRStack (yyGLRStack* yystack, size_t yysize)
812 {
813 yystack->yyerrflag = 0;
814 yystack->yyerrState = 0;
815 yynerrs = 0;
816 yystack->yyspaceLeft = yysize;
817 yystack->yynextFree = yystack->yyitems =
818 (yyGLRStackItem*) malloc (yysize * sizeof (yystack->yynextFree[0]));
819 yystack->yysplitPoint = NULL;
820 yystack->yylastDeleted = NULL;
821 yyinitStateSet (&yystack->yytops);
822 }
823
824 #define YYRELOC(YYFROMITEMS,YYTOITEMS,YYX,YYTYPE) \
825 &((YYTOITEMS) - ((YYFROMITEMS) - (yyGLRStackItem*) (YYX)))->YYTYPE
826
827 /** If STACK is expandable, extend it. WARNING: Pointers into the
828 stack from outside should be considered invalid after this call.
829 We always expand when there are 1 or fewer items left AFTER an
830 allocation, so that we can avoid having external pointers exist
831 across an allocation. */
832 static void
833 yyexpandGLRStack (yyGLRStack* yystack]b4_pure_formals[)
834 {
835 #if YYSTACKEXPANDABLE
836 yyGLRStack yynewStack;
837 yyGLRStackItem* yyp0, *yyp1;
838 size_t yysize, yynewSize;
839 size_t yyn;
840 yysize = yystack->yynextFree - yystack->yyitems;
841 if (YYMAXDEPTH <= yysize)
842 yyFail (yystack][]b4_pure_args[,
843 "parsing stack overflow (%d items)", yysize);
844 yynewSize = 2*yysize;
845 if (YYMAXDEPTH < yynewSize)
846 yynewSize = YYMAXDEPTH;
847 yyinitGLRStack (&yynewStack, yynewSize);
848 for (yyp0 = yystack->yyitems, yyp1 = yynewStack.yyitems, yyn = yysize;
849 0 < yyn;
850 yyn -= 1, yyp0 += 1, yyp1 += 1)
851 {
852 *yyp1 = *yyp0;
853 if (*(bool*) yyp0)
854 {
855 yyGLRState* yys0 = &yyp0->yystate;
856 yyGLRState* yys1 = &yyp1->yystate;
857 if (yys0->yypred != NULL)
858 yys1->yypred =
859 YYRELOC (yyp0, yyp1, yys0->yypred, yystate);
860 if (! yys0->yyresolved && yys0->yysemantics.yyfirstVal != NULL)
861 yys1->yysemantics.yyfirstVal =
862 YYRELOC(yyp0, yyp1, yys0->yysemantics.yyfirstVal, yyoption);
863 }
864 else
865 {
866 yySemanticOption* yyv0 = &yyp0->yyoption;
867 yySemanticOption* yyv1 = &yyp1->yyoption;
868 if (yyv0->yystate != NULL)
869 yyv1->yystate = YYRELOC (yyp0, yyp1, yyv0->yystate, yystate);
870 if (yyv0->yynext != NULL)
871 yyv1->yynext = YYRELOC (yyp0, yyp1, yyv0->yynext, yyoption);
872 }
873 }
874 if (yystack->yysplitPoint != NULL)
875 yystack->yysplitPoint = YYRELOC (yystack->yyitems, yynewStack.yyitems,
876 yystack->yysplitPoint, yystate);
877
878 for (yyn = 0; yyn < yystack->yytops.yysize; yyn += 1)
879 if (yystack->yytops.yystates[yyn] != NULL)
880 yystack->yytops.yystates[yyn] =
881 YYRELOC (yystack->yyitems, yynewStack.yyitems,
882 yystack->yytops.yystates[yyn], yystate);
883 free (yystack->yyitems);
884 yystack->yyitems = yynewStack.yyitems;
885 yystack->yynextFree = yynewStack.yynextFree + yysize;
886 yystack->yyspaceLeft = yynewStack.yyspaceLeft - yysize;
887
888 #else
889
890 yyFail (yystack][]b4_lpure_args[,
891 "parsing stack overflow (%d items)", yysize);
892 #endif
893 }
894
895 static void
896 yyfreeGLRStack (yyGLRStack* yystack)
897 {
898 free (yystack->yyitems);
899 yyfreeStateSet (&yystack->yytops);
900 }
901
902 /** Assuming that S is a GLRState somewhere on STACK, update the
903 * splitpoint of STACK, if needed, so that it is at least as deep as
904 * S. */
905 static inline void
906 yyupdateSplit (yyGLRStack* yystack, yyGLRState* yys)
907 {
908 if (yystack->yysplitPoint != NULL && yystack->yysplitPoint > yys)
909 yystack->yysplitPoint = yys;
910 }
911
912 /** Invalidate stack #K in STACK. */
913 static inline void
914 yymarkStackDeleted (yyGLRStack* yystack, int yyk)
915 {
916 if (yystack->yytops.yystates[yyk] != NULL)
917 yystack->yylastDeleted = yystack->yytops.yystates[yyk];
918 yystack->yytops.yystates[yyk] = NULL;
919 }
920
921 /** Undelete the last stack that was marked as deleted. Can only be
922 done once after a deletion, and only when all other stacks have
923 been deleted. */
924 static void
925 yyundeleteLastStack (yyGLRStack* yystack)
926 {
927 if (yystack->yylastDeleted == NULL || yystack->yytops.yysize != 0)
928 return;
929 yystack->yytops.yystates[0] = yystack->yylastDeleted;
930 yystack->yytops.yysize = 1;
931 YYDPRINTF ((stderr, "Restoring last deleted stack as stack #0.\n"));
932 yystack->yylastDeleted = NULL;
933 }
934
935 static inline void
936 yyremoveDeletes (yyGLRStack* yystack)
937 {
938 size_t yyi, yyj;
939 yyi = yyj = 0;
940 while (yyj < yystack->yytops.yysize)
941 {
942 if (yystack->yytops.yystates[yyi] == NULL)
943 {
944 if (yyi == yyj)
945 YYDPRINTF ((stderr, "Removing dead stacks.\n"));
946 yystack->yytops.yysize -= 1;
947 }
948 else
949 {
950 yystack->yytops.yystates[yyj] = yystack->yytops.yystates[yyi];
951 if (yyj != yyi)
952 YYDPRINTF ((stderr, "Rename stack %d -> %d.\n", yyi, yyj));
953 yyj += 1;
954 }
955 yyi += 1;
956 }
957 }
958
959 /** Shift to a new state on stack #K of STACK, corresponding to LR state
960 * LRSTATE, at input position POSN, with (resolved) semantic value SVAL. */
961 static inline void
962 yyglrShift (yyGLRStack* yystack, int yyk, yyStateNum yylrState, size_t yyposn,
963 YYSTYPE yysval, YYLTYPE* yylocp]b4_user_formals[)
964 {
965 yyGLRStackItem* yynewItem;
966
967 yynewItem = yystack->yynextFree;
968 yystack->yynextFree += 1;
969 yystack->yyspaceLeft -= 1;
970 yynewItem->yystate.yyisState = yytrue;
971 yynewItem->yystate.yylrState = yylrState;
972 yynewItem->yystate.yyposn = yyposn;
973 yynewItem->yystate.yyresolved = yytrue;
974 yynewItem->yystate.yypred = yystack->yytops.yystates[yyk];
975 yystack->yytops.yystates[yyk] = &yynewItem->yystate;
976 yynewItem->yystate.yysemantics.yysval = yysval;
977 yynewItem->yystate.yyloc = *yylocp;
978 if (yystack->yyspaceLeft < YYHEADROOM)
979 yyexpandGLRStack (yystack]b4_pure_args[);
980 }
981
982 /** Shift to a new state on stack #K of STACK, to a new state
983 * corresponding to LR state LRSTATE, at input position POSN, with
984 * the (unresolved) semantic value of RHS under the action for RULE. */
985 static inline void
986 yyglrShiftDefer (yyGLRStack* yystack, int yyk, yyStateNum yylrState,
987 size_t yyposn, yyGLRState* rhs, yyRuleNum yyrule]b4_pure_formals[)
988 {
989 yyGLRStackItem* yynewItem;
990
991 yynewItem = yystack->yynextFree;
992 yynewItem->yystate.yyisState = yytrue;
993 yynewItem->yystate.yylrState = yylrState;
994 yynewItem->yystate.yyposn = yyposn;
995 yynewItem->yystate.yyresolved = yyfalse;
996 yynewItem->yystate.yypred = yystack->yytops.yystates[yyk];
997 yynewItem->yystate.yysemantics.yyfirstVal = NULL;
998 yystack->yytops.yystates[yyk] = &yynewItem->yystate;
999 yystack->yynextFree += 1;
1000 yystack->yyspaceLeft -= 1;
1001 yyaddDeferredAction (yystack, &yynewItem->yystate, rhs, yyrule]b4_pure_args[);
1002 }
1003
1004 /** Pop the symbols consumed by reduction #RULE from the top of stack
1005 * #K of STACK, and perform the appropriate semantic action on their
1006 * semantic values. Assumes that all ambiguities in semantic values
1007 * have been previously resolved. Set *VALP to the resulting value,
1008 * and *LOCP to the computed location (if any). Return value is as
1009 * for userAction. */
1010 static inline int
1011 yydoAction (yyGLRStack* yystack, int yyk, yyRuleNum yyrule,
1012 YYSTYPE* yyvalp, YYLTYPE* yylocp]b4_user_formals[)
1013 {
1014 int yynrhs = yyrhsLength (yyrule);
1015
1016 if (yystack->yysplitPoint == NULL)
1017 {
1018 /* Standard special case: single stack. */
1019 yyGLRStackItem* rhs = (yyGLRStackItem*) yystack->yytops.yystates[yyk];
1020 assert (yyk == 0);
1021 yystack->yynextFree -= yynrhs;
1022 yystack->yyspaceLeft += yynrhs;
1023 yystack->yytops.yystates[0] = & yystack->yynextFree[-1].yystate;
1024 if (yynrhs == 0)
1025 {
1026 *yyvalp = yyval_default;
1027 *yylocp = yyloc_default;
1028 }
1029 else
1030 {
1031 *yyvalp = rhs[1-yynrhs].yystate.yysemantics.yysval;
1032 *yylocp = rhs[1-yynrhs].yystate.yyloc;
1033 }
1034 return yyuserAction (yyrule, yynrhs, rhs,
1035 yyvalp, yylocp, yystack]b4_user_args[);
1036 }
1037 else
1038 {
1039 int yyi;
1040 yyGLRState* yys;
1041 yyGLRStackItem yyrhsVals[YYMAXRHS];
1042 for (yyi = yynrhs-1, yys = yystack->yytops.yystates[yyk]; 0 <= yyi;
1043 yyi -= 1, yys = yys->yypred)
1044 {
1045 assert (yys->yypred != NULL);
1046 yyrhsVals[yyi].yystate.yyresolved = yytrue;
1047 yyrhsVals[yyi].yystate.yysemantics.yysval = yys->yysemantics.yysval;
1048 yyrhsVals[yyi].yystate.yyloc = yys->yyloc;
1049 }
1050 yyupdateSplit (yystack, yys);
1051 yystack->yytops.yystates[yyk] = yys;
1052 if (yynrhs == 0)
1053 {
1054 *yyvalp = yyval_default;
1055 *yylocp = yyloc_default;
1056 }
1057 else
1058 {
1059 *yyvalp = yyrhsVals[0].yystate.yysemantics.yysval;
1060 *yylocp = yyrhsVals[0].yystate.yyloc;
1061 }
1062 return yyuserAction (yyrule, yynrhs, yyrhsVals + (yynrhs-1),
1063 yyvalp, yylocp, yystack]b4_user_args[);
1064 }
1065 }
1066
1067 #if !YYDEBUG
1068 # define YY_REDUCE_PRINT(K, Rule)
1069 #else
1070 # define YY_REDUCE_PRINT(K, Rule) \
1071 do { \
1072 if (yydebug) \
1073 yy_reduce_print (K, Rule); \
1074 } while (0)
1075
1076 /*----------------------------------------------------------.
1077 | Report that the RULE is going to be reduced on stack #K. |
1078 `----------------------------------------------------------*/
1079
1080 static inline void
1081 yy_reduce_print (size_t yyk, yyRuleNum yyrule)
1082 {
1083 int yyi;
1084 YYDPRINTF ((stderr, "Reducing stack %d by rule %d (line %d),",
1085 yyk, yyrule - 1, yyrline[yyrule]));
1086 /* Print the symbols being reduced, and their result. */
1087 for (yyi = yyprhs[yyrule]; 0 <= yyrhs[yyi]; yyi++)
1088 YYFPRINTF (stderr, "%s ", yytokenName (yyrhs[yyi]));
1089 YYFPRINTF (stderr, " -> %s\n", yytokenName (yyr1[yyrule]));
1090 }
1091 #endif
1092
1093 /** Pop items off stack #K of STACK according to grammar rule RULE,
1094 * and push back on the resulting nonterminal symbol. Perform the
1095 * semantic action associated with RULE and store its value with the
1096 * newly pushed state, if FORCEEVAL or if STACK is currently
1097 * unambiguous. Otherwise, store the deferred semantic action with
1098 * the new state. If the new state would have an identical input
1099 * position, LR state, and predecessor to an existing state on the stack,
1100 * it is identified with that existing state, eliminating stack #K from
1101 * the STACK. In this case, the (necessarily deferred) semantic value is
1102 * added to the options for the existing state's semantic value.
1103 */
1104 static inline YYRESULTTAG
1105 yyglrReduce (yyGLRStack* yystack, size_t yyk, yyRuleNum yyrule,
1106 bool yyforceEval]b4_pure_formals[)
1107 {
1108 size_t yyposn = yystack->yytops.yystates[yyk]->yyposn;
1109
1110 if (yyforceEval || yystack->yysplitPoint == NULL)
1111 {
1112 YYSTYPE yysval;
1113 YYLTYPE yyloc;
1114
1115 YY_REDUCE_PRINT (yyk, yyrule);
1116 YYCHK (yydoAction (yystack, yyk, yyrule, &yysval, &yyloc]b4_user_args[));
1117 yyglrShift (yystack, yyk,
1118 yyLRgotoState (yystack->yytops.yystates[yyk]->yylrState,
1119 yylhsNonterm (yyrule)),
1120 yyposn, yysval, &yyloc]b4_user_args[);
1121 YYDPRINTF ((stderr, "Stack %d entering state %d\n",
1122 yyk, yystack->yytops.yystates[yyk]->yylrState));
1123 }
1124 else
1125 {
1126 size_t yyi;
1127 int yyn;
1128 yyGLRState* yys, *yys0 = yystack->yytops.yystates[yyk];
1129 yyStateNum yynewLRState;
1130
1131 for (yys = yystack->yytops.yystates[yyk], yyn = yyrhsLength (yyrule);
1132 0 < yyn; yyn -= 1)
1133 {
1134 yys = yys->yypred;
1135 assert (yys != NULL);
1136 }
1137 yyupdateSplit (yystack, yys);
1138 yynewLRState = yyLRgotoState (yys->yylrState, yylhsNonterm (yyrule));
1139 YYDPRINTF ((stderr,
1140 "Reduced stack %d by rule #%d; action deferred. "
1141 "Now in state %d.\n",
1142 yyk, yyrule-1, yynewLRState));
1143 for (yyi = 0; yyi < yystack->yytops.yysize; yyi += 1)
1144 if (yyi != yyk && yystack->yytops.yystates[yyi] != NULL)
1145 {
1146 yyGLRState* yyp, *yysplit = yystack->yysplitPoint;
1147 yyp = yystack->yytops.yystates[yyi];
1148 while (yyp != yys && yyp != yysplit && yyp->yyposn >= yyposn)
1149 {
1150 if (yyp->yylrState == yynewLRState && yyp->yypred == yys)
1151 {
1152 yyaddDeferredAction (yystack, yyp, yys0, yyrule]b4_pure_args[);
1153 yymarkStackDeleted (yystack, yyk);
1154 YYDPRINTF ((stderr, "Merging stack %d into stack %d.\n",
1155 yyk, yyi));
1156 return 0;
1157 }
1158 yyp = yyp->yypred;
1159 }
1160 }
1161 yystack->yytops.yystates[yyk] = yys;
1162 yyglrShiftDefer (yystack, yyk, yynewLRState, yyposn, yys0, yyrule]b4_pure_args[);
1163 }
1164 return 0;
1165 }
1166
1167 static int
1168 yysplitStack (yyGLRStack* yystack, int yyk)
1169 {
1170 if (yystack->yysplitPoint == NULL)
1171 {
1172 assert (yyk == 0);
1173 yystack->yysplitPoint = yystack->yytops.yystates[yyk];
1174 }
1175 if (yystack->yytops.yysize >= yystack->yytops.yycapacity)
1176 {
1177 yystack->yytops.yycapacity *= 2;
1178 yystack->yytops.yystates =
1179 (yyGLRState**) realloc (yystack->yytops.yystates,
1180 yystack->yytops.yycapacity
1181 * sizeof (yyGLRState*));
1182 }
1183 yystack->yytops.yystates[yystack->yytops.yysize]
1184 = yystack->yytops.yystates[yyk];
1185 yystack->yytops.yysize += 1;
1186 return yystack->yytops.yysize-1;
1187 }
1188
1189 /** True iff Y0 and Y1 represent identical options at the top level.
1190 * That is, they represent the same rule applied to RHS symbols
1191 * that produce the same terminal symbols. */
1192 static bool
1193 yyidenticalOptions (yySemanticOption* yyy0, yySemanticOption* yyy1)
1194 {
1195 if (yyy0->yyrule == yyy1->yyrule)
1196 {
1197 yyGLRState *yys0, *yys1;
1198 int yyn;
1199 for (yys0 = yyy0->yystate, yys1 = yyy1->yystate,
1200 yyn = yyrhsLength (yyy0->yyrule);
1201 yyn > 0;
1202 yys0 = yys0->yypred, yys1 = yys1->yypred, yyn -= 1)
1203 if (yys0->yyposn != yys1->yyposn)
1204 return yyfalse;
1205 return yytrue;
1206 }
1207 else
1208 return yyfalse;
1209 }
1210
1211 /** Assuming identicalOptions (Y0,Y1), (destructively) merge the
1212 * alternative semantic values for the RHS-symbols of Y1 into the
1213 * corresponding semantic value sets of the symbols of Y0. */
1214 static void
1215 yymergeOptionSets (yySemanticOption* yyy0, yySemanticOption* yyy1)
1216 {
1217 yyGLRState *yys0, *yys1;
1218 int yyn;
1219 for (yys0 = yyy0->yystate, yys1 = yyy1->yystate,
1220 yyn = yyrhsLength (yyy0->yyrule);
1221 yyn > 0;
1222 yys0 = yys0->yypred, yys1 = yys1->yypred, yyn -= 1)
1223 if (yys0 == yys1)
1224 break;
1225 else if (! yys0->yyresolved && ! yys1->yyresolved)
1226 {
1227 yySemanticOption* yyz;
1228 for (yyz = yys0->yysemantics.yyfirstVal; yyz->yynext != NULL;
1229 yyz = yyz->yynext)
1230 ;
1231 yyz->yynext = yys1->yysemantics.yyfirstVal;
1232 }
1233 }
1234
1235 /** Y0 and Y1 represent two possible actions to take in a given
1236 * parsing state; return 0 if no combination is possible,
1237 * 1 if user-mergeable, 2 if Y0 is preferred, 3 if Y1 is preferred. */
1238 static int
1239 yypreference (yySemanticOption* y0, yySemanticOption* y1)
1240 {
1241 yyRuleNum r0 = y0->yyrule, r1 = y1->yyrule;
1242 int p0 = yydprec[r0], p1 = yydprec[r1];
1243
1244 if (p0 == p1)
1245 {
1246 if (yymerger[r0] == 0 || yymerger[r0] != yymerger[r1])
1247 return 0;
1248 else
1249 return 1;
1250 }
1251 if (p0 == 0 || p1 == 0)
1252 return 0;
1253 if (p0 < p1)
1254 return 3;
1255 if (p1 < p0)
1256 return 2;
1257 return 0;
1258 }
1259
1260 static YYRESULTTAG yyresolveValue (yySemanticOption* yyoptionList,
1261 yyGLRStack* yystack, YYSTYPE* yyvalp,
1262 YYLTYPE* yylocp]b4_user_formals[);
1263
1264 static YYRESULTTAG
1265 yyresolveStates (yyGLRState* yys, int yyn, yyGLRStack* yystack]b4_user_formals[)
1266 {
1267 YYRESULTTAG yyflag;
1268 if (0 < yyn)
1269 {
1270 assert (yys->yypred != NULL);
1271 yyflag = yyresolveStates (yys->yypred, yyn-1, yystack]b4_user_args[);
1272 if (yyflag != yyok)
1273 return yyflag;
1274 if (! yys->yyresolved)
1275 {
1276 yyflag = yyresolveValue (yys->yysemantics.yyfirstVal, yystack,
1277 &yys->yysemantics.yysval, &yys->yyloc
1278 ]b4_user_args[);
1279 if (yyflag != yyok)
1280 return yyflag;
1281 yys->yyresolved = yytrue;
1282 }
1283 }
1284 return yyok;
1285 }
1286
1287 static YYRESULTTAG
1288 yyresolveAction (yySemanticOption* yyopt, yyGLRStack* yystack,
1289 YYSTYPE* yyvalp, YYLTYPE* yylocp]b4_user_formals[)
1290 {
1291 yyGLRStackItem yyrhsVals[YYMAXRHS];
1292 int yynrhs, yyi;
1293 yyGLRState* yys;
1294
1295 yynrhs = yyrhsLength (yyopt->yyrule);
1296 YYCHK (yyresolveStates (yyopt->yystate, yynrhs, yystack]b4_user_args[));
1297 for (yyi = yynrhs-1, yys = yyopt->yystate; 0 <= yyi;
1298 yyi -= 1, yys = yys->yypred)
1299 {
1300 assert (yys->yypred != NULL);
1301 yyrhsVals[yyi].yystate.yyresolved = yytrue;
1302 yyrhsVals[yyi].yystate.yysemantics.yysval = yys->yysemantics.yysval;
1303 yyrhsVals[yyi].yystate.yyloc = yys->yyloc;
1304 }
1305 return yyuserAction (yyopt->yyrule, yynrhs, yyrhsVals + (yynrhs-1),
1306 yyvalp, yylocp, yystack]b4_user_args[);
1307 }
1308
1309 #if YYDEBUG
1310 static void
1311 yyreportTree (yySemanticOption* yyx, int yyindent)
1312 {
1313 int yynrhs = yyrhsLength (yyx->yyrule);
1314 int yyi;
1315 yyGLRState* yys;
1316 yyGLRState* yystates[YYMAXRHS];
1317 yyGLRState yyleftmost_state;
1318
1319 for (yyi = yynrhs, yys = yyx->yystate; 0 < yyi; yyi -= 1, yys = yys->yypred)
1320 yystates[yyi] = yys;
1321 if (yys == NULL)
1322 {
1323 yyleftmost_state.yyposn = 0;
1324 yystates[0] = &yyleftmost_state;
1325 }
1326 else
1327 yystates[0] = yys;
1328
1329 if (yyx->yystate->yyposn < yys->yyposn + 1)
1330 YYFPRINTF (stderr, "%*s%s -> <Rule %d, empty>\n",
1331 yyindent, "", yytokenName (yylhsNonterm (yyx->yyrule)),
1332 yyx->yyrule);
1333 else
1334 YYFPRINTF (stderr, "%*s%s -> <Rule %d, tokens %d .. %d>\n",
1335 yyindent, "", yytokenName (yylhsNonterm (yyx->yyrule)),
1336 yyx->yyrule, yys->yyposn+1, yyx->yystate->yyposn);
1337 for (yyi = 1; yyi <= yynrhs; yyi += 1)
1338 {
1339 if (yystates[yyi]->yyresolved)
1340 {
1341 if (yystates[yyi-1]->yyposn+1 > yystates[yyi]->yyposn)
1342 YYFPRINTF (stderr, "%*s%s <empty>\n", yyindent+2, "",
1343 yytokenName (yyrhs[yyprhs[yyx->yyrule]+yyi-1]));
1344 else
1345 YYFPRINTF (stderr, "%*s%s <tokens %d .. %d>\n", yyindent+2, "",
1346 yytokenName (yyrhs[yyprhs[yyx->yyrule]+yyi-1]),
1347 yystates[yyi-1]->yyposn+1, yystates[yyi]->yyposn);
1348 }
1349 else
1350 yyreportTree (yystates[yyi]->yysemantics.yyfirstVal, yyindent+2);
1351 }
1352 }
1353 #endif
1354
1355 static void
1356 yyreportAmbiguity (yySemanticOption* yyx0, yySemanticOption* yyx1,
1357 yyGLRStack* yystack]b4_pure_formals[)
1358 {
1359 /* `Unused' warnings. */
1360 (void) yyx0;
1361 (void) yyx1;
1362
1363 #if YYDEBUG
1364 YYFPRINTF (stderr, "Ambiguity detected.\n");
1365 YYFPRINTF (stderr, "Option 1,\n");
1366 yyreportTree (yyx0, 2);
1367 YYFPRINTF (stderr, "\nOption 2,\n");
1368 yyreportTree (yyx1, 2);
1369 YYFPRINTF (stderr, "\n");
1370 #endif
1371 yyFail (yystack][]b4_pure_args[, "ambiguity detected");
1372 }
1373
1374
1375 /** Resolve the ambiguity represented by OPTIONLIST, perform the indicated
1376 * actions, and return the result. */
1377 static YYRESULTTAG
1378 yyresolveValue (yySemanticOption* yyoptionList, yyGLRStack* yystack,
1379 YYSTYPE* yyvalp, YYLTYPE* yylocp]b4_user_formals[)
1380 {
1381 yySemanticOption* yybest;
1382 yySemanticOption* yyp;
1383 int yymerge;
1384
1385 yybest = yyoptionList;
1386 yymerge = 0;
1387 for (yyp = yyoptionList->yynext; yyp != NULL; yyp = yyp->yynext)
1388 {
1389 if (yyidenticalOptions (yybest, yyp))
1390 yymergeOptionSets (yybest, yyp);
1391 else
1392 switch (yypreference (yybest, yyp))
1393 {
1394 case 0:
1395 yyreportAmbiguity (yybest, yyp, yystack]b4_pure_args[);
1396 break;
1397 case 1:
1398 yymerge = 1;
1399 break;
1400 case 2:
1401 break;
1402 case 3:
1403 yybest = yyp;
1404 yymerge = 0;
1405 break;
1406 }
1407 }
1408
1409 if (yymerge)
1410 {
1411 int yyprec = yydprec[yybest->yyrule];
1412 YYCHK (yyresolveAction (yybest, yystack, yyvalp, yylocp]b4_user_args[));
1413 for (yyp = yybest->yynext; yyp != NULL; yyp = yyp->yynext)
1414 {
1415 if (yyprec == yydprec[yyp->yyrule])
1416 {
1417 YYSTYPE yyval1;
1418 YYLTYPE yydummy;
1419 YYCHK (yyresolveAction (yyp, yystack, &yyval1, &yydummy]b4_user_args[));
1420 *yyvalp = yyuserMerge (yymerger[yyp->yyrule], yyvalp, &yyval1);
1421 }
1422 }
1423 return yyok;
1424 }
1425 else
1426 return yyresolveAction (yybest, yystack, yyvalp, yylocp]b4_user_args[);
1427 }
1428
1429 static YYRESULTTAG
1430 yyresolveStack (yyGLRStack* yystack]b4_user_formals[)
1431 {
1432 if (yystack->yysplitPoint != NULL)
1433 {
1434 yyGLRState* yys;
1435 int yyn;
1436
1437 for (yyn = 0, yys = yystack->yytops.yystates[0];
1438 yys != yystack->yysplitPoint;
1439 yys = yys->yypred, yyn += 1)
1440 ;
1441 YYCHK (yyresolveStates (yystack->yytops.yystates[0], yyn, yystack
1442 ]b4_user_args[));
1443 }
1444 return yyok;
1445 }
1446
1447 static void
1448 yycompressStack (yyGLRStack* yystack)
1449 {
1450 yyGLRState* yyp, *yyq, *yyr;
1451
1452 if (yystack->yytops.yysize != 1 || yystack->yysplitPoint == NULL)
1453 return;
1454
1455 for (yyp = yystack->yytops.yystates[0], yyq = yyp->yypred, yyr = NULL;
1456 yyp != yystack->yysplitPoint;
1457 yyr = yyp, yyp = yyq, yyq = yyp->yypred)
1458 yyp->yypred = yyr;
1459
1460 yystack->yyspaceLeft += yystack->yynextFree - yystack->yyitems;
1461 yystack->yynextFree = ((yyGLRStackItem*) yystack->yysplitPoint) + 1;
1462 yystack->yyspaceLeft -= yystack->yynextFree - yystack->yyitems;
1463 yystack->yysplitPoint = NULL;
1464 yystack->yylastDeleted = NULL;
1465
1466 while (yyr != NULL)
1467 {
1468 yystack->yynextFree->yystate = *yyr;
1469 yyr = yyr->yypred;
1470 yystack->yynextFree->yystate.yypred = & yystack->yynextFree[-1].yystate;
1471 yystack->yytops.yystates[0] = &yystack->yynextFree->yystate;
1472 yystack->yynextFree += 1;
1473 yystack->yyspaceLeft -= 1;
1474 }
1475 }
1476
1477 static YYRESULTTAG
1478 yyprocessOneStack (yyGLRStack* yystack, int yyk,
1479 size_t yyposn, YYSTYPE* yylvalp, YYLTYPE* yyllocp
1480 ]b4_user_formals[)
1481 {
1482 int yyaction;
1483 const short* yyconflicts;
1484 yyRuleNum yyrule;
1485 yySymbol* const yytokenp = yystack->yytokenp;
1486
1487 while (yystack->yytops.yystates[yyk] != NULL)
1488 {
1489 yyStateNum yystate = yystack->yytops.yystates[yyk]->yylrState;
1490
1491 assert (yystate != YYFINAL);
1492 if (yyisDefaultedState (yystate))
1493 {
1494 yyrule = yydefaultAction (yystate);
1495 if (yyrule == 0)
1496 {
1497 YYDPRINTF ((stderr, "Stack %d dies.\n", yyk));
1498 yymarkStackDeleted (yystack, yyk);
1499 return yyok;
1500 }
1501 YYCHK (yyglrReduce (yystack, yyk, yyrule, yyfalse]b4_lpure_args[));
1502 }
1503 else
1504 {
1505 if (*yytokenp == YYEMPTY)
1506 {
1507 YYDPRINTF ((stderr, "Reading a token: "));
1508 yychar = YYLEX;
1509 *yytokenp = YYTRANSLATE (yychar);
1510 YYDPRINTF ((stderr, "Next token is %s\n",
1511 yytokenName (*yytokenp)));
1512 }
1513 yygetLRActions (yystate, *yytokenp, &yyaction, &yyconflicts);
1514
1515 while (*yyconflicts != 0)
1516 {
1517 int yynewStack = yysplitStack (yystack, yyk);
1518 YYDPRINTF ((stderr, "Splitting off stack %d from %d.\n",
1519 yynewStack, yyk));
1520 YYCHK (yyglrReduce (yystack, yynewStack,
1521 *yyconflicts, yyfalse]b4_lpure_args[));
1522 YYCHK (yyprocessOneStack (yystack, yynewStack, yyposn,
1523 yylvalp, yyllocp]b4_user_args[));
1524 yyconflicts += 1;
1525 }
1526
1527 if (yyisShiftAction (yyaction))
1528 {
1529 YYDPRINTF ((stderr, "Shifting token %s on stack %d, ",
1530 yytokenName (*yytokenp), yyk));
1531 yyglrShift (yystack, yyk, yyaction, yyposn+1,
1532 *yylvalp, yyllocp]b4_user_args[);
1533 YYDPRINTF ((stderr, "which is now in state #%d\n",
1534 yystack->yytops.yystates[yyk]->yylrState));
1535 break;
1536 }
1537 else if (yyisErrorAction (yyaction))
1538 {
1539 YYDPRINTF ((stderr, "Stack %d dies.\n", yyk));
1540 yymarkStackDeleted (yystack, yyk);
1541 break;
1542 }
1543 else
1544 YYCHK (yyglrReduce (yystack, yyk, -yyaction, yyfalse]b4_lpure_args[));
1545 }
1546 }
1547 return yyok;
1548 }
1549
1550 static void
1551 yyreportParseError (yyGLRStack* yystack,
1552 YYSTYPE* yylvalp, YYLTYPE* yyllocp]b4_user_formals[)
1553 {
1554 /* `Unused' warnings. */
1555 (void) yylvalp;
1556 (void) yyllocp;
1557
1558 if (yystack->yyerrState == 0)
1559 {
1560 #if YYERROR_VERBOSE
1561 yySymbol* const yytokenp = yystack->yytokenp;
1562 int yyn, yyx, yycount;
1563 size_t yysize;
1564 const char* yyprefix;
1565 char* yyp;
1566 char* yymsg;
1567 yyn = yypact[yystack->yytops.yystates[0]->yylrState];
1568 if (YYPACT_NINF < yyn && yyn < YYLAST)
1569 {
1570 yycount = 0;
1571 /* Start YYX at -YYN if negative to avoid negative indexes in
1572 YYCHECK. */
1573 yysize = sizeof ("parse error, unexpected ")
1574 + strlen (yytokenName (*yytokenp));
1575 yyprefix = ", expecting ";
1576 for (yyx = yyn < 0 ? -yyn : 0; yyx < yytname_size && yycount <= 5;
1577 yyx += 1)
1578 if (yycheck[yyx + yyn] == yyx && yyx != YYTERROR)
1579 yysize += strlen (yytokenName (yyx)) + strlen (yyprefix),
1580 yycount += 1, yyprefix = " or ";
1581 yymsg = yyp = (char*) malloc (yysize);
1582 sprintf (yyp, "parse error, unexpected %s", 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 ])