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. */
475 static void yypstack (struct yyGLRStack
* yystackp
, size_t yyk
)
476 __attribute__ ((__unused__
));
477 static void yypdumpstack (struct yyGLRStack
* yystackp
)
478 __attribute__ ((__unused__
));
480 #else /* !]b4_api_PREFIX[DEBUG */
482 # define YYDPRINTF(Args)
483 # define YY_SYMBOL_PRINT(Title, Type, Value, Location)
485 #endif /* !]b4_api_PREFIX[DEBUG */
487 /* YYINITDEPTH -- initial size of the parser's stacks. */
489 # define YYINITDEPTH ]b4_stack_depth_init[
492 /* YYMAXDEPTH -- maximum size the stacks can grow to (effective only
493 if the built-in stack extension method is used).
495 Do not make this value too large; the results are undefined if
496 SIZE_MAX < YYMAXDEPTH * sizeof (GLRStackItem)
497 evaluated with infinite-precision integer arithmetic. */
500 # define YYMAXDEPTH ]b4_stack_depth_max[
503 /* Minimum number of free items on the stack allowed after an
504 allocation. This is to allow allocation and initialization
505 to be completed by functions that call yyexpandGLRStack before the
506 stack is expanded, thus insuring that all necessary pointers get
507 properly redirected to new data. */
510 #ifndef YYSTACKEXPANDABLE
511 # define YYSTACKEXPANDABLE 1
514 #if YYSTACKEXPANDABLE
515 # define YY_RESERVE_GLRSTACK(Yystack) \
517 if (Yystack->yyspaceLeft < YYHEADROOM) \
518 yyexpandGLRStack (Yystack); \
521 # define YY_RESERVE_GLRSTACK(Yystack) \
523 if (Yystack->yyspaceLeft < YYHEADROOM) \
524 yyMemoryExhausted (Yystack); \
532 # if defined __GLIBC__ && defined _STRING_H && defined _GNU_SOURCE
533 # define yystpcpy stpcpy
535 /* Copy YYSRC to YYDEST, returning the address of the terminating '\0' in
538 yystpcpy (char *yydest
, const char *yysrc
)
541 const char *yys
= yysrc
;
543 while ((*yyd
++ = *yys
++) != '\0')
552 /* Copy to YYRES the contents of YYSTR after stripping away unnecessary
553 quotes and backslashes, so that it's suitable for yyerror. The
554 heuristic is that double-quoting is unnecessary unless the string
555 contains an apostrophe, a comma, or backslash (other than
556 backslash-backslash). YYSTR is taken from yytname. If YYRES is
557 null, do not copy; instead, return the length of what the result
560 yytnamerr (char *yyres
, const char *yystr
)
565 char const *yyp
= yystr
;
572 goto do_not_strip_quotes
;
576 goto do_not_strip_quotes
;
589 do_not_strip_quotes
: ;
593 return strlen (yystr
);
595 return yystpcpy (yyres
, yystr
) - yyres
;
599 #endif /* !YYERROR_VERBOSE */
601 /** State numbers, as in LALR(1) machine */
602 typedef int yyStateNum
;
604 /** Rule numbers, as in LALR(1) machine */
605 typedef int yyRuleNum
;
607 /** Grammar symbol */
608 typedef int yySymbol
;
610 /** Item references, as in LALR(1) machine */
611 typedef short int yyItemNum
;
613 typedef struct yyGLRState yyGLRState
;
614 typedef struct yyGLRStateSet yyGLRStateSet
;
615 typedef struct yySemanticOption yySemanticOption
;
616 typedef union yyGLRStackItem yyGLRStackItem
;
617 typedef struct yyGLRStack yyGLRStack
;
620 /** Type tag: always true. */
622 /** Type tag for yysemantics. If true, yysval applies, otherwise
623 * yyfirstVal applies. */
625 /** Number of corresponding LALR(1) machine state. */
626 yyStateNum yylrState
;
627 /** Preceding state in this stack */
629 /** Source position of the last token produced by my symbol */
632 /** First in a chain of alternative reductions producing the
633 * non-terminal corresponding to this state, threaded through
635 yySemanticOption
* yyfirstVal
;
636 /** Semantic value for this state. */
638 } yysemantics
;]b4_locations_if([[
639 /** Source location for this state. */
643 struct yyGLRStateSet
{
644 yyGLRState
** yystates
;
645 /** During nondeterministic operation, yylookaheadNeeds tracks which
646 * stacks have actually needed the current lookahead. During deterministic
647 * operation, yylookaheadNeeds[0] is not maintained since it would merely
648 * duplicate yychar != YYEMPTY. */
649 yybool
* yylookaheadNeeds
;
650 size_t yysize
, yycapacity
;
653 struct yySemanticOption
{
654 /** Type tag: always false. */
656 /** Rule number for this reduction */
658 /** The last RHS state in the list of states to be reduced. */
660 /** The lookahead for this reduction. */
662 YYSTYPE yyval
;]b4_locations_if([[
664 /** Next sibling in chain of options. To facilitate merging,
665 * options are chained in decreasing order by address. */
666 yySemanticOption
* yynext
;
669 /** Type of the items in the GLR stack. The yyisState field
670 * indicates which item of the union is valid. */
671 union yyGLRStackItem
{
673 yySemanticOption yyoption
;
678 ]b4_locations_if([[ /* To compute the location of the error token. */
679 yyGLRStackItem yyerror_range
[3];]])[
684 YYSTYPE yyval
;]b4_locations_if([[
687 YYJMP_BUF yyexception_buffer
;
688 yyGLRStackItem
* yyitems
;
689 yyGLRStackItem
* yynextFree
;
691 yyGLRState
* yysplitPoint
;
692 yyGLRState
* yylastDeleted
;
693 yyGLRStateSet yytops
;
696 #if YYSTACKEXPANDABLE
697 static void yyexpandGLRStack (yyGLRStack
* yystackp
);
700 static void yyFail (yyGLRStack
* yystackp
]b4_pure_formals
[, const char* yymsg
)
701 __attribute__ ((__noreturn__
));
703 yyFail (yyGLRStack
* yystackp
]b4_pure_formals
[, const char* yymsg
)
705 if (yymsg
!= YY_NULL
)
706 yyerror (]b4_yyerror_args
[yymsg
);
707 YYLONGJMP (yystackp
->yyexception_buffer
, 1);
710 static void yyMemoryExhausted (yyGLRStack
* yystackp
)
711 __attribute__ ((__noreturn__
));
713 yyMemoryExhausted (yyGLRStack
* yystackp
)
715 YYLONGJMP (yystackp
->yyexception_buffer
, 2);
718 #if ]b4_api_PREFIX[DEBUG || YYERROR_VERBOSE
719 /** A printable representation of TOKEN. */
720 static inline const char*
721 yytokenName (yySymbol yytoken
)
723 if (yytoken
== YYEMPTY
)
726 return yytname
[yytoken
];
730 /** Fill in YYVSP[YYLOW1 .. YYLOW0-1] from the chain of states starting
731 * at YYVSP[YYLOW0].yystate.yypred. Leaves YYVSP[YYLOW1].yystate.yypred
732 * containing the pointer to the next state in the chain. */
733 static void yyfillin (yyGLRStackItem
*, int, int) __attribute__ ((__unused__
));
735 yyfillin (yyGLRStackItem
*yyvsp
, int yylow0
, int yylow1
)
738 yyGLRState
*s
= yyvsp
[yylow0
].yystate
.yypred
;
739 for (i
= yylow0
-1; i
>= yylow1
; i
-= 1)
741 #if ]b4_api_PREFIX[DEBUG
742 yyvsp
[i
].yystate
.yylrState
= s
->yylrState
;
744 yyvsp
[i
].yystate
.yyresolved
= s
->yyresolved
;
746 yyvsp
[i
].yystate
.yysemantics
.yysval
= s
->yysemantics
.yysval
;
748 /* The effect of using yysval or yyloc (in an immediate rule) is
750 yyvsp
[i
].yystate
.yysemantics
.yyfirstVal
= YY_NULL
;]b4_locations_if([[
751 yyvsp
[i
].yystate
.yyloc
= s
->yyloc
;]])[
752 s
= yyvsp
[i
].yystate
.yypred
= s
->yypred
;
756 /* Do nothing if YYNORMAL or if *YYLOW <= YYLOW1. Otherwise, fill in
757 * YYVSP[YYLOW1 .. *YYLOW-1] as in yyfillin and set *YYLOW = YYLOW1.
758 * For convenience, always return YYLOW1. */
759 static inline int yyfill (yyGLRStackItem
*, int *, int, yybool
)
760 __attribute__ ((__unused__
));
762 yyfill (yyGLRStackItem
*yyvsp
, int *yylow
, int yylow1
, yybool yynormal
)
764 if (!yynormal
&& yylow1
< *yylow
)
766 yyfillin (yyvsp
, *yylow
, yylow1
);
772 /** Perform user action for rule number YYN, with RHS length YYRHSLEN,
773 * and top stack item YYVSP. YYLVALP points to place to put semantic
774 * value ($$), and yylocp points to place for location information
775 * (@@$). Returns yyok for normal return, yyaccept for YYACCEPT,
776 * yyerr for YYERROR, yyabort for YYABORT. */
778 yyuserAction (yyRuleNum yyn
, int yyrhslen
, yyGLRStackItem
* yyvsp
,
779 yyGLRStack
* yystackp
,
780 YYSTYPE
* yyvalp
]b4_locuser_formals
[)
782 yybool yynormal
__attribute__ ((__unused__
)) =
783 (yystackp
->yysplitPoint
== YY_NULL
);
785 ]b4_parse_param_use([yyvalp
], [yylocp
])dnl
787 # define yyerrok (yystackp->yyerrState = 0)
789 # define YYACCEPT return yyaccept
791 # define YYABORT return yyabort
793 # define YYERROR return yyerrok, yyerr
795 # define YYRECOVERING() (yystackp->yyerrState != 0)
797 # define yyclearin (yychar = YYEMPTY)
799 # define YYFILL(N) yyfill (yyvsp, &yylow, N, yynormal)
801 # define YYBACKUP(Token, Value) \
802 return yyerror (]b4_yyerror_args[YY_("syntax error: cannot back up")), \
807 *yyvalp
= yyval_default
;
809 *yyvalp
= yyvsp
[YYFILL (1-yyrhslen
)].yystate
.yysemantics
.yysval
;]b4_locations_if([[
810 YYLLOC_DEFAULT ((*yylocp
), (yyvsp
- yyrhslen
), yyrhslen
);
811 yystackp
->yyerror_range
[1].yystate
.yyloc
= *yylocp
;
831 yyuserMerge (int yyn
, YYSTYPE
* yy0
, YYSTYPE
* yy1
)
843 /* Bison grammar-table manipulation. */
845 ]b4_yydestruct_define
[
847 /** Number of symbols composing the right hand side of rule #RULE. */
849 yyrhsLength (yyRuleNum yyrule
)
855 yydestroyGLRState (char const *yymsg
, yyGLRState
*yys
]b4_user_formals
[)
858 yydestruct (yymsg
, yystos
[yys
->yylrState
],
859 &yys
->yysemantics
.yysval
]b4_locuser_args([&yys
->yyloc
])[);
862 #if ]b4_api_PREFIX[DEBUG
865 if (yys
->yysemantics
.yyfirstVal
)
866 YYFPRINTF (stderr
, "%s unresolved ", yymsg
);
868 YYFPRINTF (stderr
, "%s incomplete ", yymsg
);
869 yy_symbol_print (stderr
, yystos
[yys
->yylrState
],
870 YY_NULL
]b4_locuser_args([&yys
->yyloc
])[);
871 YYFPRINTF (stderr
, "\n");
875 if (yys
->yysemantics
.yyfirstVal
)
877 yySemanticOption
*yyoption
= yys
->yysemantics
.yyfirstVal
;
880 for (yyrh
= yyoption
->yystate
, yyn
= yyrhsLength (yyoption
->yyrule
);
882 yyrh
= yyrh
->yypred
, yyn
-= 1)
883 yydestroyGLRState (yymsg
, yyrh
]b4_user_args
[);
888 /** Left-hand-side symbol for rule #YYRULE. */
889 static inline yySymbol
890 yylhsNonterm (yyRuleNum yyrule
)
895 #define yypact_value_is_default(Yystate) \
896 ]b4_table_value_equals([[pact]], [[Yystate]], [b4_pact_ninf])[
898 /** True iff LR state YYSTATE has only a default reduction (regardless
901 yyisDefaultedState (yyStateNum yystate
)
903 return yypact_value_is_default (yypact
[yystate
]);
906 /** The default reduction for YYSTATE, assuming it has one. */
907 static inline yyRuleNum
908 yydefaultAction (yyStateNum yystate
)
910 return yydefact
[yystate
];
913 #define yytable_value_is_error(Yytable_value) \
914 ]b4_table_value_equals([[table]], [[Yytable_value]], [b4_table_ninf])[
916 /** Set *YYACTION to the action to take in YYSTATE on seeing YYTOKEN.
918 * R < 0: Reduce on rule -R.
920 * R > 0: Shift to state R.
921 * Set *YYCONFLICTS to a pointer into yyconfl to a 0-terminated list
922 * of conflicting reductions.
925 yygetLRActions (yyStateNum yystate
, int yytoken
,
926 int* yyaction
, const short int** yyconflicts
)
928 int yyindex
= yypact
[yystate
] + yytoken
;
929 if (yypact_value_is_default (yypact
[yystate
])
930 || yyindex
< 0 || YYLAST
< yyindex
|| yycheck
[yyindex
] != yytoken
)
932 *yyaction
= -yydefact
[yystate
];
933 *yyconflicts
= yyconfl
;
935 else if (! yytable_value_is_error (yytable
[yyindex
]))
937 *yyaction
= yytable
[yyindex
];
938 *yyconflicts
= yyconfl
+ yyconflp
[yyindex
];
943 *yyconflicts
= yyconfl
+ yyconflp
[yyindex
];
947 static inline yyStateNum
948 yyLRgotoState (yyStateNum yystate
, yySymbol yylhs
)
950 int yyr
= yypgoto
[yylhs
- YYNTOKENS
] + yystate
;
951 if (0 <= yyr
&& yyr
<= YYLAST
&& yycheck
[yyr
] == yystate
)
954 return yydefgoto
[yylhs
- YYNTOKENS
];
958 yyisShiftAction (int yyaction
)
964 yyisErrorAction (int yyaction
)
966 return yyaction
== 0;
971 /** Return a fresh GLRStackItem in YYSTACKP. The item is an LR state
972 * if YYISSTATE, and otherwise a semantic option. Callers should call
973 * YY_RESERVE_GLRSTACK afterwards to make sure there is sufficient
976 static inline yyGLRStackItem
*
977 yynewGLRStackItem (yyGLRStack
* yystackp
, yybool yyisState
)
979 yyGLRStackItem
* yynewItem
= yystackp
->yynextFree
;
980 yystackp
->yyspaceLeft
-= 1;
981 yystackp
->yynextFree
+= 1;
982 yynewItem
->yystate
.yyisState
= yyisState
;
986 /** Add a new semantic action that will execute the action for rule
987 * YYRULE on the semantic values in YYRHS to the list of
988 * alternative actions for YYSTATE. Assumes that YYRHS comes from
989 * stack #YYK of *YYSTACKP. */
991 yyaddDeferredAction (yyGLRStack
* yystackp
, size_t yyk
, yyGLRState
* yystate
,
992 yyGLRState
* yyrhs
, yyRuleNum yyrule
)
994 yySemanticOption
* yynewOption
=
995 &yynewGLRStackItem (yystackp
, yyfalse
)->yyoption
;
996 yynewOption
->yystate
= yyrhs
;
997 yynewOption
->yyrule
= yyrule
;
998 if (yystackp
->yytops
.yylookaheadNeeds
[yyk
])
1000 yynewOption
->yyrawchar
= yychar
;
1001 yynewOption
->yyval
= yylval
;]b4_locations_if([
1002 yynewOption
->yyloc
= yylloc
;])[
1005 yynewOption
->yyrawchar
= YYEMPTY
;
1006 yynewOption
->yynext
= yystate
->yysemantics
.yyfirstVal
;
1007 yystate
->yysemantics
.yyfirstVal
= yynewOption
;
1009 YY_RESERVE_GLRSTACK (yystackp
);
1014 /** Initialize YYSET to a singleton set containing an empty stack. */
1016 yyinitStateSet (yyGLRStateSet
* yyset
)
1019 yyset
->yycapacity
= 16;
1020 yyset
->yystates
= (yyGLRState
**) YYMALLOC (16 * sizeof yyset
->yystates
[0]);
1021 if (! yyset
->yystates
)
1023 yyset
->yystates
[0] = YY_NULL
;
1024 yyset
->yylookaheadNeeds
=
1025 (yybool
*) YYMALLOC (16 * sizeof yyset
->yylookaheadNeeds
[0]);
1026 if (! yyset
->yylookaheadNeeds
)
1028 YYFREE (yyset
->yystates
);
1034 static void yyfreeStateSet (yyGLRStateSet
* yyset
)
1036 YYFREE (yyset
->yystates
);
1037 YYFREE (yyset
->yylookaheadNeeds
);
1040 /** Initialize *YYSTACKP to a single empty stack, with total maximum
1041 * capacity for all stacks of YYSIZE. */
1043 yyinitGLRStack (yyGLRStack
* yystackp
, size_t yysize
)
1045 yystackp
->yyerrState
= 0;
1047 yystackp
->yyspaceLeft
= yysize
;
1049 (yyGLRStackItem
*) YYMALLOC (yysize
* sizeof yystackp
->yynextFree
[0]);
1050 if (!yystackp
->yyitems
)
1052 yystackp
->yynextFree
= yystackp
->yyitems
;
1053 yystackp
->yysplitPoint
= YY_NULL
;
1054 yystackp
->yylastDeleted
= YY_NULL
;
1055 return yyinitStateSet (&yystackp
->yytops
);
1059 #if YYSTACKEXPANDABLE
1060 # define YYRELOC(YYFROMITEMS,YYTOITEMS,YYX,YYTYPE) \
1061 &((YYTOITEMS) - ((YYFROMITEMS) - (yyGLRStackItem*) (YYX)))->YYTYPE
1063 /** If *YYSTACKP is expandable, extend it. WARNING: Pointers into the
1064 stack from outside should be considered invalid after this call.
1065 We always expand when there are 1 or fewer items left AFTER an
1066 allocation, so that we can avoid having external pointers exist
1067 across an allocation. */
1069 yyexpandGLRStack (yyGLRStack
* yystackp
)
1071 yyGLRStackItem
* yynewItems
;
1072 yyGLRStackItem
* yyp0
, *yyp1
;
1075 size_t yysize
= yystackp
->yynextFree
- yystackp
->yyitems
;
1076 if (YYMAXDEPTH
- YYHEADROOM
< yysize
)
1077 yyMemoryExhausted (yystackp
);
1078 yynewSize
= 2*yysize
;
1079 if (YYMAXDEPTH
< yynewSize
)
1080 yynewSize
= YYMAXDEPTH
;
1081 yynewItems
= (yyGLRStackItem
*) YYMALLOC (yynewSize
* sizeof yynewItems
[0]);
1083 yyMemoryExhausted (yystackp
);
1084 for (yyp0
= yystackp
->yyitems
, yyp1
= yynewItems
, yyn
= yysize
;
1086 yyn
-= 1, yyp0
+= 1, yyp1
+= 1)
1089 if (*(yybool
*) yyp0
)
1091 yyGLRState
* yys0
= &yyp0
->yystate
;
1092 yyGLRState
* yys1
= &yyp1
->yystate
;
1093 if (yys0
->yypred
!= YY_NULL
)
1095 YYRELOC (yyp0
, yyp1
, yys0
->yypred
, yystate
);
1096 if (! yys0
->yyresolved
&& yys0
->yysemantics
.yyfirstVal
!= YY_NULL
)
1097 yys1
->yysemantics
.yyfirstVal
=
1098 YYRELOC (yyp0
, yyp1
, yys0
->yysemantics
.yyfirstVal
, yyoption
);
1102 yySemanticOption
* yyv0
= &yyp0
->yyoption
;
1103 yySemanticOption
* yyv1
= &yyp1
->yyoption
;
1104 if (yyv0
->yystate
!= YY_NULL
)
1105 yyv1
->yystate
= YYRELOC (yyp0
, yyp1
, yyv0
->yystate
, yystate
);
1106 if (yyv0
->yynext
!= YY_NULL
)
1107 yyv1
->yynext
= YYRELOC (yyp0
, yyp1
, yyv0
->yynext
, yyoption
);
1110 if (yystackp
->yysplitPoint
!= YY_NULL
)
1111 yystackp
->yysplitPoint
= YYRELOC (yystackp
->yyitems
, yynewItems
,
1112 yystackp
->yysplitPoint
, yystate
);
1114 for (yyn
= 0; yyn
< yystackp
->yytops
.yysize
; yyn
+= 1)
1115 if (yystackp
->yytops
.yystates
[yyn
] != YY_NULL
)
1116 yystackp
->yytops
.yystates
[yyn
] =
1117 YYRELOC (yystackp
->yyitems
, yynewItems
,
1118 yystackp
->yytops
.yystates
[yyn
], yystate
);
1119 YYFREE (yystackp
->yyitems
);
1120 yystackp
->yyitems
= yynewItems
;
1121 yystackp
->yynextFree
= yynewItems
+ yysize
;
1122 yystackp
->yyspaceLeft
= yynewSize
- yysize
;
1127 yyfreeGLRStack (yyGLRStack
* yystackp
)
1129 YYFREE (yystackp
->yyitems
);
1130 yyfreeStateSet (&yystackp
->yytops
);
1133 /** Assuming that YYS is a GLRState somewhere on *YYSTACKP, update the
1134 * splitpoint of *YYSTACKP, if needed, so that it is at least as deep as
1137 yyupdateSplit (yyGLRStack
* yystackp
, yyGLRState
* yys
)
1139 if (yystackp
->yysplitPoint
!= YY_NULL
&& yystackp
->yysplitPoint
> yys
)
1140 yystackp
->yysplitPoint
= yys
;
1143 /** Invalidate stack #YYK in *YYSTACKP. */
1145 yymarkStackDeleted (yyGLRStack
* yystackp
, size_t yyk
)
1147 if (yystackp
->yytops
.yystates
[yyk
] != YY_NULL
)
1148 yystackp
->yylastDeleted
= yystackp
->yytops
.yystates
[yyk
];
1149 yystackp
->yytops
.yystates
[yyk
] = YY_NULL
;
1152 /** Undelete the last stack in *YYSTACKP that was marked as deleted. Can
1153 only be done once after a deletion, and only when all other stacks have
1156 yyundeleteLastStack (yyGLRStack
* yystackp
)
1158 if (yystackp
->yylastDeleted
== YY_NULL
|| yystackp
->yytops
.yysize
!= 0)
1160 yystackp
->yytops
.yystates
[0] = yystackp
->yylastDeleted
;
1161 yystackp
->yytops
.yysize
= 1;
1162 YYDPRINTF ((stderr
, "Restoring last deleted stack as stack #0.\n"));
1163 yystackp
->yylastDeleted
= YY_NULL
;
1167 yyremoveDeletes (yyGLRStack
* yystackp
)
1171 while (yyj
< yystackp
->yytops
.yysize
)
1173 if (yystackp
->yytops
.yystates
[yyi
] == YY_NULL
)
1177 YYDPRINTF ((stderr
, "Removing dead stacks.\n"));
1179 yystackp
->yytops
.yysize
-= 1;
1183 yystackp
->yytops
.yystates
[yyj
] = yystackp
->yytops
.yystates
[yyi
];
1184 /* In the current implementation, it's unnecessary to copy
1185 yystackp->yytops.yylookaheadNeeds[yyi] since, after
1186 yyremoveDeletes returns, the parser immediately either enters
1187 deterministic operation or shifts a token. However, it doesn't
1188 hurt, and the code might evolve to need it. */
1189 yystackp
->yytops
.yylookaheadNeeds
[yyj
] =
1190 yystackp
->yytops
.yylookaheadNeeds
[yyi
];
1193 YYDPRINTF ((stderr
, "Rename stack %lu -> %lu.\n",
1194 (unsigned long int) yyi
, (unsigned long int) yyj
));
1202 /** Shift to a new state on stack #YYK of *YYSTACKP, corresponding to LR
1203 * state YYLRSTATE, at input position YYPOSN, with (resolved) semantic
1204 * value *YYVALP and source location *YYLOCP. */
1206 yyglrShift (yyGLRStack
* yystackp
, size_t yyk
, yyStateNum yylrState
,
1208 YYSTYPE
* yyvalp
]b4_locations_if([, YYLTYPE
* yylocp
])[)
1210 yyGLRState
* yynewState
= &yynewGLRStackItem (yystackp
, yytrue
)->yystate
;
1212 yynewState
->yylrState
= yylrState
;
1213 yynewState
->yyposn
= yyposn
;
1214 yynewState
->yyresolved
= yytrue
;
1215 yynewState
->yypred
= yystackp
->yytops
.yystates
[yyk
];
1216 yynewState
->yysemantics
.yysval
= *yyvalp
;]b4_locations_if([
1217 yynewState
->yyloc
= *yylocp
;])[
1218 yystackp
->yytops
.yystates
[yyk
] = yynewState
;
1220 YY_RESERVE_GLRSTACK (yystackp
);
1223 /** Shift stack #YYK of *YYSTACKP, to a new state corresponding to LR
1224 * state YYLRSTATE, at input position YYPOSN, with the (unresolved)
1225 * semantic value of YYRHS under the action for YYRULE. */
1227 yyglrShiftDefer (yyGLRStack
* yystackp
, size_t yyk
, yyStateNum yylrState
,
1228 size_t yyposn
, yyGLRState
* yyrhs
, yyRuleNum yyrule
)
1230 yyGLRState
* yynewState
= &yynewGLRStackItem (yystackp
, yytrue
)->yystate
;
1232 yynewState
->yylrState
= yylrState
;
1233 yynewState
->yyposn
= yyposn
;
1234 yynewState
->yyresolved
= yyfalse
;
1235 yynewState
->yypred
= yystackp
->yytops
.yystates
[yyk
];
1236 yynewState
->yysemantics
.yyfirstVal
= YY_NULL
;
1237 yystackp
->yytops
.yystates
[yyk
] = yynewState
;
1239 /* Invokes YY_RESERVE_GLRSTACK. */
1240 yyaddDeferredAction (yystackp
, yyk
, yynewState
, yyrhs
, yyrule
);
1243 #if !]b4_api_PREFIX[DEBUG
1244 # define YY_REDUCE_PRINT(Args)
1246 # define YY_REDUCE_PRINT(Args) \
1249 yy_reduce_print Args; \
1252 /*----------------------------------------------------------------------.
1253 | Report that stack #YYK of *YYSTACKP is going to be reduced by YYRULE. |
1254 `----------------------------------------------------------------------*/
1257 yy_reduce_print (int yynormal
, yyGLRStackItem
* yyvsp
, size_t yyk
,
1258 yyRuleNum yyrule
]b4_user_formals
[)
1260 int yynrhs
= yyrhsLength (yyrule
);]b4_locations_if([
1263 YYFPRINTF (stderr
, "Reducing stack %lu by rule %d (line %lu):\n",
1264 (unsigned long int) yyk
, yyrule
- 1,
1265 (unsigned long int) yyrline
[yyrule
]);
1267 yyfillin (yyvsp
, 1, -yynrhs
);
1268 /* The symbols being reduced. */
1269 for (yyi
= 0; yyi
< yynrhs
; yyi
++)
1271 YYFPRINTF (stderr
, " $%d = ", yyi
+ 1);
1272 yy_symbol_print (stderr
,
1273 yystos
[yyvsp
[yyi
- yynrhs
+ 1].yystate
.yylrState
],
1274 &yyvsp
[yyi
- yynrhs
+ 1].yystate
.yysemantics
.yysval
1275 ]b4_locations_if([, &]b4_rhs_location(yynrhs
, yyi
+ 1))[]dnl
1277 if (!yyvsp
[yyi
- yynrhs
+ 1].yystate
.yyresolved
)
1278 YYFPRINTF (stderr
, " (unresolved)");
1279 YYFPRINTF (stderr
, "\n");
1284 /** Pop the symbols consumed by reduction #YYRULE from the top of stack
1285 * #YYK of *YYSTACKP, and perform the appropriate semantic action on their
1286 * semantic values. Assumes that all ambiguities in semantic values
1287 * have been previously resolved. Set *YYVALP to the resulting value,
1288 * and *YYLOCP to the computed location (if any). Return value is as
1289 * for userAction. */
1290 static inline YYRESULTTAG
1291 yydoAction (yyGLRStack
* yystackp
, size_t yyk
, yyRuleNum yyrule
,
1292 YYSTYPE
* yyvalp
]b4_locuser_formals
[)
1294 int yynrhs
= yyrhsLength (yyrule
);
1296 if (yystackp
->yysplitPoint
== YY_NULL
)
1298 /* Standard special case: single stack. */
1299 yyGLRStackItem
* yyrhs
= (yyGLRStackItem
*) yystackp
->yytops
.yystates
[yyk
];
1300 YYASSERT (yyk
== 0);
1301 yystackp
->yynextFree
-= yynrhs
;
1302 yystackp
->yyspaceLeft
+= yynrhs
;
1303 yystackp
->yytops
.yystates
[0] = & yystackp
->yynextFree
[-1].yystate
;
1304 YY_REDUCE_PRINT ((1, yyrhs
, yyk
, yyrule
]b4_user_args
[));
1305 return yyuserAction (yyrule
, yynrhs
, yyrhs
, yystackp
,
1306 yyvalp
]b4_locuser_args
[);
1312 yyGLRStackItem yyrhsVals
[YYMAXRHS
+ YYMAXLEFT
+ 1];
1313 yys
= yyrhsVals
[YYMAXRHS
+ YYMAXLEFT
].yystate
.yypred
1314 = yystackp
->yytops
.yystates
[yyk
];]b4_locations_if([[
1316 /* Set default location. */
1317 yyrhsVals
[YYMAXRHS
+ YYMAXLEFT
- 1].yystate
.yyloc
= yys
->yyloc
;]])[
1318 for (yyi
= 0; yyi
< yynrhs
; yyi
+= 1)
1323 yyupdateSplit (yystackp
, yys
);
1324 yystackp
->yytops
.yystates
[yyk
] = yys
;
1325 YY_REDUCE_PRINT ((0, yyrhsVals
+ YYMAXRHS
+ YYMAXLEFT
- 1, yyk
, yyrule
]b4_user_args
[));
1326 return yyuserAction (yyrule
, yynrhs
, yyrhsVals
+ YYMAXRHS
+ YYMAXLEFT
- 1,
1327 yystackp
, yyvalp
]b4_locuser_args
[);
1331 /** Pop items off stack #YYK of *YYSTACKP according to grammar rule YYRULE,
1332 * and push back on the resulting nonterminal symbol. Perform the
1333 * semantic action associated with YYRULE and store its value with the
1334 * newly pushed state, if YYFORCEEVAL or if *YYSTACKP is currently
1335 * unambiguous. Otherwise, store the deferred semantic action with
1336 * the new state. If the new state would have an identical input
1337 * position, LR state, and predecessor to an existing state on the stack,
1338 * it is identified with that existing state, eliminating stack #YYK from
1339 * *YYSTACKP. In this case, the semantic value is
1340 * added to the options for the existing state's semantic value.
1342 static inline YYRESULTTAG
1343 yyglrReduce (yyGLRStack
* yystackp
, size_t yyk
, yyRuleNum yyrule
,
1344 yybool yyforceEval
]b4_user_formals
[)
1346 size_t yyposn
= yystackp
->yytops
.yystates
[yyk
]->yyposn
;
1348 if (yyforceEval
|| yystackp
->yysplitPoint
== YY_NULL
)
1351 YYSTYPE yysval
;]b4_locations_if([
1354 yyflag
= yydoAction (yystackp
, yyk
, yyrule
, &yysval
]b4_locuser_args([&yyloc
])[);
1355 if (yyflag
== yyerr
&& yystackp
->yysplitPoint
!= YY_NULL
)
1357 YYDPRINTF ((stderr
, "Parse on stack %lu rejected by rule #%d.\n",
1358 (unsigned long int) yyk
, yyrule
- 1));
1362 YY_SYMBOL_PRINT ("-> $$ =", yyr1
[yyrule
], &yysval
, &yyloc
);
1363 yyglrShift (yystackp
, yyk
,
1364 yyLRgotoState (yystackp
->yytops
.yystates
[yyk
]->yylrState
,
1365 yylhsNonterm (yyrule
)),
1366 yyposn
, &yysval
]b4_locations_if([, &yyloc
])[);
1372 yyGLRState
* yys
, *yys0
= yystackp
->yytops
.yystates
[yyk
];
1373 yyStateNum yynewLRState
;
1375 for (yys
= yystackp
->yytops
.yystates
[yyk
], yyn
= yyrhsLength (yyrule
);
1381 yyupdateSplit (yystackp
, yys
);
1382 yynewLRState
= yyLRgotoState (yys
->yylrState
, yylhsNonterm (yyrule
));
1384 "Reduced stack %lu by rule #%d; action deferred. "
1385 "Now in state %d.\n",
1386 (unsigned long int) yyk
, yyrule
- 1, yynewLRState
));
1387 for (yyi
= 0; yyi
< yystackp
->yytops
.yysize
; yyi
+= 1)
1388 if (yyi
!= yyk
&& yystackp
->yytops
.yystates
[yyi
] != YY_NULL
)
1390 yyGLRState
*yysplit
= yystackp
->yysplitPoint
;
1391 yyGLRState
*yyp
= yystackp
->yytops
.yystates
[yyi
];
1392 while (yyp
!= yys
&& yyp
!= yysplit
&& yyp
->yyposn
>= yyposn
)
1394 if (yyp
->yylrState
== yynewLRState
&& yyp
->yypred
== yys
)
1396 yyaddDeferredAction (yystackp
, yyk
, yyp
, yys0
, yyrule
);
1397 yymarkStackDeleted (yystackp
, yyk
);
1398 YYDPRINTF ((stderr
, "Merging stack %lu into stack %lu.\n",
1399 (unsigned long int) yyk
,
1400 (unsigned long int) yyi
));
1406 yystackp
->yytops
.yystates
[yyk
] = yys
;
1407 yyglrShiftDefer (yystackp
, yyk
, yynewLRState
, yyposn
, yys0
, yyrule
);
1413 yysplitStack (yyGLRStack
* yystackp
, size_t yyk
)
1415 if (yystackp
->yysplitPoint
== YY_NULL
)
1417 YYASSERT (yyk
== 0);
1418 yystackp
->yysplitPoint
= yystackp
->yytops
.yystates
[yyk
];
1420 if (yystackp
->yytops
.yysize
>= yystackp
->yytops
.yycapacity
)
1422 yyGLRState
** yynewStates
;
1423 yybool
* yynewLookaheadNeeds
;
1425 yynewStates
= YY_NULL
;
1427 if (yystackp
->yytops
.yycapacity
1428 > (YYSIZEMAX
/ (2 * sizeof yynewStates
[0])))
1429 yyMemoryExhausted (yystackp
);
1430 yystackp
->yytops
.yycapacity
*= 2;
1433 (yyGLRState
**) YYREALLOC (yystackp
->yytops
.yystates
,
1434 (yystackp
->yytops
.yycapacity
1435 * sizeof yynewStates
[0]));
1436 if (yynewStates
== YY_NULL
)
1437 yyMemoryExhausted (yystackp
);
1438 yystackp
->yytops
.yystates
= yynewStates
;
1440 yynewLookaheadNeeds
=
1441 (yybool
*) YYREALLOC (yystackp
->yytops
.yylookaheadNeeds
,
1442 (yystackp
->yytops
.yycapacity
1443 * sizeof yynewLookaheadNeeds
[0]));
1444 if (yynewLookaheadNeeds
== YY_NULL
)
1445 yyMemoryExhausted (yystackp
);
1446 yystackp
->yytops
.yylookaheadNeeds
= yynewLookaheadNeeds
;
1448 yystackp
->yytops
.yystates
[yystackp
->yytops
.yysize
]
1449 = yystackp
->yytops
.yystates
[yyk
];
1450 yystackp
->yytops
.yylookaheadNeeds
[yystackp
->yytops
.yysize
]
1451 = yystackp
->yytops
.yylookaheadNeeds
[yyk
];
1452 yystackp
->yytops
.yysize
+= 1;
1453 return yystackp
->yytops
.yysize
-1;
1456 /** True iff YYY0 and YYY1 represent identical options at the top level.
1457 * That is, they represent the same rule applied to RHS symbols
1458 * that produce the same terminal symbols. */
1460 yyidenticalOptions (yySemanticOption
* yyy0
, yySemanticOption
* yyy1
)
1462 if (yyy0
->yyrule
== yyy1
->yyrule
)
1464 yyGLRState
*yys0
, *yys1
;
1466 for (yys0
= yyy0
->yystate
, yys1
= yyy1
->yystate
,
1467 yyn
= yyrhsLength (yyy0
->yyrule
);
1469 yys0
= yys0
->yypred
, yys1
= yys1
->yypred
, yyn
-= 1)
1470 if (yys0
->yyposn
!= yys1
->yyposn
)
1478 /** Assuming identicalOptions (YYY0,YYY1), destructively merge the
1479 * alternative semantic values for the RHS-symbols of YYY1 and YYY0. */
1481 yymergeOptionSets (yySemanticOption
* yyy0
, yySemanticOption
* yyy1
)
1483 yyGLRState
*yys0
, *yys1
;
1485 for (yys0
= yyy0
->yystate
, yys1
= yyy1
->yystate
,
1486 yyn
= yyrhsLength (yyy0
->yyrule
);
1488 yys0
= yys0
->yypred
, yys1
= yys1
->yypred
, yyn
-= 1)
1492 else if (yys0
->yyresolved
)
1494 yys1
->yyresolved
= yytrue
;
1495 yys1
->yysemantics
.yysval
= yys0
->yysemantics
.yysval
;
1497 else if (yys1
->yyresolved
)
1499 yys0
->yyresolved
= yytrue
;
1500 yys0
->yysemantics
.yysval
= yys1
->yysemantics
.yysval
;
1504 yySemanticOption
** yyz0p
= &yys0
->yysemantics
.yyfirstVal
;
1505 yySemanticOption
* yyz1
= yys1
->yysemantics
.yyfirstVal
;
1508 if (yyz1
== *yyz0p
|| yyz1
== YY_NULL
)
1510 else if (*yyz0p
== YY_NULL
)
1515 else if (*yyz0p
< yyz1
)
1517 yySemanticOption
* yyz
= *yyz0p
;
1519 yyz1
= yyz1
->yynext
;
1520 (*yyz0p
)->yynext
= yyz
;
1522 yyz0p
= &(*yyz0p
)->yynext
;
1524 yys1
->yysemantics
.yyfirstVal
= yys0
->yysemantics
.yyfirstVal
;
1529 /** Y0 and Y1 represent two possible actions to take in a given
1530 * parsing state; return 0 if no combination is possible,
1531 * 1 if user-mergeable, 2 if Y0 is preferred, 3 if Y1 is preferred. */
1533 yypreference (yySemanticOption
* y0
, yySemanticOption
* y1
)
1535 yyRuleNum r0
= y0
->yyrule
, r1
= y1
->yyrule
;
1536 int p0
= yydprec
[r0
], p1
= yydprec
[r1
];
1540 if (yymerger
[r0
] == 0 || yymerger
[r0
] != yymerger
[r1
])
1545 if (p0
== 0 || p1
== 0)
1554 static YYRESULTTAG
yyresolveValue (yyGLRState
* yys
,
1555 yyGLRStack
* yystackp
]b4_user_formals
[);
1558 /** Resolve the previous YYN states starting at and including state YYS
1559 * on *YYSTACKP. If result != yyok, some states may have been left
1560 * unresolved possibly with empty semantic option chains. Regardless
1561 * of whether result = yyok, each state has been left with consistent
1562 * data so that yydestroyGLRState can be invoked if necessary. */
1564 yyresolveStates (yyGLRState
* yys
, int yyn
,
1565 yyGLRStack
* yystackp
]b4_user_formals
[)
1569 YYASSERT (yys
->yypred
);
1570 YYCHK (yyresolveStates (yys
->yypred
, yyn
-1, yystackp
]b4_user_args
[));
1571 if (! yys
->yyresolved
)
1572 YYCHK (yyresolveValue (yys
, yystackp
]b4_user_args
[));
1577 /** Resolve the states for the RHS of YYOPT on *YYSTACKP, perform its
1578 * user action, and return the semantic value and location in *YYVALP
1579 * and *YYLOCP. Regardless of whether result = yyok, all RHS states
1580 * have been destroyed (assuming the user action destroys all RHS
1581 * semantic values if invoked). */
1583 yyresolveAction (yySemanticOption
* yyopt
, yyGLRStack
* yystackp
,
1584 YYSTYPE
* yyvalp
]b4_locuser_formals
[)
1586 yyGLRStackItem yyrhsVals
[YYMAXRHS
+ YYMAXLEFT
+ 1];
1587 int yynrhs
= yyrhsLength (yyopt
->yyrule
);
1588 YYRESULTTAG yyflag
=
1589 yyresolveStates (yyopt
->yystate
, yynrhs
, yystackp
]b4_user_args
[);
1593 for (yys
= yyopt
->yystate
; yynrhs
> 0; yys
= yys
->yypred
, yynrhs
-= 1)
1594 yydestroyGLRState ("Cleanup: popping", yys
]b4_user_args
[);
1598 yyrhsVals
[YYMAXRHS
+ YYMAXLEFT
].yystate
.yypred
= yyopt
->yystate
;]b4_locations_if([[
1600 /* Set default location. */
1601 yyrhsVals
[YYMAXRHS
+ YYMAXLEFT
- 1].yystate
.yyloc
= yyopt
->yystate
->yyloc
;]])[
1603 int yychar_current
= yychar
;
1604 YYSTYPE yylval_current
= yylval
;]b4_locations_if([
1605 YYLTYPE yylloc_current
= yylloc
;])[
1606 yychar
= yyopt
->yyrawchar
;
1607 yylval
= yyopt
->yyval
;]b4_locations_if([
1608 yylloc
= yyopt
->yyloc
;])[
1609 yyflag
= yyuserAction (yyopt
->yyrule
, yynrhs
,
1610 yyrhsVals
+ YYMAXRHS
+ YYMAXLEFT
- 1,
1611 yystackp
, yyvalp
]b4_locuser_args
[);
1612 yychar
= yychar_current
;
1613 yylval
= yylval_current
;]b4_locations_if([
1614 yylloc
= yylloc_current
;])[
1619 #if ]b4_api_PREFIX[DEBUG
1621 yyreportTree (yySemanticOption
* yyx
, int yyindent
)
1623 int yynrhs
= yyrhsLength (yyx
->yyrule
);
1626 yyGLRState
* yystates
[1 + YYMAXRHS
];
1627 yyGLRState yyleftmost_state
;
1629 for (yyi
= yynrhs
, yys
= yyx
->yystate
; 0 < yyi
; yyi
-= 1, yys
= yys
->yypred
)
1630 yystates
[yyi
] = yys
;
1633 yyleftmost_state
.yyposn
= 0;
1634 yystates
[0] = &yyleftmost_state
;
1639 if (yyx
->yystate
->yyposn
< yys
->yyposn
+ 1)
1640 YYFPRINTF (stderr
, "%*s%s -> <Rule %d, empty>\n",
1641 yyindent
, "", yytokenName (yylhsNonterm (yyx
->yyrule
)),
1644 YYFPRINTF (stderr
, "%*s%s -> <Rule %d, tokens %lu .. %lu>\n",
1645 yyindent
, "", yytokenName (yylhsNonterm (yyx
->yyrule
)),
1646 yyx
->yyrule
- 1, (unsigned long int) (yys
->yyposn
+ 1),
1647 (unsigned long int) yyx
->yystate
->yyposn
);
1648 for (yyi
= 1; yyi
<= yynrhs
; yyi
+= 1)
1650 if (yystates
[yyi
]->yyresolved
)
1652 if (yystates
[yyi
-1]->yyposn
+1 > yystates
[yyi
]->yyposn
)
1653 YYFPRINTF (stderr
, "%*s%s <empty>\n", yyindent
+2, "",
1654 yytokenName (yystos
[yystates
[yyi
]->yylrState
]));
1656 YYFPRINTF (stderr
, "%*s%s <tokens %lu .. %lu>\n", yyindent
+2, "",
1657 yytokenName (yystos
[yystates
[yyi
]->yylrState
]),
1658 (unsigned long int) (yystates
[yyi
-1]->yyposn
+ 1),
1659 (unsigned long int) yystates
[yyi
]->yyposn
);
1662 yyreportTree (yystates
[yyi
]->yysemantics
.yyfirstVal
, yyindent
+2);
1668 yyreportAmbiguity (yySemanticOption
* yyx0
,
1669 yySemanticOption
* yyx1
]b4_pure_formals
[)
1674 #if ]b4_api_PREFIX[DEBUG
1675 YYFPRINTF (stderr
, "Ambiguity detected.\n");
1676 YYFPRINTF (stderr
, "Option 1,\n");
1677 yyreportTree (yyx0
, 2);
1678 YYFPRINTF (stderr
, "\nOption 2,\n");
1679 yyreportTree (yyx1
, 2);
1680 YYFPRINTF (stderr
, "\n");
1683 yyerror (]b4_yyerror_args
[YY_("syntax is ambiguous"));
1685 }]b4_locations_if([[
1687 /** Resolve the locations for each of the YYN1 states in *YYSTACKP,
1688 * ending at YYS1. Has no effect on previously resolved states.
1689 * The first semantic option of a state is always chosen. */
1691 yyresolveLocations (yyGLRState
* yys1
, int yyn1
,
1692 yyGLRStack
*yystackp
]b4_user_formals
[)
1696 yyresolveLocations (yys1
->yypred
, yyn1
- 1, yystackp
]b4_user_args
[);
1697 if (!yys1
->yyresolved
)
1699 yyGLRStackItem yyrhsloc
[1 + YYMAXRHS
];
1701 yySemanticOption
*yyoption
= yys1
->yysemantics
.yyfirstVal
;
1702 YYASSERT (yyoption
!= YY_NULL
);
1703 yynrhs
= yyrhsLength (yyoption
->yyrule
);
1708 yyresolveLocations (yyoption
->yystate
, yynrhs
,
1709 yystackp
]b4_user_args
[);
1710 for (yys
= yyoption
->yystate
, yyn
= yynrhs
;
1712 yys
= yys
->yypred
, yyn
-= 1)
1713 yyrhsloc
[yyn
].yystate
.yyloc
= yys
->yyloc
;
1717 /* Both yyresolveAction and yyresolveLocations traverse the GSS
1718 in reverse rightmost order. It is only necessary to invoke
1719 yyresolveLocations on a subforest for which yyresolveAction
1720 would have been invoked next had an ambiguity not been
1721 detected. Thus the location of the previous state (but not
1722 necessarily the previous state itself) is guaranteed to be
1723 resolved already. */
1724 yyGLRState
*yyprevious
= yyoption
->yystate
;
1725 yyrhsloc
[0].yystate
.yyloc
= yyprevious
->yyloc
;
1728 int yychar_current
= yychar
;
1729 YYSTYPE yylval_current
= yylval
;
1730 YYLTYPE yylloc_current
= yylloc
;
1731 yychar
= yyoption
->yyrawchar
;
1732 yylval
= yyoption
->yyval
;
1733 yylloc
= yyoption
->yyloc
;
1734 YYLLOC_DEFAULT ((yys1
->yyloc
), yyrhsloc
, yynrhs
);
1735 yychar
= yychar_current
;
1736 yylval
= yylval_current
;
1737 yylloc
= yylloc_current
;
1743 /** Resolve the ambiguity represented in state YYS in *YYSTACKP,
1744 * perform the indicated actions, and set the semantic value of YYS.
1745 * If result != yyok, the chain of semantic options in YYS has been
1746 * cleared instead or it has been left unmodified except that
1747 * redundant options may have been removed. Regardless of whether
1748 * result = yyok, YYS has been left with consistent data so that
1749 * yydestroyGLRState can be invoked if necessary. */
1751 yyresolveValue (yyGLRState
* yys
, yyGLRStack
* yystackp
]b4_user_formals
[)
1753 yySemanticOption
* yyoptionList
= yys
->yysemantics
.yyfirstVal
;
1754 yySemanticOption
* yybest
= yyoptionList
;
1755 yySemanticOption
** yypp
;
1756 yybool yymerge
= yyfalse
;
1758 YYRESULTTAG yyflag
;]b4_locations_if([
1759 YYLTYPE
*yylocp
= &yys
->yyloc
;])[
1761 for (yypp
= &yyoptionList
->yynext
; *yypp
!= YY_NULL
; )
1763 yySemanticOption
* yyp
= *yypp
;
1765 if (yyidenticalOptions (yybest
, yyp
))
1767 yymergeOptionSets (yybest
, yyp
);
1768 *yypp
= yyp
->yynext
;
1772 switch (yypreference (yybest
, yyp
))
1774 case 0:]b4_locations_if([[
1775 yyresolveLocations (yys
, 1, yystackp
]b4_user_args
[);]])[
1776 return yyreportAmbiguity (yybest
, yyp
]b4_pure_args
[);
1788 /* This cannot happen so it is not worth a YYASSERT (yyfalse),
1789 but some compilers complain if the default case is
1793 yypp
= &yyp
->yynext
;
1799 yySemanticOption
* yyp
;
1800 int yyprec
= yydprec
[yybest
->yyrule
];
1801 yyflag
= yyresolveAction (yybest
, yystackp
, &yysval
]b4_locuser_args
[);
1803 for (yyp
= yybest
->yynext
; yyp
!= YY_NULL
; yyp
= yyp
->yynext
)
1805 if (yyprec
== yydprec
[yyp
->yyrule
])
1807 YYSTYPE yysval_other
;]b4_locations_if([
1809 yyflag
= yyresolveAction (yyp
, yystackp
, &yysval_other
]b4_locuser_args([&yydummy
])[);
1812 yydestruct ("Cleanup: discarding incompletely merged value for",
1813 yystos
[yys
->yylrState
],
1814 &yysval
]b4_locuser_args
[);
1817 yyuserMerge (yymerger
[yyp
->yyrule
], &yysval
, &yysval_other
);
1822 yyflag
= yyresolveAction (yybest
, yystackp
, &yysval
]b4_locuser_args([yylocp
])[);
1826 yys
->yyresolved
= yytrue
;
1827 yys
->yysemantics
.yysval
= yysval
;
1830 yys
->yysemantics
.yyfirstVal
= YY_NULL
;
1835 yyresolveStack (yyGLRStack
* yystackp
]b4_user_formals
[)
1837 if (yystackp
->yysplitPoint
!= YY_NULL
)
1842 for (yyn
= 0, yys
= yystackp
->yytops
.yystates
[0];
1843 yys
!= yystackp
->yysplitPoint
;
1844 yys
= yys
->yypred
, yyn
+= 1)
1846 YYCHK (yyresolveStates (yystackp
->yytops
.yystates
[0], yyn
, yystackp
1853 yycompressStack (yyGLRStack
* yystackp
)
1855 yyGLRState
* yyp
, *yyq
, *yyr
;
1857 if (yystackp
->yytops
.yysize
!= 1 || yystackp
->yysplitPoint
== YY_NULL
)
1860 for (yyp
= yystackp
->yytops
.yystates
[0], yyq
= yyp
->yypred
, yyr
= YY_NULL
;
1861 yyp
!= yystackp
->yysplitPoint
;
1862 yyr
= yyp
, yyp
= yyq
, yyq
= yyp
->yypred
)
1865 yystackp
->yyspaceLeft
+= yystackp
->yynextFree
- yystackp
->yyitems
;
1866 yystackp
->yynextFree
= ((yyGLRStackItem
*) yystackp
->yysplitPoint
) + 1;
1867 yystackp
->yyspaceLeft
-= yystackp
->yynextFree
- yystackp
->yyitems
;
1868 yystackp
->yysplitPoint
= YY_NULL
;
1869 yystackp
->yylastDeleted
= YY_NULL
;
1871 while (yyr
!= YY_NULL
)
1873 yystackp
->yynextFree
->yystate
= *yyr
;
1875 yystackp
->yynextFree
->yystate
.yypred
= &yystackp
->yynextFree
[-1].yystate
;
1876 yystackp
->yytops
.yystates
[0] = &yystackp
->yynextFree
->yystate
;
1877 yystackp
->yynextFree
+= 1;
1878 yystackp
->yyspaceLeft
-= 1;
1883 yyprocessOneStack (yyGLRStack
* yystackp
, size_t yyk
,
1884 size_t yyposn
]b4_pure_formals
[)
1886 while (yystackp
->yytops
.yystates
[yyk
] != YY_NULL
)
1888 yyStateNum yystate
= yystackp
->yytops
.yystates
[yyk
]->yylrState
;
1889 YYDPRINTF ((stderr
, "Stack %lu Entering state %d\n",
1890 (unsigned long int) yyk
, yystate
));
1892 YYASSERT (yystate
!= YYFINAL
);
1894 if (yyisDefaultedState (yystate
))
1897 yyRuleNum yyrule
= yydefaultAction (yystate
);
1900 YYDPRINTF ((stderr
, "Stack %lu dies.\n",
1901 (unsigned long int) yyk
));
1902 yymarkStackDeleted (yystackp
, yyk
);
1905 yyflag
= yyglrReduce (yystackp
, yyk
, yyrule
, yyimmediate
[yyrule
]]b4_user_args
[);
1906 if (yyflag
== yyerr
)
1910 "(predicate failure or explicit user error).\n",
1911 (unsigned long int) yyk
));
1912 yymarkStackDeleted (yystackp
, yyk
);
1922 const short int* yyconflicts
;
1924 yystackp
->yytops
.yylookaheadNeeds
[yyk
] = yytrue
;
1925 if (yychar
== YYEMPTY
)
1927 YYDPRINTF ((stderr
, "Reading a token: "));
1931 if (yychar
<= YYEOF
)
1933 yychar
= yytoken
= YYEOF
;
1934 YYDPRINTF ((stderr
, "Now at end of input.\n"));
1938 yytoken
= YYTRANSLATE (yychar
);
1939 YY_SYMBOL_PRINT ("Next token is", yytoken
, &yylval
, &yylloc
);
1942 yygetLRActions (yystate
, yytoken
, &yyaction
, &yyconflicts
);
1944 while (*yyconflicts
!= 0)
1947 size_t yynewStack
= yysplitStack (yystackp
, yyk
);
1948 YYDPRINTF ((stderr
, "Splitting off stack %lu from %lu.\n",
1949 (unsigned long int) yynewStack
,
1950 (unsigned long int) yyk
));
1951 yyflag
= yyglrReduce (yystackp
, yynewStack
,
1953 yyimmediate
[*yyconflicts
]]b4_user_args
[);
1955 YYCHK (yyprocessOneStack (yystackp
, yynewStack
,
1956 yyposn
]b4_pure_args
[));
1957 else if (yyflag
== yyerr
)
1959 YYDPRINTF ((stderr
, "Stack %lu dies.\n",
1960 (unsigned long int) yynewStack
));
1961 yymarkStackDeleted (yystackp
, yynewStack
);
1968 if (yyisShiftAction (yyaction
))
1970 else if (yyisErrorAction (yyaction
))
1972 YYDPRINTF ((stderr
, "Stack %lu dies.\n",
1973 (unsigned long int) yyk
));
1974 yymarkStackDeleted (yystackp
, yyk
);
1979 YYRESULTTAG yyflag
= yyglrReduce (yystackp
, yyk
, -yyaction
,
1980 yyimmediate
[-yyaction
]]b4_user_args
[);
1981 if (yyflag
== yyerr
)
1985 "(predicate failure or explicit user error).\n",
1986 (unsigned long int) yyk
));
1987 yymarkStackDeleted (yystackp
, yyk
);
1990 else if (yyflag
!= yyok
)
1999 yyreportSyntaxError (yyGLRStack
* yystackp
]b4_user_formals
[)
2001 if (yystackp
->yyerrState
!= 0)
2003 #if ! YYERROR_VERBOSE
2004 yyerror (]b4_lyyerror_args
[YY_("syntax error"));
2007 yySymbol yytoken
= yychar
== YYEMPTY
? YYEMPTY
: YYTRANSLATE (yychar
);
2008 size_t yysize0
= yytnamerr (YY_NULL
, yytokenName (yytoken
));
2009 size_t yysize
= yysize0
;
2010 yybool yysize_overflow
= yyfalse
;
2011 char* yymsg
= YY_NULL
;
2012 enum { YYERROR_VERBOSE_ARGS_MAXIMUM
= 5 };
2013 /* Internationalized format string. */
2014 const char *yyformat
= YY_NULL
;
2015 /* Arguments of yyformat. */
2016 char const *yyarg
[YYERROR_VERBOSE_ARGS_MAXIMUM
];
2017 /* Number of reported tokens (one for the "unexpected", one per
2021 /* There are many possibilities here to consider:
2022 - If this state is a consistent state with a default action, then
2023 the only way this function was invoked is if the default action
2024 is an error action. In that case, don't check for expected
2025 tokens because there are none.
2026 - The only way there can be no lookahead present (in yychar) is if
2027 this state is a consistent state with a default action. Thus,
2028 detecting the absence of a lookahead is sufficient to determine
2029 that there is no unexpected or expected token to report. In that
2030 case, just report a simple "syntax error".
2031 - Don't assume there isn't a lookahead just because this state is a
2032 consistent state with a default action. There might have been a
2033 previous inconsistent state, consistent state with a non-default
2034 action, or user semantic action that manipulated yychar.
2035 - Of course, the expected token list depends on states to have
2036 correct lookahead information, and it depends on the parser not
2037 to perform extra reductions after fetching a lookahead from the
2038 scanner and before detecting a syntax error. Thus, state merging
2039 (from LALR or IELR) and default reductions corrupt the expected
2040 token list. However, the list is correct for canonical LR with
2041 one exception: it will still contain any token that will not be
2042 accepted due to an error action in a later state.
2044 if (yytoken
!= YYEMPTY
)
2046 int yyn
= yypact
[yystackp
->yytops
.yystates
[0]->yylrState
];
2047 yyarg
[yycount
++] = yytokenName (yytoken
);
2048 if (!yypact_value_is_default (yyn
))
2050 /* Start YYX at -YYN if negative to avoid negative indexes in
2051 YYCHECK. In other words, skip the first -YYN actions for this
2052 state because they are default actions. */
2053 int yyxbegin
= yyn
< 0 ? -yyn
: 0;
2054 /* Stay within bounds of both yycheck and yytname. */
2055 int yychecklim
= YYLAST
- yyn
+ 1;
2056 int yyxend
= yychecklim
< YYNTOKENS
? yychecklim
: YYNTOKENS
;
2058 for (yyx
= yyxbegin
; yyx
< yyxend
; ++yyx
)
2059 if (yycheck
[yyx
+ yyn
] == yyx
&& yyx
!= YYTERROR
2060 && !yytable_value_is_error (yytable
[yyx
+ yyn
]))
2062 if (yycount
== YYERROR_VERBOSE_ARGS_MAXIMUM
)
2068 yyarg
[yycount
++] = yytokenName (yyx
);
2070 size_t yysz
= yysize
+ yytnamerr (YY_NULL
, yytokenName (yyx
));
2071 yysize_overflow
|= yysz
< yysize
;
2080 #define YYCASE_(N, S) \
2084 YYCASE_(0, YY_("syntax error"));
2085 YYCASE_(1, YY_("syntax error, unexpected %s"));
2086 YYCASE_(2, YY_("syntax error, unexpected %s, expecting %s"));
2087 YYCASE_(3, YY_("syntax error, unexpected %s, expecting %s or %s"));
2088 YYCASE_(4, YY_("syntax error, unexpected %s, expecting %s or %s or %s"));
2089 YYCASE_(5, YY_("syntax error, unexpected %s, expecting %s or %s or %s or %s"));
2094 size_t yysz
= yysize
+ strlen (yyformat
);
2095 yysize_overflow
|= yysz
< yysize
;
2099 if (!yysize_overflow
)
2100 yymsg
= (char *) YYMALLOC (yysize
);
2106 while ((*yyp
= *yyformat
))
2108 if (*yyp
== '%' && yyformat
[1] == 's' && yyi
< yycount
)
2110 yyp
+= yytnamerr (yyp
, yyarg
[yyi
++]);
2119 yyerror (]b4_lyyerror_args
[yymsg
);
2124 yyerror (]b4_lyyerror_args
[YY_("syntax error"));
2125 yyMemoryExhausted (yystackp
);
2128 #endif /* YYERROR_VERBOSE */
2132 /* Recover from a syntax error on *YYSTACKP, assuming that *YYSTACKP->YYTOKENP,
2133 yylval, and yylloc are the syntactic category, semantic value, and location
2134 of the lookahead. */
2136 yyrecoverSyntaxError (yyGLRStack
* yystackp
]b4_user_formals
[)
2141 if (yystackp
->yyerrState
== 3)
2142 /* We just shifted the error token and (perhaps) took some
2143 reductions. Skip tokens until we can proceed. */
2147 if (yychar
== YYEOF
)
2148 yyFail (yystackp
][]b4_lpure_args
[, YY_NULL
);
2149 if (yychar
!= YYEMPTY
)
2150 {]b4_locations_if([[
2151 /* We throw away the lookahead, but the error range
2152 of the shifted error token must take it into account. */
2153 yyGLRState
*yys
= yystackp
->yytops
.yystates
[0];
2154 yyGLRStackItem yyerror_range
[3];
2155 yyerror_range
[1].yystate
.yyloc
= yys
->yyloc
;
2156 yyerror_range
[2].yystate
.yyloc
= yylloc
;
2157 YYLLOC_DEFAULT ((yys
->yyloc
), yyerror_range
, 2);]])[
2158 yytoken
= YYTRANSLATE (yychar
);
2159 yydestruct ("Error: discarding",
2160 yytoken
, &yylval
]b4_locuser_args([&yylloc
])[);
2162 YYDPRINTF ((stderr
, "Reading a token: "));
2164 if (yychar
<= YYEOF
)
2166 yychar
= yytoken
= YYEOF
;
2167 YYDPRINTF ((stderr
, "Now at end of input.\n"));
2171 yytoken
= YYTRANSLATE (yychar
);
2172 YY_SYMBOL_PRINT ("Next token is", yytoken
, &yylval
, &yylloc
);
2174 yyj
= yypact
[yystackp
->yytops
.yystates
[0]->yylrState
];
2175 if (yypact_value_is_default (yyj
))
2178 if (yyj
< 0 || YYLAST
< yyj
|| yycheck
[yyj
] != yytoken
)
2180 if (yydefact
[yystackp
->yytops
.yystates
[0]->yylrState
] != 0)
2183 else if (! yytable_value_is_error (yytable
[yyj
]))
2187 /* Reduce to one stack. */
2188 for (yyk
= 0; yyk
< yystackp
->yytops
.yysize
; yyk
+= 1)
2189 if (yystackp
->yytops
.yystates
[yyk
] != YY_NULL
)
2191 if (yyk
>= yystackp
->yytops
.yysize
)
2192 yyFail (yystackp
][]b4_lpure_args
[, YY_NULL
);
2193 for (yyk
+= 1; yyk
< yystackp
->yytops
.yysize
; yyk
+= 1)
2194 yymarkStackDeleted (yystackp
, yyk
);
2195 yyremoveDeletes (yystackp
);
2196 yycompressStack (yystackp
);
2198 /* Now pop stack until we find a state that shifts the error token. */
2199 yystackp
->yyerrState
= 3;
2200 while (yystackp
->yytops
.yystates
[0] != YY_NULL
)
2202 yyGLRState
*yys
= yystackp
->yytops
.yystates
[0];
2203 yyj
= yypact
[yys
->yylrState
];
2204 if (! yypact_value_is_default (yyj
))
2207 if (0 <= yyj
&& yyj
<= YYLAST
&& yycheck
[yyj
] == YYTERROR
2208 && yyisShiftAction (yytable
[yyj
]))
2210 /* Shift the error token. */]b4_locations_if([[
2211 /* First adjust its location.*/
2213 yystackp
->yyerror_range
[2].yystate
.yyloc
= yylloc
;
2214 YYLLOC_DEFAULT (yyerrloc
, (yystackp
->yyerror_range
), 2);]])[
2215 YY_SYMBOL_PRINT ("Shifting", yystos
[yytable
[yyj
]],
2216 &yylval
, &yyerrloc
);
2217 yyglrShift (yystackp
, 0, yytable
[yyj
],
2218 yys
->yyposn
, &yylval
]b4_locations_if([, &yyerrloc
])[);
2219 yys
= yystackp
->yytops
.yystates
[0];
2222 }]b4_locations_if([[
2223 yystackp
->yyerror_range
[1].yystate
.yyloc
= yys
->yyloc
;]])[
2224 if (yys
->yypred
!= YY_NULL
)
2225 yydestroyGLRState ("Error: popping", yys
]b4_user_args
[);
2226 yystackp
->yytops
.yystates
[0] = yys
->yypred
;
2227 yystackp
->yynextFree
-= 1;
2228 yystackp
->yyspaceLeft
+= 1;
2230 if (yystackp
->yytops
.yystates
[0] == YY_NULL
)
2231 yyFail (yystackp
][]b4_lpure_args
[, YY_NULL
);
2234 #define YYCHK1(YYE) \
2244 goto yyuser_error; \
2254 ]b4_function_define([yyparse
], [int], b4_parse_param
)[
2258 yyGLRStack
* const yystackp
= &yystack
;
2261 YYDPRINTF ((stderr
, "Starting parse\n"));
2264 yylval
= yyval_default
;]b4_locations_if([
2265 yylloc
= yyloc_default
;])[
2266 ]m4_ifdef([b4_initial_action
], [
2267 b4_dollar_pushdef([yylval
], [], [yylloc
])dnl
2268 /* User initialization code. */
2269 b4_user_initial_action
2270 b4_dollar_popdef
])[]dnl
2272 if (! yyinitGLRStack (yystackp
, YYINITDEPTH
))
2273 goto yyexhaustedlab
;
2274 switch (YYSETJMP (yystack
.yyexception_buffer
))
2277 case 1: goto yyabortlab
;
2278 case 2: goto yyexhaustedlab
;
2279 default: goto yybuglab
;
2281 yyglrShift (&yystack
, 0, 0, 0, &yylval
]b4_locations_if([, &yylloc
])[);
2286 /* For efficiency, we have two loops, the first of which is
2287 specialized to deterministic operation (single stack, no
2288 potential ambiguity). */
2294 const short int* yyconflicts
;
2296 yyStateNum yystate
= yystack
.yytops
.yystates
[0]->yylrState
;
2297 YYDPRINTF ((stderr
, "Entering state %d\n", yystate
));
2298 if (yystate
== YYFINAL
)
2300 if (yyisDefaultedState (yystate
))
2302 yyrule
= yydefaultAction (yystate
);
2305 ]b4_locations_if([[ yystack
.yyerror_range
[1].yystate
.yyloc
= yylloc
;]])[
2306 yyreportSyntaxError (&yystack
]b4_user_args
[);
2309 YYCHK1 (yyglrReduce (&yystack
, 0, yyrule
, yytrue
]b4_user_args
[));
2314 if (yychar
== YYEMPTY
)
2316 YYDPRINTF ((stderr
, "Reading a token: "));
2320 if (yychar
<= YYEOF
)
2322 yychar
= yytoken
= YYEOF
;
2323 YYDPRINTF ((stderr
, "Now at end of input.\n"));
2327 yytoken
= YYTRANSLATE (yychar
);
2328 YY_SYMBOL_PRINT ("Next token is", yytoken
, &yylval
, &yylloc
);
2331 yygetLRActions (yystate
, yytoken
, &yyaction
, &yyconflicts
);
2332 if (*yyconflicts
!= 0)
2334 if (yyisShiftAction (yyaction
))
2336 YY_SYMBOL_PRINT ("Shifting", yytoken
, &yylval
, &yylloc
);
2339 yyglrShift (&yystack
, 0, yyaction
, yyposn
, &yylval
]b4_locations_if([, &yylloc
])[);
2340 if (0 < yystack
.yyerrState
)
2341 yystack
.yyerrState
-= 1;
2343 else if (yyisErrorAction (yyaction
))
2345 ]b4_locations_if([[ yystack
.yyerror_range
[1].yystate
.yyloc
= yylloc
;]])[
2346 yyreportSyntaxError (&yystack
]b4_user_args
[);
2350 YYCHK1 (yyglrReduce (&yystack
, 0, -yyaction
, yytrue
]b4_user_args
[));
2356 yySymbol yytoken_to_shift
;
2359 for (yys
= 0; yys
< yystack
.yytops
.yysize
; yys
+= 1)
2360 yystackp
->yytops
.yylookaheadNeeds
[yys
] = yychar
!= YYEMPTY
;
2362 /* yyprocessOneStack returns one of three things:
2364 - An error flag. If the caller is yyprocessOneStack, it
2365 immediately returns as well. When the caller is finally
2366 yyparse, it jumps to an error label via YYCHK1.
2368 - yyok, but yyprocessOneStack has invoked yymarkStackDeleted
2369 (&yystack, yys), which sets the top state of yys to NULL. Thus,
2370 yyparse's following invocation of yyremoveDeletes will remove
2373 - yyok, when ready to shift a token.
2375 Except in the first case, yyparse will invoke yyremoveDeletes and
2376 then shift the next token onto all remaining stacks. This
2377 synchronization of the shift (that is, after all preceding
2378 reductions on all stacks) helps prevent double destructor calls
2379 on yylval in the event of memory exhaustion. */
2381 for (yys
= 0; yys
< yystack
.yytops
.yysize
; yys
+= 1)
2382 YYCHK1 (yyprocessOneStack (&yystack
, yys
, yyposn
]b4_lpure_args
[));
2383 yyremoveDeletes (&yystack
);
2384 if (yystack
.yytops
.yysize
== 0)
2386 yyundeleteLastStack (&yystack
);
2387 if (yystack
.yytops
.yysize
== 0)
2388 yyFail (&yystack
][]b4_lpure_args
[, YY_("syntax error"));
2389 YYCHK1 (yyresolveStack (&yystack
]b4_user_args
[));
2390 YYDPRINTF ((stderr
, "Returning to deterministic operation.\n"));
2391 ]b4_locations_if([[ yystack
.yyerror_range
[1].yystate
.yyloc
= yylloc
;]])[
2392 yyreportSyntaxError (&yystack
]b4_user_args
[);
2396 /* If any yyglrShift call fails, it will fail after shifting. Thus,
2397 a copy of yylval will already be on stack 0 in the event of a
2398 failure in the following loop. Thus, yychar is set to YYEMPTY
2399 before the loop to make sure the user destructor for yylval isn't
2401 yytoken_to_shift
= YYTRANSLATE (yychar
);
2404 for (yys
= 0; yys
< yystack
.yytops
.yysize
; yys
+= 1)
2407 const short int* yyconflicts
;
2408 yyStateNum yystate
= yystack
.yytops
.yystates
[yys
]->yylrState
;
2409 yygetLRActions (yystate
, yytoken_to_shift
, &yyaction
,
2411 /* Note that yyconflicts were handled by yyprocessOneStack. */
2412 YYDPRINTF ((stderr
, "On stack %lu, ", (unsigned long int) yys
));
2413 YY_SYMBOL_PRINT ("shifting", yytoken_to_shift
, &yylval
, &yylloc
);
2414 yyglrShift (&yystack
, yys
, yyaction
, yyposn
,
2415 &yylval
]b4_locations_if([, &yylloc
])[);
2416 YYDPRINTF ((stderr
, "Stack %lu now in state #%d\n",
2417 (unsigned long int) yys
,
2418 yystack
.yytops
.yystates
[yys
]->yylrState
));
2421 if (yystack
.yytops
.yysize
== 1)
2423 YYCHK1 (yyresolveStack (&yystack
]b4_user_args
[));
2424 YYDPRINTF ((stderr
, "Returning to deterministic operation.\n"));
2425 yycompressStack (&yystack
);
2431 yyrecoverSyntaxError (&yystack
]b4_user_args
[);
2432 yyposn
= yystack
.yytops
.yystates
[0]->yyposn
;
2448 yyerror (]b4_lyyerror_args
[YY_("memory exhausted"));
2453 if (yychar
!= YYEMPTY
)
2454 yydestruct ("Cleanup: discarding lookahead",
2455 YYTRANSLATE (yychar
), &yylval
]b4_locuser_args([&yylloc
])[);
2457 /* If the stack is well-formed, pop the stack until it is empty,
2458 destroying its entries as we go. But free the stack regardless
2459 of whether it is well-formed. */
2460 if (yystack
.yyitems
)
2462 yyGLRState
** yystates
= yystack
.yytops
.yystates
;
2465 size_t yysize
= yystack
.yytops
.yysize
;
2467 for (yyk
= 0; yyk
< yysize
; yyk
+= 1)
2470 while (yystates
[yyk
])
2472 yyGLRState
*yys
= yystates
[yyk
];
2473 ]b4_locations_if([[ yystack
.yyerror_range
[1].yystate
.yyloc
= yys
->yyloc
;]]
2474 )[ if (yys
->yypred
!= YY_NULL
)
2475 yydestroyGLRState ("Cleanup: popping", yys
]b4_user_args
[);
2476 yystates
[yyk
] = yys
->yypred
;
2477 yystack
.yynextFree
-= 1;
2478 yystack
.yyspaceLeft
+= 1;
2483 yyfreeGLRStack (&yystack
);
2489 /* DEBUGGING ONLY */
2490 #if ]b4_api_PREFIX[DEBUG
2492 yy_yypstack (yyGLRState
* yys
)
2496 yy_yypstack (yys
->yypred
);
2497 YYFPRINTF (stderr
, " -> ");
2499 YYFPRINTF (stderr
, "%d@@%lu", yys
->yylrState
,
2500 (unsigned long int) yys
->yyposn
);
2504 yypstates (yyGLRState
* yyst
)
2506 if (yyst
== YY_NULL
)
2507 YYFPRINTF (stderr
, "<null>");
2510 YYFPRINTF (stderr
, "\n");
2514 yypstack (yyGLRStack
* yystackp
, size_t yyk
)
2516 yypstates (yystackp
->yytops
.yystates
[yyk
]);
2519 #define YYINDEX(YYX) \
2520 ((YYX) == YY_NULL ? -1 : (yyGLRStackItem*) (YYX) - yystackp->yyitems)
2524 yypdumpstack (yyGLRStack
* yystackp
)
2526 yyGLRStackItem
* yyp
;
2528 for (yyp
= yystackp
->yyitems
; yyp
< yystackp
->yynextFree
; yyp
+= 1)
2530 YYFPRINTF (stderr
, "%3lu. ",
2531 (unsigned long int) (yyp
- yystackp
->yyitems
));
2532 if (*(yybool
*) yyp
)
2534 YYFPRINTF (stderr
, "Res: %d, LR State: %d, posn: %lu, pred: %ld",
2535 yyp
->yystate
.yyresolved
, yyp
->yystate
.yylrState
,
2536 (unsigned long int) yyp
->yystate
.yyposn
,
2537 (long int) YYINDEX (yyp
->yystate
.yypred
));
2538 if (! yyp
->yystate
.yyresolved
)
2539 YYFPRINTF (stderr
, ", firstVal: %ld",
2540 (long int) YYINDEX (yyp
->yystate
2541 .yysemantics
.yyfirstVal
));
2545 YYFPRINTF (stderr
, "Option. rule: %d, state: %ld, next: %ld",
2546 yyp
->yyoption
.yyrule
- 1,
2547 (long int) YYINDEX (yyp
->yyoption
.yystate
),
2548 (long int) YYINDEX (yyp
->yyoption
.yynext
));
2550 YYFPRINTF (stderr
, "\n");
2552 YYFPRINTF (stderr
, "Tops:");
2553 for (yyi
= 0; yyi
< yystackp
->yytops
.yysize
; yyi
+= 1)
2554 YYFPRINTF (stderr
, "%lu: %ld; ", (unsigned long int) yyi
,
2555 (long int) YYINDEX (yystackp
->yytops
.yystates
[yyi
]));
2556 YYFPRINTF (stderr
, "\n");
2562 # glr.cc produces its own header.
2563 m4_if(b4_skeleton
, ["glr.c"],
2565 [b4_output_begin([b4_spec_defines_file
])
2566 b4_copyright([Skeleton interface
for Bison GLR parsers in C
],
2569 ]b4_cpp_guard_open([b4_spec_defines_file
])[
2570 ]b4_shared_declarations
[
2571 ]b4_cpp_guard_close([b4_spec_defines_file
])[