3 # GLR skeleton for Bison
5 # Copyright (C) 2002-2013 Free Software Foundation, Inc.
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 3 of the License, or
10 # (at your option) any later version.
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.
17 # You should have received a copy of the GNU General Public License
18 # along with this program. If not, see <http://www.gnu.org/licenses/>.
21 # If we are loaded by glr.cc, do not override c++.m4 definitions by
23 m4_if(b4_skeleton
, ["glr.c"],
24 [m4_include(b4_pkgdatadir
/[c
.m4
])])
26 ## ---------------- ##
28 ## ---------------- ##
31 m4_define_default([b4_stack_depth_max
], [10000])
32 m4_define_default([b4_stack_depth_init
], [200])
36 ## ------------------------ ##
37 ## Pure/impure interfaces. ##
38 ## ------------------------ ##
40 b4_define_flag_if([pure
])
41 # If glr.cc is including this file and thus has already set b4_pure_flag,
42 # do not change the value of b4_pure_flag, and do not record a use of api.pure.
43 m4_ifndef([b4_pure_flag
],
44 [b4_percent_define_default([[api
.pure
]], [[false]])
45 m4_define([b4_pure_flag
],
46 [b4_percent_define_flag_if([[api
.pure
]], [[1]], [[0]])])])
50 # The possible parse-params formal arguments preceded by a comma.
52 # This is not shared with yacc.c in c.m4 because GLR relies on ISO C
53 # formal argument declarations.
54 m4_define([b4_user_formals
],
55 [m4_ifset([b4_parse_param
], [, b4_formals(b4_parse_param
)])])
60 # Optional effective arguments passed to yyerror: user args plus yylloc, and
62 m4_define([b4_yyerror_args
],
63 [b4_pure_if([b4_locations_if([yylocp
, ])])dnl
64 m4_ifset([b4_parse_param
], [b4_args(b4_parse_param
), ])])
69 # Same as above, but on the lookahead, hence &yylloc instead of yylocp.
70 m4_define([b4_lyyerror_args
],
71 [b4_pure_if([b4_locations_if([&yylloc
, ])])dnl
72 m4_ifset([b4_parse_param
], [b4_args(b4_parse_param
), ])])
77 # Same as b4_yyerror_args, but with a leading comma.
78 m4_define([b4_pure_args
],
79 [b4_pure_if([b4_locations_if([, yylocp
])])[]b4_user_args
])
84 # Same as above, but on the lookahead, hence &yylloc instead of yylocp.
85 m4_define([b4_lpure_args
],
86 [b4_pure_if([b4_locations_if([, &yylloc
])])[]b4_user_args
])
92 # Arguments passed to yyerror: user formals plus yylocp with leading comma.
93 m4_define([b4_pure_formals
],
94 [b4_pure_if([b4_locations_if([, YYLTYPE
*yylocp
])])[]b4_user_formals
])
97 # b4_locuser_formals(LOC = yylocp)
98 # --------------------------------
99 m4_define([b4_locuser_formals
],
100 [b4_locations_if([, YYLTYPE
*m4_default([$
1], [yylocp
])])[]b4_user_formals
])
103 # b4_locuser_args(LOC = yylocp)
104 # -----------------------------
105 m4_define([b4_locuser_args
],
106 [b4_locations_if([, m4_default([$
1], [yylocp
])])[]b4_user_args
])
110 ## ----------------- ##
111 ## Semantic Values. ##
112 ## ----------------- ##
115 # b4_lhs_value([TYPE])
116 # --------------------
117 # Expansion of $<TYPE>$.
118 m4_define([b4_lhs_value
],
119 [b4_symbol_value([(*yyvalp
)], [$
1])])
122 # b4_rhs_data(RULE-LENGTH, NUM)
123 # -----------------------------
124 # Expand to the semantic stack place that contains value and location
125 # of symbol number NUM in a rule of length RULE-LENGTH.
126 m4_define([b4_rhs_data
],
127 [((yyGLRStackItem
const *)yyvsp
)@
{YYFILL (b4_subtract([$
2], [$
1]))@
}.yystate
])
130 # b4_rhs_value(RULE-LENGTH, NUM, [TYPE])
131 # --------------------------------------
132 # Expansion of $<TYPE>NUM, where the current rule has RULE-LENGTH
134 m4_define([b4_rhs_value
],
135 [b4_symbol_value([b4_rhs_data([$
1], [$
2]).yysemantics
.yysval
], [$
3])])
146 m4_define([b4_lhs_location
],
150 # b4_rhs_location(RULE-LENGTH, NUM)
151 # ---------------------------------
152 # Expansion of @NUM, where the current rule has RULE-LENGTH symbols
154 m4_define([b4_rhs_location
],
155 [(b4_rhs_data([$
1], [$
2]).yyloc
)])
162 # b4_shared_declarations
163 # ----------------------
164 # Declaration that might either go into the header (if --defines)
165 # or open coded in the parser body. glr.cc has its own definition.
166 m4_if(b4_skeleton
, ["glr.c"],
167 [m4_define([b4_shared_declarations
],
169 ]b4_percent_code_get([[requires]])[
171 ]b4_declare_yylstype
[
172 ]b4_function_declare(b4_prefix
[parse
], [int], b4_parse_param
)[
173 ]b4_percent_code_get([[provides]])[]dnl
181 b4_output_begin([b4_parser_file_name
])
182 b4_copyright([Skeleton implementation
for Bison GLR parsers in C
],
185 /* C GLR parser skeleton written by Paul Hilfinger. */
189 b4_percent_code_get([[top]])[
190 ]m4_if(b4_api_prefix
, [yy
], [],
191 [[/* Substitute the type names. */
192 #define YYSTYPE ]b4_api_PREFIX[STYPE]b4_locations_if([[
193 #define YYLTYPE ]b4_api_PREFIX[LTYPE]])])[
194 ]m4_if(b4_prefix
, [yy
], [],
195 [[/* Substitute the variable and function names. */
196 #define yyparse ]b4_prefix[parse
197 #define yylex ]b4_prefix[lex
198 #define yyerror ]b4_prefix[error
199 #define yydebug ]b4_prefix[debug
201 #define yylval ]b4_prefix[lval
202 #define yychar ]b4_prefix[char
203 #define yynerrs ]b4_prefix[nerrs]b4_locations_if([[
204 #define yylloc ]b4_prefix[lloc]])]))[
206 /* First part of user declarations. */
207 ]b4_user_pre_prologue
[
211 ]b4_defines_if([[#include "@basename(]b4_spec_defines_file[@)"]],
212 [b4_shared_declarations
])[
214 /* Enabling verbose error messages. */
215 #ifdef YYERROR_VERBOSE
216 # undef YYERROR_VERBOSE
217 # define YYERROR_VERBOSE 1
219 # define YYERROR_VERBOSE ]b4_error_verbose_if([1], [0])[
222 /* Default (constant) value used for initialization for null
223 right-hand sides. Unlike the standard yacc.c template, here we set
224 the default value of $$ to a zeroed-out value. Since the default
225 value is undefined, this behavior is technically correct. */
226 static YYSTYPE yyval_default
;]b4_locations_if([[
227 static YYLTYPE yyloc_default
][]b4_yyloc_default
;])[
229 /* Copy the second part of user declarations. */
230 ]b4_user_post_prologue
231 b4_percent_code_get
[]dnl
238 # if defined YYENABLE_NLS && YYENABLE_NLS
240 # include <libintl.h> /* INFRINGES ON USER NAME SPACE */
241 # define YY_(Msgid) dgettext ("bison-runtime", Msgid)
245 # define YY_(Msgid) Msgid
253 # define YYMALLOC malloc
256 # define YYREALLOC realloc
259 #define YYSIZEMAX ((size_t) -1)
264 typedef unsigned char yybool
;
271 # define YYJMP_BUF jmp_buf
272 # define YYSETJMP(Env) setjmp (Env)
274 # define YYLONGJMP(Env, Val) (longjmp (Env, Val), YYASSERT (0))
277 ]b4_attribute_define
[
280 # define YYASSERT(Condition) ((void) ((Condition) || (abort (), 0)))
283 /* YYFINAL -- State number of the termination state. */
284 #define YYFINAL ]b4_final_state_number[
285 /* YYLAST -- Last index in YYTABLE. */
286 #define YYLAST ]b4_last[
288 /* YYNTOKENS -- Number of terminals. */
289 #define YYNTOKENS ]b4_tokens_number[
290 /* YYNNTS -- Number of nonterminals. */
291 #define YYNNTS ]b4_nterms_number[
292 /* YYNRULES -- Number of rules. */
293 #define YYNRULES ]b4_rules_number[
294 /* YYNRULES -- Number of states. */
295 #define YYNSTATES ]b4_states_number[
296 /* YYMAXRHS -- Maximum number of symbols on right-hand side of rule. */
297 #define YYMAXRHS ]b4_r2_max[
298 /* YYMAXLEFT -- Maximum number of symbols to the left of a handle
299 accessed by $0, $-1, etc., in any rule. */
300 #define YYMAXLEFT ]b4_max_left_semantic_context[
302 /* YYTRANSLATE(X) -- Bison symbol number corresponding to X. */
303 #define YYUNDEFTOK ]b4_undef_token_number[
304 #define YYMAXUTOK ]b4_user_token_number_max[
306 #define YYTRANSLATE(YYX) \
307 ((unsigned int) (YYX) <= YYMAXUTOK ? yytranslate[YYX] : YYUNDEFTOK)
309 /* YYTRANSLATE[YYLEX] -- Bison symbol number corresponding to YYLEX. */
310 static const ]b4_int_type_for([b4_translate
])[ yytranslate
[] =
315 #if ]b4_api_PREFIX[DEBUG
316 /* YYRLINE[YYN] -- source line where rule number YYN was defined. */
317 static const ]b4_int_type_for([b4_rline
])[ yyrline
[] =
323 #if ]b4_api_PREFIX[DEBUG || YYERROR_VERBOSE || ]b4_token_table_flag[
324 /* YYTNAME[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM.
325 First, the terminals, then, starting at YYNTOKENS, nonterminals. */
326 static const char *const yytname
[] =
332 #define YYPACT_NINF ]b4_pact_ninf[
333 #define YYTABLE_NINF ]b4_table_ninf[
335 ]b4_parser_tables_define
[
337 /* YYDPREC[RULE-NUM] -- Dynamic precedence of rule #RULE-NUM (0 if none). */
338 static const ]b4_int_type_for([b4_dprec
])[ yydprec
[] =
343 /* YYMERGER[RULE-NUM] -- Index of merging function for rule #RULE-NUM. */
344 static const ]b4_int_type_for([b4_merger
])[ yymerger
[] =
349 /* YYIMMEDIATE[RULE-NUM] -- True iff rule #RULE-NUM is not to be deferred, as
350 in the case of predicates. */
351 static const yybool yyimmediate
[] =
356 /* YYCONFLP[YYPACT[STATE-NUM]] -- Pointer into YYCONFL of start of
357 list of conflicting reductions corresponding to action entry for
358 state STATE-NUM in yytable. 0 means no conflicts. The list in
359 yyconfl is terminated by a rule number of 0. */
360 static const ]b4_int_type_for([b4_conflict_list_heads
])[ yyconflp
[] =
362 ]b4_conflict_list_heads
[
365 /* YYCONFL[I] -- lists of conflicting rule numbers, each terminated by
366 0, pointed into by YYCONFLP. */
367 ]dnl Do
not use b4_int_type_for here
, since there are places where
368 dnl pointers onto yyconfl are taken
, whose type is
"short int *".
369 dnl We probably ought to introduce a type
for confl
.
370 [static const short int yyconfl
[] =
372 ]b4_conflicting_rules
[
375 /* Error token number */
379 ]b4_yylloc_default_define
[
380 # define YYRHSLOC(Rhs, K) ((Rhs)[K].yystate.yyloc)
386 #define yynerrs (yystackp->yyerrcnt)
388 #define yychar (yystackp->yyrawchar)
390 #define yylval (yystackp->yyval)
392 #define yylloc (yystackp->yyloc)
393 m4_if(b4_prefix
[], [yy
], [],
394 [#define b4_prefix[]nerrs yynerrs
395 #define b4_prefix[]char yychar
396 #define b4_prefix[]lval yylval
397 #define b4_prefix[]lloc yylloc])],
398 [YYSTYPE yylval
;]b4_locations_if([[
404 static const int YYEOF
= 0;
405 static const int YYEMPTY
= -2;
407 typedef enum { yyok
, yyaccept
, yyabort
, yyerr
} YYRESULTTAG
;
411 YYRESULTTAG yychk_flag = YYE; \
412 if (yychk_flag != yyok) \
416 #if ]b4_api_PREFIX[DEBUG
419 # define YYFPRINTF fprintf
422 ]b4_yy_location_print_define
[
424 # define YYDPRINTF(Args) \
430 ]b4_yy_symbol_print_define
[
432 # define YY_SYMBOL_PRINT(Title, Type, Value, Location) \
436 YYFPRINTF (stderr, "%s ", Title); \
437 yy_symbol_print (stderr, Type, Value]b4_locuser_args([Location])[); \
438 YYFPRINTF (stderr, "\n"); \
442 /* Nonzero means print parse trace. It is left uninitialized so that
443 multiple parsers can coexist. */
447 static void yypstack (struct yyGLRStack
* yystackp
, size_t yyk
)
448 __attribute__ ((__unused__
));
449 static void yypdumpstack (struct yyGLRStack
* yystackp
)
450 __attribute__ ((__unused__
));
452 #else /* !]b4_api_PREFIX[DEBUG */
454 # define YYDPRINTF(Args)
455 # define YY_SYMBOL_PRINT(Title, Type, Value, Location)
457 #endif /* !]b4_api_PREFIX[DEBUG */
459 /* YYINITDEPTH -- initial size of the parser's stacks. */
461 # define YYINITDEPTH ]b4_stack_depth_init[
464 /* YYMAXDEPTH -- maximum size the stacks can grow to (effective only
465 if the built-in stack extension method is used).
467 Do not make this value too large; the results are undefined if
468 SIZE_MAX < YYMAXDEPTH * sizeof (GLRStackItem)
469 evaluated with infinite-precision integer arithmetic. */
472 # define YYMAXDEPTH ]b4_stack_depth_max[
475 /* Minimum number of free items on the stack allowed after an
476 allocation. This is to allow allocation and initialization
477 to be completed by functions that call yyexpandGLRStack before the
478 stack is expanded, thus insuring that all necessary pointers get
479 properly redirected to new data. */
482 #ifndef YYSTACKEXPANDABLE
483 # define YYSTACKEXPANDABLE 1
486 #if YYSTACKEXPANDABLE
487 # define YY_RESERVE_GLRSTACK(Yystack) \
489 if (Yystack->yyspaceLeft < YYHEADROOM) \
490 yyexpandGLRStack (Yystack); \
493 # define YY_RESERVE_GLRSTACK(Yystack) \
495 if (Yystack->yyspaceLeft < YYHEADROOM) \
496 yyMemoryExhausted (Yystack); \
504 # if defined __GLIBC__ && defined _STRING_H && defined _GNU_SOURCE
505 # define yystpcpy stpcpy
507 /* Copy YYSRC to YYDEST, returning the address of the terminating '\0' in
510 yystpcpy (char *yydest
, const char *yysrc
)
513 const char *yys
= yysrc
;
515 while ((*yyd
++ = *yys
++) != '\0')
524 /* Copy to YYRES the contents of YYSTR after stripping away unnecessary
525 quotes and backslashes, so that it's suitable for yyerror. The
526 heuristic is that double-quoting is unnecessary unless the string
527 contains an apostrophe, a comma, or backslash (other than
528 backslash-backslash). YYSTR is taken from yytname. If YYRES is
529 null, do not copy; instead, return the length of what the result
532 yytnamerr (char *yyres
, const char *yystr
)
537 char const *yyp
= yystr
;
544 goto do_not_strip_quotes
;
548 goto do_not_strip_quotes
;
561 do_not_strip_quotes
: ;
565 return strlen (yystr
);
567 return yystpcpy (yyres
, yystr
) - yyres
;
571 #endif /* !YYERROR_VERBOSE */
573 /** State numbers, as in LALR(1) machine */
574 typedef int yyStateNum
;
576 /** Rule numbers, as in LALR(1) machine */
577 typedef int yyRuleNum
;
579 /** Grammar symbol */
580 typedef int yySymbol
;
582 /** Item references, as in LALR(1) machine */
583 typedef short int yyItemNum
;
585 typedef struct yyGLRState yyGLRState
;
586 typedef struct yyGLRStateSet yyGLRStateSet
;
587 typedef struct yySemanticOption yySemanticOption
;
588 typedef union yyGLRStackItem yyGLRStackItem
;
589 typedef struct yyGLRStack yyGLRStack
;
592 /** Type tag: always true. */
594 /** Type tag for yysemantics. If true, yysval applies, otherwise
595 * yyfirstVal applies. */
597 /** Number of corresponding LALR(1) machine state. */
598 yyStateNum yylrState
;
599 /** Preceding state in this stack */
601 /** Source position of the last token produced by my symbol */
604 /** First in a chain of alternative reductions producing the
605 * non-terminal corresponding to this state, threaded through
607 yySemanticOption
* yyfirstVal
;
608 /** Semantic value for this state. */
610 } yysemantics
;]b4_locations_if([[
611 /** Source location for this state. */
615 struct yyGLRStateSet
{
616 yyGLRState
** yystates
;
617 /** During nondeterministic operation, yylookaheadNeeds tracks which
618 * stacks have actually needed the current lookahead. During deterministic
619 * operation, yylookaheadNeeds[0] is not maintained since it would merely
620 * duplicate yychar != YYEMPTY. */
621 yybool
* yylookaheadNeeds
;
622 size_t yysize
, yycapacity
;
625 struct yySemanticOption
{
626 /** Type tag: always false. */
628 /** Rule number for this reduction */
630 /** The last RHS state in the list of states to be reduced. */
632 /** The lookahead for this reduction. */
634 YYSTYPE yyval
;]b4_locations_if([[
636 /** Next sibling in chain of options. To facilitate merging,
637 * options are chained in decreasing order by address. */
638 yySemanticOption
* yynext
;
641 /** Type of the items in the GLR stack. The yyisState field
642 * indicates which item of the union is valid. */
643 union yyGLRStackItem
{
645 yySemanticOption yyoption
;
650 ]b4_locations_if([[ /* To compute the location of the error token. */
651 yyGLRStackItem yyerror_range
[3];]])[
656 YYSTYPE yyval
;]b4_locations_if([[
659 YYJMP_BUF yyexception_buffer
;
660 yyGLRStackItem
* yyitems
;
661 yyGLRStackItem
* yynextFree
;
663 yyGLRState
* yysplitPoint
;
664 yyGLRState
* yylastDeleted
;
665 yyGLRStateSet yytops
;
668 #if YYSTACKEXPANDABLE
669 static void yyexpandGLRStack (yyGLRStack
* yystackp
);
672 static void yyFail (yyGLRStack
* yystackp
]b4_pure_formals
[, const char* yymsg
)
673 __attribute__ ((__noreturn__
));
675 yyFail (yyGLRStack
* yystackp
]b4_pure_formals
[, const char* yymsg
)
677 if (yymsg
!= YY_NULL
)
678 yyerror (]b4_yyerror_args
[yymsg
);
679 YYLONGJMP (yystackp
->yyexception_buffer
, 1);
682 static void yyMemoryExhausted (yyGLRStack
* yystackp
)
683 __attribute__ ((__noreturn__
));
685 yyMemoryExhausted (yyGLRStack
* yystackp
)
687 YYLONGJMP (yystackp
->yyexception_buffer
, 2);
690 #if ]b4_api_PREFIX[DEBUG || YYERROR_VERBOSE
691 /** A printable representation of TOKEN. */
692 static inline const char*
693 yytokenName (yySymbol yytoken
)
695 if (yytoken
== YYEMPTY
)
698 return yytname
[yytoken
];
702 /** Fill in YYVSP[YYLOW1 .. YYLOW0-1] from the chain of states starting
703 * at YYVSP[YYLOW0].yystate.yypred. Leaves YYVSP[YYLOW1].yystate.yypred
704 * containing the pointer to the next state in the chain. */
705 static void yyfillin (yyGLRStackItem
*, int, int) __attribute__ ((__unused__
));
707 yyfillin (yyGLRStackItem
*yyvsp
, int yylow0
, int yylow1
)
710 yyGLRState
*s
= yyvsp
[yylow0
].yystate
.yypred
;
711 for (i
= yylow0
-1; i
>= yylow1
; i
-= 1)
713 #if ]b4_api_PREFIX[DEBUG
714 yyvsp
[i
].yystate
.yylrState
= s
->yylrState
;
716 yyvsp
[i
].yystate
.yyresolved
= s
->yyresolved
;
718 yyvsp
[i
].yystate
.yysemantics
.yysval
= s
->yysemantics
.yysval
;
720 /* The effect of using yysval or yyloc (in an immediate rule) is
722 yyvsp
[i
].yystate
.yysemantics
.yyfirstVal
= YY_NULL
;]b4_locations_if([[
723 yyvsp
[i
].yystate
.yyloc
= s
->yyloc
;]])[
724 s
= yyvsp
[i
].yystate
.yypred
= s
->yypred
;
728 /* Do nothing if YYNORMAL or if *YYLOW <= YYLOW1. Otherwise, fill in
729 * YYVSP[YYLOW1 .. *YYLOW-1] as in yyfillin and set *YYLOW = YYLOW1.
730 * For convenience, always return YYLOW1. */
731 static inline int yyfill (yyGLRStackItem
*, int *, int, yybool
)
732 __attribute__ ((__unused__
));
734 yyfill (yyGLRStackItem
*yyvsp
, int *yylow
, int yylow1
, yybool yynormal
)
736 if (!yynormal
&& yylow1
< *yylow
)
738 yyfillin (yyvsp
, *yylow
, yylow1
);
744 /** Perform user action for rule number YYN, with RHS length YYRHSLEN,
745 * and top stack item YYVSP. YYLVALP points to place to put semantic
746 * value ($$), and yylocp points to place for location information
747 * (@@$). Returns yyok for normal return, yyaccept for YYACCEPT,
748 * yyerr for YYERROR, yyabort for YYABORT. */
750 yyuserAction (yyRuleNum yyn
, size_t yyrhslen
, yyGLRStackItem
* yyvsp
,
751 yyGLRStack
* yystackp
,
752 YYSTYPE
* yyvalp
]b4_locuser_formals
[)
754 yybool yynormal
__attribute__ ((__unused__
)) =
755 (yystackp
->yysplitPoint
== YY_NULL
);
757 ]b4_parse_param_use([yyvalp
], [yylocp
])dnl
760 # define yyerrok (yystackp->yyerrState = 0)
762 # define YYACCEPT return yyaccept
764 # define YYABORT return yyabort
766 # define YYERROR return yyerrok, yyerr
768 # define YYRECOVERING() (yystackp->yyerrState != 0)
770 # define yyclearin (yychar = YYEMPTY)
772 # define YYFILL(N) yyfill (yyvsp, &yylow, N, yynormal)
774 # define YYBACKUP(Token, Value) \
775 return yyerror (]b4_yyerror_args[YY_("syntax error: cannot back up")), \
780 *yyvalp
= yyval_default
;
782 *yyvalp
= yyvsp
[YYFILL (1-yyrhslen
)].yystate
.yysemantics
.yysval
;]b4_locations_if([[
783 YYLLOC_DEFAULT ((*yylocp
), (yyvsp
- yyrhslen
), yyrhslen
);
784 yystackp
->yyerror_range
[1].yystate
.yyloc
= *yylocp
;
804 yyuserMerge (int yyn
, YYSTYPE
* yy0
, YYSTYPE
* yy1
)
816 /* Bison grammar-table manipulation. */
818 ]b4_yydestruct_define
[
820 /** Number of symbols composing the right hand side of rule #RULE. */
822 yyrhsLength (yyRuleNum yyrule
)
828 yydestroyGLRState (char const *yymsg
, yyGLRState
*yys
]b4_user_formals
[)
831 yydestruct (yymsg
, yystos
[yys
->yylrState
],
832 &yys
->yysemantics
.yysval
]b4_locuser_args([&yys
->yyloc
])[);
835 #if ]b4_api_PREFIX[DEBUG
838 if (yys
->yysemantics
.yyfirstVal
)
839 YYFPRINTF (stderr
, "%s unresolved", yymsg
);
841 YYFPRINTF (stderr
, "%s incomplete", yymsg
);
842 YY_SYMBOL_PRINT ("", yystos
[yys
->yylrState
], YY_NULL
, &yys
->yyloc
);
846 if (yys
->yysemantics
.yyfirstVal
)
848 yySemanticOption
*yyoption
= yys
->yysemantics
.yyfirstVal
;
851 for (yyrh
= yyoption
->yystate
, yyn
= yyrhsLength (yyoption
->yyrule
);
853 yyrh
= yyrh
->yypred
, yyn
-= 1)
854 yydestroyGLRState (yymsg
, yyrh
]b4_user_args
[);
859 /** Left-hand-side symbol for rule #YYRULE. */
860 static inline yySymbol
861 yylhsNonterm (yyRuleNum yyrule
)
866 #define yypact_value_is_default(Yystate) \
867 ]b4_table_value_equals([[pact]], [[Yystate]], [b4_pact_ninf])[
869 /** True iff LR state YYSTATE has only a default reduction (regardless
872 yyisDefaultedState (yyStateNum yystate
)
874 return yypact_value_is_default (yypact
[yystate
]);
877 /** The default reduction for YYSTATE, assuming it has one. */
878 static inline yyRuleNum
879 yydefaultAction (yyStateNum yystate
)
881 return yydefact
[yystate
];
884 #define yytable_value_is_error(Yytable_value) \
885 ]b4_table_value_equals([[table]], [[Yytable_value]], [b4_table_ninf])[
887 /** Set *YYACTION to the action to take in YYSTATE on seeing YYTOKEN.
889 * R < 0: Reduce on rule -R.
891 * R > 0: Shift to state R.
892 * Set *YYCONFLICTS to a pointer into yyconfl to a 0-terminated list
893 * of conflicting reductions.
896 yygetLRActions (yyStateNum yystate
, int yytoken
,
897 int* yyaction
, const short int** yyconflicts
)
899 int yyindex
= yypact
[yystate
] + yytoken
;
900 if (yypact_value_is_default (yypact
[yystate
])
901 || yyindex
< 0 || YYLAST
< yyindex
|| yycheck
[yyindex
] != yytoken
)
903 *yyaction
= -yydefact
[yystate
];
904 *yyconflicts
= yyconfl
;
906 else if (! yytable_value_is_error (yytable
[yyindex
]))
908 *yyaction
= yytable
[yyindex
];
909 *yyconflicts
= yyconfl
+ yyconflp
[yyindex
];
914 *yyconflicts
= yyconfl
+ yyconflp
[yyindex
];
918 static inline yyStateNum
919 yyLRgotoState (yyStateNum yystate
, yySymbol yylhs
)
921 int yyr
= yypgoto
[yylhs
- YYNTOKENS
] + yystate
;
922 if (0 <= yyr
&& yyr
<= YYLAST
&& yycheck
[yyr
] == yystate
)
925 return yydefgoto
[yylhs
- YYNTOKENS
];
929 yyisShiftAction (int yyaction
)
935 yyisErrorAction (int yyaction
)
937 return yyaction
== 0;
942 /** Return a fresh GLRStackItem in YYSTACKP. The item is an LR state
943 * if YYISSTATE, and otherwise a semantic option. Callers should call
944 * YY_RESERVE_GLRSTACK afterwards to make sure there is sufficient
947 static inline yyGLRStackItem
*
948 yynewGLRStackItem (yyGLRStack
* yystackp
, yybool yyisState
)
950 yyGLRStackItem
* yynewItem
= yystackp
->yynextFree
;
951 yystackp
->yyspaceLeft
-= 1;
952 yystackp
->yynextFree
+= 1;
953 yynewItem
->yystate
.yyisState
= yyisState
;
957 /** Add a new semantic action that will execute the action for rule
958 * YYRULE on the semantic values in YYRHS to the list of
959 * alternative actions for YYSTATE. Assumes that YYRHS comes from
960 * stack #YYK of *YYSTACKP. */
962 yyaddDeferredAction (yyGLRStack
* yystackp
, size_t yyk
, yyGLRState
* yystate
,
963 yyGLRState
* yyrhs
, yyRuleNum yyrule
)
965 yySemanticOption
* yynewOption
=
966 &yynewGLRStackItem (yystackp
, yyfalse
)->yyoption
;
967 YYASSERT (!yynewOption
->yyisState
);
968 yynewOption
->yystate
= yyrhs
;
969 yynewOption
->yyrule
= yyrule
;
970 if (yystackp
->yytops
.yylookaheadNeeds
[yyk
])
972 yynewOption
->yyrawchar
= yychar
;
973 yynewOption
->yyval
= yylval
;]b4_locations_if([
974 yynewOption
->yyloc
= yylloc
;])[
977 yynewOption
->yyrawchar
= YYEMPTY
;
978 yynewOption
->yynext
= yystate
->yysemantics
.yyfirstVal
;
979 yystate
->yysemantics
.yyfirstVal
= yynewOption
;
981 YY_RESERVE_GLRSTACK (yystackp
);
986 /** Initialize YYSET to a singleton set containing an empty stack. */
988 yyinitStateSet (yyGLRStateSet
* yyset
)
991 yyset
->yycapacity
= 16;
992 yyset
->yystates
= (yyGLRState
**) YYMALLOC (16 * sizeof yyset
->yystates
[0]);
993 if (! yyset
->yystates
)
995 yyset
->yystates
[0] = YY_NULL
;
996 yyset
->yylookaheadNeeds
=
997 (yybool
*) YYMALLOC (16 * sizeof yyset
->yylookaheadNeeds
[0]);
998 if (! yyset
->yylookaheadNeeds
)
1000 YYFREE (yyset
->yystates
);
1006 static void yyfreeStateSet (yyGLRStateSet
* yyset
)
1008 YYFREE (yyset
->yystates
);
1009 YYFREE (yyset
->yylookaheadNeeds
);
1012 /** Initialize *YYSTACKP to a single empty stack, with total maximum
1013 * capacity for all stacks of YYSIZE. */
1015 yyinitGLRStack (yyGLRStack
* yystackp
, size_t yysize
)
1017 yystackp
->yyerrState
= 0;
1019 yystackp
->yyspaceLeft
= yysize
;
1021 (yyGLRStackItem
*) YYMALLOC (yysize
* sizeof yystackp
->yynextFree
[0]);
1022 if (!yystackp
->yyitems
)
1024 yystackp
->yynextFree
= yystackp
->yyitems
;
1025 yystackp
->yysplitPoint
= YY_NULL
;
1026 yystackp
->yylastDeleted
= YY_NULL
;
1027 return yyinitStateSet (&yystackp
->yytops
);
1031 #if YYSTACKEXPANDABLE
1032 # define YYRELOC(YYFROMITEMS,YYTOITEMS,YYX,YYTYPE) \
1033 &((YYTOITEMS) - ((YYFROMITEMS) - (yyGLRStackItem*) (YYX)))->YYTYPE
1035 /** If *YYSTACKP is expandable, extend it. WARNING: Pointers into the
1036 stack from outside should be considered invalid after this call.
1037 We always expand when there are 1 or fewer items left AFTER an
1038 allocation, so that we can avoid having external pointers exist
1039 across an allocation. */
1041 yyexpandGLRStack (yyGLRStack
* yystackp
)
1043 yyGLRStackItem
* yynewItems
;
1044 yyGLRStackItem
* yyp0
, *yyp1
;
1047 size_t yysize
= yystackp
->yynextFree
- yystackp
->yyitems
;
1048 if (YYMAXDEPTH
- YYHEADROOM
< yysize
)
1049 yyMemoryExhausted (yystackp
);
1050 yynewSize
= 2*yysize
;
1051 if (YYMAXDEPTH
< yynewSize
)
1052 yynewSize
= YYMAXDEPTH
;
1053 yynewItems
= (yyGLRStackItem
*) YYMALLOC (yynewSize
* sizeof yynewItems
[0]);
1055 yyMemoryExhausted (yystackp
);
1056 for (yyp0
= yystackp
->yyitems
, yyp1
= yynewItems
, yyn
= yysize
;
1058 yyn
-= 1, yyp0
+= 1, yyp1
+= 1)
1061 if (*(yybool
*) yyp0
)
1063 yyGLRState
* yys0
= &yyp0
->yystate
;
1064 yyGLRState
* yys1
= &yyp1
->yystate
;
1065 if (yys0
->yypred
!= YY_NULL
)
1067 YYRELOC (yyp0
, yyp1
, yys0
->yypred
, yystate
);
1068 if (! yys0
->yyresolved
&& yys0
->yysemantics
.yyfirstVal
!= YY_NULL
)
1069 yys1
->yysemantics
.yyfirstVal
=
1070 YYRELOC (yyp0
, yyp1
, yys0
->yysemantics
.yyfirstVal
, yyoption
);
1074 yySemanticOption
* yyv0
= &yyp0
->yyoption
;
1075 yySemanticOption
* yyv1
= &yyp1
->yyoption
;
1076 if (yyv0
->yystate
!= YY_NULL
)
1077 yyv1
->yystate
= YYRELOC (yyp0
, yyp1
, yyv0
->yystate
, yystate
);
1078 if (yyv0
->yynext
!= YY_NULL
)
1079 yyv1
->yynext
= YYRELOC (yyp0
, yyp1
, yyv0
->yynext
, yyoption
);
1082 if (yystackp
->yysplitPoint
!= YY_NULL
)
1083 yystackp
->yysplitPoint
= YYRELOC (yystackp
->yyitems
, yynewItems
,
1084 yystackp
->yysplitPoint
, yystate
);
1086 for (yyn
= 0; yyn
< yystackp
->yytops
.yysize
; yyn
+= 1)
1087 if (yystackp
->yytops
.yystates
[yyn
] != YY_NULL
)
1088 yystackp
->yytops
.yystates
[yyn
] =
1089 YYRELOC (yystackp
->yyitems
, yynewItems
,
1090 yystackp
->yytops
.yystates
[yyn
], yystate
);
1091 YYFREE (yystackp
->yyitems
);
1092 yystackp
->yyitems
= yynewItems
;
1093 yystackp
->yynextFree
= yynewItems
+ yysize
;
1094 yystackp
->yyspaceLeft
= yynewSize
- yysize
;
1099 yyfreeGLRStack (yyGLRStack
* yystackp
)
1101 YYFREE (yystackp
->yyitems
);
1102 yyfreeStateSet (&yystackp
->yytops
);
1105 /** Assuming that YYS is a GLRState somewhere on *YYSTACKP, update the
1106 * splitpoint of *YYSTACKP, if needed, so that it is at least as deep as
1109 yyupdateSplit (yyGLRStack
* yystackp
, yyGLRState
* yys
)
1111 if (yystackp
->yysplitPoint
!= YY_NULL
&& yystackp
->yysplitPoint
> yys
)
1112 yystackp
->yysplitPoint
= yys
;
1115 /** Invalidate stack #YYK in *YYSTACKP. */
1117 yymarkStackDeleted (yyGLRStack
* yystackp
, size_t yyk
)
1119 if (yystackp
->yytops
.yystates
[yyk
] != YY_NULL
)
1120 yystackp
->yylastDeleted
= yystackp
->yytops
.yystates
[yyk
];
1121 yystackp
->yytops
.yystates
[yyk
] = YY_NULL
;
1124 /** Undelete the last stack in *YYSTACKP that was marked as deleted. Can
1125 only be done once after a deletion, and only when all other stacks have
1128 yyundeleteLastStack (yyGLRStack
* yystackp
)
1130 if (yystackp
->yylastDeleted
== YY_NULL
|| yystackp
->yytops
.yysize
!= 0)
1132 yystackp
->yytops
.yystates
[0] = yystackp
->yylastDeleted
;
1133 yystackp
->yytops
.yysize
= 1;
1134 YYDPRINTF ((stderr
, "Restoring last deleted stack as stack #0.\n"));
1135 yystackp
->yylastDeleted
= YY_NULL
;
1139 yyremoveDeletes (yyGLRStack
* yystackp
)
1143 while (yyj
< yystackp
->yytops
.yysize
)
1145 if (yystackp
->yytops
.yystates
[yyi
] == YY_NULL
)
1149 YYDPRINTF ((stderr
, "Removing dead stacks.\n"));
1151 yystackp
->yytops
.yysize
-= 1;
1155 yystackp
->yytops
.yystates
[yyj
] = yystackp
->yytops
.yystates
[yyi
];
1156 /* In the current implementation, it's unnecessary to copy
1157 yystackp->yytops.yylookaheadNeeds[yyi] since, after
1158 yyremoveDeletes returns, the parser immediately either enters
1159 deterministic operation or shifts a token. However, it doesn't
1160 hurt, and the code might evolve to need it. */
1161 yystackp
->yytops
.yylookaheadNeeds
[yyj
] =
1162 yystackp
->yytops
.yylookaheadNeeds
[yyi
];
1165 YYDPRINTF ((stderr
, "Rename stack %lu -> %lu.\n",
1166 (unsigned long int) yyi
, (unsigned long int) yyj
));
1174 /** Shift to a new state on stack #YYK of *YYSTACKP, corresponding to LR
1175 * state YYLRSTATE, at input position YYPOSN, with (resolved) semantic
1176 * value *YYVALP and source location *YYLOCP. */
1178 yyglrShift (yyGLRStack
* yystackp
, size_t yyk
, yyStateNum yylrState
,
1180 YYSTYPE
* yyvalp
]b4_locations_if([, YYLTYPE
* yylocp
])[)
1182 yyGLRState
* yynewState
= &yynewGLRStackItem (yystackp
, yytrue
)->yystate
;
1184 yynewState
->yylrState
= yylrState
;
1185 yynewState
->yyposn
= yyposn
;
1186 yynewState
->yyresolved
= yytrue
;
1187 yynewState
->yypred
= yystackp
->yytops
.yystates
[yyk
];
1188 yynewState
->yysemantics
.yysval
= *yyvalp
;]b4_locations_if([
1189 yynewState
->yyloc
= *yylocp
;])[
1190 yystackp
->yytops
.yystates
[yyk
] = yynewState
;
1192 YY_RESERVE_GLRSTACK (yystackp
);
1195 /** Shift stack #YYK of *YYSTACKP, to a new state corresponding to LR
1196 * state YYLRSTATE, at input position YYPOSN, with the (unresolved)
1197 * semantic value of YYRHS under the action for YYRULE. */
1199 yyglrShiftDefer (yyGLRStack
* yystackp
, size_t yyk
, yyStateNum yylrState
,
1200 size_t yyposn
, yyGLRState
* yyrhs
, yyRuleNum yyrule
)
1202 yyGLRState
* yynewState
= &yynewGLRStackItem (yystackp
, yytrue
)->yystate
;
1203 YYASSERT (yynewState
->yyisState
);
1205 yynewState
->yylrState
= yylrState
;
1206 yynewState
->yyposn
= yyposn
;
1207 yynewState
->yyresolved
= yyfalse
;
1208 yynewState
->yypred
= yystackp
->yytops
.yystates
[yyk
];
1209 yynewState
->yysemantics
.yyfirstVal
= YY_NULL
;
1210 yystackp
->yytops
.yystates
[yyk
] = yynewState
;
1212 /* Invokes YY_RESERVE_GLRSTACK. */
1213 yyaddDeferredAction (yystackp
, yyk
, yynewState
, yyrhs
, yyrule
);
1216 #if !]b4_api_PREFIX[DEBUG
1217 # define YY_REDUCE_PRINT(Args)
1219 # define YY_REDUCE_PRINT(Args) \
1222 yy_reduce_print Args; \
1225 /*----------------------------------------------------------------------.
1226 | Report that stack #YYK of *YYSTACKP is going to be reduced by YYRULE. |
1227 `----------------------------------------------------------------------*/
1230 yy_reduce_print (int yynormal
, yyGLRStackItem
* yyvsp
, size_t yyk
,
1231 yyRuleNum yyrule
]b4_user_formals
[)
1233 int yynrhs
= yyrhsLength (yyrule
);]b4_locations_if([
1236 YYFPRINTF (stderr
, "Reducing stack %lu by rule %d (line %lu):\n",
1237 (unsigned long int) yyk
, yyrule
- 1,
1238 (unsigned long int) yyrline
[yyrule
]);
1240 yyfillin (yyvsp
, 1, -yynrhs
);
1241 /* The symbols being reduced. */
1242 for (yyi
= 0; yyi
< yynrhs
; yyi
++)
1244 YYFPRINTF (stderr
, " $%d = ", yyi
+ 1);
1245 yy_symbol_print (stderr
,
1246 yystos
[yyvsp
[yyi
- yynrhs
+ 1].yystate
.yylrState
],
1247 &yyvsp
[yyi
- yynrhs
+ 1].yystate
.yysemantics
.yysval
1248 ]b4_locations_if([, &]b4_rhs_location(yynrhs
, yyi
+ 1))[]dnl
1250 if (!yyvsp
[yyi
- yynrhs
+ 1].yystate
.yyresolved
)
1251 YYFPRINTF (stderr
, " (unresolved)");
1252 YYFPRINTF (stderr
, "\n");
1257 /** Pop the symbols consumed by reduction #YYRULE from the top of stack
1258 * #YYK of *YYSTACKP, and perform the appropriate semantic action on their
1259 * semantic values. Assumes that all ambiguities in semantic values
1260 * have been previously resolved. Set *YYVALP to the resulting value,
1261 * and *YYLOCP to the computed location (if any). Return value is as
1262 * for userAction. */
1263 static inline YYRESULTTAG
1264 yydoAction (yyGLRStack
* yystackp
, size_t yyk
, yyRuleNum yyrule
,
1265 YYSTYPE
* yyvalp
]b4_locuser_formals
[)
1267 int yynrhs
= yyrhsLength (yyrule
);
1269 if (yystackp
->yysplitPoint
== YY_NULL
)
1271 /* Standard special case: single stack. */
1272 yyGLRStackItem
* yyrhs
= (yyGLRStackItem
*) yystackp
->yytops
.yystates
[yyk
];
1273 YYASSERT (yyk
== 0);
1274 yystackp
->yynextFree
-= yynrhs
;
1275 yystackp
->yyspaceLeft
+= yynrhs
;
1276 yystackp
->yytops
.yystates
[0] = & yystackp
->yynextFree
[-1].yystate
;
1277 YY_REDUCE_PRINT ((1, yyrhs
, yyk
, yyrule
]b4_user_args
[));
1278 return yyuserAction (yyrule
, yynrhs
, yyrhs
, yystackp
,
1279 yyvalp
]b4_locuser_args
[);
1285 yyGLRStackItem yyrhsVals
[YYMAXRHS
+ YYMAXLEFT
+ 1];
1286 yys
= yyrhsVals
[YYMAXRHS
+ YYMAXLEFT
].yystate
.yypred
1287 = yystackp
->yytops
.yystates
[yyk
];]b4_locations_if([[
1289 /* Set default location. */
1290 yyrhsVals
[YYMAXRHS
+ YYMAXLEFT
- 1].yystate
.yyloc
= yys
->yyloc
;]])[
1291 for (yyi
= 0; yyi
< yynrhs
; yyi
+= 1)
1296 yyupdateSplit (yystackp
, yys
);
1297 yystackp
->yytops
.yystates
[yyk
] = yys
;
1298 YY_REDUCE_PRINT ((0, yyrhsVals
+ YYMAXRHS
+ YYMAXLEFT
- 1, yyk
, yyrule
]b4_user_args
[));
1299 return yyuserAction (yyrule
, yynrhs
, yyrhsVals
+ YYMAXRHS
+ YYMAXLEFT
- 1,
1300 yystackp
, yyvalp
]b4_locuser_args
[);
1304 /** Pop items off stack #YYK of *YYSTACKP according to grammar rule YYRULE,
1305 * and push back on the resulting nonterminal symbol. Perform the
1306 * semantic action associated with YYRULE and store its value with the
1307 * newly pushed state, if YYFORCEEVAL or if *YYSTACKP is currently
1308 * unambiguous. Otherwise, store the deferred semantic action with
1309 * the new state. If the new state would have an identical input
1310 * position, LR state, and predecessor to an existing state on the stack,
1311 * it is identified with that existing state, eliminating stack #YYK from
1312 * *YYSTACKP. In this case, the semantic value is
1313 * added to the options for the existing state's semantic value.
1315 static inline YYRESULTTAG
1316 yyglrReduce (yyGLRStack
* yystackp
, size_t yyk
, yyRuleNum yyrule
,
1317 yybool yyforceEval
]b4_user_formals
[)
1319 size_t yyposn
= yystackp
->yytops
.yystates
[yyk
]->yyposn
;
1321 if (yyforceEval
|| yystackp
->yysplitPoint
== YY_NULL
)
1323 YYSTYPE yysval
;]b4_locations_if([[
1326 YYRESULTTAG yyflag
= yydoAction (yystackp
, yyk
, yyrule
, &yysval
]b4_locuser_args([&yyloc
])[);
1327 if (yyflag
== yyerr
&& yystackp
->yysplitPoint
!= YY_NULL
)
1329 YYDPRINTF ((stderr
, "Parse on stack %lu rejected by rule #%d.\n",
1330 (unsigned long int) yyk
, yyrule
- 1));
1334 YY_SYMBOL_PRINT ("-> $$ =", yyr1
[yyrule
], &yysval
, &yyloc
);
1335 yyglrShift (yystackp
, yyk
,
1336 yyLRgotoState (yystackp
->yytops
.yystates
[yyk
]->yylrState
,
1337 yylhsNonterm (yyrule
)),
1338 yyposn
, &yysval
]b4_locations_if([, &yyloc
])[);
1344 yyGLRState
* yys
, *yys0
= yystackp
->yytops
.yystates
[yyk
];
1345 yyStateNum yynewLRState
;
1347 for (yys
= yystackp
->yytops
.yystates
[yyk
], yyn
= yyrhsLength (yyrule
);
1353 yyupdateSplit (yystackp
, yys
);
1354 yynewLRState
= yyLRgotoState (yys
->yylrState
, yylhsNonterm (yyrule
));
1356 "Reduced stack %lu by rule #%d; action deferred. "
1357 "Now in state %d.\n",
1358 (unsigned long int) yyk
, yyrule
- 1, yynewLRState
));
1359 for (yyi
= 0; yyi
< yystackp
->yytops
.yysize
; yyi
+= 1)
1360 if (yyi
!= yyk
&& yystackp
->yytops
.yystates
[yyi
] != YY_NULL
)
1362 yyGLRState
*yysplit
= yystackp
->yysplitPoint
;
1363 yyGLRState
*yyp
= yystackp
->yytops
.yystates
[yyi
];
1364 while (yyp
!= yys
&& yyp
!= yysplit
&& yyp
->yyposn
>= yyposn
)
1366 if (yyp
->yylrState
== yynewLRState
&& yyp
->yypred
== yys
)
1368 yyaddDeferredAction (yystackp
, yyk
, yyp
, yys0
, yyrule
);
1369 yymarkStackDeleted (yystackp
, yyk
);
1370 YYDPRINTF ((stderr
, "Merging stack %lu into stack %lu.\n",
1371 (unsigned long int) yyk
,
1372 (unsigned long int) yyi
));
1378 yystackp
->yytops
.yystates
[yyk
] = yys
;
1379 yyglrShiftDefer (yystackp
, yyk
, yynewLRState
, yyposn
, yys0
, yyrule
);
1385 yysplitStack (yyGLRStack
* yystackp
, size_t yyk
)
1387 if (yystackp
->yysplitPoint
== YY_NULL
)
1389 YYASSERT (yyk
== 0);
1390 yystackp
->yysplitPoint
= yystackp
->yytops
.yystates
[yyk
];
1392 if (yystackp
->yytops
.yysize
>= yystackp
->yytops
.yycapacity
)
1394 yyGLRState
** yynewStates
;
1395 yybool
* yynewLookaheadNeeds
;
1397 yynewStates
= YY_NULL
;
1399 if (yystackp
->yytops
.yycapacity
1400 > (YYSIZEMAX
/ (2 * sizeof yynewStates
[0])))
1401 yyMemoryExhausted (yystackp
);
1402 yystackp
->yytops
.yycapacity
*= 2;
1405 (yyGLRState
**) YYREALLOC (yystackp
->yytops
.yystates
,
1406 (yystackp
->yytops
.yycapacity
1407 * sizeof yynewStates
[0]));
1408 if (yynewStates
== YY_NULL
)
1409 yyMemoryExhausted (yystackp
);
1410 yystackp
->yytops
.yystates
= yynewStates
;
1412 yynewLookaheadNeeds
=
1413 (yybool
*) YYREALLOC (yystackp
->yytops
.yylookaheadNeeds
,
1414 (yystackp
->yytops
.yycapacity
1415 * sizeof yynewLookaheadNeeds
[0]));
1416 if (yynewLookaheadNeeds
== YY_NULL
)
1417 yyMemoryExhausted (yystackp
);
1418 yystackp
->yytops
.yylookaheadNeeds
= yynewLookaheadNeeds
;
1420 yystackp
->yytops
.yystates
[yystackp
->yytops
.yysize
]
1421 = yystackp
->yytops
.yystates
[yyk
];
1422 yystackp
->yytops
.yylookaheadNeeds
[yystackp
->yytops
.yysize
]
1423 = yystackp
->yytops
.yylookaheadNeeds
[yyk
];
1424 yystackp
->yytops
.yysize
+= 1;
1425 return yystackp
->yytops
.yysize
-1;
1428 /** True iff YYY0 and YYY1 represent identical options at the top level.
1429 * That is, they represent the same rule applied to RHS symbols
1430 * that produce the same terminal symbols. */
1432 yyidenticalOptions (yySemanticOption
* yyy0
, yySemanticOption
* yyy1
)
1434 if (yyy0
->yyrule
== yyy1
->yyrule
)
1436 yyGLRState
*yys0
, *yys1
;
1438 for (yys0
= yyy0
->yystate
, yys1
= yyy1
->yystate
,
1439 yyn
= yyrhsLength (yyy0
->yyrule
);
1441 yys0
= yys0
->yypred
, yys1
= yys1
->yypred
, yyn
-= 1)
1442 if (yys0
->yyposn
!= yys1
->yyposn
)
1450 /** Assuming identicalOptions (YYY0,YYY1), destructively merge the
1451 * alternative semantic values for the RHS-symbols of YYY1 and YYY0. */
1453 yymergeOptionSets (yySemanticOption
* yyy0
, yySemanticOption
* yyy1
)
1455 yyGLRState
*yys0
, *yys1
;
1457 for (yys0
= yyy0
->yystate
, yys1
= yyy1
->yystate
,
1458 yyn
= yyrhsLength (yyy0
->yyrule
);
1460 yys0
= yys0
->yypred
, yys1
= yys1
->yypred
, yyn
-= 1)
1464 else if (yys0
->yyresolved
)
1466 yys1
->yyresolved
= yytrue
;
1467 yys1
->yysemantics
.yysval
= yys0
->yysemantics
.yysval
;
1469 else if (yys1
->yyresolved
)
1471 yys0
->yyresolved
= yytrue
;
1472 yys0
->yysemantics
.yysval
= yys1
->yysemantics
.yysval
;
1476 yySemanticOption
** yyz0p
= &yys0
->yysemantics
.yyfirstVal
;
1477 yySemanticOption
* yyz1
= yys1
->yysemantics
.yyfirstVal
;
1480 if (yyz1
== *yyz0p
|| yyz1
== YY_NULL
)
1482 else if (*yyz0p
== YY_NULL
)
1487 else if (*yyz0p
< yyz1
)
1489 yySemanticOption
* yyz
= *yyz0p
;
1491 yyz1
= yyz1
->yynext
;
1492 (*yyz0p
)->yynext
= yyz
;
1494 yyz0p
= &(*yyz0p
)->yynext
;
1496 yys1
->yysemantics
.yyfirstVal
= yys0
->yysemantics
.yyfirstVal
;
1501 /** Y0 and Y1 represent two possible actions to take in a given
1502 * parsing state; return 0 if no combination is possible,
1503 * 1 if user-mergeable, 2 if Y0 is preferred, 3 if Y1 is preferred. */
1505 yypreference (yySemanticOption
* y0
, yySemanticOption
* y1
)
1507 yyRuleNum r0
= y0
->yyrule
, r1
= y1
->yyrule
;
1508 int p0
= yydprec
[r0
], p1
= yydprec
[r1
];
1512 if (yymerger
[r0
] == 0 || yymerger
[r0
] != yymerger
[r1
])
1517 if (p0
== 0 || p1
== 0)
1526 static YYRESULTTAG
yyresolveValue (yyGLRState
* yys
,
1527 yyGLRStack
* yystackp
]b4_user_formals
[);
1530 /** Resolve the previous YYN states starting at and including state YYS
1531 * on *YYSTACKP. If result != yyok, some states may have been left
1532 * unresolved possibly with empty semantic option chains. Regardless
1533 * of whether result = yyok, each state has been left with consistent
1534 * data so that yydestroyGLRState can be invoked if necessary. */
1536 yyresolveStates (yyGLRState
* yys
, int yyn
,
1537 yyGLRStack
* yystackp
]b4_user_formals
[)
1541 YYASSERT (yys
->yypred
);
1542 YYCHK (yyresolveStates (yys
->yypred
, yyn
-1, yystackp
]b4_user_args
[));
1543 if (! yys
->yyresolved
)
1544 YYCHK (yyresolveValue (yys
, yystackp
]b4_user_args
[));
1549 /** Resolve the states for the RHS of YYOPT on *YYSTACKP, perform its
1550 * user action, and return the semantic value and location in *YYVALP
1551 * and *YYLOCP. Regardless of whether result = yyok, all RHS states
1552 * have been destroyed (assuming the user action destroys all RHS
1553 * semantic values if invoked). */
1555 yyresolveAction (yySemanticOption
* yyopt
, yyGLRStack
* yystackp
,
1556 YYSTYPE
* yyvalp
]b4_locuser_formals
[)
1558 yyGLRStackItem yyrhsVals
[YYMAXRHS
+ YYMAXLEFT
+ 1];
1559 int yynrhs
= yyrhsLength (yyopt
->yyrule
);
1560 YYRESULTTAG yyflag
=
1561 yyresolveStates (yyopt
->yystate
, yynrhs
, yystackp
]b4_user_args
[);
1565 for (yys
= yyopt
->yystate
; yynrhs
> 0; yys
= yys
->yypred
, yynrhs
-= 1)
1566 yydestroyGLRState ("Cleanup: popping", yys
]b4_user_args
[);
1570 yyrhsVals
[YYMAXRHS
+ YYMAXLEFT
].yystate
.yypred
= yyopt
->yystate
;]b4_locations_if([[
1572 /* Set default location. */
1573 yyrhsVals
[YYMAXRHS
+ YYMAXLEFT
- 1].yystate
.yyloc
= yyopt
->yystate
->yyloc
;]])[
1575 int yychar_current
= yychar
;
1576 YYSTYPE yylval_current
= yylval
;]b4_locations_if([
1577 YYLTYPE yylloc_current
= yylloc
;])[
1578 yychar
= yyopt
->yyrawchar
;
1579 yylval
= yyopt
->yyval
;]b4_locations_if([
1580 yylloc
= yyopt
->yyloc
;])[
1581 yyflag
= yyuserAction (yyopt
->yyrule
, yynrhs
,
1582 yyrhsVals
+ YYMAXRHS
+ YYMAXLEFT
- 1,
1583 yystackp
, yyvalp
]b4_locuser_args
[);
1584 yychar
= yychar_current
;
1585 yylval
= yylval_current
;]b4_locations_if([
1586 yylloc
= yylloc_current
;])[
1591 #if ]b4_api_PREFIX[DEBUG
1593 yyreportTree (yySemanticOption
* yyx
, int yyindent
)
1595 int yynrhs
= yyrhsLength (yyx
->yyrule
);
1598 yyGLRState
* yystates
[1 + YYMAXRHS
];
1599 yyGLRState yyleftmost_state
;
1601 for (yyi
= yynrhs
, yys
= yyx
->yystate
; 0 < yyi
; yyi
-= 1, yys
= yys
->yypred
)
1602 yystates
[yyi
] = yys
;
1605 yyleftmost_state
.yyposn
= 0;
1606 yystates
[0] = &yyleftmost_state
;
1611 if (yyx
->yystate
->yyposn
< yys
->yyposn
+ 1)
1612 YYFPRINTF (stderr
, "%*s%s -> <Rule %d, empty>\n",
1613 yyindent
, "", yytokenName (yylhsNonterm (yyx
->yyrule
)),
1616 YYFPRINTF (stderr
, "%*s%s -> <Rule %d, tokens %lu .. %lu>\n",
1617 yyindent
, "", yytokenName (yylhsNonterm (yyx
->yyrule
)),
1618 yyx
->yyrule
- 1, (unsigned long int) (yys
->yyposn
+ 1),
1619 (unsigned long int) yyx
->yystate
->yyposn
);
1620 for (yyi
= 1; yyi
<= yynrhs
; yyi
+= 1)
1622 if (yystates
[yyi
]->yyresolved
)
1624 if (yystates
[yyi
-1]->yyposn
+1 > yystates
[yyi
]->yyposn
)
1625 YYFPRINTF (stderr
, "%*s%s <empty>\n", yyindent
+2, "",
1626 yytokenName (yystos
[yystates
[yyi
]->yylrState
]));
1628 YYFPRINTF (stderr
, "%*s%s <tokens %lu .. %lu>\n", yyindent
+2, "",
1629 yytokenName (yystos
[yystates
[yyi
]->yylrState
]),
1630 (unsigned long int) (yystates
[yyi
-1]->yyposn
+ 1),
1631 (unsigned long int) yystates
[yyi
]->yyposn
);
1634 yyreportTree (yystates
[yyi
]->yysemantics
.yyfirstVal
, yyindent
+2);
1640 yyreportAmbiguity (yySemanticOption
* yyx0
,
1641 yySemanticOption
* yyx1
]b4_pure_formals
[)
1646 #if ]b4_api_PREFIX[DEBUG
1647 YYFPRINTF (stderr
, "Ambiguity detected.\n");
1648 YYFPRINTF (stderr
, "Option 1,\n");
1649 yyreportTree (yyx0
, 2);
1650 YYFPRINTF (stderr
, "\nOption 2,\n");
1651 yyreportTree (yyx1
, 2);
1652 YYFPRINTF (stderr
, "\n");
1655 yyerror (]b4_yyerror_args
[YY_("syntax is ambiguous"));
1657 }]b4_locations_if([[
1659 /** Resolve the locations for each of the YYN1 states in *YYSTACKP,
1660 * ending at YYS1. Has no effect on previously resolved states.
1661 * The first semantic option of a state is always chosen. */
1663 yyresolveLocations (yyGLRState
* yys1
, int yyn1
,
1664 yyGLRStack
*yystackp
]b4_user_formals
[)
1668 yyresolveLocations (yys1
->yypred
, yyn1
- 1, yystackp
]b4_user_args
[);
1669 if (!yys1
->yyresolved
)
1671 yyGLRStackItem yyrhsloc
[1 + YYMAXRHS
];
1673 yySemanticOption
*yyoption
= yys1
->yysemantics
.yyfirstVal
;
1674 YYASSERT (yyoption
!= YY_NULL
);
1675 yynrhs
= yyrhsLength (yyoption
->yyrule
);
1680 yyresolveLocations (yyoption
->yystate
, yynrhs
,
1681 yystackp
]b4_user_args
[);
1682 for (yys
= yyoption
->yystate
, yyn
= yynrhs
;
1684 yys
= yys
->yypred
, yyn
-= 1)
1685 yyrhsloc
[yyn
].yystate
.yyloc
= yys
->yyloc
;
1689 /* Both yyresolveAction and yyresolveLocations traverse the GSS
1690 in reverse rightmost order. It is only necessary to invoke
1691 yyresolveLocations on a subforest for which yyresolveAction
1692 would have been invoked next had an ambiguity not been
1693 detected. Thus the location of the previous state (but not
1694 necessarily the previous state itself) is guaranteed to be
1695 resolved already. */
1696 yyGLRState
*yyprevious
= yyoption
->yystate
;
1697 yyrhsloc
[0].yystate
.yyloc
= yyprevious
->yyloc
;
1700 int yychar_current
= yychar
;
1701 YYSTYPE yylval_current
= yylval
;
1702 YYLTYPE yylloc_current
= yylloc
;
1703 yychar
= yyoption
->yyrawchar
;
1704 yylval
= yyoption
->yyval
;
1705 yylloc
= yyoption
->yyloc
;
1706 YYLLOC_DEFAULT ((yys1
->yyloc
), yyrhsloc
, yynrhs
);
1707 yychar
= yychar_current
;
1708 yylval
= yylval_current
;
1709 yylloc
= yylloc_current
;
1715 /** Resolve the ambiguity represented in state YYS in *YYSTACKP,
1716 * perform the indicated actions, and set the semantic value of YYS.
1717 * If result != yyok, the chain of semantic options in YYS has been
1718 * cleared instead or it has been left unmodified except that
1719 * redundant options may have been removed. Regardless of whether
1720 * result = yyok, YYS has been left with consistent data so that
1721 * yydestroyGLRState can be invoked if necessary. */
1723 yyresolveValue (yyGLRState
* yys
, yyGLRStack
* yystackp
]b4_user_formals
[)
1725 yySemanticOption
* yyoptionList
= yys
->yysemantics
.yyfirstVal
;
1726 yySemanticOption
* yybest
= yyoptionList
;
1727 yySemanticOption
** yypp
;
1728 yybool yymerge
= yyfalse
;
1730 YYRESULTTAG yyflag
;]b4_locations_if([
1731 YYLTYPE
*yylocp
= &yys
->yyloc
;])[
1733 for (yypp
= &yyoptionList
->yynext
; *yypp
!= YY_NULL
; )
1735 yySemanticOption
* yyp
= *yypp
;
1737 if (yyidenticalOptions (yybest
, yyp
))
1739 yymergeOptionSets (yybest
, yyp
);
1740 *yypp
= yyp
->yynext
;
1744 switch (yypreference (yybest
, yyp
))
1746 case 0:]b4_locations_if([[
1747 yyresolveLocations (yys
, 1, yystackp
]b4_user_args
[);]])[
1748 return yyreportAmbiguity (yybest
, yyp
]b4_pure_args
[);
1760 /* This cannot happen so it is not worth a YYASSERT (yyfalse),
1761 but some compilers complain if the default case is
1765 yypp
= &yyp
->yynext
;
1771 yySemanticOption
* yyp
;
1772 int yyprec
= yydprec
[yybest
->yyrule
];
1773 yyflag
= yyresolveAction (yybest
, yystackp
, &yysval
]b4_locuser_args
[);
1775 for (yyp
= yybest
->yynext
; yyp
!= YY_NULL
; yyp
= yyp
->yynext
)
1777 if (yyprec
== yydprec
[yyp
->yyrule
])
1779 YYSTYPE yysval_other
;]b4_locations_if([
1781 yyflag
= yyresolveAction (yyp
, yystackp
, &yysval_other
]b4_locuser_args([&yydummy
])[);
1784 yydestruct ("Cleanup: discarding incompletely merged value for",
1785 yystos
[yys
->yylrState
],
1786 &yysval
]b4_locuser_args
[);
1789 yyuserMerge (yymerger
[yyp
->yyrule
], &yysval
, &yysval_other
);
1794 yyflag
= yyresolveAction (yybest
, yystackp
, &yysval
]b4_locuser_args([yylocp
])[);
1798 yys
->yyresolved
= yytrue
;
1799 yys
->yysemantics
.yysval
= yysval
;
1802 yys
->yysemantics
.yyfirstVal
= YY_NULL
;
1807 yyresolveStack (yyGLRStack
* yystackp
]b4_user_formals
[)
1809 if (yystackp
->yysplitPoint
!= YY_NULL
)
1814 for (yyn
= 0, yys
= yystackp
->yytops
.yystates
[0];
1815 yys
!= yystackp
->yysplitPoint
;
1816 yys
= yys
->yypred
, yyn
+= 1)
1818 YYCHK (yyresolveStates (yystackp
->yytops
.yystates
[0], yyn
, yystackp
1825 yycompressStack (yyGLRStack
* yystackp
)
1827 yyGLRState
* yyp
, *yyq
, *yyr
;
1829 if (yystackp
->yytops
.yysize
!= 1 || yystackp
->yysplitPoint
== YY_NULL
)
1832 for (yyp
= yystackp
->yytops
.yystates
[0], yyq
= yyp
->yypred
, yyr
= YY_NULL
;
1833 yyp
!= yystackp
->yysplitPoint
;
1834 yyr
= yyp
, yyp
= yyq
, yyq
= yyp
->yypred
)
1837 yystackp
->yyspaceLeft
+= yystackp
->yynextFree
- yystackp
->yyitems
;
1838 yystackp
->yynextFree
= ((yyGLRStackItem
*) yystackp
->yysplitPoint
) + 1;
1839 yystackp
->yyspaceLeft
-= yystackp
->yynextFree
- yystackp
->yyitems
;
1840 yystackp
->yysplitPoint
= YY_NULL
;
1841 yystackp
->yylastDeleted
= YY_NULL
;
1843 while (yyr
!= YY_NULL
)
1845 yystackp
->yynextFree
->yystate
= *yyr
;
1847 yystackp
->yynextFree
->yystate
.yypred
= &yystackp
->yynextFree
[-1].yystate
;
1848 yystackp
->yytops
.yystates
[0] = &yystackp
->yynextFree
->yystate
;
1849 yystackp
->yynextFree
+= 1;
1850 yystackp
->yyspaceLeft
-= 1;
1855 yyprocessOneStack (yyGLRStack
* yystackp
, size_t yyk
,
1856 size_t yyposn
]b4_pure_formals
[)
1858 while (yystackp
->yytops
.yystates
[yyk
] != YY_NULL
)
1860 yyStateNum yystate
= yystackp
->yytops
.yystates
[yyk
]->yylrState
;
1861 YYDPRINTF ((stderr
, "Stack %lu Entering state %d\n",
1862 (unsigned long int) yyk
, yystate
));
1864 YYASSERT (yystate
!= YYFINAL
);
1866 if (yyisDefaultedState (yystate
))
1869 yyRuleNum yyrule
= yydefaultAction (yystate
);
1872 YYDPRINTF ((stderr
, "Stack %lu dies.\n",
1873 (unsigned long int) yyk
));
1874 yymarkStackDeleted (yystackp
, yyk
);
1877 yyflag
= yyglrReduce (yystackp
, yyk
, yyrule
, yyimmediate
[yyrule
]]b4_user_args
[);
1878 if (yyflag
== yyerr
)
1882 "(predicate failure or explicit user error).\n",
1883 (unsigned long int) yyk
));
1884 yymarkStackDeleted (yystackp
, yyk
);
1894 const short int* yyconflicts
;
1896 yystackp
->yytops
.yylookaheadNeeds
[yyk
] = yytrue
;
1897 if (yychar
== YYEMPTY
)
1899 YYDPRINTF ((stderr
, "Reading a token: "));
1903 if (yychar
<= YYEOF
)
1905 yychar
= yytoken
= YYEOF
;
1906 YYDPRINTF ((stderr
, "Now at end of input.\n"));
1910 yytoken
= YYTRANSLATE (yychar
);
1911 YY_SYMBOL_PRINT ("Next token is", yytoken
, &yylval
, &yylloc
);
1914 yygetLRActions (yystate
, yytoken
, &yyaction
, &yyconflicts
);
1916 while (*yyconflicts
!= 0)
1919 size_t yynewStack
= yysplitStack (yystackp
, yyk
);
1920 YYDPRINTF ((stderr
, "Splitting off stack %lu from %lu.\n",
1921 (unsigned long int) yynewStack
,
1922 (unsigned long int) yyk
));
1923 yyflag
= yyglrReduce (yystackp
, yynewStack
,
1925 yyimmediate
[*yyconflicts
]]b4_user_args
[);
1927 YYCHK (yyprocessOneStack (yystackp
, yynewStack
,
1928 yyposn
]b4_pure_args
[));
1929 else if (yyflag
== yyerr
)
1931 YYDPRINTF ((stderr
, "Stack %lu dies.\n",
1932 (unsigned long int) yynewStack
));
1933 yymarkStackDeleted (yystackp
, yynewStack
);
1940 if (yyisShiftAction (yyaction
))
1942 else if (yyisErrorAction (yyaction
))
1944 YYDPRINTF ((stderr
, "Stack %lu dies.\n",
1945 (unsigned long int) yyk
));
1946 yymarkStackDeleted (yystackp
, yyk
);
1951 YYRESULTTAG yyflag
= yyglrReduce (yystackp
, yyk
, -yyaction
,
1952 yyimmediate
[-yyaction
]]b4_user_args
[);
1953 if (yyflag
== yyerr
)
1957 "(predicate failure or explicit user error).\n",
1958 (unsigned long int) yyk
));
1959 yymarkStackDeleted (yystackp
, yyk
);
1962 else if (yyflag
!= yyok
)
1971 yyreportSyntaxError (yyGLRStack
* yystackp
]b4_user_formals
[)
1973 if (yystackp
->yyerrState
!= 0)
1975 #if ! YYERROR_VERBOSE
1976 yyerror (]b4_lyyerror_args
[YY_("syntax error"));
1979 yySymbol yytoken
= yychar
== YYEMPTY
? YYEMPTY
: YYTRANSLATE (yychar
);
1980 size_t yysize0
= yytnamerr (YY_NULL
, yytokenName (yytoken
));
1981 size_t yysize
= yysize0
;
1982 yybool yysize_overflow
= yyfalse
;
1983 char* yymsg
= YY_NULL
;
1984 enum { YYERROR_VERBOSE_ARGS_MAXIMUM
= 5 };
1985 /* Internationalized format string. */
1986 const char *yyformat
= YY_NULL
;
1987 /* Arguments of yyformat. */
1988 char const *yyarg
[YYERROR_VERBOSE_ARGS_MAXIMUM
];
1989 /* Number of reported tokens (one for the "unexpected", one per
1993 /* There are many possibilities here to consider:
1994 - If this state is a consistent state with a default action, then
1995 the only way this function was invoked is if the default action
1996 is an error action. In that case, don't check for expected
1997 tokens because there are none.
1998 - The only way there can be no lookahead present (in yychar) is if
1999 this state is a consistent state with a default action. Thus,
2000 detecting the absence of a lookahead is sufficient to determine
2001 that there is no unexpected or expected token to report. In that
2002 case, just report a simple "syntax error".
2003 - Don't assume there isn't a lookahead just because this state is a
2004 consistent state with a default action. There might have been a
2005 previous inconsistent state, consistent state with a non-default
2006 action, or user semantic action that manipulated yychar.
2007 - Of course, the expected token list depends on states to have
2008 correct lookahead information, and it depends on the parser not
2009 to perform extra reductions after fetching a lookahead from the
2010 scanner and before detecting a syntax error. Thus, state merging
2011 (from LALR or IELR) and default reductions corrupt the expected
2012 token list. However, the list is correct for canonical LR with
2013 one exception: it will still contain any token that will not be
2014 accepted due to an error action in a later state.
2016 if (yytoken
!= YYEMPTY
)
2018 int yyn
= yypact
[yystackp
->yytops
.yystates
[0]->yylrState
];
2019 yyarg
[yycount
++] = yytokenName (yytoken
);
2020 if (!yypact_value_is_default (yyn
))
2022 /* Start YYX at -YYN if negative to avoid negative indexes in
2023 YYCHECK. In other words, skip the first -YYN actions for this
2024 state because they are default actions. */
2025 int yyxbegin
= yyn
< 0 ? -yyn
: 0;
2026 /* Stay within bounds of both yycheck and yytname. */
2027 int yychecklim
= YYLAST
- yyn
+ 1;
2028 int yyxend
= yychecklim
< YYNTOKENS
? yychecklim
: YYNTOKENS
;
2030 for (yyx
= yyxbegin
; yyx
< yyxend
; ++yyx
)
2031 if (yycheck
[yyx
+ yyn
] == yyx
&& yyx
!= YYTERROR
2032 && !yytable_value_is_error (yytable
[yyx
+ yyn
]))
2034 if (yycount
== YYERROR_VERBOSE_ARGS_MAXIMUM
)
2040 yyarg
[yycount
++] = yytokenName (yyx
);
2042 size_t yysz
= yysize
+ yytnamerr (YY_NULL
, yytokenName (yyx
));
2043 yysize_overflow
|= yysz
< yysize
;
2052 #define YYCASE_(N, S) \
2056 YYCASE_(0, YY_("syntax error"));
2057 YYCASE_(1, YY_("syntax error, unexpected %s"));
2058 YYCASE_(2, YY_("syntax error, unexpected %s, expecting %s"));
2059 YYCASE_(3, YY_("syntax error, unexpected %s, expecting %s or %s"));
2060 YYCASE_(4, YY_("syntax error, unexpected %s, expecting %s or %s or %s"));
2061 YYCASE_(5, YY_("syntax error, unexpected %s, expecting %s or %s or %s or %s"));
2066 size_t yysz
= yysize
+ strlen (yyformat
);
2067 yysize_overflow
|= yysz
< yysize
;
2071 if (!yysize_overflow
)
2072 yymsg
= (char *) YYMALLOC (yysize
);
2078 while ((*yyp
= *yyformat
))
2080 if (*yyp
== '%' && yyformat
[1] == 's' && yyi
< yycount
)
2082 yyp
+= yytnamerr (yyp
, yyarg
[yyi
++]);
2091 yyerror (]b4_lyyerror_args
[yymsg
);
2096 yyerror (]b4_lyyerror_args
[YY_("syntax error"));
2097 yyMemoryExhausted (yystackp
);
2100 #endif /* YYERROR_VERBOSE */
2104 /* Recover from a syntax error on *YYSTACKP, assuming that *YYSTACKP->YYTOKENP,
2105 yylval, and yylloc are the syntactic category, semantic value, and location
2106 of the lookahead. */
2108 yyrecoverSyntaxError (yyGLRStack
* yystackp
]b4_user_formals
[)
2113 if (yystackp
->yyerrState
== 3)
2114 /* We just shifted the error token and (perhaps) took some
2115 reductions. Skip tokens until we can proceed. */
2119 if (yychar
== YYEOF
)
2120 yyFail (yystackp
][]b4_lpure_args
[, YY_NULL
);
2121 if (yychar
!= YYEMPTY
)
2122 {]b4_locations_if([[
2123 /* We throw away the lookahead, but the error range
2124 of the shifted error token must take it into account. */
2125 yyGLRState
*yys
= yystackp
->yytops
.yystates
[0];
2126 yyGLRStackItem yyerror_range
[3];
2127 yyerror_range
[1].yystate
.yyloc
= yys
->yyloc
;
2128 yyerror_range
[2].yystate
.yyloc
= yylloc
;
2129 YYLLOC_DEFAULT ((yys
->yyloc
), yyerror_range
, 2);]])[
2130 yytoken
= YYTRANSLATE (yychar
);
2131 yydestruct ("Error: discarding",
2132 yytoken
, &yylval
]b4_locuser_args([&yylloc
])[);
2134 YYDPRINTF ((stderr
, "Reading a token: "));
2136 if (yychar
<= YYEOF
)
2138 yychar
= yytoken
= YYEOF
;
2139 YYDPRINTF ((stderr
, "Now at end of input.\n"));
2143 yytoken
= YYTRANSLATE (yychar
);
2144 YY_SYMBOL_PRINT ("Next token is", yytoken
, &yylval
, &yylloc
);
2146 yyj
= yypact
[yystackp
->yytops
.yystates
[0]->yylrState
];
2147 if (yypact_value_is_default (yyj
))
2150 if (yyj
< 0 || YYLAST
< yyj
|| yycheck
[yyj
] != yytoken
)
2152 if (yydefact
[yystackp
->yytops
.yystates
[0]->yylrState
] != 0)
2155 else if (! yytable_value_is_error (yytable
[yyj
]))
2159 /* Reduce to one stack. */
2160 for (yyk
= 0; yyk
< yystackp
->yytops
.yysize
; yyk
+= 1)
2161 if (yystackp
->yytops
.yystates
[yyk
] != YY_NULL
)
2163 if (yyk
>= yystackp
->yytops
.yysize
)
2164 yyFail (yystackp
][]b4_lpure_args
[, YY_NULL
);
2165 for (yyk
+= 1; yyk
< yystackp
->yytops
.yysize
; yyk
+= 1)
2166 yymarkStackDeleted (yystackp
, yyk
);
2167 yyremoveDeletes (yystackp
);
2168 yycompressStack (yystackp
);
2170 /* Now pop stack until we find a state that shifts the error token. */
2171 yystackp
->yyerrState
= 3;
2172 while (yystackp
->yytops
.yystates
[0] != YY_NULL
)
2174 yyGLRState
*yys
= yystackp
->yytops
.yystates
[0];
2175 yyj
= yypact
[yys
->yylrState
];
2176 if (! yypact_value_is_default (yyj
))
2179 if (0 <= yyj
&& yyj
<= YYLAST
&& yycheck
[yyj
] == YYTERROR
2180 && yyisShiftAction (yytable
[yyj
]))
2182 /* Shift the error token. */]b4_locations_if([[
2183 /* First adjust its location.*/
2185 yystackp
->yyerror_range
[2].yystate
.yyloc
= yylloc
;
2186 YYLLOC_DEFAULT (yyerrloc
, (yystackp
->yyerror_range
), 2);]])[
2187 YY_SYMBOL_PRINT ("Shifting", yystos
[yytable
[yyj
]],
2188 &yylval
, &yyerrloc
);
2189 yyglrShift (yystackp
, 0, yytable
[yyj
],
2190 yys
->yyposn
, &yylval
]b4_locations_if([, &yyerrloc
])[);
2191 yys
= yystackp
->yytops
.yystates
[0];
2194 }]b4_locations_if([[
2195 yystackp
->yyerror_range
[1].yystate
.yyloc
= yys
->yyloc
;]])[
2196 if (yys
->yypred
!= YY_NULL
)
2197 yydestroyGLRState ("Error: popping", yys
]b4_user_args
[);
2198 yystackp
->yytops
.yystates
[0] = yys
->yypred
;
2199 yystackp
->yynextFree
-= 1;
2200 yystackp
->yyspaceLeft
+= 1;
2202 if (yystackp
->yytops
.yystates
[0] == YY_NULL
)
2203 yyFail (yystackp
][]b4_lpure_args
[, YY_NULL
);
2206 #define YYCHK1(YYE) \
2216 goto yyuser_error; \
2226 ]b4_function_define([yyparse
], [int], b4_parse_param
)[
2230 yyGLRStack
* const yystackp
= &yystack
;
2233 YYDPRINTF ((stderr
, "Starting parse\n"));
2236 yylval
= yyval_default
;]b4_locations_if([
2237 yylloc
= yyloc_default
;])[
2238 ]m4_ifdef([b4_initial_action
], [
2239 b4_dollar_pushdef([yylval
], [], [yylloc
])dnl
2240 /* User initialization code. */
2241 b4_user_initial_action
2242 b4_dollar_popdef
])[]dnl
2244 if (! yyinitGLRStack (yystackp
, YYINITDEPTH
))
2245 goto yyexhaustedlab
;
2246 switch (YYSETJMP (yystack
.yyexception_buffer
))
2249 case 1: goto yyabortlab
;
2250 case 2: goto yyexhaustedlab
;
2251 default: goto yybuglab
;
2253 yyglrShift (&yystack
, 0, 0, 0, &yylval
]b4_locations_if([, &yylloc
])[);
2258 /* For efficiency, we have two loops, the first of which is
2259 specialized to deterministic operation (single stack, no
2260 potential ambiguity). */
2266 const short int* yyconflicts
;
2268 yyStateNum yystate
= yystack
.yytops
.yystates
[0]->yylrState
;
2269 YYDPRINTF ((stderr
, "Entering state %d\n", yystate
));
2270 if (yystate
== YYFINAL
)
2272 if (yyisDefaultedState (yystate
))
2274 yyrule
= yydefaultAction (yystate
);
2277 ]b4_locations_if([[ yystack
.yyerror_range
[1].yystate
.yyloc
= yylloc
;]])[
2278 yyreportSyntaxError (&yystack
]b4_user_args
[);
2281 YYCHK1 (yyglrReduce (&yystack
, 0, yyrule
, yytrue
]b4_user_args
[));
2286 if (yychar
== YYEMPTY
)
2288 YYDPRINTF ((stderr
, "Reading a token: "));
2292 if (yychar
<= YYEOF
)
2294 yychar
= yytoken
= YYEOF
;
2295 YYDPRINTF ((stderr
, "Now at end of input.\n"));
2299 yytoken
= YYTRANSLATE (yychar
);
2300 YY_SYMBOL_PRINT ("Next token is", yytoken
, &yylval
, &yylloc
);
2303 yygetLRActions (yystate
, yytoken
, &yyaction
, &yyconflicts
);
2304 if (*yyconflicts
!= 0)
2306 if (yyisShiftAction (yyaction
))
2308 YY_SYMBOL_PRINT ("Shifting", yytoken
, &yylval
, &yylloc
);
2311 yyglrShift (&yystack
, 0, yyaction
, yyposn
, &yylval
]b4_locations_if([, &yylloc
])[);
2312 if (0 < yystack
.yyerrState
)
2313 yystack
.yyerrState
-= 1;
2315 else if (yyisErrorAction (yyaction
))
2317 ]b4_locations_if([[ yystack
.yyerror_range
[1].yystate
.yyloc
= yylloc
;]])[
2318 yyreportSyntaxError (&yystack
]b4_user_args
[);
2322 YYCHK1 (yyglrReduce (&yystack
, 0, -yyaction
, yytrue
]b4_user_args
[));
2328 yySymbol yytoken_to_shift
;
2331 for (yys
= 0; yys
< yystack
.yytops
.yysize
; yys
+= 1)
2332 yystackp
->yytops
.yylookaheadNeeds
[yys
] = yychar
!= YYEMPTY
;
2334 /* yyprocessOneStack returns one of three things:
2336 - An error flag. If the caller is yyprocessOneStack, it
2337 immediately returns as well. When the caller is finally
2338 yyparse, it jumps to an error label via YYCHK1.
2340 - yyok, but yyprocessOneStack has invoked yymarkStackDeleted
2341 (&yystack, yys), which sets the top state of yys to NULL. Thus,
2342 yyparse's following invocation of yyremoveDeletes will remove
2345 - yyok, when ready to shift a token.
2347 Except in the first case, yyparse will invoke yyremoveDeletes and
2348 then shift the next token onto all remaining stacks. This
2349 synchronization of the shift (that is, after all preceding
2350 reductions on all stacks) helps prevent double destructor calls
2351 on yylval in the event of memory exhaustion. */
2353 for (yys
= 0; yys
< yystack
.yytops
.yysize
; yys
+= 1)
2354 YYCHK1 (yyprocessOneStack (&yystack
, yys
, yyposn
]b4_lpure_args
[));
2355 yyremoveDeletes (&yystack
);
2356 if (yystack
.yytops
.yysize
== 0)
2358 yyundeleteLastStack (&yystack
);
2359 if (yystack
.yytops
.yysize
== 0)
2360 yyFail (&yystack
][]b4_lpure_args
[, YY_("syntax error"));
2361 YYCHK1 (yyresolveStack (&yystack
]b4_user_args
[));
2362 YYDPRINTF ((stderr
, "Returning to deterministic operation.\n"));
2363 ]b4_locations_if([[ yystack
.yyerror_range
[1].yystate
.yyloc
= yylloc
;]])[
2364 yyreportSyntaxError (&yystack
]b4_user_args
[);
2368 /* If any yyglrShift call fails, it will fail after shifting. Thus,
2369 a copy of yylval will already be on stack 0 in the event of a
2370 failure in the following loop. Thus, yychar is set to YYEMPTY
2371 before the loop to make sure the user destructor for yylval isn't
2373 yytoken_to_shift
= YYTRANSLATE (yychar
);
2376 for (yys
= 0; yys
< yystack
.yytops
.yysize
; yys
+= 1)
2379 const short int* yyconflicts
;
2380 yyStateNum yystate
= yystack
.yytops
.yystates
[yys
]->yylrState
;
2381 yygetLRActions (yystate
, yytoken_to_shift
, &yyaction
,
2383 /* Note that yyconflicts were handled by yyprocessOneStack. */
2384 YYDPRINTF ((stderr
, "On stack %lu, ", (unsigned long int) yys
));
2385 YY_SYMBOL_PRINT ("shifting", yytoken_to_shift
, &yylval
, &yylloc
);
2386 yyglrShift (&yystack
, yys
, yyaction
, yyposn
,
2387 &yylval
]b4_locations_if([, &yylloc
])[);
2388 YYDPRINTF ((stderr
, "Stack %lu now in state #%d\n",
2389 (unsigned long int) yys
,
2390 yystack
.yytops
.yystates
[yys
]->yylrState
));
2393 if (yystack
.yytops
.yysize
== 1)
2395 YYCHK1 (yyresolveStack (&yystack
]b4_user_args
[));
2396 YYDPRINTF ((stderr
, "Returning to deterministic operation.\n"));
2397 yycompressStack (&yystack
);
2403 yyrecoverSyntaxError (&yystack
]b4_user_args
[);
2404 yyposn
= yystack
.yytops
.yystates
[0]->yyposn
;
2420 yyerror (]b4_lyyerror_args
[YY_("memory exhausted"));
2425 if (yychar
!= YYEMPTY
)
2426 yydestruct ("Cleanup: discarding lookahead",
2427 YYTRANSLATE (yychar
), &yylval
]b4_locuser_args([&yylloc
])[);
2429 /* If the stack is well-formed, pop the stack until it is empty,
2430 destroying its entries as we go. But free the stack regardless
2431 of whether it is well-formed. */
2432 if (yystack
.yyitems
)
2434 yyGLRState
** yystates
= yystack
.yytops
.yystates
;
2437 size_t yysize
= yystack
.yytops
.yysize
;
2439 for (yyk
= 0; yyk
< yysize
; yyk
+= 1)
2442 while (yystates
[yyk
])
2444 yyGLRState
*yys
= yystates
[yyk
];
2445 ]b4_locations_if([[ yystack
.yyerror_range
[1].yystate
.yyloc
= yys
->yyloc
;]]
2446 )[ if (yys
->yypred
!= YY_NULL
)
2447 yydestroyGLRState ("Cleanup: popping", yys
]b4_user_args
[);
2448 yystates
[yyk
] = yys
->yypred
;
2449 yystack
.yynextFree
-= 1;
2450 yystack
.yyspaceLeft
+= 1;
2455 yyfreeGLRStack (&yystack
);
2461 /* DEBUGGING ONLY */
2462 #if ]b4_api_PREFIX[DEBUG
2464 yy_yypstack (yyGLRState
* yys
)
2468 yy_yypstack (yys
->yypred
);
2469 YYFPRINTF (stderr
, " -> ");
2471 YYFPRINTF (stderr
, "%d@@%lu", yys
->yylrState
,
2472 (unsigned long int) yys
->yyposn
);
2476 yypstates (yyGLRState
* yyst
)
2478 if (yyst
== YY_NULL
)
2479 YYFPRINTF (stderr
, "<null>");
2482 YYFPRINTF (stderr
, "\n");
2486 yypstack (yyGLRStack
* yystackp
, size_t yyk
)
2488 yypstates (yystackp
->yytops
.yystates
[yyk
]);
2491 #define YYINDEX(YYX) \
2492 ((YYX) == YY_NULL ? -1 : (yyGLRStackItem*) (YYX) - yystackp->yyitems)
2496 yypdumpstack (yyGLRStack
* yystackp
)
2498 yyGLRStackItem
* yyp
;
2500 for (yyp
= yystackp
->yyitems
; yyp
< yystackp
->yynextFree
; yyp
+= 1)
2502 YYFPRINTF (stderr
, "%3lu. ",
2503 (unsigned long int) (yyp
- yystackp
->yyitems
));
2504 if (*(yybool
*) yyp
)
2506 YYASSERT (yyp
->yystate
.yyisState
);
2507 YYASSERT (yyp
->yyoption
.yyisState
);
2508 YYFPRINTF (stderr
, "Res: %d, LR State: %d, posn: %lu, pred: %ld",
2509 yyp
->yystate
.yyresolved
, yyp
->yystate
.yylrState
,
2510 (unsigned long int) yyp
->yystate
.yyposn
,
2511 (long int) YYINDEX (yyp
->yystate
.yypred
));
2512 if (! yyp
->yystate
.yyresolved
)
2513 YYFPRINTF (stderr
, ", firstVal: %ld",
2514 (long int) YYINDEX (yyp
->yystate
2515 .yysemantics
.yyfirstVal
));
2519 YYASSERT (!yyp
->yystate
.yyisState
);
2520 YYASSERT (!yyp
->yyoption
.yyisState
);
2521 YYFPRINTF (stderr
, "Option. rule: %d, state: %ld, next: %ld",
2522 yyp
->yyoption
.yyrule
- 1,
2523 (long int) YYINDEX (yyp
->yyoption
.yystate
),
2524 (long int) YYINDEX (yyp
->yyoption
.yynext
));
2526 YYFPRINTF (stderr
, "\n");
2528 YYFPRINTF (stderr
, "Tops:");
2529 for (yyi
= 0; yyi
< yystackp
->yytops
.yysize
; yyi
+= 1)
2530 YYFPRINTF (stderr
, "%lu: %ld; ", (unsigned long int) yyi
,
2531 (long int) YYINDEX (yystackp
->yytops
.yystates
[yyi
]));
2532 YYFPRINTF (stderr
, "\n");
2538 #undef yynerrs]b4_locations_if([
2541 m4_if(b4_prefix
, [yy
], [],
2542 [[/* Substitute the variable and function names. */
2543 #define yyparse ]b4_prefix[parse
2544 #define yylex ]b4_prefix[lex
2545 #define yyerror ]b4_prefix[error
2546 #define yylval ]b4_prefix[lval
2547 #define yychar ]b4_prefix[char
2548 #define yydebug ]b4_prefix[debug
2549 #define yynerrs ]b4_prefix[nerrs]b4_locations_if([[
2550 #define yylloc ]b4_prefix[lloc]])])[
2555 # glr.cc produces its own header.
2556 m4_if(b4_skeleton
, ["glr.c"],
2558 [b4_output_begin([b4_spec_defines_file
])
2559 b4_copyright([Skeleton interface
for Bison GLR parsers in C
],
2562 ]b4_cpp_guard_open([b4_spec_defines_file
])[
2563 ]b4_shared_declarations
[
2564 ]b4_cpp_guard_close([b4_spec_defines_file
])[