3 # GLR skeleton for Bison
5 # Copyright (C) 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009,
6 # 2010 Free Software Foundation, Inc.
8 # This program is free software: you can redistribute it and/or modify
9 # it under the terms of the GNU General Public License as published by
10 # the Free Software Foundation, either version 3 of the License, or
11 # (at your option) any later version.
13 # This program is distributed in the hope that it will be useful,
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 # GNU General Public License for more details.
18 # You should have received a copy of the GNU General Public License
19 # along with this program. If not, see <http://www.gnu.org/licenses/>.
22 m4_include(b4_pkgdatadir
/[c
.m4
])
24 ## ---------------- ##
26 ## ---------------- ##
29 m4_define_default([b4_stack_depth_max
], [10000])
30 m4_define_default([b4_stack_depth_init
], [200])
34 ## ------------------------ ##
35 ## Pure/impure interfaces. ##
36 ## ------------------------ ##
38 b4_define_flag_if([pure
])
39 # If glr.cc is including this file and thus has already set b4_pure_flag, don't
40 # change the value of b4_pure_flag, and don't record a use of api.pure.
41 m4_ifndef([b4_pure_flag
],
42 [b4_percent_define_default([[api
.pure
]], [[false]])
43 m4_define([b4_pure_flag
],
44 [b4_percent_define_flag_if([[api
.pure
]], [[1]], [[0]])])])
48 # The possible parse-params formal arguments preceded by a comma.
50 # This is not shared with yacc.c in c.m4 because GLR relies on ISO C
51 # formal argument declarations.
52 m4_define([b4_user_formals
],
53 [m4_ifset([b4_parse_param
], [, b4_c_ansi_formals(b4_parse_param
)])])
58 # Accumule in b4_lex_param all the yylex arguments.
59 # Yes, this is quite ugly...
60 m4_define([b4_lex_param
],
61 m4_dquote(b4_pure_if([[[[YYSTYPE
*]], [[&yylval
]]][]dnl
62 b4_locations_if([, [[YYLTYPE
*], [&yylloc
]]])])dnl
63 m4_ifdef([b4_lex_param
], [, ]b4_lex_param
)))
68 # Optional effective arguments passed to yyerror: user args plus yylloc, and
70 m4_define([b4_yyerror_args
],
71 [b4_pure_if([b4_locations_if([yylocp
, ])])dnl
72 m4_ifset([b4_parse_param
], [b4_c_args(b4_parse_param
), ])])
77 # Same as above, but on the lookahead, hence &yylloc instead of yylocp.
78 m4_define([b4_lyyerror_args
],
79 [b4_pure_if([b4_locations_if([&yylloc
, ])])dnl
80 m4_ifset([b4_parse_param
], [b4_c_args(b4_parse_param
), ])])
85 # Same as b4_yyerror_args, but with a leading comma.
86 m4_define([b4_pure_args
],
87 [b4_pure_if([b4_locations_if([, yylocp
])])[]b4_user_args
])
92 # Same as above, but on the lookahead, hence &yylloc instead of yylocp.
93 m4_define([b4_lpure_args
],
94 [b4_pure_if([b4_locations_if([, &yylloc
])])[]b4_user_args
])
99 # Arguments passed to yyerror: user formals plus yylocp.
100 m4_define([b4_pure_formals
],
101 [b4_pure_if([b4_locations_if([, YYLTYPE
*yylocp
])])[]b4_user_formals
])
104 ## ----------------- ##
105 ## Semantic Values. ##
106 ## ----------------- ##
109 # b4_lhs_value([TYPE])
110 # --------------------
111 # Expansion of $<TYPE>$.
112 m4_define([b4_lhs_value
],
113 [((*yyvalp
)[]m4_ifval([$
1], [.$
1]))])
116 # b4_rhs_value(RULE-LENGTH, NUM, [TYPE])
117 # --------------------------------------
118 # Expansion of $<TYPE>NUM, where the current rule has RULE-LENGTH
120 m4_define([b4_rhs_value
],
121 [(((yyGLRStackItem
const *)yyvsp
)@
{YYFILL (($
2) - ($
1))@
}.yystate
.yysemantics
.yysval
[]m4_ifval([$
3], [.$
3]))])
132 m4_define([b4_lhs_location
],
136 # b4_rhs_location(RULE-LENGTH, NUM)
137 # ---------------------------------
138 # Expansion of @NUM, where the current rule has RULE-LENGTH symbols
140 m4_define([b4_rhs_location
],
141 [(((yyGLRStackItem
const *)yyvsp
)@
{YYFILL (($
2) - ($
1))@
}.yystate
.yyloc
)])
149 # We do want M4 expansion after # for CPP macros.
152 @
output(b4_parser_file_name@
)@
153 b4_copyright([Skeleton implementation
for Bison GLR parsers in C
],
154 [2002, 2003, 2004, 2005, 2006, 2009, 2010])
156 /* C GLR parser skeleton written by Paul Hilfinger. */
160 b4_percent_code_get([[top]])[]dnl
161 m4_if(b4_prefix
, [yy
], [],
162 [/* Substitute the variable and function names. */
163 #define yyparse b4_prefix[]parse
164 #define yylex b4_prefix[]lex
165 #define yyerror b4_prefix[]error
166 #define yylval b4_prefix[]lval
167 #define yychar b4_prefix[]char
168 #define yydebug b4_prefix[]debug
169 #define yynerrs b4_prefix[]nerrs
170 #define yylloc b4_prefix[]lloc])[
172 /* Copy the first part of user declarations. */
173 ]b4_user_pre_prologue
175 dnl
# b4_shared_declarations
176 dnl
# ----------------------
177 dnl
# Declaration that might either go into the header (if --defines)
178 dnl
# or open coded in the parser body.
179 m4_define([b4_shared_declarations
],
180 [b4_percent_code_get([[requires]])[]dnl
182 b4_token_enums(b4_tokens
)
185 ]m4_ifdef([b4_stype
],
186 [[typedef union ]b4_union_name
[
190 # define YYSTYPE_IS_TRIVIAL 1]],
191 [m4_if(b4_tag_seen_flag
, 0,
192 [[typedef int YYSTYPE
;
193 # define YYSTYPE_IS_TRIVIAL 1]])])[
196 #if ! defined YYLTYPE && ! defined YYLTYPE_IS_DECLARED
197 typedef struct YYLTYPE
208 # define YYLTYPE_IS_DECLARED 1
209 # define YYLTYPE_IS_TRIVIAL 1
212 ]b4_percent_code_get([[provides]])[]dnl
215 b4_defines_if([[#include "@basename(]b4_spec_defines_file[@)"]],
216 [b4_shared_declarations
])[
218 /* Enabling traces. */
220 # define YYDEBUG ]b4_debug_flag[
223 /* Enabling verbose error messages. */
224 #ifdef YYERROR_VERBOSE
225 # undef YYERROR_VERBOSE
226 # define YYERROR_VERBOSE 1
228 # define YYERROR_VERBOSE ]b4_error_verbose_flag[
231 /* Enabling the token table. */
232 #ifndef YYTOKEN_TABLE
233 # define YYTOKEN_TABLE ]b4_token_table[
236 /* Default (constant) value used for initialization for null
237 right-hand sides. Unlike the standard yacc.c template,
238 here we set the default value of $$ to a zeroed-out value.
239 Since the default value is undefined, this behavior is
240 technically correct. */
241 static YYSTYPE yyval_default
;
243 /* Copy the second part of user declarations. */
244 ]b4_user_post_prologue
245 b4_percent_code_get
[]dnl
252 # if defined YYENABLE_NLS && YYENABLE_NLS
254 # include <libintl.h> /* INFRINGES ON USER NAME SPACE */
255 # define YY_(msgid) dgettext ("bison-runtime", msgid)
259 # define YY_(msgid) msgid
263 /* Suppress unused-variable warnings by "using" E. */
264 #if ! defined lint || defined __GNUC__
265 # define YYUSE(e) ((void) (e))
267 # define YYUSE(e) /* empty */
270 /* Identity function, used to suppress warnings about constant conditions. */
274 ]b4_c_function_def([YYID
], [static int], [[int i
], [i
]])[
284 # define YYMALLOC malloc
287 # define YYREALLOC realloc
290 #define YYSIZEMAX ((size_t) -1)
295 typedef unsigned char yybool
;
302 # define YYJMP_BUF jmp_buf
303 # define YYSETJMP(env) setjmp (env)
304 # define YYLONGJMP(env, val) longjmp (env, val)
311 #ifndef __attribute__
312 /* This feature is available in gcc versions 2.5 and later. */
313 # if (! defined __GNUC__ || __GNUC__ < 2 \
314 || (__GNUC__ == 2 && __GNUC_MINOR__ < 5) \
315 || (defined __STRICT_ANSI__ && __STRICT_ANSI__))
316 # define __attribute__(Spec) /* empty */
320 ]b4_locations_if([#define YYOPTIONAL_LOC(Name) Name],[
322 # define YYOPTIONAL_LOC(Name) /* empty */
324 # define YYOPTIONAL_LOC(Name) Name __attribute__ ((__unused__))
328 # define YYASSERT(condition) ((void) ((condition) || (abort (), 0)))
331 /* YYFINAL -- State number of the termination state. */
332 #define YYFINAL ]b4_final_state_number[
333 /* YYLAST -- Last index in YYTABLE. */
334 #define YYLAST ]b4_last[
336 /* YYNTOKENS -- Number of terminals. */
337 #define YYNTOKENS ]b4_tokens_number[
338 /* YYNNTS -- Number of nonterminals. */
339 #define YYNNTS ]b4_nterms_number[
340 /* YYNRULES -- Number of rules. */
341 #define YYNRULES ]b4_rules_number[
342 /* YYNRULES -- Number of states. */
343 #define YYNSTATES ]b4_states_number[
344 /* YYMAXRHS -- Maximum number of symbols on right-hand side of rule. */
345 #define YYMAXRHS ]b4_r2_max[
346 /* YYMAXLEFT -- Maximum number of symbols to the left of a handle
347 accessed by $0, $-1, etc., in any rule. */
348 #define YYMAXLEFT ]b4_max_left_semantic_context[
350 /* YYTRANSLATE(X) -- Bison symbol number corresponding to X. */
351 #define YYUNDEFTOK ]b4_undef_token_number[
352 #define YYMAXUTOK ]b4_user_token_number_max[
354 #define YYTRANSLATE(YYX) \
355 ((unsigned int) (YYX) <= YYMAXUTOK ? yytranslate[YYX] : YYUNDEFTOK)
357 /* YYTRANSLATE[YYLEX] -- Bison symbol number corresponding to YYLEX. */
358 static const ]b4_int_type_for([b4_translate
])[ yytranslate
[] =
364 /* YYPRHS[YYN] -- Index of the first RHS symbol of rule number YYN in
366 static const ]b4_int_type_for([b4_prhs
])[ yyprhs
[] =
371 /* YYRHS -- A `-1'-separated list of the rules' RHS. */
372 static const ]b4_int_type_for([b4_rhs
])[ yyrhs
[] =
377 /* YYRLINE[YYN] -- source line where rule number YYN was defined. */
378 static const ]b4_int_type_for([b4_rline
])[ yyrline
[] =
384 #if YYDEBUG || YYERROR_VERBOSE || YYTOKEN_TABLE
385 /* YYTNAME[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM.
386 First, the terminals, then, starting at YYNTOKENS, nonterminals. */
387 static const char *const yytname
[] =
393 /* YYR1[YYN] -- Symbol number of symbol that rule YYN derives. */
394 static const ]b4_int_type_for([b4_r1
])[ yyr1
[] =
399 /* YYR2[YYN] -- Number of symbols composing right hand side of rule YYN. */
400 static const ]b4_int_type_for([b4_r2
])[ yyr2
[] =
405 /* YYDPREC[RULE-NUM] -- Dynamic precedence of rule #RULE-NUM (0 if none). */
406 static const ]b4_int_type_for([b4_dprec
])[ yydprec
[] =
411 /* YYMERGER[RULE-NUM] -- Index of merging function for rule #RULE-NUM. */
412 static const ]b4_int_type_for([b4_merger
])[ yymerger
[] =
417 /* YYDEFACT[S] -- default rule to reduce with in state S when YYTABLE
418 doesn't specify something else to do. Zero means the default is an
420 static const ]b4_int_type_for([b4_defact
])[ yydefact
[] =
425 /* YYPDEFGOTO[NTERM-NUM]. */
426 static const ]b4_int_type_for([b4_defgoto
])[ yydefgoto
[] =
431 /* YYPACT[STATE-NUM] -- Index in YYTABLE of the portion describing
433 #define YYPACT_NINF ]b4_pact_ninf[
434 static const ]b4_int_type_for([b4_pact
])[ yypact
[] =
439 /* YYPGOTO[NTERM-NUM]. */
440 static const ]b4_int_type_for([b4_pgoto
])[ yypgoto
[] =
445 /* YYTABLE[YYPACT[STATE-NUM]]. What to do in state STATE-NUM. If
446 positive, shift that token. If negative, reduce the rule which
447 number is the opposite. If zero, do what YYDEFACT says.
448 If YYTABLE_NINF, syntax error. */
449 #define YYTABLE_NINF ]b4_table_ninf[
450 static const ]b4_int_type_for([b4_table
])[ yytable
[] =
455 /* YYCONFLP[YYPACT[STATE-NUM]] -- Pointer into YYCONFL of start of
456 list of conflicting reductions corresponding to action entry for
457 state STATE-NUM in yytable. 0 means no conflicts. The list in
458 yyconfl is terminated by a rule number of 0. */
459 static const ]b4_int_type_for([b4_conflict_list_heads
])[ yyconflp
[] =
461 ]b4_conflict_list_heads
[
464 /* YYCONFL[I] -- lists of conflicting rule numbers, each terminated by
465 0, pointed into by YYCONFLP. */
466 ]dnl Do
not use b4_int_type_for here
, since there are places where
467 dnl pointers onto yyconfl are taken
, which type is
"short int *".
468 dnl We probably ought to introduce a type
for confl
.
469 [static const short int yyconfl
[] =
471 ]b4_conflicting_rules
[
474 static const ]b4_int_type_for([b4_check
])[ yycheck
[] =
479 /* YYSTOS[STATE-NUM] -- The (internal number of the) accessing
480 symbol of state STATE-NUM. */
481 static const ]b4_int_type_for([b4_stos
])[ yystos
[] =
487 /* Prevent warning if -Wmissing-prototypes. */
488 ]b4_c_ansi_function_decl([yyparse
], [int], b4_parse_param
)[
490 /* Error token number */
493 /* YYLLOC_DEFAULT -- Set CURRENT to span from RHS[1] to RHS[N].
494 If N is 0, then set CURRENT to the empty location which ends
495 the previous symbol: RHS[0] (always defined). */
498 #define YYRHSLOC(Rhs, K) ((Rhs)[K].yystate.yyloc)
499 #ifndef YYLLOC_DEFAULT
500 # define YYLLOC_DEFAULT(Current, Rhs, N) \
504 (Current).first_line = YYRHSLOC (Rhs, 1).first_line; \
505 (Current).first_column = YYRHSLOC (Rhs, 1).first_column; \
506 (Current).last_line = YYRHSLOC (Rhs, N).last_line; \
507 (Current).last_column = YYRHSLOC (Rhs, N).last_column; \
511 (Current).first_line = (Current).last_line = \
512 YYRHSLOC (Rhs, 0).last_line; \
513 (Current).first_column = (Current).last_column = \
514 YYRHSLOC (Rhs, 0).last_column; \
518 /* YY_LOCATION_PRINT -- Print the location on the stream.
519 This macro was not mandated originally: define only if we know
520 we won't break user code: when these are the locations we know. */
522 # define YY_LOCATION_PRINT(File, Loc) \
523 fprintf (File, "%d.%d-%d.%d", \
524 (Loc).first_line, (Loc).first_column, \
525 (Loc).last_line, (Loc).last_column)
528 #ifndef YYLLOC_DEFAULT
529 # define YYLLOC_DEFAULT(Current, Rhs, N) ((void) 0)
533 #ifndef YY_LOCATION_PRINT
534 # define YY_LOCATION_PRINT(File, Loc) ((void) 0)
538 /* YYLEX -- calling `yylex' with the right arguments. */
539 #define YYLEX ]b4_c_function_call([yylex], [int], b4_lex_param)[
544 #define yynerrs (yystackp->yyerrcnt)
546 #define yychar (yystackp->yyrawchar)
548 #define yylval (yystackp->yyval)
550 #define yylloc (yystackp->yyloc)
551 m4_if(b4_prefix
[], [yy
], [],
552 [#define b4_prefix[]nerrs yynerrs
553 #define b4_prefix[]char yychar
554 #define b4_prefix[]lval yylval
555 #define b4_prefix[]lloc yylloc])],
563 static const int YYEOF
= 0;
564 static const int YYEMPTY
= -2;
566 typedef enum { yyok
, yyaccept
, yyabort
, yyerr
} YYRESULTTAG
;
569 do { YYRESULTTAG yyflag = YYE; if (yyflag != yyok) return yyflag; } \
575 # define YYFPRINTF fprintf
578 # define YYDPRINTF(Args) \
584 ]b4_yy_symbol_print_generate([b4_c_ansi_function_def
])[
586 # define YY_SYMBOL_PRINT(Title, Type, Value, Location) \
590 YYFPRINTF (stderr, "%s ", Title); \
591 yy_symbol_print (stderr, Type, \
592 Value]b4_locations_if([, Location])[]b4_user_args[); \
593 YYFPRINTF (stderr, "\n"); \
597 /* Nonzero means print parse trace. It is left uninitialized so that
598 multiple parsers can coexist. */
603 # define YYDPRINTF(Args)
604 # define YY_SYMBOL_PRINT(Title, Type, Value, Location)
606 #endif /* !YYDEBUG */
608 /* YYINITDEPTH -- initial size of the parser's stacks. */
610 # define YYINITDEPTH ]b4_stack_depth_init[
613 /* YYMAXDEPTH -- maximum size the stacks can grow to (effective only
614 if the built-in stack extension method is used).
616 Do not make this value too large; the results are undefined if
617 SIZE_MAX < YYMAXDEPTH * sizeof (GLRStackItem)
618 evaluated with infinite-precision integer arithmetic. */
621 # define YYMAXDEPTH ]b4_stack_depth_max[
624 /* Minimum number of free items on the stack allowed after an
625 allocation. This is to allow allocation and initialization
626 to be completed by functions that call yyexpandGLRStack before the
627 stack is expanded, thus insuring that all necessary pointers get
628 properly redirected to new data. */
631 #ifndef YYSTACKEXPANDABLE
632 # if (! defined __cplusplus \
633 || (]b4_locations_if([[defined YYLTYPE_IS_TRIVIAL && YYLTYPE_IS_TRIVIAL \
634 && ]])[defined YYSTYPE_IS_TRIVIAL && YYSTYPE_IS_TRIVIAL))
635 # define YYSTACKEXPANDABLE 1
637 # define YYSTACKEXPANDABLE 0
641 #if YYSTACKEXPANDABLE
642 # define YY_RESERVE_GLRSTACK(Yystack) \
644 if (Yystack->yyspaceLeft < YYHEADROOM) \
645 yyexpandGLRStack (Yystack); \
648 # define YY_RESERVE_GLRSTACK(Yystack) \
650 if (Yystack->yyspaceLeft < YYHEADROOM) \
651 yyMemoryExhausted (Yystack); \
659 # if defined __GLIBC__ && defined _STRING_H && defined _GNU_SOURCE
660 # define yystpcpy stpcpy
662 /* Copy YYSRC to YYDEST, returning the address of the terminating '\0' in
665 yystpcpy (char *yydest
, const char *yysrc
)
668 const char *yys
= yysrc
;
670 while ((*yyd
++ = *yys
++) != '\0')
679 /* Copy to YYRES the contents of YYSTR after stripping away unnecessary
680 quotes and backslashes, so that it's suitable for yyerror. The
681 heuristic is that double-quoting is unnecessary unless the string
682 contains an apostrophe, a comma, or backslash (other than
683 backslash-backslash). YYSTR is taken from yytname. If YYRES is
684 null, do not copy; instead, return the length of what the result
687 yytnamerr (char *yyres
, const char *yystr
)
692 char const *yyp
= yystr
;
699 goto do_not_strip_quotes
;
703 goto do_not_strip_quotes
;
716 do_not_strip_quotes
: ;
720 return strlen (yystr
);
722 return yystpcpy (yyres
, yystr
) - yyres
;
726 #endif /* !YYERROR_VERBOSE */
728 /** State numbers, as in LALR(1) machine */
729 typedef int yyStateNum
;
731 /** Rule numbers, as in LALR(1) machine */
732 typedef int yyRuleNum
;
734 /** Grammar symbol */
735 typedef short int yySymbol
;
737 /** Item references, as in LALR(1) machine */
738 typedef short int yyItemNum
;
740 typedef struct yyGLRState yyGLRState
;
741 typedef struct yyGLRStateSet yyGLRStateSet
;
742 typedef struct yySemanticOption yySemanticOption
;
743 typedef union yyGLRStackItem yyGLRStackItem
;
744 typedef struct yyGLRStack yyGLRStack
;
747 /** Type tag: always true. */
749 /** Type tag for yysemantics. If true, yysval applies, otherwise
750 * yyfirstVal applies. */
752 /** Number of corresponding LALR(1) machine state. */
753 yyStateNum yylrState
;
754 /** Preceding state in this stack */
756 /** Source position of the first token produced by my symbol */
759 /** First in a chain of alternative reductions producing the
760 * non-terminal corresponding to this state, threaded through
762 yySemanticOption
* yyfirstVal
;
763 /** Semantic value for this state. */
766 /** Source location for this state. */
770 struct yyGLRStateSet
{
771 yyGLRState
** yystates
;
772 /** During nondeterministic operation, yylookaheadNeeds tracks which
773 * stacks have actually needed the current lookahead. During deterministic
774 * operation, yylookaheadNeeds[0] is not maintained since it would merely
775 * duplicate yychar != YYEMPTY. */
776 yybool
* yylookaheadNeeds
;
777 size_t yysize
, yycapacity
;
780 struct yySemanticOption
{
781 /** Type tag: always false. */
783 /** Rule number for this reduction */
785 /** The last RHS state in the list of states to be reduced. */
787 /** The lookahead for this reduction. */
791 /** Next sibling in chain of options. To facilitate merging,
792 * options are chained in decreasing order by address. */
793 yySemanticOption
* yynext
;
796 /** Type of the items in the GLR stack. The yyisState field
797 * indicates which item of the union is valid. */
798 union yyGLRStackItem
{
800 yySemanticOption yyoption
;
805 ]b4_locations_if([[ /* To compute the location of the error token. */
806 yyGLRStackItem yyerror_range
[3];]])[
814 YYJMP_BUF yyexception_buffer
;
815 yyGLRStackItem
* yyitems
;
816 yyGLRStackItem
* yynextFree
;
818 yyGLRState
* yysplitPoint
;
819 yyGLRState
* yylastDeleted
;
820 yyGLRStateSet yytops
;
823 #if YYSTACKEXPANDABLE
824 static void yyexpandGLRStack (yyGLRStack
* yystackp
);
827 static void yyFail (yyGLRStack
* yystackp
]b4_pure_formals
[, const char* yymsg
)
828 __attribute__ ((__noreturn__
));
830 yyFail (yyGLRStack
* yystackp
]b4_pure_formals
[, const char* yymsg
)
833 yyerror (]b4_yyerror_args
[yymsg
);
834 YYLONGJMP (yystackp
->yyexception_buffer
, 1);
837 static void yyMemoryExhausted (yyGLRStack
* yystackp
)
838 __attribute__ ((__noreturn__
));
840 yyMemoryExhausted (yyGLRStack
* yystackp
)
842 YYLONGJMP (yystackp
->yyexception_buffer
, 2);
845 #if YYDEBUG || YYERROR_VERBOSE
846 /** A printable representation of TOKEN. */
847 static inline const char*
848 yytokenName (yySymbol yytoken
)
850 if (yytoken
== YYEMPTY
)
853 return yytname
[yytoken
];
857 /** Fill in YYVSP[YYLOW1 .. YYLOW0-1] from the chain of states starting
858 * at YYVSP[YYLOW0].yystate.yypred. Leaves YYVSP[YYLOW1].yystate.yypred
859 * containing the pointer to the next state in the chain. */
860 static void yyfillin (yyGLRStackItem
*, int, int) __attribute__ ((__unused__
));
862 yyfillin (yyGLRStackItem
*yyvsp
, int yylow0
, int yylow1
)
866 s
= yyvsp
[yylow0
].yystate
.yypred
;
867 for (i
= yylow0
-1; i
>= yylow1
; i
-= 1)
869 YYASSERT (s
->yyresolved
);
870 yyvsp
[i
].yystate
.yyresolved
= yytrue
;
871 yyvsp
[i
].yystate
.yysemantics
.yysval
= s
->yysemantics
.yysval
;
872 yyvsp
[i
].yystate
.yyloc
= s
->yyloc
;
873 s
= yyvsp
[i
].yystate
.yypred
= s
->yypred
;
877 /* Do nothing if YYNORMAL or if *YYLOW <= YYLOW1. Otherwise, fill in
878 * YYVSP[YYLOW1 .. *YYLOW-1] as in yyfillin and set *YYLOW = YYLOW1.
879 * For convenience, always return YYLOW1. */
880 static inline int yyfill (yyGLRStackItem
*, int *, int, yybool
)
881 __attribute__ ((__unused__
));
883 yyfill (yyGLRStackItem
*yyvsp
, int *yylow
, int yylow1
, yybool yynormal
)
885 if (!yynormal
&& yylow1
< *yylow
)
887 yyfillin (yyvsp
, *yylow
, yylow1
);
893 /** Perform user action for rule number YYN, with RHS length YYRHSLEN,
894 * and top stack item YYVSP. YYLVALP points to place to put semantic
895 * value ($$), and yylocp points to place for location information
896 * (@@$). Returns yyok for normal return, yyaccept for YYACCEPT,
897 * yyerr for YYERROR, yyabort for YYABORT. */
898 /*ARGSUSED*/ static YYRESULTTAG
899 yyuserAction (yyRuleNum yyn
, int yyrhslen
, yyGLRStackItem
* yyvsp
,
901 YYLTYPE
* YYOPTIONAL_LOC (yylocp
),
905 yybool yynormal
__attribute__ ((__unused__
)) =
906 (yystackp
->yysplitPoint
== NULL
);
908 ]b4_parse_param_use
[]dnl
910 # define yyerrok (yystackp->yyerrState = 0)
912 # define YYACCEPT return yyaccept
914 # define YYABORT return yyabort
916 # define YYERROR return yyerrok, yyerr
918 # define YYRECOVERING() (yystackp->yyerrState != 0)
920 # define yyclearin (yychar = YYEMPTY)
922 # define YYFILL(N) yyfill (yyvsp, &yylow, N, yynormal)
924 # define YYBACKUP(Token, Value) \
925 return yyerror (]b4_yyerror_args[YY_("syntax error: cannot back up")), \
930 *yyvalp
= yyval_default
;
932 *yyvalp
= yyvsp
[YYFILL (1-yyrhslen
)].yystate
.yysemantics
.yysval
;
933 YYLLOC_DEFAULT ((*yylocp
), (yyvsp
- yyrhslen
), yyrhslen
);
934 ]b4_locations_if([[ yystackp
->yyerror_range
[1].yystate
.yyloc
= *yylocp
;
953 /*ARGSUSED*/ static void
954 yyuserMerge (int yyn
, YYSTYPE
* yy0
, YYSTYPE
* yy1
)
966 /* Bison grammar-table manipulation. */
968 ]b4_yydestruct_generate([b4_c_ansi_function_def
])[
970 /** Number of symbols composing the right hand side of rule #RULE. */
972 yyrhsLength (yyRuleNum yyrule
)
978 yydestroyGLRState (char const *yymsg
, yyGLRState
*yys
]b4_user_formals
[)
981 yydestruct (yymsg
, yystos
[yys
->yylrState
],
982 &yys
->yysemantics
.yysval
]b4_locations_if([, &yys
->yyloc
])[]b4_user_args
[);
988 if (yys
->yysemantics
.yyfirstVal
)
989 YYFPRINTF (stderr
, "%s unresolved ", yymsg
);
991 YYFPRINTF (stderr
, "%s incomplete ", yymsg
);
992 yy_symbol_print (stderr
, yystos
[yys
->yylrState
],
993 NULL
]b4_locations_if([, &yys
->yyloc
])[]b4_user_args
[);
994 YYFPRINTF (stderr
, "\n");
998 if (yys
->yysemantics
.yyfirstVal
)
1000 yySemanticOption
*yyoption
= yys
->yysemantics
.yyfirstVal
;
1003 for (yyrh
= yyoption
->yystate
, yyn
= yyrhsLength (yyoption
->yyrule
);
1005 yyrh
= yyrh
->yypred
, yyn
-= 1)
1006 yydestroyGLRState (yymsg
, yyrh
]b4_user_args
[);
1011 /** Left-hand-side symbol for rule #RULE. */
1012 static inline yySymbol
1013 yylhsNonterm (yyRuleNum yyrule
)
1015 return yyr1
[yyrule
];
1018 #define yyis_pact_ninf(yystate) \
1019 ]m4_if(m4_eval(b4_pact_ninf < b4_pact_min), [1],
1021 [((yystate
) == YYPACT_NINF
)])[
1023 /** True iff LR state STATE has only a default reduction (regardless
1025 static inline yybool
1026 yyisDefaultedState (yyStateNum yystate
)
1028 return yyis_pact_ninf (yypact
[yystate
]);
1031 /** The default reduction for STATE, assuming it has one. */
1032 static inline yyRuleNum
1033 yydefaultAction (yyStateNum yystate
)
1035 return yydefact
[yystate
];
1038 #define yyis_table_ninf(yytable_value) \
1039 ]m4_if(m4_eval(b4_table_ninf < b4_table_min), [1],
1041 [((yytable_value
) == YYTABLE_NINF
)])[
1043 /** Set *YYACTION to the action to take in YYSTATE on seeing YYTOKEN.
1045 * R < 0: Reduce on rule -R.
1047 * R > 0: Shift to state R.
1048 * Set *CONFLICTS to a pointer into yyconfl to 0-terminated list of
1049 * conflicting reductions.
1052 yygetLRActions (yyStateNum yystate
, int yytoken
,
1053 int* yyaction
, const short int** yyconflicts
)
1055 int yyindex
= yypact
[yystate
] + yytoken
;
1056 if (yyindex
< 0 || YYLAST
< yyindex
|| yycheck
[yyindex
] != yytoken
)
1058 *yyaction
= -yydefact
[yystate
];
1059 *yyconflicts
= yyconfl
;
1061 else if (! yyis_table_ninf (yytable
[yyindex
]))
1063 *yyaction
= yytable
[yyindex
];
1064 *yyconflicts
= yyconfl
+ yyconflp
[yyindex
];
1069 *yyconflicts
= yyconfl
+ yyconflp
[yyindex
];
1073 static inline yyStateNum
1074 yyLRgotoState (yyStateNum yystate
, yySymbol yylhs
)
1077 yyr
= yypgoto
[yylhs
- YYNTOKENS
] + yystate
;
1078 if (0 <= yyr
&& yyr
<= YYLAST
&& yycheck
[yyr
] == yystate
)
1079 return yytable
[yyr
];
1081 return yydefgoto
[yylhs
- YYNTOKENS
];
1084 static inline yybool
1085 yyisShiftAction (int yyaction
)
1087 return 0 < yyaction
;
1090 static inline yybool
1091 yyisErrorAction (int yyaction
)
1093 return yyaction
== 0;
1098 /** Return a fresh GLRStackItem. Callers should call
1099 * YY_RESERVE_GLRSTACK afterwards to make sure there is sufficient
1102 static inline yyGLRStackItem
*
1103 yynewGLRStackItem (yyGLRStack
* yystackp
, yybool yyisState
)
1105 yyGLRStackItem
* yynewItem
= yystackp
->yynextFree
;
1106 yystackp
->yyspaceLeft
-= 1;
1107 yystackp
->yynextFree
+= 1;
1108 yynewItem
->yystate
.yyisState
= yyisState
;
1112 /** Add a new semantic action that will execute the action for rule
1113 * RULENUM on the semantic values in RHS to the list of
1114 * alternative actions for STATE. Assumes that RHS comes from
1115 * stack #K of *STACKP. */
1117 yyaddDeferredAction (yyGLRStack
* yystackp
, size_t yyk
, yyGLRState
* yystate
,
1118 yyGLRState
* rhs
, yyRuleNum yyrule
)
1120 yySemanticOption
* yynewOption
=
1121 &yynewGLRStackItem (yystackp
, yyfalse
)->yyoption
;
1122 yynewOption
->yystate
= rhs
;
1123 yynewOption
->yyrule
= yyrule
;
1124 if (yystackp
->yytops
.yylookaheadNeeds
[yyk
])
1126 yynewOption
->yyrawchar
= yychar
;
1127 yynewOption
->yyval
= yylval
;
1128 yynewOption
->yyloc
= yylloc
;
1131 yynewOption
->yyrawchar
= YYEMPTY
;
1132 yynewOption
->yynext
= yystate
->yysemantics
.yyfirstVal
;
1133 yystate
->yysemantics
.yyfirstVal
= yynewOption
;
1135 YY_RESERVE_GLRSTACK (yystackp
);
1140 /** Initialize SET to a singleton set containing an empty stack. */
1142 yyinitStateSet (yyGLRStateSet
* yyset
)
1145 yyset
->yycapacity
= 16;
1146 yyset
->yystates
= (yyGLRState
**) YYMALLOC (16 * sizeof yyset
->yystates
[0]);
1147 if (! yyset
->yystates
)
1149 yyset
->yystates
[0] = NULL
;
1150 yyset
->yylookaheadNeeds
=
1151 (yybool
*) YYMALLOC (16 * sizeof yyset
->yylookaheadNeeds
[0]);
1152 if (! yyset
->yylookaheadNeeds
)
1154 YYFREE (yyset
->yystates
);
1160 static void yyfreeStateSet (yyGLRStateSet
* yyset
)
1162 YYFREE (yyset
->yystates
);
1163 YYFREE (yyset
->yylookaheadNeeds
);
1166 /** Initialize STACK to a single empty stack, with total maximum
1167 * capacity for all stacks of SIZE. */
1169 yyinitGLRStack (yyGLRStack
* yystackp
, size_t yysize
)
1171 yystackp
->yyerrState
= 0;
1173 yystackp
->yyspaceLeft
= yysize
;
1175 (yyGLRStackItem
*) YYMALLOC (yysize
* sizeof yystackp
->yynextFree
[0]);
1176 if (!yystackp
->yyitems
)
1178 yystackp
->yynextFree
= yystackp
->yyitems
;
1179 yystackp
->yysplitPoint
= NULL
;
1180 yystackp
->yylastDeleted
= NULL
;
1181 return yyinitStateSet (&yystackp
->yytops
);
1185 #if YYSTACKEXPANDABLE
1186 # define YYRELOC(YYFROMITEMS,YYTOITEMS,YYX,YYTYPE) \
1187 &((YYTOITEMS) - ((YYFROMITEMS) - (yyGLRStackItem*) (YYX)))->YYTYPE
1189 /** If STACK is expandable, extend it. WARNING: Pointers into the
1190 stack from outside should be considered invalid after this call.
1191 We always expand when there are 1 or fewer items left AFTER an
1192 allocation, so that we can avoid having external pointers exist
1193 across an allocation. */
1195 yyexpandGLRStack (yyGLRStack
* yystackp
)
1197 yyGLRStackItem
* yynewItems
;
1198 yyGLRStackItem
* yyp0
, *yyp1
;
1199 size_t yysize
, yynewSize
;
1201 yysize
= yystackp
->yynextFree
- yystackp
->yyitems
;
1202 if (YYMAXDEPTH
- YYHEADROOM
< yysize
)
1203 yyMemoryExhausted (yystackp
);
1204 yynewSize
= 2*yysize
;
1205 if (YYMAXDEPTH
< yynewSize
)
1206 yynewSize
= YYMAXDEPTH
;
1207 yynewItems
= (yyGLRStackItem
*) YYMALLOC (yynewSize
* sizeof yynewItems
[0]);
1209 yyMemoryExhausted (yystackp
);
1210 for (yyp0
= yystackp
->yyitems
, yyp1
= yynewItems
, yyn
= yysize
;
1212 yyn
-= 1, yyp0
+= 1, yyp1
+= 1)
1215 if (*(yybool
*) yyp0
)
1217 yyGLRState
* yys0
= &yyp0
->yystate
;
1218 yyGLRState
* yys1
= &yyp1
->yystate
;
1219 if (yys0
->yypred
!= NULL
)
1221 YYRELOC (yyp0
, yyp1
, yys0
->yypred
, yystate
);
1222 if (! yys0
->yyresolved
&& yys0
->yysemantics
.yyfirstVal
!= NULL
)
1223 yys1
->yysemantics
.yyfirstVal
=
1224 YYRELOC(yyp0
, yyp1
, yys0
->yysemantics
.yyfirstVal
, yyoption
);
1228 yySemanticOption
* yyv0
= &yyp0
->yyoption
;
1229 yySemanticOption
* yyv1
= &yyp1
->yyoption
;
1230 if (yyv0
->yystate
!= NULL
)
1231 yyv1
->yystate
= YYRELOC (yyp0
, yyp1
, yyv0
->yystate
, yystate
);
1232 if (yyv0
->yynext
!= NULL
)
1233 yyv1
->yynext
= YYRELOC (yyp0
, yyp1
, yyv0
->yynext
, yyoption
);
1236 if (yystackp
->yysplitPoint
!= NULL
)
1237 yystackp
->yysplitPoint
= YYRELOC (yystackp
->yyitems
, yynewItems
,
1238 yystackp
->yysplitPoint
, yystate
);
1240 for (yyn
= 0; yyn
< yystackp
->yytops
.yysize
; yyn
+= 1)
1241 if (yystackp
->yytops
.yystates
[yyn
] != NULL
)
1242 yystackp
->yytops
.yystates
[yyn
] =
1243 YYRELOC (yystackp
->yyitems
, yynewItems
,
1244 yystackp
->yytops
.yystates
[yyn
], yystate
);
1245 YYFREE (yystackp
->yyitems
);
1246 yystackp
->yyitems
= yynewItems
;
1247 yystackp
->yynextFree
= yynewItems
+ yysize
;
1248 yystackp
->yyspaceLeft
= yynewSize
- yysize
;
1253 yyfreeGLRStack (yyGLRStack
* yystackp
)
1255 YYFREE (yystackp
->yyitems
);
1256 yyfreeStateSet (&yystackp
->yytops
);
1259 /** Assuming that S is a GLRState somewhere on STACK, update the
1260 * splitpoint of STACK, if needed, so that it is at least as deep as
1263 yyupdateSplit (yyGLRStack
* yystackp
, yyGLRState
* yys
)
1265 if (yystackp
->yysplitPoint
!= NULL
&& yystackp
->yysplitPoint
> yys
)
1266 yystackp
->yysplitPoint
= yys
;
1269 /** Invalidate stack #K in STACK. */
1271 yymarkStackDeleted (yyGLRStack
* yystackp
, size_t yyk
)
1273 if (yystackp
->yytops
.yystates
[yyk
] != NULL
)
1274 yystackp
->yylastDeleted
= yystackp
->yytops
.yystates
[yyk
];
1275 yystackp
->yytops
.yystates
[yyk
] = NULL
;
1278 /** Undelete the last stack that was marked as deleted. Can only be
1279 done once after a deletion, and only when all other stacks have
1282 yyundeleteLastStack (yyGLRStack
* yystackp
)
1284 if (yystackp
->yylastDeleted
== NULL
|| yystackp
->yytops
.yysize
!= 0)
1286 yystackp
->yytops
.yystates
[0] = yystackp
->yylastDeleted
;
1287 yystackp
->yytops
.yysize
= 1;
1288 YYDPRINTF ((stderr
, "Restoring last deleted stack as stack #0.\n"));
1289 yystackp
->yylastDeleted
= NULL
;
1293 yyremoveDeletes (yyGLRStack
* yystackp
)
1297 while (yyj
< yystackp
->yytops
.yysize
)
1299 if (yystackp
->yytops
.yystates
[yyi
] == NULL
)
1303 YYDPRINTF ((stderr
, "Removing dead stacks.\n"));
1305 yystackp
->yytops
.yysize
-= 1;
1309 yystackp
->yytops
.yystates
[yyj
] = yystackp
->yytops
.yystates
[yyi
];
1310 /* In the current implementation, it's unnecessary to copy
1311 yystackp->yytops.yylookaheadNeeds[yyi] since, after
1312 yyremoveDeletes returns, the parser immediately either enters
1313 deterministic operation or shifts a token. However, it doesn't
1314 hurt, and the code might evolve to need it. */
1315 yystackp
->yytops
.yylookaheadNeeds
[yyj
] =
1316 yystackp
->yytops
.yylookaheadNeeds
[yyi
];
1319 YYDPRINTF ((stderr
, "Rename stack %lu -> %lu.\n",
1320 (unsigned long int) yyi
, (unsigned long int) yyj
));
1328 /** Shift to a new state on stack #K of STACK, corresponding to LR state
1329 * LRSTATE, at input position POSN, with (resolved) semantic value SVAL. */
1331 yyglrShift (yyGLRStack
* yystackp
, size_t yyk
, yyStateNum yylrState
,
1333 YYSTYPE
* yyvalp
, YYLTYPE
* yylocp
)
1335 yyGLRState
* yynewState
= &yynewGLRStackItem (yystackp
, yytrue
)->yystate
;
1337 yynewState
->yylrState
= yylrState
;
1338 yynewState
->yyposn
= yyposn
;
1339 yynewState
->yyresolved
= yytrue
;
1340 yynewState
->yypred
= yystackp
->yytops
.yystates
[yyk
];
1341 yynewState
->yysemantics
.yysval
= *yyvalp
;
1342 yynewState
->yyloc
= *yylocp
;
1343 yystackp
->yytops
.yystates
[yyk
] = yynewState
;
1345 YY_RESERVE_GLRSTACK (yystackp
);
1348 /** Shift stack #K of YYSTACK, to a new state corresponding to LR
1349 * state YYLRSTATE, at input position YYPOSN, with the (unresolved)
1350 * semantic value of YYRHS under the action for YYRULE. */
1352 yyglrShiftDefer (yyGLRStack
* yystackp
, size_t yyk
, yyStateNum yylrState
,
1353 size_t yyposn
, yyGLRState
* rhs
, yyRuleNum yyrule
)
1355 yyGLRState
* yynewState
= &yynewGLRStackItem (yystackp
, yytrue
)->yystate
;
1357 yynewState
->yylrState
= yylrState
;
1358 yynewState
->yyposn
= yyposn
;
1359 yynewState
->yyresolved
= yyfalse
;
1360 yynewState
->yypred
= yystackp
->yytops
.yystates
[yyk
];
1361 yynewState
->yysemantics
.yyfirstVal
= NULL
;
1362 yystackp
->yytops
.yystates
[yyk
] = yynewState
;
1364 /* Invokes YY_RESERVE_GLRSTACK. */
1365 yyaddDeferredAction (yystackp
, yyk
, yynewState
, rhs
, yyrule
);
1368 /** Pop the symbols consumed by reduction #RULE from the top of stack
1369 * #K of STACK, and perform the appropriate semantic action on their
1370 * semantic values. Assumes that all ambiguities in semantic values
1371 * have been previously resolved. Set *VALP to the resulting value,
1372 * and *LOCP to the computed location (if any). Return value is as
1373 * for userAction. */
1374 static inline YYRESULTTAG
1375 yydoAction (yyGLRStack
* yystackp
, size_t yyk
, yyRuleNum yyrule
,
1376 YYSTYPE
* yyvalp
, YYLTYPE
* yylocp
]b4_user_formals
[)
1378 int yynrhs
= yyrhsLength (yyrule
);
1380 if (yystackp
->yysplitPoint
== NULL
)
1382 /* Standard special case: single stack. */
1383 yyGLRStackItem
* rhs
= (yyGLRStackItem
*) yystackp
->yytops
.yystates
[yyk
];
1384 YYASSERT (yyk
== 0);
1385 yystackp
->yynextFree
-= yynrhs
;
1386 yystackp
->yyspaceLeft
+= yynrhs
;
1387 yystackp
->yytops
.yystates
[0] = & yystackp
->yynextFree
[-1].yystate
;
1388 return yyuserAction (yyrule
, yynrhs
, rhs
,
1389 yyvalp
, yylocp
, yystackp
]b4_user_args
[);
1393 /* At present, doAction is never called in nondeterministic
1394 * mode, so this branch is never taken. It is here in
1395 * anticipation of a future feature that will allow immediate
1396 * evaluation of selected actions in nondeterministic mode. */
1399 yyGLRStackItem yyrhsVals
[YYMAXRHS
+ YYMAXLEFT
+ 1];
1400 yys
= yyrhsVals
[YYMAXRHS
+ YYMAXLEFT
].yystate
.yypred
1401 = yystackp
->yytops
.yystates
[yyk
];]b4_locations_if([[
1403 /* Set default location. */
1404 yyrhsVals
[YYMAXRHS
+ YYMAXLEFT
- 1].yystate
.yyloc
= yys
->yyloc
;]])[
1405 for (yyi
= 0; yyi
< yynrhs
; yyi
+= 1)
1410 yyupdateSplit (yystackp
, yys
);
1411 yystackp
->yytops
.yystates
[yyk
] = yys
;
1412 return yyuserAction (yyrule
, yynrhs
, yyrhsVals
+ YYMAXRHS
+ YYMAXLEFT
- 1,
1413 yyvalp
, yylocp
, yystackp
]b4_user_args
[);
1418 # define YY_REDUCE_PRINT(Args)
1420 # define YY_REDUCE_PRINT(Args) \
1423 yy_reduce_print Args; \
1426 /*----------------------------------------------------------.
1427 | Report that the RULE is going to be reduced on stack #K. |
1428 `----------------------------------------------------------*/
1430 /*ARGSUSED*/ static inline void
1431 yy_reduce_print (yyGLRStack
* yystackp
, size_t yyk
, yyRuleNum yyrule
,
1432 YYSTYPE
* yyvalp
, YYLTYPE
* yylocp
]b4_user_formals
[)
1434 int yynrhs
= yyrhsLength (yyrule
);
1435 yybool yynormal
__attribute__ ((__unused__
)) =
1436 (yystackp
->yysplitPoint
== NULL
);
1437 yyGLRStackItem
* yyvsp
= (yyGLRStackItem
*) yystackp
->yytops
.yystates
[yyk
];
1442 ]b4_parse_param_use
[]dnl
1443 [ YYFPRINTF (stderr
, "Reducing stack %lu by rule %d (line %lu):\n",
1444 (unsigned long int) yyk
, yyrule
- 1,
1445 (unsigned long int) yyrline
[yyrule
]);
1446 /* The symbols being reduced. */
1447 for (yyi
= 0; yyi
< yynrhs
; yyi
++)
1449 YYFPRINTF (stderr
, " $%d = ", yyi
+ 1);
1450 yy_symbol_print (stderr
, yyrhs
[yyprhs
[yyrule
] + yyi
],
1451 &]b4_rhs_value(yynrhs
, yyi
+ 1)[
1452 ]b4_locations_if([, &]b4_rhs_location(yynrhs
, yyi
+ 1))[]dnl
1454 YYFPRINTF (stderr
, "\n");
1459 /** Pop items off stack #K of STACK according to grammar rule RULE,
1460 * and push back on the resulting nonterminal symbol. Perform the
1461 * semantic action associated with RULE and store its value with the
1462 * newly pushed state, if FORCEEVAL or if STACK is currently
1463 * unambiguous. Otherwise, store the deferred semantic action with
1464 * the new state. If the new state would have an identical input
1465 * position, LR state, and predecessor to an existing state on the stack,
1466 * it is identified with that existing state, eliminating stack #K from
1467 * the STACK. In this case, the (necessarily deferred) semantic value is
1468 * added to the options for the existing state's semantic value.
1470 static inline YYRESULTTAG
1471 yyglrReduce (yyGLRStack
* yystackp
, size_t yyk
, yyRuleNum yyrule
,
1472 yybool yyforceEval
]b4_user_formals
[)
1474 size_t yyposn
= yystackp
->yytops
.yystates
[yyk
]->yyposn
;
1476 if (yyforceEval
|| yystackp
->yysplitPoint
== NULL
)
1481 YY_REDUCE_PRINT ((yystackp
, yyk
, yyrule
, &yysval
, &yyloc
]b4_user_args
[));
1482 YYCHK (yydoAction (yystackp
, yyk
, yyrule
, &yysval
,
1483 &yyloc
]b4_user_args
[));
1484 YY_SYMBOL_PRINT ("-> $$ =", yyr1
[yyrule
], &yysval
, &yyloc
);
1485 yyglrShift (yystackp
, yyk
,
1486 yyLRgotoState (yystackp
->yytops
.yystates
[yyk
]->yylrState
,
1487 yylhsNonterm (yyrule
)),
1488 yyposn
, &yysval
, &yyloc
);
1494 yyGLRState
* yys
, *yys0
= yystackp
->yytops
.yystates
[yyk
];
1495 yyStateNum yynewLRState
;
1497 for (yys
= yystackp
->yytops
.yystates
[yyk
], yyn
= yyrhsLength (yyrule
);
1503 yyupdateSplit (yystackp
, yys
);
1504 yynewLRState
= yyLRgotoState (yys
->yylrState
, yylhsNonterm (yyrule
));
1506 "Reduced stack %lu by rule #%d; action deferred. Now in state %d.\n",
1507 (unsigned long int) yyk
, yyrule
- 1, yynewLRState
));
1508 for (yyi
= 0; yyi
< yystackp
->yytops
.yysize
; yyi
+= 1)
1509 if (yyi
!= yyk
&& yystackp
->yytops
.yystates
[yyi
] != NULL
)
1511 yyGLRState
* yyp
, *yysplit
= yystackp
->yysplitPoint
;
1512 yyp
= yystackp
->yytops
.yystates
[yyi
];
1513 while (yyp
!= yys
&& yyp
!= yysplit
&& yyp
->yyposn
>= yyposn
)
1515 if (yyp
->yylrState
== yynewLRState
&& yyp
->yypred
== yys
)
1517 yyaddDeferredAction (yystackp
, yyk
, yyp
, yys0
, yyrule
);
1518 yymarkStackDeleted (yystackp
, yyk
);
1519 YYDPRINTF ((stderr
, "Merging stack %lu into stack %lu.\n",
1520 (unsigned long int) yyk
,
1521 (unsigned long int) yyi
));
1527 yystackp
->yytops
.yystates
[yyk
] = yys
;
1528 yyglrShiftDefer (yystackp
, yyk
, yynewLRState
, yyposn
, yys0
, yyrule
);
1534 yysplitStack (yyGLRStack
* yystackp
, size_t yyk
)
1536 if (yystackp
->yysplitPoint
== NULL
)
1538 YYASSERT (yyk
== 0);
1539 yystackp
->yysplitPoint
= yystackp
->yytops
.yystates
[yyk
];
1541 if (yystackp
->yytops
.yysize
>= yystackp
->yytops
.yycapacity
)
1543 yyGLRState
** yynewStates
;
1544 yybool
* yynewLookaheadNeeds
;
1548 if (yystackp
->yytops
.yycapacity
1549 > (YYSIZEMAX
/ (2 * sizeof yynewStates
[0])))
1550 yyMemoryExhausted (yystackp
);
1551 yystackp
->yytops
.yycapacity
*= 2;
1554 (yyGLRState
**) YYREALLOC (yystackp
->yytops
.yystates
,
1555 (yystackp
->yytops
.yycapacity
1556 * sizeof yynewStates
[0]));
1557 if (yynewStates
== NULL
)
1558 yyMemoryExhausted (yystackp
);
1559 yystackp
->yytops
.yystates
= yynewStates
;
1561 yynewLookaheadNeeds
=
1562 (yybool
*) YYREALLOC (yystackp
->yytops
.yylookaheadNeeds
,
1563 (yystackp
->yytops
.yycapacity
1564 * sizeof yynewLookaheadNeeds
[0]));
1565 if (yynewLookaheadNeeds
== NULL
)
1566 yyMemoryExhausted (yystackp
);
1567 yystackp
->yytops
.yylookaheadNeeds
= yynewLookaheadNeeds
;
1569 yystackp
->yytops
.yystates
[yystackp
->yytops
.yysize
]
1570 = yystackp
->yytops
.yystates
[yyk
];
1571 yystackp
->yytops
.yylookaheadNeeds
[yystackp
->yytops
.yysize
]
1572 = yystackp
->yytops
.yylookaheadNeeds
[yyk
];
1573 yystackp
->yytops
.yysize
+= 1;
1574 return yystackp
->yytops
.yysize
-1;
1577 /** True iff Y0 and Y1 represent identical options at the top level.
1578 * That is, they represent the same rule applied to RHS symbols
1579 * that produce the same terminal symbols. */
1581 yyidenticalOptions (yySemanticOption
* yyy0
, yySemanticOption
* yyy1
)
1583 if (yyy0
->yyrule
== yyy1
->yyrule
)
1585 yyGLRState
*yys0
, *yys1
;
1587 for (yys0
= yyy0
->yystate
, yys1
= yyy1
->yystate
,
1588 yyn
= yyrhsLength (yyy0
->yyrule
);
1590 yys0
= yys0
->yypred
, yys1
= yys1
->yypred
, yyn
-= 1)
1591 if (yys0
->yyposn
!= yys1
->yyposn
)
1599 /** Assuming identicalOptions (Y0,Y1), destructively merge the
1600 * alternative semantic values for the RHS-symbols of Y1 and Y0. */
1602 yymergeOptionSets (yySemanticOption
* yyy0
, yySemanticOption
* yyy1
)
1604 yyGLRState
*yys0
, *yys1
;
1606 for (yys0
= yyy0
->yystate
, yys1
= yyy1
->yystate
,
1607 yyn
= yyrhsLength (yyy0
->yyrule
);
1609 yys0
= yys0
->yypred
, yys1
= yys1
->yypred
, yyn
-= 1)
1613 else if (yys0
->yyresolved
)
1615 yys1
->yyresolved
= yytrue
;
1616 yys1
->yysemantics
.yysval
= yys0
->yysemantics
.yysval
;
1618 else if (yys1
->yyresolved
)
1620 yys0
->yyresolved
= yytrue
;
1621 yys0
->yysemantics
.yysval
= yys1
->yysemantics
.yysval
;
1625 yySemanticOption
** yyz0p
;
1626 yySemanticOption
* yyz1
;
1627 yyz0p
= &yys0
->yysemantics
.yyfirstVal
;
1628 yyz1
= yys1
->yysemantics
.yyfirstVal
;
1629 while (YYID (yytrue
))
1631 if (yyz1
== *yyz0p
|| yyz1
== NULL
)
1633 else if (*yyz0p
== NULL
)
1638 else if (*yyz0p
< yyz1
)
1640 yySemanticOption
* yyz
= *yyz0p
;
1642 yyz1
= yyz1
->yynext
;
1643 (*yyz0p
)->yynext
= yyz
;
1645 yyz0p
= &(*yyz0p
)->yynext
;
1647 yys1
->yysemantics
.yyfirstVal
= yys0
->yysemantics
.yyfirstVal
;
1652 /** Y0 and Y1 represent two possible actions to take in a given
1653 * parsing state; return 0 if no combination is possible,
1654 * 1 if user-mergeable, 2 if Y0 is preferred, 3 if Y1 is preferred. */
1656 yypreference (yySemanticOption
* y0
, yySemanticOption
* y1
)
1658 yyRuleNum r0
= y0
->yyrule
, r1
= y1
->yyrule
;
1659 int p0
= yydprec
[r0
], p1
= yydprec
[r1
];
1663 if (yymerger
[r0
] == 0 || yymerger
[r0
] != yymerger
[r1
])
1668 if (p0
== 0 || p1
== 0)
1677 static YYRESULTTAG
yyresolveValue (yyGLRState
* yys
,
1678 yyGLRStack
* yystackp
]b4_user_formals
[);
1681 /** Resolve the previous N states starting at and including state S. If result
1682 * != yyok, some states may have been left unresolved possibly with empty
1683 * semantic option chains. Regardless of whether result = yyok, each state
1684 * has been left with consistent data so that yydestroyGLRState can be invoked
1687 yyresolveStates (yyGLRState
* yys
, int yyn
,
1688 yyGLRStack
* yystackp
]b4_user_formals
[)
1692 YYASSERT (yys
->yypred
);
1693 YYCHK (yyresolveStates (yys
->yypred
, yyn
-1, yystackp
]b4_user_args
[));
1694 if (! yys
->yyresolved
)
1695 YYCHK (yyresolveValue (yys
, yystackp
]b4_user_args
[));
1700 /** Resolve the states for the RHS of OPT, perform its user action, and return
1701 * the semantic value and location. Regardless of whether result = yyok, all
1702 * RHS states have been destroyed (assuming the user action destroys all RHS
1703 * semantic values if invoked). */
1705 yyresolveAction (yySemanticOption
* yyopt
, yyGLRStack
* yystackp
,
1706 YYSTYPE
* yyvalp
, YYLTYPE
* yylocp
]b4_user_formals
[)
1708 yyGLRStackItem yyrhsVals
[YYMAXRHS
+ YYMAXLEFT
+ 1];
1711 YYSTYPE yylval_current
;
1712 YYLTYPE yylloc_current
;
1715 yynrhs
= yyrhsLength (yyopt
->yyrule
);
1716 yyflag
= yyresolveStates (yyopt
->yystate
, yynrhs
, yystackp
]b4_user_args
[);
1720 for (yys
= yyopt
->yystate
; yynrhs
> 0; yys
= yys
->yypred
, yynrhs
-= 1)
1721 yydestroyGLRState ("Cleanup: popping", yys
]b4_user_args
[);
1725 yyrhsVals
[YYMAXRHS
+ YYMAXLEFT
].yystate
.yypred
= yyopt
->yystate
;]b4_locations_if([[
1727 /* Set default location. */
1728 yyrhsVals
[YYMAXRHS
+ YYMAXLEFT
- 1].yystate
.yyloc
= yyopt
->yystate
->yyloc
;]])[
1729 yychar_current
= yychar
;
1730 yylval_current
= yylval
;
1731 yylloc_current
= yylloc
;
1732 yychar
= yyopt
->yyrawchar
;
1733 yylval
= yyopt
->yyval
;
1734 yylloc
= yyopt
->yyloc
;
1735 yyflag
= yyuserAction (yyopt
->yyrule
, yynrhs
,
1736 yyrhsVals
+ YYMAXRHS
+ YYMAXLEFT
- 1,
1737 yyvalp
, yylocp
, yystackp
]b4_user_args
[);
1738 yychar
= yychar_current
;
1739 yylval
= yylval_current
;
1740 yylloc
= yylloc_current
;
1746 yyreportTree (yySemanticOption
* yyx
, int yyindent
)
1748 int yynrhs
= yyrhsLength (yyx
->yyrule
);
1751 yyGLRState
* yystates
[1 + YYMAXRHS
];
1752 yyGLRState yyleftmost_state
;
1754 for (yyi
= yynrhs
, yys
= yyx
->yystate
; 0 < yyi
; yyi
-= 1, yys
= yys
->yypred
)
1755 yystates
[yyi
] = yys
;
1758 yyleftmost_state
.yyposn
= 0;
1759 yystates
[0] = &yyleftmost_state
;
1764 if (yyx
->yystate
->yyposn
< yys
->yyposn
+ 1)
1765 YYFPRINTF (stderr
, "%*s%s -> <Rule %d, empty>\n",
1766 yyindent
, "", yytokenName (yylhsNonterm (yyx
->yyrule
)),
1769 YYFPRINTF (stderr
, "%*s%s -> <Rule %d, tokens %lu .. %lu>\n",
1770 yyindent
, "", yytokenName (yylhsNonterm (yyx
->yyrule
)),
1771 yyx
->yyrule
- 1, (unsigned long int) (yys
->yyposn
+ 1),
1772 (unsigned long int) yyx
->yystate
->yyposn
);
1773 for (yyi
= 1; yyi
<= yynrhs
; yyi
+= 1)
1775 if (yystates
[yyi
]->yyresolved
)
1777 if (yystates
[yyi
-1]->yyposn
+1 > yystates
[yyi
]->yyposn
)
1778 YYFPRINTF (stderr
, "%*s%s <empty>\n", yyindent
+2, "",
1779 yytokenName (yyrhs
[yyprhs
[yyx
->yyrule
]+yyi
-1]));
1781 YYFPRINTF (stderr
, "%*s%s <tokens %lu .. %lu>\n", yyindent
+2, "",
1782 yytokenName (yyrhs
[yyprhs
[yyx
->yyrule
]+yyi
-1]),
1783 (unsigned long int) (yystates
[yyi
- 1]->yyposn
+ 1),
1784 (unsigned long int) yystates
[yyi
]->yyposn
);
1787 yyreportTree (yystates
[yyi
]->yysemantics
.yyfirstVal
, yyindent
+2);
1792 /*ARGSUSED*/ static YYRESULTTAG
1793 yyreportAmbiguity (yySemanticOption
* yyx0
,
1794 yySemanticOption
* yyx1
]b4_pure_formals
[)
1800 YYFPRINTF (stderr
, "Ambiguity detected.\n");
1801 YYFPRINTF (stderr
, "Option 1,\n");
1802 yyreportTree (yyx0
, 2);
1803 YYFPRINTF (stderr
, "\nOption 2,\n");
1804 yyreportTree (yyx1
, 2);
1805 YYFPRINTF (stderr
, "\n");
1808 yyerror (]b4_yyerror_args
[YY_("syntax is ambiguous"));
1812 /** Starting at and including state S1, resolve the location for each of the
1813 * previous N1 states that is unresolved. The first semantic option of a state
1814 * is always chosen. */
1816 yyresolveLocations (yyGLRState
* yys1
, int yyn1
,
1817 yyGLRStack
*yystackp
]b4_user_formals
[)
1821 yyresolveLocations (yys1
->yypred
, yyn1
- 1, yystackp
]b4_user_args
[);
1822 if (!yys1
->yyresolved
)
1824 yySemanticOption
*yyoption
;
1825 yyGLRStackItem yyrhsloc
[1 + YYMAXRHS
];
1828 YYSTYPE yylval_current
;
1829 YYLTYPE yylloc_current
;
1830 yyoption
= yys1
->yysemantics
.yyfirstVal
;
1831 YYASSERT (yyoption
!= NULL
);
1832 yynrhs
= yyrhsLength (yyoption
->yyrule
);
1837 yyresolveLocations (yyoption
->yystate
, yynrhs
,
1838 yystackp
]b4_user_args
[);
1839 for (yys
= yyoption
->yystate
, yyn
= yynrhs
;
1841 yys
= yys
->yypred
, yyn
-= 1)
1842 yyrhsloc
[yyn
].yystate
.yyloc
= yys
->yyloc
;
1846 /* Both yyresolveAction and yyresolveLocations traverse the GSS
1847 in reverse rightmost order. It is only necessary to invoke
1848 yyresolveLocations on a subforest for which yyresolveAction
1849 would have been invoked next had an ambiguity not been
1850 detected. Thus the location of the previous state (but not
1851 necessarily the previous state itself) is guaranteed to be
1852 resolved already. */
1853 yyGLRState
*yyprevious
= yyoption
->yystate
;
1854 yyrhsloc
[0].yystate
.yyloc
= yyprevious
->yyloc
;
1856 yychar_current
= yychar
;
1857 yylval_current
= yylval
;
1858 yylloc_current
= yylloc
;
1859 yychar
= yyoption
->yyrawchar
;
1860 yylval
= yyoption
->yyval
;
1861 yylloc
= yyoption
->yyloc
;
1862 YYLLOC_DEFAULT ((yys1
->yyloc
), yyrhsloc
, yynrhs
);
1863 yychar
= yychar_current
;
1864 yylval
= yylval_current
;
1865 yylloc
= yylloc_current
;
1870 /** Resolve the ambiguity represented in state S, perform the indicated
1871 * actions, and set the semantic value of S. If result != yyok, the chain of
1872 * semantic options in S has been cleared instead or it has been left
1873 * unmodified except that redundant options may have been removed. Regardless
1874 * of whether result = yyok, S has been left with consistent data so that
1875 * yydestroyGLRState can be invoked if necessary. */
1877 yyresolveValue (yyGLRState
* yys
, yyGLRStack
* yystackp
]b4_user_formals
[)
1879 yySemanticOption
* yyoptionList
= yys
->yysemantics
.yyfirstVal
;
1880 yySemanticOption
* yybest
;
1881 yySemanticOption
** yypp
;
1885 YYLTYPE
*yylocp
= &yys
->yyloc
;
1887 yybest
= yyoptionList
;
1889 for (yypp
= &yyoptionList
->yynext
; *yypp
!= NULL
; )
1891 yySemanticOption
* yyp
= *yypp
;
1893 if (yyidenticalOptions (yybest
, yyp
))
1895 yymergeOptionSets (yybest
, yyp
);
1896 *yypp
= yyp
->yynext
;
1900 switch (yypreference (yybest
, yyp
))
1903 yyresolveLocations (yys
, 1, yystackp
]b4_user_args
[);
1904 return yyreportAmbiguity (yybest
, yyp
]b4_pure_args
[);
1916 /* This cannot happen so it is not worth a YYASSERT (yyfalse),
1917 but some compilers complain if the default case is
1921 yypp
= &yyp
->yynext
;
1927 yySemanticOption
* yyp
;
1928 int yyprec
= yydprec
[yybest
->yyrule
];
1929 yyflag
= yyresolveAction (yybest
, yystackp
, &yysval
,
1930 yylocp
]b4_user_args
[);
1932 for (yyp
= yybest
->yynext
; yyp
!= NULL
; yyp
= yyp
->yynext
)
1934 if (yyprec
== yydprec
[yyp
->yyrule
])
1936 YYSTYPE yysval_other
;
1938 yyflag
= yyresolveAction (yyp
, yystackp
, &yysval_other
,
1939 &yydummy
]b4_user_args
[);
1942 yydestruct ("Cleanup: discarding incompletely merged value for",
1943 yystos
[yys
->yylrState
],
1944 &yysval
]b4_locations_if([, yylocp
])[]b4_user_args
[);
1947 yyuserMerge (yymerger
[yyp
->yyrule
], &yysval
, &yysval_other
);
1952 yyflag
= yyresolveAction (yybest
, yystackp
, &yysval
, yylocp
]b4_user_args
[);
1956 yys
->yyresolved
= yytrue
;
1957 yys
->yysemantics
.yysval
= yysval
;
1960 yys
->yysemantics
.yyfirstVal
= NULL
;
1965 yyresolveStack (yyGLRStack
* yystackp
]b4_user_formals
[)
1967 if (yystackp
->yysplitPoint
!= NULL
)
1972 for (yyn
= 0, yys
= yystackp
->yytops
.yystates
[0];
1973 yys
!= yystackp
->yysplitPoint
;
1974 yys
= yys
->yypred
, yyn
+= 1)
1976 YYCHK (yyresolveStates (yystackp
->yytops
.yystates
[0], yyn
, yystackp
1983 yycompressStack (yyGLRStack
* yystackp
)
1985 yyGLRState
* yyp
, *yyq
, *yyr
;
1987 if (yystackp
->yytops
.yysize
!= 1 || yystackp
->yysplitPoint
== NULL
)
1990 for (yyp
= yystackp
->yytops
.yystates
[0], yyq
= yyp
->yypred
, yyr
= NULL
;
1991 yyp
!= yystackp
->yysplitPoint
;
1992 yyr
= yyp
, yyp
= yyq
, yyq
= yyp
->yypred
)
1995 yystackp
->yyspaceLeft
+= yystackp
->yynextFree
- yystackp
->yyitems
;
1996 yystackp
->yynextFree
= ((yyGLRStackItem
*) yystackp
->yysplitPoint
) + 1;
1997 yystackp
->yyspaceLeft
-= yystackp
->yynextFree
- yystackp
->yyitems
;
1998 yystackp
->yysplitPoint
= NULL
;
1999 yystackp
->yylastDeleted
= NULL
;
2003 yystackp
->yynextFree
->yystate
= *yyr
;
2005 yystackp
->yynextFree
->yystate
.yypred
= &yystackp
->yynextFree
[-1].yystate
;
2006 yystackp
->yytops
.yystates
[0] = &yystackp
->yynextFree
->yystate
;
2007 yystackp
->yynextFree
+= 1;
2008 yystackp
->yyspaceLeft
-= 1;
2013 yyprocessOneStack (yyGLRStack
* yystackp
, size_t yyk
,
2014 size_t yyposn
]b4_pure_formals
[)
2017 const short int* yyconflicts
;
2020 while (yystackp
->yytops
.yystates
[yyk
] != NULL
)
2022 yyStateNum yystate
= yystackp
->yytops
.yystates
[yyk
]->yylrState
;
2023 YYDPRINTF ((stderr
, "Stack %lu Entering state %d\n",
2024 (unsigned long int) yyk
, yystate
));
2026 YYASSERT (yystate
!= YYFINAL
);
2028 if (yyisDefaultedState (yystate
))
2030 yyrule
= yydefaultAction (yystate
);
2033 YYDPRINTF ((stderr
, "Stack %lu dies.\n",
2034 (unsigned long int) yyk
));
2035 yymarkStackDeleted (yystackp
, yyk
);
2038 YYCHK (yyglrReduce (yystackp
, yyk
, yyrule
, yyfalse
]b4_user_args
[));
2043 yystackp
->yytops
.yylookaheadNeeds
[yyk
] = yytrue
;
2044 if (yychar
== YYEMPTY
)
2046 YYDPRINTF ((stderr
, "Reading a token: "));
2050 if (yychar
<= YYEOF
)
2052 yychar
= yytoken
= YYEOF
;
2053 YYDPRINTF ((stderr
, "Now at end of input.\n"));
2057 yytoken
= YYTRANSLATE (yychar
);
2058 YY_SYMBOL_PRINT ("Next token is", yytoken
, &yylval
, &yylloc
);
2061 yygetLRActions (yystate
, yytoken
, &yyaction
, &yyconflicts
);
2063 while (*yyconflicts
!= 0)
2065 size_t yynewStack
= yysplitStack (yystackp
, yyk
);
2066 YYDPRINTF ((stderr
, "Splitting off stack %lu from %lu.\n",
2067 (unsigned long int) yynewStack
,
2068 (unsigned long int) yyk
));
2069 YYCHK (yyglrReduce (yystackp
, yynewStack
,
2070 *yyconflicts
, yyfalse
]b4_user_args
[));
2071 YYCHK (yyprocessOneStack (yystackp
, yynewStack
,
2072 yyposn
]b4_pure_args
[));
2076 if (yyisShiftAction (yyaction
))
2078 else if (yyisErrorAction (yyaction
))
2080 YYDPRINTF ((stderr
, "Stack %lu dies.\n",
2081 (unsigned long int) yyk
));
2082 yymarkStackDeleted (yystackp
, yyk
);
2086 YYCHK (yyglrReduce (yystackp
, yyk
, -yyaction
,
2087 yyfalse
]b4_user_args
[));
2093 /*ARGSUSED*/ static void
2094 yyreportSyntaxError (yyGLRStack
* yystackp
]b4_user_formals
[)
2096 if (yystackp
->yyerrState
== 0)
2100 yyn
= yypact
[yystackp
->yytops
.yystates
[0]->yylrState
];
2101 if (YYPACT_NINF
< yyn
&& yyn
<= YYLAST
)
2103 yySymbol yytoken
= YYTRANSLATE (yychar
);
2104 size_t yysize0
= yytnamerr (NULL
, yytokenName (yytoken
));
2105 size_t yysize
= yysize0
;
2107 yybool yysize_overflow
= yyfalse
;
2109 enum { YYERROR_VERBOSE_ARGS_MAXIMUM
= 5 };
2110 char const *yyarg
[YYERROR_VERBOSE_ARGS_MAXIMUM
];
2114 static char const yyunexpected
[] = "syntax error, unexpected %s";
2115 static char const yyexpecting
[] = ", expecting %s";
2116 static char const yyor
[] = " or %s";
2117 char yyformat
[sizeof yyunexpected
2118 + sizeof yyexpecting
- 1
2119 + ((YYERROR_VERBOSE_ARGS_MAXIMUM
- 2)
2120 * (sizeof yyor
- 1))];
2121 char const *yyprefix
= yyexpecting
;
2123 /* Start YYX at -YYN if negative to avoid negative indexes in
2125 int yyxbegin
= yyn
< 0 ? -yyn
: 0;
2127 /* Stay within bounds of both yycheck and yytname. */
2128 int yychecklim
= YYLAST
- yyn
+ 1;
2129 int yyxend
= yychecklim
< YYNTOKENS
? yychecklim
: YYNTOKENS
;
2132 yyarg
[0] = yytokenName (yytoken
);
2133 yyfmt
= yystpcpy (yyformat
, yyunexpected
);
2135 for (yyx
= yyxbegin
; yyx
< yyxend
; ++yyx
)
2136 if (yycheck
[yyx
+ yyn
] == yyx
&& yyx
!= YYTERROR
)
2138 if (yycount
== YYERROR_VERBOSE_ARGS_MAXIMUM
)
2142 yyformat
[sizeof yyunexpected
- 1] = '\0';
2145 yyarg
[yycount
++] = yytokenName (yyx
);
2146 yysize1
= yysize
+ yytnamerr (NULL
, yytokenName (yyx
));
2147 yysize_overflow
|= yysize1
< yysize
;
2149 yyfmt
= yystpcpy (yyfmt
, yyprefix
);
2153 yyf
= YY_(yyformat
);
2154 yysize1
= yysize
+ strlen (yyf
);
2155 yysize_overflow
|= yysize1
< yysize
;
2158 if (!yysize_overflow
)
2159 yymsg
= (char *) YYMALLOC (yysize
);
2165 while ((*yyp
= *yyf
))
2167 if (*yyp
== '%' && yyf
[1] == 's' && yyi
< yycount
)
2169 yyp
+= yytnamerr (yyp
, yyarg
[yyi
++]);
2178 yyerror (]b4_lyyerror_args
[yymsg
);
2183 yyerror (]b4_lyyerror_args
[YY_("syntax error"));
2184 yyMemoryExhausted (yystackp
);
2188 #endif /* YYERROR_VERBOSE */
2189 yyerror (]b4_lyyerror_args
[YY_("syntax error"));
2194 /* Recover from a syntax error on *YYSTACKP, assuming that *YYSTACKP->YYTOKENP,
2195 yylval, and yylloc are the syntactic category, semantic value, and location
2196 of the lookahead. */
2197 /*ARGSUSED*/ static void
2198 yyrecoverSyntaxError (yyGLRStack
* yystackp
]b4_user_formals
[)
2203 if (yystackp
->yyerrState
== 3)
2204 /* We just shifted the error token and (perhaps) took some
2205 reductions. Skip tokens until we can proceed. */
2206 while (YYID (yytrue
))
2209 if (yychar
== YYEOF
)
2210 yyFail (yystackp
][]b4_lpure_args
[, NULL
);
2211 if (yychar
!= YYEMPTY
)
2212 {]b4_locations_if([[
2213 /* We throw away the lookahead, but the error range
2214 of the shifted error token must take it into account. */
2215 yyGLRState
*yys
= yystackp
->yytops
.yystates
[0];
2216 yyGLRStackItem yyerror_range
[3];
2217 yyerror_range
[1].yystate
.yyloc
= yys
->yyloc
;
2218 yyerror_range
[2].yystate
.yyloc
= yylloc
;
2219 YYLLOC_DEFAULT ((yys
->yyloc
), yyerror_range
, 2);]])[
2220 yytoken
= YYTRANSLATE (yychar
);
2221 yydestruct ("Error: discarding",
2222 yytoken
, &yylval
]b4_locations_if([, &yylloc
])[]b4_user_args
[);
2224 YYDPRINTF ((stderr
, "Reading a token: "));
2226 if (yychar
<= YYEOF
)
2228 yychar
= yytoken
= YYEOF
;
2229 YYDPRINTF ((stderr
, "Now at end of input.\n"));
2233 yytoken
= YYTRANSLATE (yychar
);
2234 YY_SYMBOL_PRINT ("Next token is", yytoken
, &yylval
, &yylloc
);
2236 yyj
= yypact
[yystackp
->yytops
.yystates
[0]->yylrState
];
2237 if (yyis_pact_ninf (yyj
))
2240 if (yyj
< 0 || YYLAST
< yyj
|| yycheck
[yyj
] != yytoken
)
2242 if (yydefact
[yystackp
->yytops
.yystates
[0]->yylrState
] != 0)
2245 else if (yytable
[yyj
] != 0 && ! yyis_table_ninf (yytable
[yyj
]))
2249 /* Reduce to one stack. */
2250 for (yyk
= 0; yyk
< yystackp
->yytops
.yysize
; yyk
+= 1)
2251 if (yystackp
->yytops
.yystates
[yyk
] != NULL
)
2253 if (yyk
>= yystackp
->yytops
.yysize
)
2254 yyFail (yystackp
][]b4_lpure_args
[, NULL
);
2255 for (yyk
+= 1; yyk
< yystackp
->yytops
.yysize
; yyk
+= 1)
2256 yymarkStackDeleted (yystackp
, yyk
);
2257 yyremoveDeletes (yystackp
);
2258 yycompressStack (yystackp
);
2260 /* Now pop stack until we find a state that shifts the error token. */
2261 yystackp
->yyerrState
= 3;
2262 while (yystackp
->yytops
.yystates
[0] != NULL
)
2264 yyGLRState
*yys
= yystackp
->yytops
.yystates
[0];
2265 yyj
= yypact
[yys
->yylrState
];
2266 if (! yyis_pact_ninf (yyj
))
2269 if (0 <= yyj
&& yyj
<= YYLAST
&& yycheck
[yyj
] == YYTERROR
2270 && yyisShiftAction (yytable
[yyj
]))
2272 /* Shift the error token having adjusted its location. */
2273 YYLTYPE yyerrloc
;]b4_locations_if([[
2274 yystackp
->yyerror_range
[2].yystate
.yyloc
= yylloc
;
2275 YYLLOC_DEFAULT (yyerrloc
, (yystackp
->yyerror_range
), 2);]])[
2276 YY_SYMBOL_PRINT ("Shifting", yystos
[yytable
[yyj
]],
2277 &yylval
, &yyerrloc
);
2278 yyglrShift (yystackp
, 0, yytable
[yyj
],
2279 yys
->yyposn
, &yylval
, &yyerrloc
);
2280 yys
= yystackp
->yytops
.yystates
[0];
2284 ]b4_locations_if([[ yystackp
->yyerror_range
[1].yystate
.yyloc
= yys
->yyloc
;]])[
2285 if (yys
->yypred
!= NULL
)
2286 yydestroyGLRState ("Error: popping", yys
]b4_user_args
[);
2287 yystackp
->yytops
.yystates
[0] = yys
->yypred
;
2288 yystackp
->yynextFree
-= 1;
2289 yystackp
->yyspaceLeft
+= 1;
2291 if (yystackp
->yytops
.yystates
[0] == NULL
)
2292 yyFail (yystackp
][]b4_lpure_args
[, NULL
);
2295 #define YYCHK1(YYE) \
2305 goto yyuser_error; \
2316 ]b4_c_ansi_function_def([yyparse
], [int], b4_parse_param
)[
2320 yyGLRStack
* const yystackp
= &yystack
;
2323 YYDPRINTF ((stderr
, "Starting parse\n"));
2326 yylval
= yyval_default
;
2328 #if defined YYLTYPE_IS_TRIVIAL && YYLTYPE_IS_TRIVIAL
2329 yylloc
.first_line
= yylloc
.last_line
= ]b4_location_initial_line
[;
2330 yylloc
.first_column
= yylloc
.last_column
= ]b4_location_initial_column
[;
2333 m4_ifdef([b4_initial_action
], [
2334 m4_pushdef([b4_at_dollar
], [yylloc
])dnl
2335 m4_pushdef([b4_dollar_dollar
], [yylval
])dnl
2336 /* User initialization code. */
2337 b4_user_initial_action
2338 m4_popdef([b4_dollar_dollar
])dnl
2339 m4_popdef([b4_at_dollar
])])dnl
2341 if (! yyinitGLRStack (yystackp
, YYINITDEPTH
))
2342 goto yyexhaustedlab
;
2343 switch (YYSETJMP (yystack
.yyexception_buffer
))
2346 case 1: goto yyabortlab
;
2347 case 2: goto yyexhaustedlab
;
2348 default: goto yybuglab
;
2350 yyglrShift (&yystack
, 0, 0, 0, &yylval
, &yylloc
);
2353 while (YYID (yytrue
))
2355 /* For efficiency, we have two loops, the first of which is
2356 specialized to deterministic operation (single stack, no
2357 potential ambiguity). */
2359 while (YYID (yytrue
))
2363 const short int* yyconflicts
;
2365 yyStateNum yystate
= yystack
.yytops
.yystates
[0]->yylrState
;
2366 YYDPRINTF ((stderr
, "Entering state %d\n", yystate
));
2367 if (yystate
== YYFINAL
)
2369 if (yyisDefaultedState (yystate
))
2371 yyrule
= yydefaultAction (yystate
);
2374 ]b4_locations_if([[ yystack
.yyerror_range
[1].yystate
.yyloc
= yylloc
;]])[
2375 yyreportSyntaxError (&yystack
]b4_user_args
[);
2378 YYCHK1 (yyglrReduce (&yystack
, 0, yyrule
, yytrue
]b4_user_args
[));
2383 if (yychar
== YYEMPTY
)
2385 YYDPRINTF ((stderr
, "Reading a token: "));
2389 if (yychar
<= YYEOF
)
2391 yychar
= yytoken
= YYEOF
;
2392 YYDPRINTF ((stderr
, "Now at end of input.\n"));
2396 yytoken
= YYTRANSLATE (yychar
);
2397 YY_SYMBOL_PRINT ("Next token is", yytoken
, &yylval
, &yylloc
);
2400 yygetLRActions (yystate
, yytoken
, &yyaction
, &yyconflicts
);
2401 if (*yyconflicts
!= 0)
2403 if (yyisShiftAction (yyaction
))
2405 YY_SYMBOL_PRINT ("Shifting", yytoken
, &yylval
, &yylloc
);
2408 yyglrShift (&yystack
, 0, yyaction
, yyposn
, &yylval
, &yylloc
);
2409 if (0 < yystack
.yyerrState
)
2410 yystack
.yyerrState
-= 1;
2412 else if (yyisErrorAction (yyaction
))
2414 ]b4_locations_if([[ yystack
.yyerror_range
[1].yystate
.yyloc
= yylloc
;]])[
2415 yyreportSyntaxError (&yystack
]b4_user_args
[);
2419 YYCHK1 (yyglrReduce (&yystack
, 0, -yyaction
, yytrue
]b4_user_args
[));
2423 while (YYID (yytrue
))
2425 yySymbol yytoken_to_shift
;
2428 for (yys
= 0; yys
< yystack
.yytops
.yysize
; yys
+= 1)
2429 yystackp
->yytops
.yylookaheadNeeds
[yys
] = yychar
!= YYEMPTY
;
2431 /* yyprocessOneStack returns one of three things:
2433 - An error flag. If the caller is yyprocessOneStack, it
2434 immediately returns as well. When the caller is finally
2435 yyparse, it jumps to an error label via YYCHK1.
2437 - yyok, but yyprocessOneStack has invoked yymarkStackDeleted
2438 (&yystack, yys), which sets the top state of yys to NULL. Thus,
2439 yyparse's following invocation of yyremoveDeletes will remove
2442 - yyok, when ready to shift a token.
2444 Except in the first case, yyparse will invoke yyremoveDeletes and
2445 then shift the next token onto all remaining stacks. This
2446 synchronization of the shift (that is, after all preceding
2447 reductions on all stacks) helps prevent double destructor calls
2448 on yylval in the event of memory exhaustion. */
2450 for (yys
= 0; yys
< yystack
.yytops
.yysize
; yys
+= 1)
2451 YYCHK1 (yyprocessOneStack (&yystack
, yys
, yyposn
]b4_lpure_args
[));
2452 yyremoveDeletes (&yystack
);
2453 if (yystack
.yytops
.yysize
== 0)
2455 yyundeleteLastStack (&yystack
);
2456 if (yystack
.yytops
.yysize
== 0)
2457 yyFail (&yystack
][]b4_lpure_args
[, YY_("syntax error"));
2458 YYCHK1 (yyresolveStack (&yystack
]b4_user_args
[));
2459 YYDPRINTF ((stderr
, "Returning to deterministic operation.\n"));
2460 ]b4_locations_if([[ yystack
.yyerror_range
[1].yystate
.yyloc
= yylloc
;]])[
2461 yyreportSyntaxError (&yystack
]b4_user_args
[);
2465 /* If any yyglrShift call fails, it will fail after shifting. Thus,
2466 a copy of yylval will already be on stack 0 in the event of a
2467 failure in the following loop. Thus, yychar is set to YYEMPTY
2468 before the loop to make sure the user destructor for yylval isn't
2470 yytoken_to_shift
= YYTRANSLATE (yychar
);
2473 for (yys
= 0; yys
< yystack
.yytops
.yysize
; yys
+= 1)
2476 const short int* yyconflicts
;
2477 yyStateNum yystate
= yystack
.yytops
.yystates
[yys
]->yylrState
;
2478 yygetLRActions (yystate
, yytoken_to_shift
, &yyaction
,
2480 /* Note that yyconflicts were handled by yyprocessOneStack. */
2481 YYDPRINTF ((stderr
, "On stack %lu, ", (unsigned long int) yys
));
2482 YY_SYMBOL_PRINT ("shifting", yytoken_to_shift
, &yylval
, &yylloc
);
2483 yyglrShift (&yystack
, yys
, yyaction
, yyposn
,
2485 YYDPRINTF ((stderr
, "Stack %lu now in state #%d\n",
2486 (unsigned long int) yys
,
2487 yystack
.yytops
.yystates
[yys
]->yylrState
));
2490 if (yystack
.yytops
.yysize
== 1)
2492 YYCHK1 (yyresolveStack (&yystack
]b4_user_args
[));
2493 YYDPRINTF ((stderr
, "Returning to deterministic operation.\n"));
2494 yycompressStack (&yystack
);
2500 yyrecoverSyntaxError (&yystack
]b4_user_args
[);
2501 yyposn
= yystack
.yytops
.yystates
[0]->yyposn
;
2517 yyerror (]b4_lyyerror_args
[YY_("memory exhausted"));
2522 if (yychar
!= YYEMPTY
)
2523 yydestruct ("Cleanup: discarding lookahead",
2524 YYTRANSLATE (yychar
),
2525 &yylval
]b4_locations_if([, &yylloc
])[]b4_user_args
[);
2527 /* If the stack is well-formed, pop the stack until it is empty,
2528 destroying its entries as we go. But free the stack regardless
2529 of whether it is well-formed. */
2530 if (yystack
.yyitems
)
2532 yyGLRState
** yystates
= yystack
.yytops
.yystates
;
2535 size_t yysize
= yystack
.yytops
.yysize
;
2537 for (yyk
= 0; yyk
< yysize
; yyk
+= 1)
2540 while (yystates
[yyk
])
2542 yyGLRState
*yys
= yystates
[yyk
];
2543 ]b4_locations_if([[ yystack
.yyerror_range
[1].yystate
.yyloc
= yys
->yyloc
;]]
2544 )[ if (yys
->yypred
!= NULL
)
2545 yydestroyGLRState ("Cleanup: popping", yys
]b4_user_args
[);
2546 yystates
[yyk
] = yys
->yypred
;
2547 yystack
.yynextFree
-= 1;
2548 yystack
.yyspaceLeft
+= 1;
2553 yyfreeGLRStack (&yystack
);
2556 /* Make sure YYID is used. */
2557 return YYID (yyresult
);
2560 /* DEBUGGING ONLY */
2562 static void yypstack (yyGLRStack
* yystackp
, size_t yyk
)
2563 __attribute__ ((__unused__
));
2564 static void yypdumpstack (yyGLRStack
* yystackp
) __attribute__ ((__unused__
));
2567 yy_yypstack (yyGLRState
* yys
)
2571 yy_yypstack (yys
->yypred
);
2572 YYFPRINTF (stderr
, " -> ");
2574 YYFPRINTF (stderr
, "%d@@%lu", yys
->yylrState
,
2575 (unsigned long int) yys
->yyposn
);
2579 yypstates (yyGLRState
* yyst
)
2582 YYFPRINTF (stderr
, "<null>");
2585 YYFPRINTF (stderr
, "\n");
2589 yypstack (yyGLRStack
* yystackp
, size_t yyk
)
2591 yypstates (yystackp
->yytops
.yystates
[yyk
]);
2594 #define YYINDEX(YYX) \
2595 ((YYX) == NULL ? -1 : (yyGLRStackItem*) (YYX) - yystackp->yyitems)
2599 yypdumpstack (yyGLRStack
* yystackp
)
2601 yyGLRStackItem
* yyp
;
2603 for (yyp
= yystackp
->yyitems
; yyp
< yystackp
->yynextFree
; yyp
+= 1)
2605 YYFPRINTF (stderr
, "%3lu. ",
2606 (unsigned long int) (yyp
- yystackp
->yyitems
));
2607 if (*(yybool
*) yyp
)
2609 YYFPRINTF (stderr
, "Res: %d, LR State: %d, posn: %lu, pred: %ld",
2610 yyp
->yystate
.yyresolved
, yyp
->yystate
.yylrState
,
2611 (unsigned long int) yyp
->yystate
.yyposn
,
2612 (long int) YYINDEX (yyp
->yystate
.yypred
));
2613 if (! yyp
->yystate
.yyresolved
)
2614 YYFPRINTF (stderr
, ", firstVal: %ld",
2615 (long int) YYINDEX (yyp
->yystate
2616 .yysemantics
.yyfirstVal
));
2620 YYFPRINTF (stderr
, "Option. rule: %d, state: %ld, next: %ld",
2621 yyp
->yyoption
.yyrule
- 1,
2622 (long int) YYINDEX (yyp
->yyoption
.yystate
),
2623 (long int) YYINDEX (yyp
->yyoption
.yynext
));
2625 YYFPRINTF (stderr
, "\n");
2627 YYFPRINTF (stderr
, "Tops:");
2628 for (yyi
= 0; yyi
< yystackp
->yytops
.yysize
; yyi
+= 1)
2629 YYFPRINTF (stderr
, "%lu: %ld; ", (unsigned long int) yyi
,
2630 (long int) YYINDEX (yystackp
->yytops
.yystates
[yyi
]));
2631 YYFPRINTF (stderr
, "\n");
2638 dnl glr
.cc produces its own header
.
2640 m4_if(b4_skeleton
, ["glr.c"],
2642 [@
output(b4_spec_defines_file@
)@
2643 b4_copyright([Skeleton interface
for Bison GLR parsers in C
],
2644 [2002, 2003, 2004, 2005, 2006, 2009, 2010])
2646 b4_shared_declarations
2649 [[extern YYSTYPE
]b4_prefix
[lval
;]])
2651 b4_locations_if([b4_pure_if([],
2652 [extern YYLTYPE
]b4_prefix
[lloc
;])