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