3 # GLR skeleton for Bison
5 # Copyright (C) 2002-2012 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
249 /* Suppress unused-variable warnings by "using" E. */
251 # define YYUSE(E) ((void) (E))
253 # define YYUSE(E) /* empty */
260 # define YYMALLOC malloc
263 # define YYREALLOC realloc
266 #define YYSIZEMAX ((size_t) -1)
271 typedef unsigned char yybool
;
278 # define YYJMP_BUF jmp_buf
279 # define YYSETJMP(Env) setjmp (Env)
281 # define YYLONGJMP(Env, Val) (longjmp (Env, Val), YYASSERT (0))
288 #ifndef __attribute__
289 /* This feature is available in gcc versions 2.5 and later. */
290 # if (! defined __GNUC__ || __GNUC__ < 2 \
291 || (__GNUC__ == 2 && __GNUC_MINOR__ < 5))
292 # define __attribute__(Spec) /* empty */
297 # define YYASSERT(Condition) ((void) ((Condition) || (abort (), 0)))
300 /* YYFINAL -- State number of the termination state. */
301 #define YYFINAL ]b4_final_state_number[
302 /* YYLAST -- Last index in YYTABLE. */
303 #define YYLAST ]b4_last[
305 /* YYNTOKENS -- Number of terminals. */
306 #define YYNTOKENS ]b4_tokens_number[
307 /* YYNNTS -- Number of nonterminals. */
308 #define YYNNTS ]b4_nterms_number[
309 /* YYNRULES -- Number of rules. */
310 #define YYNRULES ]b4_rules_number[
311 /* YYNRULES -- Number of states. */
312 #define YYNSTATES ]b4_states_number[
313 /* YYMAXRHS -- Maximum number of symbols on right-hand side of rule. */
314 #define YYMAXRHS ]b4_r2_max[
315 /* YYMAXLEFT -- Maximum number of symbols to the left of a handle
316 accessed by $0, $-1, etc., in any rule. */
317 #define YYMAXLEFT ]b4_max_left_semantic_context[
319 /* YYTRANSLATE(X) -- Bison symbol number corresponding to X. */
320 #define YYUNDEFTOK ]b4_undef_token_number[
321 #define YYMAXUTOK ]b4_user_token_number_max[
323 #define YYTRANSLATE(YYX) \
324 ((unsigned int) (YYX) <= YYMAXUTOK ? yytranslate[YYX] : YYUNDEFTOK)
326 /* YYTRANSLATE[YYLEX] -- Bison symbol number corresponding to YYLEX. */
327 static const ]b4_int_type_for([b4_translate
])[ yytranslate
[] =
332 #if ]b4_api_PREFIX[DEBUG
333 /* YYRLINE[YYN] -- source line where rule number YYN was defined. */
334 static const ]b4_int_type_for([b4_rline
])[ yyrline
[] =
340 #if ]b4_api_PREFIX[DEBUG || YYERROR_VERBOSE || ]b4_token_table_flag[
341 /* YYTNAME[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM.
342 First, the terminals, then, starting at YYNTOKENS, nonterminals. */
343 static const char *const yytname
[] =
349 #define YYPACT_NINF ]b4_pact_ninf[
350 #define YYTABLE_NINF ]b4_table_ninf[
352 ]b4_parser_tables_define
[
354 /* YYDPREC[RULE-NUM] -- Dynamic precedence of rule #RULE-NUM (0 if none). */
355 static const ]b4_int_type_for([b4_dprec
])[ yydprec
[] =
360 /* YYMERGER[RULE-NUM] -- Index of merging function for rule #RULE-NUM. */
361 static const ]b4_int_type_for([b4_merger
])[ yymerger
[] =
366 /* YYIMMEDIATE[RULE-NUM] -- True iff rule #RULE-NUM is not to be deferred, as
367 in the case of predicates. */
368 static const yybool yyimmediate
[] =
373 /* YYCONFLP[YYPACT[STATE-NUM]] -- Pointer into YYCONFL of start of
374 list of conflicting reductions corresponding to action entry for
375 state STATE-NUM in yytable. 0 means no conflicts. The list in
376 yyconfl is terminated by a rule number of 0. */
377 static const ]b4_int_type_for([b4_conflict_list_heads
])[ yyconflp
[] =
379 ]b4_conflict_list_heads
[
382 /* YYCONFL[I] -- lists of conflicting rule numbers, each terminated by
383 0, pointed into by YYCONFLP. */
384 ]dnl Do
not use b4_int_type_for here
, since there are places where
385 dnl pointers onto yyconfl are taken
, whose type is
"short int *".
386 dnl We probably ought to introduce a type
for confl
.
387 [static const short int yyconfl
[] =
389 ]b4_conflicting_rules
[
392 /* Error token number */
396 ]b4_yylloc_default_define
[
397 # define YYRHSLOC(Rhs, K) ((Rhs)[K].yystate.yyloc)
399 ]b4_yy_location_print_define
[
404 #define yynerrs (yystackp->yyerrcnt)
406 #define yychar (yystackp->yyrawchar)
408 #define yylval (yystackp->yyval)
410 #define yylloc (yystackp->yyloc)
411 m4_if(b4_prefix
[], [yy
], [],
412 [#define b4_prefix[]nerrs yynerrs
413 #define b4_prefix[]char yychar
414 #define b4_prefix[]lval yylval
415 #define b4_prefix[]lloc yylloc])],
416 [YYSTYPE yylval
;]b4_locations_if([[
422 static const int YYEOF
= 0;
423 static const int YYEMPTY
= -2;
425 typedef enum { yyok
, yyaccept
, yyabort
, yyerr
} YYRESULTTAG
;
429 YYRESULTTAG yychk_flag = YYE; \
430 if (yychk_flag != yyok) \
434 #if ]b4_api_PREFIX[DEBUG
437 # define YYFPRINTF fprintf
440 # define YYDPRINTF(Args) \
446 ]b4_yy_symbol_print_define
[
448 # define YY_SYMBOL_PRINT(Title, Type, Value, Location) \
452 YYFPRINTF (stderr, "%s ", Title); \
453 yy_symbol_print (stderr, Type, Value]b4_locuser_args([Location])[); \
454 YYFPRINTF (stderr, "\n"); \
458 /* Nonzero means print parse trace. It is left uninitialized so that
459 multiple parsers can coexist. */
463 static void yypstack (struct yyGLRStack
* yystackp
, size_t yyk
)
464 __attribute__ ((__unused__
));
465 static void yypdumpstack (struct yyGLRStack
* yystackp
)
466 __attribute__ ((__unused__
));
468 #else /* !]b4_api_PREFIX[DEBUG */
470 # define YYDPRINTF(Args)
471 # define YY_SYMBOL_PRINT(Title, Type, Value, Location)
473 #endif /* !]b4_api_PREFIX[DEBUG */
475 /* YYINITDEPTH -- initial size of the parser's stacks. */
477 # define YYINITDEPTH ]b4_stack_depth_init[
480 /* YYMAXDEPTH -- maximum size the stacks can grow to (effective only
481 if the built-in stack extension method is used).
483 Do not make this value too large; the results are undefined if
484 SIZE_MAX < YYMAXDEPTH * sizeof (GLRStackItem)
485 evaluated with infinite-precision integer arithmetic. */
488 # define YYMAXDEPTH ]b4_stack_depth_max[
491 /* Minimum number of free items on the stack allowed after an
492 allocation. This is to allow allocation and initialization
493 to be completed by functions that call yyexpandGLRStack before the
494 stack is expanded, thus insuring that all necessary pointers get
495 properly redirected to new data. */
498 #ifndef YYSTACKEXPANDABLE
499 # define YYSTACKEXPANDABLE 1
502 #if YYSTACKEXPANDABLE
503 # define YY_RESERVE_GLRSTACK(Yystack) \
505 if (Yystack->yyspaceLeft < YYHEADROOM) \
506 yyexpandGLRStack (Yystack); \
509 # define YY_RESERVE_GLRSTACK(Yystack) \
511 if (Yystack->yyspaceLeft < YYHEADROOM) \
512 yyMemoryExhausted (Yystack); \
520 # if defined __GLIBC__ && defined _STRING_H && defined _GNU_SOURCE
521 # define yystpcpy stpcpy
523 /* Copy YYSRC to YYDEST, returning the address of the terminating '\0' in
526 yystpcpy (char *yydest
, const char *yysrc
)
529 const char *yys
= yysrc
;
531 while ((*yyd
++ = *yys
++) != '\0')
540 /* Copy to YYRES the contents of YYSTR after stripping away unnecessary
541 quotes and backslashes, so that it's suitable for yyerror. The
542 heuristic is that double-quoting is unnecessary unless the string
543 contains an apostrophe, a comma, or backslash (other than
544 backslash-backslash). YYSTR is taken from yytname. If YYRES is
545 null, do not copy; instead, return the length of what the result
548 yytnamerr (char *yyres
, const char *yystr
)
553 char const *yyp
= yystr
;
560 goto do_not_strip_quotes
;
564 goto do_not_strip_quotes
;
577 do_not_strip_quotes
: ;
581 return strlen (yystr
);
583 return yystpcpy (yyres
, yystr
) - yyres
;
587 #endif /* !YYERROR_VERBOSE */
589 /** State numbers, as in LALR(1) machine */
590 typedef int yyStateNum
;
592 /** Rule numbers, as in LALR(1) machine */
593 typedef int yyRuleNum
;
595 /** Grammar symbol */
596 typedef int yySymbol
;
598 /** Item references, as in LALR(1) machine */
599 typedef short int yyItemNum
;
601 typedef struct yyGLRState yyGLRState
;
602 typedef struct yyGLRStateSet yyGLRStateSet
;
603 typedef struct yySemanticOption yySemanticOption
;
604 typedef union yyGLRStackItem yyGLRStackItem
;
605 typedef struct yyGLRStack yyGLRStack
;
608 /** Type tag: always true. */
610 /** Type tag for yysemantics. If true, yysval applies, otherwise
611 * yyfirstVal applies. */
613 /** Number of corresponding LALR(1) machine state. */
614 yyStateNum yylrState
;
615 /** Preceding state in this stack */
617 /** Source position of the last token produced by my symbol */
620 /** First in a chain of alternative reductions producing the
621 * non-terminal corresponding to this state, threaded through
623 yySemanticOption
* yyfirstVal
;
624 /** Semantic value for this state. */
626 } yysemantics
;]b4_locations_if([[
627 /** Source location for this state. */
631 struct yyGLRStateSet
{
632 yyGLRState
** yystates
;
633 /** During nondeterministic operation, yylookaheadNeeds tracks which
634 * stacks have actually needed the current lookahead. During deterministic
635 * operation, yylookaheadNeeds[0] is not maintained since it would merely
636 * duplicate yychar != YYEMPTY. */
637 yybool
* yylookaheadNeeds
;
638 size_t yysize
, yycapacity
;
641 struct yySemanticOption
{
642 /** Type tag: always false. */
644 /** Rule number for this reduction */
646 /** The last RHS state in the list of states to be reduced. */
648 /** The lookahead for this reduction. */
650 YYSTYPE yyval
;]b4_locations_if([[
652 /** Next sibling in chain of options. To facilitate merging,
653 * options are chained in decreasing order by address. */
654 yySemanticOption
* yynext
;
657 /** Type of the items in the GLR stack. The yyisState field
658 * indicates which item of the union is valid. */
659 union yyGLRStackItem
{
661 yySemanticOption yyoption
;
666 ]b4_locations_if([[ /* To compute the location of the error token. */
667 yyGLRStackItem yyerror_range
[3];]])[
672 YYSTYPE yyval
;]b4_locations_if([[
675 YYJMP_BUF yyexception_buffer
;
676 yyGLRStackItem
* yyitems
;
677 yyGLRStackItem
* yynextFree
;
679 yyGLRState
* yysplitPoint
;
680 yyGLRState
* yylastDeleted
;
681 yyGLRStateSet yytops
;
684 #if YYSTACKEXPANDABLE
685 static void yyexpandGLRStack (yyGLRStack
* yystackp
);
688 static void yyFail (yyGLRStack
* yystackp
]b4_pure_formals
[, const char* yymsg
)
689 __attribute__ ((__noreturn__
));
691 yyFail (yyGLRStack
* yystackp
]b4_pure_formals
[, const char* yymsg
)
693 if (yymsg
!= YY_NULL
)
694 yyerror (]b4_yyerror_args
[yymsg
);
695 YYLONGJMP (yystackp
->yyexception_buffer
, 1);
698 static void yyMemoryExhausted (yyGLRStack
* yystackp
)
699 __attribute__ ((__noreturn__
));
701 yyMemoryExhausted (yyGLRStack
* yystackp
)
703 YYLONGJMP (yystackp
->yyexception_buffer
, 2);
706 #if ]b4_api_PREFIX[DEBUG || YYERROR_VERBOSE
707 /** A printable representation of TOKEN. */
708 static inline const char*
709 yytokenName (yySymbol yytoken
)
711 if (yytoken
== YYEMPTY
)
714 return yytname
[yytoken
];
718 /** Fill in YYVSP[YYLOW1 .. YYLOW0-1] from the chain of states starting
719 * at YYVSP[YYLOW0].yystate.yypred. Leaves YYVSP[YYLOW1].yystate.yypred
720 * containing the pointer to the next state in the chain. */
721 static void yyfillin (yyGLRStackItem
*, int, int) __attribute__ ((__unused__
));
723 yyfillin (yyGLRStackItem
*yyvsp
, int yylow0
, int yylow1
)
726 yyGLRState
*s
= yyvsp
[yylow0
].yystate
.yypred
;
727 for (i
= yylow0
-1; i
>= yylow1
; i
-= 1)
729 #if ]b4_api_PREFIX[DEBUG
730 yyvsp
[i
].yystate
.yylrState
= s
->yylrState
;
732 yyvsp
[i
].yystate
.yyresolved
= s
->yyresolved
;
734 yyvsp
[i
].yystate
.yysemantics
.yysval
= s
->yysemantics
.yysval
;
736 /* The effect of using yysval or yyloc (in an immediate rule) is
738 yyvsp
[i
].yystate
.yysemantics
.yyfirstVal
= YY_NULL
;]b4_locations_if([[
739 yyvsp
[i
].yystate
.yyloc
= s
->yyloc
;]])[
740 s
= yyvsp
[i
].yystate
.yypred
= s
->yypred
;
744 /* Do nothing if YYNORMAL or if *YYLOW <= YYLOW1. Otherwise, fill in
745 * YYVSP[YYLOW1 .. *YYLOW-1] as in yyfillin and set *YYLOW = YYLOW1.
746 * For convenience, always return YYLOW1. */
747 static inline int yyfill (yyGLRStackItem
*, int *, int, yybool
)
748 __attribute__ ((__unused__
));
750 yyfill (yyGLRStackItem
*yyvsp
, int *yylow
, int yylow1
, yybool yynormal
)
752 if (!yynormal
&& yylow1
< *yylow
)
754 yyfillin (yyvsp
, *yylow
, yylow1
);
760 /** Perform user action for rule number YYN, with RHS length YYRHSLEN,
761 * and top stack item YYVSP. YYLVALP points to place to put semantic
762 * value ($$), and yylocp points to place for location information
763 * (@@$). Returns yyok for normal return, yyaccept for YYACCEPT,
764 * yyerr for YYERROR, yyabort for YYABORT. */
766 yyuserAction (yyRuleNum yyn
, int yyrhslen
, yyGLRStackItem
* yyvsp
,
767 yyGLRStack
* yystackp
,
768 YYSTYPE
* yyvalp
]b4_locuser_formals
[)
770 yybool yynormal
__attribute__ ((__unused__
)) =
771 (yystackp
->yysplitPoint
== YY_NULL
);
773 ]b4_parse_param_use([yyvalp
], [yylocp
])dnl
775 # define yyerrok (yystackp->yyerrState = 0)
777 # define YYACCEPT return yyaccept
779 # define YYABORT return yyabort
781 # define YYERROR return yyerrok, yyerr
783 # define YYRECOVERING() (yystackp->yyerrState != 0)
785 # define yyclearin (yychar = YYEMPTY)
787 # define YYFILL(N) yyfill (yyvsp, &yylow, N, yynormal)
789 # define YYBACKUP(Token, Value) \
790 return yyerror (]b4_yyerror_args[YY_("syntax error: cannot back up")), \
795 *yyvalp
= yyval_default
;
797 *yyvalp
= yyvsp
[YYFILL (1-yyrhslen
)].yystate
.yysemantics
.yysval
;]b4_locations_if([[
798 YYLLOC_DEFAULT ((*yylocp
), (yyvsp
- yyrhslen
), yyrhslen
);
799 yystackp
->yyerror_range
[1].yystate
.yyloc
= *yylocp
;
819 yyuserMerge (int yyn
, YYSTYPE
* yy0
, YYSTYPE
* yy1
)
831 /* Bison grammar-table manipulation. */
833 ]b4_yydestruct_define
[
835 /** Number of symbols composing the right hand side of rule #RULE. */
837 yyrhsLength (yyRuleNum yyrule
)
843 yydestroyGLRState (char const *yymsg
, yyGLRState
*yys
]b4_user_formals
[)
846 yydestruct (yymsg
, yystos
[yys
->yylrState
],
847 &yys
->yysemantics
.yysval
]b4_locuser_args([&yys
->yyloc
])[);
850 #if ]b4_api_PREFIX[DEBUG
853 if (yys
->yysemantics
.yyfirstVal
)
854 YYFPRINTF (stderr
, "%s unresolved ", yymsg
);
856 YYFPRINTF (stderr
, "%s incomplete ", yymsg
);
857 yy_symbol_print (stderr
, yystos
[yys
->yylrState
],
858 YY_NULL
]b4_locuser_args([&yys
->yyloc
])[);
859 YYFPRINTF (stderr
, "\n");
863 if (yys
->yysemantics
.yyfirstVal
)
865 yySemanticOption
*yyoption
= yys
->yysemantics
.yyfirstVal
;
868 for (yyrh
= yyoption
->yystate
, yyn
= yyrhsLength (yyoption
->yyrule
);
870 yyrh
= yyrh
->yypred
, yyn
-= 1)
871 yydestroyGLRState (yymsg
, yyrh
]b4_user_args
[);
876 /** Left-hand-side symbol for rule #YYRULE. */
877 static inline yySymbol
878 yylhsNonterm (yyRuleNum yyrule
)
883 #define yypact_value_is_default(Yystate) \
884 ]b4_table_value_equals([[pact]], [[Yystate]], [b4_pact_ninf])[
886 /** True iff LR state YYSTATE has only a default reduction (regardless
889 yyisDefaultedState (yyStateNum yystate
)
891 return yypact_value_is_default (yypact
[yystate
]);
894 /** The default reduction for YYSTATE, assuming it has one. */
895 static inline yyRuleNum
896 yydefaultAction (yyStateNum yystate
)
898 return yydefact
[yystate
];
901 #define yytable_value_is_error(Yytable_value) \
902 ]b4_table_value_equals([[table]], [[Yytable_value]], [b4_table_ninf])[
904 /** Set *YYACTION to the action to take in YYSTATE on seeing YYTOKEN.
906 * R < 0: Reduce on rule -R.
908 * R > 0: Shift to state R.
909 * Set *YYCONFLICTS to a pointer into yyconfl to a 0-terminated list
910 * of conflicting reductions.
913 yygetLRActions (yyStateNum yystate
, int yytoken
,
914 int* yyaction
, const short int** yyconflicts
)
916 int yyindex
= yypact
[yystate
] + yytoken
;
917 if (yypact_value_is_default (yypact
[yystate
])
918 || yyindex
< 0 || YYLAST
< yyindex
|| yycheck
[yyindex
] != yytoken
)
920 *yyaction
= -yydefact
[yystate
];
921 *yyconflicts
= yyconfl
;
923 else if (! yytable_value_is_error (yytable
[yyindex
]))
925 *yyaction
= yytable
[yyindex
];
926 *yyconflicts
= yyconfl
+ yyconflp
[yyindex
];
931 *yyconflicts
= yyconfl
+ yyconflp
[yyindex
];
935 static inline yyStateNum
936 yyLRgotoState (yyStateNum yystate
, yySymbol yylhs
)
938 int yyr
= yypgoto
[yylhs
- YYNTOKENS
] + yystate
;
939 if (0 <= yyr
&& yyr
<= YYLAST
&& yycheck
[yyr
] == yystate
)
942 return yydefgoto
[yylhs
- YYNTOKENS
];
946 yyisShiftAction (int yyaction
)
952 yyisErrorAction (int yyaction
)
954 return yyaction
== 0;
959 /** Return a fresh GLRStackItem in YYSTACKP. The item is an LR state
960 * if YYISSTATE, and otherwise a semantic option. Callers should call
961 * YY_RESERVE_GLRSTACK afterwards to make sure there is sufficient
964 static inline yyGLRStackItem
*
965 yynewGLRStackItem (yyGLRStack
* yystackp
, yybool yyisState
)
967 yyGLRStackItem
* yynewItem
= yystackp
->yynextFree
;
968 yystackp
->yyspaceLeft
-= 1;
969 yystackp
->yynextFree
+= 1;
970 yynewItem
->yystate
.yyisState
= yyisState
;
974 /** Add a new semantic action that will execute the action for rule
975 * YYRULE on the semantic values in YYRHS to the list of
976 * alternative actions for YYSTATE. Assumes that YYRHS comes from
977 * stack #YYK of *YYSTACKP. */
979 yyaddDeferredAction (yyGLRStack
* yystackp
, size_t yyk
, yyGLRState
* yystate
,
980 yyGLRState
* yyrhs
, yyRuleNum yyrule
)
982 yySemanticOption
* yynewOption
=
983 &yynewGLRStackItem (yystackp
, yyfalse
)->yyoption
;
984 yynewOption
->yystate
= yyrhs
;
985 yynewOption
->yyrule
= yyrule
;
986 if (yystackp
->yytops
.yylookaheadNeeds
[yyk
])
988 yynewOption
->yyrawchar
= yychar
;
989 yynewOption
->yyval
= yylval
;]b4_locations_if([
990 yynewOption
->yyloc
= yylloc
;])[
993 yynewOption
->yyrawchar
= YYEMPTY
;
994 yynewOption
->yynext
= yystate
->yysemantics
.yyfirstVal
;
995 yystate
->yysemantics
.yyfirstVal
= yynewOption
;
997 YY_RESERVE_GLRSTACK (yystackp
);
1002 /** Initialize YYSET to a singleton set containing an empty stack. */
1004 yyinitStateSet (yyGLRStateSet
* yyset
)
1007 yyset
->yycapacity
= 16;
1008 yyset
->yystates
= (yyGLRState
**) YYMALLOC (16 * sizeof yyset
->yystates
[0]);
1009 if (! yyset
->yystates
)
1011 yyset
->yystates
[0] = YY_NULL
;
1012 yyset
->yylookaheadNeeds
=
1013 (yybool
*) YYMALLOC (16 * sizeof yyset
->yylookaheadNeeds
[0]);
1014 if (! yyset
->yylookaheadNeeds
)
1016 YYFREE (yyset
->yystates
);
1022 static void yyfreeStateSet (yyGLRStateSet
* yyset
)
1024 YYFREE (yyset
->yystates
);
1025 YYFREE (yyset
->yylookaheadNeeds
);
1028 /** Initialize *YYSTACKP to a single empty stack, with total maximum
1029 * capacity for all stacks of YYSIZE. */
1031 yyinitGLRStack (yyGLRStack
* yystackp
, size_t yysize
)
1033 yystackp
->yyerrState
= 0;
1035 yystackp
->yyspaceLeft
= yysize
;
1037 (yyGLRStackItem
*) YYMALLOC (yysize
* sizeof yystackp
->yynextFree
[0]);
1038 if (!yystackp
->yyitems
)
1040 yystackp
->yynextFree
= yystackp
->yyitems
;
1041 yystackp
->yysplitPoint
= YY_NULL
;
1042 yystackp
->yylastDeleted
= YY_NULL
;
1043 return yyinitStateSet (&yystackp
->yytops
);
1047 #if YYSTACKEXPANDABLE
1048 # define YYRELOC(YYFROMITEMS,YYTOITEMS,YYX,YYTYPE) \
1049 &((YYTOITEMS) - ((YYFROMITEMS) - (yyGLRStackItem*) (YYX)))->YYTYPE
1051 /** If *YYSTACKP is expandable, extend it. WARNING: Pointers into the
1052 stack from outside should be considered invalid after this call.
1053 We always expand when there are 1 or fewer items left AFTER an
1054 allocation, so that we can avoid having external pointers exist
1055 across an allocation. */
1057 yyexpandGLRStack (yyGLRStack
* yystackp
)
1059 yyGLRStackItem
* yynewItems
;
1060 yyGLRStackItem
* yyp0
, *yyp1
;
1063 size_t yysize
= yystackp
->yynextFree
- yystackp
->yyitems
;
1064 if (YYMAXDEPTH
- YYHEADROOM
< yysize
)
1065 yyMemoryExhausted (yystackp
);
1066 yynewSize
= 2*yysize
;
1067 if (YYMAXDEPTH
< yynewSize
)
1068 yynewSize
= YYMAXDEPTH
;
1069 yynewItems
= (yyGLRStackItem
*) YYMALLOC (yynewSize
* sizeof yynewItems
[0]);
1071 yyMemoryExhausted (yystackp
);
1072 for (yyp0
= yystackp
->yyitems
, yyp1
= yynewItems
, yyn
= yysize
;
1074 yyn
-= 1, yyp0
+= 1, yyp1
+= 1)
1077 if (*(yybool
*) yyp0
)
1079 yyGLRState
* yys0
= &yyp0
->yystate
;
1080 yyGLRState
* yys1
= &yyp1
->yystate
;
1081 if (yys0
->yypred
!= YY_NULL
)
1083 YYRELOC (yyp0
, yyp1
, yys0
->yypred
, yystate
);
1084 if (! yys0
->yyresolved
&& yys0
->yysemantics
.yyfirstVal
!= YY_NULL
)
1085 yys1
->yysemantics
.yyfirstVal
=
1086 YYRELOC (yyp0
, yyp1
, yys0
->yysemantics
.yyfirstVal
, yyoption
);
1090 yySemanticOption
* yyv0
= &yyp0
->yyoption
;
1091 yySemanticOption
* yyv1
= &yyp1
->yyoption
;
1092 if (yyv0
->yystate
!= YY_NULL
)
1093 yyv1
->yystate
= YYRELOC (yyp0
, yyp1
, yyv0
->yystate
, yystate
);
1094 if (yyv0
->yynext
!= YY_NULL
)
1095 yyv1
->yynext
= YYRELOC (yyp0
, yyp1
, yyv0
->yynext
, yyoption
);
1098 if (yystackp
->yysplitPoint
!= YY_NULL
)
1099 yystackp
->yysplitPoint
= YYRELOC (yystackp
->yyitems
, yynewItems
,
1100 yystackp
->yysplitPoint
, yystate
);
1102 for (yyn
= 0; yyn
< yystackp
->yytops
.yysize
; yyn
+= 1)
1103 if (yystackp
->yytops
.yystates
[yyn
] != YY_NULL
)
1104 yystackp
->yytops
.yystates
[yyn
] =
1105 YYRELOC (yystackp
->yyitems
, yynewItems
,
1106 yystackp
->yytops
.yystates
[yyn
], yystate
);
1107 YYFREE (yystackp
->yyitems
);
1108 yystackp
->yyitems
= yynewItems
;
1109 yystackp
->yynextFree
= yynewItems
+ yysize
;
1110 yystackp
->yyspaceLeft
= yynewSize
- yysize
;
1115 yyfreeGLRStack (yyGLRStack
* yystackp
)
1117 YYFREE (yystackp
->yyitems
);
1118 yyfreeStateSet (&yystackp
->yytops
);
1121 /** Assuming that YYS is a GLRState somewhere on *YYSTACKP, update the
1122 * splitpoint of *YYSTACKP, if needed, so that it is at least as deep as
1125 yyupdateSplit (yyGLRStack
* yystackp
, yyGLRState
* yys
)
1127 if (yystackp
->yysplitPoint
!= YY_NULL
&& yystackp
->yysplitPoint
> yys
)
1128 yystackp
->yysplitPoint
= yys
;
1131 /** Invalidate stack #YYK in *YYSTACKP. */
1133 yymarkStackDeleted (yyGLRStack
* yystackp
, size_t yyk
)
1135 if (yystackp
->yytops
.yystates
[yyk
] != YY_NULL
)
1136 yystackp
->yylastDeleted
= yystackp
->yytops
.yystates
[yyk
];
1137 yystackp
->yytops
.yystates
[yyk
] = YY_NULL
;
1140 /** Undelete the last stack in *YYSTACKP that was marked as deleted. Can
1141 only be done once after a deletion, and only when all other stacks have
1144 yyundeleteLastStack (yyGLRStack
* yystackp
)
1146 if (yystackp
->yylastDeleted
== YY_NULL
|| yystackp
->yytops
.yysize
!= 0)
1148 yystackp
->yytops
.yystates
[0] = yystackp
->yylastDeleted
;
1149 yystackp
->yytops
.yysize
= 1;
1150 YYDPRINTF ((stderr
, "Restoring last deleted stack as stack #0.\n"));
1151 yystackp
->yylastDeleted
= YY_NULL
;
1155 yyremoveDeletes (yyGLRStack
* yystackp
)
1159 while (yyj
< yystackp
->yytops
.yysize
)
1161 if (yystackp
->yytops
.yystates
[yyi
] == YY_NULL
)
1165 YYDPRINTF ((stderr
, "Removing dead stacks.\n"));
1167 yystackp
->yytops
.yysize
-= 1;
1171 yystackp
->yytops
.yystates
[yyj
] = yystackp
->yytops
.yystates
[yyi
];
1172 /* In the current implementation, it's unnecessary to copy
1173 yystackp->yytops.yylookaheadNeeds[yyi] since, after
1174 yyremoveDeletes returns, the parser immediately either enters
1175 deterministic operation or shifts a token. However, it doesn't
1176 hurt, and the code might evolve to need it. */
1177 yystackp
->yytops
.yylookaheadNeeds
[yyj
] =
1178 yystackp
->yytops
.yylookaheadNeeds
[yyi
];
1181 YYDPRINTF ((stderr
, "Rename stack %lu -> %lu.\n",
1182 (unsigned long int) yyi
, (unsigned long int) yyj
));
1190 /** Shift to a new state on stack #YYK of *YYSTACKP, corresponding to LR
1191 * state YYLRSTATE, at input position YYPOSN, with (resolved) semantic
1192 * value *YYVALP and source location *YYLOCP. */
1194 yyglrShift (yyGLRStack
* yystackp
, size_t yyk
, yyStateNum yylrState
,
1196 YYSTYPE
* yyvalp
]b4_locations_if([, YYLTYPE
* yylocp
])[)
1198 yyGLRState
* yynewState
= &yynewGLRStackItem (yystackp
, yytrue
)->yystate
;
1200 yynewState
->yylrState
= yylrState
;
1201 yynewState
->yyposn
= yyposn
;
1202 yynewState
->yyresolved
= yytrue
;
1203 yynewState
->yypred
= yystackp
->yytops
.yystates
[yyk
];
1204 yynewState
->yysemantics
.yysval
= *yyvalp
;]b4_locations_if([
1205 yynewState
->yyloc
= *yylocp
;])[
1206 yystackp
->yytops
.yystates
[yyk
] = yynewState
;
1208 YY_RESERVE_GLRSTACK (yystackp
);
1211 /** Shift stack #YYK of *YYSTACKP, to a new state corresponding to LR
1212 * state YYLRSTATE, at input position YYPOSN, with the (unresolved)
1213 * semantic value of YYRHS under the action for YYRULE. */
1215 yyglrShiftDefer (yyGLRStack
* yystackp
, size_t yyk
, yyStateNum yylrState
,
1216 size_t yyposn
, yyGLRState
* yyrhs
, yyRuleNum yyrule
)
1218 yyGLRState
* yynewState
= &yynewGLRStackItem (yystackp
, yytrue
)->yystate
;
1220 yynewState
->yylrState
= yylrState
;
1221 yynewState
->yyposn
= yyposn
;
1222 yynewState
->yyresolved
= yyfalse
;
1223 yynewState
->yypred
= yystackp
->yytops
.yystates
[yyk
];
1224 yynewState
->yysemantics
.yyfirstVal
= YY_NULL
;
1225 yystackp
->yytops
.yystates
[yyk
] = yynewState
;
1227 /* Invokes YY_RESERVE_GLRSTACK. */
1228 yyaddDeferredAction (yystackp
, yyk
, yynewState
, yyrhs
, yyrule
);
1231 #if !]b4_api_PREFIX[DEBUG
1232 # define YY_REDUCE_PRINT(Args)
1234 # define YY_REDUCE_PRINT(Args) \
1237 yy_reduce_print Args; \
1240 /*----------------------------------------------------------------------.
1241 | Report that stack #YYK of *YYSTACKP is going to be reduced by YYRULE. |
1242 `----------------------------------------------------------------------*/
1245 yy_reduce_print (int yynormal
, yyGLRStackItem
* yyvsp
, size_t yyk
,
1246 yyRuleNum yyrule
]b4_user_formals
[)
1248 int yynrhs
= yyrhsLength (yyrule
);]b4_locations_if([
1251 YYFPRINTF (stderr
, "Reducing stack %lu by rule %d (line %lu):\n",
1252 (unsigned long int) yyk
, yyrule
- 1,
1253 (unsigned long int) yyrline
[yyrule
]);
1255 yyfillin (yyvsp
, 1, -yynrhs
);
1256 /* The symbols being reduced. */
1257 for (yyi
= 0; yyi
< yynrhs
; yyi
++)
1259 YYFPRINTF (stderr
, " $%d = ", yyi
+ 1);
1260 yy_symbol_print (stderr
,
1261 yystos
[yyvsp
[yyi
- yynrhs
+ 1].yystate
.yylrState
],
1262 &yyvsp
[yyi
- yynrhs
+ 1].yystate
.yysemantics
.yysval
1263 ]b4_locations_if([, &]b4_rhs_location(yynrhs
, yyi
+ 1))[]dnl
1265 if (!yyvsp
[yyi
- yynrhs
+ 1].yystate
.yyresolved
)
1266 YYFPRINTF (stderr
, " (unresolved)");
1267 YYFPRINTF (stderr
, "\n");
1272 /** Pop the symbols consumed by reduction #YYRULE from the top of stack
1273 * #YYK of *YYSTACKP, and perform the appropriate semantic action on their
1274 * semantic values. Assumes that all ambiguities in semantic values
1275 * have been previously resolved. Set *YYVALP to the resulting value,
1276 * and *YYLOCP to the computed location (if any). Return value is as
1277 * for userAction. */
1278 static inline YYRESULTTAG
1279 yydoAction (yyGLRStack
* yystackp
, size_t yyk
, yyRuleNum yyrule
,
1280 YYSTYPE
* yyvalp
]b4_locuser_formals
[)
1282 int yynrhs
= yyrhsLength (yyrule
);
1284 if (yystackp
->yysplitPoint
== YY_NULL
)
1286 /* Standard special case: single stack. */
1287 yyGLRStackItem
* yyrhs
= (yyGLRStackItem
*) yystackp
->yytops
.yystates
[yyk
];
1288 YYASSERT (yyk
== 0);
1289 yystackp
->yynextFree
-= yynrhs
;
1290 yystackp
->yyspaceLeft
+= yynrhs
;
1291 yystackp
->yytops
.yystates
[0] = & yystackp
->yynextFree
[-1].yystate
;
1292 YY_REDUCE_PRINT ((1, yyrhs
, yyk
, yyrule
]b4_user_args
[));
1293 return yyuserAction (yyrule
, yynrhs
, yyrhs
, yystackp
,
1294 yyvalp
]b4_locuser_args
[);
1300 yyGLRStackItem yyrhsVals
[YYMAXRHS
+ YYMAXLEFT
+ 1];
1301 yys
= yyrhsVals
[YYMAXRHS
+ YYMAXLEFT
].yystate
.yypred
1302 = yystackp
->yytops
.yystates
[yyk
];]b4_locations_if([[
1304 /* Set default location. */
1305 yyrhsVals
[YYMAXRHS
+ YYMAXLEFT
- 1].yystate
.yyloc
= yys
->yyloc
;]])[
1306 for (yyi
= 0; yyi
< yynrhs
; yyi
+= 1)
1311 yyupdateSplit (yystackp
, yys
);
1312 yystackp
->yytops
.yystates
[yyk
] = yys
;
1313 YY_REDUCE_PRINT ((0, yyrhsVals
+ YYMAXRHS
+ YYMAXLEFT
- 1, yyk
, yyrule
]b4_user_args
[));
1314 return yyuserAction (yyrule
, yynrhs
, yyrhsVals
+ YYMAXRHS
+ YYMAXLEFT
- 1,
1315 yystackp
, yyvalp
]b4_locuser_args
[);
1319 /** Pop items off stack #YYK of *YYSTACKP according to grammar rule YYRULE,
1320 * and push back on the resulting nonterminal symbol. Perform the
1321 * semantic action associated with YYRULE and store its value with the
1322 * newly pushed state, if YYFORCEEVAL or if *YYSTACKP is currently
1323 * unambiguous. Otherwise, store the deferred semantic action with
1324 * the new state. If the new state would have an identical input
1325 * position, LR state, and predecessor to an existing state on the stack,
1326 * it is identified with that existing state, eliminating stack #YYK from
1327 * *YYSTACKP. In this case, the semantic value is
1328 * added to the options for the existing state's semantic value.
1330 static inline YYRESULTTAG
1331 yyglrReduce (yyGLRStack
* yystackp
, size_t yyk
, yyRuleNum yyrule
,
1332 yybool yyforceEval
]b4_user_formals
[)
1334 size_t yyposn
= yystackp
->yytops
.yystates
[yyk
]->yyposn
;
1336 if (yyforceEval
|| yystackp
->yysplitPoint
== YY_NULL
)
1339 YYSTYPE yysval
;]b4_locations_if([
1342 yyflag
= yydoAction (yystackp
, yyk
, yyrule
, &yysval
]b4_locuser_args([&yyloc
])[);
1343 if (yyflag
== yyerr
&& yystackp
->yysplitPoint
!= YY_NULL
)
1345 YYDPRINTF ((stderr
, "Parse on stack %lu rejected by rule #%d.\n",
1346 (unsigned long int) yyk
, yyrule
- 1));
1350 YY_SYMBOL_PRINT ("-> $$ =", yyr1
[yyrule
], &yysval
, &yyloc
);
1351 yyglrShift (yystackp
, yyk
,
1352 yyLRgotoState (yystackp
->yytops
.yystates
[yyk
]->yylrState
,
1353 yylhsNonterm (yyrule
)),
1354 yyposn
, &yysval
]b4_locations_if([, &yyloc
])[);
1360 yyGLRState
* yys
, *yys0
= yystackp
->yytops
.yystates
[yyk
];
1361 yyStateNum yynewLRState
;
1363 for (yys
= yystackp
->yytops
.yystates
[yyk
], yyn
= yyrhsLength (yyrule
);
1369 yyupdateSplit (yystackp
, yys
);
1370 yynewLRState
= yyLRgotoState (yys
->yylrState
, yylhsNonterm (yyrule
));
1372 "Reduced stack %lu by rule #%d; action deferred. "
1373 "Now in state %d.\n",
1374 (unsigned long int) yyk
, yyrule
- 1, yynewLRState
));
1375 for (yyi
= 0; yyi
< yystackp
->yytops
.yysize
; yyi
+= 1)
1376 if (yyi
!= yyk
&& yystackp
->yytops
.yystates
[yyi
] != YY_NULL
)
1378 yyGLRState
*yysplit
= yystackp
->yysplitPoint
;
1379 yyGLRState
*yyp
= yystackp
->yytops
.yystates
[yyi
];
1380 while (yyp
!= yys
&& yyp
!= yysplit
&& yyp
->yyposn
>= yyposn
)
1382 if (yyp
->yylrState
== yynewLRState
&& yyp
->yypred
== yys
)
1384 yyaddDeferredAction (yystackp
, yyk
, yyp
, yys0
, yyrule
);
1385 yymarkStackDeleted (yystackp
, yyk
);
1386 YYDPRINTF ((stderr
, "Merging stack %lu into stack %lu.\n",
1387 (unsigned long int) yyk
,
1388 (unsigned long int) yyi
));
1394 yystackp
->yytops
.yystates
[yyk
] = yys
;
1395 yyglrShiftDefer (yystackp
, yyk
, yynewLRState
, yyposn
, yys0
, yyrule
);
1401 yysplitStack (yyGLRStack
* yystackp
, size_t yyk
)
1403 if (yystackp
->yysplitPoint
== YY_NULL
)
1405 YYASSERT (yyk
== 0);
1406 yystackp
->yysplitPoint
= yystackp
->yytops
.yystates
[yyk
];
1408 if (yystackp
->yytops
.yysize
>= yystackp
->yytops
.yycapacity
)
1410 yyGLRState
** yynewStates
;
1411 yybool
* yynewLookaheadNeeds
;
1413 yynewStates
= YY_NULL
;
1415 if (yystackp
->yytops
.yycapacity
1416 > (YYSIZEMAX
/ (2 * sizeof yynewStates
[0])))
1417 yyMemoryExhausted (yystackp
);
1418 yystackp
->yytops
.yycapacity
*= 2;
1421 (yyGLRState
**) YYREALLOC (yystackp
->yytops
.yystates
,
1422 (yystackp
->yytops
.yycapacity
1423 * sizeof yynewStates
[0]));
1424 if (yynewStates
== YY_NULL
)
1425 yyMemoryExhausted (yystackp
);
1426 yystackp
->yytops
.yystates
= yynewStates
;
1428 yynewLookaheadNeeds
=
1429 (yybool
*) YYREALLOC (yystackp
->yytops
.yylookaheadNeeds
,
1430 (yystackp
->yytops
.yycapacity
1431 * sizeof yynewLookaheadNeeds
[0]));
1432 if (yynewLookaheadNeeds
== YY_NULL
)
1433 yyMemoryExhausted (yystackp
);
1434 yystackp
->yytops
.yylookaheadNeeds
= yynewLookaheadNeeds
;
1436 yystackp
->yytops
.yystates
[yystackp
->yytops
.yysize
]
1437 = yystackp
->yytops
.yystates
[yyk
];
1438 yystackp
->yytops
.yylookaheadNeeds
[yystackp
->yytops
.yysize
]
1439 = yystackp
->yytops
.yylookaheadNeeds
[yyk
];
1440 yystackp
->yytops
.yysize
+= 1;
1441 return yystackp
->yytops
.yysize
-1;
1444 /** True iff YYY0 and YYY1 represent identical options at the top level.
1445 * That is, they represent the same rule applied to RHS symbols
1446 * that produce the same terminal symbols. */
1448 yyidenticalOptions (yySemanticOption
* yyy0
, yySemanticOption
* yyy1
)
1450 if (yyy0
->yyrule
== yyy1
->yyrule
)
1452 yyGLRState
*yys0
, *yys1
;
1454 for (yys0
= yyy0
->yystate
, yys1
= yyy1
->yystate
,
1455 yyn
= yyrhsLength (yyy0
->yyrule
);
1457 yys0
= yys0
->yypred
, yys1
= yys1
->yypred
, yyn
-= 1)
1458 if (yys0
->yyposn
!= yys1
->yyposn
)
1466 /** Assuming identicalOptions (YYY0,YYY1), destructively merge the
1467 * alternative semantic values for the RHS-symbols of YYY1 and YYY0. */
1469 yymergeOptionSets (yySemanticOption
* yyy0
, yySemanticOption
* yyy1
)
1471 yyGLRState
*yys0
, *yys1
;
1473 for (yys0
= yyy0
->yystate
, yys1
= yyy1
->yystate
,
1474 yyn
= yyrhsLength (yyy0
->yyrule
);
1476 yys0
= yys0
->yypred
, yys1
= yys1
->yypred
, yyn
-= 1)
1480 else if (yys0
->yyresolved
)
1482 yys1
->yyresolved
= yytrue
;
1483 yys1
->yysemantics
.yysval
= yys0
->yysemantics
.yysval
;
1485 else if (yys1
->yyresolved
)
1487 yys0
->yyresolved
= yytrue
;
1488 yys0
->yysemantics
.yysval
= yys1
->yysemantics
.yysval
;
1492 yySemanticOption
** yyz0p
= &yys0
->yysemantics
.yyfirstVal
;
1493 yySemanticOption
* yyz1
= yys1
->yysemantics
.yyfirstVal
;
1496 if (yyz1
== *yyz0p
|| yyz1
== YY_NULL
)
1498 else if (*yyz0p
== YY_NULL
)
1503 else if (*yyz0p
< yyz1
)
1505 yySemanticOption
* yyz
= *yyz0p
;
1507 yyz1
= yyz1
->yynext
;
1508 (*yyz0p
)->yynext
= yyz
;
1510 yyz0p
= &(*yyz0p
)->yynext
;
1512 yys1
->yysemantics
.yyfirstVal
= yys0
->yysemantics
.yyfirstVal
;
1517 /** Y0 and Y1 represent two possible actions to take in a given
1518 * parsing state; return 0 if no combination is possible,
1519 * 1 if user-mergeable, 2 if Y0 is preferred, 3 if Y1 is preferred. */
1521 yypreference (yySemanticOption
* y0
, yySemanticOption
* y1
)
1523 yyRuleNum r0
= y0
->yyrule
, r1
= y1
->yyrule
;
1524 int p0
= yydprec
[r0
], p1
= yydprec
[r1
];
1528 if (yymerger
[r0
] == 0 || yymerger
[r0
] != yymerger
[r1
])
1533 if (p0
== 0 || p1
== 0)
1542 static YYRESULTTAG
yyresolveValue (yyGLRState
* yys
,
1543 yyGLRStack
* yystackp
]b4_user_formals
[);
1546 /** Resolve the previous YYN states starting at and including state YYS
1547 * on *YYSTACKP. If result != yyok, some states may have been left
1548 * unresolved possibly with empty semantic option chains. Regardless
1549 * of whether result = yyok, each state has been left with consistent
1550 * data so that yydestroyGLRState can be invoked if necessary. */
1552 yyresolveStates (yyGLRState
* yys
, int yyn
,
1553 yyGLRStack
* yystackp
]b4_user_formals
[)
1557 YYASSERT (yys
->yypred
);
1558 YYCHK (yyresolveStates (yys
->yypred
, yyn
-1, yystackp
]b4_user_args
[));
1559 if (! yys
->yyresolved
)
1560 YYCHK (yyresolveValue (yys
, yystackp
]b4_user_args
[));
1565 /** Resolve the states for the RHS of YYOPT on *YYSTACKP, perform its
1566 * user action, and return the semantic value and location in *YYVALP
1567 * and *YYLOCP. Regardless of whether result = yyok, all RHS states
1568 * have been destroyed (assuming the user action destroys all RHS
1569 * semantic values if invoked). */
1571 yyresolveAction (yySemanticOption
* yyopt
, yyGLRStack
* yystackp
,
1572 YYSTYPE
* yyvalp
]b4_locuser_formals
[)
1574 yyGLRStackItem yyrhsVals
[YYMAXRHS
+ YYMAXLEFT
+ 1];
1575 int yynrhs
= yyrhsLength (yyopt
->yyrule
);
1576 YYRESULTTAG yyflag
=
1577 yyresolveStates (yyopt
->yystate
, yynrhs
, yystackp
]b4_user_args
[);
1581 for (yys
= yyopt
->yystate
; yynrhs
> 0; yys
= yys
->yypred
, yynrhs
-= 1)
1582 yydestroyGLRState ("Cleanup: popping", yys
]b4_user_args
[);
1586 yyrhsVals
[YYMAXRHS
+ YYMAXLEFT
].yystate
.yypred
= yyopt
->yystate
;]b4_locations_if([[
1588 /* Set default location. */
1589 yyrhsVals
[YYMAXRHS
+ YYMAXLEFT
- 1].yystate
.yyloc
= yyopt
->yystate
->yyloc
;]])[
1591 int yychar_current
= yychar
;
1592 YYSTYPE yylval_current
= yylval
;]b4_locations_if([
1593 YYLTYPE yylloc_current
= yylloc
;])[
1594 yychar
= yyopt
->yyrawchar
;
1595 yylval
= yyopt
->yyval
;]b4_locations_if([
1596 yylloc
= yyopt
->yyloc
;])[
1597 yyflag
= yyuserAction (yyopt
->yyrule
, yynrhs
,
1598 yyrhsVals
+ YYMAXRHS
+ YYMAXLEFT
- 1,
1599 yystackp
, yyvalp
]b4_locuser_args
[);
1600 yychar
= yychar_current
;
1601 yylval
= yylval_current
;]b4_locations_if([
1602 yylloc
= yylloc_current
;])[
1607 #if ]b4_api_PREFIX[DEBUG
1609 yyreportTree (yySemanticOption
* yyx
, int yyindent
)
1611 int yynrhs
= yyrhsLength (yyx
->yyrule
);
1614 yyGLRState
* yystates
[1 + YYMAXRHS
];
1615 yyGLRState yyleftmost_state
;
1617 for (yyi
= yynrhs
, yys
= yyx
->yystate
; 0 < yyi
; yyi
-= 1, yys
= yys
->yypred
)
1618 yystates
[yyi
] = yys
;
1621 yyleftmost_state
.yyposn
= 0;
1622 yystates
[0] = &yyleftmost_state
;
1627 if (yyx
->yystate
->yyposn
< yys
->yyposn
+ 1)
1628 YYFPRINTF (stderr
, "%*s%s -> <Rule %d, empty>\n",
1629 yyindent
, "", yytokenName (yylhsNonterm (yyx
->yyrule
)),
1632 YYFPRINTF (stderr
, "%*s%s -> <Rule %d, tokens %lu .. %lu>\n",
1633 yyindent
, "", yytokenName (yylhsNonterm (yyx
->yyrule
)),
1634 yyx
->yyrule
- 1, (unsigned long int) (yys
->yyposn
+ 1),
1635 (unsigned long int) yyx
->yystate
->yyposn
);
1636 for (yyi
= 1; yyi
<= yynrhs
; yyi
+= 1)
1638 if (yystates
[yyi
]->yyresolved
)
1640 if (yystates
[yyi
-1]->yyposn
+1 > yystates
[yyi
]->yyposn
)
1641 YYFPRINTF (stderr
, "%*s%s <empty>\n", yyindent
+2, "",
1642 yytokenName (yystos
[yystates
[yyi
]->yylrState
]));
1644 YYFPRINTF (stderr
, "%*s%s <tokens %lu .. %lu>\n", yyindent
+2, "",
1645 yytokenName (yystos
[yystates
[yyi
]->yylrState
]),
1646 (unsigned long int) (yystates
[yyi
-1]->yyposn
+ 1),
1647 (unsigned long int) yystates
[yyi
]->yyposn
);
1650 yyreportTree (yystates
[yyi
]->yysemantics
.yyfirstVal
, yyindent
+2);
1656 yyreportAmbiguity (yySemanticOption
* yyx0
,
1657 yySemanticOption
* yyx1
]b4_pure_formals
[)
1662 #if ]b4_api_PREFIX[DEBUG
1663 YYFPRINTF (stderr
, "Ambiguity detected.\n");
1664 YYFPRINTF (stderr
, "Option 1,\n");
1665 yyreportTree (yyx0
, 2);
1666 YYFPRINTF (stderr
, "\nOption 2,\n");
1667 yyreportTree (yyx1
, 2);
1668 YYFPRINTF (stderr
, "\n");
1671 yyerror (]b4_yyerror_args
[YY_("syntax is ambiguous"));
1673 }]b4_locations_if([[
1675 /** Resolve the locations for each of the YYN1 states in *YYSTACKP,
1676 * ending at YYS1. Has no effect on previously resolved states.
1677 * The first semantic option of a state is always chosen. */
1679 yyresolveLocations (yyGLRState
* yys1
, int yyn1
,
1680 yyGLRStack
*yystackp
]b4_user_formals
[)
1684 yyresolveLocations (yys1
->yypred
, yyn1
- 1, yystackp
]b4_user_args
[);
1685 if (!yys1
->yyresolved
)
1687 yyGLRStackItem yyrhsloc
[1 + YYMAXRHS
];
1689 yySemanticOption
*yyoption
= yys1
->yysemantics
.yyfirstVal
;
1690 YYASSERT (yyoption
!= YY_NULL
);
1691 yynrhs
= yyrhsLength (yyoption
->yyrule
);
1696 yyresolveLocations (yyoption
->yystate
, yynrhs
,
1697 yystackp
]b4_user_args
[);
1698 for (yys
= yyoption
->yystate
, yyn
= yynrhs
;
1700 yys
= yys
->yypred
, yyn
-= 1)
1701 yyrhsloc
[yyn
].yystate
.yyloc
= yys
->yyloc
;
1705 /* Both yyresolveAction and yyresolveLocations traverse the GSS
1706 in reverse rightmost order. It is only necessary to invoke
1707 yyresolveLocations on a subforest for which yyresolveAction
1708 would have been invoked next had an ambiguity not been
1709 detected. Thus the location of the previous state (but not
1710 necessarily the previous state itself) is guaranteed to be
1711 resolved already. */
1712 yyGLRState
*yyprevious
= yyoption
->yystate
;
1713 yyrhsloc
[0].yystate
.yyloc
= yyprevious
->yyloc
;
1716 int yychar_current
= yychar
;
1717 YYSTYPE yylval_current
= yylval
;
1718 YYLTYPE yylloc_current
= yylloc
;
1719 yychar
= yyoption
->yyrawchar
;
1720 yylval
= yyoption
->yyval
;
1721 yylloc
= yyoption
->yyloc
;
1722 YYLLOC_DEFAULT ((yys1
->yyloc
), yyrhsloc
, yynrhs
);
1723 yychar
= yychar_current
;
1724 yylval
= yylval_current
;
1725 yylloc
= yylloc_current
;
1731 /** Resolve the ambiguity represented in state YYS in *YYSTACKP,
1732 * perform the indicated actions, and set the semantic value of YYS.
1733 * If result != yyok, the chain of semantic options in YYS has been
1734 * cleared instead or it has been left unmodified except that
1735 * redundant options may have been removed. Regardless of whether
1736 * result = yyok, YYS has been left with consistent data so that
1737 * yydestroyGLRState can be invoked if necessary. */
1739 yyresolveValue (yyGLRState
* yys
, yyGLRStack
* yystackp
]b4_user_formals
[)
1741 yySemanticOption
* yyoptionList
= yys
->yysemantics
.yyfirstVal
;
1742 yySemanticOption
* yybest
= yyoptionList
;
1743 yySemanticOption
** yypp
;
1744 yybool yymerge
= yyfalse
;
1746 YYRESULTTAG yyflag
;]b4_locations_if([
1747 YYLTYPE
*yylocp
= &yys
->yyloc
;])[
1749 for (yypp
= &yyoptionList
->yynext
; *yypp
!= YY_NULL
; )
1751 yySemanticOption
* yyp
= *yypp
;
1753 if (yyidenticalOptions (yybest
, yyp
))
1755 yymergeOptionSets (yybest
, yyp
);
1756 *yypp
= yyp
->yynext
;
1760 switch (yypreference (yybest
, yyp
))
1762 case 0:]b4_locations_if([[
1763 yyresolveLocations (yys
, 1, yystackp
]b4_user_args
[);]])[
1764 return yyreportAmbiguity (yybest
, yyp
]b4_pure_args
[);
1776 /* This cannot happen so it is not worth a YYASSERT (yyfalse),
1777 but some compilers complain if the default case is
1781 yypp
= &yyp
->yynext
;
1787 yySemanticOption
* yyp
;
1788 int yyprec
= yydprec
[yybest
->yyrule
];
1789 yyflag
= yyresolveAction (yybest
, yystackp
, &yysval
]b4_locuser_args
[);
1791 for (yyp
= yybest
->yynext
; yyp
!= YY_NULL
; yyp
= yyp
->yynext
)
1793 if (yyprec
== yydprec
[yyp
->yyrule
])
1795 YYSTYPE yysval_other
;]b4_locations_if([
1797 yyflag
= yyresolveAction (yyp
, yystackp
, &yysval_other
]b4_locuser_args([&yydummy
])[);
1800 yydestruct ("Cleanup: discarding incompletely merged value for",
1801 yystos
[yys
->yylrState
],
1802 &yysval
]b4_locuser_args
[);
1805 yyuserMerge (yymerger
[yyp
->yyrule
], &yysval
, &yysval_other
);
1810 yyflag
= yyresolveAction (yybest
, yystackp
, &yysval
]b4_locuser_args([yylocp
])[);
1814 yys
->yyresolved
= yytrue
;
1815 yys
->yysemantics
.yysval
= yysval
;
1818 yys
->yysemantics
.yyfirstVal
= YY_NULL
;
1823 yyresolveStack (yyGLRStack
* yystackp
]b4_user_formals
[)
1825 if (yystackp
->yysplitPoint
!= YY_NULL
)
1830 for (yyn
= 0, yys
= yystackp
->yytops
.yystates
[0];
1831 yys
!= yystackp
->yysplitPoint
;
1832 yys
= yys
->yypred
, yyn
+= 1)
1834 YYCHK (yyresolveStates (yystackp
->yytops
.yystates
[0], yyn
, yystackp
1841 yycompressStack (yyGLRStack
* yystackp
)
1843 yyGLRState
* yyp
, *yyq
, *yyr
;
1845 if (yystackp
->yytops
.yysize
!= 1 || yystackp
->yysplitPoint
== YY_NULL
)
1848 for (yyp
= yystackp
->yytops
.yystates
[0], yyq
= yyp
->yypred
, yyr
= YY_NULL
;
1849 yyp
!= yystackp
->yysplitPoint
;
1850 yyr
= yyp
, yyp
= yyq
, yyq
= yyp
->yypred
)
1853 yystackp
->yyspaceLeft
+= yystackp
->yynextFree
- yystackp
->yyitems
;
1854 yystackp
->yynextFree
= ((yyGLRStackItem
*) yystackp
->yysplitPoint
) + 1;
1855 yystackp
->yyspaceLeft
-= yystackp
->yynextFree
- yystackp
->yyitems
;
1856 yystackp
->yysplitPoint
= YY_NULL
;
1857 yystackp
->yylastDeleted
= YY_NULL
;
1859 while (yyr
!= YY_NULL
)
1861 yystackp
->yynextFree
->yystate
= *yyr
;
1863 yystackp
->yynextFree
->yystate
.yypred
= &yystackp
->yynextFree
[-1].yystate
;
1864 yystackp
->yytops
.yystates
[0] = &yystackp
->yynextFree
->yystate
;
1865 yystackp
->yynextFree
+= 1;
1866 yystackp
->yyspaceLeft
-= 1;
1871 yyprocessOneStack (yyGLRStack
* yystackp
, size_t yyk
,
1872 size_t yyposn
]b4_pure_formals
[)
1874 while (yystackp
->yytops
.yystates
[yyk
] != YY_NULL
)
1876 yyStateNum yystate
= yystackp
->yytops
.yystates
[yyk
]->yylrState
;
1877 YYDPRINTF ((stderr
, "Stack %lu Entering state %d\n",
1878 (unsigned long int) yyk
, yystate
));
1880 YYASSERT (yystate
!= YYFINAL
);
1882 if (yyisDefaultedState (yystate
))
1885 yyRuleNum yyrule
= yydefaultAction (yystate
);
1888 YYDPRINTF ((stderr
, "Stack %lu dies.\n",
1889 (unsigned long int) yyk
));
1890 yymarkStackDeleted (yystackp
, yyk
);
1893 yyflag
= yyglrReduce (yystackp
, yyk
, yyrule
, yyimmediate
[yyrule
]]b4_user_args
[);
1894 if (yyflag
== yyerr
)
1898 "(predicate failure or explicit user error).\n",
1899 (unsigned long int) yyk
));
1900 yymarkStackDeleted (yystackp
, yyk
);
1910 const short int* yyconflicts
;
1912 yystackp
->yytops
.yylookaheadNeeds
[yyk
] = yytrue
;
1913 if (yychar
== YYEMPTY
)
1915 YYDPRINTF ((stderr
, "Reading a token: "));
1919 if (yychar
<= YYEOF
)
1921 yychar
= yytoken
= YYEOF
;
1922 YYDPRINTF ((stderr
, "Now at end of input.\n"));
1926 yytoken
= YYTRANSLATE (yychar
);
1927 YY_SYMBOL_PRINT ("Next token is", yytoken
, &yylval
, &yylloc
);
1930 yygetLRActions (yystate
, yytoken
, &yyaction
, &yyconflicts
);
1932 while (*yyconflicts
!= 0)
1935 size_t yynewStack
= yysplitStack (yystackp
, yyk
);
1936 YYDPRINTF ((stderr
, "Splitting off stack %lu from %lu.\n",
1937 (unsigned long int) yynewStack
,
1938 (unsigned long int) yyk
));
1939 yyflag
= yyglrReduce (yystackp
, yynewStack
,
1941 yyimmediate
[*yyconflicts
]]b4_user_args
[);
1943 YYCHK (yyprocessOneStack (yystackp
, yynewStack
,
1944 yyposn
]b4_pure_args
[));
1945 else if (yyflag
== yyerr
)
1947 YYDPRINTF ((stderr
, "Stack %lu dies.\n",
1948 (unsigned long int) yynewStack
));
1949 yymarkStackDeleted (yystackp
, yynewStack
);
1956 if (yyisShiftAction (yyaction
))
1958 else if (yyisErrorAction (yyaction
))
1960 YYDPRINTF ((stderr
, "Stack %lu dies.\n",
1961 (unsigned long int) yyk
));
1962 yymarkStackDeleted (yystackp
, yyk
);
1967 YYRESULTTAG yyflag
= yyglrReduce (yystackp
, yyk
, -yyaction
,
1968 yyimmediate
[-yyaction
]]b4_user_args
[);
1969 if (yyflag
== yyerr
)
1973 "(predicate failure or explicit user error).\n",
1974 (unsigned long int) yyk
));
1975 yymarkStackDeleted (yystackp
, yyk
);
1978 else if (yyflag
!= yyok
)
1987 yyreportSyntaxError (yyGLRStack
* yystackp
]b4_user_formals
[)
1989 if (yystackp
->yyerrState
!= 0)
1991 #if ! YYERROR_VERBOSE
1992 yyerror (]b4_lyyerror_args
[YY_("syntax error"));
1995 yySymbol yytoken
= yychar
== YYEMPTY
? YYEMPTY
: YYTRANSLATE (yychar
);
1996 size_t yysize0
= yytnamerr (YY_NULL
, yytokenName (yytoken
));
1997 size_t yysize
= yysize0
;
1998 yybool yysize_overflow
= yyfalse
;
1999 char* yymsg
= YY_NULL
;
2000 enum { YYERROR_VERBOSE_ARGS_MAXIMUM
= 5 };
2001 /* Internationalized format string. */
2002 const char *yyformat
= YY_NULL
;
2003 /* Arguments of yyformat. */
2004 char const *yyarg
[YYERROR_VERBOSE_ARGS_MAXIMUM
];
2005 /* Number of reported tokens (one for the "unexpected", one per
2009 /* There are many possibilities here to consider:
2010 - If this state is a consistent state with a default action, then
2011 the only way this function was invoked is if the default action
2012 is an error action. In that case, don't check for expected
2013 tokens because there are none.
2014 - The only way there can be no lookahead present (in yychar) is if
2015 this state is a consistent state with a default action. Thus,
2016 detecting the absence of a lookahead is sufficient to determine
2017 that there is no unexpected or expected token to report. In that
2018 case, just report a simple "syntax error".
2019 - Don't assume there isn't a lookahead just because this state is a
2020 consistent state with a default action. There might have been a
2021 previous inconsistent state, consistent state with a non-default
2022 action, or user semantic action that manipulated yychar.
2023 - Of course, the expected token list depends on states to have
2024 correct lookahead information, and it depends on the parser not
2025 to perform extra reductions after fetching a lookahead from the
2026 scanner and before detecting a syntax error. Thus, state merging
2027 (from LALR or IELR) and default reductions corrupt the expected
2028 token list. However, the list is correct for canonical LR with
2029 one exception: it will still contain any token that will not be
2030 accepted due to an error action in a later state.
2032 if (yytoken
!= YYEMPTY
)
2034 int yyn
= yypact
[yystackp
->yytops
.yystates
[0]->yylrState
];
2035 yyarg
[yycount
++] = yytokenName (yytoken
);
2036 if (!yypact_value_is_default (yyn
))
2038 /* Start YYX at -YYN if negative to avoid negative indexes in
2039 YYCHECK. In other words, skip the first -YYN actions for this
2040 state because they are default actions. */
2041 int yyxbegin
= yyn
< 0 ? -yyn
: 0;
2042 /* Stay within bounds of both yycheck and yytname. */
2043 int yychecklim
= YYLAST
- yyn
+ 1;
2044 int yyxend
= yychecklim
< YYNTOKENS
? yychecklim
: YYNTOKENS
;
2046 for (yyx
= yyxbegin
; yyx
< yyxend
; ++yyx
)
2047 if (yycheck
[yyx
+ yyn
] == yyx
&& yyx
!= YYTERROR
2048 && !yytable_value_is_error (yytable
[yyx
+ yyn
]))
2050 if (yycount
== YYERROR_VERBOSE_ARGS_MAXIMUM
)
2056 yyarg
[yycount
++] = yytokenName (yyx
);
2058 size_t yysz
= yysize
+ yytnamerr (YY_NULL
, yytokenName (yyx
));
2059 yysize_overflow
|= yysz
< yysize
;
2068 #define YYCASE_(N, S) \
2072 YYCASE_(0, YY_("syntax error"));
2073 YYCASE_(1, YY_("syntax error, unexpected %s"));
2074 YYCASE_(2, YY_("syntax error, unexpected %s, expecting %s"));
2075 YYCASE_(3, YY_("syntax error, unexpected %s, expecting %s or %s"));
2076 YYCASE_(4, YY_("syntax error, unexpected %s, expecting %s or %s or %s"));
2077 YYCASE_(5, YY_("syntax error, unexpected %s, expecting %s or %s or %s or %s"));
2082 size_t yysz
= yysize
+ strlen (yyformat
);
2083 yysize_overflow
|= yysz
< yysize
;
2087 if (!yysize_overflow
)
2088 yymsg
= (char *) YYMALLOC (yysize
);
2094 while ((*yyp
= *yyformat
))
2096 if (*yyp
== '%' && yyformat
[1] == 's' && yyi
< yycount
)
2098 yyp
+= yytnamerr (yyp
, yyarg
[yyi
++]);
2107 yyerror (]b4_lyyerror_args
[yymsg
);
2112 yyerror (]b4_lyyerror_args
[YY_("syntax error"));
2113 yyMemoryExhausted (yystackp
);
2116 #endif /* YYERROR_VERBOSE */
2120 /* Recover from a syntax error on *YYSTACKP, assuming that *YYSTACKP->YYTOKENP,
2121 yylval, and yylloc are the syntactic category, semantic value, and location
2122 of the lookahead. */
2124 yyrecoverSyntaxError (yyGLRStack
* yystackp
]b4_user_formals
[)
2129 if (yystackp
->yyerrState
== 3)
2130 /* We just shifted the error token and (perhaps) took some
2131 reductions. Skip tokens until we can proceed. */
2135 if (yychar
== YYEOF
)
2136 yyFail (yystackp
][]b4_lpure_args
[, YY_NULL
);
2137 if (yychar
!= YYEMPTY
)
2138 {]b4_locations_if([[
2139 /* We throw away the lookahead, but the error range
2140 of the shifted error token must take it into account. */
2141 yyGLRState
*yys
= yystackp
->yytops
.yystates
[0];
2142 yyGLRStackItem yyerror_range
[3];
2143 yyerror_range
[1].yystate
.yyloc
= yys
->yyloc
;
2144 yyerror_range
[2].yystate
.yyloc
= yylloc
;
2145 YYLLOC_DEFAULT ((yys
->yyloc
), yyerror_range
, 2);]])[
2146 yytoken
= YYTRANSLATE (yychar
);
2147 yydestruct ("Error: discarding",
2148 yytoken
, &yylval
]b4_locuser_args([&yylloc
])[);
2150 YYDPRINTF ((stderr
, "Reading a token: "));
2152 if (yychar
<= YYEOF
)
2154 yychar
= yytoken
= YYEOF
;
2155 YYDPRINTF ((stderr
, "Now at end of input.\n"));
2159 yytoken
= YYTRANSLATE (yychar
);
2160 YY_SYMBOL_PRINT ("Next token is", yytoken
, &yylval
, &yylloc
);
2162 yyj
= yypact
[yystackp
->yytops
.yystates
[0]->yylrState
];
2163 if (yypact_value_is_default (yyj
))
2166 if (yyj
< 0 || YYLAST
< yyj
|| yycheck
[yyj
] != yytoken
)
2168 if (yydefact
[yystackp
->yytops
.yystates
[0]->yylrState
] != 0)
2171 else if (! yytable_value_is_error (yytable
[yyj
]))
2175 /* Reduce to one stack. */
2176 for (yyk
= 0; yyk
< yystackp
->yytops
.yysize
; yyk
+= 1)
2177 if (yystackp
->yytops
.yystates
[yyk
] != YY_NULL
)
2179 if (yyk
>= yystackp
->yytops
.yysize
)
2180 yyFail (yystackp
][]b4_lpure_args
[, YY_NULL
);
2181 for (yyk
+= 1; yyk
< yystackp
->yytops
.yysize
; yyk
+= 1)
2182 yymarkStackDeleted (yystackp
, yyk
);
2183 yyremoveDeletes (yystackp
);
2184 yycompressStack (yystackp
);
2186 /* Now pop stack until we find a state that shifts the error token. */
2187 yystackp
->yyerrState
= 3;
2188 while (yystackp
->yytops
.yystates
[0] != YY_NULL
)
2190 yyGLRState
*yys
= yystackp
->yytops
.yystates
[0];
2191 yyj
= yypact
[yys
->yylrState
];
2192 if (! yypact_value_is_default (yyj
))
2195 if (0 <= yyj
&& yyj
<= YYLAST
&& yycheck
[yyj
] == YYTERROR
2196 && yyisShiftAction (yytable
[yyj
]))
2198 /* Shift the error token. */]b4_locations_if([[
2199 /* First adjust its location.*/
2201 yystackp
->yyerror_range
[2].yystate
.yyloc
= yylloc
;
2202 YYLLOC_DEFAULT (yyerrloc
, (yystackp
->yyerror_range
), 2);]])[
2203 YY_SYMBOL_PRINT ("Shifting", yystos
[yytable
[yyj
]],
2204 &yylval
, &yyerrloc
);
2205 yyglrShift (yystackp
, 0, yytable
[yyj
],
2206 yys
->yyposn
, &yylval
]b4_locations_if([, &yyerrloc
])[);
2207 yys
= yystackp
->yytops
.yystates
[0];
2210 }]b4_locations_if([[
2211 yystackp
->yyerror_range
[1].yystate
.yyloc
= yys
->yyloc
;]])[
2212 if (yys
->yypred
!= YY_NULL
)
2213 yydestroyGLRState ("Error: popping", yys
]b4_user_args
[);
2214 yystackp
->yytops
.yystates
[0] = yys
->yypred
;
2215 yystackp
->yynextFree
-= 1;
2216 yystackp
->yyspaceLeft
+= 1;
2218 if (yystackp
->yytops
.yystates
[0] == YY_NULL
)
2219 yyFail (yystackp
][]b4_lpure_args
[, YY_NULL
);
2222 #define YYCHK1(YYE) \
2232 goto yyuser_error; \
2242 ]b4_function_define([yyparse
], [int], b4_parse_param
)[
2246 yyGLRStack
* const yystackp
= &yystack
;
2249 YYDPRINTF ((stderr
, "Starting parse\n"));
2252 yylval
= yyval_default
;]b4_locations_if([
2253 yylloc
= yyloc_default
;])[
2254 ]m4_ifdef([b4_initial_action
], [
2255 b4_dollar_pushdef([yylval
], [], [yylloc
])dnl
2256 /* User initialization code. */
2257 b4_user_initial_action
2258 b4_dollar_popdef
])[]dnl
2260 if (! yyinitGLRStack (yystackp
, YYINITDEPTH
))
2261 goto yyexhaustedlab
;
2262 switch (YYSETJMP (yystack
.yyexception_buffer
))
2265 case 1: goto yyabortlab
;
2266 case 2: goto yyexhaustedlab
;
2267 default: goto yybuglab
;
2269 yyglrShift (&yystack
, 0, 0, 0, &yylval
]b4_locations_if([, &yylloc
])[);
2274 /* For efficiency, we have two loops, the first of which is
2275 specialized to deterministic operation (single stack, no
2276 potential ambiguity). */
2282 const short int* yyconflicts
;
2284 yyStateNum yystate
= yystack
.yytops
.yystates
[0]->yylrState
;
2285 YYDPRINTF ((stderr
, "Entering state %d\n", yystate
));
2286 if (yystate
== YYFINAL
)
2288 if (yyisDefaultedState (yystate
))
2290 yyrule
= yydefaultAction (yystate
);
2293 ]b4_locations_if([[ yystack
.yyerror_range
[1].yystate
.yyloc
= yylloc
;]])[
2294 yyreportSyntaxError (&yystack
]b4_user_args
[);
2297 YYCHK1 (yyglrReduce (&yystack
, 0, yyrule
, yytrue
]b4_user_args
[));
2302 if (yychar
== YYEMPTY
)
2304 YYDPRINTF ((stderr
, "Reading a token: "));
2308 if (yychar
<= YYEOF
)
2310 yychar
= yytoken
= YYEOF
;
2311 YYDPRINTF ((stderr
, "Now at end of input.\n"));
2315 yytoken
= YYTRANSLATE (yychar
);
2316 YY_SYMBOL_PRINT ("Next token is", yytoken
, &yylval
, &yylloc
);
2319 yygetLRActions (yystate
, yytoken
, &yyaction
, &yyconflicts
);
2320 if (*yyconflicts
!= 0)
2322 if (yyisShiftAction (yyaction
))
2324 YY_SYMBOL_PRINT ("Shifting", yytoken
, &yylval
, &yylloc
);
2327 yyglrShift (&yystack
, 0, yyaction
, yyposn
, &yylval
]b4_locations_if([, &yylloc
])[);
2328 if (0 < yystack
.yyerrState
)
2329 yystack
.yyerrState
-= 1;
2331 else if (yyisErrorAction (yyaction
))
2333 ]b4_locations_if([[ yystack
.yyerror_range
[1].yystate
.yyloc
= yylloc
;]])[
2334 yyreportSyntaxError (&yystack
]b4_user_args
[);
2338 YYCHK1 (yyglrReduce (&yystack
, 0, -yyaction
, yytrue
]b4_user_args
[));
2344 yySymbol yytoken_to_shift
;
2347 for (yys
= 0; yys
< yystack
.yytops
.yysize
; yys
+= 1)
2348 yystackp
->yytops
.yylookaheadNeeds
[yys
] = yychar
!= YYEMPTY
;
2350 /* yyprocessOneStack returns one of three things:
2352 - An error flag. If the caller is yyprocessOneStack, it
2353 immediately returns as well. When the caller is finally
2354 yyparse, it jumps to an error label via YYCHK1.
2356 - yyok, but yyprocessOneStack has invoked yymarkStackDeleted
2357 (&yystack, yys), which sets the top state of yys to NULL. Thus,
2358 yyparse's following invocation of yyremoveDeletes will remove
2361 - yyok, when ready to shift a token.
2363 Except in the first case, yyparse will invoke yyremoveDeletes and
2364 then shift the next token onto all remaining stacks. This
2365 synchronization of the shift (that is, after all preceding
2366 reductions on all stacks) helps prevent double destructor calls
2367 on yylval in the event of memory exhaustion. */
2369 for (yys
= 0; yys
< yystack
.yytops
.yysize
; yys
+= 1)
2370 YYCHK1 (yyprocessOneStack (&yystack
, yys
, yyposn
]b4_lpure_args
[));
2371 yyremoveDeletes (&yystack
);
2372 if (yystack
.yytops
.yysize
== 0)
2374 yyundeleteLastStack (&yystack
);
2375 if (yystack
.yytops
.yysize
== 0)
2376 yyFail (&yystack
][]b4_lpure_args
[, YY_("syntax error"));
2377 YYCHK1 (yyresolveStack (&yystack
]b4_user_args
[));
2378 YYDPRINTF ((stderr
, "Returning to deterministic operation.\n"));
2379 ]b4_locations_if([[ yystack
.yyerror_range
[1].yystate
.yyloc
= yylloc
;]])[
2380 yyreportSyntaxError (&yystack
]b4_user_args
[);
2384 /* If any yyglrShift call fails, it will fail after shifting. Thus,
2385 a copy of yylval will already be on stack 0 in the event of a
2386 failure in the following loop. Thus, yychar is set to YYEMPTY
2387 before the loop to make sure the user destructor for yylval isn't
2389 yytoken_to_shift
= YYTRANSLATE (yychar
);
2392 for (yys
= 0; yys
< yystack
.yytops
.yysize
; yys
+= 1)
2395 const short int* yyconflicts
;
2396 yyStateNum yystate
= yystack
.yytops
.yystates
[yys
]->yylrState
;
2397 yygetLRActions (yystate
, yytoken_to_shift
, &yyaction
,
2399 /* Note that yyconflicts were handled by yyprocessOneStack. */
2400 YYDPRINTF ((stderr
, "On stack %lu, ", (unsigned long int) yys
));
2401 YY_SYMBOL_PRINT ("shifting", yytoken_to_shift
, &yylval
, &yylloc
);
2402 yyglrShift (&yystack
, yys
, yyaction
, yyposn
,
2403 &yylval
]b4_locations_if([, &yylloc
])[);
2404 YYDPRINTF ((stderr
, "Stack %lu now in state #%d\n",
2405 (unsigned long int) yys
,
2406 yystack
.yytops
.yystates
[yys
]->yylrState
));
2409 if (yystack
.yytops
.yysize
== 1)
2411 YYCHK1 (yyresolveStack (&yystack
]b4_user_args
[));
2412 YYDPRINTF ((stderr
, "Returning to deterministic operation.\n"));
2413 yycompressStack (&yystack
);
2419 yyrecoverSyntaxError (&yystack
]b4_user_args
[);
2420 yyposn
= yystack
.yytops
.yystates
[0]->yyposn
;
2436 yyerror (]b4_lyyerror_args
[YY_("memory exhausted"));
2441 if (yychar
!= YYEMPTY
)
2442 yydestruct ("Cleanup: discarding lookahead",
2443 YYTRANSLATE (yychar
), &yylval
]b4_locuser_args([&yylloc
])[);
2445 /* If the stack is well-formed, pop the stack until it is empty,
2446 destroying its entries as we go. But free the stack regardless
2447 of whether it is well-formed. */
2448 if (yystack
.yyitems
)
2450 yyGLRState
** yystates
= yystack
.yytops
.yystates
;
2453 size_t yysize
= yystack
.yytops
.yysize
;
2455 for (yyk
= 0; yyk
< yysize
; yyk
+= 1)
2458 while (yystates
[yyk
])
2460 yyGLRState
*yys
= yystates
[yyk
];
2461 ]b4_locations_if([[ yystack
.yyerror_range
[1].yystate
.yyloc
= yys
->yyloc
;]]
2462 )[ if (yys
->yypred
!= YY_NULL
)
2463 yydestroyGLRState ("Cleanup: popping", yys
]b4_user_args
[);
2464 yystates
[yyk
] = yys
->yypred
;
2465 yystack
.yynextFree
-= 1;
2466 yystack
.yyspaceLeft
+= 1;
2471 yyfreeGLRStack (&yystack
);
2477 /* DEBUGGING ONLY */
2478 #if ]b4_api_PREFIX[DEBUG
2480 yy_yypstack (yyGLRState
* yys
)
2484 yy_yypstack (yys
->yypred
);
2485 YYFPRINTF (stderr
, " -> ");
2487 YYFPRINTF (stderr
, "%d@@%lu", yys
->yylrState
,
2488 (unsigned long int) yys
->yyposn
);
2492 yypstates (yyGLRState
* yyst
)
2494 if (yyst
== YY_NULL
)
2495 YYFPRINTF (stderr
, "<null>");
2498 YYFPRINTF (stderr
, "\n");
2502 yypstack (yyGLRStack
* yystackp
, size_t yyk
)
2504 yypstates (yystackp
->yytops
.yystates
[yyk
]);
2507 #define YYINDEX(YYX) \
2508 ((YYX) == YY_NULL ? -1 : (yyGLRStackItem*) (YYX) - yystackp->yyitems)
2512 yypdumpstack (yyGLRStack
* yystackp
)
2514 yyGLRStackItem
* yyp
;
2516 for (yyp
= yystackp
->yyitems
; yyp
< yystackp
->yynextFree
; yyp
+= 1)
2518 YYFPRINTF (stderr
, "%3lu. ",
2519 (unsigned long int) (yyp
- yystackp
->yyitems
));
2520 if (*(yybool
*) yyp
)
2522 YYFPRINTF (stderr
, "Res: %d, LR State: %d, posn: %lu, pred: %ld",
2523 yyp
->yystate
.yyresolved
, yyp
->yystate
.yylrState
,
2524 (unsigned long int) yyp
->yystate
.yyposn
,
2525 (long int) YYINDEX (yyp
->yystate
.yypred
));
2526 if (! yyp
->yystate
.yyresolved
)
2527 YYFPRINTF (stderr
, ", firstVal: %ld",
2528 (long int) YYINDEX (yyp
->yystate
2529 .yysemantics
.yyfirstVal
));
2533 YYFPRINTF (stderr
, "Option. rule: %d, state: %ld, next: %ld",
2534 yyp
->yyoption
.yyrule
- 1,
2535 (long int) YYINDEX (yyp
->yyoption
.yystate
),
2536 (long int) YYINDEX (yyp
->yyoption
.yynext
));
2538 YYFPRINTF (stderr
, "\n");
2540 YYFPRINTF (stderr
, "Tops:");
2541 for (yyi
= 0; yyi
< yystackp
->yytops
.yysize
; yyi
+= 1)
2542 YYFPRINTF (stderr
, "%lu: %ld; ", (unsigned long int) yyi
,
2543 (long int) YYINDEX (yystackp
->yytops
.yystates
[yyi
]));
2544 YYFPRINTF (stderr
, "\n");
2550 #undef yynerrs]b4_locations_if([
2553 m4_if(b4_prefix
, [yy
], [],
2554 [[/* Substitute the variable and function names. */
2555 #define yyparse ]b4_prefix[parse
2556 #define yylex ]b4_prefix[lex
2557 #define yyerror ]b4_prefix[error
2558 #define yylval ]b4_prefix[lval
2559 #define yychar ]b4_prefix[char
2560 #define yydebug ]b4_prefix[debug
2561 #define yynerrs ]b4_prefix[nerrs]b4_locations_if([[
2562 #define yylloc ]b4_prefix[lloc]])])[
2567 # glr.cc produces its own header.
2568 m4_if(b4_skeleton
, ["glr.c"],
2570 [b4_output_begin([b4_spec_defines_file
])
2571 b4_copyright([Skeleton interface
for Bison GLR parsers in C
],
2574 ]b4_cpp_guard_open([b4_spec_defines_file
])[
2575 ]b4_shared_declarations
[
2576 ]b4_cpp_guard_close([b4_spec_defines_file
])[