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