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
)])
170 # We do want M4 expansion after # for CPP macros.
173 @
output(b4_parser_file_name@
)@
174 b4_copyright([Skeleton implementation
for Bison GLR parsers in C
],
177 /* C GLR parser skeleton written by Paul Hilfinger. */
181 b4_percent_code_get([[top]])[]dnl
182 m4_if(b4_prefix
, [yy
], [],
183 [/* Substitute the variable and function names. */
184 #define yyparse b4_prefix[]parse
185 #define yylex b4_prefix[]lex
186 #define yyerror b4_prefix[]error
187 #define yylval b4_prefix[]lval
188 #define yychar b4_prefix[]char
189 #define yydebug b4_prefix[]debug
190 #define yynerrs b4_prefix[]nerrs
191 #define yylloc b4_prefix[]lloc])[
193 /* Copy the first part of user declarations. */
194 ]b4_user_pre_prologue
198 dnl
# b4_shared_declarations
199 dnl
# ----------------------
200 dnl
# Declaration that might either go into the header (if --defines)
201 dnl
# or open coded in the parser body.
202 m4_define([b4_shared_declarations
],
203 [b4_percent_code_get([[requires]])[]dnl
205 b4_token_enums(b4_tokens
)
208 ]m4_ifdef([b4_stype
],
209 [[typedef union ]b4_union_name
[
213 # define YYSTYPE_IS_TRIVIAL 1]],
214 [m4_if(b4_tag_seen_flag
, 0,
215 [[typedef int YYSTYPE
;
216 # define YYSTYPE_IS_TRIVIAL 1]])])[
219 #if ! defined YYLTYPE && ! defined YYLTYPE_IS_DECLARED
220 typedef struct YYLTYPE
231 # define YYLTYPE_IS_DECLARED 1
232 # define YYLTYPE_IS_TRIVIAL 1
235 ]b4_percent_code_get([[provides]])[]dnl
238 b4_defines_if([[#include "@basename(]b4_spec_defines_file[@)"]],
239 [b4_shared_declarations
])[
241 /* Enabling traces. */
243 # define YYDEBUG ]b4_parse_trace_if([1], [0])[
246 /* Enabling verbose error messages. */
247 #ifdef YYERROR_VERBOSE
248 # undef YYERROR_VERBOSE
249 # define YYERROR_VERBOSE 1
251 # define YYERROR_VERBOSE ]b4_error_verbose_if([1], [0])[
254 /* Enabling the token table. */
255 #ifndef YYTOKEN_TABLE
256 # define YYTOKEN_TABLE ]b4_token_table[
259 /* Default (constant) value used for initialization for null
260 right-hand sides. Unlike the standard yacc.c template,
261 here we set the default value of $$ to a zeroed-out value.
262 Since the default value is undefined, this behavior is
263 technically correct. */
264 static YYSTYPE yyval_default
;
266 /* Copy the second part of user declarations. */
267 ]b4_user_post_prologue
268 b4_percent_code_get
[]dnl
275 # if defined YYENABLE_NLS && YYENABLE_NLS
277 # include <libintl.h> /* INFRINGES ON USER NAME SPACE */
278 # define YY_(msgid) dgettext ("bison-runtime", msgid)
282 # define YY_(msgid) msgid
286 /* Suppress unused-variable warnings by "using" E. */
287 #if ! defined lint || defined __GNUC__
288 # define YYUSE(e) ((void) (e))
290 # define YYUSE(e) /* empty */
293 /* Identity function, used to suppress warnings about constant conditions. */
297 ]b4_c_function_def([YYID
], [static int], [[int i
], [i
]])[
307 # define YYMALLOC malloc
310 # define YYREALLOC realloc
313 #define YYSIZEMAX ((size_t) -1)
318 typedef unsigned char yybool
;
325 # define YYJMP_BUF jmp_buf
326 # define YYSETJMP(env) setjmp (env)
327 # define YYLONGJMP(env, val) longjmp (env, val)
334 #ifndef __attribute__
335 /* This feature is available in gcc versions 2.5 and later. */
336 # if (! defined __GNUC__ || __GNUC__ < 2 \
337 || (__GNUC__ == 2 && __GNUC_MINOR__ < 5))
338 # define __attribute__(Spec) /* empty */
342 ]b4_locations_if([#define YYOPTIONAL_LOC(Name) Name],[
344 # define YYOPTIONAL_LOC(Name) /* empty */
346 # define YYOPTIONAL_LOC(Name) Name __attribute__ ((__unused__))
350 # define YYASSERT(condition) ((void) ((condition) || (abort (), 0)))
353 /* YYFINAL -- State number of the termination state. */
354 #define YYFINAL ]b4_final_state_number[
355 /* YYLAST -- Last index in YYTABLE. */
356 #define YYLAST ]b4_last[
358 /* YYNTOKENS -- Number of terminals. */
359 #define YYNTOKENS ]b4_tokens_number[
360 /* YYNNTS -- Number of nonterminals. */
361 #define YYNNTS ]b4_nterms_number[
362 /* YYNRULES -- Number of rules. */
363 #define YYNRULES ]b4_rules_number[
364 /* YYNRULES -- Number of states. */
365 #define YYNSTATES ]b4_states_number[
366 /* YYMAXRHS -- Maximum number of symbols on right-hand side of rule. */
367 #define YYMAXRHS ]b4_r2_max[
368 /* YYMAXLEFT -- Maximum number of symbols to the left of a handle
369 accessed by $0, $-1, etc., in any rule. */
370 #define YYMAXLEFT ]b4_max_left_semantic_context[
372 /* YYTRANSLATE(X) -- Bison symbol number corresponding to X. */
373 #define YYUNDEFTOK ]b4_undef_token_number[
374 #define YYMAXUTOK ]b4_user_token_number_max[
376 #define YYTRANSLATE(YYX) \
377 ((unsigned int) (YYX) <= YYMAXUTOK ? yytranslate[YYX] : YYUNDEFTOK)
379 /* YYTRANSLATE[YYLEX] -- Bison symbol number corresponding to YYLEX. */
380 static const ]b4_int_type_for([b4_translate
])[ yytranslate
[] =
386 /* YYRLINE[YYN] -- source line where rule number YYN was defined. */
387 static const ]b4_int_type_for([b4_rline
])[ yyrline
[] =
393 #if YYDEBUG || YYERROR_VERBOSE || YYTOKEN_TABLE
394 /* YYTNAME[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM.
395 First, the terminals, then, starting at YYNTOKENS, nonterminals. */
396 static const char *const yytname
[] =
402 #define YYPACT_NINF ]b4_pact_ninf[
403 #define YYTABLE_NINF ]b4_table_ninf[
405 ]b4_parser_tables_define
[
407 /* YYDPREC[RULE-NUM] -- Dynamic precedence of rule #RULE-NUM (0 if none). */
408 static const ]b4_int_type_for([b4_dprec
])[ yydprec
[] =
413 /* YYMERGER[RULE-NUM] -- Index of merging function for rule #RULE-NUM. */
414 static const ]b4_int_type_for([b4_merger
])[ yymerger
[] =
419 /* YYIMMEDIATE[RULE-NUM] -- True iff rule #RULE-NUM is not to be deferred, as
420 in the case of predicates. */
421 static const yybool yyimmediate
[] =
426 /* YYCONFLP[YYPACT[STATE-NUM]] -- Pointer into YYCONFL of start of
427 list of conflicting reductions corresponding to action entry for
428 state STATE-NUM in yytable. 0 means no conflicts. The list in
429 yyconfl is terminated by a rule number of 0. */
430 static const ]b4_int_type_for([b4_conflict_list_heads
])[ yyconflp
[] =
432 ]b4_conflict_list_heads
[
435 /* YYCONFL[I] -- lists of conflicting rule numbers, each terminated by
436 0, pointed into by YYCONFLP. */
437 ]dnl Do
not use b4_int_type_for here
, since there are places where
438 dnl pointers onto yyconfl are taken
, which type is
"short int *".
439 dnl We probably ought to introduce a type
for confl
.
440 [static const short int yyconfl
[] =
442 ]b4_conflicting_rules
[
445 /* Prevent warning if -Wmissing-prototypes. */
446 ]b4_c_ansi_function_decl([yyparse
], [int], b4_parse_param
)[
448 /* Error token number */
451 /* YYLLOC_DEFAULT -- Set CURRENT to span from RHS[1] to RHS[N].
452 If N is 0, then set CURRENT to the empty location which ends
453 the previous symbol: RHS[0] (always defined). */
456 #define YYRHSLOC(Rhs, K) ((Rhs)[K].yystate.yyloc)
457 #ifndef YYLLOC_DEFAULT
458 # define YYLLOC_DEFAULT(Current, Rhs, N) \
462 (Current).first_line = YYRHSLOC (Rhs, 1).first_line; \
463 (Current).first_column = YYRHSLOC (Rhs, 1).first_column; \
464 (Current).last_line = YYRHSLOC (Rhs, N).last_line; \
465 (Current).last_column = YYRHSLOC (Rhs, N).last_column; \
469 (Current).first_line = (Current).last_line = \
470 YYRHSLOC (Rhs, 0).last_line; \
471 (Current).first_column = (Current).last_column = \
472 YYRHSLOC (Rhs, 0).last_column; \
476 /* YY_LOCATION_PRINT -- Print the location on the stream.
477 This macro was not mandated originally: define only if we know
478 we won't break user code: when these are the locations we know. */
480 # define YY_LOCATION_PRINT(File, Loc) \
481 fprintf (File, "%d.%d-%d.%d", \
482 (Loc).first_line, (Loc).first_column, \
483 (Loc).last_line, (Loc).last_column)
486 #ifndef YYLLOC_DEFAULT
487 # define YYLLOC_DEFAULT(Current, Rhs, N) ((void) 0)
491 #ifndef YY_LOCATION_PRINT
492 # define YY_LOCATION_PRINT(File, Loc) ((void) 0)
496 /* YYLEX -- calling `yylex' with the right arguments. */
497 #define YYLEX ]b4_c_function_call([yylex], [int], b4_lex_param)[
502 #define yynerrs (yystackp->yyerrcnt)
504 #define yychar (yystackp->yyrawchar)
506 #define yylval (yystackp->yyval)
508 #define yylloc (yystackp->yyloc)
509 m4_if(b4_prefix
[], [yy
], [],
510 [#define b4_prefix[]nerrs yynerrs
511 #define b4_prefix[]char yychar
512 #define b4_prefix[]lval yylval
513 #define b4_prefix[]lloc yylloc])],
521 static const int YYEOF
= 0;
522 static const int YYEMPTY
= -2;
524 typedef enum { yyok
, yyaccept
, yyabort
, yyerr
} YYRESULTTAG
;
528 YYRESULTTAG yychk_flag = YYE; \
529 if (yychk_flag != yyok) \
536 # define YYFPRINTF fprintf
539 # define YYDPRINTF(Args) \
545 ]b4_yy_symbol_print_generate([b4_c_ansi_function_def
])[
547 # define YY_SYMBOL_PRINT(Title, Type, Value, Location) \
551 YYFPRINTF (stderr, "%s ", Title); \
552 yy_symbol_print (stderr, Type, Value]b4_locuser_args([Location])[); \
553 YYFPRINTF (stderr, "\n"); \
557 /* Nonzero means print parse trace. It is left uninitialized so that
558 multiple parsers can coexist. */
563 # define YYDPRINTF(Args)
564 # define YY_SYMBOL_PRINT(Title, Type, Value, Location)
566 #endif /* !YYDEBUG */
568 /* YYINITDEPTH -- initial size of the parser's stacks. */
570 # define YYINITDEPTH ]b4_stack_depth_init[
573 /* YYMAXDEPTH -- maximum size the stacks can grow to (effective only
574 if the built-in stack extension method is used).
576 Do not make this value too large; the results are undefined if
577 SIZE_MAX < YYMAXDEPTH * sizeof (GLRStackItem)
578 evaluated with infinite-precision integer arithmetic. */
581 # define YYMAXDEPTH ]b4_stack_depth_max[
584 /* Minimum number of free items on the stack allowed after an
585 allocation. This is to allow allocation and initialization
586 to be completed by functions that call yyexpandGLRStack before the
587 stack is expanded, thus insuring that all necessary pointers get
588 properly redirected to new data. */
591 #ifndef YYSTACKEXPANDABLE
592 # define YYSTACKEXPANDABLE 1
595 #if YYSTACKEXPANDABLE
596 # define YY_RESERVE_GLRSTACK(Yystack) \
598 if (Yystack->yyspaceLeft < YYHEADROOM) \
599 yyexpandGLRStack (Yystack); \
602 # define YY_RESERVE_GLRSTACK(Yystack) \
604 if (Yystack->yyspaceLeft < YYHEADROOM) \
605 yyMemoryExhausted (Yystack); \
613 # if defined __GLIBC__ && defined _STRING_H && defined _GNU_SOURCE
614 # define yystpcpy stpcpy
616 /* Copy YYSRC to YYDEST, returning the address of the terminating '\0' in
619 yystpcpy (char *yydest
, const char *yysrc
)
622 const char *yys
= yysrc
;
624 while ((*yyd
++ = *yys
++) != '\0')
633 /* Copy to YYRES the contents of YYSTR after stripping away unnecessary
634 quotes and backslashes, so that it's suitable for yyerror. The
635 heuristic is that double-quoting is unnecessary unless the string
636 contains an apostrophe, a comma, or backslash (other than
637 backslash-backslash). YYSTR is taken from yytname. If YYRES is
638 null, do not copy; instead, return the length of what the result
641 yytnamerr (char *yyres
, const char *yystr
)
646 char const *yyp
= yystr
;
653 goto do_not_strip_quotes
;
657 goto do_not_strip_quotes
;
670 do_not_strip_quotes
: ;
674 return strlen (yystr
);
676 return yystpcpy (yyres
, yystr
) - yyres
;
680 #endif /* !YYERROR_VERBOSE */
682 /** State numbers, as in LALR(1) machine */
683 typedef int yyStateNum
;
685 /** Rule numbers, as in LALR(1) machine */
686 typedef int yyRuleNum
;
688 /** Grammar symbol */
689 typedef int yySymbol
;
691 /** Item references, as in LALR(1) machine */
692 typedef short int yyItemNum
;
694 typedef struct yyGLRState yyGLRState
;
695 typedef struct yyGLRStateSet yyGLRStateSet
;
696 typedef struct yySemanticOption yySemanticOption
;
697 typedef union yyGLRStackItem yyGLRStackItem
;
698 typedef struct yyGLRStack yyGLRStack
;
701 /** Type tag: always true. */
703 /** Type tag for yysemantics. If true, yysval applies, otherwise
704 * yyfirstVal applies. */
706 /** Number of corresponding LALR(1) machine state. */
707 yyStateNum yylrState
;
708 /** Preceding state in this stack */
710 /** Source position of the last token produced by my symbol */
713 /** First in a chain of alternative reductions producing the
714 * non-terminal corresponding to this state, threaded through
716 yySemanticOption
* yyfirstVal
;
717 /** Semantic value for this state. */
720 /** Source location for this state. */
724 struct yyGLRStateSet
{
725 yyGLRState
** yystates
;
726 /** During nondeterministic operation, yylookaheadNeeds tracks which
727 * stacks have actually needed the current lookahead. During deterministic
728 * operation, yylookaheadNeeds[0] is not maintained since it would merely
729 * duplicate yychar != YYEMPTY. */
730 yybool
* yylookaheadNeeds
;
731 size_t yysize
, yycapacity
;
734 struct yySemanticOption
{
735 /** Type tag: always false. */
737 /** Rule number for this reduction */
739 /** The last RHS state in the list of states to be reduced. */
741 /** The lookahead for this reduction. */
745 /** Next sibling in chain of options. To facilitate merging,
746 * options are chained in decreasing order by address. */
747 yySemanticOption
* yynext
;
750 /** Type of the items in the GLR stack. The yyisState field
751 * indicates which item of the union is valid. */
752 union yyGLRStackItem
{
754 yySemanticOption yyoption
;
759 ]b4_locations_if([[ /* To compute the location of the error token. */
760 yyGLRStackItem yyerror_range
[3];]])[
768 YYJMP_BUF yyexception_buffer
;
769 yyGLRStackItem
* yyitems
;
770 yyGLRStackItem
* yynextFree
;
772 yyGLRState
* yysplitPoint
;
773 yyGLRState
* yylastDeleted
;
774 yyGLRStateSet yytops
;
777 #if YYSTACKEXPANDABLE
778 static void yyexpandGLRStack (yyGLRStack
* yystackp
);
781 static void yyFail (yyGLRStack
* yystackp
]b4_pure_formals
[, const char* yymsg
)
782 __attribute__ ((__noreturn__
));
784 yyFail (yyGLRStack
* yystackp
]b4_pure_formals
[, const char* yymsg
)
786 if (yymsg
!= YY_NULL
)
787 yyerror (]b4_yyerror_args
[yymsg
);
788 YYLONGJMP (yystackp
->yyexception_buffer
, 1);
791 static void yyMemoryExhausted (yyGLRStack
* yystackp
)
792 __attribute__ ((__noreturn__
));
794 yyMemoryExhausted (yyGLRStack
* yystackp
)
796 YYLONGJMP (yystackp
->yyexception_buffer
, 2);
799 #if YYDEBUG || YYERROR_VERBOSE
800 /** A printable representation of TOKEN. */
801 static inline const char*
802 yytokenName (yySymbol yytoken
)
804 if (yytoken
== YYEMPTY
)
807 return yytname
[yytoken
];
811 /** Fill in YYVSP[YYLOW1 .. YYLOW0-1] from the chain of states starting
812 * at YYVSP[YYLOW0].yystate.yypred. Leaves YYVSP[YYLOW1].yystate.yypred
813 * containing the pointer to the next state in the chain. */
814 static void yyfillin (yyGLRStackItem
*, int, int) __attribute__ ((__unused__
));
816 yyfillin (yyGLRStackItem
*yyvsp
, int yylow0
, int yylow1
)
820 s
= yyvsp
[yylow0
].yystate
.yypred
;
821 for (i
= yylow0
-1; i
>= yylow1
; i
-= 1)
824 yyvsp
[i
].yystate
.yylrState
= s
->yylrState
;
826 yyvsp
[i
].yystate
.yyresolved
= s
->yyresolved
;
828 yyvsp
[i
].yystate
.yysemantics
.yysval
= s
->yysemantics
.yysval
;
830 /* The effect of using yysval or yyloc (in an immediate rule) is
832 yyvsp
[i
].yystate
.yysemantics
.yyfirstVal
= YY_NULL
;
833 yyvsp
[i
].yystate
.yyloc
= s
->yyloc
;
834 s
= yyvsp
[i
].yystate
.yypred
= s
->yypred
;
838 /* Do nothing if YYNORMAL or if *YYLOW <= YYLOW1. Otherwise, fill in
839 * YYVSP[YYLOW1 .. *YYLOW-1] as in yyfillin and set *YYLOW = YYLOW1.
840 * For convenience, always return YYLOW1. */
841 static inline int yyfill (yyGLRStackItem
*, int *, int, yybool
)
842 __attribute__ ((__unused__
));
844 yyfill (yyGLRStackItem
*yyvsp
, int *yylow
, int yylow1
, yybool yynormal
)
846 if (!yynormal
&& yylow1
< *yylow
)
848 yyfillin (yyvsp
, *yylow
, yylow1
);
854 /** Perform user action for rule number YYN, with RHS length YYRHSLEN,
855 * and top stack item YYVSP. YYLVALP points to place to put semantic
856 * value ($$), and yylocp points to place for location information
857 * (@@$). Returns yyok for normal return, yyaccept for YYACCEPT,
858 * yyerr for YYERROR, yyabort for YYABORT. */
859 /*ARGSUSED*/ static YYRESULTTAG
860 yyuserAction (yyRuleNum yyn
, int yyrhslen
, yyGLRStackItem
* yyvsp
,
861 yyGLRStack
* yystackp
,
862 YYSTYPE
* yyvalp
]b4_locuser_formals
[)
864 yybool yynormal
__attribute__ ((__unused__
)) =
865 (yystackp
->yysplitPoint
== YY_NULL
);
867 ]b4_parse_param_use([yyvalp
], [yylocp
])dnl
869 # define yyerrok (yystackp->yyerrState = 0)
871 # define YYACCEPT return yyaccept
873 # define YYABORT return yyabort
875 # define YYERROR return yyerrok, yyerr
877 # define YYRECOVERING() (yystackp->yyerrState != 0)
879 # define yyclearin (yychar = YYEMPTY)
881 # define YYFILL(N) yyfill (yyvsp, &yylow, N, yynormal)
883 # define YYBACKUP(Token, Value) \
884 return yyerror (]b4_yyerror_args[YY_("syntax error: cannot back up")), \
889 *yyvalp
= yyval_default
;
891 *yyvalp
= yyvsp
[YYFILL (1-yyrhslen
)].yystate
.yysemantics
.yysval
;]b4_locations_if([[
892 YYLLOC_DEFAULT ((*yylocp
), (yyvsp
- yyrhslen
), yyrhslen
);
893 yystackp
->yyerror_range
[1].yystate
.yyloc
= *yylocp
;
912 /*ARGSUSED*/ static void
913 yyuserMerge (int yyn
, YYSTYPE
* yy0
, YYSTYPE
* yy1
)
925 /* Bison grammar-table manipulation. */
927 ]b4_yydestruct_generate([b4_c_ansi_function_def
])[
929 /** Number of symbols composing the right hand side of rule #RULE. */
931 yyrhsLength (yyRuleNum yyrule
)
937 yydestroyGLRState (char const *yymsg
, yyGLRState
*yys
]b4_user_formals
[)
940 yydestruct (yymsg
, yystos
[yys
->yylrState
],
941 &yys
->yysemantics
.yysval
]b4_locuser_args([&yys
->yyloc
])[);
947 if (yys
->yysemantics
.yyfirstVal
)
948 YYFPRINTF (stderr
, "%s unresolved ", yymsg
);
950 YYFPRINTF (stderr
, "%s incomplete ", yymsg
);
951 yy_symbol_print (stderr
, yystos
[yys
->yylrState
],
952 YY_NULL
]b4_locuser_args([&yys
->yyloc
])[);
953 YYFPRINTF (stderr
, "\n");
957 if (yys
->yysemantics
.yyfirstVal
)
959 yySemanticOption
*yyoption
= yys
->yysemantics
.yyfirstVal
;
962 for (yyrh
= yyoption
->yystate
, yyn
= yyrhsLength (yyoption
->yyrule
);
964 yyrh
= yyrh
->yypred
, yyn
-= 1)
965 yydestroyGLRState (yymsg
, yyrh
]b4_user_args
[);
970 /** Left-hand-side symbol for rule #YYRULE. */
971 static inline yySymbol
972 yylhsNonterm (yyRuleNum yyrule
)
977 #define yypact_value_is_default(yystate) \
978 ]b4_table_value_equals([[pact]], [[yystate]], [b4_pact_ninf])[
980 /** True iff LR state YYSTATE has only a default reduction (regardless
983 yyisDefaultedState (yyStateNum yystate
)
985 return yypact_value_is_default (yypact
[yystate
]);
988 /** The default reduction for YYSTATE, assuming it has one. */
989 static inline yyRuleNum
990 yydefaultAction (yyStateNum yystate
)
992 return yydefact
[yystate
];
995 #define yytable_value_is_error(yytable_value) \
996 ]b4_table_value_equals([[table]], [[yytable_value]], [b4_table_ninf])[
998 /** Set *YYACTION to the action to take in YYSTATE on seeing YYTOKEN.
1000 * R < 0: Reduce on rule -R.
1002 * R > 0: Shift to state R.
1003 * Set *YYCONFLICTS to a pointer into yyconfl to a 0-terminated list
1004 * of conflicting reductions.
1007 yygetLRActions (yyStateNum yystate
, int yytoken
,
1008 int* yyaction
, const short int** yyconflicts
)
1010 int yyindex
= yypact
[yystate
] + yytoken
;
1011 if (yypact_value_is_default (yypact
[yystate
])
1012 || yyindex
< 0 || YYLAST
< yyindex
|| yycheck
[yyindex
] != yytoken
)
1014 *yyaction
= -yydefact
[yystate
];
1015 *yyconflicts
= yyconfl
;
1017 else if (! yytable_value_is_error (yytable
[yyindex
]))
1019 *yyaction
= yytable
[yyindex
];
1020 *yyconflicts
= yyconfl
+ yyconflp
[yyindex
];
1025 *yyconflicts
= yyconfl
+ yyconflp
[yyindex
];
1029 static inline yyStateNum
1030 yyLRgotoState (yyStateNum yystate
, yySymbol yylhs
)
1032 int yyr
= yypgoto
[yylhs
- YYNTOKENS
] + yystate
;
1033 if (0 <= yyr
&& yyr
<= YYLAST
&& yycheck
[yyr
] == yystate
)
1034 return yytable
[yyr
];
1036 return yydefgoto
[yylhs
- YYNTOKENS
];
1039 static inline yybool
1040 yyisShiftAction (int yyaction
)
1042 return 0 < yyaction
;
1045 static inline yybool
1046 yyisErrorAction (int yyaction
)
1048 return yyaction
== 0;
1053 /** Return a fresh GLRStackItem in YYSTACKP. The item is an LR state
1054 * if YYISSTATE, and otherwise a semantic option. Callers should call
1055 * YY_RESERVE_GLRSTACK afterwards to make sure there is sufficient
1058 static inline yyGLRStackItem
*
1059 yynewGLRStackItem (yyGLRStack
* yystackp
, yybool yyisState
)
1061 yyGLRStackItem
* yynewItem
= yystackp
->yynextFree
;
1062 yystackp
->yyspaceLeft
-= 1;
1063 yystackp
->yynextFree
+= 1;
1064 yynewItem
->yystate
.yyisState
= yyisState
;
1068 /** Add a new semantic action that will execute the action for rule
1069 * YYRULE on the semantic values in YYRHS to the list of
1070 * alternative actions for YYSTATE. Assumes that YYRHS comes from
1071 * stack #YYK of *YYSTACKP. */
1073 yyaddDeferredAction (yyGLRStack
* yystackp
, size_t yyk
, yyGLRState
* yystate
,
1074 yyGLRState
* yyrhs
, yyRuleNum yyrule
)
1076 yySemanticOption
* yynewOption
=
1077 &yynewGLRStackItem (yystackp
, yyfalse
)->yyoption
;
1078 yynewOption
->yystate
= yyrhs
;
1079 yynewOption
->yyrule
= yyrule
;
1080 if (yystackp
->yytops
.yylookaheadNeeds
[yyk
])
1082 yynewOption
->yyrawchar
= yychar
;
1083 yynewOption
->yyval
= yylval
;]b4_locations_if([
1084 yynewOption
->yyloc
= yylloc
;])[
1087 yynewOption
->yyrawchar
= YYEMPTY
;
1088 yynewOption
->yynext
= yystate
->yysemantics
.yyfirstVal
;
1089 yystate
->yysemantics
.yyfirstVal
= yynewOption
;
1091 YY_RESERVE_GLRSTACK (yystackp
);
1096 /** Initialize YYSET to a singleton set containing an empty stack. */
1098 yyinitStateSet (yyGLRStateSet
* yyset
)
1101 yyset
->yycapacity
= 16;
1102 yyset
->yystates
= (yyGLRState
**) YYMALLOC (16 * sizeof yyset
->yystates
[0]);
1103 if (! yyset
->yystates
)
1105 yyset
->yystates
[0] = YY_NULL
;
1106 yyset
->yylookaheadNeeds
=
1107 (yybool
*) YYMALLOC (16 * sizeof yyset
->yylookaheadNeeds
[0]);
1108 if (! yyset
->yylookaheadNeeds
)
1110 YYFREE (yyset
->yystates
);
1116 static void yyfreeStateSet (yyGLRStateSet
* yyset
)
1118 YYFREE (yyset
->yystates
);
1119 YYFREE (yyset
->yylookaheadNeeds
);
1122 /** Initialize *YYSTACKP to a single empty stack, with total maximum
1123 * capacity for all stacks of YYSIZE. */
1125 yyinitGLRStack (yyGLRStack
* yystackp
, size_t yysize
)
1127 yystackp
->yyerrState
= 0;
1129 yystackp
->yyspaceLeft
= yysize
;
1131 (yyGLRStackItem
*) YYMALLOC (yysize
* sizeof yystackp
->yynextFree
[0]);
1132 if (!yystackp
->yyitems
)
1134 yystackp
->yynextFree
= yystackp
->yyitems
;
1135 yystackp
->yysplitPoint
= YY_NULL
;
1136 yystackp
->yylastDeleted
= YY_NULL
;
1137 return yyinitStateSet (&yystackp
->yytops
);
1141 #if YYSTACKEXPANDABLE
1142 # define YYRELOC(YYFROMITEMS,YYTOITEMS,YYX,YYTYPE) \
1143 &((YYTOITEMS) - ((YYFROMITEMS) - (yyGLRStackItem*) (YYX)))->YYTYPE
1145 /** If *YYSTACKP is expandable, extend it. WARNING: Pointers into the
1146 stack from outside should be considered invalid after this call.
1147 We always expand when there are 1 or fewer items left AFTER an
1148 allocation, so that we can avoid having external pointers exist
1149 across an allocation. */
1151 yyexpandGLRStack (yyGLRStack
* yystackp
)
1153 yyGLRStackItem
* yynewItems
;
1154 yyGLRStackItem
* yyp0
, *yyp1
;
1155 size_t yysize
, yynewSize
;
1157 yysize
= yystackp
->yynextFree
- yystackp
->yyitems
;
1158 if (YYMAXDEPTH
- YYHEADROOM
< yysize
)
1159 yyMemoryExhausted (yystackp
);
1160 yynewSize
= 2*yysize
;
1161 if (YYMAXDEPTH
< yynewSize
)
1162 yynewSize
= YYMAXDEPTH
;
1163 yynewItems
= (yyGLRStackItem
*) YYMALLOC (yynewSize
* sizeof yynewItems
[0]);
1165 yyMemoryExhausted (yystackp
);
1166 for (yyp0
= yystackp
->yyitems
, yyp1
= yynewItems
, yyn
= yysize
;
1168 yyn
-= 1, yyp0
+= 1, yyp1
+= 1)
1171 if (*(yybool
*) yyp0
)
1173 yyGLRState
* yys0
= &yyp0
->yystate
;
1174 yyGLRState
* yys1
= &yyp1
->yystate
;
1175 if (yys0
->yypred
!= YY_NULL
)
1177 YYRELOC (yyp0
, yyp1
, yys0
->yypred
, yystate
);
1178 if (! yys0
->yyresolved
&& yys0
->yysemantics
.yyfirstVal
!= YY_NULL
)
1179 yys1
->yysemantics
.yyfirstVal
=
1180 YYRELOC(yyp0
, yyp1
, yys0
->yysemantics
.yyfirstVal
, yyoption
);
1184 yySemanticOption
* yyv0
= &yyp0
->yyoption
;
1185 yySemanticOption
* yyv1
= &yyp1
->yyoption
;
1186 if (yyv0
->yystate
!= YY_NULL
)
1187 yyv1
->yystate
= YYRELOC (yyp0
, yyp1
, yyv0
->yystate
, yystate
);
1188 if (yyv0
->yynext
!= YY_NULL
)
1189 yyv1
->yynext
= YYRELOC (yyp0
, yyp1
, yyv0
->yynext
, yyoption
);
1192 if (yystackp
->yysplitPoint
!= YY_NULL
)
1193 yystackp
->yysplitPoint
= YYRELOC (yystackp
->yyitems
, yynewItems
,
1194 yystackp
->yysplitPoint
, yystate
);
1196 for (yyn
= 0; yyn
< yystackp
->yytops
.yysize
; yyn
+= 1)
1197 if (yystackp
->yytops
.yystates
[yyn
] != YY_NULL
)
1198 yystackp
->yytops
.yystates
[yyn
] =
1199 YYRELOC (yystackp
->yyitems
, yynewItems
,
1200 yystackp
->yytops
.yystates
[yyn
], yystate
);
1201 YYFREE (yystackp
->yyitems
);
1202 yystackp
->yyitems
= yynewItems
;
1203 yystackp
->yynextFree
= yynewItems
+ yysize
;
1204 yystackp
->yyspaceLeft
= yynewSize
- yysize
;
1209 yyfreeGLRStack (yyGLRStack
* yystackp
)
1211 YYFREE (yystackp
->yyitems
);
1212 yyfreeStateSet (&yystackp
->yytops
);
1215 /** Assuming that YYS is a GLRState somewhere on *YYSTACKP, update the
1216 * splitpoint of *YYSTACKP, if needed, so that it is at least as deep as
1219 yyupdateSplit (yyGLRStack
* yystackp
, yyGLRState
* yys
)
1221 if (yystackp
->yysplitPoint
!= YY_NULL
&& yystackp
->yysplitPoint
> yys
)
1222 yystackp
->yysplitPoint
= yys
;
1225 /** Invalidate stack #YYK in *YYSTACKP. */
1227 yymarkStackDeleted (yyGLRStack
* yystackp
, size_t yyk
)
1229 if (yystackp
->yytops
.yystates
[yyk
] != YY_NULL
)
1230 yystackp
->yylastDeleted
= yystackp
->yytops
.yystates
[yyk
];
1231 yystackp
->yytops
.yystates
[yyk
] = YY_NULL
;
1234 /** Undelete the last stack in *YYSTACKP that was marked as deleted. Can
1235 only be done once after a deletion, and only when all other stacks have
1238 yyundeleteLastStack (yyGLRStack
* yystackp
)
1240 if (yystackp
->yylastDeleted
== YY_NULL
|| yystackp
->yytops
.yysize
!= 0)
1242 yystackp
->yytops
.yystates
[0] = yystackp
->yylastDeleted
;
1243 yystackp
->yytops
.yysize
= 1;
1244 YYDPRINTF ((stderr
, "Restoring last deleted stack as stack #0.\n"));
1245 yystackp
->yylastDeleted
= YY_NULL
;
1249 yyremoveDeletes (yyGLRStack
* yystackp
)
1253 while (yyj
< yystackp
->yytops
.yysize
)
1255 if (yystackp
->yytops
.yystates
[yyi
] == YY_NULL
)
1259 YYDPRINTF ((stderr
, "Removing dead stacks.\n"));
1261 yystackp
->yytops
.yysize
-= 1;
1265 yystackp
->yytops
.yystates
[yyj
] = yystackp
->yytops
.yystates
[yyi
];
1266 /* In the current implementation, it's unnecessary to copy
1267 yystackp->yytops.yylookaheadNeeds[yyi] since, after
1268 yyremoveDeletes returns, the parser immediately either enters
1269 deterministic operation or shifts a token. However, it doesn't
1270 hurt, and the code might evolve to need it. */
1271 yystackp
->yytops
.yylookaheadNeeds
[yyj
] =
1272 yystackp
->yytops
.yylookaheadNeeds
[yyi
];
1275 YYDPRINTF ((stderr
, "Rename stack %lu -> %lu.\n",
1276 (unsigned long int) yyi
, (unsigned long int) yyj
));
1284 /** Shift to a new state on stack #YYK of *YYSTACKP, corresponding to LR
1285 * state YYLRSTATE, at input position YYPOSN, with (resolved) semantic
1286 * value *YYVALP and source location *YYLOCP. */
1288 yyglrShift (yyGLRStack
* yystackp
, size_t yyk
, yyStateNum yylrState
,
1290 YYSTYPE
* yyvalp
]b4_locations_if([, YYLTYPE
* yylocp
])[)
1292 yyGLRState
* yynewState
= &yynewGLRStackItem (yystackp
, yytrue
)->yystate
;
1294 yynewState
->yylrState
= yylrState
;
1295 yynewState
->yyposn
= yyposn
;
1296 yynewState
->yyresolved
= yytrue
;
1297 yynewState
->yypred
= yystackp
->yytops
.yystates
[yyk
];
1298 yynewState
->yysemantics
.yysval
= *yyvalp
;]b4_locations_if([
1299 yynewState
->yyloc
= *yylocp
;])[
1300 yystackp
->yytops
.yystates
[yyk
] = yynewState
;
1302 YY_RESERVE_GLRSTACK (yystackp
);
1305 /** Shift stack #YYK of *YYSTACKP, to a new state corresponding to LR
1306 * state YYLRSTATE, at input position YYPOSN, with the (unresolved)
1307 * semantic value of YYRHS under the action for YYRULE. */
1309 yyglrShiftDefer (yyGLRStack
* yystackp
, size_t yyk
, yyStateNum yylrState
,
1310 size_t yyposn
, yyGLRState
* yyrhs
, yyRuleNum yyrule
)
1312 yyGLRState
* yynewState
= &yynewGLRStackItem (yystackp
, yytrue
)->yystate
;
1314 yynewState
->yylrState
= yylrState
;
1315 yynewState
->yyposn
= yyposn
;
1316 yynewState
->yyresolved
= yyfalse
;
1317 yynewState
->yypred
= yystackp
->yytops
.yystates
[yyk
];
1318 yynewState
->yysemantics
.yyfirstVal
= YY_NULL
;
1319 yystackp
->yytops
.yystates
[yyk
] = yynewState
;
1321 /* Invokes YY_RESERVE_GLRSTACK. */
1322 yyaddDeferredAction (yystackp
, yyk
, yynewState
, yyrhs
, yyrule
);
1326 # define YY_REDUCE_PRINT(Args)
1328 # define YY_REDUCE_PRINT(Args) \
1331 yy_reduce_print Args; \
1334 /*----------------------------------------------------------------------.
1335 | Report that stack #YYK of *YYSTACKP is going to be reduced by YYRULE. |
1336 `----------------------------------------------------------------------*/
1338 /*ARGSUSED*/ static inline void
1339 yy_reduce_print (int yynormal
, yyGLRStackItem
* yyvsp
, size_t yyk
,
1340 yyRuleNum yyrule
]b4_user_formals
[)
1342 int yynrhs
= yyrhsLength (yyrule
);]b4_locations_if([
1345 YYFPRINTF (stderr
, "Reducing stack %lu by rule %d (line %lu):\n",
1346 (unsigned long int) yyk
, yyrule
- 1,
1347 (unsigned long int) yyrline
[yyrule
]);
1349 yyfillin (yyvsp
, 1, -yynrhs
);
1350 /* The symbols being reduced. */
1351 for (yyi
= 0; yyi
< yynrhs
; yyi
++)
1353 YYFPRINTF (stderr
, " $%d = ", yyi
+ 1);
1354 yy_symbol_print (stderr
,
1355 yystos
[yyvsp
[yyi
- yynrhs
+ 1].yystate
.yylrState
],
1356 &yyvsp
[yyi
- yynrhs
+ 1].yystate
.yysemantics
.yysval
1357 ]b4_locations_if([, &]b4_rhs_location(yynrhs
, yyi
+ 1))[]dnl
1359 if (!yyvsp
[yyi
- yynrhs
+ 1].yystate
.yyresolved
)
1360 YYFPRINTF (stderr
, " (unresolved)");
1361 YYFPRINTF (stderr
, "\n");
1366 /** Pop the symbols consumed by reduction #YYRULE from the top of stack
1367 * #YYK of *YYSTACKP, and perform the appropriate semantic action on their
1368 * semantic values. Assumes that all ambiguities in semantic values
1369 * have been previously resolved. Set *YYVALP to the resulting value,
1370 * and *YYLOCP to the computed location (if any). Return value is as
1371 * for userAction. */
1372 static inline YYRESULTTAG
1373 yydoAction (yyGLRStack
* yystackp
, size_t yyk
, yyRuleNum yyrule
,
1374 YYSTYPE
* yyvalp
]b4_locuser_formals
[)
1376 int yynrhs
= yyrhsLength (yyrule
);
1378 if (yystackp
->yysplitPoint
== YY_NULL
)
1380 /* Standard special case: single stack. */
1381 yyGLRStackItem
* yyrhs
= (yyGLRStackItem
*) yystackp
->yytops
.yystates
[yyk
];
1382 YYASSERT (yyk
== 0);
1383 yystackp
->yynextFree
-= yynrhs
;
1384 yystackp
->yyspaceLeft
+= yynrhs
;
1385 yystackp
->yytops
.yystates
[0] = & yystackp
->yynextFree
[-1].yystate
;
1386 YY_REDUCE_PRINT ((1, yyrhs
, yyk
, yyrule
]b4_user_args
[));
1387 return yyuserAction (yyrule
, yynrhs
, yyrhs
, yystackp
,
1388 yyvalp
]b4_locuser_args
[);
1394 yyGLRStackItem yyrhsVals
[YYMAXRHS
+ YYMAXLEFT
+ 1];
1395 yys
= yyrhsVals
[YYMAXRHS
+ YYMAXLEFT
].yystate
.yypred
1396 = yystackp
->yytops
.yystates
[yyk
];]b4_locations_if([[
1398 /* Set default location. */
1399 yyrhsVals
[YYMAXRHS
+ YYMAXLEFT
- 1].yystate
.yyloc
= yys
->yyloc
;]])[
1400 for (yyi
= 0; yyi
< yynrhs
; yyi
+= 1)
1405 yyupdateSplit (yystackp
, yys
);
1406 yystackp
->yytops
.yystates
[yyk
] = yys
;
1407 YY_REDUCE_PRINT ((0, yyrhsVals
+ YYMAXRHS
+ YYMAXLEFT
- 1, yyk
, yyrule
]b4_user_args
[));
1408 return yyuserAction (yyrule
, yynrhs
, yyrhsVals
+ YYMAXRHS
+ YYMAXLEFT
- 1,
1409 yystackp
, yyvalp
]b4_locuser_args
[);
1413 /** Pop items off stack #YYK of *YYSTACKP according to grammar rule YYRULE,
1414 * and push back on the resulting nonterminal symbol. Perform the
1415 * semantic action associated with YYRULE and store its value with the
1416 * newly pushed state, if YYFORCEEVAL or if *YYSTACKP is currently
1417 * unambiguous. Otherwise, store the deferred semantic action with
1418 * the new state. If the new state would have an identical input
1419 * position, LR state, and predecessor to an existing state on the stack,
1420 * it is identified with that existing state, eliminating stack #YYK from
1421 * *YYSTACKP. In this case, the semantic value is
1422 * added to the options for the existing state's semantic value.
1424 static inline YYRESULTTAG
1425 yyglrReduce (yyGLRStack
* yystackp
, size_t yyk
, yyRuleNum yyrule
,
1426 yybool yyforceEval
]b4_user_formals
[)
1428 size_t yyposn
= yystackp
->yytops
.yystates
[yyk
]->yyposn
;
1430 if (yyforceEval
|| yystackp
->yysplitPoint
== YY_NULL
)
1433 YYSTYPE yysval
;]b4_locations_if([
1436 yyflag
= yydoAction (yystackp
, yyk
, yyrule
, &yysval
]b4_locuser_args([&yyloc
])[);
1437 if (yyflag
== yyerr
&& yystackp
->yysplitPoint
!= YY_NULL
)
1439 YYDPRINTF ((stderr
, "Parse on stack %lu rejected by rule #%d.\n",
1440 (unsigned long int) yyk
, yyrule
- 1));
1444 YY_SYMBOL_PRINT ("-> $$ =", yyr1
[yyrule
], &yysval
, &yyloc
);
1445 yyglrShift (yystackp
, yyk
,
1446 yyLRgotoState (yystackp
->yytops
.yystates
[yyk
]->yylrState
,
1447 yylhsNonterm (yyrule
)),
1448 yyposn
, &yysval
]b4_locations_if([, &yyloc
])[);
1454 yyGLRState
* yys
, *yys0
= yystackp
->yytops
.yystates
[yyk
];
1455 yyStateNum yynewLRState
;
1457 for (yys
= yystackp
->yytops
.yystates
[yyk
], yyn
= yyrhsLength (yyrule
);
1463 yyupdateSplit (yystackp
, yys
);
1464 yynewLRState
= yyLRgotoState (yys
->yylrState
, yylhsNonterm (yyrule
));
1466 "Reduced stack %lu by rule #%d; action deferred. "
1467 "Now in state %d.\n",
1468 (unsigned long int) yyk
, yyrule
- 1, yynewLRState
));
1469 for (yyi
= 0; yyi
< yystackp
->yytops
.yysize
; yyi
+= 1)
1470 if (yyi
!= yyk
&& yystackp
->yytops
.yystates
[yyi
] != YY_NULL
)
1472 yyGLRState
* yyp
, *yysplit
= yystackp
->yysplitPoint
;
1473 yyp
= yystackp
->yytops
.yystates
[yyi
];
1474 while (yyp
!= yys
&& yyp
!= yysplit
&& yyp
->yyposn
>= yyposn
)
1476 if (yyp
->yylrState
== yynewLRState
&& yyp
->yypred
== yys
)
1478 yyaddDeferredAction (yystackp
, yyk
, yyp
, yys0
, yyrule
);
1479 yymarkStackDeleted (yystackp
, yyk
);
1480 YYDPRINTF ((stderr
, "Merging stack %lu into stack %lu.\n",
1481 (unsigned long int) yyk
,
1482 (unsigned long int) yyi
));
1488 yystackp
->yytops
.yystates
[yyk
] = yys
;
1489 yyglrShiftDefer (yystackp
, yyk
, yynewLRState
, yyposn
, yys0
, yyrule
);
1495 yysplitStack (yyGLRStack
* yystackp
, size_t yyk
)
1497 if (yystackp
->yysplitPoint
== YY_NULL
)
1499 YYASSERT (yyk
== 0);
1500 yystackp
->yysplitPoint
= yystackp
->yytops
.yystates
[yyk
];
1502 if (yystackp
->yytops
.yysize
>= yystackp
->yytops
.yycapacity
)
1504 yyGLRState
** yynewStates
;
1505 yybool
* yynewLookaheadNeeds
;
1507 yynewStates
= YY_NULL
;
1509 if (yystackp
->yytops
.yycapacity
1510 > (YYSIZEMAX
/ (2 * sizeof yynewStates
[0])))
1511 yyMemoryExhausted (yystackp
);
1512 yystackp
->yytops
.yycapacity
*= 2;
1515 (yyGLRState
**) YYREALLOC (yystackp
->yytops
.yystates
,
1516 (yystackp
->yytops
.yycapacity
1517 * sizeof yynewStates
[0]));
1518 if (yynewStates
== YY_NULL
)
1519 yyMemoryExhausted (yystackp
);
1520 yystackp
->yytops
.yystates
= yynewStates
;
1522 yynewLookaheadNeeds
=
1523 (yybool
*) YYREALLOC (yystackp
->yytops
.yylookaheadNeeds
,
1524 (yystackp
->yytops
.yycapacity
1525 * sizeof yynewLookaheadNeeds
[0]));
1526 if (yynewLookaheadNeeds
== YY_NULL
)
1527 yyMemoryExhausted (yystackp
);
1528 yystackp
->yytops
.yylookaheadNeeds
= yynewLookaheadNeeds
;
1530 yystackp
->yytops
.yystates
[yystackp
->yytops
.yysize
]
1531 = yystackp
->yytops
.yystates
[yyk
];
1532 yystackp
->yytops
.yylookaheadNeeds
[yystackp
->yytops
.yysize
]
1533 = yystackp
->yytops
.yylookaheadNeeds
[yyk
];
1534 yystackp
->yytops
.yysize
+= 1;
1535 return yystackp
->yytops
.yysize
-1;
1538 /** True iff YYY0 and YYY1 represent identical options at the top level.
1539 * That is, they represent the same rule applied to RHS symbols
1540 * that produce the same terminal symbols. */
1542 yyidenticalOptions (yySemanticOption
* yyy0
, yySemanticOption
* yyy1
)
1544 if (yyy0
->yyrule
== yyy1
->yyrule
)
1546 yyGLRState
*yys0
, *yys1
;
1548 for (yys0
= yyy0
->yystate
, yys1
= yyy1
->yystate
,
1549 yyn
= yyrhsLength (yyy0
->yyrule
);
1551 yys0
= yys0
->yypred
, yys1
= yys1
->yypred
, yyn
-= 1)
1552 if (yys0
->yyposn
!= yys1
->yyposn
)
1560 /** Assuming identicalOptions (YYY0,YYY1), destructively merge the
1561 * alternative semantic values for the RHS-symbols of YYY1 and YYY0. */
1563 yymergeOptionSets (yySemanticOption
* yyy0
, yySemanticOption
* yyy1
)
1565 yyGLRState
*yys0
, *yys1
;
1567 for (yys0
= yyy0
->yystate
, yys1
= yyy1
->yystate
,
1568 yyn
= yyrhsLength (yyy0
->yyrule
);
1570 yys0
= yys0
->yypred
, yys1
= yys1
->yypred
, yyn
-= 1)
1574 else if (yys0
->yyresolved
)
1576 yys1
->yyresolved
= yytrue
;
1577 yys1
->yysemantics
.yysval
= yys0
->yysemantics
.yysval
;
1579 else if (yys1
->yyresolved
)
1581 yys0
->yyresolved
= yytrue
;
1582 yys0
->yysemantics
.yysval
= yys1
->yysemantics
.yysval
;
1586 yySemanticOption
** yyz0p
;
1587 yySemanticOption
* yyz1
;
1588 yyz0p
= &yys0
->yysemantics
.yyfirstVal
;
1589 yyz1
= yys1
->yysemantics
.yyfirstVal
;
1590 while (YYID (yytrue
))
1592 if (yyz1
== *yyz0p
|| yyz1
== YY_NULL
)
1594 else if (*yyz0p
== YY_NULL
)
1599 else if (*yyz0p
< yyz1
)
1601 yySemanticOption
* yyz
= *yyz0p
;
1603 yyz1
= yyz1
->yynext
;
1604 (*yyz0p
)->yynext
= yyz
;
1606 yyz0p
= &(*yyz0p
)->yynext
;
1608 yys1
->yysemantics
.yyfirstVal
= yys0
->yysemantics
.yyfirstVal
;
1613 /** Y0 and Y1 represent two possible actions to take in a given
1614 * parsing state; return 0 if no combination is possible,
1615 * 1 if user-mergeable, 2 if Y0 is preferred, 3 if Y1 is preferred. */
1617 yypreference (yySemanticOption
* y0
, yySemanticOption
* y1
)
1619 yyRuleNum r0
= y0
->yyrule
, r1
= y1
->yyrule
;
1620 int p0
= yydprec
[r0
], p1
= yydprec
[r1
];
1624 if (yymerger
[r0
] == 0 || yymerger
[r0
] != yymerger
[r1
])
1629 if (p0
== 0 || p1
== 0)
1638 static YYRESULTTAG
yyresolveValue (yyGLRState
* yys
,
1639 yyGLRStack
* yystackp
]b4_user_formals
[);
1642 /** Resolve the previous YYN states starting at and including state YYS
1643 * on *YYSTACKP. If result != yyok, some states may have been left
1644 * unresolved possibly with empty semantic option chains. Regardless
1645 * of whether result = yyok, each state has been left with consistent
1646 * data so that yydestroyGLRState can be invoked if necessary. */
1648 yyresolveStates (yyGLRState
* yys
, int yyn
,
1649 yyGLRStack
* yystackp
]b4_user_formals
[)
1653 YYASSERT (yys
->yypred
);
1654 YYCHK (yyresolveStates (yys
->yypred
, yyn
-1, yystackp
]b4_user_args
[));
1655 if (! yys
->yyresolved
)
1656 YYCHK (yyresolveValue (yys
, yystackp
]b4_user_args
[));
1661 /** Resolve the states for the RHS of YYOPT on *YYSTACKP, perform its
1662 * user action, and return the semantic value and location in *YYVALP
1663 * and *YYLOCP. Regardless of whether result = yyok, all RHS states
1664 * have been destroyed (assuming the user action destroys all RHS
1665 * semantic values if invoked). */
1667 yyresolveAction (yySemanticOption
* yyopt
, yyGLRStack
* yystackp
,
1668 YYSTYPE
* yyvalp
]b4_locuser_formals
[)
1670 yyGLRStackItem yyrhsVals
[YYMAXRHS
+ YYMAXLEFT
+ 1];
1673 YYSTYPE yylval_current
;]b4_locations_if([
1674 YYLTYPE yylloc_current
;])[
1677 yynrhs
= yyrhsLength (yyopt
->yyrule
);
1678 yyflag
= yyresolveStates (yyopt
->yystate
, yynrhs
, yystackp
]b4_user_args
[);
1682 for (yys
= yyopt
->yystate
; yynrhs
> 0; yys
= yys
->yypred
, yynrhs
-= 1)
1683 yydestroyGLRState ("Cleanup: popping", yys
]b4_user_args
[);
1687 yyrhsVals
[YYMAXRHS
+ YYMAXLEFT
].yystate
.yypred
= yyopt
->yystate
;]b4_locations_if([[
1689 /* Set default location. */
1690 yyrhsVals
[YYMAXRHS
+ YYMAXLEFT
- 1].yystate
.yyloc
= yyopt
->yystate
->yyloc
;]])[
1691 yychar_current
= yychar
;
1692 yylval_current
= yylval
;]b4_locations_if([
1693 yylloc_current
= yylloc
;])[
1694 yychar
= yyopt
->yyrawchar
;
1695 yylval
= yyopt
->yyval
;]b4_locations_if([
1696 yylloc
= yyopt
->yyloc
;])[
1697 yyflag
= yyuserAction (yyopt
->yyrule
, yynrhs
,
1698 yyrhsVals
+ YYMAXRHS
+ YYMAXLEFT
- 1,
1699 yystackp
, yyvalp
]b4_locuser_args
[);
1700 yychar
= yychar_current
;
1701 yylval
= yylval_current
;]b4_locations_if([
1702 yylloc
= yylloc_current
;])[
1708 yyreportTree (yySemanticOption
* yyx
, int yyindent
)
1710 int yynrhs
= yyrhsLength (yyx
->yyrule
);
1713 yyGLRState
* yystates
[1 + YYMAXRHS
];
1714 yyGLRState yyleftmost_state
;
1716 for (yyi
= yynrhs
, yys
= yyx
->yystate
; 0 < yyi
; yyi
-= 1, yys
= yys
->yypred
)
1717 yystates
[yyi
] = yys
;
1720 yyleftmost_state
.yyposn
= 0;
1721 yystates
[0] = &yyleftmost_state
;
1726 if (yyx
->yystate
->yyposn
< yys
->yyposn
+ 1)
1727 YYFPRINTF (stderr
, "%*s%s -> <Rule %d, empty>\n",
1728 yyindent
, "", yytokenName (yylhsNonterm (yyx
->yyrule
)),
1731 YYFPRINTF (stderr
, "%*s%s -> <Rule %d, tokens %lu .. %lu>\n",
1732 yyindent
, "", yytokenName (yylhsNonterm (yyx
->yyrule
)),
1733 yyx
->yyrule
- 1, (unsigned long int) (yys
->yyposn
+ 1),
1734 (unsigned long int) yyx
->yystate
->yyposn
);
1735 for (yyi
= 1; yyi
<= yynrhs
; yyi
+= 1)
1737 if (yystates
[yyi
]->yyresolved
)
1739 if (yystates
[yyi
-1]->yyposn
+1 > yystates
[yyi
]->yyposn
)
1740 YYFPRINTF (stderr
, "%*s%s <empty>\n", yyindent
+2, "",
1741 yytokenName (yystos
[yystates
[yyi
]->yylrState
]));
1743 YYFPRINTF (stderr
, "%*s%s <tokens %lu .. %lu>\n", yyindent
+2, "",
1744 yytokenName (yystos
[yystates
[yyi
]->yylrState
]),
1745 (unsigned long int) (yystates
[yyi
-1]->yyposn
+ 1),
1746 (unsigned long int) yystates
[yyi
]->yyposn
);
1749 yyreportTree (yystates
[yyi
]->yysemantics
.yyfirstVal
, yyindent
+2);
1754 /*ARGSUSED*/ static YYRESULTTAG
1755 yyreportAmbiguity (yySemanticOption
* yyx0
,
1756 yySemanticOption
* yyx1
]b4_pure_formals
[)
1762 YYFPRINTF (stderr
, "Ambiguity detected.\n");
1763 YYFPRINTF (stderr
, "Option 1,\n");
1764 yyreportTree (yyx0
, 2);
1765 YYFPRINTF (stderr
, "\nOption 2,\n");
1766 yyreportTree (yyx1
, 2);
1767 YYFPRINTF (stderr
, "\n");
1770 yyerror (]b4_yyerror_args
[YY_("syntax is ambiguous"));
1772 }]b4_locations_if([[
1774 /** Resolve the locations for each of the YYN1 states in *YYSTACKP,
1775 * ending at YYS1. Has no effect on previously resolved states.
1776 * The first semantic option of a state is always chosen. */
1778 yyresolveLocations (yyGLRState
* yys1
, int yyn1
,
1779 yyGLRStack
*yystackp
]b4_user_formals
[)
1783 yyresolveLocations (yys1
->yypred
, yyn1
- 1, yystackp
]b4_user_args
[);
1784 if (!yys1
->yyresolved
)
1786 yySemanticOption
*yyoption
;
1787 yyGLRStackItem yyrhsloc
[1 + YYMAXRHS
];
1790 YYSTYPE yylval_current
;
1791 YYLTYPE yylloc_current
;
1792 yyoption
= yys1
->yysemantics
.yyfirstVal
;
1793 YYASSERT (yyoption
!= YY_NULL
);
1794 yynrhs
= yyrhsLength (yyoption
->yyrule
);
1799 yyresolveLocations (yyoption
->yystate
, yynrhs
,
1800 yystackp
]b4_user_args
[);
1801 for (yys
= yyoption
->yystate
, yyn
= yynrhs
;
1803 yys
= yys
->yypred
, yyn
-= 1)
1804 yyrhsloc
[yyn
].yystate
.yyloc
= yys
->yyloc
;
1808 /* Both yyresolveAction and yyresolveLocations traverse the GSS
1809 in reverse rightmost order. It is only necessary to invoke
1810 yyresolveLocations on a subforest for which yyresolveAction
1811 would have been invoked next had an ambiguity not been
1812 detected. Thus the location of the previous state (but not
1813 necessarily the previous state itself) is guaranteed to be
1814 resolved already. */
1815 yyGLRState
*yyprevious
= yyoption
->yystate
;
1816 yyrhsloc
[0].yystate
.yyloc
= yyprevious
->yyloc
;
1818 yychar_current
= yychar
;
1819 yylval_current
= yylval
;
1820 yylloc_current
= yylloc
;
1821 yychar
= yyoption
->yyrawchar
;
1822 yylval
= yyoption
->yyval
;
1823 yylloc
= yyoption
->yyloc
;
1824 YYLLOC_DEFAULT ((yys1
->yyloc
), yyrhsloc
, yynrhs
);
1825 yychar
= yychar_current
;
1826 yylval
= yylval_current
;
1827 yylloc
= yylloc_current
;
1832 /** Resolve the ambiguity represented in state YYS in *YYSTACKP,
1833 * perform the indicated actions, and set the semantic value of YYS.
1834 * If result != yyok, the chain of semantic options in YYS has been
1835 * cleared instead or it has been left unmodified except that
1836 * redundant options may have been removed. Regardless of whether
1837 * result = yyok, YYS has been left with consistent data so that
1838 * yydestroyGLRState can be invoked if necessary. */
1840 yyresolveValue (yyGLRState
* yys
, yyGLRStack
* yystackp
]b4_user_formals
[)
1842 yySemanticOption
* yyoptionList
= yys
->yysemantics
.yyfirstVal
;
1843 yySemanticOption
* yybest
= yyoptionList
;
1844 yySemanticOption
** yypp
;
1845 yybool yymerge
= yyfalse
;
1847 YYRESULTTAG yyflag
;]b4_locations_if([
1848 YYLTYPE
*yylocp
= &yys
->yyloc
;])[
1850 for (yypp
= &yyoptionList
->yynext
; *yypp
!= YY_NULL
; )
1852 yySemanticOption
* yyp
= *yypp
;
1854 if (yyidenticalOptions (yybest
, yyp
))
1856 yymergeOptionSets (yybest
, yyp
);
1857 *yypp
= yyp
->yynext
;
1861 switch (yypreference (yybest
, yyp
))
1863 case 0:]b4_locations_if([[
1864 yyresolveLocations (yys
, 1, yystackp
]b4_user_args
[);]])[
1865 return yyreportAmbiguity (yybest
, yyp
]b4_pure_args
[);
1877 /* This cannot happen so it is not worth a YYASSERT (yyfalse),
1878 but some compilers complain if the default case is
1882 yypp
= &yyp
->yynext
;
1888 yySemanticOption
* yyp
;
1889 int yyprec
= yydprec
[yybest
->yyrule
];
1890 yyflag
= yyresolveAction (yybest
, yystackp
, &yysval
]b4_locuser_args
[);
1892 for (yyp
= yybest
->yynext
; yyp
!= YY_NULL
; yyp
= yyp
->yynext
)
1894 if (yyprec
== yydprec
[yyp
->yyrule
])
1896 YYSTYPE yysval_other
;]b4_locations_if([
1898 yyflag
= yyresolveAction (yyp
, yystackp
, &yysval_other
]b4_locuser_args([&yydummy
])[);
1901 yydestruct ("Cleanup: discarding incompletely merged value for",
1902 yystos
[yys
->yylrState
],
1903 &yysval
]b4_locuser_args
[);
1906 yyuserMerge (yymerger
[yyp
->yyrule
], &yysval
, &yysval_other
);
1911 yyflag
= yyresolveAction (yybest
, yystackp
, &yysval
]b4_locuser_args([yylocp
])[);
1915 yys
->yyresolved
= yytrue
;
1916 yys
->yysemantics
.yysval
= yysval
;
1919 yys
->yysemantics
.yyfirstVal
= YY_NULL
;
1924 yyresolveStack (yyGLRStack
* yystackp
]b4_user_formals
[)
1926 if (yystackp
->yysplitPoint
!= YY_NULL
)
1931 for (yyn
= 0, yys
= yystackp
->yytops
.yystates
[0];
1932 yys
!= yystackp
->yysplitPoint
;
1933 yys
= yys
->yypred
, yyn
+= 1)
1935 YYCHK (yyresolveStates (yystackp
->yytops
.yystates
[0], yyn
, yystackp
1942 yycompressStack (yyGLRStack
* yystackp
)
1944 yyGLRState
* yyp
, *yyq
, *yyr
;
1946 if (yystackp
->yytops
.yysize
!= 1 || yystackp
->yysplitPoint
== YY_NULL
)
1949 for (yyp
= yystackp
->yytops
.yystates
[0], yyq
= yyp
->yypred
, yyr
= YY_NULL
;
1950 yyp
!= yystackp
->yysplitPoint
;
1951 yyr
= yyp
, yyp
= yyq
, yyq
= yyp
->yypred
)
1954 yystackp
->yyspaceLeft
+= yystackp
->yynextFree
- yystackp
->yyitems
;
1955 yystackp
->yynextFree
= ((yyGLRStackItem
*) yystackp
->yysplitPoint
) + 1;
1956 yystackp
->yyspaceLeft
-= yystackp
->yynextFree
- yystackp
->yyitems
;
1957 yystackp
->yysplitPoint
= YY_NULL
;
1958 yystackp
->yylastDeleted
= YY_NULL
;
1960 while (yyr
!= YY_NULL
)
1962 yystackp
->yynextFree
->yystate
= *yyr
;
1964 yystackp
->yynextFree
->yystate
.yypred
= &yystackp
->yynextFree
[-1].yystate
;
1965 yystackp
->yytops
.yystates
[0] = &yystackp
->yynextFree
->yystate
;
1966 yystackp
->yynextFree
+= 1;
1967 yystackp
->yyspaceLeft
-= 1;
1972 yyprocessOneStack (yyGLRStack
* yystackp
, size_t yyk
,
1973 size_t yyposn
]b4_pure_formals
[)
1975 while (yystackp
->yytops
.yystates
[yyk
] != YY_NULL
)
1977 yyStateNum yystate
= yystackp
->yytops
.yystates
[yyk
]->yylrState
;
1978 YYDPRINTF ((stderr
, "Stack %lu Entering state %d\n",
1979 (unsigned long int) yyk
, yystate
));
1981 YYASSERT (yystate
!= YYFINAL
);
1983 if (yyisDefaultedState (yystate
))
1986 yyRuleNum yyrule
= yydefaultAction (yystate
);
1989 YYDPRINTF ((stderr
, "Stack %lu dies.\n",
1990 (unsigned long int) yyk
));
1991 yymarkStackDeleted (yystackp
, yyk
);
1994 yyflag
= yyglrReduce (yystackp
, yyk
, yyrule
, yyimmediate
[yyrule
]]b4_user_args
[);
1995 if (yyflag
== yyerr
)
1999 "(predicate failure or explicit user error).\n",
2000 (unsigned long int) yyk
));
2001 yymarkStackDeleted (yystackp
, yyk
);
2011 const short int* yyconflicts
;
2013 yystackp
->yytops
.yylookaheadNeeds
[yyk
] = yytrue
;
2014 if (yychar
== YYEMPTY
)
2016 YYDPRINTF ((stderr
, "Reading a token: "));
2020 if (yychar
<= YYEOF
)
2022 yychar
= yytoken
= YYEOF
;
2023 YYDPRINTF ((stderr
, "Now at end of input.\n"));
2027 yytoken
= YYTRANSLATE (yychar
);
2028 YY_SYMBOL_PRINT ("Next token is", yytoken
, &yylval
, &yylloc
);
2031 yygetLRActions (yystate
, yytoken
, &yyaction
, &yyconflicts
);
2033 while (*yyconflicts
!= 0)
2036 size_t yynewStack
= yysplitStack (yystackp
, yyk
);
2037 YYDPRINTF ((stderr
, "Splitting off stack %lu from %lu.\n",
2038 (unsigned long int) yynewStack
,
2039 (unsigned long int) yyk
));
2040 yyflag
= yyglrReduce (yystackp
, yynewStack
,
2042 yyimmediate
[*yyconflicts
]]b4_user_args
[);
2044 YYCHK (yyprocessOneStack (yystackp
, yynewStack
,
2045 yyposn
]b4_pure_args
[));
2046 else if (yyflag
== yyerr
)
2048 YYDPRINTF ((stderr
, "Stack %lu dies.\n",
2049 (unsigned long int) yynewStack
));
2050 yymarkStackDeleted (yystackp
, yynewStack
);
2057 if (yyisShiftAction (yyaction
))
2059 else if (yyisErrorAction (yyaction
))
2061 YYDPRINTF ((stderr
, "Stack %lu dies.\n",
2062 (unsigned long int) yyk
));
2063 yymarkStackDeleted (yystackp
, yyk
);
2068 YYRESULTTAG yyflag
= yyglrReduce (yystackp
, yyk
, -yyaction
,
2069 yyimmediate
[-yyaction
]]b4_user_args
[);
2070 if (yyflag
== yyerr
)
2074 "(predicate failure or explicit user error).\n",
2075 (unsigned long int) yyk
));
2076 yymarkStackDeleted (yystackp
, yyk
);
2079 else if (yyflag
!= yyok
)
2087 /*ARGSUSED*/ static void
2088 yyreportSyntaxError (yyGLRStack
* yystackp
]b4_user_formals
[)
2090 if (yystackp
->yyerrState
!= 0)
2092 #if ! YYERROR_VERBOSE
2093 yyerror (]b4_lyyerror_args
[YY_("syntax error"));
2095 yySymbol yytoken
= yychar
== YYEMPTY
? YYEMPTY
: YYTRANSLATE (yychar
);
2096 size_t yysize0
= yytnamerr (YY_NULL
, yytokenName (yytoken
));
2097 size_t yysize
= yysize0
;
2099 yybool yysize_overflow
= yyfalse
;
2100 char* yymsg
= YY_NULL
;
2101 enum { YYERROR_VERBOSE_ARGS_MAXIMUM
= 5 };
2102 /* Internationalized format string. */
2103 const char *yyformat
= YY_NULL
;
2104 /* Arguments of yyformat. */
2105 char const *yyarg
[YYERROR_VERBOSE_ARGS_MAXIMUM
];
2106 /* Number of reported tokens (one for the "unexpected", one per
2110 /* There are many possibilities here to consider:
2111 - If this state is a consistent state with a default action, then
2112 the only way this function was invoked is if the default action
2113 is an error action. In that case, don't check for expected
2114 tokens because there are none.
2115 - The only way there can be no lookahead present (in yychar) is if
2116 this state is a consistent state with a default action. Thus,
2117 detecting the absence of a lookahead is sufficient to determine
2118 that there is no unexpected or expected token to report. In that
2119 case, just report a simple "syntax error".
2120 - Don't assume there isn't a lookahead just because this state is a
2121 consistent state with a default action. There might have been a
2122 previous inconsistent state, consistent state with a non-default
2123 action, or user semantic action that manipulated yychar.
2124 - Of course, the expected token list depends on states to have
2125 correct lookahead information, and it depends on the parser not
2126 to perform extra reductions after fetching a lookahead from the
2127 scanner and before detecting a syntax error. Thus, state merging
2128 (from LALR or IELR) and default reductions corrupt the expected
2129 token list. However, the list is correct for canonical LR with
2130 one exception: it will still contain any token that will not be
2131 accepted due to an error action in a later state.
2133 if (yytoken
!= YYEMPTY
)
2135 int yyn
= yypact
[yystackp
->yytops
.yystates
[0]->yylrState
];
2136 yyarg
[yycount
++] = yytokenName (yytoken
);
2137 if (!yypact_value_is_default (yyn
))
2139 /* Start YYX at -YYN if negative to avoid negative indexes in
2140 YYCHECK. In other words, skip the first -YYN actions for this
2141 state because they are default actions. */
2142 int yyxbegin
= yyn
< 0 ? -yyn
: 0;
2143 /* Stay within bounds of both yycheck and yytname. */
2144 int yychecklim
= YYLAST
- yyn
+ 1;
2145 int yyxend
= yychecklim
< YYNTOKENS
? yychecklim
: YYNTOKENS
;
2147 for (yyx
= yyxbegin
; yyx
< yyxend
; ++yyx
)
2148 if (yycheck
[yyx
+ yyn
] == yyx
&& yyx
!= YYTERROR
2149 && !yytable_value_is_error (yytable
[yyx
+ yyn
]))
2151 if (yycount
== YYERROR_VERBOSE_ARGS_MAXIMUM
)
2157 yyarg
[yycount
++] = yytokenName (yyx
);
2158 yysize1
= yysize
+ yytnamerr (YY_NULL
, yytokenName (yyx
));
2159 yysize_overflow
|= yysize1
< yysize
;
2167 #define YYCASE_(N, S) \
2171 YYCASE_(0, YY_("syntax error"));
2172 YYCASE_(1, YY_("syntax error, unexpected %s"));
2173 YYCASE_(2, YY_("syntax error, unexpected %s, expecting %s"));
2174 YYCASE_(3, YY_("syntax error, unexpected %s, expecting %s or %s"));
2175 YYCASE_(4, YY_("syntax error, unexpected %s, expecting %s or %s or %s"));
2176 YYCASE_(5, YY_("syntax error, unexpected %s, expecting %s or %s or %s or %s"));
2180 yysize1
= yysize
+ strlen (yyformat
);
2181 yysize_overflow
|= yysize1
< yysize
;
2184 if (!yysize_overflow
)
2185 yymsg
= (char *) YYMALLOC (yysize
);
2191 while ((*yyp
= *yyformat
))
2193 if (*yyp
== '%' && yyformat
[1] == 's' && yyi
< yycount
)
2195 yyp
+= yytnamerr (yyp
, yyarg
[yyi
++]);
2204 yyerror (]b4_lyyerror_args
[yymsg
);
2209 yyerror (]b4_lyyerror_args
[YY_("syntax error"));
2210 yyMemoryExhausted (yystackp
);
2212 #endif /* YYERROR_VERBOSE */
2216 /* Recover from a syntax error on *YYSTACKP, assuming that *YYSTACKP->YYTOKENP,
2217 yylval, and yylloc are the syntactic category, semantic value, and location
2218 of the lookahead. */
2219 /*ARGSUSED*/ static void
2220 yyrecoverSyntaxError (yyGLRStack
* yystackp
]b4_user_formals
[)
2225 if (yystackp
->yyerrState
== 3)
2226 /* We just shifted the error token and (perhaps) took some
2227 reductions. Skip tokens until we can proceed. */
2228 while (YYID (yytrue
))
2231 if (yychar
== YYEOF
)
2232 yyFail (yystackp
][]b4_lpure_args
[, YY_NULL
);
2233 if (yychar
!= YYEMPTY
)
2234 {]b4_locations_if([[
2235 /* We throw away the lookahead, but the error range
2236 of the shifted error token must take it into account. */
2237 yyGLRState
*yys
= yystackp
->yytops
.yystates
[0];
2238 yyGLRStackItem yyerror_range
[3];
2239 yyerror_range
[1].yystate
.yyloc
= yys
->yyloc
;
2240 yyerror_range
[2].yystate
.yyloc
= yylloc
;
2241 YYLLOC_DEFAULT ((yys
->yyloc
), yyerror_range
, 2);]])[
2242 yytoken
= YYTRANSLATE (yychar
);
2243 yydestruct ("Error: discarding",
2244 yytoken
, &yylval
]b4_locuser_args([&yylloc
])[);
2246 YYDPRINTF ((stderr
, "Reading a token: "));
2248 if (yychar
<= YYEOF
)
2250 yychar
= yytoken
= YYEOF
;
2251 YYDPRINTF ((stderr
, "Now at end of input.\n"));
2255 yytoken
= YYTRANSLATE (yychar
);
2256 YY_SYMBOL_PRINT ("Next token is", yytoken
, &yylval
, &yylloc
);
2258 yyj
= yypact
[yystackp
->yytops
.yystates
[0]->yylrState
];
2259 if (yypact_value_is_default (yyj
))
2262 if (yyj
< 0 || YYLAST
< yyj
|| yycheck
[yyj
] != yytoken
)
2264 if (yydefact
[yystackp
->yytops
.yystates
[0]->yylrState
] != 0)
2267 else if (! yytable_value_is_error (yytable
[yyj
]))
2271 /* Reduce to one stack. */
2272 for (yyk
= 0; yyk
< yystackp
->yytops
.yysize
; yyk
+= 1)
2273 if (yystackp
->yytops
.yystates
[yyk
] != YY_NULL
)
2275 if (yyk
>= yystackp
->yytops
.yysize
)
2276 yyFail (yystackp
][]b4_lpure_args
[, YY_NULL
);
2277 for (yyk
+= 1; yyk
< yystackp
->yytops
.yysize
; yyk
+= 1)
2278 yymarkStackDeleted (yystackp
, yyk
);
2279 yyremoveDeletes (yystackp
);
2280 yycompressStack (yystackp
);
2282 /* Now pop stack until we find a state that shifts the error token. */
2283 yystackp
->yyerrState
= 3;
2284 while (yystackp
->yytops
.yystates
[0] != YY_NULL
)
2286 yyGLRState
*yys
= yystackp
->yytops
.yystates
[0];
2287 yyj
= yypact
[yys
->yylrState
];
2288 if (! yypact_value_is_default (yyj
))
2291 if (0 <= yyj
&& yyj
<= YYLAST
&& yycheck
[yyj
] == YYTERROR
2292 && yyisShiftAction (yytable
[yyj
]))
2294 /* Shift the error token. */]b4_locations_if([[
2295 /* First adjust its location.*/
2297 yystackp
->yyerror_range
[2].yystate
.yyloc
= yylloc
;
2298 YYLLOC_DEFAULT (yyerrloc
, (yystackp
->yyerror_range
), 2);]])[
2299 YY_SYMBOL_PRINT ("Shifting", yystos
[yytable
[yyj
]],
2300 &yylval
, &yyerrloc
);
2301 yyglrShift (yystackp
, 0, yytable
[yyj
],
2302 yys
->yyposn
, &yylval
]b4_locations_if([, &yyerrloc
])[);
2303 yys
= yystackp
->yytops
.yystates
[0];
2306 }]b4_locations_if([[
2307 yystackp
->yyerror_range
[1].yystate
.yyloc
= yys
->yyloc
;]])[
2308 if (yys
->yypred
!= YY_NULL
)
2309 yydestroyGLRState ("Error: popping", yys
]b4_user_args
[);
2310 yystackp
->yytops
.yystates
[0] = yys
->yypred
;
2311 yystackp
->yynextFree
-= 1;
2312 yystackp
->yyspaceLeft
+= 1;
2314 if (yystackp
->yytops
.yystates
[0] == YY_NULL
)
2315 yyFail (yystackp
][]b4_lpure_args
[, YY_NULL
);
2318 #define YYCHK1(YYE) \
2328 goto yyuser_error; \
2338 ]b4_c_ansi_function_def([yyparse
], [int], b4_parse_param
)[
2342 yyGLRStack
* const yystackp
= &yystack
;
2345 YYDPRINTF ((stderr
, "Starting parse\n"));
2348 yylval
= yyval_default
;
2350 #if defined YYLTYPE_IS_TRIVIAL && YYLTYPE_IS_TRIVIAL
2351 yylloc
.first_line
= yylloc
.last_line
= ]b4_location_initial_line
[;
2352 yylloc
.first_column
= yylloc
.last_column
= ]b4_location_initial_column
[;
2355 m4_ifdef([b4_initial_action
], [
2356 m4_pushdef([b4_at_dollar
], [yylloc
])dnl
2357 m4_pushdef([b4_dollar_dollar
], [yylval
])dnl
2358 /* User initialization code. */
2359 b4_user_initial_action
2360 m4_popdef([b4_dollar_dollar
])dnl
2361 m4_popdef([b4_at_dollar
])])dnl
2363 if (! yyinitGLRStack (yystackp
, YYINITDEPTH
))
2364 goto yyexhaustedlab
;
2365 switch (YYSETJMP (yystack
.yyexception_buffer
))
2368 case 1: goto yyabortlab
;
2369 case 2: goto yyexhaustedlab
;
2370 default: goto yybuglab
;
2372 yyglrShift (&yystack
, 0, 0, 0, &yylval
]b4_locations_if([, &yylloc
])[);
2375 while (YYID (yytrue
))
2377 /* For efficiency, we have two loops, the first of which is
2378 specialized to deterministic operation (single stack, no
2379 potential ambiguity). */
2381 while (YYID (yytrue
))
2385 const short int* yyconflicts
;
2387 yyStateNum yystate
= yystack
.yytops
.yystates
[0]->yylrState
;
2388 YYDPRINTF ((stderr
, "Entering state %d\n", yystate
));
2389 if (yystate
== YYFINAL
)
2391 if (yyisDefaultedState (yystate
))
2393 yyrule
= yydefaultAction (yystate
);
2396 ]b4_locations_if([[ yystack
.yyerror_range
[1].yystate
.yyloc
= yylloc
;]])[
2397 yyreportSyntaxError (&yystack
]b4_user_args
[);
2400 YYCHK1 (yyglrReduce (&yystack
, 0, yyrule
, yytrue
]b4_user_args
[));
2405 if (yychar
== YYEMPTY
)
2407 YYDPRINTF ((stderr
, "Reading a token: "));
2411 if (yychar
<= YYEOF
)
2413 yychar
= yytoken
= YYEOF
;
2414 YYDPRINTF ((stderr
, "Now at end of input.\n"));
2418 yytoken
= YYTRANSLATE (yychar
);
2419 YY_SYMBOL_PRINT ("Next token is", yytoken
, &yylval
, &yylloc
);
2422 yygetLRActions (yystate
, yytoken
, &yyaction
, &yyconflicts
);
2423 if (*yyconflicts
!= 0)
2425 if (yyisShiftAction (yyaction
))
2427 YY_SYMBOL_PRINT ("Shifting", yytoken
, &yylval
, &yylloc
);
2430 yyglrShift (&yystack
, 0, yyaction
, yyposn
, &yylval
]b4_locations_if([, &yylloc
])[);
2431 if (0 < yystack
.yyerrState
)
2432 yystack
.yyerrState
-= 1;
2434 else if (yyisErrorAction (yyaction
))
2436 ]b4_locations_if([[ yystack
.yyerror_range
[1].yystate
.yyloc
= yylloc
;]])[
2437 yyreportSyntaxError (&yystack
]b4_user_args
[);
2441 YYCHK1 (yyglrReduce (&yystack
, 0, -yyaction
, yytrue
]b4_user_args
[));
2445 while (YYID (yytrue
))
2447 yySymbol yytoken_to_shift
;
2450 for (yys
= 0; yys
< yystack
.yytops
.yysize
; yys
+= 1)
2451 yystackp
->yytops
.yylookaheadNeeds
[yys
] = yychar
!= YYEMPTY
;
2453 /* yyprocessOneStack returns one of three things:
2455 - An error flag. If the caller is yyprocessOneStack, it
2456 immediately returns as well. When the caller is finally
2457 yyparse, it jumps to an error label via YYCHK1.
2459 - yyok, but yyprocessOneStack has invoked yymarkStackDeleted
2460 (&yystack, yys), which sets the top state of yys to NULL. Thus,
2461 yyparse's following invocation of yyremoveDeletes will remove
2464 - yyok, when ready to shift a token.
2466 Except in the first case, yyparse will invoke yyremoveDeletes and
2467 then shift the next token onto all remaining stacks. This
2468 synchronization of the shift (that is, after all preceding
2469 reductions on all stacks) helps prevent double destructor calls
2470 on yylval in the event of memory exhaustion. */
2472 for (yys
= 0; yys
< yystack
.yytops
.yysize
; yys
+= 1)
2473 YYCHK1 (yyprocessOneStack (&yystack
, yys
, yyposn
]b4_lpure_args
[));
2474 yyremoveDeletes (&yystack
);
2475 if (yystack
.yytops
.yysize
== 0)
2477 yyundeleteLastStack (&yystack
);
2478 if (yystack
.yytops
.yysize
== 0)
2479 yyFail (&yystack
][]b4_lpure_args
[, YY_("syntax error"));
2480 YYCHK1 (yyresolveStack (&yystack
]b4_user_args
[));
2481 YYDPRINTF ((stderr
, "Returning to deterministic operation.\n"));
2482 ]b4_locations_if([[ yystack
.yyerror_range
[1].yystate
.yyloc
= yylloc
;]])[
2483 yyreportSyntaxError (&yystack
]b4_user_args
[);
2487 /* If any yyglrShift call fails, it will fail after shifting. Thus,
2488 a copy of yylval will already be on stack 0 in the event of a
2489 failure in the following loop. Thus, yychar is set to YYEMPTY
2490 before the loop to make sure the user destructor for yylval isn't
2492 yytoken_to_shift
= YYTRANSLATE (yychar
);
2495 for (yys
= 0; yys
< yystack
.yytops
.yysize
; yys
+= 1)
2498 const short int* yyconflicts
;
2499 yyStateNum yystate
= yystack
.yytops
.yystates
[yys
]->yylrState
;
2500 yygetLRActions (yystate
, yytoken_to_shift
, &yyaction
,
2502 /* Note that yyconflicts were handled by yyprocessOneStack. */
2503 YYDPRINTF ((stderr
, "On stack %lu, ", (unsigned long int) yys
));
2504 YY_SYMBOL_PRINT ("shifting", yytoken_to_shift
, &yylval
, &yylloc
);
2505 yyglrShift (&yystack
, yys
, yyaction
, yyposn
,
2506 &yylval
]b4_locations_if([, &yylloc
])[);
2507 YYDPRINTF ((stderr
, "Stack %lu now in state #%d\n",
2508 (unsigned long int) yys
,
2509 yystack
.yytops
.yystates
[yys
]->yylrState
));
2512 if (yystack
.yytops
.yysize
== 1)
2514 YYCHK1 (yyresolveStack (&yystack
]b4_user_args
[));
2515 YYDPRINTF ((stderr
, "Returning to deterministic operation.\n"));
2516 yycompressStack (&yystack
);
2522 yyrecoverSyntaxError (&yystack
]b4_user_args
[);
2523 yyposn
= yystack
.yytops
.yystates
[0]->yyposn
;
2539 yyerror (]b4_lyyerror_args
[YY_("memory exhausted"));
2544 if (yychar
!= YYEMPTY
)
2545 yydestruct ("Cleanup: discarding lookahead",
2546 YYTRANSLATE (yychar
), &yylval
]b4_locuser_args([&yylloc
])[);
2548 /* If the stack is well-formed, pop the stack until it is empty,
2549 destroying its entries as we go. But free the stack regardless
2550 of whether it is well-formed. */
2551 if (yystack
.yyitems
)
2553 yyGLRState
** yystates
= yystack
.yytops
.yystates
;
2556 size_t yysize
= yystack
.yytops
.yysize
;
2558 for (yyk
= 0; yyk
< yysize
; yyk
+= 1)
2561 while (yystates
[yyk
])
2563 yyGLRState
*yys
= yystates
[yyk
];
2564 ]b4_locations_if([[ yystack
.yyerror_range
[1].yystate
.yyloc
= yys
->yyloc
;]]
2565 )[ if (yys
->yypred
!= YY_NULL
)
2566 yydestroyGLRState ("Cleanup: popping", yys
]b4_user_args
[);
2567 yystates
[yyk
] = yys
->yypred
;
2568 yystack
.yynextFree
-= 1;
2569 yystack
.yyspaceLeft
+= 1;
2574 yyfreeGLRStack (&yystack
);
2577 /* Make sure YYID is used. */
2578 return YYID (yyresult
);
2581 /* DEBUGGING ONLY */
2583 static void yypstack (yyGLRStack
* yystackp
, size_t yyk
)
2584 __attribute__ ((__unused__
));
2585 static void yypdumpstack (yyGLRStack
* yystackp
) __attribute__ ((__unused__
));
2588 yy_yypstack (yyGLRState
* yys
)
2592 yy_yypstack (yys
->yypred
);
2593 YYFPRINTF (stderr
, " -> ");
2595 YYFPRINTF (stderr
, "%d@@%lu", yys
->yylrState
,
2596 (unsigned long int) yys
->yyposn
);
2600 yypstates (yyGLRState
* yyst
)
2602 if (yyst
== YY_NULL
)
2603 YYFPRINTF (stderr
, "<null>");
2606 YYFPRINTF (stderr
, "\n");
2610 yypstack (yyGLRStack
* yystackp
, size_t yyk
)
2612 yypstates (yystackp
->yytops
.yystates
[yyk
]);
2615 #define YYINDEX(YYX) \
2616 ((YYX) == YY_NULL ? -1 : (yyGLRStackItem*) (YYX) - yystackp->yyitems)
2620 yypdumpstack (yyGLRStack
* yystackp
)
2622 yyGLRStackItem
* yyp
;
2624 for (yyp
= yystackp
->yyitems
; yyp
< yystackp
->yynextFree
; yyp
+= 1)
2626 YYFPRINTF (stderr
, "%3lu. ",
2627 (unsigned long int) (yyp
- yystackp
->yyitems
));
2628 if (*(yybool
*) yyp
)
2630 YYFPRINTF (stderr
, "Res: %d, LR State: %d, posn: %lu, pred: %ld",
2631 yyp
->yystate
.yyresolved
, yyp
->yystate
.yylrState
,
2632 (unsigned long int) yyp
->yystate
.yyposn
,
2633 (long int) YYINDEX (yyp
->yystate
.yypred
));
2634 if (! yyp
->yystate
.yyresolved
)
2635 YYFPRINTF (stderr
, ", firstVal: %ld",
2636 (long int) YYINDEX (yyp
->yystate
2637 .yysemantics
.yyfirstVal
));
2641 YYFPRINTF (stderr
, "Option. rule: %d, state: %ld, next: %ld",
2642 yyp
->yyoption
.yyrule
- 1,
2643 (long int) YYINDEX (yyp
->yyoption
.yystate
),
2644 (long int) YYINDEX (yyp
->yyoption
.yynext
));
2646 YYFPRINTF (stderr
, "\n");
2648 YYFPRINTF (stderr
, "Tops:");
2649 for (yyi
= 0; yyi
< yystackp
->yytops
.yysize
; yyi
+= 1)
2650 YYFPRINTF (stderr
, "%lu: %ld; ", (unsigned long int) yyi
,
2651 (long int) YYINDEX (yystackp
->yytops
.yystates
[yyi
]));
2652 YYFPRINTF (stderr
, "\n");
2657 dnl glr
.cc produces its own header
.
2659 m4_if(b4_skeleton
, ["glr.c"],
2661 [@
output(b4_spec_defines_file@
)@
2662 b4_copyright([Skeleton interface
for Bison GLR parsers in C
],
2665 b4_shared_declarations
2668 [[extern YYSTYPE
]b4_prefix
[lval
;]])
2670 b4_locations_if([b4_pure_if([],
2671 [extern YYLTYPE
]b4_prefix
[lloc
;])