3 # GLR skeleton for Bison
4 # Copyright (C) 2002, 2003, 2004, 2005, 2006, 2007 Free Software Foundation,
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 2 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, write to the Free Software
19 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
23 m4_include(b4_pkgdatadir
/[c
.m4
])
26 b4_complain([[non
-deterministic push parsers are
not yet supported
]])])
28 ## ---------------- ##
30 ## ---------------- ##
33 m4_define_default([b4_stack_depth_max
], [10000])
34 m4_define_default([b4_stack_depth_init
], [200])
38 ## ------------------------ ##
39 ## Pure/impure interfaces. ##
40 ## ------------------------ ##
45 # The possible parse-params formal arguments preceded by a comma.
47 # This is not shared with yacc.c in c.m4 because GLR relies on ISO C
48 # formal argument declarations.
49 m4_define([b4_user_formals
],
50 [m4_ifset([b4_parse_param
], [, b4_c_ansi_formals(b4_parse_param
)])])
55 # Accumule in b4_lex_param all the yylex arguments.
56 # Yes, this is quite ugly...
57 m4_define([b4_lex_param
],
58 m4_dquote(b4_pure_if([[[[YYSTYPE
*]], [[&yylval
]]][]dnl
59 b4_locations_if([, [[YYLTYPE
*], [&yylloc
]]])])dnl
60 m4_ifdef([b4_lex_param
], [, ]b4_lex_param
)))
65 # Optional effective arguments passed to yyerror: user args plus yylloc, and
67 m4_define([b4_yyerror_args
],
68 [b4_pure_if([b4_locations_if([yylocp
, ])])dnl
69 m4_ifset([b4_parse_param
], [b4_c_args(b4_parse_param
), ])])
74 # Same as above, but on the lookahead, hence &yylloc instead of yylocp.
75 m4_define([b4_lyyerror_args
],
76 [b4_pure_if([b4_locations_if([&yylloc
, ])])dnl
77 m4_ifset([b4_parse_param
], [b4_c_args(b4_parse_param
), ])])
82 # Same as b4_yyerror_args, but with a leading comma.
83 m4_define([b4_pure_args
],
84 [b4_pure_if([b4_locations_if([, yylocp
])])[]b4_user_args
])
89 # Same as above, but on the lookahead, hence &yylloc instead of yylocp.
90 m4_define([b4_lpure_args
],
91 [b4_pure_if([b4_locations_if([, &yylloc
])])[]b4_user_args
])
96 # Arguments passed to yyerror: user formals plus yylocp.
97 m4_define([b4_pure_formals
],
98 [b4_pure_if([b4_locations_if([, YYLTYPE
*yylocp
])])[]b4_user_formals
])
101 ## ----------------- ##
102 ## Semantic Values. ##
103 ## ----------------- ##
106 # b4_lhs_value([TYPE])
107 # --------------------
108 # Expansion of $<TYPE>$.
109 m4_define([b4_lhs_value
],
110 [((*yyvalp
)[]m4_ifval([$
1], [.$
1]))])
113 # b4_rhs_value(RULE-LENGTH, NUM, [TYPE])
114 # --------------------------------------
115 # Expansion of $<TYPE>NUM, where the current rule has RULE-LENGTH
117 m4_define([b4_rhs_value
],
118 [(((yyGLRStackItem
const *)yyvsp
)@
{YYFILL (($
2) - ($
1))@
}.yystate
.yysemantics
.yysval
[]m4_ifval([$
3], [.$
3]))])
129 m4_define([b4_lhs_location
],
133 # b4_rhs_location(RULE-LENGTH, NUM)
134 # ---------------------------------
135 # Expansion of @NUM, where the current rule has RULE-LENGTH symbols
137 m4_define([b4_rhs_location
],
138 [(((yyGLRStackItem
const *)yyvsp
)@
{YYFILL (($
2) - ($
1))@
}.yystate
.yyloc
)])
146 # We do want M4 expansion after # for CPP macros.
149 @
output(b4_parser_file_name@
)
150 b4_copyright([Skeleton implementation
for Bison GLR parsers in C
],
151 [2002, 2003, 2004, 2005, 2006])
153 /* C GLR parser skeleton written by Paul Hilfinger. */
157 b4_percent_code_get([[top]])[]dnl
158 m4_if(b4_prefix
, [yy
], [],
159 [/* Substitute the variable and function names. */
160 #define yyparse b4_prefix[]parse
161 #define yylex b4_prefix[]lex
162 #define yyerror b4_prefix[]error
163 #define yylval b4_prefix[]lval
164 #define yychar b4_prefix[]char
165 #define yydebug b4_prefix[]debug
166 #define yynerrs b4_prefix[]nerrs
167 #define yylloc b4_prefix[]lloc])[
169 /* Copy the first part of user declarations. */
170 ]b4_user_pre_prologue
172 dnl
# b4_shared_declarations
173 dnl
# ----------------------
174 dnl
# Declaration that might either go into the header (if --defines)
175 dnl
# or open coded in the parser body.
176 m4_define([b4_shared_declarations
],
177 [b4_percent_code_get([[requires]])[]dnl
179 b4_token_enums(b4_tokens
)
182 ]m4_ifdef([b4_stype
],
183 [[typedef union ]b4_union_name
[
187 # define YYSTYPE_IS_TRIVIAL 1]],
188 [m4_if(b4_tag_seen_flag
, 0,
189 [[typedef int YYSTYPE
;
190 # define YYSTYPE_IS_TRIVIAL 1]])])[
193 #if ! defined YYLTYPE && ! defined YYLTYPE_IS_DECLARED
194 typedef struct YYLTYPE
205 # define YYLTYPE_IS_DECLARED 1
206 # define YYLTYPE_IS_TRIVIAL 1
209 ]b4_percent_code_get([[provides]])[]dnl
212 b4_defines_if([[#include "@basename(]b4_spec_defines_file[@)"]],
213 [b4_shared_declarations
])[
215 /* Enabling traces. */
217 # define YYDEBUG ]b4_debug_flag[
220 /* Enabling verbose error messages. */
221 #ifdef YYERROR_VERBOSE
222 # undef YYERROR_VERBOSE
223 # define YYERROR_VERBOSE 1
225 # define YYERROR_VERBOSE ]b4_error_verbose_flag[
228 /* Enabling the token table. */
229 #ifndef YYTOKEN_TABLE
230 # define YYTOKEN_TABLE ]b4_token_table[
233 /* Default (constant) value used for initialization for null
234 right-hand sides. Unlike the standard yacc.c template,
235 here we set the default value of $$ to a zeroed-out value.
236 Since the default value is undefined, this behavior is
237 technically correct. */
238 static YYSTYPE yyval_default
;
240 /* Copy the second part of user declarations. */
241 ]b4_user_post_prologue
242 b4_percent_code_get
[]dnl
251 # include <libintl.h> /* INFRINGES ON USER NAME SPACE */
252 # define YY_(msgid) dgettext ("bison-runtime", msgid)
256 # define YY_(msgid) msgid
260 /* Suppress unused-variable warnings by "using" E. */
261 #if ! defined lint || defined __GNUC__
262 # define YYUSE(e) ((void) (e))
264 # define YYUSE(e) /* empty */
267 /* Identity function, used to suppress warnings about constant conditions. */
271 ]b4_c_function_def([YYID
], [static int], [[int i
], [i
]])[
281 # define YYMALLOC malloc
284 # define YYREALLOC realloc
287 #define YYSIZEMAX ((size_t) -1)
292 typedef unsigned char yybool
;
299 # define YYJMP_BUF jmp_buf
300 # define YYSETJMP(env) setjmp (env)
301 # define YYLONGJMP(env, val) longjmp (env, val)
308 #ifndef __attribute__
309 /* This feature is available in gcc versions 2.5 and later. */
310 # if (! defined __GNUC__ || __GNUC__ < 2 \
311 || (__GNUC__ == 2 && __GNUC_MINOR__ < 5) || __STRICT_ANSI__)
312 # define __attribute__(Spec) /* empty */
316 ]b4_locations_if([#define YYOPTIONAL_LOC(Name) Name],[
318 # define YYOPTIONAL_LOC(Name) /* empty */
320 # define YYOPTIONAL_LOC(Name) Name __attribute__ ((__unused__))
324 # define YYASSERT(condition) ((void) ((condition) || (abort (), 0)))
327 /* YYFINAL -- State number of the termination state. */
328 #define YYFINAL ]b4_final_state_number[
329 /* YYLAST -- Last index in YYTABLE. */
330 #define YYLAST ]b4_last[
332 /* YYNTOKENS -- Number of terminals. */
333 #define YYNTOKENS ]b4_tokens_number[
334 /* YYNNTS -- Number of nonterminals. */
335 #define YYNNTS ]b4_nterms_number[
336 /* YYNRULES -- Number of rules. */
337 #define YYNRULES ]b4_rules_number[
338 /* YYNRULES -- Number of states. */
339 #define YYNSTATES ]b4_states_number[
340 /* YYMAXRHS -- Maximum number of symbols on right-hand side of rule. */
341 #define YYMAXRHS ]b4_r2_max[
342 /* YYMAXLEFT -- Maximum number of symbols to the left of a handle
343 accessed by $0, $-1, etc., in any rule. */
344 #define YYMAXLEFT ]b4_max_left_semantic_context[
346 /* YYTRANSLATE(X) -- Bison symbol number corresponding to X. */
347 #define YYUNDEFTOK ]b4_undef_token_number[
348 #define YYMAXUTOK ]b4_user_token_number_max[
350 #define YYTRANSLATE(YYX) \
351 ((unsigned int) (YYX) <= YYMAXUTOK ? yytranslate[YYX] : YYUNDEFTOK)
353 /* YYTRANSLATE[YYLEX] -- Bison symbol number corresponding to YYLEX. */
354 static const ]b4_int_type_for([b4_translate
])[ yytranslate
[] =
360 /* YYPRHS[YYN] -- Index of the first RHS symbol of rule number YYN in
362 static const ]b4_int_type_for([b4_prhs
])[ yyprhs
[] =
367 /* YYRHS -- A `-1'-separated list of the rules' RHS. */
368 static const ]b4_int_type_for([b4_rhs
])[ yyrhs
[] =
373 /* YYRLINE[YYN] -- source line where rule number YYN was defined. */
374 static const ]b4_int_type_for([b4_rline
])[ yyrline
[] =
380 #if YYDEBUG || YYERROR_VERBOSE || YYTOKEN_TABLE
381 /* YYTNAME[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM.
382 First, the terminals, then, starting at YYNTOKENS, nonterminals. */
383 static const char *const yytname
[] =
389 /* YYR1[YYN] -- Symbol number of symbol that rule YYN derives. */
390 static const ]b4_int_type_for([b4_r1
])[ yyr1
[] =
395 /* YYR2[YYN] -- Number of symbols composing right hand side of rule YYN. */
396 static const ]b4_int_type_for([b4_r2
])[ yyr2
[] =
401 /* YYDPREC[RULE-NUM] -- Dynamic precedence of rule #RULE-NUM (0 if none). */
402 static const ]b4_int_type_for([b4_dprec
])[ yydprec
[] =
407 /* YYMERGER[RULE-NUM] -- Index of merging function for rule #RULE-NUM. */
408 static const ]b4_int_type_for([b4_merger
])[ yymerger
[] =
413 /* YYDEFACT[S] -- default rule to reduce with in state S when YYTABLE
414 doesn't specify something else to do. Zero means the default is an
416 static const ]b4_int_type_for([b4_defact
])[ yydefact
[] =
421 /* YYPDEFGOTO[NTERM-NUM]. */
422 static const ]b4_int_type_for([b4_defgoto
])[ yydefgoto
[] =
427 /* YYPACT[STATE-NUM] -- Index in YYTABLE of the portion describing
429 #define YYPACT_NINF ]b4_pact_ninf[
430 static const ]b4_int_type_for([b4_pact
])[ yypact
[] =
435 /* YYPGOTO[NTERM-NUM]. */
436 static const ]b4_int_type_for([b4_pgoto
])[ yypgoto
[] =
441 /* YYTABLE[YYPACT[STATE-NUM]]. What to do in state STATE-NUM. If
442 positive, shift that token. If negative, reduce the rule which
443 number is the opposite. If zero, do what YYDEFACT says.
444 If YYTABLE_NINF, syntax error. */
445 #define YYTABLE_NINF ]b4_table_ninf[
446 static const ]b4_int_type_for([b4_table
])[ yytable
[] =
451 /* YYCONFLP[YYPACT[STATE-NUM]] -- Pointer into YYCONFL of start of
452 list of conflicting reductions corresponding to action entry for
453 state STATE-NUM in yytable. 0 means no conflicts. The list in
454 yyconfl is terminated by a rule number of 0. */
455 static const ]b4_int_type_for([b4_conflict_list_heads
])[ yyconflp
[] =
457 ]b4_conflict_list_heads
[
460 /* YYCONFL[I] -- lists of conflicting rule numbers, each terminated by
461 0, pointed into by YYCONFLP. */
462 ]dnl Do
not use b4_int_type_for here
, since there are places where
463 dnl pointers onto yyconfl are taken
, which type is
"short int *".
464 dnl We probably ought to introduce a type
for confl
.
465 [static const short int yyconfl
[] =
467 ]b4_conflicting_rules
[
470 static const ]b4_int_type_for([b4_check
])[ yycheck
[] =
475 /* YYSTOS[STATE-NUM] -- The (internal number of the) accessing
476 symbol of state STATE-NUM. */
477 static const ]b4_int_type_for([b4_stos
])[ yystos
[] =
483 /* Prevent warning if -Wmissing-prototypes. */
484 ]b4_c_ansi_function_decl([yyparse
], [int], b4_parse_param
)[
486 /* Error token number */
489 /* YYLLOC_DEFAULT -- Set CURRENT to span from RHS[1] to RHS[N].
490 If N is 0, then set CURRENT to the empty location which ends
491 the previous symbol: RHS[0] (always defined). */
494 #define YYRHSLOC(Rhs, K) ((Rhs)[K].yystate.yyloc)
495 #ifndef YYLLOC_DEFAULT
496 # define YYLLOC_DEFAULT(Current, Rhs, N) \
500 (Current).first_line = YYRHSLOC (Rhs, 1).first_line; \
501 (Current).first_column = YYRHSLOC (Rhs, 1).first_column; \
502 (Current).last_line = YYRHSLOC (Rhs, N).last_line; \
503 (Current).last_column = YYRHSLOC (Rhs, N).last_column; \
507 (Current).first_line = (Current).last_line = \
508 YYRHSLOC (Rhs, 0).last_line; \
509 (Current).first_column = (Current).last_column = \
510 YYRHSLOC (Rhs, 0).last_column; \
514 /* YY_LOCATION_PRINT -- Print the location on the stream.
515 This macro was not mandated originally: define only if we know
516 we won't break user code: when these are the locations we know. */
518 # define YY_LOCATION_PRINT(File, Loc) \
519 fprintf (File, "%d.%d-%d.%d", \
520 (Loc).first_line, (Loc).first_column, \
521 (Loc).last_line, (Loc).last_column)
524 #ifndef YYLLOC_DEFAULT
525 # define YYLLOC_DEFAULT(Current, Rhs, N) ((void) 0)
529 #ifndef YY_LOCATION_PRINT
530 # define YY_LOCATION_PRINT(File, Loc) ((void) 0)
534 /* YYLEX -- calling `yylex' with the right arguments. */
535 #define YYLEX ]b4_c_function_call([yylex], [int], b4_lex_param)[
540 #define yynerrs (yystackp->yyerrcnt)
542 #define yychar (yystackp->yyrawchar)
544 #define yylval (yystackp->yyval)
546 #define yylloc (yystackp->yyloc)
547 m4_if(b4_prefix
[], [yy
], [],
548 [#define b4_prefix[]nerrs yynerrs
549 #define b4_prefix[]char yychar
550 #define b4_prefix[]lval yylval
551 #define b4_prefix[]lloc yylloc])],
559 static const int YYEOF
= 0;
560 static const int YYEMPTY
= -2;
562 typedef enum { yyok
, yyaccept
, yyabort
, yyerr
} YYRESULTTAG
;
565 do { YYRESULTTAG yyflag = YYE; if (yyflag != yyok) return yyflag; } \
571 # define YYFPRINTF fprintf
574 # define YYDPRINTF(Args) \
580 ]b4_yy_symbol_print_generate([b4_c_ansi_function_def
])[
582 # define YY_SYMBOL_PRINT(Title, Type, Value, Location) \
586 YYFPRINTF (stderr, "%s ", Title); \
587 yy_symbol_print (stderr, Type, \
588 Value]b4_locations_if([, Location])[]b4_user_args[); \
589 YYFPRINTF (stderr, "\n"); \
593 /* Nonzero means print parse trace. It is left uninitialized so that
594 multiple parsers can coexist. */
599 # define YYDPRINTF(Args)
600 # define YY_SYMBOL_PRINT(Title, Type, Value, Location)
602 #endif /* !YYDEBUG */
604 /* YYINITDEPTH -- initial size of the parser's stacks. */
606 # define YYINITDEPTH ]b4_stack_depth_init[
609 /* YYMAXDEPTH -- maximum size the stacks can grow to (effective only
610 if the built-in stack extension method is used).
612 Do not make this value too large; the results are undefined if
613 SIZE_MAX < YYMAXDEPTH * sizeof (GLRStackItem)
614 evaluated with infinite-precision integer arithmetic. */
617 # define YYMAXDEPTH ]b4_stack_depth_max[
620 /* Minimum number of free items on the stack allowed after an
621 allocation. This is to allow allocation and initialization
622 to be completed by functions that call yyexpandGLRStack before the
623 stack is expanded, thus insuring that all necessary pointers get
624 properly redirected to new data. */
627 #ifndef YYSTACKEXPANDABLE
628 # if (! defined __cplusplus \
629 || (]b4_locations_if([[defined YYLTYPE_IS_TRIVIAL && YYLTYPE_IS_TRIVIAL \
630 && ]])[defined YYSTYPE_IS_TRIVIAL && YYSTYPE_IS_TRIVIAL))
631 # define YYSTACKEXPANDABLE 1
633 # define YYSTACKEXPANDABLE 0
637 #if YYSTACKEXPANDABLE
638 # define YY_RESERVE_GLRSTACK(Yystack) \
640 if (Yystack->yyspaceLeft < YYHEADROOM) \
641 yyexpandGLRStack (Yystack); \
644 # define YY_RESERVE_GLRSTACK(Yystack) \
646 if (Yystack->yyspaceLeft < YYHEADROOM) \
647 yyMemoryExhausted (Yystack); \
655 # if defined __GLIBC__ && defined _STRING_H && defined _GNU_SOURCE
656 # define yystpcpy stpcpy
658 /* Copy YYSRC to YYDEST, returning the address of the terminating '\0' in
661 yystpcpy (char *yydest
, const char *yysrc
)
664 const char *yys
= yysrc
;
666 while ((*yyd
++ = *yys
++) != '\0')
675 /* Copy to YYRES the contents of YYSTR after stripping away unnecessary
676 quotes and backslashes, so that it's suitable for yyerror. The
677 heuristic is that double-quoting is unnecessary unless the string
678 contains an apostrophe, a comma, or backslash (other than
679 backslash-backslash). YYSTR is taken from yytname. If YYRES is
680 null, do not copy; instead, return the length of what the result
683 yytnamerr (char *yyres
, const char *yystr
)
688 char const *yyp
= yystr
;
695 goto do_not_strip_quotes
;
699 goto do_not_strip_quotes
;
712 do_not_strip_quotes
: ;
716 return strlen (yystr
);
718 return yystpcpy (yyres
, yystr
) - yyres
;
722 #endif /* !YYERROR_VERBOSE */
724 /** State numbers, as in LALR(1) machine */
725 typedef int yyStateNum
;
727 /** Rule numbers, as in LALR(1) machine */
728 typedef int yyRuleNum
;
730 /** Grammar symbol */
731 typedef short int yySymbol
;
733 /** Item references, as in LALR(1) machine */
734 typedef short int yyItemNum
;
736 typedef struct yyGLRState yyGLRState
;
737 typedef struct yyGLRStateSet yyGLRStateSet
;
738 typedef struct yySemanticOption yySemanticOption
;
739 typedef union yyGLRStackItem yyGLRStackItem
;
740 typedef struct yyGLRStack yyGLRStack
;
743 /** Type tag: always true. */
745 /** Type tag for yysemantics. If true, yysval applies, otherwise
746 * yyfirstVal applies. */
748 /** Number of corresponding LALR(1) machine state. */
749 yyStateNum yylrState
;
750 /** Preceding state in this stack */
752 /** Source position of the first token produced by my symbol */
755 /** First in a chain of alternative reductions producing the
756 * non-terminal corresponding to this state, threaded through
758 yySemanticOption
* yyfirstVal
;
759 /** Semantic value for this state. */
762 /** Source location for this state. */
766 struct yyGLRStateSet
{
767 yyGLRState
** yystates
;
768 /** During nondeterministic operation, yylookaheadNeeds tracks which
769 * stacks have actually needed the current lookahead. During deterministic
770 * operation, yylookaheadNeeds[0] is not maintained since it would merely
771 * duplicate yychar != YYEMPTY. */
772 yybool
* yylookaheadNeeds
;
773 size_t yysize
, yycapacity
;
776 struct yySemanticOption
{
777 /** Type tag: always false. */
779 /** Rule number for this reduction */
781 /** The last RHS state in the list of states to be reduced. */
783 /** The lookahead for this reduction. */
787 /** Next sibling in chain of options. To facilitate merging,
788 * options are chained in decreasing order by address. */
789 yySemanticOption
* yynext
;
792 /** Type of the items in the GLR stack. The yyisState field
793 * indicates which item of the union is valid. */
794 union yyGLRStackItem
{
796 yySemanticOption yyoption
;
801 ]b4_locations_if([[ /* To compute the location of the error token. */
802 yyGLRStackItem yyerror_range
[3];]])[
810 YYJMP_BUF yyexception_buffer
;
811 yyGLRStackItem
* yyitems
;
812 yyGLRStackItem
* yynextFree
;
814 yyGLRState
* yysplitPoint
;
815 yyGLRState
* yylastDeleted
;
816 yyGLRStateSet yytops
;
819 #if YYSTACKEXPANDABLE
820 static void yyexpandGLRStack (yyGLRStack
* yystackp
);
823 static void yyFail (yyGLRStack
* yystackp
]b4_pure_formals
[, const char* yymsg
)
824 __attribute__ ((__noreturn__
));
826 yyFail (yyGLRStack
* yystackp
]b4_pure_formals
[, const char* yymsg
)
829 yyerror (]b4_yyerror_args
[yymsg
);
830 YYLONGJMP (yystackp
->yyexception_buffer
, 1);
833 static void yyMemoryExhausted (yyGLRStack
* yystackp
)
834 __attribute__ ((__noreturn__
));
836 yyMemoryExhausted (yyGLRStack
* yystackp
)
838 YYLONGJMP (yystackp
->yyexception_buffer
, 2);
841 #if YYDEBUG || YYERROR_VERBOSE
842 /** A printable representation of TOKEN. */
843 static inline const char*
844 yytokenName (yySymbol yytoken
)
846 if (yytoken
== YYEMPTY
)
849 return yytname
[yytoken
];
853 /** Fill in YYVSP[YYLOW1 .. YYLOW0-1] from the chain of states starting
854 * at YYVSP[YYLOW0].yystate.yypred. Leaves YYVSP[YYLOW1].yystate.yypred
855 * containing the pointer to the next state in the chain. */
856 static void yyfillin (yyGLRStackItem
*, int, int) __attribute__ ((__unused__
));
858 yyfillin (yyGLRStackItem
*yyvsp
, int yylow0
, int yylow1
)
862 s
= yyvsp
[yylow0
].yystate
.yypred
;
863 for (i
= yylow0
-1; i
>= yylow1
; i
-= 1)
865 YYASSERT (s
->yyresolved
);
866 yyvsp
[i
].yystate
.yyresolved
= yytrue
;
867 yyvsp
[i
].yystate
.yysemantics
.yysval
= s
->yysemantics
.yysval
;
868 yyvsp
[i
].yystate
.yyloc
= s
->yyloc
;
869 s
= yyvsp
[i
].yystate
.yypred
= s
->yypred
;
873 /* Do nothing if YYNORMAL or if *YYLOW <= YYLOW1. Otherwise, fill in
874 * YYVSP[YYLOW1 .. *YYLOW-1] as in yyfillin and set *YYLOW = YYLOW1.
875 * For convenience, always return YYLOW1. */
876 static inline int yyfill (yyGLRStackItem
*, int *, int, yybool
)
877 __attribute__ ((__unused__
));
879 yyfill (yyGLRStackItem
*yyvsp
, int *yylow
, int yylow1
, yybool yynormal
)
881 if (!yynormal
&& yylow1
< *yylow
)
883 yyfillin (yyvsp
, *yylow
, yylow1
);
889 /** Perform user action for rule number YYN, with RHS length YYRHSLEN,
890 * and top stack item YYVSP. YYLVALP points to place to put semantic
891 * value ($$), and yylocp points to place for location information
892 * (@@$). Returns yyok for normal return, yyaccept for YYACCEPT,
893 * yyerr for YYERROR, yyabort for YYABORT. */
894 /*ARGSUSED*/ static YYRESULTTAG
895 yyuserAction (yyRuleNum yyn
, int yyrhslen
, yyGLRStackItem
* yyvsp
,
897 YYLTYPE
* YYOPTIONAL_LOC (yylocp
),
901 yybool yynormal
__attribute__ ((__unused__
)) =
902 (yystackp
->yysplitPoint
== NULL
);
904 ]b4_parse_param_use
[]dnl
906 # define yyerrok (yystackp->yyerrState = 0)
908 # define YYACCEPT return yyaccept
910 # define YYABORT return yyabort
912 # define YYERROR return yyerrok, yyerr
914 # define YYRECOVERING() (yystackp->yyerrState != 0)
916 # define yyclearin (yychar = YYEMPTY)
918 # define YYFILL(N) yyfill (yyvsp, &yylow, N, yynormal)
920 # define YYBACKUP(Token, Value) \
921 return yyerror (]b4_yyerror_args[YY_("syntax error: cannot back up")), \
926 *yyvalp
= yyval_default
;
928 *yyvalp
= yyvsp
[YYFILL (1-yyrhslen
)].yystate
.yysemantics
.yysval
;
929 YYLLOC_DEFAULT ((*yylocp
), (yyvsp
- yyrhslen
), yyrhslen
);
930 ]b4_locations_if([[ yystackp
->yyerror_range
[1].yystate
.yyloc
= *yylocp
;
949 /*ARGSUSED*/ static void
950 yyuserMerge (int yyn
, YYSTYPE
* yy0
, YYSTYPE
* yy1
)
962 /* Bison grammar-table manipulation. */
964 ]b4_yydestruct_generate([b4_c_ansi_function_def
])[
966 /** Number of symbols composing the right hand side of rule #RULE. */
968 yyrhsLength (yyRuleNum yyrule
)
974 yydestroyGLRState (char const *yymsg
, yyGLRState
*yys
]b4_user_formals
[)
977 yydestruct (yymsg
, yystos
[yys
->yylrState
],
978 &yys
->yysemantics
.yysval
]b4_locations_if([, &yys
->yyloc
])[]b4_user_args
[);
984 if (yys
->yysemantics
.yyfirstVal
)
985 YYFPRINTF (stderr
, "%s unresolved ", yymsg
);
987 YYFPRINTF (stderr
, "%s incomplete ", yymsg
);
988 yy_symbol_print (stderr
, yystos
[yys
->yylrState
],
989 NULL
]b4_locations_if([, &yys
->yyloc
])[]b4_user_args
[);
990 YYFPRINTF (stderr
, "\n");
994 if (yys
->yysemantics
.yyfirstVal
)
996 yySemanticOption
*yyoption
= yys
->yysemantics
.yyfirstVal
;
999 for (yyrh
= yyoption
->yystate
, yyn
= yyrhsLength (yyoption
->yyrule
);
1001 yyrh
= yyrh
->yypred
, yyn
-= 1)
1002 yydestroyGLRState (yymsg
, yyrh
]b4_user_args
[);
1007 /** Left-hand-side symbol for rule #RULE. */
1008 static inline yySymbol
1009 yylhsNonterm (yyRuleNum yyrule
)
1011 return yyr1
[yyrule
];
1014 #define yyis_pact_ninf(yystate) \
1015 ]m4_if(m4_eval(b4_pact_ninf < b4_pact_min), [1],
1017 [((yystate
) == YYPACT_NINF
)])[
1019 /** True iff LR state STATE has only a default reduction (regardless
1021 static inline yybool
1022 yyisDefaultedState (yyStateNum yystate
)
1024 return yyis_pact_ninf (yypact
[yystate
]);
1027 /** The default reduction for STATE, assuming it has one. */
1028 static inline yyRuleNum
1029 yydefaultAction (yyStateNum yystate
)
1031 return yydefact
[yystate
];
1034 #define yyis_table_ninf(yytable_value) \
1035 ]m4_if(m4_eval(b4_table_ninf < b4_table_min), [1],
1037 [((yytable_value
) == YYTABLE_NINF
)])[
1039 /** Set *YYACTION to the action to take in YYSTATE on seeing YYTOKEN.
1041 * R < 0: Reduce on rule -R.
1043 * R > 0: Shift to state R.
1044 * Set *CONFLICTS to a pointer into yyconfl to 0-terminated list of
1045 * conflicting reductions.
1048 yygetLRActions (yyStateNum yystate
, int yytoken
,
1049 int* yyaction
, const short int** yyconflicts
)
1051 int yyindex
= yypact
[yystate
] + yytoken
;
1052 if (yyindex
< 0 || YYLAST
< yyindex
|| yycheck
[yyindex
] != yytoken
)
1054 *yyaction
= -yydefact
[yystate
];
1055 *yyconflicts
= yyconfl
;
1057 else if (! yyis_table_ninf (yytable
[yyindex
]))
1059 *yyaction
= yytable
[yyindex
];
1060 *yyconflicts
= yyconfl
+ yyconflp
[yyindex
];
1065 *yyconflicts
= yyconfl
+ yyconflp
[yyindex
];
1069 static inline yyStateNum
1070 yyLRgotoState (yyStateNum yystate
, yySymbol yylhs
)
1073 yyr
= yypgoto
[yylhs
- YYNTOKENS
] + yystate
;
1074 if (0 <= yyr
&& yyr
<= YYLAST
&& yycheck
[yyr
] == yystate
)
1075 return yytable
[yyr
];
1077 return yydefgoto
[yylhs
- YYNTOKENS
];
1080 static inline yybool
1081 yyisShiftAction (int yyaction
)
1083 return 0 < yyaction
;
1086 static inline yybool
1087 yyisErrorAction (int yyaction
)
1089 return yyaction
== 0;
1094 /** Return a fresh GLRStackItem. Callers should call
1095 * YY_RESERVE_GLRSTACK afterwards to make sure there is sufficient
1098 static inline yyGLRStackItem
*
1099 yynewGLRStackItem (yyGLRStack
* yystackp
, yybool yyisState
)
1101 yyGLRStackItem
* yynewItem
= yystackp
->yynextFree
;
1102 yystackp
->yyspaceLeft
-= 1;
1103 yystackp
->yynextFree
+= 1;
1104 yynewItem
->yystate
.yyisState
= yyisState
;
1108 /** Add a new semantic action that will execute the action for rule
1109 * RULENUM on the semantic values in RHS to the list of
1110 * alternative actions for STATE. Assumes that RHS comes from
1111 * stack #K of *STACKP. */
1113 yyaddDeferredAction (yyGLRStack
* yystackp
, size_t yyk
, yyGLRState
* yystate
,
1114 yyGLRState
* rhs
, yyRuleNum yyrule
)
1116 yySemanticOption
* yynewOption
=
1117 &yynewGLRStackItem (yystackp
, yyfalse
)->yyoption
;
1118 yynewOption
->yystate
= rhs
;
1119 yynewOption
->yyrule
= yyrule
;
1120 if (yystackp
->yytops
.yylookaheadNeeds
[yyk
])
1122 yynewOption
->yyrawchar
= yychar
;
1123 yynewOption
->yyval
= yylval
;
1124 yynewOption
->yyloc
= yylloc
;
1127 yynewOption
->yyrawchar
= YYEMPTY
;
1128 yynewOption
->yynext
= yystate
->yysemantics
.yyfirstVal
;
1129 yystate
->yysemantics
.yyfirstVal
= yynewOption
;
1131 YY_RESERVE_GLRSTACK (yystackp
);
1136 /** Initialize SET to a singleton set containing an empty stack. */
1138 yyinitStateSet (yyGLRStateSet
* yyset
)
1141 yyset
->yycapacity
= 16;
1142 yyset
->yystates
= (yyGLRState
**) YYMALLOC (16 * sizeof yyset
->yystates
[0]);
1143 if (! yyset
->yystates
)
1145 yyset
->yystates
[0] = NULL
;
1146 yyset
->yylookaheadNeeds
=
1147 (yybool
*) YYMALLOC (16 * sizeof yyset
->yylookaheadNeeds
[0]);
1148 if (! yyset
->yylookaheadNeeds
)
1150 YYFREE (yyset
->yystates
);
1156 static void yyfreeStateSet (yyGLRStateSet
* yyset
)
1158 YYFREE (yyset
->yystates
);
1159 YYFREE (yyset
->yylookaheadNeeds
);
1162 /** Initialize STACK to a single empty stack, with total maximum
1163 * capacity for all stacks of SIZE. */
1165 yyinitGLRStack (yyGLRStack
* yystackp
, size_t yysize
)
1167 yystackp
->yyerrState
= 0;
1169 yystackp
->yyspaceLeft
= yysize
;
1171 (yyGLRStackItem
*) YYMALLOC (yysize
* sizeof yystackp
->yynextFree
[0]);
1172 if (!yystackp
->yyitems
)
1174 yystackp
->yynextFree
= yystackp
->yyitems
;
1175 yystackp
->yysplitPoint
= NULL
;
1176 yystackp
->yylastDeleted
= NULL
;
1177 return yyinitStateSet (&yystackp
->yytops
);
1181 #if YYSTACKEXPANDABLE
1182 # define YYRELOC(YYFROMITEMS,YYTOITEMS,YYX,YYTYPE) \
1183 &((YYTOITEMS) - ((YYFROMITEMS) - (yyGLRStackItem*) (YYX)))->YYTYPE
1185 /** If STACK is expandable, extend it. WARNING: Pointers into the
1186 stack from outside should be considered invalid after this call.
1187 We always expand when there are 1 or fewer items left AFTER an
1188 allocation, so that we can avoid having external pointers exist
1189 across an allocation. */
1191 yyexpandGLRStack (yyGLRStack
* yystackp
)
1193 yyGLRStackItem
* yynewItems
;
1194 yyGLRStackItem
* yyp0
, *yyp1
;
1195 size_t yysize
, yynewSize
;
1197 yysize
= yystackp
->yynextFree
- yystackp
->yyitems
;
1198 if (YYMAXDEPTH
- YYHEADROOM
< yysize
)
1199 yyMemoryExhausted (yystackp
);
1200 yynewSize
= 2*yysize
;
1201 if (YYMAXDEPTH
< yynewSize
)
1202 yynewSize
= YYMAXDEPTH
;
1203 yynewItems
= (yyGLRStackItem
*) YYMALLOC (yynewSize
* sizeof yynewItems
[0]);
1205 yyMemoryExhausted (yystackp
);
1206 for (yyp0
= yystackp
->yyitems
, yyp1
= yynewItems
, yyn
= yysize
;
1208 yyn
-= 1, yyp0
+= 1, yyp1
+= 1)
1211 if (*(yybool
*) yyp0
)
1213 yyGLRState
* yys0
= &yyp0
->yystate
;
1214 yyGLRState
* yys1
= &yyp1
->yystate
;
1215 if (yys0
->yypred
!= NULL
)
1217 YYRELOC (yyp0
, yyp1
, yys0
->yypred
, yystate
);
1218 if (! yys0
->yyresolved
&& yys0
->yysemantics
.yyfirstVal
!= NULL
)
1219 yys1
->yysemantics
.yyfirstVal
=
1220 YYRELOC(yyp0
, yyp1
, yys0
->yysemantics
.yyfirstVal
, yyoption
);
1224 yySemanticOption
* yyv0
= &yyp0
->yyoption
;
1225 yySemanticOption
* yyv1
= &yyp1
->yyoption
;
1226 if (yyv0
->yystate
!= NULL
)
1227 yyv1
->yystate
= YYRELOC (yyp0
, yyp1
, yyv0
->yystate
, yystate
);
1228 if (yyv0
->yynext
!= NULL
)
1229 yyv1
->yynext
= YYRELOC (yyp0
, yyp1
, yyv0
->yynext
, yyoption
);
1232 if (yystackp
->yysplitPoint
!= NULL
)
1233 yystackp
->yysplitPoint
= YYRELOC (yystackp
->yyitems
, yynewItems
,
1234 yystackp
->yysplitPoint
, yystate
);
1236 for (yyn
= 0; yyn
< yystackp
->yytops
.yysize
; yyn
+= 1)
1237 if (yystackp
->yytops
.yystates
[yyn
] != NULL
)
1238 yystackp
->yytops
.yystates
[yyn
] =
1239 YYRELOC (yystackp
->yyitems
, yynewItems
,
1240 yystackp
->yytops
.yystates
[yyn
], yystate
);
1241 YYFREE (yystackp
->yyitems
);
1242 yystackp
->yyitems
= yynewItems
;
1243 yystackp
->yynextFree
= yynewItems
+ yysize
;
1244 yystackp
->yyspaceLeft
= yynewSize
- yysize
;
1249 yyfreeGLRStack (yyGLRStack
* yystackp
)
1251 YYFREE (yystackp
->yyitems
);
1252 yyfreeStateSet (&yystackp
->yytops
);
1255 /** Assuming that S is a GLRState somewhere on STACK, update the
1256 * splitpoint of STACK, if needed, so that it is at least as deep as
1259 yyupdateSplit (yyGLRStack
* yystackp
, yyGLRState
* yys
)
1261 if (yystackp
->yysplitPoint
!= NULL
&& yystackp
->yysplitPoint
> yys
)
1262 yystackp
->yysplitPoint
= yys
;
1265 /** Invalidate stack #K in STACK. */
1267 yymarkStackDeleted (yyGLRStack
* yystackp
, size_t yyk
)
1269 if (yystackp
->yytops
.yystates
[yyk
] != NULL
)
1270 yystackp
->yylastDeleted
= yystackp
->yytops
.yystates
[yyk
];
1271 yystackp
->yytops
.yystates
[yyk
] = NULL
;
1274 /** Undelete the last stack that was marked as deleted. Can only be
1275 done once after a deletion, and only when all other stacks have
1278 yyundeleteLastStack (yyGLRStack
* yystackp
)
1280 if (yystackp
->yylastDeleted
== NULL
|| yystackp
->yytops
.yysize
!= 0)
1282 yystackp
->yytops
.yystates
[0] = yystackp
->yylastDeleted
;
1283 yystackp
->yytops
.yysize
= 1;
1284 YYDPRINTF ((stderr
, "Restoring last deleted stack as stack #0.\n"));
1285 yystackp
->yylastDeleted
= NULL
;
1289 yyremoveDeletes (yyGLRStack
* yystackp
)
1293 while (yyj
< yystackp
->yytops
.yysize
)
1295 if (yystackp
->yytops
.yystates
[yyi
] == NULL
)
1299 YYDPRINTF ((stderr
, "Removing dead stacks.\n"));
1301 yystackp
->yytops
.yysize
-= 1;
1305 yystackp
->yytops
.yystates
[yyj
] = yystackp
->yytops
.yystates
[yyi
];
1306 /* In the current implementation, it's unnecessary to copy
1307 yystackp->yytops.yylookaheadNeeds[yyi] since, after
1308 yyremoveDeletes returns, the parser immediately either enters
1309 deterministic operation or shifts a token. However, it doesn't
1310 hurt, and the code might evolve to need it. */
1311 yystackp
->yytops
.yylookaheadNeeds
[yyj
] =
1312 yystackp
->yytops
.yylookaheadNeeds
[yyi
];
1315 YYDPRINTF ((stderr
, "Rename stack %lu -> %lu.\n",
1316 (unsigned long int) yyi
, (unsigned long int) yyj
));
1324 /** Shift to a new state on stack #K of STACK, corresponding to LR state
1325 * LRSTATE, at input position POSN, with (resolved) semantic value SVAL. */
1327 yyglrShift (yyGLRStack
* yystackp
, size_t yyk
, yyStateNum yylrState
,
1329 YYSTYPE
* yyvalp
, YYLTYPE
* yylocp
)
1331 yyGLRState
* yynewState
= &yynewGLRStackItem (yystackp
, yytrue
)->yystate
;
1333 yynewState
->yylrState
= yylrState
;
1334 yynewState
->yyposn
= yyposn
;
1335 yynewState
->yyresolved
= yytrue
;
1336 yynewState
->yypred
= yystackp
->yytops
.yystates
[yyk
];
1337 yynewState
->yysemantics
.yysval
= *yyvalp
;
1338 yynewState
->yyloc
= *yylocp
;
1339 yystackp
->yytops
.yystates
[yyk
] = yynewState
;
1341 YY_RESERVE_GLRSTACK (yystackp
);
1344 /** Shift stack #K of YYSTACK, to a new state corresponding to LR
1345 * state YYLRSTATE, at input position YYPOSN, with the (unresolved)
1346 * semantic value of YYRHS under the action for YYRULE. */
1348 yyglrShiftDefer (yyGLRStack
* yystackp
, size_t yyk
, yyStateNum yylrState
,
1349 size_t yyposn
, yyGLRState
* rhs
, yyRuleNum yyrule
)
1351 yyGLRState
* yynewState
= &yynewGLRStackItem (yystackp
, yytrue
)->yystate
;
1353 yynewState
->yylrState
= yylrState
;
1354 yynewState
->yyposn
= yyposn
;
1355 yynewState
->yyresolved
= yyfalse
;
1356 yynewState
->yypred
= yystackp
->yytops
.yystates
[yyk
];
1357 yynewState
->yysemantics
.yyfirstVal
= NULL
;
1358 yystackp
->yytops
.yystates
[yyk
] = yynewState
;
1360 /* Invokes YY_RESERVE_GLRSTACK. */
1361 yyaddDeferredAction (yystackp
, yyk
, yynewState
, rhs
, yyrule
);
1364 /** Pop the symbols consumed by reduction #RULE from the top of stack
1365 * #K of STACK, and perform the appropriate semantic action on their
1366 * semantic values. Assumes that all ambiguities in semantic values
1367 * have been previously resolved. Set *VALP to the resulting value,
1368 * and *LOCP to the computed location (if any). Return value is as
1369 * for userAction. */
1370 static inline YYRESULTTAG
1371 yydoAction (yyGLRStack
* yystackp
, size_t yyk
, yyRuleNum yyrule
,
1372 YYSTYPE
* yyvalp
, YYLTYPE
* yylocp
]b4_user_formals
[)
1374 int yynrhs
= yyrhsLength (yyrule
);
1376 if (yystackp
->yysplitPoint
== NULL
)
1378 /* Standard special case: single stack. */
1379 yyGLRStackItem
* rhs
= (yyGLRStackItem
*) yystackp
->yytops
.yystates
[yyk
];
1380 YYASSERT (yyk
== 0);
1381 yystackp
->yynextFree
-= yynrhs
;
1382 yystackp
->yyspaceLeft
+= yynrhs
;
1383 yystackp
->yytops
.yystates
[0] = & yystackp
->yynextFree
[-1].yystate
;
1384 return yyuserAction (yyrule
, yynrhs
, rhs
,
1385 yyvalp
, yylocp
, yystackp
]b4_user_args
[);
1389 /* At present, doAction is never called in nondeterministic
1390 * mode, so this branch is never taken. It is here in
1391 * anticipation of a future feature that will allow immediate
1392 * evaluation of selected actions in nondeterministic mode. */
1395 yyGLRStackItem yyrhsVals
[YYMAXRHS
+ YYMAXLEFT
+ 1];
1396 yys
= yyrhsVals
[YYMAXRHS
+ YYMAXLEFT
].yystate
.yypred
1397 = yystackp
->yytops
.yystates
[yyk
];]b4_locations_if([[
1399 /* Set default location. */
1400 yyrhsVals
[YYMAXRHS
+ YYMAXLEFT
- 1].yystate
.yyloc
= yys
->yyloc
;]])[
1401 for (yyi
= 0; yyi
< yynrhs
; yyi
+= 1)
1406 yyupdateSplit (yystackp
, yys
);
1407 yystackp
->yytops
.yystates
[yyk
] = yys
;
1408 return yyuserAction (yyrule
, yynrhs
, yyrhsVals
+ YYMAXRHS
+ YYMAXLEFT
- 1,
1409 yyvalp
, yylocp
, yystackp
]b4_user_args
[);
1414 # define YY_REDUCE_PRINT(Args)
1416 # define YY_REDUCE_PRINT(Args) \
1419 yy_reduce_print Args; \
1422 /*----------------------------------------------------------.
1423 | Report that the RULE is going to be reduced on stack #K. |
1424 `----------------------------------------------------------*/
1426 /*ARGSUSED*/ static inline void
1427 yy_reduce_print (yyGLRStack
* yystackp
, size_t yyk
, yyRuleNum yyrule
,
1428 YYSTYPE
* yyvalp
, YYLTYPE
* yylocp
]b4_user_formals
[)
1430 int yynrhs
= yyrhsLength (yyrule
);
1431 yybool yynormal
__attribute__ ((__unused__
)) =
1432 (yystackp
->yysplitPoint
== NULL
);
1433 yyGLRStackItem
* yyvsp
= (yyGLRStackItem
*) yystackp
->yytops
.yystates
[yyk
];
1438 ]b4_parse_param_use
[]dnl
1439 [ YYFPRINTF (stderr
, "Reducing stack %lu by rule %d (line %lu):\n",
1440 (unsigned long int) yyk
, yyrule
- 1,
1441 (unsigned long int) yyrline
[yyrule
]);
1442 /* The symbols being reduced. */
1443 for (yyi
= 0; yyi
< yynrhs
; yyi
++)
1445 YYFPRINTF (stderr
, " $%d = ", yyi
+ 1);
1446 yy_symbol_print (stderr
, yyrhs
[yyprhs
[yyrule
] + yyi
],
1447 &]b4_rhs_value(yynrhs
, yyi
+ 1)[
1448 ]b4_locations_if([, &]b4_rhs_location(yynrhs
, yyi
+ 1))[]dnl
1450 YYFPRINTF (stderr
, "\n");
1455 /** Pop items off stack #K of STACK according to grammar rule RULE,
1456 * and push back on the resulting nonterminal symbol. Perform the
1457 * semantic action associated with RULE and store its value with the
1458 * newly pushed state, if FORCEEVAL or if STACK is currently
1459 * unambiguous. Otherwise, store the deferred semantic action with
1460 * the new state. If the new state would have an identical input
1461 * position, LR state, and predecessor to an existing state on the stack,
1462 * it is identified with that existing state, eliminating stack #K from
1463 * the STACK. In this case, the (necessarily deferred) semantic value is
1464 * added to the options for the existing state's semantic value.
1466 static inline YYRESULTTAG
1467 yyglrReduce (yyGLRStack
* yystackp
, size_t yyk
, yyRuleNum yyrule
,
1468 yybool yyforceEval
]b4_user_formals
[)
1470 size_t yyposn
= yystackp
->yytops
.yystates
[yyk
]->yyposn
;
1472 if (yyforceEval
|| yystackp
->yysplitPoint
== NULL
)
1477 YY_REDUCE_PRINT ((yystackp
, yyk
, yyrule
, &yysval
, &yyloc
]b4_user_args
[));
1478 YYCHK (yydoAction (yystackp
, yyk
, yyrule
, &yysval
,
1479 &yyloc
]b4_user_args
[));
1480 YY_SYMBOL_PRINT ("-> $$ =", yyr1
[yyrule
], &yysval
, &yyloc
);
1481 yyglrShift (yystackp
, yyk
,
1482 yyLRgotoState (yystackp
->yytops
.yystates
[yyk
]->yylrState
,
1483 yylhsNonterm (yyrule
)),
1484 yyposn
, &yysval
, &yyloc
);
1490 yyGLRState
* yys
, *yys0
= yystackp
->yytops
.yystates
[yyk
];
1491 yyStateNum yynewLRState
;
1493 for (yys
= yystackp
->yytops
.yystates
[yyk
], yyn
= yyrhsLength (yyrule
);
1499 yyupdateSplit (yystackp
, yys
);
1500 yynewLRState
= yyLRgotoState (yys
->yylrState
, yylhsNonterm (yyrule
));
1502 "Reduced stack %lu by rule #%d; action deferred. Now in state %d.\n",
1503 (unsigned long int) yyk
, yyrule
- 1, yynewLRState
));
1504 for (yyi
= 0; yyi
< yystackp
->yytops
.yysize
; yyi
+= 1)
1505 if (yyi
!= yyk
&& yystackp
->yytops
.yystates
[yyi
] != NULL
)
1507 yyGLRState
* yyp
, *yysplit
= yystackp
->yysplitPoint
;
1508 yyp
= yystackp
->yytops
.yystates
[yyi
];
1509 while (yyp
!= yys
&& yyp
!= yysplit
&& yyp
->yyposn
>= yyposn
)
1511 if (yyp
->yylrState
== yynewLRState
&& yyp
->yypred
== yys
)
1513 yyaddDeferredAction (yystackp
, yyk
, yyp
, yys0
, yyrule
);
1514 yymarkStackDeleted (yystackp
, yyk
);
1515 YYDPRINTF ((stderr
, "Merging stack %lu into stack %lu.\n",
1516 (unsigned long int) yyk
,
1517 (unsigned long int) yyi
));
1523 yystackp
->yytops
.yystates
[yyk
] = yys
;
1524 yyglrShiftDefer (yystackp
, yyk
, yynewLRState
, yyposn
, yys0
, yyrule
);
1530 yysplitStack (yyGLRStack
* yystackp
, size_t yyk
)
1532 if (yystackp
->yysplitPoint
== NULL
)
1534 YYASSERT (yyk
== 0);
1535 yystackp
->yysplitPoint
= yystackp
->yytops
.yystates
[yyk
];
1537 if (yystackp
->yytops
.yysize
>= yystackp
->yytops
.yycapacity
)
1539 yyGLRState
** yynewStates
;
1540 yybool
* yynewLookaheadNeeds
;
1544 if (yystackp
->yytops
.yycapacity
1545 > (YYSIZEMAX
/ (2 * sizeof yynewStates
[0])))
1546 yyMemoryExhausted (yystackp
);
1547 yystackp
->yytops
.yycapacity
*= 2;
1550 (yyGLRState
**) YYREALLOC (yystackp
->yytops
.yystates
,
1551 (yystackp
->yytops
.yycapacity
1552 * sizeof yynewStates
[0]));
1553 if (yynewStates
== NULL
)
1554 yyMemoryExhausted (yystackp
);
1555 yystackp
->yytops
.yystates
= yynewStates
;
1557 yynewLookaheadNeeds
=
1558 (yybool
*) YYREALLOC (yystackp
->yytops
.yylookaheadNeeds
,
1559 (yystackp
->yytops
.yycapacity
1560 * sizeof yynewLookaheadNeeds
[0]));
1561 if (yynewLookaheadNeeds
== NULL
)
1562 yyMemoryExhausted (yystackp
);
1563 yystackp
->yytops
.yylookaheadNeeds
= yynewLookaheadNeeds
;
1565 yystackp
->yytops
.yystates
[yystackp
->yytops
.yysize
]
1566 = yystackp
->yytops
.yystates
[yyk
];
1567 yystackp
->yytops
.yylookaheadNeeds
[yystackp
->yytops
.yysize
]
1568 = yystackp
->yytops
.yylookaheadNeeds
[yyk
];
1569 yystackp
->yytops
.yysize
+= 1;
1570 return yystackp
->yytops
.yysize
-1;
1573 /** True iff Y0 and Y1 represent identical options at the top level.
1574 * That is, they represent the same rule applied to RHS symbols
1575 * that produce the same terminal symbols. */
1577 yyidenticalOptions (yySemanticOption
* yyy0
, yySemanticOption
* yyy1
)
1579 if (yyy0
->yyrule
== yyy1
->yyrule
)
1581 yyGLRState
*yys0
, *yys1
;
1583 for (yys0
= yyy0
->yystate
, yys1
= yyy1
->yystate
,
1584 yyn
= yyrhsLength (yyy0
->yyrule
);
1586 yys0
= yys0
->yypred
, yys1
= yys1
->yypred
, yyn
-= 1)
1587 if (yys0
->yyposn
!= yys1
->yyposn
)
1595 /** Assuming identicalOptions (Y0,Y1), destructively merge the
1596 * alternative semantic values for the RHS-symbols of Y1 and Y0. */
1598 yymergeOptionSets (yySemanticOption
* yyy0
, yySemanticOption
* yyy1
)
1600 yyGLRState
*yys0
, *yys1
;
1602 for (yys0
= yyy0
->yystate
, yys1
= yyy1
->yystate
,
1603 yyn
= yyrhsLength (yyy0
->yyrule
);
1605 yys0
= yys0
->yypred
, yys1
= yys1
->yypred
, yyn
-= 1)
1609 else if (yys0
->yyresolved
)
1611 yys1
->yyresolved
= yytrue
;
1612 yys1
->yysemantics
.yysval
= yys0
->yysemantics
.yysval
;
1614 else if (yys1
->yyresolved
)
1616 yys0
->yyresolved
= yytrue
;
1617 yys0
->yysemantics
.yysval
= yys1
->yysemantics
.yysval
;
1621 yySemanticOption
** yyz0p
;
1622 yySemanticOption
* yyz1
;
1623 yyz0p
= &yys0
->yysemantics
.yyfirstVal
;
1624 yyz1
= yys1
->yysemantics
.yyfirstVal
;
1625 while (YYID (yytrue
))
1627 if (yyz1
== *yyz0p
|| yyz1
== NULL
)
1629 else if (*yyz0p
== NULL
)
1634 else if (*yyz0p
< yyz1
)
1636 yySemanticOption
* yyz
= *yyz0p
;
1638 yyz1
= yyz1
->yynext
;
1639 (*yyz0p
)->yynext
= yyz
;
1641 yyz0p
= &(*yyz0p
)->yynext
;
1643 yys1
->yysemantics
.yyfirstVal
= yys0
->yysemantics
.yyfirstVal
;
1648 /** Y0 and Y1 represent two possible actions to take in a given
1649 * parsing state; return 0 if no combination is possible,
1650 * 1 if user-mergeable, 2 if Y0 is preferred, 3 if Y1 is preferred. */
1652 yypreference (yySemanticOption
* y0
, yySemanticOption
* y1
)
1654 yyRuleNum r0
= y0
->yyrule
, r1
= y1
->yyrule
;
1655 int p0
= yydprec
[r0
], p1
= yydprec
[r1
];
1659 if (yymerger
[r0
] == 0 || yymerger
[r0
] != yymerger
[r1
])
1664 if (p0
== 0 || p1
== 0)
1673 static YYRESULTTAG
yyresolveValue (yyGLRState
* yys
,
1674 yyGLRStack
* yystackp
]b4_user_formals
[);
1677 /** Resolve the previous N states starting at and including state S. If result
1678 * != yyok, some states may have been left unresolved possibly with empty
1679 * semantic option chains. Regardless of whether result = yyok, each state
1680 * has been left with consistent data so that yydestroyGLRState can be invoked
1683 yyresolveStates (yyGLRState
* yys
, int yyn
,
1684 yyGLRStack
* yystackp
]b4_user_formals
[)
1688 YYASSERT (yys
->yypred
);
1689 YYCHK (yyresolveStates (yys
->yypred
, yyn
-1, yystackp
]b4_user_args
[));
1690 if (! yys
->yyresolved
)
1691 YYCHK (yyresolveValue (yys
, yystackp
]b4_user_args
[));
1696 /** Resolve the states for the RHS of OPT, perform its user action, and return
1697 * the semantic value and location. Regardless of whether result = yyok, all
1698 * RHS states have been destroyed (assuming the user action destroys all RHS
1699 * semantic values if invoked). */
1701 yyresolveAction (yySemanticOption
* yyopt
, yyGLRStack
* yystackp
,
1702 YYSTYPE
* yyvalp
, YYLTYPE
* yylocp
]b4_user_formals
[)
1704 yyGLRStackItem yyrhsVals
[YYMAXRHS
+ YYMAXLEFT
+ 1];
1707 YYSTYPE yylval_current
;
1708 YYLTYPE yylloc_current
;
1711 yynrhs
= yyrhsLength (yyopt
->yyrule
);
1712 yyflag
= yyresolveStates (yyopt
->yystate
, yynrhs
, yystackp
]b4_user_args
[);
1716 for (yys
= yyopt
->yystate
; yynrhs
> 0; yys
= yys
->yypred
, yynrhs
-= 1)
1717 yydestroyGLRState ("Cleanup: popping", yys
]b4_user_args
[);
1721 yyrhsVals
[YYMAXRHS
+ YYMAXLEFT
].yystate
.yypred
= yyopt
->yystate
;]b4_locations_if([[
1723 /* Set default location. */
1724 yyrhsVals
[YYMAXRHS
+ YYMAXLEFT
- 1].yystate
.yyloc
= yyopt
->yystate
->yyloc
;]])[
1725 yychar_current
= yychar
;
1726 yylval_current
= yylval
;
1727 yylloc_current
= yylloc
;
1728 yychar
= yyopt
->yyrawchar
;
1729 yylval
= yyopt
->yyval
;
1730 yylloc
= yyopt
->yyloc
;
1731 yyflag
= yyuserAction (yyopt
->yyrule
, yynrhs
,
1732 yyrhsVals
+ YYMAXRHS
+ YYMAXLEFT
- 1,
1733 yyvalp
, yylocp
, yystackp
]b4_user_args
[);
1734 yychar
= yychar_current
;
1735 yylval
= yylval_current
;
1736 yylloc
= yylloc_current
;
1742 yyreportTree (yySemanticOption
* yyx
, int yyindent
)
1744 int yynrhs
= yyrhsLength (yyx
->yyrule
);
1747 yyGLRState
* yystates
[1 + YYMAXRHS
];
1748 yyGLRState yyleftmost_state
;
1750 for (yyi
= yynrhs
, yys
= yyx
->yystate
; 0 < yyi
; yyi
-= 1, yys
= yys
->yypred
)
1751 yystates
[yyi
] = yys
;
1754 yyleftmost_state
.yyposn
= 0;
1755 yystates
[0] = &yyleftmost_state
;
1760 if (yyx
->yystate
->yyposn
< yys
->yyposn
+ 1)
1761 YYFPRINTF (stderr
, "%*s%s -> <Rule %d, empty>\n",
1762 yyindent
, "", yytokenName (yylhsNonterm (yyx
->yyrule
)),
1765 YYFPRINTF (stderr
, "%*s%s -> <Rule %d, tokens %lu .. %lu>\n",
1766 yyindent
, "", yytokenName (yylhsNonterm (yyx
->yyrule
)),
1767 yyx
->yyrule
- 1, (unsigned long int) (yys
->yyposn
+ 1),
1768 (unsigned long int) yyx
->yystate
->yyposn
);
1769 for (yyi
= 1; yyi
<= yynrhs
; yyi
+= 1)
1771 if (yystates
[yyi
]->yyresolved
)
1773 if (yystates
[yyi
-1]->yyposn
+1 > yystates
[yyi
]->yyposn
)
1774 YYFPRINTF (stderr
, "%*s%s <empty>\n", yyindent
+2, "",
1775 yytokenName (yyrhs
[yyprhs
[yyx
->yyrule
]+yyi
-1]));
1777 YYFPRINTF (stderr
, "%*s%s <tokens %lu .. %lu>\n", yyindent
+2, "",
1778 yytokenName (yyrhs
[yyprhs
[yyx
->yyrule
]+yyi
-1]),
1779 (unsigned long int) (yystates
[yyi
- 1]->yyposn
+ 1),
1780 (unsigned long int) yystates
[yyi
]->yyposn
);
1783 yyreportTree (yystates
[yyi
]->yysemantics
.yyfirstVal
, yyindent
+2);
1788 /*ARGSUSED*/ static YYRESULTTAG
1789 yyreportAmbiguity (yySemanticOption
* yyx0
,
1790 yySemanticOption
* yyx1
]b4_pure_formals
[)
1796 YYFPRINTF (stderr
, "Ambiguity detected.\n");
1797 YYFPRINTF (stderr
, "Option 1,\n");
1798 yyreportTree (yyx0
, 2);
1799 YYFPRINTF (stderr
, "\nOption 2,\n");
1800 yyreportTree (yyx1
, 2);
1801 YYFPRINTF (stderr
, "\n");
1804 yyerror (]b4_yyerror_args
[YY_("syntax is ambiguous"));
1808 /** Starting at and including state S1, resolve the location for each of the
1809 * previous N1 states that is unresolved. The first semantic option of a state
1810 * is always chosen. */
1812 yyresolveLocations (yyGLRState
* yys1
, int yyn1
,
1813 yyGLRStack
*yystackp
]b4_user_formals
[)
1817 yyresolveLocations (yys1
->yypred
, yyn1
- 1, yystackp
]b4_user_args
[);
1818 if (!yys1
->yyresolved
)
1820 yySemanticOption
*yyoption
;
1821 yyGLRStackItem yyrhsloc
[1 + YYMAXRHS
];
1824 YYSTYPE yylval_current
;
1825 YYLTYPE yylloc_current
;
1826 yyoption
= yys1
->yysemantics
.yyfirstVal
;
1827 YYASSERT (yyoption
!= NULL
);
1828 yynrhs
= yyrhsLength (yyoption
->yyrule
);
1833 yyresolveLocations (yyoption
->yystate
, yynrhs
,
1834 yystackp
]b4_user_args
[);
1835 for (yys
= yyoption
->yystate
, yyn
= yynrhs
;
1837 yys
= yys
->yypred
, yyn
-= 1)
1838 yyrhsloc
[yyn
].yystate
.yyloc
= yys
->yyloc
;
1842 /* Both yyresolveAction and yyresolveLocations traverse the GSS
1843 in reverse rightmost order. It is only necessary to invoke
1844 yyresolveLocations on a subforest for which yyresolveAction
1845 would have been invoked next had an ambiguity not been
1846 detected. Thus the location of the previous state (but not
1847 necessarily the previous state itself) is guaranteed to be
1848 resolved already. */
1849 yyGLRState
*yyprevious
= yyoption
->yystate
;
1850 yyrhsloc
[0].yystate
.yyloc
= yyprevious
->yyloc
;
1852 yychar_current
= yychar
;
1853 yylval_current
= yylval
;
1854 yylloc_current
= yylloc
;
1855 yychar
= yyoption
->yyrawchar
;
1856 yylval
= yyoption
->yyval
;
1857 yylloc
= yyoption
->yyloc
;
1858 YYLLOC_DEFAULT ((yys1
->yyloc
), yyrhsloc
, yynrhs
);
1859 yychar
= yychar_current
;
1860 yylval
= yylval_current
;
1861 yylloc
= yylloc_current
;
1866 /** Resolve the ambiguity represented in state S, perform the indicated
1867 * actions, and set the semantic value of S. If result != yyok, the chain of
1868 * semantic options in S has been cleared instead or it has been left
1869 * unmodified except that redundant options may have been removed. Regardless
1870 * of whether result = yyok, S has been left with consistent data so that
1871 * yydestroyGLRState can be invoked if necessary. */
1873 yyresolveValue (yyGLRState
* yys
, yyGLRStack
* yystackp
]b4_user_formals
[)
1875 yySemanticOption
* yyoptionList
= yys
->yysemantics
.yyfirstVal
;
1876 yySemanticOption
* yybest
;
1877 yySemanticOption
** yypp
;
1881 YYLTYPE
*yylocp
= &yys
->yyloc
;
1883 yybest
= yyoptionList
;
1885 for (yypp
= &yyoptionList
->yynext
; *yypp
!= NULL
; )
1887 yySemanticOption
* yyp
= *yypp
;
1889 if (yyidenticalOptions (yybest
, yyp
))
1891 yymergeOptionSets (yybest
, yyp
);
1892 *yypp
= yyp
->yynext
;
1896 switch (yypreference (yybest
, yyp
))
1899 yyresolveLocations (yys
, 1, yystackp
]b4_user_args
[);
1900 return yyreportAmbiguity (yybest
, yyp
]b4_pure_args
[);
1912 /* This cannot happen so it is not worth a YYASSERT (yyfalse),
1913 but some compilers complain if the default case is
1917 yypp
= &yyp
->yynext
;
1923 yySemanticOption
* yyp
;
1924 int yyprec
= yydprec
[yybest
->yyrule
];
1925 yyflag
= yyresolveAction (yybest
, yystackp
, &yysval
,
1926 yylocp
]b4_user_args
[);
1928 for (yyp
= yybest
->yynext
; yyp
!= NULL
; yyp
= yyp
->yynext
)
1930 if (yyprec
== yydprec
[yyp
->yyrule
])
1932 YYSTYPE yysval_other
;
1934 yyflag
= yyresolveAction (yyp
, yystackp
, &yysval_other
,
1935 &yydummy
]b4_user_args
[);
1938 yydestruct ("Cleanup: discarding incompletely merged value for",
1939 yystos
[yys
->yylrState
],
1940 &yysval
]b4_locations_if([, yylocp
])[]b4_user_args
[);
1943 yyuserMerge (yymerger
[yyp
->yyrule
], &yysval
, &yysval_other
);
1948 yyflag
= yyresolveAction (yybest
, yystackp
, &yysval
, yylocp
]b4_user_args
[);
1952 yys
->yyresolved
= yytrue
;
1953 yys
->yysemantics
.yysval
= yysval
;
1956 yys
->yysemantics
.yyfirstVal
= NULL
;
1961 yyresolveStack (yyGLRStack
* yystackp
]b4_user_formals
[)
1963 if (yystackp
->yysplitPoint
!= NULL
)
1968 for (yyn
= 0, yys
= yystackp
->yytops
.yystates
[0];
1969 yys
!= yystackp
->yysplitPoint
;
1970 yys
= yys
->yypred
, yyn
+= 1)
1972 YYCHK (yyresolveStates (yystackp
->yytops
.yystates
[0], yyn
, yystackp
1979 yycompressStack (yyGLRStack
* yystackp
)
1981 yyGLRState
* yyp
, *yyq
, *yyr
;
1983 if (yystackp
->yytops
.yysize
!= 1 || yystackp
->yysplitPoint
== NULL
)
1986 for (yyp
= yystackp
->yytops
.yystates
[0], yyq
= yyp
->yypred
, yyr
= NULL
;
1987 yyp
!= yystackp
->yysplitPoint
;
1988 yyr
= yyp
, yyp
= yyq
, yyq
= yyp
->yypred
)
1991 yystackp
->yyspaceLeft
+= yystackp
->yynextFree
- yystackp
->yyitems
;
1992 yystackp
->yynextFree
= ((yyGLRStackItem
*) yystackp
->yysplitPoint
) + 1;
1993 yystackp
->yyspaceLeft
-= yystackp
->yynextFree
- yystackp
->yyitems
;
1994 yystackp
->yysplitPoint
= NULL
;
1995 yystackp
->yylastDeleted
= NULL
;
1999 yystackp
->yynextFree
->yystate
= *yyr
;
2001 yystackp
->yynextFree
->yystate
.yypred
= &yystackp
->yynextFree
[-1].yystate
;
2002 yystackp
->yytops
.yystates
[0] = &yystackp
->yynextFree
->yystate
;
2003 yystackp
->yynextFree
+= 1;
2004 yystackp
->yyspaceLeft
-= 1;
2009 yyprocessOneStack (yyGLRStack
* yystackp
, size_t yyk
,
2010 size_t yyposn
]b4_pure_formals
[)
2013 const short int* yyconflicts
;
2016 while (yystackp
->yytops
.yystates
[yyk
] != NULL
)
2018 yyStateNum yystate
= yystackp
->yytops
.yystates
[yyk
]->yylrState
;
2019 YYDPRINTF ((stderr
, "Stack %lu Entering state %d\n",
2020 (unsigned long int) yyk
, yystate
));
2022 YYASSERT (yystate
!= YYFINAL
);
2024 if (yyisDefaultedState (yystate
))
2026 yyrule
= yydefaultAction (yystate
);
2029 YYDPRINTF ((stderr
, "Stack %lu dies.\n",
2030 (unsigned long int) yyk
));
2031 yymarkStackDeleted (yystackp
, yyk
);
2034 YYCHK (yyglrReduce (yystackp
, yyk
, yyrule
, yyfalse
]b4_user_args
[));
2039 yystackp
->yytops
.yylookaheadNeeds
[yyk
] = yytrue
;
2040 if (yychar
== YYEMPTY
)
2042 YYDPRINTF ((stderr
, "Reading a token: "));
2046 if (yychar
<= YYEOF
)
2048 yychar
= yytoken
= YYEOF
;
2049 YYDPRINTF ((stderr
, "Now at end of input.\n"));
2053 yytoken
= YYTRANSLATE (yychar
);
2054 YY_SYMBOL_PRINT ("Next token is", yytoken
, &yylval
, &yylloc
);
2057 yygetLRActions (yystate
, yytoken
, &yyaction
, &yyconflicts
);
2059 while (*yyconflicts
!= 0)
2061 size_t yynewStack
= yysplitStack (yystackp
, yyk
);
2062 YYDPRINTF ((stderr
, "Splitting off stack %lu from %lu.\n",
2063 (unsigned long int) yynewStack
,
2064 (unsigned long int) yyk
));
2065 YYCHK (yyglrReduce (yystackp
, yynewStack
,
2066 *yyconflicts
, yyfalse
]b4_user_args
[));
2067 YYCHK (yyprocessOneStack (yystackp
, yynewStack
,
2068 yyposn
]b4_pure_args
[));
2072 if (yyisShiftAction (yyaction
))
2074 else if (yyisErrorAction (yyaction
))
2076 YYDPRINTF ((stderr
, "Stack %lu dies.\n",
2077 (unsigned long int) yyk
));
2078 yymarkStackDeleted (yystackp
, yyk
);
2082 YYCHK (yyglrReduce (yystackp
, yyk
, -yyaction
,
2083 yyfalse
]b4_user_args
[));
2089 /*ARGSUSED*/ static void
2090 yyreportSyntaxError (yyGLRStack
* yystackp
]b4_user_formals
[)
2092 if (yystackp
->yyerrState
== 0)
2096 yyn
= yypact
[yystackp
->yytops
.yystates
[0]->yylrState
];
2097 if (YYPACT_NINF
< yyn
&& yyn
<= YYLAST
)
2099 yySymbol yytoken
= YYTRANSLATE (yychar
);
2100 size_t yysize0
= yytnamerr (NULL
, yytokenName (yytoken
));
2101 size_t yysize
= yysize0
;
2103 yybool yysize_overflow
= yyfalse
;
2105 enum { YYERROR_VERBOSE_ARGS_MAXIMUM
= 5 };
2106 char const *yyarg
[YYERROR_VERBOSE_ARGS_MAXIMUM
];
2110 static char const yyunexpected
[] = "syntax error, unexpected %s";
2111 static char const yyexpecting
[] = ", expecting %s";
2112 static char const yyor
[] = " or %s";
2113 char yyformat
[sizeof yyunexpected
2114 + sizeof yyexpecting
- 1
2115 + ((YYERROR_VERBOSE_ARGS_MAXIMUM
- 2)
2116 * (sizeof yyor
- 1))];
2117 char const *yyprefix
= yyexpecting
;
2119 /* Start YYX at -YYN if negative to avoid negative indexes in
2121 int yyxbegin
= yyn
< 0 ? -yyn
: 0;
2123 /* Stay within bounds of both yycheck and yytname. */
2124 int yychecklim
= YYLAST
- yyn
+ 1;
2125 int yyxend
= yychecklim
< YYNTOKENS
? yychecklim
: YYNTOKENS
;
2128 yyarg
[0] = yytokenName (yytoken
);
2129 yyfmt
= yystpcpy (yyformat
, yyunexpected
);
2131 for (yyx
= yyxbegin
; yyx
< yyxend
; ++yyx
)
2132 if (yycheck
[yyx
+ yyn
] == yyx
&& yyx
!= YYTERROR
)
2134 if (yycount
== YYERROR_VERBOSE_ARGS_MAXIMUM
)
2138 yyformat
[sizeof yyunexpected
- 1] = '\0';
2141 yyarg
[yycount
++] = yytokenName (yyx
);
2142 yysize1
= yysize
+ yytnamerr (NULL
, yytokenName (yyx
));
2143 yysize_overflow
|= yysize1
< yysize
;
2145 yyfmt
= yystpcpy (yyfmt
, yyprefix
);
2149 yyf
= YY_(yyformat
);
2150 yysize1
= yysize
+ strlen (yyf
);
2151 yysize_overflow
|= yysize1
< yysize
;
2154 if (!yysize_overflow
)
2155 yymsg
= (char *) YYMALLOC (yysize
);
2161 while ((*yyp
= *yyf
))
2163 if (*yyp
== '%' && yyf
[1] == 's' && yyi
< yycount
)
2165 yyp
+= yytnamerr (yyp
, yyarg
[yyi
++]);
2174 yyerror (]b4_lyyerror_args
[yymsg
);
2179 yyerror (]b4_lyyerror_args
[YY_("syntax error"));
2180 yyMemoryExhausted (yystackp
);
2184 #endif /* YYERROR_VERBOSE */
2185 yyerror (]b4_lyyerror_args
[YY_("syntax error"));
2190 /* Recover from a syntax error on *YYSTACKP, assuming that *YYSTACKP->YYTOKENP,
2191 yylval, and yylloc are the syntactic category, semantic value, and location
2192 of the lookahead. */
2193 /*ARGSUSED*/ static void
2194 yyrecoverSyntaxError (yyGLRStack
* yystackp
]b4_user_formals
[)
2199 if (yystackp
->yyerrState
== 3)
2200 /* We just shifted the error token and (perhaps) took some
2201 reductions. Skip tokens until we can proceed. */
2202 while (YYID (yytrue
))
2205 if (yychar
== YYEOF
)
2206 yyFail (yystackp
][]b4_lpure_args
[, NULL
);
2207 if (yychar
!= YYEMPTY
)
2208 {]b4_locations_if([[
2209 /* We throw away the lookahead, but the error range
2210 of the shifted error token must take it into account. */
2211 yyGLRState
*yys
= yystackp
->yytops
.yystates
[0];
2212 yyGLRStackItem yyerror_range
[3];
2213 yyerror_range
[1].yystate
.yyloc
= yys
->yyloc
;
2214 yyerror_range
[2].yystate
.yyloc
= yylloc
;
2215 YYLLOC_DEFAULT ((yys
->yyloc
), yyerror_range
, 2);]])[
2216 yytoken
= YYTRANSLATE (yychar
);
2217 yydestruct ("Error: discarding",
2218 yytoken
, &yylval
]b4_locations_if([, &yylloc
])[]b4_user_args
[);
2220 YYDPRINTF ((stderr
, "Reading a token: "));
2222 if (yychar
<= YYEOF
)
2224 yychar
= yytoken
= YYEOF
;
2225 YYDPRINTF ((stderr
, "Now at end of input.\n"));
2229 yytoken
= YYTRANSLATE (yychar
);
2230 YY_SYMBOL_PRINT ("Next token is", yytoken
, &yylval
, &yylloc
);
2232 yyj
= yypact
[yystackp
->yytops
.yystates
[0]->yylrState
];
2233 if (yyis_pact_ninf (yyj
))
2236 if (yyj
< 0 || YYLAST
< yyj
|| yycheck
[yyj
] != yytoken
)
2238 if (yydefact
[yystackp
->yytops
.yystates
[0]->yylrState
] != 0)
2241 else if (yytable
[yyj
] != 0 && ! yyis_table_ninf (yytable
[yyj
]))
2245 /* Reduce to one stack. */
2246 for (yyk
= 0; yyk
< yystackp
->yytops
.yysize
; yyk
+= 1)
2247 if (yystackp
->yytops
.yystates
[yyk
] != NULL
)
2249 if (yyk
>= yystackp
->yytops
.yysize
)
2250 yyFail (yystackp
][]b4_lpure_args
[, NULL
);
2251 for (yyk
+= 1; yyk
< yystackp
->yytops
.yysize
; yyk
+= 1)
2252 yymarkStackDeleted (yystackp
, yyk
);
2253 yyremoveDeletes (yystackp
);
2254 yycompressStack (yystackp
);
2256 /* Now pop stack until we find a state that shifts the error token. */
2257 yystackp
->yyerrState
= 3;
2258 while (yystackp
->yytops
.yystates
[0] != NULL
)
2260 yyGLRState
*yys
= yystackp
->yytops
.yystates
[0];
2261 yyj
= yypact
[yys
->yylrState
];
2262 if (! yyis_pact_ninf (yyj
))
2265 if (0 <= yyj
&& yyj
<= YYLAST
&& yycheck
[yyj
] == YYTERROR
2266 && yyisShiftAction (yytable
[yyj
]))
2268 /* Shift the error token having adjusted its location. */
2269 YYLTYPE yyerrloc
;]b4_locations_if([[
2270 yystackp
->yyerror_range
[2].yystate
.yyloc
= yylloc
;
2271 YYLLOC_DEFAULT (yyerrloc
, (yystackp
->yyerror_range
), 2);]])[
2272 YY_SYMBOL_PRINT ("Shifting", yystos
[yytable
[yyj
]],
2273 &yylval
, &yyerrloc
);
2274 yyglrShift (yystackp
, 0, yytable
[yyj
],
2275 yys
->yyposn
, &yylval
, &yyerrloc
);
2276 yys
= yystackp
->yytops
.yystates
[0];
2280 ]b4_locations_if([[ yystackp
->yyerror_range
[1].yystate
.yyloc
= yys
->yyloc
;]])[
2281 if (yys
->yypred
!= NULL
)
2282 yydestroyGLRState ("Error: popping", yys
]b4_user_args
[);
2283 yystackp
->yytops
.yystates
[0] = yys
->yypred
;
2284 yystackp
->yynextFree
-= 1;
2285 yystackp
->yyspaceLeft
+= 1;
2287 if (yystackp
->yytops
.yystates
[0] == NULL
)
2288 yyFail (yystackp
][]b4_lpure_args
[, NULL
);
2291 #define YYCHK1(YYE) \
2301 goto yyuser_error; \
2312 ]b4_c_ansi_function_def([yyparse
], [int], b4_parse_param
)[
2316 yyGLRStack
* const yystackp
= &yystack
;
2319 YYDPRINTF ((stderr
, "Starting parse\n"));
2322 yylval
= yyval_default
;
2324 #if YYLTYPE_IS_TRIVIAL
2325 yylloc
.first_line
= yylloc
.last_line
= ]b4_location_initial_line
[;
2326 yylloc
.first_column
= yylloc
.last_column
= ]b4_location_initial_column
[;
2329 m4_ifdef([b4_initial_action
], [
2330 m4_pushdef([b4_at_dollar
], [yylloc
])dnl
2331 m4_pushdef([b4_dollar_dollar
], [yylval
])dnl
2332 /* User initialization code. */
2333 b4_user_initial_action
2334 m4_popdef([b4_dollar_dollar
])dnl
2335 m4_popdef([b4_at_dollar
])])dnl
2337 if (! yyinitGLRStack (yystackp
, YYINITDEPTH
))
2338 goto yyexhaustedlab
;
2339 switch (YYSETJMP (yystack
.yyexception_buffer
))
2342 case 1: goto yyabortlab
;
2343 case 2: goto yyexhaustedlab
;
2344 default: goto yybuglab
;
2346 yyglrShift (&yystack
, 0, 0, 0, &yylval
, &yylloc
);
2349 while (YYID (yytrue
))
2351 /* For efficiency, we have two loops, the first of which is
2352 specialized to deterministic operation (single stack, no
2353 potential ambiguity). */
2355 while (YYID (yytrue
))
2359 const short int* yyconflicts
;
2361 yyStateNum yystate
= yystack
.yytops
.yystates
[0]->yylrState
;
2362 YYDPRINTF ((stderr
, "Entering state %d\n", yystate
));
2363 if (yystate
== YYFINAL
)
2365 if (yyisDefaultedState (yystate
))
2367 yyrule
= yydefaultAction (yystate
);
2370 ]b4_locations_if([[ yystack
.yyerror_range
[1].yystate
.yyloc
= yylloc
;]])[
2371 yyreportSyntaxError (&yystack
]b4_user_args
[);
2374 YYCHK1 (yyglrReduce (&yystack
, 0, yyrule
, yytrue
]b4_user_args
[));
2379 if (yychar
== YYEMPTY
)
2381 YYDPRINTF ((stderr
, "Reading a token: "));
2385 if (yychar
<= YYEOF
)
2387 yychar
= yytoken
= YYEOF
;
2388 YYDPRINTF ((stderr
, "Now at end of input.\n"));
2392 yytoken
= YYTRANSLATE (yychar
);
2393 YY_SYMBOL_PRINT ("Next token is", yytoken
, &yylval
, &yylloc
);
2396 yygetLRActions (yystate
, yytoken
, &yyaction
, &yyconflicts
);
2397 if (*yyconflicts
!= 0)
2399 if (yyisShiftAction (yyaction
))
2401 YY_SYMBOL_PRINT ("Shifting", yytoken
, &yylval
, &yylloc
);
2404 yyglrShift (&yystack
, 0, yyaction
, yyposn
, &yylval
, &yylloc
);
2405 if (0 < yystack
.yyerrState
)
2406 yystack
.yyerrState
-= 1;
2408 else if (yyisErrorAction (yyaction
))
2410 ]b4_locations_if([[ yystack
.yyerror_range
[1].yystate
.yyloc
= yylloc
;]])[
2411 yyreportSyntaxError (&yystack
]b4_user_args
[);
2415 YYCHK1 (yyglrReduce (&yystack
, 0, -yyaction
, yytrue
]b4_user_args
[));
2419 while (YYID (yytrue
))
2421 yySymbol yytoken_to_shift
;
2424 for (yys
= 0; yys
< yystack
.yytops
.yysize
; yys
+= 1)
2425 yystackp
->yytops
.yylookaheadNeeds
[yys
] = yychar
!= YYEMPTY
;
2427 /* yyprocessOneStack returns one of three things:
2429 - An error flag. If the caller is yyprocessOneStack, it
2430 immediately returns as well. When the caller is finally
2431 yyparse, it jumps to an error label via YYCHK1.
2433 - yyok, but yyprocessOneStack has invoked yymarkStackDeleted
2434 (&yystack, yys), which sets the top state of yys to NULL. Thus,
2435 yyparse's following invocation of yyremoveDeletes will remove
2438 - yyok, when ready to shift a token.
2440 Except in the first case, yyparse will invoke yyremoveDeletes and
2441 then shift the next token onto all remaining stacks. This
2442 synchronization of the shift (that is, after all preceding
2443 reductions on all stacks) helps prevent double destructor calls
2444 on yylval in the event of memory exhaustion. */
2446 for (yys
= 0; yys
< yystack
.yytops
.yysize
; yys
+= 1)
2447 YYCHK1 (yyprocessOneStack (&yystack
, yys
, yyposn
]b4_lpure_args
[));
2448 yyremoveDeletes (&yystack
);
2449 if (yystack
.yytops
.yysize
== 0)
2451 yyundeleteLastStack (&yystack
);
2452 if (yystack
.yytops
.yysize
== 0)
2453 yyFail (&yystack
][]b4_lpure_args
[, YY_("syntax error"));
2454 YYCHK1 (yyresolveStack (&yystack
]b4_user_args
[));
2455 YYDPRINTF ((stderr
, "Returning to deterministic operation.\n"));
2456 ]b4_locations_if([[ yystack
.yyerror_range
[1].yystate
.yyloc
= yylloc
;]])[
2457 yyreportSyntaxError (&yystack
]b4_user_args
[);
2461 /* If any yyglrShift call fails, it will fail after shifting. Thus,
2462 a copy of yylval will already be on stack 0 in the event of a
2463 failure in the following loop. Thus, yychar is set to YYEMPTY
2464 before the loop to make sure the user destructor for yylval isn't
2466 yytoken_to_shift
= YYTRANSLATE (yychar
);
2469 for (yys
= 0; yys
< yystack
.yytops
.yysize
; yys
+= 1)
2472 const short int* yyconflicts
;
2473 yyStateNum yystate
= yystack
.yytops
.yystates
[yys
]->yylrState
;
2474 yygetLRActions (yystate
, yytoken_to_shift
, &yyaction
,
2476 /* Note that yyconflicts were handled by yyprocessOneStack. */
2477 YYDPRINTF ((stderr
, "On stack %lu, ", (unsigned long int) yys
));
2478 YY_SYMBOL_PRINT ("shifting", yytoken_to_shift
, &yylval
, &yylloc
);
2479 yyglrShift (&yystack
, yys
, yyaction
, yyposn
,
2481 YYDPRINTF ((stderr
, "Stack %lu now in state #%d\n",
2482 (unsigned long int) yys
,
2483 yystack
.yytops
.yystates
[yys
]->yylrState
));
2486 if (yystack
.yytops
.yysize
== 1)
2488 YYCHK1 (yyresolveStack (&yystack
]b4_user_args
[));
2489 YYDPRINTF ((stderr
, "Returning to deterministic operation.\n"));
2490 yycompressStack (&yystack
);
2496 yyrecoverSyntaxError (&yystack
]b4_user_args
[);
2497 yyposn
= yystack
.yytops
.yystates
[0]->yyposn
;
2513 yyerror (]b4_lyyerror_args
[YY_("memory exhausted"));
2518 if (yychar
!= YYEMPTY
)
2519 yydestruct ("Cleanup: discarding lookahead",
2520 YYTRANSLATE (yychar
),
2521 &yylval
]b4_locations_if([, &yylloc
])[]b4_user_args
[);
2523 /* If the stack is well-formed, pop the stack until it is empty,
2524 destroying its entries as we go. But free the stack regardless
2525 of whether it is well-formed. */
2526 if (yystack
.yyitems
)
2528 yyGLRState
** yystates
= yystack
.yytops
.yystates
;
2531 size_t yysize
= yystack
.yytops
.yysize
;
2533 for (yyk
= 0; yyk
< yysize
; yyk
+= 1)
2536 while (yystates
[yyk
])
2538 yyGLRState
*yys
= yystates
[yyk
];
2539 ]b4_locations_if([[ yystack
.yyerror_range
[1].yystate
.yyloc
= yys
->yyloc
;]]
2540 )[ if (yys
->yypred
!= NULL
)
2541 yydestroyGLRState ("Cleanup: popping", yys
]b4_user_args
[);
2542 yystates
[yyk
] = yys
->yypred
;
2543 yystack
.yynextFree
-= 1;
2544 yystack
.yyspaceLeft
+= 1;
2549 yyfreeGLRStack (&yystack
);
2552 /* Make sure YYID is used. */
2553 return YYID (yyresult
);
2556 /* DEBUGGING ONLY */
2558 static void yypstack (yyGLRStack
* yystackp
, size_t yyk
)
2559 __attribute__ ((__unused__
));
2560 static void yypdumpstack (yyGLRStack
* yystackp
) __attribute__ ((__unused__
));
2563 yy_yypstack (yyGLRState
* yys
)
2567 yy_yypstack (yys
->yypred
);
2568 fprintf (stderr
, " -> ");
2570 fprintf (stderr
, "%d@@%lu", yys
->yylrState
, (unsigned long int) yys
->yyposn
);
2574 yypstates (yyGLRState
* yyst
)
2577 fprintf (stderr
, "<null>");
2580 fprintf (stderr
, "\n");
2584 yypstack (yyGLRStack
* yystackp
, size_t yyk
)
2586 yypstates (yystackp
->yytops
.yystates
[yyk
]);
2589 #define YYINDEX(YYX) \
2590 ((YYX) == NULL ? -1 : (yyGLRStackItem*) (YYX) - yystackp->yyitems)
2594 yypdumpstack (yyGLRStack
* yystackp
)
2596 yyGLRStackItem
* yyp
;
2598 for (yyp
= yystackp
->yyitems
; yyp
< yystackp
->yynextFree
; yyp
+= 1)
2600 fprintf (stderr
, "%3lu. ", (unsigned long int) (yyp
- yystackp
->yyitems
));
2601 if (*(yybool
*) yyp
)
2603 fprintf (stderr
, "Res: %d, LR State: %d, posn: %lu, pred: %ld",
2604 yyp
->yystate
.yyresolved
, yyp
->yystate
.yylrState
,
2605 (unsigned long int) yyp
->yystate
.yyposn
,
2606 (long int) YYINDEX (yyp
->yystate
.yypred
));
2607 if (! yyp
->yystate
.yyresolved
)
2608 fprintf (stderr
, ", firstVal: %ld",
2609 (long int) YYINDEX (yyp
->yystate
.yysemantics
.yyfirstVal
));
2613 fprintf (stderr
, "Option. rule: %d, state: %ld, next: %ld",
2614 yyp
->yyoption
.yyrule
- 1,
2615 (long int) YYINDEX (yyp
->yyoption
.yystate
),
2616 (long int) YYINDEX (yyp
->yyoption
.yynext
));
2618 fprintf (stderr
, "\n");
2620 fprintf (stderr
, "Tops:");
2621 for (yyi
= 0; yyi
< yystackp
->yytops
.yysize
; yyi
+= 1)
2622 fprintf (stderr
, "%lu: %ld; ", (unsigned long int) yyi
,
2623 (long int) YYINDEX (yystackp
->yytops
.yystates
[yyi
]));
2624 fprintf (stderr
, "\n");
2631 dnl glr
.cc produces its own header
.
2633 m4_if(b4_skeleton
, ["glr.c"],
2635 [@
output(b4_spec_defines_file@
)
2636 b4_copyright([Skeleton interface
for Bison GLR parsers in C
],
2637 [2002, 2003, 2004, 2005, 2006])
2639 b4_shared_declarations
2642 [[extern YYSTYPE b4_prefix
][lval
;]])
2644 b4_locations_if([b4_pure_if([],
2645 [extern YYLTYPE b4_prefix
[]lloc
;])