3 # GLR skeleton for Bison
5 # Copyright (C) 2002-2012 Free Software Foundation, Inc.
7 # This program is free software: you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License as published by
9 # the Free Software Foundation, either version 3 of the License, or
10 # (at your option) any later version.
12 # This program is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
17 # You should have received a copy of the GNU General Public License
18 # along with this program. If not, see <http://www.gnu.org/licenses/>.
21 m4_include(b4_pkgdatadir
/[c
.m4
])
23 ## ---------------- ##
25 ## ---------------- ##
28 m4_define_default([b4_stack_depth_max
], [10000])
29 m4_define_default([b4_stack_depth_init
], [200])
33 ## ------------------------ ##
34 ## Pure/impure interfaces. ##
35 ## ------------------------ ##
37 b4_define_flag_if([pure
])
38 # If glr.cc is including this file and thus has already set b4_pure_flag,
39 # do not change the value of b4_pure_flag, and do not record a use of api.pure.
40 m4_ifndef([b4_pure_flag
],
41 [b4_percent_define_default([[api
.pure
]], [[false]])
42 m4_define([b4_pure_flag
],
43 [b4_percent_define_flag_if([[api
.pure
]], [[1]], [[0]])])])
47 # The possible parse-params formal arguments preceded by a comma.
49 # This is not shared with yacc.c in c.m4 because GLR relies on ISO C
50 # formal argument declarations.
51 m4_define([b4_user_formals
],
52 [m4_ifset([b4_parse_param
], [, b4_c_ansi_formals(b4_parse_param
)])])
57 # Accumule in b4_lex_param all the yylex arguments.
58 # Yes, this is quite ugly...
59 m4_define([b4_lex_param
],
60 m4_dquote(b4_pure_if([[[[YYSTYPE
*]], [[&yylval
]]][]dnl
61 b4_locations_if([, [[YYLTYPE
*], [&yylloc
]]])])dnl
62 m4_ifdef([b4_lex_param
], [, ]b4_lex_param
)))
67 # Optional effective arguments passed to yyerror: user args plus yylloc, and
69 m4_define([b4_yyerror_args
],
70 [b4_pure_if([b4_locations_if([yylocp
, ])])dnl
71 m4_ifset([b4_parse_param
], [b4_c_args(b4_parse_param
), ])])
76 # Same as above, but on the lookahead, hence &yylloc instead of yylocp.
77 m4_define([b4_lyyerror_args
],
78 [b4_pure_if([b4_locations_if([&yylloc
, ])])dnl
79 m4_ifset([b4_parse_param
], [b4_c_args(b4_parse_param
), ])])
84 # Same as b4_yyerror_args, but with a leading comma.
85 m4_define([b4_pure_args
],
86 [b4_pure_if([b4_locations_if([, yylocp
])])[]b4_user_args
])
91 # Same as above, but on the lookahead, hence &yylloc instead of yylocp.
92 m4_define([b4_lpure_args
],
93 [b4_pure_if([b4_locations_if([, &yylloc
])])[]b4_user_args
])
99 # Arguments passed to yyerror: user formals plus yylocp with leading comma.
100 m4_define([b4_pure_formals
],
101 [b4_pure_if([b4_locations_if([, YYLTYPE
*yylocp
])])[]b4_user_formals
])
104 # b4_locuser_formals(LOC = yylocp)
105 # --------------------------------
106 m4_define([b4_locuser_formals
],
107 [b4_locations_if([, YYLTYPE
*m4_default([$
1], [yylocp
])])[]b4_user_formals
])
110 # b4_locuser_args(LOC = yylocp)
111 # -----------------------------
112 m4_define([b4_locuser_args
],
113 [b4_locations_if([, m4_default([$
1], [yylocp
])])[]b4_user_args
])
117 ## ----------------- ##
118 ## Semantic Values. ##
119 ## ----------------- ##
122 # b4_lhs_value([TYPE])
123 # --------------------
124 # Expansion of $<TYPE>$.
125 m4_define([b4_lhs_value
],
126 [b4_symbol_value([(*yyvalp
)], [$
1])])
129 # b4_rhs_data(RULE-LENGTH, NUM)
130 # -----------------------------
131 # Expand to the semantic stack place that contains value and location
132 # of symbol number NUM in a rule of length RULE-LENGTH.
133 m4_define([b4_rhs_data
],
134 [((yyGLRStackItem
const *)yyvsp
)@
{YYFILL (b4_subtract([$
2], [$
1]))@
}.yystate
])
137 # b4_rhs_value(RULE-LENGTH, NUM, [TYPE])
138 # --------------------------------------
139 # Expansion of $<TYPE>NUM, where the current rule has RULE-LENGTH
141 m4_define([b4_rhs_value
],
142 [b4_symbol_value([b4_rhs_data([$
1], [$
2]).yysemantics
.yysval
], [$
3])])
153 m4_define([b4_lhs_location
],
157 # b4_rhs_location(RULE-LENGTH, NUM)
158 # ---------------------------------
159 # Expansion of @NUM, where the current rule has RULE-LENGTH symbols
161 m4_define([b4_rhs_location
],
162 [(b4_rhs_data([$
1], [$
2]).yyloc
)])
169 # b4_shared_declarations
170 # ----------------------
171 # Declaration that might either go into the header (if --defines)
172 # or open coded in the parser body.
173 m4_define([b4_shared_declarations
],
175 ]b4_percent_code_get([[requires]])[
176 ]b4_token_enums(b4_tokens
)[
177 ]b4_declare_yylstype
[
178 ]b4_c_ansi_function_decl(b4_prefix
[parse
], [int], b4_parse_param
)[
179 ]b4_percent_code_get([[provides]])[]dnl
187 # We do want M4 expansion after # for CPP macros.
190 @
output(b4_parser_file_name@
)@
191 b4_copyright([Skeleton implementation
for Bison GLR parsers in C
],
194 /* C GLR parser skeleton written by Paul Hilfinger. */
198 b4_percent_code_get([[top]])[
199 ]m4_if(b4_prefix
, [yy
], [],
200 [[/* Substitute the variable and function names. */
201 #define yyparse ]b4_prefix[parse
202 #define yylex ]b4_prefix[lex
203 #define yyerror ]b4_prefix[error
204 #define yylval ]b4_prefix[lval
205 #define yychar ]b4_prefix[char
206 #define yydebug ]b4_prefix[debug
207 #define yynerrs ]b4_prefix[nerrs]b4_locations_if([[
208 #define yylloc ]b4_prefix[lloc]])])[
210 /* Copy the first part of user declarations. */
211 ]b4_user_pre_prologue
[
215 ]b4_defines_if([[#include "@basename(]b4_spec_defines_file[@)"]],
216 [b4_shared_declarations
])[
218 /* Enabling verbose error messages. */
219 #ifdef YYERROR_VERBOSE
220 # undef YYERROR_VERBOSE
221 # define YYERROR_VERBOSE 1
223 # define YYERROR_VERBOSE ]b4_error_verbose_if([1], [0])[
226 /* Default (constant) value used for initialization for null
227 right-hand sides. Unlike the standard yacc.c template,
228 here we set the default value of $$ to a zeroed-out value.
229 Since the default value is undefined, this behavior is
230 technically correct. */
231 static YYSTYPE yyval_default
;
233 /* Copy the second part of user declarations. */
234 ]b4_user_post_prologue
235 b4_percent_code_get
[]dnl
242 # if defined YYENABLE_NLS && YYENABLE_NLS
244 # include <libintl.h> /* INFRINGES ON USER NAME SPACE */
245 # define YY_(msgid) dgettext ("bison-runtime", msgid)
249 # define YY_(msgid) msgid
253 /* Suppress unused-variable warnings by "using" E. */
254 #if ! defined lint || defined __GNUC__
255 # define YYUSE(e) ((void) (e))
257 # define YYUSE(e) /* empty */
260 /* Identity function, used to suppress warnings about constant conditions. */
264 ]b4_c_function_def([YYID
], [static int], [[int i
], [i
]])[
274 # define YYMALLOC malloc
277 # define YYREALLOC realloc
280 #define YYSIZEMAX ((size_t) -1)
285 typedef unsigned char yybool
;
292 # define YYJMP_BUF jmp_buf
293 # define YYSETJMP(env) setjmp (env)
294 # define YYLONGJMP(env, val) longjmp (env, val)
301 #ifndef __attribute__
302 /* This feature is available in gcc versions 2.5 and later. */
303 # if (! defined __GNUC__ || __GNUC__ < 2 \
304 || (__GNUC__ == 2 && __GNUC_MINOR__ < 5))
305 # define __attribute__(Spec) /* empty */
309 ]b4_locations_if([#define YYOPTIONAL_LOC(Name) Name],[
311 # define YYOPTIONAL_LOC(Name) /* empty */
313 # define YYOPTIONAL_LOC(Name) Name __attribute__ ((__unused__))
317 # define YYASSERT(condition) ((void) ((condition) || (abort (), 0)))
320 /* YYFINAL -- State number of the termination state. */
321 #define YYFINAL ]b4_final_state_number[
322 /* YYLAST -- Last index in YYTABLE. */
323 #define YYLAST ]b4_last[
325 /* YYNTOKENS -- Number of terminals. */
326 #define YYNTOKENS ]b4_tokens_number[
327 /* YYNNTS -- Number of nonterminals. */
328 #define YYNNTS ]b4_nterms_number[
329 /* YYNRULES -- Number of rules. */
330 #define YYNRULES ]b4_rules_number[
331 /* YYNRULES -- Number of states. */
332 #define YYNSTATES ]b4_states_number[
333 /* YYMAXRHS -- Maximum number of symbols on right-hand side of rule. */
334 #define YYMAXRHS ]b4_r2_max[
335 /* YYMAXLEFT -- Maximum number of symbols to the left of a handle
336 accessed by $0, $-1, etc., in any rule. */
337 #define YYMAXLEFT ]b4_max_left_semantic_context[
339 /* YYTRANSLATE(X) -- Bison symbol number corresponding to X. */
340 #define YYUNDEFTOK ]b4_undef_token_number[
341 #define YYMAXUTOK ]b4_user_token_number_max[
343 #define YYTRANSLATE(YYX) \
344 ((unsigned int) (YYX) <= YYMAXUTOK ? yytranslate[YYX] : YYUNDEFTOK)
346 /* YYTRANSLATE[YYLEX] -- Bison symbol number corresponding to YYLEX. */
347 static const ]b4_int_type_for([b4_translate
])[ yytranslate
[] =
353 /* YYRLINE[YYN] -- source line where rule number YYN was defined. */
354 static const ]b4_int_type_for([b4_rline
])[ yyrline
[] =
360 #if YYDEBUG || YYERROR_VERBOSE || ]b4_token_table_flag[
361 /* YYTNAME[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM.
362 First, the terminals, then, starting at YYNTOKENS, nonterminals. */
363 static const char *const yytname
[] =
369 #define YYPACT_NINF ]b4_pact_ninf[
370 #define YYTABLE_NINF ]b4_table_ninf[
372 ]b4_parser_tables_define
[
374 /* YYDPREC[RULE-NUM] -- Dynamic precedence of rule #RULE-NUM (0 if none). */
375 static const ]b4_int_type_for([b4_dprec
])[ yydprec
[] =
380 /* YYMERGER[RULE-NUM] -- Index of merging function for rule #RULE-NUM. */
381 static const ]b4_int_type_for([b4_merger
])[ yymerger
[] =
386 /* YYIMMEDIATE[RULE-NUM] -- True iff rule #RULE-NUM is not to be deferred, as
387 in the case of predicates. */
388 static const yybool yyimmediate
[] =
393 /* YYCONFLP[YYPACT[STATE-NUM]] -- Pointer into YYCONFL of start of
394 list of conflicting reductions corresponding to action entry for
395 state STATE-NUM in yytable. 0 means no conflicts. The list in
396 yyconfl is terminated by a rule number of 0. */
397 static const ]b4_int_type_for([b4_conflict_list_heads
])[ yyconflp
[] =
399 ]b4_conflict_list_heads
[
402 /* YYCONFL[I] -- lists of conflicting rule numbers, each terminated by
403 0, pointed into by YYCONFLP. */
404 ]dnl Do
not use b4_int_type_for here
, since there are places where
405 dnl pointers onto yyconfl are taken
, which type is
"short int *".
406 dnl We probably ought to introduce a type
for confl
.
407 [static const short int yyconfl
[] =
409 ]b4_conflicting_rules
[
412 /* Error token number */
415 /* YYLLOC_DEFAULT -- Set CURRENT to span from RHS[1] to RHS[N].
416 If N is 0, then set CURRENT to the empty location which ends
417 the previous symbol: RHS[0] (always defined). */
420 #define YYRHSLOC(Rhs, K) ((Rhs)[K].yystate.yyloc)
421 #ifndef YYLLOC_DEFAULT
422 # define YYLLOC_DEFAULT(Current, Rhs, N) \
426 (Current).first_line = YYRHSLOC (Rhs, 1).first_line; \
427 (Current).first_column = YYRHSLOC (Rhs, 1).first_column; \
428 (Current).last_line = YYRHSLOC (Rhs, N).last_line; \
429 (Current).last_column = YYRHSLOC (Rhs, N).last_column; \
433 (Current).first_line = (Current).last_line = \
434 YYRHSLOC (Rhs, 0).last_line; \
435 (Current).first_column = (Current).last_column = \
436 YYRHSLOC (Rhs, 0).last_column; \
440 /* YY_LOCATION_PRINT -- Print the location on the stream.
441 This macro was not mandated originally: define only if we know
442 we won't break user code: when these are the locations we know. */
444 # define YY_LOCATION_PRINT(File, Loc) \
445 fprintf (File, "%d.%d-%d.%d", \
446 (Loc).first_line, (Loc).first_column, \
447 (Loc).last_line, (Loc).last_column)
450 #ifndef YYLLOC_DEFAULT
451 # define YYLLOC_DEFAULT(Current, Rhs, N) ((void) 0)
455 #ifndef YY_LOCATION_PRINT
456 # define YY_LOCATION_PRINT(File, Loc) ((void) 0)
460 /* YYLEX -- calling `yylex' with the right arguments. */
461 #define YYLEX ]b4_c_function_call([yylex], [int], b4_lex_param)[
466 #define yynerrs (yystackp->yyerrcnt)
468 #define yychar (yystackp->yyrawchar)
470 #define yylval (yystackp->yyval)
472 #define yylloc (yystackp->yyloc)
473 m4_if(b4_prefix
[], [yy
], [],
474 [#define b4_prefix[]nerrs yynerrs
475 #define b4_prefix[]char yychar
476 #define b4_prefix[]lval yylval
477 #define b4_prefix[]lloc yylloc])],
478 [YYSTYPE yylval
;]b4_locations_if([[
484 static const int YYEOF
= 0;
485 static const int YYEMPTY
= -2;
487 typedef enum { yyok
, yyaccept
, yyabort
, yyerr
} YYRESULTTAG
;
491 YYRESULTTAG yychk_flag = YYE; \
492 if (yychk_flag != yyok) \
499 # define YYFPRINTF fprintf
502 # define YYDPRINTF(Args) \
508 ]b4_yy_symbol_print_generate([b4_c_ansi_function_def
])[
510 # define YY_SYMBOL_PRINT(Title, Type, Value, Location) \
514 YYFPRINTF (stderr, "%s ", Title); \
515 yy_symbol_print (stderr, Type, Value]b4_locuser_args([Location])[); \
516 YYFPRINTF (stderr, "\n"); \
520 /* Nonzero means print parse trace. It is left uninitialized so that
521 multiple parsers can coexist. */
526 # define YYDPRINTF(Args)
527 # define YY_SYMBOL_PRINT(Title, Type, Value, Location)
529 #endif /* !YYDEBUG */
531 /* YYINITDEPTH -- initial size of the parser's stacks. */
533 # define YYINITDEPTH ]b4_stack_depth_init[
536 /* YYMAXDEPTH -- maximum size the stacks can grow to (effective only
537 if the built-in stack extension method is used).
539 Do not make this value too large; the results are undefined if
540 SIZE_MAX < YYMAXDEPTH * sizeof (GLRStackItem)
541 evaluated with infinite-precision integer arithmetic. */
544 # define YYMAXDEPTH ]b4_stack_depth_max[
547 /* Minimum number of free items on the stack allowed after an
548 allocation. This is to allow allocation and initialization
549 to be completed by functions that call yyexpandGLRStack before the
550 stack is expanded, thus insuring that all necessary pointers get
551 properly redirected to new data. */
554 #ifndef YYSTACKEXPANDABLE
555 # define YYSTACKEXPANDABLE 1
558 #if YYSTACKEXPANDABLE
559 # define YY_RESERVE_GLRSTACK(Yystack) \
561 if (Yystack->yyspaceLeft < YYHEADROOM) \
562 yyexpandGLRStack (Yystack); \
565 # define YY_RESERVE_GLRSTACK(Yystack) \
567 if (Yystack->yyspaceLeft < YYHEADROOM) \
568 yyMemoryExhausted (Yystack); \
576 # if defined __GLIBC__ && defined _STRING_H && defined _GNU_SOURCE
577 # define yystpcpy stpcpy
579 /* Copy YYSRC to YYDEST, returning the address of the terminating '\0' in
582 yystpcpy (char *yydest
, const char *yysrc
)
585 const char *yys
= yysrc
;
587 while ((*yyd
++ = *yys
++) != '\0')
596 /* Copy to YYRES the contents of YYSTR after stripping away unnecessary
597 quotes and backslashes, so that it's suitable for yyerror. The
598 heuristic is that double-quoting is unnecessary unless the string
599 contains an apostrophe, a comma, or backslash (other than
600 backslash-backslash). YYSTR is taken from yytname. If YYRES is
601 null, do not copy; instead, return the length of what the result
604 yytnamerr (char *yyres
, const char *yystr
)
609 char const *yyp
= yystr
;
616 goto do_not_strip_quotes
;
620 goto do_not_strip_quotes
;
633 do_not_strip_quotes
: ;
637 return strlen (yystr
);
639 return yystpcpy (yyres
, yystr
) - yyres
;
643 #endif /* !YYERROR_VERBOSE */
645 /** State numbers, as in LALR(1) machine */
646 typedef int yyStateNum
;
648 /** Rule numbers, as in LALR(1) machine */
649 typedef int yyRuleNum
;
651 /** Grammar symbol */
652 typedef int yySymbol
;
654 /** Item references, as in LALR(1) machine */
655 typedef short int yyItemNum
;
657 typedef struct yyGLRState yyGLRState
;
658 typedef struct yyGLRStateSet yyGLRStateSet
;
659 typedef struct yySemanticOption yySemanticOption
;
660 typedef union yyGLRStackItem yyGLRStackItem
;
661 typedef struct yyGLRStack yyGLRStack
;
664 /** Type tag: always true. */
666 /** Type tag for yysemantics. If true, yysval applies, otherwise
667 * yyfirstVal applies. */
669 /** Number of corresponding LALR(1) machine state. */
670 yyStateNum yylrState
;
671 /** Preceding state in this stack */
673 /** Source position of the last token produced by my symbol */
676 /** First in a chain of alternative reductions producing the
677 * non-terminal corresponding to this state, threaded through
679 yySemanticOption
* yyfirstVal
;
680 /** Semantic value for this state. */
682 } yysemantics
;]b4_locations_if([[
683 /** Source location for this state. */
687 struct yyGLRStateSet
{
688 yyGLRState
** yystates
;
689 /** During nondeterministic operation, yylookaheadNeeds tracks which
690 * stacks have actually needed the current lookahead. During deterministic
691 * operation, yylookaheadNeeds[0] is not maintained since it would merely
692 * duplicate yychar != YYEMPTY. */
693 yybool
* yylookaheadNeeds
;
694 size_t yysize
, yycapacity
;
697 struct yySemanticOption
{
698 /** Type tag: always false. */
700 /** Rule number for this reduction */
702 /** The last RHS state in the list of states to be reduced. */
704 /** The lookahead for this reduction. */
706 YYSTYPE yyval
;]b4_locations_if([[
708 /** Next sibling in chain of options. To facilitate merging,
709 * options are chained in decreasing order by address. */
710 yySemanticOption
* yynext
;
713 /** Type of the items in the GLR stack. The yyisState field
714 * indicates which item of the union is valid. */
715 union yyGLRStackItem
{
717 yySemanticOption yyoption
;
722 ]b4_locations_if([[ /* To compute the location of the error token. */
723 yyGLRStackItem yyerror_range
[3];]])[
728 YYSTYPE yyval
;]b4_locations_if([[
731 YYJMP_BUF yyexception_buffer
;
732 yyGLRStackItem
* yyitems
;
733 yyGLRStackItem
* yynextFree
;
735 yyGLRState
* yysplitPoint
;
736 yyGLRState
* yylastDeleted
;
737 yyGLRStateSet yytops
;
740 #if YYSTACKEXPANDABLE
741 static void yyexpandGLRStack (yyGLRStack
* yystackp
);
744 static void yyFail (yyGLRStack
* yystackp
]b4_pure_formals
[, const char* yymsg
)
745 __attribute__ ((__noreturn__
));
747 yyFail (yyGLRStack
* yystackp
]b4_pure_formals
[, const char* yymsg
)
749 if (yymsg
!= YY_NULL
)
750 yyerror (]b4_yyerror_args
[yymsg
);
751 YYLONGJMP (yystackp
->yyexception_buffer
, 1);
754 static void yyMemoryExhausted (yyGLRStack
* yystackp
)
755 __attribute__ ((__noreturn__
));
757 yyMemoryExhausted (yyGLRStack
* yystackp
)
759 YYLONGJMP (yystackp
->yyexception_buffer
, 2);
762 #if YYDEBUG || YYERROR_VERBOSE
763 /** A printable representation of TOKEN. */
764 static inline const char*
765 yytokenName (yySymbol yytoken
)
767 if (yytoken
== YYEMPTY
)
770 return yytname
[yytoken
];
774 /** Fill in YYVSP[YYLOW1 .. YYLOW0-1] from the chain of states starting
775 * at YYVSP[YYLOW0].yystate.yypred. Leaves YYVSP[YYLOW1].yystate.yypred
776 * containing the pointer to the next state in the chain. */
777 static void yyfillin (yyGLRStackItem
*, int, int) __attribute__ ((__unused__
));
779 yyfillin (yyGLRStackItem
*yyvsp
, int yylow0
, int yylow1
)
782 yyGLRState
*s
= yyvsp
[yylow0
].yystate
.yypred
;
783 for (i
= yylow0
-1; i
>= yylow1
; i
-= 1)
786 yyvsp
[i
].yystate
.yylrState
= s
->yylrState
;
788 yyvsp
[i
].yystate
.yyresolved
= s
->yyresolved
;
790 yyvsp
[i
].yystate
.yysemantics
.yysval
= s
->yysemantics
.yysval
;
792 /* The effect of using yysval or yyloc (in an immediate rule) is
794 yyvsp
[i
].yystate
.yysemantics
.yyfirstVal
= YY_NULL
;]b4_locations_if([[
795 yyvsp
[i
].yystate
.yyloc
= s
->yyloc
;]])[
796 s
= yyvsp
[i
].yystate
.yypred
= s
->yypred
;
800 /* Do nothing if YYNORMAL or if *YYLOW <= YYLOW1. Otherwise, fill in
801 * YYVSP[YYLOW1 .. *YYLOW-1] as in yyfillin and set *YYLOW = YYLOW1.
802 * For convenience, always return YYLOW1. */
803 static inline int yyfill (yyGLRStackItem
*, int *, int, yybool
)
804 __attribute__ ((__unused__
));
806 yyfill (yyGLRStackItem
*yyvsp
, int *yylow
, int yylow1
, yybool yynormal
)
808 if (!yynormal
&& yylow1
< *yylow
)
810 yyfillin (yyvsp
, *yylow
, yylow1
);
816 /** Perform user action for rule number YYN, with RHS length YYRHSLEN,
817 * and top stack item YYVSP. YYLVALP points to place to put semantic
818 * value ($$), and yylocp points to place for location information
819 * (@@$). Returns yyok for normal return, yyaccept for YYACCEPT,
820 * yyerr for YYERROR, yyabort for YYABORT. */
821 /*ARGSUSED*/ static YYRESULTTAG
822 yyuserAction (yyRuleNum yyn
, int yyrhslen
, yyGLRStackItem
* yyvsp
,
823 yyGLRStack
* yystackp
,
824 YYSTYPE
* yyvalp
]b4_locuser_formals
[)
826 yybool yynormal
__attribute__ ((__unused__
)) =
827 (yystackp
->yysplitPoint
== YY_NULL
);
829 ]b4_parse_param_use([yyvalp
], [yylocp
])dnl
831 # define yyerrok (yystackp->yyerrState = 0)
833 # define YYACCEPT return yyaccept
835 # define YYABORT return yyabort
837 # define YYERROR return yyerrok, yyerr
839 # define YYRECOVERING() (yystackp->yyerrState != 0)
841 # define yyclearin (yychar = YYEMPTY)
843 # define YYFILL(N) yyfill (yyvsp, &yylow, N, yynormal)
845 # define YYBACKUP(Token, Value) \
846 return yyerror (]b4_yyerror_args[YY_("syntax error: cannot back up")), \
851 *yyvalp
= yyval_default
;
853 *yyvalp
= yyvsp
[YYFILL (1-yyrhslen
)].yystate
.yysemantics
.yysval
;]b4_locations_if([[
854 YYLLOC_DEFAULT ((*yylocp
), (yyvsp
- yyrhslen
), yyrhslen
);
855 yystackp
->yyerror_range
[1].yystate
.yyloc
= *yylocp
;
874 /*ARGSUSED*/ static void
875 yyuserMerge (int yyn
, YYSTYPE
* yy0
, YYSTYPE
* yy1
)
887 /* Bison grammar-table manipulation. */
889 ]b4_yydestruct_generate([b4_c_ansi_function_def
])[
891 /** Number of symbols composing the right hand side of rule #RULE. */
893 yyrhsLength (yyRuleNum yyrule
)
899 yydestroyGLRState (char const *yymsg
, yyGLRState
*yys
]b4_user_formals
[)
902 yydestruct (yymsg
, yystos
[yys
->yylrState
],
903 &yys
->yysemantics
.yysval
]b4_locuser_args([&yys
->yyloc
])[);
909 if (yys
->yysemantics
.yyfirstVal
)
910 YYFPRINTF (stderr
, "%s unresolved ", yymsg
);
912 YYFPRINTF (stderr
, "%s incomplete ", yymsg
);
913 yy_symbol_print (stderr
, yystos
[yys
->yylrState
],
914 YY_NULL
]b4_locuser_args([&yys
->yyloc
])[);
915 YYFPRINTF (stderr
, "\n");
919 if (yys
->yysemantics
.yyfirstVal
)
921 yySemanticOption
*yyoption
= yys
->yysemantics
.yyfirstVal
;
924 for (yyrh
= yyoption
->yystate
, yyn
= yyrhsLength (yyoption
->yyrule
);
926 yyrh
= yyrh
->yypred
, yyn
-= 1)
927 yydestroyGLRState (yymsg
, yyrh
]b4_user_args
[);
932 /** Left-hand-side symbol for rule #YYRULE. */
933 static inline yySymbol
934 yylhsNonterm (yyRuleNum yyrule
)
939 #define yypact_value_is_default(yystate) \
940 ]b4_table_value_equals([[pact]], [[yystate]], [b4_pact_ninf])[
942 /** True iff LR state YYSTATE has only a default reduction (regardless
945 yyisDefaultedState (yyStateNum yystate
)
947 return yypact_value_is_default (yypact
[yystate
]);
950 /** The default reduction for YYSTATE, assuming it has one. */
951 static inline yyRuleNum
952 yydefaultAction (yyStateNum yystate
)
954 return yydefact
[yystate
];
957 #define yytable_value_is_error(yytable_value) \
958 ]b4_table_value_equals([[table]], [[yytable_value]], [b4_table_ninf])[
960 /** Set *YYACTION to the action to take in YYSTATE on seeing YYTOKEN.
962 * R < 0: Reduce on rule -R.
964 * R > 0: Shift to state R.
965 * Set *YYCONFLICTS to a pointer into yyconfl to a 0-terminated list
966 * of conflicting reductions.
969 yygetLRActions (yyStateNum yystate
, int yytoken
,
970 int* yyaction
, const short int** yyconflicts
)
972 int yyindex
= yypact
[yystate
] + yytoken
;
973 if (yypact_value_is_default (yypact
[yystate
])
974 || yyindex
< 0 || YYLAST
< yyindex
|| yycheck
[yyindex
] != yytoken
)
976 *yyaction
= -yydefact
[yystate
];
977 *yyconflicts
= yyconfl
;
979 else if (! yytable_value_is_error (yytable
[yyindex
]))
981 *yyaction
= yytable
[yyindex
];
982 *yyconflicts
= yyconfl
+ yyconflp
[yyindex
];
987 *yyconflicts
= yyconfl
+ yyconflp
[yyindex
];
991 static inline yyStateNum
992 yyLRgotoState (yyStateNum yystate
, yySymbol yylhs
)
994 int yyr
= yypgoto
[yylhs
- YYNTOKENS
] + yystate
;
995 if (0 <= yyr
&& yyr
<= YYLAST
&& yycheck
[yyr
] == yystate
)
998 return yydefgoto
[yylhs
- YYNTOKENS
];
1001 static inline yybool
1002 yyisShiftAction (int yyaction
)
1004 return 0 < yyaction
;
1007 static inline yybool
1008 yyisErrorAction (int yyaction
)
1010 return yyaction
== 0;
1015 /** Return a fresh GLRStackItem in YYSTACKP. The item is an LR state
1016 * if YYISSTATE, and otherwise a semantic option. Callers should call
1017 * YY_RESERVE_GLRSTACK afterwards to make sure there is sufficient
1020 static inline yyGLRStackItem
*
1021 yynewGLRStackItem (yyGLRStack
* yystackp
, yybool yyisState
)
1023 yyGLRStackItem
* yynewItem
= yystackp
->yynextFree
;
1024 yystackp
->yyspaceLeft
-= 1;
1025 yystackp
->yynextFree
+= 1;
1026 yynewItem
->yystate
.yyisState
= yyisState
;
1030 /** Add a new semantic action that will execute the action for rule
1031 * YYRULE on the semantic values in YYRHS to the list of
1032 * alternative actions for YYSTATE. Assumes that YYRHS comes from
1033 * stack #YYK of *YYSTACKP. */
1035 yyaddDeferredAction (yyGLRStack
* yystackp
, size_t yyk
, yyGLRState
* yystate
,
1036 yyGLRState
* yyrhs
, yyRuleNum yyrule
)
1038 yySemanticOption
* yynewOption
=
1039 &yynewGLRStackItem (yystackp
, yyfalse
)->yyoption
;
1040 yynewOption
->yystate
= yyrhs
;
1041 yynewOption
->yyrule
= yyrule
;
1042 if (yystackp
->yytops
.yylookaheadNeeds
[yyk
])
1044 yynewOption
->yyrawchar
= yychar
;
1045 yynewOption
->yyval
= yylval
;]b4_locations_if([
1046 yynewOption
->yyloc
= yylloc
;])[
1049 yynewOption
->yyrawchar
= YYEMPTY
;
1050 yynewOption
->yynext
= yystate
->yysemantics
.yyfirstVal
;
1051 yystate
->yysemantics
.yyfirstVal
= yynewOption
;
1053 YY_RESERVE_GLRSTACK (yystackp
);
1058 /** Initialize YYSET to a singleton set containing an empty stack. */
1060 yyinitStateSet (yyGLRStateSet
* yyset
)
1063 yyset
->yycapacity
= 16;
1064 yyset
->yystates
= (yyGLRState
**) YYMALLOC (16 * sizeof yyset
->yystates
[0]);
1065 if (! yyset
->yystates
)
1067 yyset
->yystates
[0] = YY_NULL
;
1068 yyset
->yylookaheadNeeds
=
1069 (yybool
*) YYMALLOC (16 * sizeof yyset
->yylookaheadNeeds
[0]);
1070 if (! yyset
->yylookaheadNeeds
)
1072 YYFREE (yyset
->yystates
);
1078 static void yyfreeStateSet (yyGLRStateSet
* yyset
)
1080 YYFREE (yyset
->yystates
);
1081 YYFREE (yyset
->yylookaheadNeeds
);
1084 /** Initialize *YYSTACKP to a single empty stack, with total maximum
1085 * capacity for all stacks of YYSIZE. */
1087 yyinitGLRStack (yyGLRStack
* yystackp
, size_t yysize
)
1089 yystackp
->yyerrState
= 0;
1091 yystackp
->yyspaceLeft
= yysize
;
1093 (yyGLRStackItem
*) YYMALLOC (yysize
* sizeof yystackp
->yynextFree
[0]);
1094 if (!yystackp
->yyitems
)
1096 yystackp
->yynextFree
= yystackp
->yyitems
;
1097 yystackp
->yysplitPoint
= YY_NULL
;
1098 yystackp
->yylastDeleted
= YY_NULL
;
1099 return yyinitStateSet (&yystackp
->yytops
);
1103 #if YYSTACKEXPANDABLE
1104 # define YYRELOC(YYFROMITEMS,YYTOITEMS,YYX,YYTYPE) \
1105 &((YYTOITEMS) - ((YYFROMITEMS) - (yyGLRStackItem*) (YYX)))->YYTYPE
1107 /** If *YYSTACKP is expandable, extend it. WARNING: Pointers into the
1108 stack from outside should be considered invalid after this call.
1109 We always expand when there are 1 or fewer items left AFTER an
1110 allocation, so that we can avoid having external pointers exist
1111 across an allocation. */
1113 yyexpandGLRStack (yyGLRStack
* yystackp
)
1115 yyGLRStackItem
* yynewItems
;
1116 yyGLRStackItem
* yyp0
, *yyp1
;
1119 size_t yysize
= yystackp
->yynextFree
- yystackp
->yyitems
;
1120 if (YYMAXDEPTH
- YYHEADROOM
< yysize
)
1121 yyMemoryExhausted (yystackp
);
1122 yynewSize
= 2*yysize
;
1123 if (YYMAXDEPTH
< yynewSize
)
1124 yynewSize
= YYMAXDEPTH
;
1125 yynewItems
= (yyGLRStackItem
*) YYMALLOC (yynewSize
* sizeof yynewItems
[0]);
1127 yyMemoryExhausted (yystackp
);
1128 for (yyp0
= yystackp
->yyitems
, yyp1
= yynewItems
, yyn
= yysize
;
1130 yyn
-= 1, yyp0
+= 1, yyp1
+= 1)
1133 if (*(yybool
*) yyp0
)
1135 yyGLRState
* yys0
= &yyp0
->yystate
;
1136 yyGLRState
* yys1
= &yyp1
->yystate
;
1137 if (yys0
->yypred
!= YY_NULL
)
1139 YYRELOC (yyp0
, yyp1
, yys0
->yypred
, yystate
);
1140 if (! yys0
->yyresolved
&& yys0
->yysemantics
.yyfirstVal
!= YY_NULL
)
1141 yys1
->yysemantics
.yyfirstVal
=
1142 YYRELOC (yyp0
, yyp1
, yys0
->yysemantics
.yyfirstVal
, yyoption
);
1146 yySemanticOption
* yyv0
= &yyp0
->yyoption
;
1147 yySemanticOption
* yyv1
= &yyp1
->yyoption
;
1148 if (yyv0
->yystate
!= YY_NULL
)
1149 yyv1
->yystate
= YYRELOC (yyp0
, yyp1
, yyv0
->yystate
, yystate
);
1150 if (yyv0
->yynext
!= YY_NULL
)
1151 yyv1
->yynext
= YYRELOC (yyp0
, yyp1
, yyv0
->yynext
, yyoption
);
1154 if (yystackp
->yysplitPoint
!= YY_NULL
)
1155 yystackp
->yysplitPoint
= YYRELOC (yystackp
->yyitems
, yynewItems
,
1156 yystackp
->yysplitPoint
, yystate
);
1158 for (yyn
= 0; yyn
< yystackp
->yytops
.yysize
; yyn
+= 1)
1159 if (yystackp
->yytops
.yystates
[yyn
] != YY_NULL
)
1160 yystackp
->yytops
.yystates
[yyn
] =
1161 YYRELOC (yystackp
->yyitems
, yynewItems
,
1162 yystackp
->yytops
.yystates
[yyn
], yystate
);
1163 YYFREE (yystackp
->yyitems
);
1164 yystackp
->yyitems
= yynewItems
;
1165 yystackp
->yynextFree
= yynewItems
+ yysize
;
1166 yystackp
->yyspaceLeft
= yynewSize
- yysize
;
1171 yyfreeGLRStack (yyGLRStack
* yystackp
)
1173 YYFREE (yystackp
->yyitems
);
1174 yyfreeStateSet (&yystackp
->yytops
);
1177 /** Assuming that YYS is a GLRState somewhere on *YYSTACKP, update the
1178 * splitpoint of *YYSTACKP, if needed, so that it is at least as deep as
1181 yyupdateSplit (yyGLRStack
* yystackp
, yyGLRState
* yys
)
1183 if (yystackp
->yysplitPoint
!= YY_NULL
&& yystackp
->yysplitPoint
> yys
)
1184 yystackp
->yysplitPoint
= yys
;
1187 /** Invalidate stack #YYK in *YYSTACKP. */
1189 yymarkStackDeleted (yyGLRStack
* yystackp
, size_t yyk
)
1191 if (yystackp
->yytops
.yystates
[yyk
] != YY_NULL
)
1192 yystackp
->yylastDeleted
= yystackp
->yytops
.yystates
[yyk
];
1193 yystackp
->yytops
.yystates
[yyk
] = YY_NULL
;
1196 /** Undelete the last stack in *YYSTACKP that was marked as deleted. Can
1197 only be done once after a deletion, and only when all other stacks have
1200 yyundeleteLastStack (yyGLRStack
* yystackp
)
1202 if (yystackp
->yylastDeleted
== YY_NULL
|| yystackp
->yytops
.yysize
!= 0)
1204 yystackp
->yytops
.yystates
[0] = yystackp
->yylastDeleted
;
1205 yystackp
->yytops
.yysize
= 1;
1206 YYDPRINTF ((stderr
, "Restoring last deleted stack as stack #0.\n"));
1207 yystackp
->yylastDeleted
= YY_NULL
;
1211 yyremoveDeletes (yyGLRStack
* yystackp
)
1215 while (yyj
< yystackp
->yytops
.yysize
)
1217 if (yystackp
->yytops
.yystates
[yyi
] == YY_NULL
)
1221 YYDPRINTF ((stderr
, "Removing dead stacks.\n"));
1223 yystackp
->yytops
.yysize
-= 1;
1227 yystackp
->yytops
.yystates
[yyj
] = yystackp
->yytops
.yystates
[yyi
];
1228 /* In the current implementation, it's unnecessary to copy
1229 yystackp->yytops.yylookaheadNeeds[yyi] since, after
1230 yyremoveDeletes returns, the parser immediately either enters
1231 deterministic operation or shifts a token. However, it doesn't
1232 hurt, and the code might evolve to need it. */
1233 yystackp
->yytops
.yylookaheadNeeds
[yyj
] =
1234 yystackp
->yytops
.yylookaheadNeeds
[yyi
];
1237 YYDPRINTF ((stderr
, "Rename stack %lu -> %lu.\n",
1238 (unsigned long int) yyi
, (unsigned long int) yyj
));
1246 /** Shift to a new state on stack #YYK of *YYSTACKP, corresponding to LR
1247 * state YYLRSTATE, at input position YYPOSN, with (resolved) semantic
1248 * value *YYVALP and source location *YYLOCP. */
1250 yyglrShift (yyGLRStack
* yystackp
, size_t yyk
, yyStateNum yylrState
,
1252 YYSTYPE
* yyvalp
]b4_locations_if([, YYLTYPE
* yylocp
])[)
1254 yyGLRState
* yynewState
= &yynewGLRStackItem (yystackp
, yytrue
)->yystate
;
1256 yynewState
->yylrState
= yylrState
;
1257 yynewState
->yyposn
= yyposn
;
1258 yynewState
->yyresolved
= yytrue
;
1259 yynewState
->yypred
= yystackp
->yytops
.yystates
[yyk
];
1260 yynewState
->yysemantics
.yysval
= *yyvalp
;]b4_locations_if([
1261 yynewState
->yyloc
= *yylocp
;])[
1262 yystackp
->yytops
.yystates
[yyk
] = yynewState
;
1264 YY_RESERVE_GLRSTACK (yystackp
);
1267 /** Shift stack #YYK of *YYSTACKP, to a new state corresponding to LR
1268 * state YYLRSTATE, at input position YYPOSN, with the (unresolved)
1269 * semantic value of YYRHS under the action for YYRULE. */
1271 yyglrShiftDefer (yyGLRStack
* yystackp
, size_t yyk
, yyStateNum yylrState
,
1272 size_t yyposn
, yyGLRState
* yyrhs
, yyRuleNum yyrule
)
1274 yyGLRState
* yynewState
= &yynewGLRStackItem (yystackp
, yytrue
)->yystate
;
1276 yynewState
->yylrState
= yylrState
;
1277 yynewState
->yyposn
= yyposn
;
1278 yynewState
->yyresolved
= yyfalse
;
1279 yynewState
->yypred
= yystackp
->yytops
.yystates
[yyk
];
1280 yynewState
->yysemantics
.yyfirstVal
= YY_NULL
;
1281 yystackp
->yytops
.yystates
[yyk
] = yynewState
;
1283 /* Invokes YY_RESERVE_GLRSTACK. */
1284 yyaddDeferredAction (yystackp
, yyk
, yynewState
, yyrhs
, yyrule
);
1288 # define YY_REDUCE_PRINT(Args)
1290 # define YY_REDUCE_PRINT(Args) \
1293 yy_reduce_print Args; \
1296 /*----------------------------------------------------------------------.
1297 | Report that stack #YYK of *YYSTACKP is going to be reduced by YYRULE. |
1298 `----------------------------------------------------------------------*/
1300 /*ARGSUSED*/ static inline void
1301 yy_reduce_print (int yynormal
, yyGLRStackItem
* yyvsp
, size_t yyk
,
1302 yyRuleNum yyrule
]b4_user_formals
[)
1304 int yynrhs
= yyrhsLength (yyrule
);]b4_locations_if([
1307 YYFPRINTF (stderr
, "Reducing stack %lu by rule %d (line %lu):\n",
1308 (unsigned long int) yyk
, yyrule
- 1,
1309 (unsigned long int) yyrline
[yyrule
]);
1311 yyfillin (yyvsp
, 1, -yynrhs
);
1312 /* The symbols being reduced. */
1313 for (yyi
= 0; yyi
< yynrhs
; yyi
++)
1315 YYFPRINTF (stderr
, " $%d = ", yyi
+ 1);
1316 yy_symbol_print (stderr
,
1317 yystos
[yyvsp
[yyi
- yynrhs
+ 1].yystate
.yylrState
],
1318 &yyvsp
[yyi
- yynrhs
+ 1].yystate
.yysemantics
.yysval
1319 ]b4_locations_if([, &]b4_rhs_location(yynrhs
, yyi
+ 1))[]dnl
1321 if (!yyvsp
[yyi
- yynrhs
+ 1].yystate
.yyresolved
)
1322 YYFPRINTF (stderr
, " (unresolved)");
1323 YYFPRINTF (stderr
, "\n");
1328 /** Pop the symbols consumed by reduction #YYRULE from the top of stack
1329 * #YYK of *YYSTACKP, and perform the appropriate semantic action on their
1330 * semantic values. Assumes that all ambiguities in semantic values
1331 * have been previously resolved. Set *YYVALP to the resulting value,
1332 * and *YYLOCP to the computed location (if any). Return value is as
1333 * for userAction. */
1334 static inline YYRESULTTAG
1335 yydoAction (yyGLRStack
* yystackp
, size_t yyk
, yyRuleNum yyrule
,
1336 YYSTYPE
* yyvalp
]b4_locuser_formals
[)
1338 int yynrhs
= yyrhsLength (yyrule
);
1340 if (yystackp
->yysplitPoint
== YY_NULL
)
1342 /* Standard special case: single stack. */
1343 yyGLRStackItem
* yyrhs
= (yyGLRStackItem
*) yystackp
->yytops
.yystates
[yyk
];
1344 YYASSERT (yyk
== 0);
1345 yystackp
->yynextFree
-= yynrhs
;
1346 yystackp
->yyspaceLeft
+= yynrhs
;
1347 yystackp
->yytops
.yystates
[0] = & yystackp
->yynextFree
[-1].yystate
;
1348 YY_REDUCE_PRINT ((1, yyrhs
, yyk
, yyrule
]b4_user_args
[));
1349 return yyuserAction (yyrule
, yynrhs
, yyrhs
, yystackp
,
1350 yyvalp
]b4_locuser_args
[);
1356 yyGLRStackItem yyrhsVals
[YYMAXRHS
+ YYMAXLEFT
+ 1];
1357 yys
= yyrhsVals
[YYMAXRHS
+ YYMAXLEFT
].yystate
.yypred
1358 = yystackp
->yytops
.yystates
[yyk
];]b4_locations_if([[
1360 /* Set default location. */
1361 yyrhsVals
[YYMAXRHS
+ YYMAXLEFT
- 1].yystate
.yyloc
= yys
->yyloc
;]])[
1362 for (yyi
= 0; yyi
< yynrhs
; yyi
+= 1)
1367 yyupdateSplit (yystackp
, yys
);
1368 yystackp
->yytops
.yystates
[yyk
] = yys
;
1369 YY_REDUCE_PRINT ((0, yyrhsVals
+ YYMAXRHS
+ YYMAXLEFT
- 1, yyk
, yyrule
]b4_user_args
[));
1370 return yyuserAction (yyrule
, yynrhs
, yyrhsVals
+ YYMAXRHS
+ YYMAXLEFT
- 1,
1371 yystackp
, yyvalp
]b4_locuser_args
[);
1375 /** Pop items off stack #YYK of *YYSTACKP according to grammar rule YYRULE,
1376 * and push back on the resulting nonterminal symbol. Perform the
1377 * semantic action associated with YYRULE and store its value with the
1378 * newly pushed state, if YYFORCEEVAL or if *YYSTACKP is currently
1379 * unambiguous. Otherwise, store the deferred semantic action with
1380 * the new state. If the new state would have an identical input
1381 * position, LR state, and predecessor to an existing state on the stack,
1382 * it is identified with that existing state, eliminating stack #YYK from
1383 * *YYSTACKP. In this case, the semantic value is
1384 * added to the options for the existing state's semantic value.
1386 static inline YYRESULTTAG
1387 yyglrReduce (yyGLRStack
* yystackp
, size_t yyk
, yyRuleNum yyrule
,
1388 yybool yyforceEval
]b4_user_formals
[)
1390 size_t yyposn
= yystackp
->yytops
.yystates
[yyk
]->yyposn
;
1392 if (yyforceEval
|| yystackp
->yysplitPoint
== YY_NULL
)
1395 YYSTYPE yysval
;]b4_locations_if([
1398 yyflag
= yydoAction (yystackp
, yyk
, yyrule
, &yysval
]b4_locuser_args([&yyloc
])[);
1399 if (yyflag
== yyerr
&& yystackp
->yysplitPoint
!= YY_NULL
)
1401 YYDPRINTF ((stderr
, "Parse on stack %lu rejected by rule #%d.\n",
1402 (unsigned long int) yyk
, yyrule
- 1));
1406 YY_SYMBOL_PRINT ("-> $$ =", yyr1
[yyrule
], &yysval
, &yyloc
);
1407 yyglrShift (yystackp
, yyk
,
1408 yyLRgotoState (yystackp
->yytops
.yystates
[yyk
]->yylrState
,
1409 yylhsNonterm (yyrule
)),
1410 yyposn
, &yysval
]b4_locations_if([, &yyloc
])[);
1416 yyGLRState
* yys
, *yys0
= yystackp
->yytops
.yystates
[yyk
];
1417 yyStateNum yynewLRState
;
1419 for (yys
= yystackp
->yytops
.yystates
[yyk
], yyn
= yyrhsLength (yyrule
);
1425 yyupdateSplit (yystackp
, yys
);
1426 yynewLRState
= yyLRgotoState (yys
->yylrState
, yylhsNonterm (yyrule
));
1428 "Reduced stack %lu by rule #%d; action deferred. "
1429 "Now in state %d.\n",
1430 (unsigned long int) yyk
, yyrule
- 1, yynewLRState
));
1431 for (yyi
= 0; yyi
< yystackp
->yytops
.yysize
; yyi
+= 1)
1432 if (yyi
!= yyk
&& yystackp
->yytops
.yystates
[yyi
] != YY_NULL
)
1434 yyGLRState
*yysplit
= yystackp
->yysplitPoint
;
1435 yyGLRState
*yyp
= yystackp
->yytops
.yystates
[yyi
];
1436 while (yyp
!= yys
&& yyp
!= yysplit
&& yyp
->yyposn
>= yyposn
)
1438 if (yyp
->yylrState
== yynewLRState
&& yyp
->yypred
== yys
)
1440 yyaddDeferredAction (yystackp
, yyk
, yyp
, yys0
, yyrule
);
1441 yymarkStackDeleted (yystackp
, yyk
);
1442 YYDPRINTF ((stderr
, "Merging stack %lu into stack %lu.\n",
1443 (unsigned long int) yyk
,
1444 (unsigned long int) yyi
));
1450 yystackp
->yytops
.yystates
[yyk
] = yys
;
1451 yyglrShiftDefer (yystackp
, yyk
, yynewLRState
, yyposn
, yys0
, yyrule
);
1457 yysplitStack (yyGLRStack
* yystackp
, size_t yyk
)
1459 if (yystackp
->yysplitPoint
== YY_NULL
)
1461 YYASSERT (yyk
== 0);
1462 yystackp
->yysplitPoint
= yystackp
->yytops
.yystates
[yyk
];
1464 if (yystackp
->yytops
.yysize
>= yystackp
->yytops
.yycapacity
)
1466 yyGLRState
** yynewStates
;
1467 yybool
* yynewLookaheadNeeds
;
1469 yynewStates
= YY_NULL
;
1471 if (yystackp
->yytops
.yycapacity
1472 > (YYSIZEMAX
/ (2 * sizeof yynewStates
[0])))
1473 yyMemoryExhausted (yystackp
);
1474 yystackp
->yytops
.yycapacity
*= 2;
1477 (yyGLRState
**) YYREALLOC (yystackp
->yytops
.yystates
,
1478 (yystackp
->yytops
.yycapacity
1479 * sizeof yynewStates
[0]));
1480 if (yynewStates
== YY_NULL
)
1481 yyMemoryExhausted (yystackp
);
1482 yystackp
->yytops
.yystates
= yynewStates
;
1484 yynewLookaheadNeeds
=
1485 (yybool
*) YYREALLOC (yystackp
->yytops
.yylookaheadNeeds
,
1486 (yystackp
->yytops
.yycapacity
1487 * sizeof yynewLookaheadNeeds
[0]));
1488 if (yynewLookaheadNeeds
== YY_NULL
)
1489 yyMemoryExhausted (yystackp
);
1490 yystackp
->yytops
.yylookaheadNeeds
= yynewLookaheadNeeds
;
1492 yystackp
->yytops
.yystates
[yystackp
->yytops
.yysize
]
1493 = yystackp
->yytops
.yystates
[yyk
];
1494 yystackp
->yytops
.yylookaheadNeeds
[yystackp
->yytops
.yysize
]
1495 = yystackp
->yytops
.yylookaheadNeeds
[yyk
];
1496 yystackp
->yytops
.yysize
+= 1;
1497 return yystackp
->yytops
.yysize
-1;
1500 /** True iff YYY0 and YYY1 represent identical options at the top level.
1501 * That is, they represent the same rule applied to RHS symbols
1502 * that produce the same terminal symbols. */
1504 yyidenticalOptions (yySemanticOption
* yyy0
, yySemanticOption
* yyy1
)
1506 if (yyy0
->yyrule
== yyy1
->yyrule
)
1508 yyGLRState
*yys0
, *yys1
;
1510 for (yys0
= yyy0
->yystate
, yys1
= yyy1
->yystate
,
1511 yyn
= yyrhsLength (yyy0
->yyrule
);
1513 yys0
= yys0
->yypred
, yys1
= yys1
->yypred
, yyn
-= 1)
1514 if (yys0
->yyposn
!= yys1
->yyposn
)
1522 /** Assuming identicalOptions (YYY0,YYY1), destructively merge the
1523 * alternative semantic values for the RHS-symbols of YYY1 and YYY0. */
1525 yymergeOptionSets (yySemanticOption
* yyy0
, yySemanticOption
* yyy1
)
1527 yyGLRState
*yys0
, *yys1
;
1529 for (yys0
= yyy0
->yystate
, yys1
= yyy1
->yystate
,
1530 yyn
= yyrhsLength (yyy0
->yyrule
);
1532 yys0
= yys0
->yypred
, yys1
= yys1
->yypred
, yyn
-= 1)
1536 else if (yys0
->yyresolved
)
1538 yys1
->yyresolved
= yytrue
;
1539 yys1
->yysemantics
.yysval
= yys0
->yysemantics
.yysval
;
1541 else if (yys1
->yyresolved
)
1543 yys0
->yyresolved
= yytrue
;
1544 yys0
->yysemantics
.yysval
= yys1
->yysemantics
.yysval
;
1548 yySemanticOption
** yyz0p
= &yys0
->yysemantics
.yyfirstVal
;
1549 yySemanticOption
* yyz1
= yys1
->yysemantics
.yyfirstVal
;
1550 while (YYID (yytrue
))
1552 if (yyz1
== *yyz0p
|| yyz1
== YY_NULL
)
1554 else if (*yyz0p
== YY_NULL
)
1559 else if (*yyz0p
< yyz1
)
1561 yySemanticOption
* yyz
= *yyz0p
;
1563 yyz1
= yyz1
->yynext
;
1564 (*yyz0p
)->yynext
= yyz
;
1566 yyz0p
= &(*yyz0p
)->yynext
;
1568 yys1
->yysemantics
.yyfirstVal
= yys0
->yysemantics
.yyfirstVal
;
1573 /** Y0 and Y1 represent two possible actions to take in a given
1574 * parsing state; return 0 if no combination is possible,
1575 * 1 if user-mergeable, 2 if Y0 is preferred, 3 if Y1 is preferred. */
1577 yypreference (yySemanticOption
* y0
, yySemanticOption
* y1
)
1579 yyRuleNum r0
= y0
->yyrule
, r1
= y1
->yyrule
;
1580 int p0
= yydprec
[r0
], p1
= yydprec
[r1
];
1584 if (yymerger
[r0
] == 0 || yymerger
[r0
] != yymerger
[r1
])
1589 if (p0
== 0 || p1
== 0)
1598 static YYRESULTTAG
yyresolveValue (yyGLRState
* yys
,
1599 yyGLRStack
* yystackp
]b4_user_formals
[);
1602 /** Resolve the previous YYN states starting at and including state YYS
1603 * on *YYSTACKP. If result != yyok, some states may have been left
1604 * unresolved possibly with empty semantic option chains. Regardless
1605 * of whether result = yyok, each state has been left with consistent
1606 * data so that yydestroyGLRState can be invoked if necessary. */
1608 yyresolveStates (yyGLRState
* yys
, int yyn
,
1609 yyGLRStack
* yystackp
]b4_user_formals
[)
1613 YYASSERT (yys
->yypred
);
1614 YYCHK (yyresolveStates (yys
->yypred
, yyn
-1, yystackp
]b4_user_args
[));
1615 if (! yys
->yyresolved
)
1616 YYCHK (yyresolveValue (yys
, yystackp
]b4_user_args
[));
1621 /** Resolve the states for the RHS of YYOPT on *YYSTACKP, perform its
1622 * user action, and return the semantic value and location in *YYVALP
1623 * and *YYLOCP. Regardless of whether result = yyok, all RHS states
1624 * have been destroyed (assuming the user action destroys all RHS
1625 * semantic values if invoked). */
1627 yyresolveAction (yySemanticOption
* yyopt
, yyGLRStack
* yystackp
,
1628 YYSTYPE
* yyvalp
]b4_locuser_formals
[)
1630 yyGLRStackItem yyrhsVals
[YYMAXRHS
+ YYMAXLEFT
+ 1];
1631 int yynrhs
= yyrhsLength (yyopt
->yyrule
);
1632 YYRESULTTAG yyflag
=
1633 yyresolveStates (yyopt
->yystate
, yynrhs
, yystackp
]b4_user_args
[);
1637 for (yys
= yyopt
->yystate
; yynrhs
> 0; yys
= yys
->yypred
, yynrhs
-= 1)
1638 yydestroyGLRState ("Cleanup: popping", yys
]b4_user_args
[);
1642 yyrhsVals
[YYMAXRHS
+ YYMAXLEFT
].yystate
.yypred
= yyopt
->yystate
;]b4_locations_if([[
1644 /* Set default location. */
1645 yyrhsVals
[YYMAXRHS
+ YYMAXLEFT
- 1].yystate
.yyloc
= yyopt
->yystate
->yyloc
;]])[
1647 int yychar_current
= yychar
;
1648 YYSTYPE yylval_current
= yylval
;]b4_locations_if([
1649 YYLTYPE yylloc_current
= yylloc
;])[
1650 yychar
= yyopt
->yyrawchar
;
1651 yylval
= yyopt
->yyval
;]b4_locations_if([
1652 yylloc
= yyopt
->yyloc
;])[
1653 yyflag
= yyuserAction (yyopt
->yyrule
, yynrhs
,
1654 yyrhsVals
+ YYMAXRHS
+ YYMAXLEFT
- 1,
1655 yystackp
, yyvalp
]b4_locuser_args
[);
1656 yychar
= yychar_current
;
1657 yylval
= yylval_current
;]b4_locations_if([
1658 yylloc
= yylloc_current
;])[
1665 yyreportTree (yySemanticOption
* yyx
, int yyindent
)
1667 int yynrhs
= yyrhsLength (yyx
->yyrule
);
1670 yyGLRState
* yystates
[1 + YYMAXRHS
];
1671 yyGLRState yyleftmost_state
;
1673 for (yyi
= yynrhs
, yys
= yyx
->yystate
; 0 < yyi
; yyi
-= 1, yys
= yys
->yypred
)
1674 yystates
[yyi
] = yys
;
1677 yyleftmost_state
.yyposn
= 0;
1678 yystates
[0] = &yyleftmost_state
;
1683 if (yyx
->yystate
->yyposn
< yys
->yyposn
+ 1)
1684 YYFPRINTF (stderr
, "%*s%s -> <Rule %d, empty>\n",
1685 yyindent
, "", yytokenName (yylhsNonterm (yyx
->yyrule
)),
1688 YYFPRINTF (stderr
, "%*s%s -> <Rule %d, tokens %lu .. %lu>\n",
1689 yyindent
, "", yytokenName (yylhsNonterm (yyx
->yyrule
)),
1690 yyx
->yyrule
- 1, (unsigned long int) (yys
->yyposn
+ 1),
1691 (unsigned long int) yyx
->yystate
->yyposn
);
1692 for (yyi
= 1; yyi
<= yynrhs
; yyi
+= 1)
1694 if (yystates
[yyi
]->yyresolved
)
1696 if (yystates
[yyi
-1]->yyposn
+1 > yystates
[yyi
]->yyposn
)
1697 YYFPRINTF (stderr
, "%*s%s <empty>\n", yyindent
+2, "",
1698 yytokenName (yystos
[yystates
[yyi
]->yylrState
]));
1700 YYFPRINTF (stderr
, "%*s%s <tokens %lu .. %lu>\n", yyindent
+2, "",
1701 yytokenName (yystos
[yystates
[yyi
]->yylrState
]),
1702 (unsigned long int) (yystates
[yyi
-1]->yyposn
+ 1),
1703 (unsigned long int) yystates
[yyi
]->yyposn
);
1706 yyreportTree (yystates
[yyi
]->yysemantics
.yyfirstVal
, yyindent
+2);
1711 /*ARGSUSED*/ static YYRESULTTAG
1712 yyreportAmbiguity (yySemanticOption
* yyx0
,
1713 yySemanticOption
* yyx1
]b4_pure_formals
[)
1719 YYFPRINTF (stderr
, "Ambiguity detected.\n");
1720 YYFPRINTF (stderr
, "Option 1,\n");
1721 yyreportTree (yyx0
, 2);
1722 YYFPRINTF (stderr
, "\nOption 2,\n");
1723 yyreportTree (yyx1
, 2);
1724 YYFPRINTF (stderr
, "\n");
1727 yyerror (]b4_yyerror_args
[YY_("syntax is ambiguous"));
1729 }]b4_locations_if([[
1731 /** Resolve the locations for each of the YYN1 states in *YYSTACKP,
1732 * ending at YYS1. Has no effect on previously resolved states.
1733 * The first semantic option of a state is always chosen. */
1735 yyresolveLocations (yyGLRState
* yys1
, int yyn1
,
1736 yyGLRStack
*yystackp
]b4_user_formals
[)
1740 yyresolveLocations (yys1
->yypred
, yyn1
- 1, yystackp
]b4_user_args
[);
1741 if (!yys1
->yyresolved
)
1743 yyGLRStackItem yyrhsloc
[1 + YYMAXRHS
];
1745 yySemanticOption
*yyoption
= yys1
->yysemantics
.yyfirstVal
;
1746 YYASSERT (yyoption
!= YY_NULL
);
1747 yynrhs
= yyrhsLength (yyoption
->yyrule
);
1752 yyresolveLocations (yyoption
->yystate
, yynrhs
,
1753 yystackp
]b4_user_args
[);
1754 for (yys
= yyoption
->yystate
, yyn
= yynrhs
;
1756 yys
= yys
->yypred
, yyn
-= 1)
1757 yyrhsloc
[yyn
].yystate
.yyloc
= yys
->yyloc
;
1761 /* Both yyresolveAction and yyresolveLocations traverse the GSS
1762 in reverse rightmost order. It is only necessary to invoke
1763 yyresolveLocations on a subforest for which yyresolveAction
1764 would have been invoked next had an ambiguity not been
1765 detected. Thus the location of the previous state (but not
1766 necessarily the previous state itself) is guaranteed to be
1767 resolved already. */
1768 yyGLRState
*yyprevious
= yyoption
->yystate
;
1769 yyrhsloc
[0].yystate
.yyloc
= yyprevious
->yyloc
;
1772 int yychar_current
= yychar
;
1773 YYSTYPE yylval_current
= yylval
;
1774 YYLTYPE yylloc_current
= yylloc
;
1775 yychar
= yyoption
->yyrawchar
;
1776 yylval
= yyoption
->yyval
;
1777 yylloc
= yyoption
->yyloc
;
1778 YYLLOC_DEFAULT ((yys1
->yyloc
), yyrhsloc
, yynrhs
);
1779 yychar
= yychar_current
;
1780 yylval
= yylval_current
;
1781 yylloc
= yylloc_current
;
1787 /** Resolve the ambiguity represented in state YYS in *YYSTACKP,
1788 * perform the indicated actions, and set the semantic value of YYS.
1789 * If result != yyok, the chain of semantic options in YYS has been
1790 * cleared instead or it has been left unmodified except that
1791 * redundant options may have been removed. Regardless of whether
1792 * result = yyok, YYS has been left with consistent data so that
1793 * yydestroyGLRState can be invoked if necessary. */
1795 yyresolveValue (yyGLRState
* yys
, yyGLRStack
* yystackp
]b4_user_formals
[)
1797 yySemanticOption
* yyoptionList
= yys
->yysemantics
.yyfirstVal
;
1798 yySemanticOption
* yybest
= yyoptionList
;
1799 yySemanticOption
** yypp
;
1800 yybool yymerge
= yyfalse
;
1802 YYRESULTTAG yyflag
;]b4_locations_if([
1803 YYLTYPE
*yylocp
= &yys
->yyloc
;])[
1805 for (yypp
= &yyoptionList
->yynext
; *yypp
!= YY_NULL
; )
1807 yySemanticOption
* yyp
= *yypp
;
1809 if (yyidenticalOptions (yybest
, yyp
))
1811 yymergeOptionSets (yybest
, yyp
);
1812 *yypp
= yyp
->yynext
;
1816 switch (yypreference (yybest
, yyp
))
1818 case 0:]b4_locations_if([[
1819 yyresolveLocations (yys
, 1, yystackp
]b4_user_args
[);]])[
1820 return yyreportAmbiguity (yybest
, yyp
]b4_pure_args
[);
1832 /* This cannot happen so it is not worth a YYASSERT (yyfalse),
1833 but some compilers complain if the default case is
1837 yypp
= &yyp
->yynext
;
1843 yySemanticOption
* yyp
;
1844 int yyprec
= yydprec
[yybest
->yyrule
];
1845 yyflag
= yyresolveAction (yybest
, yystackp
, &yysval
]b4_locuser_args
[);
1847 for (yyp
= yybest
->yynext
; yyp
!= YY_NULL
; yyp
= yyp
->yynext
)
1849 if (yyprec
== yydprec
[yyp
->yyrule
])
1851 YYSTYPE yysval_other
;]b4_locations_if([
1853 yyflag
= yyresolveAction (yyp
, yystackp
, &yysval_other
]b4_locuser_args([&yydummy
])[);
1856 yydestruct ("Cleanup: discarding incompletely merged value for",
1857 yystos
[yys
->yylrState
],
1858 &yysval
]b4_locuser_args
[);
1861 yyuserMerge (yymerger
[yyp
->yyrule
], &yysval
, &yysval_other
);
1866 yyflag
= yyresolveAction (yybest
, yystackp
, &yysval
]b4_locuser_args([yylocp
])[);
1870 yys
->yyresolved
= yytrue
;
1871 yys
->yysemantics
.yysval
= yysval
;
1874 yys
->yysemantics
.yyfirstVal
= YY_NULL
;
1879 yyresolveStack (yyGLRStack
* yystackp
]b4_user_formals
[)
1881 if (yystackp
->yysplitPoint
!= YY_NULL
)
1886 for (yyn
= 0, yys
= yystackp
->yytops
.yystates
[0];
1887 yys
!= yystackp
->yysplitPoint
;
1888 yys
= yys
->yypred
, yyn
+= 1)
1890 YYCHK (yyresolveStates (yystackp
->yytops
.yystates
[0], yyn
, yystackp
1897 yycompressStack (yyGLRStack
* yystackp
)
1899 yyGLRState
* yyp
, *yyq
, *yyr
;
1901 if (yystackp
->yytops
.yysize
!= 1 || yystackp
->yysplitPoint
== YY_NULL
)
1904 for (yyp
= yystackp
->yytops
.yystates
[0], yyq
= yyp
->yypred
, yyr
= YY_NULL
;
1905 yyp
!= yystackp
->yysplitPoint
;
1906 yyr
= yyp
, yyp
= yyq
, yyq
= yyp
->yypred
)
1909 yystackp
->yyspaceLeft
+= yystackp
->yynextFree
- yystackp
->yyitems
;
1910 yystackp
->yynextFree
= ((yyGLRStackItem
*) yystackp
->yysplitPoint
) + 1;
1911 yystackp
->yyspaceLeft
-= yystackp
->yynextFree
- yystackp
->yyitems
;
1912 yystackp
->yysplitPoint
= YY_NULL
;
1913 yystackp
->yylastDeleted
= YY_NULL
;
1915 while (yyr
!= YY_NULL
)
1917 yystackp
->yynextFree
->yystate
= *yyr
;
1919 yystackp
->yynextFree
->yystate
.yypred
= &yystackp
->yynextFree
[-1].yystate
;
1920 yystackp
->yytops
.yystates
[0] = &yystackp
->yynextFree
->yystate
;
1921 yystackp
->yynextFree
+= 1;
1922 yystackp
->yyspaceLeft
-= 1;
1927 yyprocessOneStack (yyGLRStack
* yystackp
, size_t yyk
,
1928 size_t yyposn
]b4_pure_formals
[)
1930 while (yystackp
->yytops
.yystates
[yyk
] != YY_NULL
)
1932 yyStateNum yystate
= yystackp
->yytops
.yystates
[yyk
]->yylrState
;
1933 YYDPRINTF ((stderr
, "Stack %lu Entering state %d\n",
1934 (unsigned long int) yyk
, yystate
));
1936 YYASSERT (yystate
!= YYFINAL
);
1938 if (yyisDefaultedState (yystate
))
1941 yyRuleNum yyrule
= yydefaultAction (yystate
);
1944 YYDPRINTF ((stderr
, "Stack %lu dies.\n",
1945 (unsigned long int) yyk
));
1946 yymarkStackDeleted (yystackp
, yyk
);
1949 yyflag
= yyglrReduce (yystackp
, yyk
, yyrule
, yyimmediate
[yyrule
]]b4_user_args
[);
1950 if (yyflag
== yyerr
)
1954 "(predicate failure or explicit user error).\n",
1955 (unsigned long int) yyk
));
1956 yymarkStackDeleted (yystackp
, yyk
);
1966 const short int* yyconflicts
;
1968 yystackp
->yytops
.yylookaheadNeeds
[yyk
] = yytrue
;
1969 if (yychar
== YYEMPTY
)
1971 YYDPRINTF ((stderr
, "Reading a token: "));
1975 if (yychar
<= YYEOF
)
1977 yychar
= yytoken
= YYEOF
;
1978 YYDPRINTF ((stderr
, "Now at end of input.\n"));
1982 yytoken
= YYTRANSLATE (yychar
);
1983 YY_SYMBOL_PRINT ("Next token is", yytoken
, &yylval
, &yylloc
);
1986 yygetLRActions (yystate
, yytoken
, &yyaction
, &yyconflicts
);
1988 while (*yyconflicts
!= 0)
1991 size_t yynewStack
= yysplitStack (yystackp
, yyk
);
1992 YYDPRINTF ((stderr
, "Splitting off stack %lu from %lu.\n",
1993 (unsigned long int) yynewStack
,
1994 (unsigned long int) yyk
));
1995 yyflag
= yyglrReduce (yystackp
, yynewStack
,
1997 yyimmediate
[*yyconflicts
]]b4_user_args
[);
1999 YYCHK (yyprocessOneStack (yystackp
, yynewStack
,
2000 yyposn
]b4_pure_args
[));
2001 else if (yyflag
== yyerr
)
2003 YYDPRINTF ((stderr
, "Stack %lu dies.\n",
2004 (unsigned long int) yynewStack
));
2005 yymarkStackDeleted (yystackp
, yynewStack
);
2012 if (yyisShiftAction (yyaction
))
2014 else if (yyisErrorAction (yyaction
))
2016 YYDPRINTF ((stderr
, "Stack %lu dies.\n",
2017 (unsigned long int) yyk
));
2018 yymarkStackDeleted (yystackp
, yyk
);
2023 YYRESULTTAG yyflag
= yyglrReduce (yystackp
, yyk
, -yyaction
,
2024 yyimmediate
[-yyaction
]]b4_user_args
[);
2025 if (yyflag
== yyerr
)
2029 "(predicate failure or explicit user error).\n",
2030 (unsigned long int) yyk
));
2031 yymarkStackDeleted (yystackp
, yyk
);
2034 else if (yyflag
!= yyok
)
2042 /*ARGSUSED*/ static void
2043 yyreportSyntaxError (yyGLRStack
* yystackp
]b4_user_formals
[)
2045 if (yystackp
->yyerrState
!= 0)
2047 #if ! YYERROR_VERBOSE
2048 yyerror (]b4_lyyerror_args
[YY_("syntax error"));
2050 yySymbol yytoken
= yychar
== YYEMPTY
? YYEMPTY
: YYTRANSLATE (yychar
);
2051 size_t yysize0
= yytnamerr (YY_NULL
, yytokenName (yytoken
));
2052 size_t yysize
= yysize0
;
2054 yybool yysize_overflow
= yyfalse
;
2055 char* yymsg
= YY_NULL
;
2056 enum { YYERROR_VERBOSE_ARGS_MAXIMUM
= 5 };
2057 /* Internationalized format string. */
2058 const char *yyformat
= YY_NULL
;
2059 /* Arguments of yyformat. */
2060 char const *yyarg
[YYERROR_VERBOSE_ARGS_MAXIMUM
];
2061 /* Number of reported tokens (one for the "unexpected", one per
2065 /* There are many possibilities here to consider:
2066 - If this state is a consistent state with a default action, then
2067 the only way this function was invoked is if the default action
2068 is an error action. In that case, don't check for expected
2069 tokens because there are none.
2070 - The only way there can be no lookahead present (in yychar) is if
2071 this state is a consistent state with a default action. Thus,
2072 detecting the absence of a lookahead is sufficient to determine
2073 that there is no unexpected or expected token to report. In that
2074 case, just report a simple "syntax error".
2075 - Don't assume there isn't a lookahead just because this state is a
2076 consistent state with a default action. There might have been a
2077 previous inconsistent state, consistent state with a non-default
2078 action, or user semantic action that manipulated yychar.
2079 - Of course, the expected token list depends on states to have
2080 correct lookahead information, and it depends on the parser not
2081 to perform extra reductions after fetching a lookahead from the
2082 scanner and before detecting a syntax error. Thus, state merging
2083 (from LALR or IELR) and default reductions corrupt the expected
2084 token list. However, the list is correct for canonical LR with
2085 one exception: it will still contain any token that will not be
2086 accepted due to an error action in a later state.
2088 if (yytoken
!= YYEMPTY
)
2090 int yyn
= yypact
[yystackp
->yytops
.yystates
[0]->yylrState
];
2091 yyarg
[yycount
++] = yytokenName (yytoken
);
2092 if (!yypact_value_is_default (yyn
))
2094 /* Start YYX at -YYN if negative to avoid negative indexes in
2095 YYCHECK. In other words, skip the first -YYN actions for this
2096 state because they are default actions. */
2097 int yyxbegin
= yyn
< 0 ? -yyn
: 0;
2098 /* Stay within bounds of both yycheck and yytname. */
2099 int yychecklim
= YYLAST
- yyn
+ 1;
2100 int yyxend
= yychecklim
< YYNTOKENS
? yychecklim
: YYNTOKENS
;
2102 for (yyx
= yyxbegin
; yyx
< yyxend
; ++yyx
)
2103 if (yycheck
[yyx
+ yyn
] == yyx
&& yyx
!= YYTERROR
2104 && !yytable_value_is_error (yytable
[yyx
+ yyn
]))
2106 if (yycount
== YYERROR_VERBOSE_ARGS_MAXIMUM
)
2112 yyarg
[yycount
++] = yytokenName (yyx
);
2113 yysize1
= yysize
+ yytnamerr (YY_NULL
, yytokenName (yyx
));
2114 yysize_overflow
|= yysize1
< yysize
;
2122 #define YYCASE_(N, S) \
2126 YYCASE_(0, YY_("syntax error"));
2127 YYCASE_(1, YY_("syntax error, unexpected %s"));
2128 YYCASE_(2, YY_("syntax error, unexpected %s, expecting %s"));
2129 YYCASE_(3, YY_("syntax error, unexpected %s, expecting %s or %s"));
2130 YYCASE_(4, YY_("syntax error, unexpected %s, expecting %s or %s or %s"));
2131 YYCASE_(5, YY_("syntax error, unexpected %s, expecting %s or %s or %s or %s"));
2135 yysize1
= yysize
+ strlen (yyformat
);
2136 yysize_overflow
|= yysize1
< yysize
;
2139 if (!yysize_overflow
)
2140 yymsg
= (char *) YYMALLOC (yysize
);
2146 while ((*yyp
= *yyformat
))
2148 if (*yyp
== '%' && yyformat
[1] == 's' && yyi
< yycount
)
2150 yyp
+= yytnamerr (yyp
, yyarg
[yyi
++]);
2159 yyerror (]b4_lyyerror_args
[yymsg
);
2164 yyerror (]b4_lyyerror_args
[YY_("syntax error"));
2165 yyMemoryExhausted (yystackp
);
2167 #endif /* YYERROR_VERBOSE */
2171 /* Recover from a syntax error on *YYSTACKP, assuming that *YYSTACKP->YYTOKENP,
2172 yylval, and yylloc are the syntactic category, semantic value, and location
2173 of the lookahead. */
2174 /*ARGSUSED*/ static void
2175 yyrecoverSyntaxError (yyGLRStack
* yystackp
]b4_user_formals
[)
2180 if (yystackp
->yyerrState
== 3)
2181 /* We just shifted the error token and (perhaps) took some
2182 reductions. Skip tokens until we can proceed. */
2183 while (YYID (yytrue
))
2186 if (yychar
== YYEOF
)
2187 yyFail (yystackp
][]b4_lpure_args
[, YY_NULL
);
2188 if (yychar
!= YYEMPTY
)
2189 {]b4_locations_if([[
2190 /* We throw away the lookahead, but the error range
2191 of the shifted error token must take it into account. */
2192 yyGLRState
*yys
= yystackp
->yytops
.yystates
[0];
2193 yyGLRStackItem yyerror_range
[3];
2194 yyerror_range
[1].yystate
.yyloc
= yys
->yyloc
;
2195 yyerror_range
[2].yystate
.yyloc
= yylloc
;
2196 YYLLOC_DEFAULT ((yys
->yyloc
), yyerror_range
, 2);]])[
2197 yytoken
= YYTRANSLATE (yychar
);
2198 yydestruct ("Error: discarding",
2199 yytoken
, &yylval
]b4_locuser_args([&yylloc
])[);
2201 YYDPRINTF ((stderr
, "Reading a token: "));
2203 if (yychar
<= YYEOF
)
2205 yychar
= yytoken
= YYEOF
;
2206 YYDPRINTF ((stderr
, "Now at end of input.\n"));
2210 yytoken
= YYTRANSLATE (yychar
);
2211 YY_SYMBOL_PRINT ("Next token is", yytoken
, &yylval
, &yylloc
);
2213 yyj
= yypact
[yystackp
->yytops
.yystates
[0]->yylrState
];
2214 if (yypact_value_is_default (yyj
))
2217 if (yyj
< 0 || YYLAST
< yyj
|| yycheck
[yyj
] != yytoken
)
2219 if (yydefact
[yystackp
->yytops
.yystates
[0]->yylrState
] != 0)
2222 else if (! yytable_value_is_error (yytable
[yyj
]))
2226 /* Reduce to one stack. */
2227 for (yyk
= 0; yyk
< yystackp
->yytops
.yysize
; yyk
+= 1)
2228 if (yystackp
->yytops
.yystates
[yyk
] != YY_NULL
)
2230 if (yyk
>= yystackp
->yytops
.yysize
)
2231 yyFail (yystackp
][]b4_lpure_args
[, YY_NULL
);
2232 for (yyk
+= 1; yyk
< yystackp
->yytops
.yysize
; yyk
+= 1)
2233 yymarkStackDeleted (yystackp
, yyk
);
2234 yyremoveDeletes (yystackp
);
2235 yycompressStack (yystackp
);
2237 /* Now pop stack until we find a state that shifts the error token. */
2238 yystackp
->yyerrState
= 3;
2239 while (yystackp
->yytops
.yystates
[0] != YY_NULL
)
2241 yyGLRState
*yys
= yystackp
->yytops
.yystates
[0];
2242 yyj
= yypact
[yys
->yylrState
];
2243 if (! yypact_value_is_default (yyj
))
2246 if (0 <= yyj
&& yyj
<= YYLAST
&& yycheck
[yyj
] == YYTERROR
2247 && yyisShiftAction (yytable
[yyj
]))
2249 /* Shift the error token. */]b4_locations_if([[
2250 /* First adjust its location.*/
2252 yystackp
->yyerror_range
[2].yystate
.yyloc
= yylloc
;
2253 YYLLOC_DEFAULT (yyerrloc
, (yystackp
->yyerror_range
), 2);]])[
2254 YY_SYMBOL_PRINT ("Shifting", yystos
[yytable
[yyj
]],
2255 &yylval
, &yyerrloc
);
2256 yyglrShift (yystackp
, 0, yytable
[yyj
],
2257 yys
->yyposn
, &yylval
]b4_locations_if([, &yyerrloc
])[);
2258 yys
= yystackp
->yytops
.yystates
[0];
2261 }]b4_locations_if([[
2262 yystackp
->yyerror_range
[1].yystate
.yyloc
= yys
->yyloc
;]])[
2263 if (yys
->yypred
!= YY_NULL
)
2264 yydestroyGLRState ("Error: popping", yys
]b4_user_args
[);
2265 yystackp
->yytops
.yystates
[0] = yys
->yypred
;
2266 yystackp
->yynextFree
-= 1;
2267 yystackp
->yyspaceLeft
+= 1;
2269 if (yystackp
->yytops
.yystates
[0] == YY_NULL
)
2270 yyFail (yystackp
][]b4_lpure_args
[, YY_NULL
);
2273 #define YYCHK1(YYE) \
2283 goto yyuser_error; \
2293 ]b4_c_ansi_function_def([yyparse
], [int], b4_parse_param
)[
2297 yyGLRStack
* const yystackp
= &yystack
;
2300 YYDPRINTF ((stderr
, "Starting parse\n"));
2303 yylval
= yyval_default
;
2305 #if defined YYLTYPE_IS_TRIVIAL && YYLTYPE_IS_TRIVIAL
2306 yylloc
.first_line
= yylloc
.last_line
= ]b4_location_initial_line
[;
2307 yylloc
.first_column
= yylloc
.last_column
= ]b4_location_initial_column
[;
2310 m4_ifdef([b4_initial_action
], [
2311 m4_pushdef([b4_at_dollar
], [yylloc
])dnl
2312 m4_pushdef([b4_dollar_dollar
], [yylval
])dnl
2313 /* User initialization code. */
2314 b4_user_initial_action
2315 m4_popdef([b4_dollar_dollar
])dnl
2316 m4_popdef([b4_at_dollar
])])dnl
2318 if (! yyinitGLRStack (yystackp
, YYINITDEPTH
))
2319 goto yyexhaustedlab
;
2320 switch (YYSETJMP (yystack
.yyexception_buffer
))
2323 case 1: goto yyabortlab
;
2324 case 2: goto yyexhaustedlab
;
2325 default: goto yybuglab
;
2327 yyglrShift (&yystack
, 0, 0, 0, &yylval
]b4_locations_if([, &yylloc
])[);
2330 while (YYID (yytrue
))
2332 /* For efficiency, we have two loops, the first of which is
2333 specialized to deterministic operation (single stack, no
2334 potential ambiguity). */
2336 while (YYID (yytrue
))
2340 const short int* yyconflicts
;
2342 yyStateNum yystate
= yystack
.yytops
.yystates
[0]->yylrState
;
2343 YYDPRINTF ((stderr
, "Entering state %d\n", yystate
));
2344 if (yystate
== YYFINAL
)
2346 if (yyisDefaultedState (yystate
))
2348 yyrule
= yydefaultAction (yystate
);
2351 ]b4_locations_if([[ yystack
.yyerror_range
[1].yystate
.yyloc
= yylloc
;]])[
2352 yyreportSyntaxError (&yystack
]b4_user_args
[);
2355 YYCHK1 (yyglrReduce (&yystack
, 0, yyrule
, yytrue
]b4_user_args
[));
2360 if (yychar
== YYEMPTY
)
2362 YYDPRINTF ((stderr
, "Reading a token: "));
2366 if (yychar
<= YYEOF
)
2368 yychar
= yytoken
= YYEOF
;
2369 YYDPRINTF ((stderr
, "Now at end of input.\n"));
2373 yytoken
= YYTRANSLATE (yychar
);
2374 YY_SYMBOL_PRINT ("Next token is", yytoken
, &yylval
, &yylloc
);
2377 yygetLRActions (yystate
, yytoken
, &yyaction
, &yyconflicts
);
2378 if (*yyconflicts
!= 0)
2380 if (yyisShiftAction (yyaction
))
2382 YY_SYMBOL_PRINT ("Shifting", yytoken
, &yylval
, &yylloc
);
2385 yyglrShift (&yystack
, 0, yyaction
, yyposn
, &yylval
]b4_locations_if([, &yylloc
])[);
2386 if (0 < yystack
.yyerrState
)
2387 yystack
.yyerrState
-= 1;
2389 else if (yyisErrorAction (yyaction
))
2391 ]b4_locations_if([[ yystack
.yyerror_range
[1].yystate
.yyloc
= yylloc
;]])[
2392 yyreportSyntaxError (&yystack
]b4_user_args
[);
2396 YYCHK1 (yyglrReduce (&yystack
, 0, -yyaction
, yytrue
]b4_user_args
[));
2400 while (YYID (yytrue
))
2402 yySymbol yytoken_to_shift
;
2405 for (yys
= 0; yys
< yystack
.yytops
.yysize
; yys
+= 1)
2406 yystackp
->yytops
.yylookaheadNeeds
[yys
] = yychar
!= YYEMPTY
;
2408 /* yyprocessOneStack returns one of three things:
2410 - An error flag. If the caller is yyprocessOneStack, it
2411 immediately returns as well. When the caller is finally
2412 yyparse, it jumps to an error label via YYCHK1.
2414 - yyok, but yyprocessOneStack has invoked yymarkStackDeleted
2415 (&yystack, yys), which sets the top state of yys to NULL. Thus,
2416 yyparse's following invocation of yyremoveDeletes will remove
2419 - yyok, when ready to shift a token.
2421 Except in the first case, yyparse will invoke yyremoveDeletes and
2422 then shift the next token onto all remaining stacks. This
2423 synchronization of the shift (that is, after all preceding
2424 reductions on all stacks) helps prevent double destructor calls
2425 on yylval in the event of memory exhaustion. */
2427 for (yys
= 0; yys
< yystack
.yytops
.yysize
; yys
+= 1)
2428 YYCHK1 (yyprocessOneStack (&yystack
, yys
, yyposn
]b4_lpure_args
[));
2429 yyremoveDeletes (&yystack
);
2430 if (yystack
.yytops
.yysize
== 0)
2432 yyundeleteLastStack (&yystack
);
2433 if (yystack
.yytops
.yysize
== 0)
2434 yyFail (&yystack
][]b4_lpure_args
[, YY_("syntax error"));
2435 YYCHK1 (yyresolveStack (&yystack
]b4_user_args
[));
2436 YYDPRINTF ((stderr
, "Returning to deterministic operation.\n"));
2437 ]b4_locations_if([[ yystack
.yyerror_range
[1].yystate
.yyloc
= yylloc
;]])[
2438 yyreportSyntaxError (&yystack
]b4_user_args
[);
2442 /* If any yyglrShift call fails, it will fail after shifting. Thus,
2443 a copy of yylval will already be on stack 0 in the event of a
2444 failure in the following loop. Thus, yychar is set to YYEMPTY
2445 before the loop to make sure the user destructor for yylval isn't
2447 yytoken_to_shift
= YYTRANSLATE (yychar
);
2450 for (yys
= 0; yys
< yystack
.yytops
.yysize
; yys
+= 1)
2453 const short int* yyconflicts
;
2454 yyStateNum yystate
= yystack
.yytops
.yystates
[yys
]->yylrState
;
2455 yygetLRActions (yystate
, yytoken_to_shift
, &yyaction
,
2457 /* Note that yyconflicts were handled by yyprocessOneStack. */
2458 YYDPRINTF ((stderr
, "On stack %lu, ", (unsigned long int) yys
));
2459 YY_SYMBOL_PRINT ("shifting", yytoken_to_shift
, &yylval
, &yylloc
);
2460 yyglrShift (&yystack
, yys
, yyaction
, yyposn
,
2461 &yylval
]b4_locations_if([, &yylloc
])[);
2462 YYDPRINTF ((stderr
, "Stack %lu now in state #%d\n",
2463 (unsigned long int) yys
,
2464 yystack
.yytops
.yystates
[yys
]->yylrState
));
2467 if (yystack
.yytops
.yysize
== 1)
2469 YYCHK1 (yyresolveStack (&yystack
]b4_user_args
[));
2470 YYDPRINTF ((stderr
, "Returning to deterministic operation.\n"));
2471 yycompressStack (&yystack
);
2477 yyrecoverSyntaxError (&yystack
]b4_user_args
[);
2478 yyposn
= yystack
.yytops
.yystates
[0]->yyposn
;
2494 yyerror (]b4_lyyerror_args
[YY_("memory exhausted"));
2499 if (yychar
!= YYEMPTY
)
2500 yydestruct ("Cleanup: discarding lookahead",
2501 YYTRANSLATE (yychar
), &yylval
]b4_locuser_args([&yylloc
])[);
2503 /* If the stack is well-formed, pop the stack until it is empty,
2504 destroying its entries as we go. But free the stack regardless
2505 of whether it is well-formed. */
2506 if (yystack
.yyitems
)
2508 yyGLRState
** yystates
= yystack
.yytops
.yystates
;
2511 size_t yysize
= yystack
.yytops
.yysize
;
2513 for (yyk
= 0; yyk
< yysize
; yyk
+= 1)
2516 while (yystates
[yyk
])
2518 yyGLRState
*yys
= yystates
[yyk
];
2519 ]b4_locations_if([[ yystack
.yyerror_range
[1].yystate
.yyloc
= yys
->yyloc
;]]
2520 )[ if (yys
->yypred
!= YY_NULL
)
2521 yydestroyGLRState ("Cleanup: popping", yys
]b4_user_args
[);
2522 yystates
[yyk
] = yys
->yypred
;
2523 yystack
.yynextFree
-= 1;
2524 yystack
.yyspaceLeft
+= 1;
2529 yyfreeGLRStack (&yystack
);
2532 /* Make sure YYID is used. */
2533 return YYID (yyresult
);
2536 /* DEBUGGING ONLY */
2538 static void yypstack (yyGLRStack
* yystackp
, size_t yyk
)
2539 __attribute__ ((__unused__
));
2540 static void yypdumpstack (yyGLRStack
* yystackp
) __attribute__ ((__unused__
));
2543 yy_yypstack (yyGLRState
* yys
)
2547 yy_yypstack (yys
->yypred
);
2548 YYFPRINTF (stderr
, " -> ");
2550 YYFPRINTF (stderr
, "%d@@%lu", yys
->yylrState
,
2551 (unsigned long int) yys
->yyposn
);
2555 yypstates (yyGLRState
* yyst
)
2557 if (yyst
== YY_NULL
)
2558 YYFPRINTF (stderr
, "<null>");
2561 YYFPRINTF (stderr
, "\n");
2565 yypstack (yyGLRStack
* yystackp
, size_t yyk
)
2567 yypstates (yystackp
->yytops
.yystates
[yyk
]);
2570 #define YYINDEX(YYX) \
2571 ((YYX) == YY_NULL ? -1 : (yyGLRStackItem*) (YYX) - yystackp->yyitems)
2575 yypdumpstack (yyGLRStack
* yystackp
)
2577 yyGLRStackItem
* yyp
;
2579 for (yyp
= yystackp
->yyitems
; yyp
< yystackp
->yynextFree
; yyp
+= 1)
2581 YYFPRINTF (stderr
, "%3lu. ",
2582 (unsigned long int) (yyp
- yystackp
->yyitems
));
2583 if (*(yybool
*) yyp
)
2585 YYFPRINTF (stderr
, "Res: %d, LR State: %d, posn: %lu, pred: %ld",
2586 yyp
->yystate
.yyresolved
, yyp
->yystate
.yylrState
,
2587 (unsigned long int) yyp
->yystate
.yyposn
,
2588 (long int) YYINDEX (yyp
->yystate
.yypred
));
2589 if (! yyp
->yystate
.yyresolved
)
2590 YYFPRINTF (stderr
, ", firstVal: %ld",
2591 (long int) YYINDEX (yyp
->yystate
2592 .yysemantics
.yyfirstVal
));
2596 YYFPRINTF (stderr
, "Option. rule: %d, state: %ld, next: %ld",
2597 yyp
->yyoption
.yyrule
- 1,
2598 (long int) YYINDEX (yyp
->yyoption
.yystate
),
2599 (long int) YYINDEX (yyp
->yyoption
.yynext
));
2601 YYFPRINTF (stderr
, "\n");
2603 YYFPRINTF (stderr
, "Tops:");
2604 for (yyi
= 0; yyi
< yystackp
->yytops
.yysize
; yyi
+= 1)
2605 YYFPRINTF (stderr
, "%lu: %ld; ", (unsigned long int) yyi
,
2606 (long int) YYINDEX (yystackp
->yytops
.yystates
[yyi
]));
2607 YYFPRINTF (stderr
, "\n");
2612 dnl glr
.cc produces its own header
.
2614 m4_if(b4_skeleton
, ["glr.c"],
2616 [@
output(b4_spec_defines_file@
)@
2617 b4_copyright([Skeleton interface
for Bison GLR parsers in C
],
2620 ]b4_cpp_guard_open([b4_spec_defines_file
])[
2621 ]b4_shared_declarations
[
2622 ]b4_cpp_guard_close([b4_spec_defines_file
])[