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 b4_output_begin([b4_parser_file_name
])
183 b4_copyright([Skeleton implementation
for Bison GLR parsers in C
],
186 /* C GLR parser skeleton written by Paul Hilfinger. */
190 b4_percent_code_get([[top]])[
191 ]m4_if(b4_api_prefix
, [yy
], [],
192 [[/* Substitute the type names. */
193 #define YYSTYPE ]b4_api_PREFIX[STYPE]b4_locations_if([[
194 #define YYLTYPE ]b4_api_PREFIX[LTYPE]])])[
195 ]m4_if(b4_prefix
, [yy
], [],
196 [[/* Substitute the variable and function names. */
197 #define yyparse ]b4_prefix[parse
198 #define yylex ]b4_prefix[lex
199 #define yyerror ]b4_prefix[error
200 #define yylval ]b4_prefix[lval
201 #define yychar ]b4_prefix[char
202 #define yydebug ]b4_prefix[debug
203 #define yynerrs ]b4_prefix[nerrs]b4_locations_if([[
204 #define yylloc ]b4_prefix[lloc]])])[
206 /* Copy the first part of user declarations. */
207 ]b4_user_pre_prologue
[
211 ]b4_defines_if([[#include "@basename(]b4_spec_defines_file[@)"]],
212 [b4_shared_declarations
])[
214 /* Enabling verbose error messages. */
215 #ifdef YYERROR_VERBOSE
216 # undef YYERROR_VERBOSE
217 # define YYERROR_VERBOSE 1
219 # define YYERROR_VERBOSE ]b4_error_verbose_flag[
222 /* Default (constant) value used for initialization for null
223 right-hand sides. Unlike the standard yacc.c template, here we set
224 the default value of $$ to a zeroed-out value. Since the default
225 value is undefined, this behavior is technically correct. */
226 static YYSTYPE yyval_default
;]b4_locations_if([[
227 static YYLTYPE yyloc_default
][]b4_yyloc_default
;])[
229 /* Copy the second part of user declarations. */
230 ]b4_user_post_prologue
231 b4_percent_code_get
[]dnl
238 # if defined YYENABLE_NLS && YYENABLE_NLS
240 # include <libintl.h> /* INFRINGES ON USER NAME SPACE */
241 # define YY_(Msgid) dgettext ("bison-runtime", Msgid)
245 # define YY_(Msgid) Msgid
249 /* Suppress unused-variable warnings by "using" E. */
250 #if ! defined lint || defined __GNUC__
251 # define YYUSE(E) ((void) (E))
253 # define YYUSE(E) /* empty */
256 /* Identity function, used to suppress warnings about constant conditions. */
260 ]b4_c_function_def([YYID
], [static int], [[int i
], [i
]])[
270 # define YYMALLOC malloc
273 # define YYREALLOC realloc
276 #define YYSIZEMAX ((size_t) -1)
281 typedef unsigned char yybool
;
288 # define YYJMP_BUF jmp_buf
289 # define YYSETJMP(Env) setjmp (Env)
291 # define YYLONGJMP(Env, Val) (longjmp (Env, Val), YYASSERT (0))
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 */
307 # define YYASSERT(Condition) ((void) ((Condition) || (abort (), 0)))
310 /* YYFINAL -- State number of the termination state. */
311 #define YYFINAL ]b4_final_state_number[
312 /* YYLAST -- Last index in YYTABLE. */
313 #define YYLAST ]b4_last[
315 /* YYNTOKENS -- Number of terminals. */
316 #define YYNTOKENS ]b4_tokens_number[
317 /* YYNNTS -- Number of nonterminals. */
318 #define YYNNTS ]b4_nterms_number[
319 /* YYNRULES -- Number of rules. */
320 #define YYNRULES ]b4_rules_number[
321 /* YYNRULES -- Number of states. */
322 #define YYNSTATES ]b4_states_number[
323 /* YYMAXRHS -- Maximum number of symbols on right-hand side of rule. */
324 #define YYMAXRHS ]b4_r2_max[
325 /* YYMAXLEFT -- Maximum number of symbols to the left of a handle
326 accessed by $0, $-1, etc., in any rule. */
327 #define YYMAXLEFT ]b4_max_left_semantic_context[
329 /* YYTRANSLATE(X) -- Bison symbol number corresponding to X. */
330 #define YYUNDEFTOK ]b4_undef_token_number[
331 #define YYMAXUTOK ]b4_user_token_number_max[
333 #define YYTRANSLATE(YYX) \
334 ((unsigned int) (YYX) <= YYMAXUTOK ? yytranslate[YYX] : YYUNDEFTOK)
336 /* YYTRANSLATE[YYLEX] -- Bison symbol number corresponding to YYLEX. */
337 static const ]b4_int_type_for([b4_translate
])[ yytranslate
[] =
342 #if ]b4_api_PREFIX[DEBUG
343 /* YYPRHS[YYN] -- Index of the first RHS symbol of rule number YYN in
345 static const ]b4_int_type_for([b4_prhs
])[ yyprhs
[] =
350 /* YYRHS -- A `-1'-separated list of the rules' RHS. */
351 static const ]b4_int_type_for([b4_rhs
])[ yyrhs
[] =
356 /* YYRLINE[YYN] -- source line where rule number YYN was defined. */
357 static const ]b4_int_type_for([b4_rline
])[ yyrline
[] =
363 #if ]b4_api_PREFIX[DEBUG || YYERROR_VERBOSE || ]b4_token_table_flag[
364 /* YYTNAME[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM.
365 First, the terminals, then, starting at YYNTOKENS, nonterminals. */
366 static const char *const yytname
[] =
372 /* YYR1[YYN] -- Symbol number of symbol that rule YYN derives. */
373 static const ]b4_int_type_for([b4_r1
])[ yyr1
[] =
378 /* YYR2[YYN] -- Number of symbols composing right hand side of rule YYN. */
379 static const ]b4_int_type_for([b4_r2
])[ yyr2
[] =
384 /* YYDPREC[RULE-NUM] -- Dynamic precedence of rule #RULE-NUM (0 if none). */
385 static const ]b4_int_type_for([b4_dprec
])[ yydprec
[] =
390 /* YYMERGER[RULE-NUM] -- Index of merging function for rule #RULE-NUM. */
391 static const ]b4_int_type_for([b4_merger
])[ yymerger
[] =
396 /* YYDEFACT[S] -- default reduction number in state S. Performed when
397 YYTABLE doesn't specify something else to do. Zero means the default
399 static const ]b4_int_type_for([b4_defact
])[ yydefact
[] =
404 /* YYPDEFGOTO[NTERM-NUM]. */
405 static const ]b4_int_type_for([b4_defgoto
])[ yydefgoto
[] =
410 /* YYPACT[STATE-NUM] -- Index in YYTABLE of the portion describing
412 #define YYPACT_NINF ]b4_pact_ninf[
413 static const ]b4_int_type_for([b4_pact
])[ yypact
[] =
418 /* YYPGOTO[NTERM-NUM]. */
419 static const ]b4_int_type_for([b4_pgoto
])[ yypgoto
[] =
424 /* YYTABLE[YYPACT[STATE-NUM]]. What to do in state STATE-NUM. If
425 positive, shift that token. If negative, reduce the rule which
426 number is the opposite. If YYTABLE_NINF, syntax error. */
427 #define YYTABLE_NINF ]b4_table_ninf[
428 static const ]b4_int_type_for([b4_table
])[ yytable
[] =
433 /* YYCONFLP[YYPACT[STATE-NUM]] -- Pointer into YYCONFL of start of
434 list of conflicting reductions corresponding to action entry for
435 state STATE-NUM in yytable. 0 means no conflicts. The list in
436 yyconfl is terminated by a rule number of 0. */
437 static const ]b4_int_type_for([b4_conflict_list_heads
])[ yyconflp
[] =
439 ]b4_conflict_list_heads
[
442 /* YYCONFL[I] -- lists of conflicting rule numbers, each terminated by
443 0, pointed into by YYCONFLP. */
444 ]dnl Do
not use b4_int_type_for here
, since there are places where
445 dnl pointers onto yyconfl are taken
, which type is
"short int *".
446 dnl We probably ought to introduce a type
for confl
.
447 [static const short int yyconfl
[] =
449 ]b4_conflicting_rules
[
452 static const ]b4_int_type_for([b4_check
])[ yycheck
[] =
457 /* YYSTOS[STATE-NUM] -- The (internal number of the) accessing
458 symbol of state STATE-NUM. */
459 static const ]b4_int_type_for([b4_stos
])[ yystos
[] =
464 /* Error token number */
468 ]b4_yylloc_default_define
[
469 # define YYRHSLOC(Rhs, K) ((Rhs)[K].yystate.yyloc)
471 ]b4_yy_location_print_define
[
473 /* YYLEX -- calling `yylex' with the right arguments. */
474 #define YYLEX ]b4_c_function_call([yylex], [int], b4_lex_param)[
479 #define yynerrs (yystackp->yyerrcnt)
481 #define yychar (yystackp->yyrawchar)
483 #define yylval (yystackp->yyval)
485 #define yylloc (yystackp->yyloc)
486 m4_if(b4_prefix
[], [yy
], [],
487 [#define b4_prefix[]nerrs yynerrs
488 #define b4_prefix[]char yychar
489 #define b4_prefix[]lval yylval
490 #define b4_prefix[]lloc yylloc])],
491 [YYSTYPE yylval
;]b4_locations_if([[
497 static const int YYEOF
= 0;
498 static const int YYEMPTY
= -2;
500 typedef enum { yyok
, yyaccept
, yyabort
, yyerr
} YYRESULTTAG
;
503 do { YYRESULTTAG yyflag = YYE; if (yyflag != yyok) return yyflag; } \
506 #if ]b4_api_PREFIX[DEBUG
509 # define YYFPRINTF fprintf
512 # define YYDPRINTF(Args) \
518 ]b4_yy_symbol_print_generate([b4_c_ansi_function_def
])[
520 # define YY_SYMBOL_PRINT(Title, Type, Value, Location) \
524 YYFPRINTF (stderr, "%s ", Title); \
525 yy_symbol_print (stderr, Type, Value]b4_locuser_args([Location])[); \
526 YYFPRINTF (stderr, "\n"); \
530 /* Nonzero means print parse trace. It is left uninitialized so that
531 multiple parsers can coexist. */
534 #else /* !]b4_api_PREFIX[DEBUG */
536 # define YYDPRINTF(Args)
537 # define YY_SYMBOL_PRINT(Title, Type, Value, Location)
539 #endif /* !]b4_api_PREFIX[DEBUG */
541 /* YYINITDEPTH -- initial size of the parser's stacks. */
543 # define YYINITDEPTH ]b4_stack_depth_init[
546 /* YYMAXDEPTH -- maximum size the stacks can grow to (effective only
547 if the built-in stack extension method is used).
549 Do not make this value too large; the results are undefined if
550 SIZE_MAX < YYMAXDEPTH * sizeof (GLRStackItem)
551 evaluated with infinite-precision integer arithmetic. */
554 # define YYMAXDEPTH ]b4_stack_depth_max[
557 /* Minimum number of free items on the stack allowed after an
558 allocation. This is to allow allocation and initialization
559 to be completed by functions that call yyexpandGLRStack before the
560 stack is expanded, thus insuring that all necessary pointers get
561 properly redirected to new data. */
564 #ifndef YYSTACKEXPANDABLE
565 # if (! defined __cplusplus \
566 || (]b4_locations_if([[defined ]b4_api_PREFIX[LTYPE_IS_TRIVIAL && ]b4_api_PREFIX[LTYPE_IS_TRIVIAL \
567 && ]])[defined ]b4_api_PREFIX[STYPE_IS_TRIVIAL && ]b4_api_PREFIX[STYPE_IS_TRIVIAL))
568 # define YYSTACKEXPANDABLE 1
570 # define YYSTACKEXPANDABLE 0
574 #if YYSTACKEXPANDABLE
575 # define YY_RESERVE_GLRSTACK(Yystack) \
577 if (Yystack->yyspaceLeft < YYHEADROOM) \
578 yyexpandGLRStack (Yystack); \
581 # define YY_RESERVE_GLRSTACK(Yystack) \
583 if (Yystack->yyspaceLeft < YYHEADROOM) \
584 yyMemoryExhausted (Yystack); \
592 # if defined __GLIBC__ && defined _STRING_H && defined _GNU_SOURCE
593 # define yystpcpy stpcpy
595 /* Copy YYSRC to YYDEST, returning the address of the terminating '\0' in
598 yystpcpy (char *yydest
, const char *yysrc
)
601 const char *yys
= yysrc
;
603 while ((*yyd
++ = *yys
++) != '\0')
612 /* Copy to YYRES the contents of YYSTR after stripping away unnecessary
613 quotes and backslashes, so that it's suitable for yyerror. The
614 heuristic is that double-quoting is unnecessary unless the string
615 contains an apostrophe, a comma, or backslash (other than
616 backslash-backslash). YYSTR is taken from yytname. If YYRES is
617 null, do not copy; instead, return the length of what the result
620 yytnamerr (char *yyres
, const char *yystr
)
625 char const *yyp
= yystr
;
632 goto do_not_strip_quotes
;
636 goto do_not_strip_quotes
;
649 do_not_strip_quotes
: ;
653 return strlen (yystr
);
655 return yystpcpy (yyres
, yystr
) - yyres
;
659 #endif /* !YYERROR_VERBOSE */
661 /** State numbers, as in LALR(1) machine */
662 typedef int yyStateNum
;
664 /** Rule numbers, as in LALR(1) machine */
665 typedef int yyRuleNum
;
667 /** Grammar symbol */
668 typedef short int yySymbol
;
670 /** Item references, as in LALR(1) machine */
671 typedef short int yyItemNum
;
673 typedef struct yyGLRState yyGLRState
;
674 typedef struct yyGLRStateSet yyGLRStateSet
;
675 typedef struct yySemanticOption yySemanticOption
;
676 typedef union yyGLRStackItem yyGLRStackItem
;
677 typedef struct yyGLRStack yyGLRStack
;
680 /** Type tag: always true. */
682 /** Type tag for yysemantics. If true, yysval applies, otherwise
683 * yyfirstVal applies. */
685 /** Number of corresponding LALR(1) machine state. */
686 yyStateNum yylrState
;
687 /** Preceding state in this stack */
689 /** Source position of the first token produced by my symbol */
692 /** First in a chain of alternative reductions producing the
693 * non-terminal corresponding to this state, threaded through
695 yySemanticOption
* yyfirstVal
;
696 /** Semantic value for this state. */
698 } yysemantics
;]b4_locations_if([[
699 /** Source location for this state. */
703 struct yyGLRStateSet
{
704 yyGLRState
** yystates
;
705 /** During nondeterministic operation, yylookaheadNeeds tracks which
706 * stacks have actually needed the current lookahead. During deterministic
707 * operation, yylookaheadNeeds[0] is not maintained since it would merely
708 * duplicate yychar != YYEMPTY. */
709 yybool
* yylookaheadNeeds
;
710 size_t yysize
, yycapacity
;
713 struct yySemanticOption
{
714 /** Type tag: always false. */
716 /** Rule number for this reduction */
718 /** The last RHS state in the list of states to be reduced. */
720 /** The lookahead for this reduction. */
722 YYSTYPE yyval
;]b4_locations_if([[
724 /** Next sibling in chain of options. To facilitate merging,
725 * options are chained in decreasing order by address. */
726 yySemanticOption
* yynext
;
729 /** Type of the items in the GLR stack. The yyisState field
730 * indicates which item of the union is valid. */
731 union yyGLRStackItem
{
733 yySemanticOption yyoption
;
738 ]b4_locations_if([[ /* To compute the location of the error token. */
739 yyGLRStackItem yyerror_range
[3];]])[
744 YYSTYPE yyval
;]b4_locations_if([[
747 YYJMP_BUF yyexception_buffer
;
748 yyGLRStackItem
* yyitems
;
749 yyGLRStackItem
* yynextFree
;
751 yyGLRState
* yysplitPoint
;
752 yyGLRState
* yylastDeleted
;
753 yyGLRStateSet yytops
;
756 #if YYSTACKEXPANDABLE
757 static void yyexpandGLRStack (yyGLRStack
* yystackp
);
760 static void yyFail (yyGLRStack
* yystackp
]b4_pure_formals
[, const char* yymsg
)
761 __attribute__ ((__noreturn__
));
763 yyFail (yyGLRStack
* yystackp
]b4_pure_formals
[, const char* yymsg
)
765 if (yymsg
!= YY_NULL
)
766 yyerror (]b4_yyerror_args
[yymsg
);
767 YYLONGJMP (yystackp
->yyexception_buffer
, 1);
770 static void yyMemoryExhausted (yyGLRStack
* yystackp
)
771 __attribute__ ((__noreturn__
));
773 yyMemoryExhausted (yyGLRStack
* yystackp
)
775 YYLONGJMP (yystackp
->yyexception_buffer
, 2);
778 #if ]b4_api_PREFIX[DEBUG || YYERROR_VERBOSE
779 /** A printable representation of TOKEN. */
780 static inline const char*
781 yytokenName (yySymbol yytoken
)
783 if (yytoken
== YYEMPTY
)
786 return yytname
[yytoken
];
790 /** Fill in YYVSP[YYLOW1 .. YYLOW0-1] from the chain of states starting
791 * at YYVSP[YYLOW0].yystate.yypred. Leaves YYVSP[YYLOW1].yystate.yypred
792 * containing the pointer to the next state in the chain. */
793 static void yyfillin (yyGLRStackItem
*, int, int) __attribute__ ((__unused__
));
795 yyfillin (yyGLRStackItem
*yyvsp
, int yylow0
, int yylow1
)
798 yyGLRState
*s
= yyvsp
[yylow0
].yystate
.yypred
;
799 for (i
= yylow0
-1; i
>= yylow1
; i
-= 1)
801 YYASSERT (s
->yyresolved
);
802 yyvsp
[i
].yystate
.yyresolved
= yytrue
;
803 yyvsp
[i
].yystate
.yysemantics
.yysval
= s
->yysemantics
.yysval
;]b4_locations_if([[
804 yyvsp
[i
].yystate
.yyloc
= s
->yyloc
;]])[
805 s
= yyvsp
[i
].yystate
.yypred
= s
->yypred
;
809 /* Do nothing if YYNORMAL or if *YYLOW <= YYLOW1. Otherwise, fill in
810 * YYVSP[YYLOW1 .. *YYLOW-1] as in yyfillin and set *YYLOW = YYLOW1.
811 * For convenience, always return YYLOW1. */
812 static inline int yyfill (yyGLRStackItem
*, int *, int, yybool
)
813 __attribute__ ((__unused__
));
815 yyfill (yyGLRStackItem
*yyvsp
, int *yylow
, int yylow1
, yybool yynormal
)
817 if (!yynormal
&& yylow1
< *yylow
)
819 yyfillin (yyvsp
, *yylow
, yylow1
);
825 /** Perform user action for rule number YYN, with RHS length YYRHSLEN,
826 * and top stack item YYVSP. YYLVALP points to place to put semantic
827 * value ($$), and yylocp points to place for location information
828 * (@@$). Returns yyok for normal return, yyaccept for YYACCEPT,
829 * yyerr for YYERROR, yyabort for YYABORT. */
830 /*ARGSUSED*/ static YYRESULTTAG
831 yyuserAction (yyRuleNum yyn
, int yyrhslen
, yyGLRStackItem
* yyvsp
,
832 yyGLRStack
* yystackp
,
833 YYSTYPE
* yyvalp
]b4_locuser_formals
[)
835 yybool yynormal
__attribute__ ((__unused__
)) =
836 (yystackp
->yysplitPoint
== YY_NULL
);
838 ]b4_parse_param_use
[]dnl
840 # define yyerrok (yystackp->yyerrState = 0)
842 # define YYACCEPT return yyaccept
844 # define YYABORT return yyabort
846 # define YYERROR return yyerrok, yyerr
848 # define YYRECOVERING() (yystackp->yyerrState != 0)
850 # define yyclearin (yychar = YYEMPTY)
852 # define YYFILL(N) yyfill (yyvsp, &yylow, N, yynormal)
854 # define YYBACKUP(Token, Value) \
855 return yyerror (]b4_yyerror_args[YY_("syntax error: cannot back up")), \
860 *yyvalp
= yyval_default
;
862 *yyvalp
= yyvsp
[YYFILL (1-yyrhslen
)].yystate
.yysemantics
.yysval
;]b4_locations_if([[
863 YYLLOC_DEFAULT ((*yylocp
), (yyvsp
- yyrhslen
), yyrhslen
);
864 yystackp
->yyerror_range
[1].yystate
.yyloc
= *yylocp
;
883 /*ARGSUSED*/ static void
884 yyuserMerge (int yyn
, YYSTYPE
* yy0
, YYSTYPE
* yy1
)
896 /* Bison grammar-table manipulation. */
898 ]b4_yydestruct_generate([b4_c_ansi_function_def
])[
900 /** Number of symbols composing the right hand side of rule #RULE. */
902 yyrhsLength (yyRuleNum yyrule
)
908 yydestroyGLRState (char const *yymsg
, yyGLRState
*yys
]b4_user_formals
[)
911 yydestruct (yymsg
, yystos
[yys
->yylrState
],
912 &yys
->yysemantics
.yysval
]b4_locuser_args([&yys
->yyloc
])[);
915 #if ]b4_api_PREFIX[DEBUG
918 if (yys
->yysemantics
.yyfirstVal
)
919 YYFPRINTF (stderr
, "%s unresolved ", yymsg
);
921 YYFPRINTF (stderr
, "%s incomplete ", yymsg
);
922 yy_symbol_print (stderr
, yystos
[yys
->yylrState
],
923 YY_NULL
]b4_locuser_args([&yys
->yyloc
])[);
924 YYFPRINTF (stderr
, "\n");
928 if (yys
->yysemantics
.yyfirstVal
)
930 yySemanticOption
*yyoption
= yys
->yysemantics
.yyfirstVal
;
933 for (yyrh
= yyoption
->yystate
, yyn
= yyrhsLength (yyoption
->yyrule
);
935 yyrh
= yyrh
->yypred
, yyn
-= 1)
936 yydestroyGLRState (yymsg
, yyrh
]b4_user_args
[);
941 /** Left-hand-side symbol for rule #RULE. */
942 static inline yySymbol
943 yylhsNonterm (yyRuleNum yyrule
)
948 #define yypact_value_is_default(Yystate) \
949 ]b4_table_value_equals([[pact]], [[Yystate]], [b4_pact_ninf])[
951 /** True iff LR state STATE has only a default reduction (regardless
954 yyisDefaultedState (yyStateNum yystate
)
956 return yypact_value_is_default (yypact
[yystate
]);
959 /** The default reduction for STATE, assuming it has one. */
960 static inline yyRuleNum
961 yydefaultAction (yyStateNum yystate
)
963 return yydefact
[yystate
];
966 #define yytable_value_is_error(Yytable_value) \
967 ]b4_table_value_equals([[table]], [[Yytable_value]], [b4_table_ninf])[
969 /** Set *YYACTION to the action to take in YYSTATE on seeing YYTOKEN.
971 * R < 0: Reduce on rule -R.
973 * R > 0: Shift to state R.
974 * Set *CONFLICTS to a pointer into yyconfl to 0-terminated list of
975 * conflicting reductions.
978 yygetLRActions (yyStateNum yystate
, int yytoken
,
979 int* yyaction
, const short int** yyconflicts
)
981 int yyindex
= yypact
[yystate
] + yytoken
;
982 if (yypact_value_is_default (yypact
[yystate
])
983 || yyindex
< 0 || YYLAST
< yyindex
|| yycheck
[yyindex
] != yytoken
)
985 *yyaction
= -yydefact
[yystate
];
986 *yyconflicts
= yyconfl
;
988 else if (! yytable_value_is_error (yytable
[yyindex
]))
990 *yyaction
= yytable
[yyindex
];
991 *yyconflicts
= yyconfl
+ yyconflp
[yyindex
];
996 *yyconflicts
= yyconfl
+ yyconflp
[yyindex
];
1000 static inline yyStateNum
1001 yyLRgotoState (yyStateNum yystate
, yySymbol yylhs
)
1004 yyr
= yypgoto
[yylhs
- YYNTOKENS
] + yystate
;
1005 if (0 <= yyr
&& yyr
<= YYLAST
&& yycheck
[yyr
] == yystate
)
1006 return yytable
[yyr
];
1008 return yydefgoto
[yylhs
- YYNTOKENS
];
1011 static inline yybool
1012 yyisShiftAction (int yyaction
)
1014 return 0 < yyaction
;
1017 static inline yybool
1018 yyisErrorAction (int yyaction
)
1020 return yyaction
== 0;
1025 /** Return a fresh GLRStackItem. Callers should call
1026 * YY_RESERVE_GLRSTACK afterwards to make sure there is sufficient
1029 static inline yyGLRStackItem
*
1030 yynewGLRStackItem (yyGLRStack
* yystackp
, yybool yyisState
)
1032 yyGLRStackItem
* yynewItem
= yystackp
->yynextFree
;
1033 yystackp
->yyspaceLeft
-= 1;
1034 yystackp
->yynextFree
+= 1;
1035 yynewItem
->yystate
.yyisState
= yyisState
;
1039 /** Add a new semantic action that will execute the action for rule
1040 * RULENUM on the semantic values in RHS to the list of
1041 * alternative actions for STATE. Assumes that RHS comes from
1042 * stack #K of *STACKP. */
1044 yyaddDeferredAction (yyGLRStack
* yystackp
, size_t yyk
, yyGLRState
* yystate
,
1045 yyGLRState
* rhs
, yyRuleNum yyrule
)
1047 yySemanticOption
* yynewOption
=
1048 &yynewGLRStackItem (yystackp
, yyfalse
)->yyoption
;
1049 yynewOption
->yystate
= rhs
;
1050 yynewOption
->yyrule
= yyrule
;
1051 if (yystackp
->yytops
.yylookaheadNeeds
[yyk
])
1053 yynewOption
->yyrawchar
= yychar
;
1054 yynewOption
->yyval
= yylval
;]b4_locations_if([
1055 yynewOption
->yyloc
= yylloc
;])[
1058 yynewOption
->yyrawchar
= YYEMPTY
;
1059 yynewOption
->yynext
= yystate
->yysemantics
.yyfirstVal
;
1060 yystate
->yysemantics
.yyfirstVal
= yynewOption
;
1062 YY_RESERVE_GLRSTACK (yystackp
);
1067 /** Initialize SET to a singleton set containing an empty stack. */
1069 yyinitStateSet (yyGLRStateSet
* yyset
)
1072 yyset
->yycapacity
= 16;
1073 yyset
->yystates
= (yyGLRState
**) YYMALLOC (16 * sizeof yyset
->yystates
[0]);
1074 if (! yyset
->yystates
)
1076 yyset
->yystates
[0] = YY_NULL
;
1077 yyset
->yylookaheadNeeds
=
1078 (yybool
*) YYMALLOC (16 * sizeof yyset
->yylookaheadNeeds
[0]);
1079 if (! yyset
->yylookaheadNeeds
)
1081 YYFREE (yyset
->yystates
);
1087 static void yyfreeStateSet (yyGLRStateSet
* yyset
)
1089 YYFREE (yyset
->yystates
);
1090 YYFREE (yyset
->yylookaheadNeeds
);
1093 /** Initialize STACK to a single empty stack, with total maximum
1094 * capacity for all stacks of SIZE. */
1096 yyinitGLRStack (yyGLRStack
* yystackp
, size_t yysize
)
1098 yystackp
->yyerrState
= 0;
1100 yystackp
->yyspaceLeft
= yysize
;
1102 (yyGLRStackItem
*) YYMALLOC (yysize
* sizeof yystackp
->yynextFree
[0]);
1103 if (!yystackp
->yyitems
)
1105 yystackp
->yynextFree
= yystackp
->yyitems
;
1106 yystackp
->yysplitPoint
= YY_NULL
;
1107 yystackp
->yylastDeleted
= YY_NULL
;
1108 return yyinitStateSet (&yystackp
->yytops
);
1112 #if YYSTACKEXPANDABLE
1113 # define YYRELOC(YYFROMITEMS,YYTOITEMS,YYX,YYTYPE) \
1114 &((YYTOITEMS) - ((YYFROMITEMS) - (yyGLRStackItem*) (YYX)))->YYTYPE
1116 /** If STACK is expandable, extend it. WARNING: Pointers into the
1117 stack from outside should be considered invalid after this call.
1118 We always expand when there are 1 or fewer items left AFTER an
1119 allocation, so that we can avoid having external pointers exist
1120 across an allocation. */
1122 yyexpandGLRStack (yyGLRStack
* yystackp
)
1124 yyGLRStackItem
* yynewItems
;
1125 yyGLRStackItem
* yyp0
, *yyp1
;
1128 size_t yysize
= yystackp
->yynextFree
- yystackp
->yyitems
;
1129 if (YYMAXDEPTH
- YYHEADROOM
< yysize
)
1130 yyMemoryExhausted (yystackp
);
1131 yynewSize
= 2*yysize
;
1132 if (YYMAXDEPTH
< yynewSize
)
1133 yynewSize
= YYMAXDEPTH
;
1134 yynewItems
= (yyGLRStackItem
*) YYMALLOC (yynewSize
* sizeof yynewItems
[0]);
1136 yyMemoryExhausted (yystackp
);
1137 for (yyp0
= yystackp
->yyitems
, yyp1
= yynewItems
, yyn
= yysize
;
1139 yyn
-= 1, yyp0
+= 1, yyp1
+= 1)
1142 if (*(yybool
*) yyp0
)
1144 yyGLRState
* yys0
= &yyp0
->yystate
;
1145 yyGLRState
* yys1
= &yyp1
->yystate
;
1146 if (yys0
->yypred
!= YY_NULL
)
1148 YYRELOC (yyp0
, yyp1
, yys0
->yypred
, yystate
);
1149 if (! yys0
->yyresolved
&& yys0
->yysemantics
.yyfirstVal
!= YY_NULL
)
1150 yys1
->yysemantics
.yyfirstVal
=
1151 YYRELOC (yyp0
, yyp1
, yys0
->yysemantics
.yyfirstVal
, yyoption
);
1155 yySemanticOption
* yyv0
= &yyp0
->yyoption
;
1156 yySemanticOption
* yyv1
= &yyp1
->yyoption
;
1157 if (yyv0
->yystate
!= YY_NULL
)
1158 yyv1
->yystate
= YYRELOC (yyp0
, yyp1
, yyv0
->yystate
, yystate
);
1159 if (yyv0
->yynext
!= YY_NULL
)
1160 yyv1
->yynext
= YYRELOC (yyp0
, yyp1
, yyv0
->yynext
, yyoption
);
1163 if (yystackp
->yysplitPoint
!= YY_NULL
)
1164 yystackp
->yysplitPoint
= YYRELOC (yystackp
->yyitems
, yynewItems
,
1165 yystackp
->yysplitPoint
, yystate
);
1167 for (yyn
= 0; yyn
< yystackp
->yytops
.yysize
; yyn
+= 1)
1168 if (yystackp
->yytops
.yystates
[yyn
] != YY_NULL
)
1169 yystackp
->yytops
.yystates
[yyn
] =
1170 YYRELOC (yystackp
->yyitems
, yynewItems
,
1171 yystackp
->yytops
.yystates
[yyn
], yystate
);
1172 YYFREE (yystackp
->yyitems
);
1173 yystackp
->yyitems
= yynewItems
;
1174 yystackp
->yynextFree
= yynewItems
+ yysize
;
1175 yystackp
->yyspaceLeft
= yynewSize
- yysize
;
1180 yyfreeGLRStack (yyGLRStack
* yystackp
)
1182 YYFREE (yystackp
->yyitems
);
1183 yyfreeStateSet (&yystackp
->yytops
);
1186 /** Assuming that S is a GLRState somewhere on STACK, update the
1187 * splitpoint of STACK, if needed, so that it is at least as deep as
1190 yyupdateSplit (yyGLRStack
* yystackp
, yyGLRState
* yys
)
1192 if (yystackp
->yysplitPoint
!= YY_NULL
&& yystackp
->yysplitPoint
> yys
)
1193 yystackp
->yysplitPoint
= yys
;
1196 /** Invalidate stack #K in STACK. */
1198 yymarkStackDeleted (yyGLRStack
* yystackp
, size_t yyk
)
1200 if (yystackp
->yytops
.yystates
[yyk
] != YY_NULL
)
1201 yystackp
->yylastDeleted
= yystackp
->yytops
.yystates
[yyk
];
1202 yystackp
->yytops
.yystates
[yyk
] = YY_NULL
;
1205 /** Undelete the last stack that was marked as deleted. Can only be
1206 done once after a deletion, and only when all other stacks have
1209 yyundeleteLastStack (yyGLRStack
* yystackp
)
1211 if (yystackp
->yylastDeleted
== YY_NULL
|| yystackp
->yytops
.yysize
!= 0)
1213 yystackp
->yytops
.yystates
[0] = yystackp
->yylastDeleted
;
1214 yystackp
->yytops
.yysize
= 1;
1215 YYDPRINTF ((stderr
, "Restoring last deleted stack as stack #0.\n"));
1216 yystackp
->yylastDeleted
= YY_NULL
;
1220 yyremoveDeletes (yyGLRStack
* yystackp
)
1224 while (yyj
< yystackp
->yytops
.yysize
)
1226 if (yystackp
->yytops
.yystates
[yyi
] == YY_NULL
)
1230 YYDPRINTF ((stderr
, "Removing dead stacks.\n"));
1232 yystackp
->yytops
.yysize
-= 1;
1236 yystackp
->yytops
.yystates
[yyj
] = yystackp
->yytops
.yystates
[yyi
];
1237 /* In the current implementation, it's unnecessary to copy
1238 yystackp->yytops.yylookaheadNeeds[yyi] since, after
1239 yyremoveDeletes returns, the parser immediately either enters
1240 deterministic operation or shifts a token. However, it doesn't
1241 hurt, and the code might evolve to need it. */
1242 yystackp
->yytops
.yylookaheadNeeds
[yyj
] =
1243 yystackp
->yytops
.yylookaheadNeeds
[yyi
];
1246 YYDPRINTF ((stderr
, "Rename stack %lu -> %lu.\n",
1247 (unsigned long int) yyi
, (unsigned long int) yyj
));
1255 /** Shift to a new state on stack #K of STACK, corresponding to LR state
1256 * LRSTATE, at input position POSN, with (resolved) semantic value SVAL. */
1258 yyglrShift (yyGLRStack
* yystackp
, size_t yyk
, yyStateNum yylrState
,
1260 YYSTYPE
* yyvalp
]b4_locations_if([, YYLTYPE
* yylocp
])[)
1262 yyGLRState
* yynewState
= &yynewGLRStackItem (yystackp
, yytrue
)->yystate
;
1264 yynewState
->yylrState
= yylrState
;
1265 yynewState
->yyposn
= yyposn
;
1266 yynewState
->yyresolved
= yytrue
;
1267 yynewState
->yypred
= yystackp
->yytops
.yystates
[yyk
];
1268 yynewState
->yysemantics
.yysval
= *yyvalp
;]b4_locations_if([
1269 yynewState
->yyloc
= *yylocp
;])[
1270 yystackp
->yytops
.yystates
[yyk
] = yynewState
;
1272 YY_RESERVE_GLRSTACK (yystackp
);
1275 /** Shift stack #K of YYSTACK, to a new state corresponding to LR
1276 * state YYLRSTATE, at input position YYPOSN, with the (unresolved)
1277 * semantic value of YYRHS under the action for YYRULE. */
1279 yyglrShiftDefer (yyGLRStack
* yystackp
, size_t yyk
, yyStateNum yylrState
,
1280 size_t yyposn
, yyGLRState
* rhs
, yyRuleNum yyrule
)
1282 yyGLRState
* yynewState
= &yynewGLRStackItem (yystackp
, yytrue
)->yystate
;
1284 yynewState
->yylrState
= yylrState
;
1285 yynewState
->yyposn
= yyposn
;
1286 yynewState
->yyresolved
= yyfalse
;
1287 yynewState
->yypred
= yystackp
->yytops
.yystates
[yyk
];
1288 yynewState
->yysemantics
.yyfirstVal
= YY_NULL
;
1289 yystackp
->yytops
.yystates
[yyk
] = yynewState
;
1291 /* Invokes YY_RESERVE_GLRSTACK. */
1292 yyaddDeferredAction (yystackp
, yyk
, yynewState
, rhs
, yyrule
);
1295 /** Pop the symbols consumed by reduction #RULE from the top of stack
1296 * #K of STACK, and perform the appropriate semantic action on their
1297 * semantic values. Assumes that all ambiguities in semantic values
1298 * have been previously resolved. Set *VALP to the resulting value,
1299 * and *LOCP to the computed location (if any). Return value is as
1300 * for userAction. */
1301 static inline YYRESULTTAG
1302 yydoAction (yyGLRStack
* yystackp
, size_t yyk
, yyRuleNum yyrule
,
1303 YYSTYPE
* yyvalp
]b4_locuser_formals
[)
1305 int yynrhs
= yyrhsLength (yyrule
);
1307 if (yystackp
->yysplitPoint
== YY_NULL
)
1309 /* Standard special case: single stack. */
1310 yyGLRStackItem
* rhs
= (yyGLRStackItem
*) yystackp
->yytops
.yystates
[yyk
];
1311 YYASSERT (yyk
== 0);
1312 yystackp
->yynextFree
-= yynrhs
;
1313 yystackp
->yyspaceLeft
+= yynrhs
;
1314 yystackp
->yytops
.yystates
[0] = & yystackp
->yynextFree
[-1].yystate
;
1315 return yyuserAction (yyrule
, yynrhs
, rhs
, yystackp
,
1316 yyvalp
]b4_locuser_args
[);
1320 /* At present, doAction is never called in nondeterministic
1321 * mode, so this branch is never taken. It is here in
1322 * anticipation of a future feature that will allow immediate
1323 * evaluation of selected actions in nondeterministic mode. */
1326 yyGLRStackItem yyrhsVals
[YYMAXRHS
+ YYMAXLEFT
+ 1];
1327 yys
= yyrhsVals
[YYMAXRHS
+ YYMAXLEFT
].yystate
.yypred
1328 = yystackp
->yytops
.yystates
[yyk
];]b4_locations_if([[
1330 /* Set default location. */
1331 yyrhsVals
[YYMAXRHS
+ YYMAXLEFT
- 1].yystate
.yyloc
= yys
->yyloc
;]])[
1332 for (yyi
= 0; yyi
< yynrhs
; yyi
+= 1)
1337 yyupdateSplit (yystackp
, yys
);
1338 yystackp
->yytops
.yystates
[yyk
] = yys
;
1339 return yyuserAction (yyrule
, yynrhs
, yyrhsVals
+ YYMAXRHS
+ YYMAXLEFT
- 1,
1340 yystackp
, yyvalp
]b4_locuser_args
[);
1344 #if !]b4_api_PREFIX[DEBUG
1345 # define YY_REDUCE_PRINT(Args)
1347 # define YY_REDUCE_PRINT(Args) \
1350 yy_reduce_print Args; \
1353 /*----------------------------------------------------------.
1354 | Report that the RULE is going to be reduced on stack #K. |
1355 `----------------------------------------------------------*/
1357 /*ARGSUSED*/ static inline void
1358 yy_reduce_print (yyGLRStack
* yystackp
, size_t yyk
, yyRuleNum yyrule
,
1359 YYSTYPE
* yyvalp
]b4_locuser_formals
[)
1361 int yynrhs
= yyrhsLength (yyrule
);
1362 yybool yynormal
__attribute__ ((__unused__
)) =
1363 (yystackp
->yysplitPoint
== YY_NULL
);
1364 yyGLRStackItem
* yyvsp
= (yyGLRStackItem
*) yystackp
->yytops
.yystates
[yyk
];
1367 YYUSE (yyvalp
);]b4_locations_if([
1369 ]b4_parse_param_use
[]dnl
1370 [ YYFPRINTF (stderr
, "Reducing stack %lu by rule %d (line %lu):\n",
1371 (unsigned long int) yyk
, yyrule
- 1,
1372 (unsigned long int) yyrline
[yyrule
]);
1373 /* The symbols being reduced. */
1374 for (yyi
= 0; yyi
< yynrhs
; yyi
++)
1376 YYFPRINTF (stderr
, " $%d = ", yyi
+ 1);
1377 yy_symbol_print (stderr
, yyrhs
[yyprhs
[yyrule
] + yyi
],
1378 &]b4_rhs_value(yynrhs
, yyi
+ 1)[
1379 ]b4_locations_if([, &]b4_rhs_location(yynrhs
, yyi
+ 1))[]dnl
1381 YYFPRINTF (stderr
, "\n");
1386 /** Pop items off stack #K of STACK according to grammar rule RULE,
1387 * and push back on the resulting nonterminal symbol. Perform the
1388 * semantic action associated with RULE and store its value with the
1389 * newly pushed state, if FORCEEVAL or if STACK is currently
1390 * unambiguous. Otherwise, store the deferred semantic action with
1391 * the new state. If the new state would have an identical input
1392 * position, LR state, and predecessor to an existing state on the stack,
1393 * it is identified with that existing state, eliminating stack #K from
1394 * the STACK. In this case, the (necessarily deferred) semantic value is
1395 * added to the options for the existing state's semantic value.
1397 static inline YYRESULTTAG
1398 yyglrReduce (yyGLRStack
* yystackp
, size_t yyk
, yyRuleNum yyrule
,
1399 yybool yyforceEval
]b4_user_formals
[)
1401 size_t yyposn
= yystackp
->yytops
.yystates
[yyk
]->yyposn
;
1403 if (yyforceEval
|| yystackp
->yysplitPoint
== YY_NULL
)
1405 YYSTYPE yysval
;]b4_locations_if([
1408 YY_REDUCE_PRINT ((yystackp
, yyk
, yyrule
, &yysval
]b4_locuser_args([&yyloc
])[));
1409 YYCHK (yydoAction (yystackp
, yyk
, yyrule
, &yysval
]b4_locuser_args([&yyloc
])[));
1410 YY_SYMBOL_PRINT ("-> $$ =", yyr1
[yyrule
], &yysval
, &yyloc
);
1411 yyglrShift (yystackp
, yyk
,
1412 yyLRgotoState (yystackp
->yytops
.yystates
[yyk
]->yylrState
,
1413 yylhsNonterm (yyrule
)),
1414 yyposn
, &yysval
]b4_locations_if([, &yyloc
])[);
1420 yyGLRState
* yys
, *yys0
= yystackp
->yytops
.yystates
[yyk
];
1421 yyStateNum yynewLRState
;
1423 for (yys
= yystackp
->yytops
.yystates
[yyk
], yyn
= yyrhsLength (yyrule
);
1429 yyupdateSplit (yystackp
, yys
);
1430 yynewLRState
= yyLRgotoState (yys
->yylrState
, yylhsNonterm (yyrule
));
1432 "Reduced stack %lu by rule #%d; action deferred. Now in state %d.\n",
1433 (unsigned long int) yyk
, yyrule
- 1, yynewLRState
));
1434 for (yyi
= 0; yyi
< yystackp
->yytops
.yysize
; yyi
+= 1)
1435 if (yyi
!= yyk
&& yystackp
->yytops
.yystates
[yyi
] != YY_NULL
)
1437 yyGLRState
*yysplit
= yystackp
->yysplitPoint
;
1438 yyGLRState
*yyp
= yystackp
->yytops
.yystates
[yyi
];
1439 while (yyp
!= yys
&& yyp
!= yysplit
&& yyp
->yyposn
>= yyposn
)
1441 if (yyp
->yylrState
== yynewLRState
&& yyp
->yypred
== yys
)
1443 yyaddDeferredAction (yystackp
, yyk
, yyp
, yys0
, yyrule
);
1444 yymarkStackDeleted (yystackp
, yyk
);
1445 YYDPRINTF ((stderr
, "Merging stack %lu into stack %lu.\n",
1446 (unsigned long int) yyk
,
1447 (unsigned long int) yyi
));
1453 yystackp
->yytops
.yystates
[yyk
] = yys
;
1454 yyglrShiftDefer (yystackp
, yyk
, yynewLRState
, yyposn
, yys0
, yyrule
);
1460 yysplitStack (yyGLRStack
* yystackp
, size_t yyk
)
1462 if (yystackp
->yysplitPoint
== YY_NULL
)
1464 YYASSERT (yyk
== 0);
1465 yystackp
->yysplitPoint
= yystackp
->yytops
.yystates
[yyk
];
1467 if (yystackp
->yytops
.yysize
>= yystackp
->yytops
.yycapacity
)
1469 yyGLRState
** yynewStates
;
1470 yybool
* yynewLookaheadNeeds
;
1472 yynewStates
= YY_NULL
;
1474 if (yystackp
->yytops
.yycapacity
1475 > (YYSIZEMAX
/ (2 * sizeof yynewStates
[0])))
1476 yyMemoryExhausted (yystackp
);
1477 yystackp
->yytops
.yycapacity
*= 2;
1480 (yyGLRState
**) YYREALLOC (yystackp
->yytops
.yystates
,
1481 (yystackp
->yytops
.yycapacity
1482 * sizeof yynewStates
[0]));
1483 if (yynewStates
== YY_NULL
)
1484 yyMemoryExhausted (yystackp
);
1485 yystackp
->yytops
.yystates
= yynewStates
;
1487 yynewLookaheadNeeds
=
1488 (yybool
*) YYREALLOC (yystackp
->yytops
.yylookaheadNeeds
,
1489 (yystackp
->yytops
.yycapacity
1490 * sizeof yynewLookaheadNeeds
[0]));
1491 if (yynewLookaheadNeeds
== YY_NULL
)
1492 yyMemoryExhausted (yystackp
);
1493 yystackp
->yytops
.yylookaheadNeeds
= yynewLookaheadNeeds
;
1495 yystackp
->yytops
.yystates
[yystackp
->yytops
.yysize
]
1496 = yystackp
->yytops
.yystates
[yyk
];
1497 yystackp
->yytops
.yylookaheadNeeds
[yystackp
->yytops
.yysize
]
1498 = yystackp
->yytops
.yylookaheadNeeds
[yyk
];
1499 yystackp
->yytops
.yysize
+= 1;
1500 return yystackp
->yytops
.yysize
-1;
1503 /** True iff Y0 and Y1 represent identical options at the top level.
1504 * That is, they represent the same rule applied to RHS symbols
1505 * that produce the same terminal symbols. */
1507 yyidenticalOptions (yySemanticOption
* yyy0
, yySemanticOption
* yyy1
)
1509 if (yyy0
->yyrule
== yyy1
->yyrule
)
1511 yyGLRState
*yys0
, *yys1
;
1513 for (yys0
= yyy0
->yystate
, yys1
= yyy1
->yystate
,
1514 yyn
= yyrhsLength (yyy0
->yyrule
);
1516 yys0
= yys0
->yypred
, yys1
= yys1
->yypred
, yyn
-= 1)
1517 if (yys0
->yyposn
!= yys1
->yyposn
)
1525 /** Assuming identicalOptions (Y0,Y1), destructively merge the
1526 * alternative semantic values for the RHS-symbols of Y1 and Y0. */
1528 yymergeOptionSets (yySemanticOption
* yyy0
, yySemanticOption
* yyy1
)
1530 yyGLRState
*yys0
, *yys1
;
1532 for (yys0
= yyy0
->yystate
, yys1
= yyy1
->yystate
,
1533 yyn
= yyrhsLength (yyy0
->yyrule
);
1535 yys0
= yys0
->yypred
, yys1
= yys1
->yypred
, yyn
-= 1)
1539 else if (yys0
->yyresolved
)
1541 yys1
->yyresolved
= yytrue
;
1542 yys1
->yysemantics
.yysval
= yys0
->yysemantics
.yysval
;
1544 else if (yys1
->yyresolved
)
1546 yys0
->yyresolved
= yytrue
;
1547 yys0
->yysemantics
.yysval
= yys1
->yysemantics
.yysval
;
1551 yySemanticOption
** yyz0p
= &yys0
->yysemantics
.yyfirstVal
;
1552 yySemanticOption
* yyz1
= yys1
->yysemantics
.yyfirstVal
;
1553 while (YYID (yytrue
))
1555 if (yyz1
== *yyz0p
|| yyz1
== YY_NULL
)
1557 else if (*yyz0p
== YY_NULL
)
1562 else if (*yyz0p
< yyz1
)
1564 yySemanticOption
* yyz
= *yyz0p
;
1566 yyz1
= yyz1
->yynext
;
1567 (*yyz0p
)->yynext
= yyz
;
1569 yyz0p
= &(*yyz0p
)->yynext
;
1571 yys1
->yysemantics
.yyfirstVal
= yys0
->yysemantics
.yyfirstVal
;
1576 /** Y0 and Y1 represent two possible actions to take in a given
1577 * parsing state; return 0 if no combination is possible,
1578 * 1 if user-mergeable, 2 if Y0 is preferred, 3 if Y1 is preferred. */
1580 yypreference (yySemanticOption
* y0
, yySemanticOption
* y1
)
1582 yyRuleNum r0
= y0
->yyrule
, r1
= y1
->yyrule
;
1583 int p0
= yydprec
[r0
], p1
= yydprec
[r1
];
1587 if (yymerger
[r0
] == 0 || yymerger
[r0
] != yymerger
[r1
])
1592 if (p0
== 0 || p1
== 0)
1601 static YYRESULTTAG
yyresolveValue (yyGLRState
* yys
,
1602 yyGLRStack
* yystackp
]b4_user_formals
[);
1605 /** Resolve the previous N states starting at and including state S. If result
1606 * != yyok, some states may have been left unresolved possibly with empty
1607 * semantic option chains. Regardless of whether result = yyok, each state
1608 * has been left with consistent data so that yydestroyGLRState can be invoked
1611 yyresolveStates (yyGLRState
* yys
, int yyn
,
1612 yyGLRStack
* yystackp
]b4_user_formals
[)
1616 YYASSERT (yys
->yypred
);
1617 YYCHK (yyresolveStates (yys
->yypred
, yyn
-1, yystackp
]b4_user_args
[));
1618 if (! yys
->yyresolved
)
1619 YYCHK (yyresolveValue (yys
, yystackp
]b4_user_args
[));
1624 /** Resolve the states for the RHS of OPT, perform its user action, and return
1625 * the semantic value and location. Regardless of whether result = yyok, all
1626 * RHS states have been destroyed (assuming the user action destroys all RHS
1627 * semantic values if invoked). */
1629 yyresolveAction (yySemanticOption
* yyopt
, yyGLRStack
* yystackp
,
1630 YYSTYPE
* yyvalp
]b4_locuser_formals
[)
1632 yyGLRStackItem yyrhsVals
[YYMAXRHS
+ YYMAXLEFT
+ 1];
1633 int yynrhs
= yyrhsLength (yyopt
->yyrule
);
1634 YYRESULTTAG yyflag
=
1635 yyresolveStates (yyopt
->yystate
, yynrhs
, yystackp
]b4_user_args
[);
1639 for (yys
= yyopt
->yystate
; yynrhs
> 0; yys
= yys
->yypred
, yynrhs
-= 1)
1640 yydestroyGLRState ("Cleanup: popping", yys
]b4_user_args
[);
1644 yyrhsVals
[YYMAXRHS
+ YYMAXLEFT
].yystate
.yypred
= yyopt
->yystate
;]b4_locations_if([[
1646 /* Set default location. */
1647 yyrhsVals
[YYMAXRHS
+ YYMAXLEFT
- 1].yystate
.yyloc
= yyopt
->yystate
->yyloc
;]])[
1649 int yychar_current
= yychar
;
1650 YYSTYPE yylval_current
= yylval
;]b4_locations_if([
1651 YYLTYPE yylloc_current
= yylloc
;])[
1652 yychar
= yyopt
->yyrawchar
;
1653 yylval
= yyopt
->yyval
;]b4_locations_if([
1654 yylloc
= yyopt
->yyloc
;])[
1655 yyflag
= yyuserAction (yyopt
->yyrule
, yynrhs
,
1656 yyrhsVals
+ YYMAXRHS
+ YYMAXLEFT
- 1,
1657 yystackp
, yyvalp
]b4_locuser_args
[);
1658 yychar
= yychar_current
;
1659 yylval
= yylval_current
;]b4_locations_if([
1660 yylloc
= yylloc_current
;])[
1665 #if ]b4_api_PREFIX[DEBUG
1667 yyreportTree (yySemanticOption
* yyx
, int yyindent
)
1669 int yynrhs
= yyrhsLength (yyx
->yyrule
);
1672 yyGLRState
* yystates
[1 + YYMAXRHS
];
1673 yyGLRState yyleftmost_state
;
1675 for (yyi
= yynrhs
, yys
= yyx
->yystate
; 0 < yyi
; yyi
-= 1, yys
= yys
->yypred
)
1676 yystates
[yyi
] = yys
;
1679 yyleftmost_state
.yyposn
= 0;
1680 yystates
[0] = &yyleftmost_state
;
1685 if (yyx
->yystate
->yyposn
< yys
->yyposn
+ 1)
1686 YYFPRINTF (stderr
, "%*s%s -> <Rule %d, empty>\n",
1687 yyindent
, "", yytokenName (yylhsNonterm (yyx
->yyrule
)),
1690 YYFPRINTF (stderr
, "%*s%s -> <Rule %d, tokens %lu .. %lu>\n",
1691 yyindent
, "", yytokenName (yylhsNonterm (yyx
->yyrule
)),
1692 yyx
->yyrule
- 1, (unsigned long int) (yys
->yyposn
+ 1),
1693 (unsigned long int) yyx
->yystate
->yyposn
);
1694 for (yyi
= 1; yyi
<= yynrhs
; yyi
+= 1)
1696 if (yystates
[yyi
]->yyresolved
)
1698 if (yystates
[yyi
-1]->yyposn
+1 > yystates
[yyi
]->yyposn
)
1699 YYFPRINTF (stderr
, "%*s%s <empty>\n", yyindent
+2, "",
1700 yytokenName (yyrhs
[yyprhs
[yyx
->yyrule
]+yyi
-1]));
1702 YYFPRINTF (stderr
, "%*s%s <tokens %lu .. %lu>\n", yyindent
+2, "",
1703 yytokenName (yyrhs
[yyprhs
[yyx
->yyrule
]+yyi
-1]),
1704 (unsigned long int) (yystates
[yyi
- 1]->yyposn
+ 1),
1705 (unsigned long int) yystates
[yyi
]->yyposn
);
1708 yyreportTree (yystates
[yyi
]->yysemantics
.yyfirstVal
, yyindent
+2);
1713 /*ARGSUSED*/ static YYRESULTTAG
1714 yyreportAmbiguity (yySemanticOption
* yyx0
,
1715 yySemanticOption
* yyx1
]b4_pure_formals
[)
1720 #if ]b4_api_PREFIX[DEBUG
1721 YYFPRINTF (stderr
, "Ambiguity detected.\n");
1722 YYFPRINTF (stderr
, "Option 1,\n");
1723 yyreportTree (yyx0
, 2);
1724 YYFPRINTF (stderr
, "\nOption 2,\n");
1725 yyreportTree (yyx1
, 2);
1726 YYFPRINTF (stderr
, "\n");
1729 yyerror (]b4_yyerror_args
[YY_("syntax is ambiguous"));
1731 }]b4_locations_if([[
1733 /** Starting at and including state S1, resolve the location for each of the
1734 * previous N1 states that is unresolved. The first semantic option of a state
1735 * is always chosen. */
1737 yyresolveLocations (yyGLRState
* yys1
, int yyn1
,
1738 yyGLRStack
*yystackp
]b4_user_formals
[)
1742 yyresolveLocations (yys1
->yypred
, yyn1
- 1, yystackp
]b4_user_args
[);
1743 if (!yys1
->yyresolved
)
1745 yyGLRStackItem yyrhsloc
[1 + YYMAXRHS
];
1747 yySemanticOption
*yyoption
= yys1
->yysemantics
.yyfirstVal
;
1748 YYASSERT (yyoption
!= YY_NULL
);
1749 yynrhs
= yyrhsLength (yyoption
->yyrule
);
1754 yyresolveLocations (yyoption
->yystate
, yynrhs
,
1755 yystackp
]b4_user_args
[);
1756 for (yys
= yyoption
->yystate
, yyn
= yynrhs
;
1758 yys
= yys
->yypred
, yyn
-= 1)
1759 yyrhsloc
[yyn
].yystate
.yyloc
= yys
->yyloc
;
1763 /* Both yyresolveAction and yyresolveLocations traverse the GSS
1764 in reverse rightmost order. It is only necessary to invoke
1765 yyresolveLocations on a subforest for which yyresolveAction
1766 would have been invoked next had an ambiguity not been
1767 detected. Thus the location of the previous state (but not
1768 necessarily the previous state itself) is guaranteed to be
1769 resolved already. */
1770 yyGLRState
*yyprevious
= yyoption
->yystate
;
1771 yyrhsloc
[0].yystate
.yyloc
= yyprevious
->yyloc
;
1774 int yychar_current
= yychar
;
1775 YYSTYPE yylval_current
= yylval
;
1776 YYLTYPE yylloc_current
= yylloc
;
1777 yychar
= yyoption
->yyrawchar
;
1778 yylval
= yyoption
->yyval
;
1779 yylloc
= yyoption
->yyloc
;
1780 YYLLOC_DEFAULT ((yys1
->yyloc
), yyrhsloc
, yynrhs
);
1781 yychar
= yychar_current
;
1782 yylval
= yylval_current
;
1783 yylloc
= yylloc_current
;
1789 /** Resolve the ambiguity represented in state S, perform the indicated
1790 * actions, and set the semantic value of S. If result != yyok, the chain of
1791 * semantic options in S has been cleared instead or it has been left
1792 * unmodified except that redundant options may have been removed. Regardless
1793 * of whether result = yyok, S has been left with consistent data so that
1794 * yydestroyGLRState can be invoked if necessary. */
1796 yyresolveValue (yyGLRState
* yys
, yyGLRStack
* yystackp
]b4_user_formals
[)
1798 yySemanticOption
* yyoptionList
= yys
->yysemantics
.yyfirstVal
;
1799 yySemanticOption
* yybest
= yyoptionList
;
1800 yySemanticOption
** yypp
;
1801 yybool yymerge
= yyfalse
;
1803 YYRESULTTAG yyflag
;]b4_locations_if([
1804 YYLTYPE
*yylocp
= &yys
->yyloc
;])[
1806 for (yypp
= &yyoptionList
->yynext
; *yypp
!= YY_NULL
; )
1808 yySemanticOption
* yyp
= *yypp
;
1810 if (yyidenticalOptions (yybest
, yyp
))
1812 yymergeOptionSets (yybest
, yyp
);
1813 *yypp
= yyp
->yynext
;
1817 switch (yypreference (yybest
, yyp
))
1819 case 0:]b4_locations_if([[
1820 yyresolveLocations (yys
, 1, yystackp
]b4_user_args
[);]])[
1821 return yyreportAmbiguity (yybest
, yyp
]b4_pure_args
[);
1833 /* This cannot happen so it is not worth a YYASSERT (yyfalse),
1834 but some compilers complain if the default case is
1838 yypp
= &yyp
->yynext
;
1844 yySemanticOption
* yyp
;
1845 int yyprec
= yydprec
[yybest
->yyrule
];
1846 yyflag
= yyresolveAction (yybest
, yystackp
, &yysval
]b4_locuser_args
[);
1848 for (yyp
= yybest
->yynext
; yyp
!= YY_NULL
; yyp
= yyp
->yynext
)
1850 if (yyprec
== yydprec
[yyp
->yyrule
])
1852 YYSTYPE yysval_other
;]b4_locations_if([
1854 yyflag
= yyresolveAction (yyp
, yystackp
, &yysval_other
]b4_locuser_args([&yydummy
])[);
1857 yydestruct ("Cleanup: discarding incompletely merged value for",
1858 yystos
[yys
->yylrState
],
1859 &yysval
]b4_locuser_args
[);
1862 yyuserMerge (yymerger
[yyp
->yyrule
], &yysval
, &yysval_other
);
1867 yyflag
= yyresolveAction (yybest
, yystackp
, &yysval
]b4_locuser_args([yylocp
])[);
1871 yys
->yyresolved
= yytrue
;
1872 yys
->yysemantics
.yysval
= yysval
;
1875 yys
->yysemantics
.yyfirstVal
= YY_NULL
;
1880 yyresolveStack (yyGLRStack
* yystackp
]b4_user_formals
[)
1882 if (yystackp
->yysplitPoint
!= YY_NULL
)
1887 for (yyn
= 0, yys
= yystackp
->yytops
.yystates
[0];
1888 yys
!= yystackp
->yysplitPoint
;
1889 yys
= yys
->yypred
, yyn
+= 1)
1891 YYCHK (yyresolveStates (yystackp
->yytops
.yystates
[0], yyn
, yystackp
1898 yycompressStack (yyGLRStack
* yystackp
)
1900 yyGLRState
* yyp
, *yyq
, *yyr
;
1902 if (yystackp
->yytops
.yysize
!= 1 || yystackp
->yysplitPoint
== YY_NULL
)
1905 for (yyp
= yystackp
->yytops
.yystates
[0], yyq
= yyp
->yypred
, yyr
= YY_NULL
;
1906 yyp
!= yystackp
->yysplitPoint
;
1907 yyr
= yyp
, yyp
= yyq
, yyq
= yyp
->yypred
)
1910 yystackp
->yyspaceLeft
+= yystackp
->yynextFree
- yystackp
->yyitems
;
1911 yystackp
->yynextFree
= ((yyGLRStackItem
*) yystackp
->yysplitPoint
) + 1;
1912 yystackp
->yyspaceLeft
-= yystackp
->yynextFree
- yystackp
->yyitems
;
1913 yystackp
->yysplitPoint
= YY_NULL
;
1914 yystackp
->yylastDeleted
= YY_NULL
;
1916 while (yyr
!= YY_NULL
)
1918 yystackp
->yynextFree
->yystate
= *yyr
;
1920 yystackp
->yynextFree
->yystate
.yypred
= &yystackp
->yynextFree
[-1].yystate
;
1921 yystackp
->yytops
.yystates
[0] = &yystackp
->yynextFree
->yystate
;
1922 yystackp
->yynextFree
+= 1;
1923 yystackp
->yyspaceLeft
-= 1;
1928 yyprocessOneStack (yyGLRStack
* yystackp
, size_t yyk
,
1929 size_t yyposn
]b4_pure_formals
[)
1932 const short int* yyconflicts
;
1935 while (yystackp
->yytops
.yystates
[yyk
] != YY_NULL
)
1937 yyStateNum yystate
= yystackp
->yytops
.yystates
[yyk
]->yylrState
;
1938 YYDPRINTF ((stderr
, "Stack %lu Entering state %d\n",
1939 (unsigned long int) yyk
, yystate
));
1941 YYASSERT (yystate
!= YYFINAL
);
1943 if (yyisDefaultedState (yystate
))
1945 yyrule
= yydefaultAction (yystate
);
1948 YYDPRINTF ((stderr
, "Stack %lu dies.\n",
1949 (unsigned long int) yyk
));
1950 yymarkStackDeleted (yystackp
, yyk
);
1953 YYCHK (yyglrReduce (yystackp
, yyk
, yyrule
, yyfalse
]b4_user_args
[));
1958 yystackp
->yytops
.yylookaheadNeeds
[yyk
] = yytrue
;
1959 if (yychar
== YYEMPTY
)
1961 YYDPRINTF ((stderr
, "Reading a token: "));
1965 if (yychar
<= YYEOF
)
1967 yychar
= yytoken
= YYEOF
;
1968 YYDPRINTF ((stderr
, "Now at end of input.\n"));
1972 yytoken
= YYTRANSLATE (yychar
);
1973 YY_SYMBOL_PRINT ("Next token is", yytoken
, &yylval
, &yylloc
);
1976 yygetLRActions (yystate
, yytoken
, &yyaction
, &yyconflicts
);
1978 while (*yyconflicts
!= 0)
1980 size_t yynewStack
= yysplitStack (yystackp
, yyk
);
1981 YYDPRINTF ((stderr
, "Splitting off stack %lu from %lu.\n",
1982 (unsigned long int) yynewStack
,
1983 (unsigned long int) yyk
));
1984 YYCHK (yyglrReduce (yystackp
, yynewStack
,
1985 *yyconflicts
, yyfalse
]b4_user_args
[));
1986 YYCHK (yyprocessOneStack (yystackp
, yynewStack
,
1987 yyposn
]b4_pure_args
[));
1991 if (yyisShiftAction (yyaction
))
1993 else if (yyisErrorAction (yyaction
))
1995 YYDPRINTF ((stderr
, "Stack %lu dies.\n",
1996 (unsigned long int) yyk
));
1997 yymarkStackDeleted (yystackp
, yyk
);
2001 YYCHK (yyglrReduce (yystackp
, yyk
, -yyaction
,
2002 yyfalse
]b4_user_args
[));
2008 /*ARGSUSED*/ static void
2009 yyreportSyntaxError (yyGLRStack
* yystackp
]b4_user_formals
[)
2011 if (yystackp
->yyerrState
!= 0)
2013 #if ! YYERROR_VERBOSE
2014 yyerror (]b4_lyyerror_args
[YY_("syntax error"));
2017 yySymbol yytoken
= yychar
== YYEMPTY
? YYEMPTY
: YYTRANSLATE (yychar
);
2018 size_t yysize0
= yytnamerr (YY_NULL
, yytokenName (yytoken
));
2019 size_t yysize
= yysize0
;
2020 yybool yysize_overflow
= yyfalse
;
2021 char* yymsg
= YY_NULL
;
2022 enum { YYERROR_VERBOSE_ARGS_MAXIMUM
= 5 };
2023 /* Internationalized format string. */
2024 const char *yyformat
= YY_NULL
;
2025 /* Arguments of yyformat. */
2026 char const *yyarg
[YYERROR_VERBOSE_ARGS_MAXIMUM
];
2027 /* Number of reported tokens (one for the "unexpected", one per
2031 /* There are many possibilities here to consider:
2032 - If this state is a consistent state with a default action, then
2033 the only way this function was invoked is if the default action
2034 is an error action. In that case, don't check for expected
2035 tokens because there are none.
2036 - The only way there can be no lookahead present (in yychar) is if
2037 this state is a consistent state with a default action. Thus,
2038 detecting the absence of a lookahead is sufficient to determine
2039 that there is no unexpected or expected token to report. In that
2040 case, just report a simple "syntax error".
2041 - Don't assume there isn't a lookahead just because this state is a
2042 consistent state with a default action. There might have been a
2043 previous inconsistent state, consistent state with a non-default
2044 action, or user semantic action that manipulated yychar.
2045 - Of course, the expected token list depends on states to have
2046 correct lookahead information, and it depends on the parser not
2047 to perform extra reductions after fetching a lookahead from the
2048 scanner and before detecting a syntax error. Thus, state merging
2049 (from LALR or IELR) and default reductions corrupt the expected
2050 token list. However, the list is correct for canonical LR with
2051 one exception: it will still contain any token that will not be
2052 accepted due to an error action in a later state.
2054 if (yytoken
!= YYEMPTY
)
2056 int yyn
= yypact
[yystackp
->yytops
.yystates
[0]->yylrState
];
2057 yyarg
[yycount
++] = yytokenName (yytoken
);
2058 if (!yypact_value_is_default (yyn
))
2060 /* Start YYX at -YYN if negative to avoid negative indexes in
2061 YYCHECK. In other words, skip the first -YYN actions for this
2062 state because they are default actions. */
2063 int yyxbegin
= yyn
< 0 ? -yyn
: 0;
2064 /* Stay within bounds of both yycheck and yytname. */
2065 int yychecklim
= YYLAST
- yyn
+ 1;
2066 int yyxend
= yychecklim
< YYNTOKENS
? yychecklim
: YYNTOKENS
;
2068 for (yyx
= yyxbegin
; yyx
< yyxend
; ++yyx
)
2069 if (yycheck
[yyx
+ yyn
] == yyx
&& yyx
!= YYTERROR
2070 && !yytable_value_is_error (yytable
[yyx
+ yyn
]))
2072 if (yycount
== YYERROR_VERBOSE_ARGS_MAXIMUM
)
2078 yyarg
[yycount
++] = yytokenName (yyx
);
2080 size_t yysz
= yysize
+ yytnamerr (YY_NULL
, yytokenName (yyx
));
2081 yysize_overflow
|= yysz
< yysize
;
2090 #define YYCASE_(N, S) \
2094 YYCASE_(0, YY_("syntax error"));
2095 YYCASE_(1, YY_("syntax error, unexpected %s"));
2096 YYCASE_(2, YY_("syntax error, unexpected %s, expecting %s"));
2097 YYCASE_(3, YY_("syntax error, unexpected %s, expecting %s or %s"));
2098 YYCASE_(4, YY_("syntax error, unexpected %s, expecting %s or %s or %s"));
2099 YYCASE_(5, YY_("syntax error, unexpected %s, expecting %s or %s or %s or %s"));
2104 size_t yysz
= yysize
+ strlen (yyformat
);
2105 yysize_overflow
|= yysz
< yysize
;
2109 if (!yysize_overflow
)
2110 yymsg
= (char *) YYMALLOC (yysize
);
2116 while ((*yyp
= *yyformat
))
2118 if (*yyp
== '%' && yyformat
[1] == 's' && yyi
< yycount
)
2120 yyp
+= yytnamerr (yyp
, yyarg
[yyi
++]);
2129 yyerror (]b4_lyyerror_args
[yymsg
);
2134 yyerror (]b4_lyyerror_args
[YY_("syntax error"));
2135 yyMemoryExhausted (yystackp
);
2138 #endif /* YYERROR_VERBOSE */
2142 /* Recover from a syntax error on *YYSTACKP, assuming that *YYSTACKP->YYTOKENP,
2143 yylval, and yylloc are the syntactic category, semantic value, and location
2144 of the lookahead. */
2145 /*ARGSUSED*/ static void
2146 yyrecoverSyntaxError (yyGLRStack
* yystackp
]b4_user_formals
[)
2151 if (yystackp
->yyerrState
== 3)
2152 /* We just shifted the error token and (perhaps) took some
2153 reductions. Skip tokens until we can proceed. */
2154 while (YYID (yytrue
))
2157 if (yychar
== YYEOF
)
2158 yyFail (yystackp
][]b4_lpure_args
[, YY_NULL
);
2159 if (yychar
!= YYEMPTY
)
2160 {]b4_locations_if([[
2161 /* We throw away the lookahead, but the error range
2162 of the shifted error token must take it into account. */
2163 yyGLRState
*yys
= yystackp
->yytops
.yystates
[0];
2164 yyGLRStackItem yyerror_range
[3];
2165 yyerror_range
[1].yystate
.yyloc
= yys
->yyloc
;
2166 yyerror_range
[2].yystate
.yyloc
= yylloc
;
2167 YYLLOC_DEFAULT ((yys
->yyloc
), yyerror_range
, 2);]])[
2168 yytoken
= YYTRANSLATE (yychar
);
2169 yydestruct ("Error: discarding",
2170 yytoken
, &yylval
]b4_locuser_args([&yylloc
])[);
2172 YYDPRINTF ((stderr
, "Reading a token: "));
2174 if (yychar
<= YYEOF
)
2176 yychar
= yytoken
= YYEOF
;
2177 YYDPRINTF ((stderr
, "Now at end of input.\n"));
2181 yytoken
= YYTRANSLATE (yychar
);
2182 YY_SYMBOL_PRINT ("Next token is", yytoken
, &yylval
, &yylloc
);
2184 yyj
= yypact
[yystackp
->yytops
.yystates
[0]->yylrState
];
2185 if (yypact_value_is_default (yyj
))
2188 if (yyj
< 0 || YYLAST
< yyj
|| yycheck
[yyj
] != yytoken
)
2190 if (yydefact
[yystackp
->yytops
.yystates
[0]->yylrState
] != 0)
2193 else if (! yytable_value_is_error (yytable
[yyj
]))
2197 /* Reduce to one stack. */
2198 for (yyk
= 0; yyk
< yystackp
->yytops
.yysize
; yyk
+= 1)
2199 if (yystackp
->yytops
.yystates
[yyk
] != YY_NULL
)
2201 if (yyk
>= yystackp
->yytops
.yysize
)
2202 yyFail (yystackp
][]b4_lpure_args
[, YY_NULL
);
2203 for (yyk
+= 1; yyk
< yystackp
->yytops
.yysize
; yyk
+= 1)
2204 yymarkStackDeleted (yystackp
, yyk
);
2205 yyremoveDeletes (yystackp
);
2206 yycompressStack (yystackp
);
2208 /* Now pop stack until we find a state that shifts the error token. */
2209 yystackp
->yyerrState
= 3;
2210 while (yystackp
->yytops
.yystates
[0] != YY_NULL
)
2212 yyGLRState
*yys
= yystackp
->yytops
.yystates
[0];
2213 yyj
= yypact
[yys
->yylrState
];
2214 if (! yypact_value_is_default (yyj
))
2217 if (0 <= yyj
&& yyj
<= YYLAST
&& yycheck
[yyj
] == YYTERROR
2218 && yyisShiftAction (yytable
[yyj
]))
2220 /* Shift the error token. */]b4_locations_if([[
2221 /* First adjust its location.*/
2223 yystackp
->yyerror_range
[2].yystate
.yyloc
= yylloc
;
2224 YYLLOC_DEFAULT (yyerrloc
, (yystackp
->yyerror_range
), 2);]])[
2225 YY_SYMBOL_PRINT ("Shifting", yystos
[yytable
[yyj
]],
2226 &yylval
, &yyerrloc
);
2227 yyglrShift (yystackp
, 0, yytable
[yyj
],
2228 yys
->yyposn
, &yylval
]b4_locations_if([, &yyerrloc
])[);
2229 yys
= yystackp
->yytops
.yystates
[0];
2232 }]b4_locations_if([[
2233 yystackp
->yyerror_range
[1].yystate
.yyloc
= yys
->yyloc
;]])[
2234 if (yys
->yypred
!= YY_NULL
)
2235 yydestroyGLRState ("Error: popping", yys
]b4_user_args
[);
2236 yystackp
->yytops
.yystates
[0] = yys
->yypred
;
2237 yystackp
->yynextFree
-= 1;
2238 yystackp
->yyspaceLeft
+= 1;
2240 if (yystackp
->yytops
.yystates
[0] == YY_NULL
)
2241 yyFail (yystackp
][]b4_lpure_args
[, YY_NULL
);
2244 #define YYCHK1(YYE) \
2254 goto yyuser_error; \
2265 ]b4_c_ansi_function_def([yyparse
], [int], b4_parse_param
)[
2269 yyGLRStack
* const yystackp
= &yystack
;
2272 YYDPRINTF ((stderr
, "Starting parse\n"));
2275 yylval
= yyval_default
;]b4_locations_if([
2276 yylloc
= yyloc_default
;])[
2277 ]m4_ifdef([b4_initial_action
], [
2278 b4_dollar_pushdef([yylval
], [], [yylloc
])dnl
2279 /* User initialization code. */
2280 b4_user_initial_action
2281 b4_dollar_popdef
])[]dnl
2283 if (! yyinitGLRStack (yystackp
, YYINITDEPTH
))
2284 goto yyexhaustedlab
;
2285 switch (YYSETJMP (yystack
.yyexception_buffer
))
2288 case 1: goto yyabortlab
;
2289 case 2: goto yyexhaustedlab
;
2290 default: goto yybuglab
;
2292 yyglrShift (&yystack
, 0, 0, 0, &yylval
]b4_locations_if([, &yylloc
])[);
2295 while (YYID (yytrue
))
2297 /* For efficiency, we have two loops, the first of which is
2298 specialized to deterministic operation (single stack, no
2299 potential ambiguity). */
2301 while (YYID (yytrue
))
2305 const short int* yyconflicts
;
2307 yyStateNum yystate
= yystack
.yytops
.yystates
[0]->yylrState
;
2308 YYDPRINTF ((stderr
, "Entering state %d\n", yystate
));
2309 if (yystate
== YYFINAL
)
2311 if (yyisDefaultedState (yystate
))
2313 yyrule
= yydefaultAction (yystate
);
2316 ]b4_locations_if([[ yystack
.yyerror_range
[1].yystate
.yyloc
= yylloc
;]])[
2317 yyreportSyntaxError (&yystack
]b4_user_args
[);
2320 YYCHK1 (yyglrReduce (&yystack
, 0, yyrule
, yytrue
]b4_user_args
[));
2325 if (yychar
== YYEMPTY
)
2327 YYDPRINTF ((stderr
, "Reading a token: "));
2331 if (yychar
<= YYEOF
)
2333 yychar
= yytoken
= YYEOF
;
2334 YYDPRINTF ((stderr
, "Now at end of input.\n"));
2338 yytoken
= YYTRANSLATE (yychar
);
2339 YY_SYMBOL_PRINT ("Next token is", yytoken
, &yylval
, &yylloc
);
2342 yygetLRActions (yystate
, yytoken
, &yyaction
, &yyconflicts
);
2343 if (*yyconflicts
!= 0)
2345 if (yyisShiftAction (yyaction
))
2347 YY_SYMBOL_PRINT ("Shifting", yytoken
, &yylval
, &yylloc
);
2350 yyglrShift (&yystack
, 0, yyaction
, yyposn
, &yylval
]b4_locations_if([, &yylloc
])[);
2351 if (0 < yystack
.yyerrState
)
2352 yystack
.yyerrState
-= 1;
2354 else if (yyisErrorAction (yyaction
))
2356 ]b4_locations_if([[ yystack
.yyerror_range
[1].yystate
.yyloc
= yylloc
;]])[
2357 yyreportSyntaxError (&yystack
]b4_user_args
[);
2361 YYCHK1 (yyglrReduce (&yystack
, 0, -yyaction
, yytrue
]b4_user_args
[));
2365 while (YYID (yytrue
))
2367 yySymbol yytoken_to_shift
;
2370 for (yys
= 0; yys
< yystack
.yytops
.yysize
; yys
+= 1)
2371 yystackp
->yytops
.yylookaheadNeeds
[yys
] = yychar
!= YYEMPTY
;
2373 /* yyprocessOneStack returns one of three things:
2375 - An error flag. If the caller is yyprocessOneStack, it
2376 immediately returns as well. When the caller is finally
2377 yyparse, it jumps to an error label via YYCHK1.
2379 - yyok, but yyprocessOneStack has invoked yymarkStackDeleted
2380 (&yystack, yys), which sets the top state of yys to NULL. Thus,
2381 yyparse's following invocation of yyremoveDeletes will remove
2384 - yyok, when ready to shift a token.
2386 Except in the first case, yyparse will invoke yyremoveDeletes and
2387 then shift the next token onto all remaining stacks. This
2388 synchronization of the shift (that is, after all preceding
2389 reductions on all stacks) helps prevent double destructor calls
2390 on yylval in the event of memory exhaustion. */
2392 for (yys
= 0; yys
< yystack
.yytops
.yysize
; yys
+= 1)
2393 YYCHK1 (yyprocessOneStack (&yystack
, yys
, yyposn
]b4_lpure_args
[));
2394 yyremoveDeletes (&yystack
);
2395 if (yystack
.yytops
.yysize
== 0)
2397 yyundeleteLastStack (&yystack
);
2398 if (yystack
.yytops
.yysize
== 0)
2399 yyFail (&yystack
][]b4_lpure_args
[, YY_("syntax error"));
2400 YYCHK1 (yyresolveStack (&yystack
]b4_user_args
[));
2401 YYDPRINTF ((stderr
, "Returning to deterministic operation.\n"));
2402 ]b4_locations_if([[ yystack
.yyerror_range
[1].yystate
.yyloc
= yylloc
;]])[
2403 yyreportSyntaxError (&yystack
]b4_user_args
[);
2407 /* If any yyglrShift call fails, it will fail after shifting. Thus,
2408 a copy of yylval will already be on stack 0 in the event of a
2409 failure in the following loop. Thus, yychar is set to YYEMPTY
2410 before the loop to make sure the user destructor for yylval isn't
2412 yytoken_to_shift
= YYTRANSLATE (yychar
);
2415 for (yys
= 0; yys
< yystack
.yytops
.yysize
; yys
+= 1)
2418 const short int* yyconflicts
;
2419 yyStateNum yystate
= yystack
.yytops
.yystates
[yys
]->yylrState
;
2420 yygetLRActions (yystate
, yytoken_to_shift
, &yyaction
,
2422 /* Note that yyconflicts were handled by yyprocessOneStack. */
2423 YYDPRINTF ((stderr
, "On stack %lu, ", (unsigned long int) yys
));
2424 YY_SYMBOL_PRINT ("shifting", yytoken_to_shift
, &yylval
, &yylloc
);
2425 yyglrShift (&yystack
, yys
, yyaction
, yyposn
,
2426 &yylval
]b4_locations_if([, &yylloc
])[);
2427 YYDPRINTF ((stderr
, "Stack %lu now in state #%d\n",
2428 (unsigned long int) yys
,
2429 yystack
.yytops
.yystates
[yys
]->yylrState
));
2432 if (yystack
.yytops
.yysize
== 1)
2434 YYCHK1 (yyresolveStack (&yystack
]b4_user_args
[));
2435 YYDPRINTF ((stderr
, "Returning to deterministic operation.\n"));
2436 yycompressStack (&yystack
);
2442 yyrecoverSyntaxError (&yystack
]b4_user_args
[);
2443 yyposn
= yystack
.yytops
.yystates
[0]->yyposn
;
2459 yyerror (]b4_lyyerror_args
[YY_("memory exhausted"));
2464 if (yychar
!= YYEMPTY
)
2465 yydestruct ("Cleanup: discarding lookahead",
2466 YYTRANSLATE (yychar
), &yylval
]b4_locuser_args([&yylloc
])[);
2468 /* If the stack is well-formed, pop the stack until it is empty,
2469 destroying its entries as we go. But free the stack regardless
2470 of whether it is well-formed. */
2471 if (yystack
.yyitems
)
2473 yyGLRState
** yystates
= yystack
.yytops
.yystates
;
2476 size_t yysize
= yystack
.yytops
.yysize
;
2478 for (yyk
= 0; yyk
< yysize
; yyk
+= 1)
2481 while (yystates
[yyk
])
2483 yyGLRState
*yys
= yystates
[yyk
];
2484 ]b4_locations_if([[ yystack
.yyerror_range
[1].yystate
.yyloc
= yys
->yyloc
;]]
2485 )[ if (yys
->yypred
!= YY_NULL
)
2486 yydestroyGLRState ("Cleanup: popping", yys
]b4_user_args
[);
2487 yystates
[yyk
] = yys
->yypred
;
2488 yystack
.yynextFree
-= 1;
2489 yystack
.yyspaceLeft
+= 1;
2494 yyfreeGLRStack (&yystack
);
2497 /* Make sure YYID is used. */
2498 return YYID (yyresult
);
2501 /* DEBUGGING ONLY */
2502 #if ]b4_api_PREFIX[DEBUG
2503 static void yypstack (yyGLRStack
* yystackp
, size_t yyk
)
2504 __attribute__ ((__unused__
));
2505 static void yypdumpstack (yyGLRStack
* yystackp
) __attribute__ ((__unused__
));
2508 yy_yypstack (yyGLRState
* yys
)
2512 yy_yypstack (yys
->yypred
);
2513 YYFPRINTF (stderr
, " -> ");
2515 YYFPRINTF (stderr
, "%d@@%lu", yys
->yylrState
,
2516 (unsigned long int) yys
->yyposn
);
2520 yypstates (yyGLRState
* yyst
)
2522 if (yyst
== YY_NULL
)
2523 YYFPRINTF (stderr
, "<null>");
2526 YYFPRINTF (stderr
, "\n");
2530 yypstack (yyGLRStack
* yystackp
, size_t yyk
)
2532 yypstates (yystackp
->yytops
.yystates
[yyk
]);
2535 #define YYINDEX(YYX) \
2536 ((YYX) == YY_NULL ? -1 : (yyGLRStackItem*) (YYX) - yystackp->yyitems)
2540 yypdumpstack (yyGLRStack
* yystackp
)
2542 yyGLRStackItem
* yyp
;
2544 for (yyp
= yystackp
->yyitems
; yyp
< yystackp
->yynextFree
; yyp
+= 1)
2546 YYFPRINTF (stderr
, "%3lu. ",
2547 (unsigned long int) (yyp
- yystackp
->yyitems
));
2548 if (*(yybool
*) yyp
)
2550 YYFPRINTF (stderr
, "Res: %d, LR State: %d, posn: %lu, pred: %ld",
2551 yyp
->yystate
.yyresolved
, yyp
->yystate
.yylrState
,
2552 (unsigned long int) yyp
->yystate
.yyposn
,
2553 (long int) YYINDEX (yyp
->yystate
.yypred
));
2554 if (! yyp
->yystate
.yyresolved
)
2555 YYFPRINTF (stderr
, ", firstVal: %ld",
2556 (long int) YYINDEX (yyp
->yystate
2557 .yysemantics
.yyfirstVal
));
2561 YYFPRINTF (stderr
, "Option. rule: %d, state: %ld, next: %ld",
2562 yyp
->yyoption
.yyrule
- 1,
2563 (long int) YYINDEX (yyp
->yyoption
.yystate
),
2564 (long int) YYINDEX (yyp
->yyoption
.yynext
));
2566 YYFPRINTF (stderr
, "\n");
2568 YYFPRINTF (stderr
, "Tops:");
2569 for (yyi
= 0; yyi
< yystackp
->yytops
.yysize
; yyi
+= 1)
2570 YYFPRINTF (stderr
, "%lu: %ld; ", (unsigned long int) yyi
,
2571 (long int) YYINDEX (yystackp
->yytops
.yystates
[yyi
]));
2572 YYFPRINTF (stderr
, "\n");
2578 # glr.cc produces its own header.
2579 m4_if(b4_skeleton
, ["glr.c"],
2581 [b4_output_begin([b4_spec_defines_file
])
2582 b4_copyright([Skeleton interface
for Bison GLR parsers in C
],
2585 ]b4_cpp_guard_open([b4_spec_defines_file
])[
2586 ]b4_shared_declarations
[
2587 ]b4_cpp_guard_close([b4_spec_defines_file
])[