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 [b4_symbol_value([(*yyvalp
)], [$
1])])
132 # b4_rhs_data(RULE-LENGTH, NUM)
133 # -----------------------------
134 # Expand to the semantic stack place that contains value and location
135 # of symbol number NUM in a rule of length RULE-LENGTH.
136 m4_define([b4_rhs_data
],
137 [((yyGLRStackItem
const *)yyvsp
)@
{YYFILL (b4_subtract([$
2], [$
1]))@
}.yystate
])
140 # b4_rhs_value(RULE-LENGTH, NUM, [TYPE])
141 # --------------------------------------
142 # Expansion of $<TYPE>NUM, where the current rule has RULE-LENGTH
144 m4_define([b4_rhs_value
],
145 [b4_symbol_value([b4_rhs_data([$
1], [$
2]).yysemantics
.yysval
], [$
3])])
156 m4_define([b4_lhs_location
],
160 # b4_rhs_location(RULE-LENGTH, NUM)
161 # ---------------------------------
162 # Expansion of @NUM, where the current rule has RULE-LENGTH symbols
164 m4_define([b4_rhs_location
],
165 [(b4_rhs_data([$
1], [$
2]).yyloc
)])
172 # b4_shared_declarations
173 # ----------------------
174 # Declaration that might either go into the header (if --defines)
175 # or open coded in the parser body.
176 m4_define([b4_shared_declarations
],
178 ]b4_percent_code_get([[requires]])[
179 ]b4_token_enums(b4_tokens
)[
180 ]b4_declare_yylstype
[
181 ]b4_c_ansi_function_decl(b4_prefix
[parse
], [int], b4_parse_param
)[
182 ]b4_percent_code_get([[provides]])[]dnl
190 # We do want M4 expansion after # for CPP macros.
193 @
output(b4_parser_file_name@
)@
194 b4_copyright([Skeleton implementation
for Bison GLR parsers in C
],
197 /* C GLR parser skeleton written by Paul Hilfinger. */
201 b4_percent_code_get([[top]])[
202 ]m4_if(b4_api_prefix
, [yy
], [],
203 [[/* Substitute the type names. */
204 #define YYSTYPE ]b4_api_PREFIX[STYPE]b4_locations_if([[
205 #define YYLTYPE ]b4_api_PREFIX[LTYPE]])])[
206 ]m4_if(b4_prefix
, [yy
], [],
207 [[/* Substitute the variable and function names. */
208 #define yyparse ]b4_prefix[parse
209 #define yylex ]b4_prefix[lex
210 #define yyerror ]b4_prefix[error
211 #define yylval ]b4_prefix[lval
212 #define yychar ]b4_prefix[char
213 #define yydebug ]b4_prefix[debug
214 #define yynerrs ]b4_prefix[nerrs]b4_locations_if([[
215 #define yylloc ]b4_prefix[lloc]])])[
217 /* Copy the first part of user declarations. */
218 ]b4_user_pre_prologue
[
222 ]b4_defines_if([[#include "@basename(]b4_spec_defines_file[@)"]],
223 [b4_shared_declarations
])[
225 /* Enabling verbose error messages. */
226 #ifdef YYERROR_VERBOSE
227 # undef YYERROR_VERBOSE
228 # define YYERROR_VERBOSE 1
230 # define YYERROR_VERBOSE ]b4_error_verbose_if([1], [0])[
233 /* Default (constant) value used for initialization for null
234 right-hand sides. Unlike the standard yacc.c template,
235 here we set the default value of $$ to a zeroed-out value.
236 Since the default value is undefined, this behavior is
237 technically correct. */
238 static YYSTYPE yyval_default
;
240 /* Copy the second part of user declarations. */
241 ]b4_user_post_prologue
242 b4_percent_code_get
[]dnl
249 # if defined YYENABLE_NLS && YYENABLE_NLS
251 # include <libintl.h> /* INFRINGES ON USER NAME SPACE */
252 # define YY_(msgid) dgettext ("bison-runtime", msgid)
256 # define YY_(msgid) msgid
260 /* Suppress unused-variable warnings by "using" E. */
261 #if ! defined lint || defined __GNUC__
262 # define YYUSE(e) ((void) (e))
264 # define YYUSE(e) /* empty */
267 /* Identity function, used to suppress warnings about constant conditions. */
271 ]b4_c_function_def([YYID
], [static int], [[int i
], [i
]])[
281 # define YYMALLOC malloc
284 # define YYREALLOC realloc
287 #define YYSIZEMAX ((size_t) -1)
292 typedef unsigned char yybool
;
299 # define YYJMP_BUF jmp_buf
300 # define YYSETJMP(env) setjmp (env)
301 # define YYLONGJMP(env, val) longjmp (env, val)
308 #ifndef __attribute__
309 /* This feature is available in gcc versions 2.5 and later. */
310 # if (! defined __GNUC__ || __GNUC__ < 2 \
311 || (__GNUC__ == 2 && __GNUC_MINOR__ < 5))
312 # define __attribute__(Spec) /* empty */
316 ]b4_locations_if([#define YYOPTIONAL_LOC(Name) Name],[
318 # define YYOPTIONAL_LOC(Name) /* empty */
320 # define YYOPTIONAL_LOC(Name) Name __attribute__ ((__unused__))
324 # define YYASSERT(condition) ((void) ((condition) || (abort (), 0)))
327 /* YYFINAL -- State number of the termination state. */
328 #define YYFINAL ]b4_final_state_number[
329 /* YYLAST -- Last index in YYTABLE. */
330 #define YYLAST ]b4_last[
332 /* YYNTOKENS -- Number of terminals. */
333 #define YYNTOKENS ]b4_tokens_number[
334 /* YYNNTS -- Number of nonterminals. */
335 #define YYNNTS ]b4_nterms_number[
336 /* YYNRULES -- Number of rules. */
337 #define YYNRULES ]b4_rules_number[
338 /* YYNRULES -- Number of states. */
339 #define YYNSTATES ]b4_states_number[
340 /* YYMAXRHS -- Maximum number of symbols on right-hand side of rule. */
341 #define YYMAXRHS ]b4_r2_max[
342 /* YYMAXLEFT -- Maximum number of symbols to the left of a handle
343 accessed by $0, $-1, etc., in any rule. */
344 #define YYMAXLEFT ]b4_max_left_semantic_context[
346 /* YYTRANSLATE(X) -- Bison symbol number corresponding to X. */
347 #define YYUNDEFTOK ]b4_undef_token_number[
348 #define YYMAXUTOK ]b4_user_token_number_max[
350 #define YYTRANSLATE(YYX) \
351 ((unsigned int) (YYX) <= YYMAXUTOK ? yytranslate[YYX] : YYUNDEFTOK)
353 /* YYTRANSLATE[YYLEX] -- Bison symbol number corresponding to YYLEX. */
354 static const ]b4_int_type_for([b4_translate
])[ yytranslate
[] =
359 #if ]b4_api_PREFIX[DEBUG
360 /* YYRLINE[YYN] -- source line where rule number YYN was defined. */
361 static const ]b4_int_type_for([b4_rline
])[ yyrline
[] =
367 #if ]b4_api_PREFIX[DEBUG || YYERROR_VERBOSE || ]b4_token_table_flag[
368 /* YYTNAME[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM.
369 First, the terminals, then, starting at YYNTOKENS, nonterminals. */
370 static const char *const yytname
[] =
376 #define YYPACT_NINF ]b4_pact_ninf[
377 #define YYTABLE_NINF ]b4_table_ninf[
379 ]b4_parser_tables_define
[
381 /* YYDPREC[RULE-NUM] -- Dynamic precedence of rule #RULE-NUM (0 if none). */
382 static const ]b4_int_type_for([b4_dprec
])[ yydprec
[] =
387 /* YYMERGER[RULE-NUM] -- Index of merging function for rule #RULE-NUM. */
388 static const ]b4_int_type_for([b4_merger
])[ yymerger
[] =
393 /* YYIMMEDIATE[RULE-NUM] -- True iff rule #RULE-NUM is not to be deferred, as
394 in the case of predicates. */
395 static const yybool yyimmediate
[] =
400 /* YYCONFLP[YYPACT[STATE-NUM]] -- Pointer into YYCONFL of start of
401 list of conflicting reductions corresponding to action entry for
402 state STATE-NUM in yytable. 0 means no conflicts. The list in
403 yyconfl is terminated by a rule number of 0. */
404 static const ]b4_int_type_for([b4_conflict_list_heads
])[ yyconflp
[] =
406 ]b4_conflict_list_heads
[
409 /* YYCONFL[I] -- lists of conflicting rule numbers, each terminated by
410 0, pointed into by YYCONFLP. */
411 ]dnl Do
not use b4_int_type_for here
, since there are places where
412 dnl pointers onto yyconfl are taken
, which type is
"short int *".
413 dnl We probably ought to introduce a type
for confl
.
414 [static const short int yyconfl
[] =
416 ]b4_conflicting_rules
[
419 /* Error token number */
423 #ifndef YYLLOC_DEFAULT
424 ]b4_yylloc_default_define
[
425 # define YYRHSLOC(Rhs, K) ((Rhs)[K].yystate.yyloc)
427 /* YY_LOCATION_PRINT -- Print the location on the stream.
428 This macro was not mandated originally: define only if we know
429 we won't break user code: when these are the locations we know. */
431 # define YY_LOCATION_PRINT(File, Loc) \
432 fprintf (File, "%d.%d-%d.%d", \
433 (Loc).first_line, (Loc).first_column, \
434 (Loc).last_line, (Loc).last_column)
437 #ifndef YYLLOC_DEFAULT
438 # define YYLLOC_DEFAULT(Current, Rhs, N) ((void) 0)
442 #ifndef YY_LOCATION_PRINT
443 # define YY_LOCATION_PRINT(File, Loc) ((void) 0)
446 /* YYLEX -- calling `yylex' with the right arguments. */
447 #define YYLEX ]b4_c_function_call([yylex], [int], b4_lex_param)[
452 #define yynerrs (yystackp->yyerrcnt)
454 #define yychar (yystackp->yyrawchar)
456 #define yylval (yystackp->yyval)
458 #define yylloc (yystackp->yyloc)
459 m4_if(b4_prefix
[], [yy
], [],
460 [#define b4_prefix[]nerrs yynerrs
461 #define b4_prefix[]char yychar
462 #define b4_prefix[]lval yylval
463 #define b4_prefix[]lloc yylloc])],
464 [YYSTYPE yylval
;]b4_locations_if([[
470 static const int YYEOF
= 0;
471 static const int YYEMPTY
= -2;
473 typedef enum { yyok
, yyaccept
, yyabort
, yyerr
} YYRESULTTAG
;
477 YYRESULTTAG yychk_flag = YYE; \
478 if (yychk_flag != yyok) \
482 #if ]b4_api_PREFIX[DEBUG
485 # define YYFPRINTF fprintf
488 # define YYDPRINTF(Args) \
494 ]b4_yy_symbol_print_generate([b4_c_ansi_function_def
])[
496 # define YY_SYMBOL_PRINT(Title, Type, Value, Location) \
500 YYFPRINTF (stderr, "%s ", Title); \
501 yy_symbol_print (stderr, Type, Value]b4_locuser_args([Location])[); \
502 YYFPRINTF (stderr, "\n"); \
506 /* Nonzero means print parse trace. It is left uninitialized so that
507 multiple parsers can coexist. */
510 #else /* !]b4_api_PREFIX[DEBUG */
512 # define YYDPRINTF(Args)
513 # define YY_SYMBOL_PRINT(Title, Type, Value, Location)
515 #endif /* !]b4_api_PREFIX[DEBUG */
517 /* YYINITDEPTH -- initial size of the parser's stacks. */
519 # define YYINITDEPTH ]b4_stack_depth_init[
522 /* YYMAXDEPTH -- maximum size the stacks can grow to (effective only
523 if the built-in stack extension method is used).
525 Do not make this value too large; the results are undefined if
526 SIZE_MAX < YYMAXDEPTH * sizeof (GLRStackItem)
527 evaluated with infinite-precision integer arithmetic. */
530 # define YYMAXDEPTH ]b4_stack_depth_max[
533 /* Minimum number of free items on the stack allowed after an
534 allocation. This is to allow allocation and initialization
535 to be completed by functions that call yyexpandGLRStack before the
536 stack is expanded, thus insuring that all necessary pointers get
537 properly redirected to new data. */
540 #ifndef YYSTACKEXPANDABLE
541 # define YYSTACKEXPANDABLE 1
544 #if YYSTACKEXPANDABLE
545 # define YY_RESERVE_GLRSTACK(Yystack) \
547 if (Yystack->yyspaceLeft < YYHEADROOM) \
548 yyexpandGLRStack (Yystack); \
551 # define YY_RESERVE_GLRSTACK(Yystack) \
553 if (Yystack->yyspaceLeft < YYHEADROOM) \
554 yyMemoryExhausted (Yystack); \
562 # if defined __GLIBC__ && defined _STRING_H && defined _GNU_SOURCE
563 # define yystpcpy stpcpy
565 /* Copy YYSRC to YYDEST, returning the address of the terminating '\0' in
568 yystpcpy (char *yydest
, const char *yysrc
)
571 const char *yys
= yysrc
;
573 while ((*yyd
++ = *yys
++) != '\0')
582 /* Copy to YYRES the contents of YYSTR after stripping away unnecessary
583 quotes and backslashes, so that it's suitable for yyerror. The
584 heuristic is that double-quoting is unnecessary unless the string
585 contains an apostrophe, a comma, or backslash (other than
586 backslash-backslash). YYSTR is taken from yytname. If YYRES is
587 null, do not copy; instead, return the length of what the result
590 yytnamerr (char *yyres
, const char *yystr
)
595 char const *yyp
= yystr
;
602 goto do_not_strip_quotes
;
606 goto do_not_strip_quotes
;
619 do_not_strip_quotes
: ;
623 return strlen (yystr
);
625 return yystpcpy (yyres
, yystr
) - yyres
;
629 #endif /* !YYERROR_VERBOSE */
631 /** State numbers, as in LALR(1) machine */
632 typedef int yyStateNum
;
634 /** Rule numbers, as in LALR(1) machine */
635 typedef int yyRuleNum
;
637 /** Grammar symbol */
638 typedef int yySymbol
;
640 /** Item references, as in LALR(1) machine */
641 typedef short int yyItemNum
;
643 typedef struct yyGLRState yyGLRState
;
644 typedef struct yyGLRStateSet yyGLRStateSet
;
645 typedef struct yySemanticOption yySemanticOption
;
646 typedef union yyGLRStackItem yyGLRStackItem
;
647 typedef struct yyGLRStack yyGLRStack
;
650 /** Type tag: always true. */
652 /** Type tag for yysemantics. If true, yysval applies, otherwise
653 * yyfirstVal applies. */
655 /** Number of corresponding LALR(1) machine state. */
656 yyStateNum yylrState
;
657 /** Preceding state in this stack */
659 /** Source position of the last token produced by my symbol */
662 /** First in a chain of alternative reductions producing the
663 * non-terminal corresponding to this state, threaded through
665 yySemanticOption
* yyfirstVal
;
666 /** Semantic value for this state. */
668 } yysemantics
;]b4_locations_if([[
669 /** Source location for this state. */
673 struct yyGLRStateSet
{
674 yyGLRState
** yystates
;
675 /** During nondeterministic operation, yylookaheadNeeds tracks which
676 * stacks have actually needed the current lookahead. During deterministic
677 * operation, yylookaheadNeeds[0] is not maintained since it would merely
678 * duplicate yychar != YYEMPTY. */
679 yybool
* yylookaheadNeeds
;
680 size_t yysize
, yycapacity
;
683 struct yySemanticOption
{
684 /** Type tag: always false. */
686 /** Rule number for this reduction */
688 /** The last RHS state in the list of states to be reduced. */
690 /** The lookahead for this reduction. */
692 YYSTYPE yyval
;]b4_locations_if([[
694 /** Next sibling in chain of options. To facilitate merging,
695 * options are chained in decreasing order by address. */
696 yySemanticOption
* yynext
;
699 /** Type of the items in the GLR stack. The yyisState field
700 * indicates which item of the union is valid. */
701 union yyGLRStackItem
{
703 yySemanticOption yyoption
;
708 ]b4_locations_if([[ /* To compute the location of the error token. */
709 yyGLRStackItem yyerror_range
[3];]])[
714 YYSTYPE yyval
;]b4_locations_if([[
717 YYJMP_BUF yyexception_buffer
;
718 yyGLRStackItem
* yyitems
;
719 yyGLRStackItem
* yynextFree
;
721 yyGLRState
* yysplitPoint
;
722 yyGLRState
* yylastDeleted
;
723 yyGLRStateSet yytops
;
726 #if YYSTACKEXPANDABLE
727 static void yyexpandGLRStack (yyGLRStack
* yystackp
);
730 static void yyFail (yyGLRStack
* yystackp
]b4_pure_formals
[, const char* yymsg
)
731 __attribute__ ((__noreturn__
));
733 yyFail (yyGLRStack
* yystackp
]b4_pure_formals
[, const char* yymsg
)
735 if (yymsg
!= YY_NULL
)
736 yyerror (]b4_yyerror_args
[yymsg
);
737 YYLONGJMP (yystackp
->yyexception_buffer
, 1);
740 static void yyMemoryExhausted (yyGLRStack
* yystackp
)
741 __attribute__ ((__noreturn__
));
743 yyMemoryExhausted (yyGLRStack
* yystackp
)
745 YYLONGJMP (yystackp
->yyexception_buffer
, 2);
748 #if ]b4_api_PREFIX[DEBUG || YYERROR_VERBOSE
749 /** A printable representation of TOKEN. */
750 static inline const char*
751 yytokenName (yySymbol yytoken
)
753 if (yytoken
== YYEMPTY
)
756 return yytname
[yytoken
];
760 /** Fill in YYVSP[YYLOW1 .. YYLOW0-1] from the chain of states starting
761 * at YYVSP[YYLOW0].yystate.yypred. Leaves YYVSP[YYLOW1].yystate.yypred
762 * containing the pointer to the next state in the chain. */
763 static void yyfillin (yyGLRStackItem
*, int, int) __attribute__ ((__unused__
));
765 yyfillin (yyGLRStackItem
*yyvsp
, int yylow0
, int yylow1
)
768 yyGLRState
*s
= yyvsp
[yylow0
].yystate
.yypred
;
769 for (i
= yylow0
-1; i
>= yylow1
; i
-= 1)
771 #if ]b4_api_PREFIX[DEBUG
772 yyvsp
[i
].yystate
.yylrState
= s
->yylrState
;
774 yyvsp
[i
].yystate
.yyresolved
= s
->yyresolved
;
776 yyvsp
[i
].yystate
.yysemantics
.yysval
= s
->yysemantics
.yysval
;
778 /* The effect of using yysval or yyloc (in an immediate rule) is
780 yyvsp
[i
].yystate
.yysemantics
.yyfirstVal
= YY_NULL
;]b4_locations_if([[
781 yyvsp
[i
].yystate
.yyloc
= s
->yyloc
;]])[
782 s
= yyvsp
[i
].yystate
.yypred
= s
->yypred
;
786 /* Do nothing if YYNORMAL or if *YYLOW <= YYLOW1. Otherwise, fill in
787 * YYVSP[YYLOW1 .. *YYLOW-1] as in yyfillin and set *YYLOW = YYLOW1.
788 * For convenience, always return YYLOW1. */
789 static inline int yyfill (yyGLRStackItem
*, int *, int, yybool
)
790 __attribute__ ((__unused__
));
792 yyfill (yyGLRStackItem
*yyvsp
, int *yylow
, int yylow1
, yybool yynormal
)
794 if (!yynormal
&& yylow1
< *yylow
)
796 yyfillin (yyvsp
, *yylow
, yylow1
);
802 /** Perform user action for rule number YYN, with RHS length YYRHSLEN,
803 * and top stack item YYVSP. YYLVALP points to place to put semantic
804 * value ($$), and yylocp points to place for location information
805 * (@@$). Returns yyok for normal return, yyaccept for YYACCEPT,
806 * yyerr for YYERROR, yyabort for YYABORT. */
807 /*ARGSUSED*/ static YYRESULTTAG
808 yyuserAction (yyRuleNum yyn
, int yyrhslen
, yyGLRStackItem
* yyvsp
,
809 yyGLRStack
* yystackp
,
810 YYSTYPE
* yyvalp
]b4_locuser_formals
[)
812 yybool yynormal
__attribute__ ((__unused__
)) =
813 (yystackp
->yysplitPoint
== YY_NULL
);
815 ]b4_parse_param_use([yyvalp
], [yylocp
])dnl
817 # define yyerrok (yystackp->yyerrState = 0)
819 # define YYACCEPT return yyaccept
821 # define YYABORT return yyabort
823 # define YYERROR return yyerrok, yyerr
825 # define YYRECOVERING() (yystackp->yyerrState != 0)
827 # define yyclearin (yychar = YYEMPTY)
829 # define YYFILL(N) yyfill (yyvsp, &yylow, N, yynormal)
831 # define YYBACKUP(Token, Value) \
832 return yyerror (]b4_yyerror_args[YY_("syntax error: cannot back up")), \
837 *yyvalp
= yyval_default
;
839 *yyvalp
= yyvsp
[YYFILL (1-yyrhslen
)].yystate
.yysemantics
.yysval
;]b4_locations_if([[
840 YYLLOC_DEFAULT ((*yylocp
), (yyvsp
- yyrhslen
), yyrhslen
);
841 yystackp
->yyerror_range
[1].yystate
.yyloc
= *yylocp
;
860 /*ARGSUSED*/ static void
861 yyuserMerge (int yyn
, YYSTYPE
* yy0
, YYSTYPE
* yy1
)
873 /* Bison grammar-table manipulation. */
875 ]b4_yydestruct_generate([b4_c_ansi_function_def
])[
877 /** Number of symbols composing the right hand side of rule #RULE. */
879 yyrhsLength (yyRuleNum yyrule
)
885 yydestroyGLRState (char const *yymsg
, yyGLRState
*yys
]b4_user_formals
[)
888 yydestruct (yymsg
, yystos
[yys
->yylrState
],
889 &yys
->yysemantics
.yysval
]b4_locuser_args([&yys
->yyloc
])[);
892 #if ]b4_api_PREFIX[DEBUG
895 if (yys
->yysemantics
.yyfirstVal
)
896 YYFPRINTF (stderr
, "%s unresolved ", yymsg
);
898 YYFPRINTF (stderr
, "%s incomplete ", yymsg
);
899 yy_symbol_print (stderr
, yystos
[yys
->yylrState
],
900 YY_NULL
]b4_locuser_args([&yys
->yyloc
])[);
901 YYFPRINTF (stderr
, "\n");
905 if (yys
->yysemantics
.yyfirstVal
)
907 yySemanticOption
*yyoption
= yys
->yysemantics
.yyfirstVal
;
910 for (yyrh
= yyoption
->yystate
, yyn
= yyrhsLength (yyoption
->yyrule
);
912 yyrh
= yyrh
->yypred
, yyn
-= 1)
913 yydestroyGLRState (yymsg
, yyrh
]b4_user_args
[);
918 /** Left-hand-side symbol for rule #YYRULE. */
919 static inline yySymbol
920 yylhsNonterm (yyRuleNum yyrule
)
925 #define yypact_value_is_default(yystate) \
926 ]b4_table_value_equals([[pact]], [[yystate]], [b4_pact_ninf])[
928 /** True iff LR state YYSTATE has only a default reduction (regardless
931 yyisDefaultedState (yyStateNum yystate
)
933 return yypact_value_is_default (yypact
[yystate
]);
936 /** The default reduction for YYSTATE, assuming it has one. */
937 static inline yyRuleNum
938 yydefaultAction (yyStateNum yystate
)
940 return yydefact
[yystate
];
943 #define yytable_value_is_error(yytable_value) \
944 ]b4_table_value_equals([[table]], [[yytable_value]], [b4_table_ninf])[
946 /** Set *YYACTION to the action to take in YYSTATE on seeing YYTOKEN.
948 * R < 0: Reduce on rule -R.
950 * R > 0: Shift to state R.
951 * Set *YYCONFLICTS to a pointer into yyconfl to a 0-terminated list
952 * of conflicting reductions.
955 yygetLRActions (yyStateNum yystate
, int yytoken
,
956 int* yyaction
, const short int** yyconflicts
)
958 int yyindex
= yypact
[yystate
] + yytoken
;
959 if (yypact_value_is_default (yypact
[yystate
])
960 || yyindex
< 0 || YYLAST
< yyindex
|| yycheck
[yyindex
] != yytoken
)
962 *yyaction
= -yydefact
[yystate
];
963 *yyconflicts
= yyconfl
;
965 else if (! yytable_value_is_error (yytable
[yyindex
]))
967 *yyaction
= yytable
[yyindex
];
968 *yyconflicts
= yyconfl
+ yyconflp
[yyindex
];
973 *yyconflicts
= yyconfl
+ yyconflp
[yyindex
];
977 static inline yyStateNum
978 yyLRgotoState (yyStateNum yystate
, yySymbol yylhs
)
980 int yyr
= yypgoto
[yylhs
- YYNTOKENS
] + yystate
;
981 if (0 <= yyr
&& yyr
<= YYLAST
&& yycheck
[yyr
] == yystate
)
984 return yydefgoto
[yylhs
- YYNTOKENS
];
988 yyisShiftAction (int yyaction
)
994 yyisErrorAction (int yyaction
)
996 return yyaction
== 0;
1001 /** Return a fresh GLRStackItem in YYSTACKP. The item is an LR state
1002 * if YYISSTATE, and otherwise a semantic option. Callers should call
1003 * YY_RESERVE_GLRSTACK afterwards to make sure there is sufficient
1006 static inline yyGLRStackItem
*
1007 yynewGLRStackItem (yyGLRStack
* yystackp
, yybool yyisState
)
1009 yyGLRStackItem
* yynewItem
= yystackp
->yynextFree
;
1010 yystackp
->yyspaceLeft
-= 1;
1011 yystackp
->yynextFree
+= 1;
1012 yynewItem
->yystate
.yyisState
= yyisState
;
1016 /** Add a new semantic action that will execute the action for rule
1017 * YYRULE on the semantic values in YYRHS to the list of
1018 * alternative actions for YYSTATE. Assumes that YYRHS comes from
1019 * stack #YYK of *YYSTACKP. */
1021 yyaddDeferredAction (yyGLRStack
* yystackp
, size_t yyk
, yyGLRState
* yystate
,
1022 yyGLRState
* yyrhs
, yyRuleNum yyrule
)
1024 yySemanticOption
* yynewOption
=
1025 &yynewGLRStackItem (yystackp
, yyfalse
)->yyoption
;
1026 yynewOption
->yystate
= yyrhs
;
1027 yynewOption
->yyrule
= yyrule
;
1028 if (yystackp
->yytops
.yylookaheadNeeds
[yyk
])
1030 yynewOption
->yyrawchar
= yychar
;
1031 yynewOption
->yyval
= yylval
;]b4_locations_if([
1032 yynewOption
->yyloc
= yylloc
;])[
1035 yynewOption
->yyrawchar
= YYEMPTY
;
1036 yynewOption
->yynext
= yystate
->yysemantics
.yyfirstVal
;
1037 yystate
->yysemantics
.yyfirstVal
= yynewOption
;
1039 YY_RESERVE_GLRSTACK (yystackp
);
1044 /** Initialize YYSET to a singleton set containing an empty stack. */
1046 yyinitStateSet (yyGLRStateSet
* yyset
)
1049 yyset
->yycapacity
= 16;
1050 yyset
->yystates
= (yyGLRState
**) YYMALLOC (16 * sizeof yyset
->yystates
[0]);
1051 if (! yyset
->yystates
)
1053 yyset
->yystates
[0] = YY_NULL
;
1054 yyset
->yylookaheadNeeds
=
1055 (yybool
*) YYMALLOC (16 * sizeof yyset
->yylookaheadNeeds
[0]);
1056 if (! yyset
->yylookaheadNeeds
)
1058 YYFREE (yyset
->yystates
);
1064 static void yyfreeStateSet (yyGLRStateSet
* yyset
)
1066 YYFREE (yyset
->yystates
);
1067 YYFREE (yyset
->yylookaheadNeeds
);
1070 /** Initialize *YYSTACKP to a single empty stack, with total maximum
1071 * capacity for all stacks of YYSIZE. */
1073 yyinitGLRStack (yyGLRStack
* yystackp
, size_t yysize
)
1075 yystackp
->yyerrState
= 0;
1077 yystackp
->yyspaceLeft
= yysize
;
1079 (yyGLRStackItem
*) YYMALLOC (yysize
* sizeof yystackp
->yynextFree
[0]);
1080 if (!yystackp
->yyitems
)
1082 yystackp
->yynextFree
= yystackp
->yyitems
;
1083 yystackp
->yysplitPoint
= YY_NULL
;
1084 yystackp
->yylastDeleted
= YY_NULL
;
1085 return yyinitStateSet (&yystackp
->yytops
);
1089 #if YYSTACKEXPANDABLE
1090 # define YYRELOC(YYFROMITEMS,YYTOITEMS,YYX,YYTYPE) \
1091 &((YYTOITEMS) - ((YYFROMITEMS) - (yyGLRStackItem*) (YYX)))->YYTYPE
1093 /** If *YYSTACKP is expandable, extend it. WARNING: Pointers into the
1094 stack from outside should be considered invalid after this call.
1095 We always expand when there are 1 or fewer items left AFTER an
1096 allocation, so that we can avoid having external pointers exist
1097 across an allocation. */
1099 yyexpandGLRStack (yyGLRStack
* yystackp
)
1101 yyGLRStackItem
* yynewItems
;
1102 yyGLRStackItem
* yyp0
, *yyp1
;
1105 size_t yysize
= yystackp
->yynextFree
- yystackp
->yyitems
;
1106 if (YYMAXDEPTH
- YYHEADROOM
< yysize
)
1107 yyMemoryExhausted (yystackp
);
1108 yynewSize
= 2*yysize
;
1109 if (YYMAXDEPTH
< yynewSize
)
1110 yynewSize
= YYMAXDEPTH
;
1111 yynewItems
= (yyGLRStackItem
*) YYMALLOC (yynewSize
* sizeof yynewItems
[0]);
1113 yyMemoryExhausted (yystackp
);
1114 for (yyp0
= yystackp
->yyitems
, yyp1
= yynewItems
, yyn
= yysize
;
1116 yyn
-= 1, yyp0
+= 1, yyp1
+= 1)
1119 if (*(yybool
*) yyp0
)
1121 yyGLRState
* yys0
= &yyp0
->yystate
;
1122 yyGLRState
* yys1
= &yyp1
->yystate
;
1123 if (yys0
->yypred
!= YY_NULL
)
1125 YYRELOC (yyp0
, yyp1
, yys0
->yypred
, yystate
);
1126 if (! yys0
->yyresolved
&& yys0
->yysemantics
.yyfirstVal
!= YY_NULL
)
1127 yys1
->yysemantics
.yyfirstVal
=
1128 YYRELOC (yyp0
, yyp1
, yys0
->yysemantics
.yyfirstVal
, yyoption
);
1132 yySemanticOption
* yyv0
= &yyp0
->yyoption
;
1133 yySemanticOption
* yyv1
= &yyp1
->yyoption
;
1134 if (yyv0
->yystate
!= YY_NULL
)
1135 yyv1
->yystate
= YYRELOC (yyp0
, yyp1
, yyv0
->yystate
, yystate
);
1136 if (yyv0
->yynext
!= YY_NULL
)
1137 yyv1
->yynext
= YYRELOC (yyp0
, yyp1
, yyv0
->yynext
, yyoption
);
1140 if (yystackp
->yysplitPoint
!= YY_NULL
)
1141 yystackp
->yysplitPoint
= YYRELOC (yystackp
->yyitems
, yynewItems
,
1142 yystackp
->yysplitPoint
, yystate
);
1144 for (yyn
= 0; yyn
< yystackp
->yytops
.yysize
; yyn
+= 1)
1145 if (yystackp
->yytops
.yystates
[yyn
] != YY_NULL
)
1146 yystackp
->yytops
.yystates
[yyn
] =
1147 YYRELOC (yystackp
->yyitems
, yynewItems
,
1148 yystackp
->yytops
.yystates
[yyn
], yystate
);
1149 YYFREE (yystackp
->yyitems
);
1150 yystackp
->yyitems
= yynewItems
;
1151 yystackp
->yynextFree
= yynewItems
+ yysize
;
1152 yystackp
->yyspaceLeft
= yynewSize
- yysize
;
1157 yyfreeGLRStack (yyGLRStack
* yystackp
)
1159 YYFREE (yystackp
->yyitems
);
1160 yyfreeStateSet (&yystackp
->yytops
);
1163 /** Assuming that YYS is a GLRState somewhere on *YYSTACKP, update the
1164 * splitpoint of *YYSTACKP, if needed, so that it is at least as deep as
1167 yyupdateSplit (yyGLRStack
* yystackp
, yyGLRState
* yys
)
1169 if (yystackp
->yysplitPoint
!= YY_NULL
&& yystackp
->yysplitPoint
> yys
)
1170 yystackp
->yysplitPoint
= yys
;
1173 /** Invalidate stack #YYK in *YYSTACKP. */
1175 yymarkStackDeleted (yyGLRStack
* yystackp
, size_t yyk
)
1177 if (yystackp
->yytops
.yystates
[yyk
] != YY_NULL
)
1178 yystackp
->yylastDeleted
= yystackp
->yytops
.yystates
[yyk
];
1179 yystackp
->yytops
.yystates
[yyk
] = YY_NULL
;
1182 /** Undelete the last stack in *YYSTACKP that was marked as deleted. Can
1183 only be done once after a deletion, and only when all other stacks have
1186 yyundeleteLastStack (yyGLRStack
* yystackp
)
1188 if (yystackp
->yylastDeleted
== YY_NULL
|| yystackp
->yytops
.yysize
!= 0)
1190 yystackp
->yytops
.yystates
[0] = yystackp
->yylastDeleted
;
1191 yystackp
->yytops
.yysize
= 1;
1192 YYDPRINTF ((stderr
, "Restoring last deleted stack as stack #0.\n"));
1193 yystackp
->yylastDeleted
= YY_NULL
;
1197 yyremoveDeletes (yyGLRStack
* yystackp
)
1201 while (yyj
< yystackp
->yytops
.yysize
)
1203 if (yystackp
->yytops
.yystates
[yyi
] == YY_NULL
)
1207 YYDPRINTF ((stderr
, "Removing dead stacks.\n"));
1209 yystackp
->yytops
.yysize
-= 1;
1213 yystackp
->yytops
.yystates
[yyj
] = yystackp
->yytops
.yystates
[yyi
];
1214 /* In the current implementation, it's unnecessary to copy
1215 yystackp->yytops.yylookaheadNeeds[yyi] since, after
1216 yyremoveDeletes returns, the parser immediately either enters
1217 deterministic operation or shifts a token. However, it doesn't
1218 hurt, and the code might evolve to need it. */
1219 yystackp
->yytops
.yylookaheadNeeds
[yyj
] =
1220 yystackp
->yytops
.yylookaheadNeeds
[yyi
];
1223 YYDPRINTF ((stderr
, "Rename stack %lu -> %lu.\n",
1224 (unsigned long int) yyi
, (unsigned long int) yyj
));
1232 /** Shift to a new state on stack #YYK of *YYSTACKP, corresponding to LR
1233 * state YYLRSTATE, at input position YYPOSN, with (resolved) semantic
1234 * value *YYVALP and source location *YYLOCP. */
1236 yyglrShift (yyGLRStack
* yystackp
, size_t yyk
, yyStateNum yylrState
,
1238 YYSTYPE
* yyvalp
]b4_locations_if([, YYLTYPE
* yylocp
])[)
1240 yyGLRState
* yynewState
= &yynewGLRStackItem (yystackp
, yytrue
)->yystate
;
1242 yynewState
->yylrState
= yylrState
;
1243 yynewState
->yyposn
= yyposn
;
1244 yynewState
->yyresolved
= yytrue
;
1245 yynewState
->yypred
= yystackp
->yytops
.yystates
[yyk
];
1246 yynewState
->yysemantics
.yysval
= *yyvalp
;]b4_locations_if([
1247 yynewState
->yyloc
= *yylocp
;])[
1248 yystackp
->yytops
.yystates
[yyk
] = yynewState
;
1250 YY_RESERVE_GLRSTACK (yystackp
);
1253 /** Shift stack #YYK of *YYSTACKP, to a new state corresponding to LR
1254 * state YYLRSTATE, at input position YYPOSN, with the (unresolved)
1255 * semantic value of YYRHS under the action for YYRULE. */
1257 yyglrShiftDefer (yyGLRStack
* yystackp
, size_t yyk
, yyStateNum yylrState
,
1258 size_t yyposn
, yyGLRState
* yyrhs
, yyRuleNum yyrule
)
1260 yyGLRState
* yynewState
= &yynewGLRStackItem (yystackp
, yytrue
)->yystate
;
1262 yynewState
->yylrState
= yylrState
;
1263 yynewState
->yyposn
= yyposn
;
1264 yynewState
->yyresolved
= yyfalse
;
1265 yynewState
->yypred
= yystackp
->yytops
.yystates
[yyk
];
1266 yynewState
->yysemantics
.yyfirstVal
= YY_NULL
;
1267 yystackp
->yytops
.yystates
[yyk
] = yynewState
;
1269 /* Invokes YY_RESERVE_GLRSTACK. */
1270 yyaddDeferredAction (yystackp
, yyk
, yynewState
, yyrhs
, yyrule
);
1273 #if !]b4_api_PREFIX[DEBUG
1274 # define YY_REDUCE_PRINT(Args)
1276 # define YY_REDUCE_PRINT(Args) \
1279 yy_reduce_print Args; \
1282 /*----------------------------------------------------------------------.
1283 | Report that stack #YYK of *YYSTACKP is going to be reduced by YYRULE. |
1284 `----------------------------------------------------------------------*/
1286 /*ARGSUSED*/ static inline void
1287 yy_reduce_print (int yynormal
, yyGLRStackItem
* yyvsp
, size_t yyk
,
1288 yyRuleNum yyrule
]b4_user_formals
[)
1290 int yynrhs
= yyrhsLength (yyrule
);]b4_locations_if([
1293 YYFPRINTF (stderr
, "Reducing stack %lu by rule %d (line %lu):\n",
1294 (unsigned long int) yyk
, yyrule
- 1,
1295 (unsigned long int) yyrline
[yyrule
]);
1297 yyfillin (yyvsp
, 1, -yynrhs
);
1298 /* The symbols being reduced. */
1299 for (yyi
= 0; yyi
< yynrhs
; yyi
++)
1301 YYFPRINTF (stderr
, " $%d = ", yyi
+ 1);
1302 yy_symbol_print (stderr
,
1303 yystos
[yyvsp
[yyi
- yynrhs
+ 1].yystate
.yylrState
],
1304 &yyvsp
[yyi
- yynrhs
+ 1].yystate
.yysemantics
.yysval
1305 ]b4_locations_if([, &]b4_rhs_location(yynrhs
, yyi
+ 1))[]dnl
1307 if (!yyvsp
[yyi
- yynrhs
+ 1].yystate
.yyresolved
)
1308 YYFPRINTF (stderr
, " (unresolved)");
1309 YYFPRINTF (stderr
, "\n");
1314 /** Pop the symbols consumed by reduction #YYRULE from the top of stack
1315 * #YYK of *YYSTACKP, and perform the appropriate semantic action on their
1316 * semantic values. Assumes that all ambiguities in semantic values
1317 * have been previously resolved. Set *YYVALP to the resulting value,
1318 * and *YYLOCP to the computed location (if any). Return value is as
1319 * for userAction. */
1320 static inline YYRESULTTAG
1321 yydoAction (yyGLRStack
* yystackp
, size_t yyk
, yyRuleNum yyrule
,
1322 YYSTYPE
* yyvalp
]b4_locuser_formals
[)
1324 int yynrhs
= yyrhsLength (yyrule
);
1326 if (yystackp
->yysplitPoint
== YY_NULL
)
1328 /* Standard special case: single stack. */
1329 yyGLRStackItem
* yyrhs
= (yyGLRStackItem
*) yystackp
->yytops
.yystates
[yyk
];
1330 YYASSERT (yyk
== 0);
1331 yystackp
->yynextFree
-= yynrhs
;
1332 yystackp
->yyspaceLeft
+= yynrhs
;
1333 yystackp
->yytops
.yystates
[0] = & yystackp
->yynextFree
[-1].yystate
;
1334 YY_REDUCE_PRINT ((1, yyrhs
, yyk
, yyrule
]b4_user_args
[));
1335 return yyuserAction (yyrule
, yynrhs
, yyrhs
, yystackp
,
1336 yyvalp
]b4_locuser_args
[);
1342 yyGLRStackItem yyrhsVals
[YYMAXRHS
+ YYMAXLEFT
+ 1];
1343 yys
= yyrhsVals
[YYMAXRHS
+ YYMAXLEFT
].yystate
.yypred
1344 = yystackp
->yytops
.yystates
[yyk
];]b4_locations_if([[
1346 /* Set default location. */
1347 yyrhsVals
[YYMAXRHS
+ YYMAXLEFT
- 1].yystate
.yyloc
= yys
->yyloc
;]])[
1348 for (yyi
= 0; yyi
< yynrhs
; yyi
+= 1)
1353 yyupdateSplit (yystackp
, yys
);
1354 yystackp
->yytops
.yystates
[yyk
] = yys
;
1355 YY_REDUCE_PRINT ((0, yyrhsVals
+ YYMAXRHS
+ YYMAXLEFT
- 1, yyk
, yyrule
]b4_user_args
[));
1356 return yyuserAction (yyrule
, yynrhs
, yyrhsVals
+ YYMAXRHS
+ YYMAXLEFT
- 1,
1357 yystackp
, yyvalp
]b4_locuser_args
[);
1361 /** Pop items off stack #YYK of *YYSTACKP according to grammar rule YYRULE,
1362 * and push back on the resulting nonterminal symbol. Perform the
1363 * semantic action associated with YYRULE and store its value with the
1364 * newly pushed state, if YYFORCEEVAL or if *YYSTACKP is currently
1365 * unambiguous. Otherwise, store the deferred semantic action with
1366 * the new state. If the new state would have an identical input
1367 * position, LR state, and predecessor to an existing state on the stack,
1368 * it is identified with that existing state, eliminating stack #YYK from
1369 * *YYSTACKP. In this case, the semantic value is
1370 * added to the options for the existing state's semantic value.
1372 static inline YYRESULTTAG
1373 yyglrReduce (yyGLRStack
* yystackp
, size_t yyk
, yyRuleNum yyrule
,
1374 yybool yyforceEval
]b4_user_formals
[)
1376 size_t yyposn
= yystackp
->yytops
.yystates
[yyk
]->yyposn
;
1378 if (yyforceEval
|| yystackp
->yysplitPoint
== YY_NULL
)
1381 YYSTYPE yysval
;]b4_locations_if([
1384 yyflag
= yydoAction (yystackp
, yyk
, yyrule
, &yysval
]b4_locuser_args([&yyloc
])[);
1385 if (yyflag
== yyerr
&& yystackp
->yysplitPoint
!= YY_NULL
)
1387 YYDPRINTF ((stderr
, "Parse on stack %lu rejected by rule #%d.\n",
1388 (unsigned long int) yyk
, yyrule
- 1));
1392 YY_SYMBOL_PRINT ("-> $$ =", yyr1
[yyrule
], &yysval
, &yyloc
);
1393 yyglrShift (yystackp
, yyk
,
1394 yyLRgotoState (yystackp
->yytops
.yystates
[yyk
]->yylrState
,
1395 yylhsNonterm (yyrule
)),
1396 yyposn
, &yysval
]b4_locations_if([, &yyloc
])[);
1402 yyGLRState
* yys
, *yys0
= yystackp
->yytops
.yystates
[yyk
];
1403 yyStateNum yynewLRState
;
1405 for (yys
= yystackp
->yytops
.yystates
[yyk
], yyn
= yyrhsLength (yyrule
);
1411 yyupdateSplit (yystackp
, yys
);
1412 yynewLRState
= yyLRgotoState (yys
->yylrState
, yylhsNonterm (yyrule
));
1414 "Reduced stack %lu by rule #%d; action deferred. "
1415 "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 YYY0 and YYY1 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 (YYY0,YYY1), destructively merge the
1509 * alternative semantic values for the RHS-symbols of YYY1 and YYY0. */
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 YYN states starting at and including state YYS
1589 * on *YYSTACKP. If result != yyok, some states may have been left
1590 * unresolved possibly with empty semantic option chains. Regardless
1591 * of whether result = yyok, each state has been left with consistent
1592 * data so that yydestroyGLRState can be invoked if necessary. */
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 YYOPT on *YYSTACKP, perform its
1608 * user action, and return the semantic value and location in *YYVALP
1609 * and *YYLOCP. Regardless of whether result = yyok, all RHS states
1610 * have been destroyed (assuming the user action destroys all RHS
1611 * semantic values if invoked). */
1613 yyresolveAction (yySemanticOption
* yyopt
, yyGLRStack
* yystackp
,
1614 YYSTYPE
* yyvalp
]b4_locuser_formals
[)
1616 yyGLRStackItem yyrhsVals
[YYMAXRHS
+ YYMAXLEFT
+ 1];
1617 int yynrhs
= yyrhsLength (yyopt
->yyrule
);
1618 YYRESULTTAG yyflag
=
1619 yyresolveStates (yyopt
->yystate
, yynrhs
, yystackp
]b4_user_args
[);
1623 for (yys
= yyopt
->yystate
; yynrhs
> 0; yys
= yys
->yypred
, yynrhs
-= 1)
1624 yydestroyGLRState ("Cleanup: popping", yys
]b4_user_args
[);
1628 yyrhsVals
[YYMAXRHS
+ YYMAXLEFT
].yystate
.yypred
= yyopt
->yystate
;]b4_locations_if([[
1630 /* Set default location. */
1631 yyrhsVals
[YYMAXRHS
+ YYMAXLEFT
- 1].yystate
.yyloc
= yyopt
->yystate
->yyloc
;]])[
1633 int yychar_current
= yychar
;
1634 YYSTYPE yylval_current
= yylval
;]b4_locations_if([
1635 YYLTYPE yylloc_current
= yylloc
;])[
1636 yychar
= yyopt
->yyrawchar
;
1637 yylval
= yyopt
->yyval
;]b4_locations_if([
1638 yylloc
= yyopt
->yyloc
;])[
1639 yyflag
= yyuserAction (yyopt
->yyrule
, yynrhs
,
1640 yyrhsVals
+ YYMAXRHS
+ YYMAXLEFT
- 1,
1641 yystackp
, yyvalp
]b4_locuser_args
[);
1642 yychar
= yychar_current
;
1643 yylval
= yylval_current
;]b4_locations_if([
1644 yylloc
= yylloc_current
;])[
1649 #if ]b4_api_PREFIX[DEBUG
1651 yyreportTree (yySemanticOption
* yyx
, int yyindent
)
1653 int yynrhs
= yyrhsLength (yyx
->yyrule
);
1656 yyGLRState
* yystates
[1 + YYMAXRHS
];
1657 yyGLRState yyleftmost_state
;
1659 for (yyi
= yynrhs
, yys
= yyx
->yystate
; 0 < yyi
; yyi
-= 1, yys
= yys
->yypred
)
1660 yystates
[yyi
] = yys
;
1663 yyleftmost_state
.yyposn
= 0;
1664 yystates
[0] = &yyleftmost_state
;
1669 if (yyx
->yystate
->yyposn
< yys
->yyposn
+ 1)
1670 YYFPRINTF (stderr
, "%*s%s -> <Rule %d, empty>\n",
1671 yyindent
, "", yytokenName (yylhsNonterm (yyx
->yyrule
)),
1674 YYFPRINTF (stderr
, "%*s%s -> <Rule %d, tokens %lu .. %lu>\n",
1675 yyindent
, "", yytokenName (yylhsNonterm (yyx
->yyrule
)),
1676 yyx
->yyrule
- 1, (unsigned long int) (yys
->yyposn
+ 1),
1677 (unsigned long int) yyx
->yystate
->yyposn
);
1678 for (yyi
= 1; yyi
<= yynrhs
; yyi
+= 1)
1680 if (yystates
[yyi
]->yyresolved
)
1682 if (yystates
[yyi
-1]->yyposn
+1 > yystates
[yyi
]->yyposn
)
1683 YYFPRINTF (stderr
, "%*s%s <empty>\n", yyindent
+2, "",
1684 yytokenName (yystos
[yystates
[yyi
]->yylrState
]));
1686 YYFPRINTF (stderr
, "%*s%s <tokens %lu .. %lu>\n", yyindent
+2, "",
1687 yytokenName (yystos
[yystates
[yyi
]->yylrState
]),
1688 (unsigned long int) (yystates
[yyi
-1]->yyposn
+ 1),
1689 (unsigned long int) yystates
[yyi
]->yyposn
);
1692 yyreportTree (yystates
[yyi
]->yysemantics
.yyfirstVal
, yyindent
+2);
1697 /*ARGSUSED*/ static YYRESULTTAG
1698 yyreportAmbiguity (yySemanticOption
* yyx0
,
1699 yySemanticOption
* yyx1
]b4_pure_formals
[)
1704 #if ]b4_api_PREFIX[DEBUG
1705 YYFPRINTF (stderr
, "Ambiguity detected.\n");
1706 YYFPRINTF (stderr
, "Option 1,\n");
1707 yyreportTree (yyx0
, 2);
1708 YYFPRINTF (stderr
, "\nOption 2,\n");
1709 yyreportTree (yyx1
, 2);
1710 YYFPRINTF (stderr
, "\n");
1713 yyerror (]b4_yyerror_args
[YY_("syntax is ambiguous"));
1715 }]b4_locations_if([[
1717 /** Resolve the locations for each of the YYN1 states in *YYSTACKP,
1718 * ending at YYS1. Has no effect on previously resolved states.
1719 * The first semantic option of a state is always chosen. */
1721 yyresolveLocations (yyGLRState
* yys1
, int yyn1
,
1722 yyGLRStack
*yystackp
]b4_user_formals
[)
1726 yyresolveLocations (yys1
->yypred
, yyn1
- 1, yystackp
]b4_user_args
[);
1727 if (!yys1
->yyresolved
)
1729 yyGLRStackItem yyrhsloc
[1 + YYMAXRHS
];
1731 yySemanticOption
*yyoption
= yys1
->yysemantics
.yyfirstVal
;
1732 YYASSERT (yyoption
!= YY_NULL
);
1733 yynrhs
= yyrhsLength (yyoption
->yyrule
);
1738 yyresolveLocations (yyoption
->yystate
, yynrhs
,
1739 yystackp
]b4_user_args
[);
1740 for (yys
= yyoption
->yystate
, yyn
= yynrhs
;
1742 yys
= yys
->yypred
, yyn
-= 1)
1743 yyrhsloc
[yyn
].yystate
.yyloc
= yys
->yyloc
;
1747 /* Both yyresolveAction and yyresolveLocations traverse the GSS
1748 in reverse rightmost order. It is only necessary to invoke
1749 yyresolveLocations on a subforest for which yyresolveAction
1750 would have been invoked next had an ambiguity not been
1751 detected. Thus the location of the previous state (but not
1752 necessarily the previous state itself) is guaranteed to be
1753 resolved already. */
1754 yyGLRState
*yyprevious
= yyoption
->yystate
;
1755 yyrhsloc
[0].yystate
.yyloc
= yyprevious
->yyloc
;
1758 int yychar_current
= yychar
;
1759 YYSTYPE yylval_current
= yylval
;
1760 YYLTYPE yylloc_current
= yylloc
;
1761 yychar
= yyoption
->yyrawchar
;
1762 yylval
= yyoption
->yyval
;
1763 yylloc
= yyoption
->yyloc
;
1764 YYLLOC_DEFAULT ((yys1
->yyloc
), yyrhsloc
, yynrhs
);
1765 yychar
= yychar_current
;
1766 yylval
= yylval_current
;
1767 yylloc
= yylloc_current
;
1773 /** Resolve the ambiguity represented in state YYS in *YYSTACKP,
1774 * perform the indicated actions, and set the semantic value of YYS.
1775 * If result != yyok, the chain of semantic options in YYS has been
1776 * cleared instead or it has been left unmodified except that
1777 * redundant options may have been removed. Regardless of whether
1778 * result = yyok, YYS has been left with consistent data so that
1779 * yydestroyGLRState can be invoked if necessary. */
1781 yyresolveValue (yyGLRState
* yys
, yyGLRStack
* yystackp
]b4_user_formals
[)
1783 yySemanticOption
* yyoptionList
= yys
->yysemantics
.yyfirstVal
;
1784 yySemanticOption
* yybest
= yyoptionList
;
1785 yySemanticOption
** yypp
;
1786 yybool yymerge
= yyfalse
;
1788 YYRESULTTAG yyflag
;]b4_locations_if([
1789 YYLTYPE
*yylocp
= &yys
->yyloc
;])[
1791 for (yypp
= &yyoptionList
->yynext
; *yypp
!= YY_NULL
; )
1793 yySemanticOption
* yyp
= *yypp
;
1795 if (yyidenticalOptions (yybest
, yyp
))
1797 yymergeOptionSets (yybest
, yyp
);
1798 *yypp
= yyp
->yynext
;
1802 switch (yypreference (yybest
, yyp
))
1804 case 0:]b4_locations_if([[
1805 yyresolveLocations (yys
, 1, yystackp
]b4_user_args
[);]])[
1806 return yyreportAmbiguity (yybest
, yyp
]b4_pure_args
[);
1818 /* This cannot happen so it is not worth a YYASSERT (yyfalse),
1819 but some compilers complain if the default case is
1823 yypp
= &yyp
->yynext
;
1829 yySemanticOption
* yyp
;
1830 int yyprec
= yydprec
[yybest
->yyrule
];
1831 yyflag
= yyresolveAction (yybest
, yystackp
, &yysval
]b4_locuser_args
[);
1833 for (yyp
= yybest
->yynext
; yyp
!= YY_NULL
; yyp
= yyp
->yynext
)
1835 if (yyprec
== yydprec
[yyp
->yyrule
])
1837 YYSTYPE yysval_other
;]b4_locations_if([
1839 yyflag
= yyresolveAction (yyp
, yystackp
, &yysval_other
]b4_locuser_args([&yydummy
])[);
1842 yydestruct ("Cleanup: discarding incompletely merged value for",
1843 yystos
[yys
->yylrState
],
1844 &yysval
]b4_locuser_args
[);
1847 yyuserMerge (yymerger
[yyp
->yyrule
], &yysval
, &yysval_other
);
1852 yyflag
= yyresolveAction (yybest
, yystackp
, &yysval
]b4_locuser_args([yylocp
])[);
1856 yys
->yyresolved
= yytrue
;
1857 yys
->yysemantics
.yysval
= yysval
;
1860 yys
->yysemantics
.yyfirstVal
= YY_NULL
;
1865 yyresolveStack (yyGLRStack
* yystackp
]b4_user_formals
[)
1867 if (yystackp
->yysplitPoint
!= YY_NULL
)
1872 for (yyn
= 0, yys
= yystackp
->yytops
.yystates
[0];
1873 yys
!= yystackp
->yysplitPoint
;
1874 yys
= yys
->yypred
, yyn
+= 1)
1876 YYCHK (yyresolveStates (yystackp
->yytops
.yystates
[0], yyn
, yystackp
1883 yycompressStack (yyGLRStack
* yystackp
)
1885 yyGLRState
* yyp
, *yyq
, *yyr
;
1887 if (yystackp
->yytops
.yysize
!= 1 || yystackp
->yysplitPoint
== YY_NULL
)
1890 for (yyp
= yystackp
->yytops
.yystates
[0], yyq
= yyp
->yypred
, yyr
= YY_NULL
;
1891 yyp
!= yystackp
->yysplitPoint
;
1892 yyr
= yyp
, yyp
= yyq
, yyq
= yyp
->yypred
)
1895 yystackp
->yyspaceLeft
+= yystackp
->yynextFree
- yystackp
->yyitems
;
1896 yystackp
->yynextFree
= ((yyGLRStackItem
*) yystackp
->yysplitPoint
) + 1;
1897 yystackp
->yyspaceLeft
-= yystackp
->yynextFree
- yystackp
->yyitems
;
1898 yystackp
->yysplitPoint
= YY_NULL
;
1899 yystackp
->yylastDeleted
= YY_NULL
;
1901 while (yyr
!= YY_NULL
)
1903 yystackp
->yynextFree
->yystate
= *yyr
;
1905 yystackp
->yynextFree
->yystate
.yypred
= &yystackp
->yynextFree
[-1].yystate
;
1906 yystackp
->yytops
.yystates
[0] = &yystackp
->yynextFree
->yystate
;
1907 yystackp
->yynextFree
+= 1;
1908 yystackp
->yyspaceLeft
-= 1;
1913 yyprocessOneStack (yyGLRStack
* yystackp
, size_t yyk
,
1914 size_t yyposn
]b4_pure_formals
[)
1916 while (yystackp
->yytops
.yystates
[yyk
] != YY_NULL
)
1918 yyStateNum yystate
= yystackp
->yytops
.yystates
[yyk
]->yylrState
;
1919 YYDPRINTF ((stderr
, "Stack %lu Entering state %d\n",
1920 (unsigned long int) yyk
, yystate
));
1922 YYASSERT (yystate
!= YYFINAL
);
1924 if (yyisDefaultedState (yystate
))
1927 yyRuleNum yyrule
= yydefaultAction (yystate
);
1930 YYDPRINTF ((stderr
, "Stack %lu dies.\n",
1931 (unsigned long int) yyk
));
1932 yymarkStackDeleted (yystackp
, yyk
);
1935 yyflag
= yyglrReduce (yystackp
, yyk
, yyrule
, yyimmediate
[yyrule
]]b4_user_args
[);
1936 if (yyflag
== yyerr
)
1940 "(predicate failure or explicit user error).\n",
1941 (unsigned long int) yyk
));
1942 yymarkStackDeleted (yystackp
, yyk
);
1952 const short int* yyconflicts
;
1954 yystackp
->yytops
.yylookaheadNeeds
[yyk
] = yytrue
;
1955 if (yychar
== YYEMPTY
)
1957 YYDPRINTF ((stderr
, "Reading a token: "));
1961 if (yychar
<= YYEOF
)
1963 yychar
= yytoken
= YYEOF
;
1964 YYDPRINTF ((stderr
, "Now at end of input.\n"));
1968 yytoken
= YYTRANSLATE (yychar
);
1969 YY_SYMBOL_PRINT ("Next token is", yytoken
, &yylval
, &yylloc
);
1972 yygetLRActions (yystate
, yytoken
, &yyaction
, &yyconflicts
);
1974 while (*yyconflicts
!= 0)
1977 size_t yynewStack
= yysplitStack (yystackp
, yyk
);
1978 YYDPRINTF ((stderr
, "Splitting off stack %lu from %lu.\n",
1979 (unsigned long int) yynewStack
,
1980 (unsigned long int) yyk
));
1981 yyflag
= yyglrReduce (yystackp
, yynewStack
,
1983 yyimmediate
[*yyconflicts
]]b4_user_args
[);
1985 YYCHK (yyprocessOneStack (yystackp
, yynewStack
,
1986 yyposn
]b4_pure_args
[));
1987 else if (yyflag
== yyerr
)
1989 YYDPRINTF ((stderr
, "Stack %lu dies.\n",
1990 (unsigned long int) yynewStack
));
1991 yymarkStackDeleted (yystackp
, yynewStack
);
1998 if (yyisShiftAction (yyaction
))
2000 else if (yyisErrorAction (yyaction
))
2002 YYDPRINTF ((stderr
, "Stack %lu dies.\n",
2003 (unsigned long int) yyk
));
2004 yymarkStackDeleted (yystackp
, yyk
);
2009 YYRESULTTAG yyflag
= yyglrReduce (yystackp
, yyk
, -yyaction
,
2010 yyimmediate
[-yyaction
]]b4_user_args
[);
2011 if (yyflag
== yyerr
)
2015 "(predicate failure or explicit user error).\n",
2016 (unsigned long int) yyk
));
2017 yymarkStackDeleted (yystackp
, yyk
);
2020 else if (yyflag
!= yyok
)
2028 /*ARGSUSED*/ static void
2029 yyreportSyntaxError (yyGLRStack
* yystackp
]b4_user_formals
[)
2031 if (yystackp
->yyerrState
!= 0)
2033 #if ! YYERROR_VERBOSE
2034 yyerror (]b4_lyyerror_args
[YY_("syntax error"));
2036 yySymbol yytoken
= yychar
== YYEMPTY
? YYEMPTY
: YYTRANSLATE (yychar
);
2037 size_t yysize0
= yytnamerr (YY_NULL
, yytokenName (yytoken
));
2038 size_t yysize
= yysize0
;
2040 yybool yysize_overflow
= yyfalse
;
2041 char* yymsg
= YY_NULL
;
2042 enum { YYERROR_VERBOSE_ARGS_MAXIMUM
= 5 };
2043 /* Internationalized format string. */
2044 const char *yyformat
= YY_NULL
;
2045 /* Arguments of yyformat. */
2046 char const *yyarg
[YYERROR_VERBOSE_ARGS_MAXIMUM
];
2047 /* Number of reported tokens (one for the "unexpected", one per
2051 /* There are many possibilities here to consider:
2052 - If this state is a consistent state with a default action, then
2053 the only way this function was invoked is if the default action
2054 is an error action. In that case, don't check for expected
2055 tokens because there are none.
2056 - The only way there can be no lookahead present (in yychar) is if
2057 this state is a consistent state with a default action. Thus,
2058 detecting the absence of a lookahead is sufficient to determine
2059 that there is no unexpected or expected token to report. In that
2060 case, just report a simple "syntax error".
2061 - Don't assume there isn't a lookahead just because this state is a
2062 consistent state with a default action. There might have been a
2063 previous inconsistent state, consistent state with a non-default
2064 action, or user semantic action that manipulated yychar.
2065 - Of course, the expected token list depends on states to have
2066 correct lookahead information, and it depends on the parser not
2067 to perform extra reductions after fetching a lookahead from the
2068 scanner and before detecting a syntax error. Thus, state merging
2069 (from LALR or IELR) and default reductions corrupt the expected
2070 token list. However, the list is correct for canonical LR with
2071 one exception: it will still contain any token that will not be
2072 accepted due to an error action in a later state.
2074 if (yytoken
!= YYEMPTY
)
2076 int yyn
= yypact
[yystackp
->yytops
.yystates
[0]->yylrState
];
2077 yyarg
[yycount
++] = yytokenName (yytoken
);
2078 if (!yypact_value_is_default (yyn
))
2080 /* Start YYX at -YYN if negative to avoid negative indexes in
2081 YYCHECK. In other words, skip the first -YYN actions for this
2082 state because they are default actions. */
2083 int yyxbegin
= yyn
< 0 ? -yyn
: 0;
2084 /* Stay within bounds of both yycheck and yytname. */
2085 int yychecklim
= YYLAST
- yyn
+ 1;
2086 int yyxend
= yychecklim
< YYNTOKENS
? yychecklim
: YYNTOKENS
;
2088 for (yyx
= yyxbegin
; yyx
< yyxend
; ++yyx
)
2089 if (yycheck
[yyx
+ yyn
] == yyx
&& yyx
!= YYTERROR
2090 && !yytable_value_is_error (yytable
[yyx
+ yyn
]))
2092 if (yycount
== YYERROR_VERBOSE_ARGS_MAXIMUM
)
2098 yyarg
[yycount
++] = yytokenName (yyx
);
2099 yysize1
= yysize
+ yytnamerr (YY_NULL
, yytokenName (yyx
));
2100 yysize_overflow
|= yysize1
< yysize
;
2108 #define YYCASE_(N, S) \
2112 YYCASE_(0, YY_("syntax error"));
2113 YYCASE_(1, YY_("syntax error, unexpected %s"));
2114 YYCASE_(2, YY_("syntax error, unexpected %s, expecting %s"));
2115 YYCASE_(3, YY_("syntax error, unexpected %s, expecting %s or %s"));
2116 YYCASE_(4, YY_("syntax error, unexpected %s, expecting %s or %s or %s"));
2117 YYCASE_(5, YY_("syntax error, unexpected %s, expecting %s or %s or %s or %s"));
2121 yysize1
= yysize
+ strlen (yyformat
);
2122 yysize_overflow
|= yysize1
< yysize
;
2125 if (!yysize_overflow
)
2126 yymsg
= (char *) YYMALLOC (yysize
);
2132 while ((*yyp
= *yyformat
))
2134 if (*yyp
== '%' && yyformat
[1] == 's' && yyi
< yycount
)
2136 yyp
+= yytnamerr (yyp
, yyarg
[yyi
++]);
2145 yyerror (]b4_lyyerror_args
[yymsg
);
2150 yyerror (]b4_lyyerror_args
[YY_("syntax error"));
2151 yyMemoryExhausted (yystackp
);
2153 #endif /* YYERROR_VERBOSE */
2157 /* Recover from a syntax error on *YYSTACKP, assuming that *YYSTACKP->YYTOKENP,
2158 yylval, and yylloc are the syntactic category, semantic value, and location
2159 of the lookahead. */
2160 /*ARGSUSED*/ static void
2161 yyrecoverSyntaxError (yyGLRStack
* yystackp
]b4_user_formals
[)
2166 if (yystackp
->yyerrState
== 3)
2167 /* We just shifted the error token and (perhaps) took some
2168 reductions. Skip tokens until we can proceed. */
2169 while (YYID (yytrue
))
2172 if (yychar
== YYEOF
)
2173 yyFail (yystackp
][]b4_lpure_args
[, YY_NULL
);
2174 if (yychar
!= YYEMPTY
)
2175 {]b4_locations_if([[
2176 /* We throw away the lookahead, but the error range
2177 of the shifted error token must take it into account. */
2178 yyGLRState
*yys
= yystackp
->yytops
.yystates
[0];
2179 yyGLRStackItem yyerror_range
[3];
2180 yyerror_range
[1].yystate
.yyloc
= yys
->yyloc
;
2181 yyerror_range
[2].yystate
.yyloc
= yylloc
;
2182 YYLLOC_DEFAULT ((yys
->yyloc
), yyerror_range
, 2);]])[
2183 yytoken
= YYTRANSLATE (yychar
);
2184 yydestruct ("Error: discarding",
2185 yytoken
, &yylval
]b4_locuser_args([&yylloc
])[);
2187 YYDPRINTF ((stderr
, "Reading a token: "));
2189 if (yychar
<= YYEOF
)
2191 yychar
= yytoken
= YYEOF
;
2192 YYDPRINTF ((stderr
, "Now at end of input.\n"));
2196 yytoken
= YYTRANSLATE (yychar
);
2197 YY_SYMBOL_PRINT ("Next token is", yytoken
, &yylval
, &yylloc
);
2199 yyj
= yypact
[yystackp
->yytops
.yystates
[0]->yylrState
];
2200 if (yypact_value_is_default (yyj
))
2203 if (yyj
< 0 || YYLAST
< yyj
|| yycheck
[yyj
] != yytoken
)
2205 if (yydefact
[yystackp
->yytops
.yystates
[0]->yylrState
] != 0)
2208 else if (! yytable_value_is_error (yytable
[yyj
]))
2212 /* Reduce to one stack. */
2213 for (yyk
= 0; yyk
< yystackp
->yytops
.yysize
; yyk
+= 1)
2214 if (yystackp
->yytops
.yystates
[yyk
] != YY_NULL
)
2216 if (yyk
>= yystackp
->yytops
.yysize
)
2217 yyFail (yystackp
][]b4_lpure_args
[, YY_NULL
);
2218 for (yyk
+= 1; yyk
< yystackp
->yytops
.yysize
; yyk
+= 1)
2219 yymarkStackDeleted (yystackp
, yyk
);
2220 yyremoveDeletes (yystackp
);
2221 yycompressStack (yystackp
);
2223 /* Now pop stack until we find a state that shifts the error token. */
2224 yystackp
->yyerrState
= 3;
2225 while (yystackp
->yytops
.yystates
[0] != YY_NULL
)
2227 yyGLRState
*yys
= yystackp
->yytops
.yystates
[0];
2228 yyj
= yypact
[yys
->yylrState
];
2229 if (! yypact_value_is_default (yyj
))
2232 if (0 <= yyj
&& yyj
<= YYLAST
&& yycheck
[yyj
] == YYTERROR
2233 && yyisShiftAction (yytable
[yyj
]))
2235 /* Shift the error token. */]b4_locations_if([[
2236 /* First adjust its location.*/
2238 yystackp
->yyerror_range
[2].yystate
.yyloc
= yylloc
;
2239 YYLLOC_DEFAULT (yyerrloc
, (yystackp
->yyerror_range
), 2);]])[
2240 YY_SYMBOL_PRINT ("Shifting", yystos
[yytable
[yyj
]],
2241 &yylval
, &yyerrloc
);
2242 yyglrShift (yystackp
, 0, yytable
[yyj
],
2243 yys
->yyposn
, &yylval
]b4_locations_if([, &yyerrloc
])[);
2244 yys
= yystackp
->yytops
.yystates
[0];
2247 }]b4_locations_if([[
2248 yystackp
->yyerror_range
[1].yystate
.yyloc
= yys
->yyloc
;]])[
2249 if (yys
->yypred
!= YY_NULL
)
2250 yydestroyGLRState ("Error: popping", yys
]b4_user_args
[);
2251 yystackp
->yytops
.yystates
[0] = yys
->yypred
;
2252 yystackp
->yynextFree
-= 1;
2253 yystackp
->yyspaceLeft
+= 1;
2255 if (yystackp
->yytops
.yystates
[0] == YY_NULL
)
2256 yyFail (yystackp
][]b4_lpure_args
[, YY_NULL
);
2259 #define YYCHK1(YYE) \
2269 goto yyuser_error; \
2279 ]b4_c_ansi_function_def([yyparse
], [int], b4_parse_param
)[
2283 yyGLRStack
* const yystackp
= &yystack
;
2286 YYDPRINTF ((stderr
, "Starting parse\n"));
2289 yylval
= yyval_default
;
2291 #if defined ]b4_api_PREFIX[LTYPE_IS_TRIVIAL && ]b4_api_PREFIX[LTYPE_IS_TRIVIAL
2292 yylloc
.first_line
= yylloc
.last_line
= ]b4_location_initial_line
[;
2293 yylloc
.first_column
= yylloc
.last_column
= ]b4_location_initial_column
[;
2296 m4_ifdef([b4_initial_action
], [
2297 m4_pushdef([b4_at_dollar
], [yylloc
])dnl
2298 m4_pushdef([b4_dollar_dollar
], [yylval
])dnl
2299 /* User initialization code. */
2300 b4_user_initial_action
2301 m4_popdef([b4_dollar_dollar
])dnl
2302 m4_popdef([b4_at_dollar
])])dnl
2304 if (! yyinitGLRStack (yystackp
, YYINITDEPTH
))
2305 goto yyexhaustedlab
;
2306 switch (YYSETJMP (yystack
.yyexception_buffer
))
2309 case 1: goto yyabortlab
;
2310 case 2: goto yyexhaustedlab
;
2311 default: goto yybuglab
;
2313 yyglrShift (&yystack
, 0, 0, 0, &yylval
]b4_locations_if([, &yylloc
])[);
2316 while (YYID (yytrue
))
2318 /* For efficiency, we have two loops, the first of which is
2319 specialized to deterministic operation (single stack, no
2320 potential ambiguity). */
2322 while (YYID (yytrue
))
2326 const short int* yyconflicts
;
2328 yyStateNum yystate
= yystack
.yytops
.yystates
[0]->yylrState
;
2329 YYDPRINTF ((stderr
, "Entering state %d\n", yystate
));
2330 if (yystate
== YYFINAL
)
2332 if (yyisDefaultedState (yystate
))
2334 yyrule
= yydefaultAction (yystate
);
2337 ]b4_locations_if([[ yystack
.yyerror_range
[1].yystate
.yyloc
= yylloc
;]])[
2338 yyreportSyntaxError (&yystack
]b4_user_args
[);
2341 YYCHK1 (yyglrReduce (&yystack
, 0, yyrule
, yytrue
]b4_user_args
[));
2346 if (yychar
== YYEMPTY
)
2348 YYDPRINTF ((stderr
, "Reading a token: "));
2352 if (yychar
<= YYEOF
)
2354 yychar
= yytoken
= YYEOF
;
2355 YYDPRINTF ((stderr
, "Now at end of input.\n"));
2359 yytoken
= YYTRANSLATE (yychar
);
2360 YY_SYMBOL_PRINT ("Next token is", yytoken
, &yylval
, &yylloc
);
2363 yygetLRActions (yystate
, yytoken
, &yyaction
, &yyconflicts
);
2364 if (*yyconflicts
!= 0)
2366 if (yyisShiftAction (yyaction
))
2368 YY_SYMBOL_PRINT ("Shifting", yytoken
, &yylval
, &yylloc
);
2371 yyglrShift (&yystack
, 0, yyaction
, yyposn
, &yylval
]b4_locations_if([, &yylloc
])[);
2372 if (0 < yystack
.yyerrState
)
2373 yystack
.yyerrState
-= 1;
2375 else if (yyisErrorAction (yyaction
))
2377 ]b4_locations_if([[ yystack
.yyerror_range
[1].yystate
.yyloc
= yylloc
;]])[
2378 yyreportSyntaxError (&yystack
]b4_user_args
[);
2382 YYCHK1 (yyglrReduce (&yystack
, 0, -yyaction
, yytrue
]b4_user_args
[));
2386 while (YYID (yytrue
))
2388 yySymbol yytoken_to_shift
;
2391 for (yys
= 0; yys
< yystack
.yytops
.yysize
; yys
+= 1)
2392 yystackp
->yytops
.yylookaheadNeeds
[yys
] = yychar
!= YYEMPTY
;
2394 /* yyprocessOneStack returns one of three things:
2396 - An error flag. If the caller is yyprocessOneStack, it
2397 immediately returns as well. When the caller is finally
2398 yyparse, it jumps to an error label via YYCHK1.
2400 - yyok, but yyprocessOneStack has invoked yymarkStackDeleted
2401 (&yystack, yys), which sets the top state of yys to NULL. Thus,
2402 yyparse's following invocation of yyremoveDeletes will remove
2405 - yyok, when ready to shift a token.
2407 Except in the first case, yyparse will invoke yyremoveDeletes and
2408 then shift the next token onto all remaining stacks. This
2409 synchronization of the shift (that is, after all preceding
2410 reductions on all stacks) helps prevent double destructor calls
2411 on yylval in the event of memory exhaustion. */
2413 for (yys
= 0; yys
< yystack
.yytops
.yysize
; yys
+= 1)
2414 YYCHK1 (yyprocessOneStack (&yystack
, yys
, yyposn
]b4_lpure_args
[));
2415 yyremoveDeletes (&yystack
);
2416 if (yystack
.yytops
.yysize
== 0)
2418 yyundeleteLastStack (&yystack
);
2419 if (yystack
.yytops
.yysize
== 0)
2420 yyFail (&yystack
][]b4_lpure_args
[, YY_("syntax error"));
2421 YYCHK1 (yyresolveStack (&yystack
]b4_user_args
[));
2422 YYDPRINTF ((stderr
, "Returning to deterministic operation.\n"));
2423 ]b4_locations_if([[ yystack
.yyerror_range
[1].yystate
.yyloc
= yylloc
;]])[
2424 yyreportSyntaxError (&yystack
]b4_user_args
[);
2428 /* If any yyglrShift call fails, it will fail after shifting. Thus,
2429 a copy of yylval will already be on stack 0 in the event of a
2430 failure in the following loop. Thus, yychar is set to YYEMPTY
2431 before the loop to make sure the user destructor for yylval isn't
2433 yytoken_to_shift
= YYTRANSLATE (yychar
);
2436 for (yys
= 0; yys
< yystack
.yytops
.yysize
; yys
+= 1)
2439 const short int* yyconflicts
;
2440 yyStateNum yystate
= yystack
.yytops
.yystates
[yys
]->yylrState
;
2441 yygetLRActions (yystate
, yytoken_to_shift
, &yyaction
,
2443 /* Note that yyconflicts were handled by yyprocessOneStack. */
2444 YYDPRINTF ((stderr
, "On stack %lu, ", (unsigned long int) yys
));
2445 YY_SYMBOL_PRINT ("shifting", yytoken_to_shift
, &yylval
, &yylloc
);
2446 yyglrShift (&yystack
, yys
, yyaction
, yyposn
,
2447 &yylval
]b4_locations_if([, &yylloc
])[);
2448 YYDPRINTF ((stderr
, "Stack %lu now in state #%d\n",
2449 (unsigned long int) yys
,
2450 yystack
.yytops
.yystates
[yys
]->yylrState
));
2453 if (yystack
.yytops
.yysize
== 1)
2455 YYCHK1 (yyresolveStack (&yystack
]b4_user_args
[));
2456 YYDPRINTF ((stderr
, "Returning to deterministic operation.\n"));
2457 yycompressStack (&yystack
);
2463 yyrecoverSyntaxError (&yystack
]b4_user_args
[);
2464 yyposn
= yystack
.yytops
.yystates
[0]->yyposn
;
2480 yyerror (]b4_lyyerror_args
[YY_("memory exhausted"));
2485 if (yychar
!= YYEMPTY
)
2486 yydestruct ("Cleanup: discarding lookahead",
2487 YYTRANSLATE (yychar
), &yylval
]b4_locuser_args([&yylloc
])[);
2489 /* If the stack is well-formed, pop the stack until it is empty,
2490 destroying its entries as we go. But free the stack regardless
2491 of whether it is well-formed. */
2492 if (yystack
.yyitems
)
2494 yyGLRState
** yystates
= yystack
.yytops
.yystates
;
2497 size_t yysize
= yystack
.yytops
.yysize
;
2499 for (yyk
= 0; yyk
< yysize
; yyk
+= 1)
2502 while (yystates
[yyk
])
2504 yyGLRState
*yys
= yystates
[yyk
];
2505 ]b4_locations_if([[ yystack
.yyerror_range
[1].yystate
.yyloc
= yys
->yyloc
;]]
2506 )[ if (yys
->yypred
!= YY_NULL
)
2507 yydestroyGLRState ("Cleanup: popping", yys
]b4_user_args
[);
2508 yystates
[yyk
] = yys
->yypred
;
2509 yystack
.yynextFree
-= 1;
2510 yystack
.yyspaceLeft
+= 1;
2515 yyfreeGLRStack (&yystack
);
2518 /* Make sure YYID is used. */
2519 return YYID (yyresult
);
2522 /* DEBUGGING ONLY */
2523 #if ]b4_api_PREFIX[DEBUG
2524 static void yypstack (yyGLRStack
* yystackp
, size_t yyk
)
2525 __attribute__ ((__unused__
));
2526 static void yypdumpstack (yyGLRStack
* yystackp
) __attribute__ ((__unused__
));
2529 yy_yypstack (yyGLRState
* yys
)
2533 yy_yypstack (yys
->yypred
);
2534 YYFPRINTF (stderr
, " -> ");
2536 YYFPRINTF (stderr
, "%d@@%lu", yys
->yylrState
,
2537 (unsigned long int) yys
->yyposn
);
2541 yypstates (yyGLRState
* yyst
)
2543 if (yyst
== YY_NULL
)
2544 YYFPRINTF (stderr
, "<null>");
2547 YYFPRINTF (stderr
, "\n");
2551 yypstack (yyGLRStack
* yystackp
, size_t yyk
)
2553 yypstates (yystackp
->yytops
.yystates
[yyk
]);
2556 #define YYINDEX(YYX) \
2557 ((YYX) == YY_NULL ? -1 : (yyGLRStackItem*) (YYX) - yystackp->yyitems)
2561 yypdumpstack (yyGLRStack
* yystackp
)
2563 yyGLRStackItem
* yyp
;
2565 for (yyp
= yystackp
->yyitems
; yyp
< yystackp
->yynextFree
; yyp
+= 1)
2567 YYFPRINTF (stderr
, "%3lu. ",
2568 (unsigned long int) (yyp
- yystackp
->yyitems
));
2569 if (*(yybool
*) yyp
)
2571 YYFPRINTF (stderr
, "Res: %d, LR State: %d, posn: %lu, pred: %ld",
2572 yyp
->yystate
.yyresolved
, yyp
->yystate
.yylrState
,
2573 (unsigned long int) yyp
->yystate
.yyposn
,
2574 (long int) YYINDEX (yyp
->yystate
.yypred
));
2575 if (! yyp
->yystate
.yyresolved
)
2576 YYFPRINTF (stderr
, ", firstVal: %ld",
2577 (long int) YYINDEX (yyp
->yystate
2578 .yysemantics
.yyfirstVal
));
2582 YYFPRINTF (stderr
, "Option. rule: %d, state: %ld, next: %ld",
2583 yyp
->yyoption
.yyrule
- 1,
2584 (long int) YYINDEX (yyp
->yyoption
.yystate
),
2585 (long int) YYINDEX (yyp
->yyoption
.yynext
));
2587 YYFPRINTF (stderr
, "\n");
2589 YYFPRINTF (stderr
, "Tops:");
2590 for (yyi
= 0; yyi
< yystackp
->yytops
.yysize
; yyi
+= 1)
2591 YYFPRINTF (stderr
, "%lu: %ld; ", (unsigned long int) yyi
,
2592 (long int) YYINDEX (yystackp
->yytops
.yystates
[yyi
]));
2593 YYFPRINTF (stderr
, "\n");
2598 dnl glr
.cc produces its own header
.
2600 m4_if(b4_skeleton
, ["glr.c"],
2602 [@
output(b4_spec_defines_file@
)@
2603 b4_copyright([Skeleton interface
for Bison GLR parsers in C
],
2606 ]b4_cpp_guard_open([b4_spec_defines_file
])[
2607 ]b4_shared_declarations
[
2608 ]b4_cpp_guard_close([b4_spec_defines_file
])[