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_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_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_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 [b4_symbol_value([(*yyvalp
)], [$
1])])
132 # b4_rhs_data(RULE-LENGTH, NUM)
133 # -----------------------------
134 # Expand to the semantic stack place that contains value and location
135 # of symbol number NUM in a rule of length RULE-LENGTH.
136 m4_define([b4_rhs_data
],
137 [((yyGLRStackItem
const *)yyvsp
)@
{YYFILL (b4_subtract([$
2], [$
1]))@
}.yystate
])
140 # b4_rhs_value(RULE-LENGTH, NUM, [TYPE])
141 # --------------------------------------
142 # Expansion of $<TYPE>NUM, where the current rule has RULE-LENGTH
144 m4_define([b4_rhs_value
],
145 [b4_symbol_value([b4_rhs_data([$
1], [$
2]).yysemantics
.yysval
], [$
3])])
156 m4_define([b4_lhs_location
],
160 # b4_rhs_location(RULE-LENGTH, NUM)
161 # ---------------------------------
162 # Expansion of @NUM, where the current rule has RULE-LENGTH symbols
164 m4_define([b4_rhs_location
],
165 [(b4_rhs_data([$
1], [$
2]).yyloc
)])
172 # b4_shared_declarations
173 # ----------------------
174 # Declaration that might either go into the header (if --defines)
175 # or open coded in the parser body. glr.cc has its own definition.
176 m4_if(b4_skeleton
, ["glr.c"],
177 [m4_define([b4_shared_declarations
],
179 ]b4_percent_code_get([[requires]])[
181 ]b4_declare_yylstype
[
182 ]b4_function_declare(b4_prefix
[parse
], [int], b4_parse_param
)[
183 ]b4_percent_code_get([[provides]])[]dnl
191 b4_output_begin([b4_parser_file_name
])
192 b4_copyright([Skeleton implementation
for Bison GLR parsers in C
],
195 /* C GLR parser skeleton written by Paul Hilfinger. */
199 b4_percent_code_get([[top]])[
200 ]m4_if(b4_api_prefix
, [yy
], [],
201 [[/* Substitute the type names. */
202 #define YYSTYPE ]b4_api_PREFIX[STYPE]b4_locations_if([[
203 #define YYLTYPE ]b4_api_PREFIX[LTYPE]])])[
204 ]m4_if(b4_prefix
, [yy
], [],
205 [[/* Substitute the variable and function names. */
206 #define yyparse ]b4_prefix[parse
207 #define yylex ]b4_prefix[lex
208 #define yyerror ]b4_prefix[error
209 #define yylval ]b4_prefix[lval
210 #define yychar ]b4_prefix[char
211 #define yydebug ]b4_prefix[debug
212 #define yynerrs ]b4_prefix[nerrs]b4_locations_if([[
213 #define yylloc ]b4_prefix[lloc]])])[
215 /* First part of user declarations. */
216 ]b4_user_pre_prologue
[
220 ]b4_defines_if([[#include "@basename(]b4_spec_defines_file[@)"]],
221 [b4_shared_declarations
])[
223 /* Enabling verbose error messages. */
224 #ifdef YYERROR_VERBOSE
225 # undef YYERROR_VERBOSE
226 # define YYERROR_VERBOSE 1
228 # define YYERROR_VERBOSE ]b4_error_verbose_if([1], [0])[
231 /* Default (constant) value used for initialization for null
232 right-hand sides. Unlike the standard yacc.c template, here we set
233 the default value of $$ to a zeroed-out value. Since the default
234 value is undefined, this behavior is technically correct. */
235 static YYSTYPE yyval_default
;]b4_locations_if([[
236 static YYLTYPE yyloc_default
][]b4_yyloc_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. */
260 # define YYUSE(E) ((void) (E))
262 # define YYUSE(E) /* empty */
269 # define YYMALLOC malloc
272 # define YYREALLOC realloc
275 #define YYSIZEMAX ((size_t) -1)
280 typedef unsigned char yybool
;
287 # define YYJMP_BUF jmp_buf
288 # define YYSETJMP(Env) setjmp (Env)
290 # define YYLONGJMP(Env, Val) (longjmp (Env, Val), YYASSERT (0))
297 #ifndef __attribute__
298 /* This feature is available in gcc versions 2.5 and later. */
299 # if (! defined __GNUC__ || __GNUC__ < 2 \
300 || (__GNUC__ == 2 && __GNUC_MINOR__ < 5))
301 # define __attribute__(Spec) /* empty */
306 # define YYASSERT(Condition) ((void) ((Condition) || (abort (), 0)))
309 /* YYFINAL -- State number of the termination state. */
310 #define YYFINAL ]b4_final_state_number[
311 /* YYLAST -- Last index in YYTABLE. */
312 #define YYLAST ]b4_last[
314 /* YYNTOKENS -- Number of terminals. */
315 #define YYNTOKENS ]b4_tokens_number[
316 /* YYNNTS -- Number of nonterminals. */
317 #define YYNNTS ]b4_nterms_number[
318 /* YYNRULES -- Number of rules. */
319 #define YYNRULES ]b4_rules_number[
320 /* YYNRULES -- Number of states. */
321 #define YYNSTATES ]b4_states_number[
322 /* YYMAXRHS -- Maximum number of symbols on right-hand side of rule. */
323 #define YYMAXRHS ]b4_r2_max[
324 /* YYMAXLEFT -- Maximum number of symbols to the left of a handle
325 accessed by $0, $-1, etc., in any rule. */
326 #define YYMAXLEFT ]b4_max_left_semantic_context[
328 /* YYTRANSLATE(X) -- Bison symbol number corresponding to X. */
329 #define YYUNDEFTOK ]b4_undef_token_number[
330 #define YYMAXUTOK ]b4_user_token_number_max[
332 #define YYTRANSLATE(YYX) \
333 ((unsigned int) (YYX) <= YYMAXUTOK ? yytranslate[YYX] : YYUNDEFTOK)
335 /* YYTRANSLATE[YYLEX] -- Bison symbol number corresponding to YYLEX. */
336 static const ]b4_int_type_for([b4_translate
])[ yytranslate
[] =
341 #if ]b4_api_PREFIX[DEBUG
342 /* YYRLINE[YYN] -- source line where rule number YYN was defined. */
343 static const ]b4_int_type_for([b4_rline
])[ yyrline
[] =
349 #if ]b4_api_PREFIX[DEBUG || YYERROR_VERBOSE || ]b4_token_table_flag[
350 /* YYTNAME[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM.
351 First, the terminals, then, starting at YYNTOKENS, nonterminals. */
352 static const char *const yytname
[] =
358 #define YYPACT_NINF ]b4_pact_ninf[
359 #define YYTABLE_NINF ]b4_table_ninf[
361 ]b4_parser_tables_define
[
363 /* YYDPREC[RULE-NUM] -- Dynamic precedence of rule #RULE-NUM (0 if none). */
364 static const ]b4_int_type_for([b4_dprec
])[ yydprec
[] =
369 /* YYMERGER[RULE-NUM] -- Index of merging function for rule #RULE-NUM. */
370 static const ]b4_int_type_for([b4_merger
])[ yymerger
[] =
375 /* YYIMMEDIATE[RULE-NUM] -- True iff rule #RULE-NUM is not to be deferred, as
376 in the case of predicates. */
377 static const yybool yyimmediate
[] =
382 /* YYCONFLP[YYPACT[STATE-NUM]] -- Pointer into YYCONFL of start of
383 list of conflicting reductions corresponding to action entry for
384 state STATE-NUM in yytable. 0 means no conflicts. The list in
385 yyconfl is terminated by a rule number of 0. */
386 static const ]b4_int_type_for([b4_conflict_list_heads
])[ yyconflp
[] =
388 ]b4_conflict_list_heads
[
391 /* YYCONFL[I] -- lists of conflicting rule numbers, each terminated by
392 0, pointed into by YYCONFLP. */
393 ]dnl Do
not use b4_int_type_for here
, since there are places where
394 dnl pointers onto yyconfl are taken
, which type is
"short int *".
395 dnl We probably ought to introduce a type
for confl
.
396 [static const short int yyconfl
[] =
398 ]b4_conflicting_rules
[
401 /* Error token number */
405 ]b4_yylloc_default_define
[
406 # define YYRHSLOC(Rhs, K) ((Rhs)[K].yystate.yyloc)
408 ]b4_yy_location_print_define
[
410 /* YYLEX -- calling `yylex' with the right arguments. */
411 #define YYLEX ]b4_function_call([yylex], [int], b4_lex_param)[
416 #define yynerrs (yystackp->yyerrcnt)
418 #define yychar (yystackp->yyrawchar)
420 #define yylval (yystackp->yyval)
422 #define yylloc (yystackp->yyloc)
423 m4_if(b4_prefix
[], [yy
], [],
424 [#define b4_prefix[]nerrs yynerrs
425 #define b4_prefix[]char yychar
426 #define b4_prefix[]lval yylval
427 #define b4_prefix[]lloc yylloc])],
428 [YYSTYPE yylval
;]b4_locations_if([[
434 static const int YYEOF
= 0;
435 static const int YYEMPTY
= -2;
437 typedef enum { yyok
, yyaccept
, yyabort
, yyerr
} YYRESULTTAG
;
441 YYRESULTTAG yychk_flag = YYE; \
442 if (yychk_flag != yyok) \
446 #if ]b4_api_PREFIX[DEBUG
449 # define YYFPRINTF fprintf
452 # define YYDPRINTF(Args) \
458 ]b4_yy_symbol_print_define
[
460 # define YY_SYMBOL_PRINT(Title, Type, Value, Location) \
464 YYFPRINTF (stderr, "%s ", Title); \
465 yy_symbol_print (stderr, Type, Value]b4_locuser_args([Location])[); \
466 YYFPRINTF (stderr, "\n"); \
470 /* Nonzero means print parse trace. It is left uninitialized so that
471 multiple parsers can coexist. */
474 #else /* !]b4_api_PREFIX[DEBUG */
476 # define YYDPRINTF(Args)
477 # define YY_SYMBOL_PRINT(Title, Type, Value, Location)
479 #endif /* !]b4_api_PREFIX[DEBUG */
481 /* YYINITDEPTH -- initial size of the parser's stacks. */
483 # define YYINITDEPTH ]b4_stack_depth_init[
486 /* YYMAXDEPTH -- maximum size the stacks can grow to (effective only
487 if the built-in stack extension method is used).
489 Do not make this value too large; the results are undefined if
490 SIZE_MAX < YYMAXDEPTH * sizeof (GLRStackItem)
491 evaluated with infinite-precision integer arithmetic. */
494 # define YYMAXDEPTH ]b4_stack_depth_max[
497 /* Minimum number of free items on the stack allowed after an
498 allocation. This is to allow allocation and initialization
499 to be completed by functions that call yyexpandGLRStack before the
500 stack is expanded, thus insuring that all necessary pointers get
501 properly redirected to new data. */
504 #ifndef YYSTACKEXPANDABLE
505 # define YYSTACKEXPANDABLE 1
508 #if YYSTACKEXPANDABLE
509 # define YY_RESERVE_GLRSTACK(Yystack) \
511 if (Yystack->yyspaceLeft < YYHEADROOM) \
512 yyexpandGLRStack (Yystack); \
515 # define YY_RESERVE_GLRSTACK(Yystack) \
517 if (Yystack->yyspaceLeft < YYHEADROOM) \
518 yyMemoryExhausted (Yystack); \
526 # if defined __GLIBC__ && defined _STRING_H && defined _GNU_SOURCE
527 # define yystpcpy stpcpy
529 /* Copy YYSRC to YYDEST, returning the address of the terminating '\0' in
532 yystpcpy (char *yydest
, const char *yysrc
)
535 const char *yys
= yysrc
;
537 while ((*yyd
++ = *yys
++) != '\0')
546 /* Copy to YYRES the contents of YYSTR after stripping away unnecessary
547 quotes and backslashes, so that it's suitable for yyerror. The
548 heuristic is that double-quoting is unnecessary unless the string
549 contains an apostrophe, a comma, or backslash (other than
550 backslash-backslash). YYSTR is taken from yytname. If YYRES is
551 null, do not copy; instead, return the length of what the result
554 yytnamerr (char *yyres
, const char *yystr
)
559 char const *yyp
= yystr
;
566 goto do_not_strip_quotes
;
570 goto do_not_strip_quotes
;
583 do_not_strip_quotes
: ;
587 return strlen (yystr
);
589 return yystpcpy (yyres
, yystr
) - yyres
;
593 #endif /* !YYERROR_VERBOSE */
595 /** State numbers, as in LALR(1) machine */
596 typedef int yyStateNum
;
598 /** Rule numbers, as in LALR(1) machine */
599 typedef int yyRuleNum
;
601 /** Grammar symbol */
602 typedef int yySymbol
;
604 /** Item references, as in LALR(1) machine */
605 typedef short int yyItemNum
;
607 typedef struct yyGLRState yyGLRState
;
608 typedef struct yyGLRStateSet yyGLRStateSet
;
609 typedef struct yySemanticOption yySemanticOption
;
610 typedef union yyGLRStackItem yyGLRStackItem
;
611 typedef struct yyGLRStack yyGLRStack
;
614 /** Type tag: always true. */
616 /** Type tag for yysemantics. If true, yysval applies, otherwise
617 * yyfirstVal applies. */
619 /** Number of corresponding LALR(1) machine state. */
620 yyStateNum yylrState
;
621 /** Preceding state in this stack */
623 /** Source position of the last token produced by my symbol */
626 /** First in a chain of alternative reductions producing the
627 * non-terminal corresponding to this state, threaded through
629 yySemanticOption
* yyfirstVal
;
630 /** Semantic value for this state. */
632 } yysemantics
;]b4_locations_if([[
633 /** Source location for this state. */
637 struct yyGLRStateSet
{
638 yyGLRState
** yystates
;
639 /** During nondeterministic operation, yylookaheadNeeds tracks which
640 * stacks have actually needed the current lookahead. During deterministic
641 * operation, yylookaheadNeeds[0] is not maintained since it would merely
642 * duplicate yychar != YYEMPTY. */
643 yybool
* yylookaheadNeeds
;
644 size_t yysize
, yycapacity
;
647 struct yySemanticOption
{
648 /** Type tag: always false. */
650 /** Rule number for this reduction */
652 /** The last RHS state in the list of states to be reduced. */
654 /** The lookahead for this reduction. */
656 YYSTYPE yyval
;]b4_locations_if([[
658 /** Next sibling in chain of options. To facilitate merging,
659 * options are chained in decreasing order by address. */
660 yySemanticOption
* yynext
;
663 /** Type of the items in the GLR stack. The yyisState field
664 * indicates which item of the union is valid. */
665 union yyGLRStackItem
{
667 yySemanticOption yyoption
;
672 ]b4_locations_if([[ /* To compute the location of the error token. */
673 yyGLRStackItem yyerror_range
[3];]])[
678 YYSTYPE yyval
;]b4_locations_if([[
681 YYJMP_BUF yyexception_buffer
;
682 yyGLRStackItem
* yyitems
;
683 yyGLRStackItem
* yynextFree
;
685 yyGLRState
* yysplitPoint
;
686 yyGLRState
* yylastDeleted
;
687 yyGLRStateSet yytops
;
690 #if YYSTACKEXPANDABLE
691 static void yyexpandGLRStack (yyGLRStack
* yystackp
);
694 static void yyFail (yyGLRStack
* yystackp
]b4_pure_formals
[, const char* yymsg
)
695 __attribute__ ((__noreturn__
));
697 yyFail (yyGLRStack
* yystackp
]b4_pure_formals
[, const char* yymsg
)
699 if (yymsg
!= YY_NULL
)
700 yyerror (]b4_yyerror_args
[yymsg
);
701 YYLONGJMP (yystackp
->yyexception_buffer
, 1);
704 static void yyMemoryExhausted (yyGLRStack
* yystackp
)
705 __attribute__ ((__noreturn__
));
707 yyMemoryExhausted (yyGLRStack
* yystackp
)
709 YYLONGJMP (yystackp
->yyexception_buffer
, 2);
712 #if ]b4_api_PREFIX[DEBUG || YYERROR_VERBOSE
713 /** A printable representation of TOKEN. */
714 static inline const char*
715 yytokenName (yySymbol yytoken
)
717 if (yytoken
== YYEMPTY
)
720 return yytname
[yytoken
];
724 /** Fill in YYVSP[YYLOW1 .. YYLOW0-1] from the chain of states starting
725 * at YYVSP[YYLOW0].yystate.yypred. Leaves YYVSP[YYLOW1].yystate.yypred
726 * containing the pointer to the next state in the chain. */
727 static void yyfillin (yyGLRStackItem
*, int, int) __attribute__ ((__unused__
));
729 yyfillin (yyGLRStackItem
*yyvsp
, int yylow0
, int yylow1
)
732 yyGLRState
*s
= yyvsp
[yylow0
].yystate
.yypred
;
733 for (i
= yylow0
-1; i
>= yylow1
; i
-= 1)
735 #if ]b4_api_PREFIX[DEBUG
736 yyvsp
[i
].yystate
.yylrState
= s
->yylrState
;
738 yyvsp
[i
].yystate
.yyresolved
= s
->yyresolved
;
740 yyvsp
[i
].yystate
.yysemantics
.yysval
= s
->yysemantics
.yysval
;
742 /* The effect of using yysval or yyloc (in an immediate rule) is
744 yyvsp
[i
].yystate
.yysemantics
.yyfirstVal
= YY_NULL
;]b4_locations_if([[
745 yyvsp
[i
].yystate
.yyloc
= s
->yyloc
;]])[
746 s
= yyvsp
[i
].yystate
.yypred
= s
->yypred
;
750 /* Do nothing if YYNORMAL or if *YYLOW <= YYLOW1. Otherwise, fill in
751 * YYVSP[YYLOW1 .. *YYLOW-1] as in yyfillin and set *YYLOW = YYLOW1.
752 * For convenience, always return YYLOW1. */
753 static inline int yyfill (yyGLRStackItem
*, int *, int, yybool
)
754 __attribute__ ((__unused__
));
756 yyfill (yyGLRStackItem
*yyvsp
, int *yylow
, int yylow1
, yybool yynormal
)
758 if (!yynormal
&& yylow1
< *yylow
)
760 yyfillin (yyvsp
, *yylow
, yylow1
);
766 /** Perform user action for rule number YYN, with RHS length YYRHSLEN,
767 * and top stack item YYVSP. YYLVALP points to place to put semantic
768 * value ($$), and yylocp points to place for location information
769 * (@@$). Returns yyok for normal return, yyaccept for YYACCEPT,
770 * yyerr for YYERROR, yyabort for YYABORT. */
772 yyuserAction (yyRuleNum yyn
, int yyrhslen
, yyGLRStackItem
* yyvsp
,
773 yyGLRStack
* yystackp
,
774 YYSTYPE
* yyvalp
]b4_locuser_formals
[)
776 yybool yynormal
__attribute__ ((__unused__
)) =
777 (yystackp
->yysplitPoint
== YY_NULL
);
779 ]b4_parse_param_use([yyvalp
], [yylocp
])dnl
781 # define yyerrok (yystackp->yyerrState = 0)
783 # define YYACCEPT return yyaccept
785 # define YYABORT return yyabort
787 # define YYERROR return yyerrok, yyerr
789 # define YYRECOVERING() (yystackp->yyerrState != 0)
791 # define yyclearin (yychar = YYEMPTY)
793 # define YYFILL(N) yyfill (yyvsp, &yylow, N, yynormal)
795 # define YYBACKUP(Token, Value) \
796 return yyerror (]b4_yyerror_args[YY_("syntax error: cannot back up")), \
801 *yyvalp
= yyval_default
;
803 *yyvalp
= yyvsp
[YYFILL (1-yyrhslen
)].yystate
.yysemantics
.yysval
;]b4_locations_if([[
804 YYLLOC_DEFAULT ((*yylocp
), (yyvsp
- yyrhslen
), yyrhslen
);
805 yystackp
->yyerror_range
[1].yystate
.yyloc
= *yylocp
;
825 yyuserMerge (int yyn
, YYSTYPE
* yy0
, YYSTYPE
* yy1
)
837 /* Bison grammar-table manipulation. */
839 ]b4_yydestruct_define
[
841 /** Number of symbols composing the right hand side of rule #RULE. */
843 yyrhsLength (yyRuleNum yyrule
)
849 yydestroyGLRState (char const *yymsg
, yyGLRState
*yys
]b4_user_formals
[)
852 yydestruct (yymsg
, yystos
[yys
->yylrState
],
853 &yys
->yysemantics
.yysval
]b4_locuser_args([&yys
->yyloc
])[);
856 #if ]b4_api_PREFIX[DEBUG
859 if (yys
->yysemantics
.yyfirstVal
)
860 YYFPRINTF (stderr
, "%s unresolved ", yymsg
);
862 YYFPRINTF (stderr
, "%s incomplete ", yymsg
);
863 yy_symbol_print (stderr
, yystos
[yys
->yylrState
],
864 YY_NULL
]b4_locuser_args([&yys
->yyloc
])[);
865 YYFPRINTF (stderr
, "\n");
869 if (yys
->yysemantics
.yyfirstVal
)
871 yySemanticOption
*yyoption
= yys
->yysemantics
.yyfirstVal
;
874 for (yyrh
= yyoption
->yystate
, yyn
= yyrhsLength (yyoption
->yyrule
);
876 yyrh
= yyrh
->yypred
, yyn
-= 1)
877 yydestroyGLRState (yymsg
, yyrh
]b4_user_args
[);
882 /** Left-hand-side symbol for rule #YYRULE. */
883 static inline yySymbol
884 yylhsNonterm (yyRuleNum yyrule
)
889 #define yypact_value_is_default(Yystate) \
890 ]b4_table_value_equals([[pact]], [[Yystate]], [b4_pact_ninf])[
892 /** True iff LR state YYSTATE has only a default reduction (regardless
895 yyisDefaultedState (yyStateNum yystate
)
897 return yypact_value_is_default (yypact
[yystate
]);
900 /** The default reduction for YYSTATE, assuming it has one. */
901 static inline yyRuleNum
902 yydefaultAction (yyStateNum yystate
)
904 return yydefact
[yystate
];
907 #define yytable_value_is_error(Yytable_value) \
908 ]b4_table_value_equals([[table]], [[Yytable_value]], [b4_table_ninf])[
910 /** Set *YYACTION to the action to take in YYSTATE on seeing YYTOKEN.
912 * R < 0: Reduce on rule -R.
914 * R > 0: Shift to state R.
915 * Set *YYCONFLICTS to a pointer into yyconfl to a 0-terminated list
916 * of conflicting reductions.
919 yygetLRActions (yyStateNum yystate
, int yytoken
,
920 int* yyaction
, const short int** yyconflicts
)
922 int yyindex
= yypact
[yystate
] + yytoken
;
923 if (yypact_value_is_default (yypact
[yystate
])
924 || yyindex
< 0 || YYLAST
< yyindex
|| yycheck
[yyindex
] != yytoken
)
926 *yyaction
= -yydefact
[yystate
];
927 *yyconflicts
= yyconfl
;
929 else if (! yytable_value_is_error (yytable
[yyindex
]))
931 *yyaction
= yytable
[yyindex
];
932 *yyconflicts
= yyconfl
+ yyconflp
[yyindex
];
937 *yyconflicts
= yyconfl
+ yyconflp
[yyindex
];
941 static inline yyStateNum
942 yyLRgotoState (yyStateNum yystate
, yySymbol yylhs
)
944 int yyr
= yypgoto
[yylhs
- YYNTOKENS
] + yystate
;
945 if (0 <= yyr
&& yyr
<= YYLAST
&& yycheck
[yyr
] == yystate
)
948 return yydefgoto
[yylhs
- YYNTOKENS
];
952 yyisShiftAction (int yyaction
)
958 yyisErrorAction (int yyaction
)
960 return yyaction
== 0;
965 /** Return a fresh GLRStackItem in YYSTACKP. The item is an LR state
966 * if YYISSTATE, and otherwise a semantic option. Callers should call
967 * YY_RESERVE_GLRSTACK afterwards to make sure there is sufficient
970 static inline yyGLRStackItem
*
971 yynewGLRStackItem (yyGLRStack
* yystackp
, yybool yyisState
)
973 yyGLRStackItem
* yynewItem
= yystackp
->yynextFree
;
974 yystackp
->yyspaceLeft
-= 1;
975 yystackp
->yynextFree
+= 1;
976 yynewItem
->yystate
.yyisState
= yyisState
;
980 /** Add a new semantic action that will execute the action for rule
981 * YYRULE on the semantic values in YYRHS to the list of
982 * alternative actions for YYSTATE. Assumes that YYRHS comes from
983 * stack #YYK of *YYSTACKP. */
985 yyaddDeferredAction (yyGLRStack
* yystackp
, size_t yyk
, yyGLRState
* yystate
,
986 yyGLRState
* yyrhs
, yyRuleNum yyrule
)
988 yySemanticOption
* yynewOption
=
989 &yynewGLRStackItem (yystackp
, yyfalse
)->yyoption
;
990 yynewOption
->yystate
= yyrhs
;
991 yynewOption
->yyrule
= yyrule
;
992 if (yystackp
->yytops
.yylookaheadNeeds
[yyk
])
994 yynewOption
->yyrawchar
= yychar
;
995 yynewOption
->yyval
= yylval
;]b4_locations_if([
996 yynewOption
->yyloc
= yylloc
;])[
999 yynewOption
->yyrawchar
= YYEMPTY
;
1000 yynewOption
->yynext
= yystate
->yysemantics
.yyfirstVal
;
1001 yystate
->yysemantics
.yyfirstVal
= yynewOption
;
1003 YY_RESERVE_GLRSTACK (yystackp
);
1008 /** Initialize YYSET to a singleton set containing an empty stack. */
1010 yyinitStateSet (yyGLRStateSet
* yyset
)
1013 yyset
->yycapacity
= 16;
1014 yyset
->yystates
= (yyGLRState
**) YYMALLOC (16 * sizeof yyset
->yystates
[0]);
1015 if (! yyset
->yystates
)
1017 yyset
->yystates
[0] = YY_NULL
;
1018 yyset
->yylookaheadNeeds
=
1019 (yybool
*) YYMALLOC (16 * sizeof yyset
->yylookaheadNeeds
[0]);
1020 if (! yyset
->yylookaheadNeeds
)
1022 YYFREE (yyset
->yystates
);
1028 static void yyfreeStateSet (yyGLRStateSet
* yyset
)
1030 YYFREE (yyset
->yystates
);
1031 YYFREE (yyset
->yylookaheadNeeds
);
1034 /** Initialize *YYSTACKP to a single empty stack, with total maximum
1035 * capacity for all stacks of YYSIZE. */
1037 yyinitGLRStack (yyGLRStack
* yystackp
, size_t yysize
)
1039 yystackp
->yyerrState
= 0;
1041 yystackp
->yyspaceLeft
= yysize
;
1043 (yyGLRStackItem
*) YYMALLOC (yysize
* sizeof yystackp
->yynextFree
[0]);
1044 if (!yystackp
->yyitems
)
1046 yystackp
->yynextFree
= yystackp
->yyitems
;
1047 yystackp
->yysplitPoint
= YY_NULL
;
1048 yystackp
->yylastDeleted
= YY_NULL
;
1049 return yyinitStateSet (&yystackp
->yytops
);
1053 #if YYSTACKEXPANDABLE
1054 # define YYRELOC(YYFROMITEMS,YYTOITEMS,YYX,YYTYPE) \
1055 &((YYTOITEMS) - ((YYFROMITEMS) - (yyGLRStackItem*) (YYX)))->YYTYPE
1057 /** If *YYSTACKP is expandable, extend it. WARNING: Pointers into the
1058 stack from outside should be considered invalid after this call.
1059 We always expand when there are 1 or fewer items left AFTER an
1060 allocation, so that we can avoid having external pointers exist
1061 across an allocation. */
1063 yyexpandGLRStack (yyGLRStack
* yystackp
)
1065 yyGLRStackItem
* yynewItems
;
1066 yyGLRStackItem
* yyp0
, *yyp1
;
1069 size_t yysize
= yystackp
->yynextFree
- yystackp
->yyitems
;
1070 if (YYMAXDEPTH
- YYHEADROOM
< yysize
)
1071 yyMemoryExhausted (yystackp
);
1072 yynewSize
= 2*yysize
;
1073 if (YYMAXDEPTH
< yynewSize
)
1074 yynewSize
= YYMAXDEPTH
;
1075 yynewItems
= (yyGLRStackItem
*) YYMALLOC (yynewSize
* sizeof yynewItems
[0]);
1077 yyMemoryExhausted (yystackp
);
1078 for (yyp0
= yystackp
->yyitems
, yyp1
= yynewItems
, yyn
= yysize
;
1080 yyn
-= 1, yyp0
+= 1, yyp1
+= 1)
1083 if (*(yybool
*) yyp0
)
1085 yyGLRState
* yys0
= &yyp0
->yystate
;
1086 yyGLRState
* yys1
= &yyp1
->yystate
;
1087 if (yys0
->yypred
!= YY_NULL
)
1089 YYRELOC (yyp0
, yyp1
, yys0
->yypred
, yystate
);
1090 if (! yys0
->yyresolved
&& yys0
->yysemantics
.yyfirstVal
!= YY_NULL
)
1091 yys1
->yysemantics
.yyfirstVal
=
1092 YYRELOC (yyp0
, yyp1
, yys0
->yysemantics
.yyfirstVal
, yyoption
);
1096 yySemanticOption
* yyv0
= &yyp0
->yyoption
;
1097 yySemanticOption
* yyv1
= &yyp1
->yyoption
;
1098 if (yyv0
->yystate
!= YY_NULL
)
1099 yyv1
->yystate
= YYRELOC (yyp0
, yyp1
, yyv0
->yystate
, yystate
);
1100 if (yyv0
->yynext
!= YY_NULL
)
1101 yyv1
->yynext
= YYRELOC (yyp0
, yyp1
, yyv0
->yynext
, yyoption
);
1104 if (yystackp
->yysplitPoint
!= YY_NULL
)
1105 yystackp
->yysplitPoint
= YYRELOC (yystackp
->yyitems
, yynewItems
,
1106 yystackp
->yysplitPoint
, yystate
);
1108 for (yyn
= 0; yyn
< yystackp
->yytops
.yysize
; yyn
+= 1)
1109 if (yystackp
->yytops
.yystates
[yyn
] != YY_NULL
)
1110 yystackp
->yytops
.yystates
[yyn
] =
1111 YYRELOC (yystackp
->yyitems
, yynewItems
,
1112 yystackp
->yytops
.yystates
[yyn
], yystate
);
1113 YYFREE (yystackp
->yyitems
);
1114 yystackp
->yyitems
= yynewItems
;
1115 yystackp
->yynextFree
= yynewItems
+ yysize
;
1116 yystackp
->yyspaceLeft
= yynewSize
- yysize
;
1121 yyfreeGLRStack (yyGLRStack
* yystackp
)
1123 YYFREE (yystackp
->yyitems
);
1124 yyfreeStateSet (&yystackp
->yytops
);
1127 /** Assuming that YYS is a GLRState somewhere on *YYSTACKP, update the
1128 * splitpoint of *YYSTACKP, if needed, so that it is at least as deep as
1131 yyupdateSplit (yyGLRStack
* yystackp
, yyGLRState
* yys
)
1133 if (yystackp
->yysplitPoint
!= YY_NULL
&& yystackp
->yysplitPoint
> yys
)
1134 yystackp
->yysplitPoint
= yys
;
1137 /** Invalidate stack #YYK in *YYSTACKP. */
1139 yymarkStackDeleted (yyGLRStack
* yystackp
, size_t yyk
)
1141 if (yystackp
->yytops
.yystates
[yyk
] != YY_NULL
)
1142 yystackp
->yylastDeleted
= yystackp
->yytops
.yystates
[yyk
];
1143 yystackp
->yytops
.yystates
[yyk
] = YY_NULL
;
1146 /** Undelete the last stack in *YYSTACKP that was marked as deleted. Can
1147 only be done once after a deletion, and only when all other stacks have
1150 yyundeleteLastStack (yyGLRStack
* yystackp
)
1152 if (yystackp
->yylastDeleted
== YY_NULL
|| yystackp
->yytops
.yysize
!= 0)
1154 yystackp
->yytops
.yystates
[0] = yystackp
->yylastDeleted
;
1155 yystackp
->yytops
.yysize
= 1;
1156 YYDPRINTF ((stderr
, "Restoring last deleted stack as stack #0.\n"));
1157 yystackp
->yylastDeleted
= YY_NULL
;
1161 yyremoveDeletes (yyGLRStack
* yystackp
)
1165 while (yyj
< yystackp
->yytops
.yysize
)
1167 if (yystackp
->yytops
.yystates
[yyi
] == YY_NULL
)
1171 YYDPRINTF ((stderr
, "Removing dead stacks.\n"));
1173 yystackp
->yytops
.yysize
-= 1;
1177 yystackp
->yytops
.yystates
[yyj
] = yystackp
->yytops
.yystates
[yyi
];
1178 /* In the current implementation, it's unnecessary to copy
1179 yystackp->yytops.yylookaheadNeeds[yyi] since, after
1180 yyremoveDeletes returns, the parser immediately either enters
1181 deterministic operation or shifts a token. However, it doesn't
1182 hurt, and the code might evolve to need it. */
1183 yystackp
->yytops
.yylookaheadNeeds
[yyj
] =
1184 yystackp
->yytops
.yylookaheadNeeds
[yyi
];
1187 YYDPRINTF ((stderr
, "Rename stack %lu -> %lu.\n",
1188 (unsigned long int) yyi
, (unsigned long int) yyj
));
1196 /** Shift to a new state on stack #YYK of *YYSTACKP, corresponding to LR
1197 * state YYLRSTATE, at input position YYPOSN, with (resolved) semantic
1198 * value *YYVALP and source location *YYLOCP. */
1200 yyglrShift (yyGLRStack
* yystackp
, size_t yyk
, yyStateNum yylrState
,
1202 YYSTYPE
* yyvalp
]b4_locations_if([, YYLTYPE
* yylocp
])[)
1204 yyGLRState
* yynewState
= &yynewGLRStackItem (yystackp
, yytrue
)->yystate
;
1206 yynewState
->yylrState
= yylrState
;
1207 yynewState
->yyposn
= yyposn
;
1208 yynewState
->yyresolved
= yytrue
;
1209 yynewState
->yypred
= yystackp
->yytops
.yystates
[yyk
];
1210 yynewState
->yysemantics
.yysval
= *yyvalp
;]b4_locations_if([
1211 yynewState
->yyloc
= *yylocp
;])[
1212 yystackp
->yytops
.yystates
[yyk
] = yynewState
;
1214 YY_RESERVE_GLRSTACK (yystackp
);
1217 /** Shift stack #YYK of *YYSTACKP, to a new state corresponding to LR
1218 * state YYLRSTATE, at input position YYPOSN, with the (unresolved)
1219 * semantic value of YYRHS under the action for YYRULE. */
1221 yyglrShiftDefer (yyGLRStack
* yystackp
, size_t yyk
, yyStateNum yylrState
,
1222 size_t yyposn
, yyGLRState
* yyrhs
, yyRuleNum yyrule
)
1224 yyGLRState
* yynewState
= &yynewGLRStackItem (yystackp
, yytrue
)->yystate
;
1226 yynewState
->yylrState
= yylrState
;
1227 yynewState
->yyposn
= yyposn
;
1228 yynewState
->yyresolved
= yyfalse
;
1229 yynewState
->yypred
= yystackp
->yytops
.yystates
[yyk
];
1230 yynewState
->yysemantics
.yyfirstVal
= YY_NULL
;
1231 yystackp
->yytops
.yystates
[yyk
] = yynewState
;
1233 /* Invokes YY_RESERVE_GLRSTACK. */
1234 yyaddDeferredAction (yystackp
, yyk
, yynewState
, yyrhs
, yyrule
);
1237 #if !]b4_api_PREFIX[DEBUG
1238 # define YY_REDUCE_PRINT(Args)
1240 # define YY_REDUCE_PRINT(Args) \
1243 yy_reduce_print Args; \
1246 /*----------------------------------------------------------------------.
1247 | Report that stack #YYK of *YYSTACKP is going to be reduced by YYRULE. |
1248 `----------------------------------------------------------------------*/
1251 yy_reduce_print (int yynormal
, yyGLRStackItem
* yyvsp
, size_t yyk
,
1252 yyRuleNum yyrule
]b4_user_formals
[)
1254 int yynrhs
= yyrhsLength (yyrule
);]b4_locations_if([
1257 YYFPRINTF (stderr
, "Reducing stack %lu by rule %d (line %lu):\n",
1258 (unsigned long int) yyk
, yyrule
- 1,
1259 (unsigned long int) yyrline
[yyrule
]);
1261 yyfillin (yyvsp
, 1, -yynrhs
);
1262 /* The symbols being reduced. */
1263 for (yyi
= 0; yyi
< yynrhs
; yyi
++)
1265 YYFPRINTF (stderr
, " $%d = ", yyi
+ 1);
1266 yy_symbol_print (stderr
,
1267 yystos
[yyvsp
[yyi
- yynrhs
+ 1].yystate
.yylrState
],
1268 &yyvsp
[yyi
- yynrhs
+ 1].yystate
.yysemantics
.yysval
1269 ]b4_locations_if([, &]b4_rhs_location(yynrhs
, yyi
+ 1))[]dnl
1271 if (!yyvsp
[yyi
- yynrhs
+ 1].yystate
.yyresolved
)
1272 YYFPRINTF (stderr
, " (unresolved)");
1273 YYFPRINTF (stderr
, "\n");
1278 /** Pop the symbols consumed by reduction #YYRULE from the top of stack
1279 * #YYK of *YYSTACKP, and perform the appropriate semantic action on their
1280 * semantic values. Assumes that all ambiguities in semantic values
1281 * have been previously resolved. Set *YYVALP to the resulting value,
1282 * and *YYLOCP to the computed location (if any). Return value is as
1283 * for userAction. */
1284 static inline YYRESULTTAG
1285 yydoAction (yyGLRStack
* yystackp
, size_t yyk
, yyRuleNum yyrule
,
1286 YYSTYPE
* yyvalp
]b4_locuser_formals
[)
1288 int yynrhs
= yyrhsLength (yyrule
);
1290 if (yystackp
->yysplitPoint
== YY_NULL
)
1292 /* Standard special case: single stack. */
1293 yyGLRStackItem
* yyrhs
= (yyGLRStackItem
*) yystackp
->yytops
.yystates
[yyk
];
1294 YYASSERT (yyk
== 0);
1295 yystackp
->yynextFree
-= yynrhs
;
1296 yystackp
->yyspaceLeft
+= yynrhs
;
1297 yystackp
->yytops
.yystates
[0] = & yystackp
->yynextFree
[-1].yystate
;
1298 YY_REDUCE_PRINT ((1, yyrhs
, yyk
, yyrule
]b4_user_args
[));
1299 return yyuserAction (yyrule
, yynrhs
, yyrhs
, yystackp
,
1300 yyvalp
]b4_locuser_args
[);
1306 yyGLRStackItem yyrhsVals
[YYMAXRHS
+ YYMAXLEFT
+ 1];
1307 yys
= yyrhsVals
[YYMAXRHS
+ YYMAXLEFT
].yystate
.yypred
1308 = yystackp
->yytops
.yystates
[yyk
];]b4_locations_if([[
1310 /* Set default location. */
1311 yyrhsVals
[YYMAXRHS
+ YYMAXLEFT
- 1].yystate
.yyloc
= yys
->yyloc
;]])[
1312 for (yyi
= 0; yyi
< yynrhs
; yyi
+= 1)
1317 yyupdateSplit (yystackp
, yys
);
1318 yystackp
->yytops
.yystates
[yyk
] = yys
;
1319 YY_REDUCE_PRINT ((0, yyrhsVals
+ YYMAXRHS
+ YYMAXLEFT
- 1, yyk
, yyrule
]b4_user_args
[));
1320 return yyuserAction (yyrule
, yynrhs
, yyrhsVals
+ YYMAXRHS
+ YYMAXLEFT
- 1,
1321 yystackp
, yyvalp
]b4_locuser_args
[);
1325 /** Pop items off stack #YYK of *YYSTACKP according to grammar rule YYRULE,
1326 * and push back on the resulting nonterminal symbol. Perform the
1327 * semantic action associated with YYRULE and store its value with the
1328 * newly pushed state, if YYFORCEEVAL or if *YYSTACKP is currently
1329 * unambiguous. Otherwise, store the deferred semantic action with
1330 * the new state. If the new state would have an identical input
1331 * position, LR state, and predecessor to an existing state on the stack,
1332 * it is identified with that existing state, eliminating stack #YYK from
1333 * *YYSTACKP. In this case, the semantic value is
1334 * added to the options for the existing state's semantic value.
1336 static inline YYRESULTTAG
1337 yyglrReduce (yyGLRStack
* yystackp
, size_t yyk
, yyRuleNum yyrule
,
1338 yybool yyforceEval
]b4_user_formals
[)
1340 size_t yyposn
= yystackp
->yytops
.yystates
[yyk
]->yyposn
;
1342 if (yyforceEval
|| yystackp
->yysplitPoint
== YY_NULL
)
1345 YYSTYPE yysval
;]b4_locations_if([
1348 yyflag
= yydoAction (yystackp
, yyk
, yyrule
, &yysval
]b4_locuser_args([&yyloc
])[);
1349 if (yyflag
== yyerr
&& yystackp
->yysplitPoint
!= YY_NULL
)
1351 YYDPRINTF ((stderr
, "Parse on stack %lu rejected by rule #%d.\n",
1352 (unsigned long int) yyk
, yyrule
- 1));
1356 YY_SYMBOL_PRINT ("-> $$ =", yyr1
[yyrule
], &yysval
, &yyloc
);
1357 yyglrShift (yystackp
, yyk
,
1358 yyLRgotoState (yystackp
->yytops
.yystates
[yyk
]->yylrState
,
1359 yylhsNonterm (yyrule
)),
1360 yyposn
, &yysval
]b4_locations_if([, &yyloc
])[);
1366 yyGLRState
* yys
, *yys0
= yystackp
->yytops
.yystates
[yyk
];
1367 yyStateNum yynewLRState
;
1369 for (yys
= yystackp
->yytops
.yystates
[yyk
], yyn
= yyrhsLength (yyrule
);
1375 yyupdateSplit (yystackp
, yys
);
1376 yynewLRState
= yyLRgotoState (yys
->yylrState
, yylhsNonterm (yyrule
));
1378 "Reduced stack %lu by rule #%d; action deferred. "
1379 "Now in state %d.\n",
1380 (unsigned long int) yyk
, yyrule
- 1, yynewLRState
));
1381 for (yyi
= 0; yyi
< yystackp
->yytops
.yysize
; yyi
+= 1)
1382 if (yyi
!= yyk
&& yystackp
->yytops
.yystates
[yyi
] != YY_NULL
)
1384 yyGLRState
*yysplit
= yystackp
->yysplitPoint
;
1385 yyGLRState
*yyp
= yystackp
->yytops
.yystates
[yyi
];
1386 while (yyp
!= yys
&& yyp
!= yysplit
&& yyp
->yyposn
>= yyposn
)
1388 if (yyp
->yylrState
== yynewLRState
&& yyp
->yypred
== yys
)
1390 yyaddDeferredAction (yystackp
, yyk
, yyp
, yys0
, yyrule
);
1391 yymarkStackDeleted (yystackp
, yyk
);
1392 YYDPRINTF ((stderr
, "Merging stack %lu into stack %lu.\n",
1393 (unsigned long int) yyk
,
1394 (unsigned long int) yyi
));
1400 yystackp
->yytops
.yystates
[yyk
] = yys
;
1401 yyglrShiftDefer (yystackp
, yyk
, yynewLRState
, yyposn
, yys0
, yyrule
);
1407 yysplitStack (yyGLRStack
* yystackp
, size_t yyk
)
1409 if (yystackp
->yysplitPoint
== YY_NULL
)
1411 YYASSERT (yyk
== 0);
1412 yystackp
->yysplitPoint
= yystackp
->yytops
.yystates
[yyk
];
1414 if (yystackp
->yytops
.yysize
>= yystackp
->yytops
.yycapacity
)
1416 yyGLRState
** yynewStates
;
1417 yybool
* yynewLookaheadNeeds
;
1419 yynewStates
= YY_NULL
;
1421 if (yystackp
->yytops
.yycapacity
1422 > (YYSIZEMAX
/ (2 * sizeof yynewStates
[0])))
1423 yyMemoryExhausted (yystackp
);
1424 yystackp
->yytops
.yycapacity
*= 2;
1427 (yyGLRState
**) YYREALLOC (yystackp
->yytops
.yystates
,
1428 (yystackp
->yytops
.yycapacity
1429 * sizeof yynewStates
[0]));
1430 if (yynewStates
== YY_NULL
)
1431 yyMemoryExhausted (yystackp
);
1432 yystackp
->yytops
.yystates
= yynewStates
;
1434 yynewLookaheadNeeds
=
1435 (yybool
*) YYREALLOC (yystackp
->yytops
.yylookaheadNeeds
,
1436 (yystackp
->yytops
.yycapacity
1437 * sizeof yynewLookaheadNeeds
[0]));
1438 if (yynewLookaheadNeeds
== YY_NULL
)
1439 yyMemoryExhausted (yystackp
);
1440 yystackp
->yytops
.yylookaheadNeeds
= yynewLookaheadNeeds
;
1442 yystackp
->yytops
.yystates
[yystackp
->yytops
.yysize
]
1443 = yystackp
->yytops
.yystates
[yyk
];
1444 yystackp
->yytops
.yylookaheadNeeds
[yystackp
->yytops
.yysize
]
1445 = yystackp
->yytops
.yylookaheadNeeds
[yyk
];
1446 yystackp
->yytops
.yysize
+= 1;
1447 return yystackp
->yytops
.yysize
-1;
1450 /** True iff YYY0 and YYY1 represent identical options at the top level.
1451 * That is, they represent the same rule applied to RHS symbols
1452 * that produce the same terminal symbols. */
1454 yyidenticalOptions (yySemanticOption
* yyy0
, yySemanticOption
* yyy1
)
1456 if (yyy0
->yyrule
== yyy1
->yyrule
)
1458 yyGLRState
*yys0
, *yys1
;
1460 for (yys0
= yyy0
->yystate
, yys1
= yyy1
->yystate
,
1461 yyn
= yyrhsLength (yyy0
->yyrule
);
1463 yys0
= yys0
->yypred
, yys1
= yys1
->yypred
, yyn
-= 1)
1464 if (yys0
->yyposn
!= yys1
->yyposn
)
1472 /** Assuming identicalOptions (YYY0,YYY1), destructively merge the
1473 * alternative semantic values for the RHS-symbols of YYY1 and YYY0. */
1475 yymergeOptionSets (yySemanticOption
* yyy0
, yySemanticOption
* yyy1
)
1477 yyGLRState
*yys0
, *yys1
;
1479 for (yys0
= yyy0
->yystate
, yys1
= yyy1
->yystate
,
1480 yyn
= yyrhsLength (yyy0
->yyrule
);
1482 yys0
= yys0
->yypred
, yys1
= yys1
->yypred
, yyn
-= 1)
1486 else if (yys0
->yyresolved
)
1488 yys1
->yyresolved
= yytrue
;
1489 yys1
->yysemantics
.yysval
= yys0
->yysemantics
.yysval
;
1491 else if (yys1
->yyresolved
)
1493 yys0
->yyresolved
= yytrue
;
1494 yys0
->yysemantics
.yysval
= yys1
->yysemantics
.yysval
;
1498 yySemanticOption
** yyz0p
= &yys0
->yysemantics
.yyfirstVal
;
1499 yySemanticOption
* yyz1
= yys1
->yysemantics
.yyfirstVal
;
1502 if (yyz1
== *yyz0p
|| yyz1
== YY_NULL
)
1504 else if (*yyz0p
== YY_NULL
)
1509 else if (*yyz0p
< yyz1
)
1511 yySemanticOption
* yyz
= *yyz0p
;
1513 yyz1
= yyz1
->yynext
;
1514 (*yyz0p
)->yynext
= yyz
;
1516 yyz0p
= &(*yyz0p
)->yynext
;
1518 yys1
->yysemantics
.yyfirstVal
= yys0
->yysemantics
.yyfirstVal
;
1523 /** Y0 and Y1 represent two possible actions to take in a given
1524 * parsing state; return 0 if no combination is possible,
1525 * 1 if user-mergeable, 2 if Y0 is preferred, 3 if Y1 is preferred. */
1527 yypreference (yySemanticOption
* y0
, yySemanticOption
* y1
)
1529 yyRuleNum r0
= y0
->yyrule
, r1
= y1
->yyrule
;
1530 int p0
= yydprec
[r0
], p1
= yydprec
[r1
];
1534 if (yymerger
[r0
] == 0 || yymerger
[r0
] != yymerger
[r1
])
1539 if (p0
== 0 || p1
== 0)
1548 static YYRESULTTAG
yyresolveValue (yyGLRState
* yys
,
1549 yyGLRStack
* yystackp
]b4_user_formals
[);
1552 /** Resolve the previous YYN states starting at and including state YYS
1553 * on *YYSTACKP. If result != yyok, some states may have been left
1554 * unresolved possibly with empty semantic option chains. Regardless
1555 * of whether result = yyok, each state has been left with consistent
1556 * data so that yydestroyGLRState can be invoked if necessary. */
1558 yyresolveStates (yyGLRState
* yys
, int yyn
,
1559 yyGLRStack
* yystackp
]b4_user_formals
[)
1563 YYASSERT (yys
->yypred
);
1564 YYCHK (yyresolveStates (yys
->yypred
, yyn
-1, yystackp
]b4_user_args
[));
1565 if (! yys
->yyresolved
)
1566 YYCHK (yyresolveValue (yys
, yystackp
]b4_user_args
[));
1571 /** Resolve the states for the RHS of YYOPT on *YYSTACKP, perform its
1572 * user action, and return the semantic value and location in *YYVALP
1573 * and *YYLOCP. Regardless of whether result = yyok, all RHS states
1574 * have been destroyed (assuming the user action destroys all RHS
1575 * semantic values if invoked). */
1577 yyresolveAction (yySemanticOption
* yyopt
, yyGLRStack
* yystackp
,
1578 YYSTYPE
* yyvalp
]b4_locuser_formals
[)
1580 yyGLRStackItem yyrhsVals
[YYMAXRHS
+ YYMAXLEFT
+ 1];
1581 int yynrhs
= yyrhsLength (yyopt
->yyrule
);
1582 YYRESULTTAG yyflag
=
1583 yyresolveStates (yyopt
->yystate
, yynrhs
, yystackp
]b4_user_args
[);
1587 for (yys
= yyopt
->yystate
; yynrhs
> 0; yys
= yys
->yypred
, yynrhs
-= 1)
1588 yydestroyGLRState ("Cleanup: popping", yys
]b4_user_args
[);
1592 yyrhsVals
[YYMAXRHS
+ YYMAXLEFT
].yystate
.yypred
= yyopt
->yystate
;]b4_locations_if([[
1594 /* Set default location. */
1595 yyrhsVals
[YYMAXRHS
+ YYMAXLEFT
- 1].yystate
.yyloc
= yyopt
->yystate
->yyloc
;]])[
1597 int yychar_current
= yychar
;
1598 YYSTYPE yylval_current
= yylval
;]b4_locations_if([
1599 YYLTYPE yylloc_current
= yylloc
;])[
1600 yychar
= yyopt
->yyrawchar
;
1601 yylval
= yyopt
->yyval
;]b4_locations_if([
1602 yylloc
= yyopt
->yyloc
;])[
1603 yyflag
= yyuserAction (yyopt
->yyrule
, yynrhs
,
1604 yyrhsVals
+ YYMAXRHS
+ YYMAXLEFT
- 1,
1605 yystackp
, yyvalp
]b4_locuser_args
[);
1606 yychar
= yychar_current
;
1607 yylval
= yylval_current
;]b4_locations_if([
1608 yylloc
= yylloc_current
;])[
1613 #if ]b4_api_PREFIX[DEBUG
1615 yyreportTree (yySemanticOption
* yyx
, int yyindent
)
1617 int yynrhs
= yyrhsLength (yyx
->yyrule
);
1620 yyGLRState
* yystates
[1 + YYMAXRHS
];
1621 yyGLRState yyleftmost_state
;
1623 for (yyi
= yynrhs
, yys
= yyx
->yystate
; 0 < yyi
; yyi
-= 1, yys
= yys
->yypred
)
1624 yystates
[yyi
] = yys
;
1627 yyleftmost_state
.yyposn
= 0;
1628 yystates
[0] = &yyleftmost_state
;
1633 if (yyx
->yystate
->yyposn
< yys
->yyposn
+ 1)
1634 YYFPRINTF (stderr
, "%*s%s -> <Rule %d, empty>\n",
1635 yyindent
, "", yytokenName (yylhsNonterm (yyx
->yyrule
)),
1638 YYFPRINTF (stderr
, "%*s%s -> <Rule %d, tokens %lu .. %lu>\n",
1639 yyindent
, "", yytokenName (yylhsNonterm (yyx
->yyrule
)),
1640 yyx
->yyrule
- 1, (unsigned long int) (yys
->yyposn
+ 1),
1641 (unsigned long int) yyx
->yystate
->yyposn
);
1642 for (yyi
= 1; yyi
<= yynrhs
; yyi
+= 1)
1644 if (yystates
[yyi
]->yyresolved
)
1646 if (yystates
[yyi
-1]->yyposn
+1 > yystates
[yyi
]->yyposn
)
1647 YYFPRINTF (stderr
, "%*s%s <empty>\n", yyindent
+2, "",
1648 yytokenName (yystos
[yystates
[yyi
]->yylrState
]));
1650 YYFPRINTF (stderr
, "%*s%s <tokens %lu .. %lu>\n", yyindent
+2, "",
1651 yytokenName (yystos
[yystates
[yyi
]->yylrState
]),
1652 (unsigned long int) (yystates
[yyi
-1]->yyposn
+ 1),
1653 (unsigned long int) yystates
[yyi
]->yyposn
);
1656 yyreportTree (yystates
[yyi
]->yysemantics
.yyfirstVal
, yyindent
+2);
1662 yyreportAmbiguity (yySemanticOption
* yyx0
,
1663 yySemanticOption
* yyx1
]b4_pure_formals
[)
1668 #if ]b4_api_PREFIX[DEBUG
1669 YYFPRINTF (stderr
, "Ambiguity detected.\n");
1670 YYFPRINTF (stderr
, "Option 1,\n");
1671 yyreportTree (yyx0
, 2);
1672 YYFPRINTF (stderr
, "\nOption 2,\n");
1673 yyreportTree (yyx1
, 2);
1674 YYFPRINTF (stderr
, "\n");
1677 yyerror (]b4_yyerror_args
[YY_("syntax is ambiguous"));
1679 }]b4_locations_if([[
1681 /** Resolve the locations for each of the YYN1 states in *YYSTACKP,
1682 * ending at YYS1. Has no effect on previously resolved states.
1683 * The first semantic option of a state is always chosen. */
1685 yyresolveLocations (yyGLRState
* yys1
, int yyn1
,
1686 yyGLRStack
*yystackp
]b4_user_formals
[)
1690 yyresolveLocations (yys1
->yypred
, yyn1
- 1, yystackp
]b4_user_args
[);
1691 if (!yys1
->yyresolved
)
1693 yyGLRStackItem yyrhsloc
[1 + YYMAXRHS
];
1695 yySemanticOption
*yyoption
= yys1
->yysemantics
.yyfirstVal
;
1696 YYASSERT (yyoption
!= YY_NULL
);
1697 yynrhs
= yyrhsLength (yyoption
->yyrule
);
1702 yyresolveLocations (yyoption
->yystate
, yynrhs
,
1703 yystackp
]b4_user_args
[);
1704 for (yys
= yyoption
->yystate
, yyn
= yynrhs
;
1706 yys
= yys
->yypred
, yyn
-= 1)
1707 yyrhsloc
[yyn
].yystate
.yyloc
= yys
->yyloc
;
1711 /* Both yyresolveAction and yyresolveLocations traverse the GSS
1712 in reverse rightmost order. It is only necessary to invoke
1713 yyresolveLocations on a subforest for which yyresolveAction
1714 would have been invoked next had an ambiguity not been
1715 detected. Thus the location of the previous state (but not
1716 necessarily the previous state itself) is guaranteed to be
1717 resolved already. */
1718 yyGLRState
*yyprevious
= yyoption
->yystate
;
1719 yyrhsloc
[0].yystate
.yyloc
= yyprevious
->yyloc
;
1722 int yychar_current
= yychar
;
1723 YYSTYPE yylval_current
= yylval
;
1724 YYLTYPE yylloc_current
= yylloc
;
1725 yychar
= yyoption
->yyrawchar
;
1726 yylval
= yyoption
->yyval
;
1727 yylloc
= yyoption
->yyloc
;
1728 YYLLOC_DEFAULT ((yys1
->yyloc
), yyrhsloc
, yynrhs
);
1729 yychar
= yychar_current
;
1730 yylval
= yylval_current
;
1731 yylloc
= yylloc_current
;
1737 /** Resolve the ambiguity represented in state YYS in *YYSTACKP,
1738 * perform the indicated actions, and set the semantic value of YYS.
1739 * If result != yyok, the chain of semantic options in YYS has been
1740 * cleared instead or it has been left unmodified except that
1741 * redundant options may have been removed. Regardless of whether
1742 * result = yyok, YYS has been left with consistent data so that
1743 * yydestroyGLRState can be invoked if necessary. */
1745 yyresolveValue (yyGLRState
* yys
, yyGLRStack
* yystackp
]b4_user_formals
[)
1747 yySemanticOption
* yyoptionList
= yys
->yysemantics
.yyfirstVal
;
1748 yySemanticOption
* yybest
= yyoptionList
;
1749 yySemanticOption
** yypp
;
1750 yybool yymerge
= yyfalse
;
1752 YYRESULTTAG yyflag
;]b4_locations_if([
1753 YYLTYPE
*yylocp
= &yys
->yyloc
;])[
1755 for (yypp
= &yyoptionList
->yynext
; *yypp
!= YY_NULL
; )
1757 yySemanticOption
* yyp
= *yypp
;
1759 if (yyidenticalOptions (yybest
, yyp
))
1761 yymergeOptionSets (yybest
, yyp
);
1762 *yypp
= yyp
->yynext
;
1766 switch (yypreference (yybest
, yyp
))
1768 case 0:]b4_locations_if([[
1769 yyresolveLocations (yys
, 1, yystackp
]b4_user_args
[);]])[
1770 return yyreportAmbiguity (yybest
, yyp
]b4_pure_args
[);
1782 /* This cannot happen so it is not worth a YYASSERT (yyfalse),
1783 but some compilers complain if the default case is
1787 yypp
= &yyp
->yynext
;
1793 yySemanticOption
* yyp
;
1794 int yyprec
= yydprec
[yybest
->yyrule
];
1795 yyflag
= yyresolveAction (yybest
, yystackp
, &yysval
]b4_locuser_args
[);
1797 for (yyp
= yybest
->yynext
; yyp
!= YY_NULL
; yyp
= yyp
->yynext
)
1799 if (yyprec
== yydprec
[yyp
->yyrule
])
1801 YYSTYPE yysval_other
;]b4_locations_if([
1803 yyflag
= yyresolveAction (yyp
, yystackp
, &yysval_other
]b4_locuser_args([&yydummy
])[);
1806 yydestruct ("Cleanup: discarding incompletely merged value for",
1807 yystos
[yys
->yylrState
],
1808 &yysval
]b4_locuser_args
[);
1811 yyuserMerge (yymerger
[yyp
->yyrule
], &yysval
, &yysval_other
);
1816 yyflag
= yyresolveAction (yybest
, yystackp
, &yysval
]b4_locuser_args([yylocp
])[);
1820 yys
->yyresolved
= yytrue
;
1821 yys
->yysemantics
.yysval
= yysval
;
1824 yys
->yysemantics
.yyfirstVal
= YY_NULL
;
1829 yyresolveStack (yyGLRStack
* yystackp
]b4_user_formals
[)
1831 if (yystackp
->yysplitPoint
!= YY_NULL
)
1836 for (yyn
= 0, yys
= yystackp
->yytops
.yystates
[0];
1837 yys
!= yystackp
->yysplitPoint
;
1838 yys
= yys
->yypred
, yyn
+= 1)
1840 YYCHK (yyresolveStates (yystackp
->yytops
.yystates
[0], yyn
, yystackp
1847 yycompressStack (yyGLRStack
* yystackp
)
1849 yyGLRState
* yyp
, *yyq
, *yyr
;
1851 if (yystackp
->yytops
.yysize
!= 1 || yystackp
->yysplitPoint
== YY_NULL
)
1854 for (yyp
= yystackp
->yytops
.yystates
[0], yyq
= yyp
->yypred
, yyr
= YY_NULL
;
1855 yyp
!= yystackp
->yysplitPoint
;
1856 yyr
= yyp
, yyp
= yyq
, yyq
= yyp
->yypred
)
1859 yystackp
->yyspaceLeft
+= yystackp
->yynextFree
- yystackp
->yyitems
;
1860 yystackp
->yynextFree
= ((yyGLRStackItem
*) yystackp
->yysplitPoint
) + 1;
1861 yystackp
->yyspaceLeft
-= yystackp
->yynextFree
- yystackp
->yyitems
;
1862 yystackp
->yysplitPoint
= YY_NULL
;
1863 yystackp
->yylastDeleted
= YY_NULL
;
1865 while (yyr
!= YY_NULL
)
1867 yystackp
->yynextFree
->yystate
= *yyr
;
1869 yystackp
->yynextFree
->yystate
.yypred
= &yystackp
->yynextFree
[-1].yystate
;
1870 yystackp
->yytops
.yystates
[0] = &yystackp
->yynextFree
->yystate
;
1871 yystackp
->yynextFree
+= 1;
1872 yystackp
->yyspaceLeft
-= 1;
1877 yyprocessOneStack (yyGLRStack
* yystackp
, size_t yyk
,
1878 size_t yyposn
]b4_pure_formals
[)
1880 while (yystackp
->yytops
.yystates
[yyk
] != YY_NULL
)
1882 yyStateNum yystate
= yystackp
->yytops
.yystates
[yyk
]->yylrState
;
1883 YYDPRINTF ((stderr
, "Stack %lu Entering state %d\n",
1884 (unsigned long int) yyk
, yystate
));
1886 YYASSERT (yystate
!= YYFINAL
);
1888 if (yyisDefaultedState (yystate
))
1891 yyRuleNum yyrule
= yydefaultAction (yystate
);
1894 YYDPRINTF ((stderr
, "Stack %lu dies.\n",
1895 (unsigned long int) yyk
));
1896 yymarkStackDeleted (yystackp
, yyk
);
1899 yyflag
= yyglrReduce (yystackp
, yyk
, yyrule
, yyimmediate
[yyrule
]]b4_user_args
[);
1900 if (yyflag
== yyerr
)
1904 "(predicate failure or explicit user error).\n",
1905 (unsigned long int) yyk
));
1906 yymarkStackDeleted (yystackp
, yyk
);
1916 const short int* yyconflicts
;
1918 yystackp
->yytops
.yylookaheadNeeds
[yyk
] = yytrue
;
1919 if (yychar
== YYEMPTY
)
1921 YYDPRINTF ((stderr
, "Reading a token: "));
1925 if (yychar
<= YYEOF
)
1927 yychar
= yytoken
= YYEOF
;
1928 YYDPRINTF ((stderr
, "Now at end of input.\n"));
1932 yytoken
= YYTRANSLATE (yychar
);
1933 YY_SYMBOL_PRINT ("Next token is", yytoken
, &yylval
, &yylloc
);
1936 yygetLRActions (yystate
, yytoken
, &yyaction
, &yyconflicts
);
1938 while (*yyconflicts
!= 0)
1941 size_t yynewStack
= yysplitStack (yystackp
, yyk
);
1942 YYDPRINTF ((stderr
, "Splitting off stack %lu from %lu.\n",
1943 (unsigned long int) yynewStack
,
1944 (unsigned long int) yyk
));
1945 yyflag
= yyglrReduce (yystackp
, yynewStack
,
1947 yyimmediate
[*yyconflicts
]]b4_user_args
[);
1949 YYCHK (yyprocessOneStack (yystackp
, yynewStack
,
1950 yyposn
]b4_pure_args
[));
1951 else if (yyflag
== yyerr
)
1953 YYDPRINTF ((stderr
, "Stack %lu dies.\n",
1954 (unsigned long int) yynewStack
));
1955 yymarkStackDeleted (yystackp
, yynewStack
);
1962 if (yyisShiftAction (yyaction
))
1964 else if (yyisErrorAction (yyaction
))
1966 YYDPRINTF ((stderr
, "Stack %lu dies.\n",
1967 (unsigned long int) yyk
));
1968 yymarkStackDeleted (yystackp
, yyk
);
1973 YYRESULTTAG yyflag
= yyglrReduce (yystackp
, yyk
, -yyaction
,
1974 yyimmediate
[-yyaction
]]b4_user_args
[);
1975 if (yyflag
== yyerr
)
1979 "(predicate failure or explicit user error).\n",
1980 (unsigned long int) yyk
));
1981 yymarkStackDeleted (yystackp
, yyk
);
1984 else if (yyflag
!= yyok
)
1993 yyreportSyntaxError (yyGLRStack
* yystackp
]b4_user_formals
[)
1995 if (yystackp
->yyerrState
!= 0)
1997 #if ! YYERROR_VERBOSE
1998 yyerror (]b4_lyyerror_args
[YY_("syntax error"));
2000 yySymbol yytoken
= yychar
== YYEMPTY
? YYEMPTY
: YYTRANSLATE (yychar
);
2001 size_t yysize0
= yytnamerr (YY_NULL
, yytokenName (yytoken
));
2002 size_t yysize
= yysize0
;
2004 yybool yysize_overflow
= yyfalse
;
2005 char* yymsg
= YY_NULL
;
2006 enum { YYERROR_VERBOSE_ARGS_MAXIMUM
= 5 };
2007 /* Internationalized format string. */
2008 const char *yyformat
= YY_NULL
;
2009 /* Arguments of yyformat. */
2010 char const *yyarg
[YYERROR_VERBOSE_ARGS_MAXIMUM
];
2011 /* Number of reported tokens (one for the "unexpected", one per
2015 /* There are many possibilities here to consider:
2016 - If this state is a consistent state with a default action, then
2017 the only way this function was invoked is if the default action
2018 is an error action. In that case, don't check for expected
2019 tokens because there are none.
2020 - The only way there can be no lookahead present (in yychar) is if
2021 this state is a consistent state with a default action. Thus,
2022 detecting the absence of a lookahead is sufficient to determine
2023 that there is no unexpected or expected token to report. In that
2024 case, just report a simple "syntax error".
2025 - Don't assume there isn't a lookahead just because this state is a
2026 consistent state with a default action. There might have been a
2027 previous inconsistent state, consistent state with a non-default
2028 action, or user semantic action that manipulated yychar.
2029 - Of course, the expected token list depends on states to have
2030 correct lookahead information, and it depends on the parser not
2031 to perform extra reductions after fetching a lookahead from the
2032 scanner and before detecting a syntax error. Thus, state merging
2033 (from LALR or IELR) and default reductions corrupt the expected
2034 token list. However, the list is correct for canonical LR with
2035 one exception: it will still contain any token that will not be
2036 accepted due to an error action in a later state.
2038 if (yytoken
!= YYEMPTY
)
2040 int yyn
= yypact
[yystackp
->yytops
.yystates
[0]->yylrState
];
2041 yyarg
[yycount
++] = yytokenName (yytoken
);
2042 if (!yypact_value_is_default (yyn
))
2044 /* Start YYX at -YYN if negative to avoid negative indexes in
2045 YYCHECK. In other words, skip the first -YYN actions for this
2046 state because they are default actions. */
2047 int yyxbegin
= yyn
< 0 ? -yyn
: 0;
2048 /* Stay within bounds of both yycheck and yytname. */
2049 int yychecklim
= YYLAST
- yyn
+ 1;
2050 int yyxend
= yychecklim
< YYNTOKENS
? yychecklim
: YYNTOKENS
;
2052 for (yyx
= yyxbegin
; yyx
< yyxend
; ++yyx
)
2053 if (yycheck
[yyx
+ yyn
] == yyx
&& yyx
!= YYTERROR
2054 && !yytable_value_is_error (yytable
[yyx
+ yyn
]))
2056 if (yycount
== YYERROR_VERBOSE_ARGS_MAXIMUM
)
2062 yyarg
[yycount
++] = yytokenName (yyx
);
2063 yysize1
= yysize
+ yytnamerr (YY_NULL
, yytokenName (yyx
));
2064 yysize_overflow
|= yysize1
< yysize
;
2072 #define YYCASE_(N, S) \
2076 YYCASE_(0, YY_("syntax error"));
2077 YYCASE_(1, YY_("syntax error, unexpected %s"));
2078 YYCASE_(2, YY_("syntax error, unexpected %s, expecting %s"));
2079 YYCASE_(3, YY_("syntax error, unexpected %s, expecting %s or %s"));
2080 YYCASE_(4, YY_("syntax error, unexpected %s, expecting %s or %s or %s"));
2081 YYCASE_(5, YY_("syntax error, unexpected %s, expecting %s or %s or %s or %s"));
2085 yysize1
= yysize
+ strlen (yyformat
);
2086 yysize_overflow
|= yysize1
< yysize
;
2089 if (!yysize_overflow
)
2090 yymsg
= (char *) YYMALLOC (yysize
);
2096 while ((*yyp
= *yyformat
))
2098 if (*yyp
== '%' && yyformat
[1] == 's' && yyi
< yycount
)
2100 yyp
+= yytnamerr (yyp
, yyarg
[yyi
++]);
2109 yyerror (]b4_lyyerror_args
[yymsg
);
2114 yyerror (]b4_lyyerror_args
[YY_("syntax error"));
2115 yyMemoryExhausted (yystackp
);
2117 #endif /* YYERROR_VERBOSE */
2121 /* Recover from a syntax error on *YYSTACKP, assuming that *YYSTACKP->YYTOKENP,
2122 yylval, and yylloc are the syntactic category, semantic value, and location
2123 of the lookahead. */
2125 yyrecoverSyntaxError (yyGLRStack
* yystackp
]b4_user_formals
[)
2130 if (yystackp
->yyerrState
== 3)
2131 /* We just shifted the error token and (perhaps) took some
2132 reductions. Skip tokens until we can proceed. */
2136 if (yychar
== YYEOF
)
2137 yyFail (yystackp
][]b4_lpure_args
[, YY_NULL
);
2138 if (yychar
!= YYEMPTY
)
2139 {]b4_locations_if([[
2140 /* We throw away the lookahead, but the error range
2141 of the shifted error token must take it into account. */
2142 yyGLRState
*yys
= yystackp
->yytops
.yystates
[0];
2143 yyGLRStackItem yyerror_range
[3];
2144 yyerror_range
[1].yystate
.yyloc
= yys
->yyloc
;
2145 yyerror_range
[2].yystate
.yyloc
= yylloc
;
2146 YYLLOC_DEFAULT ((yys
->yyloc
), yyerror_range
, 2);]])[
2147 yytoken
= YYTRANSLATE (yychar
);
2148 yydestruct ("Error: discarding",
2149 yytoken
, &yylval
]b4_locuser_args([&yylloc
])[);
2151 YYDPRINTF ((stderr
, "Reading a token: "));
2153 if (yychar
<= YYEOF
)
2155 yychar
= yytoken
= YYEOF
;
2156 YYDPRINTF ((stderr
, "Now at end of input.\n"));
2160 yytoken
= YYTRANSLATE (yychar
);
2161 YY_SYMBOL_PRINT ("Next token is", yytoken
, &yylval
, &yylloc
);
2163 yyj
= yypact
[yystackp
->yytops
.yystates
[0]->yylrState
];
2164 if (yypact_value_is_default (yyj
))
2167 if (yyj
< 0 || YYLAST
< yyj
|| yycheck
[yyj
] != yytoken
)
2169 if (yydefact
[yystackp
->yytops
.yystates
[0]->yylrState
] != 0)
2172 else if (! yytable_value_is_error (yytable
[yyj
]))
2176 /* Reduce to one stack. */
2177 for (yyk
= 0; yyk
< yystackp
->yytops
.yysize
; yyk
+= 1)
2178 if (yystackp
->yytops
.yystates
[yyk
] != YY_NULL
)
2180 if (yyk
>= yystackp
->yytops
.yysize
)
2181 yyFail (yystackp
][]b4_lpure_args
[, YY_NULL
);
2182 for (yyk
+= 1; yyk
< yystackp
->yytops
.yysize
; yyk
+= 1)
2183 yymarkStackDeleted (yystackp
, yyk
);
2184 yyremoveDeletes (yystackp
);
2185 yycompressStack (yystackp
);
2187 /* Now pop stack until we find a state that shifts the error token. */
2188 yystackp
->yyerrState
= 3;
2189 while (yystackp
->yytops
.yystates
[0] != YY_NULL
)
2191 yyGLRState
*yys
= yystackp
->yytops
.yystates
[0];
2192 yyj
= yypact
[yys
->yylrState
];
2193 if (! yypact_value_is_default (yyj
))
2196 if (0 <= yyj
&& yyj
<= YYLAST
&& yycheck
[yyj
] == YYTERROR
2197 && yyisShiftAction (yytable
[yyj
]))
2199 /* Shift the error token. */]b4_locations_if([[
2200 /* First adjust its location.*/
2202 yystackp
->yyerror_range
[2].yystate
.yyloc
= yylloc
;
2203 YYLLOC_DEFAULT (yyerrloc
, (yystackp
->yyerror_range
), 2);]])[
2204 YY_SYMBOL_PRINT ("Shifting", yystos
[yytable
[yyj
]],
2205 &yylval
, &yyerrloc
);
2206 yyglrShift (yystackp
, 0, yytable
[yyj
],
2207 yys
->yyposn
, &yylval
]b4_locations_if([, &yyerrloc
])[);
2208 yys
= yystackp
->yytops
.yystates
[0];
2211 }]b4_locations_if([[
2212 yystackp
->yyerror_range
[1].yystate
.yyloc
= yys
->yyloc
;]])[
2213 if (yys
->yypred
!= YY_NULL
)
2214 yydestroyGLRState ("Error: popping", yys
]b4_user_args
[);
2215 yystackp
->yytops
.yystates
[0] = yys
->yypred
;
2216 yystackp
->yynextFree
-= 1;
2217 yystackp
->yyspaceLeft
+= 1;
2219 if (yystackp
->yytops
.yystates
[0] == YY_NULL
)
2220 yyFail (yystackp
][]b4_lpure_args
[, YY_NULL
);
2223 #define YYCHK1(YYE) \
2233 goto yyuser_error; \
2243 ]b4_function_define([yyparse
], [int], b4_parse_param
)[
2247 yyGLRStack
* const yystackp
= &yystack
;
2250 YYDPRINTF ((stderr
, "Starting parse\n"));
2253 yylval
= yyval_default
;]b4_locations_if([
2254 yylloc
= yyloc_default
;])[
2255 ]m4_ifdef([b4_initial_action
], [
2256 b4_dollar_pushdef([yylval
], [], [yylloc
])dnl
2257 /* User initialization code. */
2258 b4_user_initial_action
2259 b4_dollar_popdef
])[]dnl
2261 if (! yyinitGLRStack (yystackp
, YYINITDEPTH
))
2262 goto yyexhaustedlab
;
2263 switch (YYSETJMP (yystack
.yyexception_buffer
))
2266 case 1: goto yyabortlab
;
2267 case 2: goto yyexhaustedlab
;
2268 default: goto yybuglab
;
2270 yyglrShift (&yystack
, 0, 0, 0, &yylval
]b4_locations_if([, &yylloc
])[);
2275 /* For efficiency, we have two loops, the first of which is
2276 specialized to deterministic operation (single stack, no
2277 potential ambiguity). */
2283 const short int* yyconflicts
;
2285 yyStateNum yystate
= yystack
.yytops
.yystates
[0]->yylrState
;
2286 YYDPRINTF ((stderr
, "Entering state %d\n", yystate
));
2287 if (yystate
== YYFINAL
)
2289 if (yyisDefaultedState (yystate
))
2291 yyrule
= yydefaultAction (yystate
);
2294 ]b4_locations_if([[ yystack
.yyerror_range
[1].yystate
.yyloc
= yylloc
;]])[
2295 yyreportSyntaxError (&yystack
]b4_user_args
[);
2298 YYCHK1 (yyglrReduce (&yystack
, 0, yyrule
, yytrue
]b4_user_args
[));
2303 if (yychar
== YYEMPTY
)
2305 YYDPRINTF ((stderr
, "Reading a token: "));
2309 if (yychar
<= YYEOF
)
2311 yychar
= yytoken
= YYEOF
;
2312 YYDPRINTF ((stderr
, "Now at end of input.\n"));
2316 yytoken
= YYTRANSLATE (yychar
);
2317 YY_SYMBOL_PRINT ("Next token is", yytoken
, &yylval
, &yylloc
);
2320 yygetLRActions (yystate
, yytoken
, &yyaction
, &yyconflicts
);
2321 if (*yyconflicts
!= 0)
2323 if (yyisShiftAction (yyaction
))
2325 YY_SYMBOL_PRINT ("Shifting", yytoken
, &yylval
, &yylloc
);
2328 yyglrShift (&yystack
, 0, yyaction
, yyposn
, &yylval
]b4_locations_if([, &yylloc
])[);
2329 if (0 < yystack
.yyerrState
)
2330 yystack
.yyerrState
-= 1;
2332 else if (yyisErrorAction (yyaction
))
2334 ]b4_locations_if([[ yystack
.yyerror_range
[1].yystate
.yyloc
= yylloc
;]])[
2335 yyreportSyntaxError (&yystack
]b4_user_args
[);
2339 YYCHK1 (yyglrReduce (&yystack
, 0, -yyaction
, yytrue
]b4_user_args
[));
2345 yySymbol yytoken_to_shift
;
2348 for (yys
= 0; yys
< yystack
.yytops
.yysize
; yys
+= 1)
2349 yystackp
->yytops
.yylookaheadNeeds
[yys
] = yychar
!= YYEMPTY
;
2351 /* yyprocessOneStack returns one of three things:
2353 - An error flag. If the caller is yyprocessOneStack, it
2354 immediately returns as well. When the caller is finally
2355 yyparse, it jumps to an error label via YYCHK1.
2357 - yyok, but yyprocessOneStack has invoked yymarkStackDeleted
2358 (&yystack, yys), which sets the top state of yys to NULL. Thus,
2359 yyparse's following invocation of yyremoveDeletes will remove
2362 - yyok, when ready to shift a token.
2364 Except in the first case, yyparse will invoke yyremoveDeletes and
2365 then shift the next token onto all remaining stacks. This
2366 synchronization of the shift (that is, after all preceding
2367 reductions on all stacks) helps prevent double destructor calls
2368 on yylval in the event of memory exhaustion. */
2370 for (yys
= 0; yys
< yystack
.yytops
.yysize
; yys
+= 1)
2371 YYCHK1 (yyprocessOneStack (&yystack
, yys
, yyposn
]b4_lpure_args
[));
2372 yyremoveDeletes (&yystack
);
2373 if (yystack
.yytops
.yysize
== 0)
2375 yyundeleteLastStack (&yystack
);
2376 if (yystack
.yytops
.yysize
== 0)
2377 yyFail (&yystack
][]b4_lpure_args
[, YY_("syntax error"));
2378 YYCHK1 (yyresolveStack (&yystack
]b4_user_args
[));
2379 YYDPRINTF ((stderr
, "Returning to deterministic operation.\n"));
2380 ]b4_locations_if([[ yystack
.yyerror_range
[1].yystate
.yyloc
= yylloc
;]])[
2381 yyreportSyntaxError (&yystack
]b4_user_args
[);
2385 /* If any yyglrShift call fails, it will fail after shifting. Thus,
2386 a copy of yylval will already be on stack 0 in the event of a
2387 failure in the following loop. Thus, yychar is set to YYEMPTY
2388 before the loop to make sure the user destructor for yylval isn't
2390 yytoken_to_shift
= YYTRANSLATE (yychar
);
2393 for (yys
= 0; yys
< yystack
.yytops
.yysize
; yys
+= 1)
2396 const short int* yyconflicts
;
2397 yyStateNum yystate
= yystack
.yytops
.yystates
[yys
]->yylrState
;
2398 yygetLRActions (yystate
, yytoken_to_shift
, &yyaction
,
2400 /* Note that yyconflicts were handled by yyprocessOneStack. */
2401 YYDPRINTF ((stderr
, "On stack %lu, ", (unsigned long int) yys
));
2402 YY_SYMBOL_PRINT ("shifting", yytoken_to_shift
, &yylval
, &yylloc
);
2403 yyglrShift (&yystack
, yys
, yyaction
, yyposn
,
2404 &yylval
]b4_locations_if([, &yylloc
])[);
2405 YYDPRINTF ((stderr
, "Stack %lu now in state #%d\n",
2406 (unsigned long int) yys
,
2407 yystack
.yytops
.yystates
[yys
]->yylrState
));
2410 if (yystack
.yytops
.yysize
== 1)
2412 YYCHK1 (yyresolveStack (&yystack
]b4_user_args
[));
2413 YYDPRINTF ((stderr
, "Returning to deterministic operation.\n"));
2414 yycompressStack (&yystack
);
2420 yyrecoverSyntaxError (&yystack
]b4_user_args
[);
2421 yyposn
= yystack
.yytops
.yystates
[0]->yyposn
;
2437 yyerror (]b4_lyyerror_args
[YY_("memory exhausted"));
2442 if (yychar
!= YYEMPTY
)
2443 yydestruct ("Cleanup: discarding lookahead",
2444 YYTRANSLATE (yychar
), &yylval
]b4_locuser_args([&yylloc
])[);
2446 /* If the stack is well-formed, pop the stack until it is empty,
2447 destroying its entries as we go. But free the stack regardless
2448 of whether it is well-formed. */
2449 if (yystack
.yyitems
)
2451 yyGLRState
** yystates
= yystack
.yytops
.yystates
;
2454 size_t yysize
= yystack
.yytops
.yysize
;
2456 for (yyk
= 0; yyk
< yysize
; yyk
+= 1)
2459 while (yystates
[yyk
])
2461 yyGLRState
*yys
= yystates
[yyk
];
2462 ]b4_locations_if([[ yystack
.yyerror_range
[1].yystate
.yyloc
= yys
->yyloc
;]]
2463 )[ if (yys
->yypred
!= YY_NULL
)
2464 yydestroyGLRState ("Cleanup: popping", yys
]b4_user_args
[);
2465 yystates
[yyk
] = yys
->yypred
;
2466 yystack
.yynextFree
-= 1;
2467 yystack
.yyspaceLeft
+= 1;
2472 yyfreeGLRStack (&yystack
);
2478 /* DEBUGGING ONLY */
2479 #if ]b4_api_PREFIX[DEBUG
2480 static void yypstack (yyGLRStack
* yystackp
, size_t yyk
)
2481 __attribute__ ((__unused__
));
2482 static void yypdumpstack (yyGLRStack
* yystackp
) __attribute__ ((__unused__
));
2485 yy_yypstack (yyGLRState
* yys
)
2489 yy_yypstack (yys
->yypred
);
2490 YYFPRINTF (stderr
, " -> ");
2492 YYFPRINTF (stderr
, "%d@@%lu", yys
->yylrState
,
2493 (unsigned long int) yys
->yyposn
);
2497 yypstates (yyGLRState
* yyst
)
2499 if (yyst
== YY_NULL
)
2500 YYFPRINTF (stderr
, "<null>");
2503 YYFPRINTF (stderr
, "\n");
2507 yypstack (yyGLRStack
* yystackp
, size_t yyk
)
2509 yypstates (yystackp
->yytops
.yystates
[yyk
]);
2512 #define YYINDEX(YYX) \
2513 ((YYX) == YY_NULL ? -1 : (yyGLRStackItem*) (YYX) - yystackp->yyitems)
2517 yypdumpstack (yyGLRStack
* yystackp
)
2519 yyGLRStackItem
* yyp
;
2521 for (yyp
= yystackp
->yyitems
; yyp
< yystackp
->yynextFree
; yyp
+= 1)
2523 YYFPRINTF (stderr
, "%3lu. ",
2524 (unsigned long int) (yyp
- yystackp
->yyitems
));
2525 if (*(yybool
*) yyp
)
2527 YYFPRINTF (stderr
, "Res: %d, LR State: %d, posn: %lu, pred: %ld",
2528 yyp
->yystate
.yyresolved
, yyp
->yystate
.yylrState
,
2529 (unsigned long int) yyp
->yystate
.yyposn
,
2530 (long int) YYINDEX (yyp
->yystate
.yypred
));
2531 if (! yyp
->yystate
.yyresolved
)
2532 YYFPRINTF (stderr
, ", firstVal: %ld",
2533 (long int) YYINDEX (yyp
->yystate
2534 .yysemantics
.yyfirstVal
));
2538 YYFPRINTF (stderr
, "Option. rule: %d, state: %ld, next: %ld",
2539 yyp
->yyoption
.yyrule
- 1,
2540 (long int) YYINDEX (yyp
->yyoption
.yystate
),
2541 (long int) YYINDEX (yyp
->yyoption
.yynext
));
2543 YYFPRINTF (stderr
, "\n");
2545 YYFPRINTF (stderr
, "Tops:");
2546 for (yyi
= 0; yyi
< yystackp
->yytops
.yysize
; yyi
+= 1)
2547 YYFPRINTF (stderr
, "%lu: %ld; ", (unsigned long int) yyi
,
2548 (long int) YYINDEX (yystackp
->yytops
.yystates
[yyi
]));
2549 YYFPRINTF (stderr
, "\n");
2555 # glr.cc produces its own header.
2556 m4_if(b4_skeleton
, ["glr.c"],
2558 [b4_output_begin([b4_spec_defines_file
])
2559 b4_copyright([Skeleton interface
for Bison GLR parsers in C
],
2562 ]b4_cpp_guard_open([b4_spec_defines_file
])[
2563 ]b4_shared_declarations
[
2564 ]b4_cpp_guard_close([b4_spec_defines_file
])[