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_c_ansi_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_c_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_c_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 [((*yyvalp
)[]m4_ifval([$
1], [.$
1]))])
132 # b4_rhs_value(RULE-LENGTH, NUM, [TYPE])
133 # --------------------------------------
134 # Expansion of $<TYPE>NUM, where the current rule has RULE-LENGTH
136 m4_define([b4_rhs_value
],
137 [(((yyGLRStackItem
const *)yyvsp
)@
{YYFILL (($
2) - ($
1))@
}.yystate
.yysemantics
.yysval
[]m4_ifval([$
3], [.$
3]))])
148 m4_define([b4_lhs_location
],
152 # b4_rhs_location(RULE-LENGTH, NUM)
153 # ---------------------------------
154 # Expansion of @NUM, where the current rule has RULE-LENGTH symbols
156 m4_define([b4_rhs_location
],
157 [(((yyGLRStackItem
const *)yyvsp
)@
{YYFILL (($
2) - ($
1))@
}.yystate
.yyloc
)])
164 # b4_shared_declarations
165 # ----------------------
166 # Declaration that might either go into the header (if --defines)
167 # or open coded in the parser body.
168 m4_define([b4_shared_declarations
],
170 ]b4_percent_code_get([[requires]])[
171 ]b4_token_enums(b4_tokens
)[
172 ]b4_declare_yylstype
[
173 ]b4_c_ansi_function_decl(b4_prefix
[parse
], [int], b4_parse_param
)[
174 ]b4_percent_code_get([[provides]])[]dnl
182 # We do want M4 expansion after # for CPP macros.
185 @
output(b4_parser_file_name@
)@
186 b4_copyright([Skeleton implementation
for Bison GLR parsers in C
],
189 /* C GLR parser skeleton written by Paul Hilfinger. */
193 b4_percent_code_get([[top]])[
194 ]m4_if(b4_api_prefix
, [yy
], [],
195 [[/* Substitute the type names. */
196 #define YYSTYPE ]b4_api_PREFIX[STYPE]b4_locations_if([[
197 #define YYLTYPE ]b4_api_PREFIX[LTYPE]])])[
198 ]m4_if(b4_prefix
, [yy
], [],
199 [[/* Substitute the variable and function names. */
200 #define yyparse ]b4_prefix[parse
201 #define yylex ]b4_prefix[lex
202 #define yyerror ]b4_prefix[error
203 #define yylval ]b4_prefix[lval
204 #define yychar ]b4_prefix[char
205 #define yydebug ]b4_prefix[debug
206 #define yynerrs ]b4_prefix[nerrs]b4_locations_if([[
207 #define yylloc ]b4_prefix[lloc]])])[
209 /* Copy the first part of user declarations. */
210 ]b4_user_pre_prologue
[
214 ]b4_defines_if([[#include "@basename(]b4_spec_defines_file[@)"]],
215 [b4_shared_declarations
])[
217 /* Enabling verbose error messages. */
218 #ifdef YYERROR_VERBOSE
219 # undef YYERROR_VERBOSE
220 # define YYERROR_VERBOSE 1
222 # define YYERROR_VERBOSE ]b4_error_verbose_flag[
225 /* Default (constant) value used for initialization for null
226 right-hand sides. Unlike the standard yacc.c template, here we set
227 the default value of $$ to a zeroed-out value. Since the default
228 value is undefined, this behavior is technically correct. */
229 static YYSTYPE yyval_default
;]b4_locations_if([[
230 static YYLTYPE yyloc_default
][]b4_yyloc_default
;])[
232 /* Copy the second part of user declarations. */
233 ]b4_user_post_prologue
234 b4_percent_code_get
[]dnl
241 # if defined YYENABLE_NLS && YYENABLE_NLS
243 # include <libintl.h> /* INFRINGES ON USER NAME SPACE */
244 # define YY_(Msgid) dgettext ("bison-runtime", Msgid)
248 # define YY_(Msgid) Msgid
252 /* Suppress unused-variable warnings by "using" E. */
253 #if ! defined lint || defined __GNUC__
254 # define YYUSE(E) ((void) (E))
256 # define YYUSE(E) /* empty */
259 /* Identity function, used to suppress warnings about constant conditions. */
263 ]b4_c_function_def([YYID
], [static int], [[int i
], [i
]])[
273 # define YYMALLOC malloc
276 # define YYREALLOC realloc
279 #define YYSIZEMAX ((size_t) -1)
284 typedef unsigned char yybool
;
291 # define YYJMP_BUF jmp_buf
292 # define YYSETJMP(Env) setjmp (Env)
294 # define YYLONGJMP(Env, Val) (longjmp (Env, Val), YYASSERT (0))
301 #ifndef __attribute__
302 /* This feature is available in gcc versions 2.5 and later. */
303 # if (! defined __GNUC__ || __GNUC__ < 2 \
304 || (__GNUC__ == 2 && __GNUC_MINOR__ < 5))
305 # define __attribute__(Spec) /* empty */
310 # define YYASSERT(Condition) ((void) ((Condition) || (abort (), 0)))
313 /* YYFINAL -- State number of the termination state. */
314 #define YYFINAL ]b4_final_state_number[
315 /* YYLAST -- Last index in YYTABLE. */
316 #define YYLAST ]b4_last[
318 /* YYNTOKENS -- Number of terminals. */
319 #define YYNTOKENS ]b4_tokens_number[
320 /* YYNNTS -- Number of nonterminals. */
321 #define YYNNTS ]b4_nterms_number[
322 /* YYNRULES -- Number of rules. */
323 #define YYNRULES ]b4_rules_number[
324 /* YYNRULES -- Number of states. */
325 #define YYNSTATES ]b4_states_number[
326 /* YYMAXRHS -- Maximum number of symbols on right-hand side of rule. */
327 #define YYMAXRHS ]b4_r2_max[
328 /* YYMAXLEFT -- Maximum number of symbols to the left of a handle
329 accessed by $0, $-1, etc., in any rule. */
330 #define YYMAXLEFT ]b4_max_left_semantic_context[
332 /* YYTRANSLATE(X) -- Bison symbol number corresponding to X. */
333 #define YYUNDEFTOK ]b4_undef_token_number[
334 #define YYMAXUTOK ]b4_user_token_number_max[
336 #define YYTRANSLATE(YYX) \
337 ((unsigned int) (YYX) <= YYMAXUTOK ? yytranslate[YYX] : YYUNDEFTOK)
339 /* YYTRANSLATE[YYLEX] -- Bison symbol number corresponding to YYLEX. */
340 static const ]b4_int_type_for([b4_translate
])[ yytranslate
[] =
345 #if ]b4_api_PREFIX[DEBUG
346 /* YYPRHS[YYN] -- Index of the first RHS symbol of rule number YYN in
348 static const ]b4_int_type_for([b4_prhs
])[ yyprhs
[] =
353 /* YYRHS -- A `-1'-separated list of the rules' RHS. */
354 static const ]b4_int_type_for([b4_rhs
])[ yyrhs
[] =
359 /* YYRLINE[YYN] -- source line where rule number YYN was defined. */
360 static const ]b4_int_type_for([b4_rline
])[ yyrline
[] =
366 #if ]b4_api_PREFIX[DEBUG || YYERROR_VERBOSE || ]b4_token_table_flag[
367 /* YYTNAME[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM.
368 First, the terminals, then, starting at YYNTOKENS, nonterminals. */
369 static const char *const yytname
[] =
375 /* YYR1[YYN] -- Symbol number of symbol that rule YYN derives. */
376 static const ]b4_int_type_for([b4_r1
])[ yyr1
[] =
381 /* YYR2[YYN] -- Number of symbols composing right hand side of rule YYN. */
382 static const ]b4_int_type_for([b4_r2
])[ yyr2
[] =
387 /* YYDPREC[RULE-NUM] -- Dynamic precedence of rule #RULE-NUM (0 if none). */
388 static const ]b4_int_type_for([b4_dprec
])[ yydprec
[] =
393 /* YYMERGER[RULE-NUM] -- Index of merging function for rule #RULE-NUM. */
394 static const ]b4_int_type_for([b4_merger
])[ yymerger
[] =
399 /* YYDEFACT[S] -- default reduction number in state S. Performed when
400 YYTABLE doesn't specify something else to do. Zero means the default
402 static const ]b4_int_type_for([b4_defact
])[ yydefact
[] =
407 /* YYPDEFGOTO[NTERM-NUM]. */
408 static const ]b4_int_type_for([b4_defgoto
])[ yydefgoto
[] =
413 /* YYPACT[STATE-NUM] -- Index in YYTABLE of the portion describing
415 #define YYPACT_NINF ]b4_pact_ninf[
416 static const ]b4_int_type_for([b4_pact
])[ yypact
[] =
421 /* YYPGOTO[NTERM-NUM]. */
422 static const ]b4_int_type_for([b4_pgoto
])[ yypgoto
[] =
427 /* YYTABLE[YYPACT[STATE-NUM]]. What to do in state STATE-NUM. If
428 positive, shift that token. If negative, reduce the rule which
429 number is the opposite. If YYTABLE_NINF, syntax error. */
430 #define YYTABLE_NINF ]b4_table_ninf[
431 static const ]b4_int_type_for([b4_table
])[ yytable
[] =
436 /* YYCONFLP[YYPACT[STATE-NUM]] -- Pointer into YYCONFL of start of
437 list of conflicting reductions corresponding to action entry for
438 state STATE-NUM in yytable. 0 means no conflicts. The list in
439 yyconfl is terminated by a rule number of 0. */
440 static const ]b4_int_type_for([b4_conflict_list_heads
])[ yyconflp
[] =
442 ]b4_conflict_list_heads
[
445 /* YYCONFL[I] -- lists of conflicting rule numbers, each terminated by
446 0, pointed into by YYCONFLP. */
447 ]dnl Do
not use b4_int_type_for here
, since there are places where
448 dnl pointers onto yyconfl are taken
, which type is
"short int *".
449 dnl We probably ought to introduce a type
for confl
.
450 [static const short int yyconfl
[] =
452 ]b4_conflicting_rules
[
455 static const ]b4_int_type_for([b4_check
])[ yycheck
[] =
460 /* YYSTOS[STATE-NUM] -- The (internal number of the) accessing
461 symbol of state STATE-NUM. */
462 static const ]b4_int_type_for([b4_stos
])[ yystos
[] =
467 /* Error token number */
471 ]b4_yylloc_default_define
[
472 # define YYRHSLOC(Rhs, K) ((Rhs)[K].yystate.yyloc)
474 ]b4_yy_location_print_define
[
476 /* YYLEX -- calling `yylex' with the right arguments. */
477 #define YYLEX ]b4_c_function_call([yylex], [int], b4_lex_param)[
482 #define yynerrs (yystackp->yyerrcnt)
484 #define yychar (yystackp->yyrawchar)
486 #define yylval (yystackp->yyval)
488 #define yylloc (yystackp->yyloc)
489 m4_if(b4_prefix
[], [yy
], [],
490 [#define b4_prefix[]nerrs yynerrs
491 #define b4_prefix[]char yychar
492 #define b4_prefix[]lval yylval
493 #define b4_prefix[]lloc yylloc])],
494 [YYSTYPE yylval
;]b4_locations_if([[
500 static const int YYEOF
= 0;
501 static const int YYEMPTY
= -2;
503 typedef enum { yyok
, yyaccept
, yyabort
, yyerr
} YYRESULTTAG
;
506 do { YYRESULTTAG yyflag = YYE; if (yyflag != yyok) return yyflag; } \
509 #if ]b4_api_PREFIX[DEBUG
512 # define YYFPRINTF fprintf
515 # define YYDPRINTF(Args) \
521 ]b4_yy_symbol_print_generate([b4_c_ansi_function_def
])[
523 # define YY_SYMBOL_PRINT(Title, Type, Value, Location) \
527 YYFPRINTF (stderr, "%s ", Title); \
528 yy_symbol_print (stderr, Type, Value]b4_locuser_args([Location])[); \
529 YYFPRINTF (stderr, "\n"); \
533 /* Nonzero means print parse trace. It is left uninitialized so that
534 multiple parsers can coexist. */
537 #else /* !]b4_api_PREFIX[DEBUG */
539 # define YYDPRINTF(Args)
540 # define YY_SYMBOL_PRINT(Title, Type, Value, Location)
542 #endif /* !]b4_api_PREFIX[DEBUG */
544 /* YYINITDEPTH -- initial size of the parser's stacks. */
546 # define YYINITDEPTH ]b4_stack_depth_init[
549 /* YYMAXDEPTH -- maximum size the stacks can grow to (effective only
550 if the built-in stack extension method is used).
552 Do not make this value too large; the results are undefined if
553 SIZE_MAX < YYMAXDEPTH * sizeof (GLRStackItem)
554 evaluated with infinite-precision integer arithmetic. */
557 # define YYMAXDEPTH ]b4_stack_depth_max[
560 /* Minimum number of free items on the stack allowed after an
561 allocation. This is to allow allocation and initialization
562 to be completed by functions that call yyexpandGLRStack before the
563 stack is expanded, thus insuring that all necessary pointers get
564 properly redirected to new data. */
567 #ifndef YYSTACKEXPANDABLE
568 # if (! defined __cplusplus \
569 || (]b4_locations_if([[defined ]b4_api_PREFIX[LTYPE_IS_TRIVIAL && ]b4_api_PREFIX[LTYPE_IS_TRIVIAL \
570 && ]])[defined ]b4_api_PREFIX[STYPE_IS_TRIVIAL && ]b4_api_PREFIX[STYPE_IS_TRIVIAL))
571 # define YYSTACKEXPANDABLE 1
573 # define YYSTACKEXPANDABLE 0
577 #if YYSTACKEXPANDABLE
578 # define YY_RESERVE_GLRSTACK(Yystack) \
580 if (Yystack->yyspaceLeft < YYHEADROOM) \
581 yyexpandGLRStack (Yystack); \
584 # define YY_RESERVE_GLRSTACK(Yystack) \
586 if (Yystack->yyspaceLeft < YYHEADROOM) \
587 yyMemoryExhausted (Yystack); \
595 # if defined __GLIBC__ && defined _STRING_H && defined _GNU_SOURCE
596 # define yystpcpy stpcpy
598 /* Copy YYSRC to YYDEST, returning the address of the terminating '\0' in
601 yystpcpy (char *yydest
, const char *yysrc
)
604 const char *yys
= yysrc
;
606 while ((*yyd
++ = *yys
++) != '\0')
615 /* Copy to YYRES the contents of YYSTR after stripping away unnecessary
616 quotes and backslashes, so that it's suitable for yyerror. The
617 heuristic is that double-quoting is unnecessary unless the string
618 contains an apostrophe, a comma, or backslash (other than
619 backslash-backslash). YYSTR is taken from yytname. If YYRES is
620 null, do not copy; instead, return the length of what the result
623 yytnamerr (char *yyres
, const char *yystr
)
628 char const *yyp
= yystr
;
635 goto do_not_strip_quotes
;
639 goto do_not_strip_quotes
;
652 do_not_strip_quotes
: ;
656 return strlen (yystr
);
658 return yystpcpy (yyres
, yystr
) - yyres
;
662 #endif /* !YYERROR_VERBOSE */
664 /** State numbers, as in LALR(1) machine */
665 typedef int yyStateNum
;
667 /** Rule numbers, as in LALR(1) machine */
668 typedef int yyRuleNum
;
670 /** Grammar symbol */
671 typedef short int yySymbol
;
673 /** Item references, as in LALR(1) machine */
674 typedef short int yyItemNum
;
676 typedef struct yyGLRState yyGLRState
;
677 typedef struct yyGLRStateSet yyGLRStateSet
;
678 typedef struct yySemanticOption yySemanticOption
;
679 typedef union yyGLRStackItem yyGLRStackItem
;
680 typedef struct yyGLRStack yyGLRStack
;
683 /** Type tag: always true. */
685 /** Type tag for yysemantics. If true, yysval applies, otherwise
686 * yyfirstVal applies. */
688 /** Number of corresponding LALR(1) machine state. */
689 yyStateNum yylrState
;
690 /** Preceding state in this stack */
692 /** Source position of the first token produced by my symbol */
695 /** First in a chain of alternative reductions producing the
696 * non-terminal corresponding to this state, threaded through
698 yySemanticOption
* yyfirstVal
;
699 /** Semantic value for this state. */
701 } yysemantics
;]b4_locations_if([[
702 /** Source location for this state. */
706 struct yyGLRStateSet
{
707 yyGLRState
** yystates
;
708 /** During nondeterministic operation, yylookaheadNeeds tracks which
709 * stacks have actually needed the current lookahead. During deterministic
710 * operation, yylookaheadNeeds[0] is not maintained since it would merely
711 * duplicate yychar != YYEMPTY. */
712 yybool
* yylookaheadNeeds
;
713 size_t yysize
, yycapacity
;
716 struct yySemanticOption
{
717 /** Type tag: always false. */
719 /** Rule number for this reduction */
721 /** The last RHS state in the list of states to be reduced. */
723 /** The lookahead for this reduction. */
725 YYSTYPE yyval
;]b4_locations_if([[
727 /** Next sibling in chain of options. To facilitate merging,
728 * options are chained in decreasing order by address. */
729 yySemanticOption
* yynext
;
732 /** Type of the items in the GLR stack. The yyisState field
733 * indicates which item of the union is valid. */
734 union yyGLRStackItem
{
736 yySemanticOption yyoption
;
741 ]b4_locations_if([[ /* To compute the location of the error token. */
742 yyGLRStackItem yyerror_range
[3];]])[
747 YYSTYPE yyval
;]b4_locations_if([[
750 YYJMP_BUF yyexception_buffer
;
751 yyGLRStackItem
* yyitems
;
752 yyGLRStackItem
* yynextFree
;
754 yyGLRState
* yysplitPoint
;
755 yyGLRState
* yylastDeleted
;
756 yyGLRStateSet yytops
;
759 #if YYSTACKEXPANDABLE
760 static void yyexpandGLRStack (yyGLRStack
* yystackp
);
763 static void yyFail (yyGLRStack
* yystackp
]b4_pure_formals
[, const char* yymsg
)
764 __attribute__ ((__noreturn__
));
766 yyFail (yyGLRStack
* yystackp
]b4_pure_formals
[, const char* yymsg
)
768 if (yymsg
!= YY_NULL
)
769 yyerror (]b4_yyerror_args
[yymsg
);
770 YYLONGJMP (yystackp
->yyexception_buffer
, 1);
773 static void yyMemoryExhausted (yyGLRStack
* yystackp
)
774 __attribute__ ((__noreturn__
));
776 yyMemoryExhausted (yyGLRStack
* yystackp
)
778 YYLONGJMP (yystackp
->yyexception_buffer
, 2);
781 #if ]b4_api_PREFIX[DEBUG || YYERROR_VERBOSE
782 /** A printable representation of TOKEN. */
783 static inline const char*
784 yytokenName (yySymbol yytoken
)
786 if (yytoken
== YYEMPTY
)
789 return yytname
[yytoken
];
793 /** Fill in YYVSP[YYLOW1 .. YYLOW0-1] from the chain of states starting
794 * at YYVSP[YYLOW0].yystate.yypred. Leaves YYVSP[YYLOW1].yystate.yypred
795 * containing the pointer to the next state in the chain. */
796 static void yyfillin (yyGLRStackItem
*, int, int) __attribute__ ((__unused__
));
798 yyfillin (yyGLRStackItem
*yyvsp
, int yylow0
, int yylow1
)
801 yyGLRState
*s
= yyvsp
[yylow0
].yystate
.yypred
;
802 for (i
= yylow0
-1; i
>= yylow1
; i
-= 1)
804 YYASSERT (s
->yyresolved
);
805 yyvsp
[i
].yystate
.yyresolved
= yytrue
;
806 yyvsp
[i
].yystate
.yysemantics
.yysval
= s
->yysemantics
.yysval
;]b4_locations_if([[
807 yyvsp
[i
].yystate
.yyloc
= s
->yyloc
;]])[
808 s
= yyvsp
[i
].yystate
.yypred
= s
->yypred
;
812 /* Do nothing if YYNORMAL or if *YYLOW <= YYLOW1. Otherwise, fill in
813 * YYVSP[YYLOW1 .. *YYLOW-1] as in yyfillin and set *YYLOW = YYLOW1.
814 * For convenience, always return YYLOW1. */
815 static inline int yyfill (yyGLRStackItem
*, int *, int, yybool
)
816 __attribute__ ((__unused__
));
818 yyfill (yyGLRStackItem
*yyvsp
, int *yylow
, int yylow1
, yybool yynormal
)
820 if (!yynormal
&& yylow1
< *yylow
)
822 yyfillin (yyvsp
, *yylow
, yylow1
);
828 /** Perform user action for rule number YYN, with RHS length YYRHSLEN,
829 * and top stack item YYVSP. YYLVALP points to place to put semantic
830 * value ($$), and yylocp points to place for location information
831 * (@@$). Returns yyok for normal return, yyaccept for YYACCEPT,
832 * yyerr for YYERROR, yyabort for YYABORT. */
833 /*ARGSUSED*/ static YYRESULTTAG
834 yyuserAction (yyRuleNum yyn
, int yyrhslen
, yyGLRStackItem
* yyvsp
,
835 yyGLRStack
* yystackp
,
836 YYSTYPE
* yyvalp
]b4_locuser_formals
[)
838 yybool yynormal
__attribute__ ((__unused__
)) =
839 (yystackp
->yysplitPoint
== YY_NULL
);
841 ]b4_parse_param_use
[]dnl
843 # define yyerrok (yystackp->yyerrState = 0)
845 # define YYACCEPT return yyaccept
847 # define YYABORT return yyabort
849 # define YYERROR return yyerrok, yyerr
851 # define YYRECOVERING() (yystackp->yyerrState != 0)
853 # define yyclearin (yychar = YYEMPTY)
855 # define YYFILL(N) yyfill (yyvsp, &yylow, N, yynormal)
857 # define YYBACKUP(Token, Value) \
858 return yyerror (]b4_yyerror_args[YY_("syntax error: cannot back up")), \
863 *yyvalp
= yyval_default
;
865 *yyvalp
= yyvsp
[YYFILL (1-yyrhslen
)].yystate
.yysemantics
.yysval
;]b4_locations_if([[
866 YYLLOC_DEFAULT ((*yylocp
), (yyvsp
- yyrhslen
), yyrhslen
);
867 yystackp
->yyerror_range
[1].yystate
.yyloc
= *yylocp
;
886 /*ARGSUSED*/ static void
887 yyuserMerge (int yyn
, YYSTYPE
* yy0
, YYSTYPE
* yy1
)
899 /* Bison grammar-table manipulation. */
901 ]b4_yydestruct_generate([b4_c_ansi_function_def
])[
903 /** Number of symbols composing the right hand side of rule #RULE. */
905 yyrhsLength (yyRuleNum yyrule
)
911 yydestroyGLRState (char const *yymsg
, yyGLRState
*yys
]b4_user_formals
[)
914 yydestruct (yymsg
, yystos
[yys
->yylrState
],
915 &yys
->yysemantics
.yysval
]b4_locuser_args([&yys
->yyloc
])[);
918 #if ]b4_api_PREFIX[DEBUG
921 if (yys
->yysemantics
.yyfirstVal
)
922 YYFPRINTF (stderr
, "%s unresolved ", yymsg
);
924 YYFPRINTF (stderr
, "%s incomplete ", yymsg
);
925 yy_symbol_print (stderr
, yystos
[yys
->yylrState
],
926 YY_NULL
]b4_locuser_args([&yys
->yyloc
])[);
927 YYFPRINTF (stderr
, "\n");
931 if (yys
->yysemantics
.yyfirstVal
)
933 yySemanticOption
*yyoption
= yys
->yysemantics
.yyfirstVal
;
936 for (yyrh
= yyoption
->yystate
, yyn
= yyrhsLength (yyoption
->yyrule
);
938 yyrh
= yyrh
->yypred
, yyn
-= 1)
939 yydestroyGLRState (yymsg
, yyrh
]b4_user_args
[);
944 /** Left-hand-side symbol for rule #RULE. */
945 static inline yySymbol
946 yylhsNonterm (yyRuleNum yyrule
)
951 #define yypact_value_is_default(Yystate) \
952 ]b4_table_value_equals([[pact]], [[Yystate]], [b4_pact_ninf])[
954 /** True iff LR state STATE has only a default reduction (regardless
957 yyisDefaultedState (yyStateNum yystate
)
959 return yypact_value_is_default (yypact
[yystate
]);
962 /** The default reduction for STATE, assuming it has one. */
963 static inline yyRuleNum
964 yydefaultAction (yyStateNum yystate
)
966 return yydefact
[yystate
];
969 #define yytable_value_is_error(Yytable_value) \
970 ]b4_table_value_equals([[table]], [[Yytable_value]], [b4_table_ninf])[
972 /** Set *YYACTION to the action to take in YYSTATE on seeing YYTOKEN.
974 * R < 0: Reduce on rule -R.
976 * R > 0: Shift to state R.
977 * Set *CONFLICTS to a pointer into yyconfl to 0-terminated list of
978 * conflicting reductions.
981 yygetLRActions (yyStateNum yystate
, int yytoken
,
982 int* yyaction
, const short int** yyconflicts
)
984 int yyindex
= yypact
[yystate
] + yytoken
;
985 if (yypact_value_is_default (yypact
[yystate
])
986 || yyindex
< 0 || YYLAST
< yyindex
|| yycheck
[yyindex
] != yytoken
)
988 *yyaction
= -yydefact
[yystate
];
989 *yyconflicts
= yyconfl
;
991 else if (! yytable_value_is_error (yytable
[yyindex
]))
993 *yyaction
= yytable
[yyindex
];
994 *yyconflicts
= yyconfl
+ yyconflp
[yyindex
];
999 *yyconflicts
= yyconfl
+ yyconflp
[yyindex
];
1003 static inline yyStateNum
1004 yyLRgotoState (yyStateNum yystate
, yySymbol yylhs
)
1007 yyr
= yypgoto
[yylhs
- YYNTOKENS
] + yystate
;
1008 if (0 <= yyr
&& yyr
<= YYLAST
&& yycheck
[yyr
] == yystate
)
1009 return yytable
[yyr
];
1011 return yydefgoto
[yylhs
- YYNTOKENS
];
1014 static inline yybool
1015 yyisShiftAction (int yyaction
)
1017 return 0 < yyaction
;
1020 static inline yybool
1021 yyisErrorAction (int yyaction
)
1023 return yyaction
== 0;
1028 /** Return a fresh GLRStackItem. Callers should call
1029 * YY_RESERVE_GLRSTACK afterwards to make sure there is sufficient
1032 static inline yyGLRStackItem
*
1033 yynewGLRStackItem (yyGLRStack
* yystackp
, yybool yyisState
)
1035 yyGLRStackItem
* yynewItem
= yystackp
->yynextFree
;
1036 yystackp
->yyspaceLeft
-= 1;
1037 yystackp
->yynextFree
+= 1;
1038 yynewItem
->yystate
.yyisState
= yyisState
;
1042 /** Add a new semantic action that will execute the action for rule
1043 * RULENUM on the semantic values in RHS to the list of
1044 * alternative actions for STATE. Assumes that RHS comes from
1045 * stack #K of *STACKP. */
1047 yyaddDeferredAction (yyGLRStack
* yystackp
, size_t yyk
, yyGLRState
* yystate
,
1048 yyGLRState
* rhs
, yyRuleNum yyrule
)
1050 yySemanticOption
* yynewOption
=
1051 &yynewGLRStackItem (yystackp
, yyfalse
)->yyoption
;
1052 yynewOption
->yystate
= rhs
;
1053 yynewOption
->yyrule
= yyrule
;
1054 if (yystackp
->yytops
.yylookaheadNeeds
[yyk
])
1056 yynewOption
->yyrawchar
= yychar
;
1057 yynewOption
->yyval
= yylval
;]b4_locations_if([
1058 yynewOption
->yyloc
= yylloc
;])[
1061 yynewOption
->yyrawchar
= YYEMPTY
;
1062 yynewOption
->yynext
= yystate
->yysemantics
.yyfirstVal
;
1063 yystate
->yysemantics
.yyfirstVal
= yynewOption
;
1065 YY_RESERVE_GLRSTACK (yystackp
);
1070 /** Initialize SET to a singleton set containing an empty stack. */
1072 yyinitStateSet (yyGLRStateSet
* yyset
)
1075 yyset
->yycapacity
= 16;
1076 yyset
->yystates
= (yyGLRState
**) YYMALLOC (16 * sizeof yyset
->yystates
[0]);
1077 if (! yyset
->yystates
)
1079 yyset
->yystates
[0] = YY_NULL
;
1080 yyset
->yylookaheadNeeds
=
1081 (yybool
*) YYMALLOC (16 * sizeof yyset
->yylookaheadNeeds
[0]);
1082 if (! yyset
->yylookaheadNeeds
)
1084 YYFREE (yyset
->yystates
);
1090 static void yyfreeStateSet (yyGLRStateSet
* yyset
)
1092 YYFREE (yyset
->yystates
);
1093 YYFREE (yyset
->yylookaheadNeeds
);
1096 /** Initialize STACK to a single empty stack, with total maximum
1097 * capacity for all stacks of SIZE. */
1099 yyinitGLRStack (yyGLRStack
* yystackp
, size_t yysize
)
1101 yystackp
->yyerrState
= 0;
1103 yystackp
->yyspaceLeft
= yysize
;
1105 (yyGLRStackItem
*) YYMALLOC (yysize
* sizeof yystackp
->yynextFree
[0]);
1106 if (!yystackp
->yyitems
)
1108 yystackp
->yynextFree
= yystackp
->yyitems
;
1109 yystackp
->yysplitPoint
= YY_NULL
;
1110 yystackp
->yylastDeleted
= YY_NULL
;
1111 return yyinitStateSet (&yystackp
->yytops
);
1115 #if YYSTACKEXPANDABLE
1116 # define YYRELOC(YYFROMITEMS,YYTOITEMS,YYX,YYTYPE) \
1117 &((YYTOITEMS) - ((YYFROMITEMS) - (yyGLRStackItem*) (YYX)))->YYTYPE
1119 /** If STACK is expandable, extend it. WARNING: Pointers into the
1120 stack from outside should be considered invalid after this call.
1121 We always expand when there are 1 or fewer items left AFTER an
1122 allocation, so that we can avoid having external pointers exist
1123 across an allocation. */
1125 yyexpandGLRStack (yyGLRStack
* yystackp
)
1127 yyGLRStackItem
* yynewItems
;
1128 yyGLRStackItem
* yyp0
, *yyp1
;
1131 size_t yysize
= yystackp
->yynextFree
- yystackp
->yyitems
;
1132 if (YYMAXDEPTH
- YYHEADROOM
< yysize
)
1133 yyMemoryExhausted (yystackp
);
1134 yynewSize
= 2*yysize
;
1135 if (YYMAXDEPTH
< yynewSize
)
1136 yynewSize
= YYMAXDEPTH
;
1137 yynewItems
= (yyGLRStackItem
*) YYMALLOC (yynewSize
* sizeof yynewItems
[0]);
1139 yyMemoryExhausted (yystackp
);
1140 for (yyp0
= yystackp
->yyitems
, yyp1
= yynewItems
, yyn
= yysize
;
1142 yyn
-= 1, yyp0
+= 1, yyp1
+= 1)
1145 if (*(yybool
*) yyp0
)
1147 yyGLRState
* yys0
= &yyp0
->yystate
;
1148 yyGLRState
* yys1
= &yyp1
->yystate
;
1149 if (yys0
->yypred
!= YY_NULL
)
1151 YYRELOC (yyp0
, yyp1
, yys0
->yypred
, yystate
);
1152 if (! yys0
->yyresolved
&& yys0
->yysemantics
.yyfirstVal
!= YY_NULL
)
1153 yys1
->yysemantics
.yyfirstVal
=
1154 YYRELOC (yyp0
, yyp1
, yys0
->yysemantics
.yyfirstVal
, yyoption
);
1158 yySemanticOption
* yyv0
= &yyp0
->yyoption
;
1159 yySemanticOption
* yyv1
= &yyp1
->yyoption
;
1160 if (yyv0
->yystate
!= YY_NULL
)
1161 yyv1
->yystate
= YYRELOC (yyp0
, yyp1
, yyv0
->yystate
, yystate
);
1162 if (yyv0
->yynext
!= YY_NULL
)
1163 yyv1
->yynext
= YYRELOC (yyp0
, yyp1
, yyv0
->yynext
, yyoption
);
1166 if (yystackp
->yysplitPoint
!= YY_NULL
)
1167 yystackp
->yysplitPoint
= YYRELOC (yystackp
->yyitems
, yynewItems
,
1168 yystackp
->yysplitPoint
, yystate
);
1170 for (yyn
= 0; yyn
< yystackp
->yytops
.yysize
; yyn
+= 1)
1171 if (yystackp
->yytops
.yystates
[yyn
] != YY_NULL
)
1172 yystackp
->yytops
.yystates
[yyn
] =
1173 YYRELOC (yystackp
->yyitems
, yynewItems
,
1174 yystackp
->yytops
.yystates
[yyn
], yystate
);
1175 YYFREE (yystackp
->yyitems
);
1176 yystackp
->yyitems
= yynewItems
;
1177 yystackp
->yynextFree
= yynewItems
+ yysize
;
1178 yystackp
->yyspaceLeft
= yynewSize
- yysize
;
1183 yyfreeGLRStack (yyGLRStack
* yystackp
)
1185 YYFREE (yystackp
->yyitems
);
1186 yyfreeStateSet (&yystackp
->yytops
);
1189 /** Assuming that S is a GLRState somewhere on STACK, update the
1190 * splitpoint of STACK, if needed, so that it is at least as deep as
1193 yyupdateSplit (yyGLRStack
* yystackp
, yyGLRState
* yys
)
1195 if (yystackp
->yysplitPoint
!= YY_NULL
&& yystackp
->yysplitPoint
> yys
)
1196 yystackp
->yysplitPoint
= yys
;
1199 /** Invalidate stack #K in STACK. */
1201 yymarkStackDeleted (yyGLRStack
* yystackp
, size_t yyk
)
1203 if (yystackp
->yytops
.yystates
[yyk
] != YY_NULL
)
1204 yystackp
->yylastDeleted
= yystackp
->yytops
.yystates
[yyk
];
1205 yystackp
->yytops
.yystates
[yyk
] = YY_NULL
;
1208 /** Undelete the last stack that was marked as deleted. Can only be
1209 done once after a deletion, and only when all other stacks have
1212 yyundeleteLastStack (yyGLRStack
* yystackp
)
1214 if (yystackp
->yylastDeleted
== YY_NULL
|| yystackp
->yytops
.yysize
!= 0)
1216 yystackp
->yytops
.yystates
[0] = yystackp
->yylastDeleted
;
1217 yystackp
->yytops
.yysize
= 1;
1218 YYDPRINTF ((stderr
, "Restoring last deleted stack as stack #0.\n"));
1219 yystackp
->yylastDeleted
= YY_NULL
;
1223 yyremoveDeletes (yyGLRStack
* yystackp
)
1227 while (yyj
< yystackp
->yytops
.yysize
)
1229 if (yystackp
->yytops
.yystates
[yyi
] == YY_NULL
)
1233 YYDPRINTF ((stderr
, "Removing dead stacks.\n"));
1235 yystackp
->yytops
.yysize
-= 1;
1239 yystackp
->yytops
.yystates
[yyj
] = yystackp
->yytops
.yystates
[yyi
];
1240 /* In the current implementation, it's unnecessary to copy
1241 yystackp->yytops.yylookaheadNeeds[yyi] since, after
1242 yyremoveDeletes returns, the parser immediately either enters
1243 deterministic operation or shifts a token. However, it doesn't
1244 hurt, and the code might evolve to need it. */
1245 yystackp
->yytops
.yylookaheadNeeds
[yyj
] =
1246 yystackp
->yytops
.yylookaheadNeeds
[yyi
];
1249 YYDPRINTF ((stderr
, "Rename stack %lu -> %lu.\n",
1250 (unsigned long int) yyi
, (unsigned long int) yyj
));
1258 /** Shift to a new state on stack #K of STACK, corresponding to LR state
1259 * LRSTATE, at input position POSN, with (resolved) semantic value SVAL. */
1261 yyglrShift (yyGLRStack
* yystackp
, size_t yyk
, yyStateNum yylrState
,
1263 YYSTYPE
* yyvalp
]b4_locations_if([, YYLTYPE
* yylocp
])[)
1265 yyGLRState
* yynewState
= &yynewGLRStackItem (yystackp
, yytrue
)->yystate
;
1267 yynewState
->yylrState
= yylrState
;
1268 yynewState
->yyposn
= yyposn
;
1269 yynewState
->yyresolved
= yytrue
;
1270 yynewState
->yypred
= yystackp
->yytops
.yystates
[yyk
];
1271 yynewState
->yysemantics
.yysval
= *yyvalp
;]b4_locations_if([
1272 yynewState
->yyloc
= *yylocp
;])[
1273 yystackp
->yytops
.yystates
[yyk
] = yynewState
;
1275 YY_RESERVE_GLRSTACK (yystackp
);
1278 /** Shift stack #K of YYSTACK, to a new state corresponding to LR
1279 * state YYLRSTATE, at input position YYPOSN, with the (unresolved)
1280 * semantic value of YYRHS under the action for YYRULE. */
1282 yyglrShiftDefer (yyGLRStack
* yystackp
, size_t yyk
, yyStateNum yylrState
,
1283 size_t yyposn
, yyGLRState
* rhs
, yyRuleNum yyrule
)
1285 yyGLRState
* yynewState
= &yynewGLRStackItem (yystackp
, yytrue
)->yystate
;
1287 yynewState
->yylrState
= yylrState
;
1288 yynewState
->yyposn
= yyposn
;
1289 yynewState
->yyresolved
= yyfalse
;
1290 yynewState
->yypred
= yystackp
->yytops
.yystates
[yyk
];
1291 yynewState
->yysemantics
.yyfirstVal
= YY_NULL
;
1292 yystackp
->yytops
.yystates
[yyk
] = yynewState
;
1294 /* Invokes YY_RESERVE_GLRSTACK. */
1295 yyaddDeferredAction (yystackp
, yyk
, yynewState
, rhs
, yyrule
);
1298 /** Pop the symbols consumed by reduction #RULE from the top of stack
1299 * #K of STACK, and perform the appropriate semantic action on their
1300 * semantic values. Assumes that all ambiguities in semantic values
1301 * have been previously resolved. Set *VALP to the resulting value,
1302 * and *LOCP to the computed location (if any). Return value is as
1303 * for userAction. */
1304 static inline YYRESULTTAG
1305 yydoAction (yyGLRStack
* yystackp
, size_t yyk
, yyRuleNum yyrule
,
1306 YYSTYPE
* yyvalp
]b4_locuser_formals
[)
1308 int yynrhs
= yyrhsLength (yyrule
);
1310 if (yystackp
->yysplitPoint
== YY_NULL
)
1312 /* Standard special case: single stack. */
1313 yyGLRStackItem
* rhs
= (yyGLRStackItem
*) yystackp
->yytops
.yystates
[yyk
];
1314 YYASSERT (yyk
== 0);
1315 yystackp
->yynextFree
-= yynrhs
;
1316 yystackp
->yyspaceLeft
+= yynrhs
;
1317 yystackp
->yytops
.yystates
[0] = & yystackp
->yynextFree
[-1].yystate
;
1318 return yyuserAction (yyrule
, yynrhs
, rhs
, yystackp
,
1319 yyvalp
]b4_locuser_args
[);
1323 /* At present, doAction is never called in nondeterministic
1324 * mode, so this branch is never taken. It is here in
1325 * anticipation of a future feature that will allow immediate
1326 * evaluation of selected actions in nondeterministic mode. */
1329 yyGLRStackItem yyrhsVals
[YYMAXRHS
+ YYMAXLEFT
+ 1];
1330 yys
= yyrhsVals
[YYMAXRHS
+ YYMAXLEFT
].yystate
.yypred
1331 = yystackp
->yytops
.yystates
[yyk
];]b4_locations_if([[
1333 /* Set default location. */
1334 yyrhsVals
[YYMAXRHS
+ YYMAXLEFT
- 1].yystate
.yyloc
= yys
->yyloc
;]])[
1335 for (yyi
= 0; yyi
< yynrhs
; yyi
+= 1)
1340 yyupdateSplit (yystackp
, yys
);
1341 yystackp
->yytops
.yystates
[yyk
] = yys
;
1342 return yyuserAction (yyrule
, yynrhs
, yyrhsVals
+ YYMAXRHS
+ YYMAXLEFT
- 1,
1343 yystackp
, yyvalp
]b4_locuser_args
[);
1347 #if !]b4_api_PREFIX[DEBUG
1348 # define YY_REDUCE_PRINT(Args)
1350 # define YY_REDUCE_PRINT(Args) \
1353 yy_reduce_print Args; \
1356 /*----------------------------------------------------------.
1357 | Report that the RULE is going to be reduced on stack #K. |
1358 `----------------------------------------------------------*/
1360 /*ARGSUSED*/ static inline void
1361 yy_reduce_print (yyGLRStack
* yystackp
, size_t yyk
, yyRuleNum yyrule
,
1362 YYSTYPE
* yyvalp
]b4_locuser_formals
[)
1364 int yynrhs
= yyrhsLength (yyrule
);
1365 yybool yynormal
__attribute__ ((__unused__
)) =
1366 (yystackp
->yysplitPoint
== YY_NULL
);
1367 yyGLRStackItem
* yyvsp
= (yyGLRStackItem
*) yystackp
->yytops
.yystates
[yyk
];
1370 YYUSE (yyvalp
);]b4_locations_if([
1372 ]b4_parse_param_use
[]dnl
1373 [ YYFPRINTF (stderr
, "Reducing stack %lu by rule %d (line %lu):\n",
1374 (unsigned long int) yyk
, yyrule
- 1,
1375 (unsigned long int) yyrline
[yyrule
]);
1376 /* The symbols being reduced. */
1377 for (yyi
= 0; yyi
< yynrhs
; yyi
++)
1379 YYFPRINTF (stderr
, " $%d = ", yyi
+ 1);
1380 yy_symbol_print (stderr
, yyrhs
[yyprhs
[yyrule
] + yyi
],
1381 &]b4_rhs_value(yynrhs
, yyi
+ 1)[
1382 ]b4_locations_if([, &]b4_rhs_location(yynrhs
, yyi
+ 1))[]dnl
1384 YYFPRINTF (stderr
, "\n");
1389 /** Pop items off stack #K of STACK according to grammar rule RULE,
1390 * and push back on the resulting nonterminal symbol. Perform the
1391 * semantic action associated with RULE and store its value with the
1392 * newly pushed state, if FORCEEVAL or if STACK is currently
1393 * unambiguous. Otherwise, store the deferred semantic action with
1394 * the new state. If the new state would have an identical input
1395 * position, LR state, and predecessor to an existing state on the stack,
1396 * it is identified with that existing state, eliminating stack #K from
1397 * the STACK. In this case, the (necessarily deferred) semantic value is
1398 * added to the options for the existing state's semantic value.
1400 static inline YYRESULTTAG
1401 yyglrReduce (yyGLRStack
* yystackp
, size_t yyk
, yyRuleNum yyrule
,
1402 yybool yyforceEval
]b4_user_formals
[)
1404 size_t yyposn
= yystackp
->yytops
.yystates
[yyk
]->yyposn
;
1406 if (yyforceEval
|| yystackp
->yysplitPoint
== YY_NULL
)
1408 YYSTYPE yysval
;]b4_locations_if([
1411 YY_REDUCE_PRINT ((yystackp
, yyk
, yyrule
, &yysval
]b4_locuser_args([&yyloc
])[));
1412 YYCHK (yydoAction (yystackp
, yyk
, yyrule
, &yysval
]b4_locuser_args([&yyloc
])[));
1413 YY_SYMBOL_PRINT ("-> $$ =", yyr1
[yyrule
], &yysval
, &yyloc
);
1414 yyglrShift (yystackp
, yyk
,
1415 yyLRgotoState (yystackp
->yytops
.yystates
[yyk
]->yylrState
,
1416 yylhsNonterm (yyrule
)),
1417 yyposn
, &yysval
]b4_locations_if([, &yyloc
])[);
1423 yyGLRState
* yys
, *yys0
= yystackp
->yytops
.yystates
[yyk
];
1424 yyStateNum yynewLRState
;
1426 for (yys
= yystackp
->yytops
.yystates
[yyk
], yyn
= yyrhsLength (yyrule
);
1432 yyupdateSplit (yystackp
, yys
);
1433 yynewLRState
= yyLRgotoState (yys
->yylrState
, yylhsNonterm (yyrule
));
1435 "Reduced stack %lu by rule #%d; action deferred. Now in state %d.\n",
1436 (unsigned long int) yyk
, yyrule
- 1, yynewLRState
));
1437 for (yyi
= 0; yyi
< yystackp
->yytops
.yysize
; yyi
+= 1)
1438 if (yyi
!= yyk
&& yystackp
->yytops
.yystates
[yyi
] != YY_NULL
)
1440 yyGLRState
*yysplit
= yystackp
->yysplitPoint
;
1441 yyGLRState
*yyp
= yystackp
->yytops
.yystates
[yyi
];
1442 while (yyp
!= yys
&& yyp
!= yysplit
&& yyp
->yyposn
>= yyposn
)
1444 if (yyp
->yylrState
== yynewLRState
&& yyp
->yypred
== yys
)
1446 yyaddDeferredAction (yystackp
, yyk
, yyp
, yys0
, yyrule
);
1447 yymarkStackDeleted (yystackp
, yyk
);
1448 YYDPRINTF ((stderr
, "Merging stack %lu into stack %lu.\n",
1449 (unsigned long int) yyk
,
1450 (unsigned long int) yyi
));
1456 yystackp
->yytops
.yystates
[yyk
] = yys
;
1457 yyglrShiftDefer (yystackp
, yyk
, yynewLRState
, yyposn
, yys0
, yyrule
);
1463 yysplitStack (yyGLRStack
* yystackp
, size_t yyk
)
1465 if (yystackp
->yysplitPoint
== YY_NULL
)
1467 YYASSERT (yyk
== 0);
1468 yystackp
->yysplitPoint
= yystackp
->yytops
.yystates
[yyk
];
1470 if (yystackp
->yytops
.yysize
>= yystackp
->yytops
.yycapacity
)
1472 yyGLRState
** yynewStates
;
1473 yybool
* yynewLookaheadNeeds
;
1475 yynewStates
= YY_NULL
;
1477 if (yystackp
->yytops
.yycapacity
1478 > (YYSIZEMAX
/ (2 * sizeof yynewStates
[0])))
1479 yyMemoryExhausted (yystackp
);
1480 yystackp
->yytops
.yycapacity
*= 2;
1483 (yyGLRState
**) YYREALLOC (yystackp
->yytops
.yystates
,
1484 (yystackp
->yytops
.yycapacity
1485 * sizeof yynewStates
[0]));
1486 if (yynewStates
== YY_NULL
)
1487 yyMemoryExhausted (yystackp
);
1488 yystackp
->yytops
.yystates
= yynewStates
;
1490 yynewLookaheadNeeds
=
1491 (yybool
*) YYREALLOC (yystackp
->yytops
.yylookaheadNeeds
,
1492 (yystackp
->yytops
.yycapacity
1493 * sizeof yynewLookaheadNeeds
[0]));
1494 if (yynewLookaheadNeeds
== YY_NULL
)
1495 yyMemoryExhausted (yystackp
);
1496 yystackp
->yytops
.yylookaheadNeeds
= yynewLookaheadNeeds
;
1498 yystackp
->yytops
.yystates
[yystackp
->yytops
.yysize
]
1499 = yystackp
->yytops
.yystates
[yyk
];
1500 yystackp
->yytops
.yylookaheadNeeds
[yystackp
->yytops
.yysize
]
1501 = yystackp
->yytops
.yylookaheadNeeds
[yyk
];
1502 yystackp
->yytops
.yysize
+= 1;
1503 return yystackp
->yytops
.yysize
-1;
1506 /** True iff Y0 and Y1 represent identical options at the top level.
1507 * That is, they represent the same rule applied to RHS symbols
1508 * that produce the same terminal symbols. */
1510 yyidenticalOptions (yySemanticOption
* yyy0
, yySemanticOption
* yyy1
)
1512 if (yyy0
->yyrule
== yyy1
->yyrule
)
1514 yyGLRState
*yys0
, *yys1
;
1516 for (yys0
= yyy0
->yystate
, yys1
= yyy1
->yystate
,
1517 yyn
= yyrhsLength (yyy0
->yyrule
);
1519 yys0
= yys0
->yypred
, yys1
= yys1
->yypred
, yyn
-= 1)
1520 if (yys0
->yyposn
!= yys1
->yyposn
)
1528 /** Assuming identicalOptions (Y0,Y1), destructively merge the
1529 * alternative semantic values for the RHS-symbols of Y1 and Y0. */
1531 yymergeOptionSets (yySemanticOption
* yyy0
, yySemanticOption
* yyy1
)
1533 yyGLRState
*yys0
, *yys1
;
1535 for (yys0
= yyy0
->yystate
, yys1
= yyy1
->yystate
,
1536 yyn
= yyrhsLength (yyy0
->yyrule
);
1538 yys0
= yys0
->yypred
, yys1
= yys1
->yypred
, yyn
-= 1)
1542 else if (yys0
->yyresolved
)
1544 yys1
->yyresolved
= yytrue
;
1545 yys1
->yysemantics
.yysval
= yys0
->yysemantics
.yysval
;
1547 else if (yys1
->yyresolved
)
1549 yys0
->yyresolved
= yytrue
;
1550 yys0
->yysemantics
.yysval
= yys1
->yysemantics
.yysval
;
1554 yySemanticOption
** yyz0p
= &yys0
->yysemantics
.yyfirstVal
;
1555 yySemanticOption
* yyz1
= yys1
->yysemantics
.yyfirstVal
;
1556 while (YYID (yytrue
))
1558 if (yyz1
== *yyz0p
|| yyz1
== YY_NULL
)
1560 else if (*yyz0p
== YY_NULL
)
1565 else if (*yyz0p
< yyz1
)
1567 yySemanticOption
* yyz
= *yyz0p
;
1569 yyz1
= yyz1
->yynext
;
1570 (*yyz0p
)->yynext
= yyz
;
1572 yyz0p
= &(*yyz0p
)->yynext
;
1574 yys1
->yysemantics
.yyfirstVal
= yys0
->yysemantics
.yyfirstVal
;
1579 /** Y0 and Y1 represent two possible actions to take in a given
1580 * parsing state; return 0 if no combination is possible,
1581 * 1 if user-mergeable, 2 if Y0 is preferred, 3 if Y1 is preferred. */
1583 yypreference (yySemanticOption
* y0
, yySemanticOption
* y1
)
1585 yyRuleNum r0
= y0
->yyrule
, r1
= y1
->yyrule
;
1586 int p0
= yydprec
[r0
], p1
= yydprec
[r1
];
1590 if (yymerger
[r0
] == 0 || yymerger
[r0
] != yymerger
[r1
])
1595 if (p0
== 0 || p1
== 0)
1604 static YYRESULTTAG
yyresolveValue (yyGLRState
* yys
,
1605 yyGLRStack
* yystackp
]b4_user_formals
[);
1608 /** Resolve the previous N states starting at and including state S. If result
1609 * != yyok, some states may have been left unresolved possibly with empty
1610 * semantic option chains. Regardless of whether result = yyok, each state
1611 * has been left with consistent data so that yydestroyGLRState can be invoked
1614 yyresolveStates (yyGLRState
* yys
, int yyn
,
1615 yyGLRStack
* yystackp
]b4_user_formals
[)
1619 YYASSERT (yys
->yypred
);
1620 YYCHK (yyresolveStates (yys
->yypred
, yyn
-1, yystackp
]b4_user_args
[));
1621 if (! yys
->yyresolved
)
1622 YYCHK (yyresolveValue (yys
, yystackp
]b4_user_args
[));
1627 /** Resolve the states for the RHS of OPT, perform its user action, and return
1628 * the semantic value and location. Regardless of whether result = yyok, all
1629 * RHS states have been destroyed (assuming the user action destroys all RHS
1630 * semantic values if invoked). */
1632 yyresolveAction (yySemanticOption
* yyopt
, yyGLRStack
* yystackp
,
1633 YYSTYPE
* yyvalp
]b4_locuser_formals
[)
1635 yyGLRStackItem yyrhsVals
[YYMAXRHS
+ YYMAXLEFT
+ 1];
1636 int yynrhs
= yyrhsLength (yyopt
->yyrule
);
1637 YYRESULTTAG yyflag
=
1638 yyresolveStates (yyopt
->yystate
, yynrhs
, yystackp
]b4_user_args
[);
1642 for (yys
= yyopt
->yystate
; yynrhs
> 0; yys
= yys
->yypred
, yynrhs
-= 1)
1643 yydestroyGLRState ("Cleanup: popping", yys
]b4_user_args
[);
1647 yyrhsVals
[YYMAXRHS
+ YYMAXLEFT
].yystate
.yypred
= yyopt
->yystate
;]b4_locations_if([[
1649 /* Set default location. */
1650 yyrhsVals
[YYMAXRHS
+ YYMAXLEFT
- 1].yystate
.yyloc
= yyopt
->yystate
->yyloc
;]])[
1652 int yychar_current
= yychar
;
1653 YYSTYPE yylval_current
= yylval
;]b4_locations_if([
1654 YYLTYPE yylloc_current
= yylloc
;])[
1655 yychar
= yyopt
->yyrawchar
;
1656 yylval
= yyopt
->yyval
;]b4_locations_if([
1657 yylloc
= yyopt
->yyloc
;])[
1658 yyflag
= yyuserAction (yyopt
->yyrule
, yynrhs
,
1659 yyrhsVals
+ YYMAXRHS
+ YYMAXLEFT
- 1,
1660 yystackp
, yyvalp
]b4_locuser_args
[);
1661 yychar
= yychar_current
;
1662 yylval
= yylval_current
;]b4_locations_if([
1663 yylloc
= yylloc_current
;])[
1668 #if ]b4_api_PREFIX[DEBUG
1670 yyreportTree (yySemanticOption
* yyx
, int yyindent
)
1672 int yynrhs
= yyrhsLength (yyx
->yyrule
);
1675 yyGLRState
* yystates
[1 + YYMAXRHS
];
1676 yyGLRState yyleftmost_state
;
1678 for (yyi
= yynrhs
, yys
= yyx
->yystate
; 0 < yyi
; yyi
-= 1, yys
= yys
->yypred
)
1679 yystates
[yyi
] = yys
;
1682 yyleftmost_state
.yyposn
= 0;
1683 yystates
[0] = &yyleftmost_state
;
1688 if (yyx
->yystate
->yyposn
< yys
->yyposn
+ 1)
1689 YYFPRINTF (stderr
, "%*s%s -> <Rule %d, empty>\n",
1690 yyindent
, "", yytokenName (yylhsNonterm (yyx
->yyrule
)),
1693 YYFPRINTF (stderr
, "%*s%s -> <Rule %d, tokens %lu .. %lu>\n",
1694 yyindent
, "", yytokenName (yylhsNonterm (yyx
->yyrule
)),
1695 yyx
->yyrule
- 1, (unsigned long int) (yys
->yyposn
+ 1),
1696 (unsigned long int) yyx
->yystate
->yyposn
);
1697 for (yyi
= 1; yyi
<= yynrhs
; yyi
+= 1)
1699 if (yystates
[yyi
]->yyresolved
)
1701 if (yystates
[yyi
-1]->yyposn
+1 > yystates
[yyi
]->yyposn
)
1702 YYFPRINTF (stderr
, "%*s%s <empty>\n", yyindent
+2, "",
1703 yytokenName (yyrhs
[yyprhs
[yyx
->yyrule
]+yyi
-1]));
1705 YYFPRINTF (stderr
, "%*s%s <tokens %lu .. %lu>\n", yyindent
+2, "",
1706 yytokenName (yyrhs
[yyprhs
[yyx
->yyrule
]+yyi
-1]),
1707 (unsigned long int) (yystates
[yyi
- 1]->yyposn
+ 1),
1708 (unsigned long int) yystates
[yyi
]->yyposn
);
1711 yyreportTree (yystates
[yyi
]->yysemantics
.yyfirstVal
, yyindent
+2);
1716 /*ARGSUSED*/ static YYRESULTTAG
1717 yyreportAmbiguity (yySemanticOption
* yyx0
,
1718 yySemanticOption
* yyx1
]b4_pure_formals
[)
1723 #if ]b4_api_PREFIX[DEBUG
1724 YYFPRINTF (stderr
, "Ambiguity detected.\n");
1725 YYFPRINTF (stderr
, "Option 1,\n");
1726 yyreportTree (yyx0
, 2);
1727 YYFPRINTF (stderr
, "\nOption 2,\n");
1728 yyreportTree (yyx1
, 2);
1729 YYFPRINTF (stderr
, "\n");
1732 yyerror (]b4_yyerror_args
[YY_("syntax is ambiguous"));
1734 }]b4_locations_if([[
1736 /** Starting at and including state S1, resolve the location for each of the
1737 * previous N1 states that is unresolved. The first semantic option of a state
1738 * is always chosen. */
1740 yyresolveLocations (yyGLRState
* yys1
, int yyn1
,
1741 yyGLRStack
*yystackp
]b4_user_formals
[)
1745 yyresolveLocations (yys1
->yypred
, yyn1
- 1, yystackp
]b4_user_args
[);
1746 if (!yys1
->yyresolved
)
1748 yyGLRStackItem yyrhsloc
[1 + YYMAXRHS
];
1750 yySemanticOption
*yyoption
= yys1
->yysemantics
.yyfirstVal
;
1751 YYASSERT (yyoption
!= YY_NULL
);
1752 yynrhs
= yyrhsLength (yyoption
->yyrule
);
1757 yyresolveLocations (yyoption
->yystate
, yynrhs
,
1758 yystackp
]b4_user_args
[);
1759 for (yys
= yyoption
->yystate
, yyn
= yynrhs
;
1761 yys
= yys
->yypred
, yyn
-= 1)
1762 yyrhsloc
[yyn
].yystate
.yyloc
= yys
->yyloc
;
1766 /* Both yyresolveAction and yyresolveLocations traverse the GSS
1767 in reverse rightmost order. It is only necessary to invoke
1768 yyresolveLocations on a subforest for which yyresolveAction
1769 would have been invoked next had an ambiguity not been
1770 detected. Thus the location of the previous state (but not
1771 necessarily the previous state itself) is guaranteed to be
1772 resolved already. */
1773 yyGLRState
*yyprevious
= yyoption
->yystate
;
1774 yyrhsloc
[0].yystate
.yyloc
= yyprevious
->yyloc
;
1777 int yychar_current
= yychar
;
1778 YYSTYPE yylval_current
= yylval
;
1779 YYLTYPE yylloc_current
= yylloc
;
1780 yychar
= yyoption
->yyrawchar
;
1781 yylval
= yyoption
->yyval
;
1782 yylloc
= yyoption
->yyloc
;
1783 YYLLOC_DEFAULT ((yys1
->yyloc
), yyrhsloc
, yynrhs
);
1784 yychar
= yychar_current
;
1785 yylval
= yylval_current
;
1786 yylloc
= yylloc_current
;
1792 /** Resolve the ambiguity represented in state S, perform the indicated
1793 * actions, and set the semantic value of S. If result != yyok, the chain of
1794 * semantic options in S has been cleared instead or it has been left
1795 * unmodified except that redundant options may have been removed. Regardless
1796 * of whether result = yyok, S has been left with consistent data so that
1797 * yydestroyGLRState can be invoked if necessary. */
1799 yyresolveValue (yyGLRState
* yys
, yyGLRStack
* yystackp
]b4_user_formals
[)
1801 yySemanticOption
* yyoptionList
= yys
->yysemantics
.yyfirstVal
;
1802 yySemanticOption
* yybest
= yyoptionList
;
1803 yySemanticOption
** yypp
;
1804 yybool yymerge
= yyfalse
;
1806 YYRESULTTAG yyflag
;]b4_locations_if([
1807 YYLTYPE
*yylocp
= &yys
->yyloc
;])[
1809 for (yypp
= &yyoptionList
->yynext
; *yypp
!= YY_NULL
; )
1811 yySemanticOption
* yyp
= *yypp
;
1813 if (yyidenticalOptions (yybest
, yyp
))
1815 yymergeOptionSets (yybest
, yyp
);
1816 *yypp
= yyp
->yynext
;
1820 switch (yypreference (yybest
, yyp
))
1822 case 0:]b4_locations_if([[
1823 yyresolveLocations (yys
, 1, yystackp
]b4_user_args
[);]])[
1824 return yyreportAmbiguity (yybest
, yyp
]b4_pure_args
[);
1836 /* This cannot happen so it is not worth a YYASSERT (yyfalse),
1837 but some compilers complain if the default case is
1841 yypp
= &yyp
->yynext
;
1847 yySemanticOption
* yyp
;
1848 int yyprec
= yydprec
[yybest
->yyrule
];
1849 yyflag
= yyresolveAction (yybest
, yystackp
, &yysval
]b4_locuser_args
[);
1851 for (yyp
= yybest
->yynext
; yyp
!= YY_NULL
; yyp
= yyp
->yynext
)
1853 if (yyprec
== yydprec
[yyp
->yyrule
])
1855 YYSTYPE yysval_other
;]b4_locations_if([
1857 yyflag
= yyresolveAction (yyp
, yystackp
, &yysval_other
]b4_locuser_args([&yydummy
])[);
1860 yydestruct ("Cleanup: discarding incompletely merged value for",
1861 yystos
[yys
->yylrState
],
1862 &yysval
]b4_locuser_args
[);
1865 yyuserMerge (yymerger
[yyp
->yyrule
], &yysval
, &yysval_other
);
1870 yyflag
= yyresolveAction (yybest
, yystackp
, &yysval
]b4_locuser_args([yylocp
])[);
1874 yys
->yyresolved
= yytrue
;
1875 yys
->yysemantics
.yysval
= yysval
;
1878 yys
->yysemantics
.yyfirstVal
= YY_NULL
;
1883 yyresolveStack (yyGLRStack
* yystackp
]b4_user_formals
[)
1885 if (yystackp
->yysplitPoint
!= YY_NULL
)
1890 for (yyn
= 0, yys
= yystackp
->yytops
.yystates
[0];
1891 yys
!= yystackp
->yysplitPoint
;
1892 yys
= yys
->yypred
, yyn
+= 1)
1894 YYCHK (yyresolveStates (yystackp
->yytops
.yystates
[0], yyn
, yystackp
1901 yycompressStack (yyGLRStack
* yystackp
)
1903 yyGLRState
* yyp
, *yyq
, *yyr
;
1905 if (yystackp
->yytops
.yysize
!= 1 || yystackp
->yysplitPoint
== YY_NULL
)
1908 for (yyp
= yystackp
->yytops
.yystates
[0], yyq
= yyp
->yypred
, yyr
= YY_NULL
;
1909 yyp
!= yystackp
->yysplitPoint
;
1910 yyr
= yyp
, yyp
= yyq
, yyq
= yyp
->yypred
)
1913 yystackp
->yyspaceLeft
+= yystackp
->yynextFree
- yystackp
->yyitems
;
1914 yystackp
->yynextFree
= ((yyGLRStackItem
*) yystackp
->yysplitPoint
) + 1;
1915 yystackp
->yyspaceLeft
-= yystackp
->yynextFree
- yystackp
->yyitems
;
1916 yystackp
->yysplitPoint
= YY_NULL
;
1917 yystackp
->yylastDeleted
= YY_NULL
;
1919 while (yyr
!= YY_NULL
)
1921 yystackp
->yynextFree
->yystate
= *yyr
;
1923 yystackp
->yynextFree
->yystate
.yypred
= &yystackp
->yynextFree
[-1].yystate
;
1924 yystackp
->yytops
.yystates
[0] = &yystackp
->yynextFree
->yystate
;
1925 yystackp
->yynextFree
+= 1;
1926 yystackp
->yyspaceLeft
-= 1;
1931 yyprocessOneStack (yyGLRStack
* yystackp
, size_t yyk
,
1932 size_t yyposn
]b4_pure_formals
[)
1935 const short int* yyconflicts
;
1938 while (yystackp
->yytops
.yystates
[yyk
] != YY_NULL
)
1940 yyStateNum yystate
= yystackp
->yytops
.yystates
[yyk
]->yylrState
;
1941 YYDPRINTF ((stderr
, "Stack %lu Entering state %d\n",
1942 (unsigned long int) yyk
, yystate
));
1944 YYASSERT (yystate
!= YYFINAL
);
1946 if (yyisDefaultedState (yystate
))
1948 yyrule
= yydefaultAction (yystate
);
1951 YYDPRINTF ((stderr
, "Stack %lu dies.\n",
1952 (unsigned long int) yyk
));
1953 yymarkStackDeleted (yystackp
, yyk
);
1956 YYCHK (yyglrReduce (yystackp
, yyk
, yyrule
, yyfalse
]b4_user_args
[));
1961 yystackp
->yytops
.yylookaheadNeeds
[yyk
] = yytrue
;
1962 if (yychar
== YYEMPTY
)
1964 YYDPRINTF ((stderr
, "Reading a token: "));
1968 if (yychar
<= YYEOF
)
1970 yychar
= yytoken
= YYEOF
;
1971 YYDPRINTF ((stderr
, "Now at end of input.\n"));
1975 yytoken
= YYTRANSLATE (yychar
);
1976 YY_SYMBOL_PRINT ("Next token is", yytoken
, &yylval
, &yylloc
);
1979 yygetLRActions (yystate
, yytoken
, &yyaction
, &yyconflicts
);
1981 while (*yyconflicts
!= 0)
1983 size_t yynewStack
= yysplitStack (yystackp
, yyk
);
1984 YYDPRINTF ((stderr
, "Splitting off stack %lu from %lu.\n",
1985 (unsigned long int) yynewStack
,
1986 (unsigned long int) yyk
));
1987 YYCHK (yyglrReduce (yystackp
, yynewStack
,
1988 *yyconflicts
, yyfalse
]b4_user_args
[));
1989 YYCHK (yyprocessOneStack (yystackp
, yynewStack
,
1990 yyposn
]b4_pure_args
[));
1994 if (yyisShiftAction (yyaction
))
1996 else if (yyisErrorAction (yyaction
))
1998 YYDPRINTF ((stderr
, "Stack %lu dies.\n",
1999 (unsigned long int) yyk
));
2000 yymarkStackDeleted (yystackp
, yyk
);
2004 YYCHK (yyglrReduce (yystackp
, yyk
, -yyaction
,
2005 yyfalse
]b4_user_args
[));
2011 /*ARGSUSED*/ static void
2012 yyreportSyntaxError (yyGLRStack
* yystackp
]b4_user_formals
[)
2014 if (yystackp
->yyerrState
!= 0)
2016 #if ! YYERROR_VERBOSE
2017 yyerror (]b4_lyyerror_args
[YY_("syntax error"));
2019 yySymbol yytoken
= yychar
== YYEMPTY
? YYEMPTY
: YYTRANSLATE (yychar
);
2020 size_t yysize0
= yytnamerr (YY_NULL
, yytokenName (yytoken
));
2021 size_t yysize
= yysize0
;
2023 yybool yysize_overflow
= yyfalse
;
2024 char* yymsg
= YY_NULL
;
2025 enum { YYERROR_VERBOSE_ARGS_MAXIMUM
= 5 };
2026 /* Internationalized format string. */
2027 const char *yyformat
= YY_NULL
;
2028 /* Arguments of yyformat. */
2029 char const *yyarg
[YYERROR_VERBOSE_ARGS_MAXIMUM
];
2030 /* Number of reported tokens (one for the "unexpected", one per
2034 /* There are many possibilities here to consider:
2035 - If this state is a consistent state with a default action, then
2036 the only way this function was invoked is if the default action
2037 is an error action. In that case, don't check for expected
2038 tokens because there are none.
2039 - The only way there can be no lookahead present (in yychar) is if
2040 this state is a consistent state with a default action. Thus,
2041 detecting the absence of a lookahead is sufficient to determine
2042 that there is no unexpected or expected token to report. In that
2043 case, just report a simple "syntax error".
2044 - Don't assume there isn't a lookahead just because this state is a
2045 consistent state with a default action. There might have been a
2046 previous inconsistent state, consistent state with a non-default
2047 action, or user semantic action that manipulated yychar.
2048 - Of course, the expected token list depends on states to have
2049 correct lookahead information, and it depends on the parser not
2050 to perform extra reductions after fetching a lookahead from the
2051 scanner and before detecting a syntax error. Thus, state merging
2052 (from LALR or IELR) and default reductions corrupt the expected
2053 token list. However, the list is correct for canonical LR with
2054 one exception: it will still contain any token that will not be
2055 accepted due to an error action in a later state.
2057 if (yytoken
!= YYEMPTY
)
2059 int yyn
= yypact
[yystackp
->yytops
.yystates
[0]->yylrState
];
2060 yyarg
[yycount
++] = yytokenName (yytoken
);
2061 if (!yypact_value_is_default (yyn
))
2063 /* Start YYX at -YYN if negative to avoid negative indexes in
2064 YYCHECK. In other words, skip the first -YYN actions for this
2065 state because they are default actions. */
2066 int yyxbegin
= yyn
< 0 ? -yyn
: 0;
2067 /* Stay within bounds of both yycheck and yytname. */
2068 int yychecklim
= YYLAST
- yyn
+ 1;
2069 int yyxend
= yychecklim
< YYNTOKENS
? yychecklim
: YYNTOKENS
;
2071 for (yyx
= yyxbegin
; yyx
< yyxend
; ++yyx
)
2072 if (yycheck
[yyx
+ yyn
] == yyx
&& yyx
!= YYTERROR
2073 && !yytable_value_is_error (yytable
[yyx
+ yyn
]))
2075 if (yycount
== YYERROR_VERBOSE_ARGS_MAXIMUM
)
2081 yyarg
[yycount
++] = yytokenName (yyx
);
2082 yysize1
= yysize
+ yytnamerr (YY_NULL
, yytokenName (yyx
));
2083 yysize_overflow
|= yysize1
< yysize
;
2091 #define YYCASE_(N, S) \
2095 YYCASE_(0, YY_("syntax error"));
2096 YYCASE_(1, YY_("syntax error, unexpected %s"));
2097 YYCASE_(2, YY_("syntax error, unexpected %s, expecting %s"));
2098 YYCASE_(3, YY_("syntax error, unexpected %s, expecting %s or %s"));
2099 YYCASE_(4, YY_("syntax error, unexpected %s, expecting %s or %s or %s"));
2100 YYCASE_(5, YY_("syntax error, unexpected %s, expecting %s or %s or %s or %s"));
2104 yysize1
= yysize
+ strlen (yyformat
);
2105 yysize_overflow
|= yysize1
< yysize
;
2108 if (!yysize_overflow
)
2109 yymsg
= (char *) YYMALLOC (yysize
);
2115 while ((*yyp
= *yyformat
))
2117 if (*yyp
== '%' && yyformat
[1] == 's' && yyi
< yycount
)
2119 yyp
+= yytnamerr (yyp
, yyarg
[yyi
++]);
2128 yyerror (]b4_lyyerror_args
[yymsg
);
2133 yyerror (]b4_lyyerror_args
[YY_("syntax error"));
2134 yyMemoryExhausted (yystackp
);
2136 #endif /* YYERROR_VERBOSE */
2140 /* Recover from a syntax error on *YYSTACKP, assuming that *YYSTACKP->YYTOKENP,
2141 yylval, and yylloc are the syntactic category, semantic value, and location
2142 of the lookahead. */
2143 /*ARGSUSED*/ static void
2144 yyrecoverSyntaxError (yyGLRStack
* yystackp
]b4_user_formals
[)
2149 if (yystackp
->yyerrState
== 3)
2150 /* We just shifted the error token and (perhaps) took some
2151 reductions. Skip tokens until we can proceed. */
2152 while (YYID (yytrue
))
2155 if (yychar
== YYEOF
)
2156 yyFail (yystackp
][]b4_lpure_args
[, YY_NULL
);
2157 if (yychar
!= YYEMPTY
)
2158 {]b4_locations_if([[
2159 /* We throw away the lookahead, but the error range
2160 of the shifted error token must take it into account. */
2161 yyGLRState
*yys
= yystackp
->yytops
.yystates
[0];
2162 yyGLRStackItem yyerror_range
[3];
2163 yyerror_range
[1].yystate
.yyloc
= yys
->yyloc
;
2164 yyerror_range
[2].yystate
.yyloc
= yylloc
;
2165 YYLLOC_DEFAULT ((yys
->yyloc
), yyerror_range
, 2);]])[
2166 yytoken
= YYTRANSLATE (yychar
);
2167 yydestruct ("Error: discarding",
2168 yytoken
, &yylval
]b4_locuser_args([&yylloc
])[);
2170 YYDPRINTF ((stderr
, "Reading a token: "));
2172 if (yychar
<= YYEOF
)
2174 yychar
= yytoken
= YYEOF
;
2175 YYDPRINTF ((stderr
, "Now at end of input.\n"));
2179 yytoken
= YYTRANSLATE (yychar
);
2180 YY_SYMBOL_PRINT ("Next token is", yytoken
, &yylval
, &yylloc
);
2182 yyj
= yypact
[yystackp
->yytops
.yystates
[0]->yylrState
];
2183 if (yypact_value_is_default (yyj
))
2186 if (yyj
< 0 || YYLAST
< yyj
|| yycheck
[yyj
] != yytoken
)
2188 if (yydefact
[yystackp
->yytops
.yystates
[0]->yylrState
] != 0)
2191 else if (! yytable_value_is_error (yytable
[yyj
]))
2195 /* Reduce to one stack. */
2196 for (yyk
= 0; yyk
< yystackp
->yytops
.yysize
; yyk
+= 1)
2197 if (yystackp
->yytops
.yystates
[yyk
] != YY_NULL
)
2199 if (yyk
>= yystackp
->yytops
.yysize
)
2200 yyFail (yystackp
][]b4_lpure_args
[, YY_NULL
);
2201 for (yyk
+= 1; yyk
< yystackp
->yytops
.yysize
; yyk
+= 1)
2202 yymarkStackDeleted (yystackp
, yyk
);
2203 yyremoveDeletes (yystackp
);
2204 yycompressStack (yystackp
);
2206 /* Now pop stack until we find a state that shifts the error token. */
2207 yystackp
->yyerrState
= 3;
2208 while (yystackp
->yytops
.yystates
[0] != YY_NULL
)
2210 yyGLRState
*yys
= yystackp
->yytops
.yystates
[0];
2211 yyj
= yypact
[yys
->yylrState
];
2212 if (! yypact_value_is_default (yyj
))
2215 if (0 <= yyj
&& yyj
<= YYLAST
&& yycheck
[yyj
] == YYTERROR
2216 && yyisShiftAction (yytable
[yyj
]))
2218 /* Shift the error token. */]b4_locations_if([[
2219 /* First adjust its location.*/
2221 yystackp
->yyerror_range
[2].yystate
.yyloc
= yylloc
;
2222 YYLLOC_DEFAULT (yyerrloc
, (yystackp
->yyerror_range
), 2);]])[
2223 YY_SYMBOL_PRINT ("Shifting", yystos
[yytable
[yyj
]],
2224 &yylval
, &yyerrloc
);
2225 yyglrShift (yystackp
, 0, yytable
[yyj
],
2226 yys
->yyposn
, &yylval
]b4_locations_if([, &yyerrloc
])[);
2227 yys
= yystackp
->yytops
.yystates
[0];
2230 }]b4_locations_if([[
2231 yystackp
->yyerror_range
[1].yystate
.yyloc
= yys
->yyloc
;]])[
2232 if (yys
->yypred
!= YY_NULL
)
2233 yydestroyGLRState ("Error: popping", yys
]b4_user_args
[);
2234 yystackp
->yytops
.yystates
[0] = yys
->yypred
;
2235 yystackp
->yynextFree
-= 1;
2236 yystackp
->yyspaceLeft
+= 1;
2238 if (yystackp
->yytops
.yystates
[0] == YY_NULL
)
2239 yyFail (yystackp
][]b4_lpure_args
[, YY_NULL
);
2242 #define YYCHK1(YYE) \
2252 goto yyuser_error; \
2263 ]b4_c_ansi_function_def([yyparse
], [int], b4_parse_param
)[
2267 yyGLRStack
* const yystackp
= &yystack
;
2270 YYDPRINTF ((stderr
, "Starting parse\n"));
2273 yylval
= yyval_default
;]b4_locations_if([
2274 yylloc
= yyloc_default
;])[
2275 ]m4_ifdef([b4_initial_action
], [
2276 b4_dollar_pushdef([yylval
], [], [yylloc
])dnl
2277 /* User initialization code. */
2278 b4_user_initial_action
2279 b4_dollar_popdef
])[]dnl
2281 if (! yyinitGLRStack (yystackp
, YYINITDEPTH
))
2282 goto yyexhaustedlab
;
2283 switch (YYSETJMP (yystack
.yyexception_buffer
))
2286 case 1: goto yyabortlab
;
2287 case 2: goto yyexhaustedlab
;
2288 default: goto yybuglab
;
2290 yyglrShift (&yystack
, 0, 0, 0, &yylval
]b4_locations_if([, &yylloc
])[);
2293 while (YYID (yytrue
))
2295 /* For efficiency, we have two loops, the first of which is
2296 specialized to deterministic operation (single stack, no
2297 potential ambiguity). */
2299 while (YYID (yytrue
))
2303 const short int* yyconflicts
;
2305 yyStateNum yystate
= yystack
.yytops
.yystates
[0]->yylrState
;
2306 YYDPRINTF ((stderr
, "Entering state %d\n", yystate
));
2307 if (yystate
== YYFINAL
)
2309 if (yyisDefaultedState (yystate
))
2311 yyrule
= yydefaultAction (yystate
);
2314 ]b4_locations_if([[ yystack
.yyerror_range
[1].yystate
.yyloc
= yylloc
;]])[
2315 yyreportSyntaxError (&yystack
]b4_user_args
[);
2318 YYCHK1 (yyglrReduce (&yystack
, 0, yyrule
, yytrue
]b4_user_args
[));
2323 if (yychar
== YYEMPTY
)
2325 YYDPRINTF ((stderr
, "Reading a token: "));
2329 if (yychar
<= YYEOF
)
2331 yychar
= yytoken
= YYEOF
;
2332 YYDPRINTF ((stderr
, "Now at end of input.\n"));
2336 yytoken
= YYTRANSLATE (yychar
);
2337 YY_SYMBOL_PRINT ("Next token is", yytoken
, &yylval
, &yylloc
);
2340 yygetLRActions (yystate
, yytoken
, &yyaction
, &yyconflicts
);
2341 if (*yyconflicts
!= 0)
2343 if (yyisShiftAction (yyaction
))
2345 YY_SYMBOL_PRINT ("Shifting", yytoken
, &yylval
, &yylloc
);
2348 yyglrShift (&yystack
, 0, yyaction
, yyposn
, &yylval
]b4_locations_if([, &yylloc
])[);
2349 if (0 < yystack
.yyerrState
)
2350 yystack
.yyerrState
-= 1;
2352 else if (yyisErrorAction (yyaction
))
2354 ]b4_locations_if([[ yystack
.yyerror_range
[1].yystate
.yyloc
= yylloc
;]])[
2355 yyreportSyntaxError (&yystack
]b4_user_args
[);
2359 YYCHK1 (yyglrReduce (&yystack
, 0, -yyaction
, yytrue
]b4_user_args
[));
2363 while (YYID (yytrue
))
2365 yySymbol yytoken_to_shift
;
2368 for (yys
= 0; yys
< yystack
.yytops
.yysize
; yys
+= 1)
2369 yystackp
->yytops
.yylookaheadNeeds
[yys
] = yychar
!= YYEMPTY
;
2371 /* yyprocessOneStack returns one of three things:
2373 - An error flag. If the caller is yyprocessOneStack, it
2374 immediately returns as well. When the caller is finally
2375 yyparse, it jumps to an error label via YYCHK1.
2377 - yyok, but yyprocessOneStack has invoked yymarkStackDeleted
2378 (&yystack, yys), which sets the top state of yys to NULL. Thus,
2379 yyparse's following invocation of yyremoveDeletes will remove
2382 - yyok, when ready to shift a token.
2384 Except in the first case, yyparse will invoke yyremoveDeletes and
2385 then shift the next token onto all remaining stacks. This
2386 synchronization of the shift (that is, after all preceding
2387 reductions on all stacks) helps prevent double destructor calls
2388 on yylval in the event of memory exhaustion. */
2390 for (yys
= 0; yys
< yystack
.yytops
.yysize
; yys
+= 1)
2391 YYCHK1 (yyprocessOneStack (&yystack
, yys
, yyposn
]b4_lpure_args
[));
2392 yyremoveDeletes (&yystack
);
2393 if (yystack
.yytops
.yysize
== 0)
2395 yyundeleteLastStack (&yystack
);
2396 if (yystack
.yytops
.yysize
== 0)
2397 yyFail (&yystack
][]b4_lpure_args
[, YY_("syntax error"));
2398 YYCHK1 (yyresolveStack (&yystack
]b4_user_args
[));
2399 YYDPRINTF ((stderr
, "Returning to deterministic operation.\n"));
2400 ]b4_locations_if([[ yystack
.yyerror_range
[1].yystate
.yyloc
= yylloc
;]])[
2401 yyreportSyntaxError (&yystack
]b4_user_args
[);
2405 /* If any yyglrShift call fails, it will fail after shifting. Thus,
2406 a copy of yylval will already be on stack 0 in the event of a
2407 failure in the following loop. Thus, yychar is set to YYEMPTY
2408 before the loop to make sure the user destructor for yylval isn't
2410 yytoken_to_shift
= YYTRANSLATE (yychar
);
2413 for (yys
= 0; yys
< yystack
.yytops
.yysize
; yys
+= 1)
2416 const short int* yyconflicts
;
2417 yyStateNum yystate
= yystack
.yytops
.yystates
[yys
]->yylrState
;
2418 yygetLRActions (yystate
, yytoken_to_shift
, &yyaction
,
2420 /* Note that yyconflicts were handled by yyprocessOneStack. */
2421 YYDPRINTF ((stderr
, "On stack %lu, ", (unsigned long int) yys
));
2422 YY_SYMBOL_PRINT ("shifting", yytoken_to_shift
, &yylval
, &yylloc
);
2423 yyglrShift (&yystack
, yys
, yyaction
, yyposn
,
2424 &yylval
]b4_locations_if([, &yylloc
])[);
2425 YYDPRINTF ((stderr
, "Stack %lu now in state #%d\n",
2426 (unsigned long int) yys
,
2427 yystack
.yytops
.yystates
[yys
]->yylrState
));
2430 if (yystack
.yytops
.yysize
== 1)
2432 YYCHK1 (yyresolveStack (&yystack
]b4_user_args
[));
2433 YYDPRINTF ((stderr
, "Returning to deterministic operation.\n"));
2434 yycompressStack (&yystack
);
2440 yyrecoverSyntaxError (&yystack
]b4_user_args
[);
2441 yyposn
= yystack
.yytops
.yystates
[0]->yyposn
;
2457 yyerror (]b4_lyyerror_args
[YY_("memory exhausted"));
2462 if (yychar
!= YYEMPTY
)
2463 yydestruct ("Cleanup: discarding lookahead",
2464 YYTRANSLATE (yychar
), &yylval
]b4_locuser_args([&yylloc
])[);
2466 /* If the stack is well-formed, pop the stack until it is empty,
2467 destroying its entries as we go. But free the stack regardless
2468 of whether it is well-formed. */
2469 if (yystack
.yyitems
)
2471 yyGLRState
** yystates
= yystack
.yytops
.yystates
;
2474 size_t yysize
= yystack
.yytops
.yysize
;
2476 for (yyk
= 0; yyk
< yysize
; yyk
+= 1)
2479 while (yystates
[yyk
])
2481 yyGLRState
*yys
= yystates
[yyk
];
2482 ]b4_locations_if([[ yystack
.yyerror_range
[1].yystate
.yyloc
= yys
->yyloc
;]]
2483 )[ if (yys
->yypred
!= YY_NULL
)
2484 yydestroyGLRState ("Cleanup: popping", yys
]b4_user_args
[);
2485 yystates
[yyk
] = yys
->yypred
;
2486 yystack
.yynextFree
-= 1;
2487 yystack
.yyspaceLeft
+= 1;
2492 yyfreeGLRStack (&yystack
);
2495 /* Make sure YYID is used. */
2496 return YYID (yyresult
);
2499 /* DEBUGGING ONLY */
2500 #if ]b4_api_PREFIX[DEBUG
2501 static void yypstack (yyGLRStack
* yystackp
, size_t yyk
)
2502 __attribute__ ((__unused__
));
2503 static void yypdumpstack (yyGLRStack
* yystackp
) __attribute__ ((__unused__
));
2506 yy_yypstack (yyGLRState
* yys
)
2510 yy_yypstack (yys
->yypred
);
2511 YYFPRINTF (stderr
, " -> ");
2513 YYFPRINTF (stderr
, "%d@@%lu", yys
->yylrState
,
2514 (unsigned long int) yys
->yyposn
);
2518 yypstates (yyGLRState
* yyst
)
2520 if (yyst
== YY_NULL
)
2521 YYFPRINTF (stderr
, "<null>");
2524 YYFPRINTF (stderr
, "\n");
2528 yypstack (yyGLRStack
* yystackp
, size_t yyk
)
2530 yypstates (yystackp
->yytops
.yystates
[yyk
]);
2533 #define YYINDEX(YYX) \
2534 ((YYX) == YY_NULL ? -1 : (yyGLRStackItem*) (YYX) - yystackp->yyitems)
2538 yypdumpstack (yyGLRStack
* yystackp
)
2540 yyGLRStackItem
* yyp
;
2542 for (yyp
= yystackp
->yyitems
; yyp
< yystackp
->yynextFree
; yyp
+= 1)
2544 YYFPRINTF (stderr
, "%3lu. ",
2545 (unsigned long int) (yyp
- yystackp
->yyitems
));
2546 if (*(yybool
*) yyp
)
2548 YYFPRINTF (stderr
, "Res: %d, LR State: %d, posn: %lu, pred: %ld",
2549 yyp
->yystate
.yyresolved
, yyp
->yystate
.yylrState
,
2550 (unsigned long int) yyp
->yystate
.yyposn
,
2551 (long int) YYINDEX (yyp
->yystate
.yypred
));
2552 if (! yyp
->yystate
.yyresolved
)
2553 YYFPRINTF (stderr
, ", firstVal: %ld",
2554 (long int) YYINDEX (yyp
->yystate
2555 .yysemantics
.yyfirstVal
));
2559 YYFPRINTF (stderr
, "Option. rule: %d, state: %ld, next: %ld",
2560 yyp
->yyoption
.yyrule
- 1,
2561 (long int) YYINDEX (yyp
->yyoption
.yystate
),
2562 (long int) YYINDEX (yyp
->yyoption
.yynext
));
2564 YYFPRINTF (stderr
, "\n");
2566 YYFPRINTF (stderr
, "Tops:");
2567 for (yyi
= 0; yyi
< yystackp
->yytops
.yysize
; yyi
+= 1)
2568 YYFPRINTF (stderr
, "%lu: %ld; ", (unsigned long int) yyi
,
2569 (long int) YYINDEX (yystackp
->yytops
.yystates
[yyi
]));
2570 YYFPRINTF (stderr
, "\n");
2575 dnl glr
.cc produces its own header
.
2577 m4_if(b4_skeleton
, ["glr.c"],
2579 [@
output(b4_spec_defines_file@
)@
2580 b4_copyright([Skeleton interface
for Bison GLR parsers in C
],
2583 ]b4_cpp_guard_open([b4_spec_defines_file
])[
2584 ]b4_shared_declarations
[
2585 ]b4_cpp_guard_close([b4_spec_defines_file
])[