3 # GLR skeleton for Bison
5 # Copyright (C) 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009,
6 # 2010 Free Software Foundation, Inc.
8 # This program is free software: you can redistribute it and/or modify
9 # it under the terms of the GNU General Public License as published by
10 # the Free Software Foundation, either version 3 of the License, or
11 # (at your option) any later version.
13 # This program is distributed in the hope that it will be useful,
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 # GNU General Public License for more details.
18 # You should have received a copy of the GNU General Public License
19 # along with this program. If not, see <http://www.gnu.org/licenses/>.
22 m4_include(b4_pkgdatadir
/[c
.m4
])
24 ## ---------------- ##
26 ## ---------------- ##
29 m4_define_default([b4_stack_depth_max
], [10000])
30 m4_define_default([b4_stack_depth_init
], [200])
34 ## ------------------------ ##
35 ## Pure/impure interfaces. ##
36 ## ------------------------ ##
38 b4_define_flag_if([pure
])
39 # If glr.cc is including this file and thus has already set b4_pure_flag, don't
40 # change the value of b4_pure_flag, and don't record a use of api.pure.
41 m4_ifndef([b4_pure_flag
],
42 [b4_percent_define_default([[api
.pure
]], [[false]])
43 m4_define([b4_pure_flag
],
44 [b4_percent_define_flag_if([[api
.pure
]], [[1]], [[0]])])])
48 # The possible parse-params formal arguments preceded by a comma.
50 # This is not shared with yacc.c in c.m4 because GLR relies on ISO C
51 # formal argument declarations.
52 m4_define([b4_user_formals
],
53 [m4_ifset([b4_parse_param
], [, b4_c_ansi_formals(b4_parse_param
)])])
58 # Accumule in b4_lex_param all the yylex arguments.
59 # Yes, this is quite ugly...
60 m4_define([b4_lex_param
],
61 m4_dquote(b4_pure_if([[[[YYSTYPE
*]], [[&yylval
]]][]dnl
62 b4_locations_if([, [[YYLTYPE
*], [&yylloc
]]])])dnl
63 m4_ifdef([b4_lex_param
], [, ]b4_lex_param
)))
68 # Optional effective arguments passed to yyerror: user args plus yylloc, and
70 m4_define([b4_yyerror_args
],
71 [b4_pure_if([b4_locations_if([yylocp
, ])])dnl
72 m4_ifset([b4_parse_param
], [b4_c_args(b4_parse_param
), ])])
77 # Same as above, but on the lookahead, hence &yylloc instead of yylocp.
78 m4_define([b4_lyyerror_args
],
79 [b4_pure_if([b4_locations_if([&yylloc
, ])])dnl
80 m4_ifset([b4_parse_param
], [b4_c_args(b4_parse_param
), ])])
85 # Same as b4_yyerror_args, but with a leading comma.
86 m4_define([b4_pure_args
],
87 [b4_pure_if([b4_locations_if([, yylocp
])])[]b4_user_args
])
92 # Same as above, but on the lookahead, hence &yylloc instead of yylocp.
93 m4_define([b4_lpure_args
],
94 [b4_pure_if([b4_locations_if([, &yylloc
])])[]b4_user_args
])
99 # Arguments passed to yyerror: user formals plus yylocp.
100 m4_define([b4_pure_formals
],
101 [b4_pure_if([b4_locations_if([, YYLTYPE
*yylocp
])])[]b4_user_formals
])
104 ## ----------------- ##
105 ## Semantic Values. ##
106 ## ----------------- ##
109 # b4_lhs_value([TYPE])
110 # --------------------
111 # Expansion of $<TYPE>$.
112 m4_define([b4_lhs_value
],
113 [b4_symbol_value([(*yyvalp
)], [$
1])])
116 # b4_rhs_data(RULE-LENGTH, NUM)
117 # -----------------------------
118 # Expand to the semantic stack place that contains value and location
119 # of symbol number NUM in a rule of length RULE-LENGTH.
120 m4_define([b4_rhs_data
],
121 [((yyGLRStackItem
const *)yyvsp
)@
{YYFILL (b4_subtract([$
2], [$
1]))@
}.yystate
])
124 # b4_rhs_value(RULE-LENGTH, NUM, [TYPE])
125 # --------------------------------------
126 # Expansion of $<TYPE>NUM, where the current rule has RULE-LENGTH
128 m4_define([b4_rhs_value
],
129 [b4_symbol_value([b4_rhs_data([$
1], [$
2]).yysemantics
.yysval
], [$
3])])
140 m4_define([b4_lhs_location
],
144 # b4_rhs_location(RULE-LENGTH, NUM)
145 # ---------------------------------
146 # Expansion of @NUM, where the current rule has RULE-LENGTH symbols
148 m4_define([b4_rhs_location
],
149 [(b4_rhs_data([$
1], [$
2]).yyloc
)])
157 # We do want M4 expansion after # for CPP macros.
160 @
output(b4_parser_file_name@
)@
161 b4_copyright([Skeleton implementation
for Bison GLR parsers in C
],
162 [2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010])
164 /* C GLR parser skeleton written by Paul Hilfinger. */
168 b4_percent_code_get([[top]])[]dnl
169 m4_if(b4_prefix
, [yy
], [],
170 [/* Substitute the variable and function names. */
171 #define yyparse b4_prefix[]parse
172 #define yylex b4_prefix[]lex
173 #define yyerror b4_prefix[]error
174 #define yylval b4_prefix[]lval
175 #define yychar b4_prefix[]char
176 #define yydebug b4_prefix[]debug
177 #define yynerrs b4_prefix[]nerrs
178 #define yylloc b4_prefix[]lloc])[
180 /* Copy the first part of user declarations. */
181 ]b4_user_pre_prologue
183 dnl
# b4_shared_declarations
184 dnl
# ----------------------
185 dnl
# Declaration that might either go into the header (if --defines)
186 dnl
# or open coded in the parser body.
187 m4_define([b4_shared_declarations
],
188 [b4_percent_code_get([[requires]])[]dnl
190 b4_token_enums(b4_tokens
)
193 ]m4_ifdef([b4_stype
],
194 [[typedef union ]b4_union_name
[
198 # define YYSTYPE_IS_TRIVIAL 1]],
199 [m4_if(b4_tag_seen_flag
, 0,
200 [[typedef int YYSTYPE
;
201 # define YYSTYPE_IS_TRIVIAL 1]])])[
204 #if ! defined YYLTYPE && ! defined YYLTYPE_IS_DECLARED
205 typedef struct YYLTYPE
216 # define YYLTYPE_IS_DECLARED 1
217 # define YYLTYPE_IS_TRIVIAL 1
220 ]b4_percent_code_get([[provides]])[]dnl
223 b4_defines_if([[#include "@basename(]b4_spec_defines_file[@)"]],
224 [b4_shared_declarations
])[
226 /* Enabling traces. */
228 # define YYDEBUG ]b4_parse_trace_if([1], [0])[
231 /* Enabling verbose error messages. */
232 #ifdef YYERROR_VERBOSE
233 # undef YYERROR_VERBOSE
234 # define YYERROR_VERBOSE 1
236 # define YYERROR_VERBOSE ]b4_error_verbose_if([1], [0])[
239 /* Enabling the token table. */
240 #ifndef YYTOKEN_TABLE
241 # define YYTOKEN_TABLE ]b4_token_table[
244 /* Default (constant) value used for initialization for null
245 right-hand sides. Unlike the standard yacc.c template,
246 here we set the default value of $$ to a zeroed-out value.
247 Since the default value is undefined, this behavior is
248 technically correct. */
249 static YYSTYPE yyval_default
;
251 /* Copy the second part of user declarations. */
252 ]b4_user_post_prologue
253 b4_percent_code_get
[]dnl
260 # if defined YYENABLE_NLS && YYENABLE_NLS
262 # include <libintl.h> /* INFRINGES ON USER NAME SPACE */
263 # define YY_(msgid) dgettext ("bison-runtime", msgid)
267 # define YY_(msgid) msgid
271 /* Suppress unused-variable warnings by "using" E. */
272 #if ! defined lint || defined __GNUC__
273 # define YYUSE(e) ((void) (e))
275 # define YYUSE(e) /* empty */
278 /* Identity function, used to suppress warnings about constant conditions. */
282 ]b4_c_function_def([YYID
], [static int], [[int i
], [i
]])[
292 # define YYMALLOC malloc
295 # define YYREALLOC realloc
298 #define YYSIZEMAX ((size_t) -1)
303 typedef unsigned char yybool
;
310 # define YYJMP_BUF jmp_buf
311 # define YYSETJMP(env) setjmp (env)
312 # define YYLONGJMP(env, val) longjmp (env, val)
319 #ifndef __attribute__
320 /* This feature is available in gcc versions 2.5 and later. */
321 # if (! defined __GNUC__ || __GNUC__ < 2 \
322 || (__GNUC__ == 2 && __GNUC_MINOR__ < 5) \
323 || (defined __STRICT_ANSI__ && __STRICT_ANSI__))
324 # define __attribute__(Spec) /* empty */
328 ]b4_locations_if([#define YYOPTIONAL_LOC(Name) Name],[
330 # define YYOPTIONAL_LOC(Name) /* empty */
332 # define YYOPTIONAL_LOC(Name) Name __attribute__ ((__unused__))
336 # define YYASSERT(condition) ((void) ((condition) || (abort (), 0)))
339 /* YYFINAL -- State number of the termination state. */
340 #define YYFINAL ]b4_final_state_number[
341 /* YYLAST -- Last index in YYTABLE. */
342 #define YYLAST ]b4_last[
344 /* YYNTOKENS -- Number of terminals. */
345 #define YYNTOKENS ]b4_tokens_number[
346 /* YYNNTS -- Number of nonterminals. */
347 #define YYNNTS ]b4_nterms_number[
348 /* YYNRULES -- Number of rules. */
349 #define YYNRULES ]b4_rules_number[
350 /* YYNRULES -- Number of states. */
351 #define YYNSTATES ]b4_states_number[
352 /* YYMAXRHS -- Maximum number of symbols on right-hand side of rule. */
353 #define YYMAXRHS ]b4_r2_max[
354 /* YYMAXLEFT -- Maximum number of symbols to the left of a handle
355 accessed by $0, $-1, etc., in any rule. */
356 #define YYMAXLEFT ]b4_max_left_semantic_context[
358 /* YYTRANSLATE(X) -- Bison symbol number corresponding to X. */
359 #define YYUNDEFTOK ]b4_undef_token_number[
360 #define YYMAXUTOK ]b4_user_token_number_max[
362 #define YYTRANSLATE(YYX) \
363 ((unsigned int) (YYX) <= YYMAXUTOK ? yytranslate[YYX] : YYUNDEFTOK)
365 /* YYTRANSLATE[YYLEX] -- Bison symbol number corresponding to YYLEX. */
366 static const ]b4_int_type_for([b4_translate
])[ yytranslate
[] =
372 /* YYRLINE[YYN] -- source line where rule number YYN was defined. */
373 static const ]b4_int_type_for([b4_rline
])[ yyrline
[] =
379 #if YYDEBUG || YYERROR_VERBOSE || YYTOKEN_TABLE
380 /* YYTNAME[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM.
381 First, the terminals, then, starting at YYNTOKENS, nonterminals. */
382 static const char *const yytname
[] =
388 #define YYPACT_NINF ]b4_pact_ninf[
389 #define YYTABLE_NINF ]b4_table_ninf[
391 ]b4_parser_tables_define
[
393 /* YYDPREC[RULE-NUM] -- Dynamic precedence of rule #RULE-NUM (0 if none). */
394 static const ]b4_int_type_for([b4_dprec
])[ yydprec
[] =
399 /* YYMERGER[RULE-NUM] -- Index of merging function for rule #RULE-NUM. */
400 static const ]b4_int_type_for([b4_merger
])[ yymerger
[] =
405 /* YYIMMEDIATE[RULE-NUM] -- True iff rule #RULE-NUM is not to be deferred, as
406 in the case of predicates. */
407 static const yybool yyimmediate
[] =
412 /* YYCONFLP[YYPACT[STATE-NUM]] -- Pointer into YYCONFL of start of
413 list of conflicting reductions corresponding to action entry for
414 state STATE-NUM in yytable. 0 means no conflicts. The list in
415 yyconfl is terminated by a rule number of 0. */
416 static const ]b4_int_type_for([b4_conflict_list_heads
])[ yyconflp
[] =
418 ]b4_conflict_list_heads
[
421 /* YYCONFL[I] -- lists of conflicting rule numbers, each terminated by
422 0, pointed into by YYCONFLP. */
423 ]dnl Do
not use b4_int_type_for here
, since there are places where
424 dnl pointers onto yyconfl are taken
, which type is
"short int *".
425 dnl We probably ought to introduce a type
for confl
.
426 [static const short int yyconfl
[] =
428 ]b4_conflicting_rules
[
431 /* Prevent warning if -Wmissing-prototypes. */
432 ]b4_c_ansi_function_decl([yyparse
], [int], b4_parse_param
)[
434 /* Error token number */
437 /* YYLLOC_DEFAULT -- Set CURRENT to span from RHS[1] to RHS[N].
438 If N is 0, then set CURRENT to the empty location which ends
439 the previous symbol: RHS[0] (always defined). */
442 #define YYRHSLOC(Rhs, K) ((Rhs)[K].yystate.yyloc)
443 #ifndef YYLLOC_DEFAULT
444 # define YYLLOC_DEFAULT(Current, Rhs, N) \
448 (Current).first_line = YYRHSLOC (Rhs, 1).first_line; \
449 (Current).first_column = YYRHSLOC (Rhs, 1).first_column; \
450 (Current).last_line = YYRHSLOC (Rhs, N).last_line; \
451 (Current).last_column = YYRHSLOC (Rhs, N).last_column; \
455 (Current).first_line = (Current).last_line = \
456 YYRHSLOC (Rhs, 0).last_line; \
457 (Current).first_column = (Current).last_column = \
458 YYRHSLOC (Rhs, 0).last_column; \
462 /* YY_LOCATION_PRINT -- Print the location on the stream.
463 This macro was not mandated originally: define only if we know
464 we won't break user code: when these are the locations we know. */
466 # define YY_LOCATION_PRINT(File, Loc) \
467 fprintf (File, "%d.%d-%d.%d", \
468 (Loc).first_line, (Loc).first_column, \
469 (Loc).last_line, (Loc).last_column)
472 #ifndef YYLLOC_DEFAULT
473 # define YYLLOC_DEFAULT(Current, Rhs, N) ((void) 0)
477 #ifndef YY_LOCATION_PRINT
478 # define YY_LOCATION_PRINT(File, Loc) ((void) 0)
482 /* YYLEX -- calling `yylex' with the right arguments. */
483 #define YYLEX ]b4_c_function_call([yylex], [int], b4_lex_param)[
488 #define yynerrs (yystackp->yyerrcnt)
490 #define yychar (yystackp->yyrawchar)
492 #define yylval (yystackp->yyval)
494 #define yylloc (yystackp->yyloc)
495 m4_if(b4_prefix
[], [yy
], [],
496 [#define b4_prefix[]nerrs yynerrs
497 #define b4_prefix[]char yychar
498 #define b4_prefix[]lval yylval
499 #define b4_prefix[]lloc yylloc])],
507 static const int YYEOF
= 0;
508 static const int YYEMPTY
= -2;
510 typedef enum { yyok
, yyaccept
, yyabort
, yyerr
} YYRESULTTAG
;
514 YYRESULTTAG yychk_flag = YYE; \
515 if (yychk_flag != yyok) \
522 # define YYFPRINTF fprintf
525 # define YYDPRINTF(Args) \
531 ]b4_yy_symbol_print_generate([b4_c_ansi_function_def
])[
533 # define YY_SYMBOL_PRINT(Title, Type, Value, Location) \
537 YYFPRINTF (stderr, "%s ", Title); \
538 yy_symbol_print (stderr, Type, \
539 Value]b4_locations_if([, Location])[]b4_user_args[); \
540 YYFPRINTF (stderr, "\n"); \
544 /* Nonzero means print parse trace. It is left uninitialized so that
545 multiple parsers can coexist. */
550 # define YYDPRINTF(Args)
551 # define YY_SYMBOL_PRINT(Title, Type, Value, Location)
553 #endif /* !YYDEBUG */
555 /* YYINITDEPTH -- initial size of the parser's stacks. */
557 # define YYINITDEPTH ]b4_stack_depth_init[
560 /* YYMAXDEPTH -- maximum size the stacks can grow to (effective only
561 if the built-in stack extension method is used).
563 Do not make this value too large; the results are undefined if
564 SIZE_MAX < YYMAXDEPTH * sizeof (GLRStackItem)
565 evaluated with infinite-precision integer arithmetic. */
568 # define YYMAXDEPTH ]b4_stack_depth_max[
571 /* Minimum number of free items on the stack allowed after an
572 allocation. This is to allow allocation and initialization
573 to be completed by functions that call yyexpandGLRStack before the
574 stack is expanded, thus insuring that all necessary pointers get
575 properly redirected to new data. */
578 #ifndef YYSTACKEXPANDABLE
579 # define YYSTACKEXPANDABLE 1
582 #if YYSTACKEXPANDABLE
583 # define YY_RESERVE_GLRSTACK(Yystack) \
585 if (Yystack->yyspaceLeft < YYHEADROOM) \
586 yyexpandGLRStack (Yystack); \
589 # define YY_RESERVE_GLRSTACK(Yystack) \
591 if (Yystack->yyspaceLeft < YYHEADROOM) \
592 yyMemoryExhausted (Yystack); \
600 # if defined __GLIBC__ && defined _STRING_H && defined _GNU_SOURCE
601 # define yystpcpy stpcpy
603 /* Copy YYSRC to YYDEST, returning the address of the terminating '\0' in
606 yystpcpy (char *yydest
, const char *yysrc
)
609 const char *yys
= yysrc
;
611 while ((*yyd
++ = *yys
++) != '\0')
620 /* Copy to YYRES the contents of YYSTR after stripping away unnecessary
621 quotes and backslashes, so that it's suitable for yyerror. The
622 heuristic is that double-quoting is unnecessary unless the string
623 contains an apostrophe, a comma, or backslash (other than
624 backslash-backslash). YYSTR is taken from yytname. If YYRES is
625 null, do not copy; instead, return the length of what the result
628 yytnamerr (char *yyres
, const char *yystr
)
633 char const *yyp
= yystr
;
640 goto do_not_strip_quotes
;
644 goto do_not_strip_quotes
;
657 do_not_strip_quotes
: ;
661 return strlen (yystr
);
663 return yystpcpy (yyres
, yystr
) - yyres
;
667 #endif /* !YYERROR_VERBOSE */
669 /** State numbers, as in LALR(1) machine */
670 typedef int yyStateNum
;
672 /** Rule numbers, as in LALR(1) machine */
673 typedef int yyRuleNum
;
675 /** Grammar symbol */
676 typedef int yySymbol
;
678 /** Item references, as in LALR(1) machine */
679 typedef short int yyItemNum
;
681 typedef struct yyGLRState yyGLRState
;
682 typedef struct yyGLRStateSet yyGLRStateSet
;
683 typedef struct yySemanticOption yySemanticOption
;
684 typedef union yyGLRStackItem yyGLRStackItem
;
685 typedef struct yyGLRStack yyGLRStack
;
688 /** Type tag: always true. */
690 /** Type tag for yysemantics. If true, yysval applies, otherwise
691 * yyfirstVal applies. */
693 /** Number of corresponding LALR(1) machine state. */
694 yyStateNum yylrState
;
695 /** Preceding state in this stack */
697 /** Source position of the last token produced by my symbol */
700 /** First in a chain of alternative reductions producing the
701 * non-terminal corresponding to this state, threaded through
703 yySemanticOption
* yyfirstVal
;
704 /** Semantic value for this state. */
707 /** Source location for this state. */
711 struct yyGLRStateSet
{
712 yyGLRState
** yystates
;
713 /** During nondeterministic operation, yylookaheadNeeds tracks which
714 * stacks have actually needed the current lookahead. During deterministic
715 * operation, yylookaheadNeeds[0] is not maintained since it would merely
716 * duplicate yychar != YYEMPTY. */
717 yybool
* yylookaheadNeeds
;
718 size_t yysize
, yycapacity
;
721 struct yySemanticOption
{
722 /** Type tag: always false. */
724 /** Rule number for this reduction */
726 /** The last RHS state in the list of states to be reduced. */
728 /** The lookahead for this reduction. */
732 /** Next sibling in chain of options. To facilitate merging,
733 * options are chained in decreasing order by address. */
734 yySemanticOption
* yynext
;
737 /** Type of the items in the GLR stack. The yyisState field
738 * indicates which item of the union is valid. */
739 union yyGLRStackItem
{
741 yySemanticOption yyoption
;
746 ]b4_locations_if([[ /* To compute the location of the error token. */
747 yyGLRStackItem yyerror_range
[3];]])[
755 YYJMP_BUF yyexception_buffer
;
756 yyGLRStackItem
* yyitems
;
757 yyGLRStackItem
* yynextFree
;
759 yyGLRState
* yysplitPoint
;
760 yyGLRState
* yylastDeleted
;
761 yyGLRStateSet yytops
;
764 #if YYSTACKEXPANDABLE
765 static void yyexpandGLRStack (yyGLRStack
* yystackp
);
768 static void yyFail (yyGLRStack
* yystackp
]b4_pure_formals
[, const char* yymsg
)
769 __attribute__ ((__noreturn__
));
771 yyFail (yyGLRStack
* yystackp
]b4_pure_formals
[, const char* yymsg
)
774 yyerror (]b4_yyerror_args
[yymsg
);
775 YYLONGJMP (yystackp
->yyexception_buffer
, 1);
778 static void yyMemoryExhausted (yyGLRStack
* yystackp
)
779 __attribute__ ((__noreturn__
));
781 yyMemoryExhausted (yyGLRStack
* yystackp
)
783 YYLONGJMP (yystackp
->yyexception_buffer
, 2);
786 #if YYDEBUG || YYERROR_VERBOSE
787 /** A printable representation of TOKEN. */
788 static inline const char*
789 yytokenName (yySymbol yytoken
)
791 if (yytoken
== YYEMPTY
)
794 return yytname
[yytoken
];
798 /** Fill in YYVSP[YYLOW1 .. YYLOW0-1] from the chain of states starting
799 * at YYVSP[YYLOW0].yystate.yypred. Leaves YYVSP[YYLOW1].yystate.yypred
800 * containing the pointer to the next state in the chain. */
801 static void yyfillin (yyGLRStackItem
*, int, int) __attribute__ ((__unused__
));
803 yyfillin (yyGLRStackItem
*yyvsp
, int yylow0
, int yylow1
)
807 s
= yyvsp
[yylow0
].yystate
.yypred
;
808 for (i
= yylow0
-1; i
>= yylow1
; i
-= 1)
811 yyvsp
[i
].yystate
.yylrState
= s
->yylrState
;
813 yyvsp
[i
].yystate
.yyresolved
= s
->yyresolved
;
815 yyvsp
[i
].yystate
.yysemantics
.yysval
= s
->yysemantics
.yysval
;
817 /* The effect of using yysval or yyloc (in an immediate rule) is
819 yyvsp
[i
].yystate
.yysemantics
.yyfirstVal
= NULL
;
820 yyvsp
[i
].yystate
.yyloc
= s
->yyloc
;
821 s
= yyvsp
[i
].yystate
.yypred
= s
->yypred
;
825 /* Do nothing if YYNORMAL or if *YYLOW <= YYLOW1. Otherwise, fill in
826 * YYVSP[YYLOW1 .. *YYLOW-1] as in yyfillin and set *YYLOW = YYLOW1.
827 * For convenience, always return YYLOW1. */
828 static inline int yyfill (yyGLRStackItem
*, int *, int, yybool
)
829 __attribute__ ((__unused__
));
831 yyfill (yyGLRStackItem
*yyvsp
, int *yylow
, int yylow1
, yybool yynormal
)
833 if (!yynormal
&& yylow1
< *yylow
)
835 yyfillin (yyvsp
, *yylow
, yylow1
);
841 /** Perform user action for rule number YYN, with RHS length YYRHSLEN,
842 * and top stack item YYVSP. YYLVALP points to place to put semantic
843 * value ($$), and yylocp points to place for location information
844 * (@@$). Returns yyok for normal return, yyaccept for YYACCEPT,
845 * yyerr for YYERROR, yyabort for YYABORT. */
846 /*ARGSUSED*/ static YYRESULTTAG
847 yyuserAction (yyRuleNum yyn
, int yyrhslen
, yyGLRStackItem
* yyvsp
,
849 YYLTYPE
* YYOPTIONAL_LOC (yylocp
),
853 yybool yynormal
__attribute__ ((__unused__
)) =
854 (yystackp
->yysplitPoint
== NULL
);
856 ]b4_parse_param_use
[]dnl
858 # define yyerrok (yystackp->yyerrState = 0)
860 # define YYACCEPT return yyaccept
862 # define YYABORT return yyabort
864 # define YYERROR return yyerrok, yyerr
866 # define YYRECOVERING() (yystackp->yyerrState != 0)
868 # define yyclearin (yychar = YYEMPTY)
870 # define YYFILL(N) yyfill (yyvsp, &yylow, N, yynormal)
872 # define YYBACKUP(Token, Value) \
873 return yyerror (]b4_yyerror_args[YY_("syntax error: cannot back up")), \
878 *yyvalp
= yyval_default
;
880 *yyvalp
= yyvsp
[YYFILL (1-yyrhslen
)].yystate
.yysemantics
.yysval
;
881 YYLLOC_DEFAULT ((*yylocp
), (yyvsp
- yyrhslen
), yyrhslen
);
882 ]b4_locations_if([[ yystackp
->yyerror_range
[1].yystate
.yyloc
= *yylocp
;
901 /*ARGSUSED*/ static void
902 yyuserMerge (int yyn
, YYSTYPE
* yy0
, YYSTYPE
* yy1
)
914 /* Bison grammar-table manipulation. */
916 ]b4_yydestruct_generate([b4_c_ansi_function_def
])[
918 /** Number of symbols composing the right hand side of rule #RULE. */
920 yyrhsLength (yyRuleNum yyrule
)
926 yydestroyGLRState (char const *yymsg
, yyGLRState
*yys
]b4_user_formals
[)
929 yydestruct (yymsg
, yystos
[yys
->yylrState
],
930 &yys
->yysemantics
.yysval
]b4_locations_if([, &yys
->yyloc
])[]b4_user_args
[);
936 if (yys
->yysemantics
.yyfirstVal
)
937 YYFPRINTF (stderr
, "%s unresolved ", yymsg
);
939 YYFPRINTF (stderr
, "%s incomplete ", yymsg
);
940 yy_symbol_print (stderr
, yystos
[yys
->yylrState
],
941 NULL
]b4_locations_if([, &yys
->yyloc
])[]b4_user_args
[);
942 YYFPRINTF (stderr
, "\n");
946 if (yys
->yysemantics
.yyfirstVal
)
948 yySemanticOption
*yyoption
= yys
->yysemantics
.yyfirstVal
;
951 for (yyrh
= yyoption
->yystate
, yyn
= yyrhsLength (yyoption
->yyrule
);
953 yyrh
= yyrh
->yypred
, yyn
-= 1)
954 yydestroyGLRState (yymsg
, yyrh
]b4_user_args
[);
959 /** Left-hand-side symbol for rule #YYRULE. */
960 static inline yySymbol
961 yylhsNonterm (yyRuleNum yyrule
)
966 #define yypact_value_is_default(yystate) \
967 ]b4_table_value_equals([[pact]], [[yystate]], [b4_pact_ninf])[
969 /** True iff LR state YYSTATE has only a default reduction (regardless
972 yyisDefaultedState (yyStateNum yystate
)
974 return yypact_value_is_default (yypact
[yystate
]);
977 /** The default reduction for YYSTATE, assuming it has one. */
978 static inline yyRuleNum
979 yydefaultAction (yyStateNum yystate
)
981 return yydefact
[yystate
];
984 #define yytable_value_is_error(yytable_value) \
985 ]b4_table_value_equals([[table]], [[yytable_value]], [b4_table_ninf])[
987 /** Set *YYACTION to the action to take in YYSTATE on seeing YYTOKEN.
989 * R < 0: Reduce on rule -R.
991 * R > 0: Shift to state R.
992 * Set *YYCONFLICTS to a pointer into yyconfl to a 0-terminated list
993 * of conflicting reductions.
996 yygetLRActions (yyStateNum yystate
, int yytoken
,
997 int* yyaction
, const short int** yyconflicts
)
999 int yyindex
= yypact
[yystate
] + yytoken
;
1000 if (yypact_value_is_default (yypact
[yystate
])
1001 || yyindex
< 0 || YYLAST
< yyindex
|| yycheck
[yyindex
] != yytoken
)
1003 *yyaction
= -yydefact
[yystate
];
1004 *yyconflicts
= yyconfl
;
1006 else if (! yytable_value_is_error (yytable
[yyindex
]))
1008 *yyaction
= yytable
[yyindex
];
1009 *yyconflicts
= yyconfl
+ yyconflp
[yyindex
];
1014 *yyconflicts
= yyconfl
+ yyconflp
[yyindex
];
1018 static inline yyStateNum
1019 yyLRgotoState (yyStateNum yystate
, yySymbol yylhs
)
1021 int yyr
= yypgoto
[yylhs
- YYNTOKENS
] + yystate
;
1022 if (0 <= yyr
&& yyr
<= YYLAST
&& yycheck
[yyr
] == yystate
)
1023 return yytable
[yyr
];
1025 return yydefgoto
[yylhs
- YYNTOKENS
];
1028 static inline yybool
1029 yyisShiftAction (int yyaction
)
1031 return 0 < yyaction
;
1034 static inline yybool
1035 yyisErrorAction (int yyaction
)
1037 return yyaction
== 0;
1042 /** Return a fresh GLRStackItem in YYSTACKP. The item is an LR state
1043 * if YYISSTATE, and otherwise a semantic option. Callers should call
1044 * YY_RESERVE_GLRSTACK afterwards to make sure there is sufficient
1047 static inline yyGLRStackItem
*
1048 yynewGLRStackItem (yyGLRStack
* yystackp
, yybool yyisState
)
1050 yyGLRStackItem
* yynewItem
= yystackp
->yynextFree
;
1051 yystackp
->yyspaceLeft
-= 1;
1052 yystackp
->yynextFree
+= 1;
1053 yynewItem
->yystate
.yyisState
= yyisState
;
1057 /** Add a new semantic action that will execute the action for rule
1058 * YYRULE on the semantic values in YYRHS to the list of
1059 * alternative actions for YYSTATE. Assumes that YYRHS comes from
1060 * stack #YYK of *YYSTACKP. */
1062 yyaddDeferredAction (yyGLRStack
* yystackp
, size_t yyk
, yyGLRState
* yystate
,
1063 yyGLRState
* yyrhs
, yyRuleNum yyrule
)
1065 yySemanticOption
* yynewOption
=
1066 &yynewGLRStackItem (yystackp
, yyfalse
)->yyoption
;
1067 yynewOption
->yystate
= yyrhs
;
1068 yynewOption
->yyrule
= yyrule
;
1069 if (yystackp
->yytops
.yylookaheadNeeds
[yyk
])
1071 yynewOption
->yyrawchar
= yychar
;
1072 yynewOption
->yyval
= yylval
;
1073 yynewOption
->yyloc
= yylloc
;
1076 yynewOption
->yyrawchar
= YYEMPTY
;
1077 yynewOption
->yynext
= yystate
->yysemantics
.yyfirstVal
;
1078 yystate
->yysemantics
.yyfirstVal
= yynewOption
;
1080 YY_RESERVE_GLRSTACK (yystackp
);
1085 /** Initialize YYSET to a singleton set containing an empty stack. */
1087 yyinitStateSet (yyGLRStateSet
* yyset
)
1090 yyset
->yycapacity
= 16;
1091 yyset
->yystates
= (yyGLRState
**) YYMALLOC (16 * sizeof yyset
->yystates
[0]);
1092 if (! yyset
->yystates
)
1094 yyset
->yystates
[0] = NULL
;
1095 yyset
->yylookaheadNeeds
=
1096 (yybool
*) YYMALLOC (16 * sizeof yyset
->yylookaheadNeeds
[0]);
1097 if (! yyset
->yylookaheadNeeds
)
1099 YYFREE (yyset
->yystates
);
1105 static void yyfreeStateSet (yyGLRStateSet
* yyset
)
1107 YYFREE (yyset
->yystates
);
1108 YYFREE (yyset
->yylookaheadNeeds
);
1111 /** Initialize *YYSTACKP to a single empty stack, with total maximum
1112 * capacity for all stacks of YYSIZE. */
1114 yyinitGLRStack (yyGLRStack
* yystackp
, size_t yysize
)
1116 yystackp
->yyerrState
= 0;
1118 yystackp
->yyspaceLeft
= yysize
;
1120 (yyGLRStackItem
*) YYMALLOC (yysize
* sizeof yystackp
->yynextFree
[0]);
1121 if (!yystackp
->yyitems
)
1123 yystackp
->yynextFree
= yystackp
->yyitems
;
1124 yystackp
->yysplitPoint
= NULL
;
1125 yystackp
->yylastDeleted
= NULL
;
1126 return yyinitStateSet (&yystackp
->yytops
);
1130 #if YYSTACKEXPANDABLE
1131 # define YYRELOC(YYFROMITEMS,YYTOITEMS,YYX,YYTYPE) \
1132 &((YYTOITEMS) - ((YYFROMITEMS) - (yyGLRStackItem*) (YYX)))->YYTYPE
1134 /** If *YYSTACKP is expandable, extend it. WARNING: Pointers into the
1135 stack from outside should be considered invalid after this call.
1136 We always expand when there are 1 or fewer items left AFTER an
1137 allocation, so that we can avoid having external pointers exist
1138 across an allocation. */
1140 yyexpandGLRStack (yyGLRStack
* yystackp
)
1142 yyGLRStackItem
* yynewItems
;
1143 yyGLRStackItem
* yyp0
, *yyp1
;
1144 size_t yysize
, yynewSize
;
1146 yysize
= yystackp
->yynextFree
- yystackp
->yyitems
;
1147 if (YYMAXDEPTH
- YYHEADROOM
< yysize
)
1148 yyMemoryExhausted (yystackp
);
1149 yynewSize
= 2*yysize
;
1150 if (YYMAXDEPTH
< yynewSize
)
1151 yynewSize
= YYMAXDEPTH
;
1152 yynewItems
= (yyGLRStackItem
*) YYMALLOC (yynewSize
* sizeof yynewItems
[0]);
1154 yyMemoryExhausted (yystackp
);
1155 for (yyp0
= yystackp
->yyitems
, yyp1
= yynewItems
, yyn
= yysize
;
1157 yyn
-= 1, yyp0
+= 1, yyp1
+= 1)
1160 if (*(yybool
*) yyp0
)
1162 yyGLRState
* yys0
= &yyp0
->yystate
;
1163 yyGLRState
* yys1
= &yyp1
->yystate
;
1164 if (yys0
->yypred
!= NULL
)
1166 YYRELOC (yyp0
, yyp1
, yys0
->yypred
, yystate
);
1167 if (! yys0
->yyresolved
&& yys0
->yysemantics
.yyfirstVal
!= NULL
)
1168 yys1
->yysemantics
.yyfirstVal
=
1169 YYRELOC(yyp0
, yyp1
, yys0
->yysemantics
.yyfirstVal
, yyoption
);
1173 yySemanticOption
* yyv0
= &yyp0
->yyoption
;
1174 yySemanticOption
* yyv1
= &yyp1
->yyoption
;
1175 if (yyv0
->yystate
!= NULL
)
1176 yyv1
->yystate
= YYRELOC (yyp0
, yyp1
, yyv0
->yystate
, yystate
);
1177 if (yyv0
->yynext
!= NULL
)
1178 yyv1
->yynext
= YYRELOC (yyp0
, yyp1
, yyv0
->yynext
, yyoption
);
1181 if (yystackp
->yysplitPoint
!= NULL
)
1182 yystackp
->yysplitPoint
= YYRELOC (yystackp
->yyitems
, yynewItems
,
1183 yystackp
->yysplitPoint
, yystate
);
1185 for (yyn
= 0; yyn
< yystackp
->yytops
.yysize
; yyn
+= 1)
1186 if (yystackp
->yytops
.yystates
[yyn
] != NULL
)
1187 yystackp
->yytops
.yystates
[yyn
] =
1188 YYRELOC (yystackp
->yyitems
, yynewItems
,
1189 yystackp
->yytops
.yystates
[yyn
], yystate
);
1190 YYFREE (yystackp
->yyitems
);
1191 yystackp
->yyitems
= yynewItems
;
1192 yystackp
->yynextFree
= yynewItems
+ yysize
;
1193 yystackp
->yyspaceLeft
= yynewSize
- yysize
;
1198 yyfreeGLRStack (yyGLRStack
* yystackp
)
1200 YYFREE (yystackp
->yyitems
);
1201 yyfreeStateSet (&yystackp
->yytops
);
1204 /** Assuming that YYS is a GLRState somewhere on *YYSTACKP, update the
1205 * splitpoint of *YYSTACKP, if needed, so that it is at least as deep as
1208 yyupdateSplit (yyGLRStack
* yystackp
, yyGLRState
* yys
)
1210 if (yystackp
->yysplitPoint
!= NULL
&& yystackp
->yysplitPoint
> yys
)
1211 yystackp
->yysplitPoint
= yys
;
1214 /** Invalidate stack #YYK in *YYSTACKP. */
1216 yymarkStackDeleted (yyGLRStack
* yystackp
, size_t yyk
)
1218 if (yystackp
->yytops
.yystates
[yyk
] != NULL
)
1219 yystackp
->yylastDeleted
= yystackp
->yytops
.yystates
[yyk
];
1220 yystackp
->yytops
.yystates
[yyk
] = NULL
;
1223 /** Undelete the last stack in *YYSTACKP that was marked as deleted. Can
1224 only be done once after a deletion, and only when all other stacks have
1227 yyundeleteLastStack (yyGLRStack
* yystackp
)
1229 if (yystackp
->yylastDeleted
== NULL
|| yystackp
->yytops
.yysize
!= 0)
1231 yystackp
->yytops
.yystates
[0] = yystackp
->yylastDeleted
;
1232 yystackp
->yytops
.yysize
= 1;
1233 YYDPRINTF ((stderr
, "Restoring last deleted stack as stack #0.\n"));
1234 yystackp
->yylastDeleted
= NULL
;
1238 yyremoveDeletes (yyGLRStack
* yystackp
)
1242 while (yyj
< yystackp
->yytops
.yysize
)
1244 if (yystackp
->yytops
.yystates
[yyi
] == NULL
)
1248 YYDPRINTF ((stderr
, "Removing dead stacks.\n"));
1250 yystackp
->yytops
.yysize
-= 1;
1254 yystackp
->yytops
.yystates
[yyj
] = yystackp
->yytops
.yystates
[yyi
];
1255 /* In the current implementation, it's unnecessary to copy
1256 yystackp->yytops.yylookaheadNeeds[yyi] since, after
1257 yyremoveDeletes returns, the parser immediately either enters
1258 deterministic operation or shifts a token. However, it doesn't
1259 hurt, and the code might evolve to need it. */
1260 yystackp
->yytops
.yylookaheadNeeds
[yyj
] =
1261 yystackp
->yytops
.yylookaheadNeeds
[yyi
];
1264 YYDPRINTF ((stderr
, "Rename stack %lu -> %lu.\n",
1265 (unsigned long int) yyi
, (unsigned long int) yyj
));
1273 /** Shift to a new state on stack #YYK of *YYSTACKP, corresponding to LR
1274 * state YYLRSTATE, at input position YYPOSN, with (resolved) semantic
1275 * value *YYVALP and source location *YYLOCP. */
1277 yyglrShift (yyGLRStack
* yystackp
, size_t yyk
, yyStateNum yylrState
,
1279 YYSTYPE
* yyvalp
, YYLTYPE
* yylocp
)
1281 yyGLRState
* yynewState
= &yynewGLRStackItem (yystackp
, yytrue
)->yystate
;
1283 yynewState
->yylrState
= yylrState
;
1284 yynewState
->yyposn
= yyposn
;
1285 yynewState
->yyresolved
= yytrue
;
1286 yynewState
->yypred
= yystackp
->yytops
.yystates
[yyk
];
1287 yynewState
->yysemantics
.yysval
= *yyvalp
;
1288 yynewState
->yyloc
= *yylocp
;
1289 yystackp
->yytops
.yystates
[yyk
] = yynewState
;
1291 YY_RESERVE_GLRSTACK (yystackp
);
1294 /** Shift stack #YYK of *YYSTACKP, to a new state corresponding to LR
1295 * state YYLRSTATE, at input position YYPOSN, with the (unresolved)
1296 * semantic value of YYRHS under the action for YYRULE. */
1298 yyglrShiftDefer (yyGLRStack
* yystackp
, size_t yyk
, yyStateNum yylrState
,
1299 size_t yyposn
, yyGLRState
* yyrhs
, yyRuleNum yyrule
)
1301 yyGLRState
* yynewState
= &yynewGLRStackItem (yystackp
, yytrue
)->yystate
;
1303 yynewState
->yylrState
= yylrState
;
1304 yynewState
->yyposn
= yyposn
;
1305 yynewState
->yyresolved
= yyfalse
;
1306 yynewState
->yypred
= yystackp
->yytops
.yystates
[yyk
];
1307 yynewState
->yysemantics
.yyfirstVal
= NULL
;
1308 yystackp
->yytops
.yystates
[yyk
] = yynewState
;
1310 /* Invokes YY_RESERVE_GLRSTACK. */
1311 yyaddDeferredAction (yystackp
, yyk
, yynewState
, yyrhs
, yyrule
);
1315 # define YY_REDUCE_PRINT(Args)
1317 # define YY_REDUCE_PRINT(Args) \
1320 yy_reduce_print Args; \
1323 /*----------------------------------------------------------------------.
1324 | Report that stack #YYK of *YYSTACKP is going to be reduced by YYRULE. |
1325 `----------------------------------------------------------------------*/
1327 /*ARGSUSED*/ static inline void
1328 yy_reduce_print (int yynormal
, yyGLRStackItem
* yyvsp
, size_t yyk
, yyRuleNum yyrule
]b4_user_formals
[)
1330 int yynrhs
= yyrhsLength (yyrule
);]b4_locations_if([
1333 ]b4_parse_param_use
[]dnl
1334 [ YYFPRINTF (stderr
, "Reducing stack %lu by rule %d (line %lu):\n",
1335 (unsigned long int) yyk
, yyrule
- 1,
1336 (unsigned long int) yyrline
[yyrule
]);
1338 yyfillin (yyvsp
, 1, -yynrhs
);
1339 /* The symbols being reduced. */
1340 for (yyi
= 0; yyi
< yynrhs
; yyi
++)
1342 YYFPRINTF (stderr
, " $%d = ", yyi
+ 1);
1343 yy_symbol_print (stderr
,
1344 yystos
[yyvsp
[yyi
- yynrhs
+ 1].yystate
.yylrState
],
1345 &yyvsp
[yyi
- yynrhs
+ 1].yystate
.yysemantics
.yysval
1346 ]b4_locations_if([, &]b4_rhs_location(yynrhs
, yyi
+ 1))[]dnl
1348 if (!yyvsp
[yyi
- yynrhs
+ 1].yystate
.yyresolved
)
1349 YYFPRINTF (stderr
, " (unresolved)");
1350 YYFPRINTF (stderr
, "\n");
1355 /** Pop the symbols consumed by reduction #YYRULE from the top of stack
1356 * #YYK of *YYSTACKP, and perform the appropriate semantic action on their
1357 * semantic values. Assumes that all ambiguities in semantic values
1358 * have been previously resolved. Set *YYVALP to the resulting value,
1359 * and *YYLOCP to the computed location (if any). Return value is as
1360 * for userAction. */
1361 static inline YYRESULTTAG
1362 yydoAction (yyGLRStack
* yystackp
, size_t yyk
, yyRuleNum yyrule
,
1363 YYSTYPE
* yyvalp
, YYLTYPE
* yylocp
]b4_user_formals
[)
1365 int yynrhs
= yyrhsLength (yyrule
);
1367 if (yystackp
->yysplitPoint
== NULL
)
1369 /* Standard special case: single stack. */
1370 yyGLRStackItem
* yyrhs
= (yyGLRStackItem
*) yystackp
->yytops
.yystates
[yyk
];
1371 YYASSERT (yyk
== 0);
1372 yystackp
->yynextFree
-= yynrhs
;
1373 yystackp
->yyspaceLeft
+= yynrhs
;
1374 yystackp
->yytops
.yystates
[0] = & yystackp
->yynextFree
[-1].yystate
;
1375 YY_REDUCE_PRINT ((1, yyrhs
, yyk
, yyrule
]b4_user_args
[));
1376 return yyuserAction (yyrule
, yynrhs
, yyrhs
,
1377 yyvalp
, yylocp
, yystackp
]b4_user_args
[);
1383 yyGLRStackItem yyrhsVals
[YYMAXRHS
+ YYMAXLEFT
+ 1];
1384 yys
= yyrhsVals
[YYMAXRHS
+ YYMAXLEFT
].yystate
.yypred
1385 = yystackp
->yytops
.yystates
[yyk
];]b4_locations_if([[
1387 /* Set default location. */
1388 yyrhsVals
[YYMAXRHS
+ YYMAXLEFT
- 1].yystate
.yyloc
= yys
->yyloc
;]])[
1389 for (yyi
= 0; yyi
< yynrhs
; yyi
+= 1)
1394 yyupdateSplit (yystackp
, yys
);
1395 yystackp
->yytops
.yystates
[yyk
] = yys
;
1396 YY_REDUCE_PRINT ((0, yyrhsVals
+ YYMAXRHS
+ YYMAXLEFT
- 1, yyk
, yyrule
]b4_user_args
[));
1397 return yyuserAction (yyrule
, yynrhs
, yyrhsVals
+ YYMAXRHS
+ YYMAXLEFT
- 1,
1398 yyvalp
, yylocp
, yystackp
]b4_user_args
[);
1402 /** Pop items off stack #YYK of *YYSTACKP according to grammar rule YYRULE,
1403 * and push back on the resulting nonterminal symbol. Perform the
1404 * semantic action associated with YYRULE and store its value with the
1405 * newly pushed state, if YYFORCEEVAL or if *YYSTACKP is currently
1406 * unambiguous. Otherwise, store the deferred semantic action with
1407 * the new state. If the new state would have an identical input
1408 * position, LR state, and predecessor to an existing state on the stack,
1409 * it is identified with that existing state, eliminating stack #YYK from
1410 * *YYSTACKP. In this case, the semantic value is
1411 * added to the options for the existing state's semantic value.
1413 static inline YYRESULTTAG
1414 yyglrReduce (yyGLRStack
* yystackp
, size_t yyk
, yyRuleNum yyrule
,
1415 yybool yyforceEval
]b4_user_formals
[)
1417 size_t yyposn
= yystackp
->yytops
.yystates
[yyk
]->yyposn
;
1419 if (yyforceEval
|| yystackp
->yysplitPoint
== NULL
)
1425 yyflag
= yydoAction (yystackp
, yyk
, yyrule
, &yysval
,
1426 &yyloc
]b4_user_args
[);
1427 if (yyflag
== yyerr
&& yystackp
->yysplitPoint
!= NULL
)
1429 YYDPRINTF ((stderr
, "Parse on stack %lu rejected by rule #%d.\n",
1430 (unsigned long int) yyk
, yyrule
- 1));
1434 YY_SYMBOL_PRINT ("-> $$ =", yyr1
[yyrule
], &yysval
, &yyloc
);
1435 yyglrShift (yystackp
, yyk
,
1436 yyLRgotoState (yystackp
->yytops
.yystates
[yyk
]->yylrState
,
1437 yylhsNonterm (yyrule
)),
1438 yyposn
, &yysval
, &yyloc
);
1444 yyGLRState
* yys
, *yys0
= yystackp
->yytops
.yystates
[yyk
];
1445 yyStateNum yynewLRState
;
1447 for (yys
= yystackp
->yytops
.yystates
[yyk
], yyn
= yyrhsLength (yyrule
);
1453 yyupdateSplit (yystackp
, yys
);
1454 yynewLRState
= yyLRgotoState (yys
->yylrState
, yylhsNonterm (yyrule
));
1456 "Reduced stack %lu by rule #%d; action deferred. Now in state %d.\n",
1457 (unsigned long int) yyk
, yyrule
- 1, yynewLRState
));
1458 for (yyi
= 0; yyi
< yystackp
->yytops
.yysize
; yyi
+= 1)
1459 if (yyi
!= yyk
&& yystackp
->yytops
.yystates
[yyi
] != NULL
)
1461 yyGLRState
* yyp
, *yysplit
= yystackp
->yysplitPoint
;
1462 yyp
= yystackp
->yytops
.yystates
[yyi
];
1463 while (yyp
!= yys
&& yyp
!= yysplit
&& yyp
->yyposn
>= yyposn
)
1465 if (yyp
->yylrState
== yynewLRState
&& yyp
->yypred
== yys
)
1467 yyaddDeferredAction (yystackp
, yyk
, yyp
, yys0
, yyrule
);
1468 yymarkStackDeleted (yystackp
, yyk
);
1469 YYDPRINTF ((stderr
, "Merging stack %lu into stack %lu.\n",
1470 (unsigned long int) yyk
,
1471 (unsigned long int) yyi
));
1477 yystackp
->yytops
.yystates
[yyk
] = yys
;
1478 yyglrShiftDefer (yystackp
, yyk
, yynewLRState
, yyposn
, yys0
, yyrule
);
1484 yysplitStack (yyGLRStack
* yystackp
, size_t yyk
)
1486 if (yystackp
->yysplitPoint
== NULL
)
1488 YYASSERT (yyk
== 0);
1489 yystackp
->yysplitPoint
= yystackp
->yytops
.yystates
[yyk
];
1491 if (yystackp
->yytops
.yysize
>= yystackp
->yytops
.yycapacity
)
1493 yyGLRState
** yynewStates
;
1494 yybool
* yynewLookaheadNeeds
;
1498 if (yystackp
->yytops
.yycapacity
1499 > (YYSIZEMAX
/ (2 * sizeof yynewStates
[0])))
1500 yyMemoryExhausted (yystackp
);
1501 yystackp
->yytops
.yycapacity
*= 2;
1504 (yyGLRState
**) YYREALLOC (yystackp
->yytops
.yystates
,
1505 (yystackp
->yytops
.yycapacity
1506 * sizeof yynewStates
[0]));
1507 if (yynewStates
== NULL
)
1508 yyMemoryExhausted (yystackp
);
1509 yystackp
->yytops
.yystates
= yynewStates
;
1511 yynewLookaheadNeeds
=
1512 (yybool
*) YYREALLOC (yystackp
->yytops
.yylookaheadNeeds
,
1513 (yystackp
->yytops
.yycapacity
1514 * sizeof yynewLookaheadNeeds
[0]));
1515 if (yynewLookaheadNeeds
== NULL
)
1516 yyMemoryExhausted (yystackp
);
1517 yystackp
->yytops
.yylookaheadNeeds
= yynewLookaheadNeeds
;
1519 yystackp
->yytops
.yystates
[yystackp
->yytops
.yysize
]
1520 = yystackp
->yytops
.yystates
[yyk
];
1521 yystackp
->yytops
.yylookaheadNeeds
[yystackp
->yytops
.yysize
]
1522 = yystackp
->yytops
.yylookaheadNeeds
[yyk
];
1523 yystackp
->yytops
.yysize
+= 1;
1524 return yystackp
->yytops
.yysize
-1;
1527 /** True iff YYY0 and YYY1 represent identical options at the top level.
1528 * That is, they represent the same rule applied to RHS symbols
1529 * that produce the same terminal symbols. */
1531 yyidenticalOptions (yySemanticOption
* yyy0
, yySemanticOption
* yyy1
)
1533 if (yyy0
->yyrule
== yyy1
->yyrule
)
1535 yyGLRState
*yys0
, *yys1
;
1537 for (yys0
= yyy0
->yystate
, yys1
= yyy1
->yystate
,
1538 yyn
= yyrhsLength (yyy0
->yyrule
);
1540 yys0
= yys0
->yypred
, yys1
= yys1
->yypred
, yyn
-= 1)
1541 if (yys0
->yyposn
!= yys1
->yyposn
)
1549 /** Assuming identicalOptions (YYY0,YYY1), destructively merge the
1550 * alternative semantic values for the RHS-symbols of YYY1 and YYY0. */
1552 yymergeOptionSets (yySemanticOption
* yyy0
, yySemanticOption
* yyy1
)
1554 yyGLRState
*yys0
, *yys1
;
1556 for (yys0
= yyy0
->yystate
, yys1
= yyy1
->yystate
,
1557 yyn
= yyrhsLength (yyy0
->yyrule
);
1559 yys0
= yys0
->yypred
, yys1
= yys1
->yypred
, yyn
-= 1)
1563 else if (yys0
->yyresolved
)
1565 yys1
->yyresolved
= yytrue
;
1566 yys1
->yysemantics
.yysval
= yys0
->yysemantics
.yysval
;
1568 else if (yys1
->yyresolved
)
1570 yys0
->yyresolved
= yytrue
;
1571 yys0
->yysemantics
.yysval
= yys1
->yysemantics
.yysval
;
1575 yySemanticOption
** yyz0p
;
1576 yySemanticOption
* yyz1
;
1577 yyz0p
= &yys0
->yysemantics
.yyfirstVal
;
1578 yyz1
= yys1
->yysemantics
.yyfirstVal
;
1579 while (YYID (yytrue
))
1581 if (yyz1
== *yyz0p
|| yyz1
== NULL
)
1583 else if (*yyz0p
== NULL
)
1588 else if (*yyz0p
< yyz1
)
1590 yySemanticOption
* yyz
= *yyz0p
;
1592 yyz1
= yyz1
->yynext
;
1593 (*yyz0p
)->yynext
= yyz
;
1595 yyz0p
= &(*yyz0p
)->yynext
;
1597 yys1
->yysemantics
.yyfirstVal
= yys0
->yysemantics
.yyfirstVal
;
1602 /** Y0 and Y1 represent two possible actions to take in a given
1603 * parsing state; return 0 if no combination is possible,
1604 * 1 if user-mergeable, 2 if Y0 is preferred, 3 if Y1 is preferred. */
1606 yypreference (yySemanticOption
* y0
, yySemanticOption
* y1
)
1608 yyRuleNum r0
= y0
->yyrule
, r1
= y1
->yyrule
;
1609 int p0
= yydprec
[r0
], p1
= yydprec
[r1
];
1613 if (yymerger
[r0
] == 0 || yymerger
[r0
] != yymerger
[r1
])
1618 if (p0
== 0 || p1
== 0)
1627 static YYRESULTTAG
yyresolveValue (yyGLRState
* yys
,
1628 yyGLRStack
* yystackp
]b4_user_formals
[);
1631 /** Resolve the previous YYN states starting at and including state YYS
1632 * on *YYSTACKP. If result != yyok, some states may have been left
1633 * unresolved possibly with empty semantic option chains. Regardless
1634 * of whether result = yyok, each state has been left with consistent
1635 * data so that yydestroyGLRState can be invoked if necessary. */
1637 yyresolveStates (yyGLRState
* yys
, int yyn
,
1638 yyGLRStack
* yystackp
]b4_user_formals
[)
1642 YYASSERT (yys
->yypred
);
1643 YYCHK (yyresolveStates (yys
->yypred
, yyn
-1, yystackp
]b4_user_args
[));
1644 if (! yys
->yyresolved
)
1645 YYCHK (yyresolveValue (yys
, yystackp
]b4_user_args
[));
1650 /** Resolve the states for the RHS of YYOPT on *YYSTACKP, perform its
1651 * user action, and return the semantic value and location in *YYVALP
1652 * and *YYLOCP. Regardless of whether result = yyok, all RHS states
1653 * have been destroyed (assuming the user action destroys all RHS
1654 * semantic values if invoked). */
1656 yyresolveAction (yySemanticOption
* yyopt
, yyGLRStack
* yystackp
,
1657 YYSTYPE
* yyvalp
, YYLTYPE
* yylocp
]b4_user_formals
[)
1659 yyGLRStackItem yyrhsVals
[YYMAXRHS
+ YYMAXLEFT
+ 1];
1662 YYSTYPE yylval_current
;
1663 YYLTYPE yylloc_current
;
1666 yynrhs
= yyrhsLength (yyopt
->yyrule
);
1667 yyflag
= yyresolveStates (yyopt
->yystate
, yynrhs
, yystackp
]b4_user_args
[);
1671 for (yys
= yyopt
->yystate
; yynrhs
> 0; yys
= yys
->yypred
, yynrhs
-= 1)
1672 yydestroyGLRState ("Cleanup: popping", yys
]b4_user_args
[);
1676 yyrhsVals
[YYMAXRHS
+ YYMAXLEFT
].yystate
.yypred
= yyopt
->yystate
;]b4_locations_if([[
1678 /* Set default location. */
1679 yyrhsVals
[YYMAXRHS
+ YYMAXLEFT
- 1].yystate
.yyloc
= yyopt
->yystate
->yyloc
;]])[
1680 yychar_current
= yychar
;
1681 yylval_current
= yylval
;
1682 yylloc_current
= yylloc
;
1683 yychar
= yyopt
->yyrawchar
;
1684 yylval
= yyopt
->yyval
;
1685 yylloc
= yyopt
->yyloc
;
1686 yyflag
= yyuserAction (yyopt
->yyrule
, yynrhs
,
1687 yyrhsVals
+ YYMAXRHS
+ YYMAXLEFT
- 1,
1688 yyvalp
, yylocp
, yystackp
]b4_user_args
[);
1689 yychar
= yychar_current
;
1690 yylval
= yylval_current
;
1691 yylloc
= yylloc_current
;
1697 yyreportTree (yySemanticOption
* yyx
, int yyindent
)
1699 int yynrhs
= yyrhsLength (yyx
->yyrule
);
1702 yyGLRState
* yystates
[1 + YYMAXRHS
];
1703 yyGLRState yyleftmost_state
;
1705 for (yyi
= yynrhs
, yys
= yyx
->yystate
; 0 < yyi
; yyi
-= 1, yys
= yys
->yypred
)
1706 yystates
[yyi
] = yys
;
1709 yyleftmost_state
.yyposn
= 0;
1710 yystates
[0] = &yyleftmost_state
;
1715 if (yyx
->yystate
->yyposn
< yys
->yyposn
+ 1)
1716 YYFPRINTF (stderr
, "%*s%s -> <Rule %d, empty>\n",
1717 yyindent
, "", yytokenName (yylhsNonterm (yyx
->yyrule
)),
1720 YYFPRINTF (stderr
, "%*s%s -> <Rule %d, tokens %lu .. %lu>\n",
1721 yyindent
, "", yytokenName (yylhsNonterm (yyx
->yyrule
)),
1722 yyx
->yyrule
- 1, (unsigned long int) (yys
->yyposn
+ 1),
1723 (unsigned long int) yyx
->yystate
->yyposn
);
1724 for (yyi
= 1; yyi
<= yynrhs
; yyi
+= 1)
1726 if (yystates
[yyi
]->yyresolved
)
1728 if (yystates
[yyi
-1]->yyposn
+1 > yystates
[yyi
]->yyposn
)
1729 YYFPRINTF (stderr
, "%*s%s <empty>\n", yyindent
+2, "",
1730 yytokenName (yystos
[yystates
[yyi
-1]->yylrState
]));
1732 YYFPRINTF (stderr
, "%*s%s <tokens %lu .. %lu>\n", yyindent
+2, "",
1733 yytokenName (yystos
[yystates
[yyi
-1]->yylrState
]),
1734 (unsigned long int) (yystates
[yyi
-1]->yyposn
+ 1),
1735 (unsigned long int) yystates
[yyi
]->yyposn
);
1738 yyreportTree (yystates
[yyi
]->yysemantics
.yyfirstVal
, yyindent
+2);
1743 /*ARGSUSED*/ static YYRESULTTAG
1744 yyreportAmbiguity (yySemanticOption
* yyx0
,
1745 yySemanticOption
* yyx1
]b4_pure_formals
[)
1751 YYFPRINTF (stderr
, "Ambiguity detected.\n");
1752 YYFPRINTF (stderr
, "Option 1,\n");
1753 yyreportTree (yyx0
, 2);
1754 YYFPRINTF (stderr
, "\nOption 2,\n");
1755 yyreportTree (yyx1
, 2);
1756 YYFPRINTF (stderr
, "\n");
1759 yyerror (]b4_yyerror_args
[YY_("syntax is ambiguous"));
1763 /** Resolve the locations for each of the YYN1 states in *YYSTACKP,
1764 * ending at YYS1. Has no effect on previously resolved states.
1765 * The first semantic option of a state is always chosen. */
1767 yyresolveLocations (yyGLRState
* yys1
, int yyn1
,
1768 yyGLRStack
*yystackp
]b4_user_formals
[)
1772 yyresolveLocations (yys1
->yypred
, yyn1
- 1, yystackp
]b4_user_args
[);
1773 if (!yys1
->yyresolved
)
1775 yySemanticOption
*yyoption
;
1776 yyGLRStackItem yyrhsloc
[1 + YYMAXRHS
];
1779 YYSTYPE yylval_current
;
1780 YYLTYPE yylloc_current
;
1781 yyoption
= yys1
->yysemantics
.yyfirstVal
;
1782 YYASSERT (yyoption
!= NULL
);
1783 yynrhs
= yyrhsLength (yyoption
->yyrule
);
1788 yyresolveLocations (yyoption
->yystate
, yynrhs
,
1789 yystackp
]b4_user_args
[);
1790 for (yys
= yyoption
->yystate
, yyn
= yynrhs
;
1792 yys
= yys
->yypred
, yyn
-= 1)
1793 yyrhsloc
[yyn
].yystate
.yyloc
= yys
->yyloc
;
1797 /* Both yyresolveAction and yyresolveLocations traverse the GSS
1798 in reverse rightmost order. It is only necessary to invoke
1799 yyresolveLocations on a subforest for which yyresolveAction
1800 would have been invoked next had an ambiguity not been
1801 detected. Thus the location of the previous state (but not
1802 necessarily the previous state itself) is guaranteed to be
1803 resolved already. */
1804 yyGLRState
*yyprevious
= yyoption
->yystate
;
1805 yyrhsloc
[0].yystate
.yyloc
= yyprevious
->yyloc
;
1807 yychar_current
= yychar
;
1808 yylval_current
= yylval
;
1809 yylloc_current
= yylloc
;
1810 yychar
= yyoption
->yyrawchar
;
1811 yylval
= yyoption
->yyval
;
1812 yylloc
= yyoption
->yyloc
;
1813 YYLLOC_DEFAULT ((yys1
->yyloc
), yyrhsloc
, yynrhs
);
1814 yychar
= yychar_current
;
1815 yylval
= yylval_current
;
1816 yylloc
= yylloc_current
;
1821 /** Resolve the ambiguity represented in state YYS in *YYSTACKP,
1822 * perform the indicated actions, and set the semantic value of YYS.
1823 * If result != yyok, the chain of semantic options in YYS has been
1824 * cleared instead or it has been left unmodified except that
1825 * redundant options may have been removed. Regardless of whether
1826 * result = yyok, YYS has been left with consistent data so that
1827 * yydestroyGLRState can be invoked if necessary. */
1829 yyresolveValue (yyGLRState
* yys
, yyGLRStack
* yystackp
]b4_user_formals
[)
1831 yySemanticOption
* yyoptionList
= yys
->yysemantics
.yyfirstVal
;
1832 yySemanticOption
* yybest
;
1833 yySemanticOption
** yypp
;
1837 YYLTYPE
*yylocp
= &yys
->yyloc
;
1839 yybest
= yyoptionList
;
1841 for (yypp
= &yyoptionList
->yynext
; *yypp
!= NULL
; )
1843 yySemanticOption
* yyp
= *yypp
;
1845 if (yyidenticalOptions (yybest
, yyp
))
1847 yymergeOptionSets (yybest
, yyp
);
1848 *yypp
= yyp
->yynext
;
1852 switch (yypreference (yybest
, yyp
))
1855 yyresolveLocations (yys
, 1, yystackp
]b4_user_args
[);
1856 return yyreportAmbiguity (yybest
, yyp
]b4_pure_args
[);
1868 /* This cannot happen so it is not worth a YYASSERT (yyfalse),
1869 but some compilers complain if the default case is
1873 yypp
= &yyp
->yynext
;
1879 yySemanticOption
* yyp
;
1880 int yyprec
= yydprec
[yybest
->yyrule
];
1881 yyflag
= yyresolveAction (yybest
, yystackp
, &yysval
,
1882 yylocp
]b4_user_args
[);
1884 for (yyp
= yybest
->yynext
; yyp
!= NULL
; yyp
= yyp
->yynext
)
1886 if (yyprec
== yydprec
[yyp
->yyrule
])
1888 YYSTYPE yysval_other
;
1890 yyflag
= yyresolveAction (yyp
, yystackp
, &yysval_other
,
1891 &yydummy
]b4_user_args
[);
1894 yydestruct ("Cleanup: discarding incompletely merged value for",
1895 yystos
[yys
->yylrState
],
1896 &yysval
]b4_locations_if([, yylocp
])[]b4_user_args
[);
1899 yyuserMerge (yymerger
[yyp
->yyrule
], &yysval
, &yysval_other
);
1904 yyflag
= yyresolveAction (yybest
, yystackp
, &yysval
, yylocp
]b4_user_args
[);
1908 yys
->yyresolved
= yytrue
;
1909 yys
->yysemantics
.yysval
= yysval
;
1912 yys
->yysemantics
.yyfirstVal
= NULL
;
1917 yyresolveStack (yyGLRStack
* yystackp
]b4_user_formals
[)
1919 if (yystackp
->yysplitPoint
!= NULL
)
1924 for (yyn
= 0, yys
= yystackp
->yytops
.yystates
[0];
1925 yys
!= yystackp
->yysplitPoint
;
1926 yys
= yys
->yypred
, yyn
+= 1)
1928 YYCHK (yyresolveStates (yystackp
->yytops
.yystates
[0], yyn
, yystackp
1935 yycompressStack (yyGLRStack
* yystackp
)
1937 yyGLRState
* yyp
, *yyq
, *yyr
;
1939 if (yystackp
->yytops
.yysize
!= 1 || yystackp
->yysplitPoint
== NULL
)
1942 for (yyp
= yystackp
->yytops
.yystates
[0], yyq
= yyp
->yypred
, yyr
= NULL
;
1943 yyp
!= yystackp
->yysplitPoint
;
1944 yyr
= yyp
, yyp
= yyq
, yyq
= yyp
->yypred
)
1947 yystackp
->yyspaceLeft
+= yystackp
->yynextFree
- yystackp
->yyitems
;
1948 yystackp
->yynextFree
= ((yyGLRStackItem
*) yystackp
->yysplitPoint
) + 1;
1949 yystackp
->yyspaceLeft
-= yystackp
->yynextFree
- yystackp
->yyitems
;
1950 yystackp
->yysplitPoint
= NULL
;
1951 yystackp
->yylastDeleted
= NULL
;
1955 yystackp
->yynextFree
->yystate
= *yyr
;
1957 yystackp
->yynextFree
->yystate
.yypred
= &yystackp
->yynextFree
[-1].yystate
;
1958 yystackp
->yytops
.yystates
[0] = &yystackp
->yynextFree
->yystate
;
1959 yystackp
->yynextFree
+= 1;
1960 yystackp
->yyspaceLeft
-= 1;
1965 yyprocessOneStack (yyGLRStack
* yystackp
, size_t yyk
,
1966 size_t yyposn
]b4_pure_formals
[)
1968 while (yystackp
->yytops
.yystates
[yyk
] != NULL
)
1970 yyStateNum yystate
= yystackp
->yytops
.yystates
[yyk
]->yylrState
;
1971 YYDPRINTF ((stderr
, "Stack %lu Entering state %d\n",
1972 (unsigned long int) yyk
, yystate
));
1974 YYASSERT (yystate
!= YYFINAL
);
1976 if (yyisDefaultedState (yystate
))
1979 yyRuleNum yyrule
= yydefaultAction (yystate
);
1982 YYDPRINTF ((stderr
, "Stack %lu dies.\n",
1983 (unsigned long int) yyk
));
1984 yymarkStackDeleted (yystackp
, yyk
);
1987 yyflag
= yyglrReduce (yystackp
, yyk
, yyrule
, yyimmediate
[yyrule
]]b4_user_args
[);
1988 if (yyflag
== yyerr
)
1990 YYDPRINTF ((stderr
, "Stack %lu dies (predicate failure or explicit user error).\n",
1991 (unsigned long int) yyk
));
1992 yymarkStackDeleted (yystackp
, yyk
);
2002 const short int* yyconflicts
;
2004 yystackp
->yytops
.yylookaheadNeeds
[yyk
] = yytrue
;
2005 if (yychar
== YYEMPTY
)
2007 YYDPRINTF ((stderr
, "Reading a token: "));
2011 if (yychar
<= YYEOF
)
2013 yychar
= yytoken
= YYEOF
;
2014 YYDPRINTF ((stderr
, "Now at end of input.\n"));
2018 yytoken
= YYTRANSLATE (yychar
);
2019 YY_SYMBOL_PRINT ("Next token is", yytoken
, &yylval
, &yylloc
);
2022 yygetLRActions (yystate
, yytoken
, &yyaction
, &yyconflicts
);
2024 while (*yyconflicts
!= 0)
2027 size_t yynewStack
= yysplitStack (yystackp
, yyk
);
2028 YYDPRINTF ((stderr
, "Splitting off stack %lu from %lu.\n",
2029 (unsigned long int) yynewStack
,
2030 (unsigned long int) yyk
));
2031 yyflag
= yyglrReduce (yystackp
, yynewStack
,
2033 yyimmediate
[*yyconflicts
]]b4_user_args
[);
2035 YYCHK (yyprocessOneStack (yystackp
, yynewStack
,
2036 yyposn
]b4_pure_args
[));
2037 else if (yyflag
== yyerr
)
2039 YYDPRINTF ((stderr
, "Stack %lu dies.\n",
2040 (unsigned long int) yynewStack
));
2041 yymarkStackDeleted (yystackp
, yynewStack
);
2048 if (yyisShiftAction (yyaction
))
2050 else if (yyisErrorAction (yyaction
))
2052 YYDPRINTF ((stderr
, "Stack %lu dies.\n",
2053 (unsigned long int) yyk
));
2054 yymarkStackDeleted (yystackp
, yyk
);
2059 YYRESULTTAG yyflag
= yyglrReduce (yystackp
, yyk
, -yyaction
,
2060 yyimmediate
[-yyaction
]]b4_user_args
[);
2061 if (yyflag
== yyerr
)
2063 YYDPRINTF ((stderr
, "Stack %lu dies (predicate failure or explicit user error).\n",
2064 (unsigned long int) yyk
));
2065 yymarkStackDeleted (yystackp
, yyk
);
2068 else if (yyflag
!= yyok
)
2076 /*ARGSUSED*/ static void
2077 yyreportSyntaxError (yyGLRStack
* yystackp
]b4_user_formals
[)
2079 if (yystackp
->yyerrState
== 0)
2083 yyn
= yypact
[yystackp
->yytops
.yystates
[0]->yylrState
];
2084 if (YYPACT_NINF
< yyn
&& yyn
<= YYLAST
)
2086 yySymbol yytoken
= YYTRANSLATE (yychar
);
2087 size_t yysize0
= yytnamerr (NULL
, yytokenName (yytoken
));
2088 size_t yysize
= yysize0
;
2090 yybool yysize_overflow
= yyfalse
;
2092 enum { YYERROR_VERBOSE_ARGS_MAXIMUM
= 5 };
2093 /* Internationalized format string. */
2094 const char *yyformat
= 0;
2095 /* Arguments of yyformat. */
2096 char const *yyarg
[YYERROR_VERBOSE_ARGS_MAXIMUM
];
2098 /* Start YYX at -YYN if negative to avoid negative indexes in
2099 YYCHECK. In other words, skip the first -YYN actions for this
2100 state because they are default actions. */
2101 int yyxbegin
= yyn
< 0 ? -yyn
: 0;
2103 /* Stay within bounds of both yycheck and yytname. */
2104 int yychecklim
= YYLAST
- yyn
+ 1;
2105 int yyxend
= yychecklim
< YYNTOKENS
? yychecklim
: YYNTOKENS
;
2107 /* Number of reported tokens (one for the "unexpected", one per
2112 yyarg
[yycount
++] = yytokenName (yytoken
);
2114 for (yyx
= yyxbegin
; yyx
< yyxend
; ++yyx
)
2115 if (yycheck
[yyx
+ yyn
] == yyx
&& yyx
!= YYTERROR
2116 && !yytable_value_is_error (yytable
[yyx
+ yyn
]))
2118 if (yycount
== YYERROR_VERBOSE_ARGS_MAXIMUM
)
2124 yyarg
[yycount
++] = yytokenName (yyx
);
2125 yysize1
= yysize
+ yytnamerr (NULL
, yytokenName (yyx
));
2126 yysize_overflow
|= yysize1
< yysize
;
2132 #define YYCASE_(N, S) \
2136 YYCASE_(1, YY_("syntax error, unexpected %s"));
2137 YYCASE_(2, YY_("syntax error, unexpected %s, expecting %s"));
2138 YYCASE_(3, YY_("syntax error, unexpected %s, expecting %s or %s"));
2139 YYCASE_(4, YY_("syntax error, unexpected %s, expecting %s or %s or %s"));
2140 YYCASE_(5, YY_("syntax error, unexpected %s, expecting %s or %s or %s or %s"));
2144 yysize1
= yysize
+ strlen (yyformat
);
2145 yysize_overflow
|= yysize1
< yysize
;
2148 if (!yysize_overflow
)
2149 yymsg
= (char *) YYMALLOC (yysize
);
2155 while ((*yyp
= *yyformat
))
2157 if (*yyp
== '%' && yyformat
[1] == 's' && yyi
< yycount
)
2159 yyp
+= yytnamerr (yyp
, yyarg
[yyi
++]);
2168 yyerror (]b4_lyyerror_args
[yymsg
);
2173 yyerror (]b4_lyyerror_args
[YY_("syntax error"));
2174 yyMemoryExhausted (yystackp
);
2178 #endif /* YYERROR_VERBOSE */
2179 yyerror (]b4_lyyerror_args
[YY_("syntax error"));
2184 /* Recover from a syntax error on *YYSTACKP, assuming that *YYSTACKP->YYTOKENP,
2185 yylval, and yylloc are the syntactic category, semantic value, and location
2186 of the lookahead. */
2187 /*ARGSUSED*/ static void
2188 yyrecoverSyntaxError (yyGLRStack
* yystackp
]b4_user_formals
[)
2193 if (yystackp
->yyerrState
== 3)
2194 /* We just shifted the error token and (perhaps) took some
2195 reductions. Skip tokens until we can proceed. */
2196 while (YYID (yytrue
))
2199 if (yychar
== YYEOF
)
2200 yyFail (yystackp
][]b4_lpure_args
[, NULL
);
2201 if (yychar
!= YYEMPTY
)
2202 {]b4_locations_if([[
2203 /* We throw away the lookahead, but the error range
2204 of the shifted error token must take it into account. */
2205 yyGLRState
*yys
= yystackp
->yytops
.yystates
[0];
2206 yyGLRStackItem yyerror_range
[3];
2207 yyerror_range
[1].yystate
.yyloc
= yys
->yyloc
;
2208 yyerror_range
[2].yystate
.yyloc
= yylloc
;
2209 YYLLOC_DEFAULT ((yys
->yyloc
), yyerror_range
, 2);]])[
2210 yytoken
= YYTRANSLATE (yychar
);
2211 yydestruct ("Error: discarding",
2212 yytoken
, &yylval
]b4_locations_if([, &yylloc
])[]b4_user_args
[);
2214 YYDPRINTF ((stderr
, "Reading a token: "));
2216 if (yychar
<= YYEOF
)
2218 yychar
= yytoken
= YYEOF
;
2219 YYDPRINTF ((stderr
, "Now at end of input.\n"));
2223 yytoken
= YYTRANSLATE (yychar
);
2224 YY_SYMBOL_PRINT ("Next token is", yytoken
, &yylval
, &yylloc
);
2226 yyj
= yypact
[yystackp
->yytops
.yystates
[0]->yylrState
];
2227 if (yypact_value_is_default (yyj
))
2230 if (yyj
< 0 || YYLAST
< yyj
|| yycheck
[yyj
] != yytoken
)
2232 if (yydefact
[yystackp
->yytops
.yystates
[0]->yylrState
] != 0)
2235 else if (! yytable_value_is_error (yytable
[yyj
]))
2239 /* Reduce to one stack. */
2240 for (yyk
= 0; yyk
< yystackp
->yytops
.yysize
; yyk
+= 1)
2241 if (yystackp
->yytops
.yystates
[yyk
] != NULL
)
2243 if (yyk
>= yystackp
->yytops
.yysize
)
2244 yyFail (yystackp
][]b4_lpure_args
[, NULL
);
2245 for (yyk
+= 1; yyk
< yystackp
->yytops
.yysize
; yyk
+= 1)
2246 yymarkStackDeleted (yystackp
, yyk
);
2247 yyremoveDeletes (yystackp
);
2248 yycompressStack (yystackp
);
2250 /* Now pop stack until we find a state that shifts the error token. */
2251 yystackp
->yyerrState
= 3;
2252 while (yystackp
->yytops
.yystates
[0] != NULL
)
2254 yyGLRState
*yys
= yystackp
->yytops
.yystates
[0];
2255 yyj
= yypact
[yys
->yylrState
];
2256 if (! yypact_value_is_default (yyj
))
2259 if (0 <= yyj
&& yyj
<= YYLAST
&& yycheck
[yyj
] == YYTERROR
2260 && yyisShiftAction (yytable
[yyj
]))
2262 /* Shift the error token having adjusted its location. */
2263 YYLTYPE yyerrloc
;]b4_locations_if([[
2264 yystackp
->yyerror_range
[2].yystate
.yyloc
= yylloc
;
2265 YYLLOC_DEFAULT (yyerrloc
, (yystackp
->yyerror_range
), 2);]])[
2266 YY_SYMBOL_PRINT ("Shifting", yystos
[yytable
[yyj
]],
2267 &yylval
, &yyerrloc
);
2268 yyglrShift (yystackp
, 0, yytable
[yyj
],
2269 yys
->yyposn
, &yylval
, &yyerrloc
);
2270 yys
= yystackp
->yytops
.yystates
[0];
2274 ]b4_locations_if([[ yystackp
->yyerror_range
[1].yystate
.yyloc
= yys
->yyloc
;]])[
2275 if (yys
->yypred
!= NULL
)
2276 yydestroyGLRState ("Error: popping", yys
]b4_user_args
[);
2277 yystackp
->yytops
.yystates
[0] = yys
->yypred
;
2278 yystackp
->yynextFree
-= 1;
2279 yystackp
->yyspaceLeft
+= 1;
2281 if (yystackp
->yytops
.yystates
[0] == NULL
)
2282 yyFail (yystackp
][]b4_lpure_args
[, NULL
);
2285 #define YYCHK1(YYE) \
2295 goto yyuser_error; \
2305 ]b4_c_ansi_function_def([yyparse
], [int], b4_parse_param
)[
2309 yyGLRStack
* const yystackp
= &yystack
;
2312 YYDPRINTF ((stderr
, "Starting parse\n"));
2315 yylval
= yyval_default
;
2317 #if defined YYLTYPE_IS_TRIVIAL && YYLTYPE_IS_TRIVIAL
2318 yylloc
.first_line
= yylloc
.last_line
= ]b4_location_initial_line
[;
2319 yylloc
.first_column
= yylloc
.last_column
= ]b4_location_initial_column
[;
2322 m4_ifdef([b4_initial_action
], [
2323 m4_pushdef([b4_at_dollar
], [yylloc
])dnl
2324 m4_pushdef([b4_dollar_dollar
], [yylval
])dnl
2325 /* User initialization code. */
2326 b4_user_initial_action
2327 m4_popdef([b4_dollar_dollar
])dnl
2328 m4_popdef([b4_at_dollar
])])dnl
2330 if (! yyinitGLRStack (yystackp
, YYINITDEPTH
))
2331 goto yyexhaustedlab
;
2332 switch (YYSETJMP (yystack
.yyexception_buffer
))
2335 case 1: goto yyabortlab
;
2336 case 2: goto yyexhaustedlab
;
2337 default: goto yybuglab
;
2339 yyglrShift (&yystack
, 0, 0, 0, &yylval
, &yylloc
);
2342 while (YYID (yytrue
))
2344 /* For efficiency, we have two loops, the first of which is
2345 specialized to deterministic operation (single stack, no
2346 potential ambiguity). */
2348 while (YYID (yytrue
))
2352 const short int* yyconflicts
;
2354 yyStateNum yystate
= yystack
.yytops
.yystates
[0]->yylrState
;
2355 YYDPRINTF ((stderr
, "Entering state %d\n", yystate
));
2356 if (yystate
== YYFINAL
)
2358 if (yyisDefaultedState (yystate
))
2360 yyrule
= yydefaultAction (yystate
);
2363 ]b4_locations_if([[ yystack
.yyerror_range
[1].yystate
.yyloc
= yylloc
;]])[
2364 yyreportSyntaxError (&yystack
]b4_user_args
[);
2367 YYCHK1 (yyglrReduce (&yystack
, 0, yyrule
, yytrue
]b4_user_args
[));
2372 if (yychar
== YYEMPTY
)
2374 YYDPRINTF ((stderr
, "Reading a token: "));
2378 if (yychar
<= YYEOF
)
2380 yychar
= yytoken
= YYEOF
;
2381 YYDPRINTF ((stderr
, "Now at end of input.\n"));
2385 yytoken
= YYTRANSLATE (yychar
);
2386 YY_SYMBOL_PRINT ("Next token is", yytoken
, &yylval
, &yylloc
);
2389 yygetLRActions (yystate
, yytoken
, &yyaction
, &yyconflicts
);
2390 if (*yyconflicts
!= 0)
2392 if (yyisShiftAction (yyaction
))
2394 YY_SYMBOL_PRINT ("Shifting", yytoken
, &yylval
, &yylloc
);
2397 yyglrShift (&yystack
, 0, yyaction
, yyposn
, &yylval
, &yylloc
);
2398 if (0 < yystack
.yyerrState
)
2399 yystack
.yyerrState
-= 1;
2401 else if (yyisErrorAction (yyaction
))
2403 ]b4_locations_if([[ yystack
.yyerror_range
[1].yystate
.yyloc
= yylloc
;]])[
2404 yyreportSyntaxError (&yystack
]b4_user_args
[);
2408 YYCHK1 (yyglrReduce (&yystack
, 0, -yyaction
, yytrue
]b4_user_args
[));
2412 while (YYID (yytrue
))
2414 yySymbol yytoken_to_shift
;
2417 for (yys
= 0; yys
< yystack
.yytops
.yysize
; yys
+= 1)
2418 yystackp
->yytops
.yylookaheadNeeds
[yys
] = yychar
!= YYEMPTY
;
2420 /* yyprocessOneStack returns one of three things:
2422 - An error flag. If the caller is yyprocessOneStack, it
2423 immediately returns as well. When the caller is finally
2424 yyparse, it jumps to an error label via YYCHK1.
2426 - yyok, but yyprocessOneStack has invoked yymarkStackDeleted
2427 (&yystack, yys), which sets the top state of yys to NULL. Thus,
2428 yyparse's following invocation of yyremoveDeletes will remove
2431 - yyok, when ready to shift a token.
2433 Except in the first case, yyparse will invoke yyremoveDeletes and
2434 then shift the next token onto all remaining stacks. This
2435 synchronization of the shift (that is, after all preceding
2436 reductions on all stacks) helps prevent double destructor calls
2437 on yylval in the event of memory exhaustion. */
2439 for (yys
= 0; yys
< yystack
.yytops
.yysize
; yys
+= 1)
2440 YYCHK1 (yyprocessOneStack (&yystack
, yys
, yyposn
]b4_lpure_args
[));
2441 yyremoveDeletes (&yystack
);
2442 if (yystack
.yytops
.yysize
== 0)
2444 yyundeleteLastStack (&yystack
);
2445 if (yystack
.yytops
.yysize
== 0)
2446 yyFail (&yystack
][]b4_lpure_args
[, YY_("syntax error"));
2447 YYCHK1 (yyresolveStack (&yystack
]b4_user_args
[));
2448 YYDPRINTF ((stderr
, "Returning to deterministic operation.\n"));
2449 ]b4_locations_if([[ yystack
.yyerror_range
[1].yystate
.yyloc
= yylloc
;]])[
2450 yyreportSyntaxError (&yystack
]b4_user_args
[);
2454 /* If any yyglrShift call fails, it will fail after shifting. Thus,
2455 a copy of yylval will already be on stack 0 in the event of a
2456 failure in the following loop. Thus, yychar is set to YYEMPTY
2457 before the loop to make sure the user destructor for yylval isn't
2459 yytoken_to_shift
= YYTRANSLATE (yychar
);
2462 for (yys
= 0; yys
< yystack
.yytops
.yysize
; yys
+= 1)
2465 const short int* yyconflicts
;
2466 yyStateNum yystate
= yystack
.yytops
.yystates
[yys
]->yylrState
;
2467 yygetLRActions (yystate
, yytoken_to_shift
, &yyaction
,
2469 /* Note that yyconflicts were handled by yyprocessOneStack. */
2470 YYDPRINTF ((stderr
, "On stack %lu, ", (unsigned long int) yys
));
2471 YY_SYMBOL_PRINT ("shifting", yytoken_to_shift
, &yylval
, &yylloc
);
2472 yyglrShift (&yystack
, yys
, yyaction
, yyposn
,
2474 YYDPRINTF ((stderr
, "Stack %lu now in state #%d\n",
2475 (unsigned long int) yys
,
2476 yystack
.yytops
.yystates
[yys
]->yylrState
));
2479 if (yystack
.yytops
.yysize
== 1)
2481 YYCHK1 (yyresolveStack (&yystack
]b4_user_args
[));
2482 YYDPRINTF ((stderr
, "Returning to deterministic operation.\n"));
2483 yycompressStack (&yystack
);
2489 yyrecoverSyntaxError (&yystack
]b4_user_args
[);
2490 yyposn
= yystack
.yytops
.yystates
[0]->yyposn
;
2506 yyerror (]b4_lyyerror_args
[YY_("memory exhausted"));
2511 if (yychar
!= YYEMPTY
)
2512 yydestruct ("Cleanup: discarding lookahead",
2513 YYTRANSLATE (yychar
),
2514 &yylval
]b4_locations_if([, &yylloc
])[]b4_user_args
[);
2516 /* If the stack is well-formed, pop the stack until it is empty,
2517 destroying its entries as we go. But free the stack regardless
2518 of whether it is well-formed. */
2519 if (yystack
.yyitems
)
2521 yyGLRState
** yystates
= yystack
.yytops
.yystates
;
2524 size_t yysize
= yystack
.yytops
.yysize
;
2526 for (yyk
= 0; yyk
< yysize
; yyk
+= 1)
2529 while (yystates
[yyk
])
2531 yyGLRState
*yys
= yystates
[yyk
];
2532 ]b4_locations_if([[ yystack
.yyerror_range
[1].yystate
.yyloc
= yys
->yyloc
;]]
2533 )[ if (yys
->yypred
!= NULL
)
2534 yydestroyGLRState ("Cleanup: popping", yys
]b4_user_args
[);
2535 yystates
[yyk
] = yys
->yypred
;
2536 yystack
.yynextFree
-= 1;
2537 yystack
.yyspaceLeft
+= 1;
2542 yyfreeGLRStack (&yystack
);
2545 /* Make sure YYID is used. */
2546 return YYID (yyresult
);
2549 /* DEBUGGING ONLY */
2551 static void yypstack (yyGLRStack
* yystackp
, size_t yyk
)
2552 __attribute__ ((__unused__
));
2553 static void yypdumpstack (yyGLRStack
* yystackp
) __attribute__ ((__unused__
));
2556 yy_yypstack (yyGLRState
* yys
)
2560 yy_yypstack (yys
->yypred
);
2561 YYFPRINTF (stderr
, " -> ");
2563 YYFPRINTF (stderr
, "%d@@%lu", yys
->yylrState
,
2564 (unsigned long int) yys
->yyposn
);
2568 yypstates (yyGLRState
* yyst
)
2571 YYFPRINTF (stderr
, "<null>");
2574 YYFPRINTF (stderr
, "\n");
2578 yypstack (yyGLRStack
* yystackp
, size_t yyk
)
2580 yypstates (yystackp
->yytops
.yystates
[yyk
]);
2583 #define YYINDEX(YYX) \
2584 ((YYX) == NULL ? -1 : (yyGLRStackItem*) (YYX) - yystackp->yyitems)
2588 yypdumpstack (yyGLRStack
* yystackp
)
2590 yyGLRStackItem
* yyp
;
2592 for (yyp
= yystackp
->yyitems
; yyp
< yystackp
->yynextFree
; yyp
+= 1)
2594 YYFPRINTF (stderr
, "%3lu. ",
2595 (unsigned long int) (yyp
- yystackp
->yyitems
));
2596 if (*(yybool
*) yyp
)
2598 YYFPRINTF (stderr
, "Res: %d, LR State: %d, posn: %lu, pred: %ld",
2599 yyp
->yystate
.yyresolved
, yyp
->yystate
.yylrState
,
2600 (unsigned long int) yyp
->yystate
.yyposn
,
2601 (long int) YYINDEX (yyp
->yystate
.yypred
));
2602 if (! yyp
->yystate
.yyresolved
)
2603 YYFPRINTF (stderr
, ", firstVal: %ld",
2604 (long int) YYINDEX (yyp
->yystate
2605 .yysemantics
.yyfirstVal
));
2609 YYFPRINTF (stderr
, "Option. rule: %d, state: %ld, next: %ld",
2610 yyp
->yyoption
.yyrule
- 1,
2611 (long int) YYINDEX (yyp
->yyoption
.yystate
),
2612 (long int) YYINDEX (yyp
->yyoption
.yynext
));
2614 YYFPRINTF (stderr
, "\n");
2616 YYFPRINTF (stderr
, "Tops:");
2617 for (yyi
= 0; yyi
< yystackp
->yytops
.yysize
; yyi
+= 1)
2618 YYFPRINTF (stderr
, "%lu: %ld; ", (unsigned long int) yyi
,
2619 (long int) YYINDEX (yystackp
->yytops
.yystates
[yyi
]));
2620 YYFPRINTF (stderr
, "\n");
2625 dnl glr
.cc produces its own header
.
2627 m4_if(b4_skeleton
, ["glr.c"],
2629 [@
output(b4_spec_defines_file@
)@
2630 b4_copyright([Skeleton interface
for Bison GLR parsers in C
],
2631 [2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010])
2633 b4_shared_declarations
2636 [[extern YYSTYPE
]b4_prefix
[lval
;]])
2638 b4_locations_if([b4_pure_if([],
2639 [extern YYLTYPE
]b4_prefix
[lloc
;])