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_locations_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_locations_if([yylocp
, ])])dnl
65 m4_ifset([b4_parse_param
], [b4_c_args(b4_parse_param
), ])])
70 # Same as above, but on the lookahead, hence &yylloc instead of yylocp.
71 m4_define([b4_lyyerror_args
],
72 [b4_pure_if([b4_locations_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_locations_if([, yylocp
])])[]b4_user_args
])
85 # Same as above, but on the lookahead, hence &yylloc instead of yylocp.
86 m4_define([b4_lpure_args
],
87 [b4_pure_if([b4_locations_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_locations_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 /* C GLR parser skeleton written by Paul Hilfinger. */
153 m4_if(b4_prefix
, [yy
], [],
154 [/* Substitute the variable and function names. */
155 #define yyparse b4_prefix[]parse
156 #define yylex b4_prefix[]lex
157 #define yyerror b4_prefix[]error
158 #define yylval b4_prefix[]lval
159 #define yychar b4_prefix[]char
160 #define yydebug b4_prefix[]debug
161 #define yynerrs b4_prefix[]nerrs
162 #define yylloc b4_prefix[]lloc])[
164 /* Copy the first part of user declarations. */
167 dnl
# b4_shared_declarations
168 dnl
# ----------------------
169 dnl
# Declaration that might either go into the header (if --defines)
170 dnl
# or open coded in the parser body.
171 m4_define([b4_shared_declarations
],
172 [m4_ifdef([b4_start_header
],
173 [[/* Copy the %start-header blocks. */
174 ]b4_start_header
])[]dnl
176 b4_token_enums(b4_tokens
)
178 [#if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED
179 ]m4_ifdef([b4_stype
],
180 [typedef union b4_union_name
182 /* Line __line__ of glr.c. */
183 b4_syncline([@oline@
], [@ofile@
])
185 [typedef int YYSTYPE
;])[
186 # define YYSTYPE_IS_DECLARED 1
187 # define YYSTYPE_IS_TRIVIAL 1
190 #if ! defined YYLTYPE && ! defined YYLTYPE_IS_DECLARED
191 typedef struct YYLTYPE
202 # define YYLTYPE_IS_DECLARED 1
203 # define YYLTYPE_IS_TRIVIAL 1
206 ]m4_ifdef([b4_end_header
],
207 [[/* Copy the %end-header blocks. */
208 ]b4_end_header
])[]dnl
211 b4_defines_if([#include @output_header_name@],
212 [b4_shared_declarations
])[
214 /* Enabling traces. */
216 # define YYDEBUG ]b4_debug_flag[
219 /* Enabling verbose error messages. */
220 #ifdef YYERROR_VERBOSE
221 # undef YYERROR_VERBOSE
222 # define YYERROR_VERBOSE 1
224 # define YYERROR_VERBOSE ]b4_error_verbose_flag[
227 /* Enabling the token table. */
228 #ifndef YYTOKEN_TABLE
229 # define YYTOKEN_TABLE ]b4_token_table[
232 /* Default (constant) value used for initialization for null
233 right-hand sides. Unlike the standard yacc.c template,
234 here we set the default value of $$ to a zeroed-out value.
235 Since the default value is undefined, this behavior is
236 technically correct. */
237 static YYSTYPE yyval_default
;
239 /* Copy the second part of user declarations. */
242 ]/* Line __line__ of glr.c. */
243 b4_syncline([@oline@
], [@ofile@
])
253 # include <libintl.h> /* INFRINGES ON USER NAME SPACE */
254 # define YY_(msgid) dgettext ("bison-runtime", msgid)
258 # define YY_(msgid) msgid
262 /* Suppress unused-variable warnings by "using" E. */
263 #if ! defined lint || defined __GNUC__
264 # define YYUSE(e) ((void) (e))
266 # define YYUSE(e) /* empty */
269 /* Identity function, used to suppress warnings about constant conditions. */
273 ]b4_c_function_def([YYID
], [static int], [[int i
], [i
]])[
283 # define YYMALLOC malloc
286 # define YYREALLOC realloc
289 #define YYSIZEMAX ((size_t) -1)
294 typedef unsigned char yybool
;
301 # define YYJMP_BUF jmp_buf
302 # define YYSETJMP(env) setjmp (env)
303 # define YYLONGJMP(env, val) longjmp (env, val)
310 #ifndef __attribute__
311 /* This feature is available in gcc versions 2.5 and later. */
312 # if (! defined __GNUC__ || __GNUC__ < 2 \
313 || (__GNUC__ == 2 && __GNUC_MINOR__ < 5) || __STRICT_ANSI__)
314 # define __attribute__(Spec) /* empty */
318 ]b4_locations_if([#define YYOPTIONAL_LOC(Name) Name],[
320 # define YYOPTIONAL_LOC(Name) /* empty */
322 # define YYOPTIONAL_LOC(Name) Name __attribute__ ((__unused__))
326 # define YYASSERT(condition) ((void) ((condition) || (abort (), 0)))
329 /* YYFINAL -- State number of the termination state. */
330 #define YYFINAL ]b4_final_state_number[
331 /* YYLAST -- Last index in YYTABLE. */
332 #define YYLAST ]b4_last[
334 /* YYNTOKENS -- Number of terminals. */
335 #define YYNTOKENS ]b4_tokens_number[
336 /* YYNNTS -- Number of nonterminals. */
337 #define YYNNTS ]b4_nterms_number[
338 /* YYNRULES -- Number of rules. */
339 #define YYNRULES ]b4_rules_number[
340 /* YYNRULES -- Number of states. */
341 #define YYNSTATES ]b4_states_number[
342 /* YYMAXRHS -- Maximum number of symbols on right-hand side of rule. */
343 #define YYMAXRHS ]b4_r2_max[
344 /* YYMAXLEFT -- Maximum number of symbols to the left of a handle
345 accessed by $0, $-1, etc., in any rule. */
346 #define YYMAXLEFT ]b4_max_left_semantic_context[
348 /* YYTRANSLATE(X) -- Bison symbol number corresponding to X. */
349 #define YYUNDEFTOK ]b4_undef_token_number[
350 #define YYMAXUTOK ]b4_user_token_number_max[
352 #define YYTRANSLATE(YYX) \
353 ((YYX <= 0) ? YYEOF : \
354 (unsigned int) (YYX) <= YYMAXUTOK ? yytranslate[YYX] : YYUNDEFTOK)
356 /* YYTRANSLATE[YYLEX] -- Bison symbol number corresponding to YYLEX. */
357 static const ]b4_int_type_for([b4_translate
])[ yytranslate
[] =
363 /* YYPRHS[YYN] -- Index of the first RHS symbol of rule number YYN in
365 static const ]b4_int_type_for([b4_prhs
])[ yyprhs
[] =
370 /* YYRHS -- A `-1'-separated list of the rules' RHS. */
371 static const ]b4_int_type_for([b4_rhs
])[ yyrhs
[] =
376 /* YYRLINE[YYN] -- source line where rule number YYN was defined. */
377 static const ]b4_int_type_for([b4_rline
])[ yyrline
[] =
383 #if YYDEBUG || YYERROR_VERBOSE || YYTOKEN_TABLE
384 /* YYTNAME[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM.
385 First, the terminals, then, starting at YYNTOKENS, nonterminals. */
386 static const char *const yytname
[] =
392 /* YYR1[YYN] -- Symbol number of symbol that rule YYN derives. */
393 static const ]b4_int_type_for([b4_r1
])[ yyr1
[] =
398 /* YYR2[YYN] -- Number of symbols composing right hand side of rule YYN. */
399 static const ]b4_int_type_for([b4_r2
])[ yyr2
[] =
404 /* YYDPREC[RULE-NUM] -- Dynamic precedence of rule #RULE-NUM (0 if none). */
405 static const ]b4_int_type_for([b4_dprec
])[ yydprec
[] =
410 /* YYMERGER[RULE-NUM] -- Index of merging function for rule #RULE-NUM. */
411 static const ]b4_int_type_for([b4_merger
])[ yymerger
[] =
416 /* YYDEFACT[S] -- default rule to reduce with in state S when YYTABLE
417 doesn't specify something else to do. Zero means the default is an
419 static const ]b4_int_type_for([b4_defact
])[ yydefact
[] =
424 /* YYPDEFGOTO[NTERM-NUM]. */
425 static const ]b4_int_type_for([b4_defgoto
])[ yydefgoto
[] =
430 /* YYPACT[STATE-NUM] -- Index in YYTABLE of the portion describing
432 #define YYPACT_NINF ]b4_pact_ninf[
433 static const ]b4_int_type_for([b4_pact
])[ yypact
[] =
438 /* YYPGOTO[NTERM-NUM]. */
439 static const ]b4_int_type_for([b4_pgoto
])[ yypgoto
[] =
444 /* YYTABLE[YYPACT[STATE-NUM]]. What to do in state STATE-NUM. If
445 positive, shift that token. If negative, reduce the rule which
446 number is the opposite. If zero, do what YYDEFACT says.
447 If YYTABLE_NINF, syntax error. */
448 #define YYTABLE_NINF ]b4_table_ninf[
449 static const ]b4_int_type_for([b4_table
])[ yytable
[] =
454 /* YYCONFLP[YYPACT[STATE-NUM]] -- Pointer into YYCONFL of start of
455 list of conflicting reductions corresponding to action entry for
456 state STATE-NUM in yytable. 0 means no conflicts. The list in
457 yyconfl is terminated by a rule number of 0. */
458 static const ]b4_int_type_for([b4_conflict_list_heads
])[ yyconflp
[] =
460 ]b4_conflict_list_heads
[
463 /* YYCONFL[I] -- lists of conflicting rule numbers, each terminated by
464 0, pointed into by YYCONFLP. */
465 ]dnl Do
not use b4_int_type_for here
, since there are places where
466 dnl pointers onto yyconfl are taken
, which type is
"short int *".
467 dnl We probably ought to introduce a type
for confl
.
468 [static const short int yyconfl
[] =
470 ]b4_conflicting_rules
[
473 static const ]b4_int_type_for([b4_check
])[ yycheck
[] =
478 /* YYSTOS[STATE-NUM] -- The (internal number of the) accessing
479 symbol of state STATE-NUM. */
480 static const ]b4_int_type_for([b4_stos
])[ yystos
[] =
486 /* Prevent warning if -Wmissing-prototypes. */
487 ]b4_c_ansi_function_decl([yyparse
], [int], b4_parse_param
)[
489 /* Error token number */
492 /* YYLLOC_DEFAULT -- Set CURRENT to span from RHS[1] to RHS[N].
493 If N is 0, then set CURRENT to the empty location which ends
494 the previous symbol: RHS[0] (always defined). */
497 #define YYRHSLOC(Rhs, K) ((Rhs)[K].yystate.yyloc)
498 #ifndef YYLLOC_DEFAULT
499 # define YYLLOC_DEFAULT(Current, Rhs, N) \
503 (Current).first_line = YYRHSLOC (Rhs, 1).first_line; \
504 (Current).first_column = YYRHSLOC (Rhs, 1).first_column; \
505 (Current).last_line = YYRHSLOC (Rhs, N).last_line; \
506 (Current).last_column = YYRHSLOC (Rhs, N).last_column; \
510 (Current).first_line = (Current).last_line = \
511 YYRHSLOC (Rhs, 0).last_line; \
512 (Current).first_column = (Current).last_column = \
513 YYRHSLOC (Rhs, 0).last_column; \
517 /* YY_LOCATION_PRINT -- Print the location on the stream.
518 This macro was not mandated originally: define only if we know
519 we won't break user code: when these are the locations we know. */
521 # define YY_LOCATION_PRINT(File, Loc) \
522 fprintf (File, "%d.%d-%d.%d", \
523 (Loc).first_line, (Loc).first_column, \
524 (Loc).last_line, (Loc).last_column)
527 #ifndef YYLLOC_DEFAULT
528 # define YYLLOC_DEFAULT(Current, Rhs, N) ((void) 0)
532 #ifndef YY_LOCATION_PRINT
533 # define YY_LOCATION_PRINT(File, Loc) ((void) 0)
537 /* YYLEX -- calling `yylex' with the right arguments. */
538 #define YYLEX ]b4_c_function_call([yylex], [int], b4_lex_param)[
543 #define yynerrs (yystackp->yyerrcnt)
545 #define yychar (yystackp->yyrawchar)
547 #define yylval (yystackp->yyval)
549 #define yylloc (yystackp->yyloc)
550 m4_if(b4_prefix
[], [yy
], [],
551 [#define b4_prefix[]nerrs yynerrs
552 #define b4_prefix[]char yychar
553 #define b4_prefix[]lval yylval
554 #define b4_prefix[]lloc yylloc])],
562 static const int YYEOF
= 0;
563 static const int YYEMPTY
= -2;
565 typedef enum { yyok
, yyaccept
, yyabort
, yyerr
} YYRESULTTAG
;
568 do { YYRESULTTAG yyflag = YYE; if (yyflag != yyok) return yyflag; } \
574 # define YYFPRINTF fprintf
577 # define YYDPRINTF(Args) \
583 ]b4_yy_symbol_print_generate([b4_c_ansi_function_def
])[
585 # define YY_SYMBOL_PRINT(Title, Type, Value, Location) \
589 YYFPRINTF (stderr, "%s ", Title); \
590 yy_symbol_print (stderr, Type, \
591 Value]b4_locations_if([, Location])[]b4_user_args[); \
592 YYFPRINTF (stderr, "\n"); \
596 /* Nonzero means print parse trace. It is left uninitialized so that
597 multiple parsers can coexist. */
602 # define YYDPRINTF(Args)
603 # define YY_SYMBOL_PRINT(Title, Type, Value, Location)
605 #endif /* !YYDEBUG */
607 /* YYINITDEPTH -- initial size of the parser's stacks. */
609 # define YYINITDEPTH ]b4_stack_depth_init[
612 /* YYMAXDEPTH -- maximum size the stacks can grow to (effective only
613 if the built-in stack extension method is used).
615 Do not make this value too large; the results are undefined if
616 SIZE_MAX < YYMAXDEPTH * sizeof (GLRStackItem)
617 evaluated with infinite-precision integer arithmetic. */
620 # define YYMAXDEPTH ]b4_stack_depth_max[
623 /* Minimum number of free items on the stack allowed after an
624 allocation. This is to allow allocation and initialization
625 to be completed by functions that call yyexpandGLRStack before the
626 stack is expanded, thus insuring that all necessary pointers get
627 properly redirected to new data. */
630 #ifndef YYSTACKEXPANDABLE
631 # if (! defined __cplusplus \
632 || (]b4_locations_if([[defined YYLTYPE_IS_TRIVIAL && YYLTYPE_IS_TRIVIAL \
633 && ]])[defined YYSTYPE_IS_TRIVIAL && YYSTYPE_IS_TRIVIAL))
634 # define YYSTACKEXPANDABLE 1
636 # define YYSTACKEXPANDABLE 0
640 #if YYSTACKEXPANDABLE
641 # define YY_RESERVE_GLRSTACK(Yystack) \
643 if (Yystack->yyspaceLeft < YYHEADROOM) \
644 yyexpandGLRStack (Yystack); \
647 # define YY_RESERVE_GLRSTACK(Yystack) \
649 if (Yystack->yyspaceLeft < YYHEADROOM) \
650 yyMemoryExhausted (Yystack); \
658 # if defined __GLIBC__ && defined _STRING_H && defined _GNU_SOURCE
659 # define yystpcpy stpcpy
661 /* Copy YYSRC to YYDEST, returning the address of the terminating '\0' in
664 yystpcpy (char *yydest
, const char *yysrc
)
667 const char *yys
= yysrc
;
669 while ((*yyd
++ = *yys
++) != '\0')
678 /* Copy to YYRES the contents of YYSTR after stripping away unnecessary
679 quotes and backslashes, so that it's suitable for yyerror. The
680 heuristic is that double-quoting is unnecessary unless the string
681 contains an apostrophe, a comma, or backslash (other than
682 backslash-backslash). YYSTR is taken from yytname. If YYRES is
683 null, do not copy; instead, return the length of what the result
686 yytnamerr (char *yyres
, const char *yystr
)
691 char const *yyp
= yystr
;
698 goto do_not_strip_quotes
;
702 goto do_not_strip_quotes
;
715 do_not_strip_quotes
: ;
719 return strlen (yystr
);
721 return yystpcpy (yyres
, yystr
) - yyres
;
725 #endif /* !YYERROR_VERBOSE */
727 /** State numbers, as in LALR(1) machine */
728 typedef int yyStateNum
;
730 /** Rule numbers, as in LALR(1) machine */
731 typedef int yyRuleNum
;
733 /** Grammar symbol */
734 typedef short int yySymbol
;
736 /** Item references, as in LALR(1) machine */
737 typedef short int yyItemNum
;
739 typedef struct yyGLRState yyGLRState
;
740 typedef struct yyGLRStateSet yyGLRStateSet
;
741 typedef struct yySemanticOption yySemanticOption
;
742 typedef union yyGLRStackItem yyGLRStackItem
;
743 typedef struct yyGLRStack yyGLRStack
;
746 /** Type tag: always true. */
748 /** Type tag for yysemantics. If true, yysval applies, otherwise
749 * yyfirstVal applies. */
751 /** Number of corresponding LALR(1) machine state. */
752 yyStateNum yylrState
;
753 /** Preceding state in this stack */
755 /** Source position of the first token produced by my symbol */
758 /** First in a chain of alternative reductions producing the
759 * non-terminal corresponding to this state, threaded through
761 yySemanticOption
* yyfirstVal
;
762 /** Semantic value for this state. */
765 /** Source location for this state. */
769 struct yyGLRStateSet
{
770 yyGLRState
** yystates
;
771 /** During nondeterministic operation, yylookaheadNeeds tracks which
772 * stacks have actually needed the current lookahead. During deterministic
773 * operation, yylookaheadNeeds[0] is not maintained since it would merely
774 * duplicate yychar != YYEMPTY. */
775 yybool
* yylookaheadNeeds
;
776 size_t yysize
, yycapacity
;
779 struct yySemanticOption
{
780 /** Type tag: always false. */
782 /** Rule number for this reduction */
784 /** The last RHS state in the list of states to be reduced. */
786 /** The lookahead for this reduction. */
790 /** Next sibling in chain of options. To facilitate merging,
791 * options are chained in decreasing order by address. */
792 yySemanticOption
* yynext
;
795 /** Type of the items in the GLR stack. The yyisState field
796 * indicates which item of the union is valid. */
797 union yyGLRStackItem
{
799 yySemanticOption yyoption
;
804 ]b4_locations_if([[ /* To compute the location of the error token. */
805 yyGLRStackItem yyerror_range
[3];]])[
813 YYJMP_BUF yyexception_buffer
;
814 yyGLRStackItem
* yyitems
;
815 yyGLRStackItem
* yynextFree
;
817 yyGLRState
* yysplitPoint
;
818 yyGLRState
* yylastDeleted
;
819 yyGLRStateSet yytops
;
822 #if YYSTACKEXPANDABLE
823 static void yyexpandGLRStack (yyGLRStack
* yystackp
);
826 static void yyFail (yyGLRStack
* yystackp
]b4_pure_formals
[, const char* yymsg
)
827 __attribute__ ((__noreturn__
));
829 yyFail (yyGLRStack
* yystackp
]b4_pure_formals
[, const char* yymsg
)
832 yyerror (]b4_yyerror_args
[yymsg
);
833 YYLONGJMP (yystackp
->yyexception_buffer
, 1);
836 static void yyMemoryExhausted (yyGLRStack
* yystackp
)
837 __attribute__ ((__noreturn__
));
839 yyMemoryExhausted (yyGLRStack
* yystackp
)
841 YYLONGJMP (yystackp
->yyexception_buffer
, 2);
844 #if YYDEBUG || YYERROR_VERBOSE
845 /** A printable representation of TOKEN. */
846 static inline const char*
847 yytokenName (yySymbol yytoken
)
849 if (yytoken
== YYEMPTY
)
852 return yytname
[yytoken
];
856 /** Fill in YYVSP[YYLOW1 .. YYLOW0-1] from the chain of states starting
857 * at YYVSP[YYLOW0].yystate.yypred. Leaves YYVSP[YYLOW1].yystate.yypred
858 * containing the pointer to the next state in the chain. */
859 static void yyfillin (yyGLRStackItem
*, int, int) __attribute__ ((__unused__
));
861 yyfillin (yyGLRStackItem
*yyvsp
, int yylow0
, int yylow1
)
865 s
= yyvsp
[yylow0
].yystate
.yypred
;
866 for (i
= yylow0
-1; i
>= yylow1
; i
-= 1)
868 YYASSERT (s
->yyresolved
);
869 yyvsp
[i
].yystate
.yyresolved
= yytrue
;
870 yyvsp
[i
].yystate
.yysemantics
.yysval
= s
->yysemantics
.yysval
;
871 yyvsp
[i
].yystate
.yyloc
= s
->yyloc
;
872 s
= yyvsp
[i
].yystate
.yypred
= s
->yypred
;
876 /* Do nothing if YYNORMAL or if *YYLOW <= YYLOW1. Otherwise, fill in
877 * YYVSP[YYLOW1 .. *YYLOW-1] as in yyfillin and set *YYLOW = YYLOW1.
878 * For convenience, always return YYLOW1. */
879 static inline int yyfill (yyGLRStackItem
*, int *, int, yybool
)
880 __attribute__ ((__unused__
));
882 yyfill (yyGLRStackItem
*yyvsp
, int *yylow
, int yylow1
, yybool yynormal
)
884 if (!yynormal
&& yylow1
< *yylow
)
886 yyfillin (yyvsp
, *yylow
, yylow1
);
892 /** Perform user action for rule number YYN, with RHS length YYRHSLEN,
893 * and top stack item YYVSP. YYLVALP points to place to put semantic
894 * value ($$), and yylocp points to place for location information
895 * (@@$). Returns yyok for normal return, yyaccept for YYACCEPT,
896 * yyerr for YYERROR, yyabort for YYABORT. */
897 /*ARGSUSED*/ static YYRESULTTAG
898 yyuserAction (yyRuleNum yyn
, int yyrhslen
, yyGLRStackItem
* yyvsp
,
900 YYLTYPE
* YYOPTIONAL_LOC (yylocp
),
904 yybool yynormal
__attribute__ ((__unused__
)) =
905 (yystackp
->yysplitPoint
== NULL
);
907 ]b4_parse_param_use
[]dnl
909 # define yyerrok (yystackp->yyerrState = 0)
911 # define YYACCEPT return yyaccept
913 # define YYABORT return yyabort
915 # define YYERROR return yyerrok, yyerr
917 # define YYRECOVERING() (yystackp->yyerrState != 0)
919 # define yyclearin (yychar = YYEMPTY)
921 # define YYFILL(N) yyfill (yyvsp, &yylow, N, yynormal)
923 # define YYBACKUP(Token, Value) \
924 return yyerror (]b4_yyerror_args[YY_("syntax error: cannot back up")), \
929 *yyvalp
= yyval_default
;
931 *yyvalp
= yyvsp
[YYFILL (1-yyrhslen
)].yystate
.yysemantics
.yysval
;
932 YYLLOC_DEFAULT ((*yylocp
), (yyvsp
- yyrhslen
), yyrhslen
);
933 ]b4_locations_if([[ yystackp
->yyerror_range
[1].yystate
.yyloc
= *yylocp
;
938 /* Line __line__ of glr.c. */
939 b4_syncline([@oline@
], [@ofile@
])[
954 /*ARGSUSED*/ static void
955 yyuserMerge (int yyn
, YYSTYPE
* yy0
, YYSTYPE
* yy1
)
967 /* Bison grammar-table manipulation. */
969 ]b4_yydestruct_generate([b4_c_ansi_function_def
])[
971 /** Number of symbols composing the right hand side of rule #RULE. */
973 yyrhsLength (yyRuleNum yyrule
)
979 yydestroyGLRState (char const *yymsg
, yyGLRState
*yys
]b4_user_formals
[)
982 yydestruct (yymsg
, yystos
[yys
->yylrState
],
983 &yys
->yysemantics
.yysval
]b4_locations_if([, &yys
->yyloc
])[]b4_user_args
[);
989 if (yys
->yysemantics
.yyfirstVal
)
990 YYFPRINTF (stderr
, "%s unresolved ", yymsg
);
992 YYFPRINTF (stderr
, "%s incomplete ", yymsg
);
993 yy_symbol_print (stderr
, yystos
[yys
->yylrState
],
994 NULL
]b4_locations_if([, &yys
->yyloc
])[]b4_user_args
[);
995 YYFPRINTF (stderr
, "\n");
999 if (yys
->yysemantics
.yyfirstVal
)
1001 yySemanticOption
*yyoption
= yys
->yysemantics
.yyfirstVal
;
1004 for (yyrh
= yyoption
->yystate
, yyn
= yyrhsLength (yyoption
->yyrule
);
1006 yyrh
= yyrh
->yypred
, yyn
-= 1)
1007 yydestroyGLRState (yymsg
, yyrh
]b4_user_args
[);
1012 /** Left-hand-side symbol for rule #RULE. */
1013 static inline yySymbol
1014 yylhsNonterm (yyRuleNum yyrule
)
1016 return yyr1
[yyrule
];
1019 #define yyis_pact_ninf(yystate) \
1020 ]m4_if(m4_eval(b4_pact_ninf < b4_pact_min), [1],
1022 [((yystate
) == YYPACT_NINF
)])[
1024 /** True iff LR state STATE has only a default reduction (regardless
1026 static inline yybool
1027 yyisDefaultedState (yyStateNum yystate
)
1029 return yyis_pact_ninf (yypact
[yystate
]);
1032 /** The default reduction for STATE, assuming it has one. */
1033 static inline yyRuleNum
1034 yydefaultAction (yyStateNum yystate
)
1036 return yydefact
[yystate
];
1039 #define yyis_table_ninf(yytable_value) \
1040 ]m4_if(m4_eval(b4_table_ninf < b4_table_min), [1],
1042 [((yytable_value
) == YYTABLE_NINF
)])[
1044 /** Set *YYACTION to the action to take in YYSTATE on seeing YYTOKEN.
1046 * R < 0: Reduce on rule -R.
1048 * R > 0: Shift to state R.
1049 * Set *CONFLICTS to a pointer into yyconfl to 0-terminated list of
1050 * conflicting reductions.
1053 yygetLRActions (yyStateNum yystate
, int yytoken
,
1054 int* yyaction
, const short int** yyconflicts
)
1056 int yyindex
= yypact
[yystate
] + yytoken
;
1057 if (yyindex
< 0 || YYLAST
< yyindex
|| yycheck
[yyindex
] != yytoken
)
1059 *yyaction
= -yydefact
[yystate
];
1060 *yyconflicts
= yyconfl
;
1062 else if (! yyis_table_ninf (yytable
[yyindex
]))
1064 *yyaction
= yytable
[yyindex
];
1065 *yyconflicts
= yyconfl
+ yyconflp
[yyindex
];
1070 *yyconflicts
= yyconfl
+ yyconflp
[yyindex
];
1074 static inline yyStateNum
1075 yyLRgotoState (yyStateNum yystate
, yySymbol yylhs
)
1078 yyr
= yypgoto
[yylhs
- YYNTOKENS
] + yystate
;
1079 if (0 <= yyr
&& yyr
<= YYLAST
&& yycheck
[yyr
] == yystate
)
1080 return yytable
[yyr
];
1082 return yydefgoto
[yylhs
- YYNTOKENS
];
1085 static inline yybool
1086 yyisShiftAction (int yyaction
)
1088 return 0 < yyaction
;
1091 static inline yybool
1092 yyisErrorAction (int yyaction
)
1094 return yyaction
== 0;
1099 /** Return a fresh GLRStackItem. Callers should call
1100 * YY_RESERVE_GLRSTACK afterwards to make sure there is sufficient
1103 static inline yyGLRStackItem
*
1104 yynewGLRStackItem (yyGLRStack
* yystackp
, yybool yyisState
)
1106 yyGLRStackItem
* yynewItem
= yystackp
->yynextFree
;
1107 yystackp
->yyspaceLeft
-= 1;
1108 yystackp
->yynextFree
+= 1;
1109 yynewItem
->yystate
.yyisState
= yyisState
;
1113 /** Add a new semantic action that will execute the action for rule
1114 * RULENUM on the semantic values in RHS to the list of
1115 * alternative actions for STATE. Assumes that RHS comes from
1116 * stack #K of *STACKP. */
1118 yyaddDeferredAction (yyGLRStack
* yystackp
, size_t yyk
, yyGLRState
* yystate
,
1119 yyGLRState
* rhs
, yyRuleNum yyrule
)
1121 yySemanticOption
* yynewOption
=
1122 &yynewGLRStackItem (yystackp
, yyfalse
)->yyoption
;
1123 yynewOption
->yystate
= rhs
;
1124 yynewOption
->yyrule
= yyrule
;
1125 if (yystackp
->yytops
.yylookaheadNeeds
[yyk
])
1127 yynewOption
->yyrawchar
= yychar
;
1128 yynewOption
->yyval
= yylval
;
1129 yynewOption
->yyloc
= yylloc
;
1132 yynewOption
->yyrawchar
= YYEMPTY
;
1133 yynewOption
->yynext
= yystate
->yysemantics
.yyfirstVal
;
1134 yystate
->yysemantics
.yyfirstVal
= yynewOption
;
1136 YY_RESERVE_GLRSTACK (yystackp
);
1141 /** Initialize SET to a singleton set containing an empty stack. */
1143 yyinitStateSet (yyGLRStateSet
* yyset
)
1146 yyset
->yycapacity
= 16;
1147 yyset
->yystates
= (yyGLRState
**) YYMALLOC (16 * sizeof yyset
->yystates
[0]);
1148 if (! yyset
->yystates
)
1150 yyset
->yystates
[0] = NULL
;
1151 yyset
->yylookaheadNeeds
=
1152 (yybool
*) YYMALLOC (16 * sizeof yyset
->yylookaheadNeeds
[0]);
1153 if (! yyset
->yylookaheadNeeds
)
1155 YYFREE (yyset
->yystates
);
1161 static void yyfreeStateSet (yyGLRStateSet
* yyset
)
1163 YYFREE (yyset
->yystates
);
1164 YYFREE (yyset
->yylookaheadNeeds
);
1167 /** Initialize STACK to a single empty stack, with total maximum
1168 * capacity for all stacks of SIZE. */
1170 yyinitGLRStack (yyGLRStack
* yystackp
, size_t yysize
)
1172 yystackp
->yyerrState
= 0;
1174 yystackp
->yyspaceLeft
= yysize
;
1176 (yyGLRStackItem
*) YYMALLOC (yysize
* sizeof yystackp
->yynextFree
[0]);
1177 if (!yystackp
->yyitems
)
1179 yystackp
->yynextFree
= yystackp
->yyitems
;
1180 yystackp
->yysplitPoint
= NULL
;
1181 yystackp
->yylastDeleted
= NULL
;
1182 return yyinitStateSet (&yystackp
->yytops
);
1186 #if YYSTACKEXPANDABLE
1187 # define YYRELOC(YYFROMITEMS,YYTOITEMS,YYX,YYTYPE) \
1188 &((YYTOITEMS) - ((YYFROMITEMS) - (yyGLRStackItem*) (YYX)))->YYTYPE
1190 /** If STACK is expandable, extend it. WARNING: Pointers into the
1191 stack from outside should be considered invalid after this call.
1192 We always expand when there are 1 or fewer items left AFTER an
1193 allocation, so that we can avoid having external pointers exist
1194 across an allocation. */
1196 yyexpandGLRStack (yyGLRStack
* yystackp
)
1198 yyGLRStackItem
* yynewItems
;
1199 yyGLRStackItem
* yyp0
, *yyp1
;
1200 size_t yysize
, yynewSize
;
1202 yysize
= yystackp
->yynextFree
- yystackp
->yyitems
;
1203 if (YYMAXDEPTH
- YYHEADROOM
< yysize
)
1204 yyMemoryExhausted (yystackp
);
1205 yynewSize
= 2*yysize
;
1206 if (YYMAXDEPTH
< yynewSize
)
1207 yynewSize
= YYMAXDEPTH
;
1208 yynewItems
= (yyGLRStackItem
*) YYMALLOC (yynewSize
* sizeof yynewItems
[0]);
1210 yyMemoryExhausted (yystackp
);
1211 for (yyp0
= yystackp
->yyitems
, yyp1
= yynewItems
, yyn
= yysize
;
1213 yyn
-= 1, yyp0
+= 1, yyp1
+= 1)
1216 if (*(yybool
*) yyp0
)
1218 yyGLRState
* yys0
= &yyp0
->yystate
;
1219 yyGLRState
* yys1
= &yyp1
->yystate
;
1220 if (yys0
->yypred
!= NULL
)
1222 YYRELOC (yyp0
, yyp1
, yys0
->yypred
, yystate
);
1223 if (! yys0
->yyresolved
&& yys0
->yysemantics
.yyfirstVal
!= NULL
)
1224 yys1
->yysemantics
.yyfirstVal
=
1225 YYRELOC(yyp0
, yyp1
, yys0
->yysemantics
.yyfirstVal
, yyoption
);
1229 yySemanticOption
* yyv0
= &yyp0
->yyoption
;
1230 yySemanticOption
* yyv1
= &yyp1
->yyoption
;
1231 if (yyv0
->yystate
!= NULL
)
1232 yyv1
->yystate
= YYRELOC (yyp0
, yyp1
, yyv0
->yystate
, yystate
);
1233 if (yyv0
->yynext
!= NULL
)
1234 yyv1
->yynext
= YYRELOC (yyp0
, yyp1
, yyv0
->yynext
, yyoption
);
1237 if (yystackp
->yysplitPoint
!= NULL
)
1238 yystackp
->yysplitPoint
= YYRELOC (yystackp
->yyitems
, yynewItems
,
1239 yystackp
->yysplitPoint
, yystate
);
1241 for (yyn
= 0; yyn
< yystackp
->yytops
.yysize
; yyn
+= 1)
1242 if (yystackp
->yytops
.yystates
[yyn
] != NULL
)
1243 yystackp
->yytops
.yystates
[yyn
] =
1244 YYRELOC (yystackp
->yyitems
, yynewItems
,
1245 yystackp
->yytops
.yystates
[yyn
], yystate
);
1246 YYFREE (yystackp
->yyitems
);
1247 yystackp
->yyitems
= yynewItems
;
1248 yystackp
->yynextFree
= yynewItems
+ yysize
;
1249 yystackp
->yyspaceLeft
= yynewSize
- yysize
;
1254 yyfreeGLRStack (yyGLRStack
* yystackp
)
1256 YYFREE (yystackp
->yyitems
);
1257 yyfreeStateSet (&yystackp
->yytops
);
1260 /** Assuming that S is a GLRState somewhere on STACK, update the
1261 * splitpoint of STACK, if needed, so that it is at least as deep as
1264 yyupdateSplit (yyGLRStack
* yystackp
, yyGLRState
* yys
)
1266 if (yystackp
->yysplitPoint
!= NULL
&& yystackp
->yysplitPoint
> yys
)
1267 yystackp
->yysplitPoint
= yys
;
1270 /** Invalidate stack #K in STACK. */
1272 yymarkStackDeleted (yyGLRStack
* yystackp
, size_t yyk
)
1274 if (yystackp
->yytops
.yystates
[yyk
] != NULL
)
1275 yystackp
->yylastDeleted
= yystackp
->yytops
.yystates
[yyk
];
1276 yystackp
->yytops
.yystates
[yyk
] = NULL
;
1279 /** Undelete the last stack that was marked as deleted. Can only be
1280 done once after a deletion, and only when all other stacks have
1283 yyundeleteLastStack (yyGLRStack
* yystackp
)
1285 if (yystackp
->yylastDeleted
== NULL
|| yystackp
->yytops
.yysize
!= 0)
1287 yystackp
->yytops
.yystates
[0] = yystackp
->yylastDeleted
;
1288 yystackp
->yytops
.yysize
= 1;
1289 YYDPRINTF ((stderr
, "Restoring last deleted stack as stack #0.\n"));
1290 yystackp
->yylastDeleted
= NULL
;
1294 yyremoveDeletes (yyGLRStack
* yystackp
)
1298 while (yyj
< yystackp
->yytops
.yysize
)
1300 if (yystackp
->yytops
.yystates
[yyi
] == NULL
)
1304 YYDPRINTF ((stderr
, "Removing dead stacks.\n"));
1306 yystackp
->yytops
.yysize
-= 1;
1310 yystackp
->yytops
.yystates
[yyj
] = yystackp
->yytops
.yystates
[yyi
];
1311 /* In the current implementation, it's unnecessary to copy
1312 yystackp->yytops.yylookaheadNeeds[yyi] since, after
1313 yyremoveDeletes returns, the parser immediately either enters
1314 deterministic operation or shifts a token. However, it doesn't
1315 hurt, and the code might evolve to need it. */
1316 yystackp
->yytops
.yylookaheadNeeds
[yyj
] =
1317 yystackp
->yytops
.yylookaheadNeeds
[yyi
];
1320 YYDPRINTF ((stderr
, "Rename stack %lu -> %lu.\n",
1321 (unsigned long int) yyi
, (unsigned long int) yyj
));
1329 /** Shift to a new state on stack #K of STACK, corresponding to LR state
1330 * LRSTATE, at input position POSN, with (resolved) semantic value SVAL. */
1332 yyglrShift (yyGLRStack
* yystackp
, size_t yyk
, yyStateNum yylrState
,
1334 YYSTYPE
* yyvalp
, YYLTYPE
* yylocp
)
1336 yyGLRState
* yynewState
= &yynewGLRStackItem (yystackp
, yytrue
)->yystate
;
1338 yynewState
->yylrState
= yylrState
;
1339 yynewState
->yyposn
= yyposn
;
1340 yynewState
->yyresolved
= yytrue
;
1341 yynewState
->yypred
= yystackp
->yytops
.yystates
[yyk
];
1342 yynewState
->yysemantics
.yysval
= *yyvalp
;
1343 yynewState
->yyloc
= *yylocp
;
1344 yystackp
->yytops
.yystates
[yyk
] = yynewState
;
1346 YY_RESERVE_GLRSTACK (yystackp
);
1349 /** Shift stack #K of YYSTACK, to a new state corresponding to LR
1350 * state YYLRSTATE, at input position YYPOSN, with the (unresolved)
1351 * semantic value of YYRHS under the action for YYRULE. */
1353 yyglrShiftDefer (yyGLRStack
* yystackp
, size_t yyk
, yyStateNum yylrState
,
1354 size_t yyposn
, yyGLRState
* rhs
, yyRuleNum yyrule
)
1356 yyGLRState
* yynewState
= &yynewGLRStackItem (yystackp
, yytrue
)->yystate
;
1358 yynewState
->yylrState
= yylrState
;
1359 yynewState
->yyposn
= yyposn
;
1360 yynewState
->yyresolved
= yyfalse
;
1361 yynewState
->yypred
= yystackp
->yytops
.yystates
[yyk
];
1362 yynewState
->yysemantics
.yyfirstVal
= NULL
;
1363 yystackp
->yytops
.yystates
[yyk
] = yynewState
;
1365 /* Invokes YY_RESERVE_GLRSTACK. */
1366 yyaddDeferredAction (yystackp
, yyk
, yynewState
, rhs
, yyrule
);
1369 /** Pop the symbols consumed by reduction #RULE from the top of stack
1370 * #K of STACK, and perform the appropriate semantic action on their
1371 * semantic values. Assumes that all ambiguities in semantic values
1372 * have been previously resolved. Set *VALP to the resulting value,
1373 * and *LOCP to the computed location (if any). Return value is as
1374 * for userAction. */
1375 static inline YYRESULTTAG
1376 yydoAction (yyGLRStack
* yystackp
, size_t yyk
, yyRuleNum yyrule
,
1377 YYSTYPE
* yyvalp
, YYLTYPE
* yylocp
]b4_user_formals
[)
1379 int yynrhs
= yyrhsLength (yyrule
);
1381 if (yystackp
->yysplitPoint
== NULL
)
1383 /* Standard special case: single stack. */
1384 yyGLRStackItem
* rhs
= (yyGLRStackItem
*) yystackp
->yytops
.yystates
[yyk
];
1385 YYASSERT (yyk
== 0);
1386 yystackp
->yynextFree
-= yynrhs
;
1387 yystackp
->yyspaceLeft
+= yynrhs
;
1388 yystackp
->yytops
.yystates
[0] = & yystackp
->yynextFree
[-1].yystate
;
1389 return yyuserAction (yyrule
, yynrhs
, rhs
,
1390 yyvalp
, yylocp
, yystackp
]b4_user_args
[);
1394 /* At present, doAction is never called in nondeterministic
1395 * mode, so this branch is never taken. It is here in
1396 * anticipation of a future feature that will allow immediate
1397 * evaluation of selected actions in nondeterministic mode. */
1400 yyGLRStackItem yyrhsVals
[YYMAXRHS
+ YYMAXLEFT
+ 1];
1401 yys
= yyrhsVals
[YYMAXRHS
+ YYMAXLEFT
].yystate
.yypred
1402 = yystackp
->yytops
.yystates
[yyk
];]b4_locations_if([[
1404 /* Set default location. */
1405 yyrhsVals
[YYMAXRHS
+ YYMAXLEFT
- 1].yystate
.yyloc
= yys
->yyloc
;]])[
1406 for (yyi
= 0; yyi
< yynrhs
; yyi
+= 1)
1411 yyupdateSplit (yystackp
, yys
);
1412 yystackp
->yytops
.yystates
[yyk
] = yys
;
1413 return yyuserAction (yyrule
, yynrhs
, yyrhsVals
+ YYMAXRHS
+ YYMAXLEFT
- 1,
1414 yyvalp
, yylocp
, yystackp
]b4_user_args
[);
1419 # define YY_REDUCE_PRINT(Args)
1421 # define YY_REDUCE_PRINT(Args) \
1424 yy_reduce_print Args; \
1427 /*----------------------------------------------------------.
1428 | Report that the RULE is going to be reduced on stack #K. |
1429 `----------------------------------------------------------*/
1431 /*ARGSUSED*/ static inline void
1432 yy_reduce_print (yyGLRStack
* yystackp
, size_t yyk
, yyRuleNum yyrule
,
1433 YYSTYPE
* yyvalp
, YYLTYPE
* yylocp
]b4_user_formals
[)
1435 int yynrhs
= yyrhsLength (yyrule
);
1436 yybool yynormal
__attribute__ ((__unused__
)) =
1437 (yystackp
->yysplitPoint
== NULL
);
1438 yyGLRStackItem
* yyvsp
= (yyGLRStackItem
*) yystackp
->yytops
.yystates
[yyk
];
1443 ]b4_parse_param_use
[]dnl
1444 [ YYFPRINTF (stderr
, "Reducing stack %lu by rule %d (line %lu):\n",
1445 (unsigned long int) yyk
, yyrule
- 1,
1446 (unsigned long int) yyrline
[yyrule
]);
1447 /* The symbols being reduced. */
1448 for (yyi
= 0; yyi
< yynrhs
; yyi
++)
1450 fprintf (stderr
, " $%d = ", yyi
+ 1);
1451 yy_symbol_print (stderr
, yyrhs
[yyprhs
[yyrule
] + yyi
],
1452 &]b4_rhs_value(yynrhs
, yyi
+ 1)[
1453 ]b4_locations_if([, &]b4_rhs_location(yynrhs
, yyi
+ 1))[]dnl
1455 fprintf (stderr
, "\n");
1460 /** Pop items off stack #K of STACK according to grammar rule RULE,
1461 * and push back on the resulting nonterminal symbol. Perform the
1462 * semantic action associated with RULE and store its value with the
1463 * newly pushed state, if FORCEEVAL or if STACK is currently
1464 * unambiguous. Otherwise, store the deferred semantic action with
1465 * the new state. If the new state would have an identical input
1466 * position, LR state, and predecessor to an existing state on the stack,
1467 * it is identified with that existing state, eliminating stack #K from
1468 * the STACK. In this case, the (necessarily deferred) semantic value is
1469 * added to the options for the existing state's semantic value.
1471 static inline YYRESULTTAG
1472 yyglrReduce (yyGLRStack
* yystackp
, size_t yyk
, yyRuleNum yyrule
,
1473 yybool yyforceEval
]b4_user_formals
[)
1475 size_t yyposn
= yystackp
->yytops
.yystates
[yyk
]->yyposn
;
1477 if (yyforceEval
|| yystackp
->yysplitPoint
== NULL
)
1482 YY_REDUCE_PRINT ((yystackp
, yyk
, yyrule
, &yysval
, &yyloc
]b4_user_args
[));
1483 YYCHK (yydoAction (yystackp
, yyk
, yyrule
, &yysval
,
1484 &yyloc
]b4_user_args
[));
1485 YY_SYMBOL_PRINT ("-> $$ =", yyr1
[yyrule
], &yysval
, &yyloc
);
1486 yyglrShift (yystackp
, yyk
,
1487 yyLRgotoState (yystackp
->yytops
.yystates
[yyk
]->yylrState
,
1488 yylhsNonterm (yyrule
)),
1489 yyposn
, &yysval
, &yyloc
);
1495 yyGLRState
* yys
, *yys0
= yystackp
->yytops
.yystates
[yyk
];
1496 yyStateNum yynewLRState
;
1498 for (yys
= yystackp
->yytops
.yystates
[yyk
], yyn
= yyrhsLength (yyrule
);
1504 yyupdateSplit (yystackp
, yys
);
1505 yynewLRState
= yyLRgotoState (yys
->yylrState
, yylhsNonterm (yyrule
));
1507 "Reduced stack %lu by rule #%d; action deferred. Now in state %d.\n",
1508 (unsigned long int) yyk
, yyrule
- 1, yynewLRState
));
1509 for (yyi
= 0; yyi
< yystackp
->yytops
.yysize
; yyi
+= 1)
1510 if (yyi
!= yyk
&& yystackp
->yytops
.yystates
[yyi
] != NULL
)
1512 yyGLRState
* yyp
, *yysplit
= yystackp
->yysplitPoint
;
1513 yyp
= yystackp
->yytops
.yystates
[yyi
];
1514 while (yyp
!= yys
&& yyp
!= yysplit
&& yyp
->yyposn
>= yyposn
)
1516 if (yyp
->yylrState
== yynewLRState
&& yyp
->yypred
== yys
)
1518 yyaddDeferredAction (yystackp
, yyk
, yyp
, yys0
, yyrule
);
1519 yymarkStackDeleted (yystackp
, yyk
);
1520 YYDPRINTF ((stderr
, "Merging stack %lu into stack %lu.\n",
1521 (unsigned long int) yyk
,
1522 (unsigned long int) yyi
));
1528 yystackp
->yytops
.yystates
[yyk
] = yys
;
1529 yyglrShiftDefer (yystackp
, yyk
, yynewLRState
, yyposn
, yys0
, yyrule
);
1535 yysplitStack (yyGLRStack
* yystackp
, size_t yyk
)
1537 if (yystackp
->yysplitPoint
== NULL
)
1539 YYASSERT (yyk
== 0);
1540 yystackp
->yysplitPoint
= yystackp
->yytops
.yystates
[yyk
];
1542 if (yystackp
->yytops
.yysize
>= yystackp
->yytops
.yycapacity
)
1544 yyGLRState
** yynewStates
;
1545 yybool
* yynewLookaheadNeeds
;
1549 if (yystackp
->yytops
.yycapacity
1550 > (YYSIZEMAX
/ (2 * sizeof yynewStates
[0])))
1551 yyMemoryExhausted (yystackp
);
1552 yystackp
->yytops
.yycapacity
*= 2;
1555 (yyGLRState
**) YYREALLOC (yystackp
->yytops
.yystates
,
1556 (yystackp
->yytops
.yycapacity
1557 * sizeof yynewStates
[0]));
1558 if (yynewStates
== NULL
)
1559 yyMemoryExhausted (yystackp
);
1560 yystackp
->yytops
.yystates
= yynewStates
;
1562 yynewLookaheadNeeds
=
1563 (yybool
*) YYREALLOC (yystackp
->yytops
.yylookaheadNeeds
,
1564 (yystackp
->yytops
.yycapacity
1565 * sizeof yynewLookaheadNeeds
[0]));
1566 if (yynewLookaheadNeeds
== NULL
)
1567 yyMemoryExhausted (yystackp
);
1568 yystackp
->yytops
.yylookaheadNeeds
= yynewLookaheadNeeds
;
1570 yystackp
->yytops
.yystates
[yystackp
->yytops
.yysize
]
1571 = yystackp
->yytops
.yystates
[yyk
];
1572 yystackp
->yytops
.yylookaheadNeeds
[yystackp
->yytops
.yysize
]
1573 = yystackp
->yytops
.yylookaheadNeeds
[yyk
];
1574 yystackp
->yytops
.yysize
+= 1;
1575 return yystackp
->yytops
.yysize
-1;
1578 /** True iff Y0 and Y1 represent identical options at the top level.
1579 * That is, they represent the same rule applied to RHS symbols
1580 * that produce the same terminal symbols. */
1582 yyidenticalOptions (yySemanticOption
* yyy0
, yySemanticOption
* yyy1
)
1584 if (yyy0
->yyrule
== yyy1
->yyrule
)
1586 yyGLRState
*yys0
, *yys1
;
1588 for (yys0
= yyy0
->yystate
, yys1
= yyy1
->yystate
,
1589 yyn
= yyrhsLength (yyy0
->yyrule
);
1591 yys0
= yys0
->yypred
, yys1
= yys1
->yypred
, yyn
-= 1)
1592 if (yys0
->yyposn
!= yys1
->yyposn
)
1600 /** Assuming identicalOptions (Y0,Y1), destructively merge the
1601 * alternative semantic values for the RHS-symbols of Y1 and Y0. */
1603 yymergeOptionSets (yySemanticOption
* yyy0
, yySemanticOption
* yyy1
)
1605 yyGLRState
*yys0
, *yys1
;
1607 for (yys0
= yyy0
->yystate
, yys1
= yyy1
->yystate
,
1608 yyn
= yyrhsLength (yyy0
->yyrule
);
1610 yys0
= yys0
->yypred
, yys1
= yys1
->yypred
, yyn
-= 1)
1614 else if (yys0
->yyresolved
)
1616 yys1
->yyresolved
= yytrue
;
1617 yys1
->yysemantics
.yysval
= yys0
->yysemantics
.yysval
;
1619 else if (yys1
->yyresolved
)
1621 yys0
->yyresolved
= yytrue
;
1622 yys0
->yysemantics
.yysval
= yys1
->yysemantics
.yysval
;
1626 yySemanticOption
** yyz0p
;
1627 yySemanticOption
* yyz1
;
1628 yyz0p
= &yys0
->yysemantics
.yyfirstVal
;
1629 yyz1
= yys1
->yysemantics
.yyfirstVal
;
1630 while (YYID (yytrue
))
1632 if (yyz1
== *yyz0p
|| yyz1
== NULL
)
1634 else if (*yyz0p
== NULL
)
1639 else if (*yyz0p
< yyz1
)
1641 yySemanticOption
* yyz
= *yyz0p
;
1643 yyz1
= yyz1
->yynext
;
1644 (*yyz0p
)->yynext
= yyz
;
1646 yyz0p
= &(*yyz0p
)->yynext
;
1648 yys1
->yysemantics
.yyfirstVal
= yys0
->yysemantics
.yyfirstVal
;
1653 /** Y0 and Y1 represent two possible actions to take in a given
1654 * parsing state; return 0 if no combination is possible,
1655 * 1 if user-mergeable, 2 if Y0 is preferred, 3 if Y1 is preferred. */
1657 yypreference (yySemanticOption
* y0
, yySemanticOption
* y1
)
1659 yyRuleNum r0
= y0
->yyrule
, r1
= y1
->yyrule
;
1660 int p0
= yydprec
[r0
], p1
= yydprec
[r1
];
1664 if (yymerger
[r0
] == 0 || yymerger
[r0
] != yymerger
[r1
])
1669 if (p0
== 0 || p1
== 0)
1678 static YYRESULTTAG
yyresolveValue (yyGLRState
* yys
,
1679 yyGLRStack
* yystackp
]b4_user_formals
[);
1682 /** Resolve the previous N states starting at and including state S. If result
1683 * != yyok, some states may have been left unresolved possibly with empty
1684 * semantic option chains. Regardless of whether result = yyok, each state
1685 * has been left with consistent data so that yydestroyGLRState can be invoked
1688 yyresolveStates (yyGLRState
* yys
, int yyn
,
1689 yyGLRStack
* yystackp
]b4_user_formals
[)
1693 YYASSERT (yys
->yypred
);
1694 YYCHK (yyresolveStates (yys
->yypred
, yyn
-1, yystackp
]b4_user_args
[));
1695 if (! yys
->yyresolved
)
1696 YYCHK (yyresolveValue (yys
, yystackp
]b4_user_args
[));
1701 /** Resolve the states for the RHS of OPT, perform its user action, and return
1702 * the semantic value and location. Regardless of whether result = yyok, all
1703 * RHS states have been destroyed (assuming the user action destroys all RHS
1704 * semantic values if invoked). */
1706 yyresolveAction (yySemanticOption
* yyopt
, yyGLRStack
* yystackp
,
1707 YYSTYPE
* yyvalp
, YYLTYPE
* yylocp
]b4_user_formals
[)
1709 yyGLRStackItem yyrhsVals
[YYMAXRHS
+ YYMAXLEFT
+ 1];
1712 YYSTYPE yylval_current
;
1713 YYLTYPE yylloc_current
;
1716 yynrhs
= yyrhsLength (yyopt
->yyrule
);
1717 yyflag
= yyresolveStates (yyopt
->yystate
, yynrhs
, yystackp
]b4_user_args
[);
1721 for (yys
= yyopt
->yystate
; yynrhs
> 0; yys
= yys
->yypred
, yynrhs
-= 1)
1722 yydestroyGLRState ("Cleanup: popping", yys
]b4_user_args
[);
1726 yyrhsVals
[YYMAXRHS
+ YYMAXLEFT
].yystate
.yypred
= yyopt
->yystate
;]b4_locations_if([[
1728 /* Set default location. */
1729 yyrhsVals
[YYMAXRHS
+ YYMAXLEFT
- 1].yystate
.yyloc
= yyopt
->yystate
->yyloc
;]])[
1730 yychar_current
= yychar
;
1731 yylval_current
= yylval
;
1732 yylloc_current
= yylloc
;
1733 yychar
= yyopt
->yyrawchar
;
1734 yylval
= yyopt
->yyval
;
1735 yylloc
= yyopt
->yyloc
;
1736 yyflag
= yyuserAction (yyopt
->yyrule
, yynrhs
,
1737 yyrhsVals
+ YYMAXRHS
+ YYMAXLEFT
- 1,
1738 yyvalp
, yylocp
, yystackp
]b4_user_args
[);
1739 yychar
= yychar_current
;
1740 yylval
= yylval_current
;
1741 yylloc
= yylloc_current
;
1747 yyreportTree (yySemanticOption
* yyx
, int yyindent
)
1749 int yynrhs
= yyrhsLength (yyx
->yyrule
);
1752 yyGLRState
* yystates
[1 + YYMAXRHS
];
1753 yyGLRState yyleftmost_state
;
1755 for (yyi
= yynrhs
, yys
= yyx
->yystate
; 0 < yyi
; yyi
-= 1, yys
= yys
->yypred
)
1756 yystates
[yyi
] = yys
;
1759 yyleftmost_state
.yyposn
= 0;
1760 yystates
[0] = &yyleftmost_state
;
1765 if (yyx
->yystate
->yyposn
< yys
->yyposn
+ 1)
1766 YYFPRINTF (stderr
, "%*s%s -> <Rule %d, empty>\n",
1767 yyindent
, "", yytokenName (yylhsNonterm (yyx
->yyrule
)),
1770 YYFPRINTF (stderr
, "%*s%s -> <Rule %d, tokens %lu .. %lu>\n",
1771 yyindent
, "", yytokenName (yylhsNonterm (yyx
->yyrule
)),
1772 yyx
->yyrule
- 1, (unsigned long int) (yys
->yyposn
+ 1),
1773 (unsigned long int) yyx
->yystate
->yyposn
);
1774 for (yyi
= 1; yyi
<= yynrhs
; yyi
+= 1)
1776 if (yystates
[yyi
]->yyresolved
)
1778 if (yystates
[yyi
-1]->yyposn
+1 > yystates
[yyi
]->yyposn
)
1779 YYFPRINTF (stderr
, "%*s%s <empty>\n", yyindent
+2, "",
1780 yytokenName (yyrhs
[yyprhs
[yyx
->yyrule
]+yyi
-1]));
1782 YYFPRINTF (stderr
, "%*s%s <tokens %lu .. %lu>\n", yyindent
+2, "",
1783 yytokenName (yyrhs
[yyprhs
[yyx
->yyrule
]+yyi
-1]),
1784 (unsigned long int) (yystates
[yyi
- 1]->yyposn
+ 1),
1785 (unsigned long int) yystates
[yyi
]->yyposn
);
1788 yyreportTree (yystates
[yyi
]->yysemantics
.yyfirstVal
, yyindent
+2);
1793 /*ARGSUSED*/ static YYRESULTTAG
1794 yyreportAmbiguity (yySemanticOption
* yyx0
,
1795 yySemanticOption
* yyx1
]b4_pure_formals
[)
1801 YYFPRINTF (stderr
, "Ambiguity detected.\n");
1802 YYFPRINTF (stderr
, "Option 1,\n");
1803 yyreportTree (yyx0
, 2);
1804 YYFPRINTF (stderr
, "\nOption 2,\n");
1805 yyreportTree (yyx1
, 2);
1806 YYFPRINTF (stderr
, "\n");
1809 yyerror (]b4_yyerror_args
[YY_("syntax is ambiguous"));
1813 /** Starting at and including state S1, resolve the location for each of the
1814 * previous N1 states that is unresolved. The first semantic option of a state
1815 * is always chosen. */
1817 yyresolveLocations (yyGLRState
* yys1
, int yyn1
,
1818 yyGLRStack
*yystackp
]b4_user_formals
[)
1822 yyresolveLocations (yys1
->yypred
, yyn1
- 1, yystackp
]b4_user_args
[);
1823 if (!yys1
->yyresolved
)
1825 yySemanticOption
*yyoption
;
1826 yyGLRStackItem yyrhsloc
[1 + YYMAXRHS
];
1829 YYSTYPE yylval_current
;
1830 YYLTYPE yylloc_current
;
1831 yyoption
= yys1
->yysemantics
.yyfirstVal
;
1832 YYASSERT (yyoption
!= NULL
);
1833 yynrhs
= yyrhsLength (yyoption
->yyrule
);
1838 yyresolveLocations (yyoption
->yystate
, yynrhs
,
1839 yystackp
]b4_user_args
[);
1840 for (yys
= yyoption
->yystate
, yyn
= yynrhs
;
1842 yys
= yys
->yypred
, yyn
-= 1)
1843 yyrhsloc
[yyn
].yystate
.yyloc
= yys
->yyloc
;
1847 /* Both yyresolveAction and yyresolveLocations traverse the GSS
1848 in reverse rightmost order. It is only necessary to invoke
1849 yyresolveLocations on a subforest for which yyresolveAction
1850 would have been invoked next had an ambiguity not been
1851 detected. Thus the location of the previous state (but not
1852 necessarily the previous state itself) is guaranteed to be
1853 resolved already. */
1854 yyGLRState
*yyprevious
= yyoption
->yystate
;
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_locations_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
+ 1;
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 lookahead. */
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
)
2205 {]b4_locations_if([[
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_locations_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_locations_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_locations_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_locations_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_locations_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_locations_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_locations_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_locations_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
);
2534 /* Make sure YYID is used. */
2535 return YYID (yyresult
);
2538 /* DEBUGGING ONLY */
2540 static void yypstack (yyGLRStack
* yystackp
, size_t yyk
)
2541 __attribute__ ((__unused__
));
2542 static void yypdumpstack (yyGLRStack
* yystackp
) __attribute__ ((__unused__
));
2545 yy_yypstack (yyGLRState
* yys
)
2549 yy_yypstack (yys
->yypred
);
2550 fprintf (stderr
, " -> ");
2552 fprintf (stderr
, "%d@@%lu", yys
->yylrState
, (unsigned long int) yys
->yyposn
);
2556 yypstates (yyGLRState
* yyst
)
2559 fprintf (stderr
, "<null>");
2562 fprintf (stderr
, "\n");
2566 yypstack (yyGLRStack
* yystackp
, size_t yyk
)
2568 yypstates (yystackp
->yytops
.yystates
[yyk
]);
2571 #define YYINDEX(YYX) \
2572 ((YYX) == NULL ? -1 : (yyGLRStackItem*) (YYX) - yystackp->yyitems)
2576 yypdumpstack (yyGLRStack
* yystackp
)
2578 yyGLRStackItem
* yyp
;
2580 for (yyp
= yystackp
->yyitems
; yyp
< yystackp
->yynextFree
; yyp
+= 1)
2582 fprintf (stderr
, "%3lu. ", (unsigned long int) (yyp
- yystackp
->yyitems
));
2583 if (*(yybool
*) yyp
)
2585 fprintf (stderr
, "Res: %d, LR State: %d, posn: %lu, pred: %ld",
2586 yyp
->yystate
.yyresolved
, yyp
->yystate
.yylrState
,
2587 (unsigned long int) yyp
->yystate
.yyposn
,
2588 (long int) YYINDEX (yyp
->yystate
.yypred
));
2589 if (! yyp
->yystate
.yyresolved
)
2590 fprintf (stderr
, ", firstVal: %ld",
2591 (long int) YYINDEX (yyp
->yystate
.yysemantics
.yyfirstVal
));
2595 fprintf (stderr
, "Option. rule: %d, state: %ld, next: %ld",
2596 yyp
->yyoption
.yyrule
- 1,
2597 (long int) YYINDEX (yyp
->yyoption
.yystate
),
2598 (long int) YYINDEX (yyp
->yyoption
.yynext
));
2600 fprintf (stderr
, "\n");
2602 fprintf (stderr
, "Tops:");
2603 for (yyi
= 0; yyi
< yystackp
->yytops
.yysize
; yyi
+= 1)
2604 fprintf (stderr
, "%lu: %ld; ", (unsigned long int) yyi
,
2605 (long int) YYINDEX (yystackp
->yytops
.yystates
[yyi
]));
2606 fprintf (stderr
, "\n");
2613 [@output @output_header_name@
2614 b4_copyright([Skeleton interface
for Bison GLR parsers in C
],
2615 [2002, 2003, 2004, 2005, 2006])
2617 b4_shared_declarations
2619 extern YYSTYPE b4_prefix
[]lval
;
2621 b4_locations_if([b4_pure_if([],
2622 [extern YYLTYPE b4_prefix
[]lloc
;])