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 /* Enabling the token table. */
227 #ifndef YYTOKEN_TABLE
228 # define YYTOKEN_TABLE ]b4_token_table[
231 /* Default (constant) value used for initialization for null
232 right-hand sides. Unlike the standard yacc.c template,
233 here we set the default value of $$ to a zeroed-out value.
234 Since the default value is undefined, this behavior is
235 technically correct. */
236 static YYSTYPE yyval_default
;
238 /* Copy the second part of user declarations. */
239 ]b4_user_post_prologue
240 b4_percent_code_get
[]dnl
247 # if defined YYENABLE_NLS && YYENABLE_NLS
249 # include <libintl.h> /* INFRINGES ON USER NAME SPACE */
250 # define YY_(msgid) dgettext ("bison-runtime", msgid)
254 # define YY_(msgid) msgid
258 /* Suppress unused-variable warnings by "using" E. */
259 #if ! defined lint || defined __GNUC__
260 # define YYUSE(e) ((void) (e))
262 # define YYUSE(e) /* empty */
265 /* Identity function, used to suppress warnings about constant conditions. */
269 ]b4_c_function_def([YYID
], [static int], [[int i
], [i
]])[
279 # define YYMALLOC malloc
282 # define YYREALLOC realloc
285 #define YYSIZEMAX ((size_t) -1)
290 typedef unsigned char yybool
;
297 # define YYJMP_BUF jmp_buf
298 # define YYSETJMP(env) setjmp (env)
299 # define YYLONGJMP(env, val) longjmp (env, val)
306 #ifndef __attribute__
307 /* This feature is available in gcc versions 2.5 and later. */
308 # if (! defined __GNUC__ || __GNUC__ < 2 \
309 || (__GNUC__ == 2 && __GNUC_MINOR__ < 5))
310 # define __attribute__(Spec) /* empty */
314 ]b4_locations_if([#define YYOPTIONAL_LOC(Name) Name],[
316 # define YYOPTIONAL_LOC(Name) /* empty */
318 # define YYOPTIONAL_LOC(Name) Name __attribute__ ((__unused__))
322 # define YYASSERT(condition) ((void) ((condition) || (abort (), 0)))
325 /* YYFINAL -- State number of the termination state. */
326 #define YYFINAL ]b4_final_state_number[
327 /* YYLAST -- Last index in YYTABLE. */
328 #define YYLAST ]b4_last[
330 /* YYNTOKENS -- Number of terminals. */
331 #define YYNTOKENS ]b4_tokens_number[
332 /* YYNNTS -- Number of nonterminals. */
333 #define YYNNTS ]b4_nterms_number[
334 /* YYNRULES -- Number of rules. */
335 #define YYNRULES ]b4_rules_number[
336 /* YYNRULES -- Number of states. */
337 #define YYNSTATES ]b4_states_number[
338 /* YYMAXRHS -- Maximum number of symbols on right-hand side of rule. */
339 #define YYMAXRHS ]b4_r2_max[
340 /* YYMAXLEFT -- Maximum number of symbols to the left of a handle
341 accessed by $0, $-1, etc., in any rule. */
342 #define YYMAXLEFT ]b4_max_left_semantic_context[
344 /* YYTRANSLATE(X) -- Bison symbol number corresponding to X. */
345 #define YYUNDEFTOK ]b4_undef_token_number[
346 #define YYMAXUTOK ]b4_user_token_number_max[
348 #define YYTRANSLATE(YYX) \
349 ((unsigned int) (YYX) <= YYMAXUTOK ? yytranslate[YYX] : YYUNDEFTOK)
351 /* YYTRANSLATE[YYLEX] -- Bison symbol number corresponding to YYLEX. */
352 static const ]b4_int_type_for([b4_translate
])[ yytranslate
[] =
358 /* YYRLINE[YYN] -- source line where rule number YYN was defined. */
359 static const ]b4_int_type_for([b4_rline
])[ yyrline
[] =
365 #if YYDEBUG || YYERROR_VERBOSE || YYTOKEN_TABLE
366 /* YYTNAME[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM.
367 First, the terminals, then, starting at YYNTOKENS, nonterminals. */
368 static const char *const yytname
[] =
374 #define YYPACT_NINF ]b4_pact_ninf[
375 #define YYTABLE_NINF ]b4_table_ninf[
377 ]b4_parser_tables_define
[
379 /* YYDPREC[RULE-NUM] -- Dynamic precedence of rule #RULE-NUM (0 if none). */
380 static const ]b4_int_type_for([b4_dprec
])[ yydprec
[] =
385 /* YYMERGER[RULE-NUM] -- Index of merging function for rule #RULE-NUM. */
386 static const ]b4_int_type_for([b4_merger
])[ yymerger
[] =
391 /* YYIMMEDIATE[RULE-NUM] -- True iff rule #RULE-NUM is not to be deferred, as
392 in the case of predicates. */
393 static const yybool yyimmediate
[] =
398 /* YYCONFLP[YYPACT[STATE-NUM]] -- Pointer into YYCONFL of start of
399 list of conflicting reductions corresponding to action entry for
400 state STATE-NUM in yytable. 0 means no conflicts. The list in
401 yyconfl is terminated by a rule number of 0. */
402 static const ]b4_int_type_for([b4_conflict_list_heads
])[ yyconflp
[] =
404 ]b4_conflict_list_heads
[
407 /* YYCONFL[I] -- lists of conflicting rule numbers, each terminated by
408 0, pointed into by YYCONFLP. */
409 ]dnl Do
not use b4_int_type_for here
, since there are places where
410 dnl pointers onto yyconfl are taken
, which type is
"short int *".
411 dnl We probably ought to introduce a type
for confl
.
412 [static const short int yyconfl
[] =
414 ]b4_conflicting_rules
[
417 /* Error token number */
420 /* YYLLOC_DEFAULT -- Set CURRENT to span from RHS[1] to RHS[N].
421 If N is 0, then set CURRENT to the empty location which ends
422 the previous symbol: RHS[0] (always defined). */
425 #define YYRHSLOC(Rhs, K) ((Rhs)[K].yystate.yyloc)
426 #ifndef YYLLOC_DEFAULT
427 # define YYLLOC_DEFAULT(Current, Rhs, N) \
431 (Current).first_line = YYRHSLOC (Rhs, 1).first_line; \
432 (Current).first_column = YYRHSLOC (Rhs, 1).first_column; \
433 (Current).last_line = YYRHSLOC (Rhs, N).last_line; \
434 (Current).last_column = YYRHSLOC (Rhs, N).last_column; \
438 (Current).first_line = (Current).last_line = \
439 YYRHSLOC (Rhs, 0).last_line; \
440 (Current).first_column = (Current).last_column = \
441 YYRHSLOC (Rhs, 0).last_column; \
445 /* YY_LOCATION_PRINT -- Print the location on the stream.
446 This macro was not mandated originally: define only if we know
447 we won't break user code: when these are the locations we know. */
449 # define YY_LOCATION_PRINT(File, Loc) \
450 fprintf (File, "%d.%d-%d.%d", \
451 (Loc).first_line, (Loc).first_column, \
452 (Loc).last_line, (Loc).last_column)
455 #ifndef YYLLOC_DEFAULT
456 # define YYLLOC_DEFAULT(Current, Rhs, N) ((void) 0)
460 #ifndef YY_LOCATION_PRINT
461 # define YY_LOCATION_PRINT(File, Loc) ((void) 0)
465 /* YYLEX -- calling `yylex' with the right arguments. */
466 #define YYLEX ]b4_c_function_call([yylex], [int], b4_lex_param)[
471 #define yynerrs (yystackp->yyerrcnt)
473 #define yychar (yystackp->yyrawchar)
475 #define yylval (yystackp->yyval)
477 #define yylloc (yystackp->yyloc)
478 m4_if(b4_prefix
[], [yy
], [],
479 [#define b4_prefix[]nerrs yynerrs
480 #define b4_prefix[]char yychar
481 #define b4_prefix[]lval yylval
482 #define b4_prefix[]lloc yylloc])],
483 [YYSTYPE yylval
;]b4_locations_if([[
489 static const int YYEOF
= 0;
490 static const int YYEMPTY
= -2;
492 typedef enum { yyok
, yyaccept
, yyabort
, yyerr
} YYRESULTTAG
;
496 YYRESULTTAG yychk_flag = YYE; \
497 if (yychk_flag != yyok) \
504 # define YYFPRINTF fprintf
507 # define YYDPRINTF(Args) \
513 ]b4_yy_symbol_print_generate([b4_c_ansi_function_def
])[
515 # define YY_SYMBOL_PRINT(Title, Type, Value, Location) \
519 YYFPRINTF (stderr, "%s ", Title); \
520 yy_symbol_print (stderr, Type, Value]b4_locuser_args([Location])[); \
521 YYFPRINTF (stderr, "\n"); \
525 /* Nonzero means print parse trace. It is left uninitialized so that
526 multiple parsers can coexist. */
531 # define YYDPRINTF(Args)
532 # define YY_SYMBOL_PRINT(Title, Type, Value, Location)
534 #endif /* !YYDEBUG */
536 /* YYINITDEPTH -- initial size of the parser's stacks. */
538 # define YYINITDEPTH ]b4_stack_depth_init[
541 /* YYMAXDEPTH -- maximum size the stacks can grow to (effective only
542 if the built-in stack extension method is used).
544 Do not make this value too large; the results are undefined if
545 SIZE_MAX < YYMAXDEPTH * sizeof (GLRStackItem)
546 evaluated with infinite-precision integer arithmetic. */
549 # define YYMAXDEPTH ]b4_stack_depth_max[
552 /* Minimum number of free items on the stack allowed after an
553 allocation. This is to allow allocation and initialization
554 to be completed by functions that call yyexpandGLRStack before the
555 stack is expanded, thus insuring that all necessary pointers get
556 properly redirected to new data. */
559 #ifndef YYSTACKEXPANDABLE
560 # define YYSTACKEXPANDABLE 1
563 #if YYSTACKEXPANDABLE
564 # define YY_RESERVE_GLRSTACK(Yystack) \
566 if (Yystack->yyspaceLeft < YYHEADROOM) \
567 yyexpandGLRStack (Yystack); \
570 # define YY_RESERVE_GLRSTACK(Yystack) \
572 if (Yystack->yyspaceLeft < YYHEADROOM) \
573 yyMemoryExhausted (Yystack); \
581 # if defined __GLIBC__ && defined _STRING_H && defined _GNU_SOURCE
582 # define yystpcpy stpcpy
584 /* Copy YYSRC to YYDEST, returning the address of the terminating '\0' in
587 yystpcpy (char *yydest
, const char *yysrc
)
590 const char *yys
= yysrc
;
592 while ((*yyd
++ = *yys
++) != '\0')
601 /* Copy to YYRES the contents of YYSTR after stripping away unnecessary
602 quotes and backslashes, so that it's suitable for yyerror. The
603 heuristic is that double-quoting is unnecessary unless the string
604 contains an apostrophe, a comma, or backslash (other than
605 backslash-backslash). YYSTR is taken from yytname. If YYRES is
606 null, do not copy; instead, return the length of what the result
609 yytnamerr (char *yyres
, const char *yystr
)
614 char const *yyp
= yystr
;
621 goto do_not_strip_quotes
;
625 goto do_not_strip_quotes
;
638 do_not_strip_quotes
: ;
642 return strlen (yystr
);
644 return yystpcpy (yyres
, yystr
) - yyres
;
648 #endif /* !YYERROR_VERBOSE */
650 /** State numbers, as in LALR(1) machine */
651 typedef int yyStateNum
;
653 /** Rule numbers, as in LALR(1) machine */
654 typedef int yyRuleNum
;
656 /** Grammar symbol */
657 typedef int yySymbol
;
659 /** Item references, as in LALR(1) machine */
660 typedef short int yyItemNum
;
662 typedef struct yyGLRState yyGLRState
;
663 typedef struct yyGLRStateSet yyGLRStateSet
;
664 typedef struct yySemanticOption yySemanticOption
;
665 typedef union yyGLRStackItem yyGLRStackItem
;
666 typedef struct yyGLRStack yyGLRStack
;
669 /** Type tag: always true. */
671 /** Type tag for yysemantics. If true, yysval applies, otherwise
672 * yyfirstVal applies. */
674 /** Number of corresponding LALR(1) machine state. */
675 yyStateNum yylrState
;
676 /** Preceding state in this stack */
678 /** Source position of the last token produced by my symbol */
681 /** First in a chain of alternative reductions producing the
682 * non-terminal corresponding to this state, threaded through
684 yySemanticOption
* yyfirstVal
;
685 /** Semantic value for this state. */
687 } yysemantics
;]b4_locations_if([[
688 /** Source location for this state. */
692 struct yyGLRStateSet
{
693 yyGLRState
** yystates
;
694 /** During nondeterministic operation, yylookaheadNeeds tracks which
695 * stacks have actually needed the current lookahead. During deterministic
696 * operation, yylookaheadNeeds[0] is not maintained since it would merely
697 * duplicate yychar != YYEMPTY. */
698 yybool
* yylookaheadNeeds
;
699 size_t yysize
, yycapacity
;
702 struct yySemanticOption
{
703 /** Type tag: always false. */
705 /** Rule number for this reduction */
707 /** The last RHS state in the list of states to be reduced. */
709 /** The lookahead for this reduction. */
711 YYSTYPE yyval
;]b4_locations_if([[
713 /** Next sibling in chain of options. To facilitate merging,
714 * options are chained in decreasing order by address. */
715 yySemanticOption
* yynext
;
718 /** Type of the items in the GLR stack. The yyisState field
719 * indicates which item of the union is valid. */
720 union yyGLRStackItem
{
722 yySemanticOption yyoption
;
727 ]b4_locations_if([[ /* To compute the location of the error token. */
728 yyGLRStackItem yyerror_range
[3];]])[
733 YYSTYPE yyval
;]b4_locations_if([[
736 YYJMP_BUF yyexception_buffer
;
737 yyGLRStackItem
* yyitems
;
738 yyGLRStackItem
* yynextFree
;
740 yyGLRState
* yysplitPoint
;
741 yyGLRState
* yylastDeleted
;
742 yyGLRStateSet yytops
;
745 #if YYSTACKEXPANDABLE
746 static void yyexpandGLRStack (yyGLRStack
* yystackp
);
749 static void yyFail (yyGLRStack
* yystackp
]b4_pure_formals
[, const char* yymsg
)
750 __attribute__ ((__noreturn__
));
752 yyFail (yyGLRStack
* yystackp
]b4_pure_formals
[, const char* yymsg
)
754 if (yymsg
!= YY_NULL
)
755 yyerror (]b4_yyerror_args
[yymsg
);
756 YYLONGJMP (yystackp
->yyexception_buffer
, 1);
759 static void yyMemoryExhausted (yyGLRStack
* yystackp
)
760 __attribute__ ((__noreturn__
));
762 yyMemoryExhausted (yyGLRStack
* yystackp
)
764 YYLONGJMP (yystackp
->yyexception_buffer
, 2);
767 #if YYDEBUG || YYERROR_VERBOSE
768 /** A printable representation of TOKEN. */
769 static inline const char*
770 yytokenName (yySymbol yytoken
)
772 if (yytoken
== YYEMPTY
)
775 return yytname
[yytoken
];
779 /** Fill in YYVSP[YYLOW1 .. YYLOW0-1] from the chain of states starting
780 * at YYVSP[YYLOW0].yystate.yypred. Leaves YYVSP[YYLOW1].yystate.yypred
781 * containing the pointer to the next state in the chain. */
782 static void yyfillin (yyGLRStackItem
*, int, int) __attribute__ ((__unused__
));
784 yyfillin (yyGLRStackItem
*yyvsp
, int yylow0
, int yylow1
)
787 yyGLRState
*s
= yyvsp
[yylow0
].yystate
.yypred
;
788 for (i
= yylow0
-1; i
>= yylow1
; i
-= 1)
791 yyvsp
[i
].yystate
.yylrState
= s
->yylrState
;
793 yyvsp
[i
].yystate
.yyresolved
= s
->yyresolved
;
795 yyvsp
[i
].yystate
.yysemantics
.yysval
= s
->yysemantics
.yysval
;
797 /* The effect of using yysval or yyloc (in an immediate rule) is
799 yyvsp
[i
].yystate
.yysemantics
.yyfirstVal
= YY_NULL
;]b4_locations_if([[
800 yyvsp
[i
].yystate
.yyloc
= s
->yyloc
;]])[
801 s
= yyvsp
[i
].yystate
.yypred
= s
->yypred
;
805 /* Do nothing if YYNORMAL or if *YYLOW <= YYLOW1. Otherwise, fill in
806 * YYVSP[YYLOW1 .. *YYLOW-1] as in yyfillin and set *YYLOW = YYLOW1.
807 * For convenience, always return YYLOW1. */
808 static inline int yyfill (yyGLRStackItem
*, int *, int, yybool
)
809 __attribute__ ((__unused__
));
811 yyfill (yyGLRStackItem
*yyvsp
, int *yylow
, int yylow1
, yybool yynormal
)
813 if (!yynormal
&& yylow1
< *yylow
)
815 yyfillin (yyvsp
, *yylow
, yylow1
);
821 /** Perform user action for rule number YYN, with RHS length YYRHSLEN,
822 * and top stack item YYVSP. YYLVALP points to place to put semantic
823 * value ($$), and yylocp points to place for location information
824 * (@@$). Returns yyok for normal return, yyaccept for YYACCEPT,
825 * yyerr for YYERROR, yyabort for YYABORT. */
826 /*ARGSUSED*/ static YYRESULTTAG
827 yyuserAction (yyRuleNum yyn
, int yyrhslen
, yyGLRStackItem
* yyvsp
,
828 yyGLRStack
* yystackp
,
829 YYSTYPE
* yyvalp
]b4_locuser_formals
[)
831 yybool yynormal
__attribute__ ((__unused__
)) =
832 (yystackp
->yysplitPoint
== YY_NULL
);
834 ]b4_parse_param_use([yyvalp
], [yylocp
])dnl
836 # define yyerrok (yystackp->yyerrState = 0)
838 # define YYACCEPT return yyaccept
840 # define YYABORT return yyabort
842 # define YYERROR return yyerrok, yyerr
844 # define YYRECOVERING() (yystackp->yyerrState != 0)
846 # define yyclearin (yychar = YYEMPTY)
848 # define YYFILL(N) yyfill (yyvsp, &yylow, N, yynormal)
850 # define YYBACKUP(Token, Value) \
851 return yyerror (]b4_yyerror_args[YY_("syntax error: cannot back up")), \
856 *yyvalp
= yyval_default
;
858 *yyvalp
= yyvsp
[YYFILL (1-yyrhslen
)].yystate
.yysemantics
.yysval
;]b4_locations_if([[
859 YYLLOC_DEFAULT ((*yylocp
), (yyvsp
- yyrhslen
), yyrhslen
);
860 yystackp
->yyerror_range
[1].yystate
.yyloc
= *yylocp
;
879 /*ARGSUSED*/ static void
880 yyuserMerge (int yyn
, YYSTYPE
* yy0
, YYSTYPE
* yy1
)
892 /* Bison grammar-table manipulation. */
894 ]b4_yydestruct_generate([b4_c_ansi_function_def
])[
896 /** Number of symbols composing the right hand side of rule #RULE. */
898 yyrhsLength (yyRuleNum yyrule
)
904 yydestroyGLRState (char const *yymsg
, yyGLRState
*yys
]b4_user_formals
[)
907 yydestruct (yymsg
, yystos
[yys
->yylrState
],
908 &yys
->yysemantics
.yysval
]b4_locuser_args([&yys
->yyloc
])[);
914 if (yys
->yysemantics
.yyfirstVal
)
915 YYFPRINTF (stderr
, "%s unresolved ", yymsg
);
917 YYFPRINTF (stderr
, "%s incomplete ", yymsg
);
918 yy_symbol_print (stderr
, yystos
[yys
->yylrState
],
919 YY_NULL
]b4_locuser_args([&yys
->yyloc
])[);
920 YYFPRINTF (stderr
, "\n");
924 if (yys
->yysemantics
.yyfirstVal
)
926 yySemanticOption
*yyoption
= yys
->yysemantics
.yyfirstVal
;
929 for (yyrh
= yyoption
->yystate
, yyn
= yyrhsLength (yyoption
->yyrule
);
931 yyrh
= yyrh
->yypred
, yyn
-= 1)
932 yydestroyGLRState (yymsg
, yyrh
]b4_user_args
[);
937 /** Left-hand-side symbol for rule #YYRULE. */
938 static inline yySymbol
939 yylhsNonterm (yyRuleNum yyrule
)
944 #define yypact_value_is_default(yystate) \
945 ]b4_table_value_equals([[pact]], [[yystate]], [b4_pact_ninf])[
947 /** True iff LR state YYSTATE has only a default reduction (regardless
950 yyisDefaultedState (yyStateNum yystate
)
952 return yypact_value_is_default (yypact
[yystate
]);
955 /** The default reduction for YYSTATE, assuming it has one. */
956 static inline yyRuleNum
957 yydefaultAction (yyStateNum yystate
)
959 return yydefact
[yystate
];
962 #define yytable_value_is_error(yytable_value) \
963 ]b4_table_value_equals([[table]], [[yytable_value]], [b4_table_ninf])[
965 /** Set *YYACTION to the action to take in YYSTATE on seeing YYTOKEN.
967 * R < 0: Reduce on rule -R.
969 * R > 0: Shift to state R.
970 * Set *YYCONFLICTS to a pointer into yyconfl to a 0-terminated list
971 * of conflicting reductions.
974 yygetLRActions (yyStateNum yystate
, int yytoken
,
975 int* yyaction
, const short int** yyconflicts
)
977 int yyindex
= yypact
[yystate
] + yytoken
;
978 if (yypact_value_is_default (yypact
[yystate
])
979 || yyindex
< 0 || YYLAST
< yyindex
|| yycheck
[yyindex
] != yytoken
)
981 *yyaction
= -yydefact
[yystate
];
982 *yyconflicts
= yyconfl
;
984 else if (! yytable_value_is_error (yytable
[yyindex
]))
986 *yyaction
= yytable
[yyindex
];
987 *yyconflicts
= yyconfl
+ yyconflp
[yyindex
];
992 *yyconflicts
= yyconfl
+ yyconflp
[yyindex
];
996 static inline yyStateNum
997 yyLRgotoState (yyStateNum yystate
, yySymbol yylhs
)
999 int yyr
= yypgoto
[yylhs
- YYNTOKENS
] + yystate
;
1000 if (0 <= yyr
&& yyr
<= YYLAST
&& yycheck
[yyr
] == yystate
)
1001 return yytable
[yyr
];
1003 return yydefgoto
[yylhs
- YYNTOKENS
];
1006 static inline yybool
1007 yyisShiftAction (int yyaction
)
1009 return 0 < yyaction
;
1012 static inline yybool
1013 yyisErrorAction (int yyaction
)
1015 return yyaction
== 0;
1020 /** Return a fresh GLRStackItem in YYSTACKP. The item is an LR state
1021 * if YYISSTATE, and otherwise a semantic option. Callers should call
1022 * YY_RESERVE_GLRSTACK afterwards to make sure there is sufficient
1025 static inline yyGLRStackItem
*
1026 yynewGLRStackItem (yyGLRStack
* yystackp
, yybool yyisState
)
1028 yyGLRStackItem
* yynewItem
= yystackp
->yynextFree
;
1029 yystackp
->yyspaceLeft
-= 1;
1030 yystackp
->yynextFree
+= 1;
1031 yynewItem
->yystate
.yyisState
= yyisState
;
1035 /** Add a new semantic action that will execute the action for rule
1036 * YYRULE on the semantic values in YYRHS to the list of
1037 * alternative actions for YYSTATE. Assumes that YYRHS comes from
1038 * stack #YYK of *YYSTACKP. */
1040 yyaddDeferredAction (yyGLRStack
* yystackp
, size_t yyk
, yyGLRState
* yystate
,
1041 yyGLRState
* yyrhs
, yyRuleNum yyrule
)
1043 yySemanticOption
* yynewOption
=
1044 &yynewGLRStackItem (yystackp
, yyfalse
)->yyoption
;
1045 yynewOption
->yystate
= yyrhs
;
1046 yynewOption
->yyrule
= yyrule
;
1047 if (yystackp
->yytops
.yylookaheadNeeds
[yyk
])
1049 yynewOption
->yyrawchar
= yychar
;
1050 yynewOption
->yyval
= yylval
;]b4_locations_if([
1051 yynewOption
->yyloc
= yylloc
;])[
1054 yynewOption
->yyrawchar
= YYEMPTY
;
1055 yynewOption
->yynext
= yystate
->yysemantics
.yyfirstVal
;
1056 yystate
->yysemantics
.yyfirstVal
= yynewOption
;
1058 YY_RESERVE_GLRSTACK (yystackp
);
1063 /** Initialize YYSET to a singleton set containing an empty stack. */
1065 yyinitStateSet (yyGLRStateSet
* yyset
)
1068 yyset
->yycapacity
= 16;
1069 yyset
->yystates
= (yyGLRState
**) YYMALLOC (16 * sizeof yyset
->yystates
[0]);
1070 if (! yyset
->yystates
)
1072 yyset
->yystates
[0] = YY_NULL
;
1073 yyset
->yylookaheadNeeds
=
1074 (yybool
*) YYMALLOC (16 * sizeof yyset
->yylookaheadNeeds
[0]);
1075 if (! yyset
->yylookaheadNeeds
)
1077 YYFREE (yyset
->yystates
);
1083 static void yyfreeStateSet (yyGLRStateSet
* yyset
)
1085 YYFREE (yyset
->yystates
);
1086 YYFREE (yyset
->yylookaheadNeeds
);
1089 /** Initialize *YYSTACKP to a single empty stack, with total maximum
1090 * capacity for all stacks of YYSIZE. */
1092 yyinitGLRStack (yyGLRStack
* yystackp
, size_t yysize
)
1094 yystackp
->yyerrState
= 0;
1096 yystackp
->yyspaceLeft
= yysize
;
1098 (yyGLRStackItem
*) YYMALLOC (yysize
* sizeof yystackp
->yynextFree
[0]);
1099 if (!yystackp
->yyitems
)
1101 yystackp
->yynextFree
= yystackp
->yyitems
;
1102 yystackp
->yysplitPoint
= YY_NULL
;
1103 yystackp
->yylastDeleted
= YY_NULL
;
1104 return yyinitStateSet (&yystackp
->yytops
);
1108 #if YYSTACKEXPANDABLE
1109 # define YYRELOC(YYFROMITEMS,YYTOITEMS,YYX,YYTYPE) \
1110 &((YYTOITEMS) - ((YYFROMITEMS) - (yyGLRStackItem*) (YYX)))->YYTYPE
1112 /** If *YYSTACKP is expandable, extend it. WARNING: Pointers into the
1113 stack from outside should be considered invalid after this call.
1114 We always expand when there are 1 or fewer items left AFTER an
1115 allocation, so that we can avoid having external pointers exist
1116 across an allocation. */
1118 yyexpandGLRStack (yyGLRStack
* yystackp
)
1120 yyGLRStackItem
* yynewItems
;
1121 yyGLRStackItem
* yyp0
, *yyp1
;
1124 size_t yysize
= yystackp
->yynextFree
- yystackp
->yyitems
;
1125 if (YYMAXDEPTH
- YYHEADROOM
< yysize
)
1126 yyMemoryExhausted (yystackp
);
1127 yynewSize
= 2*yysize
;
1128 if (YYMAXDEPTH
< yynewSize
)
1129 yynewSize
= YYMAXDEPTH
;
1130 yynewItems
= (yyGLRStackItem
*) YYMALLOC (yynewSize
* sizeof yynewItems
[0]);
1132 yyMemoryExhausted (yystackp
);
1133 for (yyp0
= yystackp
->yyitems
, yyp1
= yynewItems
, yyn
= yysize
;
1135 yyn
-= 1, yyp0
+= 1, yyp1
+= 1)
1138 if (*(yybool
*) yyp0
)
1140 yyGLRState
* yys0
= &yyp0
->yystate
;
1141 yyGLRState
* yys1
= &yyp1
->yystate
;
1142 if (yys0
->yypred
!= YY_NULL
)
1144 YYRELOC (yyp0
, yyp1
, yys0
->yypred
, yystate
);
1145 if (! yys0
->yyresolved
&& yys0
->yysemantics
.yyfirstVal
!= YY_NULL
)
1146 yys1
->yysemantics
.yyfirstVal
=
1147 YYRELOC (yyp0
, yyp1
, yys0
->yysemantics
.yyfirstVal
, yyoption
);
1151 yySemanticOption
* yyv0
= &yyp0
->yyoption
;
1152 yySemanticOption
* yyv1
= &yyp1
->yyoption
;
1153 if (yyv0
->yystate
!= YY_NULL
)
1154 yyv1
->yystate
= YYRELOC (yyp0
, yyp1
, yyv0
->yystate
, yystate
);
1155 if (yyv0
->yynext
!= YY_NULL
)
1156 yyv1
->yynext
= YYRELOC (yyp0
, yyp1
, yyv0
->yynext
, yyoption
);
1159 if (yystackp
->yysplitPoint
!= YY_NULL
)
1160 yystackp
->yysplitPoint
= YYRELOC (yystackp
->yyitems
, yynewItems
,
1161 yystackp
->yysplitPoint
, yystate
);
1163 for (yyn
= 0; yyn
< yystackp
->yytops
.yysize
; yyn
+= 1)
1164 if (yystackp
->yytops
.yystates
[yyn
] != YY_NULL
)
1165 yystackp
->yytops
.yystates
[yyn
] =
1166 YYRELOC (yystackp
->yyitems
, yynewItems
,
1167 yystackp
->yytops
.yystates
[yyn
], yystate
);
1168 YYFREE (yystackp
->yyitems
);
1169 yystackp
->yyitems
= yynewItems
;
1170 yystackp
->yynextFree
= yynewItems
+ yysize
;
1171 yystackp
->yyspaceLeft
= yynewSize
- yysize
;
1176 yyfreeGLRStack (yyGLRStack
* yystackp
)
1178 YYFREE (yystackp
->yyitems
);
1179 yyfreeStateSet (&yystackp
->yytops
);
1182 /** Assuming that YYS is a GLRState somewhere on *YYSTACKP, update the
1183 * splitpoint of *YYSTACKP, if needed, so that it is at least as deep as
1186 yyupdateSplit (yyGLRStack
* yystackp
, yyGLRState
* yys
)
1188 if (yystackp
->yysplitPoint
!= YY_NULL
&& yystackp
->yysplitPoint
> yys
)
1189 yystackp
->yysplitPoint
= yys
;
1192 /** Invalidate stack #YYK in *YYSTACKP. */
1194 yymarkStackDeleted (yyGLRStack
* yystackp
, size_t yyk
)
1196 if (yystackp
->yytops
.yystates
[yyk
] != YY_NULL
)
1197 yystackp
->yylastDeleted
= yystackp
->yytops
.yystates
[yyk
];
1198 yystackp
->yytops
.yystates
[yyk
] = YY_NULL
;
1201 /** Undelete the last stack in *YYSTACKP that was marked as deleted. Can
1202 only be done once after a deletion, and only when all other stacks have
1205 yyundeleteLastStack (yyGLRStack
* yystackp
)
1207 if (yystackp
->yylastDeleted
== YY_NULL
|| yystackp
->yytops
.yysize
!= 0)
1209 yystackp
->yytops
.yystates
[0] = yystackp
->yylastDeleted
;
1210 yystackp
->yytops
.yysize
= 1;
1211 YYDPRINTF ((stderr
, "Restoring last deleted stack as stack #0.\n"));
1212 yystackp
->yylastDeleted
= YY_NULL
;
1216 yyremoveDeletes (yyGLRStack
* yystackp
)
1220 while (yyj
< yystackp
->yytops
.yysize
)
1222 if (yystackp
->yytops
.yystates
[yyi
] == YY_NULL
)
1226 YYDPRINTF ((stderr
, "Removing dead stacks.\n"));
1228 yystackp
->yytops
.yysize
-= 1;
1232 yystackp
->yytops
.yystates
[yyj
] = yystackp
->yytops
.yystates
[yyi
];
1233 /* In the current implementation, it's unnecessary to copy
1234 yystackp->yytops.yylookaheadNeeds[yyi] since, after
1235 yyremoveDeletes returns, the parser immediately either enters
1236 deterministic operation or shifts a token. However, it doesn't
1237 hurt, and the code might evolve to need it. */
1238 yystackp
->yytops
.yylookaheadNeeds
[yyj
] =
1239 yystackp
->yytops
.yylookaheadNeeds
[yyi
];
1242 YYDPRINTF ((stderr
, "Rename stack %lu -> %lu.\n",
1243 (unsigned long int) yyi
, (unsigned long int) yyj
));
1251 /** Shift to a new state on stack #YYK of *YYSTACKP, corresponding to LR
1252 * state YYLRSTATE, at input position YYPOSN, with (resolved) semantic
1253 * value *YYVALP and source location *YYLOCP. */
1255 yyglrShift (yyGLRStack
* yystackp
, size_t yyk
, yyStateNum yylrState
,
1257 YYSTYPE
* yyvalp
]b4_locations_if([, YYLTYPE
* yylocp
])[)
1259 yyGLRState
* yynewState
= &yynewGLRStackItem (yystackp
, yytrue
)->yystate
;
1261 yynewState
->yylrState
= yylrState
;
1262 yynewState
->yyposn
= yyposn
;
1263 yynewState
->yyresolved
= yytrue
;
1264 yynewState
->yypred
= yystackp
->yytops
.yystates
[yyk
];
1265 yynewState
->yysemantics
.yysval
= *yyvalp
;]b4_locations_if([
1266 yynewState
->yyloc
= *yylocp
;])[
1267 yystackp
->yytops
.yystates
[yyk
] = yynewState
;
1269 YY_RESERVE_GLRSTACK (yystackp
);
1272 /** Shift stack #YYK of *YYSTACKP, to a new state corresponding to LR
1273 * state YYLRSTATE, at input position YYPOSN, with the (unresolved)
1274 * semantic value of YYRHS under the action for YYRULE. */
1276 yyglrShiftDefer (yyGLRStack
* yystackp
, size_t yyk
, yyStateNum yylrState
,
1277 size_t yyposn
, yyGLRState
* yyrhs
, yyRuleNum yyrule
)
1279 yyGLRState
* yynewState
= &yynewGLRStackItem (yystackp
, yytrue
)->yystate
;
1281 yynewState
->yylrState
= yylrState
;
1282 yynewState
->yyposn
= yyposn
;
1283 yynewState
->yyresolved
= yyfalse
;
1284 yynewState
->yypred
= yystackp
->yytops
.yystates
[yyk
];
1285 yynewState
->yysemantics
.yyfirstVal
= YY_NULL
;
1286 yystackp
->yytops
.yystates
[yyk
] = yynewState
;
1288 /* Invokes YY_RESERVE_GLRSTACK. */
1289 yyaddDeferredAction (yystackp
, yyk
, yynewState
, yyrhs
, yyrule
);
1293 # define YY_REDUCE_PRINT(Args)
1295 # define YY_REDUCE_PRINT(Args) \
1298 yy_reduce_print Args; \
1301 /*----------------------------------------------------------------------.
1302 | Report that stack #YYK of *YYSTACKP is going to be reduced by YYRULE. |
1303 `----------------------------------------------------------------------*/
1305 /*ARGSUSED*/ static inline void
1306 yy_reduce_print (int yynormal
, yyGLRStackItem
* yyvsp
, size_t yyk
,
1307 yyRuleNum yyrule
]b4_user_formals
[)
1309 int yynrhs
= yyrhsLength (yyrule
);]b4_locations_if([
1312 YYFPRINTF (stderr
, "Reducing stack %lu by rule %d (line %lu):\n",
1313 (unsigned long int) yyk
, yyrule
- 1,
1314 (unsigned long int) yyrline
[yyrule
]);
1316 yyfillin (yyvsp
, 1, -yynrhs
);
1317 /* The symbols being reduced. */
1318 for (yyi
= 0; yyi
< yynrhs
; yyi
++)
1320 YYFPRINTF (stderr
, " $%d = ", yyi
+ 1);
1321 yy_symbol_print (stderr
,
1322 yystos
[yyvsp
[yyi
- yynrhs
+ 1].yystate
.yylrState
],
1323 &yyvsp
[yyi
- yynrhs
+ 1].yystate
.yysemantics
.yysval
1324 ]b4_locations_if([, &]b4_rhs_location(yynrhs
, yyi
+ 1))[]dnl
1326 if (!yyvsp
[yyi
- yynrhs
+ 1].yystate
.yyresolved
)
1327 YYFPRINTF (stderr
, " (unresolved)");
1328 YYFPRINTF (stderr
, "\n");
1333 /** Pop the symbols consumed by reduction #YYRULE from the top of stack
1334 * #YYK of *YYSTACKP, and perform the appropriate semantic action on their
1335 * semantic values. Assumes that all ambiguities in semantic values
1336 * have been previously resolved. Set *YYVALP to the resulting value,
1337 * and *YYLOCP to the computed location (if any). Return value is as
1338 * for userAction. */
1339 static inline YYRESULTTAG
1340 yydoAction (yyGLRStack
* yystackp
, size_t yyk
, yyRuleNum yyrule
,
1341 YYSTYPE
* yyvalp
]b4_locuser_formals
[)
1343 int yynrhs
= yyrhsLength (yyrule
);
1345 if (yystackp
->yysplitPoint
== YY_NULL
)
1347 /* Standard special case: single stack. */
1348 yyGLRStackItem
* yyrhs
= (yyGLRStackItem
*) yystackp
->yytops
.yystates
[yyk
];
1349 YYASSERT (yyk
== 0);
1350 yystackp
->yynextFree
-= yynrhs
;
1351 yystackp
->yyspaceLeft
+= yynrhs
;
1352 yystackp
->yytops
.yystates
[0] = & yystackp
->yynextFree
[-1].yystate
;
1353 YY_REDUCE_PRINT ((1, yyrhs
, yyk
, yyrule
]b4_user_args
[));
1354 return yyuserAction (yyrule
, yynrhs
, yyrhs
, yystackp
,
1355 yyvalp
]b4_locuser_args
[);
1361 yyGLRStackItem yyrhsVals
[YYMAXRHS
+ YYMAXLEFT
+ 1];
1362 yys
= yyrhsVals
[YYMAXRHS
+ YYMAXLEFT
].yystate
.yypred
1363 = yystackp
->yytops
.yystates
[yyk
];]b4_locations_if([[
1365 /* Set default location. */
1366 yyrhsVals
[YYMAXRHS
+ YYMAXLEFT
- 1].yystate
.yyloc
= yys
->yyloc
;]])[
1367 for (yyi
= 0; yyi
< yynrhs
; yyi
+= 1)
1372 yyupdateSplit (yystackp
, yys
);
1373 yystackp
->yytops
.yystates
[yyk
] = yys
;
1374 YY_REDUCE_PRINT ((0, yyrhsVals
+ YYMAXRHS
+ YYMAXLEFT
- 1, yyk
, yyrule
]b4_user_args
[));
1375 return yyuserAction (yyrule
, yynrhs
, yyrhsVals
+ YYMAXRHS
+ YYMAXLEFT
- 1,
1376 yystackp
, yyvalp
]b4_locuser_args
[);
1380 /** Pop items off stack #YYK of *YYSTACKP according to grammar rule YYRULE,
1381 * and push back on the resulting nonterminal symbol. Perform the
1382 * semantic action associated with YYRULE and store its value with the
1383 * newly pushed state, if YYFORCEEVAL or if *YYSTACKP is currently
1384 * unambiguous. Otherwise, store the deferred semantic action with
1385 * the new state. If the new state would have an identical input
1386 * position, LR state, and predecessor to an existing state on the stack,
1387 * it is identified with that existing state, eliminating stack #YYK from
1388 * *YYSTACKP. In this case, the semantic value is
1389 * added to the options for the existing state's semantic value.
1391 static inline YYRESULTTAG
1392 yyglrReduce (yyGLRStack
* yystackp
, size_t yyk
, yyRuleNum yyrule
,
1393 yybool yyforceEval
]b4_user_formals
[)
1395 size_t yyposn
= yystackp
->yytops
.yystates
[yyk
]->yyposn
;
1397 if (yyforceEval
|| yystackp
->yysplitPoint
== YY_NULL
)
1400 YYSTYPE yysval
;]b4_locations_if([
1403 yyflag
= yydoAction (yystackp
, yyk
, yyrule
, &yysval
]b4_locuser_args([&yyloc
])[);
1404 if (yyflag
== yyerr
&& yystackp
->yysplitPoint
!= YY_NULL
)
1406 YYDPRINTF ((stderr
, "Parse on stack %lu rejected by rule #%d.\n",
1407 (unsigned long int) yyk
, yyrule
- 1));
1411 YY_SYMBOL_PRINT ("-> $$ =", yyr1
[yyrule
], &yysval
, &yyloc
);
1412 yyglrShift (yystackp
, yyk
,
1413 yyLRgotoState (yystackp
->yytops
.yystates
[yyk
]->yylrState
,
1414 yylhsNonterm (yyrule
)),
1415 yyposn
, &yysval
]b4_locations_if([, &yyloc
])[);
1421 yyGLRState
* yys
, *yys0
= yystackp
->yytops
.yystates
[yyk
];
1422 yyStateNum yynewLRState
;
1424 for (yys
= yystackp
->yytops
.yystates
[yyk
], yyn
= yyrhsLength (yyrule
);
1430 yyupdateSplit (yystackp
, yys
);
1431 yynewLRState
= yyLRgotoState (yys
->yylrState
, yylhsNonterm (yyrule
));
1433 "Reduced stack %lu by rule #%d; action deferred. "
1434 "Now in state %d.\n",
1435 (unsigned long int) yyk
, yyrule
- 1, yynewLRState
));
1436 for (yyi
= 0; yyi
< yystackp
->yytops
.yysize
; yyi
+= 1)
1437 if (yyi
!= yyk
&& yystackp
->yytops
.yystates
[yyi
] != YY_NULL
)
1439 yyGLRState
*yysplit
= yystackp
->yysplitPoint
;
1440 yyGLRState
*yyp
= yystackp
->yytops
.yystates
[yyi
];
1441 while (yyp
!= yys
&& yyp
!= yysplit
&& yyp
->yyposn
>= yyposn
)
1443 if (yyp
->yylrState
== yynewLRState
&& yyp
->yypred
== yys
)
1445 yyaddDeferredAction (yystackp
, yyk
, yyp
, yys0
, yyrule
);
1446 yymarkStackDeleted (yystackp
, yyk
);
1447 YYDPRINTF ((stderr
, "Merging stack %lu into stack %lu.\n",
1448 (unsigned long int) yyk
,
1449 (unsigned long int) yyi
));
1455 yystackp
->yytops
.yystates
[yyk
] = yys
;
1456 yyglrShiftDefer (yystackp
, yyk
, yynewLRState
, yyposn
, yys0
, yyrule
);
1462 yysplitStack (yyGLRStack
* yystackp
, size_t yyk
)
1464 if (yystackp
->yysplitPoint
== YY_NULL
)
1466 YYASSERT (yyk
== 0);
1467 yystackp
->yysplitPoint
= yystackp
->yytops
.yystates
[yyk
];
1469 if (yystackp
->yytops
.yysize
>= yystackp
->yytops
.yycapacity
)
1471 yyGLRState
** yynewStates
;
1472 yybool
* yynewLookaheadNeeds
;
1474 yynewStates
= YY_NULL
;
1476 if (yystackp
->yytops
.yycapacity
1477 > (YYSIZEMAX
/ (2 * sizeof yynewStates
[0])))
1478 yyMemoryExhausted (yystackp
);
1479 yystackp
->yytops
.yycapacity
*= 2;
1482 (yyGLRState
**) YYREALLOC (yystackp
->yytops
.yystates
,
1483 (yystackp
->yytops
.yycapacity
1484 * sizeof yynewStates
[0]));
1485 if (yynewStates
== YY_NULL
)
1486 yyMemoryExhausted (yystackp
);
1487 yystackp
->yytops
.yystates
= yynewStates
;
1489 yynewLookaheadNeeds
=
1490 (yybool
*) YYREALLOC (yystackp
->yytops
.yylookaheadNeeds
,
1491 (yystackp
->yytops
.yycapacity
1492 * sizeof yynewLookaheadNeeds
[0]));
1493 if (yynewLookaheadNeeds
== YY_NULL
)
1494 yyMemoryExhausted (yystackp
);
1495 yystackp
->yytops
.yylookaheadNeeds
= yynewLookaheadNeeds
;
1497 yystackp
->yytops
.yystates
[yystackp
->yytops
.yysize
]
1498 = yystackp
->yytops
.yystates
[yyk
];
1499 yystackp
->yytops
.yylookaheadNeeds
[yystackp
->yytops
.yysize
]
1500 = yystackp
->yytops
.yylookaheadNeeds
[yyk
];
1501 yystackp
->yytops
.yysize
+= 1;
1502 return yystackp
->yytops
.yysize
-1;
1505 /** True iff YYY0 and YYY1 represent identical options at the top level.
1506 * That is, they represent the same rule applied to RHS symbols
1507 * that produce the same terminal symbols. */
1509 yyidenticalOptions (yySemanticOption
* yyy0
, yySemanticOption
* yyy1
)
1511 if (yyy0
->yyrule
== yyy1
->yyrule
)
1513 yyGLRState
*yys0
, *yys1
;
1515 for (yys0
= yyy0
->yystate
, yys1
= yyy1
->yystate
,
1516 yyn
= yyrhsLength (yyy0
->yyrule
);
1518 yys0
= yys0
->yypred
, yys1
= yys1
->yypred
, yyn
-= 1)
1519 if (yys0
->yyposn
!= yys1
->yyposn
)
1527 /** Assuming identicalOptions (YYY0,YYY1), destructively merge the
1528 * alternative semantic values for the RHS-symbols of YYY1 and YYY0. */
1530 yymergeOptionSets (yySemanticOption
* yyy0
, yySemanticOption
* yyy1
)
1532 yyGLRState
*yys0
, *yys1
;
1534 for (yys0
= yyy0
->yystate
, yys1
= yyy1
->yystate
,
1535 yyn
= yyrhsLength (yyy0
->yyrule
);
1537 yys0
= yys0
->yypred
, yys1
= yys1
->yypred
, yyn
-= 1)
1541 else if (yys0
->yyresolved
)
1543 yys1
->yyresolved
= yytrue
;
1544 yys1
->yysemantics
.yysval
= yys0
->yysemantics
.yysval
;
1546 else if (yys1
->yyresolved
)
1548 yys0
->yyresolved
= yytrue
;
1549 yys0
->yysemantics
.yysval
= yys1
->yysemantics
.yysval
;
1553 yySemanticOption
** yyz0p
= &yys0
->yysemantics
.yyfirstVal
;
1554 yySemanticOption
* yyz1
= yys1
->yysemantics
.yyfirstVal
;
1555 while (YYID (yytrue
))
1557 if (yyz1
== *yyz0p
|| yyz1
== YY_NULL
)
1559 else if (*yyz0p
== YY_NULL
)
1564 else if (*yyz0p
< yyz1
)
1566 yySemanticOption
* yyz
= *yyz0p
;
1568 yyz1
= yyz1
->yynext
;
1569 (*yyz0p
)->yynext
= yyz
;
1571 yyz0p
= &(*yyz0p
)->yynext
;
1573 yys1
->yysemantics
.yyfirstVal
= yys0
->yysemantics
.yyfirstVal
;
1578 /** Y0 and Y1 represent two possible actions to take in a given
1579 * parsing state; return 0 if no combination is possible,
1580 * 1 if user-mergeable, 2 if Y0 is preferred, 3 if Y1 is preferred. */
1582 yypreference (yySemanticOption
* y0
, yySemanticOption
* y1
)
1584 yyRuleNum r0
= y0
->yyrule
, r1
= y1
->yyrule
;
1585 int p0
= yydprec
[r0
], p1
= yydprec
[r1
];
1589 if (yymerger
[r0
] == 0 || yymerger
[r0
] != yymerger
[r1
])
1594 if (p0
== 0 || p1
== 0)
1603 static YYRESULTTAG
yyresolveValue (yyGLRState
* yys
,
1604 yyGLRStack
* yystackp
]b4_user_formals
[);
1607 /** Resolve the previous YYN states starting at and including state YYS
1608 * on *YYSTACKP. If result != yyok, some states may have been left
1609 * unresolved possibly with empty semantic option chains. Regardless
1610 * of whether result = yyok, each state has been left with consistent
1611 * data so that yydestroyGLRState can be invoked if necessary. */
1613 yyresolveStates (yyGLRState
* yys
, int yyn
,
1614 yyGLRStack
* yystackp
]b4_user_formals
[)
1618 YYASSERT (yys
->yypred
);
1619 YYCHK (yyresolveStates (yys
->yypred
, yyn
-1, yystackp
]b4_user_args
[));
1620 if (! yys
->yyresolved
)
1621 YYCHK (yyresolveValue (yys
, yystackp
]b4_user_args
[));
1626 /** Resolve the states for the RHS of YYOPT on *YYSTACKP, perform its
1627 * user action, and return the semantic value and location in *YYVALP
1628 * and *YYLOCP. Regardless of whether result = yyok, all RHS states
1629 * have been destroyed (assuming the user action destroys all RHS
1630 * semantic values if invoked). */
1632 yyresolveAction (yySemanticOption
* yyopt
, yyGLRStack
* yystackp
,
1633 YYSTYPE
* yyvalp
]b4_locuser_formals
[)
1635 yyGLRStackItem yyrhsVals
[YYMAXRHS
+ YYMAXLEFT
+ 1];
1636 int yynrhs
= yyrhsLength (yyopt
->yyrule
);
1637 YYRESULTTAG yyflag
=
1638 yyresolveStates (yyopt
->yystate
, yynrhs
, yystackp
]b4_user_args
[);
1642 for (yys
= yyopt
->yystate
; yynrhs
> 0; yys
= yys
->yypred
, yynrhs
-= 1)
1643 yydestroyGLRState ("Cleanup: popping", yys
]b4_user_args
[);
1647 yyrhsVals
[YYMAXRHS
+ YYMAXLEFT
].yystate
.yypred
= yyopt
->yystate
;]b4_locations_if([[
1649 /* Set default location. */
1650 yyrhsVals
[YYMAXRHS
+ YYMAXLEFT
- 1].yystate
.yyloc
= yyopt
->yystate
->yyloc
;]])[
1652 int yychar_current
= yychar
;
1653 YYSTYPE yylval_current
= yylval
;]b4_locations_if([
1654 YYLTYPE yylloc_current
= yylloc
;])[
1655 yychar
= yyopt
->yyrawchar
;
1656 yylval
= yyopt
->yyval
;]b4_locations_if([
1657 yylloc
= yyopt
->yyloc
;])[
1658 yyflag
= yyuserAction (yyopt
->yyrule
, yynrhs
,
1659 yyrhsVals
+ YYMAXRHS
+ YYMAXLEFT
- 1,
1660 yystackp
, yyvalp
]b4_locuser_args
[);
1661 yychar
= yychar_current
;
1662 yylval
= yylval_current
;]b4_locations_if([
1663 yylloc
= yylloc_current
;])[
1670 yyreportTree (yySemanticOption
* yyx
, int yyindent
)
1672 int yynrhs
= yyrhsLength (yyx
->yyrule
);
1675 yyGLRState
* yystates
[1 + YYMAXRHS
];
1676 yyGLRState yyleftmost_state
;
1678 for (yyi
= yynrhs
, yys
= yyx
->yystate
; 0 < yyi
; yyi
-= 1, yys
= yys
->yypred
)
1679 yystates
[yyi
] = yys
;
1682 yyleftmost_state
.yyposn
= 0;
1683 yystates
[0] = &yyleftmost_state
;
1688 if (yyx
->yystate
->yyposn
< yys
->yyposn
+ 1)
1689 YYFPRINTF (stderr
, "%*s%s -> <Rule %d, empty>\n",
1690 yyindent
, "", yytokenName (yylhsNonterm (yyx
->yyrule
)),
1693 YYFPRINTF (stderr
, "%*s%s -> <Rule %d, tokens %lu .. %lu>\n",
1694 yyindent
, "", yytokenName (yylhsNonterm (yyx
->yyrule
)),
1695 yyx
->yyrule
- 1, (unsigned long int) (yys
->yyposn
+ 1),
1696 (unsigned long int) yyx
->yystate
->yyposn
);
1697 for (yyi
= 1; yyi
<= yynrhs
; yyi
+= 1)
1699 if (yystates
[yyi
]->yyresolved
)
1701 if (yystates
[yyi
-1]->yyposn
+1 > yystates
[yyi
]->yyposn
)
1702 YYFPRINTF (stderr
, "%*s%s <empty>\n", yyindent
+2, "",
1703 yytokenName (yystos
[yystates
[yyi
]->yylrState
]));
1705 YYFPRINTF (stderr
, "%*s%s <tokens %lu .. %lu>\n", yyindent
+2, "",
1706 yytokenName (yystos
[yystates
[yyi
]->yylrState
]),
1707 (unsigned long int) (yystates
[yyi
-1]->yyposn
+ 1),
1708 (unsigned long int) yystates
[yyi
]->yyposn
);
1711 yyreportTree (yystates
[yyi
]->yysemantics
.yyfirstVal
, yyindent
+2);
1716 /*ARGSUSED*/ static YYRESULTTAG
1717 yyreportAmbiguity (yySemanticOption
* yyx0
,
1718 yySemanticOption
* yyx1
]b4_pure_formals
[)
1724 YYFPRINTF (stderr
, "Ambiguity detected.\n");
1725 YYFPRINTF (stderr
, "Option 1,\n");
1726 yyreportTree (yyx0
, 2);
1727 YYFPRINTF (stderr
, "\nOption 2,\n");
1728 yyreportTree (yyx1
, 2);
1729 YYFPRINTF (stderr
, "\n");
1732 yyerror (]b4_yyerror_args
[YY_("syntax is ambiguous"));
1734 }]b4_locations_if([[
1736 /** Resolve the locations for each of the YYN1 states in *YYSTACKP,
1737 * ending at YYS1. Has no effect on previously resolved states.
1738 * The first semantic option of a state is always chosen. */
1740 yyresolveLocations (yyGLRState
* yys1
, int yyn1
,
1741 yyGLRStack
*yystackp
]b4_user_formals
[)
1745 yyresolveLocations (yys1
->yypred
, yyn1
- 1, yystackp
]b4_user_args
[);
1746 if (!yys1
->yyresolved
)
1748 yyGLRStackItem yyrhsloc
[1 + YYMAXRHS
];
1750 yySemanticOption
*yyoption
= yys1
->yysemantics
.yyfirstVal
;
1751 YYASSERT (yyoption
!= YY_NULL
);
1752 yynrhs
= yyrhsLength (yyoption
->yyrule
);
1757 yyresolveLocations (yyoption
->yystate
, yynrhs
,
1758 yystackp
]b4_user_args
[);
1759 for (yys
= yyoption
->yystate
, yyn
= yynrhs
;
1761 yys
= yys
->yypred
, yyn
-= 1)
1762 yyrhsloc
[yyn
].yystate
.yyloc
= yys
->yyloc
;
1766 /* Both yyresolveAction and yyresolveLocations traverse the GSS
1767 in reverse rightmost order. It is only necessary to invoke
1768 yyresolveLocations on a subforest for which yyresolveAction
1769 would have been invoked next had an ambiguity not been
1770 detected. Thus the location of the previous state (but not
1771 necessarily the previous state itself) is guaranteed to be
1772 resolved already. */
1773 yyGLRState
*yyprevious
= yyoption
->yystate
;
1774 yyrhsloc
[0].yystate
.yyloc
= yyprevious
->yyloc
;
1777 int yychar_current
= yychar
;
1778 YYSTYPE yylval_current
= yylval
;
1779 YYLTYPE yylloc_current
= yylloc
;
1780 yychar
= yyoption
->yyrawchar
;
1781 yylval
= yyoption
->yyval
;
1782 yylloc
= yyoption
->yyloc
;
1783 YYLLOC_DEFAULT ((yys1
->yyloc
), yyrhsloc
, yynrhs
);
1784 yychar
= yychar_current
;
1785 yylval
= yylval_current
;
1786 yylloc
= yylloc_current
;
1792 /** Resolve the ambiguity represented in state YYS in *YYSTACKP,
1793 * perform the indicated actions, and set the semantic value of YYS.
1794 * If result != yyok, the chain of semantic options in YYS has been
1795 * cleared instead or it has been left unmodified except that
1796 * redundant options may have been removed. Regardless of whether
1797 * result = yyok, YYS has been left with consistent data so that
1798 * yydestroyGLRState can be invoked if necessary. */
1800 yyresolveValue (yyGLRState
* yys
, yyGLRStack
* yystackp
]b4_user_formals
[)
1802 yySemanticOption
* yyoptionList
= yys
->yysemantics
.yyfirstVal
;
1803 yySemanticOption
* yybest
= yyoptionList
;
1804 yySemanticOption
** yypp
;
1805 yybool yymerge
= yyfalse
;
1807 YYRESULTTAG yyflag
;]b4_locations_if([
1808 YYLTYPE
*yylocp
= &yys
->yyloc
;])[
1810 for (yypp
= &yyoptionList
->yynext
; *yypp
!= YY_NULL
; )
1812 yySemanticOption
* yyp
= *yypp
;
1814 if (yyidenticalOptions (yybest
, yyp
))
1816 yymergeOptionSets (yybest
, yyp
);
1817 *yypp
= yyp
->yynext
;
1821 switch (yypreference (yybest
, yyp
))
1823 case 0:]b4_locations_if([[
1824 yyresolveLocations (yys
, 1, yystackp
]b4_user_args
[);]])[
1825 return yyreportAmbiguity (yybest
, yyp
]b4_pure_args
[);
1837 /* This cannot happen so it is not worth a YYASSERT (yyfalse),
1838 but some compilers complain if the default case is
1842 yypp
= &yyp
->yynext
;
1848 yySemanticOption
* yyp
;
1849 int yyprec
= yydprec
[yybest
->yyrule
];
1850 yyflag
= yyresolveAction (yybest
, yystackp
, &yysval
]b4_locuser_args
[);
1852 for (yyp
= yybest
->yynext
; yyp
!= YY_NULL
; yyp
= yyp
->yynext
)
1854 if (yyprec
== yydprec
[yyp
->yyrule
])
1856 YYSTYPE yysval_other
;]b4_locations_if([
1858 yyflag
= yyresolveAction (yyp
, yystackp
, &yysval_other
]b4_locuser_args([&yydummy
])[);
1861 yydestruct ("Cleanup: discarding incompletely merged value for",
1862 yystos
[yys
->yylrState
],
1863 &yysval
]b4_locuser_args
[);
1866 yyuserMerge (yymerger
[yyp
->yyrule
], &yysval
, &yysval_other
);
1871 yyflag
= yyresolveAction (yybest
, yystackp
, &yysval
]b4_locuser_args([yylocp
])[);
1875 yys
->yyresolved
= yytrue
;
1876 yys
->yysemantics
.yysval
= yysval
;
1879 yys
->yysemantics
.yyfirstVal
= YY_NULL
;
1884 yyresolveStack (yyGLRStack
* yystackp
]b4_user_formals
[)
1886 if (yystackp
->yysplitPoint
!= YY_NULL
)
1891 for (yyn
= 0, yys
= yystackp
->yytops
.yystates
[0];
1892 yys
!= yystackp
->yysplitPoint
;
1893 yys
= yys
->yypred
, yyn
+= 1)
1895 YYCHK (yyresolveStates (yystackp
->yytops
.yystates
[0], yyn
, yystackp
1902 yycompressStack (yyGLRStack
* yystackp
)
1904 yyGLRState
* yyp
, *yyq
, *yyr
;
1906 if (yystackp
->yytops
.yysize
!= 1 || yystackp
->yysplitPoint
== YY_NULL
)
1909 for (yyp
= yystackp
->yytops
.yystates
[0], yyq
= yyp
->yypred
, yyr
= YY_NULL
;
1910 yyp
!= yystackp
->yysplitPoint
;
1911 yyr
= yyp
, yyp
= yyq
, yyq
= yyp
->yypred
)
1914 yystackp
->yyspaceLeft
+= yystackp
->yynextFree
- yystackp
->yyitems
;
1915 yystackp
->yynextFree
= ((yyGLRStackItem
*) yystackp
->yysplitPoint
) + 1;
1916 yystackp
->yyspaceLeft
-= yystackp
->yynextFree
- yystackp
->yyitems
;
1917 yystackp
->yysplitPoint
= YY_NULL
;
1918 yystackp
->yylastDeleted
= YY_NULL
;
1920 while (yyr
!= YY_NULL
)
1922 yystackp
->yynextFree
->yystate
= *yyr
;
1924 yystackp
->yynextFree
->yystate
.yypred
= &yystackp
->yynextFree
[-1].yystate
;
1925 yystackp
->yytops
.yystates
[0] = &yystackp
->yynextFree
->yystate
;
1926 yystackp
->yynextFree
+= 1;
1927 yystackp
->yyspaceLeft
-= 1;
1932 yyprocessOneStack (yyGLRStack
* yystackp
, size_t yyk
,
1933 size_t yyposn
]b4_pure_formals
[)
1935 while (yystackp
->yytops
.yystates
[yyk
] != YY_NULL
)
1937 yyStateNum yystate
= yystackp
->yytops
.yystates
[yyk
]->yylrState
;
1938 YYDPRINTF ((stderr
, "Stack %lu Entering state %d\n",
1939 (unsigned long int) yyk
, yystate
));
1941 YYASSERT (yystate
!= YYFINAL
);
1943 if (yyisDefaultedState (yystate
))
1946 yyRuleNum yyrule
= yydefaultAction (yystate
);
1949 YYDPRINTF ((stderr
, "Stack %lu dies.\n",
1950 (unsigned long int) yyk
));
1951 yymarkStackDeleted (yystackp
, yyk
);
1954 yyflag
= yyglrReduce (yystackp
, yyk
, yyrule
, yyimmediate
[yyrule
]]b4_user_args
[);
1955 if (yyflag
== yyerr
)
1959 "(predicate failure or explicit user error).\n",
1960 (unsigned long int) yyk
));
1961 yymarkStackDeleted (yystackp
, yyk
);
1971 const short int* yyconflicts
;
1973 yystackp
->yytops
.yylookaheadNeeds
[yyk
] = yytrue
;
1974 if (yychar
== YYEMPTY
)
1976 YYDPRINTF ((stderr
, "Reading a token: "));
1980 if (yychar
<= YYEOF
)
1982 yychar
= yytoken
= YYEOF
;
1983 YYDPRINTF ((stderr
, "Now at end of input.\n"));
1987 yytoken
= YYTRANSLATE (yychar
);
1988 YY_SYMBOL_PRINT ("Next token is", yytoken
, &yylval
, &yylloc
);
1991 yygetLRActions (yystate
, yytoken
, &yyaction
, &yyconflicts
);
1993 while (*yyconflicts
!= 0)
1996 size_t yynewStack
= yysplitStack (yystackp
, yyk
);
1997 YYDPRINTF ((stderr
, "Splitting off stack %lu from %lu.\n",
1998 (unsigned long int) yynewStack
,
1999 (unsigned long int) yyk
));
2000 yyflag
= yyglrReduce (yystackp
, yynewStack
,
2002 yyimmediate
[*yyconflicts
]]b4_user_args
[);
2004 YYCHK (yyprocessOneStack (yystackp
, yynewStack
,
2005 yyposn
]b4_pure_args
[));
2006 else if (yyflag
== yyerr
)
2008 YYDPRINTF ((stderr
, "Stack %lu dies.\n",
2009 (unsigned long int) yynewStack
));
2010 yymarkStackDeleted (yystackp
, yynewStack
);
2017 if (yyisShiftAction (yyaction
))
2019 else if (yyisErrorAction (yyaction
))
2021 YYDPRINTF ((stderr
, "Stack %lu dies.\n",
2022 (unsigned long int) yyk
));
2023 yymarkStackDeleted (yystackp
, yyk
);
2028 YYRESULTTAG yyflag
= yyglrReduce (yystackp
, yyk
, -yyaction
,
2029 yyimmediate
[-yyaction
]]b4_user_args
[);
2030 if (yyflag
== yyerr
)
2034 "(predicate failure or explicit user error).\n",
2035 (unsigned long int) yyk
));
2036 yymarkStackDeleted (yystackp
, yyk
);
2039 else if (yyflag
!= yyok
)
2047 /*ARGSUSED*/ static void
2048 yyreportSyntaxError (yyGLRStack
* yystackp
]b4_user_formals
[)
2050 if (yystackp
->yyerrState
!= 0)
2052 #if ! YYERROR_VERBOSE
2053 yyerror (]b4_lyyerror_args
[YY_("syntax error"));
2055 yySymbol yytoken
= yychar
== YYEMPTY
? YYEMPTY
: YYTRANSLATE (yychar
);
2056 size_t yysize0
= yytnamerr (YY_NULL
, yytokenName (yytoken
));
2057 size_t yysize
= yysize0
;
2059 yybool yysize_overflow
= yyfalse
;
2060 char* yymsg
= YY_NULL
;
2061 enum { YYERROR_VERBOSE_ARGS_MAXIMUM
= 5 };
2062 /* Internationalized format string. */
2063 const char *yyformat
= YY_NULL
;
2064 /* Arguments of yyformat. */
2065 char const *yyarg
[YYERROR_VERBOSE_ARGS_MAXIMUM
];
2066 /* Number of reported tokens (one for the "unexpected", one per
2070 /* There are many possibilities here to consider:
2071 - If this state is a consistent state with a default action, then
2072 the only way this function was invoked is if the default action
2073 is an error action. In that case, don't check for expected
2074 tokens because there are none.
2075 - The only way there can be no lookahead present (in yychar) is if
2076 this state is a consistent state with a default action. Thus,
2077 detecting the absence of a lookahead is sufficient to determine
2078 that there is no unexpected or expected token to report. In that
2079 case, just report a simple "syntax error".
2080 - Don't assume there isn't a lookahead just because this state is a
2081 consistent state with a default action. There might have been a
2082 previous inconsistent state, consistent state with a non-default
2083 action, or user semantic action that manipulated yychar.
2084 - Of course, the expected token list depends on states to have
2085 correct lookahead information, and it depends on the parser not
2086 to perform extra reductions after fetching a lookahead from the
2087 scanner and before detecting a syntax error. Thus, state merging
2088 (from LALR or IELR) and default reductions corrupt the expected
2089 token list. However, the list is correct for canonical LR with
2090 one exception: it will still contain any token that will not be
2091 accepted due to an error action in a later state.
2093 if (yytoken
!= YYEMPTY
)
2095 int yyn
= yypact
[yystackp
->yytops
.yystates
[0]->yylrState
];
2096 yyarg
[yycount
++] = yytokenName (yytoken
);
2097 if (!yypact_value_is_default (yyn
))
2099 /* Start YYX at -YYN if negative to avoid negative indexes in
2100 YYCHECK. In other words, skip the first -YYN actions for this
2101 state because they are default actions. */
2102 int yyxbegin
= yyn
< 0 ? -yyn
: 0;
2103 /* Stay within bounds of both yycheck and yytname. */
2104 int yychecklim
= YYLAST
- yyn
+ 1;
2105 int yyxend
= yychecklim
< YYNTOKENS
? yychecklim
: YYNTOKENS
;
2107 for (yyx
= yyxbegin
; yyx
< yyxend
; ++yyx
)
2108 if (yycheck
[yyx
+ yyn
] == yyx
&& yyx
!= YYTERROR
2109 && !yytable_value_is_error (yytable
[yyx
+ yyn
]))
2111 if (yycount
== YYERROR_VERBOSE_ARGS_MAXIMUM
)
2117 yyarg
[yycount
++] = yytokenName (yyx
);
2118 yysize1
= yysize
+ yytnamerr (YY_NULL
, yytokenName (yyx
));
2119 yysize_overflow
|= yysize1
< yysize
;
2127 #define YYCASE_(N, S) \
2131 YYCASE_(0, YY_("syntax error"));
2132 YYCASE_(1, YY_("syntax error, unexpected %s"));
2133 YYCASE_(2, YY_("syntax error, unexpected %s, expecting %s"));
2134 YYCASE_(3, YY_("syntax error, unexpected %s, expecting %s or %s"));
2135 YYCASE_(4, YY_("syntax error, unexpected %s, expecting %s or %s or %s"));
2136 YYCASE_(5, YY_("syntax error, unexpected %s, expecting %s or %s or %s or %s"));
2140 yysize1
= yysize
+ strlen (yyformat
);
2141 yysize_overflow
|= yysize1
< yysize
;
2144 if (!yysize_overflow
)
2145 yymsg
= (char *) YYMALLOC (yysize
);
2151 while ((*yyp
= *yyformat
))
2153 if (*yyp
== '%' && yyformat
[1] == 's' && yyi
< yycount
)
2155 yyp
+= yytnamerr (yyp
, yyarg
[yyi
++]);
2164 yyerror (]b4_lyyerror_args
[yymsg
);
2169 yyerror (]b4_lyyerror_args
[YY_("syntax error"));
2170 yyMemoryExhausted (yystackp
);
2172 #endif /* YYERROR_VERBOSE */
2176 /* Recover from a syntax error on *YYSTACKP, assuming that *YYSTACKP->YYTOKENP,
2177 yylval, and yylloc are the syntactic category, semantic value, and location
2178 of the lookahead. */
2179 /*ARGSUSED*/ static void
2180 yyrecoverSyntaxError (yyGLRStack
* yystackp
]b4_user_formals
[)
2185 if (yystackp
->yyerrState
== 3)
2186 /* We just shifted the error token and (perhaps) took some
2187 reductions. Skip tokens until we can proceed. */
2188 while (YYID (yytrue
))
2191 if (yychar
== YYEOF
)
2192 yyFail (yystackp
][]b4_lpure_args
[, YY_NULL
);
2193 if (yychar
!= YYEMPTY
)
2194 {]b4_locations_if([[
2195 /* We throw away the lookahead, but the error range
2196 of the shifted error token must take it into account. */
2197 yyGLRState
*yys
= yystackp
->yytops
.yystates
[0];
2198 yyGLRStackItem yyerror_range
[3];
2199 yyerror_range
[1].yystate
.yyloc
= yys
->yyloc
;
2200 yyerror_range
[2].yystate
.yyloc
= yylloc
;
2201 YYLLOC_DEFAULT ((yys
->yyloc
), yyerror_range
, 2);]])[
2202 yytoken
= YYTRANSLATE (yychar
);
2203 yydestruct ("Error: discarding",
2204 yytoken
, &yylval
]b4_locuser_args([&yylloc
])[);
2206 YYDPRINTF ((stderr
, "Reading a token: "));
2208 if (yychar
<= YYEOF
)
2210 yychar
= yytoken
= YYEOF
;
2211 YYDPRINTF ((stderr
, "Now at end of input.\n"));
2215 yytoken
= YYTRANSLATE (yychar
);
2216 YY_SYMBOL_PRINT ("Next token is", yytoken
, &yylval
, &yylloc
);
2218 yyj
= yypact
[yystackp
->yytops
.yystates
[0]->yylrState
];
2219 if (yypact_value_is_default (yyj
))
2222 if (yyj
< 0 || YYLAST
< yyj
|| yycheck
[yyj
] != yytoken
)
2224 if (yydefact
[yystackp
->yytops
.yystates
[0]->yylrState
] != 0)
2227 else if (! yytable_value_is_error (yytable
[yyj
]))
2231 /* Reduce to one stack. */
2232 for (yyk
= 0; yyk
< yystackp
->yytops
.yysize
; yyk
+= 1)
2233 if (yystackp
->yytops
.yystates
[yyk
] != YY_NULL
)
2235 if (yyk
>= yystackp
->yytops
.yysize
)
2236 yyFail (yystackp
][]b4_lpure_args
[, YY_NULL
);
2237 for (yyk
+= 1; yyk
< yystackp
->yytops
.yysize
; yyk
+= 1)
2238 yymarkStackDeleted (yystackp
, yyk
);
2239 yyremoveDeletes (yystackp
);
2240 yycompressStack (yystackp
);
2242 /* Now pop stack until we find a state that shifts the error token. */
2243 yystackp
->yyerrState
= 3;
2244 while (yystackp
->yytops
.yystates
[0] != YY_NULL
)
2246 yyGLRState
*yys
= yystackp
->yytops
.yystates
[0];
2247 yyj
= yypact
[yys
->yylrState
];
2248 if (! yypact_value_is_default (yyj
))
2251 if (0 <= yyj
&& yyj
<= YYLAST
&& yycheck
[yyj
] == YYTERROR
2252 && yyisShiftAction (yytable
[yyj
]))
2254 /* Shift the error token. */]b4_locations_if([[
2255 /* First adjust its location.*/
2257 yystackp
->yyerror_range
[2].yystate
.yyloc
= yylloc
;
2258 YYLLOC_DEFAULT (yyerrloc
, (yystackp
->yyerror_range
), 2);]])[
2259 YY_SYMBOL_PRINT ("Shifting", yystos
[yytable
[yyj
]],
2260 &yylval
, &yyerrloc
);
2261 yyglrShift (yystackp
, 0, yytable
[yyj
],
2262 yys
->yyposn
, &yylval
]b4_locations_if([, &yyerrloc
])[);
2263 yys
= yystackp
->yytops
.yystates
[0];
2266 }]b4_locations_if([[
2267 yystackp
->yyerror_range
[1].yystate
.yyloc
= yys
->yyloc
;]])[
2268 if (yys
->yypred
!= YY_NULL
)
2269 yydestroyGLRState ("Error: popping", yys
]b4_user_args
[);
2270 yystackp
->yytops
.yystates
[0] = yys
->yypred
;
2271 yystackp
->yynextFree
-= 1;
2272 yystackp
->yyspaceLeft
+= 1;
2274 if (yystackp
->yytops
.yystates
[0] == YY_NULL
)
2275 yyFail (yystackp
][]b4_lpure_args
[, YY_NULL
);
2278 #define YYCHK1(YYE) \
2288 goto yyuser_error; \
2298 ]b4_c_ansi_function_def([yyparse
], [int], b4_parse_param
)[
2302 yyGLRStack
* const yystackp
= &yystack
;
2305 YYDPRINTF ((stderr
, "Starting parse\n"));
2308 yylval
= yyval_default
;
2310 #if defined YYLTYPE_IS_TRIVIAL && YYLTYPE_IS_TRIVIAL
2311 yylloc
.first_line
= yylloc
.last_line
= ]b4_location_initial_line
[;
2312 yylloc
.first_column
= yylloc
.last_column
= ]b4_location_initial_column
[;
2315 m4_ifdef([b4_initial_action
], [
2316 m4_pushdef([b4_at_dollar
], [yylloc
])dnl
2317 m4_pushdef([b4_dollar_dollar
], [yylval
])dnl
2318 /* User initialization code. */
2319 b4_user_initial_action
2320 m4_popdef([b4_dollar_dollar
])dnl
2321 m4_popdef([b4_at_dollar
])])dnl
2323 if (! yyinitGLRStack (yystackp
, YYINITDEPTH
))
2324 goto yyexhaustedlab
;
2325 switch (YYSETJMP (yystack
.yyexception_buffer
))
2328 case 1: goto yyabortlab
;
2329 case 2: goto yyexhaustedlab
;
2330 default: goto yybuglab
;
2332 yyglrShift (&yystack
, 0, 0, 0, &yylval
]b4_locations_if([, &yylloc
])[);
2335 while (YYID (yytrue
))
2337 /* For efficiency, we have two loops, the first of which is
2338 specialized to deterministic operation (single stack, no
2339 potential ambiguity). */
2341 while (YYID (yytrue
))
2345 const short int* yyconflicts
;
2347 yyStateNum yystate
= yystack
.yytops
.yystates
[0]->yylrState
;
2348 YYDPRINTF ((stderr
, "Entering state %d\n", yystate
));
2349 if (yystate
== YYFINAL
)
2351 if (yyisDefaultedState (yystate
))
2353 yyrule
= yydefaultAction (yystate
);
2356 ]b4_locations_if([[ yystack
.yyerror_range
[1].yystate
.yyloc
= yylloc
;]])[
2357 yyreportSyntaxError (&yystack
]b4_user_args
[);
2360 YYCHK1 (yyglrReduce (&yystack
, 0, yyrule
, yytrue
]b4_user_args
[));
2365 if (yychar
== YYEMPTY
)
2367 YYDPRINTF ((stderr
, "Reading a token: "));
2371 if (yychar
<= YYEOF
)
2373 yychar
= yytoken
= YYEOF
;
2374 YYDPRINTF ((stderr
, "Now at end of input.\n"));
2378 yytoken
= YYTRANSLATE (yychar
);
2379 YY_SYMBOL_PRINT ("Next token is", yytoken
, &yylval
, &yylloc
);
2382 yygetLRActions (yystate
, yytoken
, &yyaction
, &yyconflicts
);
2383 if (*yyconflicts
!= 0)
2385 if (yyisShiftAction (yyaction
))
2387 YY_SYMBOL_PRINT ("Shifting", yytoken
, &yylval
, &yylloc
);
2390 yyglrShift (&yystack
, 0, yyaction
, yyposn
, &yylval
]b4_locations_if([, &yylloc
])[);
2391 if (0 < yystack
.yyerrState
)
2392 yystack
.yyerrState
-= 1;
2394 else if (yyisErrorAction (yyaction
))
2396 ]b4_locations_if([[ yystack
.yyerror_range
[1].yystate
.yyloc
= yylloc
;]])[
2397 yyreportSyntaxError (&yystack
]b4_user_args
[);
2401 YYCHK1 (yyglrReduce (&yystack
, 0, -yyaction
, yytrue
]b4_user_args
[));
2405 while (YYID (yytrue
))
2407 yySymbol yytoken_to_shift
;
2410 for (yys
= 0; yys
< yystack
.yytops
.yysize
; yys
+= 1)
2411 yystackp
->yytops
.yylookaheadNeeds
[yys
] = yychar
!= YYEMPTY
;
2413 /* yyprocessOneStack returns one of three things:
2415 - An error flag. If the caller is yyprocessOneStack, it
2416 immediately returns as well. When the caller is finally
2417 yyparse, it jumps to an error label via YYCHK1.
2419 - yyok, but yyprocessOneStack has invoked yymarkStackDeleted
2420 (&yystack, yys), which sets the top state of yys to NULL. Thus,
2421 yyparse's following invocation of yyremoveDeletes will remove
2424 - yyok, when ready to shift a token.
2426 Except in the first case, yyparse will invoke yyremoveDeletes and
2427 then shift the next token onto all remaining stacks. This
2428 synchronization of the shift (that is, after all preceding
2429 reductions on all stacks) helps prevent double destructor calls
2430 on yylval in the event of memory exhaustion. */
2432 for (yys
= 0; yys
< yystack
.yytops
.yysize
; yys
+= 1)
2433 YYCHK1 (yyprocessOneStack (&yystack
, yys
, yyposn
]b4_lpure_args
[));
2434 yyremoveDeletes (&yystack
);
2435 if (yystack
.yytops
.yysize
== 0)
2437 yyundeleteLastStack (&yystack
);
2438 if (yystack
.yytops
.yysize
== 0)
2439 yyFail (&yystack
][]b4_lpure_args
[, YY_("syntax error"));
2440 YYCHK1 (yyresolveStack (&yystack
]b4_user_args
[));
2441 YYDPRINTF ((stderr
, "Returning to deterministic operation.\n"));
2442 ]b4_locations_if([[ yystack
.yyerror_range
[1].yystate
.yyloc
= yylloc
;]])[
2443 yyreportSyntaxError (&yystack
]b4_user_args
[);
2447 /* If any yyglrShift call fails, it will fail after shifting. Thus,
2448 a copy of yylval will already be on stack 0 in the event of a
2449 failure in the following loop. Thus, yychar is set to YYEMPTY
2450 before the loop to make sure the user destructor for yylval isn't
2452 yytoken_to_shift
= YYTRANSLATE (yychar
);
2455 for (yys
= 0; yys
< yystack
.yytops
.yysize
; yys
+= 1)
2458 const short int* yyconflicts
;
2459 yyStateNum yystate
= yystack
.yytops
.yystates
[yys
]->yylrState
;
2460 yygetLRActions (yystate
, yytoken_to_shift
, &yyaction
,
2462 /* Note that yyconflicts were handled by yyprocessOneStack. */
2463 YYDPRINTF ((stderr
, "On stack %lu, ", (unsigned long int) yys
));
2464 YY_SYMBOL_PRINT ("shifting", yytoken_to_shift
, &yylval
, &yylloc
);
2465 yyglrShift (&yystack
, yys
, yyaction
, yyposn
,
2466 &yylval
]b4_locations_if([, &yylloc
])[);
2467 YYDPRINTF ((stderr
, "Stack %lu now in state #%d\n",
2468 (unsigned long int) yys
,
2469 yystack
.yytops
.yystates
[yys
]->yylrState
));
2472 if (yystack
.yytops
.yysize
== 1)
2474 YYCHK1 (yyresolveStack (&yystack
]b4_user_args
[));
2475 YYDPRINTF ((stderr
, "Returning to deterministic operation.\n"));
2476 yycompressStack (&yystack
);
2482 yyrecoverSyntaxError (&yystack
]b4_user_args
[);
2483 yyposn
= yystack
.yytops
.yystates
[0]->yyposn
;
2499 yyerror (]b4_lyyerror_args
[YY_("memory exhausted"));
2504 if (yychar
!= YYEMPTY
)
2505 yydestruct ("Cleanup: discarding lookahead",
2506 YYTRANSLATE (yychar
), &yylval
]b4_locuser_args([&yylloc
])[);
2508 /* If the stack is well-formed, pop the stack until it is empty,
2509 destroying its entries as we go. But free the stack regardless
2510 of whether it is well-formed. */
2511 if (yystack
.yyitems
)
2513 yyGLRState
** yystates
= yystack
.yytops
.yystates
;
2516 size_t yysize
= yystack
.yytops
.yysize
;
2518 for (yyk
= 0; yyk
< yysize
; yyk
+= 1)
2521 while (yystates
[yyk
])
2523 yyGLRState
*yys
= yystates
[yyk
];
2524 ]b4_locations_if([[ yystack
.yyerror_range
[1].yystate
.yyloc
= yys
->yyloc
;]]
2525 )[ if (yys
->yypred
!= YY_NULL
)
2526 yydestroyGLRState ("Cleanup: popping", yys
]b4_user_args
[);
2527 yystates
[yyk
] = yys
->yypred
;
2528 yystack
.yynextFree
-= 1;
2529 yystack
.yyspaceLeft
+= 1;
2534 yyfreeGLRStack (&yystack
);
2537 /* Make sure YYID is used. */
2538 return YYID (yyresult
);
2541 /* DEBUGGING ONLY */
2543 static void yypstack (yyGLRStack
* yystackp
, size_t yyk
)
2544 __attribute__ ((__unused__
));
2545 static void yypdumpstack (yyGLRStack
* yystackp
) __attribute__ ((__unused__
));
2548 yy_yypstack (yyGLRState
* yys
)
2552 yy_yypstack (yys
->yypred
);
2553 YYFPRINTF (stderr
, " -> ");
2555 YYFPRINTF (stderr
, "%d@@%lu", yys
->yylrState
,
2556 (unsigned long int) yys
->yyposn
);
2560 yypstates (yyGLRState
* yyst
)
2562 if (yyst
== YY_NULL
)
2563 YYFPRINTF (stderr
, "<null>");
2566 YYFPRINTF (stderr
, "\n");
2570 yypstack (yyGLRStack
* yystackp
, size_t yyk
)
2572 yypstates (yystackp
->yytops
.yystates
[yyk
]);
2575 #define YYINDEX(YYX) \
2576 ((YYX) == YY_NULL ? -1 : (yyGLRStackItem*) (YYX) - yystackp->yyitems)
2580 yypdumpstack (yyGLRStack
* yystackp
)
2582 yyGLRStackItem
* yyp
;
2584 for (yyp
= yystackp
->yyitems
; yyp
< yystackp
->yynextFree
; yyp
+= 1)
2586 YYFPRINTF (stderr
, "%3lu. ",
2587 (unsigned long int) (yyp
- yystackp
->yyitems
));
2588 if (*(yybool
*) yyp
)
2590 YYFPRINTF (stderr
, "Res: %d, LR State: %d, posn: %lu, pred: %ld",
2591 yyp
->yystate
.yyresolved
, yyp
->yystate
.yylrState
,
2592 (unsigned long int) yyp
->yystate
.yyposn
,
2593 (long int) YYINDEX (yyp
->yystate
.yypred
));
2594 if (! yyp
->yystate
.yyresolved
)
2595 YYFPRINTF (stderr
, ", firstVal: %ld",
2596 (long int) YYINDEX (yyp
->yystate
2597 .yysemantics
.yyfirstVal
));
2601 YYFPRINTF (stderr
, "Option. rule: %d, state: %ld, next: %ld",
2602 yyp
->yyoption
.yyrule
- 1,
2603 (long int) YYINDEX (yyp
->yyoption
.yystate
),
2604 (long int) YYINDEX (yyp
->yyoption
.yynext
));
2606 YYFPRINTF (stderr
, "\n");
2608 YYFPRINTF (stderr
, "Tops:");
2609 for (yyi
= 0; yyi
< yystackp
->yytops
.yysize
; yyi
+= 1)
2610 YYFPRINTF (stderr
, "%lu: %ld; ", (unsigned long int) yyi
,
2611 (long int) YYINDEX (yystackp
->yytops
.yystates
[yyi
]));
2612 YYFPRINTF (stderr
, "\n");
2617 dnl glr
.cc produces its own header
.
2619 m4_if(b4_skeleton
, ["glr.c"],
2621 [@
output(b4_spec_defines_file@
)@
2622 b4_copyright([Skeleton interface
for Bison GLR parsers in C
],
2625 ]b4_cpp_guard_open([b4_spec_defines_file
])[
2626 ]b4_shared_declarations
[
2627 ]b4_cpp_guard_close([b4_spec_defines_file
])[