3 # GLR skeleton for Bison
5 # Copyright (C) 2002-2013 Free Software Foundation, Inc.
7 # This program is free software: you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License as published by
9 # the Free Software Foundation, either version 3 of the License, or
10 # (at your option) any later version.
12 # This program is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
17 # You should have received a copy of the GNU General Public License
18 # along with this program. If not, see <http://www.gnu.org/licenses/>.
21 # If we are loaded by glr.cc, do not override c++.m4 definitions by
23 m4_if(b4_skeleton
, ["glr.c"],
24 [m4_include(b4_pkgdatadir
/[c
.m4
])])
26 ## ---------------- ##
28 ## ---------------- ##
31 m4_define_default([b4_stack_depth_max
], [10000])
32 m4_define_default([b4_stack_depth_init
], [200])
36 ## ------------------------ ##
37 ## Pure/impure interfaces. ##
38 ## ------------------------ ##
40 b4_define_flag_if([pure
])
41 # If glr.cc is including this file and thus has already set b4_pure_flag,
42 # do not change the value of b4_pure_flag, and do not record a use of api.pure.
43 m4_ifndef([b4_pure_flag
],
44 [b4_percent_define_default([[api
.pure
]], [[false]])
45 m4_define([b4_pure_flag
],
46 [b4_percent_define_flag_if([[api
.pure
]], [[1]], [[0]])])])
50 # The possible parse-params formal arguments preceded by a comma.
52 # This is not shared with yacc.c in c.m4 because GLR relies on ISO C
53 # formal argument declarations.
54 m4_define([b4_user_formals
],
55 [m4_ifset([b4_parse_param
], [, b4_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 /* Identity function, used to suppress warnings about constant conditions. */
253 ]b4_c_function_def([YYID
], [static int], [[int i
], [i
]])[
263 # define YYMALLOC malloc
266 # define YYREALLOC realloc
269 #define YYSIZEMAX ((size_t) -1)
274 typedef unsigned char yybool
;
281 # define YYJMP_BUF jmp_buf
282 # define YYSETJMP(Env) setjmp (Env)
284 # define YYLONGJMP(Env, Val) (longjmp (Env, Val), YYASSERT (0))
287 ]b4_attribute_define
[
290 # define YYASSERT(Condition) ((void) ((Condition) || (abort (), 0)))
293 /* YYFINAL -- State number of the termination state. */
294 #define YYFINAL ]b4_final_state_number[
295 /* YYLAST -- Last index in YYTABLE. */
296 #define YYLAST ]b4_last[
298 /* YYNTOKENS -- Number of terminals. */
299 #define YYNTOKENS ]b4_tokens_number[
300 /* YYNNTS -- Number of nonterminals. */
301 #define YYNNTS ]b4_nterms_number[
302 /* YYNRULES -- Number of rules. */
303 #define YYNRULES ]b4_rules_number[
304 /* YYNRULES -- Number of states. */
305 #define YYNSTATES ]b4_states_number[
306 /* YYMAXRHS -- Maximum number of symbols on right-hand side of rule. */
307 #define YYMAXRHS ]b4_r2_max[
308 /* YYMAXLEFT -- Maximum number of symbols to the left of a handle
309 accessed by $0, $-1, etc., in any rule. */
310 #define YYMAXLEFT ]b4_max_left_semantic_context[
312 /* YYTRANSLATE(X) -- Bison symbol number corresponding to X. */
313 #define YYUNDEFTOK ]b4_undef_token_number[
314 #define YYMAXUTOK ]b4_user_token_number_max[
316 #define YYTRANSLATE(YYX) \
317 ((unsigned int) (YYX) <= YYMAXUTOK ? yytranslate[YYX] : YYUNDEFTOK)
319 /* YYTRANSLATE[YYLEX] -- Bison symbol number corresponding to YYLEX. */
320 static const ]b4_int_type_for([b4_translate
])[ yytranslate
[] =
325 #if ]b4_api_PREFIX[DEBUG
326 /* YYPRHS[YYN] -- Index of the first RHS symbol of rule number YYN in
328 static const ]b4_int_type_for([b4_prhs
])[ yyprhs
[] =
333 /* YYRHS -- A `-1'-separated list of the rules' RHS. */
334 static const ]b4_int_type_for([b4_rhs
])[ yyrhs
[] =
339 /* YYRLINE[YYN] -- source line where rule number YYN was defined. */
340 static const ]b4_int_type_for([b4_rline
])[ yyrline
[] =
346 #if ]b4_api_PREFIX[DEBUG || YYERROR_VERBOSE || ]b4_token_table_flag[
347 /* YYTNAME[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM.
348 First, the terminals, then, starting at YYNTOKENS, nonterminals. */
349 static const char *const yytname
[] =
355 /* YYR1[YYN] -- Symbol number of symbol that rule YYN derives. */
356 static const ]b4_int_type_for([b4_r1
])[ yyr1
[] =
361 /* YYR2[YYN] -- Number of symbols composing right hand side of rule YYN. */
362 static const ]b4_int_type_for([b4_r2
])[ yyr2
[] =
367 /* YYDPREC[RULE-NUM] -- Dynamic precedence of rule #RULE-NUM (0 if none). */
368 static const ]b4_int_type_for([b4_dprec
])[ yydprec
[] =
373 /* YYMERGER[RULE-NUM] -- Index of merging function for rule #RULE-NUM. */
374 static const ]b4_int_type_for([b4_merger
])[ yymerger
[] =
379 /* YYDEFACT[S] -- default reduction number in state S. Performed when
380 YYTABLE doesn't specify something else to do. Zero means the default
382 static const ]b4_int_type_for([b4_defact
])[ yydefact
[] =
387 /* YYPDEFGOTO[NTERM-NUM]. */
388 static const ]b4_int_type_for([b4_defgoto
])[ yydefgoto
[] =
393 /* YYPACT[STATE-NUM] -- Index in YYTABLE of the portion describing
395 #define YYPACT_NINF ]b4_pact_ninf[
396 static const ]b4_int_type_for([b4_pact
])[ yypact
[] =
401 /* YYPGOTO[NTERM-NUM]. */
402 static const ]b4_int_type_for([b4_pgoto
])[ yypgoto
[] =
407 /* YYTABLE[YYPACT[STATE-NUM]]. What to do in state STATE-NUM. If
408 positive, shift that token. If negative, reduce the rule which
409 number is the opposite. If YYTABLE_NINF, syntax error. */
410 #define YYTABLE_NINF ]b4_table_ninf[
411 static const ]b4_int_type_for([b4_table
])[ yytable
[] =
416 /* YYCONFLP[YYPACT[STATE-NUM]] -- Pointer into YYCONFL of start of
417 list of conflicting reductions corresponding to action entry for
418 state STATE-NUM in yytable. 0 means no conflicts. The list in
419 yyconfl is terminated by a rule number of 0. */
420 static const ]b4_int_type_for([b4_conflict_list_heads
])[ yyconflp
[] =
422 ]b4_conflict_list_heads
[
425 /* YYCONFL[I] -- lists of conflicting rule numbers, each terminated by
426 0, pointed into by YYCONFLP. */
427 ]dnl Do
not use b4_int_type_for here
, since there are places where
428 dnl pointers onto yyconfl are taken
, which type is
"short int *".
429 dnl We probably ought to introduce a type
for confl
.
430 [static const short int yyconfl
[] =
432 ]b4_conflicting_rules
[
435 static const ]b4_int_type_for([b4_check
])[ yycheck
[] =
440 /* YYSTOS[STATE-NUM] -- The (internal number of the) accessing
441 symbol of state STATE-NUM. */
442 static const ]b4_int_type_for([b4_stos
])[ yystos
[] =
447 /* Error token number */
451 ]b4_yylloc_default_define
[
452 # define YYRHSLOC(Rhs, K) ((Rhs)[K].yystate.yyloc)
454 ]b4_yy_location_print_define
[
456 /* YYLEX -- calling `yylex' with the right arguments. */
457 #define YYLEX ]b4_c_function_call([yylex], [int], b4_lex_param)[
462 #define yynerrs (yystackp->yyerrcnt)
464 #define yychar (yystackp->yyrawchar)
466 #define yylval (yystackp->yyval)
468 #define yylloc (yystackp->yyloc)
469 m4_if(b4_prefix
[], [yy
], [],
470 [#define b4_prefix[]nerrs yynerrs
471 #define b4_prefix[]char yychar
472 #define b4_prefix[]lval yylval
473 #define b4_prefix[]lloc yylloc])],
474 [YYSTYPE yylval
;]b4_locations_if([[
480 static const int YYEOF
= 0;
481 static const int YYEMPTY
= -2;
483 typedef enum { yyok
, yyaccept
, yyabort
, yyerr
} YYRESULTTAG
;
486 do { YYRESULTTAG yyflag = YYE; if (yyflag != yyok) return yyflag; } \
489 #if ]b4_api_PREFIX[DEBUG
492 # define YYFPRINTF fprintf
495 # define YYDPRINTF(Args) \
501 ]b4_yy_symbol_print_generate([b4_c_ansi_function_def
])[
503 # define YY_SYMBOL_PRINT(Title, Type, Value, Location) \
507 YYFPRINTF (stderr, "%s ", Title); \
508 yy_symbol_print (stderr, Type, Value]b4_locuser_args([Location])[); \
509 YYFPRINTF (stderr, "\n"); \
513 /* Nonzero means print parse trace. It is left uninitialized so that
514 multiple parsers can coexist. */
517 #else /* !]b4_api_PREFIX[DEBUG */
519 # define YYDPRINTF(Args)
520 # define YY_SYMBOL_PRINT(Title, Type, Value, Location)
522 #endif /* !]b4_api_PREFIX[DEBUG */
524 /* YYINITDEPTH -- initial size of the parser's stacks. */
526 # define YYINITDEPTH ]b4_stack_depth_init[
529 /* YYMAXDEPTH -- maximum size the stacks can grow to (effective only
530 if the built-in stack extension method is used).
532 Do not make this value too large; the results are undefined if
533 SIZE_MAX < YYMAXDEPTH * sizeof (GLRStackItem)
534 evaluated with infinite-precision integer arithmetic. */
537 # define YYMAXDEPTH ]b4_stack_depth_max[
540 /* Minimum number of free items on the stack allowed after an
541 allocation. This is to allow allocation and initialization
542 to be completed by functions that call yyexpandGLRStack before the
543 stack is expanded, thus insuring that all necessary pointers get
544 properly redirected to new data. */
547 #ifndef YYSTACKEXPANDABLE
548 # if (! defined __cplusplus \
549 || (]b4_locations_if([[defined ]b4_api_PREFIX[LTYPE_IS_TRIVIAL && ]b4_api_PREFIX[LTYPE_IS_TRIVIAL \
550 && ]])[defined ]b4_api_PREFIX[STYPE_IS_TRIVIAL && ]b4_api_PREFIX[STYPE_IS_TRIVIAL))
551 # define YYSTACKEXPANDABLE 1
553 # define YYSTACKEXPANDABLE 0
557 #if YYSTACKEXPANDABLE
558 # define YY_RESERVE_GLRSTACK(Yystack) \
560 if (Yystack->yyspaceLeft < YYHEADROOM) \
561 yyexpandGLRStack (Yystack); \
564 # define YY_RESERVE_GLRSTACK(Yystack) \
566 if (Yystack->yyspaceLeft < YYHEADROOM) \
567 yyMemoryExhausted (Yystack); \
575 # if defined __GLIBC__ && defined _STRING_H && defined _GNU_SOURCE
576 # define yystpcpy stpcpy
578 /* Copy YYSRC to YYDEST, returning the address of the terminating '\0' in
581 yystpcpy (char *yydest
, const char *yysrc
)
584 const char *yys
= yysrc
;
586 while ((*yyd
++ = *yys
++) != '\0')
595 /* Copy to YYRES the contents of YYSTR after stripping away unnecessary
596 quotes and backslashes, so that it's suitable for yyerror. The
597 heuristic is that double-quoting is unnecessary unless the string
598 contains an apostrophe, a comma, or backslash (other than
599 backslash-backslash). YYSTR is taken from yytname. If YYRES is
600 null, do not copy; instead, return the length of what the result
603 yytnamerr (char *yyres
, const char *yystr
)
608 char const *yyp
= yystr
;
615 goto do_not_strip_quotes
;
619 goto do_not_strip_quotes
;
632 do_not_strip_quotes
: ;
636 return strlen (yystr
);
638 return yystpcpy (yyres
, yystr
) - yyres
;
642 #endif /* !YYERROR_VERBOSE */
644 /** State numbers, as in LALR(1) machine */
645 typedef int yyStateNum
;
647 /** Rule numbers, as in LALR(1) machine */
648 typedef int yyRuleNum
;
650 /** Grammar symbol */
651 typedef short int yySymbol
;
653 /** Item references, as in LALR(1) machine */
654 typedef short int yyItemNum
;
656 typedef struct yyGLRState yyGLRState
;
657 typedef struct yyGLRStateSet yyGLRStateSet
;
658 typedef struct yySemanticOption yySemanticOption
;
659 typedef union yyGLRStackItem yyGLRStackItem
;
660 typedef struct yyGLRStack yyGLRStack
;
663 /** Type tag: always true. */
665 /** Type tag for yysemantics. If true, yysval applies, otherwise
666 * yyfirstVal applies. */
668 /** Number of corresponding LALR(1) machine state. */
669 yyStateNum yylrState
;
670 /** Preceding state in this stack */
672 /** Source position of the first token produced by my symbol */
675 /** First in a chain of alternative reductions producing the
676 * non-terminal corresponding to this state, threaded through
678 yySemanticOption
* yyfirstVal
;
679 /** Semantic value for this state. */
681 } yysemantics
;]b4_locations_if([[
682 /** Source location for this state. */
686 struct yyGLRStateSet
{
687 yyGLRState
** yystates
;
688 /** During nondeterministic operation, yylookaheadNeeds tracks which
689 * stacks have actually needed the current lookahead. During deterministic
690 * operation, yylookaheadNeeds[0] is not maintained since it would merely
691 * duplicate yychar != YYEMPTY. */
692 yybool
* yylookaheadNeeds
;
693 size_t yysize
, yycapacity
;
696 struct yySemanticOption
{
697 /** Type tag: always false. */
699 /** Rule number for this reduction */
701 /** The last RHS state in the list of states to be reduced. */
703 /** The lookahead for this reduction. */
705 YYSTYPE yyval
;]b4_locations_if([[
707 /** Next sibling in chain of options. To facilitate merging,
708 * options are chained in decreasing order by address. */
709 yySemanticOption
* yynext
;
712 /** Type of the items in the GLR stack. The yyisState field
713 * indicates which item of the union is valid. */
714 union yyGLRStackItem
{
716 yySemanticOption yyoption
;
721 ]b4_locations_if([[ /* To compute the location of the error token. */
722 yyGLRStackItem yyerror_range
[3];]])[
727 YYSTYPE yyval
;]b4_locations_if([[
730 YYJMP_BUF yyexception_buffer
;
731 yyGLRStackItem
* yyitems
;
732 yyGLRStackItem
* yynextFree
;
734 yyGLRState
* yysplitPoint
;
735 yyGLRState
* yylastDeleted
;
736 yyGLRStateSet yytops
;
739 #if YYSTACKEXPANDABLE
740 static void yyexpandGLRStack (yyGLRStack
* yystackp
);
743 static void yyFail (yyGLRStack
* yystackp
]b4_pure_formals
[, const char* yymsg
)
744 __attribute__ ((__noreturn__
));
746 yyFail (yyGLRStack
* yystackp
]b4_pure_formals
[, const char* yymsg
)
748 if (yymsg
!= YY_NULL
)
749 yyerror (]b4_yyerror_args
[yymsg
);
750 YYLONGJMP (yystackp
->yyexception_buffer
, 1);
753 static void yyMemoryExhausted (yyGLRStack
* yystackp
)
754 __attribute__ ((__noreturn__
));
756 yyMemoryExhausted (yyGLRStack
* yystackp
)
758 YYLONGJMP (yystackp
->yyexception_buffer
, 2);
761 #if ]b4_api_PREFIX[DEBUG || YYERROR_VERBOSE
762 /** A printable representation of TOKEN. */
763 static inline const char*
764 yytokenName (yySymbol yytoken
)
766 if (yytoken
== YYEMPTY
)
769 return yytname
[yytoken
];
773 /** Fill in YYVSP[YYLOW1 .. YYLOW0-1] from the chain of states starting
774 * at YYVSP[YYLOW0].yystate.yypred. Leaves YYVSP[YYLOW1].yystate.yypred
775 * containing the pointer to the next state in the chain. */
776 static void yyfillin (yyGLRStackItem
*, int, int) __attribute__ ((__unused__
));
778 yyfillin (yyGLRStackItem
*yyvsp
, int yylow0
, int yylow1
)
781 yyGLRState
*s
= yyvsp
[yylow0
].yystate
.yypred
;
782 for (i
= yylow0
-1; i
>= yylow1
; i
-= 1)
784 YYASSERT (s
->yyresolved
);
785 yyvsp
[i
].yystate
.yyresolved
= yytrue
;
786 yyvsp
[i
].yystate
.yysemantics
.yysval
= s
->yysemantics
.yysval
;]b4_locations_if([[
787 yyvsp
[i
].yystate
.yyloc
= s
->yyloc
;]])[
788 s
= yyvsp
[i
].yystate
.yypred
= s
->yypred
;
792 /* Do nothing if YYNORMAL or if *YYLOW <= YYLOW1. Otherwise, fill in
793 * YYVSP[YYLOW1 .. *YYLOW-1] as in yyfillin and set *YYLOW = YYLOW1.
794 * For convenience, always return YYLOW1. */
795 static inline int yyfill (yyGLRStackItem
*, int *, int, yybool
)
796 __attribute__ ((__unused__
));
798 yyfill (yyGLRStackItem
*yyvsp
, int *yylow
, int yylow1
, yybool yynormal
)
800 if (!yynormal
&& yylow1
< *yylow
)
802 yyfillin (yyvsp
, *yylow
, yylow1
);
808 /** Perform user action for rule number YYN, with RHS length YYRHSLEN,
809 * and top stack item YYVSP. YYLVALP points to place to put semantic
810 * value ($$), and yylocp points to place for location information
811 * (@@$). Returns yyok for normal return, yyaccept for YYACCEPT,
812 * yyerr for YYERROR, yyabort for YYABORT. */
813 /*ARGSUSED*/ static YYRESULTTAG
814 yyuserAction (yyRuleNum yyn
, int yyrhslen
, yyGLRStackItem
* yyvsp
,
815 yyGLRStack
* yystackp
,
816 YYSTYPE
* yyvalp
]b4_locuser_formals
[)
818 yybool yynormal
__attribute__ ((__unused__
)) =
819 (yystackp
->yysplitPoint
== YY_NULL
);
821 ]b4_parse_param_use
[]dnl
823 # define yyerrok (yystackp->yyerrState = 0)
825 # define YYACCEPT return yyaccept
827 # define YYABORT return yyabort
829 # define YYERROR return yyerrok, yyerr
831 # define YYRECOVERING() (yystackp->yyerrState != 0)
833 # define yyclearin (yychar = YYEMPTY)
835 # define YYFILL(N) yyfill (yyvsp, &yylow, N, yynormal)
837 # define YYBACKUP(Token, Value) \
838 return yyerror (]b4_yyerror_args[YY_("syntax error: cannot back up")), \
843 *yyvalp
= yyval_default
;
845 *yyvalp
= yyvsp
[YYFILL (1-yyrhslen
)].yystate
.yysemantics
.yysval
;]b4_locations_if([[
846 YYLLOC_DEFAULT ((*yylocp
), (yyvsp
- yyrhslen
), yyrhslen
);
847 yystackp
->yyerror_range
[1].yystate
.yyloc
= *yylocp
;
866 /*ARGSUSED*/ static void
867 yyuserMerge (int yyn
, YYSTYPE
* yy0
, YYSTYPE
* yy1
)
879 /* Bison grammar-table manipulation. */
881 ]b4_yydestruct_generate([b4_c_ansi_function_def
])[
883 /** Number of symbols composing the right hand side of rule #RULE. */
885 yyrhsLength (yyRuleNum yyrule
)
891 yydestroyGLRState (char const *yymsg
, yyGLRState
*yys
]b4_user_formals
[)
894 yydestruct (yymsg
, yystos
[yys
->yylrState
],
895 &yys
->yysemantics
.yysval
]b4_locuser_args([&yys
->yyloc
])[);
898 #if ]b4_api_PREFIX[DEBUG
901 if (yys
->yysemantics
.yyfirstVal
)
902 YYFPRINTF (stderr
, "%s unresolved ", yymsg
);
904 YYFPRINTF (stderr
, "%s incomplete ", yymsg
);
905 yy_symbol_print (stderr
, yystos
[yys
->yylrState
],
906 YY_NULL
]b4_locuser_args([&yys
->yyloc
])[);
907 YYFPRINTF (stderr
, "\n");
911 if (yys
->yysemantics
.yyfirstVal
)
913 yySemanticOption
*yyoption
= yys
->yysemantics
.yyfirstVal
;
916 for (yyrh
= yyoption
->yystate
, yyn
= yyrhsLength (yyoption
->yyrule
);
918 yyrh
= yyrh
->yypred
, yyn
-= 1)
919 yydestroyGLRState (yymsg
, yyrh
]b4_user_args
[);
924 /** Left-hand-side symbol for rule #RULE. */
925 static inline yySymbol
926 yylhsNonterm (yyRuleNum yyrule
)
931 #define yypact_value_is_default(Yystate) \
932 ]b4_table_value_equals([[pact]], [[Yystate]], [b4_pact_ninf])[
934 /** True iff LR state STATE has only a default reduction (regardless
937 yyisDefaultedState (yyStateNum yystate
)
939 return yypact_value_is_default (yypact
[yystate
]);
942 /** The default reduction for STATE, assuming it has one. */
943 static inline yyRuleNum
944 yydefaultAction (yyStateNum yystate
)
946 return yydefact
[yystate
];
949 #define yytable_value_is_error(Yytable_value) \
950 ]b4_table_value_equals([[table]], [[Yytable_value]], [b4_table_ninf])[
952 /** Set *YYACTION to the action to take in YYSTATE on seeing YYTOKEN.
954 * R < 0: Reduce on rule -R.
956 * R > 0: Shift to state R.
957 * Set *CONFLICTS to a pointer into yyconfl to 0-terminated list of
958 * conflicting reductions.
961 yygetLRActions (yyStateNum yystate
, int yytoken
,
962 int* yyaction
, const short int** yyconflicts
)
964 int yyindex
= yypact
[yystate
] + yytoken
;
965 if (yypact_value_is_default (yypact
[yystate
])
966 || yyindex
< 0 || YYLAST
< yyindex
|| yycheck
[yyindex
] != yytoken
)
968 *yyaction
= -yydefact
[yystate
];
969 *yyconflicts
= yyconfl
;
971 else if (! yytable_value_is_error (yytable
[yyindex
]))
973 *yyaction
= yytable
[yyindex
];
974 *yyconflicts
= yyconfl
+ yyconflp
[yyindex
];
979 *yyconflicts
= yyconfl
+ yyconflp
[yyindex
];
983 static inline yyStateNum
984 yyLRgotoState (yyStateNum yystate
, yySymbol yylhs
)
987 yyr
= yypgoto
[yylhs
- YYNTOKENS
] + yystate
;
988 if (0 <= yyr
&& yyr
<= YYLAST
&& yycheck
[yyr
] == yystate
)
991 return yydefgoto
[yylhs
- YYNTOKENS
];
995 yyisShiftAction (int yyaction
)
1000 static inline yybool
1001 yyisErrorAction (int yyaction
)
1003 return yyaction
== 0;
1008 /** Return a fresh GLRStackItem. Callers should call
1009 * YY_RESERVE_GLRSTACK afterwards to make sure there is sufficient
1012 static inline yyGLRStackItem
*
1013 yynewGLRStackItem (yyGLRStack
* yystackp
, yybool yyisState
)
1015 yyGLRStackItem
* yynewItem
= yystackp
->yynextFree
;
1016 yystackp
->yyspaceLeft
-= 1;
1017 yystackp
->yynextFree
+= 1;
1018 yynewItem
->yystate
.yyisState
= yyisState
;
1022 /** Add a new semantic action that will execute the action for rule
1023 * RULENUM on the semantic values in RHS to the list of
1024 * alternative actions for STATE. Assumes that RHS comes from
1025 * stack #K of *STACKP. */
1027 yyaddDeferredAction (yyGLRStack
* yystackp
, size_t yyk
, yyGLRState
* yystate
,
1028 yyGLRState
* rhs
, yyRuleNum yyrule
)
1030 yySemanticOption
* yynewOption
=
1031 &yynewGLRStackItem (yystackp
, yyfalse
)->yyoption
;
1032 yynewOption
->yystate
= rhs
;
1033 yynewOption
->yyrule
= yyrule
;
1034 if (yystackp
->yytops
.yylookaheadNeeds
[yyk
])
1036 yynewOption
->yyrawchar
= yychar
;
1037 yynewOption
->yyval
= yylval
;]b4_locations_if([
1038 yynewOption
->yyloc
= yylloc
;])[
1041 yynewOption
->yyrawchar
= YYEMPTY
;
1042 yynewOption
->yynext
= yystate
->yysemantics
.yyfirstVal
;
1043 yystate
->yysemantics
.yyfirstVal
= yynewOption
;
1045 YY_RESERVE_GLRSTACK (yystackp
);
1050 /** Initialize SET to a singleton set containing an empty stack. */
1052 yyinitStateSet (yyGLRStateSet
* yyset
)
1055 yyset
->yycapacity
= 16;
1056 yyset
->yystates
= (yyGLRState
**) YYMALLOC (16 * sizeof yyset
->yystates
[0]);
1057 if (! yyset
->yystates
)
1059 yyset
->yystates
[0] = YY_NULL
;
1060 yyset
->yylookaheadNeeds
=
1061 (yybool
*) YYMALLOC (16 * sizeof yyset
->yylookaheadNeeds
[0]);
1062 if (! yyset
->yylookaheadNeeds
)
1064 YYFREE (yyset
->yystates
);
1070 static void yyfreeStateSet (yyGLRStateSet
* yyset
)
1072 YYFREE (yyset
->yystates
);
1073 YYFREE (yyset
->yylookaheadNeeds
);
1076 /** Initialize STACK to a single empty stack, with total maximum
1077 * capacity for all stacks of SIZE. */
1079 yyinitGLRStack (yyGLRStack
* yystackp
, size_t yysize
)
1081 yystackp
->yyerrState
= 0;
1083 yystackp
->yyspaceLeft
= yysize
;
1085 (yyGLRStackItem
*) YYMALLOC (yysize
* sizeof yystackp
->yynextFree
[0]);
1086 if (!yystackp
->yyitems
)
1088 yystackp
->yynextFree
= yystackp
->yyitems
;
1089 yystackp
->yysplitPoint
= YY_NULL
;
1090 yystackp
->yylastDeleted
= YY_NULL
;
1091 return yyinitStateSet (&yystackp
->yytops
);
1095 #if YYSTACKEXPANDABLE
1096 # define YYRELOC(YYFROMITEMS,YYTOITEMS,YYX,YYTYPE) \
1097 &((YYTOITEMS) - ((YYFROMITEMS) - (yyGLRStackItem*) (YYX)))->YYTYPE
1099 /** If STACK is expandable, extend it. WARNING: Pointers into the
1100 stack from outside should be considered invalid after this call.
1101 We always expand when there are 1 or fewer items left AFTER an
1102 allocation, so that we can avoid having external pointers exist
1103 across an allocation. */
1105 yyexpandGLRStack (yyGLRStack
* yystackp
)
1107 yyGLRStackItem
* yynewItems
;
1108 yyGLRStackItem
* yyp0
, *yyp1
;
1111 size_t yysize
= yystackp
->yynextFree
- yystackp
->yyitems
;
1112 if (YYMAXDEPTH
- YYHEADROOM
< yysize
)
1113 yyMemoryExhausted (yystackp
);
1114 yynewSize
= 2*yysize
;
1115 if (YYMAXDEPTH
< yynewSize
)
1116 yynewSize
= YYMAXDEPTH
;
1117 yynewItems
= (yyGLRStackItem
*) YYMALLOC (yynewSize
* sizeof yynewItems
[0]);
1119 yyMemoryExhausted (yystackp
);
1120 for (yyp0
= yystackp
->yyitems
, yyp1
= yynewItems
, yyn
= yysize
;
1122 yyn
-= 1, yyp0
+= 1, yyp1
+= 1)
1125 if (*(yybool
*) yyp0
)
1127 yyGLRState
* yys0
= &yyp0
->yystate
;
1128 yyGLRState
* yys1
= &yyp1
->yystate
;
1129 if (yys0
->yypred
!= YY_NULL
)
1131 YYRELOC (yyp0
, yyp1
, yys0
->yypred
, yystate
);
1132 if (! yys0
->yyresolved
&& yys0
->yysemantics
.yyfirstVal
!= YY_NULL
)
1133 yys1
->yysemantics
.yyfirstVal
=
1134 YYRELOC (yyp0
, yyp1
, yys0
->yysemantics
.yyfirstVal
, yyoption
);
1138 yySemanticOption
* yyv0
= &yyp0
->yyoption
;
1139 yySemanticOption
* yyv1
= &yyp1
->yyoption
;
1140 if (yyv0
->yystate
!= YY_NULL
)
1141 yyv1
->yystate
= YYRELOC (yyp0
, yyp1
, yyv0
->yystate
, yystate
);
1142 if (yyv0
->yynext
!= YY_NULL
)
1143 yyv1
->yynext
= YYRELOC (yyp0
, yyp1
, yyv0
->yynext
, yyoption
);
1146 if (yystackp
->yysplitPoint
!= YY_NULL
)
1147 yystackp
->yysplitPoint
= YYRELOC (yystackp
->yyitems
, yynewItems
,
1148 yystackp
->yysplitPoint
, yystate
);
1150 for (yyn
= 0; yyn
< yystackp
->yytops
.yysize
; yyn
+= 1)
1151 if (yystackp
->yytops
.yystates
[yyn
] != YY_NULL
)
1152 yystackp
->yytops
.yystates
[yyn
] =
1153 YYRELOC (yystackp
->yyitems
, yynewItems
,
1154 yystackp
->yytops
.yystates
[yyn
], yystate
);
1155 YYFREE (yystackp
->yyitems
);
1156 yystackp
->yyitems
= yynewItems
;
1157 yystackp
->yynextFree
= yynewItems
+ yysize
;
1158 yystackp
->yyspaceLeft
= yynewSize
- yysize
;
1163 yyfreeGLRStack (yyGLRStack
* yystackp
)
1165 YYFREE (yystackp
->yyitems
);
1166 yyfreeStateSet (&yystackp
->yytops
);
1169 /** Assuming that S is a GLRState somewhere on STACK, update the
1170 * splitpoint of STACK, if needed, so that it is at least as deep as
1173 yyupdateSplit (yyGLRStack
* yystackp
, yyGLRState
* yys
)
1175 if (yystackp
->yysplitPoint
!= YY_NULL
&& yystackp
->yysplitPoint
> yys
)
1176 yystackp
->yysplitPoint
= yys
;
1179 /** Invalidate stack #K in STACK. */
1181 yymarkStackDeleted (yyGLRStack
* yystackp
, size_t yyk
)
1183 if (yystackp
->yytops
.yystates
[yyk
] != YY_NULL
)
1184 yystackp
->yylastDeleted
= yystackp
->yytops
.yystates
[yyk
];
1185 yystackp
->yytops
.yystates
[yyk
] = YY_NULL
;
1188 /** Undelete the last stack that was marked as deleted. Can only be
1189 done once after a deletion, and only when all other stacks have
1192 yyundeleteLastStack (yyGLRStack
* yystackp
)
1194 if (yystackp
->yylastDeleted
== YY_NULL
|| yystackp
->yytops
.yysize
!= 0)
1196 yystackp
->yytops
.yystates
[0] = yystackp
->yylastDeleted
;
1197 yystackp
->yytops
.yysize
= 1;
1198 YYDPRINTF ((stderr
, "Restoring last deleted stack as stack #0.\n"));
1199 yystackp
->yylastDeleted
= YY_NULL
;
1203 yyremoveDeletes (yyGLRStack
* yystackp
)
1207 while (yyj
< yystackp
->yytops
.yysize
)
1209 if (yystackp
->yytops
.yystates
[yyi
] == YY_NULL
)
1213 YYDPRINTF ((stderr
, "Removing dead stacks.\n"));
1215 yystackp
->yytops
.yysize
-= 1;
1219 yystackp
->yytops
.yystates
[yyj
] = yystackp
->yytops
.yystates
[yyi
];
1220 /* In the current implementation, it's unnecessary to copy
1221 yystackp->yytops.yylookaheadNeeds[yyi] since, after
1222 yyremoveDeletes returns, the parser immediately either enters
1223 deterministic operation or shifts a token. However, it doesn't
1224 hurt, and the code might evolve to need it. */
1225 yystackp
->yytops
.yylookaheadNeeds
[yyj
] =
1226 yystackp
->yytops
.yylookaheadNeeds
[yyi
];
1229 YYDPRINTF ((stderr
, "Rename stack %lu -> %lu.\n",
1230 (unsigned long int) yyi
, (unsigned long int) yyj
));
1238 /** Shift to a new state on stack #K of STACK, corresponding to LR state
1239 * LRSTATE, at input position POSN, with (resolved) semantic value SVAL. */
1241 yyglrShift (yyGLRStack
* yystackp
, size_t yyk
, yyStateNum yylrState
,
1243 YYSTYPE
* yyvalp
]b4_locations_if([, YYLTYPE
* yylocp
])[)
1245 yyGLRState
* yynewState
= &yynewGLRStackItem (yystackp
, yytrue
)->yystate
;
1247 yynewState
->yylrState
= yylrState
;
1248 yynewState
->yyposn
= yyposn
;
1249 yynewState
->yyresolved
= yytrue
;
1250 yynewState
->yypred
= yystackp
->yytops
.yystates
[yyk
];
1251 yynewState
->yysemantics
.yysval
= *yyvalp
;]b4_locations_if([
1252 yynewState
->yyloc
= *yylocp
;])[
1253 yystackp
->yytops
.yystates
[yyk
] = yynewState
;
1255 YY_RESERVE_GLRSTACK (yystackp
);
1258 /** Shift stack #K of YYSTACK, to a new state corresponding to LR
1259 * state YYLRSTATE, at input position YYPOSN, with the (unresolved)
1260 * semantic value of YYRHS under the action for YYRULE. */
1262 yyglrShiftDefer (yyGLRStack
* yystackp
, size_t yyk
, yyStateNum yylrState
,
1263 size_t yyposn
, yyGLRState
* rhs
, yyRuleNum yyrule
)
1265 yyGLRState
* yynewState
= &yynewGLRStackItem (yystackp
, yytrue
)->yystate
;
1267 yynewState
->yylrState
= yylrState
;
1268 yynewState
->yyposn
= yyposn
;
1269 yynewState
->yyresolved
= yyfalse
;
1270 yynewState
->yypred
= yystackp
->yytops
.yystates
[yyk
];
1271 yynewState
->yysemantics
.yyfirstVal
= YY_NULL
;
1272 yystackp
->yytops
.yystates
[yyk
] = yynewState
;
1274 /* Invokes YY_RESERVE_GLRSTACK. */
1275 yyaddDeferredAction (yystackp
, yyk
, yynewState
, rhs
, yyrule
);
1278 /** Pop the symbols consumed by reduction #RULE from the top of stack
1279 * #K of STACK, and perform the appropriate semantic action on their
1280 * semantic values. Assumes that all ambiguities in semantic values
1281 * have been previously resolved. Set *VALP to the resulting value,
1282 * and *LOCP to the computed location (if any). Return value is as
1283 * for userAction. */
1284 static inline YYRESULTTAG
1285 yydoAction (yyGLRStack
* yystackp
, size_t yyk
, yyRuleNum yyrule
,
1286 YYSTYPE
* yyvalp
]b4_locuser_formals
[)
1288 int yynrhs
= yyrhsLength (yyrule
);
1290 if (yystackp
->yysplitPoint
== YY_NULL
)
1292 /* Standard special case: single stack. */
1293 yyGLRStackItem
* rhs
= (yyGLRStackItem
*) yystackp
->yytops
.yystates
[yyk
];
1294 YYASSERT (yyk
== 0);
1295 yystackp
->yynextFree
-= yynrhs
;
1296 yystackp
->yyspaceLeft
+= yynrhs
;
1297 yystackp
->yytops
.yystates
[0] = & yystackp
->yynextFree
[-1].yystate
;
1298 return yyuserAction (yyrule
, yynrhs
, rhs
, yystackp
,
1299 yyvalp
]b4_locuser_args
[);
1303 /* At present, doAction is never called in nondeterministic
1304 * mode, so this branch is never taken. It is here in
1305 * anticipation of a future feature that will allow immediate
1306 * evaluation of selected actions in nondeterministic mode. */
1309 yyGLRStackItem yyrhsVals
[YYMAXRHS
+ YYMAXLEFT
+ 1];
1310 yys
= yyrhsVals
[YYMAXRHS
+ YYMAXLEFT
].yystate
.yypred
1311 = yystackp
->yytops
.yystates
[yyk
];]b4_locations_if([[
1313 /* Set default location. */
1314 yyrhsVals
[YYMAXRHS
+ YYMAXLEFT
- 1].yystate
.yyloc
= yys
->yyloc
;]])[
1315 for (yyi
= 0; yyi
< yynrhs
; yyi
+= 1)
1320 yyupdateSplit (yystackp
, yys
);
1321 yystackp
->yytops
.yystates
[yyk
] = yys
;
1322 return yyuserAction (yyrule
, yynrhs
, yyrhsVals
+ YYMAXRHS
+ YYMAXLEFT
- 1,
1323 yystackp
, yyvalp
]b4_locuser_args
[);
1327 #if !]b4_api_PREFIX[DEBUG
1328 # define YY_REDUCE_PRINT(Args)
1330 # define YY_REDUCE_PRINT(Args) \
1333 yy_reduce_print Args; \
1336 /*----------------------------------------------------------.
1337 | Report that the RULE is going to be reduced on stack #K. |
1338 `----------------------------------------------------------*/
1340 /*ARGSUSED*/ static inline void
1341 yy_reduce_print (yyGLRStack
* yystackp
, size_t yyk
, yyRuleNum yyrule
,
1342 YYSTYPE
* yyvalp
]b4_locuser_formals
[)
1344 int yynrhs
= yyrhsLength (yyrule
);
1345 yybool yynormal
__attribute__ ((__unused__
)) =
1346 (yystackp
->yysplitPoint
== YY_NULL
);
1347 yyGLRStackItem
* yyvsp
= (yyGLRStackItem
*) yystackp
->yytops
.yystates
[yyk
];
1350 YYUSE (yyvalp
);]b4_locations_if([
1352 ]b4_parse_param_use
[]dnl
1353 [ YYFPRINTF (stderr
, "Reducing stack %lu by rule %d (line %lu):\n",
1354 (unsigned long int) yyk
, yyrule
- 1,
1355 (unsigned long int) yyrline
[yyrule
]);
1356 /* The symbols being reduced. */
1357 for (yyi
= 0; yyi
< yynrhs
; yyi
++)
1359 YYFPRINTF (stderr
, " $%d = ", yyi
+ 1);
1360 yy_symbol_print (stderr
, yyrhs
[yyprhs
[yyrule
] + yyi
],
1361 &]b4_rhs_value(yynrhs
, yyi
+ 1)[
1362 ]b4_locations_if([, &]b4_rhs_location(yynrhs
, yyi
+ 1))[]dnl
1364 YYFPRINTF (stderr
, "\n");
1369 /** Pop items off stack #K of STACK according to grammar rule RULE,
1370 * and push back on the resulting nonterminal symbol. Perform the
1371 * semantic action associated with RULE and store its value with the
1372 * newly pushed state, if FORCEEVAL or if STACK is currently
1373 * unambiguous. Otherwise, store the deferred semantic action with
1374 * the new state. If the new state would have an identical input
1375 * position, LR state, and predecessor to an existing state on the stack,
1376 * it is identified with that existing state, eliminating stack #K from
1377 * the STACK. In this case, the (necessarily deferred) semantic value is
1378 * added to the options for the existing state's semantic value.
1380 static inline YYRESULTTAG
1381 yyglrReduce (yyGLRStack
* yystackp
, size_t yyk
, yyRuleNum yyrule
,
1382 yybool yyforceEval
]b4_user_formals
[)
1384 size_t yyposn
= yystackp
->yytops
.yystates
[yyk
]->yyposn
;
1386 if (yyforceEval
|| yystackp
->yysplitPoint
== YY_NULL
)
1388 YYSTYPE yysval
;]b4_locations_if([
1391 YY_REDUCE_PRINT ((yystackp
, yyk
, yyrule
, &yysval
]b4_locuser_args([&yyloc
])[));
1392 YYCHK (yydoAction (yystackp
, yyk
, yyrule
, &yysval
]b4_locuser_args([&yyloc
])[));
1393 YY_SYMBOL_PRINT ("-> $$ =", yyr1
[yyrule
], &yysval
, &yyloc
);
1394 yyglrShift (yystackp
, yyk
,
1395 yyLRgotoState (yystackp
->yytops
.yystates
[yyk
]->yylrState
,
1396 yylhsNonterm (yyrule
)),
1397 yyposn
, &yysval
]b4_locations_if([, &yyloc
])[);
1403 yyGLRState
* yys
, *yys0
= yystackp
->yytops
.yystates
[yyk
];
1404 yyStateNum yynewLRState
;
1406 for (yys
= yystackp
->yytops
.yystates
[yyk
], yyn
= yyrhsLength (yyrule
);
1412 yyupdateSplit (yystackp
, yys
);
1413 yynewLRState
= yyLRgotoState (yys
->yylrState
, yylhsNonterm (yyrule
));
1415 "Reduced stack %lu by rule #%d; action deferred. Now in state %d.\n",
1416 (unsigned long int) yyk
, yyrule
- 1, yynewLRState
));
1417 for (yyi
= 0; yyi
< yystackp
->yytops
.yysize
; yyi
+= 1)
1418 if (yyi
!= yyk
&& yystackp
->yytops
.yystates
[yyi
] != YY_NULL
)
1420 yyGLRState
*yysplit
= yystackp
->yysplitPoint
;
1421 yyGLRState
*yyp
= yystackp
->yytops
.yystates
[yyi
];
1422 while (yyp
!= yys
&& yyp
!= yysplit
&& yyp
->yyposn
>= yyposn
)
1424 if (yyp
->yylrState
== yynewLRState
&& yyp
->yypred
== yys
)
1426 yyaddDeferredAction (yystackp
, yyk
, yyp
, yys0
, yyrule
);
1427 yymarkStackDeleted (yystackp
, yyk
);
1428 YYDPRINTF ((stderr
, "Merging stack %lu into stack %lu.\n",
1429 (unsigned long int) yyk
,
1430 (unsigned long int) yyi
));
1436 yystackp
->yytops
.yystates
[yyk
] = yys
;
1437 yyglrShiftDefer (yystackp
, yyk
, yynewLRState
, yyposn
, yys0
, yyrule
);
1443 yysplitStack (yyGLRStack
* yystackp
, size_t yyk
)
1445 if (yystackp
->yysplitPoint
== YY_NULL
)
1447 YYASSERT (yyk
== 0);
1448 yystackp
->yysplitPoint
= yystackp
->yytops
.yystates
[yyk
];
1450 if (yystackp
->yytops
.yysize
>= yystackp
->yytops
.yycapacity
)
1452 yyGLRState
** yynewStates
;
1453 yybool
* yynewLookaheadNeeds
;
1455 yynewStates
= YY_NULL
;
1457 if (yystackp
->yytops
.yycapacity
1458 > (YYSIZEMAX
/ (2 * sizeof yynewStates
[0])))
1459 yyMemoryExhausted (yystackp
);
1460 yystackp
->yytops
.yycapacity
*= 2;
1463 (yyGLRState
**) YYREALLOC (yystackp
->yytops
.yystates
,
1464 (yystackp
->yytops
.yycapacity
1465 * sizeof yynewStates
[0]));
1466 if (yynewStates
== YY_NULL
)
1467 yyMemoryExhausted (yystackp
);
1468 yystackp
->yytops
.yystates
= yynewStates
;
1470 yynewLookaheadNeeds
=
1471 (yybool
*) YYREALLOC (yystackp
->yytops
.yylookaheadNeeds
,
1472 (yystackp
->yytops
.yycapacity
1473 * sizeof yynewLookaheadNeeds
[0]));
1474 if (yynewLookaheadNeeds
== YY_NULL
)
1475 yyMemoryExhausted (yystackp
);
1476 yystackp
->yytops
.yylookaheadNeeds
= yynewLookaheadNeeds
;
1478 yystackp
->yytops
.yystates
[yystackp
->yytops
.yysize
]
1479 = yystackp
->yytops
.yystates
[yyk
];
1480 yystackp
->yytops
.yylookaheadNeeds
[yystackp
->yytops
.yysize
]
1481 = yystackp
->yytops
.yylookaheadNeeds
[yyk
];
1482 yystackp
->yytops
.yysize
+= 1;
1483 return yystackp
->yytops
.yysize
-1;
1486 /** True iff Y0 and Y1 represent identical options at the top level.
1487 * That is, they represent the same rule applied to RHS symbols
1488 * that produce the same terminal symbols. */
1490 yyidenticalOptions (yySemanticOption
* yyy0
, yySemanticOption
* yyy1
)
1492 if (yyy0
->yyrule
== yyy1
->yyrule
)
1494 yyGLRState
*yys0
, *yys1
;
1496 for (yys0
= yyy0
->yystate
, yys1
= yyy1
->yystate
,
1497 yyn
= yyrhsLength (yyy0
->yyrule
);
1499 yys0
= yys0
->yypred
, yys1
= yys1
->yypred
, yyn
-= 1)
1500 if (yys0
->yyposn
!= yys1
->yyposn
)
1508 /** Assuming identicalOptions (Y0,Y1), destructively merge the
1509 * alternative semantic values for the RHS-symbols of Y1 and Y0. */
1511 yymergeOptionSets (yySemanticOption
* yyy0
, yySemanticOption
* yyy1
)
1513 yyGLRState
*yys0
, *yys1
;
1515 for (yys0
= yyy0
->yystate
, yys1
= yyy1
->yystate
,
1516 yyn
= yyrhsLength (yyy0
->yyrule
);
1518 yys0
= yys0
->yypred
, yys1
= yys1
->yypred
, yyn
-= 1)
1522 else if (yys0
->yyresolved
)
1524 yys1
->yyresolved
= yytrue
;
1525 yys1
->yysemantics
.yysval
= yys0
->yysemantics
.yysval
;
1527 else if (yys1
->yyresolved
)
1529 yys0
->yyresolved
= yytrue
;
1530 yys0
->yysemantics
.yysval
= yys1
->yysemantics
.yysval
;
1534 yySemanticOption
** yyz0p
= &yys0
->yysemantics
.yyfirstVal
;
1535 yySemanticOption
* yyz1
= yys1
->yysemantics
.yyfirstVal
;
1536 while (YYID (yytrue
))
1538 if (yyz1
== *yyz0p
|| yyz1
== YY_NULL
)
1540 else if (*yyz0p
== YY_NULL
)
1545 else if (*yyz0p
< yyz1
)
1547 yySemanticOption
* yyz
= *yyz0p
;
1549 yyz1
= yyz1
->yynext
;
1550 (*yyz0p
)->yynext
= yyz
;
1552 yyz0p
= &(*yyz0p
)->yynext
;
1554 yys1
->yysemantics
.yyfirstVal
= yys0
->yysemantics
.yyfirstVal
;
1559 /** Y0 and Y1 represent two possible actions to take in a given
1560 * parsing state; return 0 if no combination is possible,
1561 * 1 if user-mergeable, 2 if Y0 is preferred, 3 if Y1 is preferred. */
1563 yypreference (yySemanticOption
* y0
, yySemanticOption
* y1
)
1565 yyRuleNum r0
= y0
->yyrule
, r1
= y1
->yyrule
;
1566 int p0
= yydprec
[r0
], p1
= yydprec
[r1
];
1570 if (yymerger
[r0
] == 0 || yymerger
[r0
] != yymerger
[r1
])
1575 if (p0
== 0 || p1
== 0)
1584 static YYRESULTTAG
yyresolveValue (yyGLRState
* yys
,
1585 yyGLRStack
* yystackp
]b4_user_formals
[);
1588 /** Resolve the previous N states starting at and including state S. If result
1589 * != yyok, some states may have been left unresolved possibly with empty
1590 * semantic option chains. Regardless of whether result = yyok, each state
1591 * has been left with consistent data so that yydestroyGLRState can be invoked
1594 yyresolveStates (yyGLRState
* yys
, int yyn
,
1595 yyGLRStack
* yystackp
]b4_user_formals
[)
1599 YYASSERT (yys
->yypred
);
1600 YYCHK (yyresolveStates (yys
->yypred
, yyn
-1, yystackp
]b4_user_args
[));
1601 if (! yys
->yyresolved
)
1602 YYCHK (yyresolveValue (yys
, yystackp
]b4_user_args
[));
1607 /** Resolve the states for the RHS of OPT, perform its user action, and return
1608 * the semantic value and location. Regardless of whether result = yyok, all
1609 * RHS states have been destroyed (assuming the user action destroys all RHS
1610 * semantic values if invoked). */
1612 yyresolveAction (yySemanticOption
* yyopt
, yyGLRStack
* yystackp
,
1613 YYSTYPE
* yyvalp
]b4_locuser_formals
[)
1615 yyGLRStackItem yyrhsVals
[YYMAXRHS
+ YYMAXLEFT
+ 1];
1616 int yynrhs
= yyrhsLength (yyopt
->yyrule
);
1617 YYRESULTTAG yyflag
=
1618 yyresolveStates (yyopt
->yystate
, yynrhs
, yystackp
]b4_user_args
[);
1622 for (yys
= yyopt
->yystate
; yynrhs
> 0; yys
= yys
->yypred
, yynrhs
-= 1)
1623 yydestroyGLRState ("Cleanup: popping", yys
]b4_user_args
[);
1627 yyrhsVals
[YYMAXRHS
+ YYMAXLEFT
].yystate
.yypred
= yyopt
->yystate
;]b4_locations_if([[
1629 /* Set default location. */
1630 yyrhsVals
[YYMAXRHS
+ YYMAXLEFT
- 1].yystate
.yyloc
= yyopt
->yystate
->yyloc
;]])[
1632 int yychar_current
= yychar
;
1633 YYSTYPE yylval_current
= yylval
;]b4_locations_if([
1634 YYLTYPE yylloc_current
= yylloc
;])[
1635 yychar
= yyopt
->yyrawchar
;
1636 yylval
= yyopt
->yyval
;]b4_locations_if([
1637 yylloc
= yyopt
->yyloc
;])[
1638 yyflag
= yyuserAction (yyopt
->yyrule
, yynrhs
,
1639 yyrhsVals
+ YYMAXRHS
+ YYMAXLEFT
- 1,
1640 yystackp
, yyvalp
]b4_locuser_args
[);
1641 yychar
= yychar_current
;
1642 yylval
= yylval_current
;]b4_locations_if([
1643 yylloc
= yylloc_current
;])[
1648 #if ]b4_api_PREFIX[DEBUG
1650 yyreportTree (yySemanticOption
* yyx
, int yyindent
)
1652 int yynrhs
= yyrhsLength (yyx
->yyrule
);
1655 yyGLRState
* yystates
[1 + YYMAXRHS
];
1656 yyGLRState yyleftmost_state
;
1658 for (yyi
= yynrhs
, yys
= yyx
->yystate
; 0 < yyi
; yyi
-= 1, yys
= yys
->yypred
)
1659 yystates
[yyi
] = yys
;
1662 yyleftmost_state
.yyposn
= 0;
1663 yystates
[0] = &yyleftmost_state
;
1668 if (yyx
->yystate
->yyposn
< yys
->yyposn
+ 1)
1669 YYFPRINTF (stderr
, "%*s%s -> <Rule %d, empty>\n",
1670 yyindent
, "", yytokenName (yylhsNonterm (yyx
->yyrule
)),
1673 YYFPRINTF (stderr
, "%*s%s -> <Rule %d, tokens %lu .. %lu>\n",
1674 yyindent
, "", yytokenName (yylhsNonterm (yyx
->yyrule
)),
1675 yyx
->yyrule
- 1, (unsigned long int) (yys
->yyposn
+ 1),
1676 (unsigned long int) yyx
->yystate
->yyposn
);
1677 for (yyi
= 1; yyi
<= yynrhs
; yyi
+= 1)
1679 if (yystates
[yyi
]->yyresolved
)
1681 if (yystates
[yyi
-1]->yyposn
+1 > yystates
[yyi
]->yyposn
)
1682 YYFPRINTF (stderr
, "%*s%s <empty>\n", yyindent
+2, "",
1683 yytokenName (yyrhs
[yyprhs
[yyx
->yyrule
]+yyi
-1]));
1685 YYFPRINTF (stderr
, "%*s%s <tokens %lu .. %lu>\n", yyindent
+2, "",
1686 yytokenName (yyrhs
[yyprhs
[yyx
->yyrule
]+yyi
-1]),
1687 (unsigned long int) (yystates
[yyi
- 1]->yyposn
+ 1),
1688 (unsigned long int) yystates
[yyi
]->yyposn
);
1691 yyreportTree (yystates
[yyi
]->yysemantics
.yyfirstVal
, yyindent
+2);
1696 /*ARGSUSED*/ static YYRESULTTAG
1697 yyreportAmbiguity (yySemanticOption
* yyx0
,
1698 yySemanticOption
* yyx1
]b4_pure_formals
[)
1703 #if ]b4_api_PREFIX[DEBUG
1704 YYFPRINTF (stderr
, "Ambiguity detected.\n");
1705 YYFPRINTF (stderr
, "Option 1,\n");
1706 yyreportTree (yyx0
, 2);
1707 YYFPRINTF (stderr
, "\nOption 2,\n");
1708 yyreportTree (yyx1
, 2);
1709 YYFPRINTF (stderr
, "\n");
1712 yyerror (]b4_yyerror_args
[YY_("syntax is ambiguous"));
1714 }]b4_locations_if([[
1716 /** Starting at and including state S1, resolve the location for each of the
1717 * previous N1 states that is unresolved. The first semantic option of a state
1718 * is always chosen. */
1720 yyresolveLocations (yyGLRState
* yys1
, int yyn1
,
1721 yyGLRStack
*yystackp
]b4_user_formals
[)
1725 yyresolveLocations (yys1
->yypred
, yyn1
- 1, yystackp
]b4_user_args
[);
1726 if (!yys1
->yyresolved
)
1728 yyGLRStackItem yyrhsloc
[1 + YYMAXRHS
];
1730 yySemanticOption
*yyoption
= yys1
->yysemantics
.yyfirstVal
;
1731 YYASSERT (yyoption
!= YY_NULL
);
1732 yynrhs
= yyrhsLength (yyoption
->yyrule
);
1737 yyresolveLocations (yyoption
->yystate
, yynrhs
,
1738 yystackp
]b4_user_args
[);
1739 for (yys
= yyoption
->yystate
, yyn
= yynrhs
;
1741 yys
= yys
->yypred
, yyn
-= 1)
1742 yyrhsloc
[yyn
].yystate
.yyloc
= yys
->yyloc
;
1746 /* Both yyresolveAction and yyresolveLocations traverse the GSS
1747 in reverse rightmost order. It is only necessary to invoke
1748 yyresolveLocations on a subforest for which yyresolveAction
1749 would have been invoked next had an ambiguity not been
1750 detected. Thus the location of the previous state (but not
1751 necessarily the previous state itself) is guaranteed to be
1752 resolved already. */
1753 yyGLRState
*yyprevious
= yyoption
->yystate
;
1754 yyrhsloc
[0].yystate
.yyloc
= yyprevious
->yyloc
;
1757 int yychar_current
= yychar
;
1758 YYSTYPE yylval_current
= yylval
;
1759 YYLTYPE yylloc_current
= yylloc
;
1760 yychar
= yyoption
->yyrawchar
;
1761 yylval
= yyoption
->yyval
;
1762 yylloc
= yyoption
->yyloc
;
1763 YYLLOC_DEFAULT ((yys1
->yyloc
), yyrhsloc
, yynrhs
);
1764 yychar
= yychar_current
;
1765 yylval
= yylval_current
;
1766 yylloc
= yylloc_current
;
1772 /** Resolve the ambiguity represented in state S, perform the indicated
1773 * actions, and set the semantic value of S. If result != yyok, the chain of
1774 * semantic options in S has been cleared instead or it has been left
1775 * unmodified except that redundant options may have been removed. Regardless
1776 * of whether result = yyok, S has been left with consistent data so that
1777 * yydestroyGLRState can be invoked if necessary. */
1779 yyresolveValue (yyGLRState
* yys
, yyGLRStack
* yystackp
]b4_user_formals
[)
1781 yySemanticOption
* yyoptionList
= yys
->yysemantics
.yyfirstVal
;
1782 yySemanticOption
* yybest
= yyoptionList
;
1783 yySemanticOption
** yypp
;
1784 yybool yymerge
= yyfalse
;
1786 YYRESULTTAG yyflag
;]b4_locations_if([
1787 YYLTYPE
*yylocp
= &yys
->yyloc
;])[
1789 for (yypp
= &yyoptionList
->yynext
; *yypp
!= YY_NULL
; )
1791 yySemanticOption
* yyp
= *yypp
;
1793 if (yyidenticalOptions (yybest
, yyp
))
1795 yymergeOptionSets (yybest
, yyp
);
1796 *yypp
= yyp
->yynext
;
1800 switch (yypreference (yybest
, yyp
))
1802 case 0:]b4_locations_if([[
1803 yyresolveLocations (yys
, 1, yystackp
]b4_user_args
[);]])[
1804 return yyreportAmbiguity (yybest
, yyp
]b4_pure_args
[);
1816 /* This cannot happen so it is not worth a YYASSERT (yyfalse),
1817 but some compilers complain if the default case is
1821 yypp
= &yyp
->yynext
;
1827 yySemanticOption
* yyp
;
1828 int yyprec
= yydprec
[yybest
->yyrule
];
1829 yyflag
= yyresolveAction (yybest
, yystackp
, &yysval
]b4_locuser_args
[);
1831 for (yyp
= yybest
->yynext
; yyp
!= YY_NULL
; yyp
= yyp
->yynext
)
1833 if (yyprec
== yydprec
[yyp
->yyrule
])
1835 YYSTYPE yysval_other
;]b4_locations_if([
1837 yyflag
= yyresolveAction (yyp
, yystackp
, &yysval_other
]b4_locuser_args([&yydummy
])[);
1840 yydestruct ("Cleanup: discarding incompletely merged value for",
1841 yystos
[yys
->yylrState
],
1842 &yysval
]b4_locuser_args
[);
1845 yyuserMerge (yymerger
[yyp
->yyrule
], &yysval
, &yysval_other
);
1850 yyflag
= yyresolveAction (yybest
, yystackp
, &yysval
]b4_locuser_args([yylocp
])[);
1854 yys
->yyresolved
= yytrue
;
1855 yys
->yysemantics
.yysval
= yysval
;
1858 yys
->yysemantics
.yyfirstVal
= YY_NULL
;
1863 yyresolveStack (yyGLRStack
* yystackp
]b4_user_formals
[)
1865 if (yystackp
->yysplitPoint
!= YY_NULL
)
1870 for (yyn
= 0, yys
= yystackp
->yytops
.yystates
[0];
1871 yys
!= yystackp
->yysplitPoint
;
1872 yys
= yys
->yypred
, yyn
+= 1)
1874 YYCHK (yyresolveStates (yystackp
->yytops
.yystates
[0], yyn
, yystackp
1881 yycompressStack (yyGLRStack
* yystackp
)
1883 yyGLRState
* yyp
, *yyq
, *yyr
;
1885 if (yystackp
->yytops
.yysize
!= 1 || yystackp
->yysplitPoint
== YY_NULL
)
1888 for (yyp
= yystackp
->yytops
.yystates
[0], yyq
= yyp
->yypred
, yyr
= YY_NULL
;
1889 yyp
!= yystackp
->yysplitPoint
;
1890 yyr
= yyp
, yyp
= yyq
, yyq
= yyp
->yypred
)
1893 yystackp
->yyspaceLeft
+= yystackp
->yynextFree
- yystackp
->yyitems
;
1894 yystackp
->yynextFree
= ((yyGLRStackItem
*) yystackp
->yysplitPoint
) + 1;
1895 yystackp
->yyspaceLeft
-= yystackp
->yynextFree
- yystackp
->yyitems
;
1896 yystackp
->yysplitPoint
= YY_NULL
;
1897 yystackp
->yylastDeleted
= YY_NULL
;
1899 while (yyr
!= YY_NULL
)
1901 yystackp
->yynextFree
->yystate
= *yyr
;
1903 yystackp
->yynextFree
->yystate
.yypred
= &yystackp
->yynextFree
[-1].yystate
;
1904 yystackp
->yytops
.yystates
[0] = &yystackp
->yynextFree
->yystate
;
1905 yystackp
->yynextFree
+= 1;
1906 yystackp
->yyspaceLeft
-= 1;
1911 yyprocessOneStack (yyGLRStack
* yystackp
, size_t yyk
,
1912 size_t yyposn
]b4_pure_formals
[)
1915 const short int* yyconflicts
;
1918 while (yystackp
->yytops
.yystates
[yyk
] != YY_NULL
)
1920 yyStateNum yystate
= yystackp
->yytops
.yystates
[yyk
]->yylrState
;
1921 YYDPRINTF ((stderr
, "Stack %lu Entering state %d\n",
1922 (unsigned long int) yyk
, yystate
));
1924 YYASSERT (yystate
!= YYFINAL
);
1926 if (yyisDefaultedState (yystate
))
1928 yyrule
= yydefaultAction (yystate
);
1931 YYDPRINTF ((stderr
, "Stack %lu dies.\n",
1932 (unsigned long int) yyk
));
1933 yymarkStackDeleted (yystackp
, yyk
);
1936 YYCHK (yyglrReduce (yystackp
, yyk
, yyrule
, yyfalse
]b4_user_args
[));
1941 yystackp
->yytops
.yylookaheadNeeds
[yyk
] = yytrue
;
1942 if (yychar
== YYEMPTY
)
1944 YYDPRINTF ((stderr
, "Reading a token: "));
1948 if (yychar
<= YYEOF
)
1950 yychar
= yytoken
= YYEOF
;
1951 YYDPRINTF ((stderr
, "Now at end of input.\n"));
1955 yytoken
= YYTRANSLATE (yychar
);
1956 YY_SYMBOL_PRINT ("Next token is", yytoken
, &yylval
, &yylloc
);
1959 yygetLRActions (yystate
, yytoken
, &yyaction
, &yyconflicts
);
1961 while (*yyconflicts
!= 0)
1963 size_t yynewStack
= yysplitStack (yystackp
, yyk
);
1964 YYDPRINTF ((stderr
, "Splitting off stack %lu from %lu.\n",
1965 (unsigned long int) yynewStack
,
1966 (unsigned long int) yyk
));
1967 YYCHK (yyglrReduce (yystackp
, yynewStack
,
1968 *yyconflicts
, yyfalse
]b4_user_args
[));
1969 YYCHK (yyprocessOneStack (yystackp
, yynewStack
,
1970 yyposn
]b4_pure_args
[));
1974 if (yyisShiftAction (yyaction
))
1976 else if (yyisErrorAction (yyaction
))
1978 YYDPRINTF ((stderr
, "Stack %lu dies.\n",
1979 (unsigned long int) yyk
));
1980 yymarkStackDeleted (yystackp
, yyk
);
1984 YYCHK (yyglrReduce (yystackp
, yyk
, -yyaction
,
1985 yyfalse
]b4_user_args
[));
1991 /*ARGSUSED*/ static void
1992 yyreportSyntaxError (yyGLRStack
* yystackp
]b4_user_formals
[)
1994 if (yystackp
->yyerrState
!= 0)
1996 #if ! YYERROR_VERBOSE
1997 yyerror (]b4_lyyerror_args
[YY_("syntax error"));
2000 yySymbol yytoken
= yychar
== YYEMPTY
? YYEMPTY
: YYTRANSLATE (yychar
);
2001 size_t yysize0
= yytnamerr (YY_NULL
, yytokenName (yytoken
));
2002 size_t yysize
= yysize0
;
2003 yybool yysize_overflow
= yyfalse
;
2004 char* yymsg
= YY_NULL
;
2005 enum { YYERROR_VERBOSE_ARGS_MAXIMUM
= 5 };
2006 /* Internationalized format string. */
2007 const char *yyformat
= YY_NULL
;
2008 /* Arguments of yyformat. */
2009 char const *yyarg
[YYERROR_VERBOSE_ARGS_MAXIMUM
];
2010 /* Number of reported tokens (one for the "unexpected", one per
2014 /* There are many possibilities here to consider:
2015 - If this state is a consistent state with a default action, then
2016 the only way this function was invoked is if the default action
2017 is an error action. In that case, don't check for expected
2018 tokens because there are none.
2019 - The only way there can be no lookahead present (in yychar) is if
2020 this state is a consistent state with a default action. Thus,
2021 detecting the absence of a lookahead is sufficient to determine
2022 that there is no unexpected or expected token to report. In that
2023 case, just report a simple "syntax error".
2024 - Don't assume there isn't a lookahead just because this state is a
2025 consistent state with a default action. There might have been a
2026 previous inconsistent state, consistent state with a non-default
2027 action, or user semantic action that manipulated yychar.
2028 - Of course, the expected token list depends on states to have
2029 correct lookahead information, and it depends on the parser not
2030 to perform extra reductions after fetching a lookahead from the
2031 scanner and before detecting a syntax error. Thus, state merging
2032 (from LALR or IELR) and default reductions corrupt the expected
2033 token list. However, the list is correct for canonical LR with
2034 one exception: it will still contain any token that will not be
2035 accepted due to an error action in a later state.
2037 if (yytoken
!= YYEMPTY
)
2039 int yyn
= yypact
[yystackp
->yytops
.yystates
[0]->yylrState
];
2040 yyarg
[yycount
++] = yytokenName (yytoken
);
2041 if (!yypact_value_is_default (yyn
))
2043 /* Start YYX at -YYN if negative to avoid negative indexes in
2044 YYCHECK. In other words, skip the first -YYN actions for this
2045 state because they are default actions. */
2046 int yyxbegin
= yyn
< 0 ? -yyn
: 0;
2047 /* Stay within bounds of both yycheck and yytname. */
2048 int yychecklim
= YYLAST
- yyn
+ 1;
2049 int yyxend
= yychecklim
< YYNTOKENS
? yychecklim
: YYNTOKENS
;
2051 for (yyx
= yyxbegin
; yyx
< yyxend
; ++yyx
)
2052 if (yycheck
[yyx
+ yyn
] == yyx
&& yyx
!= YYTERROR
2053 && !yytable_value_is_error (yytable
[yyx
+ yyn
]))
2055 if (yycount
== YYERROR_VERBOSE_ARGS_MAXIMUM
)
2061 yyarg
[yycount
++] = yytokenName (yyx
);
2063 size_t yysz
= yysize
+ yytnamerr (YY_NULL
, yytokenName (yyx
));
2064 yysize_overflow
|= yysz
< yysize
;
2073 #define YYCASE_(N, S) \
2077 YYCASE_(0, YY_("syntax error"));
2078 YYCASE_(1, YY_("syntax error, unexpected %s"));
2079 YYCASE_(2, YY_("syntax error, unexpected %s, expecting %s"));
2080 YYCASE_(3, YY_("syntax error, unexpected %s, expecting %s or %s"));
2081 YYCASE_(4, YY_("syntax error, unexpected %s, expecting %s or %s or %s"));
2082 YYCASE_(5, YY_("syntax error, unexpected %s, expecting %s or %s or %s or %s"));
2087 size_t yysz
= yysize
+ strlen (yyformat
);
2088 yysize_overflow
|= yysz
< yysize
;
2092 if (!yysize_overflow
)
2093 yymsg
= (char *) YYMALLOC (yysize
);
2099 while ((*yyp
= *yyformat
))
2101 if (*yyp
== '%' && yyformat
[1] == 's' && yyi
< yycount
)
2103 yyp
+= yytnamerr (yyp
, yyarg
[yyi
++]);
2112 yyerror (]b4_lyyerror_args
[yymsg
);
2117 yyerror (]b4_lyyerror_args
[YY_("syntax error"));
2118 yyMemoryExhausted (yystackp
);
2121 #endif /* YYERROR_VERBOSE */
2125 /* Recover from a syntax error on *YYSTACKP, assuming that *YYSTACKP->YYTOKENP,
2126 yylval, and yylloc are the syntactic category, semantic value, and location
2127 of the lookahead. */
2128 /*ARGSUSED*/ static void
2129 yyrecoverSyntaxError (yyGLRStack
* yystackp
]b4_user_formals
[)
2134 if (yystackp
->yyerrState
== 3)
2135 /* We just shifted the error token and (perhaps) took some
2136 reductions. Skip tokens until we can proceed. */
2137 while (YYID (yytrue
))
2140 if (yychar
== YYEOF
)
2141 yyFail (yystackp
][]b4_lpure_args
[, YY_NULL
);
2142 if (yychar
!= YYEMPTY
)
2143 {]b4_locations_if([[
2144 /* We throw away the lookahead, but the error range
2145 of the shifted error token must take it into account. */
2146 yyGLRState
*yys
= yystackp
->yytops
.yystates
[0];
2147 yyGLRStackItem yyerror_range
[3];
2148 yyerror_range
[1].yystate
.yyloc
= yys
->yyloc
;
2149 yyerror_range
[2].yystate
.yyloc
= yylloc
;
2150 YYLLOC_DEFAULT ((yys
->yyloc
), yyerror_range
, 2);]])[
2151 yytoken
= YYTRANSLATE (yychar
);
2152 yydestruct ("Error: discarding",
2153 yytoken
, &yylval
]b4_locuser_args([&yylloc
])[);
2155 YYDPRINTF ((stderr
, "Reading a token: "));
2157 if (yychar
<= YYEOF
)
2159 yychar
= yytoken
= YYEOF
;
2160 YYDPRINTF ((stderr
, "Now at end of input.\n"));
2164 yytoken
= YYTRANSLATE (yychar
);
2165 YY_SYMBOL_PRINT ("Next token is", yytoken
, &yylval
, &yylloc
);
2167 yyj
= yypact
[yystackp
->yytops
.yystates
[0]->yylrState
];
2168 if (yypact_value_is_default (yyj
))
2171 if (yyj
< 0 || YYLAST
< yyj
|| yycheck
[yyj
] != yytoken
)
2173 if (yydefact
[yystackp
->yytops
.yystates
[0]->yylrState
] != 0)
2176 else if (! yytable_value_is_error (yytable
[yyj
]))
2180 /* Reduce to one stack. */
2181 for (yyk
= 0; yyk
< yystackp
->yytops
.yysize
; yyk
+= 1)
2182 if (yystackp
->yytops
.yystates
[yyk
] != YY_NULL
)
2184 if (yyk
>= yystackp
->yytops
.yysize
)
2185 yyFail (yystackp
][]b4_lpure_args
[, YY_NULL
);
2186 for (yyk
+= 1; yyk
< yystackp
->yytops
.yysize
; yyk
+= 1)
2187 yymarkStackDeleted (yystackp
, yyk
);
2188 yyremoveDeletes (yystackp
);
2189 yycompressStack (yystackp
);
2191 /* Now pop stack until we find a state that shifts the error token. */
2192 yystackp
->yyerrState
= 3;
2193 while (yystackp
->yytops
.yystates
[0] != YY_NULL
)
2195 yyGLRState
*yys
= yystackp
->yytops
.yystates
[0];
2196 yyj
= yypact
[yys
->yylrState
];
2197 if (! yypact_value_is_default (yyj
))
2200 if (0 <= yyj
&& yyj
<= YYLAST
&& yycheck
[yyj
] == YYTERROR
2201 && yyisShiftAction (yytable
[yyj
]))
2203 /* Shift the error token. */]b4_locations_if([[
2204 /* First adjust its location.*/
2206 yystackp
->yyerror_range
[2].yystate
.yyloc
= yylloc
;
2207 YYLLOC_DEFAULT (yyerrloc
, (yystackp
->yyerror_range
), 2);]])[
2208 YY_SYMBOL_PRINT ("Shifting", yystos
[yytable
[yyj
]],
2209 &yylval
, &yyerrloc
);
2210 yyglrShift (yystackp
, 0, yytable
[yyj
],
2211 yys
->yyposn
, &yylval
]b4_locations_if([, &yyerrloc
])[);
2212 yys
= yystackp
->yytops
.yystates
[0];
2215 }]b4_locations_if([[
2216 yystackp
->yyerror_range
[1].yystate
.yyloc
= yys
->yyloc
;]])[
2217 if (yys
->yypred
!= YY_NULL
)
2218 yydestroyGLRState ("Error: popping", yys
]b4_user_args
[);
2219 yystackp
->yytops
.yystates
[0] = yys
->yypred
;
2220 yystackp
->yynextFree
-= 1;
2221 yystackp
->yyspaceLeft
+= 1;
2223 if (yystackp
->yytops
.yystates
[0] == YY_NULL
)
2224 yyFail (yystackp
][]b4_lpure_args
[, YY_NULL
);
2227 #define YYCHK1(YYE) \
2237 goto yyuser_error; \
2248 ]b4_c_ansi_function_def([yyparse
], [int], b4_parse_param
)[
2252 yyGLRStack
* const yystackp
= &yystack
;
2255 YYDPRINTF ((stderr
, "Starting parse\n"));
2258 yylval
= yyval_default
;]b4_locations_if([
2259 yylloc
= yyloc_default
;])[
2260 ]m4_ifdef([b4_initial_action
], [
2261 b4_dollar_pushdef([yylval
], [], [yylloc
])dnl
2262 /* User initialization code. */
2263 b4_user_initial_action
2264 b4_dollar_popdef
])[]dnl
2266 if (! yyinitGLRStack (yystackp
, YYINITDEPTH
))
2267 goto yyexhaustedlab
;
2268 switch (YYSETJMP (yystack
.yyexception_buffer
))
2271 case 1: goto yyabortlab
;
2272 case 2: goto yyexhaustedlab
;
2273 default: goto yybuglab
;
2275 yyglrShift (&yystack
, 0, 0, 0, &yylval
]b4_locations_if([, &yylloc
])[);
2278 while (YYID (yytrue
))
2280 /* For efficiency, we have two loops, the first of which is
2281 specialized to deterministic operation (single stack, no
2282 potential ambiguity). */
2284 while (YYID (yytrue
))
2288 const short int* yyconflicts
;
2290 yyStateNum yystate
= yystack
.yytops
.yystates
[0]->yylrState
;
2291 YYDPRINTF ((stderr
, "Entering state %d\n", yystate
));
2292 if (yystate
== YYFINAL
)
2294 if (yyisDefaultedState (yystate
))
2296 yyrule
= yydefaultAction (yystate
);
2299 ]b4_locations_if([[ yystack
.yyerror_range
[1].yystate
.yyloc
= yylloc
;]])[
2300 yyreportSyntaxError (&yystack
]b4_user_args
[);
2303 YYCHK1 (yyglrReduce (&yystack
, 0, yyrule
, yytrue
]b4_user_args
[));
2308 if (yychar
== YYEMPTY
)
2310 YYDPRINTF ((stderr
, "Reading a token: "));
2314 if (yychar
<= YYEOF
)
2316 yychar
= yytoken
= YYEOF
;
2317 YYDPRINTF ((stderr
, "Now at end of input.\n"));
2321 yytoken
= YYTRANSLATE (yychar
);
2322 YY_SYMBOL_PRINT ("Next token is", yytoken
, &yylval
, &yylloc
);
2325 yygetLRActions (yystate
, yytoken
, &yyaction
, &yyconflicts
);
2326 if (*yyconflicts
!= 0)
2328 if (yyisShiftAction (yyaction
))
2330 YY_SYMBOL_PRINT ("Shifting", yytoken
, &yylval
, &yylloc
);
2333 yyglrShift (&yystack
, 0, yyaction
, yyposn
, &yylval
]b4_locations_if([, &yylloc
])[);
2334 if (0 < yystack
.yyerrState
)
2335 yystack
.yyerrState
-= 1;
2337 else if (yyisErrorAction (yyaction
))
2339 ]b4_locations_if([[ yystack
.yyerror_range
[1].yystate
.yyloc
= yylloc
;]])[
2340 yyreportSyntaxError (&yystack
]b4_user_args
[);
2344 YYCHK1 (yyglrReduce (&yystack
, 0, -yyaction
, yytrue
]b4_user_args
[));
2348 while (YYID (yytrue
))
2350 yySymbol yytoken_to_shift
;
2353 for (yys
= 0; yys
< yystack
.yytops
.yysize
; yys
+= 1)
2354 yystackp
->yytops
.yylookaheadNeeds
[yys
] = yychar
!= YYEMPTY
;
2356 /* yyprocessOneStack returns one of three things:
2358 - An error flag. If the caller is yyprocessOneStack, it
2359 immediately returns as well. When the caller is finally
2360 yyparse, it jumps to an error label via YYCHK1.
2362 - yyok, but yyprocessOneStack has invoked yymarkStackDeleted
2363 (&yystack, yys), which sets the top state of yys to NULL. Thus,
2364 yyparse's following invocation of yyremoveDeletes will remove
2367 - yyok, when ready to shift a token.
2369 Except in the first case, yyparse will invoke yyremoveDeletes and
2370 then shift the next token onto all remaining stacks. This
2371 synchronization of the shift (that is, after all preceding
2372 reductions on all stacks) helps prevent double destructor calls
2373 on yylval in the event of memory exhaustion. */
2375 for (yys
= 0; yys
< yystack
.yytops
.yysize
; yys
+= 1)
2376 YYCHK1 (yyprocessOneStack (&yystack
, yys
, yyposn
]b4_lpure_args
[));
2377 yyremoveDeletes (&yystack
);
2378 if (yystack
.yytops
.yysize
== 0)
2380 yyundeleteLastStack (&yystack
);
2381 if (yystack
.yytops
.yysize
== 0)
2382 yyFail (&yystack
][]b4_lpure_args
[, YY_("syntax error"));
2383 YYCHK1 (yyresolveStack (&yystack
]b4_user_args
[));
2384 YYDPRINTF ((stderr
, "Returning to deterministic operation.\n"));
2385 ]b4_locations_if([[ yystack
.yyerror_range
[1].yystate
.yyloc
= yylloc
;]])[
2386 yyreportSyntaxError (&yystack
]b4_user_args
[);
2390 /* If any yyglrShift call fails, it will fail after shifting. Thus,
2391 a copy of yylval will already be on stack 0 in the event of a
2392 failure in the following loop. Thus, yychar is set to YYEMPTY
2393 before the loop to make sure the user destructor for yylval isn't
2395 yytoken_to_shift
= YYTRANSLATE (yychar
);
2398 for (yys
= 0; yys
< yystack
.yytops
.yysize
; yys
+= 1)
2401 const short int* yyconflicts
;
2402 yyStateNum yystate
= yystack
.yytops
.yystates
[yys
]->yylrState
;
2403 yygetLRActions (yystate
, yytoken_to_shift
, &yyaction
,
2405 /* Note that yyconflicts were handled by yyprocessOneStack. */
2406 YYDPRINTF ((stderr
, "On stack %lu, ", (unsigned long int) yys
));
2407 YY_SYMBOL_PRINT ("shifting", yytoken_to_shift
, &yylval
, &yylloc
);
2408 yyglrShift (&yystack
, yys
, yyaction
, yyposn
,
2409 &yylval
]b4_locations_if([, &yylloc
])[);
2410 YYDPRINTF ((stderr
, "Stack %lu now in state #%d\n",
2411 (unsigned long int) yys
,
2412 yystack
.yytops
.yystates
[yys
]->yylrState
));
2415 if (yystack
.yytops
.yysize
== 1)
2417 YYCHK1 (yyresolveStack (&yystack
]b4_user_args
[));
2418 YYDPRINTF ((stderr
, "Returning to deterministic operation.\n"));
2419 yycompressStack (&yystack
);
2425 yyrecoverSyntaxError (&yystack
]b4_user_args
[);
2426 yyposn
= yystack
.yytops
.yystates
[0]->yyposn
;
2442 yyerror (]b4_lyyerror_args
[YY_("memory exhausted"));
2447 if (yychar
!= YYEMPTY
)
2448 yydestruct ("Cleanup: discarding lookahead",
2449 YYTRANSLATE (yychar
), &yylval
]b4_locuser_args([&yylloc
])[);
2451 /* If the stack is well-formed, pop the stack until it is empty,
2452 destroying its entries as we go. But free the stack regardless
2453 of whether it is well-formed. */
2454 if (yystack
.yyitems
)
2456 yyGLRState
** yystates
= yystack
.yytops
.yystates
;
2459 size_t yysize
= yystack
.yytops
.yysize
;
2461 for (yyk
= 0; yyk
< yysize
; yyk
+= 1)
2464 while (yystates
[yyk
])
2466 yyGLRState
*yys
= yystates
[yyk
];
2467 ]b4_locations_if([[ yystack
.yyerror_range
[1].yystate
.yyloc
= yys
->yyloc
;]]
2468 )[ if (yys
->yypred
!= YY_NULL
)
2469 yydestroyGLRState ("Cleanup: popping", yys
]b4_user_args
[);
2470 yystates
[yyk
] = yys
->yypred
;
2471 yystack
.yynextFree
-= 1;
2472 yystack
.yyspaceLeft
+= 1;
2477 yyfreeGLRStack (&yystack
);
2480 /* Make sure YYID is used. */
2481 return YYID (yyresult
);
2484 /* DEBUGGING ONLY */
2485 #if ]b4_api_PREFIX[DEBUG
2486 static void yypstack (yyGLRStack
* yystackp
, size_t yyk
)
2487 __attribute__ ((__unused__
));
2488 static void yypdumpstack (yyGLRStack
* yystackp
) __attribute__ ((__unused__
));
2491 yy_yypstack (yyGLRState
* yys
)
2495 yy_yypstack (yys
->yypred
);
2496 YYFPRINTF (stderr
, " -> ");
2498 YYFPRINTF (stderr
, "%d@@%lu", yys
->yylrState
,
2499 (unsigned long int) yys
->yyposn
);
2503 yypstates (yyGLRState
* yyst
)
2505 if (yyst
== YY_NULL
)
2506 YYFPRINTF (stderr
, "<null>");
2509 YYFPRINTF (stderr
, "\n");
2513 yypstack (yyGLRStack
* yystackp
, size_t yyk
)
2515 yypstates (yystackp
->yytops
.yystates
[yyk
]);
2518 #define YYINDEX(YYX) \
2519 ((YYX) == YY_NULL ? -1 : (yyGLRStackItem*) (YYX) - yystackp->yyitems)
2523 yypdumpstack (yyGLRStack
* yystackp
)
2525 yyGLRStackItem
* yyp
;
2527 for (yyp
= yystackp
->yyitems
; yyp
< yystackp
->yynextFree
; yyp
+= 1)
2529 YYFPRINTF (stderr
, "%3lu. ",
2530 (unsigned long int) (yyp
- yystackp
->yyitems
));
2531 if (*(yybool
*) yyp
)
2533 YYFPRINTF (stderr
, "Res: %d, LR State: %d, posn: %lu, pred: %ld",
2534 yyp
->yystate
.yyresolved
, yyp
->yystate
.yylrState
,
2535 (unsigned long int) yyp
->yystate
.yyposn
,
2536 (long int) YYINDEX (yyp
->yystate
.yypred
));
2537 if (! yyp
->yystate
.yyresolved
)
2538 YYFPRINTF (stderr
, ", firstVal: %ld",
2539 (long int) YYINDEX (yyp
->yystate
2540 .yysemantics
.yyfirstVal
));
2544 YYFPRINTF (stderr
, "Option. rule: %d, state: %ld, next: %ld",
2545 yyp
->yyoption
.yyrule
- 1,
2546 (long int) YYINDEX (yyp
->yyoption
.yystate
),
2547 (long int) YYINDEX (yyp
->yyoption
.yynext
));
2549 YYFPRINTF (stderr
, "\n");
2551 YYFPRINTF (stderr
, "Tops:");
2552 for (yyi
= 0; yyi
< yystackp
->yytops
.yysize
; yyi
+= 1)
2553 YYFPRINTF (stderr
, "%lu: %ld; ", (unsigned long int) yyi
,
2554 (long int) YYINDEX (yystackp
->yytops
.yystates
[yyi
]));
2555 YYFPRINTF (stderr
, "\n");
2561 # glr.cc produces its own header.
2562 m4_if(b4_skeleton
, ["glr.c"],
2564 [b4_output_begin([b4_spec_defines_file
])
2565 b4_copyright([Skeleton interface
for Bison GLR parsers in C
],
2568 ]b4_cpp_guard_open([b4_spec_defines_file
])[
2569 ]b4_shared_declarations
[
2570 ]b4_cpp_guard_close([b4_spec_defines_file
])[