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
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
, size_t 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
776 # define yyerrok (yystackp->yyerrState = 0)
778 # define YYACCEPT return yyaccept
780 # define YYABORT return yyabort
782 # define YYERROR return yyerrok, yyerr
784 # define YYRECOVERING() (yystackp->yyerrState != 0)
786 # define yyclearin (yychar = YYEMPTY)
788 # define YYFILL(N) yyfill (yyvsp, &yylow, N, yynormal)
790 # define YYBACKUP(Token, Value) \
791 return yyerror (]b4_yyerror_args[YY_("syntax error: cannot back up")), \
796 *yyvalp
= yyval_default
;
798 *yyvalp
= yyvsp
[YYFILL (1-yyrhslen
)].yystate
.yysemantics
.yysval
;]b4_locations_if([[
799 YYLLOC_DEFAULT ((*yylocp
), (yyvsp
- yyrhslen
), yyrhslen
);
800 yystackp
->yyerror_range
[1].yystate
.yyloc
= *yylocp
;
820 yyuserMerge (int yyn
, YYSTYPE
* yy0
, YYSTYPE
* yy1
)
832 /* Bison grammar-table manipulation. */
834 ]b4_yydestruct_define
[
836 /** Number of symbols composing the right hand side of rule #RULE. */
838 yyrhsLength (yyRuleNum yyrule
)
844 yydestroyGLRState (char const *yymsg
, yyGLRState
*yys
]b4_user_formals
[)
847 yydestruct (yymsg
, yystos
[yys
->yylrState
],
848 &yys
->yysemantics
.yysval
]b4_locuser_args([&yys
->yyloc
])[);
851 #if ]b4_api_PREFIX[DEBUG
854 if (yys
->yysemantics
.yyfirstVal
)
855 YYFPRINTF (stderr
, "%s unresolved ", yymsg
);
857 YYFPRINTF (stderr
, "%s incomplete ", yymsg
);
858 yy_symbol_print (stderr
, yystos
[yys
->yylrState
],
859 YY_NULL
]b4_locuser_args([&yys
->yyloc
])[);
860 YYFPRINTF (stderr
, "\n");
864 if (yys
->yysemantics
.yyfirstVal
)
866 yySemanticOption
*yyoption
= yys
->yysemantics
.yyfirstVal
;
869 for (yyrh
= yyoption
->yystate
, yyn
= yyrhsLength (yyoption
->yyrule
);
871 yyrh
= yyrh
->yypred
, yyn
-= 1)
872 yydestroyGLRState (yymsg
, yyrh
]b4_user_args
[);
877 /** Left-hand-side symbol for rule #YYRULE. */
878 static inline yySymbol
879 yylhsNonterm (yyRuleNum yyrule
)
884 #define yypact_value_is_default(Yystate) \
885 ]b4_table_value_equals([[pact]], [[Yystate]], [b4_pact_ninf])[
887 /** True iff LR state YYSTATE has only a default reduction (regardless
890 yyisDefaultedState (yyStateNum yystate
)
892 return yypact_value_is_default (yypact
[yystate
]);
895 /** The default reduction for YYSTATE, assuming it has one. */
896 static inline yyRuleNum
897 yydefaultAction (yyStateNum yystate
)
899 return yydefact
[yystate
];
902 #define yytable_value_is_error(Yytable_value) \
903 ]b4_table_value_equals([[table]], [[Yytable_value]], [b4_table_ninf])[
905 /** Set *YYACTION to the action to take in YYSTATE on seeing YYTOKEN.
907 * R < 0: Reduce on rule -R.
909 * R > 0: Shift to state R.
910 * Set *YYCONFLICTS to a pointer into yyconfl to a 0-terminated list
911 * of conflicting reductions.
914 yygetLRActions (yyStateNum yystate
, int yytoken
,
915 int* yyaction
, const short int** yyconflicts
)
917 int yyindex
= yypact
[yystate
] + yytoken
;
918 if (yypact_value_is_default (yypact
[yystate
])
919 || yyindex
< 0 || YYLAST
< yyindex
|| yycheck
[yyindex
] != yytoken
)
921 *yyaction
= -yydefact
[yystate
];
922 *yyconflicts
= yyconfl
;
924 else if (! yytable_value_is_error (yytable
[yyindex
]))
926 *yyaction
= yytable
[yyindex
];
927 *yyconflicts
= yyconfl
+ yyconflp
[yyindex
];
932 *yyconflicts
= yyconfl
+ yyconflp
[yyindex
];
936 static inline yyStateNum
937 yyLRgotoState (yyStateNum yystate
, yySymbol yylhs
)
939 int yyr
= yypgoto
[yylhs
- YYNTOKENS
] + yystate
;
940 if (0 <= yyr
&& yyr
<= YYLAST
&& yycheck
[yyr
] == yystate
)
943 return yydefgoto
[yylhs
- YYNTOKENS
];
947 yyisShiftAction (int yyaction
)
953 yyisErrorAction (int yyaction
)
955 return yyaction
== 0;
960 /** Return a fresh GLRStackItem in YYSTACKP. The item is an LR state
961 * if YYISSTATE, and otherwise a semantic option. Callers should call
962 * YY_RESERVE_GLRSTACK afterwards to make sure there is sufficient
965 static inline yyGLRStackItem
*
966 yynewGLRStackItem (yyGLRStack
* yystackp
, yybool yyisState
)
968 yyGLRStackItem
* yynewItem
= yystackp
->yynextFree
;
969 yystackp
->yyspaceLeft
-= 1;
970 yystackp
->yynextFree
+= 1;
971 yynewItem
->yystate
.yyisState
= yyisState
;
975 /** Add a new semantic action that will execute the action for rule
976 * YYRULE on the semantic values in YYRHS to the list of
977 * alternative actions for YYSTATE. Assumes that YYRHS comes from
978 * stack #YYK of *YYSTACKP. */
980 yyaddDeferredAction (yyGLRStack
* yystackp
, size_t yyk
, yyGLRState
* yystate
,
981 yyGLRState
* yyrhs
, yyRuleNum yyrule
)
983 yySemanticOption
* yynewOption
=
984 &yynewGLRStackItem (yystackp
, yyfalse
)->yyoption
;
985 yynewOption
->yystate
= yyrhs
;
986 yynewOption
->yyrule
= yyrule
;
987 if (yystackp
->yytops
.yylookaheadNeeds
[yyk
])
989 yynewOption
->yyrawchar
= yychar
;
990 yynewOption
->yyval
= yylval
;]b4_locations_if([
991 yynewOption
->yyloc
= yylloc
;])[
994 yynewOption
->yyrawchar
= YYEMPTY
;
995 yynewOption
->yynext
= yystate
->yysemantics
.yyfirstVal
;
996 yystate
->yysemantics
.yyfirstVal
= yynewOption
;
998 YY_RESERVE_GLRSTACK (yystackp
);
1003 /** Initialize YYSET to a singleton set containing an empty stack. */
1005 yyinitStateSet (yyGLRStateSet
* yyset
)
1008 yyset
->yycapacity
= 16;
1009 yyset
->yystates
= (yyGLRState
**) YYMALLOC (16 * sizeof yyset
->yystates
[0]);
1010 if (! yyset
->yystates
)
1012 yyset
->yystates
[0] = YY_NULL
;
1013 yyset
->yylookaheadNeeds
=
1014 (yybool
*) YYMALLOC (16 * sizeof yyset
->yylookaheadNeeds
[0]);
1015 if (! yyset
->yylookaheadNeeds
)
1017 YYFREE (yyset
->yystates
);
1023 static void yyfreeStateSet (yyGLRStateSet
* yyset
)
1025 YYFREE (yyset
->yystates
);
1026 YYFREE (yyset
->yylookaheadNeeds
);
1029 /** Initialize *YYSTACKP to a single empty stack, with total maximum
1030 * capacity for all stacks of YYSIZE. */
1032 yyinitGLRStack (yyGLRStack
* yystackp
, size_t yysize
)
1034 yystackp
->yyerrState
= 0;
1036 yystackp
->yyspaceLeft
= yysize
;
1038 (yyGLRStackItem
*) YYMALLOC (yysize
* sizeof yystackp
->yynextFree
[0]);
1039 if (!yystackp
->yyitems
)
1041 yystackp
->yynextFree
= yystackp
->yyitems
;
1042 yystackp
->yysplitPoint
= YY_NULL
;
1043 yystackp
->yylastDeleted
= YY_NULL
;
1044 return yyinitStateSet (&yystackp
->yytops
);
1048 #if YYSTACKEXPANDABLE
1049 # define YYRELOC(YYFROMITEMS,YYTOITEMS,YYX,YYTYPE) \
1050 &((YYTOITEMS) - ((YYFROMITEMS) - (yyGLRStackItem*) (YYX)))->YYTYPE
1052 /** If *YYSTACKP is expandable, extend it. WARNING: Pointers into the
1053 stack from outside should be considered invalid after this call.
1054 We always expand when there are 1 or fewer items left AFTER an
1055 allocation, so that we can avoid having external pointers exist
1056 across an allocation. */
1058 yyexpandGLRStack (yyGLRStack
* yystackp
)
1060 yyGLRStackItem
* yynewItems
;
1061 yyGLRStackItem
* yyp0
, *yyp1
;
1064 size_t yysize
= yystackp
->yynextFree
- yystackp
->yyitems
;
1065 if (YYMAXDEPTH
- YYHEADROOM
< yysize
)
1066 yyMemoryExhausted (yystackp
);
1067 yynewSize
= 2*yysize
;
1068 if (YYMAXDEPTH
< yynewSize
)
1069 yynewSize
= YYMAXDEPTH
;
1070 yynewItems
= (yyGLRStackItem
*) YYMALLOC (yynewSize
* sizeof yynewItems
[0]);
1072 yyMemoryExhausted (yystackp
);
1073 for (yyp0
= yystackp
->yyitems
, yyp1
= yynewItems
, yyn
= yysize
;
1075 yyn
-= 1, yyp0
+= 1, yyp1
+= 1)
1078 if (*(yybool
*) yyp0
)
1080 yyGLRState
* yys0
= &yyp0
->yystate
;
1081 yyGLRState
* yys1
= &yyp1
->yystate
;
1082 if (yys0
->yypred
!= YY_NULL
)
1084 YYRELOC (yyp0
, yyp1
, yys0
->yypred
, yystate
);
1085 if (! yys0
->yyresolved
&& yys0
->yysemantics
.yyfirstVal
!= YY_NULL
)
1086 yys1
->yysemantics
.yyfirstVal
=
1087 YYRELOC (yyp0
, yyp1
, yys0
->yysemantics
.yyfirstVal
, yyoption
);
1091 yySemanticOption
* yyv0
= &yyp0
->yyoption
;
1092 yySemanticOption
* yyv1
= &yyp1
->yyoption
;
1093 if (yyv0
->yystate
!= YY_NULL
)
1094 yyv1
->yystate
= YYRELOC (yyp0
, yyp1
, yyv0
->yystate
, yystate
);
1095 if (yyv0
->yynext
!= YY_NULL
)
1096 yyv1
->yynext
= YYRELOC (yyp0
, yyp1
, yyv0
->yynext
, yyoption
);
1099 if (yystackp
->yysplitPoint
!= YY_NULL
)
1100 yystackp
->yysplitPoint
= YYRELOC (yystackp
->yyitems
, yynewItems
,
1101 yystackp
->yysplitPoint
, yystate
);
1103 for (yyn
= 0; yyn
< yystackp
->yytops
.yysize
; yyn
+= 1)
1104 if (yystackp
->yytops
.yystates
[yyn
] != YY_NULL
)
1105 yystackp
->yytops
.yystates
[yyn
] =
1106 YYRELOC (yystackp
->yyitems
, yynewItems
,
1107 yystackp
->yytops
.yystates
[yyn
], yystate
);
1108 YYFREE (yystackp
->yyitems
);
1109 yystackp
->yyitems
= yynewItems
;
1110 yystackp
->yynextFree
= yynewItems
+ yysize
;
1111 yystackp
->yyspaceLeft
= yynewSize
- yysize
;
1116 yyfreeGLRStack (yyGLRStack
* yystackp
)
1118 YYFREE (yystackp
->yyitems
);
1119 yyfreeStateSet (&yystackp
->yytops
);
1122 /** Assuming that YYS is a GLRState somewhere on *YYSTACKP, update the
1123 * splitpoint of *YYSTACKP, if needed, so that it is at least as deep as
1126 yyupdateSplit (yyGLRStack
* yystackp
, yyGLRState
* yys
)
1128 if (yystackp
->yysplitPoint
!= YY_NULL
&& yystackp
->yysplitPoint
> yys
)
1129 yystackp
->yysplitPoint
= yys
;
1132 /** Invalidate stack #YYK in *YYSTACKP. */
1134 yymarkStackDeleted (yyGLRStack
* yystackp
, size_t yyk
)
1136 if (yystackp
->yytops
.yystates
[yyk
] != YY_NULL
)
1137 yystackp
->yylastDeleted
= yystackp
->yytops
.yystates
[yyk
];
1138 yystackp
->yytops
.yystates
[yyk
] = YY_NULL
;
1141 /** Undelete the last stack in *YYSTACKP that was marked as deleted. Can
1142 only be done once after a deletion, and only when all other stacks have
1145 yyundeleteLastStack (yyGLRStack
* yystackp
)
1147 if (yystackp
->yylastDeleted
== YY_NULL
|| yystackp
->yytops
.yysize
!= 0)
1149 yystackp
->yytops
.yystates
[0] = yystackp
->yylastDeleted
;
1150 yystackp
->yytops
.yysize
= 1;
1151 YYDPRINTF ((stderr
, "Restoring last deleted stack as stack #0.\n"));
1152 yystackp
->yylastDeleted
= YY_NULL
;
1156 yyremoveDeletes (yyGLRStack
* yystackp
)
1160 while (yyj
< yystackp
->yytops
.yysize
)
1162 if (yystackp
->yytops
.yystates
[yyi
] == YY_NULL
)
1166 YYDPRINTF ((stderr
, "Removing dead stacks.\n"));
1168 yystackp
->yytops
.yysize
-= 1;
1172 yystackp
->yytops
.yystates
[yyj
] = yystackp
->yytops
.yystates
[yyi
];
1173 /* In the current implementation, it's unnecessary to copy
1174 yystackp->yytops.yylookaheadNeeds[yyi] since, after
1175 yyremoveDeletes returns, the parser immediately either enters
1176 deterministic operation or shifts a token. However, it doesn't
1177 hurt, and the code might evolve to need it. */
1178 yystackp
->yytops
.yylookaheadNeeds
[yyj
] =
1179 yystackp
->yytops
.yylookaheadNeeds
[yyi
];
1182 YYDPRINTF ((stderr
, "Rename stack %lu -> %lu.\n",
1183 (unsigned long int) yyi
, (unsigned long int) yyj
));
1191 /** Shift to a new state on stack #YYK of *YYSTACKP, corresponding to LR
1192 * state YYLRSTATE, at input position YYPOSN, with (resolved) semantic
1193 * value *YYVALP and source location *YYLOCP. */
1195 yyglrShift (yyGLRStack
* yystackp
, size_t yyk
, yyStateNum yylrState
,
1197 YYSTYPE
* yyvalp
]b4_locations_if([, YYLTYPE
* yylocp
])[)
1199 yyGLRState
* yynewState
= &yynewGLRStackItem (yystackp
, yytrue
)->yystate
;
1201 yynewState
->yylrState
= yylrState
;
1202 yynewState
->yyposn
= yyposn
;
1203 yynewState
->yyresolved
= yytrue
;
1204 yynewState
->yypred
= yystackp
->yytops
.yystates
[yyk
];
1205 yynewState
->yysemantics
.yysval
= *yyvalp
;]b4_locations_if([
1206 yynewState
->yyloc
= *yylocp
;])[
1207 yystackp
->yytops
.yystates
[yyk
] = yynewState
;
1209 YY_RESERVE_GLRSTACK (yystackp
);
1212 /** Shift stack #YYK of *YYSTACKP, to a new state corresponding to LR
1213 * state YYLRSTATE, at input position YYPOSN, with the (unresolved)
1214 * semantic value of YYRHS under the action for YYRULE. */
1216 yyglrShiftDefer (yyGLRStack
* yystackp
, size_t yyk
, yyStateNum yylrState
,
1217 size_t yyposn
, yyGLRState
* yyrhs
, yyRuleNum yyrule
)
1219 yyGLRState
* yynewState
= &yynewGLRStackItem (yystackp
, yytrue
)->yystate
;
1221 yynewState
->yylrState
= yylrState
;
1222 yynewState
->yyposn
= yyposn
;
1223 yynewState
->yyresolved
= yyfalse
;
1224 yynewState
->yypred
= yystackp
->yytops
.yystates
[yyk
];
1225 yynewState
->yysemantics
.yyfirstVal
= YY_NULL
;
1226 yystackp
->yytops
.yystates
[yyk
] = yynewState
;
1228 /* Invokes YY_RESERVE_GLRSTACK. */
1229 yyaddDeferredAction (yystackp
, yyk
, yynewState
, yyrhs
, yyrule
);
1232 #if !]b4_api_PREFIX[DEBUG
1233 # define YY_REDUCE_PRINT(Args)
1235 # define YY_REDUCE_PRINT(Args) \
1238 yy_reduce_print Args; \
1241 /*----------------------------------------------------------------------.
1242 | Report that stack #YYK of *YYSTACKP is going to be reduced by YYRULE. |
1243 `----------------------------------------------------------------------*/
1246 yy_reduce_print (int yynormal
, yyGLRStackItem
* yyvsp
, size_t yyk
,
1247 yyRuleNum yyrule
]b4_user_formals
[)
1249 int yynrhs
= yyrhsLength (yyrule
);]b4_locations_if([
1252 YYFPRINTF (stderr
, "Reducing stack %lu by rule %d (line %lu):\n",
1253 (unsigned long int) yyk
, yyrule
- 1,
1254 (unsigned long int) yyrline
[yyrule
]);
1256 yyfillin (yyvsp
, 1, -yynrhs
);
1257 /* The symbols being reduced. */
1258 for (yyi
= 0; yyi
< yynrhs
; yyi
++)
1260 YYFPRINTF (stderr
, " $%d = ", yyi
+ 1);
1261 yy_symbol_print (stderr
,
1262 yystos
[yyvsp
[yyi
- yynrhs
+ 1].yystate
.yylrState
],
1263 &yyvsp
[yyi
- yynrhs
+ 1].yystate
.yysemantics
.yysval
1264 ]b4_locations_if([, &]b4_rhs_location(yynrhs
, yyi
+ 1))[]dnl
1266 if (!yyvsp
[yyi
- yynrhs
+ 1].yystate
.yyresolved
)
1267 YYFPRINTF (stderr
, " (unresolved)");
1268 YYFPRINTF (stderr
, "\n");
1273 /** Pop the symbols consumed by reduction #YYRULE from the top of stack
1274 * #YYK of *YYSTACKP, and perform the appropriate semantic action on their
1275 * semantic values. Assumes that all ambiguities in semantic values
1276 * have been previously resolved. Set *YYVALP to the resulting value,
1277 * and *YYLOCP to the computed location (if any). Return value is as
1278 * for userAction. */
1279 static inline YYRESULTTAG
1280 yydoAction (yyGLRStack
* yystackp
, size_t yyk
, yyRuleNum yyrule
,
1281 YYSTYPE
* yyvalp
]b4_locuser_formals
[)
1283 int yynrhs
= yyrhsLength (yyrule
);
1285 if (yystackp
->yysplitPoint
== YY_NULL
)
1287 /* Standard special case: single stack. */
1288 yyGLRStackItem
* yyrhs
= (yyGLRStackItem
*) yystackp
->yytops
.yystates
[yyk
];
1289 YYASSERT (yyk
== 0);
1290 yystackp
->yynextFree
-= yynrhs
;
1291 yystackp
->yyspaceLeft
+= yynrhs
;
1292 yystackp
->yytops
.yystates
[0] = & yystackp
->yynextFree
[-1].yystate
;
1293 YY_REDUCE_PRINT ((1, yyrhs
, yyk
, yyrule
]b4_user_args
[));
1294 return yyuserAction (yyrule
, yynrhs
, yyrhs
, yystackp
,
1295 yyvalp
]b4_locuser_args
[);
1301 yyGLRStackItem yyrhsVals
[YYMAXRHS
+ YYMAXLEFT
+ 1];
1302 yys
= yyrhsVals
[YYMAXRHS
+ YYMAXLEFT
].yystate
.yypred
1303 = yystackp
->yytops
.yystates
[yyk
];]b4_locations_if([[
1305 /* Set default location. */
1306 yyrhsVals
[YYMAXRHS
+ YYMAXLEFT
- 1].yystate
.yyloc
= yys
->yyloc
;]])[
1307 for (yyi
= 0; yyi
< yynrhs
; yyi
+= 1)
1312 yyupdateSplit (yystackp
, yys
);
1313 yystackp
->yytops
.yystates
[yyk
] = yys
;
1314 YY_REDUCE_PRINT ((0, yyrhsVals
+ YYMAXRHS
+ YYMAXLEFT
- 1, yyk
, yyrule
]b4_user_args
[));
1315 return yyuserAction (yyrule
, yynrhs
, yyrhsVals
+ YYMAXRHS
+ YYMAXLEFT
- 1,
1316 yystackp
, yyvalp
]b4_locuser_args
[);
1320 /** Pop items off stack #YYK of *YYSTACKP according to grammar rule YYRULE,
1321 * and push back on the resulting nonterminal symbol. Perform the
1322 * semantic action associated with YYRULE and store its value with the
1323 * newly pushed state, if YYFORCEEVAL or if *YYSTACKP is currently
1324 * unambiguous. Otherwise, store the deferred semantic action with
1325 * the new state. If the new state would have an identical input
1326 * position, LR state, and predecessor to an existing state on the stack,
1327 * it is identified with that existing state, eliminating stack #YYK from
1328 * *YYSTACKP. In this case, the semantic value is
1329 * added to the options for the existing state's semantic value.
1331 static inline YYRESULTTAG
1332 yyglrReduce (yyGLRStack
* yystackp
, size_t yyk
, yyRuleNum yyrule
,
1333 yybool yyforceEval
]b4_user_formals
[)
1335 size_t yyposn
= yystackp
->yytops
.yystates
[yyk
]->yyposn
;
1337 if (yyforceEval
|| yystackp
->yysplitPoint
== YY_NULL
)
1340 YYSTYPE yysval
;]b4_locations_if([
1343 yyflag
= yydoAction (yystackp
, yyk
, yyrule
, &yysval
]b4_locuser_args([&yyloc
])[);
1344 if (yyflag
== yyerr
&& yystackp
->yysplitPoint
!= YY_NULL
)
1346 YYDPRINTF ((stderr
, "Parse on stack %lu rejected by rule #%d.\n",
1347 (unsigned long int) yyk
, yyrule
- 1));
1351 YY_SYMBOL_PRINT ("-> $$ =", yyr1
[yyrule
], &yysval
, &yyloc
);
1352 yyglrShift (yystackp
, yyk
,
1353 yyLRgotoState (yystackp
->yytops
.yystates
[yyk
]->yylrState
,
1354 yylhsNonterm (yyrule
)),
1355 yyposn
, &yysval
]b4_locations_if([, &yyloc
])[);
1361 yyGLRState
* yys
, *yys0
= yystackp
->yytops
.yystates
[yyk
];
1362 yyStateNum yynewLRState
;
1364 for (yys
= yystackp
->yytops
.yystates
[yyk
], yyn
= yyrhsLength (yyrule
);
1370 yyupdateSplit (yystackp
, yys
);
1371 yynewLRState
= yyLRgotoState (yys
->yylrState
, yylhsNonterm (yyrule
));
1373 "Reduced stack %lu by rule #%d; action deferred. "
1374 "Now in state %d.\n",
1375 (unsigned long int) yyk
, yyrule
- 1, yynewLRState
));
1376 for (yyi
= 0; yyi
< yystackp
->yytops
.yysize
; yyi
+= 1)
1377 if (yyi
!= yyk
&& yystackp
->yytops
.yystates
[yyi
] != YY_NULL
)
1379 yyGLRState
*yysplit
= yystackp
->yysplitPoint
;
1380 yyGLRState
*yyp
= yystackp
->yytops
.yystates
[yyi
];
1381 while (yyp
!= yys
&& yyp
!= yysplit
&& yyp
->yyposn
>= yyposn
)
1383 if (yyp
->yylrState
== yynewLRState
&& yyp
->yypred
== yys
)
1385 yyaddDeferredAction (yystackp
, yyk
, yyp
, yys0
, yyrule
);
1386 yymarkStackDeleted (yystackp
, yyk
);
1387 YYDPRINTF ((stderr
, "Merging stack %lu into stack %lu.\n",
1388 (unsigned long int) yyk
,
1389 (unsigned long int) yyi
));
1395 yystackp
->yytops
.yystates
[yyk
] = yys
;
1396 yyglrShiftDefer (yystackp
, yyk
, yynewLRState
, yyposn
, yys0
, yyrule
);
1402 yysplitStack (yyGLRStack
* yystackp
, size_t yyk
)
1404 if (yystackp
->yysplitPoint
== YY_NULL
)
1406 YYASSERT (yyk
== 0);
1407 yystackp
->yysplitPoint
= yystackp
->yytops
.yystates
[yyk
];
1409 if (yystackp
->yytops
.yysize
>= yystackp
->yytops
.yycapacity
)
1411 yyGLRState
** yynewStates
;
1412 yybool
* yynewLookaheadNeeds
;
1414 yynewStates
= YY_NULL
;
1416 if (yystackp
->yytops
.yycapacity
1417 > (YYSIZEMAX
/ (2 * sizeof yynewStates
[0])))
1418 yyMemoryExhausted (yystackp
);
1419 yystackp
->yytops
.yycapacity
*= 2;
1422 (yyGLRState
**) YYREALLOC (yystackp
->yytops
.yystates
,
1423 (yystackp
->yytops
.yycapacity
1424 * sizeof yynewStates
[0]));
1425 if (yynewStates
== YY_NULL
)
1426 yyMemoryExhausted (yystackp
);
1427 yystackp
->yytops
.yystates
= yynewStates
;
1429 yynewLookaheadNeeds
=
1430 (yybool
*) YYREALLOC (yystackp
->yytops
.yylookaheadNeeds
,
1431 (yystackp
->yytops
.yycapacity
1432 * sizeof yynewLookaheadNeeds
[0]));
1433 if (yynewLookaheadNeeds
== YY_NULL
)
1434 yyMemoryExhausted (yystackp
);
1435 yystackp
->yytops
.yylookaheadNeeds
= yynewLookaheadNeeds
;
1437 yystackp
->yytops
.yystates
[yystackp
->yytops
.yysize
]
1438 = yystackp
->yytops
.yystates
[yyk
];
1439 yystackp
->yytops
.yylookaheadNeeds
[yystackp
->yytops
.yysize
]
1440 = yystackp
->yytops
.yylookaheadNeeds
[yyk
];
1441 yystackp
->yytops
.yysize
+= 1;
1442 return yystackp
->yytops
.yysize
-1;
1445 /** True iff YYY0 and YYY1 represent identical options at the top level.
1446 * That is, they represent the same rule applied to RHS symbols
1447 * that produce the same terminal symbols. */
1449 yyidenticalOptions (yySemanticOption
* yyy0
, yySemanticOption
* yyy1
)
1451 if (yyy0
->yyrule
== yyy1
->yyrule
)
1453 yyGLRState
*yys0
, *yys1
;
1455 for (yys0
= yyy0
->yystate
, yys1
= yyy1
->yystate
,
1456 yyn
= yyrhsLength (yyy0
->yyrule
);
1458 yys0
= yys0
->yypred
, yys1
= yys1
->yypred
, yyn
-= 1)
1459 if (yys0
->yyposn
!= yys1
->yyposn
)
1467 /** Assuming identicalOptions (YYY0,YYY1), destructively merge the
1468 * alternative semantic values for the RHS-symbols of YYY1 and YYY0. */
1470 yymergeOptionSets (yySemanticOption
* yyy0
, yySemanticOption
* yyy1
)
1472 yyGLRState
*yys0
, *yys1
;
1474 for (yys0
= yyy0
->yystate
, yys1
= yyy1
->yystate
,
1475 yyn
= yyrhsLength (yyy0
->yyrule
);
1477 yys0
= yys0
->yypred
, yys1
= yys1
->yypred
, yyn
-= 1)
1481 else if (yys0
->yyresolved
)
1483 yys1
->yyresolved
= yytrue
;
1484 yys1
->yysemantics
.yysval
= yys0
->yysemantics
.yysval
;
1486 else if (yys1
->yyresolved
)
1488 yys0
->yyresolved
= yytrue
;
1489 yys0
->yysemantics
.yysval
= yys1
->yysemantics
.yysval
;
1493 yySemanticOption
** yyz0p
= &yys0
->yysemantics
.yyfirstVal
;
1494 yySemanticOption
* yyz1
= yys1
->yysemantics
.yyfirstVal
;
1497 if (yyz1
== *yyz0p
|| yyz1
== YY_NULL
)
1499 else if (*yyz0p
== YY_NULL
)
1504 else if (*yyz0p
< yyz1
)
1506 yySemanticOption
* yyz
= *yyz0p
;
1508 yyz1
= yyz1
->yynext
;
1509 (*yyz0p
)->yynext
= yyz
;
1511 yyz0p
= &(*yyz0p
)->yynext
;
1513 yys1
->yysemantics
.yyfirstVal
= yys0
->yysemantics
.yyfirstVal
;
1518 /** Y0 and Y1 represent two possible actions to take in a given
1519 * parsing state; return 0 if no combination is possible,
1520 * 1 if user-mergeable, 2 if Y0 is preferred, 3 if Y1 is preferred. */
1522 yypreference (yySemanticOption
* y0
, yySemanticOption
* y1
)
1524 yyRuleNum r0
= y0
->yyrule
, r1
= y1
->yyrule
;
1525 int p0
= yydprec
[r0
], p1
= yydprec
[r1
];
1529 if (yymerger
[r0
] == 0 || yymerger
[r0
] != yymerger
[r1
])
1534 if (p0
== 0 || p1
== 0)
1543 static YYRESULTTAG
yyresolveValue (yyGLRState
* yys
,
1544 yyGLRStack
* yystackp
]b4_user_formals
[);
1547 /** Resolve the previous YYN states starting at and including state YYS
1548 * on *YYSTACKP. If result != yyok, some states may have been left
1549 * unresolved possibly with empty semantic option chains. Regardless
1550 * of whether result = yyok, each state has been left with consistent
1551 * data so that yydestroyGLRState can be invoked if necessary. */
1553 yyresolveStates (yyGLRState
* yys
, int yyn
,
1554 yyGLRStack
* yystackp
]b4_user_formals
[)
1558 YYASSERT (yys
->yypred
);
1559 YYCHK (yyresolveStates (yys
->yypred
, yyn
-1, yystackp
]b4_user_args
[));
1560 if (! yys
->yyresolved
)
1561 YYCHK (yyresolveValue (yys
, yystackp
]b4_user_args
[));
1566 /** Resolve the states for the RHS of YYOPT on *YYSTACKP, perform its
1567 * user action, and return the semantic value and location in *YYVALP
1568 * and *YYLOCP. Regardless of whether result = yyok, all RHS states
1569 * have been destroyed (assuming the user action destroys all RHS
1570 * semantic values if invoked). */
1572 yyresolveAction (yySemanticOption
* yyopt
, yyGLRStack
* yystackp
,
1573 YYSTYPE
* yyvalp
]b4_locuser_formals
[)
1575 yyGLRStackItem yyrhsVals
[YYMAXRHS
+ YYMAXLEFT
+ 1];
1576 int yynrhs
= yyrhsLength (yyopt
->yyrule
);
1577 YYRESULTTAG yyflag
=
1578 yyresolveStates (yyopt
->yystate
, yynrhs
, yystackp
]b4_user_args
[);
1582 for (yys
= yyopt
->yystate
; yynrhs
> 0; yys
= yys
->yypred
, yynrhs
-= 1)
1583 yydestroyGLRState ("Cleanup: popping", yys
]b4_user_args
[);
1587 yyrhsVals
[YYMAXRHS
+ YYMAXLEFT
].yystate
.yypred
= yyopt
->yystate
;]b4_locations_if([[
1589 /* Set default location. */
1590 yyrhsVals
[YYMAXRHS
+ YYMAXLEFT
- 1].yystate
.yyloc
= yyopt
->yystate
->yyloc
;]])[
1592 int yychar_current
= yychar
;
1593 YYSTYPE yylval_current
= yylval
;]b4_locations_if([
1594 YYLTYPE yylloc_current
= yylloc
;])[
1595 yychar
= yyopt
->yyrawchar
;
1596 yylval
= yyopt
->yyval
;]b4_locations_if([
1597 yylloc
= yyopt
->yyloc
;])[
1598 yyflag
= yyuserAction (yyopt
->yyrule
, yynrhs
,
1599 yyrhsVals
+ YYMAXRHS
+ YYMAXLEFT
- 1,
1600 yystackp
, yyvalp
]b4_locuser_args
[);
1601 yychar
= yychar_current
;
1602 yylval
= yylval_current
;]b4_locations_if([
1603 yylloc
= yylloc_current
;])[
1608 #if ]b4_api_PREFIX[DEBUG
1610 yyreportTree (yySemanticOption
* yyx
, int yyindent
)
1612 int yynrhs
= yyrhsLength (yyx
->yyrule
);
1615 yyGLRState
* yystates
[1 + YYMAXRHS
];
1616 yyGLRState yyleftmost_state
;
1618 for (yyi
= yynrhs
, yys
= yyx
->yystate
; 0 < yyi
; yyi
-= 1, yys
= yys
->yypred
)
1619 yystates
[yyi
] = yys
;
1622 yyleftmost_state
.yyposn
= 0;
1623 yystates
[0] = &yyleftmost_state
;
1628 if (yyx
->yystate
->yyposn
< yys
->yyposn
+ 1)
1629 YYFPRINTF (stderr
, "%*s%s -> <Rule %d, empty>\n",
1630 yyindent
, "", yytokenName (yylhsNonterm (yyx
->yyrule
)),
1633 YYFPRINTF (stderr
, "%*s%s -> <Rule %d, tokens %lu .. %lu>\n",
1634 yyindent
, "", yytokenName (yylhsNonterm (yyx
->yyrule
)),
1635 yyx
->yyrule
- 1, (unsigned long int) (yys
->yyposn
+ 1),
1636 (unsigned long int) yyx
->yystate
->yyposn
);
1637 for (yyi
= 1; yyi
<= yynrhs
; yyi
+= 1)
1639 if (yystates
[yyi
]->yyresolved
)
1641 if (yystates
[yyi
-1]->yyposn
+1 > yystates
[yyi
]->yyposn
)
1642 YYFPRINTF (stderr
, "%*s%s <empty>\n", yyindent
+2, "",
1643 yytokenName (yystos
[yystates
[yyi
]->yylrState
]));
1645 YYFPRINTF (stderr
, "%*s%s <tokens %lu .. %lu>\n", yyindent
+2, "",
1646 yytokenName (yystos
[yystates
[yyi
]->yylrState
]),
1647 (unsigned long int) (yystates
[yyi
-1]->yyposn
+ 1),
1648 (unsigned long int) yystates
[yyi
]->yyposn
);
1651 yyreportTree (yystates
[yyi
]->yysemantics
.yyfirstVal
, yyindent
+2);
1657 yyreportAmbiguity (yySemanticOption
* yyx0
,
1658 yySemanticOption
* yyx1
]b4_pure_formals
[)
1663 #if ]b4_api_PREFIX[DEBUG
1664 YYFPRINTF (stderr
, "Ambiguity detected.\n");
1665 YYFPRINTF (stderr
, "Option 1,\n");
1666 yyreportTree (yyx0
, 2);
1667 YYFPRINTF (stderr
, "\nOption 2,\n");
1668 yyreportTree (yyx1
, 2);
1669 YYFPRINTF (stderr
, "\n");
1672 yyerror (]b4_yyerror_args
[YY_("syntax is ambiguous"));
1674 }]b4_locations_if([[
1676 /** Resolve the locations for each of the YYN1 states in *YYSTACKP,
1677 * ending at YYS1. Has no effect on previously resolved states.
1678 * The first semantic option of a state is always chosen. */
1680 yyresolveLocations (yyGLRState
* yys1
, int yyn1
,
1681 yyGLRStack
*yystackp
]b4_user_formals
[)
1685 yyresolveLocations (yys1
->yypred
, yyn1
- 1, yystackp
]b4_user_args
[);
1686 if (!yys1
->yyresolved
)
1688 yyGLRStackItem yyrhsloc
[1 + YYMAXRHS
];
1690 yySemanticOption
*yyoption
= yys1
->yysemantics
.yyfirstVal
;
1691 YYASSERT (yyoption
!= YY_NULL
);
1692 yynrhs
= yyrhsLength (yyoption
->yyrule
);
1697 yyresolveLocations (yyoption
->yystate
, yynrhs
,
1698 yystackp
]b4_user_args
[);
1699 for (yys
= yyoption
->yystate
, yyn
= yynrhs
;
1701 yys
= yys
->yypred
, yyn
-= 1)
1702 yyrhsloc
[yyn
].yystate
.yyloc
= yys
->yyloc
;
1706 /* Both yyresolveAction and yyresolveLocations traverse the GSS
1707 in reverse rightmost order. It is only necessary to invoke
1708 yyresolveLocations on a subforest for which yyresolveAction
1709 would have been invoked next had an ambiguity not been
1710 detected. Thus the location of the previous state (but not
1711 necessarily the previous state itself) is guaranteed to be
1712 resolved already. */
1713 yyGLRState
*yyprevious
= yyoption
->yystate
;
1714 yyrhsloc
[0].yystate
.yyloc
= yyprevious
->yyloc
;
1717 int yychar_current
= yychar
;
1718 YYSTYPE yylval_current
= yylval
;
1719 YYLTYPE yylloc_current
= yylloc
;
1720 yychar
= yyoption
->yyrawchar
;
1721 yylval
= yyoption
->yyval
;
1722 yylloc
= yyoption
->yyloc
;
1723 YYLLOC_DEFAULT ((yys1
->yyloc
), yyrhsloc
, yynrhs
);
1724 yychar
= yychar_current
;
1725 yylval
= yylval_current
;
1726 yylloc
= yylloc_current
;
1732 /** Resolve the ambiguity represented in state YYS in *YYSTACKP,
1733 * perform the indicated actions, and set the semantic value of YYS.
1734 * If result != yyok, the chain of semantic options in YYS has been
1735 * cleared instead or it has been left unmodified except that
1736 * redundant options may have been removed. Regardless of whether
1737 * result = yyok, YYS has been left with consistent data so that
1738 * yydestroyGLRState can be invoked if necessary. */
1740 yyresolveValue (yyGLRState
* yys
, yyGLRStack
* yystackp
]b4_user_formals
[)
1742 yySemanticOption
* yyoptionList
= yys
->yysemantics
.yyfirstVal
;
1743 yySemanticOption
* yybest
= yyoptionList
;
1744 yySemanticOption
** yypp
;
1745 yybool yymerge
= yyfalse
;
1747 YYRESULTTAG yyflag
;]b4_locations_if([
1748 YYLTYPE
*yylocp
= &yys
->yyloc
;])[
1750 for (yypp
= &yyoptionList
->yynext
; *yypp
!= YY_NULL
; )
1752 yySemanticOption
* yyp
= *yypp
;
1754 if (yyidenticalOptions (yybest
, yyp
))
1756 yymergeOptionSets (yybest
, yyp
);
1757 *yypp
= yyp
->yynext
;
1761 switch (yypreference (yybest
, yyp
))
1763 case 0:]b4_locations_if([[
1764 yyresolveLocations (yys
, 1, yystackp
]b4_user_args
[);]])[
1765 return yyreportAmbiguity (yybest
, yyp
]b4_pure_args
[);
1777 /* This cannot happen so it is not worth a YYASSERT (yyfalse),
1778 but some compilers complain if the default case is
1782 yypp
= &yyp
->yynext
;
1788 yySemanticOption
* yyp
;
1789 int yyprec
= yydprec
[yybest
->yyrule
];
1790 yyflag
= yyresolveAction (yybest
, yystackp
, &yysval
]b4_locuser_args
[);
1792 for (yyp
= yybest
->yynext
; yyp
!= YY_NULL
; yyp
= yyp
->yynext
)
1794 if (yyprec
== yydprec
[yyp
->yyrule
])
1796 YYSTYPE yysval_other
;]b4_locations_if([
1798 yyflag
= yyresolveAction (yyp
, yystackp
, &yysval_other
]b4_locuser_args([&yydummy
])[);
1801 yydestruct ("Cleanup: discarding incompletely merged value for",
1802 yystos
[yys
->yylrState
],
1803 &yysval
]b4_locuser_args
[);
1806 yyuserMerge (yymerger
[yyp
->yyrule
], &yysval
, &yysval_other
);
1811 yyflag
= yyresolveAction (yybest
, yystackp
, &yysval
]b4_locuser_args([yylocp
])[);
1815 yys
->yyresolved
= yytrue
;
1816 yys
->yysemantics
.yysval
= yysval
;
1819 yys
->yysemantics
.yyfirstVal
= YY_NULL
;
1824 yyresolveStack (yyGLRStack
* yystackp
]b4_user_formals
[)
1826 if (yystackp
->yysplitPoint
!= YY_NULL
)
1831 for (yyn
= 0, yys
= yystackp
->yytops
.yystates
[0];
1832 yys
!= yystackp
->yysplitPoint
;
1833 yys
= yys
->yypred
, yyn
+= 1)
1835 YYCHK (yyresolveStates (yystackp
->yytops
.yystates
[0], yyn
, yystackp
1842 yycompressStack (yyGLRStack
* yystackp
)
1844 yyGLRState
* yyp
, *yyq
, *yyr
;
1846 if (yystackp
->yytops
.yysize
!= 1 || yystackp
->yysplitPoint
== YY_NULL
)
1849 for (yyp
= yystackp
->yytops
.yystates
[0], yyq
= yyp
->yypred
, yyr
= YY_NULL
;
1850 yyp
!= yystackp
->yysplitPoint
;
1851 yyr
= yyp
, yyp
= yyq
, yyq
= yyp
->yypred
)
1854 yystackp
->yyspaceLeft
+= yystackp
->yynextFree
- yystackp
->yyitems
;
1855 yystackp
->yynextFree
= ((yyGLRStackItem
*) yystackp
->yysplitPoint
) + 1;
1856 yystackp
->yyspaceLeft
-= yystackp
->yynextFree
- yystackp
->yyitems
;
1857 yystackp
->yysplitPoint
= YY_NULL
;
1858 yystackp
->yylastDeleted
= YY_NULL
;
1860 while (yyr
!= YY_NULL
)
1862 yystackp
->yynextFree
->yystate
= *yyr
;
1864 yystackp
->yynextFree
->yystate
.yypred
= &yystackp
->yynextFree
[-1].yystate
;
1865 yystackp
->yytops
.yystates
[0] = &yystackp
->yynextFree
->yystate
;
1866 yystackp
->yynextFree
+= 1;
1867 yystackp
->yyspaceLeft
-= 1;
1872 yyprocessOneStack (yyGLRStack
* yystackp
, size_t yyk
,
1873 size_t yyposn
]b4_pure_formals
[)
1875 while (yystackp
->yytops
.yystates
[yyk
] != YY_NULL
)
1877 yyStateNum yystate
= yystackp
->yytops
.yystates
[yyk
]->yylrState
;
1878 YYDPRINTF ((stderr
, "Stack %lu Entering state %d\n",
1879 (unsigned long int) yyk
, yystate
));
1881 YYASSERT (yystate
!= YYFINAL
);
1883 if (yyisDefaultedState (yystate
))
1886 yyRuleNum yyrule
= yydefaultAction (yystate
);
1889 YYDPRINTF ((stderr
, "Stack %lu dies.\n",
1890 (unsigned long int) yyk
));
1891 yymarkStackDeleted (yystackp
, yyk
);
1894 yyflag
= yyglrReduce (yystackp
, yyk
, yyrule
, yyimmediate
[yyrule
]]b4_user_args
[);
1895 if (yyflag
== yyerr
)
1899 "(predicate failure or explicit user error).\n",
1900 (unsigned long int) yyk
));
1901 yymarkStackDeleted (yystackp
, yyk
);
1911 const short int* yyconflicts
;
1913 yystackp
->yytops
.yylookaheadNeeds
[yyk
] = yytrue
;
1914 if (yychar
== YYEMPTY
)
1916 YYDPRINTF ((stderr
, "Reading a token: "));
1920 if (yychar
<= YYEOF
)
1922 yychar
= yytoken
= YYEOF
;
1923 YYDPRINTF ((stderr
, "Now at end of input.\n"));
1927 yytoken
= YYTRANSLATE (yychar
);
1928 YY_SYMBOL_PRINT ("Next token is", yytoken
, &yylval
, &yylloc
);
1931 yygetLRActions (yystate
, yytoken
, &yyaction
, &yyconflicts
);
1933 while (*yyconflicts
!= 0)
1936 size_t yynewStack
= yysplitStack (yystackp
, yyk
);
1937 YYDPRINTF ((stderr
, "Splitting off stack %lu from %lu.\n",
1938 (unsigned long int) yynewStack
,
1939 (unsigned long int) yyk
));
1940 yyflag
= yyglrReduce (yystackp
, yynewStack
,
1942 yyimmediate
[*yyconflicts
]]b4_user_args
[);
1944 YYCHK (yyprocessOneStack (yystackp
, yynewStack
,
1945 yyposn
]b4_pure_args
[));
1946 else if (yyflag
== yyerr
)
1948 YYDPRINTF ((stderr
, "Stack %lu dies.\n",
1949 (unsigned long int) yynewStack
));
1950 yymarkStackDeleted (yystackp
, yynewStack
);
1957 if (yyisShiftAction (yyaction
))
1959 else if (yyisErrorAction (yyaction
))
1961 YYDPRINTF ((stderr
, "Stack %lu dies.\n",
1962 (unsigned long int) yyk
));
1963 yymarkStackDeleted (yystackp
, yyk
);
1968 YYRESULTTAG yyflag
= yyglrReduce (yystackp
, yyk
, -yyaction
,
1969 yyimmediate
[-yyaction
]]b4_user_args
[);
1970 if (yyflag
== yyerr
)
1974 "(predicate failure or explicit user error).\n",
1975 (unsigned long int) yyk
));
1976 yymarkStackDeleted (yystackp
, yyk
);
1979 else if (yyflag
!= yyok
)
1988 yyreportSyntaxError (yyGLRStack
* yystackp
]b4_user_formals
[)
1990 if (yystackp
->yyerrState
!= 0)
1992 #if ! YYERROR_VERBOSE
1993 yyerror (]b4_lyyerror_args
[YY_("syntax error"));
1996 yySymbol yytoken
= yychar
== YYEMPTY
? YYEMPTY
: YYTRANSLATE (yychar
);
1997 size_t yysize0
= yytnamerr (YY_NULL
, yytokenName (yytoken
));
1998 size_t yysize
= yysize0
;
1999 yybool yysize_overflow
= yyfalse
;
2000 char* yymsg
= YY_NULL
;
2001 enum { YYERROR_VERBOSE_ARGS_MAXIMUM
= 5 };
2002 /* Internationalized format string. */
2003 const char *yyformat
= YY_NULL
;
2004 /* Arguments of yyformat. */
2005 char const *yyarg
[YYERROR_VERBOSE_ARGS_MAXIMUM
];
2006 /* Number of reported tokens (one for the "unexpected", one per
2010 /* There are many possibilities here to consider:
2011 - If this state is a consistent state with a default action, then
2012 the only way this function was invoked is if the default action
2013 is an error action. In that case, don't check for expected
2014 tokens because there are none.
2015 - The only way there can be no lookahead present (in yychar) is if
2016 this state is a consistent state with a default action. Thus,
2017 detecting the absence of a lookahead is sufficient to determine
2018 that there is no unexpected or expected token to report. In that
2019 case, just report a simple "syntax error".
2020 - Don't assume there isn't a lookahead just because this state is a
2021 consistent state with a default action. There might have been a
2022 previous inconsistent state, consistent state with a non-default
2023 action, or user semantic action that manipulated yychar.
2024 - Of course, the expected token list depends on states to have
2025 correct lookahead information, and it depends on the parser not
2026 to perform extra reductions after fetching a lookahead from the
2027 scanner and before detecting a syntax error. Thus, state merging
2028 (from LALR or IELR) and default reductions corrupt the expected
2029 token list. However, the list is correct for canonical LR with
2030 one exception: it will still contain any token that will not be
2031 accepted due to an error action in a later state.
2033 if (yytoken
!= YYEMPTY
)
2035 int yyn
= yypact
[yystackp
->yytops
.yystates
[0]->yylrState
];
2036 yyarg
[yycount
++] = yytokenName (yytoken
);
2037 if (!yypact_value_is_default (yyn
))
2039 /* Start YYX at -YYN if negative to avoid negative indexes in
2040 YYCHECK. In other words, skip the first -YYN actions for this
2041 state because they are default actions. */
2042 int yyxbegin
= yyn
< 0 ? -yyn
: 0;
2043 /* Stay within bounds of both yycheck and yytname. */
2044 int yychecklim
= YYLAST
- yyn
+ 1;
2045 int yyxend
= yychecklim
< YYNTOKENS
? yychecklim
: YYNTOKENS
;
2047 for (yyx
= yyxbegin
; yyx
< yyxend
; ++yyx
)
2048 if (yycheck
[yyx
+ yyn
] == yyx
&& yyx
!= YYTERROR
2049 && !yytable_value_is_error (yytable
[yyx
+ yyn
]))
2051 if (yycount
== YYERROR_VERBOSE_ARGS_MAXIMUM
)
2057 yyarg
[yycount
++] = yytokenName (yyx
);
2059 size_t yysz
= yysize
+ yytnamerr (YY_NULL
, yytokenName (yyx
));
2060 yysize_overflow
|= yysz
< yysize
;
2069 #define YYCASE_(N, S) \
2073 YYCASE_(0, YY_("syntax error"));
2074 YYCASE_(1, YY_("syntax error, unexpected %s"));
2075 YYCASE_(2, YY_("syntax error, unexpected %s, expecting %s"));
2076 YYCASE_(3, YY_("syntax error, unexpected %s, expecting %s or %s"));
2077 YYCASE_(4, YY_("syntax error, unexpected %s, expecting %s or %s or %s"));
2078 YYCASE_(5, YY_("syntax error, unexpected %s, expecting %s or %s or %s or %s"));
2083 size_t yysz
= yysize
+ strlen (yyformat
);
2084 yysize_overflow
|= yysz
< yysize
;
2088 if (!yysize_overflow
)
2089 yymsg
= (char *) YYMALLOC (yysize
);
2095 while ((*yyp
= *yyformat
))
2097 if (*yyp
== '%' && yyformat
[1] == 's' && yyi
< yycount
)
2099 yyp
+= yytnamerr (yyp
, yyarg
[yyi
++]);
2108 yyerror (]b4_lyyerror_args
[yymsg
);
2113 yyerror (]b4_lyyerror_args
[YY_("syntax error"));
2114 yyMemoryExhausted (yystackp
);
2117 #endif /* YYERROR_VERBOSE */
2121 /* Recover from a syntax error on *YYSTACKP, assuming that *YYSTACKP->YYTOKENP,
2122 yylval, and yylloc are the syntactic category, semantic value, and location
2123 of the lookahead. */
2125 yyrecoverSyntaxError (yyGLRStack
* yystackp
]b4_user_formals
[)
2130 if (yystackp
->yyerrState
== 3)
2131 /* We just shifted the error token and (perhaps) took some
2132 reductions. Skip tokens until we can proceed. */
2136 if (yychar
== YYEOF
)
2137 yyFail (yystackp
][]b4_lpure_args
[, YY_NULL
);
2138 if (yychar
!= YYEMPTY
)
2139 {]b4_locations_if([[
2140 /* We throw away the lookahead, but the error range
2141 of the shifted error token must take it into account. */
2142 yyGLRState
*yys
= yystackp
->yytops
.yystates
[0];
2143 yyGLRStackItem yyerror_range
[3];
2144 yyerror_range
[1].yystate
.yyloc
= yys
->yyloc
;
2145 yyerror_range
[2].yystate
.yyloc
= yylloc
;
2146 YYLLOC_DEFAULT ((yys
->yyloc
), yyerror_range
, 2);]])[
2147 yytoken
= YYTRANSLATE (yychar
);
2148 yydestruct ("Error: discarding",
2149 yytoken
, &yylval
]b4_locuser_args([&yylloc
])[);
2151 YYDPRINTF ((stderr
, "Reading a token: "));
2153 if (yychar
<= YYEOF
)
2155 yychar
= yytoken
= YYEOF
;
2156 YYDPRINTF ((stderr
, "Now at end of input.\n"));
2160 yytoken
= YYTRANSLATE (yychar
);
2161 YY_SYMBOL_PRINT ("Next token is", yytoken
, &yylval
, &yylloc
);
2163 yyj
= yypact
[yystackp
->yytops
.yystates
[0]->yylrState
];
2164 if (yypact_value_is_default (yyj
))
2167 if (yyj
< 0 || YYLAST
< yyj
|| yycheck
[yyj
] != yytoken
)
2169 if (yydefact
[yystackp
->yytops
.yystates
[0]->yylrState
] != 0)
2172 else if (! yytable_value_is_error (yytable
[yyj
]))
2176 /* Reduce to one stack. */
2177 for (yyk
= 0; yyk
< yystackp
->yytops
.yysize
; yyk
+= 1)
2178 if (yystackp
->yytops
.yystates
[yyk
] != YY_NULL
)
2180 if (yyk
>= yystackp
->yytops
.yysize
)
2181 yyFail (yystackp
][]b4_lpure_args
[, YY_NULL
);
2182 for (yyk
+= 1; yyk
< yystackp
->yytops
.yysize
; yyk
+= 1)
2183 yymarkStackDeleted (yystackp
, yyk
);
2184 yyremoveDeletes (yystackp
);
2185 yycompressStack (yystackp
);
2187 /* Now pop stack until we find a state that shifts the error token. */
2188 yystackp
->yyerrState
= 3;
2189 while (yystackp
->yytops
.yystates
[0] != YY_NULL
)
2191 yyGLRState
*yys
= yystackp
->yytops
.yystates
[0];
2192 yyj
= yypact
[yys
->yylrState
];
2193 if (! yypact_value_is_default (yyj
))
2196 if (0 <= yyj
&& yyj
<= YYLAST
&& yycheck
[yyj
] == YYTERROR
2197 && yyisShiftAction (yytable
[yyj
]))
2199 /* Shift the error token. */]b4_locations_if([[
2200 /* First adjust its location.*/
2202 yystackp
->yyerror_range
[2].yystate
.yyloc
= yylloc
;
2203 YYLLOC_DEFAULT (yyerrloc
, (yystackp
->yyerror_range
), 2);]])[
2204 YY_SYMBOL_PRINT ("Shifting", yystos
[yytable
[yyj
]],
2205 &yylval
, &yyerrloc
);
2206 yyglrShift (yystackp
, 0, yytable
[yyj
],
2207 yys
->yyposn
, &yylval
]b4_locations_if([, &yyerrloc
])[);
2208 yys
= yystackp
->yytops
.yystates
[0];
2211 }]b4_locations_if([[
2212 yystackp
->yyerror_range
[1].yystate
.yyloc
= yys
->yyloc
;]])[
2213 if (yys
->yypred
!= YY_NULL
)
2214 yydestroyGLRState ("Error: popping", yys
]b4_user_args
[);
2215 yystackp
->yytops
.yystates
[0] = yys
->yypred
;
2216 yystackp
->yynextFree
-= 1;
2217 yystackp
->yyspaceLeft
+= 1;
2219 if (yystackp
->yytops
.yystates
[0] == YY_NULL
)
2220 yyFail (yystackp
][]b4_lpure_args
[, YY_NULL
);
2223 #define YYCHK1(YYE) \
2233 goto yyuser_error; \
2243 ]b4_function_define([yyparse
], [int], b4_parse_param
)[
2247 yyGLRStack
* const yystackp
= &yystack
;
2250 YYDPRINTF ((stderr
, "Starting parse\n"));
2253 yylval
= yyval_default
;]b4_locations_if([
2254 yylloc
= yyloc_default
;])[
2255 ]m4_ifdef([b4_initial_action
], [
2256 b4_dollar_pushdef([yylval
], [], [yylloc
])dnl
2257 /* User initialization code. */
2258 b4_user_initial_action
2259 b4_dollar_popdef
])[]dnl
2261 if (! yyinitGLRStack (yystackp
, YYINITDEPTH
))
2262 goto yyexhaustedlab
;
2263 switch (YYSETJMP (yystack
.yyexception_buffer
))
2266 case 1: goto yyabortlab
;
2267 case 2: goto yyexhaustedlab
;
2268 default: goto yybuglab
;
2270 yyglrShift (&yystack
, 0, 0, 0, &yylval
]b4_locations_if([, &yylloc
])[);
2275 /* For efficiency, we have two loops, the first of which is
2276 specialized to deterministic operation (single stack, no
2277 potential ambiguity). */
2283 const short int* yyconflicts
;
2285 yyStateNum yystate
= yystack
.yytops
.yystates
[0]->yylrState
;
2286 YYDPRINTF ((stderr
, "Entering state %d\n", yystate
));
2287 if (yystate
== YYFINAL
)
2289 if (yyisDefaultedState (yystate
))
2291 yyrule
= yydefaultAction (yystate
);
2294 ]b4_locations_if([[ yystack
.yyerror_range
[1].yystate
.yyloc
= yylloc
;]])[
2295 yyreportSyntaxError (&yystack
]b4_user_args
[);
2298 YYCHK1 (yyglrReduce (&yystack
, 0, yyrule
, yytrue
]b4_user_args
[));
2303 if (yychar
== YYEMPTY
)
2305 YYDPRINTF ((stderr
, "Reading a token: "));
2309 if (yychar
<= YYEOF
)
2311 yychar
= yytoken
= YYEOF
;
2312 YYDPRINTF ((stderr
, "Now at end of input.\n"));
2316 yytoken
= YYTRANSLATE (yychar
);
2317 YY_SYMBOL_PRINT ("Next token is", yytoken
, &yylval
, &yylloc
);
2320 yygetLRActions (yystate
, yytoken
, &yyaction
, &yyconflicts
);
2321 if (*yyconflicts
!= 0)
2323 if (yyisShiftAction (yyaction
))
2325 YY_SYMBOL_PRINT ("Shifting", yytoken
, &yylval
, &yylloc
);
2328 yyglrShift (&yystack
, 0, yyaction
, yyposn
, &yylval
]b4_locations_if([, &yylloc
])[);
2329 if (0 < yystack
.yyerrState
)
2330 yystack
.yyerrState
-= 1;
2332 else if (yyisErrorAction (yyaction
))
2334 ]b4_locations_if([[ yystack
.yyerror_range
[1].yystate
.yyloc
= yylloc
;]])[
2335 yyreportSyntaxError (&yystack
]b4_user_args
[);
2339 YYCHK1 (yyglrReduce (&yystack
, 0, -yyaction
, yytrue
]b4_user_args
[));
2345 yySymbol yytoken_to_shift
;
2348 for (yys
= 0; yys
< yystack
.yytops
.yysize
; yys
+= 1)
2349 yystackp
->yytops
.yylookaheadNeeds
[yys
] = yychar
!= YYEMPTY
;
2351 /* yyprocessOneStack returns one of three things:
2353 - An error flag. If the caller is yyprocessOneStack, it
2354 immediately returns as well. When the caller is finally
2355 yyparse, it jumps to an error label via YYCHK1.
2357 - yyok, but yyprocessOneStack has invoked yymarkStackDeleted
2358 (&yystack, yys), which sets the top state of yys to NULL. Thus,
2359 yyparse's following invocation of yyremoveDeletes will remove
2362 - yyok, when ready to shift a token.
2364 Except in the first case, yyparse will invoke yyremoveDeletes and
2365 then shift the next token onto all remaining stacks. This
2366 synchronization of the shift (that is, after all preceding
2367 reductions on all stacks) helps prevent double destructor calls
2368 on yylval in the event of memory exhaustion. */
2370 for (yys
= 0; yys
< yystack
.yytops
.yysize
; yys
+= 1)
2371 YYCHK1 (yyprocessOneStack (&yystack
, yys
, yyposn
]b4_lpure_args
[));
2372 yyremoveDeletes (&yystack
);
2373 if (yystack
.yytops
.yysize
== 0)
2375 yyundeleteLastStack (&yystack
);
2376 if (yystack
.yytops
.yysize
== 0)
2377 yyFail (&yystack
][]b4_lpure_args
[, YY_("syntax error"));
2378 YYCHK1 (yyresolveStack (&yystack
]b4_user_args
[));
2379 YYDPRINTF ((stderr
, "Returning to deterministic operation.\n"));
2380 ]b4_locations_if([[ yystack
.yyerror_range
[1].yystate
.yyloc
= yylloc
;]])[
2381 yyreportSyntaxError (&yystack
]b4_user_args
[);
2385 /* If any yyglrShift call fails, it will fail after shifting. Thus,
2386 a copy of yylval will already be on stack 0 in the event of a
2387 failure in the following loop. Thus, yychar is set to YYEMPTY
2388 before the loop to make sure the user destructor for yylval isn't
2390 yytoken_to_shift
= YYTRANSLATE (yychar
);
2393 for (yys
= 0; yys
< yystack
.yytops
.yysize
; yys
+= 1)
2396 const short int* yyconflicts
;
2397 yyStateNum yystate
= yystack
.yytops
.yystates
[yys
]->yylrState
;
2398 yygetLRActions (yystate
, yytoken_to_shift
, &yyaction
,
2400 /* Note that yyconflicts were handled by yyprocessOneStack. */
2401 YYDPRINTF ((stderr
, "On stack %lu, ", (unsigned long int) yys
));
2402 YY_SYMBOL_PRINT ("shifting", yytoken_to_shift
, &yylval
, &yylloc
);
2403 yyglrShift (&yystack
, yys
, yyaction
, yyposn
,
2404 &yylval
]b4_locations_if([, &yylloc
])[);
2405 YYDPRINTF ((stderr
, "Stack %lu now in state #%d\n",
2406 (unsigned long int) yys
,
2407 yystack
.yytops
.yystates
[yys
]->yylrState
));
2410 if (yystack
.yytops
.yysize
== 1)
2412 YYCHK1 (yyresolveStack (&yystack
]b4_user_args
[));
2413 YYDPRINTF ((stderr
, "Returning to deterministic operation.\n"));
2414 yycompressStack (&yystack
);
2420 yyrecoverSyntaxError (&yystack
]b4_user_args
[);
2421 yyposn
= yystack
.yytops
.yystates
[0]->yyposn
;
2437 yyerror (]b4_lyyerror_args
[YY_("memory exhausted"));
2442 if (yychar
!= YYEMPTY
)
2443 yydestruct ("Cleanup: discarding lookahead",
2444 YYTRANSLATE (yychar
), &yylval
]b4_locuser_args([&yylloc
])[);
2446 /* If the stack is well-formed, pop the stack until it is empty,
2447 destroying its entries as we go. But free the stack regardless
2448 of whether it is well-formed. */
2449 if (yystack
.yyitems
)
2451 yyGLRState
** yystates
= yystack
.yytops
.yystates
;
2454 size_t yysize
= yystack
.yytops
.yysize
;
2456 for (yyk
= 0; yyk
< yysize
; yyk
+= 1)
2459 while (yystates
[yyk
])
2461 yyGLRState
*yys
= yystates
[yyk
];
2462 ]b4_locations_if([[ yystack
.yyerror_range
[1].yystate
.yyloc
= yys
->yyloc
;]]
2463 )[ if (yys
->yypred
!= YY_NULL
)
2464 yydestroyGLRState ("Cleanup: popping", yys
]b4_user_args
[);
2465 yystates
[yyk
] = yys
->yypred
;
2466 yystack
.yynextFree
-= 1;
2467 yystack
.yyspaceLeft
+= 1;
2472 yyfreeGLRStack (&yystack
);
2478 /* DEBUGGING ONLY */
2479 #if ]b4_api_PREFIX[DEBUG
2481 yy_yypstack (yyGLRState
* yys
)
2485 yy_yypstack (yys
->yypred
);
2486 YYFPRINTF (stderr
, " -> ");
2488 YYFPRINTF (stderr
, "%d@@%lu", yys
->yylrState
,
2489 (unsigned long int) yys
->yyposn
);
2493 yypstates (yyGLRState
* yyst
)
2495 if (yyst
== YY_NULL
)
2496 YYFPRINTF (stderr
, "<null>");
2499 YYFPRINTF (stderr
, "\n");
2503 yypstack (yyGLRStack
* yystackp
, size_t yyk
)
2505 yypstates (yystackp
->yytops
.yystates
[yyk
]);
2508 #define YYINDEX(YYX) \
2509 ((YYX) == YY_NULL ? -1 : (yyGLRStackItem*) (YYX) - yystackp->yyitems)
2513 yypdumpstack (yyGLRStack
* yystackp
)
2515 yyGLRStackItem
* yyp
;
2517 for (yyp
= yystackp
->yyitems
; yyp
< yystackp
->yynextFree
; yyp
+= 1)
2519 YYFPRINTF (stderr
, "%3lu. ",
2520 (unsigned long int) (yyp
- yystackp
->yyitems
));
2521 if (*(yybool
*) yyp
)
2523 YYFPRINTF (stderr
, "Res: %d, LR State: %d, posn: %lu, pred: %ld",
2524 yyp
->yystate
.yyresolved
, yyp
->yystate
.yylrState
,
2525 (unsigned long int) yyp
->yystate
.yyposn
,
2526 (long int) YYINDEX (yyp
->yystate
.yypred
));
2527 if (! yyp
->yystate
.yyresolved
)
2528 YYFPRINTF (stderr
, ", firstVal: %ld",
2529 (long int) YYINDEX (yyp
->yystate
2530 .yysemantics
.yyfirstVal
));
2534 YYFPRINTF (stderr
, "Option. rule: %d, state: %ld, next: %ld",
2535 yyp
->yyoption
.yyrule
- 1,
2536 (long int) YYINDEX (yyp
->yyoption
.yystate
),
2537 (long int) YYINDEX (yyp
->yyoption
.yynext
));
2539 YYFPRINTF (stderr
, "\n");
2541 YYFPRINTF (stderr
, "Tops:");
2542 for (yyi
= 0; yyi
< yystackp
->yytops
.yysize
; yyi
+= 1)
2543 YYFPRINTF (stderr
, "%lu: %ld; ", (unsigned long int) yyi
,
2544 (long int) YYINDEX (yystackp
->yytops
.yystates
[yyi
]));
2545 YYFPRINTF (stderr
, "\n");
2551 #undef yynerrs]b4_locations_if([
2554 m4_if(b4_prefix
, [yy
], [],
2555 [[/* Substitute the variable and function names. */
2556 #define yyparse ]b4_prefix[parse
2557 #define yylex ]b4_prefix[lex
2558 #define yyerror ]b4_prefix[error
2559 #define yylval ]b4_prefix[lval
2560 #define yychar ]b4_prefix[char
2561 #define yydebug ]b4_prefix[debug
2562 #define yynerrs ]b4_prefix[nerrs]b4_locations_if([[
2563 #define yylloc ]b4_prefix[lloc]])])[
2568 # glr.cc produces its own header.
2569 m4_if(b4_skeleton
, ["glr.c"],
2571 [b4_output_begin([b4_spec_defines_file
])
2572 b4_copyright([Skeleton interface
for Bison GLR parsers in C
],
2575 ]b4_cpp_guard_open([b4_spec_defines_file
])[
2576 ]b4_shared_declarations
[
2577 ]b4_cpp_guard_close([b4_spec_defines_file
])[