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 # Accumule in b4_lex_param all the yylex arguments.
61 # Yes, this is quite ugly...
62 m4_define([b4_lex_param
],
63 m4_dquote(b4_pure_if([[[[YYSTYPE
*]], [[&yylval
]]][]dnl
64 b4_locations_if([, [[YYLTYPE
*], [&yylloc
]]])])dnl
65 m4_ifdef([b4_lex_param
], [, ]b4_lex_param
)))
70 # Optional effective arguments passed to yyerror: user args plus yylloc, and
72 m4_define([b4_yyerror_args
],
73 [b4_pure_if([b4_locations_if([yylocp
, ])])dnl
74 m4_ifset([b4_parse_param
], [b4_args(b4_parse_param
), ])])
79 # Same as above, but on the lookahead, hence &yylloc instead of yylocp.
80 m4_define([b4_lyyerror_args
],
81 [b4_pure_if([b4_locations_if([&yylloc
, ])])dnl
82 m4_ifset([b4_parse_param
], [b4_args(b4_parse_param
), ])])
87 # Same as b4_yyerror_args, but with a leading comma.
88 m4_define([b4_pure_args
],
89 [b4_pure_if([b4_locations_if([, yylocp
])])[]b4_user_args
])
94 # Same as above, but on the lookahead, hence &yylloc instead of yylocp.
95 m4_define([b4_lpure_args
],
96 [b4_pure_if([b4_locations_if([, &yylloc
])])[]b4_user_args
])
102 # Arguments passed to yyerror: user formals plus yylocp with leading comma.
103 m4_define([b4_pure_formals
],
104 [b4_pure_if([b4_locations_if([, YYLTYPE
*yylocp
])])[]b4_user_formals
])
107 # b4_locuser_formals(LOC = yylocp)
108 # --------------------------------
109 m4_define([b4_locuser_formals
],
110 [b4_locations_if([, YYLTYPE
*m4_default([$
1], [yylocp
])])[]b4_user_formals
])
113 # b4_locuser_args(LOC = yylocp)
114 # -----------------------------
115 m4_define([b4_locuser_args
],
116 [b4_locations_if([, m4_default([$
1], [yylocp
])])[]b4_user_args
])
120 ## ----------------- ##
121 ## Semantic Values. ##
122 ## ----------------- ##
125 # b4_lhs_value([TYPE])
126 # --------------------
127 # Expansion of $<TYPE>$.
128 m4_define([b4_lhs_value
],
129 [b4_symbol_value([(*yyvalp
)], [$
1])])
132 # b4_rhs_data(RULE-LENGTH, NUM)
133 # -----------------------------
134 # Expand to the semantic stack place that contains value and location
135 # of symbol number NUM in a rule of length RULE-LENGTH.
136 m4_define([b4_rhs_data
],
137 [((yyGLRStackItem
const *)yyvsp
)@
{YYFILL (b4_subtract([$
2], [$
1]))@
}.yystate
])
140 # b4_rhs_value(RULE-LENGTH, NUM, [TYPE])
141 # --------------------------------------
142 # Expansion of $<TYPE>NUM, where the current rule has RULE-LENGTH
144 m4_define([b4_rhs_value
],
145 [b4_symbol_value([b4_rhs_data([$
1], [$
2]).yysemantics
.yysval
], [$
3])])
156 m4_define([b4_lhs_location
],
160 # b4_rhs_location(RULE-LENGTH, NUM)
161 # ---------------------------------
162 # Expansion of @NUM, where the current rule has RULE-LENGTH symbols
164 m4_define([b4_rhs_location
],
165 [(b4_rhs_data([$
1], [$
2]).yyloc
)])
172 # b4_shared_declarations
173 # ----------------------
174 # Declaration that might either go into the header (if --defines)
175 # or open coded in the parser body.
176 m4_define([b4_shared_declarations
],
178 ]b4_percent_code_get([[requires]])[
180 ]b4_declare_yylstype
[
181 ]b4_function_declare(b4_prefix
[parse
], [int], b4_parse_param
)[
182 ]b4_percent_code_get([[provides]])[]dnl
190 # We do want M4 expansion after # for CPP macros.
193 @
output(b4_parser_file_name@
)@
194 b4_copyright([Skeleton implementation
for Bison GLR parsers in C
],
197 /* C GLR parser skeleton written by Paul Hilfinger. */
201 b4_percent_code_get([[top]])[
202 ]m4_if(b4_api_prefix
, [yy
], [],
203 [[/* Substitute the type names. */
204 #define YYSTYPE ]b4_api_PREFIX[STYPE]b4_locations_if([[
205 #define YYLTYPE ]b4_api_PREFIX[LTYPE]])])[
206 ]m4_if(b4_prefix
, [yy
], [],
207 [[/* Substitute the variable and function names. */
208 #define yyparse ]b4_prefix[parse
209 #define yylex ]b4_prefix[lex
210 #define yyerror ]b4_prefix[error
211 #define yylval ]b4_prefix[lval
212 #define yychar ]b4_prefix[char
213 #define yydebug ]b4_prefix[debug
214 #define yynerrs ]b4_prefix[nerrs]b4_locations_if([[
215 #define yylloc ]b4_prefix[lloc]])])[
217 /* First part of user declarations. */
218 ]b4_user_pre_prologue
[
222 ]b4_defines_if([[#include "@basename(]b4_spec_defines_file[@)"]],
223 [b4_shared_declarations
])[
225 /* Enabling verbose error messages. */
226 #ifdef YYERROR_VERBOSE
227 # undef YYERROR_VERBOSE
228 # define YYERROR_VERBOSE 1
230 # define YYERROR_VERBOSE ]b4_error_verbose_if([1], [0])[
233 /* Default (constant) value used for initialization for null
234 right-hand sides. Unlike the standard yacc.c template,
235 here we set the default value of $$ to a zeroed-out value.
236 Since the default value is undefined, this behavior is
237 technically correct. */
238 static YYSTYPE yyval_default
;
240 /* Copy the second part of user declarations. */
241 ]b4_user_post_prologue
242 b4_percent_code_get
[]dnl
249 # if defined YYENABLE_NLS && YYENABLE_NLS
251 # include <libintl.h> /* INFRINGES ON USER NAME SPACE */
252 # define YY_(msgid) dgettext ("bison-runtime", msgid)
256 # define YY_(msgid) msgid
260 /* Suppress unused-variable warnings by "using" E. */
262 # define YYUSE(e) ((void) (e))
264 # define YYUSE(e) /* empty */
271 # define YYMALLOC malloc
274 # define YYREALLOC realloc
277 #define YYSIZEMAX ((size_t) -1)
282 typedef unsigned char yybool
;
289 # define YYJMP_BUF jmp_buf
290 # define YYSETJMP(env) setjmp (env)
291 # define YYLONGJMP(env, val) longjmp (env, val)
298 #ifndef __attribute__
299 /* This feature is available in gcc versions 2.5 and later. */
300 # if (! defined __GNUC__ || __GNUC__ < 2 \
301 || (__GNUC__ == 2 && __GNUC_MINOR__ < 5))
302 # define __attribute__(Spec) /* empty */
306 ]b4_locations_if([#define YYOPTIONAL_LOC(Name) Name],[
308 # define YYOPTIONAL_LOC(Name) /* empty */
310 # define YYOPTIONAL_LOC(Name) Name __attribute__ ((__unused__))
314 # define YYASSERT(condition) ((void) ((condition) || (abort (), 0)))
317 /* YYFINAL -- State number of the termination state. */
318 #define YYFINAL ]b4_final_state_number[
319 /* YYLAST -- Last index in YYTABLE. */
320 #define YYLAST ]b4_last[
322 /* YYNTOKENS -- Number of terminals. */
323 #define YYNTOKENS ]b4_tokens_number[
324 /* YYNNTS -- Number of nonterminals. */
325 #define YYNNTS ]b4_nterms_number[
326 /* YYNRULES -- Number of rules. */
327 #define YYNRULES ]b4_rules_number[
328 /* YYNRULES -- Number of states. */
329 #define YYNSTATES ]b4_states_number[
330 /* YYMAXRHS -- Maximum number of symbols on right-hand side of rule. */
331 #define YYMAXRHS ]b4_r2_max[
332 /* YYMAXLEFT -- Maximum number of symbols to the left of a handle
333 accessed by $0, $-1, etc., in any rule. */
334 #define YYMAXLEFT ]b4_max_left_semantic_context[
336 /* YYTRANSLATE(X) -- Bison symbol number corresponding to X. */
337 #define YYUNDEFTOK ]b4_undef_token_number[
338 #define YYMAXUTOK ]b4_user_token_number_max[
340 #define YYTRANSLATE(YYX) \
341 ((unsigned int) (YYX) <= YYMAXUTOK ? yytranslate[YYX] : YYUNDEFTOK)
343 /* YYTRANSLATE[YYLEX] -- Bison symbol number corresponding to YYLEX. */
344 static const ]b4_int_type_for([b4_translate
])[ yytranslate
[] =
349 #if ]b4_api_PREFIX[DEBUG
350 /* YYRLINE[YYN] -- source line where rule number YYN was defined. */
351 static const ]b4_int_type_for([b4_rline
])[ yyrline
[] =
357 #if ]b4_api_PREFIX[DEBUG || YYERROR_VERBOSE || ]b4_token_table_flag[
358 /* YYTNAME[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM.
359 First, the terminals, then, starting at YYNTOKENS, nonterminals. */
360 static const char *const yytname
[] =
366 #define YYPACT_NINF ]b4_pact_ninf[
367 #define YYTABLE_NINF ]b4_table_ninf[
369 ]b4_parser_tables_define
[
371 /* YYDPREC[RULE-NUM] -- Dynamic precedence of rule #RULE-NUM (0 if none). */
372 static const ]b4_int_type_for([b4_dprec
])[ yydprec
[] =
377 /* YYMERGER[RULE-NUM] -- Index of merging function for rule #RULE-NUM. */
378 static const ]b4_int_type_for([b4_merger
])[ yymerger
[] =
383 /* YYIMMEDIATE[RULE-NUM] -- True iff rule #RULE-NUM is not to be deferred, as
384 in the case of predicates. */
385 static const yybool yyimmediate
[] =
390 /* YYCONFLP[YYPACT[STATE-NUM]] -- Pointer into YYCONFL of start of
391 list of conflicting reductions corresponding to action entry for
392 state STATE-NUM in yytable. 0 means no conflicts. The list in
393 yyconfl is terminated by a rule number of 0. */
394 static const ]b4_int_type_for([b4_conflict_list_heads
])[ yyconflp
[] =
396 ]b4_conflict_list_heads
[
399 /* YYCONFL[I] -- lists of conflicting rule numbers, each terminated by
400 0, pointed into by YYCONFLP. */
401 ]dnl Do
not use b4_int_type_for here
, since there are places where
402 dnl pointers onto yyconfl are taken
, which type is
"short int *".
403 dnl We probably ought to introduce a type
for confl
.
404 [static const short int yyconfl
[] =
406 ]b4_conflicting_rules
[
409 /* Error token number */
413 #ifndef YYLLOC_DEFAULT
414 ]b4_yylloc_default_define
[
415 # define YYRHSLOC(Rhs, K) ((Rhs)[K].yystate.yyloc)
417 /* YY_LOCATION_PRINT -- Print the location on the stream.
418 This macro was not mandated originally: define only if we know
419 we won't break user code: when these are the locations we know. */
421 # define YY_LOCATION_PRINT(File, Loc) \
422 fprintf (File, "%d.%d-%d.%d", \
423 (Loc).first_line, (Loc).first_column, \
424 (Loc).last_line, (Loc).last_column)
427 #ifndef YYLLOC_DEFAULT
428 # define YYLLOC_DEFAULT(Current, Rhs, N) ((void) 0)
432 #ifndef YY_LOCATION_PRINT
433 # define YY_LOCATION_PRINT(File, Loc) ((void) 0)
436 /* YYLEX -- calling `yylex' with the right arguments. */
437 #define YYLEX ]b4_function_call([yylex], [int], b4_lex_param)[
442 #define yynerrs (yystackp->yyerrcnt)
444 #define yychar (yystackp->yyrawchar)
446 #define yylval (yystackp->yyval)
448 #define yylloc (yystackp->yyloc)
449 m4_if(b4_prefix
[], [yy
], [],
450 [#define b4_prefix[]nerrs yynerrs
451 #define b4_prefix[]char yychar
452 #define b4_prefix[]lval yylval
453 #define b4_prefix[]lloc yylloc])],
454 [YYSTYPE yylval
;]b4_locations_if([[
460 static const int YYEOF
= 0;
461 static const int YYEMPTY
= -2;
463 typedef enum { yyok
, yyaccept
, yyabort
, yyerr
} YYRESULTTAG
;
467 YYRESULTTAG yychk_flag = YYE; \
468 if (yychk_flag != yyok) \
472 #if ]b4_api_PREFIX[DEBUG
475 # define YYFPRINTF fprintf
478 # define YYDPRINTF(Args) \
484 ]b4_yy_symbol_print_define
[
486 # define YY_SYMBOL_PRINT(Title, Type, Value, Location) \
490 YYFPRINTF (stderr, "%s ", Title); \
491 yy_symbol_print (stderr, Type, Value]b4_locuser_args([Location])[); \
492 YYFPRINTF (stderr, "\n"); \
496 /* Nonzero means print parse trace. It is left uninitialized so that
497 multiple parsers can coexist. */
500 #else /* !]b4_api_PREFIX[DEBUG */
502 # define YYDPRINTF(Args)
503 # define YY_SYMBOL_PRINT(Title, Type, Value, Location)
505 #endif /* !]b4_api_PREFIX[DEBUG */
507 /* YYINITDEPTH -- initial size of the parser's stacks. */
509 # define YYINITDEPTH ]b4_stack_depth_init[
512 /* YYMAXDEPTH -- maximum size the stacks can grow to (effective only
513 if the built-in stack extension method is used).
515 Do not make this value too large; the results are undefined if
516 SIZE_MAX < YYMAXDEPTH * sizeof (GLRStackItem)
517 evaluated with infinite-precision integer arithmetic. */
520 # define YYMAXDEPTH ]b4_stack_depth_max[
523 /* Minimum number of free items on the stack allowed after an
524 allocation. This is to allow allocation and initialization
525 to be completed by functions that call yyexpandGLRStack before the
526 stack is expanded, thus insuring that all necessary pointers get
527 properly redirected to new data. */
530 #ifndef YYSTACKEXPANDABLE
531 # define YYSTACKEXPANDABLE 1
534 #if YYSTACKEXPANDABLE
535 # define YY_RESERVE_GLRSTACK(Yystack) \
537 if (Yystack->yyspaceLeft < YYHEADROOM) \
538 yyexpandGLRStack (Yystack); \
541 # define YY_RESERVE_GLRSTACK(Yystack) \
543 if (Yystack->yyspaceLeft < YYHEADROOM) \
544 yyMemoryExhausted (Yystack); \
552 # if defined __GLIBC__ && defined _STRING_H && defined _GNU_SOURCE
553 # define yystpcpy stpcpy
555 /* Copy YYSRC to YYDEST, returning the address of the terminating '\0' in
558 yystpcpy (char *yydest
, const char *yysrc
)
561 const char *yys
= yysrc
;
563 while ((*yyd
++ = *yys
++) != '\0')
572 /* Copy to YYRES the contents of YYSTR after stripping away unnecessary
573 quotes and backslashes, so that it's suitable for yyerror. The
574 heuristic is that double-quoting is unnecessary unless the string
575 contains an apostrophe, a comma, or backslash (other than
576 backslash-backslash). YYSTR is taken from yytname. If YYRES is
577 null, do not copy; instead, return the length of what the result
580 yytnamerr (char *yyres
, const char *yystr
)
585 char const *yyp
= yystr
;
592 goto do_not_strip_quotes
;
596 goto do_not_strip_quotes
;
609 do_not_strip_quotes
: ;
613 return strlen (yystr
);
615 return yystpcpy (yyres
, yystr
) - yyres
;
619 #endif /* !YYERROR_VERBOSE */
621 /** State numbers, as in LALR(1) machine */
622 typedef int yyStateNum
;
624 /** Rule numbers, as in LALR(1) machine */
625 typedef int yyRuleNum
;
627 /** Grammar symbol */
628 typedef int yySymbol
;
630 /** Item references, as in LALR(1) machine */
631 typedef short int yyItemNum
;
633 typedef struct yyGLRState yyGLRState
;
634 typedef struct yyGLRStateSet yyGLRStateSet
;
635 typedef struct yySemanticOption yySemanticOption
;
636 typedef union yyGLRStackItem yyGLRStackItem
;
637 typedef struct yyGLRStack yyGLRStack
;
640 /** Type tag: always true. */
642 /** Type tag for yysemantics. If true, yysval applies, otherwise
643 * yyfirstVal applies. */
645 /** Number of corresponding LALR(1) machine state. */
646 yyStateNum yylrState
;
647 /** Preceding state in this stack */
649 /** Source position of the last token produced by my symbol */
652 /** First in a chain of alternative reductions producing the
653 * non-terminal corresponding to this state, threaded through
655 yySemanticOption
* yyfirstVal
;
656 /** Semantic value for this state. */
658 } yysemantics
;]b4_locations_if([[
659 /** Source location for this state. */
663 struct yyGLRStateSet
{
664 yyGLRState
** yystates
;
665 /** During nondeterministic operation, yylookaheadNeeds tracks which
666 * stacks have actually needed the current lookahead. During deterministic
667 * operation, yylookaheadNeeds[0] is not maintained since it would merely
668 * duplicate yychar != YYEMPTY. */
669 yybool
* yylookaheadNeeds
;
670 size_t yysize
, yycapacity
;
673 struct yySemanticOption
{
674 /** Type tag: always false. */
676 /** Rule number for this reduction */
678 /** The last RHS state in the list of states to be reduced. */
680 /** The lookahead for this reduction. */
682 YYSTYPE yyval
;]b4_locations_if([[
684 /** Next sibling in chain of options. To facilitate merging,
685 * options are chained in decreasing order by address. */
686 yySemanticOption
* yynext
;
689 /** Type of the items in the GLR stack. The yyisState field
690 * indicates which item of the union is valid. */
691 union yyGLRStackItem
{
693 yySemanticOption yyoption
;
698 ]b4_locations_if([[ /* To compute the location of the error token. */
699 yyGLRStackItem yyerror_range
[3];]])[
704 YYSTYPE yyval
;]b4_locations_if([[
707 YYJMP_BUF yyexception_buffer
;
708 yyGLRStackItem
* yyitems
;
709 yyGLRStackItem
* yynextFree
;
711 yyGLRState
* yysplitPoint
;
712 yyGLRState
* yylastDeleted
;
713 yyGLRStateSet yytops
;
716 #if YYSTACKEXPANDABLE
717 static void yyexpandGLRStack (yyGLRStack
* yystackp
);
720 static void yyFail (yyGLRStack
* yystackp
]b4_pure_formals
[, const char* yymsg
)
721 __attribute__ ((__noreturn__
));
723 yyFail (yyGLRStack
* yystackp
]b4_pure_formals
[, const char* yymsg
)
725 if (yymsg
!= YY_NULL
)
726 yyerror (]b4_yyerror_args
[yymsg
);
727 YYLONGJMP (yystackp
->yyexception_buffer
, 1);
730 static void yyMemoryExhausted (yyGLRStack
* yystackp
)
731 __attribute__ ((__noreturn__
));
733 yyMemoryExhausted (yyGLRStack
* yystackp
)
735 YYLONGJMP (yystackp
->yyexception_buffer
, 2);
738 #if ]b4_api_PREFIX[DEBUG || YYERROR_VERBOSE
739 /** A printable representation of TOKEN. */
740 static inline const char*
741 yytokenName (yySymbol yytoken
)
743 if (yytoken
== YYEMPTY
)
746 return yytname
[yytoken
];
750 /** Fill in YYVSP[YYLOW1 .. YYLOW0-1] from the chain of states starting
751 * at YYVSP[YYLOW0].yystate.yypred. Leaves YYVSP[YYLOW1].yystate.yypred
752 * containing the pointer to the next state in the chain. */
753 static void yyfillin (yyGLRStackItem
*, int, int) __attribute__ ((__unused__
));
755 yyfillin (yyGLRStackItem
*yyvsp
, int yylow0
, int yylow1
)
758 yyGLRState
*s
= yyvsp
[yylow0
].yystate
.yypred
;
759 for (i
= yylow0
-1; i
>= yylow1
; i
-= 1)
761 #if ]b4_api_PREFIX[DEBUG
762 yyvsp
[i
].yystate
.yylrState
= s
->yylrState
;
764 yyvsp
[i
].yystate
.yyresolved
= s
->yyresolved
;
766 yyvsp
[i
].yystate
.yysemantics
.yysval
= s
->yysemantics
.yysval
;
768 /* The effect of using yysval or yyloc (in an immediate rule) is
770 yyvsp
[i
].yystate
.yysemantics
.yyfirstVal
= YY_NULL
;]b4_locations_if([[
771 yyvsp
[i
].yystate
.yyloc
= s
->yyloc
;]])[
772 s
= yyvsp
[i
].yystate
.yypred
= s
->yypred
;
776 /* Do nothing if YYNORMAL or if *YYLOW <= YYLOW1. Otherwise, fill in
777 * YYVSP[YYLOW1 .. *YYLOW-1] as in yyfillin and set *YYLOW = YYLOW1.
778 * For convenience, always return YYLOW1. */
779 static inline int yyfill (yyGLRStackItem
*, int *, int, yybool
)
780 __attribute__ ((__unused__
));
782 yyfill (yyGLRStackItem
*yyvsp
, int *yylow
, int yylow1
, yybool yynormal
)
784 if (!yynormal
&& yylow1
< *yylow
)
786 yyfillin (yyvsp
, *yylow
, yylow1
);
792 /** Perform user action for rule number YYN, with RHS length YYRHSLEN,
793 * and top stack item YYVSP. YYLVALP points to place to put semantic
794 * value ($$), and yylocp points to place for location information
795 * (@@$). Returns yyok for normal return, yyaccept for YYACCEPT,
796 * yyerr for YYERROR, yyabort for YYABORT. */
798 yyuserAction (yyRuleNum yyn
, int yyrhslen
, yyGLRStackItem
* yyvsp
,
799 yyGLRStack
* yystackp
,
800 YYSTYPE
* yyvalp
]b4_locuser_formals
[)
802 yybool yynormal
__attribute__ ((__unused__
)) =
803 (yystackp
->yysplitPoint
== YY_NULL
);
805 ]b4_parse_param_use([yyvalp
], [yylocp
])dnl
807 # define yyerrok (yystackp->yyerrState = 0)
809 # define YYACCEPT return yyaccept
811 # define YYABORT return yyabort
813 # define YYERROR return yyerrok, yyerr
815 # define YYRECOVERING() (yystackp->yyerrState != 0)
817 # define yyclearin (yychar = YYEMPTY)
819 # define YYFILL(N) yyfill (yyvsp, &yylow, N, yynormal)
821 # define YYBACKUP(Token, Value) \
822 return yyerror (]b4_yyerror_args[YY_("syntax error: cannot back up")), \
827 *yyvalp
= yyval_default
;
829 *yyvalp
= yyvsp
[YYFILL (1-yyrhslen
)].yystate
.yysemantics
.yysval
;]b4_locations_if([[
830 YYLLOC_DEFAULT ((*yylocp
), (yyvsp
- yyrhslen
), yyrhslen
);
831 yystackp
->yyerror_range
[1].yystate
.yyloc
= *yylocp
;
851 yyuserMerge (int yyn
, YYSTYPE
* yy0
, YYSTYPE
* yy1
)
863 /* Bison grammar-table manipulation. */
865 ]b4_yydestruct_define
[
867 /** Number of symbols composing the right hand side of rule #RULE. */
869 yyrhsLength (yyRuleNum yyrule
)
875 yydestroyGLRState (char const *yymsg
, yyGLRState
*yys
]b4_user_formals
[)
878 yydestruct (yymsg
, yystos
[yys
->yylrState
],
879 &yys
->yysemantics
.yysval
]b4_locuser_args([&yys
->yyloc
])[);
882 #if ]b4_api_PREFIX[DEBUG
885 if (yys
->yysemantics
.yyfirstVal
)
886 YYFPRINTF (stderr
, "%s unresolved ", yymsg
);
888 YYFPRINTF (stderr
, "%s incomplete ", yymsg
);
889 yy_symbol_print (stderr
, yystos
[yys
->yylrState
],
890 YY_NULL
]b4_locuser_args([&yys
->yyloc
])[);
891 YYFPRINTF (stderr
, "\n");
895 if (yys
->yysemantics
.yyfirstVal
)
897 yySemanticOption
*yyoption
= yys
->yysemantics
.yyfirstVal
;
900 for (yyrh
= yyoption
->yystate
, yyn
= yyrhsLength (yyoption
->yyrule
);
902 yyrh
= yyrh
->yypred
, yyn
-= 1)
903 yydestroyGLRState (yymsg
, yyrh
]b4_user_args
[);
908 /** Left-hand-side symbol for rule #YYRULE. */
909 static inline yySymbol
910 yylhsNonterm (yyRuleNum yyrule
)
915 #define yypact_value_is_default(yystate) \
916 ]b4_table_value_equals([[pact]], [[yystate]], [b4_pact_ninf])[
918 /** True iff LR state YYSTATE has only a default reduction (regardless
921 yyisDefaultedState (yyStateNum yystate
)
923 return yypact_value_is_default (yypact
[yystate
]);
926 /** The default reduction for YYSTATE, assuming it has one. */
927 static inline yyRuleNum
928 yydefaultAction (yyStateNum yystate
)
930 return yydefact
[yystate
];
933 #define yytable_value_is_error(yytable_value) \
934 ]b4_table_value_equals([[table]], [[yytable_value]], [b4_table_ninf])[
936 /** Set *YYACTION to the action to take in YYSTATE on seeing YYTOKEN.
938 * R < 0: Reduce on rule -R.
940 * R > 0: Shift to state R.
941 * Set *YYCONFLICTS to a pointer into yyconfl to a 0-terminated list
942 * of conflicting reductions.
945 yygetLRActions (yyStateNum yystate
, int yytoken
,
946 int* yyaction
, const short int** yyconflicts
)
948 int yyindex
= yypact
[yystate
] + yytoken
;
949 if (yypact_value_is_default (yypact
[yystate
])
950 || yyindex
< 0 || YYLAST
< yyindex
|| yycheck
[yyindex
] != yytoken
)
952 *yyaction
= -yydefact
[yystate
];
953 *yyconflicts
= yyconfl
;
955 else if (! yytable_value_is_error (yytable
[yyindex
]))
957 *yyaction
= yytable
[yyindex
];
958 *yyconflicts
= yyconfl
+ yyconflp
[yyindex
];
963 *yyconflicts
= yyconfl
+ yyconflp
[yyindex
];
967 static inline yyStateNum
968 yyLRgotoState (yyStateNum yystate
, yySymbol yylhs
)
970 int yyr
= yypgoto
[yylhs
- YYNTOKENS
] + yystate
;
971 if (0 <= yyr
&& yyr
<= YYLAST
&& yycheck
[yyr
] == yystate
)
974 return yydefgoto
[yylhs
- YYNTOKENS
];
978 yyisShiftAction (int yyaction
)
984 yyisErrorAction (int yyaction
)
986 return yyaction
== 0;
991 /** Return a fresh GLRStackItem in YYSTACKP. The item is an LR state
992 * if YYISSTATE, and otherwise a semantic option. Callers should call
993 * YY_RESERVE_GLRSTACK afterwards to make sure there is sufficient
996 static inline yyGLRStackItem
*
997 yynewGLRStackItem (yyGLRStack
* yystackp
, yybool yyisState
)
999 yyGLRStackItem
* yynewItem
= yystackp
->yynextFree
;
1000 yystackp
->yyspaceLeft
-= 1;
1001 yystackp
->yynextFree
+= 1;
1002 yynewItem
->yystate
.yyisState
= yyisState
;
1006 /** Add a new semantic action that will execute the action for rule
1007 * YYRULE on the semantic values in YYRHS to the list of
1008 * alternative actions for YYSTATE. Assumes that YYRHS comes from
1009 * stack #YYK of *YYSTACKP. */
1011 yyaddDeferredAction (yyGLRStack
* yystackp
, size_t yyk
, yyGLRState
* yystate
,
1012 yyGLRState
* yyrhs
, yyRuleNum yyrule
)
1014 yySemanticOption
* yynewOption
=
1015 &yynewGLRStackItem (yystackp
, yyfalse
)->yyoption
;
1016 yynewOption
->yystate
= yyrhs
;
1017 yynewOption
->yyrule
= yyrule
;
1018 if (yystackp
->yytops
.yylookaheadNeeds
[yyk
])
1020 yynewOption
->yyrawchar
= yychar
;
1021 yynewOption
->yyval
= yylval
;]b4_locations_if([
1022 yynewOption
->yyloc
= yylloc
;])[
1025 yynewOption
->yyrawchar
= YYEMPTY
;
1026 yynewOption
->yynext
= yystate
->yysemantics
.yyfirstVal
;
1027 yystate
->yysemantics
.yyfirstVal
= yynewOption
;
1029 YY_RESERVE_GLRSTACK (yystackp
);
1034 /** Initialize YYSET to a singleton set containing an empty stack. */
1036 yyinitStateSet (yyGLRStateSet
* yyset
)
1039 yyset
->yycapacity
= 16;
1040 yyset
->yystates
= (yyGLRState
**) YYMALLOC (16 * sizeof yyset
->yystates
[0]);
1041 if (! yyset
->yystates
)
1043 yyset
->yystates
[0] = YY_NULL
;
1044 yyset
->yylookaheadNeeds
=
1045 (yybool
*) YYMALLOC (16 * sizeof yyset
->yylookaheadNeeds
[0]);
1046 if (! yyset
->yylookaheadNeeds
)
1048 YYFREE (yyset
->yystates
);
1054 static void yyfreeStateSet (yyGLRStateSet
* yyset
)
1056 YYFREE (yyset
->yystates
);
1057 YYFREE (yyset
->yylookaheadNeeds
);
1060 /** Initialize *YYSTACKP to a single empty stack, with total maximum
1061 * capacity for all stacks of YYSIZE. */
1063 yyinitGLRStack (yyGLRStack
* yystackp
, size_t yysize
)
1065 yystackp
->yyerrState
= 0;
1067 yystackp
->yyspaceLeft
= yysize
;
1069 (yyGLRStackItem
*) YYMALLOC (yysize
* sizeof yystackp
->yynextFree
[0]);
1070 if (!yystackp
->yyitems
)
1072 yystackp
->yynextFree
= yystackp
->yyitems
;
1073 yystackp
->yysplitPoint
= YY_NULL
;
1074 yystackp
->yylastDeleted
= YY_NULL
;
1075 return yyinitStateSet (&yystackp
->yytops
);
1079 #if YYSTACKEXPANDABLE
1080 # define YYRELOC(YYFROMITEMS,YYTOITEMS,YYX,YYTYPE) \
1081 &((YYTOITEMS) - ((YYFROMITEMS) - (yyGLRStackItem*) (YYX)))->YYTYPE
1083 /** If *YYSTACKP is expandable, extend it. WARNING: Pointers into the
1084 stack from outside should be considered invalid after this call.
1085 We always expand when there are 1 or fewer items left AFTER an
1086 allocation, so that we can avoid having external pointers exist
1087 across an allocation. */
1089 yyexpandGLRStack (yyGLRStack
* yystackp
)
1091 yyGLRStackItem
* yynewItems
;
1092 yyGLRStackItem
* yyp0
, *yyp1
;
1095 size_t yysize
= yystackp
->yynextFree
- yystackp
->yyitems
;
1096 if (YYMAXDEPTH
- YYHEADROOM
< yysize
)
1097 yyMemoryExhausted (yystackp
);
1098 yynewSize
= 2*yysize
;
1099 if (YYMAXDEPTH
< yynewSize
)
1100 yynewSize
= YYMAXDEPTH
;
1101 yynewItems
= (yyGLRStackItem
*) YYMALLOC (yynewSize
* sizeof yynewItems
[0]);
1103 yyMemoryExhausted (yystackp
);
1104 for (yyp0
= yystackp
->yyitems
, yyp1
= yynewItems
, yyn
= yysize
;
1106 yyn
-= 1, yyp0
+= 1, yyp1
+= 1)
1109 if (*(yybool
*) yyp0
)
1111 yyGLRState
* yys0
= &yyp0
->yystate
;
1112 yyGLRState
* yys1
= &yyp1
->yystate
;
1113 if (yys0
->yypred
!= YY_NULL
)
1115 YYRELOC (yyp0
, yyp1
, yys0
->yypred
, yystate
);
1116 if (! yys0
->yyresolved
&& yys0
->yysemantics
.yyfirstVal
!= YY_NULL
)
1117 yys1
->yysemantics
.yyfirstVal
=
1118 YYRELOC (yyp0
, yyp1
, yys0
->yysemantics
.yyfirstVal
, yyoption
);
1122 yySemanticOption
* yyv0
= &yyp0
->yyoption
;
1123 yySemanticOption
* yyv1
= &yyp1
->yyoption
;
1124 if (yyv0
->yystate
!= YY_NULL
)
1125 yyv1
->yystate
= YYRELOC (yyp0
, yyp1
, yyv0
->yystate
, yystate
);
1126 if (yyv0
->yynext
!= YY_NULL
)
1127 yyv1
->yynext
= YYRELOC (yyp0
, yyp1
, yyv0
->yynext
, yyoption
);
1130 if (yystackp
->yysplitPoint
!= YY_NULL
)
1131 yystackp
->yysplitPoint
= YYRELOC (yystackp
->yyitems
, yynewItems
,
1132 yystackp
->yysplitPoint
, yystate
);
1134 for (yyn
= 0; yyn
< yystackp
->yytops
.yysize
; yyn
+= 1)
1135 if (yystackp
->yytops
.yystates
[yyn
] != YY_NULL
)
1136 yystackp
->yytops
.yystates
[yyn
] =
1137 YYRELOC (yystackp
->yyitems
, yynewItems
,
1138 yystackp
->yytops
.yystates
[yyn
], yystate
);
1139 YYFREE (yystackp
->yyitems
);
1140 yystackp
->yyitems
= yynewItems
;
1141 yystackp
->yynextFree
= yynewItems
+ yysize
;
1142 yystackp
->yyspaceLeft
= yynewSize
- yysize
;
1147 yyfreeGLRStack (yyGLRStack
* yystackp
)
1149 YYFREE (yystackp
->yyitems
);
1150 yyfreeStateSet (&yystackp
->yytops
);
1153 /** Assuming that YYS is a GLRState somewhere on *YYSTACKP, update the
1154 * splitpoint of *YYSTACKP, if needed, so that it is at least as deep as
1157 yyupdateSplit (yyGLRStack
* yystackp
, yyGLRState
* yys
)
1159 if (yystackp
->yysplitPoint
!= YY_NULL
&& yystackp
->yysplitPoint
> yys
)
1160 yystackp
->yysplitPoint
= yys
;
1163 /** Invalidate stack #YYK in *YYSTACKP. */
1165 yymarkStackDeleted (yyGLRStack
* yystackp
, size_t yyk
)
1167 if (yystackp
->yytops
.yystates
[yyk
] != YY_NULL
)
1168 yystackp
->yylastDeleted
= yystackp
->yytops
.yystates
[yyk
];
1169 yystackp
->yytops
.yystates
[yyk
] = YY_NULL
;
1172 /** Undelete the last stack in *YYSTACKP that was marked as deleted. Can
1173 only be done once after a deletion, and only when all other stacks have
1176 yyundeleteLastStack (yyGLRStack
* yystackp
)
1178 if (yystackp
->yylastDeleted
== YY_NULL
|| yystackp
->yytops
.yysize
!= 0)
1180 yystackp
->yytops
.yystates
[0] = yystackp
->yylastDeleted
;
1181 yystackp
->yytops
.yysize
= 1;
1182 YYDPRINTF ((stderr
, "Restoring last deleted stack as stack #0.\n"));
1183 yystackp
->yylastDeleted
= YY_NULL
;
1187 yyremoveDeletes (yyGLRStack
* yystackp
)
1191 while (yyj
< yystackp
->yytops
.yysize
)
1193 if (yystackp
->yytops
.yystates
[yyi
] == YY_NULL
)
1197 YYDPRINTF ((stderr
, "Removing dead stacks.\n"));
1199 yystackp
->yytops
.yysize
-= 1;
1203 yystackp
->yytops
.yystates
[yyj
] = yystackp
->yytops
.yystates
[yyi
];
1204 /* In the current implementation, it's unnecessary to copy
1205 yystackp->yytops.yylookaheadNeeds[yyi] since, after
1206 yyremoveDeletes returns, the parser immediately either enters
1207 deterministic operation or shifts a token. However, it doesn't
1208 hurt, and the code might evolve to need it. */
1209 yystackp
->yytops
.yylookaheadNeeds
[yyj
] =
1210 yystackp
->yytops
.yylookaheadNeeds
[yyi
];
1213 YYDPRINTF ((stderr
, "Rename stack %lu -> %lu.\n",
1214 (unsigned long int) yyi
, (unsigned long int) yyj
));
1222 /** Shift to a new state on stack #YYK of *YYSTACKP, corresponding to LR
1223 * state YYLRSTATE, at input position YYPOSN, with (resolved) semantic
1224 * value *YYVALP and source location *YYLOCP. */
1226 yyglrShift (yyGLRStack
* yystackp
, size_t yyk
, yyStateNum yylrState
,
1228 YYSTYPE
* yyvalp
]b4_locations_if([, YYLTYPE
* yylocp
])[)
1230 yyGLRState
* yynewState
= &yynewGLRStackItem (yystackp
, yytrue
)->yystate
;
1232 yynewState
->yylrState
= yylrState
;
1233 yynewState
->yyposn
= yyposn
;
1234 yynewState
->yyresolved
= yytrue
;
1235 yynewState
->yypred
= yystackp
->yytops
.yystates
[yyk
];
1236 yynewState
->yysemantics
.yysval
= *yyvalp
;]b4_locations_if([
1237 yynewState
->yyloc
= *yylocp
;])[
1238 yystackp
->yytops
.yystates
[yyk
] = yynewState
;
1240 YY_RESERVE_GLRSTACK (yystackp
);
1243 /** Shift stack #YYK of *YYSTACKP, to a new state corresponding to LR
1244 * state YYLRSTATE, at input position YYPOSN, with the (unresolved)
1245 * semantic value of YYRHS under the action for YYRULE. */
1247 yyglrShiftDefer (yyGLRStack
* yystackp
, size_t yyk
, yyStateNum yylrState
,
1248 size_t yyposn
, yyGLRState
* yyrhs
, yyRuleNum yyrule
)
1250 yyGLRState
* yynewState
= &yynewGLRStackItem (yystackp
, yytrue
)->yystate
;
1252 yynewState
->yylrState
= yylrState
;
1253 yynewState
->yyposn
= yyposn
;
1254 yynewState
->yyresolved
= yyfalse
;
1255 yynewState
->yypred
= yystackp
->yytops
.yystates
[yyk
];
1256 yynewState
->yysemantics
.yyfirstVal
= YY_NULL
;
1257 yystackp
->yytops
.yystates
[yyk
] = yynewState
;
1259 /* Invokes YY_RESERVE_GLRSTACK. */
1260 yyaddDeferredAction (yystackp
, yyk
, yynewState
, yyrhs
, yyrule
);
1263 #if !]b4_api_PREFIX[DEBUG
1264 # define YY_REDUCE_PRINT(Args)
1266 # define YY_REDUCE_PRINT(Args) \
1269 yy_reduce_print Args; \
1272 /*----------------------------------------------------------------------.
1273 | Report that stack #YYK of *YYSTACKP is going to be reduced by YYRULE. |
1274 `----------------------------------------------------------------------*/
1277 yy_reduce_print (int yynormal
, yyGLRStackItem
* yyvsp
, size_t yyk
,
1278 yyRuleNum yyrule
]b4_user_formals
[)
1280 int yynrhs
= yyrhsLength (yyrule
);]b4_locations_if([
1283 YYFPRINTF (stderr
, "Reducing stack %lu by rule %d (line %lu):\n",
1284 (unsigned long int) yyk
, yyrule
- 1,
1285 (unsigned long int) yyrline
[yyrule
]);
1287 yyfillin (yyvsp
, 1, -yynrhs
);
1288 /* The symbols being reduced. */
1289 for (yyi
= 0; yyi
< yynrhs
; yyi
++)
1291 YYFPRINTF (stderr
, " $%d = ", yyi
+ 1);
1292 yy_symbol_print (stderr
,
1293 yystos
[yyvsp
[yyi
- yynrhs
+ 1].yystate
.yylrState
],
1294 &yyvsp
[yyi
- yynrhs
+ 1].yystate
.yysemantics
.yysval
1295 ]b4_locations_if([, &]b4_rhs_location(yynrhs
, yyi
+ 1))[]dnl
1297 if (!yyvsp
[yyi
- yynrhs
+ 1].yystate
.yyresolved
)
1298 YYFPRINTF (stderr
, " (unresolved)");
1299 YYFPRINTF (stderr
, "\n");
1304 /** Pop the symbols consumed by reduction #YYRULE from the top of stack
1305 * #YYK of *YYSTACKP, and perform the appropriate semantic action on their
1306 * semantic values. Assumes that all ambiguities in semantic values
1307 * have been previously resolved. Set *YYVALP to the resulting value,
1308 * and *YYLOCP to the computed location (if any). Return value is as
1309 * for userAction. */
1310 static inline YYRESULTTAG
1311 yydoAction (yyGLRStack
* yystackp
, size_t yyk
, yyRuleNum yyrule
,
1312 YYSTYPE
* yyvalp
]b4_locuser_formals
[)
1314 int yynrhs
= yyrhsLength (yyrule
);
1316 if (yystackp
->yysplitPoint
== YY_NULL
)
1318 /* Standard special case: single stack. */
1319 yyGLRStackItem
* yyrhs
= (yyGLRStackItem
*) yystackp
->yytops
.yystates
[yyk
];
1320 YYASSERT (yyk
== 0);
1321 yystackp
->yynextFree
-= yynrhs
;
1322 yystackp
->yyspaceLeft
+= yynrhs
;
1323 yystackp
->yytops
.yystates
[0] = & yystackp
->yynextFree
[-1].yystate
;
1324 YY_REDUCE_PRINT ((1, yyrhs
, yyk
, yyrule
]b4_user_args
[));
1325 return yyuserAction (yyrule
, yynrhs
, yyrhs
, yystackp
,
1326 yyvalp
]b4_locuser_args
[);
1332 yyGLRStackItem yyrhsVals
[YYMAXRHS
+ YYMAXLEFT
+ 1];
1333 yys
= yyrhsVals
[YYMAXRHS
+ YYMAXLEFT
].yystate
.yypred
1334 = yystackp
->yytops
.yystates
[yyk
];]b4_locations_if([[
1336 /* Set default location. */
1337 yyrhsVals
[YYMAXRHS
+ YYMAXLEFT
- 1].yystate
.yyloc
= yys
->yyloc
;]])[
1338 for (yyi
= 0; yyi
< yynrhs
; yyi
+= 1)
1343 yyupdateSplit (yystackp
, yys
);
1344 yystackp
->yytops
.yystates
[yyk
] = yys
;
1345 YY_REDUCE_PRINT ((0, yyrhsVals
+ YYMAXRHS
+ YYMAXLEFT
- 1, yyk
, yyrule
]b4_user_args
[));
1346 return yyuserAction (yyrule
, yynrhs
, yyrhsVals
+ YYMAXRHS
+ YYMAXLEFT
- 1,
1347 yystackp
, yyvalp
]b4_locuser_args
[);
1351 /** Pop items off stack #YYK of *YYSTACKP according to grammar rule YYRULE,
1352 * and push back on the resulting nonterminal symbol. Perform the
1353 * semantic action associated with YYRULE and store its value with the
1354 * newly pushed state, if YYFORCEEVAL or if *YYSTACKP is currently
1355 * unambiguous. Otherwise, store the deferred semantic action with
1356 * the new state. If the new state would have an identical input
1357 * position, LR state, and predecessor to an existing state on the stack,
1358 * it is identified with that existing state, eliminating stack #YYK from
1359 * *YYSTACKP. In this case, the semantic value is
1360 * added to the options for the existing state's semantic value.
1362 static inline YYRESULTTAG
1363 yyglrReduce (yyGLRStack
* yystackp
, size_t yyk
, yyRuleNum yyrule
,
1364 yybool yyforceEval
]b4_user_formals
[)
1366 size_t yyposn
= yystackp
->yytops
.yystates
[yyk
]->yyposn
;
1368 if (yyforceEval
|| yystackp
->yysplitPoint
== YY_NULL
)
1371 YYSTYPE yysval
;]b4_locations_if([
1374 yyflag
= yydoAction (yystackp
, yyk
, yyrule
, &yysval
]b4_locuser_args([&yyloc
])[);
1375 if (yyflag
== yyerr
&& yystackp
->yysplitPoint
!= YY_NULL
)
1377 YYDPRINTF ((stderr
, "Parse on stack %lu rejected by rule #%d.\n",
1378 (unsigned long int) yyk
, yyrule
- 1));
1382 YY_SYMBOL_PRINT ("-> $$ =", yyr1
[yyrule
], &yysval
, &yyloc
);
1383 yyglrShift (yystackp
, yyk
,
1384 yyLRgotoState (yystackp
->yytops
.yystates
[yyk
]->yylrState
,
1385 yylhsNonterm (yyrule
)),
1386 yyposn
, &yysval
]b4_locations_if([, &yyloc
])[);
1392 yyGLRState
* yys
, *yys0
= yystackp
->yytops
.yystates
[yyk
];
1393 yyStateNum yynewLRState
;
1395 for (yys
= yystackp
->yytops
.yystates
[yyk
], yyn
= yyrhsLength (yyrule
);
1401 yyupdateSplit (yystackp
, yys
);
1402 yynewLRState
= yyLRgotoState (yys
->yylrState
, yylhsNonterm (yyrule
));
1404 "Reduced stack %lu by rule #%d; action deferred. "
1405 "Now in state %d.\n",
1406 (unsigned long int) yyk
, yyrule
- 1, yynewLRState
));
1407 for (yyi
= 0; yyi
< yystackp
->yytops
.yysize
; yyi
+= 1)
1408 if (yyi
!= yyk
&& yystackp
->yytops
.yystates
[yyi
] != YY_NULL
)
1410 yyGLRState
*yysplit
= yystackp
->yysplitPoint
;
1411 yyGLRState
*yyp
= yystackp
->yytops
.yystates
[yyi
];
1412 while (yyp
!= yys
&& yyp
!= yysplit
&& yyp
->yyposn
>= yyposn
)
1414 if (yyp
->yylrState
== yynewLRState
&& yyp
->yypred
== yys
)
1416 yyaddDeferredAction (yystackp
, yyk
, yyp
, yys0
, yyrule
);
1417 yymarkStackDeleted (yystackp
, yyk
);
1418 YYDPRINTF ((stderr
, "Merging stack %lu into stack %lu.\n",
1419 (unsigned long int) yyk
,
1420 (unsigned long int) yyi
));
1426 yystackp
->yytops
.yystates
[yyk
] = yys
;
1427 yyglrShiftDefer (yystackp
, yyk
, yynewLRState
, yyposn
, yys0
, yyrule
);
1433 yysplitStack (yyGLRStack
* yystackp
, size_t yyk
)
1435 if (yystackp
->yysplitPoint
== YY_NULL
)
1437 YYASSERT (yyk
== 0);
1438 yystackp
->yysplitPoint
= yystackp
->yytops
.yystates
[yyk
];
1440 if (yystackp
->yytops
.yysize
>= yystackp
->yytops
.yycapacity
)
1442 yyGLRState
** yynewStates
;
1443 yybool
* yynewLookaheadNeeds
;
1445 yynewStates
= YY_NULL
;
1447 if (yystackp
->yytops
.yycapacity
1448 > (YYSIZEMAX
/ (2 * sizeof yynewStates
[0])))
1449 yyMemoryExhausted (yystackp
);
1450 yystackp
->yytops
.yycapacity
*= 2;
1453 (yyGLRState
**) YYREALLOC (yystackp
->yytops
.yystates
,
1454 (yystackp
->yytops
.yycapacity
1455 * sizeof yynewStates
[0]));
1456 if (yynewStates
== YY_NULL
)
1457 yyMemoryExhausted (yystackp
);
1458 yystackp
->yytops
.yystates
= yynewStates
;
1460 yynewLookaheadNeeds
=
1461 (yybool
*) YYREALLOC (yystackp
->yytops
.yylookaheadNeeds
,
1462 (yystackp
->yytops
.yycapacity
1463 * sizeof yynewLookaheadNeeds
[0]));
1464 if (yynewLookaheadNeeds
== YY_NULL
)
1465 yyMemoryExhausted (yystackp
);
1466 yystackp
->yytops
.yylookaheadNeeds
= yynewLookaheadNeeds
;
1468 yystackp
->yytops
.yystates
[yystackp
->yytops
.yysize
]
1469 = yystackp
->yytops
.yystates
[yyk
];
1470 yystackp
->yytops
.yylookaheadNeeds
[yystackp
->yytops
.yysize
]
1471 = yystackp
->yytops
.yylookaheadNeeds
[yyk
];
1472 yystackp
->yytops
.yysize
+= 1;
1473 return yystackp
->yytops
.yysize
-1;
1476 /** True iff YYY0 and YYY1 represent identical options at the top level.
1477 * That is, they represent the same rule applied to RHS symbols
1478 * that produce the same terminal symbols. */
1480 yyidenticalOptions (yySemanticOption
* yyy0
, yySemanticOption
* yyy1
)
1482 if (yyy0
->yyrule
== yyy1
->yyrule
)
1484 yyGLRState
*yys0
, *yys1
;
1486 for (yys0
= yyy0
->yystate
, yys1
= yyy1
->yystate
,
1487 yyn
= yyrhsLength (yyy0
->yyrule
);
1489 yys0
= yys0
->yypred
, yys1
= yys1
->yypred
, yyn
-= 1)
1490 if (yys0
->yyposn
!= yys1
->yyposn
)
1498 /** Assuming identicalOptions (YYY0,YYY1), destructively merge the
1499 * alternative semantic values for the RHS-symbols of YYY1 and YYY0. */
1501 yymergeOptionSets (yySemanticOption
* yyy0
, yySemanticOption
* yyy1
)
1503 yyGLRState
*yys0
, *yys1
;
1505 for (yys0
= yyy0
->yystate
, yys1
= yyy1
->yystate
,
1506 yyn
= yyrhsLength (yyy0
->yyrule
);
1508 yys0
= yys0
->yypred
, yys1
= yys1
->yypred
, yyn
-= 1)
1512 else if (yys0
->yyresolved
)
1514 yys1
->yyresolved
= yytrue
;
1515 yys1
->yysemantics
.yysval
= yys0
->yysemantics
.yysval
;
1517 else if (yys1
->yyresolved
)
1519 yys0
->yyresolved
= yytrue
;
1520 yys0
->yysemantics
.yysval
= yys1
->yysemantics
.yysval
;
1524 yySemanticOption
** yyz0p
= &yys0
->yysemantics
.yyfirstVal
;
1525 yySemanticOption
* yyz1
= yys1
->yysemantics
.yyfirstVal
;
1528 if (yyz1
== *yyz0p
|| yyz1
== YY_NULL
)
1530 else if (*yyz0p
== YY_NULL
)
1535 else if (*yyz0p
< yyz1
)
1537 yySemanticOption
* yyz
= *yyz0p
;
1539 yyz1
= yyz1
->yynext
;
1540 (*yyz0p
)->yynext
= yyz
;
1542 yyz0p
= &(*yyz0p
)->yynext
;
1544 yys1
->yysemantics
.yyfirstVal
= yys0
->yysemantics
.yyfirstVal
;
1549 /** Y0 and Y1 represent two possible actions to take in a given
1550 * parsing state; return 0 if no combination is possible,
1551 * 1 if user-mergeable, 2 if Y0 is preferred, 3 if Y1 is preferred. */
1553 yypreference (yySemanticOption
* y0
, yySemanticOption
* y1
)
1555 yyRuleNum r0
= y0
->yyrule
, r1
= y1
->yyrule
;
1556 int p0
= yydprec
[r0
], p1
= yydprec
[r1
];
1560 if (yymerger
[r0
] == 0 || yymerger
[r0
] != yymerger
[r1
])
1565 if (p0
== 0 || p1
== 0)
1574 static YYRESULTTAG
yyresolveValue (yyGLRState
* yys
,
1575 yyGLRStack
* yystackp
]b4_user_formals
[);
1578 /** Resolve the previous YYN states starting at and including state YYS
1579 * on *YYSTACKP. If result != yyok, some states may have been left
1580 * unresolved possibly with empty semantic option chains. Regardless
1581 * of whether result = yyok, each state has been left with consistent
1582 * data so that yydestroyGLRState can be invoked if necessary. */
1584 yyresolveStates (yyGLRState
* yys
, int yyn
,
1585 yyGLRStack
* yystackp
]b4_user_formals
[)
1589 YYASSERT (yys
->yypred
);
1590 YYCHK (yyresolveStates (yys
->yypred
, yyn
-1, yystackp
]b4_user_args
[));
1591 if (! yys
->yyresolved
)
1592 YYCHK (yyresolveValue (yys
, yystackp
]b4_user_args
[));
1597 /** Resolve the states for the RHS of YYOPT on *YYSTACKP, perform its
1598 * user action, and return the semantic value and location in *YYVALP
1599 * and *YYLOCP. Regardless of whether result = yyok, all RHS states
1600 * have been destroyed (assuming the user action destroys all RHS
1601 * semantic values if invoked). */
1603 yyresolveAction (yySemanticOption
* yyopt
, yyGLRStack
* yystackp
,
1604 YYSTYPE
* yyvalp
]b4_locuser_formals
[)
1606 yyGLRStackItem yyrhsVals
[YYMAXRHS
+ YYMAXLEFT
+ 1];
1607 int yynrhs
= yyrhsLength (yyopt
->yyrule
);
1608 YYRESULTTAG yyflag
=
1609 yyresolveStates (yyopt
->yystate
, yynrhs
, yystackp
]b4_user_args
[);
1613 for (yys
= yyopt
->yystate
; yynrhs
> 0; yys
= yys
->yypred
, yynrhs
-= 1)
1614 yydestroyGLRState ("Cleanup: popping", yys
]b4_user_args
[);
1618 yyrhsVals
[YYMAXRHS
+ YYMAXLEFT
].yystate
.yypred
= yyopt
->yystate
;]b4_locations_if([[
1620 /* Set default location. */
1621 yyrhsVals
[YYMAXRHS
+ YYMAXLEFT
- 1].yystate
.yyloc
= yyopt
->yystate
->yyloc
;]])[
1623 int yychar_current
= yychar
;
1624 YYSTYPE yylval_current
= yylval
;]b4_locations_if([
1625 YYLTYPE yylloc_current
= yylloc
;])[
1626 yychar
= yyopt
->yyrawchar
;
1627 yylval
= yyopt
->yyval
;]b4_locations_if([
1628 yylloc
= yyopt
->yyloc
;])[
1629 yyflag
= yyuserAction (yyopt
->yyrule
, yynrhs
,
1630 yyrhsVals
+ YYMAXRHS
+ YYMAXLEFT
- 1,
1631 yystackp
, yyvalp
]b4_locuser_args
[);
1632 yychar
= yychar_current
;
1633 yylval
= yylval_current
;]b4_locations_if([
1634 yylloc
= yylloc_current
;])[
1639 #if ]b4_api_PREFIX[DEBUG
1641 yyreportTree (yySemanticOption
* yyx
, int yyindent
)
1643 int yynrhs
= yyrhsLength (yyx
->yyrule
);
1646 yyGLRState
* yystates
[1 + YYMAXRHS
];
1647 yyGLRState yyleftmost_state
;
1649 for (yyi
= yynrhs
, yys
= yyx
->yystate
; 0 < yyi
; yyi
-= 1, yys
= yys
->yypred
)
1650 yystates
[yyi
] = yys
;
1653 yyleftmost_state
.yyposn
= 0;
1654 yystates
[0] = &yyleftmost_state
;
1659 if (yyx
->yystate
->yyposn
< yys
->yyposn
+ 1)
1660 YYFPRINTF (stderr
, "%*s%s -> <Rule %d, empty>\n",
1661 yyindent
, "", yytokenName (yylhsNonterm (yyx
->yyrule
)),
1664 YYFPRINTF (stderr
, "%*s%s -> <Rule %d, tokens %lu .. %lu>\n",
1665 yyindent
, "", yytokenName (yylhsNonterm (yyx
->yyrule
)),
1666 yyx
->yyrule
- 1, (unsigned long int) (yys
->yyposn
+ 1),
1667 (unsigned long int) yyx
->yystate
->yyposn
);
1668 for (yyi
= 1; yyi
<= yynrhs
; yyi
+= 1)
1670 if (yystates
[yyi
]->yyresolved
)
1672 if (yystates
[yyi
-1]->yyposn
+1 > yystates
[yyi
]->yyposn
)
1673 YYFPRINTF (stderr
, "%*s%s <empty>\n", yyindent
+2, "",
1674 yytokenName (yystos
[yystates
[yyi
]->yylrState
]));
1676 YYFPRINTF (stderr
, "%*s%s <tokens %lu .. %lu>\n", yyindent
+2, "",
1677 yytokenName (yystos
[yystates
[yyi
]->yylrState
]),
1678 (unsigned long int) (yystates
[yyi
-1]->yyposn
+ 1),
1679 (unsigned long int) yystates
[yyi
]->yyposn
);
1682 yyreportTree (yystates
[yyi
]->yysemantics
.yyfirstVal
, yyindent
+2);
1688 yyreportAmbiguity (yySemanticOption
* yyx0
,
1689 yySemanticOption
* yyx1
]b4_pure_formals
[)
1694 #if ]b4_api_PREFIX[DEBUG
1695 YYFPRINTF (stderr
, "Ambiguity detected.\n");
1696 YYFPRINTF (stderr
, "Option 1,\n");
1697 yyreportTree (yyx0
, 2);
1698 YYFPRINTF (stderr
, "\nOption 2,\n");
1699 yyreportTree (yyx1
, 2);
1700 YYFPRINTF (stderr
, "\n");
1703 yyerror (]b4_yyerror_args
[YY_("syntax is ambiguous"));
1705 }]b4_locations_if([[
1707 /** Resolve the locations for each of the YYN1 states in *YYSTACKP,
1708 * ending at YYS1. Has no effect on previously resolved states.
1709 * The first semantic option of a state is always chosen. */
1711 yyresolveLocations (yyGLRState
* yys1
, int yyn1
,
1712 yyGLRStack
*yystackp
]b4_user_formals
[)
1716 yyresolveLocations (yys1
->yypred
, yyn1
- 1, yystackp
]b4_user_args
[);
1717 if (!yys1
->yyresolved
)
1719 yyGLRStackItem yyrhsloc
[1 + YYMAXRHS
];
1721 yySemanticOption
*yyoption
= yys1
->yysemantics
.yyfirstVal
;
1722 YYASSERT (yyoption
!= YY_NULL
);
1723 yynrhs
= yyrhsLength (yyoption
->yyrule
);
1728 yyresolveLocations (yyoption
->yystate
, yynrhs
,
1729 yystackp
]b4_user_args
[);
1730 for (yys
= yyoption
->yystate
, yyn
= yynrhs
;
1732 yys
= yys
->yypred
, yyn
-= 1)
1733 yyrhsloc
[yyn
].yystate
.yyloc
= yys
->yyloc
;
1737 /* Both yyresolveAction and yyresolveLocations traverse the GSS
1738 in reverse rightmost order. It is only necessary to invoke
1739 yyresolveLocations on a subforest for which yyresolveAction
1740 would have been invoked next had an ambiguity not been
1741 detected. Thus the location of the previous state (but not
1742 necessarily the previous state itself) is guaranteed to be
1743 resolved already. */
1744 yyGLRState
*yyprevious
= yyoption
->yystate
;
1745 yyrhsloc
[0].yystate
.yyloc
= yyprevious
->yyloc
;
1748 int yychar_current
= yychar
;
1749 YYSTYPE yylval_current
= yylval
;
1750 YYLTYPE yylloc_current
= yylloc
;
1751 yychar
= yyoption
->yyrawchar
;
1752 yylval
= yyoption
->yyval
;
1753 yylloc
= yyoption
->yyloc
;
1754 YYLLOC_DEFAULT ((yys1
->yyloc
), yyrhsloc
, yynrhs
);
1755 yychar
= yychar_current
;
1756 yylval
= yylval_current
;
1757 yylloc
= yylloc_current
;
1763 /** Resolve the ambiguity represented in state YYS in *YYSTACKP,
1764 * perform the indicated actions, and set the semantic value of YYS.
1765 * If result != yyok, the chain of semantic options in YYS has been
1766 * cleared instead or it has been left unmodified except that
1767 * redundant options may have been removed. Regardless of whether
1768 * result = yyok, YYS has been left with consistent data so that
1769 * yydestroyGLRState can be invoked if necessary. */
1771 yyresolveValue (yyGLRState
* yys
, yyGLRStack
* yystackp
]b4_user_formals
[)
1773 yySemanticOption
* yyoptionList
= yys
->yysemantics
.yyfirstVal
;
1774 yySemanticOption
* yybest
= yyoptionList
;
1775 yySemanticOption
** yypp
;
1776 yybool yymerge
= yyfalse
;
1778 YYRESULTTAG yyflag
;]b4_locations_if([
1779 YYLTYPE
*yylocp
= &yys
->yyloc
;])[
1781 for (yypp
= &yyoptionList
->yynext
; *yypp
!= YY_NULL
; )
1783 yySemanticOption
* yyp
= *yypp
;
1785 if (yyidenticalOptions (yybest
, yyp
))
1787 yymergeOptionSets (yybest
, yyp
);
1788 *yypp
= yyp
->yynext
;
1792 switch (yypreference (yybest
, yyp
))
1794 case 0:]b4_locations_if([[
1795 yyresolveLocations (yys
, 1, yystackp
]b4_user_args
[);]])[
1796 return yyreportAmbiguity (yybest
, yyp
]b4_pure_args
[);
1808 /* This cannot happen so it is not worth a YYASSERT (yyfalse),
1809 but some compilers complain if the default case is
1813 yypp
= &yyp
->yynext
;
1819 yySemanticOption
* yyp
;
1820 int yyprec
= yydprec
[yybest
->yyrule
];
1821 yyflag
= yyresolveAction (yybest
, yystackp
, &yysval
]b4_locuser_args
[);
1823 for (yyp
= yybest
->yynext
; yyp
!= YY_NULL
; yyp
= yyp
->yynext
)
1825 if (yyprec
== yydprec
[yyp
->yyrule
])
1827 YYSTYPE yysval_other
;]b4_locations_if([
1829 yyflag
= yyresolveAction (yyp
, yystackp
, &yysval_other
]b4_locuser_args([&yydummy
])[);
1832 yydestruct ("Cleanup: discarding incompletely merged value for",
1833 yystos
[yys
->yylrState
],
1834 &yysval
]b4_locuser_args
[);
1837 yyuserMerge (yymerger
[yyp
->yyrule
], &yysval
, &yysval_other
);
1842 yyflag
= yyresolveAction (yybest
, yystackp
, &yysval
]b4_locuser_args([yylocp
])[);
1846 yys
->yyresolved
= yytrue
;
1847 yys
->yysemantics
.yysval
= yysval
;
1850 yys
->yysemantics
.yyfirstVal
= YY_NULL
;
1855 yyresolveStack (yyGLRStack
* yystackp
]b4_user_formals
[)
1857 if (yystackp
->yysplitPoint
!= YY_NULL
)
1862 for (yyn
= 0, yys
= yystackp
->yytops
.yystates
[0];
1863 yys
!= yystackp
->yysplitPoint
;
1864 yys
= yys
->yypred
, yyn
+= 1)
1866 YYCHK (yyresolveStates (yystackp
->yytops
.yystates
[0], yyn
, yystackp
1873 yycompressStack (yyGLRStack
* yystackp
)
1875 yyGLRState
* yyp
, *yyq
, *yyr
;
1877 if (yystackp
->yytops
.yysize
!= 1 || yystackp
->yysplitPoint
== YY_NULL
)
1880 for (yyp
= yystackp
->yytops
.yystates
[0], yyq
= yyp
->yypred
, yyr
= YY_NULL
;
1881 yyp
!= yystackp
->yysplitPoint
;
1882 yyr
= yyp
, yyp
= yyq
, yyq
= yyp
->yypred
)
1885 yystackp
->yyspaceLeft
+= yystackp
->yynextFree
- yystackp
->yyitems
;
1886 yystackp
->yynextFree
= ((yyGLRStackItem
*) yystackp
->yysplitPoint
) + 1;
1887 yystackp
->yyspaceLeft
-= yystackp
->yynextFree
- yystackp
->yyitems
;
1888 yystackp
->yysplitPoint
= YY_NULL
;
1889 yystackp
->yylastDeleted
= YY_NULL
;
1891 while (yyr
!= YY_NULL
)
1893 yystackp
->yynextFree
->yystate
= *yyr
;
1895 yystackp
->yynextFree
->yystate
.yypred
= &yystackp
->yynextFree
[-1].yystate
;
1896 yystackp
->yytops
.yystates
[0] = &yystackp
->yynextFree
->yystate
;
1897 yystackp
->yynextFree
+= 1;
1898 yystackp
->yyspaceLeft
-= 1;
1903 yyprocessOneStack (yyGLRStack
* yystackp
, size_t yyk
,
1904 size_t yyposn
]b4_pure_formals
[)
1906 while (yystackp
->yytops
.yystates
[yyk
] != YY_NULL
)
1908 yyStateNum yystate
= yystackp
->yytops
.yystates
[yyk
]->yylrState
;
1909 YYDPRINTF ((stderr
, "Stack %lu Entering state %d\n",
1910 (unsigned long int) yyk
, yystate
));
1912 YYASSERT (yystate
!= YYFINAL
);
1914 if (yyisDefaultedState (yystate
))
1917 yyRuleNum yyrule
= yydefaultAction (yystate
);
1920 YYDPRINTF ((stderr
, "Stack %lu dies.\n",
1921 (unsigned long int) yyk
));
1922 yymarkStackDeleted (yystackp
, yyk
);
1925 yyflag
= yyglrReduce (yystackp
, yyk
, yyrule
, yyimmediate
[yyrule
]]b4_user_args
[);
1926 if (yyflag
== yyerr
)
1930 "(predicate failure or explicit user error).\n",
1931 (unsigned long int) yyk
));
1932 yymarkStackDeleted (yystackp
, yyk
);
1942 const short int* yyconflicts
;
1944 yystackp
->yytops
.yylookaheadNeeds
[yyk
] = yytrue
;
1945 if (yychar
== YYEMPTY
)
1947 YYDPRINTF ((stderr
, "Reading a token: "));
1951 if (yychar
<= YYEOF
)
1953 yychar
= yytoken
= YYEOF
;
1954 YYDPRINTF ((stderr
, "Now at end of input.\n"));
1958 yytoken
= YYTRANSLATE (yychar
);
1959 YY_SYMBOL_PRINT ("Next token is", yytoken
, &yylval
, &yylloc
);
1962 yygetLRActions (yystate
, yytoken
, &yyaction
, &yyconflicts
);
1964 while (*yyconflicts
!= 0)
1967 size_t yynewStack
= yysplitStack (yystackp
, yyk
);
1968 YYDPRINTF ((stderr
, "Splitting off stack %lu from %lu.\n",
1969 (unsigned long int) yynewStack
,
1970 (unsigned long int) yyk
));
1971 yyflag
= yyglrReduce (yystackp
, yynewStack
,
1973 yyimmediate
[*yyconflicts
]]b4_user_args
[);
1975 YYCHK (yyprocessOneStack (yystackp
, yynewStack
,
1976 yyposn
]b4_pure_args
[));
1977 else if (yyflag
== yyerr
)
1979 YYDPRINTF ((stderr
, "Stack %lu dies.\n",
1980 (unsigned long int) yynewStack
));
1981 yymarkStackDeleted (yystackp
, yynewStack
);
1988 if (yyisShiftAction (yyaction
))
1990 else if (yyisErrorAction (yyaction
))
1992 YYDPRINTF ((stderr
, "Stack %lu dies.\n",
1993 (unsigned long int) yyk
));
1994 yymarkStackDeleted (yystackp
, yyk
);
1999 YYRESULTTAG yyflag
= yyglrReduce (yystackp
, yyk
, -yyaction
,
2000 yyimmediate
[-yyaction
]]b4_user_args
[);
2001 if (yyflag
== yyerr
)
2005 "(predicate failure or explicit user error).\n",
2006 (unsigned long int) yyk
));
2007 yymarkStackDeleted (yystackp
, yyk
);
2010 else if (yyflag
!= yyok
)
2019 yyreportSyntaxError (yyGLRStack
* yystackp
]b4_user_formals
[)
2021 if (yystackp
->yyerrState
!= 0)
2023 #if ! YYERROR_VERBOSE
2024 yyerror (]b4_lyyerror_args
[YY_("syntax error"));
2026 yySymbol yytoken
= yychar
== YYEMPTY
? YYEMPTY
: YYTRANSLATE (yychar
);
2027 size_t yysize0
= yytnamerr (YY_NULL
, yytokenName (yytoken
));
2028 size_t yysize
= yysize0
;
2030 yybool yysize_overflow
= yyfalse
;
2031 char* yymsg
= YY_NULL
;
2032 enum { YYERROR_VERBOSE_ARGS_MAXIMUM
= 5 };
2033 /* Internationalized format string. */
2034 const char *yyformat
= YY_NULL
;
2035 /* Arguments of yyformat. */
2036 char const *yyarg
[YYERROR_VERBOSE_ARGS_MAXIMUM
];
2037 /* Number of reported tokens (one for the "unexpected", one per
2041 /* There are many possibilities here to consider:
2042 - If this state is a consistent state with a default action, then
2043 the only way this function was invoked is if the default action
2044 is an error action. In that case, don't check for expected
2045 tokens because there are none.
2046 - The only way there can be no lookahead present (in yychar) is if
2047 this state is a consistent state with a default action. Thus,
2048 detecting the absence of a lookahead is sufficient to determine
2049 that there is no unexpected or expected token to report. In that
2050 case, just report a simple "syntax error".
2051 - Don't assume there isn't a lookahead just because this state is a
2052 consistent state with a default action. There might have been a
2053 previous inconsistent state, consistent state with a non-default
2054 action, or user semantic action that manipulated yychar.
2055 - Of course, the expected token list depends on states to have
2056 correct lookahead information, and it depends on the parser not
2057 to perform extra reductions after fetching a lookahead from the
2058 scanner and before detecting a syntax error. Thus, state merging
2059 (from LALR or IELR) and default reductions corrupt the expected
2060 token list. However, the list is correct for canonical LR with
2061 one exception: it will still contain any token that will not be
2062 accepted due to an error action in a later state.
2064 if (yytoken
!= YYEMPTY
)
2066 int yyn
= yypact
[yystackp
->yytops
.yystates
[0]->yylrState
];
2067 yyarg
[yycount
++] = yytokenName (yytoken
);
2068 if (!yypact_value_is_default (yyn
))
2070 /* Start YYX at -YYN if negative to avoid negative indexes in
2071 YYCHECK. In other words, skip the first -YYN actions for this
2072 state because they are default actions. */
2073 int yyxbegin
= yyn
< 0 ? -yyn
: 0;
2074 /* Stay within bounds of both yycheck and yytname. */
2075 int yychecklim
= YYLAST
- yyn
+ 1;
2076 int yyxend
= yychecklim
< YYNTOKENS
? yychecklim
: YYNTOKENS
;
2078 for (yyx
= yyxbegin
; yyx
< yyxend
; ++yyx
)
2079 if (yycheck
[yyx
+ yyn
] == yyx
&& yyx
!= YYTERROR
2080 && !yytable_value_is_error (yytable
[yyx
+ yyn
]))
2082 if (yycount
== YYERROR_VERBOSE_ARGS_MAXIMUM
)
2088 yyarg
[yycount
++] = yytokenName (yyx
);
2089 yysize1
= yysize
+ yytnamerr (YY_NULL
, yytokenName (yyx
));
2090 yysize_overflow
|= yysize1
< yysize
;
2098 #define YYCASE_(N, S) \
2102 YYCASE_(0, YY_("syntax error"));
2103 YYCASE_(1, YY_("syntax error, unexpected %s"));
2104 YYCASE_(2, YY_("syntax error, unexpected %s, expecting %s"));
2105 YYCASE_(3, YY_("syntax error, unexpected %s, expecting %s or %s"));
2106 YYCASE_(4, YY_("syntax error, unexpected %s, expecting %s or %s or %s"));
2107 YYCASE_(5, YY_("syntax error, unexpected %s, expecting %s or %s or %s or %s"));
2111 yysize1
= yysize
+ strlen (yyformat
);
2112 yysize_overflow
|= yysize1
< yysize
;
2115 if (!yysize_overflow
)
2116 yymsg
= (char *) YYMALLOC (yysize
);
2122 while ((*yyp
= *yyformat
))
2124 if (*yyp
== '%' && yyformat
[1] == 's' && yyi
< yycount
)
2126 yyp
+= yytnamerr (yyp
, yyarg
[yyi
++]);
2135 yyerror (]b4_lyyerror_args
[yymsg
);
2140 yyerror (]b4_lyyerror_args
[YY_("syntax error"));
2141 yyMemoryExhausted (yystackp
);
2143 #endif /* YYERROR_VERBOSE */
2147 /* Recover from a syntax error on *YYSTACKP, assuming that *YYSTACKP->YYTOKENP,
2148 yylval, and yylloc are the syntactic category, semantic value, and location
2149 of the lookahead. */
2151 yyrecoverSyntaxError (yyGLRStack
* yystackp
]b4_user_formals
[)
2156 if (yystackp
->yyerrState
== 3)
2157 /* We just shifted the error token and (perhaps) took some
2158 reductions. Skip tokens until we can proceed. */
2162 if (yychar
== YYEOF
)
2163 yyFail (yystackp
][]b4_lpure_args
[, YY_NULL
);
2164 if (yychar
!= YYEMPTY
)
2165 {]b4_locations_if([[
2166 /* We throw away the lookahead, but the error range
2167 of the shifted error token must take it into account. */
2168 yyGLRState
*yys
= yystackp
->yytops
.yystates
[0];
2169 yyGLRStackItem yyerror_range
[3];
2170 yyerror_range
[1].yystate
.yyloc
= yys
->yyloc
;
2171 yyerror_range
[2].yystate
.yyloc
= yylloc
;
2172 YYLLOC_DEFAULT ((yys
->yyloc
), yyerror_range
, 2);]])[
2173 yytoken
= YYTRANSLATE (yychar
);
2174 yydestruct ("Error: discarding",
2175 yytoken
, &yylval
]b4_locuser_args([&yylloc
])[);
2177 YYDPRINTF ((stderr
, "Reading a token: "));
2179 if (yychar
<= YYEOF
)
2181 yychar
= yytoken
= YYEOF
;
2182 YYDPRINTF ((stderr
, "Now at end of input.\n"));
2186 yytoken
= YYTRANSLATE (yychar
);
2187 YY_SYMBOL_PRINT ("Next token is", yytoken
, &yylval
, &yylloc
);
2189 yyj
= yypact
[yystackp
->yytops
.yystates
[0]->yylrState
];
2190 if (yypact_value_is_default (yyj
))
2193 if (yyj
< 0 || YYLAST
< yyj
|| yycheck
[yyj
] != yytoken
)
2195 if (yydefact
[yystackp
->yytops
.yystates
[0]->yylrState
] != 0)
2198 else if (! yytable_value_is_error (yytable
[yyj
]))
2202 /* Reduce to one stack. */
2203 for (yyk
= 0; yyk
< yystackp
->yytops
.yysize
; yyk
+= 1)
2204 if (yystackp
->yytops
.yystates
[yyk
] != YY_NULL
)
2206 if (yyk
>= yystackp
->yytops
.yysize
)
2207 yyFail (yystackp
][]b4_lpure_args
[, YY_NULL
);
2208 for (yyk
+= 1; yyk
< yystackp
->yytops
.yysize
; yyk
+= 1)
2209 yymarkStackDeleted (yystackp
, yyk
);
2210 yyremoveDeletes (yystackp
);
2211 yycompressStack (yystackp
);
2213 /* Now pop stack until we find a state that shifts the error token. */
2214 yystackp
->yyerrState
= 3;
2215 while (yystackp
->yytops
.yystates
[0] != YY_NULL
)
2217 yyGLRState
*yys
= yystackp
->yytops
.yystates
[0];
2218 yyj
= yypact
[yys
->yylrState
];
2219 if (! yypact_value_is_default (yyj
))
2222 if (0 <= yyj
&& yyj
<= YYLAST
&& yycheck
[yyj
] == YYTERROR
2223 && yyisShiftAction (yytable
[yyj
]))
2225 /* Shift the error token. */]b4_locations_if([[
2226 /* First adjust its location.*/
2228 yystackp
->yyerror_range
[2].yystate
.yyloc
= yylloc
;
2229 YYLLOC_DEFAULT (yyerrloc
, (yystackp
->yyerror_range
), 2);]])[
2230 YY_SYMBOL_PRINT ("Shifting", yystos
[yytable
[yyj
]],
2231 &yylval
, &yyerrloc
);
2232 yyglrShift (yystackp
, 0, yytable
[yyj
],
2233 yys
->yyposn
, &yylval
]b4_locations_if([, &yyerrloc
])[);
2234 yys
= yystackp
->yytops
.yystates
[0];
2237 }]b4_locations_if([[
2238 yystackp
->yyerror_range
[1].yystate
.yyloc
= yys
->yyloc
;]])[
2239 if (yys
->yypred
!= YY_NULL
)
2240 yydestroyGLRState ("Error: popping", yys
]b4_user_args
[);
2241 yystackp
->yytops
.yystates
[0] = yys
->yypred
;
2242 yystackp
->yynextFree
-= 1;
2243 yystackp
->yyspaceLeft
+= 1;
2245 if (yystackp
->yytops
.yystates
[0] == YY_NULL
)
2246 yyFail (yystackp
][]b4_lpure_args
[, YY_NULL
);
2249 #define YYCHK1(YYE) \
2259 goto yyuser_error; \
2269 ]b4_function_define([yyparse
], [int], b4_parse_param
)[
2273 yyGLRStack
* const yystackp
= &yystack
;
2276 YYDPRINTF ((stderr
, "Starting parse\n"));
2279 yylval
= yyval_default
;
2281 #if defined ]b4_api_PREFIX[LTYPE_IS_TRIVIAL && ]b4_api_PREFIX[LTYPE_IS_TRIVIAL
2282 yylloc
.first_line
= yylloc
.last_line
= ]b4_location_initial_line
[;
2283 yylloc
.first_column
= yylloc
.last_column
= ]b4_location_initial_column
[;
2286 m4_ifdef([b4_initial_action
], [
2287 b4_dollar_pushdef([yylval
], [], [yylloc
])dnl
2288 /* User initialization code. */
2289 b4_user_initial_action
2290 b4_dollar_popdef
])[]dnl
2292 if (! yyinitGLRStack (yystackp
, YYINITDEPTH
))
2293 goto yyexhaustedlab
;
2294 switch (YYSETJMP (yystack
.yyexception_buffer
))
2297 case 1: goto yyabortlab
;
2298 case 2: goto yyexhaustedlab
;
2299 default: goto yybuglab
;
2301 yyglrShift (&yystack
, 0, 0, 0, &yylval
]b4_locations_if([, &yylloc
])[);
2306 /* For efficiency, we have two loops, the first of which is
2307 specialized to deterministic operation (single stack, no
2308 potential ambiguity). */
2314 const short int* yyconflicts
;
2316 yyStateNum yystate
= yystack
.yytops
.yystates
[0]->yylrState
;
2317 YYDPRINTF ((stderr
, "Entering state %d\n", yystate
));
2318 if (yystate
== YYFINAL
)
2320 if (yyisDefaultedState (yystate
))
2322 yyrule
= yydefaultAction (yystate
);
2325 ]b4_locations_if([[ yystack
.yyerror_range
[1].yystate
.yyloc
= yylloc
;]])[
2326 yyreportSyntaxError (&yystack
]b4_user_args
[);
2329 YYCHK1 (yyglrReduce (&yystack
, 0, yyrule
, yytrue
]b4_user_args
[));
2334 if (yychar
== YYEMPTY
)
2336 YYDPRINTF ((stderr
, "Reading a token: "));
2340 if (yychar
<= YYEOF
)
2342 yychar
= yytoken
= YYEOF
;
2343 YYDPRINTF ((stderr
, "Now at end of input.\n"));
2347 yytoken
= YYTRANSLATE (yychar
);
2348 YY_SYMBOL_PRINT ("Next token is", yytoken
, &yylval
, &yylloc
);
2351 yygetLRActions (yystate
, yytoken
, &yyaction
, &yyconflicts
);
2352 if (*yyconflicts
!= 0)
2354 if (yyisShiftAction (yyaction
))
2356 YY_SYMBOL_PRINT ("Shifting", yytoken
, &yylval
, &yylloc
);
2359 yyglrShift (&yystack
, 0, yyaction
, yyposn
, &yylval
]b4_locations_if([, &yylloc
])[);
2360 if (0 < yystack
.yyerrState
)
2361 yystack
.yyerrState
-= 1;
2363 else if (yyisErrorAction (yyaction
))
2365 ]b4_locations_if([[ yystack
.yyerror_range
[1].yystate
.yyloc
= yylloc
;]])[
2366 yyreportSyntaxError (&yystack
]b4_user_args
[);
2370 YYCHK1 (yyglrReduce (&yystack
, 0, -yyaction
, yytrue
]b4_user_args
[));
2376 yySymbol yytoken_to_shift
;
2379 for (yys
= 0; yys
< yystack
.yytops
.yysize
; yys
+= 1)
2380 yystackp
->yytops
.yylookaheadNeeds
[yys
] = yychar
!= YYEMPTY
;
2382 /* yyprocessOneStack returns one of three things:
2384 - An error flag. If the caller is yyprocessOneStack, it
2385 immediately returns as well. When the caller is finally
2386 yyparse, it jumps to an error label via YYCHK1.
2388 - yyok, but yyprocessOneStack has invoked yymarkStackDeleted
2389 (&yystack, yys), which sets the top state of yys to NULL. Thus,
2390 yyparse's following invocation of yyremoveDeletes will remove
2393 - yyok, when ready to shift a token.
2395 Except in the first case, yyparse will invoke yyremoveDeletes and
2396 then shift the next token onto all remaining stacks. This
2397 synchronization of the shift (that is, after all preceding
2398 reductions on all stacks) helps prevent double destructor calls
2399 on yylval in the event of memory exhaustion. */
2401 for (yys
= 0; yys
< yystack
.yytops
.yysize
; yys
+= 1)
2402 YYCHK1 (yyprocessOneStack (&yystack
, yys
, yyposn
]b4_lpure_args
[));
2403 yyremoveDeletes (&yystack
);
2404 if (yystack
.yytops
.yysize
== 0)
2406 yyundeleteLastStack (&yystack
);
2407 if (yystack
.yytops
.yysize
== 0)
2408 yyFail (&yystack
][]b4_lpure_args
[, YY_("syntax error"));
2409 YYCHK1 (yyresolveStack (&yystack
]b4_user_args
[));
2410 YYDPRINTF ((stderr
, "Returning to deterministic operation.\n"));
2411 ]b4_locations_if([[ yystack
.yyerror_range
[1].yystate
.yyloc
= yylloc
;]])[
2412 yyreportSyntaxError (&yystack
]b4_user_args
[);
2416 /* If any yyglrShift call fails, it will fail after shifting. Thus,
2417 a copy of yylval will already be on stack 0 in the event of a
2418 failure in the following loop. Thus, yychar is set to YYEMPTY
2419 before the loop to make sure the user destructor for yylval isn't
2421 yytoken_to_shift
= YYTRANSLATE (yychar
);
2424 for (yys
= 0; yys
< yystack
.yytops
.yysize
; yys
+= 1)
2427 const short int* yyconflicts
;
2428 yyStateNum yystate
= yystack
.yytops
.yystates
[yys
]->yylrState
;
2429 yygetLRActions (yystate
, yytoken_to_shift
, &yyaction
,
2431 /* Note that yyconflicts were handled by yyprocessOneStack. */
2432 YYDPRINTF ((stderr
, "On stack %lu, ", (unsigned long int) yys
));
2433 YY_SYMBOL_PRINT ("shifting", yytoken_to_shift
, &yylval
, &yylloc
);
2434 yyglrShift (&yystack
, yys
, yyaction
, yyposn
,
2435 &yylval
]b4_locations_if([, &yylloc
])[);
2436 YYDPRINTF ((stderr
, "Stack %lu now in state #%d\n",
2437 (unsigned long int) yys
,
2438 yystack
.yytops
.yystates
[yys
]->yylrState
));
2441 if (yystack
.yytops
.yysize
== 1)
2443 YYCHK1 (yyresolveStack (&yystack
]b4_user_args
[));
2444 YYDPRINTF ((stderr
, "Returning to deterministic operation.\n"));
2445 yycompressStack (&yystack
);
2451 yyrecoverSyntaxError (&yystack
]b4_user_args
[);
2452 yyposn
= yystack
.yytops
.yystates
[0]->yyposn
;
2468 yyerror (]b4_lyyerror_args
[YY_("memory exhausted"));
2473 if (yychar
!= YYEMPTY
)
2474 yydestruct ("Cleanup: discarding lookahead",
2475 YYTRANSLATE (yychar
), &yylval
]b4_locuser_args([&yylloc
])[);
2477 /* If the stack is well-formed, pop the stack until it is empty,
2478 destroying its entries as we go. But free the stack regardless
2479 of whether it is well-formed. */
2480 if (yystack
.yyitems
)
2482 yyGLRState
** yystates
= yystack
.yytops
.yystates
;
2485 size_t yysize
= yystack
.yytops
.yysize
;
2487 for (yyk
= 0; yyk
< yysize
; yyk
+= 1)
2490 while (yystates
[yyk
])
2492 yyGLRState
*yys
= yystates
[yyk
];
2493 ]b4_locations_if([[ yystack
.yyerror_range
[1].yystate
.yyloc
= yys
->yyloc
;]]
2494 )[ if (yys
->yypred
!= YY_NULL
)
2495 yydestroyGLRState ("Cleanup: popping", yys
]b4_user_args
[);
2496 yystates
[yyk
] = yys
->yypred
;
2497 yystack
.yynextFree
-= 1;
2498 yystack
.yyspaceLeft
+= 1;
2503 yyfreeGLRStack (&yystack
);
2509 /* DEBUGGING ONLY */
2510 #if ]b4_api_PREFIX[DEBUG
2511 static void yypstack (yyGLRStack
* yystackp
, size_t yyk
)
2512 __attribute__ ((__unused__
));
2513 static void yypdumpstack (yyGLRStack
* yystackp
) __attribute__ ((__unused__
));
2516 yy_yypstack (yyGLRState
* yys
)
2520 yy_yypstack (yys
->yypred
);
2521 YYFPRINTF (stderr
, " -> ");
2523 YYFPRINTF (stderr
, "%d@@%lu", yys
->yylrState
,
2524 (unsigned long int) yys
->yyposn
);
2528 yypstates (yyGLRState
* yyst
)
2530 if (yyst
== YY_NULL
)
2531 YYFPRINTF (stderr
, "<null>");
2534 YYFPRINTF (stderr
, "\n");
2538 yypstack (yyGLRStack
* yystackp
, size_t yyk
)
2540 yypstates (yystackp
->yytops
.yystates
[yyk
]);
2543 #define YYINDEX(YYX) \
2544 ((YYX) == YY_NULL ? -1 : (yyGLRStackItem*) (YYX) - yystackp->yyitems)
2548 yypdumpstack (yyGLRStack
* yystackp
)
2550 yyGLRStackItem
* yyp
;
2552 for (yyp
= yystackp
->yyitems
; yyp
< yystackp
->yynextFree
; yyp
+= 1)
2554 YYFPRINTF (stderr
, "%3lu. ",
2555 (unsigned long int) (yyp
- yystackp
->yyitems
));
2556 if (*(yybool
*) yyp
)
2558 YYFPRINTF (stderr
, "Res: %d, LR State: %d, posn: %lu, pred: %ld",
2559 yyp
->yystate
.yyresolved
, yyp
->yystate
.yylrState
,
2560 (unsigned long int) yyp
->yystate
.yyposn
,
2561 (long int) YYINDEX (yyp
->yystate
.yypred
));
2562 if (! yyp
->yystate
.yyresolved
)
2563 YYFPRINTF (stderr
, ", firstVal: %ld",
2564 (long int) YYINDEX (yyp
->yystate
2565 .yysemantics
.yyfirstVal
));
2569 YYFPRINTF (stderr
, "Option. rule: %d, state: %ld, next: %ld",
2570 yyp
->yyoption
.yyrule
- 1,
2571 (long int) YYINDEX (yyp
->yyoption
.yystate
),
2572 (long int) YYINDEX (yyp
->yyoption
.yynext
));
2574 YYFPRINTF (stderr
, "\n");
2576 YYFPRINTF (stderr
, "Tops:");
2577 for (yyi
= 0; yyi
< yystackp
->yytops
.yysize
; yyi
+= 1)
2578 YYFPRINTF (stderr
, "%lu: %ld; ", (unsigned long int) yyi
,
2579 (long int) YYINDEX (yystackp
->yytops
.yystates
[yyi
]));
2580 YYFPRINTF (stderr
, "\n");
2585 dnl glr
.cc produces its own header
.
2587 m4_if(b4_skeleton
, ["glr.c"],
2589 [@
output(b4_spec_defines_file@
)@
2590 b4_copyright([Skeleton interface
for Bison GLR parsers in C
],
2593 ]b4_cpp_guard_open([b4_spec_defines_file
])[
2594 ]b4_shared_declarations
[
2595 ]b4_cpp_guard_close([b4_spec_defines_file
])[