1 m4_divert(-1) -*- C
-*-
3 # GLR skeleton for Bison
4 # Copyright (C) 2002, 2003, 2004, 2005, 2006 Free Software Foundation, Inc.
6 # This program is free software; you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation; either version 2 of the License, or
9 # (at your option) any later version.
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License
17 # along with this program; if not, write to the Free Software
18 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
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 ## ------------------------ ##
41 # The possible parse-params formal arguments preceded by a comma.
43 # This is not shared with yacc.c in c.m4 because GLR relies on ISO C
44 # formal argument declarations.
45 m4_define([b4_user_formals
],
46 [m4_ifset([b4_parse_param
], [, b4_c_ansi_formals(b4_parse_param
)])])
51 # Accumule in b4_lex_param all the yylex arguments.
52 # Yes, this is quite ugly...
53 m4_define([b4_lex_param
],
54 m4_dquote(b4_pure_if([[[[YYSTYPE
*]], [[&yylval
]]][]dnl
55 b4_location_if([, [[YYLTYPE
*], [&yylloc
]]])])dnl
56 m4_ifdef([b4_lex_param
], [, ]b4_lex_param
)))
61 # Optional effective arguments passed to yyerror: user args plus yylloc, and
63 m4_define([b4_yyerror_args
],
64 [b4_pure_if([b4_location_if([yylocp
, ])])dnl
65 m4_ifset([b4_parse_param
], [b4_c_args(b4_parse_param
), ])])
70 # Same as above, but on the look-ahead, hence &yylloc instead of yylocp.
71 m4_define([b4_lyyerror_args
],
72 [b4_pure_if([b4_location_if([&yylloc
, ])])dnl
73 m4_ifset([b4_parse_param
], [b4_c_args(b4_parse_param
), ])])
78 # Same as b4_yyerror_args, but with a leading comma.
79 m4_define([b4_pure_args
],
80 [b4_pure_if([b4_location_if([, yylocp
])])[]b4_user_args
])
85 # Same as above, but on the look-ahead, hence &yylloc instead of yylocp.
86 m4_define([b4_lpure_args
],
87 [b4_pure_if([b4_location_if([, &yylloc
])])[]b4_user_args
])
92 # Arguments passed to yyerror: user formals plus yylocp.
93 m4_define([b4_pure_formals
],
94 [b4_pure_if([b4_location_if([, YYLTYPE
*yylocp
])])[]b4_user_formals
])
97 ## ----------------- ##
98 ## Semantic Values. ##
99 ## ----------------- ##
102 # b4_lhs_value([TYPE])
103 # --------------------
104 # Expansion of $<TYPE>$.
105 m4_define([b4_lhs_value
],
106 [((*yyvalp
)[]m4_ifval([$
1], [.$
1]))])
109 # b4_rhs_value(RULE-LENGTH, NUM, [TYPE])
110 # --------------------------------------
111 # Expansion of $<TYPE>NUM, where the current rule has RULE-LENGTH
113 m4_define([b4_rhs_value
],
114 [(((yyGLRStackItem
const *)yyvsp
)@
{YYFILL (($
2) - ($
1))@
}.yystate
.yysemantics
.yysval
[]m4_ifval([$
3], [.$
3]))])
125 m4_define([b4_lhs_location
],
129 # b4_rhs_location(RULE-LENGTH, NUM)
130 # ---------------------------------
131 # Expansion of @NUM, where the current rule has RULE-LENGTH symbols
133 m4_define([b4_rhs_location
],
134 [(((yyGLRStackItem
const *)yyvsp
)@
{YYFILL (($
2) - ($
1))@
}.yystate
.yyloc
)])
142 # We do want M4 expansion after # for CPP macros.
145 @output @output_parser_name@
146 b4_copyright([Skeleton implementation
for Bison GLR parsers in C
],
147 [2002, 2003, 2004, 2005, 2006])
149 /* As a special exception, you may create a larger work that contains
150 part or all of the Bison parser skeleton and distribute that work
151 under terms of your choice, so long as that work isn't itself a
152 parser generator using the skeleton or a modified version thereof
153 as a parser skeleton. Alternatively, if you modify or redistribute
154 the parser skeleton itself, you may (at your option) remove this
155 special exception, which will cause the skeleton and the resulting
156 Bison output files to be licensed under the GNU General Public
157 License without this special exception.
159 This special exception was added by the Free Software Foundation in
160 version 2.2 of Bison. */
162 /* C GLR parser skeleton written by Paul Hilfinger. */
166 m4_if(b4_prefix
, [yy
], [],
167 [/* Substitute the variable and function names. */
168 #define yyparse b4_prefix[]parse
169 #define yylex b4_prefix[]lex
170 #define yyerror b4_prefix[]error
171 #define yylval b4_prefix[]lval
172 #define yychar b4_prefix[]char
173 #define yydebug b4_prefix[]debug
174 #define yynerrs b4_prefix[]nerrs
175 #define yylloc b4_prefix[]lloc])
177 dnl
# b4_shared_declarations
178 dnl
# ----------------------
179 dnl
# Declaration that might either go into the header (if --defines)
180 dnl
# or open coded in the parser body.
181 m4_define([b4_shared_declarations
],
182 [b4_token_enums(b4_tokens
)[
184 /* Copy the first part of user declarations. */
187 #if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED
188 ]m4_ifdef([b4_stype
],
189 [typedef union m4_bregexp(b4_stype
, [^{], [YYSTYPE
])
191 /* Line __line__ of glr.c. */
192 b4_syncline([@oline@
], [@ofile@
])
194 [typedef int YYSTYPE
;])[
195 # define YYSTYPE_IS_DECLARED 1
196 # define YYSTYPE_IS_TRIVIAL 1
199 #if ! defined YYLTYPE && ! defined YYLTYPE_IS_DECLARED
200 typedef struct YYLTYPE
211 # define YYLTYPE_IS_DECLARED 1
212 # define YYLTYPE_IS_TRIVIAL 1
216 m4_if(b4_defines_flag
, 0,
217 [b4_shared_declarations
],
218 [#include @output_header_name@])[
220 /* Enabling traces. */
222 # define YYDEBUG ]b4_debug[
225 /* Enabling verbose error messages. */
226 #ifdef YYERROR_VERBOSE
227 # undef YYERROR_VERBOSE
228 # define YYERROR_VERBOSE 1
230 # define YYERROR_VERBOSE ]b4_error_verbose[
233 /* Enabling the token table. */
234 #ifndef YYTOKEN_TABLE
235 # define YYTOKEN_TABLE ]b4_token_table[
238 /* Default (constant) value used for initialization for null
239 right-hand sides. Unlike the standard yacc.c template,
240 here we set the default value of $$ to a zeroed-out value.
241 Since the default value is undefined, this behavior is
242 technically correct. */
243 static YYSTYPE yyval_default
;
245 /* Copy the second part of user declarations. */
248 ]/* Line __line__ of glr.c. */
249 b4_syncline([@oline@
], [@ofile@
])
259 # include <libintl.h> /* INFRINGES ON USER NAME SPACE */
260 # define YY_(msgid) dgettext ("bison-runtime", msgid)
264 # define YY_(msgid) msgid
268 /* Suppress unused-variable warnings by "using" E. */
269 #if ! defined lint || defined __GNUC__
270 # define YYUSE(e) ((void) (e))
272 # define YYUSE(e) /* empty */
275 /* Identity function, used to suppress warnings about constant conditions. */
279 ]b4_c_function_def([YYID
], [static int], [[int i
], [i
]])[
289 # define YYMALLOC malloc
292 # define YYREALLOC realloc
295 #define YYSIZEMAX ((size_t) -1)
300 typedef unsigned char yybool
;
307 # define YYJMP_BUF jmp_buf
308 # define YYSETJMP(env) setjmp (env)
309 # define YYLONGJMP(env, val) longjmp (env, val)
316 #ifndef __attribute__
317 /* This feature is available in gcc versions 2.5 and later. */
318 # if (! defined __GNUC__ || __GNUC__ < 2 \
319 || (__GNUC__ == 2 && __GNUC_MINOR__ < 5) || __STRICT_ANSI__)
320 # define __attribute__(Spec) /* empty */
324 ]b4_location_if([#define YYOPTIONAL_LOC(Name) Name],[
326 # define YYOPTIONAL_LOC(Name) /* empty */
328 # define YYOPTIONAL_LOC(Name) Name __attribute__ ((__unused__))
332 # define YYASSERT(condition) ((void) ((condition) || (abort (), 0)))
335 /* YYFINAL -- State number of the termination state. */
336 #define YYFINAL ]b4_final_state_number[
337 /* YYLAST -- Last index in YYTABLE. */
338 #define YYLAST ]b4_last[
340 /* YYNTOKENS -- Number of terminals. */
341 #define YYNTOKENS ]b4_tokens_number[
342 /* YYNNTS -- Number of nonterminals. */
343 #define YYNNTS ]b4_nterms_number[
344 /* YYNRULES -- Number of rules. */
345 #define YYNRULES ]b4_rules_number[
346 /* YYNRULES -- Number of states. */
347 #define YYNSTATES ]b4_states_number[
348 /* YYMAXRHS -- Maximum number of symbols on right-hand side of rule. */
349 #define YYMAXRHS ]b4_r2_max[
350 /* YYMAXLEFT -- Maximum number of symbols to the left of a handle
351 accessed by $0, $-1, etc., in any rule. */
352 #define YYMAXLEFT ]b4_max_left_semantic_context[
354 /* YYTRANSLATE(X) -- Bison symbol number corresponding to X. */
355 #define YYUNDEFTOK ]b4_undef_token_number[
356 #define YYMAXUTOK ]b4_user_token_number_max[
358 #define YYTRANSLATE(YYX) \
359 ((YYX <= 0) ? YYEOF : \
360 (unsigned int) (YYX) <= YYMAXUTOK ? yytranslate[YYX] : YYUNDEFTOK)
362 /* YYTRANSLATE[YYLEX] -- Bison symbol number corresponding to YYLEX. */
363 static const ]b4_int_type_for([b4_translate
])[ yytranslate
[] =
369 /* YYPRHS[YYN] -- Index of the first RHS symbol of rule number YYN in
371 static const ]b4_int_type_for([b4_prhs
])[ yyprhs
[] =
376 /* YYRHS -- A `-1'-separated list of the rules' RHS. */
377 static const ]b4_int_type_for([b4_rhs
])[ yyrhs
[] =
382 /* YYRLINE[YYN] -- source line where rule number YYN was defined. */
383 static const ]b4_int_type_for([b4_rline
])[ yyrline
[] =
389 #if YYDEBUG || YYERROR_VERBOSE || YYTOKEN_TABLE
390 /* YYTNAME[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM.
391 First, the terminals, then, starting at YYNTOKENS, nonterminals. */
392 static const char *const yytname
[] =
398 /* YYR1[YYN] -- Symbol number of symbol that rule YYN derives. */
399 static const ]b4_int_type_for([b4_r1
])[ yyr1
[] =
404 /* YYR2[YYN] -- Number of symbols composing right hand side of rule YYN. */
405 static const ]b4_int_type_for([b4_r2
])[ yyr2
[] =
410 /* YYDPREC[RULE-NUM] -- Dynamic precedence of rule #RULE-NUM (0 if none). */
411 static const ]b4_int_type_for([b4_dprec
])[ yydprec
[] =
416 /* YYMERGER[RULE-NUM] -- Index of merging function for rule #RULE-NUM. */
417 static const ]b4_int_type_for([b4_merger
])[ yymerger
[] =
422 /* YYDEFACT[S] -- default rule to reduce with in state S when YYTABLE
423 doesn't specify something else to do. Zero means the default is an
425 static const ]b4_int_type_for([b4_defact
])[ yydefact
[] =
430 /* YYPDEFGOTO[NTERM-NUM]. */
431 static const ]b4_int_type_for([b4_defgoto
])[ yydefgoto
[] =
436 /* YYPACT[STATE-NUM] -- Index in YYTABLE of the portion describing
438 #define YYPACT_NINF ]b4_pact_ninf[
439 static const ]b4_int_type_for([b4_pact
])[ yypact
[] =
444 /* YYPGOTO[NTERM-NUM]. */
445 static const ]b4_int_type_for([b4_pgoto
])[ yypgoto
[] =
450 /* YYTABLE[YYPACT[STATE-NUM]]. What to do in state STATE-NUM. If
451 positive, shift that token. If negative, reduce the rule which
452 number is the opposite. If zero, do what YYDEFACT says.
453 If YYTABLE_NINF, syntax error. */
454 #define YYTABLE_NINF ]b4_table_ninf[
455 static const ]b4_int_type_for([b4_table
])[ yytable
[] =
460 /* YYCONFLP[YYPACT[STATE-NUM]] -- Pointer into YYCONFL of start of
461 list of conflicting reductions corresponding to action entry for
462 state STATE-NUM in yytable. 0 means no conflicts. The list in
463 yyconfl is terminated by a rule number of 0. */
464 static const ]b4_int_type_for([b4_conflict_list_heads
])[ yyconflp
[] =
466 ]b4_conflict_list_heads
[
469 /* YYCONFL[I] -- lists of conflicting rule numbers, each terminated by
470 0, pointed into by YYCONFLP. */
471 ]dnl Do
not use b4_int_type_for here
, since there are places where
472 dnl pointers onto yyconfl are taken
, which type is
"short int *".
473 dnl We probably ought to introduce a type
for confl
.
474 [static const short int yyconfl
[] =
476 ]b4_conflicting_rules
[
479 static const ]b4_int_type_for([b4_check
])[ yycheck
[] =
484 /* YYSTOS[STATE-NUM] -- The (internal number of the) accessing
485 symbol of state STATE-NUM. */
486 static const ]b4_int_type_for([b4_stos
])[ yystos
[] =
492 /* Prevent warning if -Wmissing-prototypes. */
493 ]b4_c_ansi_function_decl([yyparse
], [int], b4_parse_param
)[
495 /* Error token number */
498 /* YYLLOC_DEFAULT -- Set CURRENT to span from RHS[1] to RHS[N].
499 If N is 0, then set CURRENT to the empty location which ends
500 the previous symbol: RHS[0] (always defined). */
503 #define YYRHSLOC(Rhs, K) ((Rhs)[K].yystate.yyloc)
504 #ifndef YYLLOC_DEFAULT
505 # define YYLLOC_DEFAULT(Current, Rhs, N) \
509 (Current).first_line = YYRHSLOC (Rhs, 1).first_line; \
510 (Current).first_column = YYRHSLOC (Rhs, 1).first_column; \
511 (Current).last_line = YYRHSLOC (Rhs, N).last_line; \
512 (Current).last_column = YYRHSLOC (Rhs, N).last_column; \
516 (Current).first_line = (Current).last_line = \
517 YYRHSLOC (Rhs, 0).last_line; \
518 (Current).first_column = (Current).last_column = \
519 YYRHSLOC (Rhs, 0).last_column; \
523 /* YY_LOCATION_PRINT -- Print the location on the stream.
524 This macro was not mandated originally: define only if we know
525 we won't break user code: when these are the locations we know. */
527 # define YY_LOCATION_PRINT(File, Loc) \
528 fprintf (File, "%d.%d-%d.%d", \
529 (Loc).first_line, (Loc).first_column, \
530 (Loc).last_line, (Loc).last_column)
533 #ifndef YYLLOC_DEFAULT
534 # define YYLLOC_DEFAULT(Current, Rhs, N) ((void) 0)
538 #ifndef YY_LOCATION_PRINT
539 # define YY_LOCATION_PRINT(File, Loc) ((void) 0)
543 /* YYLEX -- calling `yylex' with the right arguments. */
544 #define YYLEX ]b4_c_function_call([yylex], [int], b4_lex_param)[
549 #define yynerrs (yystackp->yyerrcnt)
551 #define yychar (yystackp->yyrawchar)
553 #define yylval (yystackp->yyval)
555 #define yylloc (yystackp->yyloc)
556 m4_if(b4_prefix
[], [yy
], [],
557 [#define b4_prefix[]nerrs yynerrs
558 #define b4_prefix[]char yychar
559 #define b4_prefix[]lval yylval
560 #define b4_prefix[]lloc yylloc])],
568 static const int YYEOF
= 0;
569 static const int YYEMPTY
= -2;
571 typedef enum { yyok
, yyaccept
, yyabort
, yyerr
} YYRESULTTAG
;
574 do { YYRESULTTAG yyflag = YYE; if (yyflag != yyok) return yyflag; } \
580 # define YYFPRINTF fprintf
583 # define YYDPRINTF(Args) \
589 ]b4_yy_symbol_print_generate([b4_c_ansi_function_def
])[
591 # define YY_SYMBOL_PRINT(Title, Type, Value, Location) \
595 YYFPRINTF (stderr, "%s ", Title); \
596 yy_symbol_print (stderr, Type, \
597 Value]b4_location_if([, Location])[]b4_user_args[); \
598 YYFPRINTF (stderr, "\n"); \
602 /* Nonzero means print parse trace. It is left uninitialized so that
603 multiple parsers can coexist. */
608 # define YYDPRINTF(Args)
609 # define YY_SYMBOL_PRINT(Title, Type, Value, Location)
611 #endif /* !YYDEBUG */
613 /* YYINITDEPTH -- initial size of the parser's stacks. */
615 # define YYINITDEPTH ]b4_stack_depth_init[
618 /* YYMAXDEPTH -- maximum size the stacks can grow to (effective only
619 if the built-in stack extension method is used).
621 Do not make this value too large; the results are undefined if
622 SIZE_MAX < YYMAXDEPTH * sizeof (GLRStackItem)
623 evaluated with infinite-precision integer arithmetic. */
626 # define YYMAXDEPTH ]b4_stack_depth_max[
629 /* Minimum number of free items on the stack allowed after an
630 allocation. This is to allow allocation and initialization
631 to be completed by functions that call yyexpandGLRStack before the
632 stack is expanded, thus insuring that all necessary pointers get
633 properly redirected to new data. */
636 #ifndef YYSTACKEXPANDABLE
637 # if (! defined __cplusplus \
638 || (]b4_location_if([[defined YYLTYPE_IS_TRIVIAL && YYLTYPE_IS_TRIVIAL \
639 && ]])[defined YYSTYPE_IS_TRIVIAL && YYSTYPE_IS_TRIVIAL))
640 # define YYSTACKEXPANDABLE 1
642 # define YYSTACKEXPANDABLE 0
646 #if YYSTACKEXPANDABLE
647 # define YY_RESERVE_GLRSTACK(Yystack) \
649 if (Yystack->yyspaceLeft < YYHEADROOM) \
650 yyexpandGLRStack (Yystack); \
653 # define YY_RESERVE_GLRSTACK(Yystack) \
655 if (Yystack->yyspaceLeft < YYHEADROOM) \
656 yyMemoryExhausted (Yystack); \
664 # if defined __GLIBC__ && defined _STRING_H && defined _GNU_SOURCE
665 # define yystpcpy stpcpy
667 /* Copy YYSRC to YYDEST, returning the address of the terminating '\0' in
670 yystpcpy (char *yydest
, const char *yysrc
)
673 const char *yys
= yysrc
;
675 while ((*yyd
++ = *yys
++) != '\0')
684 /* Copy to YYRES the contents of YYSTR after stripping away unnecessary
685 quotes and backslashes, so that it's suitable for yyerror. The
686 heuristic is that double-quoting is unnecessary unless the string
687 contains an apostrophe, a comma, or backslash (other than
688 backslash-backslash). YYSTR is taken from yytname. If YYRES is
689 null, do not copy; instead, return the length of what the result
692 yytnamerr (char *yyres
, const char *yystr
)
697 char const *yyp
= yystr
;
704 goto do_not_strip_quotes
;
708 goto do_not_strip_quotes
;
721 do_not_strip_quotes
: ;
725 return strlen (yystr
);
727 return yystpcpy (yyres
, yystr
) - yyres
;
731 #endif /* !YYERROR_VERBOSE */
733 /** State numbers, as in LALR(1) machine */
734 typedef int yyStateNum
;
736 /** Rule numbers, as in LALR(1) machine */
737 typedef int yyRuleNum
;
739 /** Grammar symbol */
740 typedef short int yySymbol
;
742 /** Item references, as in LALR(1) machine */
743 typedef short int yyItemNum
;
745 typedef struct yyGLRState yyGLRState
;
746 typedef struct yyGLRStateSet yyGLRStateSet
;
747 typedef struct yySemanticOption yySemanticOption
;
748 typedef union yyGLRStackItem yyGLRStackItem
;
749 typedef struct yyGLRStack yyGLRStack
;
752 /** Type tag: always true. */
754 /** Type tag for yysemantics. If true, yysval applies, otherwise
755 * yyfirstVal applies. */
757 /** Number of corresponding LALR(1) machine state. */
758 yyStateNum yylrState
;
759 /** Preceding state in this stack */
761 /** Source position of the first token produced by my symbol */
764 /** First in a chain of alternative reductions producing the
765 * non-terminal corresponding to this state, threaded through
767 yySemanticOption
* yyfirstVal
;
768 /** Semantic value for this state. */
771 /** Source location for this state. */
775 struct yyGLRStateSet
{
776 yyGLRState
** yystates
;
777 /** During nondeterministic operation, yylookaheadNeeds tracks which
778 * stacks have actually needed the current lookahead. During deterministic
779 * operation, yylookaheadNeeds[0] is not maintained since it would merely
780 * duplicate yychar != YYEMPTY. */
781 yybool
* yylookaheadNeeds
;
782 size_t yysize
, yycapacity
;
785 struct yySemanticOption
{
786 /** Type tag: always false. */
788 /** Rule number for this reduction */
790 /** The last RHS state in the list of states to be reduced. */
792 /** The lookahead for this reduction. */
796 /** Next sibling in chain of options. To facilitate merging,
797 * options are chained in decreasing order by address. */
798 yySemanticOption
* yynext
;
801 /** Type of the items in the GLR stack. The yyisState field
802 * indicates which item of the union is valid. */
803 union yyGLRStackItem
{
805 yySemanticOption yyoption
;
810 ]b4_location_if([[ /* To compute the location of the error token. */
811 yyGLRStackItem yyerror_range
[3];]])[
819 YYJMP_BUF yyexception_buffer
;
820 yyGLRStackItem
* yyitems
;
821 yyGLRStackItem
* yynextFree
;
823 yyGLRState
* yysplitPoint
;
824 yyGLRState
* yylastDeleted
;
825 yyGLRStateSet yytops
;
828 #if YYSTACKEXPANDABLE
829 static void yyexpandGLRStack (yyGLRStack
* yystackp
);
832 static void yyFail (yyGLRStack
* yystackp
]b4_pure_formals
[, const char* yymsg
)
833 __attribute__ ((__noreturn__
));
835 yyFail (yyGLRStack
* yystackp
]b4_pure_formals
[, const char* yymsg
)
838 yyerror (]b4_yyerror_args
[yymsg
);
839 YYLONGJMP (yystackp
->yyexception_buffer
, 1);
842 static void yyMemoryExhausted (yyGLRStack
* yystackp
)
843 __attribute__ ((__noreturn__
));
845 yyMemoryExhausted (yyGLRStack
* yystackp
)
847 YYLONGJMP (yystackp
->yyexception_buffer
, 2);
850 #if YYDEBUG || YYERROR_VERBOSE
851 /** A printable representation of TOKEN. */
852 static inline const char*
853 yytokenName (yySymbol yytoken
)
855 if (yytoken
== YYEMPTY
)
858 return yytname
[yytoken
];
862 /** Fill in YYVSP[YYLOW1 .. YYLOW0-1] from the chain of states starting
863 * at YYVSP[YYLOW0].yystate.yypred. Leaves YYVSP[YYLOW1].yystate.yypred
864 * containing the pointer to the next state in the chain. */
865 static void yyfillin (yyGLRStackItem
*, int, int) __attribute__ ((__unused__
));
867 yyfillin (yyGLRStackItem
*yyvsp
, int yylow0
, int yylow1
)
871 s
= yyvsp
[yylow0
].yystate
.yypred
;
872 for (i
= yylow0
-1; i
>= yylow1
; i
-= 1)
874 YYASSERT (s
->yyresolved
);
875 yyvsp
[i
].yystate
.yyresolved
= yytrue
;
876 yyvsp
[i
].yystate
.yysemantics
.yysval
= s
->yysemantics
.yysval
;
877 yyvsp
[i
].yystate
.yyloc
= s
->yyloc
;
878 s
= yyvsp
[i
].yystate
.yypred
= s
->yypred
;
882 /* Do nothing if YYNORMAL or if *YYLOW <= YYLOW1. Otherwise, fill in
883 * YYVSP[YYLOW1 .. *YYLOW-1] as in yyfillin and set *YYLOW = YYLOW1.
884 * For convenience, always return YYLOW1. */
885 static inline int yyfill (yyGLRStackItem
*, int *, int, yybool
)
886 __attribute__ ((__unused__
));
888 yyfill (yyGLRStackItem
*yyvsp
, int *yylow
, int yylow1
, yybool yynormal
)
890 if (!yynormal
&& yylow1
< *yylow
)
892 yyfillin (yyvsp
, *yylow
, yylow1
);
898 /** Perform user action for rule number YYN, with RHS length YYRHSLEN,
899 * and top stack item YYVSP. YYLVALP points to place to put semantic
900 * value ($$), and yylocp points to place for location information
901 * (@@$). Returns yyok for normal return, yyaccept for YYACCEPT,
902 * yyerr for YYERROR, yyabort for YYABORT. */
903 /*ARGSUSED*/ static YYRESULTTAG
904 yyuserAction (yyRuleNum yyn
, int yyrhslen
, yyGLRStackItem
* yyvsp
,
906 YYLTYPE
* YYOPTIONAL_LOC (yylocp
),
910 yybool yynormal
__attribute__ ((__unused__
)) =
911 (yystackp
->yysplitPoint
== NULL
);
913 ]b4_parse_param_use
[]dnl
915 # define yyerrok (yystackp->yyerrState = 0)
917 # define YYACCEPT return yyaccept
919 # define YYABORT return yyabort
921 # define YYERROR return yyerrok, yyerr
923 # define YYRECOVERING (yystackp->yyerrState != 0)
925 # define yyclearin (yychar = YYEMPTY)
927 # define YYFILL(N) yyfill (yyvsp, &yylow, N, yynormal)
929 # define YYBACKUP(Token, Value) \
930 return yyerror (]b4_yyerror_args[YY_("syntax error: cannot back up")), \
935 *yyvalp
= yyval_default
;
937 *yyvalp
= yyvsp
[YYFILL (1-yyrhslen
)].yystate
.yysemantics
.yysval
;
938 YYLLOC_DEFAULT ((*yylocp
), (yyvsp
- yyrhslen
), yyrhslen
);
939 ]b4_location_if([[ yystackp
->yyerror_range
[1].yystate
.yyloc
= *yylocp
;
944 /* Line __line__ of glr.c. */
945 b4_syncline([@oline@
], [@ofile@
])[
960 /*ARGSUSED*/ static void
961 yyuserMerge (int yyn
, YYSTYPE
* yy0
, YYSTYPE
* yy1
)
973 /* Bison grammar-table manipulation. */
975 ]b4_yydestruct_generate([b4_c_ansi_function_def
])[
977 /** Number of symbols composing the right hand side of rule #RULE. */
979 yyrhsLength (yyRuleNum yyrule
)
985 yydestroyGLRState (char const *yymsg
, yyGLRState
*yys
]b4_user_formals
[)
988 yydestruct (yymsg
, yystos
[yys
->yylrState
],
989 &yys
->yysemantics
.yysval
]b4_location_if([, &yys
->yyloc
])[]b4_user_args
[);
995 if (yys
->yysemantics
.yyfirstVal
)
996 YYFPRINTF (stderr
, "%s unresolved ", yymsg
);
998 YYFPRINTF (stderr
, "%s incomplete ", yymsg
);
999 yy_symbol_print (stderr
, yystos
[yys
->yylrState
],
1000 NULL
]b4_location_if([, &yys
->yyloc
])[]b4_user_args
[);
1001 YYFPRINTF (stderr
, "\n");
1005 if (yys
->yysemantics
.yyfirstVal
)
1007 yySemanticOption
*yyoption
= yys
->yysemantics
.yyfirstVal
;
1010 for (yyrh
= yyoption
->yystate
, yyn
= yyrhsLength (yyoption
->yyrule
);
1012 yyrh
= yyrh
->yypred
, yyn
-= 1)
1013 yydestroyGLRState (yymsg
, yyrh
]b4_user_args
[);
1018 /** Left-hand-side symbol for rule #RULE. */
1019 static inline yySymbol
1020 yylhsNonterm (yyRuleNum yyrule
)
1022 return yyr1
[yyrule
];
1025 #define yyis_pact_ninf(yystate) \
1026 ]m4_if(m4_eval(b4_pact_ninf < b4_pact_min), [1],
1028 [((yystate
) == YYPACT_NINF
)])[
1030 /** True iff LR state STATE has only a default reduction (regardless
1032 static inline yybool
1033 yyisDefaultedState (yyStateNum yystate
)
1035 return yyis_pact_ninf (yypact
[yystate
]);
1038 /** The default reduction for STATE, assuming it has one. */
1039 static inline yyRuleNum
1040 yydefaultAction (yyStateNum yystate
)
1042 return yydefact
[yystate
];
1045 #define yyis_table_ninf(yytable_value) \
1046 ]m4_if(m4_eval(b4_table_ninf < b4_table_min), [1],
1048 [((yytable_value
) == YYTABLE_NINF
)])[
1050 /** Set *YYACTION to the action to take in YYSTATE on seeing YYTOKEN.
1052 * R < 0: Reduce on rule -R.
1054 * R > 0: Shift to state R.
1055 * Set *CONFLICTS to a pointer into yyconfl to 0-terminated list of
1056 * conflicting reductions.
1059 yygetLRActions (yyStateNum yystate
, int yytoken
,
1060 int* yyaction
, const short int** yyconflicts
)
1062 int yyindex
= yypact
[yystate
] + yytoken
;
1063 if (yyindex
< 0 || YYLAST
< yyindex
|| yycheck
[yyindex
] != yytoken
)
1065 *yyaction
= -yydefact
[yystate
];
1066 *yyconflicts
= yyconfl
;
1068 else if (! yyis_table_ninf (yytable
[yyindex
]))
1070 *yyaction
= yytable
[yyindex
];
1071 *yyconflicts
= yyconfl
+ yyconflp
[yyindex
];
1076 *yyconflicts
= yyconfl
+ yyconflp
[yyindex
];
1080 static inline yyStateNum
1081 yyLRgotoState (yyStateNum yystate
, yySymbol yylhs
)
1084 yyr
= yypgoto
[yylhs
- YYNTOKENS
] + yystate
;
1085 if (0 <= yyr
&& yyr
<= YYLAST
&& yycheck
[yyr
] == yystate
)
1086 return yytable
[yyr
];
1088 return yydefgoto
[yylhs
- YYNTOKENS
];
1091 static inline yybool
1092 yyisShiftAction (int yyaction
)
1094 return 0 < yyaction
;
1097 static inline yybool
1098 yyisErrorAction (int yyaction
)
1100 return yyaction
== 0;
1105 /** Return a fresh GLRStackItem. Callers should call
1106 * YY_RESERVE_GLRSTACK afterwards to make sure there is sufficient
1109 static inline yyGLRStackItem
*
1110 yynewGLRStackItem (yyGLRStack
* yystackp
, yybool yyisState
)
1112 yyGLRStackItem
* yynewItem
= yystackp
->yynextFree
;
1113 yystackp
->yyspaceLeft
-= 1;
1114 yystackp
->yynextFree
+= 1;
1115 yynewItem
->yystate
.yyisState
= yyisState
;
1119 /** Add a new semantic action that will execute the action for rule
1120 * RULENUM on the semantic values in RHS to the list of
1121 * alternative actions for STATE. Assumes that RHS comes from
1122 * stack #K of *STACKP. */
1124 yyaddDeferredAction (yyGLRStack
* yystackp
, size_t yyk
, yyGLRState
* yystate
,
1125 yyGLRState
* rhs
, yyRuleNum yyrule
)
1127 yySemanticOption
* yynewOption
=
1128 &yynewGLRStackItem (yystackp
, yyfalse
)->yyoption
;
1129 yynewOption
->yystate
= rhs
;
1130 yynewOption
->yyrule
= yyrule
;
1131 if (yystackp
->yytops
.yylookaheadNeeds
[yyk
])
1133 yynewOption
->yyrawchar
= yychar
;
1134 yynewOption
->yyval
= yylval
;
1135 yynewOption
->yyloc
= yylloc
;
1138 yynewOption
->yyrawchar
= YYEMPTY
;
1139 yynewOption
->yynext
= yystate
->yysemantics
.yyfirstVal
;
1140 yystate
->yysemantics
.yyfirstVal
= yynewOption
;
1142 YY_RESERVE_GLRSTACK (yystackp
);
1147 /** Initialize SET to a singleton set containing an empty stack. */
1149 yyinitStateSet (yyGLRStateSet
* yyset
)
1152 yyset
->yycapacity
= 16;
1153 yyset
->yystates
= (yyGLRState
**) YYMALLOC (16 * sizeof yyset
->yystates
[0]);
1154 if (! yyset
->yystates
)
1156 yyset
->yystates
[0] = NULL
;
1157 yyset
->yylookaheadNeeds
=
1158 (yybool
*) YYMALLOC (16 * sizeof yyset
->yylookaheadNeeds
[0]);
1159 if (! yyset
->yylookaheadNeeds
)
1161 YYFREE (yyset
->yystates
);
1167 static void yyfreeStateSet (yyGLRStateSet
* yyset
)
1169 YYFREE (yyset
->yystates
);
1170 YYFREE (yyset
->yylookaheadNeeds
);
1173 /** Initialize STACK to a single empty stack, with total maximum
1174 * capacity for all stacks of SIZE. */
1176 yyinitGLRStack (yyGLRStack
* yystackp
, size_t yysize
)
1178 yystackp
->yyerrState
= 0;
1180 yystackp
->yyspaceLeft
= yysize
;
1182 (yyGLRStackItem
*) YYMALLOC (yysize
* sizeof yystackp
->yynextFree
[0]);
1183 if (!yystackp
->yyitems
)
1185 yystackp
->yynextFree
= yystackp
->yyitems
;
1186 yystackp
->yysplitPoint
= NULL
;
1187 yystackp
->yylastDeleted
= NULL
;
1188 return yyinitStateSet (&yystackp
->yytops
);
1192 #if YYSTACKEXPANDABLE
1193 # define YYRELOC(YYFROMITEMS,YYTOITEMS,YYX,YYTYPE) \
1194 &((YYTOITEMS) - ((YYFROMITEMS) - (yyGLRStackItem*) (YYX)))->YYTYPE
1196 /** If STACK is expandable, extend it. WARNING: Pointers into the
1197 stack from outside should be considered invalid after this call.
1198 We always expand when there are 1 or fewer items left AFTER an
1199 allocation, so that we can avoid having external pointers exist
1200 across an allocation. */
1202 yyexpandGLRStack (yyGLRStack
* yystackp
)
1204 yyGLRStackItem
* yynewItems
;
1205 yyGLRStackItem
* yyp0
, *yyp1
;
1206 size_t yysize
, yynewSize
;
1208 yysize
= yystackp
->yynextFree
- yystackp
->yyitems
;
1209 if (YYMAXDEPTH
- YYHEADROOM
< yysize
)
1210 yyMemoryExhausted (yystackp
);
1211 yynewSize
= 2*yysize
;
1212 if (YYMAXDEPTH
< yynewSize
)
1213 yynewSize
= YYMAXDEPTH
;
1214 yynewItems
= (yyGLRStackItem
*) YYMALLOC (yynewSize
* sizeof yynewItems
[0]);
1216 yyMemoryExhausted (yystackp
);
1217 for (yyp0
= yystackp
->yyitems
, yyp1
= yynewItems
, yyn
= yysize
;
1219 yyn
-= 1, yyp0
+= 1, yyp1
+= 1)
1222 if (*(yybool
*) yyp0
)
1224 yyGLRState
* yys0
= &yyp0
->yystate
;
1225 yyGLRState
* yys1
= &yyp1
->yystate
;
1226 if (yys0
->yypred
!= NULL
)
1228 YYRELOC (yyp0
, yyp1
, yys0
->yypred
, yystate
);
1229 if (! yys0
->yyresolved
&& yys0
->yysemantics
.yyfirstVal
!= NULL
)
1230 yys1
->yysemantics
.yyfirstVal
=
1231 YYRELOC(yyp0
, yyp1
, yys0
->yysemantics
.yyfirstVal
, yyoption
);
1235 yySemanticOption
* yyv0
= &yyp0
->yyoption
;
1236 yySemanticOption
* yyv1
= &yyp1
->yyoption
;
1237 if (yyv0
->yystate
!= NULL
)
1238 yyv1
->yystate
= YYRELOC (yyp0
, yyp1
, yyv0
->yystate
, yystate
);
1239 if (yyv0
->yynext
!= NULL
)
1240 yyv1
->yynext
= YYRELOC (yyp0
, yyp1
, yyv0
->yynext
, yyoption
);
1243 if (yystackp
->yysplitPoint
!= NULL
)
1244 yystackp
->yysplitPoint
= YYRELOC (yystackp
->yyitems
, yynewItems
,
1245 yystackp
->yysplitPoint
, yystate
);
1247 for (yyn
= 0; yyn
< yystackp
->yytops
.yysize
; yyn
+= 1)
1248 if (yystackp
->yytops
.yystates
[yyn
] != NULL
)
1249 yystackp
->yytops
.yystates
[yyn
] =
1250 YYRELOC (yystackp
->yyitems
, yynewItems
,
1251 yystackp
->yytops
.yystates
[yyn
], yystate
);
1252 YYFREE (yystackp
->yyitems
);
1253 yystackp
->yyitems
= yynewItems
;
1254 yystackp
->yynextFree
= yynewItems
+ yysize
;
1255 yystackp
->yyspaceLeft
= yynewSize
- yysize
;
1260 yyfreeGLRStack (yyGLRStack
* yystackp
)
1262 YYFREE (yystackp
->yyitems
);
1263 yyfreeStateSet (&yystackp
->yytops
);
1266 /** Assuming that S is a GLRState somewhere on STACK, update the
1267 * splitpoint of STACK, if needed, so that it is at least as deep as
1270 yyupdateSplit (yyGLRStack
* yystackp
, yyGLRState
* yys
)
1272 if (yystackp
->yysplitPoint
!= NULL
&& yystackp
->yysplitPoint
> yys
)
1273 yystackp
->yysplitPoint
= yys
;
1276 /** Invalidate stack #K in STACK. */
1278 yymarkStackDeleted (yyGLRStack
* yystackp
, size_t yyk
)
1280 if (yystackp
->yytops
.yystates
[yyk
] != NULL
)
1281 yystackp
->yylastDeleted
= yystackp
->yytops
.yystates
[yyk
];
1282 yystackp
->yytops
.yystates
[yyk
] = NULL
;
1285 /** Undelete the last stack that was marked as deleted. Can only be
1286 done once after a deletion, and only when all other stacks have
1289 yyundeleteLastStack (yyGLRStack
* yystackp
)
1291 if (yystackp
->yylastDeleted
== NULL
|| yystackp
->yytops
.yysize
!= 0)
1293 yystackp
->yytops
.yystates
[0] = yystackp
->yylastDeleted
;
1294 yystackp
->yytops
.yysize
= 1;
1295 YYDPRINTF ((stderr
, "Restoring last deleted stack as stack #0.\n"));
1296 yystackp
->yylastDeleted
= NULL
;
1300 yyremoveDeletes (yyGLRStack
* yystackp
)
1304 while (yyj
< yystackp
->yytops
.yysize
)
1306 if (yystackp
->yytops
.yystates
[yyi
] == NULL
)
1310 YYDPRINTF ((stderr
, "Removing dead stacks.\n"));
1312 yystackp
->yytops
.yysize
-= 1;
1316 yystackp
->yytops
.yystates
[yyj
] = yystackp
->yytops
.yystates
[yyi
];
1317 /* In the current implementation, it's unnecessary to copy
1318 yystackp->yytops.yylookaheadNeeds[yyi] since, after
1319 yyremoveDeletes returns, the parser immediately either enters
1320 deterministic operation or shifts a token. However, it doesn't
1321 hurt, and the code might evolve to need it. */
1322 yystackp
->yytops
.yylookaheadNeeds
[yyj
] =
1323 yystackp
->yytops
.yylookaheadNeeds
[yyi
];
1326 YYDPRINTF ((stderr
, "Rename stack %lu -> %lu.\n",
1327 (unsigned long int) yyi
, (unsigned long int) yyj
));
1335 /** Shift to a new state on stack #K of STACK, corresponding to LR state
1336 * LRSTATE, at input position POSN, with (resolved) semantic value SVAL. */
1338 yyglrShift (yyGLRStack
* yystackp
, size_t yyk
, yyStateNum yylrState
,
1340 YYSTYPE
* yyvalp
, YYLTYPE
* yylocp
)
1342 yyGLRState
* yynewState
= &yynewGLRStackItem (yystackp
, yytrue
)->yystate
;
1344 yynewState
->yylrState
= yylrState
;
1345 yynewState
->yyposn
= yyposn
;
1346 yynewState
->yyresolved
= yytrue
;
1347 yynewState
->yypred
= yystackp
->yytops
.yystates
[yyk
];
1348 yynewState
->yysemantics
.yysval
= *yyvalp
;
1349 yynewState
->yyloc
= *yylocp
;
1350 yystackp
->yytops
.yystates
[yyk
] = yynewState
;
1352 YY_RESERVE_GLRSTACK (yystackp
);
1355 /** Shift stack #K of YYSTACK, to a new state corresponding to LR
1356 * state YYLRSTATE, at input position YYPOSN, with the (unresolved)
1357 * semantic value of YYRHS under the action for YYRULE. */
1359 yyglrShiftDefer (yyGLRStack
* yystackp
, size_t yyk
, yyStateNum yylrState
,
1360 size_t yyposn
, yyGLRState
* rhs
, yyRuleNum yyrule
)
1362 yyGLRState
* yynewState
= &yynewGLRStackItem (yystackp
, yytrue
)->yystate
;
1364 yynewState
->yylrState
= yylrState
;
1365 yynewState
->yyposn
= yyposn
;
1366 yynewState
->yyresolved
= yyfalse
;
1367 yynewState
->yypred
= yystackp
->yytops
.yystates
[yyk
];
1368 yynewState
->yysemantics
.yyfirstVal
= NULL
;
1369 yystackp
->yytops
.yystates
[yyk
] = yynewState
;
1371 /* Invokes YY_RESERVE_GLRSTACK. */
1372 yyaddDeferredAction (yystackp
, yyk
, yynewState
, rhs
, yyrule
);
1375 /** Pop the symbols consumed by reduction #RULE from the top of stack
1376 * #K of STACK, and perform the appropriate semantic action on their
1377 * semantic values. Assumes that all ambiguities in semantic values
1378 * have been previously resolved. Set *VALP to the resulting value,
1379 * and *LOCP to the computed location (if any). Return value is as
1380 * for userAction. */
1381 static inline YYRESULTTAG
1382 yydoAction (yyGLRStack
* yystackp
, size_t yyk
, yyRuleNum yyrule
,
1383 YYSTYPE
* yyvalp
, YYLTYPE
* yylocp
]b4_user_formals
[)
1385 int yynrhs
= yyrhsLength (yyrule
);
1387 if (yystackp
->yysplitPoint
== NULL
)
1389 /* Standard special case: single stack. */
1390 yyGLRStackItem
* rhs
= (yyGLRStackItem
*) yystackp
->yytops
.yystates
[yyk
];
1391 YYASSERT (yyk
== 0);
1392 yystackp
->yynextFree
-= yynrhs
;
1393 yystackp
->yyspaceLeft
+= yynrhs
;
1394 yystackp
->yytops
.yystates
[0] = & yystackp
->yynextFree
[-1].yystate
;
1395 return yyuserAction (yyrule
, yynrhs
, rhs
,
1396 yyvalp
, yylocp
, yystackp
]b4_user_args
[);
1400 /* At present, doAction is never called in nondeterministic
1401 * mode, so this branch is never taken. It is here in
1402 * anticipation of a future feature that will allow immediate
1403 * evaluation of selected actions in nondeterministic mode. */
1406 yyGLRStackItem yyrhsVals
[YYMAXRHS
+ YYMAXLEFT
+ 1];
1407 yys
= yyrhsVals
[YYMAXRHS
+ YYMAXLEFT
].yystate
.yypred
1408 = yystackp
->yytops
.yystates
[yyk
];]b4_location_if([[
1410 /* Set default location. */
1411 yyrhsVals
[YYMAXRHS
+ YYMAXLEFT
- 1].yystate
.yyloc
= yys
->yyloc
;]])[
1412 for (yyi
= 0; yyi
< yynrhs
; yyi
+= 1)
1417 yyupdateSplit (yystackp
, yys
);
1418 yystackp
->yytops
.yystates
[yyk
] = yys
;
1419 return yyuserAction (yyrule
, yynrhs
, yyrhsVals
+ YYMAXRHS
+ YYMAXLEFT
- 1,
1420 yyvalp
, yylocp
, yystackp
]b4_user_args
[);
1425 # define YY_REDUCE_PRINT(Args)
1427 # define YY_REDUCE_PRINT(Args) \
1430 yy_reduce_print Args; \
1433 /*----------------------------------------------------------.
1434 | Report that the RULE is going to be reduced on stack #K. |
1435 `----------------------------------------------------------*/
1437 /*ARGSUSED*/ static inline void
1438 yy_reduce_print (yyGLRStack
* yystackp
, size_t yyk
, yyRuleNum yyrule
,
1439 YYSTYPE
* yyvalp
, YYLTYPE
* yylocp
]b4_user_formals
[)
1441 int yynrhs
= yyrhsLength (yyrule
);
1442 yybool yynormal
__attribute__ ((__unused__
)) =
1443 (yystackp
->yysplitPoint
== NULL
);
1444 yyGLRStackItem
* yyvsp
= (yyGLRStackItem
*) yystackp
->yytops
.yystates
[yyk
];
1449 ]b4_parse_param_use
[]dnl
1450 [ YYFPRINTF (stderr
, "Reducing stack %lu by rule %d (line %lu):\n",
1451 (unsigned long int) yyk
, yyrule
- 1,
1452 (unsigned long int) yyrline
[yyrule
]);
1453 /* The symbols being reduced. */
1454 for (yyi
= 0; yyi
< yynrhs
; yyi
++)
1456 fprintf (stderr
, " $%d = ", yyi
+ 1);
1457 yy_symbol_print (stderr
, yyrhs
[yyprhs
[yyrule
] + yyi
],
1458 &]b4_rhs_value(yynrhs
, yyi
+ 1)[
1459 ]b4_location_if([, &]b4_rhs_location(yynrhs
, yyi
+ 1))[]dnl
1461 fprintf (stderr
, "\n");
1466 /** Pop items off stack #K of STACK according to grammar rule RULE,
1467 * and push back on the resulting nonterminal symbol. Perform the
1468 * semantic action associated with RULE and store its value with the
1469 * newly pushed state, if FORCEEVAL or if STACK is currently
1470 * unambiguous. Otherwise, store the deferred semantic action with
1471 * the new state. If the new state would have an identical input
1472 * position, LR state, and predecessor to an existing state on the stack,
1473 * it is identified with that existing state, eliminating stack #K from
1474 * the STACK. In this case, the (necessarily deferred) semantic value is
1475 * added to the options for the existing state's semantic value.
1477 static inline YYRESULTTAG
1478 yyglrReduce (yyGLRStack
* yystackp
, size_t yyk
, yyRuleNum yyrule
,
1479 yybool yyforceEval
]b4_user_formals
[)
1481 size_t yyposn
= yystackp
->yytops
.yystates
[yyk
]->yyposn
;
1483 if (yyforceEval
|| yystackp
->yysplitPoint
== NULL
)
1488 YY_REDUCE_PRINT ((yystackp
, yyk
, yyrule
, &yysval
, &yyloc
]b4_user_args
[));
1489 YYCHK (yydoAction (yystackp
, yyk
, yyrule
, &yysval
,
1490 &yyloc
]b4_user_args
[));
1491 YY_SYMBOL_PRINT ("-> $$ =", yyr1
[yyrule
], &yysval
, &yyloc
);
1492 yyglrShift (yystackp
, yyk
,
1493 yyLRgotoState (yystackp
->yytops
.yystates
[yyk
]->yylrState
,
1494 yylhsNonterm (yyrule
)),
1495 yyposn
, &yysval
, &yyloc
);
1501 yyGLRState
* yys
, *yys0
= yystackp
->yytops
.yystates
[yyk
];
1502 yyStateNum yynewLRState
;
1504 for (yys
= yystackp
->yytops
.yystates
[yyk
], yyn
= yyrhsLength (yyrule
);
1510 yyupdateSplit (yystackp
, yys
);
1511 yynewLRState
= yyLRgotoState (yys
->yylrState
, yylhsNonterm (yyrule
));
1513 "Reduced stack %lu by rule #%d; action deferred. Now in state %d.\n",
1514 (unsigned long int) yyk
, yyrule
- 1, yynewLRState
));
1515 for (yyi
= 0; yyi
< yystackp
->yytops
.yysize
; yyi
+= 1)
1516 if (yyi
!= yyk
&& yystackp
->yytops
.yystates
[yyi
] != NULL
)
1518 yyGLRState
* yyp
, *yysplit
= yystackp
->yysplitPoint
;
1519 yyp
= yystackp
->yytops
.yystates
[yyi
];
1520 while (yyp
!= yys
&& yyp
!= yysplit
&& yyp
->yyposn
>= yyposn
)
1522 if (yyp
->yylrState
== yynewLRState
&& yyp
->yypred
== yys
)
1524 yyaddDeferredAction (yystackp
, yyk
, yyp
, yys0
, yyrule
);
1525 yymarkStackDeleted (yystackp
, yyk
);
1526 YYDPRINTF ((stderr
, "Merging stack %lu into stack %lu.\n",
1527 (unsigned long int) yyk
,
1528 (unsigned long int) yyi
));
1534 yystackp
->yytops
.yystates
[yyk
] = yys
;
1535 yyglrShiftDefer (yystackp
, yyk
, yynewLRState
, yyposn
, yys0
, yyrule
);
1541 yysplitStack (yyGLRStack
* yystackp
, size_t yyk
)
1543 if (yystackp
->yysplitPoint
== NULL
)
1545 YYASSERT (yyk
== 0);
1546 yystackp
->yysplitPoint
= yystackp
->yytops
.yystates
[yyk
];
1548 if (yystackp
->yytops
.yysize
>= yystackp
->yytops
.yycapacity
)
1550 yyGLRState
** yynewStates
;
1551 yybool
* yynewLookaheadNeeds
;
1555 if (yystackp
->yytops
.yycapacity
1556 > (YYSIZEMAX
/ (2 * sizeof yynewStates
[0])))
1557 yyMemoryExhausted (yystackp
);
1558 yystackp
->yytops
.yycapacity
*= 2;
1561 (yyGLRState
**) YYREALLOC (yystackp
->yytops
.yystates
,
1562 (yystackp
->yytops
.yycapacity
1563 * sizeof yynewStates
[0]));
1564 if (yynewStates
== NULL
)
1565 yyMemoryExhausted (yystackp
);
1566 yystackp
->yytops
.yystates
= yynewStates
;
1568 yynewLookaheadNeeds
=
1569 (yybool
*) YYREALLOC (yystackp
->yytops
.yylookaheadNeeds
,
1570 (yystackp
->yytops
.yycapacity
1571 * sizeof yynewLookaheadNeeds
[0]));
1572 if (yynewLookaheadNeeds
== NULL
)
1573 yyMemoryExhausted (yystackp
);
1574 yystackp
->yytops
.yylookaheadNeeds
= yynewLookaheadNeeds
;
1576 yystackp
->yytops
.yystates
[yystackp
->yytops
.yysize
]
1577 = yystackp
->yytops
.yystates
[yyk
];
1578 yystackp
->yytops
.yylookaheadNeeds
[yystackp
->yytops
.yysize
]
1579 = yystackp
->yytops
.yylookaheadNeeds
[yyk
];
1580 yystackp
->yytops
.yysize
+= 1;
1581 return yystackp
->yytops
.yysize
-1;
1584 /** True iff Y0 and Y1 represent identical options at the top level.
1585 * That is, they represent the same rule applied to RHS symbols
1586 * that produce the same terminal symbols. */
1588 yyidenticalOptions (yySemanticOption
* yyy0
, yySemanticOption
* yyy1
)
1590 if (yyy0
->yyrule
== yyy1
->yyrule
)
1592 yyGLRState
*yys0
, *yys1
;
1594 for (yys0
= yyy0
->yystate
, yys1
= yyy1
->yystate
,
1595 yyn
= yyrhsLength (yyy0
->yyrule
);
1597 yys0
= yys0
->yypred
, yys1
= yys1
->yypred
, yyn
-= 1)
1598 if (yys0
->yyposn
!= yys1
->yyposn
)
1606 /** Assuming identicalOptions (Y0,Y1), destructively merge the
1607 * alternative semantic values for the RHS-symbols of Y1 and Y0. */
1609 yymergeOptionSets (yySemanticOption
* yyy0
, yySemanticOption
* yyy1
)
1611 yyGLRState
*yys0
, *yys1
;
1613 for (yys0
= yyy0
->yystate
, yys1
= yyy1
->yystate
,
1614 yyn
= yyrhsLength (yyy0
->yyrule
);
1616 yys0
= yys0
->yypred
, yys1
= yys1
->yypred
, yyn
-= 1)
1620 else if (yys0
->yyresolved
)
1622 yys1
->yyresolved
= yytrue
;
1623 yys1
->yysemantics
.yysval
= yys0
->yysemantics
.yysval
;
1625 else if (yys1
->yyresolved
)
1627 yys0
->yyresolved
= yytrue
;
1628 yys0
->yysemantics
.yysval
= yys1
->yysemantics
.yysval
;
1632 yySemanticOption
** yyz0p
;
1633 yySemanticOption
* yyz1
;
1634 yyz0p
= &yys0
->yysemantics
.yyfirstVal
;
1635 yyz1
= yys1
->yysemantics
.yyfirstVal
;
1636 while (YYID (yytrue
))
1638 if (yyz1
== *yyz0p
|| yyz1
== NULL
)
1640 else if (*yyz0p
== NULL
)
1645 else if (*yyz0p
< yyz1
)
1647 yySemanticOption
* yyz
= *yyz0p
;
1649 yyz1
= yyz1
->yynext
;
1650 (*yyz0p
)->yynext
= yyz
;
1652 yyz0p
= &(*yyz0p
)->yynext
;
1654 yys1
->yysemantics
.yyfirstVal
= yys0
->yysemantics
.yyfirstVal
;
1659 /** Y0 and Y1 represent two possible actions to take in a given
1660 * parsing state; return 0 if no combination is possible,
1661 * 1 if user-mergeable, 2 if Y0 is preferred, 3 if Y1 is preferred. */
1663 yypreference (yySemanticOption
* y0
, yySemanticOption
* y1
)
1665 yyRuleNum r0
= y0
->yyrule
, r1
= y1
->yyrule
;
1666 int p0
= yydprec
[r0
], p1
= yydprec
[r1
];
1670 if (yymerger
[r0
] == 0 || yymerger
[r0
] != yymerger
[r1
])
1675 if (p0
== 0 || p1
== 0)
1684 static YYRESULTTAG
yyresolveValue (yyGLRState
* yys
,
1685 yyGLRStack
* yystackp
]b4_user_formals
[);
1688 /** Resolve the previous N states starting at and including state S. If result
1689 * != yyok, some states may have been left unresolved possibly with empty
1690 * semantic option chains. Regardless of whether result = yyok, each state
1691 * has been left with consistent data so that yydestroyGLRState can be invoked
1694 yyresolveStates (yyGLRState
* yys
, int yyn
,
1695 yyGLRStack
* yystackp
]b4_user_formals
[)
1699 YYASSERT (yys
->yypred
);
1700 YYCHK (yyresolveStates (yys
->yypred
, yyn
-1, yystackp
]b4_user_args
[));
1701 if (! yys
->yyresolved
)
1702 YYCHK (yyresolveValue (yys
, yystackp
]b4_user_args
[));
1707 /** Resolve the states for the RHS of OPT, perform its user action, and return
1708 * the semantic value and location. Regardless of whether result = yyok, all
1709 * RHS states have been destroyed (assuming the user action destroys all RHS
1710 * semantic values if invoked). */
1712 yyresolveAction (yySemanticOption
* yyopt
, yyGLRStack
* yystackp
,
1713 YYSTYPE
* yyvalp
, YYLTYPE
* yylocp
]b4_user_formals
[)
1715 yyGLRStackItem yyrhsVals
[YYMAXRHS
+ YYMAXLEFT
+ 1];
1718 YYSTYPE yylval_current
;
1719 YYLTYPE yylloc_current
;
1722 yynrhs
= yyrhsLength (yyopt
->yyrule
);
1723 yyflag
= yyresolveStates (yyopt
->yystate
, yynrhs
, yystackp
]b4_user_args
[);
1727 for (yys
= yyopt
->yystate
; yynrhs
> 0; yys
= yys
->yypred
, yynrhs
-= 1)
1728 yydestroyGLRState ("Cleanup: popping", yys
]b4_user_args
[);
1732 yyrhsVals
[YYMAXRHS
+ YYMAXLEFT
].yystate
.yypred
= yyopt
->yystate
;]b4_location_if([[
1734 /* Set default location. */
1735 yyrhsVals
[YYMAXRHS
+ YYMAXLEFT
- 1].yystate
.yyloc
= yyopt
->yystate
->yyloc
;]])[
1736 yychar_current
= yychar
;
1737 yylval_current
= yylval
;
1738 yylloc_current
= yylloc
;
1739 yychar
= yyopt
->yyrawchar
;
1740 yylval
= yyopt
->yyval
;
1741 yylloc
= yyopt
->yyloc
;
1742 yyflag
= yyuserAction (yyopt
->yyrule
, yynrhs
,
1743 yyrhsVals
+ YYMAXRHS
+ YYMAXLEFT
- 1,
1744 yyvalp
, yylocp
, yystackp
]b4_user_args
[);
1745 yychar
= yychar_current
;
1746 yylval
= yylval_current
;
1747 yylloc
= yylloc_current
;
1753 yyreportTree (yySemanticOption
* yyx
, int yyindent
)
1755 int yynrhs
= yyrhsLength (yyx
->yyrule
);
1758 yyGLRState
* yystates
[YYMAXRHS
];
1759 yyGLRState yyleftmost_state
;
1761 for (yyi
= yynrhs
, yys
= yyx
->yystate
; 0 < yyi
; yyi
-= 1, yys
= yys
->yypred
)
1762 yystates
[yyi
] = yys
;
1765 yyleftmost_state
.yyposn
= 0;
1766 yystates
[0] = &yyleftmost_state
;
1771 if (yyx
->yystate
->yyposn
< yys
->yyposn
+ 1)
1772 YYFPRINTF (stderr
, "%*s%s -> <Rule %d, empty>\n",
1773 yyindent
, "", yytokenName (yylhsNonterm (yyx
->yyrule
)),
1776 YYFPRINTF (stderr
, "%*s%s -> <Rule %d, tokens %lu .. %lu>\n",
1777 yyindent
, "", yytokenName (yylhsNonterm (yyx
->yyrule
)),
1778 yyx
->yyrule
, (unsigned long int) (yys
->yyposn
+ 1),
1779 (unsigned long int) yyx
->yystate
->yyposn
);
1780 for (yyi
= 1; yyi
<= yynrhs
; yyi
+= 1)
1782 if (yystates
[yyi
]->yyresolved
)
1784 if (yystates
[yyi
-1]->yyposn
+1 > yystates
[yyi
]->yyposn
)
1785 YYFPRINTF (stderr
, "%*s%s <empty>\n", yyindent
+2, "",
1786 yytokenName (yyrhs
[yyprhs
[yyx
->yyrule
]+yyi
-1]));
1788 YYFPRINTF (stderr
, "%*s%s <tokens %lu .. %lu>\n", yyindent
+2, "",
1789 yytokenName (yyrhs
[yyprhs
[yyx
->yyrule
]+yyi
-1]),
1790 (unsigned long int) (yystates
[yyi
- 1]->yyposn
+ 1),
1791 (unsigned long int) yystates
[yyi
]->yyposn
);
1794 yyreportTree (yystates
[yyi
]->yysemantics
.yyfirstVal
, yyindent
+2);
1799 /*ARGSUSED*/ static YYRESULTTAG
1800 yyreportAmbiguity (yySemanticOption
* yyx0
,
1801 yySemanticOption
* yyx1
]b4_pure_formals
[)
1807 YYFPRINTF (stderr
, "Ambiguity detected.\n");
1808 YYFPRINTF (stderr
, "Option 1,\n");
1809 yyreportTree (yyx0
, 2);
1810 YYFPRINTF (stderr
, "\nOption 2,\n");
1811 yyreportTree (yyx1
, 2);
1812 YYFPRINTF (stderr
, "\n");
1815 yyerror (]b4_yyerror_args
[YY_("syntax is ambiguous"));
1819 /** Starting at and including state S1, resolve the location for each of the
1820 * previous N1 states that is unresolved. The first semantic option of a state
1821 * is always chosen. */
1823 yyresolveLocations (yyGLRState
* yys1
, int yyn1
,
1824 yyGLRStack
*yystackp
]b4_user_formals
[)
1828 yyresolveLocations (yys1
->yypred
, yyn1
- 1, yystackp
]b4_user_args
[);
1829 if (!yys1
->yyresolved
)
1831 yySemanticOption
*yyoption
;
1832 yyGLRStackItem yyrhsloc
[1 + YYMAXRHS
];
1835 YYSTYPE yylval_current
;
1836 YYLTYPE yylloc_current
;
1837 yyoption
= yys1
->yysemantics
.yyfirstVal
;
1838 YYASSERT (yyoption
!= NULL
);
1839 yynrhs
= yyrhsLength (yyoption
->yyrule
);
1844 yyresolveLocations (yyoption
->yystate
, yynrhs
,
1845 yystackp
]b4_user_args
[);
1846 for (yys
= yyoption
->yystate
, yyn
= yynrhs
;
1848 yys
= yys
->yypred
, yyn
-= 1)
1849 yyrhsloc
[yyn
].yystate
.yyloc
= yys
->yyloc
;
1853 yyGLRState
*yyprevious
= yyoption
->yystate
;
1854 YYASSERT (yyprevious
->yyresolved
);
1855 yyrhsloc
[0].yystate
.yyloc
= yyprevious
->yyloc
;
1857 yychar_current
= yychar
;
1858 yylval_current
= yylval
;
1859 yylloc_current
= yylloc
;
1860 yychar
= yyoption
->yyrawchar
;
1861 yylval
= yyoption
->yyval
;
1862 yylloc
= yyoption
->yyloc
;
1863 YYLLOC_DEFAULT ((yys1
->yyloc
), yyrhsloc
, yynrhs
);
1864 yychar
= yychar_current
;
1865 yylval
= yylval_current
;
1866 yylloc
= yylloc_current
;
1871 /** Resolve the ambiguity represented in state S, perform the indicated
1872 * actions, and set the semantic value of S. If result != yyok, the chain of
1873 * semantic options in S has been cleared instead or it has been left
1874 * unmodified except that redundant options may have been removed. Regardless
1875 * of whether result = yyok, S has been left with consistent data so that
1876 * yydestroyGLRState can be invoked if necessary. */
1878 yyresolveValue (yyGLRState
* yys
, yyGLRStack
* yystackp
]b4_user_formals
[)
1880 yySemanticOption
* yyoptionList
= yys
->yysemantics
.yyfirstVal
;
1881 yySemanticOption
* yybest
;
1882 yySemanticOption
** yypp
;
1886 YYLTYPE
*yylocp
= &yys
->yyloc
;
1888 yybest
= yyoptionList
;
1890 for (yypp
= &yyoptionList
->yynext
; *yypp
!= NULL
; )
1892 yySemanticOption
* yyp
= *yypp
;
1894 if (yyidenticalOptions (yybest
, yyp
))
1896 yymergeOptionSets (yybest
, yyp
);
1897 *yypp
= yyp
->yynext
;
1901 switch (yypreference (yybest
, yyp
))
1904 yyresolveLocations (yys
, 1, yystackp
]b4_user_args
[);
1905 return yyreportAmbiguity (yybest
, yyp
]b4_pure_args
[);
1917 /* This cannot happen so it is not worth a YYASSERT (yyfalse),
1918 but some compilers complain if the default case is
1922 yypp
= &yyp
->yynext
;
1928 yySemanticOption
* yyp
;
1929 int yyprec
= yydprec
[yybest
->yyrule
];
1930 yyflag
= yyresolveAction (yybest
, yystackp
, &yysval
,
1931 yylocp
]b4_user_args
[);
1933 for (yyp
= yybest
->yynext
; yyp
!= NULL
; yyp
= yyp
->yynext
)
1935 if (yyprec
== yydprec
[yyp
->yyrule
])
1937 YYSTYPE yysval_other
;
1939 yyflag
= yyresolveAction (yyp
, yystackp
, &yysval_other
,
1940 &yydummy
]b4_user_args
[);
1943 yydestruct ("Cleanup: discarding incompletely merged value for",
1944 yystos
[yys
->yylrState
],
1945 &yysval
]b4_location_if([, yylocp
])[]b4_user_args
[);
1948 yyuserMerge (yymerger
[yyp
->yyrule
], &yysval
, &yysval_other
);
1953 yyflag
= yyresolveAction (yybest
, yystackp
, &yysval
, yylocp
]b4_user_args
[);
1957 yys
->yyresolved
= yytrue
;
1958 yys
->yysemantics
.yysval
= yysval
;
1961 yys
->yysemantics
.yyfirstVal
= NULL
;
1966 yyresolveStack (yyGLRStack
* yystackp
]b4_user_formals
[)
1968 if (yystackp
->yysplitPoint
!= NULL
)
1973 for (yyn
= 0, yys
= yystackp
->yytops
.yystates
[0];
1974 yys
!= yystackp
->yysplitPoint
;
1975 yys
= yys
->yypred
, yyn
+= 1)
1977 YYCHK (yyresolveStates (yystackp
->yytops
.yystates
[0], yyn
, yystackp
1984 yycompressStack (yyGLRStack
* yystackp
)
1986 yyGLRState
* yyp
, *yyq
, *yyr
;
1988 if (yystackp
->yytops
.yysize
!= 1 || yystackp
->yysplitPoint
== NULL
)
1991 for (yyp
= yystackp
->yytops
.yystates
[0], yyq
= yyp
->yypred
, yyr
= NULL
;
1992 yyp
!= yystackp
->yysplitPoint
;
1993 yyr
= yyp
, yyp
= yyq
, yyq
= yyp
->yypred
)
1996 yystackp
->yyspaceLeft
+= yystackp
->yynextFree
- yystackp
->yyitems
;
1997 yystackp
->yynextFree
= ((yyGLRStackItem
*) yystackp
->yysplitPoint
) + 1;
1998 yystackp
->yyspaceLeft
-= yystackp
->yynextFree
- yystackp
->yyitems
;
1999 yystackp
->yysplitPoint
= NULL
;
2000 yystackp
->yylastDeleted
= NULL
;
2004 yystackp
->yynextFree
->yystate
= *yyr
;
2006 yystackp
->yynextFree
->yystate
.yypred
= &yystackp
->yynextFree
[-1].yystate
;
2007 yystackp
->yytops
.yystates
[0] = &yystackp
->yynextFree
->yystate
;
2008 yystackp
->yynextFree
+= 1;
2009 yystackp
->yyspaceLeft
-= 1;
2014 yyprocessOneStack (yyGLRStack
* yystackp
, size_t yyk
,
2015 size_t yyposn
]b4_pure_formals
[)
2018 const short int* yyconflicts
;
2021 while (yystackp
->yytops
.yystates
[yyk
] != NULL
)
2023 yyStateNum yystate
= yystackp
->yytops
.yystates
[yyk
]->yylrState
;
2024 YYDPRINTF ((stderr
, "Stack %lu Entering state %d\n",
2025 (unsigned long int) yyk
, yystate
));
2027 YYASSERT (yystate
!= YYFINAL
);
2029 if (yyisDefaultedState (yystate
))
2031 yyrule
= yydefaultAction (yystate
);
2034 YYDPRINTF ((stderr
, "Stack %lu dies.\n",
2035 (unsigned long int) yyk
));
2036 yymarkStackDeleted (yystackp
, yyk
);
2039 YYCHK (yyglrReduce (yystackp
, yyk
, yyrule
, yyfalse
]b4_user_args
[));
2044 yystackp
->yytops
.yylookaheadNeeds
[yyk
] = yytrue
;
2045 if (yychar
== YYEMPTY
)
2047 YYDPRINTF ((stderr
, "Reading a token: "));
2049 yytoken
= YYTRANSLATE (yychar
);
2050 YY_SYMBOL_PRINT ("Next token is", yytoken
, &yylval
, &yylloc
);
2053 yytoken
= YYTRANSLATE (yychar
);
2054 yygetLRActions (yystate
, yytoken
, &yyaction
, &yyconflicts
);
2056 while (*yyconflicts
!= 0)
2058 size_t yynewStack
= yysplitStack (yystackp
, yyk
);
2059 YYDPRINTF ((stderr
, "Splitting off stack %lu from %lu.\n",
2060 (unsigned long int) yynewStack
,
2061 (unsigned long int) yyk
));
2062 YYCHK (yyglrReduce (yystackp
, yynewStack
,
2063 *yyconflicts
, yyfalse
]b4_user_args
[));
2064 YYCHK (yyprocessOneStack (yystackp
, yynewStack
,
2065 yyposn
]b4_pure_args
[));
2069 if (yyisShiftAction (yyaction
))
2071 else if (yyisErrorAction (yyaction
))
2073 YYDPRINTF ((stderr
, "Stack %lu dies.\n",
2074 (unsigned long int) yyk
));
2075 yymarkStackDeleted (yystackp
, yyk
);
2079 YYCHK (yyglrReduce (yystackp
, yyk
, -yyaction
,
2080 yyfalse
]b4_user_args
[));
2086 /*ARGSUSED*/ static void
2087 yyreportSyntaxError (yyGLRStack
* yystackp
]b4_user_formals
[)
2089 if (yystackp
->yyerrState
== 0)
2093 yyn
= yypact
[yystackp
->yytops
.yystates
[0]->yylrState
];
2094 if (YYPACT_NINF
< yyn
&& yyn
< YYLAST
)
2096 yySymbol yytoken
= YYTRANSLATE (yychar
);
2097 size_t yysize0
= yytnamerr (NULL
, yytokenName (yytoken
));
2098 size_t yysize
= yysize0
;
2100 yybool yysize_overflow
= yyfalse
;
2102 enum { YYERROR_VERBOSE_ARGS_MAXIMUM
= 5 };
2103 char const *yyarg
[YYERROR_VERBOSE_ARGS_MAXIMUM
];
2107 static char const yyunexpected
[] = "syntax error, unexpected %s";
2108 static char const yyexpecting
[] = ", expecting %s";
2109 static char const yyor
[] = " or %s";
2110 char yyformat
[sizeof yyunexpected
2111 + sizeof yyexpecting
- 1
2112 + ((YYERROR_VERBOSE_ARGS_MAXIMUM
- 2)
2113 * (sizeof yyor
- 1))];
2114 char const *yyprefix
= yyexpecting
;
2116 /* Start YYX at -YYN if negative to avoid negative indexes in
2118 int yyxbegin
= yyn
< 0 ? -yyn
: 0;
2120 /* Stay within bounds of both yycheck and yytname. */
2121 int yychecklim
= YYLAST
- yyn
;
2122 int yyxend
= yychecklim
< YYNTOKENS
? yychecklim
: YYNTOKENS
;
2125 yyarg
[0] = yytokenName (yytoken
);
2126 yyfmt
= yystpcpy (yyformat
, yyunexpected
);
2128 for (yyx
= yyxbegin
; yyx
< yyxend
; ++yyx
)
2129 if (yycheck
[yyx
+ yyn
] == yyx
&& yyx
!= YYTERROR
)
2131 if (yycount
== YYERROR_VERBOSE_ARGS_MAXIMUM
)
2135 yyformat
[sizeof yyunexpected
- 1] = '\0';
2138 yyarg
[yycount
++] = yytokenName (yyx
);
2139 yysize1
= yysize
+ yytnamerr (NULL
, yytokenName (yyx
));
2140 yysize_overflow
|= yysize1
< yysize
;
2142 yyfmt
= yystpcpy (yyfmt
, yyprefix
);
2146 yyf
= YY_(yyformat
);
2147 yysize1
= yysize
+ strlen (yyf
);
2148 yysize_overflow
|= yysize1
< yysize
;
2151 if (!yysize_overflow
)
2152 yymsg
= (char *) YYMALLOC (yysize
);
2158 while ((*yyp
= *yyf
))
2160 if (*yyp
== '%' && yyf
[1] == 's' && yyi
< yycount
)
2162 yyp
+= yytnamerr (yyp
, yyarg
[yyi
++]);
2171 yyerror (]b4_lyyerror_args
[yymsg
);
2176 yyerror (]b4_lyyerror_args
[YY_("syntax error"));
2177 yyMemoryExhausted (yystackp
);
2181 #endif /* YYERROR_VERBOSE */
2182 yyerror (]b4_lyyerror_args
[YY_("syntax error"));
2187 /* Recover from a syntax error on *YYSTACKP, assuming that *YYSTACKP->YYTOKENP,
2188 yylval, and yylloc are the syntactic category, semantic value, and location
2189 of the look-ahead. */
2190 /*ARGSUSED*/ static void
2191 yyrecoverSyntaxError (yyGLRStack
* yystackp
]b4_user_formals
[)
2196 if (yystackp
->yyerrState
== 3)
2197 /* We just shifted the error token and (perhaps) took some
2198 reductions. Skip tokens until we can proceed. */
2199 while (YYID (yytrue
))
2202 if (yychar
== YYEOF
)
2203 yyFail (yystackp
][]b4_lpure_args
[, NULL
);
2204 if (yychar
!= YYEMPTY
)
2206 /* We throw away the lookahead, but the error range
2207 of the shifted error token must take it into account. */
2208 yyGLRState
*yys
= yystackp
->yytops
.yystates
[0];
2209 yyGLRStackItem yyerror_range
[3];
2210 yyerror_range
[1].yystate
.yyloc
= yys
->yyloc
;
2211 yyerror_range
[2].yystate
.yyloc
= yylloc
;
2212 YYLLOC_DEFAULT ((yys
->yyloc
), yyerror_range
, 2);]])[
2213 yytoken
= YYTRANSLATE (yychar
);
2214 yydestruct ("Error: discarding",
2215 yytoken
, &yylval
]b4_location_if([, &yylloc
])[]b4_user_args
[);
2217 YYDPRINTF ((stderr
, "Reading a token: "));
2219 yytoken
= YYTRANSLATE (yychar
);
2220 YY_SYMBOL_PRINT ("Next token is", yytoken
, &yylval
, &yylloc
);
2221 yyj
= yypact
[yystackp
->yytops
.yystates
[0]->yylrState
];
2222 if (yyis_pact_ninf (yyj
))
2225 if (yyj
< 0 || YYLAST
< yyj
|| yycheck
[yyj
] != yytoken
)
2227 if (yydefact
[yystackp
->yytops
.yystates
[0]->yylrState
] != 0)
2230 else if (yytable
[yyj
] != 0 && ! yyis_table_ninf (yytable
[yyj
]))
2234 /* Reduce to one stack. */
2235 for (yyk
= 0; yyk
< yystackp
->yytops
.yysize
; yyk
+= 1)
2236 if (yystackp
->yytops
.yystates
[yyk
] != NULL
)
2238 if (yyk
>= yystackp
->yytops
.yysize
)
2239 yyFail (yystackp
][]b4_lpure_args
[, NULL
);
2240 for (yyk
+= 1; yyk
< yystackp
->yytops
.yysize
; yyk
+= 1)
2241 yymarkStackDeleted (yystackp
, yyk
);
2242 yyremoveDeletes (yystackp
);
2243 yycompressStack (yystackp
);
2245 /* Now pop stack until we find a state that shifts the error token. */
2246 yystackp
->yyerrState
= 3;
2247 while (yystackp
->yytops
.yystates
[0] != NULL
)
2249 yyGLRState
*yys
= yystackp
->yytops
.yystates
[0];
2250 yyj
= yypact
[yys
->yylrState
];
2251 if (! yyis_pact_ninf (yyj
))
2254 if (0 <= yyj
&& yyj
<= YYLAST
&& yycheck
[yyj
] == YYTERROR
2255 && yyisShiftAction (yytable
[yyj
]))
2257 /* Shift the error token having adjusted its location. */
2258 YYLTYPE yyerrloc
;]b4_location_if([[
2259 yystackp
->yyerror_range
[2].yystate
.yyloc
= yylloc
;
2260 YYLLOC_DEFAULT (yyerrloc
, (yystackp
->yyerror_range
), 2);]])[
2261 YY_SYMBOL_PRINT ("Shifting", yystos
[yytable
[yyj
]],
2262 &yylval
, &yyerrloc
);
2263 yyglrShift (yystackp
, 0, yytable
[yyj
],
2264 yys
->yyposn
, &yylval
, &yyerrloc
);
2265 yys
= yystackp
->yytops
.yystates
[0];
2269 ]b4_location_if([[ yystackp
->yyerror_range
[1].yystate
.yyloc
= yys
->yyloc
;]])[
2270 yydestroyGLRState ("Error: popping", yys
]b4_user_args
[);
2271 yystackp
->yytops
.yystates
[0] = yys
->yypred
;
2272 yystackp
->yynextFree
-= 1;
2273 yystackp
->yyspaceLeft
+= 1;
2275 if (yystackp
->yytops
.yystates
[0] == NULL
)
2276 yyFail (yystackp
][]b4_lpure_args
[, NULL
);
2279 #define YYCHK1(YYE) \
2289 goto yyuser_error; \
2300 ]b4_c_ansi_function_def([yyparse
], [int], b4_parse_param
)[
2304 yyGLRStack
* const yystackp
= &yystack
;
2307 YYDPRINTF ((stderr
, "Starting parse\n"));
2310 yylval
= yyval_default
;
2312 #if YYLTYPE_IS_TRIVIAL
2313 yylloc
.first_line
= yylloc
.last_line
= 1;
2314 yylloc
.first_column
= yylloc
.last_column
= 0;
2317 m4_ifdef([b4_initial_action
], [
2318 m4_pushdef([b4_at_dollar
], [yylloc
])dnl
2319 m4_pushdef([b4_dollar_dollar
], [yylval
])dnl
2320 /* User initialization code. */
2322 m4_popdef([b4_dollar_dollar
])dnl
2323 m4_popdef([b4_at_dollar
])dnl
2324 /* Line __line__ of glr.c. */
2325 b4_syncline([@oline@
], [@ofile@
])])dnl
2327 if (! yyinitGLRStack (yystackp
, YYINITDEPTH
))
2328 goto yyexhaustedlab
;
2329 switch (YYSETJMP (yystack
.yyexception_buffer
))
2332 case 1: goto yyabortlab
;
2333 case 2: goto yyexhaustedlab
;
2334 default: goto yybuglab
;
2336 yyglrShift (&yystack
, 0, 0, 0, &yylval
, &yylloc
);
2339 while (YYID (yytrue
))
2341 /* For efficiency, we have two loops, the first of which is
2342 specialized to deterministic operation (single stack, no
2343 potential ambiguity). */
2345 while (YYID (yytrue
))
2349 const short int* yyconflicts
;
2351 yyStateNum yystate
= yystack
.yytops
.yystates
[0]->yylrState
;
2352 YYDPRINTF ((stderr
, "Entering state %d\n", yystate
));
2353 if (yystate
== YYFINAL
)
2355 if (yyisDefaultedState (yystate
))
2357 yyrule
= yydefaultAction (yystate
);
2360 ]b4_location_if([[ yystack
.yyerror_range
[1].yystate
.yyloc
= yylloc
;]])[
2361 yyreportSyntaxError (&yystack
]b4_user_args
[);
2364 YYCHK1 (yyglrReduce (&yystack
, 0, yyrule
, yytrue
]b4_user_args
[));
2369 if (yychar
== YYEMPTY
)
2371 YYDPRINTF ((stderr
, "Reading a token: "));
2373 yytoken
= YYTRANSLATE (yychar
);
2374 YY_SYMBOL_PRINT ("Next token is", yytoken
, &yylval
, &yylloc
);
2377 yytoken
= YYTRANSLATE (yychar
);
2378 yygetLRActions (yystate
, yytoken
, &yyaction
, &yyconflicts
);
2379 if (*yyconflicts
!= 0)
2381 if (yyisShiftAction (yyaction
))
2383 YY_SYMBOL_PRINT ("Shifting", yytoken
, &yylval
, &yylloc
);
2384 if (yychar
!= YYEOF
)
2387 yyglrShift (&yystack
, 0, yyaction
, yyposn
, &yylval
, &yylloc
);
2388 if (0 < yystack
.yyerrState
)
2389 yystack
.yyerrState
-= 1;
2391 else if (yyisErrorAction (yyaction
))
2393 ]b4_location_if([[ yystack
.yyerror_range
[1].yystate
.yyloc
= yylloc
;]])[
2394 yyreportSyntaxError (&yystack
]b4_user_args
[);
2398 YYCHK1 (yyglrReduce (&yystack
, 0, -yyaction
, yytrue
]b4_user_args
[));
2402 while (YYID (yytrue
))
2404 yySymbol yytoken_to_shift
;
2407 for (yys
= 0; yys
< yystack
.yytops
.yysize
; yys
+= 1)
2408 yystackp
->yytops
.yylookaheadNeeds
[yys
] = yychar
!= YYEMPTY
;
2410 /* yyprocessOneStack returns one of three things:
2412 - An error flag. If the caller is yyprocessOneStack, it
2413 immediately returns as well. When the caller is finally
2414 yyparse, it jumps to an error label via YYCHK1.
2416 - yyok, but yyprocessOneStack has invoked yymarkStackDeleted
2417 (&yystack, yys), which sets the top state of yys to NULL. Thus,
2418 yyparse's following invocation of yyremoveDeletes will remove
2421 - yyok, when ready to shift a token.
2423 Except in the first case, yyparse will invoke yyremoveDeletes and
2424 then shift the next token onto all remaining stacks. This
2425 synchronization of the shift (that is, after all preceding
2426 reductions on all stacks) helps prevent double destructor calls
2427 on yylval in the event of memory exhaustion. */
2429 for (yys
= 0; yys
< yystack
.yytops
.yysize
; yys
+= 1)
2430 YYCHK1 (yyprocessOneStack (&yystack
, yys
, yyposn
]b4_lpure_args
[));
2431 yyremoveDeletes (&yystack
);
2432 if (yystack
.yytops
.yysize
== 0)
2434 yyundeleteLastStack (&yystack
);
2435 if (yystack
.yytops
.yysize
== 0)
2436 yyFail (&yystack
][]b4_lpure_args
[, YY_("syntax error"));
2437 YYCHK1 (yyresolveStack (&yystack
]b4_user_args
[));
2438 YYDPRINTF ((stderr
, "Returning to deterministic operation.\n"));
2439 ]b4_location_if([[ yystack
.yyerror_range
[1].yystate
.yyloc
= yylloc
;]])[
2440 yyreportSyntaxError (&yystack
]b4_user_args
[);
2444 /* If any yyglrShift call fails, it will fail after shifting. Thus,
2445 a copy of yylval will already be on stack 0 in the event of a
2446 failure in the following loop. Thus, yychar is set to YYEMPTY
2447 before the loop to make sure the user destructor for yylval isn't
2449 yytoken_to_shift
= YYTRANSLATE (yychar
);
2452 for (yys
= 0; yys
< yystack
.yytops
.yysize
; yys
+= 1)
2455 const short int* yyconflicts
;
2456 yyStateNum yystate
= yystack
.yytops
.yystates
[yys
]->yylrState
;
2457 yygetLRActions (yystate
, yytoken_to_shift
, &yyaction
,
2459 /* Note that yyconflicts were handled by yyprocessOneStack. */
2460 YYDPRINTF ((stderr
, "On stack %lu, ", (unsigned long int) yys
));
2461 YY_SYMBOL_PRINT ("shifting", yytoken_to_shift
, &yylval
, &yylloc
);
2462 yyglrShift (&yystack
, yys
, yyaction
, yyposn
,
2464 YYDPRINTF ((stderr
, "Stack %lu now in state #%d\n",
2465 (unsigned long int) yys
,
2466 yystack
.yytops
.yystates
[yys
]->yylrState
));
2469 if (yystack
.yytops
.yysize
== 1)
2471 YYCHK1 (yyresolveStack (&yystack
]b4_user_args
[));
2472 YYDPRINTF ((stderr
, "Returning to deterministic operation.\n"));
2473 yycompressStack (&yystack
);
2479 yyrecoverSyntaxError (&yystack
]b4_user_args
[);
2480 yyposn
= yystack
.yytops
.yystates
[0]->yyposn
;
2496 yyerror (]b4_lyyerror_args
[YY_("memory exhausted"));
2501 if (yychar
!= YYEOF
&& yychar
!= YYEMPTY
)
2502 yydestruct ("Cleanup: discarding lookahead",
2503 YYTRANSLATE (yychar
),
2504 &yylval
]b4_location_if([, &yylloc
])[]b4_user_args
[);
2506 /* If the stack is well-formed, pop the stack until it is empty,
2507 destroying its entries as we go. But free the stack regardless
2508 of whether it is well-formed. */
2509 if (yystack
.yyitems
)
2511 yyGLRState
** yystates
= yystack
.yytops
.yystates
;
2514 size_t yysize
= yystack
.yytops
.yysize
;
2516 for (yyk
= 0; yyk
< yysize
; yyk
+= 1)
2519 while (yystates
[yyk
])
2521 yyGLRState
*yys
= yystates
[yyk
];
2522 ]b4_location_if([[ yystack
.yyerror_range
[1].yystate
.yyloc
= yys
->yyloc
;]]
2523 )[ yydestroyGLRState ("Cleanup: popping", yys
]b4_user_args
[);
2524 yystates
[yyk
] = yys
->yypred
;
2525 yystack
.yynextFree
-= 1;
2526 yystack
.yyspaceLeft
+= 1;
2531 yyfreeGLRStack (&yystack
);
2537 /* DEBUGGING ONLY */
2539 static void yypstack (yyGLRStack
* yystackp
, size_t yyk
)
2540 __attribute__ ((__unused__
));
2541 static void yypdumpstack (yyGLRStack
* yystackp
) __attribute__ ((__unused__
));
2544 yy_yypstack (yyGLRState
* yys
)
2548 yy_yypstack (yys
->yypred
);
2549 fprintf (stderr
, " -> ");
2551 fprintf (stderr
, "%d@@%lu", yys
->yylrState
, (unsigned long int) yys
->yyposn
);
2555 yypstates (yyGLRState
* yyst
)
2558 fprintf (stderr
, "<null>");
2561 fprintf (stderr
, "\n");
2565 yypstack (yyGLRStack
* yystackp
, size_t yyk
)
2567 yypstates (yystackp
->yytops
.yystates
[yyk
]);
2570 #define YYINDEX(YYX) \
2571 ((YYX) == NULL ? -1 : (yyGLRStackItem*) (YYX) - yystackp->yyitems)
2575 yypdumpstack (yyGLRStack
* yystackp
)
2577 yyGLRStackItem
* yyp
;
2579 for (yyp
= yystackp
->yyitems
; yyp
< yystackp
->yynextFree
; yyp
+= 1)
2581 fprintf (stderr
, "%3lu. ", (unsigned long int) (yyp
- yystackp
->yyitems
));
2582 if (*(yybool
*) yyp
)
2584 fprintf (stderr
, "Res: %d, LR State: %d, posn: %lu, pred: %ld",
2585 yyp
->yystate
.yyresolved
, yyp
->yystate
.yylrState
,
2586 (unsigned long int) yyp
->yystate
.yyposn
,
2587 (long int) YYINDEX (yyp
->yystate
.yypred
));
2588 if (! yyp
->yystate
.yyresolved
)
2589 fprintf (stderr
, ", firstVal: %ld",
2590 (long int) YYINDEX (yyp
->yystate
.yysemantics
.yyfirstVal
));
2594 fprintf (stderr
, "Option. rule: %d, state: %ld, next: %ld",
2595 yyp
->yyoption
.yyrule
,
2596 (long int) YYINDEX (yyp
->yyoption
.yystate
),
2597 (long int) YYINDEX (yyp
->yyoption
.yynext
));
2599 fprintf (stderr
, "\n");
2601 fprintf (stderr
, "Tops:");
2602 for (yyi
= 0; yyi
< yystackp
->yytops
.yysize
; yyi
+= 1)
2603 fprintf (stderr
, "%lu: %ld; ", (unsigned long int) yyi
,
2604 (long int) YYINDEX (yystackp
->yytops
.yystates
[yyi
]));
2605 fprintf (stderr
, "\n");
2611 m4_if(b4_defines_flag
, 0, [],
2612 [@output @output_header_name@
2613 b4_copyright([Skeleton interface
for Bison GLR parsers in C
],
2614 [2002, 2003, 2004, 2005, 2006])
2616 /* As a special exception, you may create a larger work that contains
2617 part or all of the Bison parser skeleton and distribute that work
2618 under terms of your choice, so long as that work isn't itself a
2619 parser generator using the skeleton or a modified version thereof
2620 as a parser skeleton. Alternatively, if you modify or redistribute
2621 the parser skeleton itself, you may (at your option) remove this
2622 special exception, which will cause the skeleton and the resulting
2623 Bison output files to be licensed under the GNU General Public
2624 License without this special exception.
2626 This special exception was added by the Free Software Foundation in
2627 version 2.2 of Bison. */
2630 b4_shared_declarations
2632 extern YYSTYPE b4_prefix
[]lval
;
2634 b4_location_if([b4_pure_if([],
2635 [extern YYLTYPE b4_prefix
[]lloc
;])