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
])
23 b4_check_percent_code_qualifiers([[requires]], [[provides]], [[top]])
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 m4_ifdef([b4_percent_code_top
],
158 [[/* Copy the %code "top" blocks. */
159 ]b4_user_code([b4_percent_code_top
])])[]dnl
160 m4_if(b4_prefix
, [yy
], [],
161 [/* Substitute the variable and function names. */
162 #define yyparse b4_prefix[]parse
163 #define yylex b4_prefix[]lex
164 #define yyerror b4_prefix[]error
165 #define yylval b4_prefix[]lval
166 #define yychar b4_prefix[]char
167 #define yydebug b4_prefix[]debug
168 #define yynerrs b4_prefix[]nerrs
169 #define yylloc b4_prefix[]lloc])[
171 /* Copy the first part of user declarations. */
172 ]b4_user_pre_prologue
174 dnl
# b4_shared_declarations
175 dnl
# ----------------------
176 dnl
# Declaration that might either go into the header (if --defines)
177 dnl
# or open coded in the parser body.
178 m4_define([b4_shared_declarations
],
179 [m4_ifdef([b4_percent_code_requires
],
180 [[/* Copy the %code "requires" blocks. */
181 ]b4_user_code([b4_percent_code_requires
])])[]dnl
183 b4_token_enums(b4_tokens
)
186 ]m4_ifdef([b4_stype
],
187 [[typedef union ]b4_union_name
[
190 # define YYSTYPE_IS_TRIVIAL 1]],
191 [m4_if(b4_tag_seen_flag
, 0,
192 [[typedef int YYSTYPE
;
193 # define YYSTYPE_IS_TRIVIAL 1]])])[
196 #if ! defined YYLTYPE && ! defined YYLTYPE_IS_DECLARED
197 typedef struct YYLTYPE
208 # define YYLTYPE_IS_DECLARED 1
209 # define YYLTYPE_IS_TRIVIAL 1
212 ]m4_ifdef([b4_percent_code_provides
],
213 [[/* Copy the %code "provides" blocks. */
214 ]b4_user_code([b4_percent_code_provides
])])[]dnl
217 b4_defines_if([[#include "@basename(]b4_spec_defines_file[@)"]],
218 [b4_shared_declarations
])[
220 /* Enabling traces. */
222 # define YYDEBUG ]b4_debug_flag[
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_flag[
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. */
246 ]b4_user_post_prologue
247 m4_ifdef([b4_percent_code
],
248 [[/* Copy the unqualified %code blocks. */
249 ]b4_user_code([b4_percent_code
])
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_locations_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 ((unsigned int) (YYX) <= YYMAXUTOK ? yytranslate[YYX] : YYUNDEFTOK)
361 /* YYTRANSLATE[YYLEX] -- Bison symbol number corresponding to YYLEX. */
362 static const ]b4_int_type_for([b4_translate
])[ yytranslate
[] =
368 /* YYPRHS[YYN] -- Index of the first RHS symbol of rule number YYN in
370 static const ]b4_int_type_for([b4_prhs
])[ yyprhs
[] =
375 /* YYRHS -- A `-1'-separated list of the rules' RHS. */
376 static const ]b4_int_type_for([b4_rhs
])[ yyrhs
[] =
381 /* YYRLINE[YYN] -- source line where rule number YYN was defined. */
382 static const ]b4_int_type_for([b4_rline
])[ yyrline
[] =
388 #if YYDEBUG || YYERROR_VERBOSE || YYTOKEN_TABLE
389 /* YYTNAME[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM.
390 First, the terminals, then, starting at YYNTOKENS, nonterminals. */
391 static const char *const yytname
[] =
397 /* YYR1[YYN] -- Symbol number of symbol that rule YYN derives. */
398 static const ]b4_int_type_for([b4_r1
])[ yyr1
[] =
403 /* YYR2[YYN] -- Number of symbols composing right hand side of rule YYN. */
404 static const ]b4_int_type_for([b4_r2
])[ yyr2
[] =
409 /* YYDPREC[RULE-NUM] -- Dynamic precedence of rule #RULE-NUM (0 if none). */
410 static const ]b4_int_type_for([b4_dprec
])[ yydprec
[] =
415 /* YYMERGER[RULE-NUM] -- Index of merging function for rule #RULE-NUM. */
416 static const ]b4_int_type_for([b4_merger
])[ yymerger
[] =
421 /* YYDEFACT[S] -- default rule to reduce with in state S when YYTABLE
422 doesn't specify something else to do. Zero means the default is an
424 static const ]b4_int_type_for([b4_defact
])[ yydefact
[] =
429 /* YYPDEFGOTO[NTERM-NUM]. */
430 static const ]b4_int_type_for([b4_defgoto
])[ yydefgoto
[] =
435 /* YYPACT[STATE-NUM] -- Index in YYTABLE of the portion describing
437 #define YYPACT_NINF ]b4_pact_ninf[
438 static const ]b4_int_type_for([b4_pact
])[ yypact
[] =
443 /* YYPGOTO[NTERM-NUM]. */
444 static const ]b4_int_type_for([b4_pgoto
])[ yypgoto
[] =
449 /* YYTABLE[YYPACT[STATE-NUM]]. What to do in state STATE-NUM. If
450 positive, shift that token. If negative, reduce the rule which
451 number is the opposite. If zero, do what YYDEFACT says.
452 If YYTABLE_NINF, syntax error. */
453 #define YYTABLE_NINF ]b4_table_ninf[
454 static const ]b4_int_type_for([b4_table
])[ yytable
[] =
459 /* YYCONFLP[YYPACT[STATE-NUM]] -- Pointer into YYCONFL of start of
460 list of conflicting reductions corresponding to action entry for
461 state STATE-NUM in yytable. 0 means no conflicts. The list in
462 yyconfl is terminated by a rule number of 0. */
463 static const ]b4_int_type_for([b4_conflict_list_heads
])[ yyconflp
[] =
465 ]b4_conflict_list_heads
[
468 /* YYCONFL[I] -- lists of conflicting rule numbers, each terminated by
469 0, pointed into by YYCONFLP. */
470 ]dnl Do
not use b4_int_type_for here
, since there are places where
471 dnl pointers onto yyconfl are taken
, which type is
"short int *".
472 dnl We probably ought to introduce a type
for confl
.
473 [static const short int yyconfl
[] =
475 ]b4_conflicting_rules
[
478 static const ]b4_int_type_for([b4_check
])[ yycheck
[] =
483 /* YYSTOS[STATE-NUM] -- The (internal number of the) accessing
484 symbol of state STATE-NUM. */
485 static const ]b4_int_type_for([b4_stos
])[ yystos
[] =
491 /* Prevent warning if -Wmissing-prototypes. */
492 ]b4_c_ansi_function_decl([yyparse
], [int], b4_parse_param
)[
494 /* Error token number */
497 /* YYLLOC_DEFAULT -- Set CURRENT to span from RHS[1] to RHS[N].
498 If N is 0, then set CURRENT to the empty location which ends
499 the previous symbol: RHS[0] (always defined). */
502 #define YYRHSLOC(Rhs, K) ((Rhs)[K].yystate.yyloc)
503 #ifndef YYLLOC_DEFAULT
504 # define YYLLOC_DEFAULT(Current, Rhs, N) \
508 (Current).first_line = YYRHSLOC (Rhs, 1).first_line; \
509 (Current).first_column = YYRHSLOC (Rhs, 1).first_column; \
510 (Current).last_line = YYRHSLOC (Rhs, N).last_line; \
511 (Current).last_column = YYRHSLOC (Rhs, N).last_column; \
515 (Current).first_line = (Current).last_line = \
516 YYRHSLOC (Rhs, 0).last_line; \
517 (Current).first_column = (Current).last_column = \
518 YYRHSLOC (Rhs, 0).last_column; \
522 /* YY_LOCATION_PRINT -- Print the location on the stream.
523 This macro was not mandated originally: define only if we know
524 we won't break user code: when these are the locations we know. */
526 # define YY_LOCATION_PRINT(File, Loc) \
527 fprintf (File, "%d.%d-%d.%d", \
528 (Loc).first_line, (Loc).first_column, \
529 (Loc).last_line, (Loc).last_column)
532 #ifndef YYLLOC_DEFAULT
533 # define YYLLOC_DEFAULT(Current, Rhs, N) ((void) 0)
537 #ifndef YY_LOCATION_PRINT
538 # define YY_LOCATION_PRINT(File, Loc) ((void) 0)
542 /* YYLEX -- calling `yylex' with the right arguments. */
543 #define YYLEX ]b4_c_function_call([yylex], [int], b4_lex_param)[
548 #define yynerrs (yystackp->yyerrcnt)
550 #define yychar (yystackp->yyrawchar)
552 #define yylval (yystackp->yyval)
554 #define yylloc (yystackp->yyloc)
555 m4_if(b4_prefix
[], [yy
], [],
556 [#define b4_prefix[]nerrs yynerrs
557 #define b4_prefix[]char yychar
558 #define b4_prefix[]lval yylval
559 #define b4_prefix[]lloc yylloc])],
567 static const int YYEOF
= 0;
568 static const int YYEMPTY
= -2;
570 typedef enum { yyok
, yyaccept
, yyabort
, yyerr
} YYRESULTTAG
;
573 do { YYRESULTTAG yyflag = YYE; if (yyflag != yyok) return yyflag; } \
579 # define YYFPRINTF fprintf
582 # define YYDPRINTF(Args) \
588 ]b4_yy_symbol_print_generate([b4_c_ansi_function_def
])[
590 # define YY_SYMBOL_PRINT(Title, Type, Value, Location) \
594 YYFPRINTF (stderr, "%s ", Title); \
595 yy_symbol_print (stderr, Type, \
596 Value]b4_locations_if([, Location])[]b4_user_args[); \
597 YYFPRINTF (stderr, "\n"); \
601 /* Nonzero means print parse trace. It is left uninitialized so that
602 multiple parsers can coexist. */
607 # define YYDPRINTF(Args)
608 # define YY_SYMBOL_PRINT(Title, Type, Value, Location)
610 #endif /* !YYDEBUG */
612 /* YYINITDEPTH -- initial size of the parser's stacks. */
614 # define YYINITDEPTH ]b4_stack_depth_init[
617 /* YYMAXDEPTH -- maximum size the stacks can grow to (effective only
618 if the built-in stack extension method is used).
620 Do not make this value too large; the results are undefined if
621 SIZE_MAX < YYMAXDEPTH * sizeof (GLRStackItem)
622 evaluated with infinite-precision integer arithmetic. */
625 # define YYMAXDEPTH ]b4_stack_depth_max[
628 /* Minimum number of free items on the stack allowed after an
629 allocation. This is to allow allocation and initialization
630 to be completed by functions that call yyexpandGLRStack before the
631 stack is expanded, thus insuring that all necessary pointers get
632 properly redirected to new data. */
635 #ifndef YYSTACKEXPANDABLE
636 # if (! defined __cplusplus \
637 || (]b4_locations_if([[defined YYLTYPE_IS_TRIVIAL && YYLTYPE_IS_TRIVIAL \
638 && ]])[defined YYSTYPE_IS_TRIVIAL && YYSTYPE_IS_TRIVIAL))
639 # define YYSTACKEXPANDABLE 1
641 # define YYSTACKEXPANDABLE 0
645 #if YYSTACKEXPANDABLE
646 # define YY_RESERVE_GLRSTACK(Yystack) \
648 if (Yystack->yyspaceLeft < YYHEADROOM) \
649 yyexpandGLRStack (Yystack); \
652 # define YY_RESERVE_GLRSTACK(Yystack) \
654 if (Yystack->yyspaceLeft < YYHEADROOM) \
655 yyMemoryExhausted (Yystack); \
663 # if defined __GLIBC__ && defined _STRING_H && defined _GNU_SOURCE
664 # define yystpcpy stpcpy
666 /* Copy YYSRC to YYDEST, returning the address of the terminating '\0' in
669 yystpcpy (char *yydest
, const char *yysrc
)
672 const char *yys
= yysrc
;
674 while ((*yyd
++ = *yys
++) != '\0')
683 /* Copy to YYRES the contents of YYSTR after stripping away unnecessary
684 quotes and backslashes, so that it's suitable for yyerror. The
685 heuristic is that double-quoting is unnecessary unless the string
686 contains an apostrophe, a comma, or backslash (other than
687 backslash-backslash). YYSTR is taken from yytname. If YYRES is
688 null, do not copy; instead, return the length of what the result
691 yytnamerr (char *yyres
, const char *yystr
)
696 char const *yyp
= yystr
;
703 goto do_not_strip_quotes
;
707 goto do_not_strip_quotes
;
720 do_not_strip_quotes
: ;
724 return strlen (yystr
);
726 return yystpcpy (yyres
, yystr
) - yyres
;
730 #endif /* !YYERROR_VERBOSE */
732 /** State numbers, as in LALR(1) machine */
733 typedef int yyStateNum
;
735 /** Rule numbers, as in LALR(1) machine */
736 typedef int yyRuleNum
;
738 /** Grammar symbol */
739 typedef short int yySymbol
;
741 /** Item references, as in LALR(1) machine */
742 typedef short int yyItemNum
;
744 typedef struct yyGLRState yyGLRState
;
745 typedef struct yyGLRStateSet yyGLRStateSet
;
746 typedef struct yySemanticOption yySemanticOption
;
747 typedef union yyGLRStackItem yyGLRStackItem
;
748 typedef struct yyGLRStack yyGLRStack
;
751 /** Type tag: always true. */
753 /** Type tag for yysemantics. If true, yysval applies, otherwise
754 * yyfirstVal applies. */
756 /** Number of corresponding LALR(1) machine state. */
757 yyStateNum yylrState
;
758 /** Preceding state in this stack */
760 /** Source position of the first token produced by my symbol */
763 /** First in a chain of alternative reductions producing the
764 * non-terminal corresponding to this state, threaded through
766 yySemanticOption
* yyfirstVal
;
767 /** Semantic value for this state. */
770 /** Source location for this state. */
774 struct yyGLRStateSet
{
775 yyGLRState
** yystates
;
776 /** During nondeterministic operation, yylookaheadNeeds tracks which
777 * stacks have actually needed the current lookahead. During deterministic
778 * operation, yylookaheadNeeds[0] is not maintained since it would merely
779 * duplicate yychar != YYEMPTY. */
780 yybool
* yylookaheadNeeds
;
781 size_t yysize
, yycapacity
;
784 struct yySemanticOption
{
785 /** Type tag: always false. */
787 /** Rule number for this reduction */
789 /** The last RHS state in the list of states to be reduced. */
791 /** The lookahead for this reduction. */
795 /** Next sibling in chain of options. To facilitate merging,
796 * options are chained in decreasing order by address. */
797 yySemanticOption
* yynext
;
800 /** Type of the items in the GLR stack. The yyisState field
801 * indicates which item of the union is valid. */
802 union yyGLRStackItem
{
804 yySemanticOption yyoption
;
809 ]b4_locations_if([[ /* To compute the location of the error token. */
810 yyGLRStackItem yyerror_range
[3];]])[
818 YYJMP_BUF yyexception_buffer
;
819 yyGLRStackItem
* yyitems
;
820 yyGLRStackItem
* yynextFree
;
822 yyGLRState
* yysplitPoint
;
823 yyGLRState
* yylastDeleted
;
824 yyGLRStateSet yytops
;
827 #if YYSTACKEXPANDABLE
828 static void yyexpandGLRStack (yyGLRStack
* yystackp
);
831 static void yyFail (yyGLRStack
* yystackp
]b4_pure_formals
[, const char* yymsg
)
832 __attribute__ ((__noreturn__
));
834 yyFail (yyGLRStack
* yystackp
]b4_pure_formals
[, const char* yymsg
)
837 yyerror (]b4_yyerror_args
[yymsg
);
838 YYLONGJMP (yystackp
->yyexception_buffer
, 1);
841 static void yyMemoryExhausted (yyGLRStack
* yystackp
)
842 __attribute__ ((__noreturn__
));
844 yyMemoryExhausted (yyGLRStack
* yystackp
)
846 YYLONGJMP (yystackp
->yyexception_buffer
, 2);
849 #if YYDEBUG || YYERROR_VERBOSE
850 /** A printable representation of TOKEN. */
851 static inline const char*
852 yytokenName (yySymbol yytoken
)
854 if (yytoken
== YYEMPTY
)
857 return yytname
[yytoken
];
861 /** Fill in YYVSP[YYLOW1 .. YYLOW0-1] from the chain of states starting
862 * at YYVSP[YYLOW0].yystate.yypred. Leaves YYVSP[YYLOW1].yystate.yypred
863 * containing the pointer to the next state in the chain. */
864 static void yyfillin (yyGLRStackItem
*, int, int) __attribute__ ((__unused__
));
866 yyfillin (yyGLRStackItem
*yyvsp
, int yylow0
, int yylow1
)
870 s
= yyvsp
[yylow0
].yystate
.yypred
;
871 for (i
= yylow0
-1; i
>= yylow1
; i
-= 1)
873 YYASSERT (s
->yyresolved
);
874 yyvsp
[i
].yystate
.yyresolved
= yytrue
;
875 yyvsp
[i
].yystate
.yysemantics
.yysval
= s
->yysemantics
.yysval
;
876 yyvsp
[i
].yystate
.yyloc
= s
->yyloc
;
877 s
= yyvsp
[i
].yystate
.yypred
= s
->yypred
;
881 /* Do nothing if YYNORMAL or if *YYLOW <= YYLOW1. Otherwise, fill in
882 * YYVSP[YYLOW1 .. *YYLOW-1] as in yyfillin and set *YYLOW = YYLOW1.
883 * For convenience, always return YYLOW1. */
884 static inline int yyfill (yyGLRStackItem
*, int *, int, yybool
)
885 __attribute__ ((__unused__
));
887 yyfill (yyGLRStackItem
*yyvsp
, int *yylow
, int yylow1
, yybool yynormal
)
889 if (!yynormal
&& yylow1
< *yylow
)
891 yyfillin (yyvsp
, *yylow
, yylow1
);
897 /** Perform user action for rule number YYN, with RHS length YYRHSLEN,
898 * and top stack item YYVSP. YYLVALP points to place to put semantic
899 * value ($$), and yylocp points to place for location information
900 * (@@$). Returns yyok for normal return, yyaccept for YYACCEPT,
901 * yyerr for YYERROR, yyabort for YYABORT. */
902 /*ARGSUSED*/ static YYRESULTTAG
903 yyuserAction (yyRuleNum yyn
, int yyrhslen
, yyGLRStackItem
* yyvsp
,
905 YYLTYPE
* YYOPTIONAL_LOC (yylocp
),
909 yybool yynormal
__attribute__ ((__unused__
)) =
910 (yystackp
->yysplitPoint
== NULL
);
912 ]b4_parse_param_use
[]dnl
914 # define yyerrok (yystackp->yyerrState = 0)
916 # define YYACCEPT return yyaccept
918 # define YYABORT return yyabort
920 # define YYERROR return yyerrok, yyerr
922 # define YYRECOVERING() (yystackp->yyerrState != 0)
924 # define yyclearin (yychar = YYEMPTY)
926 # define YYFILL(N) yyfill (yyvsp, &yylow, N, yynormal)
928 # define YYBACKUP(Token, Value) \
929 return yyerror (]b4_yyerror_args[YY_("syntax error: cannot back up")), \
934 *yyvalp
= yyval_default
;
936 *yyvalp
= yyvsp
[YYFILL (1-yyrhslen
)].yystate
.yysemantics
.yysval
;
937 YYLLOC_DEFAULT ((*yylocp
), (yyvsp
- yyrhslen
), yyrhslen
);
938 ]b4_locations_if([[ yystackp
->yyerror_range
[1].yystate
.yyloc
= *yylocp
;
957 /*ARGSUSED*/ static void
958 yyuserMerge (int yyn
, YYSTYPE
* yy0
, YYSTYPE
* yy1
)
970 /* Bison grammar-table manipulation. */
972 ]b4_yydestruct_generate([b4_c_ansi_function_def
])[
974 /** Number of symbols composing the right hand side of rule #RULE. */
976 yyrhsLength (yyRuleNum yyrule
)
982 yydestroyGLRState (char const *yymsg
, yyGLRState
*yys
]b4_user_formals
[)
985 yydestruct (yymsg
, yystos
[yys
->yylrState
],
986 &yys
->yysemantics
.yysval
]b4_locations_if([, &yys
->yyloc
])[]b4_user_args
[);
992 if (yys
->yysemantics
.yyfirstVal
)
993 YYFPRINTF (stderr
, "%s unresolved ", yymsg
);
995 YYFPRINTF (stderr
, "%s incomplete ", yymsg
);
996 yy_symbol_print (stderr
, yystos
[yys
->yylrState
],
997 NULL
]b4_locations_if([, &yys
->yyloc
])[]b4_user_args
[);
998 YYFPRINTF (stderr
, "\n");
1002 if (yys
->yysemantics
.yyfirstVal
)
1004 yySemanticOption
*yyoption
= yys
->yysemantics
.yyfirstVal
;
1007 for (yyrh
= yyoption
->yystate
, yyn
= yyrhsLength (yyoption
->yyrule
);
1009 yyrh
= yyrh
->yypred
, yyn
-= 1)
1010 yydestroyGLRState (yymsg
, yyrh
]b4_user_args
[);
1015 /** Left-hand-side symbol for rule #RULE. */
1016 static inline yySymbol
1017 yylhsNonterm (yyRuleNum yyrule
)
1019 return yyr1
[yyrule
];
1022 #define yyis_pact_ninf(yystate) \
1023 ]m4_if(m4_eval(b4_pact_ninf < b4_pact_min), [1],
1025 [((yystate
) == YYPACT_NINF
)])[
1027 /** True iff LR state STATE has only a default reduction (regardless
1029 static inline yybool
1030 yyisDefaultedState (yyStateNum yystate
)
1032 return yyis_pact_ninf (yypact
[yystate
]);
1035 /** The default reduction for STATE, assuming it has one. */
1036 static inline yyRuleNum
1037 yydefaultAction (yyStateNum yystate
)
1039 return yydefact
[yystate
];
1042 #define yyis_table_ninf(yytable_value) \
1043 ]m4_if(m4_eval(b4_table_ninf < b4_table_min), [1],
1045 [((yytable_value
) == YYTABLE_NINF
)])[
1047 /** Set *YYACTION to the action to take in YYSTATE on seeing YYTOKEN.
1049 * R < 0: Reduce on rule -R.
1051 * R > 0: Shift to state R.
1052 * Set *CONFLICTS to a pointer into yyconfl to 0-terminated list of
1053 * conflicting reductions.
1056 yygetLRActions (yyStateNum yystate
, int yytoken
,
1057 int* yyaction
, const short int** yyconflicts
)
1059 int yyindex
= yypact
[yystate
] + yytoken
;
1060 if (yyindex
< 0 || YYLAST
< yyindex
|| yycheck
[yyindex
] != yytoken
)
1062 *yyaction
= -yydefact
[yystate
];
1063 *yyconflicts
= yyconfl
;
1065 else if (! yyis_table_ninf (yytable
[yyindex
]))
1067 *yyaction
= yytable
[yyindex
];
1068 *yyconflicts
= yyconfl
+ yyconflp
[yyindex
];
1073 *yyconflicts
= yyconfl
+ yyconflp
[yyindex
];
1077 static inline yyStateNum
1078 yyLRgotoState (yyStateNum yystate
, yySymbol yylhs
)
1081 yyr
= yypgoto
[yylhs
- YYNTOKENS
] + yystate
;
1082 if (0 <= yyr
&& yyr
<= YYLAST
&& yycheck
[yyr
] == yystate
)
1083 return yytable
[yyr
];
1085 return yydefgoto
[yylhs
- YYNTOKENS
];
1088 static inline yybool
1089 yyisShiftAction (int yyaction
)
1091 return 0 < yyaction
;
1094 static inline yybool
1095 yyisErrorAction (int yyaction
)
1097 return yyaction
== 0;
1102 /** Return a fresh GLRStackItem. Callers should call
1103 * YY_RESERVE_GLRSTACK afterwards to make sure there is sufficient
1106 static inline yyGLRStackItem
*
1107 yynewGLRStackItem (yyGLRStack
* yystackp
, yybool yyisState
)
1109 yyGLRStackItem
* yynewItem
= yystackp
->yynextFree
;
1110 yystackp
->yyspaceLeft
-= 1;
1111 yystackp
->yynextFree
+= 1;
1112 yynewItem
->yystate
.yyisState
= yyisState
;
1116 /** Add a new semantic action that will execute the action for rule
1117 * RULENUM on the semantic values in RHS to the list of
1118 * alternative actions for STATE. Assumes that RHS comes from
1119 * stack #K of *STACKP. */
1121 yyaddDeferredAction (yyGLRStack
* yystackp
, size_t yyk
, yyGLRState
* yystate
,
1122 yyGLRState
* rhs
, yyRuleNum yyrule
)
1124 yySemanticOption
* yynewOption
=
1125 &yynewGLRStackItem (yystackp
, yyfalse
)->yyoption
;
1126 yynewOption
->yystate
= rhs
;
1127 yynewOption
->yyrule
= yyrule
;
1128 if (yystackp
->yytops
.yylookaheadNeeds
[yyk
])
1130 yynewOption
->yyrawchar
= yychar
;
1131 yynewOption
->yyval
= yylval
;
1132 yynewOption
->yyloc
= yylloc
;
1135 yynewOption
->yyrawchar
= YYEMPTY
;
1136 yynewOption
->yynext
= yystate
->yysemantics
.yyfirstVal
;
1137 yystate
->yysemantics
.yyfirstVal
= yynewOption
;
1139 YY_RESERVE_GLRSTACK (yystackp
);
1144 /** Initialize SET to a singleton set containing an empty stack. */
1146 yyinitStateSet (yyGLRStateSet
* yyset
)
1149 yyset
->yycapacity
= 16;
1150 yyset
->yystates
= (yyGLRState
**) YYMALLOC (16 * sizeof yyset
->yystates
[0]);
1151 if (! yyset
->yystates
)
1153 yyset
->yystates
[0] = NULL
;
1154 yyset
->yylookaheadNeeds
=
1155 (yybool
*) YYMALLOC (16 * sizeof yyset
->yylookaheadNeeds
[0]);
1156 if (! yyset
->yylookaheadNeeds
)
1158 YYFREE (yyset
->yystates
);
1164 static void yyfreeStateSet (yyGLRStateSet
* yyset
)
1166 YYFREE (yyset
->yystates
);
1167 YYFREE (yyset
->yylookaheadNeeds
);
1170 /** Initialize STACK to a single empty stack, with total maximum
1171 * capacity for all stacks of SIZE. */
1173 yyinitGLRStack (yyGLRStack
* yystackp
, size_t yysize
)
1175 yystackp
->yyerrState
= 0;
1177 yystackp
->yyspaceLeft
= yysize
;
1179 (yyGLRStackItem
*) YYMALLOC (yysize
* sizeof yystackp
->yynextFree
[0]);
1180 if (!yystackp
->yyitems
)
1182 yystackp
->yynextFree
= yystackp
->yyitems
;
1183 yystackp
->yysplitPoint
= NULL
;
1184 yystackp
->yylastDeleted
= NULL
;
1185 return yyinitStateSet (&yystackp
->yytops
);
1189 #if YYSTACKEXPANDABLE
1190 # define YYRELOC(YYFROMITEMS,YYTOITEMS,YYX,YYTYPE) \
1191 &((YYTOITEMS) - ((YYFROMITEMS) - (yyGLRStackItem*) (YYX)))->YYTYPE
1193 /** If STACK is expandable, extend it. WARNING: Pointers into the
1194 stack from outside should be considered invalid after this call.
1195 We always expand when there are 1 or fewer items left AFTER an
1196 allocation, so that we can avoid having external pointers exist
1197 across an allocation. */
1199 yyexpandGLRStack (yyGLRStack
* yystackp
)
1201 yyGLRStackItem
* yynewItems
;
1202 yyGLRStackItem
* yyp0
, *yyp1
;
1203 size_t yysize
, yynewSize
;
1205 yysize
= yystackp
->yynextFree
- yystackp
->yyitems
;
1206 if (YYMAXDEPTH
- YYHEADROOM
< yysize
)
1207 yyMemoryExhausted (yystackp
);
1208 yynewSize
= 2*yysize
;
1209 if (YYMAXDEPTH
< yynewSize
)
1210 yynewSize
= YYMAXDEPTH
;
1211 yynewItems
= (yyGLRStackItem
*) YYMALLOC (yynewSize
* sizeof yynewItems
[0]);
1213 yyMemoryExhausted (yystackp
);
1214 for (yyp0
= yystackp
->yyitems
, yyp1
= yynewItems
, yyn
= yysize
;
1216 yyn
-= 1, yyp0
+= 1, yyp1
+= 1)
1219 if (*(yybool
*) yyp0
)
1221 yyGLRState
* yys0
= &yyp0
->yystate
;
1222 yyGLRState
* yys1
= &yyp1
->yystate
;
1223 if (yys0
->yypred
!= NULL
)
1225 YYRELOC (yyp0
, yyp1
, yys0
->yypred
, yystate
);
1226 if (! yys0
->yyresolved
&& yys0
->yysemantics
.yyfirstVal
!= NULL
)
1227 yys1
->yysemantics
.yyfirstVal
=
1228 YYRELOC(yyp0
, yyp1
, yys0
->yysemantics
.yyfirstVal
, yyoption
);
1232 yySemanticOption
* yyv0
= &yyp0
->yyoption
;
1233 yySemanticOption
* yyv1
= &yyp1
->yyoption
;
1234 if (yyv0
->yystate
!= NULL
)
1235 yyv1
->yystate
= YYRELOC (yyp0
, yyp1
, yyv0
->yystate
, yystate
);
1236 if (yyv0
->yynext
!= NULL
)
1237 yyv1
->yynext
= YYRELOC (yyp0
, yyp1
, yyv0
->yynext
, yyoption
);
1240 if (yystackp
->yysplitPoint
!= NULL
)
1241 yystackp
->yysplitPoint
= YYRELOC (yystackp
->yyitems
, yynewItems
,
1242 yystackp
->yysplitPoint
, yystate
);
1244 for (yyn
= 0; yyn
< yystackp
->yytops
.yysize
; yyn
+= 1)
1245 if (yystackp
->yytops
.yystates
[yyn
] != NULL
)
1246 yystackp
->yytops
.yystates
[yyn
] =
1247 YYRELOC (yystackp
->yyitems
, yynewItems
,
1248 yystackp
->yytops
.yystates
[yyn
], yystate
);
1249 YYFREE (yystackp
->yyitems
);
1250 yystackp
->yyitems
= yynewItems
;
1251 yystackp
->yynextFree
= yynewItems
+ yysize
;
1252 yystackp
->yyspaceLeft
= yynewSize
- yysize
;
1257 yyfreeGLRStack (yyGLRStack
* yystackp
)
1259 YYFREE (yystackp
->yyitems
);
1260 yyfreeStateSet (&yystackp
->yytops
);
1263 /** Assuming that S is a GLRState somewhere on STACK, update the
1264 * splitpoint of STACK, if needed, so that it is at least as deep as
1267 yyupdateSplit (yyGLRStack
* yystackp
, yyGLRState
* yys
)
1269 if (yystackp
->yysplitPoint
!= NULL
&& yystackp
->yysplitPoint
> yys
)
1270 yystackp
->yysplitPoint
= yys
;
1273 /** Invalidate stack #K in STACK. */
1275 yymarkStackDeleted (yyGLRStack
* yystackp
, size_t yyk
)
1277 if (yystackp
->yytops
.yystates
[yyk
] != NULL
)
1278 yystackp
->yylastDeleted
= yystackp
->yytops
.yystates
[yyk
];
1279 yystackp
->yytops
.yystates
[yyk
] = NULL
;
1282 /** Undelete the last stack that was marked as deleted. Can only be
1283 done once after a deletion, and only when all other stacks have
1286 yyundeleteLastStack (yyGLRStack
* yystackp
)
1288 if (yystackp
->yylastDeleted
== NULL
|| yystackp
->yytops
.yysize
!= 0)
1290 yystackp
->yytops
.yystates
[0] = yystackp
->yylastDeleted
;
1291 yystackp
->yytops
.yysize
= 1;
1292 YYDPRINTF ((stderr
, "Restoring last deleted stack as stack #0.\n"));
1293 yystackp
->yylastDeleted
= NULL
;
1297 yyremoveDeletes (yyGLRStack
* yystackp
)
1301 while (yyj
< yystackp
->yytops
.yysize
)
1303 if (yystackp
->yytops
.yystates
[yyi
] == NULL
)
1307 YYDPRINTF ((stderr
, "Removing dead stacks.\n"));
1309 yystackp
->yytops
.yysize
-= 1;
1313 yystackp
->yytops
.yystates
[yyj
] = yystackp
->yytops
.yystates
[yyi
];
1314 /* In the current implementation, it's unnecessary to copy
1315 yystackp->yytops.yylookaheadNeeds[yyi] since, after
1316 yyremoveDeletes returns, the parser immediately either enters
1317 deterministic operation or shifts a token. However, it doesn't
1318 hurt, and the code might evolve to need it. */
1319 yystackp
->yytops
.yylookaheadNeeds
[yyj
] =
1320 yystackp
->yytops
.yylookaheadNeeds
[yyi
];
1323 YYDPRINTF ((stderr
, "Rename stack %lu -> %lu.\n",
1324 (unsigned long int) yyi
, (unsigned long int) yyj
));
1332 /** Shift to a new state on stack #K of STACK, corresponding to LR state
1333 * LRSTATE, at input position POSN, with (resolved) semantic value SVAL. */
1335 yyglrShift (yyGLRStack
* yystackp
, size_t yyk
, yyStateNum yylrState
,
1337 YYSTYPE
* yyvalp
, YYLTYPE
* yylocp
)
1339 yyGLRState
* yynewState
= &yynewGLRStackItem (yystackp
, yytrue
)->yystate
;
1341 yynewState
->yylrState
= yylrState
;
1342 yynewState
->yyposn
= yyposn
;
1343 yynewState
->yyresolved
= yytrue
;
1344 yynewState
->yypred
= yystackp
->yytops
.yystates
[yyk
];
1345 yynewState
->yysemantics
.yysval
= *yyvalp
;
1346 yynewState
->yyloc
= *yylocp
;
1347 yystackp
->yytops
.yystates
[yyk
] = yynewState
;
1349 YY_RESERVE_GLRSTACK (yystackp
);
1352 /** Shift stack #K of YYSTACK, to a new state corresponding to LR
1353 * state YYLRSTATE, at input position YYPOSN, with the (unresolved)
1354 * semantic value of YYRHS under the action for YYRULE. */
1356 yyglrShiftDefer (yyGLRStack
* yystackp
, size_t yyk
, yyStateNum yylrState
,
1357 size_t yyposn
, yyGLRState
* rhs
, yyRuleNum yyrule
)
1359 yyGLRState
* yynewState
= &yynewGLRStackItem (yystackp
, yytrue
)->yystate
;
1361 yynewState
->yylrState
= yylrState
;
1362 yynewState
->yyposn
= yyposn
;
1363 yynewState
->yyresolved
= yyfalse
;
1364 yynewState
->yypred
= yystackp
->yytops
.yystates
[yyk
];
1365 yynewState
->yysemantics
.yyfirstVal
= NULL
;
1366 yystackp
->yytops
.yystates
[yyk
] = yynewState
;
1368 /* Invokes YY_RESERVE_GLRSTACK. */
1369 yyaddDeferredAction (yystackp
, yyk
, yynewState
, rhs
, yyrule
);
1372 /** Pop the symbols consumed by reduction #RULE from the top of stack
1373 * #K of STACK, and perform the appropriate semantic action on their
1374 * semantic values. Assumes that all ambiguities in semantic values
1375 * have been previously resolved. Set *VALP to the resulting value,
1376 * and *LOCP to the computed location (if any). Return value is as
1377 * for userAction. */
1378 static inline YYRESULTTAG
1379 yydoAction (yyGLRStack
* yystackp
, size_t yyk
, yyRuleNum yyrule
,
1380 YYSTYPE
* yyvalp
, YYLTYPE
* yylocp
]b4_user_formals
[)
1382 int yynrhs
= yyrhsLength (yyrule
);
1384 if (yystackp
->yysplitPoint
== NULL
)
1386 /* Standard special case: single stack. */
1387 yyGLRStackItem
* rhs
= (yyGLRStackItem
*) yystackp
->yytops
.yystates
[yyk
];
1388 YYASSERT (yyk
== 0);
1389 yystackp
->yynextFree
-= yynrhs
;
1390 yystackp
->yyspaceLeft
+= yynrhs
;
1391 yystackp
->yytops
.yystates
[0] = & yystackp
->yynextFree
[-1].yystate
;
1392 return yyuserAction (yyrule
, yynrhs
, rhs
,
1393 yyvalp
, yylocp
, yystackp
]b4_user_args
[);
1397 /* At present, doAction is never called in nondeterministic
1398 * mode, so this branch is never taken. It is here in
1399 * anticipation of a future feature that will allow immediate
1400 * evaluation of selected actions in nondeterministic mode. */
1403 yyGLRStackItem yyrhsVals
[YYMAXRHS
+ YYMAXLEFT
+ 1];
1404 yys
= yyrhsVals
[YYMAXRHS
+ YYMAXLEFT
].yystate
.yypred
1405 = yystackp
->yytops
.yystates
[yyk
];]b4_locations_if([[
1407 /* Set default location. */
1408 yyrhsVals
[YYMAXRHS
+ YYMAXLEFT
- 1].yystate
.yyloc
= yys
->yyloc
;]])[
1409 for (yyi
= 0; yyi
< yynrhs
; yyi
+= 1)
1414 yyupdateSplit (yystackp
, yys
);
1415 yystackp
->yytops
.yystates
[yyk
] = yys
;
1416 return yyuserAction (yyrule
, yynrhs
, yyrhsVals
+ YYMAXRHS
+ YYMAXLEFT
- 1,
1417 yyvalp
, yylocp
, yystackp
]b4_user_args
[);
1422 # define YY_REDUCE_PRINT(Args)
1424 # define YY_REDUCE_PRINT(Args) \
1427 yy_reduce_print Args; \
1430 /*----------------------------------------------------------.
1431 | Report that the RULE is going to be reduced on stack #K. |
1432 `----------------------------------------------------------*/
1434 /*ARGSUSED*/ static inline void
1435 yy_reduce_print (yyGLRStack
* yystackp
, size_t yyk
, yyRuleNum yyrule
,
1436 YYSTYPE
* yyvalp
, YYLTYPE
* yylocp
]b4_user_formals
[)
1438 int yynrhs
= yyrhsLength (yyrule
);
1439 yybool yynormal
__attribute__ ((__unused__
)) =
1440 (yystackp
->yysplitPoint
== NULL
);
1441 yyGLRStackItem
* yyvsp
= (yyGLRStackItem
*) yystackp
->yytops
.yystates
[yyk
];
1446 ]b4_parse_param_use
[]dnl
1447 [ YYFPRINTF (stderr
, "Reducing stack %lu by rule %d (line %lu):\n",
1448 (unsigned long int) yyk
, yyrule
- 1,
1449 (unsigned long int) yyrline
[yyrule
]);
1450 /* The symbols being reduced. */
1451 for (yyi
= 0; yyi
< yynrhs
; yyi
++)
1453 fprintf (stderr
, " $%d = ", yyi
+ 1);
1454 yy_symbol_print (stderr
, yyrhs
[yyprhs
[yyrule
] + yyi
],
1455 &]b4_rhs_value(yynrhs
, yyi
+ 1)[
1456 ]b4_locations_if([, &]b4_rhs_location(yynrhs
, yyi
+ 1))[]dnl
1458 fprintf (stderr
, "\n");
1463 /** Pop items off stack #K of STACK according to grammar rule RULE,
1464 * and push back on the resulting nonterminal symbol. Perform the
1465 * semantic action associated with RULE and store its value with the
1466 * newly pushed state, if FORCEEVAL or if STACK is currently
1467 * unambiguous. Otherwise, store the deferred semantic action with
1468 * the new state. If the new state would have an identical input
1469 * position, LR state, and predecessor to an existing state on the stack,
1470 * it is identified with that existing state, eliminating stack #K from
1471 * the STACK. In this case, the (necessarily deferred) semantic value is
1472 * added to the options for the existing state's semantic value.
1474 static inline YYRESULTTAG
1475 yyglrReduce (yyGLRStack
* yystackp
, size_t yyk
, yyRuleNum yyrule
,
1476 yybool yyforceEval
]b4_user_formals
[)
1478 size_t yyposn
= yystackp
->yytops
.yystates
[yyk
]->yyposn
;
1480 if (yyforceEval
|| yystackp
->yysplitPoint
== NULL
)
1485 YY_REDUCE_PRINT ((yystackp
, yyk
, yyrule
, &yysval
, &yyloc
]b4_user_args
[));
1486 YYCHK (yydoAction (yystackp
, yyk
, yyrule
, &yysval
,
1487 &yyloc
]b4_user_args
[));
1488 YY_SYMBOL_PRINT ("-> $$ =", yyr1
[yyrule
], &yysval
, &yyloc
);
1489 yyglrShift (yystackp
, yyk
,
1490 yyLRgotoState (yystackp
->yytops
.yystates
[yyk
]->yylrState
,
1491 yylhsNonterm (yyrule
)),
1492 yyposn
, &yysval
, &yyloc
);
1498 yyGLRState
* yys
, *yys0
= yystackp
->yytops
.yystates
[yyk
];
1499 yyStateNum yynewLRState
;
1501 for (yys
= yystackp
->yytops
.yystates
[yyk
], yyn
= yyrhsLength (yyrule
);
1507 yyupdateSplit (yystackp
, yys
);
1508 yynewLRState
= yyLRgotoState (yys
->yylrState
, yylhsNonterm (yyrule
));
1510 "Reduced stack %lu by rule #%d; action deferred. Now in state %d.\n",
1511 (unsigned long int) yyk
, yyrule
- 1, yynewLRState
));
1512 for (yyi
= 0; yyi
< yystackp
->yytops
.yysize
; yyi
+= 1)
1513 if (yyi
!= yyk
&& yystackp
->yytops
.yystates
[yyi
] != NULL
)
1515 yyGLRState
* yyp
, *yysplit
= yystackp
->yysplitPoint
;
1516 yyp
= yystackp
->yytops
.yystates
[yyi
];
1517 while (yyp
!= yys
&& yyp
!= yysplit
&& yyp
->yyposn
>= yyposn
)
1519 if (yyp
->yylrState
== yynewLRState
&& yyp
->yypred
== yys
)
1521 yyaddDeferredAction (yystackp
, yyk
, yyp
, yys0
, yyrule
);
1522 yymarkStackDeleted (yystackp
, yyk
);
1523 YYDPRINTF ((stderr
, "Merging stack %lu into stack %lu.\n",
1524 (unsigned long int) yyk
,
1525 (unsigned long int) yyi
));
1531 yystackp
->yytops
.yystates
[yyk
] = yys
;
1532 yyglrShiftDefer (yystackp
, yyk
, yynewLRState
, yyposn
, yys0
, yyrule
);
1538 yysplitStack (yyGLRStack
* yystackp
, size_t yyk
)
1540 if (yystackp
->yysplitPoint
== NULL
)
1542 YYASSERT (yyk
== 0);
1543 yystackp
->yysplitPoint
= yystackp
->yytops
.yystates
[yyk
];
1545 if (yystackp
->yytops
.yysize
>= yystackp
->yytops
.yycapacity
)
1547 yyGLRState
** yynewStates
;
1548 yybool
* yynewLookaheadNeeds
;
1552 if (yystackp
->yytops
.yycapacity
1553 > (YYSIZEMAX
/ (2 * sizeof yynewStates
[0])))
1554 yyMemoryExhausted (yystackp
);
1555 yystackp
->yytops
.yycapacity
*= 2;
1558 (yyGLRState
**) YYREALLOC (yystackp
->yytops
.yystates
,
1559 (yystackp
->yytops
.yycapacity
1560 * sizeof yynewStates
[0]));
1561 if (yynewStates
== NULL
)
1562 yyMemoryExhausted (yystackp
);
1563 yystackp
->yytops
.yystates
= yynewStates
;
1565 yynewLookaheadNeeds
=
1566 (yybool
*) YYREALLOC (yystackp
->yytops
.yylookaheadNeeds
,
1567 (yystackp
->yytops
.yycapacity
1568 * sizeof yynewLookaheadNeeds
[0]));
1569 if (yynewLookaheadNeeds
== NULL
)
1570 yyMemoryExhausted (yystackp
);
1571 yystackp
->yytops
.yylookaheadNeeds
= yynewLookaheadNeeds
;
1573 yystackp
->yytops
.yystates
[yystackp
->yytops
.yysize
]
1574 = yystackp
->yytops
.yystates
[yyk
];
1575 yystackp
->yytops
.yylookaheadNeeds
[yystackp
->yytops
.yysize
]
1576 = yystackp
->yytops
.yylookaheadNeeds
[yyk
];
1577 yystackp
->yytops
.yysize
+= 1;
1578 return yystackp
->yytops
.yysize
-1;
1581 /** True iff Y0 and Y1 represent identical options at the top level.
1582 * That is, they represent the same rule applied to RHS symbols
1583 * that produce the same terminal symbols. */
1585 yyidenticalOptions (yySemanticOption
* yyy0
, yySemanticOption
* yyy1
)
1587 if (yyy0
->yyrule
== yyy1
->yyrule
)
1589 yyGLRState
*yys0
, *yys1
;
1591 for (yys0
= yyy0
->yystate
, yys1
= yyy1
->yystate
,
1592 yyn
= yyrhsLength (yyy0
->yyrule
);
1594 yys0
= yys0
->yypred
, yys1
= yys1
->yypred
, yyn
-= 1)
1595 if (yys0
->yyposn
!= yys1
->yyposn
)
1603 /** Assuming identicalOptions (Y0,Y1), destructively merge the
1604 * alternative semantic values for the RHS-symbols of Y1 and Y0. */
1606 yymergeOptionSets (yySemanticOption
* yyy0
, yySemanticOption
* yyy1
)
1608 yyGLRState
*yys0
, *yys1
;
1610 for (yys0
= yyy0
->yystate
, yys1
= yyy1
->yystate
,
1611 yyn
= yyrhsLength (yyy0
->yyrule
);
1613 yys0
= yys0
->yypred
, yys1
= yys1
->yypred
, yyn
-= 1)
1617 else if (yys0
->yyresolved
)
1619 yys1
->yyresolved
= yytrue
;
1620 yys1
->yysemantics
.yysval
= yys0
->yysemantics
.yysval
;
1622 else if (yys1
->yyresolved
)
1624 yys0
->yyresolved
= yytrue
;
1625 yys0
->yysemantics
.yysval
= yys1
->yysemantics
.yysval
;
1629 yySemanticOption
** yyz0p
;
1630 yySemanticOption
* yyz1
;
1631 yyz0p
= &yys0
->yysemantics
.yyfirstVal
;
1632 yyz1
= yys1
->yysemantics
.yyfirstVal
;
1633 while (YYID (yytrue
))
1635 if (yyz1
== *yyz0p
|| yyz1
== NULL
)
1637 else if (*yyz0p
== NULL
)
1642 else if (*yyz0p
< yyz1
)
1644 yySemanticOption
* yyz
= *yyz0p
;
1646 yyz1
= yyz1
->yynext
;
1647 (*yyz0p
)->yynext
= yyz
;
1649 yyz0p
= &(*yyz0p
)->yynext
;
1651 yys1
->yysemantics
.yyfirstVal
= yys0
->yysemantics
.yyfirstVal
;
1656 /** Y0 and Y1 represent two possible actions to take in a given
1657 * parsing state; return 0 if no combination is possible,
1658 * 1 if user-mergeable, 2 if Y0 is preferred, 3 if Y1 is preferred. */
1660 yypreference (yySemanticOption
* y0
, yySemanticOption
* y1
)
1662 yyRuleNum r0
= y0
->yyrule
, r1
= y1
->yyrule
;
1663 int p0
= yydprec
[r0
], p1
= yydprec
[r1
];
1667 if (yymerger
[r0
] == 0 || yymerger
[r0
] != yymerger
[r1
])
1672 if (p0
== 0 || p1
== 0)
1681 static YYRESULTTAG
yyresolveValue (yyGLRState
* yys
,
1682 yyGLRStack
* yystackp
]b4_user_formals
[);
1685 /** Resolve the previous N states starting at and including state S. If result
1686 * != yyok, some states may have been left unresolved possibly with empty
1687 * semantic option chains. Regardless of whether result = yyok, each state
1688 * has been left with consistent data so that yydestroyGLRState can be invoked
1691 yyresolveStates (yyGLRState
* yys
, int yyn
,
1692 yyGLRStack
* yystackp
]b4_user_formals
[)
1696 YYASSERT (yys
->yypred
);
1697 YYCHK (yyresolveStates (yys
->yypred
, yyn
-1, yystackp
]b4_user_args
[));
1698 if (! yys
->yyresolved
)
1699 YYCHK (yyresolveValue (yys
, yystackp
]b4_user_args
[));
1704 /** Resolve the states for the RHS of OPT, perform its user action, and return
1705 * the semantic value and location. Regardless of whether result = yyok, all
1706 * RHS states have been destroyed (assuming the user action destroys all RHS
1707 * semantic values if invoked). */
1709 yyresolveAction (yySemanticOption
* yyopt
, yyGLRStack
* yystackp
,
1710 YYSTYPE
* yyvalp
, YYLTYPE
* yylocp
]b4_user_formals
[)
1712 yyGLRStackItem yyrhsVals
[YYMAXRHS
+ YYMAXLEFT
+ 1];
1715 YYSTYPE yylval_current
;
1716 YYLTYPE yylloc_current
;
1719 yynrhs
= yyrhsLength (yyopt
->yyrule
);
1720 yyflag
= yyresolveStates (yyopt
->yystate
, yynrhs
, yystackp
]b4_user_args
[);
1724 for (yys
= yyopt
->yystate
; yynrhs
> 0; yys
= yys
->yypred
, yynrhs
-= 1)
1725 yydestroyGLRState ("Cleanup: popping", yys
]b4_user_args
[);
1729 yyrhsVals
[YYMAXRHS
+ YYMAXLEFT
].yystate
.yypred
= yyopt
->yystate
;]b4_locations_if([[
1731 /* Set default location. */
1732 yyrhsVals
[YYMAXRHS
+ YYMAXLEFT
- 1].yystate
.yyloc
= yyopt
->yystate
->yyloc
;]])[
1733 yychar_current
= yychar
;
1734 yylval_current
= yylval
;
1735 yylloc_current
= yylloc
;
1736 yychar
= yyopt
->yyrawchar
;
1737 yylval
= yyopt
->yyval
;
1738 yylloc
= yyopt
->yyloc
;
1739 yyflag
= yyuserAction (yyopt
->yyrule
, yynrhs
,
1740 yyrhsVals
+ YYMAXRHS
+ YYMAXLEFT
- 1,
1741 yyvalp
, yylocp
, yystackp
]b4_user_args
[);
1742 yychar
= yychar_current
;
1743 yylval
= yylval_current
;
1744 yylloc
= yylloc_current
;
1750 yyreportTree (yySemanticOption
* yyx
, int yyindent
)
1752 int yynrhs
= yyrhsLength (yyx
->yyrule
);
1755 yyGLRState
* yystates
[1 + YYMAXRHS
];
1756 yyGLRState yyleftmost_state
;
1758 for (yyi
= yynrhs
, yys
= yyx
->yystate
; 0 < yyi
; yyi
-= 1, yys
= yys
->yypred
)
1759 yystates
[yyi
] = yys
;
1762 yyleftmost_state
.yyposn
= 0;
1763 yystates
[0] = &yyleftmost_state
;
1768 if (yyx
->yystate
->yyposn
< yys
->yyposn
+ 1)
1769 YYFPRINTF (stderr
, "%*s%s -> <Rule %d, empty>\n",
1770 yyindent
, "", yytokenName (yylhsNonterm (yyx
->yyrule
)),
1773 YYFPRINTF (stderr
, "%*s%s -> <Rule %d, tokens %lu .. %lu>\n",
1774 yyindent
, "", yytokenName (yylhsNonterm (yyx
->yyrule
)),
1775 yyx
->yyrule
- 1, (unsigned long int) (yys
->yyposn
+ 1),
1776 (unsigned long int) yyx
->yystate
->yyposn
);
1777 for (yyi
= 1; yyi
<= yynrhs
; yyi
+= 1)
1779 if (yystates
[yyi
]->yyresolved
)
1781 if (yystates
[yyi
-1]->yyposn
+1 > yystates
[yyi
]->yyposn
)
1782 YYFPRINTF (stderr
, "%*s%s <empty>\n", yyindent
+2, "",
1783 yytokenName (yyrhs
[yyprhs
[yyx
->yyrule
]+yyi
-1]));
1785 YYFPRINTF (stderr
, "%*s%s <tokens %lu .. %lu>\n", yyindent
+2, "",
1786 yytokenName (yyrhs
[yyprhs
[yyx
->yyrule
]+yyi
-1]),
1787 (unsigned long int) (yystates
[yyi
- 1]->yyposn
+ 1),
1788 (unsigned long int) yystates
[yyi
]->yyposn
);
1791 yyreportTree (yystates
[yyi
]->yysemantics
.yyfirstVal
, yyindent
+2);
1796 /*ARGSUSED*/ static YYRESULTTAG
1797 yyreportAmbiguity (yySemanticOption
* yyx0
,
1798 yySemanticOption
* yyx1
]b4_pure_formals
[)
1804 YYFPRINTF (stderr
, "Ambiguity detected.\n");
1805 YYFPRINTF (stderr
, "Option 1,\n");
1806 yyreportTree (yyx0
, 2);
1807 YYFPRINTF (stderr
, "\nOption 2,\n");
1808 yyreportTree (yyx1
, 2);
1809 YYFPRINTF (stderr
, "\n");
1812 yyerror (]b4_yyerror_args
[YY_("syntax is ambiguous"));
1816 /** Starting at and including state S1, resolve the location for each of the
1817 * previous N1 states that is unresolved. The first semantic option of a state
1818 * is always chosen. */
1820 yyresolveLocations (yyGLRState
* yys1
, int yyn1
,
1821 yyGLRStack
*yystackp
]b4_user_formals
[)
1825 yyresolveLocations (yys1
->yypred
, yyn1
- 1, yystackp
]b4_user_args
[);
1826 if (!yys1
->yyresolved
)
1828 yySemanticOption
*yyoption
;
1829 yyGLRStackItem yyrhsloc
[1 + YYMAXRHS
];
1832 YYSTYPE yylval_current
;
1833 YYLTYPE yylloc_current
;
1834 yyoption
= yys1
->yysemantics
.yyfirstVal
;
1835 YYASSERT (yyoption
!= NULL
);
1836 yynrhs
= yyrhsLength (yyoption
->yyrule
);
1841 yyresolveLocations (yyoption
->yystate
, yynrhs
,
1842 yystackp
]b4_user_args
[);
1843 for (yys
= yyoption
->yystate
, yyn
= yynrhs
;
1845 yys
= yys
->yypred
, yyn
-= 1)
1846 yyrhsloc
[yyn
].yystate
.yyloc
= yys
->yyloc
;
1850 /* Both yyresolveAction and yyresolveLocations traverse the GSS
1851 in reverse rightmost order. It is only necessary to invoke
1852 yyresolveLocations on a subforest for which yyresolveAction
1853 would have been invoked next had an ambiguity not been
1854 detected. Thus the location of the previous state (but not
1855 necessarily the previous state itself) is guaranteed to be
1856 resolved already. */
1857 yyGLRState
*yyprevious
= yyoption
->yystate
;
1858 yyrhsloc
[0].yystate
.yyloc
= yyprevious
->yyloc
;
1860 yychar_current
= yychar
;
1861 yylval_current
= yylval
;
1862 yylloc_current
= yylloc
;
1863 yychar
= yyoption
->yyrawchar
;
1864 yylval
= yyoption
->yyval
;
1865 yylloc
= yyoption
->yyloc
;
1866 YYLLOC_DEFAULT ((yys1
->yyloc
), yyrhsloc
, yynrhs
);
1867 yychar
= yychar_current
;
1868 yylval
= yylval_current
;
1869 yylloc
= yylloc_current
;
1874 /** Resolve the ambiguity represented in state S, perform the indicated
1875 * actions, and set the semantic value of S. If result != yyok, the chain of
1876 * semantic options in S has been cleared instead or it has been left
1877 * unmodified except that redundant options may have been removed. Regardless
1878 * of whether result = yyok, S has been left with consistent data so that
1879 * yydestroyGLRState can be invoked if necessary. */
1881 yyresolveValue (yyGLRState
* yys
, yyGLRStack
* yystackp
]b4_user_formals
[)
1883 yySemanticOption
* yyoptionList
= yys
->yysemantics
.yyfirstVal
;
1884 yySemanticOption
* yybest
;
1885 yySemanticOption
** yypp
;
1889 YYLTYPE
*yylocp
= &yys
->yyloc
;
1891 yybest
= yyoptionList
;
1893 for (yypp
= &yyoptionList
->yynext
; *yypp
!= NULL
; )
1895 yySemanticOption
* yyp
= *yypp
;
1897 if (yyidenticalOptions (yybest
, yyp
))
1899 yymergeOptionSets (yybest
, yyp
);
1900 *yypp
= yyp
->yynext
;
1904 switch (yypreference (yybest
, yyp
))
1907 yyresolveLocations (yys
, 1, yystackp
]b4_user_args
[);
1908 return yyreportAmbiguity (yybest
, yyp
]b4_pure_args
[);
1920 /* This cannot happen so it is not worth a YYASSERT (yyfalse),
1921 but some compilers complain if the default case is
1925 yypp
= &yyp
->yynext
;
1931 yySemanticOption
* yyp
;
1932 int yyprec
= yydprec
[yybest
->yyrule
];
1933 yyflag
= yyresolveAction (yybest
, yystackp
, &yysval
,
1934 yylocp
]b4_user_args
[);
1936 for (yyp
= yybest
->yynext
; yyp
!= NULL
; yyp
= yyp
->yynext
)
1938 if (yyprec
== yydprec
[yyp
->yyrule
])
1940 YYSTYPE yysval_other
;
1942 yyflag
= yyresolveAction (yyp
, yystackp
, &yysval_other
,
1943 &yydummy
]b4_user_args
[);
1946 yydestruct ("Cleanup: discarding incompletely merged value for",
1947 yystos
[yys
->yylrState
],
1948 &yysval
]b4_locations_if([, yylocp
])[]b4_user_args
[);
1951 yyuserMerge (yymerger
[yyp
->yyrule
], &yysval
, &yysval_other
);
1956 yyflag
= yyresolveAction (yybest
, yystackp
, &yysval
, yylocp
]b4_user_args
[);
1960 yys
->yyresolved
= yytrue
;
1961 yys
->yysemantics
.yysval
= yysval
;
1964 yys
->yysemantics
.yyfirstVal
= NULL
;
1969 yyresolveStack (yyGLRStack
* yystackp
]b4_user_formals
[)
1971 if (yystackp
->yysplitPoint
!= NULL
)
1976 for (yyn
= 0, yys
= yystackp
->yytops
.yystates
[0];
1977 yys
!= yystackp
->yysplitPoint
;
1978 yys
= yys
->yypred
, yyn
+= 1)
1980 YYCHK (yyresolveStates (yystackp
->yytops
.yystates
[0], yyn
, yystackp
1987 yycompressStack (yyGLRStack
* yystackp
)
1989 yyGLRState
* yyp
, *yyq
, *yyr
;
1991 if (yystackp
->yytops
.yysize
!= 1 || yystackp
->yysplitPoint
== NULL
)
1994 for (yyp
= yystackp
->yytops
.yystates
[0], yyq
= yyp
->yypred
, yyr
= NULL
;
1995 yyp
!= yystackp
->yysplitPoint
;
1996 yyr
= yyp
, yyp
= yyq
, yyq
= yyp
->yypred
)
1999 yystackp
->yyspaceLeft
+= yystackp
->yynextFree
- yystackp
->yyitems
;
2000 yystackp
->yynextFree
= ((yyGLRStackItem
*) yystackp
->yysplitPoint
) + 1;
2001 yystackp
->yyspaceLeft
-= yystackp
->yynextFree
- yystackp
->yyitems
;
2002 yystackp
->yysplitPoint
= NULL
;
2003 yystackp
->yylastDeleted
= NULL
;
2007 yystackp
->yynextFree
->yystate
= *yyr
;
2009 yystackp
->yynextFree
->yystate
.yypred
= &yystackp
->yynextFree
[-1].yystate
;
2010 yystackp
->yytops
.yystates
[0] = &yystackp
->yynextFree
->yystate
;
2011 yystackp
->yynextFree
+= 1;
2012 yystackp
->yyspaceLeft
-= 1;
2017 yyprocessOneStack (yyGLRStack
* yystackp
, size_t yyk
,
2018 size_t yyposn
]b4_pure_formals
[)
2021 const short int* yyconflicts
;
2024 while (yystackp
->yytops
.yystates
[yyk
] != NULL
)
2026 yyStateNum yystate
= yystackp
->yytops
.yystates
[yyk
]->yylrState
;
2027 YYDPRINTF ((stderr
, "Stack %lu Entering state %d\n",
2028 (unsigned long int) yyk
, yystate
));
2030 YYASSERT (yystate
!= YYFINAL
);
2032 if (yyisDefaultedState (yystate
))
2034 yyrule
= yydefaultAction (yystate
);
2037 YYDPRINTF ((stderr
, "Stack %lu dies.\n",
2038 (unsigned long int) yyk
));
2039 yymarkStackDeleted (yystackp
, yyk
);
2042 YYCHK (yyglrReduce (yystackp
, yyk
, yyrule
, yyfalse
]b4_user_args
[));
2047 yystackp
->yytops
.yylookaheadNeeds
[yyk
] = yytrue
;
2048 if (yychar
== YYEMPTY
)
2050 YYDPRINTF ((stderr
, "Reading a token: "));
2054 if (yychar
<= YYEOF
)
2056 yychar
= yytoken
= YYEOF
;
2057 YYDPRINTF ((stderr
, "Now at end of input.\n"));
2061 yytoken
= YYTRANSLATE (yychar
);
2062 YY_SYMBOL_PRINT ("Next token is", yytoken
, &yylval
, &yylloc
);
2065 yygetLRActions (yystate
, yytoken
, &yyaction
, &yyconflicts
);
2067 while (*yyconflicts
!= 0)
2069 size_t yynewStack
= yysplitStack (yystackp
, yyk
);
2070 YYDPRINTF ((stderr
, "Splitting off stack %lu from %lu.\n",
2071 (unsigned long int) yynewStack
,
2072 (unsigned long int) yyk
));
2073 YYCHK (yyglrReduce (yystackp
, yynewStack
,
2074 *yyconflicts
, yyfalse
]b4_user_args
[));
2075 YYCHK (yyprocessOneStack (yystackp
, yynewStack
,
2076 yyposn
]b4_pure_args
[));
2080 if (yyisShiftAction (yyaction
))
2082 else if (yyisErrorAction (yyaction
))
2084 YYDPRINTF ((stderr
, "Stack %lu dies.\n",
2085 (unsigned long int) yyk
));
2086 yymarkStackDeleted (yystackp
, yyk
);
2090 YYCHK (yyglrReduce (yystackp
, yyk
, -yyaction
,
2091 yyfalse
]b4_user_args
[));
2097 /*ARGSUSED*/ static void
2098 yyreportSyntaxError (yyGLRStack
* yystackp
]b4_user_formals
[)
2100 if (yystackp
->yyerrState
== 0)
2104 yyn
= yypact
[yystackp
->yytops
.yystates
[0]->yylrState
];
2105 if (YYPACT_NINF
< yyn
&& yyn
<= YYLAST
)
2107 yySymbol yytoken
= YYTRANSLATE (yychar
);
2108 size_t yysize0
= yytnamerr (NULL
, yytokenName (yytoken
));
2109 size_t yysize
= yysize0
;
2111 yybool yysize_overflow
= yyfalse
;
2113 enum { YYERROR_VERBOSE_ARGS_MAXIMUM
= 5 };
2114 char const *yyarg
[YYERROR_VERBOSE_ARGS_MAXIMUM
];
2118 static char const yyunexpected
[] = "syntax error, unexpected %s";
2119 static char const yyexpecting
[] = ", expecting %s";
2120 static char const yyor
[] = " or %s";
2121 char yyformat
[sizeof yyunexpected
2122 + sizeof yyexpecting
- 1
2123 + ((YYERROR_VERBOSE_ARGS_MAXIMUM
- 2)
2124 * (sizeof yyor
- 1))];
2125 char const *yyprefix
= yyexpecting
;
2127 /* Start YYX at -YYN if negative to avoid negative indexes in
2129 int yyxbegin
= yyn
< 0 ? -yyn
: 0;
2131 /* Stay within bounds of both yycheck and yytname. */
2132 int yychecklim
= YYLAST
- yyn
+ 1;
2133 int yyxend
= yychecklim
< YYNTOKENS
? yychecklim
: YYNTOKENS
;
2136 yyarg
[0] = yytokenName (yytoken
);
2137 yyfmt
= yystpcpy (yyformat
, yyunexpected
);
2139 for (yyx
= yyxbegin
; yyx
< yyxend
; ++yyx
)
2140 if (yycheck
[yyx
+ yyn
] == yyx
&& yyx
!= YYTERROR
)
2142 if (yycount
== YYERROR_VERBOSE_ARGS_MAXIMUM
)
2146 yyformat
[sizeof yyunexpected
- 1] = '\0';
2149 yyarg
[yycount
++] = yytokenName (yyx
);
2150 yysize1
= yysize
+ yytnamerr (NULL
, yytokenName (yyx
));
2151 yysize_overflow
|= yysize1
< yysize
;
2153 yyfmt
= yystpcpy (yyfmt
, yyprefix
);
2157 yyf
= YY_(yyformat
);
2158 yysize1
= yysize
+ strlen (yyf
);
2159 yysize_overflow
|= yysize1
< yysize
;
2162 if (!yysize_overflow
)
2163 yymsg
= (char *) YYMALLOC (yysize
);
2169 while ((*yyp
= *yyf
))
2171 if (*yyp
== '%' && yyf
[1] == 's' && yyi
< yycount
)
2173 yyp
+= yytnamerr (yyp
, yyarg
[yyi
++]);
2182 yyerror (]b4_lyyerror_args
[yymsg
);
2187 yyerror (]b4_lyyerror_args
[YY_("syntax error"));
2188 yyMemoryExhausted (yystackp
);
2192 #endif /* YYERROR_VERBOSE */
2193 yyerror (]b4_lyyerror_args
[YY_("syntax error"));
2198 /* Recover from a syntax error on *YYSTACKP, assuming that *YYSTACKP->YYTOKENP,
2199 yylval, and yylloc are the syntactic category, semantic value, and location
2200 of the lookahead. */
2201 /*ARGSUSED*/ static void
2202 yyrecoverSyntaxError (yyGLRStack
* yystackp
]b4_user_formals
[)
2207 if (yystackp
->yyerrState
== 3)
2208 /* We just shifted the error token and (perhaps) took some
2209 reductions. Skip tokens until we can proceed. */
2210 while (YYID (yytrue
))
2213 if (yychar
== YYEOF
)
2214 yyFail (yystackp
][]b4_lpure_args
[, NULL
);
2215 if (yychar
!= YYEMPTY
)
2216 {]b4_locations_if([[
2217 /* We throw away the lookahead, but the error range
2218 of the shifted error token must take it into account. */
2219 yyGLRState
*yys
= yystackp
->yytops
.yystates
[0];
2220 yyGLRStackItem yyerror_range
[3];
2221 yyerror_range
[1].yystate
.yyloc
= yys
->yyloc
;
2222 yyerror_range
[2].yystate
.yyloc
= yylloc
;
2223 YYLLOC_DEFAULT ((yys
->yyloc
), yyerror_range
, 2);]])[
2224 yytoken
= YYTRANSLATE (yychar
);
2225 yydestruct ("Error: discarding",
2226 yytoken
, &yylval
]b4_locations_if([, &yylloc
])[]b4_user_args
[);
2228 YYDPRINTF ((stderr
, "Reading a token: "));
2230 if (yychar
<= YYEOF
)
2232 yychar
= yytoken
= YYEOF
;
2233 YYDPRINTF ((stderr
, "Now at end of input.\n"));
2237 yytoken
= YYTRANSLATE (yychar
);
2238 YY_SYMBOL_PRINT ("Next token is", yytoken
, &yylval
, &yylloc
);
2240 yyj
= yypact
[yystackp
->yytops
.yystates
[0]->yylrState
];
2241 if (yyis_pact_ninf (yyj
))
2244 if (yyj
< 0 || YYLAST
< yyj
|| yycheck
[yyj
] != yytoken
)
2246 if (yydefact
[yystackp
->yytops
.yystates
[0]->yylrState
] != 0)
2249 else if (yytable
[yyj
] != 0 && ! yyis_table_ninf (yytable
[yyj
]))
2253 /* Reduce to one stack. */
2254 for (yyk
= 0; yyk
< yystackp
->yytops
.yysize
; yyk
+= 1)
2255 if (yystackp
->yytops
.yystates
[yyk
] != NULL
)
2257 if (yyk
>= yystackp
->yytops
.yysize
)
2258 yyFail (yystackp
][]b4_lpure_args
[, NULL
);
2259 for (yyk
+= 1; yyk
< yystackp
->yytops
.yysize
; yyk
+= 1)
2260 yymarkStackDeleted (yystackp
, yyk
);
2261 yyremoveDeletes (yystackp
);
2262 yycompressStack (yystackp
);
2264 /* Now pop stack until we find a state that shifts the error token. */
2265 yystackp
->yyerrState
= 3;
2266 while (yystackp
->yytops
.yystates
[0] != NULL
)
2268 yyGLRState
*yys
= yystackp
->yytops
.yystates
[0];
2269 yyj
= yypact
[yys
->yylrState
];
2270 if (! yyis_pact_ninf (yyj
))
2273 if (0 <= yyj
&& yyj
<= YYLAST
&& yycheck
[yyj
] == YYTERROR
2274 && yyisShiftAction (yytable
[yyj
]))
2276 /* Shift the error token having adjusted its location. */
2277 YYLTYPE yyerrloc
;]b4_locations_if([[
2278 yystackp
->yyerror_range
[2].yystate
.yyloc
= yylloc
;
2279 YYLLOC_DEFAULT (yyerrloc
, (yystackp
->yyerror_range
), 2);]])[
2280 YY_SYMBOL_PRINT ("Shifting", yystos
[yytable
[yyj
]],
2281 &yylval
, &yyerrloc
);
2282 yyglrShift (yystackp
, 0, yytable
[yyj
],
2283 yys
->yyposn
, &yylval
, &yyerrloc
);
2284 yys
= yystackp
->yytops
.yystates
[0];
2288 ]b4_locations_if([[ yystackp
->yyerror_range
[1].yystate
.yyloc
= yys
->yyloc
;]])[
2289 if (yys
->yypred
!= NULL
)
2290 yydestroyGLRState ("Error: popping", yys
]b4_user_args
[);
2291 yystackp
->yytops
.yystates
[0] = yys
->yypred
;
2292 yystackp
->yynextFree
-= 1;
2293 yystackp
->yyspaceLeft
+= 1;
2295 if (yystackp
->yytops
.yystates
[0] == NULL
)
2296 yyFail (yystackp
][]b4_lpure_args
[, NULL
);
2299 #define YYCHK1(YYE) \
2309 goto yyuser_error; \
2320 ]b4_c_ansi_function_def([yyparse
], [int], b4_parse_param
)[
2324 yyGLRStack
* const yystackp
= &yystack
;
2327 YYDPRINTF ((stderr
, "Starting parse\n"));
2330 yylval
= yyval_default
;
2332 #if YYLTYPE_IS_TRIVIAL
2333 yylloc
.first_line
= yylloc
.last_line
= ]b4_location_initial_line
[;
2334 yylloc
.first_column
= yylloc
.last_column
= ]b4_location_initial_column
[;
2337 m4_ifdef([b4_initial_action
], [
2338 m4_pushdef([b4_at_dollar
], [yylloc
])dnl
2339 m4_pushdef([b4_dollar_dollar
], [yylval
])dnl
2340 /* User initialization code. */
2341 b4_user_initial_action
2342 m4_popdef([b4_dollar_dollar
])dnl
2343 m4_popdef([b4_at_dollar
])])dnl
2345 if (! yyinitGLRStack (yystackp
, YYINITDEPTH
))
2346 goto yyexhaustedlab
;
2347 switch (YYSETJMP (yystack
.yyexception_buffer
))
2350 case 1: goto yyabortlab
;
2351 case 2: goto yyexhaustedlab
;
2352 default: goto yybuglab
;
2354 yyglrShift (&yystack
, 0, 0, 0, &yylval
, &yylloc
);
2357 while (YYID (yytrue
))
2359 /* For efficiency, we have two loops, the first of which is
2360 specialized to deterministic operation (single stack, no
2361 potential ambiguity). */
2363 while (YYID (yytrue
))
2367 const short int* yyconflicts
;
2369 yyStateNum yystate
= yystack
.yytops
.yystates
[0]->yylrState
;
2370 YYDPRINTF ((stderr
, "Entering state %d\n", yystate
));
2371 if (yystate
== YYFINAL
)
2373 if (yyisDefaultedState (yystate
))
2375 yyrule
= yydefaultAction (yystate
);
2378 ]b4_locations_if([[ yystack
.yyerror_range
[1].yystate
.yyloc
= yylloc
;]])[
2379 yyreportSyntaxError (&yystack
]b4_user_args
[);
2382 YYCHK1 (yyglrReduce (&yystack
, 0, yyrule
, yytrue
]b4_user_args
[));
2387 if (yychar
== YYEMPTY
)
2389 YYDPRINTF ((stderr
, "Reading a token: "));
2393 if (yychar
<= YYEOF
)
2395 yychar
= yytoken
= YYEOF
;
2396 YYDPRINTF ((stderr
, "Now at end of input.\n"));
2400 yytoken
= YYTRANSLATE (yychar
);
2401 YY_SYMBOL_PRINT ("Next token is", yytoken
, &yylval
, &yylloc
);
2404 yygetLRActions (yystate
, yytoken
, &yyaction
, &yyconflicts
);
2405 if (*yyconflicts
!= 0)
2407 if (yyisShiftAction (yyaction
))
2409 YY_SYMBOL_PRINT ("Shifting", yytoken
, &yylval
, &yylloc
);
2412 yyglrShift (&yystack
, 0, yyaction
, yyposn
, &yylval
, &yylloc
);
2413 if (0 < yystack
.yyerrState
)
2414 yystack
.yyerrState
-= 1;
2416 else if (yyisErrorAction (yyaction
))
2418 ]b4_locations_if([[ yystack
.yyerror_range
[1].yystate
.yyloc
= yylloc
;]])[
2419 yyreportSyntaxError (&yystack
]b4_user_args
[);
2423 YYCHK1 (yyglrReduce (&yystack
, 0, -yyaction
, yytrue
]b4_user_args
[));
2427 while (YYID (yytrue
))
2429 yySymbol yytoken_to_shift
;
2432 for (yys
= 0; yys
< yystack
.yytops
.yysize
; yys
+= 1)
2433 yystackp
->yytops
.yylookaheadNeeds
[yys
] = yychar
!= YYEMPTY
;
2435 /* yyprocessOneStack returns one of three things:
2437 - An error flag. If the caller is yyprocessOneStack, it
2438 immediately returns as well. When the caller is finally
2439 yyparse, it jumps to an error label via YYCHK1.
2441 - yyok, but yyprocessOneStack has invoked yymarkStackDeleted
2442 (&yystack, yys), which sets the top state of yys to NULL. Thus,
2443 yyparse's following invocation of yyremoveDeletes will remove
2446 - yyok, when ready to shift a token.
2448 Except in the first case, yyparse will invoke yyremoveDeletes and
2449 then shift the next token onto all remaining stacks. This
2450 synchronization of the shift (that is, after all preceding
2451 reductions on all stacks) helps prevent double destructor calls
2452 on yylval in the event of memory exhaustion. */
2454 for (yys
= 0; yys
< yystack
.yytops
.yysize
; yys
+= 1)
2455 YYCHK1 (yyprocessOneStack (&yystack
, yys
, yyposn
]b4_lpure_args
[));
2456 yyremoveDeletes (&yystack
);
2457 if (yystack
.yytops
.yysize
== 0)
2459 yyundeleteLastStack (&yystack
);
2460 if (yystack
.yytops
.yysize
== 0)
2461 yyFail (&yystack
][]b4_lpure_args
[, YY_("syntax error"));
2462 YYCHK1 (yyresolveStack (&yystack
]b4_user_args
[));
2463 YYDPRINTF ((stderr
, "Returning to deterministic operation.\n"));
2464 ]b4_locations_if([[ yystack
.yyerror_range
[1].yystate
.yyloc
= yylloc
;]])[
2465 yyreportSyntaxError (&yystack
]b4_user_args
[);
2469 /* If any yyglrShift call fails, it will fail after shifting. Thus,
2470 a copy of yylval will already be on stack 0 in the event of a
2471 failure in the following loop. Thus, yychar is set to YYEMPTY
2472 before the loop to make sure the user destructor for yylval isn't
2474 yytoken_to_shift
= YYTRANSLATE (yychar
);
2477 for (yys
= 0; yys
< yystack
.yytops
.yysize
; yys
+= 1)
2480 const short int* yyconflicts
;
2481 yyStateNum yystate
= yystack
.yytops
.yystates
[yys
]->yylrState
;
2482 yygetLRActions (yystate
, yytoken_to_shift
, &yyaction
,
2484 /* Note that yyconflicts were handled by yyprocessOneStack. */
2485 YYDPRINTF ((stderr
, "On stack %lu, ", (unsigned long int) yys
));
2486 YY_SYMBOL_PRINT ("shifting", yytoken_to_shift
, &yylval
, &yylloc
);
2487 yyglrShift (&yystack
, yys
, yyaction
, yyposn
,
2489 YYDPRINTF ((stderr
, "Stack %lu now in state #%d\n",
2490 (unsigned long int) yys
,
2491 yystack
.yytops
.yystates
[yys
]->yylrState
));
2494 if (yystack
.yytops
.yysize
== 1)
2496 YYCHK1 (yyresolveStack (&yystack
]b4_user_args
[));
2497 YYDPRINTF ((stderr
, "Returning to deterministic operation.\n"));
2498 yycompressStack (&yystack
);
2504 yyrecoverSyntaxError (&yystack
]b4_user_args
[);
2505 yyposn
= yystack
.yytops
.yystates
[0]->yyposn
;
2521 yyerror (]b4_lyyerror_args
[YY_("memory exhausted"));
2526 if (yychar
!= YYEMPTY
)
2527 yydestruct ("Cleanup: discarding lookahead",
2528 YYTRANSLATE (yychar
),
2529 &yylval
]b4_locations_if([, &yylloc
])[]b4_user_args
[);
2531 /* If the stack is well-formed, pop the stack until it is empty,
2532 destroying its entries as we go. But free the stack regardless
2533 of whether it is well-formed. */
2534 if (yystack
.yyitems
)
2536 yyGLRState
** yystates
= yystack
.yytops
.yystates
;
2539 size_t yysize
= yystack
.yytops
.yysize
;
2541 for (yyk
= 0; yyk
< yysize
; yyk
+= 1)
2544 while (yystates
[yyk
])
2546 yyGLRState
*yys
= yystates
[yyk
];
2547 ]b4_locations_if([[ yystack
.yyerror_range
[1].yystate
.yyloc
= yys
->yyloc
;]]
2548 )[ if (yys
->yypred
!= NULL
)
2549 yydestroyGLRState ("Cleanup: popping", yys
]b4_user_args
[);
2550 yystates
[yyk
] = yys
->yypred
;
2551 yystack
.yynextFree
-= 1;
2552 yystack
.yyspaceLeft
+= 1;
2557 yyfreeGLRStack (&yystack
);
2560 /* Make sure YYID is used. */
2561 return YYID (yyresult
);
2564 /* DEBUGGING ONLY */
2566 static void yypstack (yyGLRStack
* yystackp
, size_t yyk
)
2567 __attribute__ ((__unused__
));
2568 static void yypdumpstack (yyGLRStack
* yystackp
) __attribute__ ((__unused__
));
2571 yy_yypstack (yyGLRState
* yys
)
2575 yy_yypstack (yys
->yypred
);
2576 fprintf (stderr
, " -> ");
2578 fprintf (stderr
, "%d@@%lu", yys
->yylrState
, (unsigned long int) yys
->yyposn
);
2582 yypstates (yyGLRState
* yyst
)
2585 fprintf (stderr
, "<null>");
2588 fprintf (stderr
, "\n");
2592 yypstack (yyGLRStack
* yystackp
, size_t yyk
)
2594 yypstates (yystackp
->yytops
.yystates
[yyk
]);
2597 #define YYINDEX(YYX) \
2598 ((YYX) == NULL ? -1 : (yyGLRStackItem*) (YYX) - yystackp->yyitems)
2602 yypdumpstack (yyGLRStack
* yystackp
)
2604 yyGLRStackItem
* yyp
;
2606 for (yyp
= yystackp
->yyitems
; yyp
< yystackp
->yynextFree
; yyp
+= 1)
2608 fprintf (stderr
, "%3lu. ", (unsigned long int) (yyp
- yystackp
->yyitems
));
2609 if (*(yybool
*) yyp
)
2611 fprintf (stderr
, "Res: %d, LR State: %d, posn: %lu, pred: %ld",
2612 yyp
->yystate
.yyresolved
, yyp
->yystate
.yylrState
,
2613 (unsigned long int) yyp
->yystate
.yyposn
,
2614 (long int) YYINDEX (yyp
->yystate
.yypred
));
2615 if (! yyp
->yystate
.yyresolved
)
2616 fprintf (stderr
, ", firstVal: %ld",
2617 (long int) YYINDEX (yyp
->yystate
.yysemantics
.yyfirstVal
));
2621 fprintf (stderr
, "Option. rule: %d, state: %ld, next: %ld",
2622 yyp
->yyoption
.yyrule
- 1,
2623 (long int) YYINDEX (yyp
->yyoption
.yystate
),
2624 (long int) YYINDEX (yyp
->yyoption
.yynext
));
2626 fprintf (stderr
, "\n");
2628 fprintf (stderr
, "Tops:");
2629 for (yyi
= 0; yyi
< yystackp
->yytops
.yysize
; yyi
+= 1)
2630 fprintf (stderr
, "%lu: %ld; ", (unsigned long int) yyi
,
2631 (long int) YYINDEX (yystackp
->yytops
.yystates
[yyi
]));
2632 fprintf (stderr
, "\n");
2639 dnl glr
.cc produces its own header
.
2641 m4_if(b4_skeleton
, ["glr.c"],
2643 [@
output(b4_spec_defines_file@
)
2644 b4_copyright([Skeleton interface
for Bison GLR parsers in C
],
2645 [2002, 2003, 2004, 2005, 2006])
2647 b4_shared_declarations
2649 extern YYSTYPE b4_prefix
[]lval
;
2651 b4_locations_if([b4_pure_if([],
2652 [extern YYLTYPE b4_prefix
[]lloc
;])