3 # GLR skeleton for Bison
5 # Copyright (C) 2002-2012 Free Software Foundation, Inc.
7 # This program is free software: you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License as published by
9 # the Free Software Foundation, either version 3 of the License, or
10 # (at your option) any later version.
12 # This program is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
17 # You should have received a copy of the GNU General Public License
18 # along with this program. If not, see <http://www.gnu.org/licenses/>.
21 # If we are loaded by glr.cc, do not override c++.m4 definitions by
23 m4_if(b4_skeleton
, ["glr.c"],
24 [m4_include(b4_pkgdatadir
/[c
.m4
])])
26 ## ---------------- ##
28 ## ---------------- ##
31 m4_define_default([b4_stack_depth_max
], [10000])
32 m4_define_default([b4_stack_depth_init
], [200])
36 ## ------------------------ ##
37 ## Pure/impure interfaces. ##
38 ## ------------------------ ##
40 b4_define_flag_if([pure
])
41 # If glr.cc is including this file and thus has already set b4_pure_flag,
42 # do not change the value of b4_pure_flag, and do not record a use of api.pure.
43 m4_ifndef([b4_pure_flag
],
44 [b4_percent_define_default([[api
.pure
]], [[false]])
45 m4_define([b4_pure_flag
],
46 [b4_percent_define_flag_if([[api
.pure
]], [[1]], [[0]])])])
50 # The possible parse-params formal arguments preceded by a comma.
52 # This is not shared with yacc.c in c.m4 because GLR relies on ISO C
53 # formal argument declarations.
54 m4_define([b4_user_formals
],
55 [m4_ifset([b4_parse_param
], [, b4_c_ansi_formals(b4_parse_param
)])])
60 # Accumule in b4_lex_param all the yylex arguments.
61 # Yes, this is quite ugly...
62 m4_define([b4_lex_param
],
63 m4_dquote(b4_pure_if([[[[YYSTYPE
*]], [[&yylval
]]][]dnl
64 b4_locations_if([, [[YYLTYPE
*], [&yylloc
]]])])dnl
65 m4_ifdef([b4_lex_param
], [, ]b4_lex_param
)))
70 # Optional effective arguments passed to yyerror: user args plus yylloc, and
72 m4_define([b4_yyerror_args
],
73 [b4_pure_if([b4_locations_if([yylocp
, ])])dnl
74 m4_ifset([b4_parse_param
], [b4_c_args(b4_parse_param
), ])])
79 # Same as above, but on the lookahead, hence &yylloc instead of yylocp.
80 m4_define([b4_lyyerror_args
],
81 [b4_pure_if([b4_locations_if([&yylloc
, ])])dnl
82 m4_ifset([b4_parse_param
], [b4_c_args(b4_parse_param
), ])])
87 # Same as b4_yyerror_args, but with a leading comma.
88 m4_define([b4_pure_args
],
89 [b4_pure_if([b4_locations_if([, yylocp
])])[]b4_user_args
])
94 # Same as above, but on the lookahead, hence &yylloc instead of yylocp.
95 m4_define([b4_lpure_args
],
96 [b4_pure_if([b4_locations_if([, &yylloc
])])[]b4_user_args
])
102 # Arguments passed to yyerror: user formals plus yylocp with leading comma.
103 m4_define([b4_pure_formals
],
104 [b4_pure_if([b4_locations_if([, YYLTYPE
*yylocp
])])[]b4_user_formals
])
107 # b4_locuser_formals(LOC = yylocp)
108 # --------------------------------
109 m4_define([b4_locuser_formals
],
110 [b4_locations_if([, YYLTYPE
*m4_default([$
1], [yylocp
])])[]b4_user_formals
])
113 # b4_locuser_args(LOC = yylocp)
114 # -----------------------------
115 m4_define([b4_locuser_args
],
116 [b4_locations_if([, m4_default([$
1], [yylocp
])])[]b4_user_args
])
120 ## ----------------- ##
121 ## Semantic Values. ##
122 ## ----------------- ##
125 # b4_lhs_value([TYPE])
126 # --------------------
127 # Expansion of $<TYPE>$.
128 m4_define([b4_lhs_value
],
129 [((*yyvalp
)[]m4_ifval([$
1], [.$
1]))])
132 # b4_rhs_value(RULE-LENGTH, NUM, [TYPE])
133 # --------------------------------------
134 # Expansion of $<TYPE>NUM, where the current rule has RULE-LENGTH
136 m4_define([b4_rhs_value
],
137 [(((yyGLRStackItem
const *)yyvsp
)@
{YYFILL (($
2) - ($
1))@
}.yystate
.yysemantics
.yysval
[]m4_ifval([$
3], [.$
3]))])
148 m4_define([b4_lhs_location
],
152 # b4_rhs_location(RULE-LENGTH, NUM)
153 # ---------------------------------
154 # Expansion of @NUM, where the current rule has RULE-LENGTH symbols
156 m4_define([b4_rhs_location
],
157 [(((yyGLRStackItem
const *)yyvsp
)@
{YYFILL (($
2) - ($
1))@
}.yystate
.yyloc
)])
164 # b4_shared_declarations
165 # ----------------------
166 # Declaration that might either go into the header (if --defines)
167 # or open coded in the parser body.
168 m4_define([b4_shared_declarations
],
170 ]b4_percent_code_get([[requires]])[
171 ]b4_token_enums(b4_tokens
)[
172 ]b4_declare_yylstype
[
173 ]b4_c_ansi_function_decl(b4_prefix
[parse
], [int], b4_parse_param
)[
174 ]b4_percent_code_get([[provides]])[]dnl
182 # We do want M4 expansion after # for CPP macros.
185 @
output(b4_parser_file_name@
)@
186 b4_copyright([Skeleton implementation
for Bison GLR parsers in C
],
189 /* C GLR parser skeleton written by Paul Hilfinger. */
193 b4_percent_code_get([[top]])[
194 ]m4_if(b4_api_prefix
, [yy
], [],
195 [[/* Substitute the type names. */
196 #define YYSTYPE ]b4_api_PREFIX[STYPE]b4_locations_if([[
197 #define YYLTYPE ]b4_api_PREFIX[LTYPE]])])[
198 ]m4_if(b4_prefix
, [yy
], [],
199 [[/* Substitute the variable and function names. */
200 #define yyparse ]b4_prefix[parse
201 #define yylex ]b4_prefix[lex
202 #define yyerror ]b4_prefix[error
203 #define yylval ]b4_prefix[lval
204 #define yychar ]b4_prefix[char
205 #define yydebug ]b4_prefix[debug
206 #define yynerrs ]b4_prefix[nerrs]b4_locations_if([[
207 #define yylloc ]b4_prefix[lloc]])])[
209 /* Copy the first part of user declarations. */
210 ]b4_user_pre_prologue
[
214 ]b4_defines_if([[#include "@basename(]b4_spec_defines_file[@)"]],
215 [b4_shared_declarations
])[
217 /* Enabling verbose error messages. */
218 #ifdef YYERROR_VERBOSE
219 # undef YYERROR_VERBOSE
220 # define YYERROR_VERBOSE 1
222 # define YYERROR_VERBOSE ]b4_error_verbose_flag[
225 /* Default (constant) value used for initialization for null
226 right-hand sides. Unlike the standard yacc.c template, here we set
227 the default value of $$ to a zeroed-out value. Since the default
228 value is undefined, this behavior is technically correct. */
229 static YYSTYPE yyval_default
;]b4_locations_if([[
230 static YYLTYPE yyloc_default
][]b4_yyloc_default
;])[
232 /* Copy the second part of user declarations. */
233 ]b4_user_post_prologue
234 b4_percent_code_get
[]dnl
241 # if defined YYENABLE_NLS && YYENABLE_NLS
243 # include <libintl.h> /* INFRINGES ON USER NAME SPACE */
244 # define YY_(Msgid) dgettext ("bison-runtime", Msgid)
248 # define YY_(Msgid) Msgid
252 /* Suppress unused-variable warnings by "using" E. */
253 #if ! defined lint || defined __GNUC__
254 # define YYUSE(E) ((void) (E))
256 # define YYUSE(E) /* empty */
259 /* Identity function, used to suppress warnings about constant conditions. */
263 ]b4_c_function_def([YYID
], [static int], [[int i
], [i
]])[
273 # define YYMALLOC malloc
276 # define YYREALLOC realloc
279 #define YYSIZEMAX ((size_t) -1)
284 typedef unsigned char yybool
;
291 # define YYJMP_BUF jmp_buf
292 # define YYSETJMP(Env) setjmp (Env)
294 # define YYLONGJMP(Env, Val) (longjmp (Env, Val), YYASSERT (0))
301 #ifndef __attribute__
302 /* This feature is available in gcc versions 2.5 and later. */
303 # if (! defined __GNUC__ || __GNUC__ < 2 \
304 || (__GNUC__ == 2 && __GNUC_MINOR__ < 5))
305 # define __attribute__(Spec) /* empty */
309 ]b4_locations_if([#define YYOPTIONAL_LOC(Name) Name],[
311 # define YYOPTIONAL_LOC(Name) /* empty */
313 # define YYOPTIONAL_LOC(Name) Name __attribute__ ((__unused__))
317 # define YYASSERT(Condition) ((void) ((Condition) || (abort (), 0)))
320 /* YYFINAL -- State number of the termination state. */
321 #define YYFINAL ]b4_final_state_number[
322 /* YYLAST -- Last index in YYTABLE. */
323 #define YYLAST ]b4_last[
325 /* YYNTOKENS -- Number of terminals. */
326 #define YYNTOKENS ]b4_tokens_number[
327 /* YYNNTS -- Number of nonterminals. */
328 #define YYNNTS ]b4_nterms_number[
329 /* YYNRULES -- Number of rules. */
330 #define YYNRULES ]b4_rules_number[
331 /* YYNRULES -- Number of states. */
332 #define YYNSTATES ]b4_states_number[
333 /* YYMAXRHS -- Maximum number of symbols on right-hand side of rule. */
334 #define YYMAXRHS ]b4_r2_max[
335 /* YYMAXLEFT -- Maximum number of symbols to the left of a handle
336 accessed by $0, $-1, etc., in any rule. */
337 #define YYMAXLEFT ]b4_max_left_semantic_context[
339 /* YYTRANSLATE(X) -- Bison symbol number corresponding to X. */
340 #define YYUNDEFTOK ]b4_undef_token_number[
341 #define YYMAXUTOK ]b4_user_token_number_max[
343 #define YYTRANSLATE(YYX) \
344 ((unsigned int) (YYX) <= YYMAXUTOK ? yytranslate[YYX] : YYUNDEFTOK)
346 /* YYTRANSLATE[YYLEX] -- Bison symbol number corresponding to YYLEX. */
347 static const ]b4_int_type_for([b4_translate
])[ yytranslate
[] =
352 #if ]b4_api_PREFIX[DEBUG
353 /* YYPRHS[YYN] -- Index of the first RHS symbol of rule number YYN in
355 static const ]b4_int_type_for([b4_prhs
])[ yyprhs
[] =
360 /* YYRHS -- A `-1'-separated list of the rules' RHS. */
361 static const ]b4_int_type_for([b4_rhs
])[ yyrhs
[] =
366 /* YYRLINE[YYN] -- source line where rule number YYN was defined. */
367 static const ]b4_int_type_for([b4_rline
])[ yyrline
[] =
373 #if ]b4_api_PREFIX[DEBUG || YYERROR_VERBOSE || ]b4_token_table_flag[
374 /* YYTNAME[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM.
375 First, the terminals, then, starting at YYNTOKENS, nonterminals. */
376 static const char *const yytname
[] =
382 /* YYR1[YYN] -- Symbol number of symbol that rule YYN derives. */
383 static const ]b4_int_type_for([b4_r1
])[ yyr1
[] =
388 /* YYR2[YYN] -- Number of symbols composing right hand side of rule YYN. */
389 static const ]b4_int_type_for([b4_r2
])[ yyr2
[] =
394 /* YYDPREC[RULE-NUM] -- Dynamic precedence of rule #RULE-NUM (0 if none). */
395 static const ]b4_int_type_for([b4_dprec
])[ yydprec
[] =
400 /* YYMERGER[RULE-NUM] -- Index of merging function for rule #RULE-NUM. */
401 static const ]b4_int_type_for([b4_merger
])[ yymerger
[] =
406 /* YYDEFACT[S] -- default reduction number in state S. Performed when
407 YYTABLE doesn't specify something else to do. Zero means the default
409 static const ]b4_int_type_for([b4_defact
])[ yydefact
[] =
414 /* YYPDEFGOTO[NTERM-NUM]. */
415 static const ]b4_int_type_for([b4_defgoto
])[ yydefgoto
[] =
420 /* YYPACT[STATE-NUM] -- Index in YYTABLE of the portion describing
422 #define YYPACT_NINF ]b4_pact_ninf[
423 static const ]b4_int_type_for([b4_pact
])[ yypact
[] =
428 /* YYPGOTO[NTERM-NUM]. */
429 static const ]b4_int_type_for([b4_pgoto
])[ yypgoto
[] =
434 /* YYTABLE[YYPACT[STATE-NUM]]. What to do in state STATE-NUM. If
435 positive, shift that token. If negative, reduce the rule which
436 number is the opposite. If YYTABLE_NINF, syntax error. */
437 #define YYTABLE_NINF ]b4_table_ninf[
438 static const ]b4_int_type_for([b4_table
])[ yytable
[] =
443 /* YYCONFLP[YYPACT[STATE-NUM]] -- Pointer into YYCONFL of start of
444 list of conflicting reductions corresponding to action entry for
445 state STATE-NUM in yytable. 0 means no conflicts. The list in
446 yyconfl is terminated by a rule number of 0. */
447 static const ]b4_int_type_for([b4_conflict_list_heads
])[ yyconflp
[] =
449 ]b4_conflict_list_heads
[
452 /* YYCONFL[I] -- lists of conflicting rule numbers, each terminated by
453 0, pointed into by YYCONFLP. */
454 ]dnl Do
not use b4_int_type_for here
, since there are places where
455 dnl pointers onto yyconfl are taken
, which type is
"short int *".
456 dnl We probably ought to introduce a type
for confl
.
457 [static const short int yyconfl
[] =
459 ]b4_conflicting_rules
[
462 static const ]b4_int_type_for([b4_check
])[ yycheck
[] =
467 /* YYSTOS[STATE-NUM] -- The (internal number of the) accessing
468 symbol of state STATE-NUM. */
469 static const ]b4_int_type_for([b4_stos
])[ yystos
[] =
474 /* Error token number */
478 ]b4_yylloc_default_define
[
479 # define YYRHSLOC(Rhs, K) ((Rhs)[K].yystate.yyloc)
481 ]b4_yy_location_print_define
[
483 /* YYLEX -- calling `yylex' with the right arguments. */
484 #define YYLEX ]b4_c_function_call([yylex], [int], b4_lex_param)[
489 #define yynerrs (yystackp->yyerrcnt)
491 #define yychar (yystackp->yyrawchar)
493 #define yylval (yystackp->yyval)
495 #define yylloc (yystackp->yyloc)
496 m4_if(b4_prefix
[], [yy
], [],
497 [#define b4_prefix[]nerrs yynerrs
498 #define b4_prefix[]char yychar
499 #define b4_prefix[]lval yylval
500 #define b4_prefix[]lloc yylloc])],
501 [YYSTYPE yylval
;]b4_locations_if([[
507 static const int YYEOF
= 0;
508 static const int YYEMPTY
= -2;
510 typedef enum { yyok
, yyaccept
, yyabort
, yyerr
} YYRESULTTAG
;
513 do { YYRESULTTAG yyflag = YYE; if (yyflag != yyok) return yyflag; } \
516 #if ]b4_api_PREFIX[DEBUG
519 # define YYFPRINTF fprintf
522 # define YYDPRINTF(Args) \
528 ]b4_yy_symbol_print_generate([b4_c_ansi_function_def
])[
530 # define YY_SYMBOL_PRINT(Title, Type, Value, Location) \
534 YYFPRINTF (stderr, "%s ", Title); \
535 yy_symbol_print (stderr, Type, Value]b4_locuser_args([Location])[); \
536 YYFPRINTF (stderr, "\n"); \
540 /* Nonzero means print parse trace. It is left uninitialized so that
541 multiple parsers can coexist. */
544 #else /* !]b4_api_PREFIX[DEBUG */
546 # define YYDPRINTF(Args)
547 # define YY_SYMBOL_PRINT(Title, Type, Value, Location)
549 #endif /* !]b4_api_PREFIX[DEBUG */
551 /* YYINITDEPTH -- initial size of the parser's stacks. */
553 # define YYINITDEPTH ]b4_stack_depth_init[
556 /* YYMAXDEPTH -- maximum size the stacks can grow to (effective only
557 if the built-in stack extension method is used).
559 Do not make this value too large; the results are undefined if
560 SIZE_MAX < YYMAXDEPTH * sizeof (GLRStackItem)
561 evaluated with infinite-precision integer arithmetic. */
564 # define YYMAXDEPTH ]b4_stack_depth_max[
567 /* Minimum number of free items on the stack allowed after an
568 allocation. This is to allow allocation and initialization
569 to be completed by functions that call yyexpandGLRStack before the
570 stack is expanded, thus insuring that all necessary pointers get
571 properly redirected to new data. */
574 #ifndef YYSTACKEXPANDABLE
575 # if (! defined __cplusplus \
576 || (]b4_locations_if([[defined ]b4_api_PREFIX[LTYPE_IS_TRIVIAL && ]b4_api_PREFIX[LTYPE_IS_TRIVIAL \
577 && ]])[defined ]b4_api_PREFIX[STYPE_IS_TRIVIAL && ]b4_api_PREFIX[STYPE_IS_TRIVIAL))
578 # define YYSTACKEXPANDABLE 1
580 # define YYSTACKEXPANDABLE 0
584 #if YYSTACKEXPANDABLE
585 # define YY_RESERVE_GLRSTACK(Yystack) \
587 if (Yystack->yyspaceLeft < YYHEADROOM) \
588 yyexpandGLRStack (Yystack); \
591 # define YY_RESERVE_GLRSTACK(Yystack) \
593 if (Yystack->yyspaceLeft < YYHEADROOM) \
594 yyMemoryExhausted (Yystack); \
602 # if defined __GLIBC__ && defined _STRING_H && defined _GNU_SOURCE
603 # define yystpcpy stpcpy
605 /* Copy YYSRC to YYDEST, returning the address of the terminating '\0' in
608 yystpcpy (char *yydest
, const char *yysrc
)
611 const char *yys
= yysrc
;
613 while ((*yyd
++ = *yys
++) != '\0')
622 /* Copy to YYRES the contents of YYSTR after stripping away unnecessary
623 quotes and backslashes, so that it's suitable for yyerror. The
624 heuristic is that double-quoting is unnecessary unless the string
625 contains an apostrophe, a comma, or backslash (other than
626 backslash-backslash). YYSTR is taken from yytname. If YYRES is
627 null, do not copy; instead, return the length of what the result
630 yytnamerr (char *yyres
, const char *yystr
)
635 char const *yyp
= yystr
;
642 goto do_not_strip_quotes
;
646 goto do_not_strip_quotes
;
659 do_not_strip_quotes
: ;
663 return strlen (yystr
);
665 return yystpcpy (yyres
, yystr
) - yyres
;
669 #endif /* !YYERROR_VERBOSE */
671 /** State numbers, as in LALR(1) machine */
672 typedef int yyStateNum
;
674 /** Rule numbers, as in LALR(1) machine */
675 typedef int yyRuleNum
;
677 /** Grammar symbol */
678 typedef short int yySymbol
;
680 /** Item references, as in LALR(1) machine */
681 typedef short int yyItemNum
;
683 typedef struct yyGLRState yyGLRState
;
684 typedef struct yyGLRStateSet yyGLRStateSet
;
685 typedef struct yySemanticOption yySemanticOption
;
686 typedef union yyGLRStackItem yyGLRStackItem
;
687 typedef struct yyGLRStack yyGLRStack
;
690 /** Type tag: always true. */
692 /** Type tag for yysemantics. If true, yysval applies, otherwise
693 * yyfirstVal applies. */
695 /** Number of corresponding LALR(1) machine state. */
696 yyStateNum yylrState
;
697 /** Preceding state in this stack */
699 /** Source position of the first token produced by my symbol */
702 /** First in a chain of alternative reductions producing the
703 * non-terminal corresponding to this state, threaded through
705 yySemanticOption
* yyfirstVal
;
706 /** Semantic value for this state. */
708 } yysemantics
;]b4_locations_if([[
709 /** Source location for this state. */
713 struct yyGLRStateSet
{
714 yyGLRState
** yystates
;
715 /** During nondeterministic operation, yylookaheadNeeds tracks which
716 * stacks have actually needed the current lookahead. During deterministic
717 * operation, yylookaheadNeeds[0] is not maintained since it would merely
718 * duplicate yychar != YYEMPTY. */
719 yybool
* yylookaheadNeeds
;
720 size_t yysize
, yycapacity
;
723 struct yySemanticOption
{
724 /** Type tag: always false. */
726 /** Rule number for this reduction */
728 /** The last RHS state in the list of states to be reduced. */
730 /** The lookahead for this reduction. */
732 YYSTYPE yyval
;]b4_locations_if([[
734 /** Next sibling in chain of options. To facilitate merging,
735 * options are chained in decreasing order by address. */
736 yySemanticOption
* yynext
;
739 /** Type of the items in the GLR stack. The yyisState field
740 * indicates which item of the union is valid. */
741 union yyGLRStackItem
{
743 yySemanticOption yyoption
;
748 ]b4_locations_if([[ /* To compute the location of the error token. */
749 yyGLRStackItem yyerror_range
[3];]])[
754 YYSTYPE yyval
;]b4_locations_if([[
757 YYJMP_BUF yyexception_buffer
;
758 yyGLRStackItem
* yyitems
;
759 yyGLRStackItem
* yynextFree
;
761 yyGLRState
* yysplitPoint
;
762 yyGLRState
* yylastDeleted
;
763 yyGLRStateSet yytops
;
766 #if YYSTACKEXPANDABLE
767 static void yyexpandGLRStack (yyGLRStack
* yystackp
);
770 static void yyFail (yyGLRStack
* yystackp
]b4_pure_formals
[, const char* yymsg
)
771 __attribute__ ((__noreturn__
));
773 yyFail (yyGLRStack
* yystackp
]b4_pure_formals
[, const char* yymsg
)
775 if (yymsg
!= YY_NULL
)
776 yyerror (]b4_yyerror_args
[yymsg
);
777 YYLONGJMP (yystackp
->yyexception_buffer
, 1);
780 static void yyMemoryExhausted (yyGLRStack
* yystackp
)
781 __attribute__ ((__noreturn__
));
783 yyMemoryExhausted (yyGLRStack
* yystackp
)
785 YYLONGJMP (yystackp
->yyexception_buffer
, 2);
788 #if ]b4_api_PREFIX[DEBUG || YYERROR_VERBOSE
789 /** A printable representation of TOKEN. */
790 static inline const char*
791 yytokenName (yySymbol yytoken
)
793 if (yytoken
== YYEMPTY
)
796 return yytname
[yytoken
];
800 /** Fill in YYVSP[YYLOW1 .. YYLOW0-1] from the chain of states starting
801 * at YYVSP[YYLOW0].yystate.yypred. Leaves YYVSP[YYLOW1].yystate.yypred
802 * containing the pointer to the next state in the chain. */
803 static void yyfillin (yyGLRStackItem
*, int, int) __attribute__ ((__unused__
));
805 yyfillin (yyGLRStackItem
*yyvsp
, int yylow0
, int yylow1
)
808 yyGLRState
*s
= yyvsp
[yylow0
].yystate
.yypred
;
809 for (i
= yylow0
-1; i
>= yylow1
; i
-= 1)
811 YYASSERT (s
->yyresolved
);
812 yyvsp
[i
].yystate
.yyresolved
= yytrue
;
813 yyvsp
[i
].yystate
.yysemantics
.yysval
= s
->yysemantics
.yysval
;]b4_locations_if([[
814 yyvsp
[i
].yystate
.yyloc
= s
->yyloc
;]])[
815 s
= yyvsp
[i
].yystate
.yypred
= s
->yypred
;
819 /* Do nothing if YYNORMAL or if *YYLOW <= YYLOW1. Otherwise, fill in
820 * YYVSP[YYLOW1 .. *YYLOW-1] as in yyfillin and set *YYLOW = YYLOW1.
821 * For convenience, always return YYLOW1. */
822 static inline int yyfill (yyGLRStackItem
*, int *, int, yybool
)
823 __attribute__ ((__unused__
));
825 yyfill (yyGLRStackItem
*yyvsp
, int *yylow
, int yylow1
, yybool yynormal
)
827 if (!yynormal
&& yylow1
< *yylow
)
829 yyfillin (yyvsp
, *yylow
, yylow1
);
835 /** Perform user action for rule number YYN, with RHS length YYRHSLEN,
836 * and top stack item YYVSP. YYLVALP points to place to put semantic
837 * value ($$), and yylocp points to place for location information
838 * (@@$). Returns yyok for normal return, yyaccept for YYACCEPT,
839 * yyerr for YYERROR, yyabort for YYABORT. */
840 /*ARGSUSED*/ static YYRESULTTAG
841 yyuserAction (yyRuleNum yyn
, int yyrhslen
, yyGLRStackItem
* yyvsp
,
842 yyGLRStack
* yystackp
,
843 YYSTYPE
* yyvalp
]b4_locuser_formals
[)
845 yybool yynormal
__attribute__ ((__unused__
)) =
846 (yystackp
->yysplitPoint
== YY_NULL
);
848 ]b4_parse_param_use
[]dnl
850 # define yyerrok (yystackp->yyerrState = 0)
852 # define YYACCEPT return yyaccept
854 # define YYABORT return yyabort
856 # define YYERROR return yyerrok, yyerr
858 # define YYRECOVERING() (yystackp->yyerrState != 0)
860 # define yyclearin (yychar = YYEMPTY)
862 # define YYFILL(N) yyfill (yyvsp, &yylow, N, yynormal)
864 # define YYBACKUP(Token, Value) \
865 return yyerror (]b4_yyerror_args[YY_("syntax error: cannot back up")), \
870 *yyvalp
= yyval_default
;
872 *yyvalp
= yyvsp
[YYFILL (1-yyrhslen
)].yystate
.yysemantics
.yysval
;]b4_locations_if([[
873 YYLLOC_DEFAULT ((*yylocp
), (yyvsp
- yyrhslen
), yyrhslen
);
874 yystackp
->yyerror_range
[1].yystate
.yyloc
= *yylocp
;
893 /*ARGSUSED*/ static void
894 yyuserMerge (int yyn
, YYSTYPE
* yy0
, YYSTYPE
* yy1
)
906 /* Bison grammar-table manipulation. */
908 ]b4_yydestruct_generate([b4_c_ansi_function_def
])[
910 /** Number of symbols composing the right hand side of rule #RULE. */
912 yyrhsLength (yyRuleNum yyrule
)
918 yydestroyGLRState (char const *yymsg
, yyGLRState
*yys
]b4_user_formals
[)
921 yydestruct (yymsg
, yystos
[yys
->yylrState
],
922 &yys
->yysemantics
.yysval
]b4_locuser_args([&yys
->yyloc
])[);
925 #if ]b4_api_PREFIX[DEBUG
928 if (yys
->yysemantics
.yyfirstVal
)
929 YYFPRINTF (stderr
, "%s unresolved ", yymsg
);
931 YYFPRINTF (stderr
, "%s incomplete ", yymsg
);
932 yy_symbol_print (stderr
, yystos
[yys
->yylrState
],
933 YY_NULL
]b4_locuser_args([&yys
->yyloc
])[);
934 YYFPRINTF (stderr
, "\n");
938 if (yys
->yysemantics
.yyfirstVal
)
940 yySemanticOption
*yyoption
= yys
->yysemantics
.yyfirstVal
;
943 for (yyrh
= yyoption
->yystate
, yyn
= yyrhsLength (yyoption
->yyrule
);
945 yyrh
= yyrh
->yypred
, yyn
-= 1)
946 yydestroyGLRState (yymsg
, yyrh
]b4_user_args
[);
951 /** Left-hand-side symbol for rule #RULE. */
952 static inline yySymbol
953 yylhsNonterm (yyRuleNum yyrule
)
958 #define yypact_value_is_default(Yystate) \
959 ]b4_table_value_equals([[pact]], [[Yystate]], [b4_pact_ninf])[
961 /** True iff LR state STATE has only a default reduction (regardless
964 yyisDefaultedState (yyStateNum yystate
)
966 return yypact_value_is_default (yypact
[yystate
]);
969 /** The default reduction for STATE, assuming it has one. */
970 static inline yyRuleNum
971 yydefaultAction (yyStateNum yystate
)
973 return yydefact
[yystate
];
976 #define yytable_value_is_error(Yytable_value) \
977 ]b4_table_value_equals([[table]], [[Yytable_value]], [b4_table_ninf])[
979 /** Set *YYACTION to the action to take in YYSTATE on seeing YYTOKEN.
981 * R < 0: Reduce on rule -R.
983 * R > 0: Shift to state R.
984 * Set *CONFLICTS to a pointer into yyconfl to 0-terminated list of
985 * conflicting reductions.
988 yygetLRActions (yyStateNum yystate
, int yytoken
,
989 int* yyaction
, const short int** yyconflicts
)
991 int yyindex
= yypact
[yystate
] + yytoken
;
992 if (yypact_value_is_default (yypact
[yystate
])
993 || yyindex
< 0 || YYLAST
< yyindex
|| yycheck
[yyindex
] != yytoken
)
995 *yyaction
= -yydefact
[yystate
];
996 *yyconflicts
= yyconfl
;
998 else if (! yytable_value_is_error (yytable
[yyindex
]))
1000 *yyaction
= yytable
[yyindex
];
1001 *yyconflicts
= yyconfl
+ yyconflp
[yyindex
];
1006 *yyconflicts
= yyconfl
+ yyconflp
[yyindex
];
1010 static inline yyStateNum
1011 yyLRgotoState (yyStateNum yystate
, yySymbol yylhs
)
1014 yyr
= yypgoto
[yylhs
- YYNTOKENS
] + yystate
;
1015 if (0 <= yyr
&& yyr
<= YYLAST
&& yycheck
[yyr
] == yystate
)
1016 return yytable
[yyr
];
1018 return yydefgoto
[yylhs
- YYNTOKENS
];
1021 static inline yybool
1022 yyisShiftAction (int yyaction
)
1024 return 0 < yyaction
;
1027 static inline yybool
1028 yyisErrorAction (int yyaction
)
1030 return yyaction
== 0;
1035 /** Return a fresh GLRStackItem. Callers should call
1036 * YY_RESERVE_GLRSTACK afterwards to make sure there is sufficient
1039 static inline yyGLRStackItem
*
1040 yynewGLRStackItem (yyGLRStack
* yystackp
, yybool yyisState
)
1042 yyGLRStackItem
* yynewItem
= yystackp
->yynextFree
;
1043 yystackp
->yyspaceLeft
-= 1;
1044 yystackp
->yynextFree
+= 1;
1045 yynewItem
->yystate
.yyisState
= yyisState
;
1049 /** Add a new semantic action that will execute the action for rule
1050 * RULENUM on the semantic values in RHS to the list of
1051 * alternative actions for STATE. Assumes that RHS comes from
1052 * stack #K of *STACKP. */
1054 yyaddDeferredAction (yyGLRStack
* yystackp
, size_t yyk
, yyGLRState
* yystate
,
1055 yyGLRState
* rhs
, yyRuleNum yyrule
)
1057 yySemanticOption
* yynewOption
=
1058 &yynewGLRStackItem (yystackp
, yyfalse
)->yyoption
;
1059 yynewOption
->yystate
= rhs
;
1060 yynewOption
->yyrule
= yyrule
;
1061 if (yystackp
->yytops
.yylookaheadNeeds
[yyk
])
1063 yynewOption
->yyrawchar
= yychar
;
1064 yynewOption
->yyval
= yylval
;]b4_locations_if([
1065 yynewOption
->yyloc
= yylloc
;])[
1068 yynewOption
->yyrawchar
= YYEMPTY
;
1069 yynewOption
->yynext
= yystate
->yysemantics
.yyfirstVal
;
1070 yystate
->yysemantics
.yyfirstVal
= yynewOption
;
1072 YY_RESERVE_GLRSTACK (yystackp
);
1077 /** Initialize SET to a singleton set containing an empty stack. */
1079 yyinitStateSet (yyGLRStateSet
* yyset
)
1082 yyset
->yycapacity
= 16;
1083 yyset
->yystates
= (yyGLRState
**) YYMALLOC (16 * sizeof yyset
->yystates
[0]);
1084 if (! yyset
->yystates
)
1086 yyset
->yystates
[0] = YY_NULL
;
1087 yyset
->yylookaheadNeeds
=
1088 (yybool
*) YYMALLOC (16 * sizeof yyset
->yylookaheadNeeds
[0]);
1089 if (! yyset
->yylookaheadNeeds
)
1091 YYFREE (yyset
->yystates
);
1097 static void yyfreeStateSet (yyGLRStateSet
* yyset
)
1099 YYFREE (yyset
->yystates
);
1100 YYFREE (yyset
->yylookaheadNeeds
);
1103 /** Initialize STACK to a single empty stack, with total maximum
1104 * capacity for all stacks of SIZE. */
1106 yyinitGLRStack (yyGLRStack
* yystackp
, size_t yysize
)
1108 yystackp
->yyerrState
= 0;
1110 yystackp
->yyspaceLeft
= yysize
;
1112 (yyGLRStackItem
*) YYMALLOC (yysize
* sizeof yystackp
->yynextFree
[0]);
1113 if (!yystackp
->yyitems
)
1115 yystackp
->yynextFree
= yystackp
->yyitems
;
1116 yystackp
->yysplitPoint
= YY_NULL
;
1117 yystackp
->yylastDeleted
= YY_NULL
;
1118 return yyinitStateSet (&yystackp
->yytops
);
1122 #if YYSTACKEXPANDABLE
1123 # define YYRELOC(YYFROMITEMS,YYTOITEMS,YYX,YYTYPE) \
1124 &((YYTOITEMS) - ((YYFROMITEMS) - (yyGLRStackItem*) (YYX)))->YYTYPE
1126 /** If STACK is expandable, extend it. WARNING: Pointers into the
1127 stack from outside should be considered invalid after this call.
1128 We always expand when there are 1 or fewer items left AFTER an
1129 allocation, so that we can avoid having external pointers exist
1130 across an allocation. */
1132 yyexpandGLRStack (yyGLRStack
* yystackp
)
1134 yyGLRStackItem
* yynewItems
;
1135 yyGLRStackItem
* yyp0
, *yyp1
;
1138 size_t yysize
= yystackp
->yynextFree
- yystackp
->yyitems
;
1139 if (YYMAXDEPTH
- YYHEADROOM
< yysize
)
1140 yyMemoryExhausted (yystackp
);
1141 yynewSize
= 2*yysize
;
1142 if (YYMAXDEPTH
< yynewSize
)
1143 yynewSize
= YYMAXDEPTH
;
1144 yynewItems
= (yyGLRStackItem
*) YYMALLOC (yynewSize
* sizeof yynewItems
[0]);
1146 yyMemoryExhausted (yystackp
);
1147 for (yyp0
= yystackp
->yyitems
, yyp1
= yynewItems
, yyn
= yysize
;
1149 yyn
-= 1, yyp0
+= 1, yyp1
+= 1)
1152 if (*(yybool
*) yyp0
)
1154 yyGLRState
* yys0
= &yyp0
->yystate
;
1155 yyGLRState
* yys1
= &yyp1
->yystate
;
1156 if (yys0
->yypred
!= YY_NULL
)
1158 YYRELOC (yyp0
, yyp1
, yys0
->yypred
, yystate
);
1159 if (! yys0
->yyresolved
&& yys0
->yysemantics
.yyfirstVal
!= YY_NULL
)
1160 yys1
->yysemantics
.yyfirstVal
=
1161 YYRELOC (yyp0
, yyp1
, yys0
->yysemantics
.yyfirstVal
, yyoption
);
1165 yySemanticOption
* yyv0
= &yyp0
->yyoption
;
1166 yySemanticOption
* yyv1
= &yyp1
->yyoption
;
1167 if (yyv0
->yystate
!= YY_NULL
)
1168 yyv1
->yystate
= YYRELOC (yyp0
, yyp1
, yyv0
->yystate
, yystate
);
1169 if (yyv0
->yynext
!= YY_NULL
)
1170 yyv1
->yynext
= YYRELOC (yyp0
, yyp1
, yyv0
->yynext
, yyoption
);
1173 if (yystackp
->yysplitPoint
!= YY_NULL
)
1174 yystackp
->yysplitPoint
= YYRELOC (yystackp
->yyitems
, yynewItems
,
1175 yystackp
->yysplitPoint
, yystate
);
1177 for (yyn
= 0; yyn
< yystackp
->yytops
.yysize
; yyn
+= 1)
1178 if (yystackp
->yytops
.yystates
[yyn
] != YY_NULL
)
1179 yystackp
->yytops
.yystates
[yyn
] =
1180 YYRELOC (yystackp
->yyitems
, yynewItems
,
1181 yystackp
->yytops
.yystates
[yyn
], yystate
);
1182 YYFREE (yystackp
->yyitems
);
1183 yystackp
->yyitems
= yynewItems
;
1184 yystackp
->yynextFree
= yynewItems
+ yysize
;
1185 yystackp
->yyspaceLeft
= yynewSize
- yysize
;
1190 yyfreeGLRStack (yyGLRStack
* yystackp
)
1192 YYFREE (yystackp
->yyitems
);
1193 yyfreeStateSet (&yystackp
->yytops
);
1196 /** Assuming that S is a GLRState somewhere on STACK, update the
1197 * splitpoint of STACK, if needed, so that it is at least as deep as
1200 yyupdateSplit (yyGLRStack
* yystackp
, yyGLRState
* yys
)
1202 if (yystackp
->yysplitPoint
!= YY_NULL
&& yystackp
->yysplitPoint
> yys
)
1203 yystackp
->yysplitPoint
= yys
;
1206 /** Invalidate stack #K in STACK. */
1208 yymarkStackDeleted (yyGLRStack
* yystackp
, size_t yyk
)
1210 if (yystackp
->yytops
.yystates
[yyk
] != YY_NULL
)
1211 yystackp
->yylastDeleted
= yystackp
->yytops
.yystates
[yyk
];
1212 yystackp
->yytops
.yystates
[yyk
] = YY_NULL
;
1215 /** Undelete the last stack that was marked as deleted. Can only be
1216 done once after a deletion, and only when all other stacks have
1219 yyundeleteLastStack (yyGLRStack
* yystackp
)
1221 if (yystackp
->yylastDeleted
== YY_NULL
|| yystackp
->yytops
.yysize
!= 0)
1223 yystackp
->yytops
.yystates
[0] = yystackp
->yylastDeleted
;
1224 yystackp
->yytops
.yysize
= 1;
1225 YYDPRINTF ((stderr
, "Restoring last deleted stack as stack #0.\n"));
1226 yystackp
->yylastDeleted
= YY_NULL
;
1230 yyremoveDeletes (yyGLRStack
* yystackp
)
1234 while (yyj
< yystackp
->yytops
.yysize
)
1236 if (yystackp
->yytops
.yystates
[yyi
] == YY_NULL
)
1240 YYDPRINTF ((stderr
, "Removing dead stacks.\n"));
1242 yystackp
->yytops
.yysize
-= 1;
1246 yystackp
->yytops
.yystates
[yyj
] = yystackp
->yytops
.yystates
[yyi
];
1247 /* In the current implementation, it's unnecessary to copy
1248 yystackp->yytops.yylookaheadNeeds[yyi] since, after
1249 yyremoveDeletes returns, the parser immediately either enters
1250 deterministic operation or shifts a token. However, it doesn't
1251 hurt, and the code might evolve to need it. */
1252 yystackp
->yytops
.yylookaheadNeeds
[yyj
] =
1253 yystackp
->yytops
.yylookaheadNeeds
[yyi
];
1256 YYDPRINTF ((stderr
, "Rename stack %lu -> %lu.\n",
1257 (unsigned long int) yyi
, (unsigned long int) yyj
));
1265 /** Shift to a new state on stack #K of STACK, corresponding to LR state
1266 * LRSTATE, at input position POSN, with (resolved) semantic value SVAL. */
1268 yyglrShift (yyGLRStack
* yystackp
, size_t yyk
, yyStateNum yylrState
,
1270 YYSTYPE
* yyvalp
]b4_locations_if([, YYLTYPE
* yylocp
])[)
1272 yyGLRState
* yynewState
= &yynewGLRStackItem (yystackp
, yytrue
)->yystate
;
1274 yynewState
->yylrState
= yylrState
;
1275 yynewState
->yyposn
= yyposn
;
1276 yynewState
->yyresolved
= yytrue
;
1277 yynewState
->yypred
= yystackp
->yytops
.yystates
[yyk
];
1278 yynewState
->yysemantics
.yysval
= *yyvalp
;]b4_locations_if([
1279 yynewState
->yyloc
= *yylocp
;])[
1280 yystackp
->yytops
.yystates
[yyk
] = yynewState
;
1282 YY_RESERVE_GLRSTACK (yystackp
);
1285 /** Shift stack #K of YYSTACK, to a new state corresponding to LR
1286 * state YYLRSTATE, at input position YYPOSN, with the (unresolved)
1287 * semantic value of YYRHS under the action for YYRULE. */
1289 yyglrShiftDefer (yyGLRStack
* yystackp
, size_t yyk
, yyStateNum yylrState
,
1290 size_t yyposn
, yyGLRState
* rhs
, yyRuleNum yyrule
)
1292 yyGLRState
* yynewState
= &yynewGLRStackItem (yystackp
, yytrue
)->yystate
;
1294 yynewState
->yylrState
= yylrState
;
1295 yynewState
->yyposn
= yyposn
;
1296 yynewState
->yyresolved
= yyfalse
;
1297 yynewState
->yypred
= yystackp
->yytops
.yystates
[yyk
];
1298 yynewState
->yysemantics
.yyfirstVal
= YY_NULL
;
1299 yystackp
->yytops
.yystates
[yyk
] = yynewState
;
1301 /* Invokes YY_RESERVE_GLRSTACK. */
1302 yyaddDeferredAction (yystackp
, yyk
, yynewState
, rhs
, yyrule
);
1305 /** Pop the symbols consumed by reduction #RULE from the top of stack
1306 * #K of STACK, and perform the appropriate semantic action on their
1307 * semantic values. Assumes that all ambiguities in semantic values
1308 * have been previously resolved. Set *VALP to the resulting value,
1309 * and *LOCP to the computed location (if any). Return value is as
1310 * for userAction. */
1311 static inline YYRESULTTAG
1312 yydoAction (yyGLRStack
* yystackp
, size_t yyk
, yyRuleNum yyrule
,
1313 YYSTYPE
* yyvalp
]b4_locuser_formals
[)
1315 int yynrhs
= yyrhsLength (yyrule
);
1317 if (yystackp
->yysplitPoint
== YY_NULL
)
1319 /* Standard special case: single stack. */
1320 yyGLRStackItem
* rhs
= (yyGLRStackItem
*) yystackp
->yytops
.yystates
[yyk
];
1321 YYASSERT (yyk
== 0);
1322 yystackp
->yynextFree
-= yynrhs
;
1323 yystackp
->yyspaceLeft
+= yynrhs
;
1324 yystackp
->yytops
.yystates
[0] = & yystackp
->yynextFree
[-1].yystate
;
1325 return yyuserAction (yyrule
, yynrhs
, rhs
, yystackp
,
1326 yyvalp
]b4_locuser_args
[);
1330 /* At present, doAction is never called in nondeterministic
1331 * mode, so this branch is never taken. It is here in
1332 * anticipation of a future feature that will allow immediate
1333 * evaluation of selected actions in nondeterministic mode. */
1336 yyGLRStackItem yyrhsVals
[YYMAXRHS
+ YYMAXLEFT
+ 1];
1337 yys
= yyrhsVals
[YYMAXRHS
+ YYMAXLEFT
].yystate
.yypred
1338 = yystackp
->yytops
.yystates
[yyk
];]b4_locations_if([[
1340 /* Set default location. */
1341 yyrhsVals
[YYMAXRHS
+ YYMAXLEFT
- 1].yystate
.yyloc
= yys
->yyloc
;]])[
1342 for (yyi
= 0; yyi
< yynrhs
; yyi
+= 1)
1347 yyupdateSplit (yystackp
, yys
);
1348 yystackp
->yytops
.yystates
[yyk
] = yys
;
1349 return yyuserAction (yyrule
, yynrhs
, yyrhsVals
+ YYMAXRHS
+ YYMAXLEFT
- 1,
1350 yystackp
, yyvalp
]b4_locuser_args
[);
1354 #if !]b4_api_PREFIX[DEBUG
1355 # define YY_REDUCE_PRINT(Args)
1357 # define YY_REDUCE_PRINT(Args) \
1360 yy_reduce_print Args; \
1363 /*----------------------------------------------------------.
1364 | Report that the RULE is going to be reduced on stack #K. |
1365 `----------------------------------------------------------*/
1367 /*ARGSUSED*/ static inline void
1368 yy_reduce_print (yyGLRStack
* yystackp
, size_t yyk
, yyRuleNum yyrule
,
1369 YYSTYPE
* yyvalp
]b4_locuser_formals
[)
1371 int yynrhs
= yyrhsLength (yyrule
);
1372 yybool yynormal
__attribute__ ((__unused__
)) =
1373 (yystackp
->yysplitPoint
== YY_NULL
);
1374 yyGLRStackItem
* yyvsp
= (yyGLRStackItem
*) yystackp
->yytops
.yystates
[yyk
];
1377 YYUSE (yyvalp
);]b4_locations_if([
1379 ]b4_parse_param_use
[]dnl
1380 [ YYFPRINTF (stderr
, "Reducing stack %lu by rule %d (line %lu):\n",
1381 (unsigned long int) yyk
, yyrule
- 1,
1382 (unsigned long int) yyrline
[yyrule
]);
1383 /* The symbols being reduced. */
1384 for (yyi
= 0; yyi
< yynrhs
; yyi
++)
1386 YYFPRINTF (stderr
, " $%d = ", yyi
+ 1);
1387 yy_symbol_print (stderr
, yyrhs
[yyprhs
[yyrule
] + yyi
],
1388 &]b4_rhs_value(yynrhs
, yyi
+ 1)[
1389 ]b4_locations_if([, &]b4_rhs_location(yynrhs
, yyi
+ 1))[]dnl
1391 YYFPRINTF (stderr
, "\n");
1396 /** Pop items off stack #K of STACK according to grammar rule RULE,
1397 * and push back on the resulting nonterminal symbol. Perform the
1398 * semantic action associated with RULE and store its value with the
1399 * newly pushed state, if FORCEEVAL or if STACK is currently
1400 * unambiguous. Otherwise, store the deferred semantic action with
1401 * the new state. If the new state would have an identical input
1402 * position, LR state, and predecessor to an existing state on the stack,
1403 * it is identified with that existing state, eliminating stack #K from
1404 * the STACK. In this case, the (necessarily deferred) semantic value is
1405 * added to the options for the existing state's semantic value.
1407 static inline YYRESULTTAG
1408 yyglrReduce (yyGLRStack
* yystackp
, size_t yyk
, yyRuleNum yyrule
,
1409 yybool yyforceEval
]b4_user_formals
[)
1411 size_t yyposn
= yystackp
->yytops
.yystates
[yyk
]->yyposn
;
1413 if (yyforceEval
|| yystackp
->yysplitPoint
== YY_NULL
)
1415 YYSTYPE yysval
;]b4_locations_if([
1418 YY_REDUCE_PRINT ((yystackp
, yyk
, yyrule
, &yysval
]b4_locuser_args([&yyloc
])[));
1419 YYCHK (yydoAction (yystackp
, yyk
, yyrule
, &yysval
]b4_locuser_args([&yyloc
])[));
1420 YY_SYMBOL_PRINT ("-> $$ =", yyr1
[yyrule
], &yysval
, &yyloc
);
1421 yyglrShift (yystackp
, yyk
,
1422 yyLRgotoState (yystackp
->yytops
.yystates
[yyk
]->yylrState
,
1423 yylhsNonterm (yyrule
)),
1424 yyposn
, &yysval
]b4_locations_if([, &yyloc
])[);
1430 yyGLRState
* yys
, *yys0
= yystackp
->yytops
.yystates
[yyk
];
1431 yyStateNum yynewLRState
;
1433 for (yys
= yystackp
->yytops
.yystates
[yyk
], yyn
= yyrhsLength (yyrule
);
1439 yyupdateSplit (yystackp
, yys
);
1440 yynewLRState
= yyLRgotoState (yys
->yylrState
, yylhsNonterm (yyrule
));
1442 "Reduced stack %lu by rule #%d; action deferred. Now in state %d.\n",
1443 (unsigned long int) yyk
, yyrule
- 1, yynewLRState
));
1444 for (yyi
= 0; yyi
< yystackp
->yytops
.yysize
; yyi
+= 1)
1445 if (yyi
!= yyk
&& yystackp
->yytops
.yystates
[yyi
] != YY_NULL
)
1447 yyGLRState
*yysplit
= yystackp
->yysplitPoint
;
1448 yyGLRState
*yyp
= yystackp
->yytops
.yystates
[yyi
];
1449 while (yyp
!= yys
&& yyp
!= yysplit
&& yyp
->yyposn
>= yyposn
)
1451 if (yyp
->yylrState
== yynewLRState
&& yyp
->yypred
== yys
)
1453 yyaddDeferredAction (yystackp
, yyk
, yyp
, yys0
, yyrule
);
1454 yymarkStackDeleted (yystackp
, yyk
);
1455 YYDPRINTF ((stderr
, "Merging stack %lu into stack %lu.\n",
1456 (unsigned long int) yyk
,
1457 (unsigned long int) yyi
));
1463 yystackp
->yytops
.yystates
[yyk
] = yys
;
1464 yyglrShiftDefer (yystackp
, yyk
, yynewLRState
, yyposn
, yys0
, yyrule
);
1470 yysplitStack (yyGLRStack
* yystackp
, size_t yyk
)
1472 if (yystackp
->yysplitPoint
== YY_NULL
)
1474 YYASSERT (yyk
== 0);
1475 yystackp
->yysplitPoint
= yystackp
->yytops
.yystates
[yyk
];
1477 if (yystackp
->yytops
.yysize
>= yystackp
->yytops
.yycapacity
)
1479 yyGLRState
** yynewStates
;
1480 yybool
* yynewLookaheadNeeds
;
1482 yynewStates
= YY_NULL
;
1484 if (yystackp
->yytops
.yycapacity
1485 > (YYSIZEMAX
/ (2 * sizeof yynewStates
[0])))
1486 yyMemoryExhausted (yystackp
);
1487 yystackp
->yytops
.yycapacity
*= 2;
1490 (yyGLRState
**) YYREALLOC (yystackp
->yytops
.yystates
,
1491 (yystackp
->yytops
.yycapacity
1492 * sizeof yynewStates
[0]));
1493 if (yynewStates
== YY_NULL
)
1494 yyMemoryExhausted (yystackp
);
1495 yystackp
->yytops
.yystates
= yynewStates
;
1497 yynewLookaheadNeeds
=
1498 (yybool
*) YYREALLOC (yystackp
->yytops
.yylookaheadNeeds
,
1499 (yystackp
->yytops
.yycapacity
1500 * sizeof yynewLookaheadNeeds
[0]));
1501 if (yynewLookaheadNeeds
== YY_NULL
)
1502 yyMemoryExhausted (yystackp
);
1503 yystackp
->yytops
.yylookaheadNeeds
= yynewLookaheadNeeds
;
1505 yystackp
->yytops
.yystates
[yystackp
->yytops
.yysize
]
1506 = yystackp
->yytops
.yystates
[yyk
];
1507 yystackp
->yytops
.yylookaheadNeeds
[yystackp
->yytops
.yysize
]
1508 = yystackp
->yytops
.yylookaheadNeeds
[yyk
];
1509 yystackp
->yytops
.yysize
+= 1;
1510 return yystackp
->yytops
.yysize
-1;
1513 /** True iff Y0 and Y1 represent identical options at the top level.
1514 * That is, they represent the same rule applied to RHS symbols
1515 * that produce the same terminal symbols. */
1517 yyidenticalOptions (yySemanticOption
* yyy0
, yySemanticOption
* yyy1
)
1519 if (yyy0
->yyrule
== yyy1
->yyrule
)
1521 yyGLRState
*yys0
, *yys1
;
1523 for (yys0
= yyy0
->yystate
, yys1
= yyy1
->yystate
,
1524 yyn
= yyrhsLength (yyy0
->yyrule
);
1526 yys0
= yys0
->yypred
, yys1
= yys1
->yypred
, yyn
-= 1)
1527 if (yys0
->yyposn
!= yys1
->yyposn
)
1535 /** Assuming identicalOptions (Y0,Y1), destructively merge the
1536 * alternative semantic values for the RHS-symbols of Y1 and Y0. */
1538 yymergeOptionSets (yySemanticOption
* yyy0
, yySemanticOption
* yyy1
)
1540 yyGLRState
*yys0
, *yys1
;
1542 for (yys0
= yyy0
->yystate
, yys1
= yyy1
->yystate
,
1543 yyn
= yyrhsLength (yyy0
->yyrule
);
1545 yys0
= yys0
->yypred
, yys1
= yys1
->yypred
, yyn
-= 1)
1549 else if (yys0
->yyresolved
)
1551 yys1
->yyresolved
= yytrue
;
1552 yys1
->yysemantics
.yysval
= yys0
->yysemantics
.yysval
;
1554 else if (yys1
->yyresolved
)
1556 yys0
->yyresolved
= yytrue
;
1557 yys0
->yysemantics
.yysval
= yys1
->yysemantics
.yysval
;
1561 yySemanticOption
** yyz0p
= &yys0
->yysemantics
.yyfirstVal
;
1562 yySemanticOption
* yyz1
= yys1
->yysemantics
.yyfirstVal
;
1563 while (YYID (yytrue
))
1565 if (yyz1
== *yyz0p
|| yyz1
== YY_NULL
)
1567 else if (*yyz0p
== YY_NULL
)
1572 else if (*yyz0p
< yyz1
)
1574 yySemanticOption
* yyz
= *yyz0p
;
1576 yyz1
= yyz1
->yynext
;
1577 (*yyz0p
)->yynext
= yyz
;
1579 yyz0p
= &(*yyz0p
)->yynext
;
1581 yys1
->yysemantics
.yyfirstVal
= yys0
->yysemantics
.yyfirstVal
;
1586 /** Y0 and Y1 represent two possible actions to take in a given
1587 * parsing state; return 0 if no combination is possible,
1588 * 1 if user-mergeable, 2 if Y0 is preferred, 3 if Y1 is preferred. */
1590 yypreference (yySemanticOption
* y0
, yySemanticOption
* y1
)
1592 yyRuleNum r0
= y0
->yyrule
, r1
= y1
->yyrule
;
1593 int p0
= yydprec
[r0
], p1
= yydprec
[r1
];
1597 if (yymerger
[r0
] == 0 || yymerger
[r0
] != yymerger
[r1
])
1602 if (p0
== 0 || p1
== 0)
1611 static YYRESULTTAG
yyresolveValue (yyGLRState
* yys
,
1612 yyGLRStack
* yystackp
]b4_user_formals
[);
1615 /** Resolve the previous N states starting at and including state S. If result
1616 * != yyok, some states may have been left unresolved possibly with empty
1617 * semantic option chains. Regardless of whether result = yyok, each state
1618 * has been left with consistent data so that yydestroyGLRState can be invoked
1621 yyresolveStates (yyGLRState
* yys
, int yyn
,
1622 yyGLRStack
* yystackp
]b4_user_formals
[)
1626 YYASSERT (yys
->yypred
);
1627 YYCHK (yyresolveStates (yys
->yypred
, yyn
-1, yystackp
]b4_user_args
[));
1628 if (! yys
->yyresolved
)
1629 YYCHK (yyresolveValue (yys
, yystackp
]b4_user_args
[));
1634 /** Resolve the states for the RHS of OPT, perform its user action, and return
1635 * the semantic value and location. Regardless of whether result = yyok, all
1636 * RHS states have been destroyed (assuming the user action destroys all RHS
1637 * semantic values if invoked). */
1639 yyresolveAction (yySemanticOption
* yyopt
, yyGLRStack
* yystackp
,
1640 YYSTYPE
* yyvalp
]b4_locuser_formals
[)
1642 yyGLRStackItem yyrhsVals
[YYMAXRHS
+ YYMAXLEFT
+ 1];
1643 int yynrhs
= yyrhsLength (yyopt
->yyrule
);
1644 YYRESULTTAG yyflag
=
1645 yyresolveStates (yyopt
->yystate
, yynrhs
, yystackp
]b4_user_args
[);
1649 for (yys
= yyopt
->yystate
; yynrhs
> 0; yys
= yys
->yypred
, yynrhs
-= 1)
1650 yydestroyGLRState ("Cleanup: popping", yys
]b4_user_args
[);
1654 yyrhsVals
[YYMAXRHS
+ YYMAXLEFT
].yystate
.yypred
= yyopt
->yystate
;]b4_locations_if([[
1656 /* Set default location. */
1657 yyrhsVals
[YYMAXRHS
+ YYMAXLEFT
- 1].yystate
.yyloc
= yyopt
->yystate
->yyloc
;]])[
1659 int yychar_current
= yychar
;
1660 YYSTYPE yylval_current
= yylval
;]b4_locations_if([
1661 YYLTYPE yylloc_current
= yylloc
;])[
1662 yychar
= yyopt
->yyrawchar
;
1663 yylval
= yyopt
->yyval
;]b4_locations_if([
1664 yylloc
= yyopt
->yyloc
;])[
1665 yyflag
= yyuserAction (yyopt
->yyrule
, yynrhs
,
1666 yyrhsVals
+ YYMAXRHS
+ YYMAXLEFT
- 1,
1667 yystackp
, yyvalp
]b4_locuser_args
[);
1668 yychar
= yychar_current
;
1669 yylval
= yylval_current
;]b4_locations_if([
1670 yylloc
= yylloc_current
;])[
1675 #if ]b4_api_PREFIX[DEBUG
1677 yyreportTree (yySemanticOption
* yyx
, int yyindent
)
1679 int yynrhs
= yyrhsLength (yyx
->yyrule
);
1682 yyGLRState
* yystates
[1 + YYMAXRHS
];
1683 yyGLRState yyleftmost_state
;
1685 for (yyi
= yynrhs
, yys
= yyx
->yystate
; 0 < yyi
; yyi
-= 1, yys
= yys
->yypred
)
1686 yystates
[yyi
] = yys
;
1689 yyleftmost_state
.yyposn
= 0;
1690 yystates
[0] = &yyleftmost_state
;
1695 if (yyx
->yystate
->yyposn
< yys
->yyposn
+ 1)
1696 YYFPRINTF (stderr
, "%*s%s -> <Rule %d, empty>\n",
1697 yyindent
, "", yytokenName (yylhsNonterm (yyx
->yyrule
)),
1700 YYFPRINTF (stderr
, "%*s%s -> <Rule %d, tokens %lu .. %lu>\n",
1701 yyindent
, "", yytokenName (yylhsNonterm (yyx
->yyrule
)),
1702 yyx
->yyrule
- 1, (unsigned long int) (yys
->yyposn
+ 1),
1703 (unsigned long int) yyx
->yystate
->yyposn
);
1704 for (yyi
= 1; yyi
<= yynrhs
; yyi
+= 1)
1706 if (yystates
[yyi
]->yyresolved
)
1708 if (yystates
[yyi
-1]->yyposn
+1 > yystates
[yyi
]->yyposn
)
1709 YYFPRINTF (stderr
, "%*s%s <empty>\n", yyindent
+2, "",
1710 yytokenName (yyrhs
[yyprhs
[yyx
->yyrule
]+yyi
-1]));
1712 YYFPRINTF (stderr
, "%*s%s <tokens %lu .. %lu>\n", yyindent
+2, "",
1713 yytokenName (yyrhs
[yyprhs
[yyx
->yyrule
]+yyi
-1]),
1714 (unsigned long int) (yystates
[yyi
- 1]->yyposn
+ 1),
1715 (unsigned long int) yystates
[yyi
]->yyposn
);
1718 yyreportTree (yystates
[yyi
]->yysemantics
.yyfirstVal
, yyindent
+2);
1723 /*ARGSUSED*/ static YYRESULTTAG
1724 yyreportAmbiguity (yySemanticOption
* yyx0
,
1725 yySemanticOption
* yyx1
]b4_pure_formals
[)
1730 #if ]b4_api_PREFIX[DEBUG
1731 YYFPRINTF (stderr
, "Ambiguity detected.\n");
1732 YYFPRINTF (stderr
, "Option 1,\n");
1733 yyreportTree (yyx0
, 2);
1734 YYFPRINTF (stderr
, "\nOption 2,\n");
1735 yyreportTree (yyx1
, 2);
1736 YYFPRINTF (stderr
, "\n");
1739 yyerror (]b4_yyerror_args
[YY_("syntax is ambiguous"));
1741 }]b4_locations_if([[
1743 /** Starting at and including state S1, resolve the location for each of the
1744 * previous N1 states that is unresolved. The first semantic option of a state
1745 * is always chosen. */
1747 yyresolveLocations (yyGLRState
* yys1
, int yyn1
,
1748 yyGLRStack
*yystackp
]b4_user_formals
[)
1752 yyresolveLocations (yys1
->yypred
, yyn1
- 1, yystackp
]b4_user_args
[);
1753 if (!yys1
->yyresolved
)
1755 yyGLRStackItem yyrhsloc
[1 + YYMAXRHS
];
1757 yySemanticOption
*yyoption
= yys1
->yysemantics
.yyfirstVal
;
1758 YYASSERT (yyoption
!= YY_NULL
);
1759 yynrhs
= yyrhsLength (yyoption
->yyrule
);
1764 yyresolveLocations (yyoption
->yystate
, yynrhs
,
1765 yystackp
]b4_user_args
[);
1766 for (yys
= yyoption
->yystate
, yyn
= yynrhs
;
1768 yys
= yys
->yypred
, yyn
-= 1)
1769 yyrhsloc
[yyn
].yystate
.yyloc
= yys
->yyloc
;
1773 /* Both yyresolveAction and yyresolveLocations traverse the GSS
1774 in reverse rightmost order. It is only necessary to invoke
1775 yyresolveLocations on a subforest for which yyresolveAction
1776 would have been invoked next had an ambiguity not been
1777 detected. Thus the location of the previous state (but not
1778 necessarily the previous state itself) is guaranteed to be
1779 resolved already. */
1780 yyGLRState
*yyprevious
= yyoption
->yystate
;
1781 yyrhsloc
[0].yystate
.yyloc
= yyprevious
->yyloc
;
1784 int yychar_current
= yychar
;
1785 YYSTYPE yylval_current
= yylval
;
1786 YYLTYPE yylloc_current
= yylloc
;
1787 yychar
= yyoption
->yyrawchar
;
1788 yylval
= yyoption
->yyval
;
1789 yylloc
= yyoption
->yyloc
;
1790 YYLLOC_DEFAULT ((yys1
->yyloc
), yyrhsloc
, yynrhs
);
1791 yychar
= yychar_current
;
1792 yylval
= yylval_current
;
1793 yylloc
= yylloc_current
;
1799 /** Resolve the ambiguity represented in state S, perform the indicated
1800 * actions, and set the semantic value of S. If result != yyok, the chain of
1801 * semantic options in S has been cleared instead or it has been left
1802 * unmodified except that redundant options may have been removed. Regardless
1803 * of whether result = yyok, S has been left with consistent data so that
1804 * yydestroyGLRState can be invoked if necessary. */
1806 yyresolveValue (yyGLRState
* yys
, yyGLRStack
* yystackp
]b4_user_formals
[)
1808 yySemanticOption
* yyoptionList
= yys
->yysemantics
.yyfirstVal
;
1809 yySemanticOption
* yybest
= yyoptionList
;
1810 yySemanticOption
** yypp
;
1811 yybool yymerge
= yyfalse
;
1813 YYRESULTTAG yyflag
;]b4_locations_if([
1814 YYLTYPE
*yylocp
= &yys
->yyloc
;])[
1816 for (yypp
= &yyoptionList
->yynext
; *yypp
!= YY_NULL
; )
1818 yySemanticOption
* yyp
= *yypp
;
1820 if (yyidenticalOptions (yybest
, yyp
))
1822 yymergeOptionSets (yybest
, yyp
);
1823 *yypp
= yyp
->yynext
;
1827 switch (yypreference (yybest
, yyp
))
1829 case 0:]b4_locations_if([[
1830 yyresolveLocations (yys
, 1, yystackp
]b4_user_args
[);]])[
1831 return yyreportAmbiguity (yybest
, yyp
]b4_pure_args
[);
1843 /* This cannot happen so it is not worth a YYASSERT (yyfalse),
1844 but some compilers complain if the default case is
1848 yypp
= &yyp
->yynext
;
1854 yySemanticOption
* yyp
;
1855 int yyprec
= yydprec
[yybest
->yyrule
];
1856 yyflag
= yyresolveAction (yybest
, yystackp
, &yysval
]b4_locuser_args
[);
1858 for (yyp
= yybest
->yynext
; yyp
!= YY_NULL
; yyp
= yyp
->yynext
)
1860 if (yyprec
== yydprec
[yyp
->yyrule
])
1862 YYSTYPE yysval_other
;]b4_locations_if([
1864 yyflag
= yyresolveAction (yyp
, yystackp
, &yysval_other
]b4_locuser_args([&yydummy
])[);
1867 yydestruct ("Cleanup: discarding incompletely merged value for",
1868 yystos
[yys
->yylrState
],
1869 &yysval
]b4_locuser_args
[);
1872 yyuserMerge (yymerger
[yyp
->yyrule
], &yysval
, &yysval_other
);
1877 yyflag
= yyresolveAction (yybest
, yystackp
, &yysval
]b4_locuser_args([yylocp
])[);
1881 yys
->yyresolved
= yytrue
;
1882 yys
->yysemantics
.yysval
= yysval
;
1885 yys
->yysemantics
.yyfirstVal
= YY_NULL
;
1890 yyresolveStack (yyGLRStack
* yystackp
]b4_user_formals
[)
1892 if (yystackp
->yysplitPoint
!= YY_NULL
)
1897 for (yyn
= 0, yys
= yystackp
->yytops
.yystates
[0];
1898 yys
!= yystackp
->yysplitPoint
;
1899 yys
= yys
->yypred
, yyn
+= 1)
1901 YYCHK (yyresolveStates (yystackp
->yytops
.yystates
[0], yyn
, yystackp
1908 yycompressStack (yyGLRStack
* yystackp
)
1910 yyGLRState
* yyp
, *yyq
, *yyr
;
1912 if (yystackp
->yytops
.yysize
!= 1 || yystackp
->yysplitPoint
== YY_NULL
)
1915 for (yyp
= yystackp
->yytops
.yystates
[0], yyq
= yyp
->yypred
, yyr
= YY_NULL
;
1916 yyp
!= yystackp
->yysplitPoint
;
1917 yyr
= yyp
, yyp
= yyq
, yyq
= yyp
->yypred
)
1920 yystackp
->yyspaceLeft
+= yystackp
->yynextFree
- yystackp
->yyitems
;
1921 yystackp
->yynextFree
= ((yyGLRStackItem
*) yystackp
->yysplitPoint
) + 1;
1922 yystackp
->yyspaceLeft
-= yystackp
->yynextFree
- yystackp
->yyitems
;
1923 yystackp
->yysplitPoint
= YY_NULL
;
1924 yystackp
->yylastDeleted
= YY_NULL
;
1926 while (yyr
!= YY_NULL
)
1928 yystackp
->yynextFree
->yystate
= *yyr
;
1930 yystackp
->yynextFree
->yystate
.yypred
= &yystackp
->yynextFree
[-1].yystate
;
1931 yystackp
->yytops
.yystates
[0] = &yystackp
->yynextFree
->yystate
;
1932 yystackp
->yynextFree
+= 1;
1933 yystackp
->yyspaceLeft
-= 1;
1938 yyprocessOneStack (yyGLRStack
* yystackp
, size_t yyk
,
1939 size_t yyposn
]b4_pure_formals
[)
1942 const short int* yyconflicts
;
1945 while (yystackp
->yytops
.yystates
[yyk
] != YY_NULL
)
1947 yyStateNum yystate
= yystackp
->yytops
.yystates
[yyk
]->yylrState
;
1948 YYDPRINTF ((stderr
, "Stack %lu Entering state %d\n",
1949 (unsigned long int) yyk
, yystate
));
1951 YYASSERT (yystate
!= YYFINAL
);
1953 if (yyisDefaultedState (yystate
))
1955 yyrule
= yydefaultAction (yystate
);
1958 YYDPRINTF ((stderr
, "Stack %lu dies.\n",
1959 (unsigned long int) yyk
));
1960 yymarkStackDeleted (yystackp
, yyk
);
1963 YYCHK (yyglrReduce (yystackp
, yyk
, yyrule
, yyfalse
]b4_user_args
[));
1968 yystackp
->yytops
.yylookaheadNeeds
[yyk
] = yytrue
;
1969 if (yychar
== YYEMPTY
)
1971 YYDPRINTF ((stderr
, "Reading a token: "));
1975 if (yychar
<= YYEOF
)
1977 yychar
= yytoken
= YYEOF
;
1978 YYDPRINTF ((stderr
, "Now at end of input.\n"));
1982 yytoken
= YYTRANSLATE (yychar
);
1983 YY_SYMBOL_PRINT ("Next token is", yytoken
, &yylval
, &yylloc
);
1986 yygetLRActions (yystate
, yytoken
, &yyaction
, &yyconflicts
);
1988 while (*yyconflicts
!= 0)
1990 size_t yynewStack
= yysplitStack (yystackp
, yyk
);
1991 YYDPRINTF ((stderr
, "Splitting off stack %lu from %lu.\n",
1992 (unsigned long int) yynewStack
,
1993 (unsigned long int) yyk
));
1994 YYCHK (yyglrReduce (yystackp
, yynewStack
,
1995 *yyconflicts
, yyfalse
]b4_user_args
[));
1996 YYCHK (yyprocessOneStack (yystackp
, yynewStack
,
1997 yyposn
]b4_pure_args
[));
2001 if (yyisShiftAction (yyaction
))
2003 else if (yyisErrorAction (yyaction
))
2005 YYDPRINTF ((stderr
, "Stack %lu dies.\n",
2006 (unsigned long int) yyk
));
2007 yymarkStackDeleted (yystackp
, yyk
);
2011 YYCHK (yyglrReduce (yystackp
, yyk
, -yyaction
,
2012 yyfalse
]b4_user_args
[));
2018 /*ARGSUSED*/ static void
2019 yyreportSyntaxError (yyGLRStack
* yystackp
]b4_user_formals
[)
2021 if (yystackp
->yyerrState
!= 0)
2023 #if ! YYERROR_VERBOSE
2024 yyerror (]b4_lyyerror_args
[YY_("syntax error"));
2026 yySymbol yytoken
= yychar
== YYEMPTY
? YYEMPTY
: YYTRANSLATE (yychar
);
2027 size_t yysize0
= yytnamerr (YY_NULL
, yytokenName (yytoken
));
2028 size_t yysize
= yysize0
;
2030 yybool yysize_overflow
= yyfalse
;
2031 char* yymsg
= YY_NULL
;
2032 enum { YYERROR_VERBOSE_ARGS_MAXIMUM
= 5 };
2033 /* Internationalized format string. */
2034 const char *yyformat
= YY_NULL
;
2035 /* Arguments of yyformat. */
2036 char const *yyarg
[YYERROR_VERBOSE_ARGS_MAXIMUM
];
2037 /* Number of reported tokens (one for the "unexpected", one per
2041 /* There are many possibilities here to consider:
2042 - If this state is a consistent state with a default action, then
2043 the only way this function was invoked is if the default action
2044 is an error action. In that case, don't check for expected
2045 tokens because there are none.
2046 - The only way there can be no lookahead present (in yychar) is if
2047 this state is a consistent state with a default action. Thus,
2048 detecting the absence of a lookahead is sufficient to determine
2049 that there is no unexpected or expected token to report. In that
2050 case, just report a simple "syntax error".
2051 - Don't assume there isn't a lookahead just because this state is a
2052 consistent state with a default action. There might have been a
2053 previous inconsistent state, consistent state with a non-default
2054 action, or user semantic action that manipulated yychar.
2055 - Of course, the expected token list depends on states to have
2056 correct lookahead information, and it depends on the parser not
2057 to perform extra reductions after fetching a lookahead from the
2058 scanner and before detecting a syntax error. Thus, state merging
2059 (from LALR or IELR) and default reductions corrupt the expected
2060 token list. However, the list is correct for canonical LR with
2061 one exception: it will still contain any token that will not be
2062 accepted due to an error action in a later state.
2064 if (yytoken
!= YYEMPTY
)
2066 int yyn
= yypact
[yystackp
->yytops
.yystates
[0]->yylrState
];
2067 yyarg
[yycount
++] = yytokenName (yytoken
);
2068 if (!yypact_value_is_default (yyn
))
2070 /* Start YYX at -YYN if negative to avoid negative indexes in
2071 YYCHECK. In other words, skip the first -YYN actions for this
2072 state because they are default actions. */
2073 int yyxbegin
= yyn
< 0 ? -yyn
: 0;
2074 /* Stay within bounds of both yycheck and yytname. */
2075 int yychecklim
= YYLAST
- yyn
+ 1;
2076 int yyxend
= yychecklim
< YYNTOKENS
? yychecklim
: YYNTOKENS
;
2078 for (yyx
= yyxbegin
; yyx
< yyxend
; ++yyx
)
2079 if (yycheck
[yyx
+ yyn
] == yyx
&& yyx
!= YYTERROR
2080 && !yytable_value_is_error (yytable
[yyx
+ yyn
]))
2082 if (yycount
== YYERROR_VERBOSE_ARGS_MAXIMUM
)
2088 yyarg
[yycount
++] = yytokenName (yyx
);
2089 yysize1
= yysize
+ yytnamerr (YY_NULL
, yytokenName (yyx
));
2090 yysize_overflow
|= yysize1
< yysize
;
2098 #define YYCASE_(N, S) \
2102 YYCASE_(0, YY_("syntax error"));
2103 YYCASE_(1, YY_("syntax error, unexpected %s"));
2104 YYCASE_(2, YY_("syntax error, unexpected %s, expecting %s"));
2105 YYCASE_(3, YY_("syntax error, unexpected %s, expecting %s or %s"));
2106 YYCASE_(4, YY_("syntax error, unexpected %s, expecting %s or %s or %s"));
2107 YYCASE_(5, YY_("syntax error, unexpected %s, expecting %s or %s or %s or %s"));
2111 yysize1
= yysize
+ strlen (yyformat
);
2112 yysize_overflow
|= yysize1
< yysize
;
2115 if (!yysize_overflow
)
2116 yymsg
= (char *) YYMALLOC (yysize
);
2122 while ((*yyp
= *yyformat
))
2124 if (*yyp
== '%' && yyformat
[1] == 's' && yyi
< yycount
)
2126 yyp
+= yytnamerr (yyp
, yyarg
[yyi
++]);
2135 yyerror (]b4_lyyerror_args
[yymsg
);
2140 yyerror (]b4_lyyerror_args
[YY_("syntax error"));
2141 yyMemoryExhausted (yystackp
);
2143 #endif /* YYERROR_VERBOSE */
2147 /* Recover from a syntax error on *YYSTACKP, assuming that *YYSTACKP->YYTOKENP,
2148 yylval, and yylloc are the syntactic category, semantic value, and location
2149 of the lookahead. */
2150 /*ARGSUSED*/ static void
2151 yyrecoverSyntaxError (yyGLRStack
* yystackp
]b4_user_formals
[)
2156 if (yystackp
->yyerrState
== 3)
2157 /* We just shifted the error token and (perhaps) took some
2158 reductions. Skip tokens until we can proceed. */
2159 while (YYID (yytrue
))
2162 if (yychar
== YYEOF
)
2163 yyFail (yystackp
][]b4_lpure_args
[, YY_NULL
);
2164 if (yychar
!= YYEMPTY
)
2165 {]b4_locations_if([[
2166 /* We throw away the lookahead, but the error range
2167 of the shifted error token must take it into account. */
2168 yyGLRState
*yys
= yystackp
->yytops
.yystates
[0];
2169 yyGLRStackItem yyerror_range
[3];
2170 yyerror_range
[1].yystate
.yyloc
= yys
->yyloc
;
2171 yyerror_range
[2].yystate
.yyloc
= yylloc
;
2172 YYLLOC_DEFAULT ((yys
->yyloc
), yyerror_range
, 2);]])[
2173 yytoken
= YYTRANSLATE (yychar
);
2174 yydestruct ("Error: discarding",
2175 yytoken
, &yylval
]b4_locuser_args([&yylloc
])[);
2177 YYDPRINTF ((stderr
, "Reading a token: "));
2179 if (yychar
<= YYEOF
)
2181 yychar
= yytoken
= YYEOF
;
2182 YYDPRINTF ((stderr
, "Now at end of input.\n"));
2186 yytoken
= YYTRANSLATE (yychar
);
2187 YY_SYMBOL_PRINT ("Next token is", yytoken
, &yylval
, &yylloc
);
2189 yyj
= yypact
[yystackp
->yytops
.yystates
[0]->yylrState
];
2190 if (yypact_value_is_default (yyj
))
2193 if (yyj
< 0 || YYLAST
< yyj
|| yycheck
[yyj
] != yytoken
)
2195 if (yydefact
[yystackp
->yytops
.yystates
[0]->yylrState
] != 0)
2198 else if (! yytable_value_is_error (yytable
[yyj
]))
2202 /* Reduce to one stack. */
2203 for (yyk
= 0; yyk
< yystackp
->yytops
.yysize
; yyk
+= 1)
2204 if (yystackp
->yytops
.yystates
[yyk
] != YY_NULL
)
2206 if (yyk
>= yystackp
->yytops
.yysize
)
2207 yyFail (yystackp
][]b4_lpure_args
[, YY_NULL
);
2208 for (yyk
+= 1; yyk
< yystackp
->yytops
.yysize
; yyk
+= 1)
2209 yymarkStackDeleted (yystackp
, yyk
);
2210 yyremoveDeletes (yystackp
);
2211 yycompressStack (yystackp
);
2213 /* Now pop stack until we find a state that shifts the error token. */
2214 yystackp
->yyerrState
= 3;
2215 while (yystackp
->yytops
.yystates
[0] != YY_NULL
)
2217 yyGLRState
*yys
= yystackp
->yytops
.yystates
[0];
2218 yyj
= yypact
[yys
->yylrState
];
2219 if (! yypact_value_is_default (yyj
))
2222 if (0 <= yyj
&& yyj
<= YYLAST
&& yycheck
[yyj
] == YYTERROR
2223 && yyisShiftAction (yytable
[yyj
]))
2225 /* Shift the error token. */]b4_locations_if([[
2226 /* First adjust its location.*/
2228 yystackp
->yyerror_range
[2].yystate
.yyloc
= yylloc
;
2229 YYLLOC_DEFAULT (yyerrloc
, (yystackp
->yyerror_range
), 2);]])[
2230 YY_SYMBOL_PRINT ("Shifting", yystos
[yytable
[yyj
]],
2231 &yylval
, &yyerrloc
);
2232 yyglrShift (yystackp
, 0, yytable
[yyj
],
2233 yys
->yyposn
, &yylval
]b4_locations_if([, &yyerrloc
])[);
2234 yys
= yystackp
->yytops
.yystates
[0];
2237 }]b4_locations_if([[
2238 yystackp
->yyerror_range
[1].yystate
.yyloc
= yys
->yyloc
;]])[
2239 if (yys
->yypred
!= YY_NULL
)
2240 yydestroyGLRState ("Error: popping", yys
]b4_user_args
[);
2241 yystackp
->yytops
.yystates
[0] = yys
->yypred
;
2242 yystackp
->yynextFree
-= 1;
2243 yystackp
->yyspaceLeft
+= 1;
2245 if (yystackp
->yytops
.yystates
[0] == YY_NULL
)
2246 yyFail (yystackp
][]b4_lpure_args
[, YY_NULL
);
2249 #define YYCHK1(YYE) \
2259 goto yyuser_error; \
2270 ]b4_c_ansi_function_def([yyparse
], [int], b4_parse_param
)[
2274 yyGLRStack
* const yystackp
= &yystack
;
2277 YYDPRINTF ((stderr
, "Starting parse\n"));
2280 yylval
= yyval_default
;]b4_locations_if([
2281 yylloc
= yyloc_default
;])[
2282 ]m4_ifdef([b4_initial_action
], [
2283 b4_dollar_pushdef([yylval
], [], [yylloc
])dnl
2284 /* User initialization code. */
2285 b4_user_initial_action
2286 b4_dollar_popdef
])[]dnl
2288 if (! yyinitGLRStack (yystackp
, YYINITDEPTH
))
2289 goto yyexhaustedlab
;
2290 switch (YYSETJMP (yystack
.yyexception_buffer
))
2293 case 1: goto yyabortlab
;
2294 case 2: goto yyexhaustedlab
;
2295 default: goto yybuglab
;
2297 yyglrShift (&yystack
, 0, 0, 0, &yylval
]b4_locations_if([, &yylloc
])[);
2300 while (YYID (yytrue
))
2302 /* For efficiency, we have two loops, the first of which is
2303 specialized to deterministic operation (single stack, no
2304 potential ambiguity). */
2306 while (YYID (yytrue
))
2310 const short int* yyconflicts
;
2312 yyStateNum yystate
= yystack
.yytops
.yystates
[0]->yylrState
;
2313 YYDPRINTF ((stderr
, "Entering state %d\n", yystate
));
2314 if (yystate
== YYFINAL
)
2316 if (yyisDefaultedState (yystate
))
2318 yyrule
= yydefaultAction (yystate
);
2321 ]b4_locations_if([[ yystack
.yyerror_range
[1].yystate
.yyloc
= yylloc
;]])[
2322 yyreportSyntaxError (&yystack
]b4_user_args
[);
2325 YYCHK1 (yyglrReduce (&yystack
, 0, yyrule
, yytrue
]b4_user_args
[));
2330 if (yychar
== YYEMPTY
)
2332 YYDPRINTF ((stderr
, "Reading a token: "));
2336 if (yychar
<= YYEOF
)
2338 yychar
= yytoken
= YYEOF
;
2339 YYDPRINTF ((stderr
, "Now at end of input.\n"));
2343 yytoken
= YYTRANSLATE (yychar
);
2344 YY_SYMBOL_PRINT ("Next token is", yytoken
, &yylval
, &yylloc
);
2347 yygetLRActions (yystate
, yytoken
, &yyaction
, &yyconflicts
);
2348 if (*yyconflicts
!= 0)
2350 if (yyisShiftAction (yyaction
))
2352 YY_SYMBOL_PRINT ("Shifting", yytoken
, &yylval
, &yylloc
);
2355 yyglrShift (&yystack
, 0, yyaction
, yyposn
, &yylval
]b4_locations_if([, &yylloc
])[);
2356 if (0 < yystack
.yyerrState
)
2357 yystack
.yyerrState
-= 1;
2359 else if (yyisErrorAction (yyaction
))
2361 ]b4_locations_if([[ yystack
.yyerror_range
[1].yystate
.yyloc
= yylloc
;]])[
2362 yyreportSyntaxError (&yystack
]b4_user_args
[);
2366 YYCHK1 (yyglrReduce (&yystack
, 0, -yyaction
, yytrue
]b4_user_args
[));
2370 while (YYID (yytrue
))
2372 yySymbol yytoken_to_shift
;
2375 for (yys
= 0; yys
< yystack
.yytops
.yysize
; yys
+= 1)
2376 yystackp
->yytops
.yylookaheadNeeds
[yys
] = yychar
!= YYEMPTY
;
2378 /* yyprocessOneStack returns one of three things:
2380 - An error flag. If the caller is yyprocessOneStack, it
2381 immediately returns as well. When the caller is finally
2382 yyparse, it jumps to an error label via YYCHK1.
2384 - yyok, but yyprocessOneStack has invoked yymarkStackDeleted
2385 (&yystack, yys), which sets the top state of yys to NULL. Thus,
2386 yyparse's following invocation of yyremoveDeletes will remove
2389 - yyok, when ready to shift a token.
2391 Except in the first case, yyparse will invoke yyremoveDeletes and
2392 then shift the next token onto all remaining stacks. This
2393 synchronization of the shift (that is, after all preceding
2394 reductions on all stacks) helps prevent double destructor calls
2395 on yylval in the event of memory exhaustion. */
2397 for (yys
= 0; yys
< yystack
.yytops
.yysize
; yys
+= 1)
2398 YYCHK1 (yyprocessOneStack (&yystack
, yys
, yyposn
]b4_lpure_args
[));
2399 yyremoveDeletes (&yystack
);
2400 if (yystack
.yytops
.yysize
== 0)
2402 yyundeleteLastStack (&yystack
);
2403 if (yystack
.yytops
.yysize
== 0)
2404 yyFail (&yystack
][]b4_lpure_args
[, YY_("syntax error"));
2405 YYCHK1 (yyresolveStack (&yystack
]b4_user_args
[));
2406 YYDPRINTF ((stderr
, "Returning to deterministic operation.\n"));
2407 ]b4_locations_if([[ yystack
.yyerror_range
[1].yystate
.yyloc
= yylloc
;]])[
2408 yyreportSyntaxError (&yystack
]b4_user_args
[);
2412 /* If any yyglrShift call fails, it will fail after shifting. Thus,
2413 a copy of yylval will already be on stack 0 in the event of a
2414 failure in the following loop. Thus, yychar is set to YYEMPTY
2415 before the loop to make sure the user destructor for yylval isn't
2417 yytoken_to_shift
= YYTRANSLATE (yychar
);
2420 for (yys
= 0; yys
< yystack
.yytops
.yysize
; yys
+= 1)
2423 const short int* yyconflicts
;
2424 yyStateNum yystate
= yystack
.yytops
.yystates
[yys
]->yylrState
;
2425 yygetLRActions (yystate
, yytoken_to_shift
, &yyaction
,
2427 /* Note that yyconflicts were handled by yyprocessOneStack. */
2428 YYDPRINTF ((stderr
, "On stack %lu, ", (unsigned long int) yys
));
2429 YY_SYMBOL_PRINT ("shifting", yytoken_to_shift
, &yylval
, &yylloc
);
2430 yyglrShift (&yystack
, yys
, yyaction
, yyposn
,
2431 &yylval
]b4_locations_if([, &yylloc
])[);
2432 YYDPRINTF ((stderr
, "Stack %lu now in state #%d\n",
2433 (unsigned long int) yys
,
2434 yystack
.yytops
.yystates
[yys
]->yylrState
));
2437 if (yystack
.yytops
.yysize
== 1)
2439 YYCHK1 (yyresolveStack (&yystack
]b4_user_args
[));
2440 YYDPRINTF ((stderr
, "Returning to deterministic operation.\n"));
2441 yycompressStack (&yystack
);
2447 yyrecoverSyntaxError (&yystack
]b4_user_args
[);
2448 yyposn
= yystack
.yytops
.yystates
[0]->yyposn
;
2464 yyerror (]b4_lyyerror_args
[YY_("memory exhausted"));
2469 if (yychar
!= YYEMPTY
)
2470 yydestruct ("Cleanup: discarding lookahead",
2471 YYTRANSLATE (yychar
), &yylval
]b4_locuser_args([&yylloc
])[);
2473 /* If the stack is well-formed, pop the stack until it is empty,
2474 destroying its entries as we go. But free the stack regardless
2475 of whether it is well-formed. */
2476 if (yystack
.yyitems
)
2478 yyGLRState
** yystates
= yystack
.yytops
.yystates
;
2481 size_t yysize
= yystack
.yytops
.yysize
;
2483 for (yyk
= 0; yyk
< yysize
; yyk
+= 1)
2486 while (yystates
[yyk
])
2488 yyGLRState
*yys
= yystates
[yyk
];
2489 ]b4_locations_if([[ yystack
.yyerror_range
[1].yystate
.yyloc
= yys
->yyloc
;]]
2490 )[ if (yys
->yypred
!= YY_NULL
)
2491 yydestroyGLRState ("Cleanup: popping", yys
]b4_user_args
[);
2492 yystates
[yyk
] = yys
->yypred
;
2493 yystack
.yynextFree
-= 1;
2494 yystack
.yyspaceLeft
+= 1;
2499 yyfreeGLRStack (&yystack
);
2502 /* Make sure YYID is used. */
2503 return YYID (yyresult
);
2506 /* DEBUGGING ONLY */
2507 #if ]b4_api_PREFIX[DEBUG
2508 static void yypstack (yyGLRStack
* yystackp
, size_t yyk
)
2509 __attribute__ ((__unused__
));
2510 static void yypdumpstack (yyGLRStack
* yystackp
) __attribute__ ((__unused__
));
2513 yy_yypstack (yyGLRState
* yys
)
2517 yy_yypstack (yys
->yypred
);
2518 YYFPRINTF (stderr
, " -> ");
2520 YYFPRINTF (stderr
, "%d@@%lu", yys
->yylrState
,
2521 (unsigned long int) yys
->yyposn
);
2525 yypstates (yyGLRState
* yyst
)
2527 if (yyst
== YY_NULL
)
2528 YYFPRINTF (stderr
, "<null>");
2531 YYFPRINTF (stderr
, "\n");
2535 yypstack (yyGLRStack
* yystackp
, size_t yyk
)
2537 yypstates (yystackp
->yytops
.yystates
[yyk
]);
2540 #define YYINDEX(YYX) \
2541 ((YYX) == YY_NULL ? -1 : (yyGLRStackItem*) (YYX) - yystackp->yyitems)
2545 yypdumpstack (yyGLRStack
* yystackp
)
2547 yyGLRStackItem
* yyp
;
2549 for (yyp
= yystackp
->yyitems
; yyp
< yystackp
->yynextFree
; yyp
+= 1)
2551 YYFPRINTF (stderr
, "%3lu. ",
2552 (unsigned long int) (yyp
- yystackp
->yyitems
));
2553 if (*(yybool
*) yyp
)
2555 YYFPRINTF (stderr
, "Res: %d, LR State: %d, posn: %lu, pred: %ld",
2556 yyp
->yystate
.yyresolved
, yyp
->yystate
.yylrState
,
2557 (unsigned long int) yyp
->yystate
.yyposn
,
2558 (long int) YYINDEX (yyp
->yystate
.yypred
));
2559 if (! yyp
->yystate
.yyresolved
)
2560 YYFPRINTF (stderr
, ", firstVal: %ld",
2561 (long int) YYINDEX (yyp
->yystate
2562 .yysemantics
.yyfirstVal
));
2566 YYFPRINTF (stderr
, "Option. rule: %d, state: %ld, next: %ld",
2567 yyp
->yyoption
.yyrule
- 1,
2568 (long int) YYINDEX (yyp
->yyoption
.yystate
),
2569 (long int) YYINDEX (yyp
->yyoption
.yynext
));
2571 YYFPRINTF (stderr
, "\n");
2573 YYFPRINTF (stderr
, "Tops:");
2574 for (yyi
= 0; yyi
< yystackp
->yytops
.yysize
; yyi
+= 1)
2575 YYFPRINTF (stderr
, "%lu: %ld; ", (unsigned long int) yyi
,
2576 (long int) YYINDEX (yystackp
->yytops
.yystates
[yyi
]));
2577 YYFPRINTF (stderr
, "\n");
2582 dnl glr
.cc produces its own header
.
2584 m4_if(b4_skeleton
, ["glr.c"],
2586 [@
output(b4_spec_defines_file@
)@
2587 b4_copyright([Skeleton interface
for Bison GLR parsers in C
],
2590 ]b4_cpp_guard_open([b4_spec_defines_file
])[
2591 ]b4_shared_declarations
[
2592 ]b4_cpp_guard_close([b4_spec_defines_file
])[