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 # If we are loaded by glr.cc, do not override c++.m4 definitions by
23 m4_if(b4_skeleton
, ["glr.c"],
24 [m4_include(b4_pkgdatadir
/[c
.m4
])])
26 ## ---------------- ##
28 ## ---------------- ##
31 m4_define_default([b4_stack_depth_max
], [10000])
32 m4_define_default([b4_stack_depth_init
], [200])
36 ## ------------------------ ##
37 ## Pure/impure interfaces. ##
38 ## ------------------------ ##
40 b4_define_flag_if([pure
])
41 # If glr.cc is including this file and thus has already set b4_pure_flag,
42 # do not change the value of b4_pure_flag, and do not record a use of api.pure.
43 m4_ifndef([b4_pure_flag
],
44 [b4_percent_define_default([[api
.pure
]], [[false]])
45 m4_define([b4_pure_flag
],
46 [b4_percent_define_flag_if([[api
.pure
]], [[1]], [[0]])])])
50 # The possible parse-params formal arguments preceded by a comma.
52 # This is not shared with yacc.c in c.m4 because GLR relies on ISO C
53 # formal argument declarations.
54 m4_define([b4_user_formals
],
55 [m4_ifset([b4_parse_param
], [, b4_c_ansi_formals(b4_parse_param
)])])
60 # Accumule in b4_lex_param all the yylex arguments.
61 # Yes, this is quite ugly...
62 m4_define([b4_lex_param
],
63 m4_dquote(b4_pure_if([[[[YYSTYPE
*]], [[&yylval
]]][]dnl
64 b4_locations_if([, [[YYLTYPE
*], [&yylloc
]]])])dnl
65 m4_ifdef([b4_lex_param
], [, ]b4_lex_param
)))
70 # Optional effective arguments passed to yyerror: user args plus yylloc, and
72 m4_define([b4_yyerror_args
],
73 [b4_pure_if([b4_locations_if([yylocp
, ])])dnl
74 m4_ifset([b4_parse_param
], [b4_c_args(b4_parse_param
), ])])
79 # Same as above, but on the lookahead, hence &yylloc instead of yylocp.
80 m4_define([b4_lyyerror_args
],
81 [b4_pure_if([b4_locations_if([&yylloc
, ])])dnl
82 m4_ifset([b4_parse_param
], [b4_c_args(b4_parse_param
), ])])
87 # Same as b4_yyerror_args, but with a leading comma.
88 m4_define([b4_pure_args
],
89 [b4_pure_if([b4_locations_if([, yylocp
])])[]b4_user_args
])
94 # Same as above, but on the lookahead, hence &yylloc instead of yylocp.
95 m4_define([b4_lpure_args
],
96 [b4_pure_if([b4_locations_if([, &yylloc
])])[]b4_user_args
])
102 # Arguments passed to yyerror: user formals plus yylocp with leading comma.
103 m4_define([b4_pure_formals
],
104 [b4_pure_if([b4_locations_if([, YYLTYPE
*yylocp
])])[]b4_user_formals
])
107 # b4_locuser_formals(LOC = yylocp)
108 # --------------------------------
109 m4_define([b4_locuser_formals
],
110 [b4_locations_if([, YYLTYPE
*m4_default([$
1], [yylocp
])])[]b4_user_formals
])
113 # b4_locuser_args(LOC = yylocp)
114 # -----------------------------
115 m4_define([b4_locuser_args
],
116 [b4_locations_if([, m4_default([$
1], [yylocp
])])[]b4_user_args
])
120 ## ----------------- ##
121 ## Semantic Values. ##
122 ## ----------------- ##
125 # b4_lhs_value([TYPE])
126 # --------------------
127 # Expansion of $<TYPE>$.
128 m4_define([b4_lhs_value
],
129 [((*yyvalp
)[]m4_ifval([$
1], [.$
1]))])
132 # b4_rhs_value(RULE-LENGTH, NUM, [TYPE])
133 # --------------------------------------
134 # Expansion of $<TYPE>NUM, where the current rule has RULE-LENGTH
136 m4_define([b4_rhs_value
],
137 [(((yyGLRStackItem
const *)yyvsp
)@
{YYFILL (($
2) - ($
1))@
}.yystate
.yysemantics
.yysval
[]m4_ifval([$
3], [.$
3]))])
148 m4_define([b4_lhs_location
],
152 # b4_rhs_location(RULE-LENGTH, NUM)
153 # ---------------------------------
154 # Expansion of @NUM, where the current rule has RULE-LENGTH symbols
156 m4_define([b4_rhs_location
],
157 [(((yyGLRStackItem
const *)yyvsp
)@
{YYFILL (($
2) - ($
1))@
}.yystate
.yyloc
)])
164 # b4_shared_declarations
165 # ----------------------
166 # Declaration that might either go into the header (if --defines)
167 # or open coded in the parser body.
168 m4_define([b4_shared_declarations
],
170 ]b4_percent_code_get([[requires]])[
171 ]b4_token_enums(b4_tokens
)[
172 ]b4_declare_yylstype
[
173 ]b4_c_ansi_function_decl(b4_prefix
[parse
], [int], b4_parse_param
)[
174 ]b4_percent_code_get([[provides]])[]dnl
182 # We do want M4 expansion after # for CPP macros.
185 @
output(b4_parser_file_name@
)@
186 b4_copyright([Skeleton implementation
for Bison GLR parsers in C
],
189 /* C GLR parser skeleton written by Paul Hilfinger. */
193 b4_percent_code_get([[top]])[
194 ]m4_if(b4_api_prefix
, [yy
], [],
195 [[/* Substitute the type names. */
196 #define YYSTYPE ]b4_api_PREFIX[STYPE]b4_locations_if([[
197 #define YYLTYPE ]b4_api_PREFIX[LTYPE]])])[
198 ]m4_if(b4_prefix
, [yy
], [],
199 [[/* Substitute the variable and function names. */
200 #define yyparse ]b4_prefix[parse
201 #define yylex ]b4_prefix[lex
202 #define yyerror ]b4_prefix[error
203 #define yylval ]b4_prefix[lval
204 #define yychar ]b4_prefix[char
205 #define yydebug ]b4_prefix[debug
206 #define yynerrs ]b4_prefix[nerrs]b4_locations_if([[
207 #define yylloc ]b4_prefix[lloc]])])[
209 /* Copy the first part of user declarations. */
210 ]b4_user_pre_prologue
[
214 ]b4_defines_if([[#include "@basename(]b4_spec_defines_file[@)"]],
215 [b4_shared_declarations
])[
217 /* Enabling verbose error messages. */
218 #ifdef YYERROR_VERBOSE
219 # undef YYERROR_VERBOSE
220 # define YYERROR_VERBOSE 1
222 # define YYERROR_VERBOSE ]b4_error_verbose_flag[
225 /* Default (constant) value used for initialization for null
226 right-hand sides. Unlike the standard yacc.c template,
227 here we set the default value of $$ to a zeroed-out value.
228 Since the default value is undefined, this behavior is
229 technically correct. */
230 static YYSTYPE yyval_default
;
232 /* Copy the second part of user declarations. */
233 ]b4_user_post_prologue
234 b4_percent_code_get
[]dnl
241 # if defined YYENABLE_NLS && YYENABLE_NLS
243 # include <libintl.h> /* INFRINGES ON USER NAME SPACE */
244 # define YY_(msgid) dgettext ("bison-runtime", msgid)
248 # define YY_(msgid) msgid
252 /* Suppress unused-variable warnings by "using" E. */
253 #if ! defined lint || defined __GNUC__
254 # define YYUSE(e) ((void) (e))
256 # define YYUSE(e) /* empty */
259 /* Identity function, used to suppress warnings about constant conditions. */
263 ]b4_c_function_def([YYID
], [static int], [[int i
], [i
]])[
273 # define YYMALLOC malloc
276 # define YYREALLOC realloc
279 #define YYSIZEMAX ((size_t) -1)
284 typedef unsigned char yybool
;
291 # define YYJMP_BUF jmp_buf
292 # define YYSETJMP(env) setjmp (env)
293 # define YYLONGJMP(env, val) longjmp (env, val)
300 #ifndef __attribute__
301 /* This feature is available in gcc versions 2.5 and later. */
302 # if (! defined __GNUC__ || __GNUC__ < 2 \
303 || (__GNUC__ == 2 && __GNUC_MINOR__ < 5))
304 # define __attribute__(Spec) /* empty */
308 ]b4_locations_if([#define YYOPTIONAL_LOC(Name) Name],[
310 # define YYOPTIONAL_LOC(Name) /* empty */
312 # define YYOPTIONAL_LOC(Name) Name __attribute__ ((__unused__))
316 # define YYASSERT(condition) ((void) ((condition) || (abort (), 0)))
319 /* YYFINAL -- State number of the termination state. */
320 #define YYFINAL ]b4_final_state_number[
321 /* YYLAST -- Last index in YYTABLE. */
322 #define YYLAST ]b4_last[
324 /* YYNTOKENS -- Number of terminals. */
325 #define YYNTOKENS ]b4_tokens_number[
326 /* YYNNTS -- Number of nonterminals. */
327 #define YYNNTS ]b4_nterms_number[
328 /* YYNRULES -- Number of rules. */
329 #define YYNRULES ]b4_rules_number[
330 /* YYNRULES -- Number of states. */
331 #define YYNSTATES ]b4_states_number[
332 /* YYMAXRHS -- Maximum number of symbols on right-hand side of rule. */
333 #define YYMAXRHS ]b4_r2_max[
334 /* YYMAXLEFT -- Maximum number of symbols to the left of a handle
335 accessed by $0, $-1, etc., in any rule. */
336 #define YYMAXLEFT ]b4_max_left_semantic_context[
338 /* YYTRANSLATE(X) -- Bison symbol number corresponding to X. */
339 #define YYUNDEFTOK ]b4_undef_token_number[
340 #define YYMAXUTOK ]b4_user_token_number_max[
342 #define YYTRANSLATE(YYX) \
343 ((unsigned int) (YYX) <= YYMAXUTOK ? yytranslate[YYX] : YYUNDEFTOK)
345 /* YYTRANSLATE[YYLEX] -- Bison symbol number corresponding to YYLEX. */
346 static const ]b4_int_type_for([b4_translate
])[ yytranslate
[] =
351 #if ]b4_api_PREFIX[DEBUG
352 /* YYPRHS[YYN] -- Index of the first RHS symbol of rule number YYN in
354 static const ]b4_int_type_for([b4_prhs
])[ yyprhs
[] =
359 /* YYRHS -- A `-1'-separated list of the rules' RHS. */
360 static const ]b4_int_type_for([b4_rhs
])[ yyrhs
[] =
365 /* YYRLINE[YYN] -- source line where rule number YYN was defined. */
366 static const ]b4_int_type_for([b4_rline
])[ yyrline
[] =
372 #if ]b4_api_PREFIX[DEBUG || YYERROR_VERBOSE || ]b4_token_table_flag[
373 /* YYTNAME[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM.
374 First, the terminals, then, starting at YYNTOKENS, nonterminals. */
375 static const char *const yytname
[] =
381 /* YYR1[YYN] -- Symbol number of symbol that rule YYN derives. */
382 static const ]b4_int_type_for([b4_r1
])[ yyr1
[] =
387 /* YYR2[YYN] -- Number of symbols composing right hand side of rule YYN. */
388 static const ]b4_int_type_for([b4_r2
])[ yyr2
[] =
393 /* YYDPREC[RULE-NUM] -- Dynamic precedence of rule #RULE-NUM (0 if none). */
394 static const ]b4_int_type_for([b4_dprec
])[ yydprec
[] =
399 /* YYMERGER[RULE-NUM] -- Index of merging function for rule #RULE-NUM. */
400 static const ]b4_int_type_for([b4_merger
])[ yymerger
[] =
405 /* YYDEFACT[S] -- default reduction number in state S. Performed when
406 YYTABLE doesn't specify something else to do. Zero means the default
408 static const ]b4_int_type_for([b4_defact
])[ yydefact
[] =
413 /* YYPDEFGOTO[NTERM-NUM]. */
414 static const ]b4_int_type_for([b4_defgoto
])[ yydefgoto
[] =
419 /* YYPACT[STATE-NUM] -- Index in YYTABLE of the portion describing
421 #define YYPACT_NINF ]b4_pact_ninf[
422 static const ]b4_int_type_for([b4_pact
])[ yypact
[] =
427 /* YYPGOTO[NTERM-NUM]. */
428 static const ]b4_int_type_for([b4_pgoto
])[ yypgoto
[] =
433 /* YYTABLE[YYPACT[STATE-NUM]]. What to do in state STATE-NUM. If
434 positive, shift that token. If negative, reduce the rule which
435 number is the opposite. If YYTABLE_NINF, syntax error. */
436 #define YYTABLE_NINF ]b4_table_ninf[
437 static const ]b4_int_type_for([b4_table
])[ yytable
[] =
442 /* YYCONFLP[YYPACT[STATE-NUM]] -- Pointer into YYCONFL of start of
443 list of conflicting reductions corresponding to action entry for
444 state STATE-NUM in yytable. 0 means no conflicts. The list in
445 yyconfl is terminated by a rule number of 0. */
446 static const ]b4_int_type_for([b4_conflict_list_heads
])[ yyconflp
[] =
448 ]b4_conflict_list_heads
[
451 /* YYCONFL[I] -- lists of conflicting rule numbers, each terminated by
452 0, pointed into by YYCONFLP. */
453 ]dnl Do
not use b4_int_type_for here
, since there are places where
454 dnl pointers onto yyconfl are taken
, which type is
"short int *".
455 dnl We probably ought to introduce a type
for confl
.
456 [static const short int yyconfl
[] =
458 ]b4_conflicting_rules
[
461 static const ]b4_int_type_for([b4_check
])[ yycheck
[] =
466 /* YYSTOS[STATE-NUM] -- The (internal number of the) accessing
467 symbol of state STATE-NUM. */
468 static const ]b4_int_type_for([b4_stos
])[ yystos
[] =
473 /* Error token number */
477 #ifndef YYLLOC_DEFAULT
478 ]b4_yylloc_default_define
[
479 # define YYRHSLOC(Rhs, K) ((Rhs)[K].yystate.yyloc)
481 /* YY_LOCATION_PRINT -- Print the location on the stream.
482 This macro was not mandated originally: define only if we know
483 we won't break user code: when these are the locations we know. */
485 # define YY_LOCATION_PRINT(File, Loc) \
486 fprintf (File, "%d.%d-%d.%d", \
487 (Loc).first_line, (Loc).first_column, \
488 (Loc).last_line, (Loc).last_column)
491 #ifndef YYLLOC_DEFAULT
492 # define YYLLOC_DEFAULT(Current, Rhs, N) ((void) 0)
496 #ifndef YY_LOCATION_PRINT
497 # define YY_LOCATION_PRINT(File, Loc) ((void) 0)
500 /* YYLEX -- calling `yylex' with the right arguments. */
501 #define YYLEX ]b4_c_function_call([yylex], [int], b4_lex_param)[
506 #define yynerrs (yystackp->yyerrcnt)
508 #define yychar (yystackp->yyrawchar)
510 #define yylval (yystackp->yyval)
512 #define yylloc (yystackp->yyloc)
513 m4_if(b4_prefix
[], [yy
], [],
514 [#define b4_prefix[]nerrs yynerrs
515 #define b4_prefix[]char yychar
516 #define b4_prefix[]lval yylval
517 #define b4_prefix[]lloc yylloc])],
518 [YYSTYPE yylval
;]b4_locations_if([[
524 static const int YYEOF
= 0;
525 static const int YYEMPTY
= -2;
527 typedef enum { yyok
, yyaccept
, yyabort
, yyerr
} YYRESULTTAG
;
530 do { YYRESULTTAG yyflag = YYE; if (yyflag != yyok) return yyflag; } \
533 #if ]b4_api_PREFIX[DEBUG
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. */
561 #else /* !]b4_api_PREFIX[DEBUG */
563 # define YYDPRINTF(Args)
564 # define YY_SYMBOL_PRINT(Title, Type, Value, Location)
566 #endif /* !]b4_api_PREFIX[DEBUG */
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 # if (! defined __cplusplus \
593 || (]b4_locations_if([[defined ]b4_api_PREFIX[LTYPE_IS_TRIVIAL && ]b4_api_PREFIX[LTYPE_IS_TRIVIAL \
594 && ]])[defined ]b4_api_PREFIX[STYPE_IS_TRIVIAL && ]b4_api_PREFIX[STYPE_IS_TRIVIAL))
595 # define YYSTACKEXPANDABLE 1
597 # define YYSTACKEXPANDABLE 0
601 #if YYSTACKEXPANDABLE
602 # define YY_RESERVE_GLRSTACK(Yystack) \
604 if (Yystack->yyspaceLeft < YYHEADROOM) \
605 yyexpandGLRStack (Yystack); \
608 # define YY_RESERVE_GLRSTACK(Yystack) \
610 if (Yystack->yyspaceLeft < YYHEADROOM) \
611 yyMemoryExhausted (Yystack); \
619 # if defined __GLIBC__ && defined _STRING_H && defined _GNU_SOURCE
620 # define yystpcpy stpcpy
622 /* Copy YYSRC to YYDEST, returning the address of the terminating '\0' in
625 yystpcpy (char *yydest
, const char *yysrc
)
628 const char *yys
= yysrc
;
630 while ((*yyd
++ = *yys
++) != '\0')
639 /* Copy to YYRES the contents of YYSTR after stripping away unnecessary
640 quotes and backslashes, so that it's suitable for yyerror. The
641 heuristic is that double-quoting is unnecessary unless the string
642 contains an apostrophe, a comma, or backslash (other than
643 backslash-backslash). YYSTR is taken from yytname. If YYRES is
644 null, do not copy; instead, return the length of what the result
647 yytnamerr (char *yyres
, const char *yystr
)
652 char const *yyp
= yystr
;
659 goto do_not_strip_quotes
;
663 goto do_not_strip_quotes
;
676 do_not_strip_quotes
: ;
680 return strlen (yystr
);
682 return yystpcpy (yyres
, yystr
) - yyres
;
686 #endif /* !YYERROR_VERBOSE */
688 /** State numbers, as in LALR(1) machine */
689 typedef int yyStateNum
;
691 /** Rule numbers, as in LALR(1) machine */
692 typedef int yyRuleNum
;
694 /** Grammar symbol */
695 typedef short int yySymbol
;
697 /** Item references, as in LALR(1) machine */
698 typedef short int yyItemNum
;
700 typedef struct yyGLRState yyGLRState
;
701 typedef struct yyGLRStateSet yyGLRStateSet
;
702 typedef struct yySemanticOption yySemanticOption
;
703 typedef union yyGLRStackItem yyGLRStackItem
;
704 typedef struct yyGLRStack yyGLRStack
;
707 /** Type tag: always true. */
709 /** Type tag for yysemantics. If true, yysval applies, otherwise
710 * yyfirstVal applies. */
712 /** Number of corresponding LALR(1) machine state. */
713 yyStateNum yylrState
;
714 /** Preceding state in this stack */
716 /** Source position of the first token produced by my symbol */
719 /** First in a chain of alternative reductions producing the
720 * non-terminal corresponding to this state, threaded through
722 yySemanticOption
* yyfirstVal
;
723 /** Semantic value for this state. */
725 } yysemantics
;]b4_locations_if([[
726 /** Source location for this state. */
730 struct yyGLRStateSet
{
731 yyGLRState
** yystates
;
732 /** During nondeterministic operation, yylookaheadNeeds tracks which
733 * stacks have actually needed the current lookahead. During deterministic
734 * operation, yylookaheadNeeds[0] is not maintained since it would merely
735 * duplicate yychar != YYEMPTY. */
736 yybool
* yylookaheadNeeds
;
737 size_t yysize
, yycapacity
;
740 struct yySemanticOption
{
741 /** Type tag: always false. */
743 /** Rule number for this reduction */
745 /** The last RHS state in the list of states to be reduced. */
747 /** The lookahead for this reduction. */
749 YYSTYPE yyval
;]b4_locations_if([[
751 /** Next sibling in chain of options. To facilitate merging,
752 * options are chained in decreasing order by address. */
753 yySemanticOption
* yynext
;
756 /** Type of the items in the GLR stack. The yyisState field
757 * indicates which item of the union is valid. */
758 union yyGLRStackItem
{
760 yySemanticOption yyoption
;
765 ]b4_locations_if([[ /* To compute the location of the error token. */
766 yyGLRStackItem yyerror_range
[3];]])[
771 YYSTYPE yyval
;]b4_locations_if([[
774 YYJMP_BUF yyexception_buffer
;
775 yyGLRStackItem
* yyitems
;
776 yyGLRStackItem
* yynextFree
;
778 yyGLRState
* yysplitPoint
;
779 yyGLRState
* yylastDeleted
;
780 yyGLRStateSet yytops
;
783 #if YYSTACKEXPANDABLE
784 static void yyexpandGLRStack (yyGLRStack
* yystackp
);
787 static void yyFail (yyGLRStack
* yystackp
]b4_pure_formals
[, const char* yymsg
)
788 __attribute__ ((__noreturn__
));
790 yyFail (yyGLRStack
* yystackp
]b4_pure_formals
[, const char* yymsg
)
792 if (yymsg
!= YY_NULL
)
793 yyerror (]b4_yyerror_args
[yymsg
);
794 YYLONGJMP (yystackp
->yyexception_buffer
, 1);
797 static void yyMemoryExhausted (yyGLRStack
* yystackp
)
798 __attribute__ ((__noreturn__
));
800 yyMemoryExhausted (yyGLRStack
* yystackp
)
802 YYLONGJMP (yystackp
->yyexception_buffer
, 2);
805 #if ]b4_api_PREFIX[DEBUG || YYERROR_VERBOSE
806 /** A printable representation of TOKEN. */
807 static inline const char*
808 yytokenName (yySymbol yytoken
)
810 if (yytoken
== YYEMPTY
)
813 return yytname
[yytoken
];
817 /** Fill in YYVSP[YYLOW1 .. YYLOW0-1] from the chain of states starting
818 * at YYVSP[YYLOW0].yystate.yypred. Leaves YYVSP[YYLOW1].yystate.yypred
819 * containing the pointer to the next state in the chain. */
820 static void yyfillin (yyGLRStackItem
*, int, int) __attribute__ ((__unused__
));
822 yyfillin (yyGLRStackItem
*yyvsp
, int yylow0
, int yylow1
)
825 yyGLRState
*s
= yyvsp
[yylow0
].yystate
.yypred
;
826 for (i
= yylow0
-1; i
>= yylow1
; i
-= 1)
828 YYASSERT (s
->yyresolved
);
829 yyvsp
[i
].yystate
.yyresolved
= yytrue
;
830 yyvsp
[i
].yystate
.yysemantics
.yysval
= s
->yysemantics
.yysval
;]b4_locations_if([[
831 yyvsp
[i
].yystate
.yyloc
= s
->yyloc
;]])[
832 s
= yyvsp
[i
].yystate
.yypred
= s
->yypred
;
836 /* Do nothing if YYNORMAL or if *YYLOW <= YYLOW1. Otherwise, fill in
837 * YYVSP[YYLOW1 .. *YYLOW-1] as in yyfillin and set *YYLOW = YYLOW1.
838 * For convenience, always return YYLOW1. */
839 static inline int yyfill (yyGLRStackItem
*, int *, int, yybool
)
840 __attribute__ ((__unused__
));
842 yyfill (yyGLRStackItem
*yyvsp
, int *yylow
, int yylow1
, yybool yynormal
)
844 if (!yynormal
&& yylow1
< *yylow
)
846 yyfillin (yyvsp
, *yylow
, yylow1
);
852 /** Perform user action for rule number YYN, with RHS length YYRHSLEN,
853 * and top stack item YYVSP. YYLVALP points to place to put semantic
854 * value ($$), and yylocp points to place for location information
855 * (@@$). Returns yyok for normal return, yyaccept for YYACCEPT,
856 * yyerr for YYERROR, yyabort for YYABORT. */
857 /*ARGSUSED*/ static YYRESULTTAG
858 yyuserAction (yyRuleNum yyn
, int yyrhslen
, yyGLRStackItem
* yyvsp
,
859 yyGLRStack
* yystackp
,
860 YYSTYPE
* yyvalp
]b4_locuser_formals
[)
862 yybool yynormal
__attribute__ ((__unused__
)) =
863 (yystackp
->yysplitPoint
== YY_NULL
);
865 ]b4_parse_param_use
[]dnl
867 # define yyerrok (yystackp->yyerrState = 0)
869 # define YYACCEPT return yyaccept
871 # define YYABORT return yyabort
873 # define YYERROR return yyerrok, yyerr
875 # define YYRECOVERING() (yystackp->yyerrState != 0)
877 # define yyclearin (yychar = YYEMPTY)
879 # define YYFILL(N) yyfill (yyvsp, &yylow, N, yynormal)
881 # define YYBACKUP(Token, Value) \
882 return yyerror (]b4_yyerror_args[YY_("syntax error: cannot back up")), \
887 *yyvalp
= yyval_default
;
889 *yyvalp
= yyvsp
[YYFILL (1-yyrhslen
)].yystate
.yysemantics
.yysval
;]b4_locations_if([[
890 YYLLOC_DEFAULT ((*yylocp
), (yyvsp
- yyrhslen
), yyrhslen
);
891 yystackp
->yyerror_range
[1].yystate
.yyloc
= *yylocp
;
910 /*ARGSUSED*/ static void
911 yyuserMerge (int yyn
, YYSTYPE
* yy0
, YYSTYPE
* yy1
)
923 /* Bison grammar-table manipulation. */
925 ]b4_yydestruct_generate([b4_c_ansi_function_def
])[
927 /** Number of symbols composing the right hand side of rule #RULE. */
929 yyrhsLength (yyRuleNum yyrule
)
935 yydestroyGLRState (char const *yymsg
, yyGLRState
*yys
]b4_user_formals
[)
938 yydestruct (yymsg
, yystos
[yys
->yylrState
],
939 &yys
->yysemantics
.yysval
]b4_locuser_args([&yys
->yyloc
])[);
942 #if ]b4_api_PREFIX[DEBUG
945 if (yys
->yysemantics
.yyfirstVal
)
946 YYFPRINTF (stderr
, "%s unresolved ", yymsg
);
948 YYFPRINTF (stderr
, "%s incomplete ", yymsg
);
949 yy_symbol_print (stderr
, yystos
[yys
->yylrState
],
950 YY_NULL
]b4_locuser_args([&yys
->yyloc
])[);
951 YYFPRINTF (stderr
, "\n");
955 if (yys
->yysemantics
.yyfirstVal
)
957 yySemanticOption
*yyoption
= yys
->yysemantics
.yyfirstVal
;
960 for (yyrh
= yyoption
->yystate
, yyn
= yyrhsLength (yyoption
->yyrule
);
962 yyrh
= yyrh
->yypred
, yyn
-= 1)
963 yydestroyGLRState (yymsg
, yyrh
]b4_user_args
[);
968 /** Left-hand-side symbol for rule #RULE. */
969 static inline yySymbol
970 yylhsNonterm (yyRuleNum yyrule
)
975 #define yypact_value_is_default(yystate) \
976 ]b4_table_value_equals([[pact]], [[yystate]], [b4_pact_ninf])[
978 /** True iff LR state STATE has only a default reduction (regardless
981 yyisDefaultedState (yyStateNum yystate
)
983 return yypact_value_is_default (yypact
[yystate
]);
986 /** The default reduction for STATE, assuming it has one. */
987 static inline yyRuleNum
988 yydefaultAction (yyStateNum yystate
)
990 return yydefact
[yystate
];
993 #define yytable_value_is_error(yytable_value) \
994 ]b4_table_value_equals([[table]], [[yytable_value]], [b4_table_ninf])[
996 /** Set *YYACTION to the action to take in YYSTATE on seeing YYTOKEN.
998 * R < 0: Reduce on rule -R.
1000 * R > 0: Shift to state R.
1001 * Set *CONFLICTS to a pointer into yyconfl to 0-terminated list of
1002 * conflicting reductions.
1005 yygetLRActions (yyStateNum yystate
, int yytoken
,
1006 int* yyaction
, const short int** yyconflicts
)
1008 int yyindex
= yypact
[yystate
] + yytoken
;
1009 if (yypact_value_is_default (yypact
[yystate
])
1010 || yyindex
< 0 || YYLAST
< yyindex
|| yycheck
[yyindex
] != yytoken
)
1012 *yyaction
= -yydefact
[yystate
];
1013 *yyconflicts
= yyconfl
;
1015 else if (! yytable_value_is_error (yytable
[yyindex
]))
1017 *yyaction
= yytable
[yyindex
];
1018 *yyconflicts
= yyconfl
+ yyconflp
[yyindex
];
1023 *yyconflicts
= yyconfl
+ yyconflp
[yyindex
];
1027 static inline yyStateNum
1028 yyLRgotoState (yyStateNum yystate
, yySymbol yylhs
)
1031 yyr
= yypgoto
[yylhs
- YYNTOKENS
] + yystate
;
1032 if (0 <= yyr
&& yyr
<= YYLAST
&& yycheck
[yyr
] == yystate
)
1033 return yytable
[yyr
];
1035 return yydefgoto
[yylhs
- YYNTOKENS
];
1038 static inline yybool
1039 yyisShiftAction (int yyaction
)
1041 return 0 < yyaction
;
1044 static inline yybool
1045 yyisErrorAction (int yyaction
)
1047 return yyaction
== 0;
1052 /** Return a fresh GLRStackItem. Callers should call
1053 * YY_RESERVE_GLRSTACK afterwards to make sure there is sufficient
1056 static inline yyGLRStackItem
*
1057 yynewGLRStackItem (yyGLRStack
* yystackp
, yybool yyisState
)
1059 yyGLRStackItem
* yynewItem
= yystackp
->yynextFree
;
1060 yystackp
->yyspaceLeft
-= 1;
1061 yystackp
->yynextFree
+= 1;
1062 yynewItem
->yystate
.yyisState
= yyisState
;
1066 /** Add a new semantic action that will execute the action for rule
1067 * RULENUM on the semantic values in RHS to the list of
1068 * alternative actions for STATE. Assumes that RHS comes from
1069 * stack #K of *STACKP. */
1071 yyaddDeferredAction (yyGLRStack
* yystackp
, size_t yyk
, yyGLRState
* yystate
,
1072 yyGLRState
* rhs
, yyRuleNum yyrule
)
1074 yySemanticOption
* yynewOption
=
1075 &yynewGLRStackItem (yystackp
, yyfalse
)->yyoption
;
1076 yynewOption
->yystate
= rhs
;
1077 yynewOption
->yyrule
= yyrule
;
1078 if (yystackp
->yytops
.yylookaheadNeeds
[yyk
])
1080 yynewOption
->yyrawchar
= yychar
;
1081 yynewOption
->yyval
= yylval
;]b4_locations_if([
1082 yynewOption
->yyloc
= yylloc
;])[
1085 yynewOption
->yyrawchar
= YYEMPTY
;
1086 yynewOption
->yynext
= yystate
->yysemantics
.yyfirstVal
;
1087 yystate
->yysemantics
.yyfirstVal
= yynewOption
;
1089 YY_RESERVE_GLRSTACK (yystackp
);
1094 /** Initialize SET to a singleton set containing an empty stack. */
1096 yyinitStateSet (yyGLRStateSet
* yyset
)
1099 yyset
->yycapacity
= 16;
1100 yyset
->yystates
= (yyGLRState
**) YYMALLOC (16 * sizeof yyset
->yystates
[0]);
1101 if (! yyset
->yystates
)
1103 yyset
->yystates
[0] = YY_NULL
;
1104 yyset
->yylookaheadNeeds
=
1105 (yybool
*) YYMALLOC (16 * sizeof yyset
->yylookaheadNeeds
[0]);
1106 if (! yyset
->yylookaheadNeeds
)
1108 YYFREE (yyset
->yystates
);
1114 static void yyfreeStateSet (yyGLRStateSet
* yyset
)
1116 YYFREE (yyset
->yystates
);
1117 YYFREE (yyset
->yylookaheadNeeds
);
1120 /** Initialize STACK to a single empty stack, with total maximum
1121 * capacity for all stacks of SIZE. */
1123 yyinitGLRStack (yyGLRStack
* yystackp
, size_t yysize
)
1125 yystackp
->yyerrState
= 0;
1127 yystackp
->yyspaceLeft
= yysize
;
1129 (yyGLRStackItem
*) YYMALLOC (yysize
* sizeof yystackp
->yynextFree
[0]);
1130 if (!yystackp
->yyitems
)
1132 yystackp
->yynextFree
= yystackp
->yyitems
;
1133 yystackp
->yysplitPoint
= YY_NULL
;
1134 yystackp
->yylastDeleted
= YY_NULL
;
1135 return yyinitStateSet (&yystackp
->yytops
);
1139 #if YYSTACKEXPANDABLE
1140 # define YYRELOC(YYFROMITEMS,YYTOITEMS,YYX,YYTYPE) \
1141 &((YYTOITEMS) - ((YYFROMITEMS) - (yyGLRStackItem*) (YYX)))->YYTYPE
1143 /** If STACK is expandable, extend it. WARNING: Pointers into the
1144 stack from outside should be considered invalid after this call.
1145 We always expand when there are 1 or fewer items left AFTER an
1146 allocation, so that we can avoid having external pointers exist
1147 across an allocation. */
1149 yyexpandGLRStack (yyGLRStack
* yystackp
)
1151 yyGLRStackItem
* yynewItems
;
1152 yyGLRStackItem
* yyp0
, *yyp1
;
1155 size_t yysize
= yystackp
->yynextFree
- yystackp
->yyitems
;
1156 if (YYMAXDEPTH
- YYHEADROOM
< yysize
)
1157 yyMemoryExhausted (yystackp
);
1158 yynewSize
= 2*yysize
;
1159 if (YYMAXDEPTH
< yynewSize
)
1160 yynewSize
= YYMAXDEPTH
;
1161 yynewItems
= (yyGLRStackItem
*) YYMALLOC (yynewSize
* sizeof yynewItems
[0]);
1163 yyMemoryExhausted (yystackp
);
1164 for (yyp0
= yystackp
->yyitems
, yyp1
= yynewItems
, yyn
= yysize
;
1166 yyn
-= 1, yyp0
+= 1, yyp1
+= 1)
1169 if (*(yybool
*) yyp0
)
1171 yyGLRState
* yys0
= &yyp0
->yystate
;
1172 yyGLRState
* yys1
= &yyp1
->yystate
;
1173 if (yys0
->yypred
!= YY_NULL
)
1175 YYRELOC (yyp0
, yyp1
, yys0
->yypred
, yystate
);
1176 if (! yys0
->yyresolved
&& yys0
->yysemantics
.yyfirstVal
!= YY_NULL
)
1177 yys1
->yysemantics
.yyfirstVal
=
1178 YYRELOC (yyp0
, yyp1
, yys0
->yysemantics
.yyfirstVal
, yyoption
);
1182 yySemanticOption
* yyv0
= &yyp0
->yyoption
;
1183 yySemanticOption
* yyv1
= &yyp1
->yyoption
;
1184 if (yyv0
->yystate
!= YY_NULL
)
1185 yyv1
->yystate
= YYRELOC (yyp0
, yyp1
, yyv0
->yystate
, yystate
);
1186 if (yyv0
->yynext
!= YY_NULL
)
1187 yyv1
->yynext
= YYRELOC (yyp0
, yyp1
, yyv0
->yynext
, yyoption
);
1190 if (yystackp
->yysplitPoint
!= YY_NULL
)
1191 yystackp
->yysplitPoint
= YYRELOC (yystackp
->yyitems
, yynewItems
,
1192 yystackp
->yysplitPoint
, yystate
);
1194 for (yyn
= 0; yyn
< yystackp
->yytops
.yysize
; yyn
+= 1)
1195 if (yystackp
->yytops
.yystates
[yyn
] != YY_NULL
)
1196 yystackp
->yytops
.yystates
[yyn
] =
1197 YYRELOC (yystackp
->yyitems
, yynewItems
,
1198 yystackp
->yytops
.yystates
[yyn
], yystate
);
1199 YYFREE (yystackp
->yyitems
);
1200 yystackp
->yyitems
= yynewItems
;
1201 yystackp
->yynextFree
= yynewItems
+ yysize
;
1202 yystackp
->yyspaceLeft
= yynewSize
- yysize
;
1207 yyfreeGLRStack (yyGLRStack
* yystackp
)
1209 YYFREE (yystackp
->yyitems
);
1210 yyfreeStateSet (&yystackp
->yytops
);
1213 /** Assuming that S is a GLRState somewhere on STACK, update the
1214 * splitpoint of STACK, if needed, so that it is at least as deep as
1217 yyupdateSplit (yyGLRStack
* yystackp
, yyGLRState
* yys
)
1219 if (yystackp
->yysplitPoint
!= YY_NULL
&& yystackp
->yysplitPoint
> yys
)
1220 yystackp
->yysplitPoint
= yys
;
1223 /** Invalidate stack #K in STACK. */
1225 yymarkStackDeleted (yyGLRStack
* yystackp
, size_t yyk
)
1227 if (yystackp
->yytops
.yystates
[yyk
] != YY_NULL
)
1228 yystackp
->yylastDeleted
= yystackp
->yytops
.yystates
[yyk
];
1229 yystackp
->yytops
.yystates
[yyk
] = YY_NULL
;
1232 /** Undelete the last stack that was marked as deleted. Can only be
1233 done once after a deletion, and only when all other stacks have
1236 yyundeleteLastStack (yyGLRStack
* yystackp
)
1238 if (yystackp
->yylastDeleted
== YY_NULL
|| yystackp
->yytops
.yysize
!= 0)
1240 yystackp
->yytops
.yystates
[0] = yystackp
->yylastDeleted
;
1241 yystackp
->yytops
.yysize
= 1;
1242 YYDPRINTF ((stderr
, "Restoring last deleted stack as stack #0.\n"));
1243 yystackp
->yylastDeleted
= YY_NULL
;
1247 yyremoveDeletes (yyGLRStack
* yystackp
)
1251 while (yyj
< yystackp
->yytops
.yysize
)
1253 if (yystackp
->yytops
.yystates
[yyi
] == YY_NULL
)
1257 YYDPRINTF ((stderr
, "Removing dead stacks.\n"));
1259 yystackp
->yytops
.yysize
-= 1;
1263 yystackp
->yytops
.yystates
[yyj
] = yystackp
->yytops
.yystates
[yyi
];
1264 /* In the current implementation, it's unnecessary to copy
1265 yystackp->yytops.yylookaheadNeeds[yyi] since, after
1266 yyremoveDeletes returns, the parser immediately either enters
1267 deterministic operation or shifts a token. However, it doesn't
1268 hurt, and the code might evolve to need it. */
1269 yystackp
->yytops
.yylookaheadNeeds
[yyj
] =
1270 yystackp
->yytops
.yylookaheadNeeds
[yyi
];
1273 YYDPRINTF ((stderr
, "Rename stack %lu -> %lu.\n",
1274 (unsigned long int) yyi
, (unsigned long int) yyj
));
1282 /** Shift to a new state on stack #K of STACK, corresponding to LR state
1283 * LRSTATE, at input position POSN, with (resolved) semantic value SVAL. */
1285 yyglrShift (yyGLRStack
* yystackp
, size_t yyk
, yyStateNum yylrState
,
1287 YYSTYPE
* yyvalp
]b4_locations_if([, YYLTYPE
* yylocp
])[)
1289 yyGLRState
* yynewState
= &yynewGLRStackItem (yystackp
, yytrue
)->yystate
;
1291 yynewState
->yylrState
= yylrState
;
1292 yynewState
->yyposn
= yyposn
;
1293 yynewState
->yyresolved
= yytrue
;
1294 yynewState
->yypred
= yystackp
->yytops
.yystates
[yyk
];
1295 yynewState
->yysemantics
.yysval
= *yyvalp
;]b4_locations_if([
1296 yynewState
->yyloc
= *yylocp
;])[
1297 yystackp
->yytops
.yystates
[yyk
] = yynewState
;
1299 YY_RESERVE_GLRSTACK (yystackp
);
1302 /** Shift stack #K of YYSTACK, to a new state corresponding to LR
1303 * state YYLRSTATE, at input position YYPOSN, with the (unresolved)
1304 * semantic value of YYRHS under the action for YYRULE. */
1306 yyglrShiftDefer (yyGLRStack
* yystackp
, size_t yyk
, yyStateNum yylrState
,
1307 size_t yyposn
, yyGLRState
* rhs
, yyRuleNum yyrule
)
1309 yyGLRState
* yynewState
= &yynewGLRStackItem (yystackp
, yytrue
)->yystate
;
1311 yynewState
->yylrState
= yylrState
;
1312 yynewState
->yyposn
= yyposn
;
1313 yynewState
->yyresolved
= yyfalse
;
1314 yynewState
->yypred
= yystackp
->yytops
.yystates
[yyk
];
1315 yynewState
->yysemantics
.yyfirstVal
= YY_NULL
;
1316 yystackp
->yytops
.yystates
[yyk
] = yynewState
;
1318 /* Invokes YY_RESERVE_GLRSTACK. */
1319 yyaddDeferredAction (yystackp
, yyk
, yynewState
, rhs
, yyrule
);
1322 /** Pop the symbols consumed by reduction #RULE from the top of stack
1323 * #K of STACK, and perform the appropriate semantic action on their
1324 * semantic values. Assumes that all ambiguities in semantic values
1325 * have been previously resolved. Set *VALP to the resulting value,
1326 * and *LOCP to the computed location (if any). Return value is as
1327 * for userAction. */
1328 static inline YYRESULTTAG
1329 yydoAction (yyGLRStack
* yystackp
, size_t yyk
, yyRuleNum yyrule
,
1330 YYSTYPE
* yyvalp
]b4_locuser_formals
[)
1332 int yynrhs
= yyrhsLength (yyrule
);
1334 if (yystackp
->yysplitPoint
== YY_NULL
)
1336 /* Standard special case: single stack. */
1337 yyGLRStackItem
* rhs
= (yyGLRStackItem
*) yystackp
->yytops
.yystates
[yyk
];
1338 YYASSERT (yyk
== 0);
1339 yystackp
->yynextFree
-= yynrhs
;
1340 yystackp
->yyspaceLeft
+= yynrhs
;
1341 yystackp
->yytops
.yystates
[0] = & yystackp
->yynextFree
[-1].yystate
;
1342 return yyuserAction (yyrule
, yynrhs
, rhs
, yystackp
,
1343 yyvalp
]b4_locuser_args
[);
1347 /* At present, doAction is never called in nondeterministic
1348 * mode, so this branch is never taken. It is here in
1349 * anticipation of a future feature that will allow immediate
1350 * evaluation of selected actions in nondeterministic mode. */
1353 yyGLRStackItem yyrhsVals
[YYMAXRHS
+ YYMAXLEFT
+ 1];
1354 yys
= yyrhsVals
[YYMAXRHS
+ YYMAXLEFT
].yystate
.yypred
1355 = yystackp
->yytops
.yystates
[yyk
];]b4_locations_if([[
1357 /* Set default location. */
1358 yyrhsVals
[YYMAXRHS
+ YYMAXLEFT
- 1].yystate
.yyloc
= yys
->yyloc
;]])[
1359 for (yyi
= 0; yyi
< yynrhs
; yyi
+= 1)
1364 yyupdateSplit (yystackp
, yys
);
1365 yystackp
->yytops
.yystates
[yyk
] = yys
;
1366 return yyuserAction (yyrule
, yynrhs
, yyrhsVals
+ YYMAXRHS
+ YYMAXLEFT
- 1,
1367 yystackp
, yyvalp
]b4_locuser_args
[);
1371 #if !]b4_api_PREFIX[DEBUG
1372 # define YY_REDUCE_PRINT(Args)
1374 # define YY_REDUCE_PRINT(Args) \
1377 yy_reduce_print Args; \
1380 /*----------------------------------------------------------.
1381 | Report that the RULE is going to be reduced on stack #K. |
1382 `----------------------------------------------------------*/
1384 /*ARGSUSED*/ static inline void
1385 yy_reduce_print (yyGLRStack
* yystackp
, size_t yyk
, yyRuleNum yyrule
,
1386 YYSTYPE
* yyvalp
]b4_locuser_formals
[)
1388 int yynrhs
= yyrhsLength (yyrule
);
1389 yybool yynormal
__attribute__ ((__unused__
)) =
1390 (yystackp
->yysplitPoint
== YY_NULL
);
1391 yyGLRStackItem
* yyvsp
= (yyGLRStackItem
*) yystackp
->yytops
.yystates
[yyk
];
1394 YYUSE (yyvalp
);]b4_locations_if([
1396 ]b4_parse_param_use
[]dnl
1397 [ YYFPRINTF (stderr
, "Reducing stack %lu by rule %d (line %lu):\n",
1398 (unsigned long int) yyk
, yyrule
- 1,
1399 (unsigned long int) yyrline
[yyrule
]);
1400 /* The symbols being reduced. */
1401 for (yyi
= 0; yyi
< yynrhs
; yyi
++)
1403 YYFPRINTF (stderr
, " $%d = ", yyi
+ 1);
1404 yy_symbol_print (stderr
, yyrhs
[yyprhs
[yyrule
] + yyi
],
1405 &]b4_rhs_value(yynrhs
, yyi
+ 1)[
1406 ]b4_locations_if([, &]b4_rhs_location(yynrhs
, yyi
+ 1))[]dnl
1408 YYFPRINTF (stderr
, "\n");
1413 /** Pop items off stack #K of STACK according to grammar rule RULE,
1414 * and push back on the resulting nonterminal symbol. Perform the
1415 * semantic action associated with RULE and store its value with the
1416 * newly pushed state, if FORCEEVAL or if STACK 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 #K from
1421 * the STACK. In this case, the (necessarily deferred) 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
)
1432 YYSTYPE yysval
;]b4_locations_if([
1435 YY_REDUCE_PRINT ((yystackp
, yyk
, yyrule
, &yysval
]b4_locuser_args([&yyloc
])[));
1436 YYCHK (yydoAction (yystackp
, yyk
, yyrule
, &yysval
]b4_locuser_args([&yyloc
])[));
1437 YY_SYMBOL_PRINT ("-> $$ =", yyr1
[yyrule
], &yysval
, &yyloc
);
1438 yyglrShift (yystackp
, yyk
,
1439 yyLRgotoState (yystackp
->yytops
.yystates
[yyk
]->yylrState
,
1440 yylhsNonterm (yyrule
)),
1441 yyposn
, &yysval
]b4_locations_if([, &yyloc
])[);
1447 yyGLRState
* yys
, *yys0
= yystackp
->yytops
.yystates
[yyk
];
1448 yyStateNum yynewLRState
;
1450 for (yys
= yystackp
->yytops
.yystates
[yyk
], yyn
= yyrhsLength (yyrule
);
1456 yyupdateSplit (yystackp
, yys
);
1457 yynewLRState
= yyLRgotoState (yys
->yylrState
, yylhsNonterm (yyrule
));
1459 "Reduced stack %lu by rule #%d; action deferred. Now in state %d.\n",
1460 (unsigned long int) yyk
, yyrule
- 1, yynewLRState
));
1461 for (yyi
= 0; yyi
< yystackp
->yytops
.yysize
; yyi
+= 1)
1462 if (yyi
!= yyk
&& yystackp
->yytops
.yystates
[yyi
] != YY_NULL
)
1464 yyGLRState
*yysplit
= yystackp
->yysplitPoint
;
1465 yyGLRState
*yyp
= yystackp
->yytops
.yystates
[yyi
];
1466 while (yyp
!= yys
&& yyp
!= yysplit
&& yyp
->yyposn
>= yyposn
)
1468 if (yyp
->yylrState
== yynewLRState
&& yyp
->yypred
== yys
)
1470 yyaddDeferredAction (yystackp
, yyk
, yyp
, yys0
, yyrule
);
1471 yymarkStackDeleted (yystackp
, yyk
);
1472 YYDPRINTF ((stderr
, "Merging stack %lu into stack %lu.\n",
1473 (unsigned long int) yyk
,
1474 (unsigned long int) yyi
));
1480 yystackp
->yytops
.yystates
[yyk
] = yys
;
1481 yyglrShiftDefer (yystackp
, yyk
, yynewLRState
, yyposn
, yys0
, yyrule
);
1487 yysplitStack (yyGLRStack
* yystackp
, size_t yyk
)
1489 if (yystackp
->yysplitPoint
== YY_NULL
)
1491 YYASSERT (yyk
== 0);
1492 yystackp
->yysplitPoint
= yystackp
->yytops
.yystates
[yyk
];
1494 if (yystackp
->yytops
.yysize
>= yystackp
->yytops
.yycapacity
)
1496 yyGLRState
** yynewStates
;
1497 yybool
* yynewLookaheadNeeds
;
1499 yynewStates
= YY_NULL
;
1501 if (yystackp
->yytops
.yycapacity
1502 > (YYSIZEMAX
/ (2 * sizeof yynewStates
[0])))
1503 yyMemoryExhausted (yystackp
);
1504 yystackp
->yytops
.yycapacity
*= 2;
1507 (yyGLRState
**) YYREALLOC (yystackp
->yytops
.yystates
,
1508 (yystackp
->yytops
.yycapacity
1509 * sizeof yynewStates
[0]));
1510 if (yynewStates
== YY_NULL
)
1511 yyMemoryExhausted (yystackp
);
1512 yystackp
->yytops
.yystates
= yynewStates
;
1514 yynewLookaheadNeeds
=
1515 (yybool
*) YYREALLOC (yystackp
->yytops
.yylookaheadNeeds
,
1516 (yystackp
->yytops
.yycapacity
1517 * sizeof yynewLookaheadNeeds
[0]));
1518 if (yynewLookaheadNeeds
== YY_NULL
)
1519 yyMemoryExhausted (yystackp
);
1520 yystackp
->yytops
.yylookaheadNeeds
= yynewLookaheadNeeds
;
1522 yystackp
->yytops
.yystates
[yystackp
->yytops
.yysize
]
1523 = yystackp
->yytops
.yystates
[yyk
];
1524 yystackp
->yytops
.yylookaheadNeeds
[yystackp
->yytops
.yysize
]
1525 = yystackp
->yytops
.yylookaheadNeeds
[yyk
];
1526 yystackp
->yytops
.yysize
+= 1;
1527 return yystackp
->yytops
.yysize
-1;
1530 /** True iff Y0 and Y1 represent identical options at the top level.
1531 * That is, they represent the same rule applied to RHS symbols
1532 * that produce the same terminal symbols. */
1534 yyidenticalOptions (yySemanticOption
* yyy0
, yySemanticOption
* yyy1
)
1536 if (yyy0
->yyrule
== yyy1
->yyrule
)
1538 yyGLRState
*yys0
, *yys1
;
1540 for (yys0
= yyy0
->yystate
, yys1
= yyy1
->yystate
,
1541 yyn
= yyrhsLength (yyy0
->yyrule
);
1543 yys0
= yys0
->yypred
, yys1
= yys1
->yypred
, yyn
-= 1)
1544 if (yys0
->yyposn
!= yys1
->yyposn
)
1552 /** Assuming identicalOptions (Y0,Y1), destructively merge the
1553 * alternative semantic values for the RHS-symbols of Y1 and Y0. */
1555 yymergeOptionSets (yySemanticOption
* yyy0
, yySemanticOption
* yyy1
)
1557 yyGLRState
*yys0
, *yys1
;
1559 for (yys0
= yyy0
->yystate
, yys1
= yyy1
->yystate
,
1560 yyn
= yyrhsLength (yyy0
->yyrule
);
1562 yys0
= yys0
->yypred
, yys1
= yys1
->yypred
, yyn
-= 1)
1566 else if (yys0
->yyresolved
)
1568 yys1
->yyresolved
= yytrue
;
1569 yys1
->yysemantics
.yysval
= yys0
->yysemantics
.yysval
;
1571 else if (yys1
->yyresolved
)
1573 yys0
->yyresolved
= yytrue
;
1574 yys0
->yysemantics
.yysval
= yys1
->yysemantics
.yysval
;
1578 yySemanticOption
** yyz0p
= &yys0
->yysemantics
.yyfirstVal
;
1579 yySemanticOption
* yyz1
= yys1
->yysemantics
.yyfirstVal
;
1580 while (YYID (yytrue
))
1582 if (yyz1
== *yyz0p
|| yyz1
== YY_NULL
)
1584 else if (*yyz0p
== YY_NULL
)
1589 else if (*yyz0p
< yyz1
)
1591 yySemanticOption
* yyz
= *yyz0p
;
1593 yyz1
= yyz1
->yynext
;
1594 (*yyz0p
)->yynext
= yyz
;
1596 yyz0p
= &(*yyz0p
)->yynext
;
1598 yys1
->yysemantics
.yyfirstVal
= yys0
->yysemantics
.yyfirstVal
;
1603 /** Y0 and Y1 represent two possible actions to take in a given
1604 * parsing state; return 0 if no combination is possible,
1605 * 1 if user-mergeable, 2 if Y0 is preferred, 3 if Y1 is preferred. */
1607 yypreference (yySemanticOption
* y0
, yySemanticOption
* y1
)
1609 yyRuleNum r0
= y0
->yyrule
, r1
= y1
->yyrule
;
1610 int p0
= yydprec
[r0
], p1
= yydprec
[r1
];
1614 if (yymerger
[r0
] == 0 || yymerger
[r0
] != yymerger
[r1
])
1619 if (p0
== 0 || p1
== 0)
1628 static YYRESULTTAG
yyresolveValue (yyGLRState
* yys
,
1629 yyGLRStack
* yystackp
]b4_user_formals
[);
1632 /** Resolve the previous N states starting at and including state S. If result
1633 * != yyok, some states may have been left unresolved possibly with empty
1634 * semantic option chains. Regardless of whether result = yyok, each state
1635 * has been left with consistent data so that yydestroyGLRState can be invoked
1638 yyresolveStates (yyGLRState
* yys
, int yyn
,
1639 yyGLRStack
* yystackp
]b4_user_formals
[)
1643 YYASSERT (yys
->yypred
);
1644 YYCHK (yyresolveStates (yys
->yypred
, yyn
-1, yystackp
]b4_user_args
[));
1645 if (! yys
->yyresolved
)
1646 YYCHK (yyresolveValue (yys
, yystackp
]b4_user_args
[));
1651 /** Resolve the states for the RHS of OPT, perform its user action, and return
1652 * the semantic value and location. Regardless of whether result = yyok, all
1653 * RHS states have been destroyed (assuming the user action destroys all RHS
1654 * semantic values if invoked). */
1656 yyresolveAction (yySemanticOption
* yyopt
, yyGLRStack
* yystackp
,
1657 YYSTYPE
* yyvalp
]b4_locuser_formals
[)
1659 yyGLRStackItem yyrhsVals
[YYMAXRHS
+ YYMAXLEFT
+ 1];
1660 int yynrhs
= yyrhsLength (yyopt
->yyrule
);
1661 YYRESULTTAG yyflag
=
1662 yyresolveStates (yyopt
->yystate
, yynrhs
, yystackp
]b4_user_args
[);
1666 for (yys
= yyopt
->yystate
; yynrhs
> 0; yys
= yys
->yypred
, yynrhs
-= 1)
1667 yydestroyGLRState ("Cleanup: popping", yys
]b4_user_args
[);
1671 yyrhsVals
[YYMAXRHS
+ YYMAXLEFT
].yystate
.yypred
= yyopt
->yystate
;]b4_locations_if([[
1673 /* Set default location. */
1674 yyrhsVals
[YYMAXRHS
+ YYMAXLEFT
- 1].yystate
.yyloc
= yyopt
->yystate
->yyloc
;]])[
1676 int yychar_current
= yychar
;
1677 YYSTYPE yylval_current
= yylval
;]b4_locations_if([
1678 YYLTYPE yylloc_current
= yylloc
;])[
1679 yychar
= yyopt
->yyrawchar
;
1680 yylval
= yyopt
->yyval
;]b4_locations_if([
1681 yylloc
= yyopt
->yyloc
;])[
1682 yyflag
= yyuserAction (yyopt
->yyrule
, yynrhs
,
1683 yyrhsVals
+ YYMAXRHS
+ YYMAXLEFT
- 1,
1684 yystackp
, yyvalp
]b4_locuser_args
[);
1685 yychar
= yychar_current
;
1686 yylval
= yylval_current
;]b4_locations_if([
1687 yylloc
= yylloc_current
;])[
1692 #if ]b4_api_PREFIX[DEBUG
1694 yyreportTree (yySemanticOption
* yyx
, int yyindent
)
1696 int yynrhs
= yyrhsLength (yyx
->yyrule
);
1699 yyGLRState
* yystates
[1 + YYMAXRHS
];
1700 yyGLRState yyleftmost_state
;
1702 for (yyi
= yynrhs
, yys
= yyx
->yystate
; 0 < yyi
; yyi
-= 1, yys
= yys
->yypred
)
1703 yystates
[yyi
] = yys
;
1706 yyleftmost_state
.yyposn
= 0;
1707 yystates
[0] = &yyleftmost_state
;
1712 if (yyx
->yystate
->yyposn
< yys
->yyposn
+ 1)
1713 YYFPRINTF (stderr
, "%*s%s -> <Rule %d, empty>\n",
1714 yyindent
, "", yytokenName (yylhsNonterm (yyx
->yyrule
)),
1717 YYFPRINTF (stderr
, "%*s%s -> <Rule %d, tokens %lu .. %lu>\n",
1718 yyindent
, "", yytokenName (yylhsNonterm (yyx
->yyrule
)),
1719 yyx
->yyrule
- 1, (unsigned long int) (yys
->yyposn
+ 1),
1720 (unsigned long int) yyx
->yystate
->yyposn
);
1721 for (yyi
= 1; yyi
<= yynrhs
; yyi
+= 1)
1723 if (yystates
[yyi
]->yyresolved
)
1725 if (yystates
[yyi
-1]->yyposn
+1 > yystates
[yyi
]->yyposn
)
1726 YYFPRINTF (stderr
, "%*s%s <empty>\n", yyindent
+2, "",
1727 yytokenName (yyrhs
[yyprhs
[yyx
->yyrule
]+yyi
-1]));
1729 YYFPRINTF (stderr
, "%*s%s <tokens %lu .. %lu>\n", yyindent
+2, "",
1730 yytokenName (yyrhs
[yyprhs
[yyx
->yyrule
]+yyi
-1]),
1731 (unsigned long int) (yystates
[yyi
- 1]->yyposn
+ 1),
1732 (unsigned long int) yystates
[yyi
]->yyposn
);
1735 yyreportTree (yystates
[yyi
]->yysemantics
.yyfirstVal
, yyindent
+2);
1740 /*ARGSUSED*/ static YYRESULTTAG
1741 yyreportAmbiguity (yySemanticOption
* yyx0
,
1742 yySemanticOption
* yyx1
]b4_pure_formals
[)
1747 #if ]b4_api_PREFIX[DEBUG
1748 YYFPRINTF (stderr
, "Ambiguity detected.\n");
1749 YYFPRINTF (stderr
, "Option 1,\n");
1750 yyreportTree (yyx0
, 2);
1751 YYFPRINTF (stderr
, "\nOption 2,\n");
1752 yyreportTree (yyx1
, 2);
1753 YYFPRINTF (stderr
, "\n");
1756 yyerror (]b4_yyerror_args
[YY_("syntax is ambiguous"));
1758 }]b4_locations_if([[
1760 /** Starting at and including state S1, resolve the location for each of the
1761 * previous N1 states that is unresolved. The first semantic option of a state
1762 * is always chosen. */
1764 yyresolveLocations (yyGLRState
* yys1
, int yyn1
,
1765 yyGLRStack
*yystackp
]b4_user_formals
[)
1769 yyresolveLocations (yys1
->yypred
, yyn1
- 1, yystackp
]b4_user_args
[);
1770 if (!yys1
->yyresolved
)
1772 yyGLRStackItem yyrhsloc
[1 + YYMAXRHS
];
1774 yySemanticOption
*yyoption
= yys1
->yysemantics
.yyfirstVal
;
1775 YYASSERT (yyoption
!= YY_NULL
);
1776 yynrhs
= yyrhsLength (yyoption
->yyrule
);
1781 yyresolveLocations (yyoption
->yystate
, yynrhs
,
1782 yystackp
]b4_user_args
[);
1783 for (yys
= yyoption
->yystate
, yyn
= yynrhs
;
1785 yys
= yys
->yypred
, yyn
-= 1)
1786 yyrhsloc
[yyn
].yystate
.yyloc
= yys
->yyloc
;
1790 /* Both yyresolveAction and yyresolveLocations traverse the GSS
1791 in reverse rightmost order. It is only necessary to invoke
1792 yyresolveLocations on a subforest for which yyresolveAction
1793 would have been invoked next had an ambiguity not been
1794 detected. Thus the location of the previous state (but not
1795 necessarily the previous state itself) is guaranteed to be
1796 resolved already. */
1797 yyGLRState
*yyprevious
= yyoption
->yystate
;
1798 yyrhsloc
[0].yystate
.yyloc
= yyprevious
->yyloc
;
1801 int yychar_current
= yychar
;
1802 YYSTYPE yylval_current
= yylval
;
1803 YYLTYPE yylloc_current
= yylloc
;
1804 yychar
= yyoption
->yyrawchar
;
1805 yylval
= yyoption
->yyval
;
1806 yylloc
= yyoption
->yyloc
;
1807 YYLLOC_DEFAULT ((yys1
->yyloc
), yyrhsloc
, yynrhs
);
1808 yychar
= yychar_current
;
1809 yylval
= yylval_current
;
1810 yylloc
= yylloc_current
;
1816 /** Resolve the ambiguity represented in state S, perform the indicated
1817 * actions, and set the semantic value of S. If result != yyok, the chain of
1818 * semantic options in S has been cleared instead or it has been left
1819 * unmodified except that redundant options may have been removed. Regardless
1820 * of whether result = yyok, S has been left with consistent data so that
1821 * yydestroyGLRState can be invoked if necessary. */
1823 yyresolveValue (yyGLRState
* yys
, yyGLRStack
* yystackp
]b4_user_formals
[)
1825 yySemanticOption
* yyoptionList
= yys
->yysemantics
.yyfirstVal
;
1826 yySemanticOption
* yybest
= yyoptionList
;
1827 yySemanticOption
** yypp
;
1828 yybool yymerge
= yyfalse
;
1830 YYRESULTTAG yyflag
;]b4_locations_if([
1831 YYLTYPE
*yylocp
= &yys
->yyloc
;])[
1833 for (yypp
= &yyoptionList
->yynext
; *yypp
!= YY_NULL
; )
1835 yySemanticOption
* yyp
= *yypp
;
1837 if (yyidenticalOptions (yybest
, yyp
))
1839 yymergeOptionSets (yybest
, yyp
);
1840 *yypp
= yyp
->yynext
;
1844 switch (yypreference (yybest
, yyp
))
1846 case 0:]b4_locations_if([[
1847 yyresolveLocations (yys
, 1, yystackp
]b4_user_args
[);]])[
1848 return yyreportAmbiguity (yybest
, yyp
]b4_pure_args
[);
1860 /* This cannot happen so it is not worth a YYASSERT (yyfalse),
1861 but some compilers complain if the default case is
1865 yypp
= &yyp
->yynext
;
1871 yySemanticOption
* yyp
;
1872 int yyprec
= yydprec
[yybest
->yyrule
];
1873 yyflag
= yyresolveAction (yybest
, yystackp
, &yysval
]b4_locuser_args
[);
1875 for (yyp
= yybest
->yynext
; yyp
!= YY_NULL
; yyp
= yyp
->yynext
)
1877 if (yyprec
== yydprec
[yyp
->yyrule
])
1879 YYSTYPE yysval_other
;]b4_locations_if([
1881 yyflag
= yyresolveAction (yyp
, yystackp
, &yysval_other
]b4_locuser_args([&yydummy
])[);
1884 yydestruct ("Cleanup: discarding incompletely merged value for",
1885 yystos
[yys
->yylrState
],
1886 &yysval
]b4_locuser_args
[);
1889 yyuserMerge (yymerger
[yyp
->yyrule
], &yysval
, &yysval_other
);
1894 yyflag
= yyresolveAction (yybest
, yystackp
, &yysval
]b4_locuser_args([yylocp
])[);
1898 yys
->yyresolved
= yytrue
;
1899 yys
->yysemantics
.yysval
= yysval
;
1902 yys
->yysemantics
.yyfirstVal
= YY_NULL
;
1907 yyresolveStack (yyGLRStack
* yystackp
]b4_user_formals
[)
1909 if (yystackp
->yysplitPoint
!= YY_NULL
)
1914 for (yyn
= 0, yys
= yystackp
->yytops
.yystates
[0];
1915 yys
!= yystackp
->yysplitPoint
;
1916 yys
= yys
->yypred
, yyn
+= 1)
1918 YYCHK (yyresolveStates (yystackp
->yytops
.yystates
[0], yyn
, yystackp
1925 yycompressStack (yyGLRStack
* yystackp
)
1927 yyGLRState
* yyp
, *yyq
, *yyr
;
1929 if (yystackp
->yytops
.yysize
!= 1 || yystackp
->yysplitPoint
== YY_NULL
)
1932 for (yyp
= yystackp
->yytops
.yystates
[0], yyq
= yyp
->yypred
, yyr
= YY_NULL
;
1933 yyp
!= yystackp
->yysplitPoint
;
1934 yyr
= yyp
, yyp
= yyq
, yyq
= yyp
->yypred
)
1937 yystackp
->yyspaceLeft
+= yystackp
->yynextFree
- yystackp
->yyitems
;
1938 yystackp
->yynextFree
= ((yyGLRStackItem
*) yystackp
->yysplitPoint
) + 1;
1939 yystackp
->yyspaceLeft
-= yystackp
->yynextFree
- yystackp
->yyitems
;
1940 yystackp
->yysplitPoint
= YY_NULL
;
1941 yystackp
->yylastDeleted
= YY_NULL
;
1943 while (yyr
!= YY_NULL
)
1945 yystackp
->yynextFree
->yystate
= *yyr
;
1947 yystackp
->yynextFree
->yystate
.yypred
= &yystackp
->yynextFree
[-1].yystate
;
1948 yystackp
->yytops
.yystates
[0] = &yystackp
->yynextFree
->yystate
;
1949 yystackp
->yynextFree
+= 1;
1950 yystackp
->yyspaceLeft
-= 1;
1955 yyprocessOneStack (yyGLRStack
* yystackp
, size_t yyk
,
1956 size_t yyposn
]b4_pure_formals
[)
1959 const short int* yyconflicts
;
1962 while (yystackp
->yytops
.yystates
[yyk
] != YY_NULL
)
1964 yyStateNum yystate
= yystackp
->yytops
.yystates
[yyk
]->yylrState
;
1965 YYDPRINTF ((stderr
, "Stack %lu Entering state %d\n",
1966 (unsigned long int) yyk
, yystate
));
1968 YYASSERT (yystate
!= YYFINAL
);
1970 if (yyisDefaultedState (yystate
))
1972 yyrule
= yydefaultAction (yystate
);
1975 YYDPRINTF ((stderr
, "Stack %lu dies.\n",
1976 (unsigned long int) yyk
));
1977 yymarkStackDeleted (yystackp
, yyk
);
1980 YYCHK (yyglrReduce (yystackp
, yyk
, yyrule
, yyfalse
]b4_user_args
[));
1985 yystackp
->yytops
.yylookaheadNeeds
[yyk
] = yytrue
;
1986 if (yychar
== YYEMPTY
)
1988 YYDPRINTF ((stderr
, "Reading a token: "));
1992 if (yychar
<= YYEOF
)
1994 yychar
= yytoken
= YYEOF
;
1995 YYDPRINTF ((stderr
, "Now at end of input.\n"));
1999 yytoken
= YYTRANSLATE (yychar
);
2000 YY_SYMBOL_PRINT ("Next token is", yytoken
, &yylval
, &yylloc
);
2003 yygetLRActions (yystate
, yytoken
, &yyaction
, &yyconflicts
);
2005 while (*yyconflicts
!= 0)
2007 size_t yynewStack
= yysplitStack (yystackp
, yyk
);
2008 YYDPRINTF ((stderr
, "Splitting off stack %lu from %lu.\n",
2009 (unsigned long int) yynewStack
,
2010 (unsigned long int) yyk
));
2011 YYCHK (yyglrReduce (yystackp
, yynewStack
,
2012 *yyconflicts
, yyfalse
]b4_user_args
[));
2013 YYCHK (yyprocessOneStack (yystackp
, yynewStack
,
2014 yyposn
]b4_pure_args
[));
2018 if (yyisShiftAction (yyaction
))
2020 else if (yyisErrorAction (yyaction
))
2022 YYDPRINTF ((stderr
, "Stack %lu dies.\n",
2023 (unsigned long int) yyk
));
2024 yymarkStackDeleted (yystackp
, yyk
);
2028 YYCHK (yyglrReduce (yystackp
, yyk
, -yyaction
,
2029 yyfalse
]b4_user_args
[));
2035 /*ARGSUSED*/ static void
2036 yyreportSyntaxError (yyGLRStack
* yystackp
]b4_user_formals
[)
2038 if (yystackp
->yyerrState
!= 0)
2040 #if ! YYERROR_VERBOSE
2041 yyerror (]b4_lyyerror_args
[YY_("syntax error"));
2043 yySymbol yytoken
= yychar
== YYEMPTY
? YYEMPTY
: YYTRANSLATE (yychar
);
2044 size_t yysize0
= yytnamerr (YY_NULL
, yytokenName (yytoken
));
2045 size_t yysize
= yysize0
;
2047 yybool yysize_overflow
= yyfalse
;
2048 char* yymsg
= YY_NULL
;
2049 enum { YYERROR_VERBOSE_ARGS_MAXIMUM
= 5 };
2050 /* Internationalized format string. */
2051 const char *yyformat
= YY_NULL
;
2052 /* Arguments of yyformat. */
2053 char const *yyarg
[YYERROR_VERBOSE_ARGS_MAXIMUM
];
2054 /* Number of reported tokens (one for the "unexpected", one per
2058 /* There are many possibilities here to consider:
2059 - If this state is a consistent state with a default action, then
2060 the only way this function was invoked is if the default action
2061 is an error action. In that case, don't check for expected
2062 tokens because there are none.
2063 - The only way there can be no lookahead present (in yychar) is if
2064 this state is a consistent state with a default action. Thus,
2065 detecting the absence of a lookahead is sufficient to determine
2066 that there is no unexpected or expected token to report. In that
2067 case, just report a simple "syntax error".
2068 - Don't assume there isn't a lookahead just because this state is a
2069 consistent state with a default action. There might have been a
2070 previous inconsistent state, consistent state with a non-default
2071 action, or user semantic action that manipulated yychar.
2072 - Of course, the expected token list depends on states to have
2073 correct lookahead information, and it depends on the parser not
2074 to perform extra reductions after fetching a lookahead from the
2075 scanner and before detecting a syntax error. Thus, state merging
2076 (from LALR or IELR) and default reductions corrupt the expected
2077 token list. However, the list is correct for canonical LR with
2078 one exception: it will still contain any token that will not be
2079 accepted due to an error action in a later state.
2081 if (yytoken
!= YYEMPTY
)
2083 int yyn
= yypact
[yystackp
->yytops
.yystates
[0]->yylrState
];
2084 yyarg
[yycount
++] = yytokenName (yytoken
);
2085 if (!yypact_value_is_default (yyn
))
2087 /* Start YYX at -YYN if negative to avoid negative indexes in
2088 YYCHECK. In other words, skip the first -YYN actions for this
2089 state because they are default actions. */
2090 int yyxbegin
= yyn
< 0 ? -yyn
: 0;
2091 /* Stay within bounds of both yycheck and yytname. */
2092 int yychecklim
= YYLAST
- yyn
+ 1;
2093 int yyxend
= yychecklim
< YYNTOKENS
? yychecklim
: YYNTOKENS
;
2095 for (yyx
= yyxbegin
; yyx
< yyxend
; ++yyx
)
2096 if (yycheck
[yyx
+ yyn
] == yyx
&& yyx
!= YYTERROR
2097 && !yytable_value_is_error (yytable
[yyx
+ yyn
]))
2099 if (yycount
== YYERROR_VERBOSE_ARGS_MAXIMUM
)
2105 yyarg
[yycount
++] = yytokenName (yyx
);
2106 yysize1
= yysize
+ yytnamerr (YY_NULL
, yytokenName (yyx
));
2107 yysize_overflow
|= yysize1
< yysize
;
2115 #define YYCASE_(N, S) \
2119 YYCASE_(0, YY_("syntax error"));
2120 YYCASE_(1, YY_("syntax error, unexpected %s"));
2121 YYCASE_(2, YY_("syntax error, unexpected %s, expecting %s"));
2122 YYCASE_(3, YY_("syntax error, unexpected %s, expecting %s or %s"));
2123 YYCASE_(4, YY_("syntax error, unexpected %s, expecting %s or %s or %s"));
2124 YYCASE_(5, YY_("syntax error, unexpected %s, expecting %s or %s or %s or %s"));
2128 yysize1
= yysize
+ strlen (yyformat
);
2129 yysize_overflow
|= yysize1
< yysize
;
2132 if (!yysize_overflow
)
2133 yymsg
= (char *) YYMALLOC (yysize
);
2139 while ((*yyp
= *yyformat
))
2141 if (*yyp
== '%' && yyformat
[1] == 's' && yyi
< yycount
)
2143 yyp
+= yytnamerr (yyp
, yyarg
[yyi
++]);
2152 yyerror (]b4_lyyerror_args
[yymsg
);
2157 yyerror (]b4_lyyerror_args
[YY_("syntax error"));
2158 yyMemoryExhausted (yystackp
);
2160 #endif /* YYERROR_VERBOSE */
2164 /* Recover from a syntax error on *YYSTACKP, assuming that *YYSTACKP->YYTOKENP,
2165 yylval, and yylloc are the syntactic category, semantic value, and location
2166 of the lookahead. */
2167 /*ARGSUSED*/ static void
2168 yyrecoverSyntaxError (yyGLRStack
* yystackp
]b4_user_formals
[)
2173 if (yystackp
->yyerrState
== 3)
2174 /* We just shifted the error token and (perhaps) took some
2175 reductions. Skip tokens until we can proceed. */
2176 while (YYID (yytrue
))
2179 if (yychar
== YYEOF
)
2180 yyFail (yystackp
][]b4_lpure_args
[, YY_NULL
);
2181 if (yychar
!= YYEMPTY
)
2182 {]b4_locations_if([[
2183 /* We throw away the lookahead, but the error range
2184 of the shifted error token must take it into account. */
2185 yyGLRState
*yys
= yystackp
->yytops
.yystates
[0];
2186 yyGLRStackItem yyerror_range
[3];
2187 yyerror_range
[1].yystate
.yyloc
= yys
->yyloc
;
2188 yyerror_range
[2].yystate
.yyloc
= yylloc
;
2189 YYLLOC_DEFAULT ((yys
->yyloc
), yyerror_range
, 2);]])[
2190 yytoken
= YYTRANSLATE (yychar
);
2191 yydestruct ("Error: discarding",
2192 yytoken
, &yylval
]b4_locuser_args([&yylloc
])[);
2194 YYDPRINTF ((stderr
, "Reading a token: "));
2196 if (yychar
<= YYEOF
)
2198 yychar
= yytoken
= YYEOF
;
2199 YYDPRINTF ((stderr
, "Now at end of input.\n"));
2203 yytoken
= YYTRANSLATE (yychar
);
2204 YY_SYMBOL_PRINT ("Next token is", yytoken
, &yylval
, &yylloc
);
2206 yyj
= yypact
[yystackp
->yytops
.yystates
[0]->yylrState
];
2207 if (yypact_value_is_default (yyj
))
2210 if (yyj
< 0 || YYLAST
< yyj
|| yycheck
[yyj
] != yytoken
)
2212 if (yydefact
[yystackp
->yytops
.yystates
[0]->yylrState
] != 0)
2215 else if (! yytable_value_is_error (yytable
[yyj
]))
2219 /* Reduce to one stack. */
2220 for (yyk
= 0; yyk
< yystackp
->yytops
.yysize
; yyk
+= 1)
2221 if (yystackp
->yytops
.yystates
[yyk
] != YY_NULL
)
2223 if (yyk
>= yystackp
->yytops
.yysize
)
2224 yyFail (yystackp
][]b4_lpure_args
[, YY_NULL
);
2225 for (yyk
+= 1; yyk
< yystackp
->yytops
.yysize
; yyk
+= 1)
2226 yymarkStackDeleted (yystackp
, yyk
);
2227 yyremoveDeletes (yystackp
);
2228 yycompressStack (yystackp
);
2230 /* Now pop stack until we find a state that shifts the error token. */
2231 yystackp
->yyerrState
= 3;
2232 while (yystackp
->yytops
.yystates
[0] != YY_NULL
)
2234 yyGLRState
*yys
= yystackp
->yytops
.yystates
[0];
2235 yyj
= yypact
[yys
->yylrState
];
2236 if (! yypact_value_is_default (yyj
))
2239 if (0 <= yyj
&& yyj
<= YYLAST
&& yycheck
[yyj
] == YYTERROR
2240 && yyisShiftAction (yytable
[yyj
]))
2242 /* Shift the error token. */]b4_locations_if([[
2243 /* First adjust its location.*/
2245 yystackp
->yyerror_range
[2].yystate
.yyloc
= yylloc
;
2246 YYLLOC_DEFAULT (yyerrloc
, (yystackp
->yyerror_range
), 2);]])[
2247 YY_SYMBOL_PRINT ("Shifting", yystos
[yytable
[yyj
]],
2248 &yylval
, &yyerrloc
);
2249 yyglrShift (yystackp
, 0, yytable
[yyj
],
2250 yys
->yyposn
, &yylval
]b4_locations_if([, &yyerrloc
])[);
2251 yys
= yystackp
->yytops
.yystates
[0];
2254 }]b4_locations_if([[
2255 yystackp
->yyerror_range
[1].yystate
.yyloc
= yys
->yyloc
;]])[
2256 if (yys
->yypred
!= YY_NULL
)
2257 yydestroyGLRState ("Error: popping", yys
]b4_user_args
[);
2258 yystackp
->yytops
.yystates
[0] = yys
->yypred
;
2259 yystackp
->yynextFree
-= 1;
2260 yystackp
->yyspaceLeft
+= 1;
2262 if (yystackp
->yytops
.yystates
[0] == YY_NULL
)
2263 yyFail (yystackp
][]b4_lpure_args
[, YY_NULL
);
2266 #define YYCHK1(YYE) \
2276 goto yyuser_error; \
2287 ]b4_c_ansi_function_def([yyparse
], [int], b4_parse_param
)[
2291 yyGLRStack
* const yystackp
= &yystack
;
2294 YYDPRINTF ((stderr
, "Starting parse\n"));
2297 yylval
= yyval_default
;
2299 #if defined ]b4_api_PREFIX[LTYPE_IS_TRIVIAL && ]b4_api_PREFIX[LTYPE_IS_TRIVIAL
2300 yylloc
.first_line
= yylloc
.last_line
= ]b4_location_initial_line
[;
2301 yylloc
.first_column
= yylloc
.last_column
= ]b4_location_initial_column
[;
2304 m4_ifdef([b4_initial_action
], [
2305 b4_dollar_pushdef([yylval
], [], [yylloc
])dnl
2306 /* User initialization code. */
2307 b4_user_initial_action
2308 b4_dollar_popdef
])[]dnl
2310 if (! yyinitGLRStack (yystackp
, YYINITDEPTH
))
2311 goto yyexhaustedlab
;
2312 switch (YYSETJMP (yystack
.yyexception_buffer
))
2315 case 1: goto yyabortlab
;
2316 case 2: goto yyexhaustedlab
;
2317 default: goto yybuglab
;
2319 yyglrShift (&yystack
, 0, 0, 0, &yylval
]b4_locations_if([, &yylloc
])[);
2322 while (YYID (yytrue
))
2324 /* For efficiency, we have two loops, the first of which is
2325 specialized to deterministic operation (single stack, no
2326 potential ambiguity). */
2328 while (YYID (yytrue
))
2332 const short int* yyconflicts
;
2334 yyStateNum yystate
= yystack
.yytops
.yystates
[0]->yylrState
;
2335 YYDPRINTF ((stderr
, "Entering state %d\n", yystate
));
2336 if (yystate
== YYFINAL
)
2338 if (yyisDefaultedState (yystate
))
2340 yyrule
= yydefaultAction (yystate
);
2343 ]b4_locations_if([[ yystack
.yyerror_range
[1].yystate
.yyloc
= yylloc
;]])[
2344 yyreportSyntaxError (&yystack
]b4_user_args
[);
2347 YYCHK1 (yyglrReduce (&yystack
, 0, yyrule
, yytrue
]b4_user_args
[));
2352 if (yychar
== YYEMPTY
)
2354 YYDPRINTF ((stderr
, "Reading a token: "));
2358 if (yychar
<= YYEOF
)
2360 yychar
= yytoken
= YYEOF
;
2361 YYDPRINTF ((stderr
, "Now at end of input.\n"));
2365 yytoken
= YYTRANSLATE (yychar
);
2366 YY_SYMBOL_PRINT ("Next token is", yytoken
, &yylval
, &yylloc
);
2369 yygetLRActions (yystate
, yytoken
, &yyaction
, &yyconflicts
);
2370 if (*yyconflicts
!= 0)
2372 if (yyisShiftAction (yyaction
))
2374 YY_SYMBOL_PRINT ("Shifting", yytoken
, &yylval
, &yylloc
);
2377 yyglrShift (&yystack
, 0, yyaction
, yyposn
, &yylval
]b4_locations_if([, &yylloc
])[);
2378 if (0 < yystack
.yyerrState
)
2379 yystack
.yyerrState
-= 1;
2381 else if (yyisErrorAction (yyaction
))
2383 ]b4_locations_if([[ yystack
.yyerror_range
[1].yystate
.yyloc
= yylloc
;]])[
2384 yyreportSyntaxError (&yystack
]b4_user_args
[);
2388 YYCHK1 (yyglrReduce (&yystack
, 0, -yyaction
, yytrue
]b4_user_args
[));
2392 while (YYID (yytrue
))
2394 yySymbol yytoken_to_shift
;
2397 for (yys
= 0; yys
< yystack
.yytops
.yysize
; yys
+= 1)
2398 yystackp
->yytops
.yylookaheadNeeds
[yys
] = yychar
!= YYEMPTY
;
2400 /* yyprocessOneStack returns one of three things:
2402 - An error flag. If the caller is yyprocessOneStack, it
2403 immediately returns as well. When the caller is finally
2404 yyparse, it jumps to an error label via YYCHK1.
2406 - yyok, but yyprocessOneStack has invoked yymarkStackDeleted
2407 (&yystack, yys), which sets the top state of yys to NULL. Thus,
2408 yyparse's following invocation of yyremoveDeletes will remove
2411 - yyok, when ready to shift a token.
2413 Except in the first case, yyparse will invoke yyremoveDeletes and
2414 then shift the next token onto all remaining stacks. This
2415 synchronization of the shift (that is, after all preceding
2416 reductions on all stacks) helps prevent double destructor calls
2417 on yylval in the event of memory exhaustion. */
2419 for (yys
= 0; yys
< yystack
.yytops
.yysize
; yys
+= 1)
2420 YYCHK1 (yyprocessOneStack (&yystack
, yys
, yyposn
]b4_lpure_args
[));
2421 yyremoveDeletes (&yystack
);
2422 if (yystack
.yytops
.yysize
== 0)
2424 yyundeleteLastStack (&yystack
);
2425 if (yystack
.yytops
.yysize
== 0)
2426 yyFail (&yystack
][]b4_lpure_args
[, YY_("syntax error"));
2427 YYCHK1 (yyresolveStack (&yystack
]b4_user_args
[));
2428 YYDPRINTF ((stderr
, "Returning to deterministic operation.\n"));
2429 ]b4_locations_if([[ yystack
.yyerror_range
[1].yystate
.yyloc
= yylloc
;]])[
2430 yyreportSyntaxError (&yystack
]b4_user_args
[);
2434 /* If any yyglrShift call fails, it will fail after shifting. Thus,
2435 a copy of yylval will already be on stack 0 in the event of a
2436 failure in the following loop. Thus, yychar is set to YYEMPTY
2437 before the loop to make sure the user destructor for yylval isn't
2439 yytoken_to_shift
= YYTRANSLATE (yychar
);
2442 for (yys
= 0; yys
< yystack
.yytops
.yysize
; yys
+= 1)
2445 const short int* yyconflicts
;
2446 yyStateNum yystate
= yystack
.yytops
.yystates
[yys
]->yylrState
;
2447 yygetLRActions (yystate
, yytoken_to_shift
, &yyaction
,
2449 /* Note that yyconflicts were handled by yyprocessOneStack. */
2450 YYDPRINTF ((stderr
, "On stack %lu, ", (unsigned long int) yys
));
2451 YY_SYMBOL_PRINT ("shifting", yytoken_to_shift
, &yylval
, &yylloc
);
2452 yyglrShift (&yystack
, yys
, yyaction
, yyposn
,
2453 &yylval
]b4_locations_if([, &yylloc
])[);
2454 YYDPRINTF ((stderr
, "Stack %lu now in state #%d\n",
2455 (unsigned long int) yys
,
2456 yystack
.yytops
.yystates
[yys
]->yylrState
));
2459 if (yystack
.yytops
.yysize
== 1)
2461 YYCHK1 (yyresolveStack (&yystack
]b4_user_args
[));
2462 YYDPRINTF ((stderr
, "Returning to deterministic operation.\n"));
2463 yycompressStack (&yystack
);
2469 yyrecoverSyntaxError (&yystack
]b4_user_args
[);
2470 yyposn
= yystack
.yytops
.yystates
[0]->yyposn
;
2486 yyerror (]b4_lyyerror_args
[YY_("memory exhausted"));
2491 if (yychar
!= YYEMPTY
)
2492 yydestruct ("Cleanup: discarding lookahead",
2493 YYTRANSLATE (yychar
), &yylval
]b4_locuser_args([&yylloc
])[);
2495 /* If the stack is well-formed, pop the stack until it is empty,
2496 destroying its entries as we go. But free the stack regardless
2497 of whether it is well-formed. */
2498 if (yystack
.yyitems
)
2500 yyGLRState
** yystates
= yystack
.yytops
.yystates
;
2503 size_t yysize
= yystack
.yytops
.yysize
;
2505 for (yyk
= 0; yyk
< yysize
; yyk
+= 1)
2508 while (yystates
[yyk
])
2510 yyGLRState
*yys
= yystates
[yyk
];
2511 ]b4_locations_if([[ yystack
.yyerror_range
[1].yystate
.yyloc
= yys
->yyloc
;]]
2512 )[ if (yys
->yypred
!= YY_NULL
)
2513 yydestroyGLRState ("Cleanup: popping", yys
]b4_user_args
[);
2514 yystates
[yyk
] = yys
->yypred
;
2515 yystack
.yynextFree
-= 1;
2516 yystack
.yyspaceLeft
+= 1;
2521 yyfreeGLRStack (&yystack
);
2524 /* Make sure YYID is used. */
2525 return YYID (yyresult
);
2528 /* DEBUGGING ONLY */
2529 #if ]b4_api_PREFIX[DEBUG
2530 static void yypstack (yyGLRStack
* yystackp
, size_t yyk
)
2531 __attribute__ ((__unused__
));
2532 static void yypdumpstack (yyGLRStack
* yystackp
) __attribute__ ((__unused__
));
2535 yy_yypstack (yyGLRState
* yys
)
2539 yy_yypstack (yys
->yypred
);
2540 YYFPRINTF (stderr
, " -> ");
2542 YYFPRINTF (stderr
, "%d@@%lu", yys
->yylrState
,
2543 (unsigned long int) yys
->yyposn
);
2547 yypstates (yyGLRState
* yyst
)
2549 if (yyst
== YY_NULL
)
2550 YYFPRINTF (stderr
, "<null>");
2553 YYFPRINTF (stderr
, "\n");
2557 yypstack (yyGLRStack
* yystackp
, size_t yyk
)
2559 yypstates (yystackp
->yytops
.yystates
[yyk
]);
2562 #define YYINDEX(YYX) \
2563 ((YYX) == YY_NULL ? -1 : (yyGLRStackItem*) (YYX) - yystackp->yyitems)
2567 yypdumpstack (yyGLRStack
* yystackp
)
2569 yyGLRStackItem
* yyp
;
2571 for (yyp
= yystackp
->yyitems
; yyp
< yystackp
->yynextFree
; yyp
+= 1)
2573 YYFPRINTF (stderr
, "%3lu. ",
2574 (unsigned long int) (yyp
- yystackp
->yyitems
));
2575 if (*(yybool
*) yyp
)
2577 YYFPRINTF (stderr
, "Res: %d, LR State: %d, posn: %lu, pred: %ld",
2578 yyp
->yystate
.yyresolved
, yyp
->yystate
.yylrState
,
2579 (unsigned long int) yyp
->yystate
.yyposn
,
2580 (long int) YYINDEX (yyp
->yystate
.yypred
));
2581 if (! yyp
->yystate
.yyresolved
)
2582 YYFPRINTF (stderr
, ", firstVal: %ld",
2583 (long int) YYINDEX (yyp
->yystate
2584 .yysemantics
.yyfirstVal
));
2588 YYFPRINTF (stderr
, "Option. rule: %d, state: %ld, next: %ld",
2589 yyp
->yyoption
.yyrule
- 1,
2590 (long int) YYINDEX (yyp
->yyoption
.yystate
),
2591 (long int) YYINDEX (yyp
->yyoption
.yynext
));
2593 YYFPRINTF (stderr
, "\n");
2595 YYFPRINTF (stderr
, "Tops:");
2596 for (yyi
= 0; yyi
< yystackp
->yytops
.yysize
; yyi
+= 1)
2597 YYFPRINTF (stderr
, "%lu: %ld; ", (unsigned long int) yyi
,
2598 (long int) YYINDEX (yystackp
->yytops
.yystates
[yyi
]));
2599 YYFPRINTF (stderr
, "\n");
2604 dnl glr
.cc produces its own header
.
2606 m4_if(b4_skeleton
, ["glr.c"],
2608 [@
output(b4_spec_defines_file@
)@
2609 b4_copyright([Skeleton interface
for Bison GLR parsers in C
],
2612 ]b4_cpp_guard_open([b4_spec_defines_file
])[
2613 ]b4_shared_declarations
[
2614 ]b4_cpp_guard_close([b4_spec_defines_file
])[