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 b4_yyloc_default_define
])[
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 #ifndef YYLLOC_DEFAULT
479 ]b4_yylloc_default_define
[
480 # define YYRHSLOC(Rhs, K) ((Rhs)[K].yystate.yyloc)
482 /* YY_LOCATION_PRINT -- Print the location on the stream.
483 This macro was not mandated originally: define only if we know
484 we won't break user code: when these are the locations we know. */
486 # define YY_LOCATION_PRINT(File, Loc) \
487 fprintf (File, "%d.%d-%d.%d", \
488 (Loc).first_line, (Loc).first_column, \
489 (Loc).last_line, (Loc).last_column)
492 #ifndef YYLLOC_DEFAULT
493 # define YYLLOC_DEFAULT(Current, Rhs, N) ((void) 0)
497 #ifndef YY_LOCATION_PRINT
498 # define YY_LOCATION_PRINT(File, Loc) ((void) 0)
501 /* YYLEX -- calling `yylex' with the right arguments. */
502 #define YYLEX ]b4_c_function_call([yylex], [int], b4_lex_param)[
507 #define yynerrs (yystackp->yyerrcnt)
509 #define yychar (yystackp->yyrawchar)
511 #define yylval (yystackp->yyval)
513 #define yylloc (yystackp->yyloc)
514 m4_if(b4_prefix
[], [yy
], [],
515 [#define b4_prefix[]nerrs yynerrs
516 #define b4_prefix[]char yychar
517 #define b4_prefix[]lval yylval
518 #define b4_prefix[]lloc yylloc])],
519 [YYSTYPE yylval
;]b4_locations_if([[
525 static const int YYEOF
= 0;
526 static const int YYEMPTY
= -2;
528 typedef enum { yyok
, yyaccept
, yyabort
, yyerr
} YYRESULTTAG
;
531 do { YYRESULTTAG yyflag = YYE; if (yyflag != yyok) return yyflag; } \
534 #if ]b4_api_PREFIX[DEBUG
537 # define YYFPRINTF fprintf
540 # define YYDPRINTF(Args) \
546 ]b4_yy_symbol_print_generate([b4_c_ansi_function_def
])[
548 # define YY_SYMBOL_PRINT(Title, Type, Value, Location) \
552 YYFPRINTF (stderr, "%s ", Title); \
553 yy_symbol_print (stderr, Type, Value]b4_locuser_args([Location])[); \
554 YYFPRINTF (stderr, "\n"); \
558 /* Nonzero means print parse trace. It is left uninitialized so that
559 multiple parsers can coexist. */
562 #else /* !]b4_api_PREFIX[DEBUG */
564 # define YYDPRINTF(Args)
565 # define YY_SYMBOL_PRINT(Title, Type, Value, Location)
567 #endif /* !]b4_api_PREFIX[DEBUG */
569 /* YYINITDEPTH -- initial size of the parser's stacks. */
571 # define YYINITDEPTH ]b4_stack_depth_init[
574 /* YYMAXDEPTH -- maximum size the stacks can grow to (effective only
575 if the built-in stack extension method is used).
577 Do not make this value too large; the results are undefined if
578 SIZE_MAX < YYMAXDEPTH * sizeof (GLRStackItem)
579 evaluated with infinite-precision integer arithmetic. */
582 # define YYMAXDEPTH ]b4_stack_depth_max[
585 /* Minimum number of free items on the stack allowed after an
586 allocation. This is to allow allocation and initialization
587 to be completed by functions that call yyexpandGLRStack before the
588 stack is expanded, thus insuring that all necessary pointers get
589 properly redirected to new data. */
592 #ifndef YYSTACKEXPANDABLE
593 # if (! defined __cplusplus \
594 || (]b4_locations_if([[defined ]b4_api_PREFIX[LTYPE_IS_TRIVIAL && ]b4_api_PREFIX[LTYPE_IS_TRIVIAL \
595 && ]])[defined ]b4_api_PREFIX[STYPE_IS_TRIVIAL && ]b4_api_PREFIX[STYPE_IS_TRIVIAL))
596 # define YYSTACKEXPANDABLE 1
598 # define YYSTACKEXPANDABLE 0
602 #if YYSTACKEXPANDABLE
603 # define YY_RESERVE_GLRSTACK(Yystack) \
605 if (Yystack->yyspaceLeft < YYHEADROOM) \
606 yyexpandGLRStack (Yystack); \
609 # define YY_RESERVE_GLRSTACK(Yystack) \
611 if (Yystack->yyspaceLeft < YYHEADROOM) \
612 yyMemoryExhausted (Yystack); \
620 # if defined __GLIBC__ && defined _STRING_H && defined _GNU_SOURCE
621 # define yystpcpy stpcpy
623 /* Copy YYSRC to YYDEST, returning the address of the terminating '\0' in
626 yystpcpy (char *yydest
, const char *yysrc
)
629 const char *yys
= yysrc
;
631 while ((*yyd
++ = *yys
++) != '\0')
640 /* Copy to YYRES the contents of YYSTR after stripping away unnecessary
641 quotes and backslashes, so that it's suitable for yyerror. The
642 heuristic is that double-quoting is unnecessary unless the string
643 contains an apostrophe, a comma, or backslash (other than
644 backslash-backslash). YYSTR is taken from yytname. If YYRES is
645 null, do not copy; instead, return the length of what the result
648 yytnamerr (char *yyres
, const char *yystr
)
653 char const *yyp
= yystr
;
660 goto do_not_strip_quotes
;
664 goto do_not_strip_quotes
;
677 do_not_strip_quotes
: ;
681 return strlen (yystr
);
683 return yystpcpy (yyres
, yystr
) - yyres
;
687 #endif /* !YYERROR_VERBOSE */
689 /** State numbers, as in LALR(1) machine */
690 typedef int yyStateNum
;
692 /** Rule numbers, as in LALR(1) machine */
693 typedef int yyRuleNum
;
695 /** Grammar symbol */
696 typedef short int yySymbol
;
698 /** Item references, as in LALR(1) machine */
699 typedef short int yyItemNum
;
701 typedef struct yyGLRState yyGLRState
;
702 typedef struct yyGLRStateSet yyGLRStateSet
;
703 typedef struct yySemanticOption yySemanticOption
;
704 typedef union yyGLRStackItem yyGLRStackItem
;
705 typedef struct yyGLRStack yyGLRStack
;
708 /** Type tag: always true. */
710 /** Type tag for yysemantics. If true, yysval applies, otherwise
711 * yyfirstVal applies. */
713 /** Number of corresponding LALR(1) machine state. */
714 yyStateNum yylrState
;
715 /** Preceding state in this stack */
717 /** Source position of the first token produced by my symbol */
720 /** First in a chain of alternative reductions producing the
721 * non-terminal corresponding to this state, threaded through
723 yySemanticOption
* yyfirstVal
;
724 /** Semantic value for this state. */
726 } yysemantics
;]b4_locations_if([[
727 /** Source location for this state. */
731 struct yyGLRStateSet
{
732 yyGLRState
** yystates
;
733 /** During nondeterministic operation, yylookaheadNeeds tracks which
734 * stacks have actually needed the current lookahead. During deterministic
735 * operation, yylookaheadNeeds[0] is not maintained since it would merely
736 * duplicate yychar != YYEMPTY. */
737 yybool
* yylookaheadNeeds
;
738 size_t yysize
, yycapacity
;
741 struct yySemanticOption
{
742 /** Type tag: always false. */
744 /** Rule number for this reduction */
746 /** The last RHS state in the list of states to be reduced. */
748 /** The lookahead for this reduction. */
750 YYSTYPE yyval
;]b4_locations_if([[
752 /** Next sibling in chain of options. To facilitate merging,
753 * options are chained in decreasing order by address. */
754 yySemanticOption
* yynext
;
757 /** Type of the items in the GLR stack. The yyisState field
758 * indicates which item of the union is valid. */
759 union yyGLRStackItem
{
761 yySemanticOption yyoption
;
766 ]b4_locations_if([[ /* To compute the location of the error token. */
767 yyGLRStackItem yyerror_range
[3];]])[
772 YYSTYPE yyval
;]b4_locations_if([[
775 YYJMP_BUF yyexception_buffer
;
776 yyGLRStackItem
* yyitems
;
777 yyGLRStackItem
* yynextFree
;
779 yyGLRState
* yysplitPoint
;
780 yyGLRState
* yylastDeleted
;
781 yyGLRStateSet yytops
;
784 #if YYSTACKEXPANDABLE
785 static void yyexpandGLRStack (yyGLRStack
* yystackp
);
788 static void yyFail (yyGLRStack
* yystackp
]b4_pure_formals
[, const char* yymsg
)
789 __attribute__ ((__noreturn__
));
791 yyFail (yyGLRStack
* yystackp
]b4_pure_formals
[, const char* yymsg
)
793 if (yymsg
!= YY_NULL
)
794 yyerror (]b4_yyerror_args
[yymsg
);
795 YYLONGJMP (yystackp
->yyexception_buffer
, 1);
798 static void yyMemoryExhausted (yyGLRStack
* yystackp
)
799 __attribute__ ((__noreturn__
));
801 yyMemoryExhausted (yyGLRStack
* yystackp
)
803 YYLONGJMP (yystackp
->yyexception_buffer
, 2);
806 #if ]b4_api_PREFIX[DEBUG || YYERROR_VERBOSE
807 /** A printable representation of TOKEN. */
808 static inline const char*
809 yytokenName (yySymbol yytoken
)
811 if (yytoken
== YYEMPTY
)
814 return yytname
[yytoken
];
818 /** Fill in YYVSP[YYLOW1 .. YYLOW0-1] from the chain of states starting
819 * at YYVSP[YYLOW0].yystate.yypred. Leaves YYVSP[YYLOW1].yystate.yypred
820 * containing the pointer to the next state in the chain. */
821 static void yyfillin (yyGLRStackItem
*, int, int) __attribute__ ((__unused__
));
823 yyfillin (yyGLRStackItem
*yyvsp
, int yylow0
, int yylow1
)
826 yyGLRState
*s
= yyvsp
[yylow0
].yystate
.yypred
;
827 for (i
= yylow0
-1; i
>= yylow1
; i
-= 1)
829 YYASSERT (s
->yyresolved
);
830 yyvsp
[i
].yystate
.yyresolved
= yytrue
;
831 yyvsp
[i
].yystate
.yysemantics
.yysval
= s
->yysemantics
.yysval
;]b4_locations_if([[
832 yyvsp
[i
].yystate
.yyloc
= s
->yyloc
;]])[
833 s
= yyvsp
[i
].yystate
.yypred
= s
->yypred
;
837 /* Do nothing if YYNORMAL or if *YYLOW <= YYLOW1. Otherwise, fill in
838 * YYVSP[YYLOW1 .. *YYLOW-1] as in yyfillin and set *YYLOW = YYLOW1.
839 * For convenience, always return YYLOW1. */
840 static inline int yyfill (yyGLRStackItem
*, int *, int, yybool
)
841 __attribute__ ((__unused__
));
843 yyfill (yyGLRStackItem
*yyvsp
, int *yylow
, int yylow1
, yybool yynormal
)
845 if (!yynormal
&& yylow1
< *yylow
)
847 yyfillin (yyvsp
, *yylow
, yylow1
);
853 /** Perform user action for rule number YYN, with RHS length YYRHSLEN,
854 * and top stack item YYVSP. YYLVALP points to place to put semantic
855 * value ($$), and yylocp points to place for location information
856 * (@@$). Returns yyok for normal return, yyaccept for YYACCEPT,
857 * yyerr for YYERROR, yyabort for YYABORT. */
858 /*ARGSUSED*/ static YYRESULTTAG
859 yyuserAction (yyRuleNum yyn
, int yyrhslen
, yyGLRStackItem
* yyvsp
,
860 yyGLRStack
* yystackp
,
861 YYSTYPE
* yyvalp
]b4_locuser_formals
[)
863 yybool yynormal
__attribute__ ((__unused__
)) =
864 (yystackp
->yysplitPoint
== YY_NULL
);
866 ]b4_parse_param_use
[]dnl
868 # define yyerrok (yystackp->yyerrState = 0)
870 # define YYACCEPT return yyaccept
872 # define YYABORT return yyabort
874 # define YYERROR return yyerrok, yyerr
876 # define YYRECOVERING() (yystackp->yyerrState != 0)
878 # define yyclearin (yychar = YYEMPTY)
880 # define YYFILL(N) yyfill (yyvsp, &yylow, N, yynormal)
882 # define YYBACKUP(Token, Value) \
883 return yyerror (]b4_yyerror_args[YY_("syntax error: cannot back up")), \
888 *yyvalp
= yyval_default
;
890 *yyvalp
= yyvsp
[YYFILL (1-yyrhslen
)].yystate
.yysemantics
.yysval
;]b4_locations_if([[
891 YYLLOC_DEFAULT ((*yylocp
), (yyvsp
- yyrhslen
), yyrhslen
);
892 yystackp
->yyerror_range
[1].yystate
.yyloc
= *yylocp
;
911 /*ARGSUSED*/ static void
912 yyuserMerge (int yyn
, YYSTYPE
* yy0
, YYSTYPE
* yy1
)
924 /* Bison grammar-table manipulation. */
926 ]b4_yydestruct_generate([b4_c_ansi_function_def
])[
928 /** Number of symbols composing the right hand side of rule #RULE. */
930 yyrhsLength (yyRuleNum yyrule
)
936 yydestroyGLRState (char const *yymsg
, yyGLRState
*yys
]b4_user_formals
[)
939 yydestruct (yymsg
, yystos
[yys
->yylrState
],
940 &yys
->yysemantics
.yysval
]b4_locuser_args([&yys
->yyloc
])[);
943 #if ]b4_api_PREFIX[DEBUG
946 if (yys
->yysemantics
.yyfirstVal
)
947 YYFPRINTF (stderr
, "%s unresolved ", yymsg
);
949 YYFPRINTF (stderr
, "%s incomplete ", yymsg
);
950 yy_symbol_print (stderr
, yystos
[yys
->yylrState
],
951 YY_NULL
]b4_locuser_args([&yys
->yyloc
])[);
952 YYFPRINTF (stderr
, "\n");
956 if (yys
->yysemantics
.yyfirstVal
)
958 yySemanticOption
*yyoption
= yys
->yysemantics
.yyfirstVal
;
961 for (yyrh
= yyoption
->yystate
, yyn
= yyrhsLength (yyoption
->yyrule
);
963 yyrh
= yyrh
->yypred
, yyn
-= 1)
964 yydestroyGLRState (yymsg
, yyrh
]b4_user_args
[);
969 /** Left-hand-side symbol for rule #RULE. */
970 static inline yySymbol
971 yylhsNonterm (yyRuleNum yyrule
)
976 #define yypact_value_is_default(Yystate) \
977 ]b4_table_value_equals([[pact]], [[Yystate]], [b4_pact_ninf])[
979 /** True iff LR state STATE has only a default reduction (regardless
982 yyisDefaultedState (yyStateNum yystate
)
984 return yypact_value_is_default (yypact
[yystate
]);
987 /** The default reduction for STATE, assuming it has one. */
988 static inline yyRuleNum
989 yydefaultAction (yyStateNum yystate
)
991 return yydefact
[yystate
];
994 #define yytable_value_is_error(Yytable_value) \
995 ]b4_table_value_equals([[table]], [[Yytable_value]], [b4_table_ninf])[
997 /** Set *YYACTION to the action to take in YYSTATE on seeing YYTOKEN.
999 * R < 0: Reduce on rule -R.
1001 * R > 0: Shift to state R.
1002 * Set *CONFLICTS to a pointer into yyconfl to 0-terminated list of
1003 * conflicting reductions.
1006 yygetLRActions (yyStateNum yystate
, int yytoken
,
1007 int* yyaction
, const short int** yyconflicts
)
1009 int yyindex
= yypact
[yystate
] + yytoken
;
1010 if (yypact_value_is_default (yypact
[yystate
])
1011 || yyindex
< 0 || YYLAST
< yyindex
|| yycheck
[yyindex
] != yytoken
)
1013 *yyaction
= -yydefact
[yystate
];
1014 *yyconflicts
= yyconfl
;
1016 else if (! yytable_value_is_error (yytable
[yyindex
]))
1018 *yyaction
= yytable
[yyindex
];
1019 *yyconflicts
= yyconfl
+ yyconflp
[yyindex
];
1024 *yyconflicts
= yyconfl
+ yyconflp
[yyindex
];
1028 static inline yyStateNum
1029 yyLRgotoState (yyStateNum yystate
, yySymbol yylhs
)
1032 yyr
= yypgoto
[yylhs
- YYNTOKENS
] + yystate
;
1033 if (0 <= yyr
&& yyr
<= YYLAST
&& yycheck
[yyr
] == yystate
)
1034 return yytable
[yyr
];
1036 return yydefgoto
[yylhs
- YYNTOKENS
];
1039 static inline yybool
1040 yyisShiftAction (int yyaction
)
1042 return 0 < yyaction
;
1045 static inline yybool
1046 yyisErrorAction (int yyaction
)
1048 return yyaction
== 0;
1053 /** Return a fresh GLRStackItem. Callers should call
1054 * YY_RESERVE_GLRSTACK afterwards to make sure there is sufficient
1057 static inline yyGLRStackItem
*
1058 yynewGLRStackItem (yyGLRStack
* yystackp
, yybool yyisState
)
1060 yyGLRStackItem
* yynewItem
= yystackp
->yynextFree
;
1061 yystackp
->yyspaceLeft
-= 1;
1062 yystackp
->yynextFree
+= 1;
1063 yynewItem
->yystate
.yyisState
= yyisState
;
1067 /** Add a new semantic action that will execute the action for rule
1068 * RULENUM on the semantic values in RHS to the list of
1069 * alternative actions for STATE. Assumes that RHS comes from
1070 * stack #K of *STACKP. */
1072 yyaddDeferredAction (yyGLRStack
* yystackp
, size_t yyk
, yyGLRState
* yystate
,
1073 yyGLRState
* rhs
, yyRuleNum yyrule
)
1075 yySemanticOption
* yynewOption
=
1076 &yynewGLRStackItem (yystackp
, yyfalse
)->yyoption
;
1077 yynewOption
->yystate
= rhs
;
1078 yynewOption
->yyrule
= yyrule
;
1079 if (yystackp
->yytops
.yylookaheadNeeds
[yyk
])
1081 yynewOption
->yyrawchar
= yychar
;
1082 yynewOption
->yyval
= yylval
;]b4_locations_if([
1083 yynewOption
->yyloc
= yylloc
;])[
1086 yynewOption
->yyrawchar
= YYEMPTY
;
1087 yynewOption
->yynext
= yystate
->yysemantics
.yyfirstVal
;
1088 yystate
->yysemantics
.yyfirstVal
= yynewOption
;
1090 YY_RESERVE_GLRSTACK (yystackp
);
1095 /** Initialize SET to a singleton set containing an empty stack. */
1097 yyinitStateSet (yyGLRStateSet
* yyset
)
1100 yyset
->yycapacity
= 16;
1101 yyset
->yystates
= (yyGLRState
**) YYMALLOC (16 * sizeof yyset
->yystates
[0]);
1102 if (! yyset
->yystates
)
1104 yyset
->yystates
[0] = YY_NULL
;
1105 yyset
->yylookaheadNeeds
=
1106 (yybool
*) YYMALLOC (16 * sizeof yyset
->yylookaheadNeeds
[0]);
1107 if (! yyset
->yylookaheadNeeds
)
1109 YYFREE (yyset
->yystates
);
1115 static void yyfreeStateSet (yyGLRStateSet
* yyset
)
1117 YYFREE (yyset
->yystates
);
1118 YYFREE (yyset
->yylookaheadNeeds
);
1121 /** Initialize STACK to a single empty stack, with total maximum
1122 * capacity for all stacks of SIZE. */
1124 yyinitGLRStack (yyGLRStack
* yystackp
, size_t yysize
)
1126 yystackp
->yyerrState
= 0;
1128 yystackp
->yyspaceLeft
= yysize
;
1130 (yyGLRStackItem
*) YYMALLOC (yysize
* sizeof yystackp
->yynextFree
[0]);
1131 if (!yystackp
->yyitems
)
1133 yystackp
->yynextFree
= yystackp
->yyitems
;
1134 yystackp
->yysplitPoint
= YY_NULL
;
1135 yystackp
->yylastDeleted
= YY_NULL
;
1136 return yyinitStateSet (&yystackp
->yytops
);
1140 #if YYSTACKEXPANDABLE
1141 # define YYRELOC(YYFROMITEMS,YYTOITEMS,YYX,YYTYPE) \
1142 &((YYTOITEMS) - ((YYFROMITEMS) - (yyGLRStackItem*) (YYX)))->YYTYPE
1144 /** If STACK is expandable, extend it. WARNING: Pointers into the
1145 stack from outside should be considered invalid after this call.
1146 We always expand when there are 1 or fewer items left AFTER an
1147 allocation, so that we can avoid having external pointers exist
1148 across an allocation. */
1150 yyexpandGLRStack (yyGLRStack
* yystackp
)
1152 yyGLRStackItem
* yynewItems
;
1153 yyGLRStackItem
* yyp0
, *yyp1
;
1156 size_t yysize
= yystackp
->yynextFree
- yystackp
->yyitems
;
1157 if (YYMAXDEPTH
- YYHEADROOM
< yysize
)
1158 yyMemoryExhausted (yystackp
);
1159 yynewSize
= 2*yysize
;
1160 if (YYMAXDEPTH
< yynewSize
)
1161 yynewSize
= YYMAXDEPTH
;
1162 yynewItems
= (yyGLRStackItem
*) YYMALLOC (yynewSize
* sizeof yynewItems
[0]);
1164 yyMemoryExhausted (yystackp
);
1165 for (yyp0
= yystackp
->yyitems
, yyp1
= yynewItems
, yyn
= yysize
;
1167 yyn
-= 1, yyp0
+= 1, yyp1
+= 1)
1170 if (*(yybool
*) yyp0
)
1172 yyGLRState
* yys0
= &yyp0
->yystate
;
1173 yyGLRState
* yys1
= &yyp1
->yystate
;
1174 if (yys0
->yypred
!= YY_NULL
)
1176 YYRELOC (yyp0
, yyp1
, yys0
->yypred
, yystate
);
1177 if (! yys0
->yyresolved
&& yys0
->yysemantics
.yyfirstVal
!= YY_NULL
)
1178 yys1
->yysemantics
.yyfirstVal
=
1179 YYRELOC (yyp0
, yyp1
, yys0
->yysemantics
.yyfirstVal
, yyoption
);
1183 yySemanticOption
* yyv0
= &yyp0
->yyoption
;
1184 yySemanticOption
* yyv1
= &yyp1
->yyoption
;
1185 if (yyv0
->yystate
!= YY_NULL
)
1186 yyv1
->yystate
= YYRELOC (yyp0
, yyp1
, yyv0
->yystate
, yystate
);
1187 if (yyv0
->yynext
!= YY_NULL
)
1188 yyv1
->yynext
= YYRELOC (yyp0
, yyp1
, yyv0
->yynext
, yyoption
);
1191 if (yystackp
->yysplitPoint
!= YY_NULL
)
1192 yystackp
->yysplitPoint
= YYRELOC (yystackp
->yyitems
, yynewItems
,
1193 yystackp
->yysplitPoint
, yystate
);
1195 for (yyn
= 0; yyn
< yystackp
->yytops
.yysize
; yyn
+= 1)
1196 if (yystackp
->yytops
.yystates
[yyn
] != YY_NULL
)
1197 yystackp
->yytops
.yystates
[yyn
] =
1198 YYRELOC (yystackp
->yyitems
, yynewItems
,
1199 yystackp
->yytops
.yystates
[yyn
], yystate
);
1200 YYFREE (yystackp
->yyitems
);
1201 yystackp
->yyitems
= yynewItems
;
1202 yystackp
->yynextFree
= yynewItems
+ yysize
;
1203 yystackp
->yyspaceLeft
= yynewSize
- yysize
;
1208 yyfreeGLRStack (yyGLRStack
* yystackp
)
1210 YYFREE (yystackp
->yyitems
);
1211 yyfreeStateSet (&yystackp
->yytops
);
1214 /** Assuming that S is a GLRState somewhere on STACK, update the
1215 * splitpoint of STACK, if needed, so that it is at least as deep as
1218 yyupdateSplit (yyGLRStack
* yystackp
, yyGLRState
* yys
)
1220 if (yystackp
->yysplitPoint
!= YY_NULL
&& yystackp
->yysplitPoint
> yys
)
1221 yystackp
->yysplitPoint
= yys
;
1224 /** Invalidate stack #K in STACK. */
1226 yymarkStackDeleted (yyGLRStack
* yystackp
, size_t yyk
)
1228 if (yystackp
->yytops
.yystates
[yyk
] != YY_NULL
)
1229 yystackp
->yylastDeleted
= yystackp
->yytops
.yystates
[yyk
];
1230 yystackp
->yytops
.yystates
[yyk
] = YY_NULL
;
1233 /** Undelete the last stack that was marked as deleted. Can only be
1234 done once after a deletion, and only when all other stacks have
1237 yyundeleteLastStack (yyGLRStack
* yystackp
)
1239 if (yystackp
->yylastDeleted
== YY_NULL
|| yystackp
->yytops
.yysize
!= 0)
1241 yystackp
->yytops
.yystates
[0] = yystackp
->yylastDeleted
;
1242 yystackp
->yytops
.yysize
= 1;
1243 YYDPRINTF ((stderr
, "Restoring last deleted stack as stack #0.\n"));
1244 yystackp
->yylastDeleted
= YY_NULL
;
1248 yyremoveDeletes (yyGLRStack
* yystackp
)
1252 while (yyj
< yystackp
->yytops
.yysize
)
1254 if (yystackp
->yytops
.yystates
[yyi
] == YY_NULL
)
1258 YYDPRINTF ((stderr
, "Removing dead stacks.\n"));
1260 yystackp
->yytops
.yysize
-= 1;
1264 yystackp
->yytops
.yystates
[yyj
] = yystackp
->yytops
.yystates
[yyi
];
1265 /* In the current implementation, it's unnecessary to copy
1266 yystackp->yytops.yylookaheadNeeds[yyi] since, after
1267 yyremoveDeletes returns, the parser immediately either enters
1268 deterministic operation or shifts a token. However, it doesn't
1269 hurt, and the code might evolve to need it. */
1270 yystackp
->yytops
.yylookaheadNeeds
[yyj
] =
1271 yystackp
->yytops
.yylookaheadNeeds
[yyi
];
1274 YYDPRINTF ((stderr
, "Rename stack %lu -> %lu.\n",
1275 (unsigned long int) yyi
, (unsigned long int) yyj
));
1283 /** Shift to a new state on stack #K of STACK, corresponding to LR state
1284 * LRSTATE, at input position POSN, with (resolved) semantic value SVAL. */
1286 yyglrShift (yyGLRStack
* yystackp
, size_t yyk
, yyStateNum yylrState
,
1288 YYSTYPE
* yyvalp
]b4_locations_if([, YYLTYPE
* yylocp
])[)
1290 yyGLRState
* yynewState
= &yynewGLRStackItem (yystackp
, yytrue
)->yystate
;
1292 yynewState
->yylrState
= yylrState
;
1293 yynewState
->yyposn
= yyposn
;
1294 yynewState
->yyresolved
= yytrue
;
1295 yynewState
->yypred
= yystackp
->yytops
.yystates
[yyk
];
1296 yynewState
->yysemantics
.yysval
= *yyvalp
;]b4_locations_if([
1297 yynewState
->yyloc
= *yylocp
;])[
1298 yystackp
->yytops
.yystates
[yyk
] = yynewState
;
1300 YY_RESERVE_GLRSTACK (yystackp
);
1303 /** Shift stack #K of YYSTACK, to a new state corresponding to LR
1304 * state YYLRSTATE, at input position YYPOSN, with the (unresolved)
1305 * semantic value of YYRHS under the action for YYRULE. */
1307 yyglrShiftDefer (yyGLRStack
* yystackp
, size_t yyk
, yyStateNum yylrState
,
1308 size_t yyposn
, yyGLRState
* rhs
, yyRuleNum yyrule
)
1310 yyGLRState
* yynewState
= &yynewGLRStackItem (yystackp
, yytrue
)->yystate
;
1312 yynewState
->yylrState
= yylrState
;
1313 yynewState
->yyposn
= yyposn
;
1314 yynewState
->yyresolved
= yyfalse
;
1315 yynewState
->yypred
= yystackp
->yytops
.yystates
[yyk
];
1316 yynewState
->yysemantics
.yyfirstVal
= YY_NULL
;
1317 yystackp
->yytops
.yystates
[yyk
] = yynewState
;
1319 /* Invokes YY_RESERVE_GLRSTACK. */
1320 yyaddDeferredAction (yystackp
, yyk
, yynewState
, rhs
, yyrule
);
1323 /** Pop the symbols consumed by reduction #RULE from the top of stack
1324 * #K of STACK, and perform the appropriate semantic action on their
1325 * semantic values. Assumes that all ambiguities in semantic values
1326 * have been previously resolved. Set *VALP to the resulting value,
1327 * and *LOCP to the computed location (if any). Return value is as
1328 * for userAction. */
1329 static inline YYRESULTTAG
1330 yydoAction (yyGLRStack
* yystackp
, size_t yyk
, yyRuleNum yyrule
,
1331 YYSTYPE
* yyvalp
]b4_locuser_formals
[)
1333 int yynrhs
= yyrhsLength (yyrule
);
1335 if (yystackp
->yysplitPoint
== YY_NULL
)
1337 /* Standard special case: single stack. */
1338 yyGLRStackItem
* rhs
= (yyGLRStackItem
*) yystackp
->yytops
.yystates
[yyk
];
1339 YYASSERT (yyk
== 0);
1340 yystackp
->yynextFree
-= yynrhs
;
1341 yystackp
->yyspaceLeft
+= yynrhs
;
1342 yystackp
->yytops
.yystates
[0] = & yystackp
->yynextFree
[-1].yystate
;
1343 return yyuserAction (yyrule
, yynrhs
, rhs
, yystackp
,
1344 yyvalp
]b4_locuser_args
[);
1348 /* At present, doAction is never called in nondeterministic
1349 * mode, so this branch is never taken. It is here in
1350 * anticipation of a future feature that will allow immediate
1351 * evaluation of selected actions in nondeterministic mode. */
1354 yyGLRStackItem yyrhsVals
[YYMAXRHS
+ YYMAXLEFT
+ 1];
1355 yys
= yyrhsVals
[YYMAXRHS
+ YYMAXLEFT
].yystate
.yypred
1356 = yystackp
->yytops
.yystates
[yyk
];]b4_locations_if([[
1358 /* Set default location. */
1359 yyrhsVals
[YYMAXRHS
+ YYMAXLEFT
- 1].yystate
.yyloc
= yys
->yyloc
;]])[
1360 for (yyi
= 0; yyi
< yynrhs
; yyi
+= 1)
1365 yyupdateSplit (yystackp
, yys
);
1366 yystackp
->yytops
.yystates
[yyk
] = yys
;
1367 return yyuserAction (yyrule
, yynrhs
, yyrhsVals
+ YYMAXRHS
+ YYMAXLEFT
- 1,
1368 yystackp
, yyvalp
]b4_locuser_args
[);
1372 #if !]b4_api_PREFIX[DEBUG
1373 # define YY_REDUCE_PRINT(Args)
1375 # define YY_REDUCE_PRINT(Args) \
1378 yy_reduce_print Args; \
1381 /*----------------------------------------------------------.
1382 | Report that the RULE is going to be reduced on stack #K. |
1383 `----------------------------------------------------------*/
1385 /*ARGSUSED*/ static inline void
1386 yy_reduce_print (yyGLRStack
* yystackp
, size_t yyk
, yyRuleNum yyrule
,
1387 YYSTYPE
* yyvalp
]b4_locuser_formals
[)
1389 int yynrhs
= yyrhsLength (yyrule
);
1390 yybool yynormal
__attribute__ ((__unused__
)) =
1391 (yystackp
->yysplitPoint
== YY_NULL
);
1392 yyGLRStackItem
* yyvsp
= (yyGLRStackItem
*) yystackp
->yytops
.yystates
[yyk
];
1395 YYUSE (yyvalp
);]b4_locations_if([
1397 ]b4_parse_param_use
[]dnl
1398 [ YYFPRINTF (stderr
, "Reducing stack %lu by rule %d (line %lu):\n",
1399 (unsigned long int) yyk
, yyrule
- 1,
1400 (unsigned long int) yyrline
[yyrule
]);
1401 /* The symbols being reduced. */
1402 for (yyi
= 0; yyi
< yynrhs
; yyi
++)
1404 YYFPRINTF (stderr
, " $%d = ", yyi
+ 1);
1405 yy_symbol_print (stderr
, yyrhs
[yyprhs
[yyrule
] + yyi
],
1406 &]b4_rhs_value(yynrhs
, yyi
+ 1)[
1407 ]b4_locations_if([, &]b4_rhs_location(yynrhs
, yyi
+ 1))[]dnl
1409 YYFPRINTF (stderr
, "\n");
1414 /** Pop items off stack #K of STACK according to grammar rule RULE,
1415 * and push back on the resulting nonterminal symbol. Perform the
1416 * semantic action associated with RULE and store its value with the
1417 * newly pushed state, if FORCEEVAL or if STACK is currently
1418 * unambiguous. Otherwise, store the deferred semantic action with
1419 * the new state. If the new state would have an identical input
1420 * position, LR state, and predecessor to an existing state on the stack,
1421 * it is identified with that existing state, eliminating stack #K from
1422 * the STACK. In this case, the (necessarily deferred) semantic value is
1423 * added to the options for the existing state's semantic value.
1425 static inline YYRESULTTAG
1426 yyglrReduce (yyGLRStack
* yystackp
, size_t yyk
, yyRuleNum yyrule
,
1427 yybool yyforceEval
]b4_user_formals
[)
1429 size_t yyposn
= yystackp
->yytops
.yystates
[yyk
]->yyposn
;
1431 if (yyforceEval
|| yystackp
->yysplitPoint
== YY_NULL
)
1433 YYSTYPE yysval
;]b4_locations_if([
1436 YY_REDUCE_PRINT ((yystackp
, yyk
, yyrule
, &yysval
]b4_locuser_args([&yyloc
])[));
1437 YYCHK (yydoAction (yystackp
, yyk
, yyrule
, &yysval
]b4_locuser_args([&yyloc
])[));
1438 YY_SYMBOL_PRINT ("-> $$ =", yyr1
[yyrule
], &yysval
, &yyloc
);
1439 yyglrShift (yystackp
, yyk
,
1440 yyLRgotoState (yystackp
->yytops
.yystates
[yyk
]->yylrState
,
1441 yylhsNonterm (yyrule
)),
1442 yyposn
, &yysval
]b4_locations_if([, &yyloc
])[);
1448 yyGLRState
* yys
, *yys0
= yystackp
->yytops
.yystates
[yyk
];
1449 yyStateNum yynewLRState
;
1451 for (yys
= yystackp
->yytops
.yystates
[yyk
], yyn
= yyrhsLength (yyrule
);
1457 yyupdateSplit (yystackp
, yys
);
1458 yynewLRState
= yyLRgotoState (yys
->yylrState
, yylhsNonterm (yyrule
));
1460 "Reduced stack %lu by rule #%d; action deferred. Now in state %d.\n",
1461 (unsigned long int) yyk
, yyrule
- 1, yynewLRState
));
1462 for (yyi
= 0; yyi
< yystackp
->yytops
.yysize
; yyi
+= 1)
1463 if (yyi
!= yyk
&& yystackp
->yytops
.yystates
[yyi
] != YY_NULL
)
1465 yyGLRState
*yysplit
= yystackp
->yysplitPoint
;
1466 yyGLRState
*yyp
= yystackp
->yytops
.yystates
[yyi
];
1467 while (yyp
!= yys
&& yyp
!= yysplit
&& yyp
->yyposn
>= yyposn
)
1469 if (yyp
->yylrState
== yynewLRState
&& yyp
->yypred
== yys
)
1471 yyaddDeferredAction (yystackp
, yyk
, yyp
, yys0
, yyrule
);
1472 yymarkStackDeleted (yystackp
, yyk
);
1473 YYDPRINTF ((stderr
, "Merging stack %lu into stack %lu.\n",
1474 (unsigned long int) yyk
,
1475 (unsigned long int) yyi
));
1481 yystackp
->yytops
.yystates
[yyk
] = yys
;
1482 yyglrShiftDefer (yystackp
, yyk
, yynewLRState
, yyposn
, yys0
, yyrule
);
1488 yysplitStack (yyGLRStack
* yystackp
, size_t yyk
)
1490 if (yystackp
->yysplitPoint
== YY_NULL
)
1492 YYASSERT (yyk
== 0);
1493 yystackp
->yysplitPoint
= yystackp
->yytops
.yystates
[yyk
];
1495 if (yystackp
->yytops
.yysize
>= yystackp
->yytops
.yycapacity
)
1497 yyGLRState
** yynewStates
;
1498 yybool
* yynewLookaheadNeeds
;
1500 yynewStates
= YY_NULL
;
1502 if (yystackp
->yytops
.yycapacity
1503 > (YYSIZEMAX
/ (2 * sizeof yynewStates
[0])))
1504 yyMemoryExhausted (yystackp
);
1505 yystackp
->yytops
.yycapacity
*= 2;
1508 (yyGLRState
**) YYREALLOC (yystackp
->yytops
.yystates
,
1509 (yystackp
->yytops
.yycapacity
1510 * sizeof yynewStates
[0]));
1511 if (yynewStates
== YY_NULL
)
1512 yyMemoryExhausted (yystackp
);
1513 yystackp
->yytops
.yystates
= yynewStates
;
1515 yynewLookaheadNeeds
=
1516 (yybool
*) YYREALLOC (yystackp
->yytops
.yylookaheadNeeds
,
1517 (yystackp
->yytops
.yycapacity
1518 * sizeof yynewLookaheadNeeds
[0]));
1519 if (yynewLookaheadNeeds
== YY_NULL
)
1520 yyMemoryExhausted (yystackp
);
1521 yystackp
->yytops
.yylookaheadNeeds
= yynewLookaheadNeeds
;
1523 yystackp
->yytops
.yystates
[yystackp
->yytops
.yysize
]
1524 = yystackp
->yytops
.yystates
[yyk
];
1525 yystackp
->yytops
.yylookaheadNeeds
[yystackp
->yytops
.yysize
]
1526 = yystackp
->yytops
.yylookaheadNeeds
[yyk
];
1527 yystackp
->yytops
.yysize
+= 1;
1528 return yystackp
->yytops
.yysize
-1;
1531 /** True iff Y0 and Y1 represent identical options at the top level.
1532 * That is, they represent the same rule applied to RHS symbols
1533 * that produce the same terminal symbols. */
1535 yyidenticalOptions (yySemanticOption
* yyy0
, yySemanticOption
* yyy1
)
1537 if (yyy0
->yyrule
== yyy1
->yyrule
)
1539 yyGLRState
*yys0
, *yys1
;
1541 for (yys0
= yyy0
->yystate
, yys1
= yyy1
->yystate
,
1542 yyn
= yyrhsLength (yyy0
->yyrule
);
1544 yys0
= yys0
->yypred
, yys1
= yys1
->yypred
, yyn
-= 1)
1545 if (yys0
->yyposn
!= yys1
->yyposn
)
1553 /** Assuming identicalOptions (Y0,Y1), destructively merge the
1554 * alternative semantic values for the RHS-symbols of Y1 and Y0. */
1556 yymergeOptionSets (yySemanticOption
* yyy0
, yySemanticOption
* yyy1
)
1558 yyGLRState
*yys0
, *yys1
;
1560 for (yys0
= yyy0
->yystate
, yys1
= yyy1
->yystate
,
1561 yyn
= yyrhsLength (yyy0
->yyrule
);
1563 yys0
= yys0
->yypred
, yys1
= yys1
->yypred
, yyn
-= 1)
1567 else if (yys0
->yyresolved
)
1569 yys1
->yyresolved
= yytrue
;
1570 yys1
->yysemantics
.yysval
= yys0
->yysemantics
.yysval
;
1572 else if (yys1
->yyresolved
)
1574 yys0
->yyresolved
= yytrue
;
1575 yys0
->yysemantics
.yysval
= yys1
->yysemantics
.yysval
;
1579 yySemanticOption
** yyz0p
= &yys0
->yysemantics
.yyfirstVal
;
1580 yySemanticOption
* yyz1
= yys1
->yysemantics
.yyfirstVal
;
1581 while (YYID (yytrue
))
1583 if (yyz1
== *yyz0p
|| yyz1
== YY_NULL
)
1585 else if (*yyz0p
== YY_NULL
)
1590 else if (*yyz0p
< yyz1
)
1592 yySemanticOption
* yyz
= *yyz0p
;
1594 yyz1
= yyz1
->yynext
;
1595 (*yyz0p
)->yynext
= yyz
;
1597 yyz0p
= &(*yyz0p
)->yynext
;
1599 yys1
->yysemantics
.yyfirstVal
= yys0
->yysemantics
.yyfirstVal
;
1604 /** Y0 and Y1 represent two possible actions to take in a given
1605 * parsing state; return 0 if no combination is possible,
1606 * 1 if user-mergeable, 2 if Y0 is preferred, 3 if Y1 is preferred. */
1608 yypreference (yySemanticOption
* y0
, yySemanticOption
* y1
)
1610 yyRuleNum r0
= y0
->yyrule
, r1
= y1
->yyrule
;
1611 int p0
= yydprec
[r0
], p1
= yydprec
[r1
];
1615 if (yymerger
[r0
] == 0 || yymerger
[r0
] != yymerger
[r1
])
1620 if (p0
== 0 || p1
== 0)
1629 static YYRESULTTAG
yyresolveValue (yyGLRState
* yys
,
1630 yyGLRStack
* yystackp
]b4_user_formals
[);
1633 /** Resolve the previous N states starting at and including state S. If result
1634 * != yyok, some states may have been left unresolved possibly with empty
1635 * semantic option chains. Regardless of whether result = yyok, each state
1636 * has been left with consistent data so that yydestroyGLRState can be invoked
1639 yyresolveStates (yyGLRState
* yys
, int yyn
,
1640 yyGLRStack
* yystackp
]b4_user_formals
[)
1644 YYASSERT (yys
->yypred
);
1645 YYCHK (yyresolveStates (yys
->yypred
, yyn
-1, yystackp
]b4_user_args
[));
1646 if (! yys
->yyresolved
)
1647 YYCHK (yyresolveValue (yys
, yystackp
]b4_user_args
[));
1652 /** Resolve the states for the RHS of OPT, perform its user action, and return
1653 * the semantic value and location. Regardless of whether result = yyok, all
1654 * RHS states have been destroyed (assuming the user action destroys all RHS
1655 * semantic values if invoked). */
1657 yyresolveAction (yySemanticOption
* yyopt
, yyGLRStack
* yystackp
,
1658 YYSTYPE
* yyvalp
]b4_locuser_formals
[)
1660 yyGLRStackItem yyrhsVals
[YYMAXRHS
+ YYMAXLEFT
+ 1];
1661 int yynrhs
= yyrhsLength (yyopt
->yyrule
);
1662 YYRESULTTAG yyflag
=
1663 yyresolveStates (yyopt
->yystate
, yynrhs
, yystackp
]b4_user_args
[);
1667 for (yys
= yyopt
->yystate
; yynrhs
> 0; yys
= yys
->yypred
, yynrhs
-= 1)
1668 yydestroyGLRState ("Cleanup: popping", yys
]b4_user_args
[);
1672 yyrhsVals
[YYMAXRHS
+ YYMAXLEFT
].yystate
.yypred
= yyopt
->yystate
;]b4_locations_if([[
1674 /* Set default location. */
1675 yyrhsVals
[YYMAXRHS
+ YYMAXLEFT
- 1].yystate
.yyloc
= yyopt
->yystate
->yyloc
;]])[
1677 int yychar_current
= yychar
;
1678 YYSTYPE yylval_current
= yylval
;]b4_locations_if([
1679 YYLTYPE yylloc_current
= yylloc
;])[
1680 yychar
= yyopt
->yyrawchar
;
1681 yylval
= yyopt
->yyval
;]b4_locations_if([
1682 yylloc
= yyopt
->yyloc
;])[
1683 yyflag
= yyuserAction (yyopt
->yyrule
, yynrhs
,
1684 yyrhsVals
+ YYMAXRHS
+ YYMAXLEFT
- 1,
1685 yystackp
, yyvalp
]b4_locuser_args
[);
1686 yychar
= yychar_current
;
1687 yylval
= yylval_current
;]b4_locations_if([
1688 yylloc
= yylloc_current
;])[
1693 #if ]b4_api_PREFIX[DEBUG
1695 yyreportTree (yySemanticOption
* yyx
, int yyindent
)
1697 int yynrhs
= yyrhsLength (yyx
->yyrule
);
1700 yyGLRState
* yystates
[1 + YYMAXRHS
];
1701 yyGLRState yyleftmost_state
;
1703 for (yyi
= yynrhs
, yys
= yyx
->yystate
; 0 < yyi
; yyi
-= 1, yys
= yys
->yypred
)
1704 yystates
[yyi
] = yys
;
1707 yyleftmost_state
.yyposn
= 0;
1708 yystates
[0] = &yyleftmost_state
;
1713 if (yyx
->yystate
->yyposn
< yys
->yyposn
+ 1)
1714 YYFPRINTF (stderr
, "%*s%s -> <Rule %d, empty>\n",
1715 yyindent
, "", yytokenName (yylhsNonterm (yyx
->yyrule
)),
1718 YYFPRINTF (stderr
, "%*s%s -> <Rule %d, tokens %lu .. %lu>\n",
1719 yyindent
, "", yytokenName (yylhsNonterm (yyx
->yyrule
)),
1720 yyx
->yyrule
- 1, (unsigned long int) (yys
->yyposn
+ 1),
1721 (unsigned long int) yyx
->yystate
->yyposn
);
1722 for (yyi
= 1; yyi
<= yynrhs
; yyi
+= 1)
1724 if (yystates
[yyi
]->yyresolved
)
1726 if (yystates
[yyi
-1]->yyposn
+1 > yystates
[yyi
]->yyposn
)
1727 YYFPRINTF (stderr
, "%*s%s <empty>\n", yyindent
+2, "",
1728 yytokenName (yyrhs
[yyprhs
[yyx
->yyrule
]+yyi
-1]));
1730 YYFPRINTF (stderr
, "%*s%s <tokens %lu .. %lu>\n", yyindent
+2, "",
1731 yytokenName (yyrhs
[yyprhs
[yyx
->yyrule
]+yyi
-1]),
1732 (unsigned long int) (yystates
[yyi
- 1]->yyposn
+ 1),
1733 (unsigned long int) yystates
[yyi
]->yyposn
);
1736 yyreportTree (yystates
[yyi
]->yysemantics
.yyfirstVal
, yyindent
+2);
1741 /*ARGSUSED*/ static YYRESULTTAG
1742 yyreportAmbiguity (yySemanticOption
* yyx0
,
1743 yySemanticOption
* yyx1
]b4_pure_formals
[)
1748 #if ]b4_api_PREFIX[DEBUG
1749 YYFPRINTF (stderr
, "Ambiguity detected.\n");
1750 YYFPRINTF (stderr
, "Option 1,\n");
1751 yyreportTree (yyx0
, 2);
1752 YYFPRINTF (stderr
, "\nOption 2,\n");
1753 yyreportTree (yyx1
, 2);
1754 YYFPRINTF (stderr
, "\n");
1757 yyerror (]b4_yyerror_args
[YY_("syntax is ambiguous"));
1759 }]b4_locations_if([[
1761 /** Starting at and including state S1, resolve the location for each of the
1762 * previous N1 states that is unresolved. The first semantic option of a state
1763 * is always chosen. */
1765 yyresolveLocations (yyGLRState
* yys1
, int yyn1
,
1766 yyGLRStack
*yystackp
]b4_user_formals
[)
1770 yyresolveLocations (yys1
->yypred
, yyn1
- 1, yystackp
]b4_user_args
[);
1771 if (!yys1
->yyresolved
)
1773 yyGLRStackItem yyrhsloc
[1 + YYMAXRHS
];
1775 yySemanticOption
*yyoption
= yys1
->yysemantics
.yyfirstVal
;
1776 YYASSERT (yyoption
!= YY_NULL
);
1777 yynrhs
= yyrhsLength (yyoption
->yyrule
);
1782 yyresolveLocations (yyoption
->yystate
, yynrhs
,
1783 yystackp
]b4_user_args
[);
1784 for (yys
= yyoption
->yystate
, yyn
= yynrhs
;
1786 yys
= yys
->yypred
, yyn
-= 1)
1787 yyrhsloc
[yyn
].yystate
.yyloc
= yys
->yyloc
;
1791 /* Both yyresolveAction and yyresolveLocations traverse the GSS
1792 in reverse rightmost order. It is only necessary to invoke
1793 yyresolveLocations on a subforest for which yyresolveAction
1794 would have been invoked next had an ambiguity not been
1795 detected. Thus the location of the previous state (but not
1796 necessarily the previous state itself) is guaranteed to be
1797 resolved already. */
1798 yyGLRState
*yyprevious
= yyoption
->yystate
;
1799 yyrhsloc
[0].yystate
.yyloc
= yyprevious
->yyloc
;
1802 int yychar_current
= yychar
;
1803 YYSTYPE yylval_current
= yylval
;
1804 YYLTYPE yylloc_current
= yylloc
;
1805 yychar
= yyoption
->yyrawchar
;
1806 yylval
= yyoption
->yyval
;
1807 yylloc
= yyoption
->yyloc
;
1808 YYLLOC_DEFAULT ((yys1
->yyloc
), yyrhsloc
, yynrhs
);
1809 yychar
= yychar_current
;
1810 yylval
= yylval_current
;
1811 yylloc
= yylloc_current
;
1817 /** Resolve the ambiguity represented in state S, perform the indicated
1818 * actions, and set the semantic value of S. If result != yyok, the chain of
1819 * semantic options in S has been cleared instead or it has been left
1820 * unmodified except that redundant options may have been removed. Regardless
1821 * of whether result = yyok, S has been left with consistent data so that
1822 * yydestroyGLRState can be invoked if necessary. */
1824 yyresolveValue (yyGLRState
* yys
, yyGLRStack
* yystackp
]b4_user_formals
[)
1826 yySemanticOption
* yyoptionList
= yys
->yysemantics
.yyfirstVal
;
1827 yySemanticOption
* yybest
= yyoptionList
;
1828 yySemanticOption
** yypp
;
1829 yybool yymerge
= yyfalse
;
1831 YYRESULTTAG yyflag
;]b4_locations_if([
1832 YYLTYPE
*yylocp
= &yys
->yyloc
;])[
1834 for (yypp
= &yyoptionList
->yynext
; *yypp
!= YY_NULL
; )
1836 yySemanticOption
* yyp
= *yypp
;
1838 if (yyidenticalOptions (yybest
, yyp
))
1840 yymergeOptionSets (yybest
, yyp
);
1841 *yypp
= yyp
->yynext
;
1845 switch (yypreference (yybest
, yyp
))
1847 case 0:]b4_locations_if([[
1848 yyresolveLocations (yys
, 1, yystackp
]b4_user_args
[);]])[
1849 return yyreportAmbiguity (yybest
, yyp
]b4_pure_args
[);
1861 /* This cannot happen so it is not worth a YYASSERT (yyfalse),
1862 but some compilers complain if the default case is
1866 yypp
= &yyp
->yynext
;
1872 yySemanticOption
* yyp
;
1873 int yyprec
= yydprec
[yybest
->yyrule
];
1874 yyflag
= yyresolveAction (yybest
, yystackp
, &yysval
]b4_locuser_args
[);
1876 for (yyp
= yybest
->yynext
; yyp
!= YY_NULL
; yyp
= yyp
->yynext
)
1878 if (yyprec
== yydprec
[yyp
->yyrule
])
1880 YYSTYPE yysval_other
;]b4_locations_if([
1882 yyflag
= yyresolveAction (yyp
, yystackp
, &yysval_other
]b4_locuser_args([&yydummy
])[);
1885 yydestruct ("Cleanup: discarding incompletely merged value for",
1886 yystos
[yys
->yylrState
],
1887 &yysval
]b4_locuser_args
[);
1890 yyuserMerge (yymerger
[yyp
->yyrule
], &yysval
, &yysval_other
);
1895 yyflag
= yyresolveAction (yybest
, yystackp
, &yysval
]b4_locuser_args([yylocp
])[);
1899 yys
->yyresolved
= yytrue
;
1900 yys
->yysemantics
.yysval
= yysval
;
1903 yys
->yysemantics
.yyfirstVal
= YY_NULL
;
1908 yyresolveStack (yyGLRStack
* yystackp
]b4_user_formals
[)
1910 if (yystackp
->yysplitPoint
!= YY_NULL
)
1915 for (yyn
= 0, yys
= yystackp
->yytops
.yystates
[0];
1916 yys
!= yystackp
->yysplitPoint
;
1917 yys
= yys
->yypred
, yyn
+= 1)
1919 YYCHK (yyresolveStates (yystackp
->yytops
.yystates
[0], yyn
, yystackp
1926 yycompressStack (yyGLRStack
* yystackp
)
1928 yyGLRState
* yyp
, *yyq
, *yyr
;
1930 if (yystackp
->yytops
.yysize
!= 1 || yystackp
->yysplitPoint
== YY_NULL
)
1933 for (yyp
= yystackp
->yytops
.yystates
[0], yyq
= yyp
->yypred
, yyr
= YY_NULL
;
1934 yyp
!= yystackp
->yysplitPoint
;
1935 yyr
= yyp
, yyp
= yyq
, yyq
= yyp
->yypred
)
1938 yystackp
->yyspaceLeft
+= yystackp
->yynextFree
- yystackp
->yyitems
;
1939 yystackp
->yynextFree
= ((yyGLRStackItem
*) yystackp
->yysplitPoint
) + 1;
1940 yystackp
->yyspaceLeft
-= yystackp
->yynextFree
- yystackp
->yyitems
;
1941 yystackp
->yysplitPoint
= YY_NULL
;
1942 yystackp
->yylastDeleted
= YY_NULL
;
1944 while (yyr
!= YY_NULL
)
1946 yystackp
->yynextFree
->yystate
= *yyr
;
1948 yystackp
->yynextFree
->yystate
.yypred
= &yystackp
->yynextFree
[-1].yystate
;
1949 yystackp
->yytops
.yystates
[0] = &yystackp
->yynextFree
->yystate
;
1950 yystackp
->yynextFree
+= 1;
1951 yystackp
->yyspaceLeft
-= 1;
1956 yyprocessOneStack (yyGLRStack
* yystackp
, size_t yyk
,
1957 size_t yyposn
]b4_pure_formals
[)
1960 const short int* yyconflicts
;
1963 while (yystackp
->yytops
.yystates
[yyk
] != YY_NULL
)
1965 yyStateNum yystate
= yystackp
->yytops
.yystates
[yyk
]->yylrState
;
1966 YYDPRINTF ((stderr
, "Stack %lu Entering state %d\n",
1967 (unsigned long int) yyk
, yystate
));
1969 YYASSERT (yystate
!= YYFINAL
);
1971 if (yyisDefaultedState (yystate
))
1973 yyrule
= yydefaultAction (yystate
);
1976 YYDPRINTF ((stderr
, "Stack %lu dies.\n",
1977 (unsigned long int) yyk
));
1978 yymarkStackDeleted (yystackp
, yyk
);
1981 YYCHK (yyglrReduce (yystackp
, yyk
, yyrule
, yyfalse
]b4_user_args
[));
1986 yystackp
->yytops
.yylookaheadNeeds
[yyk
] = yytrue
;
1987 if (yychar
== YYEMPTY
)
1989 YYDPRINTF ((stderr
, "Reading a token: "));
1993 if (yychar
<= YYEOF
)
1995 yychar
= yytoken
= YYEOF
;
1996 YYDPRINTF ((stderr
, "Now at end of input.\n"));
2000 yytoken
= YYTRANSLATE (yychar
);
2001 YY_SYMBOL_PRINT ("Next token is", yytoken
, &yylval
, &yylloc
);
2004 yygetLRActions (yystate
, yytoken
, &yyaction
, &yyconflicts
);
2006 while (*yyconflicts
!= 0)
2008 size_t yynewStack
= yysplitStack (yystackp
, yyk
);
2009 YYDPRINTF ((stderr
, "Splitting off stack %lu from %lu.\n",
2010 (unsigned long int) yynewStack
,
2011 (unsigned long int) yyk
));
2012 YYCHK (yyglrReduce (yystackp
, yynewStack
,
2013 *yyconflicts
, yyfalse
]b4_user_args
[));
2014 YYCHK (yyprocessOneStack (yystackp
, yynewStack
,
2015 yyposn
]b4_pure_args
[));
2019 if (yyisShiftAction (yyaction
))
2021 else if (yyisErrorAction (yyaction
))
2023 YYDPRINTF ((stderr
, "Stack %lu dies.\n",
2024 (unsigned long int) yyk
));
2025 yymarkStackDeleted (yystackp
, yyk
);
2029 YYCHK (yyglrReduce (yystackp
, yyk
, -yyaction
,
2030 yyfalse
]b4_user_args
[));
2036 /*ARGSUSED*/ static void
2037 yyreportSyntaxError (yyGLRStack
* yystackp
]b4_user_formals
[)
2039 if (yystackp
->yyerrState
!= 0)
2041 #if ! YYERROR_VERBOSE
2042 yyerror (]b4_lyyerror_args
[YY_("syntax error"));
2044 yySymbol yytoken
= yychar
== YYEMPTY
? YYEMPTY
: YYTRANSLATE (yychar
);
2045 size_t yysize0
= yytnamerr (YY_NULL
, yytokenName (yytoken
));
2046 size_t yysize
= yysize0
;
2048 yybool yysize_overflow
= yyfalse
;
2049 char* yymsg
= YY_NULL
;
2050 enum { YYERROR_VERBOSE_ARGS_MAXIMUM
= 5 };
2051 /* Internationalized format string. */
2052 const char *yyformat
= YY_NULL
;
2053 /* Arguments of yyformat. */
2054 char const *yyarg
[YYERROR_VERBOSE_ARGS_MAXIMUM
];
2055 /* Number of reported tokens (one for the "unexpected", one per
2059 /* There are many possibilities here to consider:
2060 - If this state is a consistent state with a default action, then
2061 the only way this function was invoked is if the default action
2062 is an error action. In that case, don't check for expected
2063 tokens because there are none.
2064 - The only way there can be no lookahead present (in yychar) is if
2065 this state is a consistent state with a default action. Thus,
2066 detecting the absence of a lookahead is sufficient to determine
2067 that there is no unexpected or expected token to report. In that
2068 case, just report a simple "syntax error".
2069 - Don't assume there isn't a lookahead just because this state is a
2070 consistent state with a default action. There might have been a
2071 previous inconsistent state, consistent state with a non-default
2072 action, or user semantic action that manipulated yychar.
2073 - Of course, the expected token list depends on states to have
2074 correct lookahead information, and it depends on the parser not
2075 to perform extra reductions after fetching a lookahead from the
2076 scanner and before detecting a syntax error. Thus, state merging
2077 (from LALR or IELR) and default reductions corrupt the expected
2078 token list. However, the list is correct for canonical LR with
2079 one exception: it will still contain any token that will not be
2080 accepted due to an error action in a later state.
2082 if (yytoken
!= YYEMPTY
)
2084 int yyn
= yypact
[yystackp
->yytops
.yystates
[0]->yylrState
];
2085 yyarg
[yycount
++] = yytokenName (yytoken
);
2086 if (!yypact_value_is_default (yyn
))
2088 /* Start YYX at -YYN if negative to avoid negative indexes in
2089 YYCHECK. In other words, skip the first -YYN actions for this
2090 state because they are default actions. */
2091 int yyxbegin
= yyn
< 0 ? -yyn
: 0;
2092 /* Stay within bounds of both yycheck and yytname. */
2093 int yychecklim
= YYLAST
- yyn
+ 1;
2094 int yyxend
= yychecklim
< YYNTOKENS
? yychecklim
: YYNTOKENS
;
2096 for (yyx
= yyxbegin
; yyx
< yyxend
; ++yyx
)
2097 if (yycheck
[yyx
+ yyn
] == yyx
&& yyx
!= YYTERROR
2098 && !yytable_value_is_error (yytable
[yyx
+ yyn
]))
2100 if (yycount
== YYERROR_VERBOSE_ARGS_MAXIMUM
)
2106 yyarg
[yycount
++] = yytokenName (yyx
);
2107 yysize1
= yysize
+ yytnamerr (YY_NULL
, yytokenName (yyx
));
2108 yysize_overflow
|= yysize1
< yysize
;
2116 #define YYCASE_(N, S) \
2120 YYCASE_(0, YY_("syntax error"));
2121 YYCASE_(1, YY_("syntax error, unexpected %s"));
2122 YYCASE_(2, YY_("syntax error, unexpected %s, expecting %s"));
2123 YYCASE_(3, YY_("syntax error, unexpected %s, expecting %s or %s"));
2124 YYCASE_(4, YY_("syntax error, unexpected %s, expecting %s or %s or %s"));
2125 YYCASE_(5, YY_("syntax error, unexpected %s, expecting %s or %s or %s or %s"));
2129 yysize1
= yysize
+ strlen (yyformat
);
2130 yysize_overflow
|= yysize1
< yysize
;
2133 if (!yysize_overflow
)
2134 yymsg
= (char *) YYMALLOC (yysize
);
2140 while ((*yyp
= *yyformat
))
2142 if (*yyp
== '%' && yyformat
[1] == 's' && yyi
< yycount
)
2144 yyp
+= yytnamerr (yyp
, yyarg
[yyi
++]);
2153 yyerror (]b4_lyyerror_args
[yymsg
);
2158 yyerror (]b4_lyyerror_args
[YY_("syntax error"));
2159 yyMemoryExhausted (yystackp
);
2161 #endif /* YYERROR_VERBOSE */
2165 /* Recover from a syntax error on *YYSTACKP, assuming that *YYSTACKP->YYTOKENP,
2166 yylval, and yylloc are the syntactic category, semantic value, and location
2167 of the lookahead. */
2168 /*ARGSUSED*/ static void
2169 yyrecoverSyntaxError (yyGLRStack
* yystackp
]b4_user_formals
[)
2174 if (yystackp
->yyerrState
== 3)
2175 /* We just shifted the error token and (perhaps) took some
2176 reductions. Skip tokens until we can proceed. */
2177 while (YYID (yytrue
))
2180 if (yychar
== YYEOF
)
2181 yyFail (yystackp
][]b4_lpure_args
[, YY_NULL
);
2182 if (yychar
!= YYEMPTY
)
2183 {]b4_locations_if([[
2184 /* We throw away the lookahead, but the error range
2185 of the shifted error token must take it into account. */
2186 yyGLRState
*yys
= yystackp
->yytops
.yystates
[0];
2187 yyGLRStackItem yyerror_range
[3];
2188 yyerror_range
[1].yystate
.yyloc
= yys
->yyloc
;
2189 yyerror_range
[2].yystate
.yyloc
= yylloc
;
2190 YYLLOC_DEFAULT ((yys
->yyloc
), yyerror_range
, 2);]])[
2191 yytoken
= YYTRANSLATE (yychar
);
2192 yydestruct ("Error: discarding",
2193 yytoken
, &yylval
]b4_locuser_args([&yylloc
])[);
2195 YYDPRINTF ((stderr
, "Reading a token: "));
2197 if (yychar
<= YYEOF
)
2199 yychar
= yytoken
= YYEOF
;
2200 YYDPRINTF ((stderr
, "Now at end of input.\n"));
2204 yytoken
= YYTRANSLATE (yychar
);
2205 YY_SYMBOL_PRINT ("Next token is", yytoken
, &yylval
, &yylloc
);
2207 yyj
= yypact
[yystackp
->yytops
.yystates
[0]->yylrState
];
2208 if (yypact_value_is_default (yyj
))
2211 if (yyj
< 0 || YYLAST
< yyj
|| yycheck
[yyj
] != yytoken
)
2213 if (yydefact
[yystackp
->yytops
.yystates
[0]->yylrState
] != 0)
2216 else if (! yytable_value_is_error (yytable
[yyj
]))
2220 /* Reduce to one stack. */
2221 for (yyk
= 0; yyk
< yystackp
->yytops
.yysize
; yyk
+= 1)
2222 if (yystackp
->yytops
.yystates
[yyk
] != YY_NULL
)
2224 if (yyk
>= yystackp
->yytops
.yysize
)
2225 yyFail (yystackp
][]b4_lpure_args
[, YY_NULL
);
2226 for (yyk
+= 1; yyk
< yystackp
->yytops
.yysize
; yyk
+= 1)
2227 yymarkStackDeleted (yystackp
, yyk
);
2228 yyremoveDeletes (yystackp
);
2229 yycompressStack (yystackp
);
2231 /* Now pop stack until we find a state that shifts the error token. */
2232 yystackp
->yyerrState
= 3;
2233 while (yystackp
->yytops
.yystates
[0] != YY_NULL
)
2235 yyGLRState
*yys
= yystackp
->yytops
.yystates
[0];
2236 yyj
= yypact
[yys
->yylrState
];
2237 if (! yypact_value_is_default (yyj
))
2240 if (0 <= yyj
&& yyj
<= YYLAST
&& yycheck
[yyj
] == YYTERROR
2241 && yyisShiftAction (yytable
[yyj
]))
2243 /* Shift the error token. */]b4_locations_if([[
2244 /* First adjust its location.*/
2246 yystackp
->yyerror_range
[2].yystate
.yyloc
= yylloc
;
2247 YYLLOC_DEFAULT (yyerrloc
, (yystackp
->yyerror_range
), 2);]])[
2248 YY_SYMBOL_PRINT ("Shifting", yystos
[yytable
[yyj
]],
2249 &yylval
, &yyerrloc
);
2250 yyglrShift (yystackp
, 0, yytable
[yyj
],
2251 yys
->yyposn
, &yylval
]b4_locations_if([, &yyerrloc
])[);
2252 yys
= yystackp
->yytops
.yystates
[0];
2255 }]b4_locations_if([[
2256 yystackp
->yyerror_range
[1].yystate
.yyloc
= yys
->yyloc
;]])[
2257 if (yys
->yypred
!= YY_NULL
)
2258 yydestroyGLRState ("Error: popping", yys
]b4_user_args
[);
2259 yystackp
->yytops
.yystates
[0] = yys
->yypred
;
2260 yystackp
->yynextFree
-= 1;
2261 yystackp
->yyspaceLeft
+= 1;
2263 if (yystackp
->yytops
.yystates
[0] == YY_NULL
)
2264 yyFail (yystackp
][]b4_lpure_args
[, YY_NULL
);
2267 #define YYCHK1(YYE) \
2277 goto yyuser_error; \
2288 ]b4_c_ansi_function_def([yyparse
], [int], b4_parse_param
)[
2292 yyGLRStack
* const yystackp
= &yystack
;
2295 YYDPRINTF ((stderr
, "Starting parse\n"));
2298 yylval
= yyval_default
;]b4_locations_if([
2299 yylloc
= yyloc_default
;])[
2300 ]m4_ifdef([b4_initial_action
], [
2301 b4_dollar_pushdef([yylval
], [], [yylloc
])dnl
2302 /* User initialization code. */
2303 b4_user_initial_action
2304 b4_dollar_popdef
])[]dnl
2306 if (! yyinitGLRStack (yystackp
, YYINITDEPTH
))
2307 goto yyexhaustedlab
;
2308 switch (YYSETJMP (yystack
.yyexception_buffer
))
2311 case 1: goto yyabortlab
;
2312 case 2: goto yyexhaustedlab
;
2313 default: goto yybuglab
;
2315 yyglrShift (&yystack
, 0, 0, 0, &yylval
]b4_locations_if([, &yylloc
])[);
2318 while (YYID (yytrue
))
2320 /* For efficiency, we have two loops, the first of which is
2321 specialized to deterministic operation (single stack, no
2322 potential ambiguity). */
2324 while (YYID (yytrue
))
2328 const short int* yyconflicts
;
2330 yyStateNum yystate
= yystack
.yytops
.yystates
[0]->yylrState
;
2331 YYDPRINTF ((stderr
, "Entering state %d\n", yystate
));
2332 if (yystate
== YYFINAL
)
2334 if (yyisDefaultedState (yystate
))
2336 yyrule
= yydefaultAction (yystate
);
2339 ]b4_locations_if([[ yystack
.yyerror_range
[1].yystate
.yyloc
= yylloc
;]])[
2340 yyreportSyntaxError (&yystack
]b4_user_args
[);
2343 YYCHK1 (yyglrReduce (&yystack
, 0, yyrule
, yytrue
]b4_user_args
[));
2348 if (yychar
== YYEMPTY
)
2350 YYDPRINTF ((stderr
, "Reading a token: "));
2354 if (yychar
<= YYEOF
)
2356 yychar
= yytoken
= YYEOF
;
2357 YYDPRINTF ((stderr
, "Now at end of input.\n"));
2361 yytoken
= YYTRANSLATE (yychar
);
2362 YY_SYMBOL_PRINT ("Next token is", yytoken
, &yylval
, &yylloc
);
2365 yygetLRActions (yystate
, yytoken
, &yyaction
, &yyconflicts
);
2366 if (*yyconflicts
!= 0)
2368 if (yyisShiftAction (yyaction
))
2370 YY_SYMBOL_PRINT ("Shifting", yytoken
, &yylval
, &yylloc
);
2373 yyglrShift (&yystack
, 0, yyaction
, yyposn
, &yylval
]b4_locations_if([, &yylloc
])[);
2374 if (0 < yystack
.yyerrState
)
2375 yystack
.yyerrState
-= 1;
2377 else if (yyisErrorAction (yyaction
))
2379 ]b4_locations_if([[ yystack
.yyerror_range
[1].yystate
.yyloc
= yylloc
;]])[
2380 yyreportSyntaxError (&yystack
]b4_user_args
[);
2384 YYCHK1 (yyglrReduce (&yystack
, 0, -yyaction
, yytrue
]b4_user_args
[));
2388 while (YYID (yytrue
))
2390 yySymbol yytoken_to_shift
;
2393 for (yys
= 0; yys
< yystack
.yytops
.yysize
; yys
+= 1)
2394 yystackp
->yytops
.yylookaheadNeeds
[yys
] = yychar
!= YYEMPTY
;
2396 /* yyprocessOneStack returns one of three things:
2398 - An error flag. If the caller is yyprocessOneStack, it
2399 immediately returns as well. When the caller is finally
2400 yyparse, it jumps to an error label via YYCHK1.
2402 - yyok, but yyprocessOneStack has invoked yymarkStackDeleted
2403 (&yystack, yys), which sets the top state of yys to NULL. Thus,
2404 yyparse's following invocation of yyremoveDeletes will remove
2407 - yyok, when ready to shift a token.
2409 Except in the first case, yyparse will invoke yyremoveDeletes and
2410 then shift the next token onto all remaining stacks. This
2411 synchronization of the shift (that is, after all preceding
2412 reductions on all stacks) helps prevent double destructor calls
2413 on yylval in the event of memory exhaustion. */
2415 for (yys
= 0; yys
< yystack
.yytops
.yysize
; yys
+= 1)
2416 YYCHK1 (yyprocessOneStack (&yystack
, yys
, yyposn
]b4_lpure_args
[));
2417 yyremoveDeletes (&yystack
);
2418 if (yystack
.yytops
.yysize
== 0)
2420 yyundeleteLastStack (&yystack
);
2421 if (yystack
.yytops
.yysize
== 0)
2422 yyFail (&yystack
][]b4_lpure_args
[, YY_("syntax error"));
2423 YYCHK1 (yyresolveStack (&yystack
]b4_user_args
[));
2424 YYDPRINTF ((stderr
, "Returning to deterministic operation.\n"));
2425 ]b4_locations_if([[ yystack
.yyerror_range
[1].yystate
.yyloc
= yylloc
;]])[
2426 yyreportSyntaxError (&yystack
]b4_user_args
[);
2430 /* If any yyglrShift call fails, it will fail after shifting. Thus,
2431 a copy of yylval will already be on stack 0 in the event of a
2432 failure in the following loop. Thus, yychar is set to YYEMPTY
2433 before the loop to make sure the user destructor for yylval isn't
2435 yytoken_to_shift
= YYTRANSLATE (yychar
);
2438 for (yys
= 0; yys
< yystack
.yytops
.yysize
; yys
+= 1)
2441 const short int* yyconflicts
;
2442 yyStateNum yystate
= yystack
.yytops
.yystates
[yys
]->yylrState
;
2443 yygetLRActions (yystate
, yytoken_to_shift
, &yyaction
,
2445 /* Note that yyconflicts were handled by yyprocessOneStack. */
2446 YYDPRINTF ((stderr
, "On stack %lu, ", (unsigned long int) yys
));
2447 YY_SYMBOL_PRINT ("shifting", yytoken_to_shift
, &yylval
, &yylloc
);
2448 yyglrShift (&yystack
, yys
, yyaction
, yyposn
,
2449 &yylval
]b4_locations_if([, &yylloc
])[);
2450 YYDPRINTF ((stderr
, "Stack %lu now in state #%d\n",
2451 (unsigned long int) yys
,
2452 yystack
.yytops
.yystates
[yys
]->yylrState
));
2455 if (yystack
.yytops
.yysize
== 1)
2457 YYCHK1 (yyresolveStack (&yystack
]b4_user_args
[));
2458 YYDPRINTF ((stderr
, "Returning to deterministic operation.\n"));
2459 yycompressStack (&yystack
);
2465 yyrecoverSyntaxError (&yystack
]b4_user_args
[);
2466 yyposn
= yystack
.yytops
.yystates
[0]->yyposn
;
2482 yyerror (]b4_lyyerror_args
[YY_("memory exhausted"));
2487 if (yychar
!= YYEMPTY
)
2488 yydestruct ("Cleanup: discarding lookahead",
2489 YYTRANSLATE (yychar
), &yylval
]b4_locuser_args([&yylloc
])[);
2491 /* If the stack is well-formed, pop the stack until it is empty,
2492 destroying its entries as we go. But free the stack regardless
2493 of whether it is well-formed. */
2494 if (yystack
.yyitems
)
2496 yyGLRState
** yystates
= yystack
.yytops
.yystates
;
2499 size_t yysize
= yystack
.yytops
.yysize
;
2501 for (yyk
= 0; yyk
< yysize
; yyk
+= 1)
2504 while (yystates
[yyk
])
2506 yyGLRState
*yys
= yystates
[yyk
];
2507 ]b4_locations_if([[ yystack
.yyerror_range
[1].yystate
.yyloc
= yys
->yyloc
;]]
2508 )[ if (yys
->yypred
!= YY_NULL
)
2509 yydestroyGLRState ("Cleanup: popping", yys
]b4_user_args
[);
2510 yystates
[yyk
] = yys
->yypred
;
2511 yystack
.yynextFree
-= 1;
2512 yystack
.yyspaceLeft
+= 1;
2517 yyfreeGLRStack (&yystack
);
2520 /* Make sure YYID is used. */
2521 return YYID (yyresult
);
2524 /* DEBUGGING ONLY */
2525 #if ]b4_api_PREFIX[DEBUG
2526 static void yypstack (yyGLRStack
* yystackp
, size_t yyk
)
2527 __attribute__ ((__unused__
));
2528 static void yypdumpstack (yyGLRStack
* yystackp
) __attribute__ ((__unused__
));
2531 yy_yypstack (yyGLRState
* yys
)
2535 yy_yypstack (yys
->yypred
);
2536 YYFPRINTF (stderr
, " -> ");
2538 YYFPRINTF (stderr
, "%d@@%lu", yys
->yylrState
,
2539 (unsigned long int) yys
->yyposn
);
2543 yypstates (yyGLRState
* yyst
)
2545 if (yyst
== YY_NULL
)
2546 YYFPRINTF (stderr
, "<null>");
2549 YYFPRINTF (stderr
, "\n");
2553 yypstack (yyGLRStack
* yystackp
, size_t yyk
)
2555 yypstates (yystackp
->yytops
.yystates
[yyk
]);
2558 #define YYINDEX(YYX) \
2559 ((YYX) == YY_NULL ? -1 : (yyGLRStackItem*) (YYX) - yystackp->yyitems)
2563 yypdumpstack (yyGLRStack
* yystackp
)
2565 yyGLRStackItem
* yyp
;
2567 for (yyp
= yystackp
->yyitems
; yyp
< yystackp
->yynextFree
; yyp
+= 1)
2569 YYFPRINTF (stderr
, "%3lu. ",
2570 (unsigned long int) (yyp
- yystackp
->yyitems
));
2571 if (*(yybool
*) yyp
)
2573 YYFPRINTF (stderr
, "Res: %d, LR State: %d, posn: %lu, pred: %ld",
2574 yyp
->yystate
.yyresolved
, yyp
->yystate
.yylrState
,
2575 (unsigned long int) yyp
->yystate
.yyposn
,
2576 (long int) YYINDEX (yyp
->yystate
.yypred
));
2577 if (! yyp
->yystate
.yyresolved
)
2578 YYFPRINTF (stderr
, ", firstVal: %ld",
2579 (long int) YYINDEX (yyp
->yystate
2580 .yysemantics
.yyfirstVal
));
2584 YYFPRINTF (stderr
, "Option. rule: %d, state: %ld, next: %ld",
2585 yyp
->yyoption
.yyrule
- 1,
2586 (long int) YYINDEX (yyp
->yyoption
.yystate
),
2587 (long int) YYINDEX (yyp
->yyoption
.yynext
));
2589 YYFPRINTF (stderr
, "\n");
2591 YYFPRINTF (stderr
, "Tops:");
2592 for (yyi
= 0; yyi
< yystackp
->yytops
.yysize
; yyi
+= 1)
2593 YYFPRINTF (stderr
, "%lu: %ld; ", (unsigned long int) yyi
,
2594 (long int) YYINDEX (yystackp
->yytops
.yystates
[yyi
]));
2595 YYFPRINTF (stderr
, "\n");
2600 dnl glr
.cc produces its own header
.
2602 m4_if(b4_skeleton
, ["glr.c"],
2604 [@
output(b4_spec_defines_file@
)@
2605 b4_copyright([Skeleton interface
for Bison GLR parsers in C
],
2608 ]b4_cpp_guard_open([b4_spec_defines_file
])[
2609 ]b4_shared_declarations
[
2610 ]b4_cpp_guard_close([b4_spec_defines_file
])[