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 yyflag = YYE; \
515 if (yyflag != 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 # if (! defined __cplusplus \
580 || (]b4_locations_if([[defined YYLTYPE_IS_TRIVIAL && YYLTYPE_IS_TRIVIAL \
581 && ]])[defined YYSTYPE_IS_TRIVIAL && YYSTYPE_IS_TRIVIAL))
582 # define YYSTACKEXPANDABLE 1
584 # define YYSTACKEXPANDABLE 0
588 #if YYSTACKEXPANDABLE
589 # define YY_RESERVE_GLRSTACK(Yystack) \
591 if (Yystack->yyspaceLeft < YYHEADROOM) \
592 yyexpandGLRStack (Yystack); \
595 # define YY_RESERVE_GLRSTACK(Yystack) \
597 if (Yystack->yyspaceLeft < YYHEADROOM) \
598 yyMemoryExhausted (Yystack); \
606 # if defined __GLIBC__ && defined _STRING_H && defined _GNU_SOURCE
607 # define yystpcpy stpcpy
609 /* Copy YYSRC to YYDEST, returning the address of the terminating '\0' in
612 yystpcpy (char *yydest
, const char *yysrc
)
615 const char *yys
= yysrc
;
617 while ((*yyd
++ = *yys
++) != '\0')
626 /* Copy to YYRES the contents of YYSTR after stripping away unnecessary
627 quotes and backslashes, so that it's suitable for yyerror. The
628 heuristic is that double-quoting is unnecessary unless the string
629 contains an apostrophe, a comma, or backslash (other than
630 backslash-backslash). YYSTR is taken from yytname. If YYRES is
631 null, do not copy; instead, return the length of what the result
634 yytnamerr (char *yyres
, const char *yystr
)
639 char const *yyp
= yystr
;
646 goto do_not_strip_quotes
;
650 goto do_not_strip_quotes
;
663 do_not_strip_quotes
: ;
667 return strlen (yystr
);
669 return yystpcpy (yyres
, yystr
) - yyres
;
673 #endif /* !YYERROR_VERBOSE */
675 /** State numbers, as in LALR(1) machine */
676 typedef int yyStateNum
;
678 /** Rule numbers, as in LALR(1) machine */
679 typedef int yyRuleNum
;
681 /** Grammar symbol */
682 typedef short int yySymbol
;
684 /** Item references, as in LALR(1) machine */
685 typedef short int yyItemNum
;
687 typedef struct yyGLRState yyGLRState
;
688 typedef struct yyGLRStateSet yyGLRStateSet
;
689 typedef struct yySemanticOption yySemanticOption
;
690 typedef union yyGLRStackItem yyGLRStackItem
;
691 typedef struct yyGLRStack yyGLRStack
;
694 /** Type tag: always true. */
696 /** Type tag for yysemantics. If true, yysval applies, otherwise
697 * yyfirstVal applies. */
699 /** Number of corresponding LALR(1) machine state. */
700 yyStateNum yylrState
;
701 /** Preceding state in this stack */
703 /** Source position of the last token produced by my symbol */
706 /** First in a chain of alternative reductions producing the
707 * non-terminal corresponding to this state, threaded through
709 yySemanticOption
* yyfirstVal
;
710 /** Semantic value for this state. */
713 /** Source location for this state. */
717 struct yyGLRStateSet
{
718 yyGLRState
** yystates
;
719 /** During nondeterministic operation, yylookaheadNeeds tracks which
720 * stacks have actually needed the current lookahead. During deterministic
721 * operation, yylookaheadNeeds[0] is not maintained since it would merely
722 * duplicate yychar != YYEMPTY. */
723 yybool
* yylookaheadNeeds
;
724 size_t yysize
, yycapacity
;
727 struct yySemanticOption
{
728 /** Type tag: always false. */
730 /** Rule number for this reduction */
732 /** The last RHS state in the list of states to be reduced. */
734 /** The lookahead for this reduction. */
738 /** Next sibling in chain of options. To facilitate merging,
739 * options are chained in decreasing order by address. */
740 yySemanticOption
* yynext
;
743 /** Type of the items in the GLR stack. The yyisState field
744 * indicates which item of the union is valid. */
745 union yyGLRStackItem
{
747 yySemanticOption yyoption
;
752 ]b4_locations_if([[ /* To compute the location of the error token. */
753 yyGLRStackItem yyerror_range
[3];]])[
761 YYJMP_BUF yyexception_buffer
;
762 yyGLRStackItem
* yyitems
;
763 yyGLRStackItem
* yynextFree
;
765 yyGLRState
* yysplitPoint
;
766 yyGLRState
* yylastDeleted
;
767 yyGLRStateSet yytops
;
770 #if YYSTACKEXPANDABLE
771 static void yyexpandGLRStack (yyGLRStack
* yystackp
);
774 static void yyFail (yyGLRStack
* yystackp
]b4_pure_formals
[, const char* yymsg
)
775 __attribute__ ((__noreturn__
));
777 yyFail (yyGLRStack
* yystackp
]b4_pure_formals
[, const char* yymsg
)
780 yyerror (]b4_yyerror_args
[yymsg
);
781 YYLONGJMP (yystackp
->yyexception_buffer
, 1);
784 static void yyMemoryExhausted (yyGLRStack
* yystackp
)
785 __attribute__ ((__noreturn__
));
787 yyMemoryExhausted (yyGLRStack
* yystackp
)
789 YYLONGJMP (yystackp
->yyexception_buffer
, 2);
792 #if YYDEBUG || YYERROR_VERBOSE
793 /** A printable representation of TOKEN. */
794 static inline const char*
795 yytokenName (yySymbol yytoken
)
797 if (yytoken
== YYEMPTY
)
800 return yytname
[yytoken
];
804 /** Fill in YYVSP[YYLOW1 .. YYLOW0-1] from the chain of states starting
805 * at YYVSP[YYLOW0].yystate.yypred. Leaves YYVSP[YYLOW1].yystate.yypred
806 * containing the pointer to the next state in the chain. */
807 static void yyfillin (yyGLRStackItem
*, int, int) __attribute__ ((__unused__
));
809 yyfillin (yyGLRStackItem
*yyvsp
, int yylow0
, int yylow1
)
813 s
= yyvsp
[yylow0
].yystate
.yypred
;
814 for (i
= yylow0
-1; i
>= yylow1
; i
-= 1)
817 yyvsp
[i
].yystate
.yylrState
= s
->yylrState
;
819 yyvsp
[i
].yystate
.yyresolved
= s
->yyresolved
;
821 yyvsp
[i
].yystate
.yysemantics
.yysval
= s
->yysemantics
.yysval
;
823 /* The effect of using yysval or yyloc (in an immediate rule) is
825 yyvsp
[i
].yystate
.yysemantics
.yyfirstVal
= NULL
;
826 yyvsp
[i
].yystate
.yyloc
= s
->yyloc
;
827 s
= yyvsp
[i
].yystate
.yypred
= s
->yypred
;
831 /* Do nothing if YYNORMAL or if *YYLOW <= YYLOW1. Otherwise, fill in
832 * YYVSP[YYLOW1 .. *YYLOW-1] as in yyfillin and set *YYLOW = YYLOW1.
833 * For convenience, always return YYLOW1. */
834 static inline int yyfill (yyGLRStackItem
*, int *, int, yybool
)
835 __attribute__ ((__unused__
));
837 yyfill (yyGLRStackItem
*yyvsp
, int *yylow
, int yylow1
, yybool yynormal
)
839 if (!yynormal
&& yylow1
< *yylow
)
841 yyfillin (yyvsp
, *yylow
, yylow1
);
847 /** Perform user action for rule number YYN, with RHS length YYRHSLEN,
848 * and top stack item YYVSP. YYLVALP points to place to put semantic
849 * value ($$), and yylocp points to place for location information
850 * (@@$). Returns yyok for normal return, yyaccept for YYACCEPT,
851 * yyerr for YYERROR, yyabort for YYABORT. */
852 /*ARGSUSED*/ static YYRESULTTAG
853 yyuserAction (yyRuleNum yyn
, int yyrhslen
, yyGLRStackItem
* yyvsp
,
855 YYLTYPE
* YYOPTIONAL_LOC (yylocp
),
859 yybool yynormal
__attribute__ ((__unused__
)) =
860 (yystackp
->yysplitPoint
== NULL
);
862 ]b4_parse_param_use
[]dnl
864 # define yyerrok (yystackp->yyerrState = 0)
866 # define YYACCEPT return yyaccept
868 # define YYABORT return yyabort
870 # define YYERROR return yyerrok, yyerr
872 # define YYRECOVERING() (yystackp->yyerrState != 0)
874 # define yyclearin (yychar = YYEMPTY)
876 # define YYFILL(N) yyfill (yyvsp, &yylow, N, yynormal)
878 # define YYBACKUP(Token, Value) \
879 return yyerror (]b4_yyerror_args[YY_("syntax error: cannot back up")), \
884 *yyvalp
= yyval_default
;
886 *yyvalp
= yyvsp
[YYFILL (1-yyrhslen
)].yystate
.yysemantics
.yysval
;
887 YYLLOC_DEFAULT ((*yylocp
), (yyvsp
- yyrhslen
), yyrhslen
);
888 ]b4_locations_if([[ yystackp
->yyerror_range
[1].yystate
.yyloc
= *yylocp
;
907 /*ARGSUSED*/ static void
908 yyuserMerge (int yyn
, YYSTYPE
* yy0
, YYSTYPE
* yy1
)
920 /* Bison grammar-table manipulation. */
922 ]b4_yydestruct_generate([b4_c_ansi_function_def
])[
924 /** Number of symbols composing the right hand side of rule #RULE. */
926 yyrhsLength (yyRuleNum yyrule
)
932 yydestroyGLRState (char const *yymsg
, yyGLRState
*yys
]b4_user_formals
[)
935 yydestruct (yymsg
, yystos
[yys
->yylrState
],
936 &yys
->yysemantics
.yysval
]b4_locations_if([, &yys
->yyloc
])[]b4_user_args
[);
942 if (yys
->yysemantics
.yyfirstVal
)
943 YYFPRINTF (stderr
, "%s unresolved ", yymsg
);
945 YYFPRINTF (stderr
, "%s incomplete ", yymsg
);
946 yy_symbol_print (stderr
, yystos
[yys
->yylrState
],
947 NULL
]b4_locations_if([, &yys
->yyloc
])[]b4_user_args
[);
948 YYFPRINTF (stderr
, "\n");
952 if (yys
->yysemantics
.yyfirstVal
)
954 yySemanticOption
*yyoption
= yys
->yysemantics
.yyfirstVal
;
957 for (yyrh
= yyoption
->yystate
, yyn
= yyrhsLength (yyoption
->yyrule
);
959 yyrh
= yyrh
->yypred
, yyn
-= 1)
960 yydestroyGLRState (yymsg
, yyrh
]b4_user_args
[);
965 /** Left-hand-side symbol for rule #YYRULE. */
966 static inline yySymbol
967 yylhsNonterm (yyRuleNum yyrule
)
972 #define yypact_value_is_default(yystate) \
973 ]b4_table_value_equals([[pact]], [[yystate]], [b4_pact_ninf])[
975 /** True iff LR state YYSTATE has only a default reduction (regardless
978 yyisDefaultedState (yyStateNum yystate
)
980 return yypact_value_is_default (yypact
[yystate
]);
983 /** The default reduction for YYSTATE, assuming it has one. */
984 static inline yyRuleNum
985 yydefaultAction (yyStateNum yystate
)
987 return yydefact
[yystate
];
990 #define yytable_value_is_error(yytable_value) \
991 ]b4_table_value_equals([[table]], [[yytable_value]], [b4_table_ninf])[
993 /** Set *YYACTION to the action to take in YYSTATE on seeing YYTOKEN.
995 * R < 0: Reduce on rule -R.
997 * R > 0: Shift to state R.
998 * Set *YYCONFLICTS to a pointer into yyconfl to a 0-terminated list
999 * of conflicting reductions.
1002 yygetLRActions (yyStateNum yystate
, int yytoken
,
1003 int* yyaction
, const short int** yyconflicts
)
1005 int yyindex
= yypact
[yystate
] + yytoken
;
1006 if (yypact_value_is_default (yypact
[yystate
])
1007 || yyindex
< 0 || YYLAST
< yyindex
|| yycheck
[yyindex
] != yytoken
)
1009 *yyaction
= -yydefact
[yystate
];
1010 *yyconflicts
= yyconfl
;
1012 else if (! yytable_value_is_error (yytable
[yyindex
]))
1014 *yyaction
= yytable
[yyindex
];
1015 *yyconflicts
= yyconfl
+ yyconflp
[yyindex
];
1020 *yyconflicts
= yyconfl
+ yyconflp
[yyindex
];
1024 static inline yyStateNum
1025 yyLRgotoState (yyStateNum yystate
, yySymbol yylhs
)
1027 int yyr
= yypgoto
[yylhs
- YYNTOKENS
] + yystate
;
1028 if (0 <= yyr
&& yyr
<= YYLAST
&& yycheck
[yyr
] == yystate
)
1029 return yytable
[yyr
];
1031 return yydefgoto
[yylhs
- YYNTOKENS
];
1034 static inline yybool
1035 yyisShiftAction (int yyaction
)
1037 return 0 < yyaction
;
1040 static inline yybool
1041 yyisErrorAction (int yyaction
)
1043 return yyaction
== 0;
1048 /** Return a fresh GLRStackItem in YYSTACKP. The item is an LR state
1049 * if YYISSTATE, and otherwise a semantic option. Callers should call
1050 * YY_RESERVE_GLRSTACK afterwards to make sure there is sufficient
1053 static inline yyGLRStackItem
*
1054 yynewGLRStackItem (yyGLRStack
* yystackp
, yybool yyisState
)
1056 yyGLRStackItem
* yynewItem
= yystackp
->yynextFree
;
1057 yystackp
->yyspaceLeft
-= 1;
1058 yystackp
->yynextFree
+= 1;
1059 yynewItem
->yystate
.yyisState
= yyisState
;
1063 /** Add a new semantic action that will execute the action for rule
1064 * YYRULE on the semantic values in YYRHS to the list of
1065 * alternative actions for YYSTATE. Assumes that YYRHS comes from
1066 * stack #YYK of *YYSTACKP. */
1068 yyaddDeferredAction (yyGLRStack
* yystackp
, size_t yyk
, yyGLRState
* yystate
,
1069 yyGLRState
* yyrhs
, yyRuleNum yyrule
)
1071 yySemanticOption
* yynewOption
=
1072 &yynewGLRStackItem (yystackp
, yyfalse
)->yyoption
;
1073 yynewOption
->yystate
= yyrhs
;
1074 yynewOption
->yyrule
= yyrule
;
1075 if (yystackp
->yytops
.yylookaheadNeeds
[yyk
])
1077 yynewOption
->yyrawchar
= yychar
;
1078 yynewOption
->yyval
= yylval
;
1079 yynewOption
->yyloc
= yylloc
;
1082 yynewOption
->yyrawchar
= YYEMPTY
;
1083 yynewOption
->yynext
= yystate
->yysemantics
.yyfirstVal
;
1084 yystate
->yysemantics
.yyfirstVal
= yynewOption
;
1086 YY_RESERVE_GLRSTACK (yystackp
);
1091 /** Initialize YYSET to a singleton set containing an empty stack. */
1093 yyinitStateSet (yyGLRStateSet
* yyset
)
1096 yyset
->yycapacity
= 16;
1097 yyset
->yystates
= (yyGLRState
**) YYMALLOC (16 * sizeof yyset
->yystates
[0]);
1098 if (! yyset
->yystates
)
1100 yyset
->yystates
[0] = NULL
;
1101 yyset
->yylookaheadNeeds
=
1102 (yybool
*) YYMALLOC (16 * sizeof yyset
->yylookaheadNeeds
[0]);
1103 if (! yyset
->yylookaheadNeeds
)
1105 YYFREE (yyset
->yystates
);
1111 static void yyfreeStateSet (yyGLRStateSet
* yyset
)
1113 YYFREE (yyset
->yystates
);
1114 YYFREE (yyset
->yylookaheadNeeds
);
1117 /** Initialize *YYSTACKP to a single empty stack, with total maximum
1118 * capacity for all stacks of YYSIZE. */
1120 yyinitGLRStack (yyGLRStack
* yystackp
, size_t yysize
)
1122 yystackp
->yyerrState
= 0;
1124 yystackp
->yyspaceLeft
= yysize
;
1126 (yyGLRStackItem
*) YYMALLOC (yysize
* sizeof yystackp
->yynextFree
[0]);
1127 if (!yystackp
->yyitems
)
1129 yystackp
->yynextFree
= yystackp
->yyitems
;
1130 yystackp
->yysplitPoint
= NULL
;
1131 yystackp
->yylastDeleted
= NULL
;
1132 return yyinitStateSet (&yystackp
->yytops
);
1136 #if YYSTACKEXPANDABLE
1137 # define YYRELOC(YYFROMITEMS,YYTOITEMS,YYX,YYTYPE) \
1138 &((YYTOITEMS) - ((YYFROMITEMS) - (yyGLRStackItem*) (YYX)))->YYTYPE
1140 /** If *YYSTACKP is expandable, extend it. WARNING: Pointers into the
1141 stack from outside should be considered invalid after this call.
1142 We always expand when there are 1 or fewer items left AFTER an
1143 allocation, so that we can avoid having external pointers exist
1144 across an allocation. */
1146 yyexpandGLRStack (yyGLRStack
* yystackp
)
1148 yyGLRStackItem
* yynewItems
;
1149 yyGLRStackItem
* yyp0
, *yyp1
;
1150 size_t yysize
, yynewSize
;
1152 yysize
= yystackp
->yynextFree
- yystackp
->yyitems
;
1153 if (YYMAXDEPTH
- YYHEADROOM
< yysize
)
1154 yyMemoryExhausted (yystackp
);
1155 yynewSize
= 2*yysize
;
1156 if (YYMAXDEPTH
< yynewSize
)
1157 yynewSize
= YYMAXDEPTH
;
1158 yynewItems
= (yyGLRStackItem
*) YYMALLOC (yynewSize
* sizeof yynewItems
[0]);
1160 yyMemoryExhausted (yystackp
);
1161 for (yyp0
= yystackp
->yyitems
, yyp1
= yynewItems
, yyn
= yysize
;
1163 yyn
-= 1, yyp0
+= 1, yyp1
+= 1)
1166 if (*(yybool
*) yyp0
)
1168 yyGLRState
* yys0
= &yyp0
->yystate
;
1169 yyGLRState
* yys1
= &yyp1
->yystate
;
1170 if (yys0
->yypred
!= NULL
)
1172 YYRELOC (yyp0
, yyp1
, yys0
->yypred
, yystate
);
1173 if (! yys0
->yyresolved
&& yys0
->yysemantics
.yyfirstVal
!= NULL
)
1174 yys1
->yysemantics
.yyfirstVal
=
1175 YYRELOC(yyp0
, yyp1
, yys0
->yysemantics
.yyfirstVal
, yyoption
);
1179 yySemanticOption
* yyv0
= &yyp0
->yyoption
;
1180 yySemanticOption
* yyv1
= &yyp1
->yyoption
;
1181 if (yyv0
->yystate
!= NULL
)
1182 yyv1
->yystate
= YYRELOC (yyp0
, yyp1
, yyv0
->yystate
, yystate
);
1183 if (yyv0
->yynext
!= NULL
)
1184 yyv1
->yynext
= YYRELOC (yyp0
, yyp1
, yyv0
->yynext
, yyoption
);
1187 if (yystackp
->yysplitPoint
!= NULL
)
1188 yystackp
->yysplitPoint
= YYRELOC (yystackp
->yyitems
, yynewItems
,
1189 yystackp
->yysplitPoint
, yystate
);
1191 for (yyn
= 0; yyn
< yystackp
->yytops
.yysize
; yyn
+= 1)
1192 if (yystackp
->yytops
.yystates
[yyn
] != NULL
)
1193 yystackp
->yytops
.yystates
[yyn
] =
1194 YYRELOC (yystackp
->yyitems
, yynewItems
,
1195 yystackp
->yytops
.yystates
[yyn
], yystate
);
1196 YYFREE (yystackp
->yyitems
);
1197 yystackp
->yyitems
= yynewItems
;
1198 yystackp
->yynextFree
= yynewItems
+ yysize
;
1199 yystackp
->yyspaceLeft
= yynewSize
- yysize
;
1204 yyfreeGLRStack (yyGLRStack
* yystackp
)
1206 YYFREE (yystackp
->yyitems
);
1207 yyfreeStateSet (&yystackp
->yytops
);
1210 /** Assuming that YYS is a GLRState somewhere on *YYSTACKP, update the
1211 * splitpoint of *YYSTACKP, if needed, so that it is at least as deep as
1214 yyupdateSplit (yyGLRStack
* yystackp
, yyGLRState
* yys
)
1216 if (yystackp
->yysplitPoint
!= NULL
&& yystackp
->yysplitPoint
> yys
)
1217 yystackp
->yysplitPoint
= yys
;
1220 /** Invalidate stack #YYK in *YYSTACKP. */
1222 yymarkStackDeleted (yyGLRStack
* yystackp
, size_t yyk
)
1224 if (yystackp
->yytops
.yystates
[yyk
] != NULL
)
1225 yystackp
->yylastDeleted
= yystackp
->yytops
.yystates
[yyk
];
1226 yystackp
->yytops
.yystates
[yyk
] = NULL
;
1229 /** Undelete the last stack in *YYSTACKP that was marked as deleted. Can
1230 only be done once after a deletion, and only when all other stacks have
1233 yyundeleteLastStack (yyGLRStack
* yystackp
)
1235 if (yystackp
->yylastDeleted
== NULL
|| yystackp
->yytops
.yysize
!= 0)
1237 yystackp
->yytops
.yystates
[0] = yystackp
->yylastDeleted
;
1238 yystackp
->yytops
.yysize
= 1;
1239 YYDPRINTF ((stderr
, "Restoring last deleted stack as stack #0.\n"));
1240 yystackp
->yylastDeleted
= NULL
;
1244 yyremoveDeletes (yyGLRStack
* yystackp
)
1248 while (yyj
< yystackp
->yytops
.yysize
)
1250 if (yystackp
->yytops
.yystates
[yyi
] == NULL
)
1254 YYDPRINTF ((stderr
, "Removing dead stacks.\n"));
1256 yystackp
->yytops
.yysize
-= 1;
1260 yystackp
->yytops
.yystates
[yyj
] = yystackp
->yytops
.yystates
[yyi
];
1261 /* In the current implementation, it's unnecessary to copy
1262 yystackp->yytops.yylookaheadNeeds[yyi] since, after
1263 yyremoveDeletes returns, the parser immediately either enters
1264 deterministic operation or shifts a token. However, it doesn't
1265 hurt, and the code might evolve to need it. */
1266 yystackp
->yytops
.yylookaheadNeeds
[yyj
] =
1267 yystackp
->yytops
.yylookaheadNeeds
[yyi
];
1270 YYDPRINTF ((stderr
, "Rename stack %lu -> %lu.\n",
1271 (unsigned long int) yyi
, (unsigned long int) yyj
));
1279 /** Shift to a new state on stack #YYK of *YYSTACKP, corresponding to LR
1280 * state YYLRSTATE, at input position YYPOSN, with (resolved) semantic
1281 * value *YYVALP and source location *YYLOCP. */
1283 yyglrShift (yyGLRStack
* yystackp
, size_t yyk
, yyStateNum yylrState
,
1285 YYSTYPE
* yyvalp
, YYLTYPE
* yylocp
)
1287 yyGLRState
* yynewState
= &yynewGLRStackItem (yystackp
, yytrue
)->yystate
;
1289 yynewState
->yylrState
= yylrState
;
1290 yynewState
->yyposn
= yyposn
;
1291 yynewState
->yyresolved
= yytrue
;
1292 yynewState
->yypred
= yystackp
->yytops
.yystates
[yyk
];
1293 yynewState
->yysemantics
.yysval
= *yyvalp
;
1294 yynewState
->yyloc
= *yylocp
;
1295 yystackp
->yytops
.yystates
[yyk
] = yynewState
;
1297 YY_RESERVE_GLRSTACK (yystackp
);
1300 /** Shift stack #YYK of *YYSTACKP, to a new state corresponding to LR
1301 * state YYLRSTATE, at input position YYPOSN, with the (unresolved)
1302 * semantic value of YYRHS under the action for YYRULE. */
1304 yyglrShiftDefer (yyGLRStack
* yystackp
, size_t yyk
, yyStateNum yylrState
,
1305 size_t yyposn
, yyGLRState
* yyrhs
, yyRuleNum yyrule
)
1307 yyGLRState
* yynewState
= &yynewGLRStackItem (yystackp
, yytrue
)->yystate
;
1309 yynewState
->yylrState
= yylrState
;
1310 yynewState
->yyposn
= yyposn
;
1311 yynewState
->yyresolved
= yyfalse
;
1312 yynewState
->yypred
= yystackp
->yytops
.yystates
[yyk
];
1313 yynewState
->yysemantics
.yyfirstVal
= NULL
;
1314 yystackp
->yytops
.yystates
[yyk
] = yynewState
;
1316 /* Invokes YY_RESERVE_GLRSTACK. */
1317 yyaddDeferredAction (yystackp
, yyk
, yynewState
, yyrhs
, yyrule
);
1321 # define YY_REDUCE_PRINT(Args)
1323 # define YY_REDUCE_PRINT(Args) \
1326 yy_reduce_print Args; \
1329 /*----------------------------------------------------------------------.
1330 | Report that stack #YYK of *YYSTACKP is going to be reduced by YYRULE. |
1331 `----------------------------------------------------------------------*/
1333 /*ARGSUSED*/ static inline void
1334 yy_reduce_print (int yynormal
, yyGLRStackItem
* yyrhsVals
, size_t yyk
, yyRuleNum yyrule
]b4_user_formals
[)
1336 int yynrhs
= yyrhsLength (yyrule
);
1338 ]b4_parse_param_use
[]dnl
1339 [ YYFPRINTF (stderr
, "Reducing stack %lu by rule %d (line %lu):\n",
1340 (unsigned long int) yyk
, yyrule
- 1,
1341 (unsigned long int) yyrline
[yyrule
]);
1343 yyfillin (yyrhsVals
, 1, -yynrhs
);
1344 /* The symbols being reduced. */
1345 for (yyi
= 0; yyi
< yynrhs
; yyi
++)
1347 YYFPRINTF (stderr
, " $%d = ", yyi
+ 1);
1348 yy_symbol_print (stderr
,
1349 yystos
[yyrhsVals
[yyi
- yynrhs
+ 1].yystate
.yylrState
],
1350 &yyrhsVals
[yyi
- yynrhs
+ 1].yystate
.yysemantics
.yysval
1351 ]b4_locations_if([, &]b4_rhs_location(yynrhs
, yyi
+ 1))[]dnl
1353 if (!yyrhsVals
[yyi
- yynrhs
+ 1].yystate
.yyresolved
)
1354 YYFPRINTF (stderr
, " (unresolved)");
1355 YYFPRINTF (stderr
, "\n");
1360 /** Pop the symbols consumed by reduction #YYRULE from the top of stack
1361 * #YYK of *YYSTACKP, and perform the appropriate semantic action on their
1362 * semantic values. Assumes that all ambiguities in semantic values
1363 * have been previously resolved. Set *YYVALP to the resulting value,
1364 * and *YYLOCP to the computed location (if any). Return value is as
1365 * for userAction. */
1366 static inline YYRESULTTAG
1367 yydoAction (yyGLRStack
* yystackp
, size_t yyk
, yyRuleNum yyrule
,
1368 YYSTYPE
* yyvalp
, YYLTYPE
* yylocp
]b4_user_formals
[)
1370 int yynrhs
= yyrhsLength (yyrule
);
1372 if (yystackp
->yysplitPoint
== NULL
)
1374 /* Standard special case: single stack. */
1375 yyGLRStackItem
* yyrhs
= (yyGLRStackItem
*) yystackp
->yytops
.yystates
[yyk
];
1376 YYASSERT (yyk
== 0);
1377 yystackp
->yynextFree
-= yynrhs
;
1378 yystackp
->yyspaceLeft
+= yynrhs
;
1379 yystackp
->yytops
.yystates
[0] = & yystackp
->yynextFree
[-1].yystate
;
1380 YY_REDUCE_PRINT ((1, yyrhs
, yyk
, yyrule
]b4_user_args
[));
1381 return yyuserAction (yyrule
, yynrhs
, yyrhs
,
1382 yyvalp
, yylocp
, yystackp
]b4_user_args
[);
1388 yyGLRStackItem yyrhsVals
[YYMAXRHS
+ YYMAXLEFT
+ 1];
1389 yys
= yyrhsVals
[YYMAXRHS
+ YYMAXLEFT
].yystate
.yypred
1390 = yystackp
->yytops
.yystates
[yyk
];]b4_locations_if([[
1392 /* Set default location. */
1393 yyrhsVals
[YYMAXRHS
+ YYMAXLEFT
- 1].yystate
.yyloc
= yys
->yyloc
;]])[
1394 for (yyi
= 0; yyi
< yynrhs
; yyi
+= 1)
1399 yyupdateSplit (yystackp
, yys
);
1400 yystackp
->yytops
.yystates
[yyk
] = yys
;
1401 YY_REDUCE_PRINT ((0, yyrhsVals
+ YYMAXRHS
+ YYMAXLEFT
- 1, yyk
, yyrule
]b4_user_args
[));
1402 return yyuserAction (yyrule
, yynrhs
, yyrhsVals
+ YYMAXRHS
+ YYMAXLEFT
- 1,
1403 yyvalp
, yylocp
, yystackp
]b4_user_args
[);
1407 /** Pop items off stack #YYK of *YYSTACKP according to grammar rule YYRULE,
1408 * and push back on the resulting nonterminal symbol. Perform the
1409 * semantic action associated with YYRULE and store its value with the
1410 * newly pushed state, if YYFORCEEVAL or if *YYSTACKP is currently
1411 * unambiguous. Otherwise, store the deferred semantic action with
1412 * the new state. If the new state would have an identical input
1413 * position, LR state, and predecessor to an existing state on the stack,
1414 * it is identified with that existing state, eliminating stack #YYK from
1415 * *YYSTACKP. In this case, the semantic value is
1416 * added to the options for the existing state's semantic value.
1418 static inline YYRESULTTAG
1419 yyglrReduce (yyGLRStack
* yystackp
, size_t yyk
, yyRuleNum yyrule
,
1420 yybool yyforceEval
]b4_user_formals
[)
1422 size_t yyposn
= yystackp
->yytops
.yystates
[yyk
]->yyposn
;
1424 if (yyforceEval
|| yystackp
->yysplitPoint
== NULL
)
1430 yyflag
= yydoAction (yystackp
, yyk
, yyrule
, &yysval
,
1431 &yyloc
]b4_user_args
[);
1432 if (yyflag
== yyerr
)
1434 YYDPRINTF ((stderr
, "Parse on stack %lu rejected by rule #%d.\n",
1435 (unsigned long int) yyk
, yyrule
- 1));
1439 YY_SYMBOL_PRINT ("-> $$ =", yyr1
[yyrule
], &yysval
, &yyloc
);
1440 yyglrShift (yystackp
, yyk
,
1441 yyLRgotoState (yystackp
->yytops
.yystates
[yyk
]->yylrState
,
1442 yylhsNonterm (yyrule
)),
1443 yyposn
, &yysval
, &yyloc
);
1449 yyGLRState
* yys
, *yys0
= yystackp
->yytops
.yystates
[yyk
];
1450 yyStateNum yynewLRState
;
1452 for (yys
= yystackp
->yytops
.yystates
[yyk
], yyn
= yyrhsLength (yyrule
);
1458 yyupdateSplit (yystackp
, yys
);
1459 yynewLRState
= yyLRgotoState (yys
->yylrState
, yylhsNonterm (yyrule
));
1461 "Reduced stack %lu by rule #%d; action deferred. Now in state %d.\n",
1462 (unsigned long int) yyk
, yyrule
- 1, yynewLRState
));
1463 for (yyi
= 0; yyi
< yystackp
->yytops
.yysize
; yyi
+= 1)
1464 if (yyi
!= yyk
&& yystackp
->yytops
.yystates
[yyi
] != NULL
)
1466 yyGLRState
* yyp
, *yysplit
= yystackp
->yysplitPoint
;
1467 yyp
= yystackp
->yytops
.yystates
[yyi
];
1468 while (yyp
!= yys
&& yyp
!= yysplit
&& yyp
->yyposn
>= yyposn
)
1470 if (yyp
->yylrState
== yynewLRState
&& yyp
->yypred
== yys
)
1472 yyaddDeferredAction (yystackp
, yyk
, yyp
, yys0
, yyrule
);
1473 yymarkStackDeleted (yystackp
, yyk
);
1474 YYDPRINTF ((stderr
, "Merging stack %lu into stack %lu.\n",
1475 (unsigned long int) yyk
,
1476 (unsigned long int) yyi
));
1482 yystackp
->yytops
.yystates
[yyk
] = yys
;
1483 yyglrShiftDefer (yystackp
, yyk
, yynewLRState
, yyposn
, yys0
, yyrule
);
1489 yysplitStack (yyGLRStack
* yystackp
, size_t yyk
)
1491 if (yystackp
->yysplitPoint
== NULL
)
1493 YYASSERT (yyk
== 0);
1494 yystackp
->yysplitPoint
= yystackp
->yytops
.yystates
[yyk
];
1496 if (yystackp
->yytops
.yysize
>= yystackp
->yytops
.yycapacity
)
1498 yyGLRState
** yynewStates
;
1499 yybool
* yynewLookaheadNeeds
;
1503 if (yystackp
->yytops
.yycapacity
1504 > (YYSIZEMAX
/ (2 * sizeof yynewStates
[0])))
1505 yyMemoryExhausted (yystackp
);
1506 yystackp
->yytops
.yycapacity
*= 2;
1509 (yyGLRState
**) YYREALLOC (yystackp
->yytops
.yystates
,
1510 (yystackp
->yytops
.yycapacity
1511 * sizeof yynewStates
[0]));
1512 if (yynewStates
== NULL
)
1513 yyMemoryExhausted (yystackp
);
1514 yystackp
->yytops
.yystates
= yynewStates
;
1516 yynewLookaheadNeeds
=
1517 (yybool
*) YYREALLOC (yystackp
->yytops
.yylookaheadNeeds
,
1518 (yystackp
->yytops
.yycapacity
1519 * sizeof yynewLookaheadNeeds
[0]));
1520 if (yynewLookaheadNeeds
== NULL
)
1521 yyMemoryExhausted (yystackp
);
1522 yystackp
->yytops
.yylookaheadNeeds
= yynewLookaheadNeeds
;
1524 yystackp
->yytops
.yystates
[yystackp
->yytops
.yysize
]
1525 = yystackp
->yytops
.yystates
[yyk
];
1526 yystackp
->yytops
.yylookaheadNeeds
[yystackp
->yytops
.yysize
]
1527 = yystackp
->yytops
.yylookaheadNeeds
[yyk
];
1528 yystackp
->yytops
.yysize
+= 1;
1529 return yystackp
->yytops
.yysize
-1;
1532 /** True iff YYY0 and YYY1 represent identical options at the top level.
1533 * That is, they represent the same rule applied to RHS symbols
1534 * that produce the same terminal symbols. */
1536 yyidenticalOptions (yySemanticOption
* yyy0
, yySemanticOption
* yyy1
)
1538 if (yyy0
->yyrule
== yyy1
->yyrule
)
1540 yyGLRState
*yys0
, *yys1
;
1542 for (yys0
= yyy0
->yystate
, yys1
= yyy1
->yystate
,
1543 yyn
= yyrhsLength (yyy0
->yyrule
);
1545 yys0
= yys0
->yypred
, yys1
= yys1
->yypred
, yyn
-= 1)
1546 if (yys0
->yyposn
!= yys1
->yyposn
)
1554 /** Assuming identicalOptions (YYY0,YYY1), destructively merge the
1555 * alternative semantic values for the RHS-symbols of YYY1 and YYY0. */
1557 yymergeOptionSets (yySemanticOption
* yyy0
, yySemanticOption
* yyy1
)
1559 yyGLRState
*yys0
, *yys1
;
1561 for (yys0
= yyy0
->yystate
, yys1
= yyy1
->yystate
,
1562 yyn
= yyrhsLength (yyy0
->yyrule
);
1564 yys0
= yys0
->yypred
, yys1
= yys1
->yypred
, yyn
-= 1)
1568 else if (yys0
->yyresolved
)
1570 yys1
->yyresolved
= yytrue
;
1571 yys1
->yysemantics
.yysval
= yys0
->yysemantics
.yysval
;
1573 else if (yys1
->yyresolved
)
1575 yys0
->yyresolved
= yytrue
;
1576 yys0
->yysemantics
.yysval
= yys1
->yysemantics
.yysval
;
1580 yySemanticOption
** yyz0p
;
1581 yySemanticOption
* yyz1
;
1582 yyz0p
= &yys0
->yysemantics
.yyfirstVal
;
1583 yyz1
= yys1
->yysemantics
.yyfirstVal
;
1584 while (YYID (yytrue
))
1586 if (yyz1
== *yyz0p
|| yyz1
== NULL
)
1588 else if (*yyz0p
== NULL
)
1593 else if (*yyz0p
< yyz1
)
1595 yySemanticOption
* yyz
= *yyz0p
;
1597 yyz1
= yyz1
->yynext
;
1598 (*yyz0p
)->yynext
= yyz
;
1600 yyz0p
= &(*yyz0p
)->yynext
;
1602 yys1
->yysemantics
.yyfirstVal
= yys0
->yysemantics
.yyfirstVal
;
1607 /** Y0 and Y1 represent two possible actions to take in a given
1608 * parsing state; return 0 if no combination is possible,
1609 * 1 if user-mergeable, 2 if Y0 is preferred, 3 if Y1 is preferred. */
1611 yypreference (yySemanticOption
* y0
, yySemanticOption
* y1
)
1613 yyRuleNum r0
= y0
->yyrule
, r1
= y1
->yyrule
;
1614 int p0
= yydprec
[r0
], p1
= yydprec
[r1
];
1618 if (yymerger
[r0
] == 0 || yymerger
[r0
] != yymerger
[r1
])
1623 if (p0
== 0 || p1
== 0)
1632 static YYRESULTTAG
yyresolveValue (yyGLRState
* yys
,
1633 yyGLRStack
* yystackp
]b4_user_formals
[);
1636 /** Resolve the previous YYN states starting at and including state YYS
1637 * on *YYSTACKP. If result != yyok, some states may have been left
1638 * unresolved possibly with empty semantic option chains. Regardless
1639 * of whether result = yyok, each state has been left with consistent
1640 * data so that yydestroyGLRState can be invoked if necessary. */
1642 yyresolveStates (yyGLRState
* yys
, int yyn
,
1643 yyGLRStack
* yystackp
]b4_user_formals
[)
1647 YYASSERT (yys
->yypred
);
1648 YYCHK (yyresolveStates (yys
->yypred
, yyn
-1, yystackp
]b4_user_args
[));
1649 if (! yys
->yyresolved
)
1650 YYCHK (yyresolveValue (yys
, yystackp
]b4_user_args
[));
1655 /** Resolve the states for the RHS of YYOPT on *YYSTACKP, perform its
1656 * user action, and return the semantic value and location in *YYVALP
1657 * and *YYLOCP. Regardless of whether result = yyok, all RHS states
1658 * have been destroyed (assuming the user action destroys all RHS
1659 * semantic values if invoked). */
1661 yyresolveAction (yySemanticOption
* yyopt
, yyGLRStack
* yystackp
,
1662 YYSTYPE
* yyvalp
, YYLTYPE
* yylocp
]b4_user_formals
[)
1664 yyGLRStackItem yyrhsVals
[YYMAXRHS
+ YYMAXLEFT
+ 1];
1667 YYSTYPE yylval_current
;
1668 YYLTYPE yylloc_current
;
1671 yynrhs
= yyrhsLength (yyopt
->yyrule
);
1672 yyflag
= yyresolveStates (yyopt
->yystate
, yynrhs
, yystackp
]b4_user_args
[);
1676 for (yys
= yyopt
->yystate
; yynrhs
> 0; yys
= yys
->yypred
, yynrhs
-= 1)
1677 yydestroyGLRState ("Cleanup: popping", yys
]b4_user_args
[);
1681 yyrhsVals
[YYMAXRHS
+ YYMAXLEFT
].yystate
.yypred
= yyopt
->yystate
;]b4_locations_if([[
1683 /* Set default location. */
1684 yyrhsVals
[YYMAXRHS
+ YYMAXLEFT
- 1].yystate
.yyloc
= yyopt
->yystate
->yyloc
;]])[
1685 yychar_current
= yychar
;
1686 yylval_current
= yylval
;
1687 yylloc_current
= yylloc
;
1688 yychar
= yyopt
->yyrawchar
;
1689 yylval
= yyopt
->yyval
;
1690 yylloc
= yyopt
->yyloc
;
1691 yyflag
= yyuserAction (yyopt
->yyrule
, yynrhs
,
1692 yyrhsVals
+ YYMAXRHS
+ YYMAXLEFT
- 1,
1693 yyvalp
, yylocp
, yystackp
]b4_user_args
[);
1694 yychar
= yychar_current
;
1695 yylval
= yylval_current
;
1696 yylloc
= yylloc_current
;
1702 yyreportTree (yySemanticOption
* yyx
, int yyindent
)
1704 int yynrhs
= yyrhsLength (yyx
->yyrule
);
1707 yyGLRState
* yystates
[1 + YYMAXRHS
];
1708 yyGLRState yyleftmost_state
;
1710 for (yyi
= yynrhs
, yys
= yyx
->yystate
; 0 < yyi
; yyi
-= 1, yys
= yys
->yypred
)
1711 yystates
[yyi
] = yys
;
1714 yyleftmost_state
.yyposn
= 0;
1715 yystates
[0] = &yyleftmost_state
;
1720 if (yyx
->yystate
->yyposn
< yys
->yyposn
+ 1)
1721 YYFPRINTF (stderr
, "%*s%s -> <Rule %d, empty>\n",
1722 yyindent
, "", yytokenName (yylhsNonterm (yyx
->yyrule
)),
1725 YYFPRINTF (stderr
, "%*s%s -> <Rule %d, tokens %lu .. %lu>\n",
1726 yyindent
, "", yytokenName (yylhsNonterm (yyx
->yyrule
)),
1727 yyx
->yyrule
- 1, (unsigned long int) (yys
->yyposn
+ 1),
1728 (unsigned long int) yyx
->yystate
->yyposn
);
1729 for (yyi
= 1; yyi
<= yynrhs
; yyi
+= 1)
1731 if (yystates
[yyi
]->yyresolved
)
1733 if (yystates
[yyi
-1]->yyposn
+1 > yystates
[yyi
]->yyposn
)
1734 YYFPRINTF (stderr
, "%*s%s <empty>\n", yyindent
+2, "",
1735 yytokenName (yystos
[yystates
[yyi
-1]->yylrState
]));
1737 YYFPRINTF (stderr
, "%*s%s <tokens %lu .. %lu>\n", yyindent
+2, "",
1738 yytokenName (yystos
[yystates
[yyi
-1]->yylrState
]),
1739 (unsigned long int) (yystates
[yyi
-1]->yyposn
+ 1),
1740 (unsigned long int) yystates
[yyi
]->yyposn
);
1743 yyreportTree (yystates
[yyi
]->yysemantics
.yyfirstVal
, yyindent
+2);
1748 /*ARGSUSED*/ static YYRESULTTAG
1749 yyreportAmbiguity (yySemanticOption
* yyx0
,
1750 yySemanticOption
* yyx1
]b4_pure_formals
[)
1756 YYFPRINTF (stderr
, "Ambiguity detected.\n");
1757 YYFPRINTF (stderr
, "Option 1,\n");
1758 yyreportTree (yyx0
, 2);
1759 YYFPRINTF (stderr
, "\nOption 2,\n");
1760 yyreportTree (yyx1
, 2);
1761 YYFPRINTF (stderr
, "\n");
1764 yyerror (]b4_yyerror_args
[YY_("syntax is ambiguous"));
1768 /** Resolve the locations for each of the YYN1 states in *YYSTACKP,
1769 * ending at YYS1. Has no effect on previously resolved states.
1770 * The first semantic option of a state is always chosen. */
1772 yyresolveLocations (yyGLRState
* yys1
, int yyn1
,
1773 yyGLRStack
*yystackp
]b4_user_formals
[)
1777 yyresolveLocations (yys1
->yypred
, yyn1
- 1, yystackp
]b4_user_args
[);
1778 if (!yys1
->yyresolved
)
1780 yySemanticOption
*yyoption
;
1781 yyGLRStackItem yyrhsloc
[1 + YYMAXRHS
];
1784 YYSTYPE yylval_current
;
1785 YYLTYPE yylloc_current
;
1786 yyoption
= yys1
->yysemantics
.yyfirstVal
;
1787 YYASSERT (yyoption
!= NULL
);
1788 yynrhs
= yyrhsLength (yyoption
->yyrule
);
1793 yyresolveLocations (yyoption
->yystate
, yynrhs
,
1794 yystackp
]b4_user_args
[);
1795 for (yys
= yyoption
->yystate
, yyn
= yynrhs
;
1797 yys
= yys
->yypred
, yyn
-= 1)
1798 yyrhsloc
[yyn
].yystate
.yyloc
= yys
->yyloc
;
1802 /* Both yyresolveAction and yyresolveLocations traverse the GSS
1803 in reverse rightmost order. It is only necessary to invoke
1804 yyresolveLocations on a subforest for which yyresolveAction
1805 would have been invoked next had an ambiguity not been
1806 detected. Thus the location of the previous state (but not
1807 necessarily the previous state itself) is guaranteed to be
1808 resolved already. */
1809 yyGLRState
*yyprevious
= yyoption
->yystate
;
1810 yyrhsloc
[0].yystate
.yyloc
= yyprevious
->yyloc
;
1812 yychar_current
= yychar
;
1813 yylval_current
= yylval
;
1814 yylloc_current
= yylloc
;
1815 yychar
= yyoption
->yyrawchar
;
1816 yylval
= yyoption
->yyval
;
1817 yylloc
= yyoption
->yyloc
;
1818 YYLLOC_DEFAULT ((yys1
->yyloc
), yyrhsloc
, yynrhs
);
1819 yychar
= yychar_current
;
1820 yylval
= yylval_current
;
1821 yylloc
= yylloc_current
;
1826 /** Resolve the ambiguity represented in state YYS in *YYSTACKP,
1827 * perform the indicated actions, and set the semantic value of YYS.
1828 * If result != yyok, the chain of semantic options in YYS has been
1829 * cleared instead or it has been left unmodified except that
1830 * redundant options may have been removed. Regardless of whether
1831 * result = yyok, YYS has been left with consistent data so that
1832 * yydestroyGLRState can be invoked if necessary. */
1834 yyresolveValue (yyGLRState
* yys
, yyGLRStack
* yystackp
]b4_user_formals
[)
1836 yySemanticOption
* yyoptionList
= yys
->yysemantics
.yyfirstVal
;
1837 yySemanticOption
* yybest
;
1838 yySemanticOption
** yypp
;
1842 YYLTYPE
*yylocp
= &yys
->yyloc
;
1844 yybest
= yyoptionList
;
1846 for (yypp
= &yyoptionList
->yynext
; *yypp
!= NULL
; )
1848 yySemanticOption
* yyp
= *yypp
;
1850 if (yyidenticalOptions (yybest
, yyp
))
1852 yymergeOptionSets (yybest
, yyp
);
1853 *yypp
= yyp
->yynext
;
1857 switch (yypreference (yybest
, yyp
))
1860 yyresolveLocations (yys
, 1, yystackp
]b4_user_args
[);
1861 return yyreportAmbiguity (yybest
, yyp
]b4_pure_args
[);
1873 /* This cannot happen so it is not worth a YYASSERT (yyfalse),
1874 but some compilers complain if the default case is
1878 yypp
= &yyp
->yynext
;
1884 yySemanticOption
* yyp
;
1885 int yyprec
= yydprec
[yybest
->yyrule
];
1886 yyflag
= yyresolveAction (yybest
, yystackp
, &yysval
,
1887 yylocp
]b4_user_args
[);
1889 for (yyp
= yybest
->yynext
; yyp
!= NULL
; yyp
= yyp
->yynext
)
1891 if (yyprec
== yydprec
[yyp
->yyrule
])
1893 YYSTYPE yysval_other
;
1895 yyflag
= yyresolveAction (yyp
, yystackp
, &yysval_other
,
1896 &yydummy
]b4_user_args
[);
1899 yydestruct ("Cleanup: discarding incompletely merged value for",
1900 yystos
[yys
->yylrState
],
1901 &yysval
]b4_locations_if([, yylocp
])[]b4_user_args
[);
1904 yyuserMerge (yymerger
[yyp
->yyrule
], &yysval
, &yysval_other
);
1909 yyflag
= yyresolveAction (yybest
, yystackp
, &yysval
, yylocp
]b4_user_args
[);
1913 yys
->yyresolved
= yytrue
;
1914 yys
->yysemantics
.yysval
= yysval
;
1917 yys
->yysemantics
.yyfirstVal
= NULL
;
1922 yyresolveStack (yyGLRStack
* yystackp
]b4_user_formals
[)
1924 if (yystackp
->yysplitPoint
!= NULL
)
1929 for (yyn
= 0, yys
= yystackp
->yytops
.yystates
[0];
1930 yys
!= yystackp
->yysplitPoint
;
1931 yys
= yys
->yypred
, yyn
+= 1)
1933 YYCHK (yyresolveStates (yystackp
->yytops
.yystates
[0], yyn
, yystackp
1940 yycompressStack (yyGLRStack
* yystackp
)
1942 yyGLRState
* yyp
, *yyq
, *yyr
;
1944 if (yystackp
->yytops
.yysize
!= 1 || yystackp
->yysplitPoint
== NULL
)
1947 for (yyp
= yystackp
->yytops
.yystates
[0], yyq
= yyp
->yypred
, yyr
= NULL
;
1948 yyp
!= yystackp
->yysplitPoint
;
1949 yyr
= yyp
, yyp
= yyq
, yyq
= yyp
->yypred
)
1952 yystackp
->yyspaceLeft
+= yystackp
->yynextFree
- yystackp
->yyitems
;
1953 yystackp
->yynextFree
= ((yyGLRStackItem
*) yystackp
->yysplitPoint
) + 1;
1954 yystackp
->yyspaceLeft
-= yystackp
->yynextFree
- yystackp
->yyitems
;
1955 yystackp
->yysplitPoint
= NULL
;
1956 yystackp
->yylastDeleted
= NULL
;
1960 yystackp
->yynextFree
->yystate
= *yyr
;
1962 yystackp
->yynextFree
->yystate
.yypred
= &yystackp
->yynextFree
[-1].yystate
;
1963 yystackp
->yytops
.yystates
[0] = &yystackp
->yynextFree
->yystate
;
1964 yystackp
->yynextFree
+= 1;
1965 yystackp
->yyspaceLeft
-= 1;
1970 yyprocessOneStack (yyGLRStack
* yystackp
, size_t yyk
,
1971 size_t yyposn
]b4_pure_formals
[)
1974 const short int* yyconflicts
;
1978 while (yystackp
->yytops
.yystates
[yyk
] != NULL
)
1980 yyStateNum yystate
= yystackp
->yytops
.yystates
[yyk
]->yylrState
;
1981 YYDPRINTF ((stderr
, "Stack %lu Entering state %d\n",
1982 (unsigned long int) yyk
, yystate
));
1984 YYASSERT (yystate
!= YYFINAL
);
1986 if (yyisDefaultedState (yystate
))
1988 yyrule
= yydefaultAction (yystate
);
1991 YYDPRINTF ((stderr
, "Stack %lu dies.\n",
1992 (unsigned long int) yyk
));
1993 yymarkStackDeleted (yystackp
, yyk
);
1996 yyflag
= yyglrReduce (yystackp
, yyk
, yyrule
, yyimmediate
[yyrule
]]b4_user_args
[);
1997 if (yyflag
== yyerr
)
1999 YYDPRINTF ((stderr
, "Stack %lu dies (predicate failure or explicit user error).\n",
2000 (unsigned long int) yyk
));
2001 yymarkStackDeleted (yystackp
, yyk
);
2011 yystackp
->yytops
.yylookaheadNeeds
[yyk
] = yytrue
;
2012 if (yychar
== YYEMPTY
)
2014 YYDPRINTF ((stderr
, "Reading a token: "));
2018 if (yychar
<= YYEOF
)
2020 yychar
= yytoken
= YYEOF
;
2021 YYDPRINTF ((stderr
, "Now at end of input.\n"));
2025 yytoken
= YYTRANSLATE (yychar
);
2026 YY_SYMBOL_PRINT ("Next token is", yytoken
, &yylval
, &yylloc
);
2029 yygetLRActions (yystate
, yytoken
, &yyaction
, &yyconflicts
);
2031 while (*yyconflicts
!= 0)
2034 size_t yynewStack
= yysplitStack (yystackp
, yyk
);
2035 YYDPRINTF ((stderr
, "Splitting off stack %lu from %lu.\n",
2036 (unsigned long int) yynewStack
,
2037 (unsigned long int) yyk
));
2038 yyflag
= yyglrReduce (yystackp
, yynewStack
,
2040 yyimmediate
[*yyconflicts
]]b4_user_args
[);
2042 YYCHK (yyprocessOneStack (yystackp
, yynewStack
,
2043 yyposn
]b4_pure_args
[));
2044 else if (yyflag
== yyerr
)
2046 YYDPRINTF ((stderr
, "Stack %lu dies.\n",
2047 (unsigned long int) yynewStack
));
2048 yymarkStackDeleted (yystackp
, yynewStack
);
2055 if (yyisShiftAction (yyaction
))
2057 else if (yyisErrorAction (yyaction
))
2059 YYDPRINTF ((stderr
, "Stack %lu dies.\n",
2060 (unsigned long int) yyk
));
2061 yymarkStackDeleted (yystackp
, yyk
);
2066 yyflag
= yyglrReduce (yystackp
, yyk
, -yyaction
,
2067 yyimmediate
[-yyaction
]]b4_user_args
[);
2068 if (yyflag
== yyerr
)
2070 YYDPRINTF ((stderr
, "Stack %lu dies (predicate failure or explicit user error).\n",
2071 (unsigned long int) yyk
));
2072 yymarkStackDeleted (yystackp
, yyk
);
2075 else if (yyflag
!= yyok
)
2083 /*ARGSUSED*/ static void
2084 yyreportSyntaxError (yyGLRStack
* yystackp
]b4_user_formals
[)
2086 if (yystackp
->yyerrState
== 0)
2090 yyn
= yypact
[yystackp
->yytops
.yystates
[0]->yylrState
];
2091 if (YYPACT_NINF
< yyn
&& yyn
<= YYLAST
)
2093 yySymbol yytoken
= YYTRANSLATE (yychar
);
2094 size_t yysize0
= yytnamerr (NULL
, yytokenName (yytoken
));
2095 size_t yysize
= yysize0
;
2097 yybool yysize_overflow
= yyfalse
;
2099 enum { YYERROR_VERBOSE_ARGS_MAXIMUM
= 5 };
2100 /* Internationalized format string. */
2101 const char *yyformat
= 0;
2102 /* Arguments of yyformat. */
2103 char const *yyarg
[YYERROR_VERBOSE_ARGS_MAXIMUM
];
2105 /* Start YYX at -YYN if negative to avoid negative indexes in
2106 YYCHECK. In other words, skip the first -YYN actions for this
2107 state because they are default actions. */
2108 int yyxbegin
= yyn
< 0 ? -yyn
: 0;
2110 /* Stay within bounds of both yycheck and yytname. */
2111 int yychecklim
= YYLAST
- yyn
+ 1;
2112 int yyxend
= yychecklim
< YYNTOKENS
? yychecklim
: YYNTOKENS
;
2114 /* Number of reported tokens (one for the "unexpected", one per
2119 yyarg
[yycount
++] = yytokenName (yytoken
);
2121 for (yyx
= yyxbegin
; yyx
< yyxend
; ++yyx
)
2122 if (yycheck
[yyx
+ yyn
] == yyx
&& yyx
!= YYTERROR
2123 && !yytable_value_is_error (yytable
[yyx
+ yyn
]))
2125 if (yycount
== YYERROR_VERBOSE_ARGS_MAXIMUM
)
2131 yyarg
[yycount
++] = yytokenName (yyx
);
2132 yysize1
= yysize
+ yytnamerr (NULL
, yytokenName (yyx
));
2133 yysize_overflow
|= yysize1
< yysize
;
2139 #define YYCASE_(N, S) \
2143 YYCASE_(1, YY_("syntax error, unexpected %s"));
2144 YYCASE_(2, YY_("syntax error, unexpected %s, expecting %s"));
2145 YYCASE_(3, YY_("syntax error, unexpected %s, expecting %s or %s"));
2146 YYCASE_(4, YY_("syntax error, unexpected %s, expecting %s or %s or %s"));
2147 YYCASE_(5, YY_("syntax error, unexpected %s, expecting %s or %s or %s or %s"));
2151 yysize1
= yysize
+ strlen (yyformat
);
2152 yysize_overflow
|= yysize1
< yysize
;
2155 if (!yysize_overflow
)
2156 yymsg
= (char *) YYMALLOC (yysize
);
2162 while ((*yyp
= *yyformat
))
2164 if (*yyp
== '%' && yyformat
[1] == 's' && yyi
< yycount
)
2166 yyp
+= yytnamerr (yyp
, yyarg
[yyi
++]);
2175 yyerror (]b4_lyyerror_args
[yymsg
);
2180 yyerror (]b4_lyyerror_args
[YY_("syntax error"));
2181 yyMemoryExhausted (yystackp
);
2185 #endif /* YYERROR_VERBOSE */
2186 yyerror (]b4_lyyerror_args
[YY_("syntax error"));
2191 /* Recover from a syntax error on *YYSTACKP, assuming that *YYSTACKP->YYTOKENP,
2192 yylval, and yylloc are the syntactic category, semantic value, and location
2193 of the lookahead. */
2194 /*ARGSUSED*/ static void
2195 yyrecoverSyntaxError (yyGLRStack
* yystackp
]b4_user_formals
[)
2200 if (yystackp
->yyerrState
== 3)
2201 /* We just shifted the error token and (perhaps) took some
2202 reductions. Skip tokens until we can proceed. */
2203 while (YYID (yytrue
))
2206 if (yychar
== YYEOF
)
2207 yyFail (yystackp
][]b4_lpure_args
[, NULL
);
2208 if (yychar
!= YYEMPTY
)
2209 {]b4_locations_if([[
2210 /* We throw away the lookahead, but the error range
2211 of the shifted error token must take it into account. */
2212 yyGLRState
*yys
= yystackp
->yytops
.yystates
[0];
2213 yyGLRStackItem yyerror_range
[3];
2214 yyerror_range
[1].yystate
.yyloc
= yys
->yyloc
;
2215 yyerror_range
[2].yystate
.yyloc
= yylloc
;
2216 YYLLOC_DEFAULT ((yys
->yyloc
), yyerror_range
, 2);]])[
2217 yytoken
= YYTRANSLATE (yychar
);
2218 yydestruct ("Error: discarding",
2219 yytoken
, &yylval
]b4_locations_if([, &yylloc
])[]b4_user_args
[);
2221 YYDPRINTF ((stderr
, "Reading a token: "));
2223 if (yychar
<= YYEOF
)
2225 yychar
= yytoken
= YYEOF
;
2226 YYDPRINTF ((stderr
, "Now at end of input.\n"));
2230 yytoken
= YYTRANSLATE (yychar
);
2231 YY_SYMBOL_PRINT ("Next token is", yytoken
, &yylval
, &yylloc
);
2233 yyj
= yypact
[yystackp
->yytops
.yystates
[0]->yylrState
];
2234 if (yypact_value_is_default (yyj
))
2237 if (yyj
< 0 || YYLAST
< yyj
|| yycheck
[yyj
] != yytoken
)
2239 if (yydefact
[yystackp
->yytops
.yystates
[0]->yylrState
] != 0)
2242 else if (! yytable_value_is_error (yytable
[yyj
]))
2246 /* Reduce to one stack. */
2247 for (yyk
= 0; yyk
< yystackp
->yytops
.yysize
; yyk
+= 1)
2248 if (yystackp
->yytops
.yystates
[yyk
] != NULL
)
2250 if (yyk
>= yystackp
->yytops
.yysize
)
2251 yyFail (yystackp
][]b4_lpure_args
[, NULL
);
2252 for (yyk
+= 1; yyk
< yystackp
->yytops
.yysize
; yyk
+= 1)
2253 yymarkStackDeleted (yystackp
, yyk
);
2254 yyremoveDeletes (yystackp
);
2255 yycompressStack (yystackp
);
2257 /* Now pop stack until we find a state that shifts the error token. */
2258 yystackp
->yyerrState
= 3;
2259 while (yystackp
->yytops
.yystates
[0] != NULL
)
2261 yyGLRState
*yys
= yystackp
->yytops
.yystates
[0];
2262 yyj
= yypact
[yys
->yylrState
];
2263 if (! yypact_value_is_default (yyj
))
2266 if (0 <= yyj
&& yyj
<= YYLAST
&& yycheck
[yyj
] == YYTERROR
2267 && yyisShiftAction (yytable
[yyj
]))
2269 /* Shift the error token having adjusted its location. */
2270 YYLTYPE yyerrloc
;]b4_locations_if([[
2271 yystackp
->yyerror_range
[2].yystate
.yyloc
= yylloc
;
2272 YYLLOC_DEFAULT (yyerrloc
, (yystackp
->yyerror_range
), 2);]])[
2273 YY_SYMBOL_PRINT ("Shifting", yystos
[yytable
[yyj
]],
2274 &yylval
, &yyerrloc
);
2275 yyglrShift (yystackp
, 0, yytable
[yyj
],
2276 yys
->yyposn
, &yylval
, &yyerrloc
);
2277 yys
= yystackp
->yytops
.yystates
[0];
2281 ]b4_locations_if([[ yystackp
->yyerror_range
[1].yystate
.yyloc
= yys
->yyloc
;]])[
2282 if (yys
->yypred
!= NULL
)
2283 yydestroyGLRState ("Error: popping", yys
]b4_user_args
[);
2284 yystackp
->yytops
.yystates
[0] = yys
->yypred
;
2285 yystackp
->yynextFree
-= 1;
2286 yystackp
->yyspaceLeft
+= 1;
2288 if (yystackp
->yytops
.yystates
[0] == NULL
)
2289 yyFail (yystackp
][]b4_lpure_args
[, NULL
);
2292 #define YYCHK1(YYE) \
2302 goto yyuser_error; \
2312 ]b4_c_ansi_function_def([yyparse
], [int], b4_parse_param
)[
2316 yyGLRStack
* const yystackp
= &yystack
;
2319 YYDPRINTF ((stderr
, "Starting parse\n"));
2322 yylval
= yyval_default
;
2324 #if defined YYLTYPE_IS_TRIVIAL && YYLTYPE_IS_TRIVIAL
2325 yylloc
.first_line
= yylloc
.last_line
= ]b4_location_initial_line
[;
2326 yylloc
.first_column
= yylloc
.last_column
= ]b4_location_initial_column
[;
2329 m4_ifdef([b4_initial_action
], [
2330 m4_pushdef([b4_at_dollar
], [yylloc
])dnl
2331 m4_pushdef([b4_dollar_dollar
], [yylval
])dnl
2332 /* User initialization code. */
2333 b4_user_initial_action
2334 m4_popdef([b4_dollar_dollar
])dnl
2335 m4_popdef([b4_at_dollar
])])dnl
2337 if (! yyinitGLRStack (yystackp
, YYINITDEPTH
))
2338 goto yyexhaustedlab
;
2339 switch (YYSETJMP (yystack
.yyexception_buffer
))
2342 case 1: goto yyabortlab
;
2343 case 2: goto yyexhaustedlab
;
2344 default: goto yybuglab
;
2346 yyglrShift (&yystack
, 0, 0, 0, &yylval
, &yylloc
);
2349 while (YYID (yytrue
))
2351 /* For efficiency, we have two loops, the first of which is
2352 specialized to deterministic operation (single stack, no
2353 potential ambiguity). */
2355 while (YYID (yytrue
))
2359 const short int* yyconflicts
;
2361 yyStateNum yystate
= yystack
.yytops
.yystates
[0]->yylrState
;
2362 YYDPRINTF ((stderr
, "Entering state %d\n", yystate
));
2363 if (yystate
== YYFINAL
)
2365 if (yyisDefaultedState (yystate
))
2367 yyrule
= yydefaultAction (yystate
);
2370 ]b4_locations_if([[ yystack
.yyerror_range
[1].yystate
.yyloc
= yylloc
;]])[
2371 yyreportSyntaxError (&yystack
]b4_user_args
[);
2374 YYCHK1 (yyglrReduce (&yystack
, 0, yyrule
, yytrue
]b4_user_args
[));
2379 if (yychar
== YYEMPTY
)
2381 YYDPRINTF ((stderr
, "Reading a token: "));
2385 if (yychar
<= YYEOF
)
2387 yychar
= yytoken
= YYEOF
;
2388 YYDPRINTF ((stderr
, "Now at end of input.\n"));
2392 yytoken
= YYTRANSLATE (yychar
);
2393 YY_SYMBOL_PRINT ("Next token is", yytoken
, &yylval
, &yylloc
);
2396 yygetLRActions (yystate
, yytoken
, &yyaction
, &yyconflicts
);
2397 if (*yyconflicts
!= 0)
2399 if (yyisShiftAction (yyaction
))
2401 YY_SYMBOL_PRINT ("Shifting", yytoken
, &yylval
, &yylloc
);
2404 yyglrShift (&yystack
, 0, yyaction
, yyposn
, &yylval
, &yylloc
);
2405 if (0 < yystack
.yyerrState
)
2406 yystack
.yyerrState
-= 1;
2408 else if (yyisErrorAction (yyaction
))
2410 ]b4_locations_if([[ yystack
.yyerror_range
[1].yystate
.yyloc
= yylloc
;]])[
2411 yyreportSyntaxError (&yystack
]b4_user_args
[);
2415 YYCHK1 (yyglrReduce (&yystack
, 0, -yyaction
, yytrue
]b4_user_args
[));
2419 while (YYID (yytrue
))
2421 yySymbol yytoken_to_shift
;
2424 for (yys
= 0; yys
< yystack
.yytops
.yysize
; yys
+= 1)
2425 yystackp
->yytops
.yylookaheadNeeds
[yys
] = yychar
!= YYEMPTY
;
2427 /* yyprocessOneStack returns one of three things:
2429 - An error flag. If the caller is yyprocessOneStack, it
2430 immediately returns as well. When the caller is finally
2431 yyparse, it jumps to an error label via YYCHK1.
2433 - yyok, but yyprocessOneStack has invoked yymarkStackDeleted
2434 (&yystack, yys), which sets the top state of yys to NULL. Thus,
2435 yyparse's following invocation of yyremoveDeletes will remove
2438 - yyok, when ready to shift a token.
2440 Except in the first case, yyparse will invoke yyremoveDeletes and
2441 then shift the next token onto all remaining stacks. This
2442 synchronization of the shift (that is, after all preceding
2443 reductions on all stacks) helps prevent double destructor calls
2444 on yylval in the event of memory exhaustion. */
2446 for (yys
= 0; yys
< yystack
.yytops
.yysize
; yys
+= 1)
2447 YYCHK1 (yyprocessOneStack (&yystack
, yys
, yyposn
]b4_lpure_args
[));
2448 yyremoveDeletes (&yystack
);
2449 if (yystack
.yytops
.yysize
== 0)
2451 yyundeleteLastStack (&yystack
);
2452 if (yystack
.yytops
.yysize
== 0)
2453 yyFail (&yystack
][]b4_lpure_args
[, YY_("syntax error"));
2454 YYCHK1 (yyresolveStack (&yystack
]b4_user_args
[));
2455 YYDPRINTF ((stderr
, "Returning to deterministic operation.\n"));
2456 ]b4_locations_if([[ yystack
.yyerror_range
[1].yystate
.yyloc
= yylloc
;]])[
2457 yyreportSyntaxError (&yystack
]b4_user_args
[);
2461 /* If any yyglrShift call fails, it will fail after shifting. Thus,
2462 a copy of yylval will already be on stack 0 in the event of a
2463 failure in the following loop. Thus, yychar is set to YYEMPTY
2464 before the loop to make sure the user destructor for yylval isn't
2466 yytoken_to_shift
= YYTRANSLATE (yychar
);
2469 for (yys
= 0; yys
< yystack
.yytops
.yysize
; yys
+= 1)
2472 const short int* yyconflicts
;
2473 yyStateNum yystate
= yystack
.yytops
.yystates
[yys
]->yylrState
;
2474 yygetLRActions (yystate
, yytoken_to_shift
, &yyaction
,
2476 /* Note that yyconflicts were handled by yyprocessOneStack. */
2477 YYDPRINTF ((stderr
, "On stack %lu, ", (unsigned long int) yys
));
2478 YY_SYMBOL_PRINT ("shifting", yytoken_to_shift
, &yylval
, &yylloc
);
2479 yyglrShift (&yystack
, yys
, yyaction
, yyposn
,
2481 YYDPRINTF ((stderr
, "Stack %lu now in state #%d\n",
2482 (unsigned long int) yys
,
2483 yystack
.yytops
.yystates
[yys
]->yylrState
));
2486 if (yystack
.yytops
.yysize
== 1)
2488 YYCHK1 (yyresolveStack (&yystack
]b4_user_args
[));
2489 YYDPRINTF ((stderr
, "Returning to deterministic operation.\n"));
2490 yycompressStack (&yystack
);
2496 yyrecoverSyntaxError (&yystack
]b4_user_args
[);
2497 yyposn
= yystack
.yytops
.yystates
[0]->yyposn
;
2513 yyerror (]b4_lyyerror_args
[YY_("memory exhausted"));
2518 if (yychar
!= YYEMPTY
)
2519 yydestruct ("Cleanup: discarding lookahead",
2520 YYTRANSLATE (yychar
),
2521 &yylval
]b4_locations_if([, &yylloc
])[]b4_user_args
[);
2523 /* If the stack is well-formed, pop the stack until it is empty,
2524 destroying its entries as we go. But free the stack regardless
2525 of whether it is well-formed. */
2526 if (yystack
.yyitems
)
2528 yyGLRState
** yystates
= yystack
.yytops
.yystates
;
2531 size_t yysize
= yystack
.yytops
.yysize
;
2533 for (yyk
= 0; yyk
< yysize
; yyk
+= 1)
2536 while (yystates
[yyk
])
2538 yyGLRState
*yys
= yystates
[yyk
];
2539 ]b4_locations_if([[ yystack
.yyerror_range
[1].yystate
.yyloc
= yys
->yyloc
;]]
2540 )[ if (yys
->yypred
!= NULL
)
2541 yydestroyGLRState ("Cleanup: popping", yys
]b4_user_args
[);
2542 yystates
[yyk
] = yys
->yypred
;
2543 yystack
.yynextFree
-= 1;
2544 yystack
.yyspaceLeft
+= 1;
2549 yyfreeGLRStack (&yystack
);
2552 /* Make sure YYID is used. */
2553 return YYID (yyresult
);
2556 /* DEBUGGING ONLY */
2558 static void yypstack (yyGLRStack
* yystackp
, size_t yyk
)
2559 __attribute__ ((__unused__
));
2560 static void yypdumpstack (yyGLRStack
* yystackp
) __attribute__ ((__unused__
));
2563 yy_yypstack (yyGLRState
* yys
)
2567 yy_yypstack (yys
->yypred
);
2568 YYFPRINTF (stderr
, " -> ");
2570 YYFPRINTF (stderr
, "%d@@%lu", yys
->yylrState
,
2571 (unsigned long int) yys
->yyposn
);
2575 yypstates (yyGLRState
* yyst
)
2578 YYFPRINTF (stderr
, "<null>");
2581 YYFPRINTF (stderr
, "\n");
2585 yypstack (yyGLRStack
* yystackp
, size_t yyk
)
2587 yypstates (yystackp
->yytops
.yystates
[yyk
]);
2590 #define YYINDEX(YYX) \
2591 ((YYX) == NULL ? -1 : (yyGLRStackItem*) (YYX) - yystackp->yyitems)
2595 yypdumpstack (yyGLRStack
* yystackp
)
2597 yyGLRStackItem
* yyp
;
2599 for (yyp
= yystackp
->yyitems
; yyp
< yystackp
->yynextFree
; yyp
+= 1)
2601 YYFPRINTF (stderr
, "%3lu. ",
2602 (unsigned long int) (yyp
- yystackp
->yyitems
));
2603 if (*(yybool
*) yyp
)
2605 YYFPRINTF (stderr
, "Res: %d, LR State: %d, posn: %lu, pred: %ld",
2606 yyp
->yystate
.yyresolved
, yyp
->yystate
.yylrState
,
2607 (unsigned long int) yyp
->yystate
.yyposn
,
2608 (long int) YYINDEX (yyp
->yystate
.yypred
));
2609 if (! yyp
->yystate
.yyresolved
)
2610 YYFPRINTF (stderr
, ", firstVal: %ld",
2611 (long int) YYINDEX (yyp
->yystate
2612 .yysemantics
.yyfirstVal
));
2616 YYFPRINTF (stderr
, "Option. rule: %d, state: %ld, next: %ld",
2617 yyp
->yyoption
.yyrule
- 1,
2618 (long int) YYINDEX (yyp
->yyoption
.yystate
),
2619 (long int) YYINDEX (yyp
->yyoption
.yynext
));
2621 YYFPRINTF (stderr
, "\n");
2623 YYFPRINTF (stderr
, "Tops:");
2624 for (yyi
= 0; yyi
< yystackp
->yytops
.yysize
; yyi
+= 1)
2625 YYFPRINTF (stderr
, "%lu: %ld; ", (unsigned long int) yyi
,
2626 (long int) YYINDEX (yystackp
->yytops
.yystates
[yyi
]));
2627 YYFPRINTF (stderr
, "\n");
2632 dnl glr
.cc produces its own header
.
2634 m4_if(b4_skeleton
, ["glr.c"],
2636 [@
output(b4_spec_defines_file@
)@
2637 b4_copyright([Skeleton interface
for Bison GLR parsers in C
],
2638 [2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010])
2640 b4_shared_declarations
2643 [[extern YYSTYPE
]b4_prefix
[lval
;]])
2645 b4_locations_if([b4_pure_if([],
2646 [extern YYLTYPE
]b4_prefix
[lloc
;])