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 # glr.cc checks %define variables also.
25 m4_if(b4_skeleton
, [["glr.c"]], [b4_check_percent_define_variables
])
27 b4_check_percent_code_qualifiers([[requires]],
32 b4_complain([[non
-deterministic push parsers are
not yet supported
]])])
34 ## ---------------- ##
36 ## ---------------- ##
39 m4_define_default([b4_stack_depth_max
], [10000])
40 m4_define_default([b4_stack_depth_init
], [200])
44 ## ------------------------ ##
45 ## Pure/impure interfaces. ##
46 ## ------------------------ ##
51 # The possible parse-params formal arguments preceded by a comma.
53 # This is not shared with yacc.c in c.m4 because GLR relies on ISO C
54 # formal argument declarations.
55 m4_define([b4_user_formals
],
56 [m4_ifset([b4_parse_param
], [, b4_c_ansi_formals(b4_parse_param
)])])
61 # Accumule in b4_lex_param all the yylex arguments.
62 # Yes, this is quite ugly...
63 m4_define([b4_lex_param
],
64 m4_dquote(b4_pure_if([[[[YYSTYPE
*]], [[&yylval
]]][]dnl
65 b4_locations_if([, [[YYLTYPE
*], [&yylloc
]]])])dnl
66 m4_ifdef([b4_lex_param
], [, ]b4_lex_param
)))
71 # Optional effective arguments passed to yyerror: user args plus yylloc, and
73 m4_define([b4_yyerror_args
],
74 [b4_pure_if([b4_locations_if([yylocp
, ])])dnl
75 m4_ifset([b4_parse_param
], [b4_c_args(b4_parse_param
), ])])
80 # Same as above, but on the lookahead, hence &yylloc instead of yylocp.
81 m4_define([b4_lyyerror_args
],
82 [b4_pure_if([b4_locations_if([&yylloc
, ])])dnl
83 m4_ifset([b4_parse_param
], [b4_c_args(b4_parse_param
), ])])
88 # Same as b4_yyerror_args, but with a leading comma.
89 m4_define([b4_pure_args
],
90 [b4_pure_if([b4_locations_if([, yylocp
])])[]b4_user_args
])
95 # Same as above, but on the lookahead, hence &yylloc instead of yylocp.
96 m4_define([b4_lpure_args
],
97 [b4_pure_if([b4_locations_if([, &yylloc
])])[]b4_user_args
])
102 # Arguments passed to yyerror: user formals plus yylocp.
103 m4_define([b4_pure_formals
],
104 [b4_pure_if([b4_locations_if([, YYLTYPE
*yylocp
])])[]b4_user_formals
])
107 ## ----------------- ##
108 ## Semantic Values. ##
109 ## ----------------- ##
112 # b4_lhs_value([TYPE])
113 # --------------------
114 # Expansion of $<TYPE>$.
115 m4_define([b4_lhs_value
],
116 [((*yyvalp
)[]m4_ifval([$
1], [.$
1]))])
119 # b4_rhs_value(RULE-LENGTH, NUM, [TYPE])
120 # --------------------------------------
121 # Expansion of $<TYPE>NUM, where the current rule has RULE-LENGTH
123 m4_define([b4_rhs_value
],
124 [(((yyGLRStackItem
const *)yyvsp
)@
{YYFILL (($
2) - ($
1))@
}.yystate
.yysemantics
.yysval
[]m4_ifval([$
3], [.$
3]))])
135 m4_define([b4_lhs_location
],
139 # b4_rhs_location(RULE-LENGTH, NUM)
140 # ---------------------------------
141 # Expansion of @NUM, where the current rule has RULE-LENGTH symbols
143 m4_define([b4_rhs_location
],
144 [(((yyGLRStackItem
const *)yyvsp
)@
{YYFILL (($
2) - ($
1))@
}.yystate
.yyloc
)])
152 # We do want M4 expansion after # for CPP macros.
155 @
output(b4_parser_file_name@
)
156 b4_copyright([Skeleton implementation
for Bison GLR parsers in C
],
157 [2002, 2003, 2004, 2005, 2006])
159 /* C GLR parser skeleton written by Paul Hilfinger. */
163 m4_ifdef([b4_percent_code_top
],
164 [[/* Copy the %code "top" blocks. */
165 ]b4_user_code([b4_percent_code_top
])])[]dnl
166 m4_if(b4_prefix
, [yy
], [],
167 [/* Substitute the variable and function names. */
168 #define yyparse b4_prefix[]parse
169 #define yylex b4_prefix[]lex
170 #define yyerror b4_prefix[]error
171 #define yylval b4_prefix[]lval
172 #define yychar b4_prefix[]char
173 #define yydebug b4_prefix[]debug
174 #define yynerrs b4_prefix[]nerrs
175 #define yylloc b4_prefix[]lloc])[
177 /* Copy the first part of user declarations. */
178 ]b4_user_pre_prologue
180 dnl
# b4_shared_declarations
181 dnl
# ----------------------
182 dnl
# Declaration that might either go into the header (if --defines)
183 dnl
# or open coded in the parser body.
184 m4_define([b4_shared_declarations
],
185 [m4_ifdef([b4_percent_code_requires
],
186 [[/* Copy the %code "requires" blocks. */
187 ]b4_user_code([b4_percent_code_requires
])])[]dnl
189 b4_token_enums(b4_tokens
)
192 ]m4_ifdef([b4_stype
],
193 [[typedef union ]b4_union_name
[
196 # define YYSTYPE_IS_TRIVIAL 1]],
197 [m4_if(b4_tag_seen_flag
, 0,
198 [[typedef int YYSTYPE
;
199 # define YYSTYPE_IS_TRIVIAL 1]])])[
202 #if ! defined YYLTYPE && ! defined YYLTYPE_IS_DECLARED
203 typedef struct YYLTYPE
214 # define YYLTYPE_IS_DECLARED 1
215 # define YYLTYPE_IS_TRIVIAL 1
218 ]m4_ifdef([b4_percent_code_provides
],
219 [[/* Copy the %code "provides" blocks. */
220 ]b4_user_code([b4_percent_code_provides
])])[]dnl
223 b4_defines_if([[#include "@basename(]b4_spec_defines_file[@)"]],
224 [b4_shared_declarations
])[
226 /* Enabling traces. */
228 # define YYDEBUG ]b4_debug_flag[
231 /* Enabling verbose error messages. */
232 #ifdef YYERROR_VERBOSE
233 # undef YYERROR_VERBOSE
234 # define YYERROR_VERBOSE 1
236 # define YYERROR_VERBOSE ]b4_error_verbose_flag[
239 /* Enabling the token table. */
240 #ifndef YYTOKEN_TABLE
241 # define YYTOKEN_TABLE ]b4_token_table[
244 /* Default (constant) value used for initialization for null
245 right-hand sides. Unlike the standard yacc.c template,
246 here we set the default value of $$ to a zeroed-out value.
247 Since the default value is undefined, this behavior is
248 technically correct. */
249 static YYSTYPE yyval_default
;
251 /* Copy the second part of user declarations. */
252 ]b4_user_post_prologue
253 m4_ifdef([b4_percent_code
],
254 [[/* Copy the unqualified %code blocks. */
255 ]b4_user_code([b4_percent_code
])
265 # include <libintl.h> /* INFRINGES ON USER NAME SPACE */
266 # define YY_(msgid) dgettext ("bison-runtime", msgid)
270 # define YY_(msgid) msgid
274 /* Suppress unused-variable warnings by "using" E. */
275 #if ! defined lint || defined __GNUC__
276 # define YYUSE(e) ((void) (e))
278 # define YYUSE(e) /* empty */
281 /* Identity function, used to suppress warnings about constant conditions. */
285 ]b4_c_function_def([YYID
], [static int], [[int i
], [i
]])[
295 # define YYMALLOC malloc
298 # define YYREALLOC realloc
301 #define YYSIZEMAX ((size_t) -1)
306 typedef unsigned char yybool
;
313 # define YYJMP_BUF jmp_buf
314 # define YYSETJMP(env) setjmp (env)
315 # define YYLONGJMP(env, val) longjmp (env, val)
322 #ifndef __attribute__
323 /* This feature is available in gcc versions 2.5 and later. */
324 # if (! defined __GNUC__ || __GNUC__ < 2 \
325 || (__GNUC__ == 2 && __GNUC_MINOR__ < 5) || __STRICT_ANSI__)
326 # define __attribute__(Spec) /* empty */
330 ]b4_locations_if([#define YYOPTIONAL_LOC(Name) Name],[
332 # define YYOPTIONAL_LOC(Name) /* empty */
334 # define YYOPTIONAL_LOC(Name) Name __attribute__ ((__unused__))
338 # define YYASSERT(condition) ((void) ((condition) || (abort (), 0)))
341 /* YYFINAL -- State number of the termination state. */
342 #define YYFINAL ]b4_final_state_number[
343 /* YYLAST -- Last index in YYTABLE. */
344 #define YYLAST ]b4_last[
346 /* YYNTOKENS -- Number of terminals. */
347 #define YYNTOKENS ]b4_tokens_number[
348 /* YYNNTS -- Number of nonterminals. */
349 #define YYNNTS ]b4_nterms_number[
350 /* YYNRULES -- Number of rules. */
351 #define YYNRULES ]b4_rules_number[
352 /* YYNRULES -- Number of states. */
353 #define YYNSTATES ]b4_states_number[
354 /* YYMAXRHS -- Maximum number of symbols on right-hand side of rule. */
355 #define YYMAXRHS ]b4_r2_max[
356 /* YYMAXLEFT -- Maximum number of symbols to the left of a handle
357 accessed by $0, $-1, etc., in any rule. */
358 #define YYMAXLEFT ]b4_max_left_semantic_context[
360 /* YYTRANSLATE(X) -- Bison symbol number corresponding to X. */
361 #define YYUNDEFTOK ]b4_undef_token_number[
362 #define YYMAXUTOK ]b4_user_token_number_max[
364 #define YYTRANSLATE(YYX) \
365 ((unsigned int) (YYX) <= YYMAXUTOK ? yytranslate[YYX] : YYUNDEFTOK)
367 /* YYTRANSLATE[YYLEX] -- Bison symbol number corresponding to YYLEX. */
368 static const ]b4_int_type_for([b4_translate
])[ yytranslate
[] =
374 /* YYPRHS[YYN] -- Index of the first RHS symbol of rule number YYN in
376 static const ]b4_int_type_for([b4_prhs
])[ yyprhs
[] =
381 /* YYRHS -- A `-1'-separated list of the rules' RHS. */
382 static const ]b4_int_type_for([b4_rhs
])[ yyrhs
[] =
387 /* YYRLINE[YYN] -- source line where rule number YYN was defined. */
388 static const ]b4_int_type_for([b4_rline
])[ yyrline
[] =
394 #if YYDEBUG || YYERROR_VERBOSE || YYTOKEN_TABLE
395 /* YYTNAME[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM.
396 First, the terminals, then, starting at YYNTOKENS, nonterminals. */
397 static const char *const yytname
[] =
403 /* YYR1[YYN] -- Symbol number of symbol that rule YYN derives. */
404 static const ]b4_int_type_for([b4_r1
])[ yyr1
[] =
409 /* YYR2[YYN] -- Number of symbols composing right hand side of rule YYN. */
410 static const ]b4_int_type_for([b4_r2
])[ yyr2
[] =
415 /* YYDPREC[RULE-NUM] -- Dynamic precedence of rule #RULE-NUM (0 if none). */
416 static const ]b4_int_type_for([b4_dprec
])[ yydprec
[] =
421 /* YYMERGER[RULE-NUM] -- Index of merging function for rule #RULE-NUM. */
422 static const ]b4_int_type_for([b4_merger
])[ yymerger
[] =
427 /* YYDEFACT[S] -- default rule to reduce with in state S when YYTABLE
428 doesn't specify something else to do. Zero means the default is an
430 static const ]b4_int_type_for([b4_defact
])[ yydefact
[] =
435 /* YYPDEFGOTO[NTERM-NUM]. */
436 static const ]b4_int_type_for([b4_defgoto
])[ yydefgoto
[] =
441 /* YYPACT[STATE-NUM] -- Index in YYTABLE of the portion describing
443 #define YYPACT_NINF ]b4_pact_ninf[
444 static const ]b4_int_type_for([b4_pact
])[ yypact
[] =
449 /* YYPGOTO[NTERM-NUM]. */
450 static const ]b4_int_type_for([b4_pgoto
])[ yypgoto
[] =
455 /* YYTABLE[YYPACT[STATE-NUM]]. What to do in state STATE-NUM. If
456 positive, shift that token. If negative, reduce the rule which
457 number is the opposite. If zero, do what YYDEFACT says.
458 If YYTABLE_NINF, syntax error. */
459 #define YYTABLE_NINF ]b4_table_ninf[
460 static const ]b4_int_type_for([b4_table
])[ yytable
[] =
465 /* YYCONFLP[YYPACT[STATE-NUM]] -- Pointer into YYCONFL of start of
466 list of conflicting reductions corresponding to action entry for
467 state STATE-NUM in yytable. 0 means no conflicts. The list in
468 yyconfl is terminated by a rule number of 0. */
469 static const ]b4_int_type_for([b4_conflict_list_heads
])[ yyconflp
[] =
471 ]b4_conflict_list_heads
[
474 /* YYCONFL[I] -- lists of conflicting rule numbers, each terminated by
475 0, pointed into by YYCONFLP. */
476 ]dnl Do
not use b4_int_type_for here
, since there are places where
477 dnl pointers onto yyconfl are taken
, which type is
"short int *".
478 dnl We probably ought to introduce a type
for confl
.
479 [static const short int yyconfl
[] =
481 ]b4_conflicting_rules
[
484 static const ]b4_int_type_for([b4_check
])[ yycheck
[] =
489 /* YYSTOS[STATE-NUM] -- The (internal number of the) accessing
490 symbol of state STATE-NUM. */
491 static const ]b4_int_type_for([b4_stos
])[ yystos
[] =
497 /* Prevent warning if -Wmissing-prototypes. */
498 ]b4_c_ansi_function_decl([yyparse
], [int], b4_parse_param
)[
500 /* Error token number */
503 /* YYLLOC_DEFAULT -- Set CURRENT to span from RHS[1] to RHS[N].
504 If N is 0, then set CURRENT to the empty location which ends
505 the previous symbol: RHS[0] (always defined). */
508 #define YYRHSLOC(Rhs, K) ((Rhs)[K].yystate.yyloc)
509 #ifndef YYLLOC_DEFAULT
510 # define YYLLOC_DEFAULT(Current, Rhs, N) \
514 (Current).first_line = YYRHSLOC (Rhs, 1).first_line; \
515 (Current).first_column = YYRHSLOC (Rhs, 1).first_column; \
516 (Current).last_line = YYRHSLOC (Rhs, N).last_line; \
517 (Current).last_column = YYRHSLOC (Rhs, N).last_column; \
521 (Current).first_line = (Current).last_line = \
522 YYRHSLOC (Rhs, 0).last_line; \
523 (Current).first_column = (Current).last_column = \
524 YYRHSLOC (Rhs, 0).last_column; \
528 /* YY_LOCATION_PRINT -- Print the location on the stream.
529 This macro was not mandated originally: define only if we know
530 we won't break user code: when these are the locations we know. */
532 # define YY_LOCATION_PRINT(File, Loc) \
533 fprintf (File, "%d.%d-%d.%d", \
534 (Loc).first_line, (Loc).first_column, \
535 (Loc).last_line, (Loc).last_column)
538 #ifndef YYLLOC_DEFAULT
539 # define YYLLOC_DEFAULT(Current, Rhs, N) ((void) 0)
543 #ifndef YY_LOCATION_PRINT
544 # define YY_LOCATION_PRINT(File, Loc) ((void) 0)
548 /* YYLEX -- calling `yylex' with the right arguments. */
549 #define YYLEX ]b4_c_function_call([yylex], [int], b4_lex_param)[
554 #define yynerrs (yystackp->yyerrcnt)
556 #define yychar (yystackp->yyrawchar)
558 #define yylval (yystackp->yyval)
560 #define yylloc (yystackp->yyloc)
561 m4_if(b4_prefix
[], [yy
], [],
562 [#define b4_prefix[]nerrs yynerrs
563 #define b4_prefix[]char yychar
564 #define b4_prefix[]lval yylval
565 #define b4_prefix[]lloc yylloc])],
573 static const int YYEOF
= 0;
574 static const int YYEMPTY
= -2;
576 typedef enum { yyok
, yyaccept
, yyabort
, yyerr
} YYRESULTTAG
;
579 do { YYRESULTTAG yyflag = YYE; if (yyflag != yyok) return yyflag; } \
585 # define YYFPRINTF fprintf
588 # define YYDPRINTF(Args) \
594 ]b4_yy_symbol_print_generate([b4_c_ansi_function_def
])[
596 # define YY_SYMBOL_PRINT(Title, Type, Value, Location) \
600 YYFPRINTF (stderr, "%s ", Title); \
601 yy_symbol_print (stderr, Type, \
602 Value]b4_locations_if([, Location])[]b4_user_args[); \
603 YYFPRINTF (stderr, "\n"); \
607 /* Nonzero means print parse trace. It is left uninitialized so that
608 multiple parsers can coexist. */
613 # define YYDPRINTF(Args)
614 # define YY_SYMBOL_PRINT(Title, Type, Value, Location)
616 #endif /* !YYDEBUG */
618 /* YYINITDEPTH -- initial size of the parser's stacks. */
620 # define YYINITDEPTH ]b4_stack_depth_init[
623 /* YYMAXDEPTH -- maximum size the stacks can grow to (effective only
624 if the built-in stack extension method is used).
626 Do not make this value too large; the results are undefined if
627 SIZE_MAX < YYMAXDEPTH * sizeof (GLRStackItem)
628 evaluated with infinite-precision integer arithmetic. */
631 # define YYMAXDEPTH ]b4_stack_depth_max[
634 /* Minimum number of free items on the stack allowed after an
635 allocation. This is to allow allocation and initialization
636 to be completed by functions that call yyexpandGLRStack before the
637 stack is expanded, thus insuring that all necessary pointers get
638 properly redirected to new data. */
641 #ifndef YYSTACKEXPANDABLE
642 # if (! defined __cplusplus \
643 || (]b4_locations_if([[defined YYLTYPE_IS_TRIVIAL && YYLTYPE_IS_TRIVIAL \
644 && ]])[defined YYSTYPE_IS_TRIVIAL && YYSTYPE_IS_TRIVIAL))
645 # define YYSTACKEXPANDABLE 1
647 # define YYSTACKEXPANDABLE 0
651 #if YYSTACKEXPANDABLE
652 # define YY_RESERVE_GLRSTACK(Yystack) \
654 if (Yystack->yyspaceLeft < YYHEADROOM) \
655 yyexpandGLRStack (Yystack); \
658 # define YY_RESERVE_GLRSTACK(Yystack) \
660 if (Yystack->yyspaceLeft < YYHEADROOM) \
661 yyMemoryExhausted (Yystack); \
669 # if defined __GLIBC__ && defined _STRING_H && defined _GNU_SOURCE
670 # define yystpcpy stpcpy
672 /* Copy YYSRC to YYDEST, returning the address of the terminating '\0' in
675 yystpcpy (char *yydest
, const char *yysrc
)
678 const char *yys
= yysrc
;
680 while ((*yyd
++ = *yys
++) != '\0')
689 /* Copy to YYRES the contents of YYSTR after stripping away unnecessary
690 quotes and backslashes, so that it's suitable for yyerror. The
691 heuristic is that double-quoting is unnecessary unless the string
692 contains an apostrophe, a comma, or backslash (other than
693 backslash-backslash). YYSTR is taken from yytname. If YYRES is
694 null, do not copy; instead, return the length of what the result
697 yytnamerr (char *yyres
, const char *yystr
)
702 char const *yyp
= yystr
;
709 goto do_not_strip_quotes
;
713 goto do_not_strip_quotes
;
726 do_not_strip_quotes
: ;
730 return strlen (yystr
);
732 return yystpcpy (yyres
, yystr
) - yyres
;
736 #endif /* !YYERROR_VERBOSE */
738 /** State numbers, as in LALR(1) machine */
739 typedef int yyStateNum
;
741 /** Rule numbers, as in LALR(1) machine */
742 typedef int yyRuleNum
;
744 /** Grammar symbol */
745 typedef short int yySymbol
;
747 /** Item references, as in LALR(1) machine */
748 typedef short int yyItemNum
;
750 typedef struct yyGLRState yyGLRState
;
751 typedef struct yyGLRStateSet yyGLRStateSet
;
752 typedef struct yySemanticOption yySemanticOption
;
753 typedef union yyGLRStackItem yyGLRStackItem
;
754 typedef struct yyGLRStack yyGLRStack
;
757 /** Type tag: always true. */
759 /** Type tag for yysemantics. If true, yysval applies, otherwise
760 * yyfirstVal applies. */
762 /** Number of corresponding LALR(1) machine state. */
763 yyStateNum yylrState
;
764 /** Preceding state in this stack */
766 /** Source position of the first token produced by my symbol */
769 /** First in a chain of alternative reductions producing the
770 * non-terminal corresponding to this state, threaded through
772 yySemanticOption
* yyfirstVal
;
773 /** Semantic value for this state. */
776 /** Source location for this state. */
780 struct yyGLRStateSet
{
781 yyGLRState
** yystates
;
782 /** During nondeterministic operation, yylookaheadNeeds tracks which
783 * stacks have actually needed the current lookahead. During deterministic
784 * operation, yylookaheadNeeds[0] is not maintained since it would merely
785 * duplicate yychar != YYEMPTY. */
786 yybool
* yylookaheadNeeds
;
787 size_t yysize
, yycapacity
;
790 struct yySemanticOption
{
791 /** Type tag: always false. */
793 /** Rule number for this reduction */
795 /** The last RHS state in the list of states to be reduced. */
797 /** The lookahead for this reduction. */
801 /** Next sibling in chain of options. To facilitate merging,
802 * options are chained in decreasing order by address. */
803 yySemanticOption
* yynext
;
806 /** Type of the items in the GLR stack. The yyisState field
807 * indicates which item of the union is valid. */
808 union yyGLRStackItem
{
810 yySemanticOption yyoption
;
815 ]b4_locations_if([[ /* To compute the location of the error token. */
816 yyGLRStackItem yyerror_range
[3];]])[
824 YYJMP_BUF yyexception_buffer
;
825 yyGLRStackItem
* yyitems
;
826 yyGLRStackItem
* yynextFree
;
828 yyGLRState
* yysplitPoint
;
829 yyGLRState
* yylastDeleted
;
830 yyGLRStateSet yytops
;
833 #if YYSTACKEXPANDABLE
834 static void yyexpandGLRStack (yyGLRStack
* yystackp
);
837 static void yyFail (yyGLRStack
* yystackp
]b4_pure_formals
[, const char* yymsg
)
838 __attribute__ ((__noreturn__
));
840 yyFail (yyGLRStack
* yystackp
]b4_pure_formals
[, const char* yymsg
)
843 yyerror (]b4_yyerror_args
[yymsg
);
844 YYLONGJMP (yystackp
->yyexception_buffer
, 1);
847 static void yyMemoryExhausted (yyGLRStack
* yystackp
)
848 __attribute__ ((__noreturn__
));
850 yyMemoryExhausted (yyGLRStack
* yystackp
)
852 YYLONGJMP (yystackp
->yyexception_buffer
, 2);
855 #if YYDEBUG || YYERROR_VERBOSE
856 /** A printable representation of TOKEN. */
857 static inline const char*
858 yytokenName (yySymbol yytoken
)
860 if (yytoken
== YYEMPTY
)
863 return yytname
[yytoken
];
867 /** Fill in YYVSP[YYLOW1 .. YYLOW0-1] from the chain of states starting
868 * at YYVSP[YYLOW0].yystate.yypred. Leaves YYVSP[YYLOW1].yystate.yypred
869 * containing the pointer to the next state in the chain. */
870 static void yyfillin (yyGLRStackItem
*, int, int) __attribute__ ((__unused__
));
872 yyfillin (yyGLRStackItem
*yyvsp
, int yylow0
, int yylow1
)
876 s
= yyvsp
[yylow0
].yystate
.yypred
;
877 for (i
= yylow0
-1; i
>= yylow1
; i
-= 1)
879 YYASSERT (s
->yyresolved
);
880 yyvsp
[i
].yystate
.yyresolved
= yytrue
;
881 yyvsp
[i
].yystate
.yysemantics
.yysval
= s
->yysemantics
.yysval
;
882 yyvsp
[i
].yystate
.yyloc
= s
->yyloc
;
883 s
= yyvsp
[i
].yystate
.yypred
= s
->yypred
;
887 /* Do nothing if YYNORMAL or if *YYLOW <= YYLOW1. Otherwise, fill in
888 * YYVSP[YYLOW1 .. *YYLOW-1] as in yyfillin and set *YYLOW = YYLOW1.
889 * For convenience, always return YYLOW1. */
890 static inline int yyfill (yyGLRStackItem
*, int *, int, yybool
)
891 __attribute__ ((__unused__
));
893 yyfill (yyGLRStackItem
*yyvsp
, int *yylow
, int yylow1
, yybool yynormal
)
895 if (!yynormal
&& yylow1
< *yylow
)
897 yyfillin (yyvsp
, *yylow
, yylow1
);
903 /** Perform user action for rule number YYN, with RHS length YYRHSLEN,
904 * and top stack item YYVSP. YYLVALP points to place to put semantic
905 * value ($$), and yylocp points to place for location information
906 * (@@$). Returns yyok for normal return, yyaccept for YYACCEPT,
907 * yyerr for YYERROR, yyabort for YYABORT. */
908 /*ARGSUSED*/ static YYRESULTTAG
909 yyuserAction (yyRuleNum yyn
, int yyrhslen
, yyGLRStackItem
* yyvsp
,
911 YYLTYPE
* YYOPTIONAL_LOC (yylocp
),
915 yybool yynormal
__attribute__ ((__unused__
)) =
916 (yystackp
->yysplitPoint
== NULL
);
918 ]b4_parse_param_use
[]dnl
920 # define yyerrok (yystackp->yyerrState = 0)
922 # define YYACCEPT return yyaccept
924 # define YYABORT return yyabort
926 # define YYERROR return yyerrok, yyerr
928 # define YYRECOVERING() (yystackp->yyerrState != 0)
930 # define yyclearin (yychar = YYEMPTY)
932 # define YYFILL(N) yyfill (yyvsp, &yylow, N, yynormal)
934 # define YYBACKUP(Token, Value) \
935 return yyerror (]b4_yyerror_args[YY_("syntax error: cannot back up")), \
940 *yyvalp
= yyval_default
;
942 *yyvalp
= yyvsp
[YYFILL (1-yyrhslen
)].yystate
.yysemantics
.yysval
;
943 YYLLOC_DEFAULT ((*yylocp
), (yyvsp
- yyrhslen
), yyrhslen
);
944 ]b4_locations_if([[ yystackp
->yyerror_range
[1].yystate
.yyloc
= *yylocp
;
963 /*ARGSUSED*/ static void
964 yyuserMerge (int yyn
, YYSTYPE
* yy0
, YYSTYPE
* yy1
)
976 /* Bison grammar-table manipulation. */
978 ]b4_yydestruct_generate([b4_c_ansi_function_def
])[
980 /** Number of symbols composing the right hand side of rule #RULE. */
982 yyrhsLength (yyRuleNum yyrule
)
988 yydestroyGLRState (char const *yymsg
, yyGLRState
*yys
]b4_user_formals
[)
991 yydestruct (yymsg
, yystos
[yys
->yylrState
],
992 &yys
->yysemantics
.yysval
]b4_locations_if([, &yys
->yyloc
])[]b4_user_args
[);
998 if (yys
->yysemantics
.yyfirstVal
)
999 YYFPRINTF (stderr
, "%s unresolved ", yymsg
);
1001 YYFPRINTF (stderr
, "%s incomplete ", yymsg
);
1002 yy_symbol_print (stderr
, yystos
[yys
->yylrState
],
1003 NULL
]b4_locations_if([, &yys
->yyloc
])[]b4_user_args
[);
1004 YYFPRINTF (stderr
, "\n");
1008 if (yys
->yysemantics
.yyfirstVal
)
1010 yySemanticOption
*yyoption
= yys
->yysemantics
.yyfirstVal
;
1013 for (yyrh
= yyoption
->yystate
, yyn
= yyrhsLength (yyoption
->yyrule
);
1015 yyrh
= yyrh
->yypred
, yyn
-= 1)
1016 yydestroyGLRState (yymsg
, yyrh
]b4_user_args
[);
1021 /** Left-hand-side symbol for rule #RULE. */
1022 static inline yySymbol
1023 yylhsNonterm (yyRuleNum yyrule
)
1025 return yyr1
[yyrule
];
1028 #define yyis_pact_ninf(yystate) \
1029 ]m4_if(m4_eval(b4_pact_ninf < b4_pact_min), [1],
1031 [((yystate
) == YYPACT_NINF
)])[
1033 /** True iff LR state STATE has only a default reduction (regardless
1035 static inline yybool
1036 yyisDefaultedState (yyStateNum yystate
)
1038 return yyis_pact_ninf (yypact
[yystate
]);
1041 /** The default reduction for STATE, assuming it has one. */
1042 static inline yyRuleNum
1043 yydefaultAction (yyStateNum yystate
)
1045 return yydefact
[yystate
];
1048 #define yyis_table_ninf(yytable_value) \
1049 ]m4_if(m4_eval(b4_table_ninf < b4_table_min), [1],
1051 [((yytable_value
) == YYTABLE_NINF
)])[
1053 /** Set *YYACTION to the action to take in YYSTATE on seeing YYTOKEN.
1055 * R < 0: Reduce on rule -R.
1057 * R > 0: Shift to state R.
1058 * Set *CONFLICTS to a pointer into yyconfl to 0-terminated list of
1059 * conflicting reductions.
1062 yygetLRActions (yyStateNum yystate
, int yytoken
,
1063 int* yyaction
, const short int** yyconflicts
)
1065 int yyindex
= yypact
[yystate
] + yytoken
;
1066 if (yyindex
< 0 || YYLAST
< yyindex
|| yycheck
[yyindex
] != yytoken
)
1068 *yyaction
= -yydefact
[yystate
];
1069 *yyconflicts
= yyconfl
;
1071 else if (! yyis_table_ninf (yytable
[yyindex
]))
1073 *yyaction
= yytable
[yyindex
];
1074 *yyconflicts
= yyconfl
+ yyconflp
[yyindex
];
1079 *yyconflicts
= yyconfl
+ yyconflp
[yyindex
];
1083 static inline yyStateNum
1084 yyLRgotoState (yyStateNum yystate
, yySymbol yylhs
)
1087 yyr
= yypgoto
[yylhs
- YYNTOKENS
] + yystate
;
1088 if (0 <= yyr
&& yyr
<= YYLAST
&& yycheck
[yyr
] == yystate
)
1089 return yytable
[yyr
];
1091 return yydefgoto
[yylhs
- YYNTOKENS
];
1094 static inline yybool
1095 yyisShiftAction (int yyaction
)
1097 return 0 < yyaction
;
1100 static inline yybool
1101 yyisErrorAction (int yyaction
)
1103 return yyaction
== 0;
1108 /** Return a fresh GLRStackItem. Callers should call
1109 * YY_RESERVE_GLRSTACK afterwards to make sure there is sufficient
1112 static inline yyGLRStackItem
*
1113 yynewGLRStackItem (yyGLRStack
* yystackp
, yybool yyisState
)
1115 yyGLRStackItem
* yynewItem
= yystackp
->yynextFree
;
1116 yystackp
->yyspaceLeft
-= 1;
1117 yystackp
->yynextFree
+= 1;
1118 yynewItem
->yystate
.yyisState
= yyisState
;
1122 /** Add a new semantic action that will execute the action for rule
1123 * RULENUM on the semantic values in RHS to the list of
1124 * alternative actions for STATE. Assumes that RHS comes from
1125 * stack #K of *STACKP. */
1127 yyaddDeferredAction (yyGLRStack
* yystackp
, size_t yyk
, yyGLRState
* yystate
,
1128 yyGLRState
* rhs
, yyRuleNum yyrule
)
1130 yySemanticOption
* yynewOption
=
1131 &yynewGLRStackItem (yystackp
, yyfalse
)->yyoption
;
1132 yynewOption
->yystate
= rhs
;
1133 yynewOption
->yyrule
= yyrule
;
1134 if (yystackp
->yytops
.yylookaheadNeeds
[yyk
])
1136 yynewOption
->yyrawchar
= yychar
;
1137 yynewOption
->yyval
= yylval
;
1138 yynewOption
->yyloc
= yylloc
;
1141 yynewOption
->yyrawchar
= YYEMPTY
;
1142 yynewOption
->yynext
= yystate
->yysemantics
.yyfirstVal
;
1143 yystate
->yysemantics
.yyfirstVal
= yynewOption
;
1145 YY_RESERVE_GLRSTACK (yystackp
);
1150 /** Initialize SET to a singleton set containing an empty stack. */
1152 yyinitStateSet (yyGLRStateSet
* yyset
)
1155 yyset
->yycapacity
= 16;
1156 yyset
->yystates
= (yyGLRState
**) YYMALLOC (16 * sizeof yyset
->yystates
[0]);
1157 if (! yyset
->yystates
)
1159 yyset
->yystates
[0] = NULL
;
1160 yyset
->yylookaheadNeeds
=
1161 (yybool
*) YYMALLOC (16 * sizeof yyset
->yylookaheadNeeds
[0]);
1162 if (! yyset
->yylookaheadNeeds
)
1164 YYFREE (yyset
->yystates
);
1170 static void yyfreeStateSet (yyGLRStateSet
* yyset
)
1172 YYFREE (yyset
->yystates
);
1173 YYFREE (yyset
->yylookaheadNeeds
);
1176 /** Initialize STACK to a single empty stack, with total maximum
1177 * capacity for all stacks of SIZE. */
1179 yyinitGLRStack (yyGLRStack
* yystackp
, size_t yysize
)
1181 yystackp
->yyerrState
= 0;
1183 yystackp
->yyspaceLeft
= yysize
;
1185 (yyGLRStackItem
*) YYMALLOC (yysize
* sizeof yystackp
->yynextFree
[0]);
1186 if (!yystackp
->yyitems
)
1188 yystackp
->yynextFree
= yystackp
->yyitems
;
1189 yystackp
->yysplitPoint
= NULL
;
1190 yystackp
->yylastDeleted
= NULL
;
1191 return yyinitStateSet (&yystackp
->yytops
);
1195 #if YYSTACKEXPANDABLE
1196 # define YYRELOC(YYFROMITEMS,YYTOITEMS,YYX,YYTYPE) \
1197 &((YYTOITEMS) - ((YYFROMITEMS) - (yyGLRStackItem*) (YYX)))->YYTYPE
1199 /** If STACK is expandable, extend it. WARNING: Pointers into the
1200 stack from outside should be considered invalid after this call.
1201 We always expand when there are 1 or fewer items left AFTER an
1202 allocation, so that we can avoid having external pointers exist
1203 across an allocation. */
1205 yyexpandGLRStack (yyGLRStack
* yystackp
)
1207 yyGLRStackItem
* yynewItems
;
1208 yyGLRStackItem
* yyp0
, *yyp1
;
1209 size_t yysize
, yynewSize
;
1211 yysize
= yystackp
->yynextFree
- yystackp
->yyitems
;
1212 if (YYMAXDEPTH
- YYHEADROOM
< yysize
)
1213 yyMemoryExhausted (yystackp
);
1214 yynewSize
= 2*yysize
;
1215 if (YYMAXDEPTH
< yynewSize
)
1216 yynewSize
= YYMAXDEPTH
;
1217 yynewItems
= (yyGLRStackItem
*) YYMALLOC (yynewSize
* sizeof yynewItems
[0]);
1219 yyMemoryExhausted (yystackp
);
1220 for (yyp0
= yystackp
->yyitems
, yyp1
= yynewItems
, yyn
= yysize
;
1222 yyn
-= 1, yyp0
+= 1, yyp1
+= 1)
1225 if (*(yybool
*) yyp0
)
1227 yyGLRState
* yys0
= &yyp0
->yystate
;
1228 yyGLRState
* yys1
= &yyp1
->yystate
;
1229 if (yys0
->yypred
!= NULL
)
1231 YYRELOC (yyp0
, yyp1
, yys0
->yypred
, yystate
);
1232 if (! yys0
->yyresolved
&& yys0
->yysemantics
.yyfirstVal
!= NULL
)
1233 yys1
->yysemantics
.yyfirstVal
=
1234 YYRELOC(yyp0
, yyp1
, yys0
->yysemantics
.yyfirstVal
, yyoption
);
1238 yySemanticOption
* yyv0
= &yyp0
->yyoption
;
1239 yySemanticOption
* yyv1
= &yyp1
->yyoption
;
1240 if (yyv0
->yystate
!= NULL
)
1241 yyv1
->yystate
= YYRELOC (yyp0
, yyp1
, yyv0
->yystate
, yystate
);
1242 if (yyv0
->yynext
!= NULL
)
1243 yyv1
->yynext
= YYRELOC (yyp0
, yyp1
, yyv0
->yynext
, yyoption
);
1246 if (yystackp
->yysplitPoint
!= NULL
)
1247 yystackp
->yysplitPoint
= YYRELOC (yystackp
->yyitems
, yynewItems
,
1248 yystackp
->yysplitPoint
, yystate
);
1250 for (yyn
= 0; yyn
< yystackp
->yytops
.yysize
; yyn
+= 1)
1251 if (yystackp
->yytops
.yystates
[yyn
] != NULL
)
1252 yystackp
->yytops
.yystates
[yyn
] =
1253 YYRELOC (yystackp
->yyitems
, yynewItems
,
1254 yystackp
->yytops
.yystates
[yyn
], yystate
);
1255 YYFREE (yystackp
->yyitems
);
1256 yystackp
->yyitems
= yynewItems
;
1257 yystackp
->yynextFree
= yynewItems
+ yysize
;
1258 yystackp
->yyspaceLeft
= yynewSize
- yysize
;
1263 yyfreeGLRStack (yyGLRStack
* yystackp
)
1265 YYFREE (yystackp
->yyitems
);
1266 yyfreeStateSet (&yystackp
->yytops
);
1269 /** Assuming that S is a GLRState somewhere on STACK, update the
1270 * splitpoint of STACK, if needed, so that it is at least as deep as
1273 yyupdateSplit (yyGLRStack
* yystackp
, yyGLRState
* yys
)
1275 if (yystackp
->yysplitPoint
!= NULL
&& yystackp
->yysplitPoint
> yys
)
1276 yystackp
->yysplitPoint
= yys
;
1279 /** Invalidate stack #K in STACK. */
1281 yymarkStackDeleted (yyGLRStack
* yystackp
, size_t yyk
)
1283 if (yystackp
->yytops
.yystates
[yyk
] != NULL
)
1284 yystackp
->yylastDeleted
= yystackp
->yytops
.yystates
[yyk
];
1285 yystackp
->yytops
.yystates
[yyk
] = NULL
;
1288 /** Undelete the last stack that was marked as deleted. Can only be
1289 done once after a deletion, and only when all other stacks have
1292 yyundeleteLastStack (yyGLRStack
* yystackp
)
1294 if (yystackp
->yylastDeleted
== NULL
|| yystackp
->yytops
.yysize
!= 0)
1296 yystackp
->yytops
.yystates
[0] = yystackp
->yylastDeleted
;
1297 yystackp
->yytops
.yysize
= 1;
1298 YYDPRINTF ((stderr
, "Restoring last deleted stack as stack #0.\n"));
1299 yystackp
->yylastDeleted
= NULL
;
1303 yyremoveDeletes (yyGLRStack
* yystackp
)
1307 while (yyj
< yystackp
->yytops
.yysize
)
1309 if (yystackp
->yytops
.yystates
[yyi
] == NULL
)
1313 YYDPRINTF ((stderr
, "Removing dead stacks.\n"));
1315 yystackp
->yytops
.yysize
-= 1;
1319 yystackp
->yytops
.yystates
[yyj
] = yystackp
->yytops
.yystates
[yyi
];
1320 /* In the current implementation, it's unnecessary to copy
1321 yystackp->yytops.yylookaheadNeeds[yyi] since, after
1322 yyremoveDeletes returns, the parser immediately either enters
1323 deterministic operation or shifts a token. However, it doesn't
1324 hurt, and the code might evolve to need it. */
1325 yystackp
->yytops
.yylookaheadNeeds
[yyj
] =
1326 yystackp
->yytops
.yylookaheadNeeds
[yyi
];
1329 YYDPRINTF ((stderr
, "Rename stack %lu -> %lu.\n",
1330 (unsigned long int) yyi
, (unsigned long int) yyj
));
1338 /** Shift to a new state on stack #K of STACK, corresponding to LR state
1339 * LRSTATE, at input position POSN, with (resolved) semantic value SVAL. */
1341 yyglrShift (yyGLRStack
* yystackp
, size_t yyk
, yyStateNum yylrState
,
1343 YYSTYPE
* yyvalp
, YYLTYPE
* yylocp
)
1345 yyGLRState
* yynewState
= &yynewGLRStackItem (yystackp
, yytrue
)->yystate
;
1347 yynewState
->yylrState
= yylrState
;
1348 yynewState
->yyposn
= yyposn
;
1349 yynewState
->yyresolved
= yytrue
;
1350 yynewState
->yypred
= yystackp
->yytops
.yystates
[yyk
];
1351 yynewState
->yysemantics
.yysval
= *yyvalp
;
1352 yynewState
->yyloc
= *yylocp
;
1353 yystackp
->yytops
.yystates
[yyk
] = yynewState
;
1355 YY_RESERVE_GLRSTACK (yystackp
);
1358 /** Shift stack #K of YYSTACK, to a new state corresponding to LR
1359 * state YYLRSTATE, at input position YYPOSN, with the (unresolved)
1360 * semantic value of YYRHS under the action for YYRULE. */
1362 yyglrShiftDefer (yyGLRStack
* yystackp
, size_t yyk
, yyStateNum yylrState
,
1363 size_t yyposn
, yyGLRState
* rhs
, yyRuleNum yyrule
)
1365 yyGLRState
* yynewState
= &yynewGLRStackItem (yystackp
, yytrue
)->yystate
;
1367 yynewState
->yylrState
= yylrState
;
1368 yynewState
->yyposn
= yyposn
;
1369 yynewState
->yyresolved
= yyfalse
;
1370 yynewState
->yypred
= yystackp
->yytops
.yystates
[yyk
];
1371 yynewState
->yysemantics
.yyfirstVal
= NULL
;
1372 yystackp
->yytops
.yystates
[yyk
] = yynewState
;
1374 /* Invokes YY_RESERVE_GLRSTACK. */
1375 yyaddDeferredAction (yystackp
, yyk
, yynewState
, rhs
, yyrule
);
1378 /** Pop the symbols consumed by reduction #RULE from the top of stack
1379 * #K of STACK, and perform the appropriate semantic action on their
1380 * semantic values. Assumes that all ambiguities in semantic values
1381 * have been previously resolved. Set *VALP to the resulting value,
1382 * and *LOCP to the computed location (if any). Return value is as
1383 * for userAction. */
1384 static inline YYRESULTTAG
1385 yydoAction (yyGLRStack
* yystackp
, size_t yyk
, yyRuleNum yyrule
,
1386 YYSTYPE
* yyvalp
, YYLTYPE
* yylocp
]b4_user_formals
[)
1388 int yynrhs
= yyrhsLength (yyrule
);
1390 if (yystackp
->yysplitPoint
== NULL
)
1392 /* Standard special case: single stack. */
1393 yyGLRStackItem
* rhs
= (yyGLRStackItem
*) yystackp
->yytops
.yystates
[yyk
];
1394 YYASSERT (yyk
== 0);
1395 yystackp
->yynextFree
-= yynrhs
;
1396 yystackp
->yyspaceLeft
+= yynrhs
;
1397 yystackp
->yytops
.yystates
[0] = & yystackp
->yynextFree
[-1].yystate
;
1398 return yyuserAction (yyrule
, yynrhs
, rhs
,
1399 yyvalp
, yylocp
, yystackp
]b4_user_args
[);
1403 /* At present, doAction is never called in nondeterministic
1404 * mode, so this branch is never taken. It is here in
1405 * anticipation of a future feature that will allow immediate
1406 * evaluation of selected actions in nondeterministic mode. */
1409 yyGLRStackItem yyrhsVals
[YYMAXRHS
+ YYMAXLEFT
+ 1];
1410 yys
= yyrhsVals
[YYMAXRHS
+ YYMAXLEFT
].yystate
.yypred
1411 = yystackp
->yytops
.yystates
[yyk
];]b4_locations_if([[
1413 /* Set default location. */
1414 yyrhsVals
[YYMAXRHS
+ YYMAXLEFT
- 1].yystate
.yyloc
= yys
->yyloc
;]])[
1415 for (yyi
= 0; yyi
< yynrhs
; yyi
+= 1)
1420 yyupdateSplit (yystackp
, yys
);
1421 yystackp
->yytops
.yystates
[yyk
] = yys
;
1422 return yyuserAction (yyrule
, yynrhs
, yyrhsVals
+ YYMAXRHS
+ YYMAXLEFT
- 1,
1423 yyvalp
, yylocp
, yystackp
]b4_user_args
[);
1428 # define YY_REDUCE_PRINT(Args)
1430 # define YY_REDUCE_PRINT(Args) \
1433 yy_reduce_print Args; \
1436 /*----------------------------------------------------------.
1437 | Report that the RULE is going to be reduced on stack #K. |
1438 `----------------------------------------------------------*/
1440 /*ARGSUSED*/ static inline void
1441 yy_reduce_print (yyGLRStack
* yystackp
, size_t yyk
, yyRuleNum yyrule
,
1442 YYSTYPE
* yyvalp
, YYLTYPE
* yylocp
]b4_user_formals
[)
1444 int yynrhs
= yyrhsLength (yyrule
);
1445 yybool yynormal
__attribute__ ((__unused__
)) =
1446 (yystackp
->yysplitPoint
== NULL
);
1447 yyGLRStackItem
* yyvsp
= (yyGLRStackItem
*) yystackp
->yytops
.yystates
[yyk
];
1452 ]b4_parse_param_use
[]dnl
1453 [ YYFPRINTF (stderr
, "Reducing stack %lu by rule %d (line %lu):\n",
1454 (unsigned long int) yyk
, yyrule
- 1,
1455 (unsigned long int) yyrline
[yyrule
]);
1456 /* The symbols being reduced. */
1457 for (yyi
= 0; yyi
< yynrhs
; yyi
++)
1459 fprintf (stderr
, " $%d = ", yyi
+ 1);
1460 yy_symbol_print (stderr
, yyrhs
[yyprhs
[yyrule
] + yyi
],
1461 &]b4_rhs_value(yynrhs
, yyi
+ 1)[
1462 ]b4_locations_if([, &]b4_rhs_location(yynrhs
, yyi
+ 1))[]dnl
1464 fprintf (stderr
, "\n");
1469 /** Pop items off stack #K of STACK according to grammar rule RULE,
1470 * and push back on the resulting nonterminal symbol. Perform the
1471 * semantic action associated with RULE and store its value with the
1472 * newly pushed state, if FORCEEVAL or if STACK is currently
1473 * unambiguous. Otherwise, store the deferred semantic action with
1474 * the new state. If the new state would have an identical input
1475 * position, LR state, and predecessor to an existing state on the stack,
1476 * it is identified with that existing state, eliminating stack #K from
1477 * the STACK. In this case, the (necessarily deferred) semantic value is
1478 * added to the options for the existing state's semantic value.
1480 static inline YYRESULTTAG
1481 yyglrReduce (yyGLRStack
* yystackp
, size_t yyk
, yyRuleNum yyrule
,
1482 yybool yyforceEval
]b4_user_formals
[)
1484 size_t yyposn
= yystackp
->yytops
.yystates
[yyk
]->yyposn
;
1486 if (yyforceEval
|| yystackp
->yysplitPoint
== NULL
)
1491 YY_REDUCE_PRINT ((yystackp
, yyk
, yyrule
, &yysval
, &yyloc
]b4_user_args
[));
1492 YYCHK (yydoAction (yystackp
, yyk
, yyrule
, &yysval
,
1493 &yyloc
]b4_user_args
[));
1494 YY_SYMBOL_PRINT ("-> $$ =", yyr1
[yyrule
], &yysval
, &yyloc
);
1495 yyglrShift (yystackp
, yyk
,
1496 yyLRgotoState (yystackp
->yytops
.yystates
[yyk
]->yylrState
,
1497 yylhsNonterm (yyrule
)),
1498 yyposn
, &yysval
, &yyloc
);
1504 yyGLRState
* yys
, *yys0
= yystackp
->yytops
.yystates
[yyk
];
1505 yyStateNum yynewLRState
;
1507 for (yys
= yystackp
->yytops
.yystates
[yyk
], yyn
= yyrhsLength (yyrule
);
1513 yyupdateSplit (yystackp
, yys
);
1514 yynewLRState
= yyLRgotoState (yys
->yylrState
, yylhsNonterm (yyrule
));
1516 "Reduced stack %lu by rule #%d; action deferred. Now in state %d.\n",
1517 (unsigned long int) yyk
, yyrule
- 1, yynewLRState
));
1518 for (yyi
= 0; yyi
< yystackp
->yytops
.yysize
; yyi
+= 1)
1519 if (yyi
!= yyk
&& yystackp
->yytops
.yystates
[yyi
] != NULL
)
1521 yyGLRState
* yyp
, *yysplit
= yystackp
->yysplitPoint
;
1522 yyp
= yystackp
->yytops
.yystates
[yyi
];
1523 while (yyp
!= yys
&& yyp
!= yysplit
&& yyp
->yyposn
>= yyposn
)
1525 if (yyp
->yylrState
== yynewLRState
&& yyp
->yypred
== yys
)
1527 yyaddDeferredAction (yystackp
, yyk
, yyp
, yys0
, yyrule
);
1528 yymarkStackDeleted (yystackp
, yyk
);
1529 YYDPRINTF ((stderr
, "Merging stack %lu into stack %lu.\n",
1530 (unsigned long int) yyk
,
1531 (unsigned long int) yyi
));
1537 yystackp
->yytops
.yystates
[yyk
] = yys
;
1538 yyglrShiftDefer (yystackp
, yyk
, yynewLRState
, yyposn
, yys0
, yyrule
);
1544 yysplitStack (yyGLRStack
* yystackp
, size_t yyk
)
1546 if (yystackp
->yysplitPoint
== NULL
)
1548 YYASSERT (yyk
== 0);
1549 yystackp
->yysplitPoint
= yystackp
->yytops
.yystates
[yyk
];
1551 if (yystackp
->yytops
.yysize
>= yystackp
->yytops
.yycapacity
)
1553 yyGLRState
** yynewStates
;
1554 yybool
* yynewLookaheadNeeds
;
1558 if (yystackp
->yytops
.yycapacity
1559 > (YYSIZEMAX
/ (2 * sizeof yynewStates
[0])))
1560 yyMemoryExhausted (yystackp
);
1561 yystackp
->yytops
.yycapacity
*= 2;
1564 (yyGLRState
**) YYREALLOC (yystackp
->yytops
.yystates
,
1565 (yystackp
->yytops
.yycapacity
1566 * sizeof yynewStates
[0]));
1567 if (yynewStates
== NULL
)
1568 yyMemoryExhausted (yystackp
);
1569 yystackp
->yytops
.yystates
= yynewStates
;
1571 yynewLookaheadNeeds
=
1572 (yybool
*) YYREALLOC (yystackp
->yytops
.yylookaheadNeeds
,
1573 (yystackp
->yytops
.yycapacity
1574 * sizeof yynewLookaheadNeeds
[0]));
1575 if (yynewLookaheadNeeds
== NULL
)
1576 yyMemoryExhausted (yystackp
);
1577 yystackp
->yytops
.yylookaheadNeeds
= yynewLookaheadNeeds
;
1579 yystackp
->yytops
.yystates
[yystackp
->yytops
.yysize
]
1580 = yystackp
->yytops
.yystates
[yyk
];
1581 yystackp
->yytops
.yylookaheadNeeds
[yystackp
->yytops
.yysize
]
1582 = yystackp
->yytops
.yylookaheadNeeds
[yyk
];
1583 yystackp
->yytops
.yysize
+= 1;
1584 return yystackp
->yytops
.yysize
-1;
1587 /** True iff Y0 and Y1 represent identical options at the top level.
1588 * That is, they represent the same rule applied to RHS symbols
1589 * that produce the same terminal symbols. */
1591 yyidenticalOptions (yySemanticOption
* yyy0
, yySemanticOption
* yyy1
)
1593 if (yyy0
->yyrule
== yyy1
->yyrule
)
1595 yyGLRState
*yys0
, *yys1
;
1597 for (yys0
= yyy0
->yystate
, yys1
= yyy1
->yystate
,
1598 yyn
= yyrhsLength (yyy0
->yyrule
);
1600 yys0
= yys0
->yypred
, yys1
= yys1
->yypred
, yyn
-= 1)
1601 if (yys0
->yyposn
!= yys1
->yyposn
)
1609 /** Assuming identicalOptions (Y0,Y1), destructively merge the
1610 * alternative semantic values for the RHS-symbols of Y1 and Y0. */
1612 yymergeOptionSets (yySemanticOption
* yyy0
, yySemanticOption
* yyy1
)
1614 yyGLRState
*yys0
, *yys1
;
1616 for (yys0
= yyy0
->yystate
, yys1
= yyy1
->yystate
,
1617 yyn
= yyrhsLength (yyy0
->yyrule
);
1619 yys0
= yys0
->yypred
, yys1
= yys1
->yypred
, yyn
-= 1)
1623 else if (yys0
->yyresolved
)
1625 yys1
->yyresolved
= yytrue
;
1626 yys1
->yysemantics
.yysval
= yys0
->yysemantics
.yysval
;
1628 else if (yys1
->yyresolved
)
1630 yys0
->yyresolved
= yytrue
;
1631 yys0
->yysemantics
.yysval
= yys1
->yysemantics
.yysval
;
1635 yySemanticOption
** yyz0p
;
1636 yySemanticOption
* yyz1
;
1637 yyz0p
= &yys0
->yysemantics
.yyfirstVal
;
1638 yyz1
= yys1
->yysemantics
.yyfirstVal
;
1639 while (YYID (yytrue
))
1641 if (yyz1
== *yyz0p
|| yyz1
== NULL
)
1643 else if (*yyz0p
== NULL
)
1648 else if (*yyz0p
< yyz1
)
1650 yySemanticOption
* yyz
= *yyz0p
;
1652 yyz1
= yyz1
->yynext
;
1653 (*yyz0p
)->yynext
= yyz
;
1655 yyz0p
= &(*yyz0p
)->yynext
;
1657 yys1
->yysemantics
.yyfirstVal
= yys0
->yysemantics
.yyfirstVal
;
1662 /** Y0 and Y1 represent two possible actions to take in a given
1663 * parsing state; return 0 if no combination is possible,
1664 * 1 if user-mergeable, 2 if Y0 is preferred, 3 if Y1 is preferred. */
1666 yypreference (yySemanticOption
* y0
, yySemanticOption
* y1
)
1668 yyRuleNum r0
= y0
->yyrule
, r1
= y1
->yyrule
;
1669 int p0
= yydprec
[r0
], p1
= yydprec
[r1
];
1673 if (yymerger
[r0
] == 0 || yymerger
[r0
] != yymerger
[r1
])
1678 if (p0
== 0 || p1
== 0)
1687 static YYRESULTTAG
yyresolveValue (yyGLRState
* yys
,
1688 yyGLRStack
* yystackp
]b4_user_formals
[);
1691 /** Resolve the previous N states starting at and including state S. If result
1692 * != yyok, some states may have been left unresolved possibly with empty
1693 * semantic option chains. Regardless of whether result = yyok, each state
1694 * has been left with consistent data so that yydestroyGLRState can be invoked
1697 yyresolveStates (yyGLRState
* yys
, int yyn
,
1698 yyGLRStack
* yystackp
]b4_user_formals
[)
1702 YYASSERT (yys
->yypred
);
1703 YYCHK (yyresolveStates (yys
->yypred
, yyn
-1, yystackp
]b4_user_args
[));
1704 if (! yys
->yyresolved
)
1705 YYCHK (yyresolveValue (yys
, yystackp
]b4_user_args
[));
1710 /** Resolve the states for the RHS of OPT, perform its user action, and return
1711 * the semantic value and location. Regardless of whether result = yyok, all
1712 * RHS states have been destroyed (assuming the user action destroys all RHS
1713 * semantic values if invoked). */
1715 yyresolveAction (yySemanticOption
* yyopt
, yyGLRStack
* yystackp
,
1716 YYSTYPE
* yyvalp
, YYLTYPE
* yylocp
]b4_user_formals
[)
1718 yyGLRStackItem yyrhsVals
[YYMAXRHS
+ YYMAXLEFT
+ 1];
1721 YYSTYPE yylval_current
;
1722 YYLTYPE yylloc_current
;
1725 yynrhs
= yyrhsLength (yyopt
->yyrule
);
1726 yyflag
= yyresolveStates (yyopt
->yystate
, yynrhs
, yystackp
]b4_user_args
[);
1730 for (yys
= yyopt
->yystate
; yynrhs
> 0; yys
= yys
->yypred
, yynrhs
-= 1)
1731 yydestroyGLRState ("Cleanup: popping", yys
]b4_user_args
[);
1735 yyrhsVals
[YYMAXRHS
+ YYMAXLEFT
].yystate
.yypred
= yyopt
->yystate
;]b4_locations_if([[
1737 /* Set default location. */
1738 yyrhsVals
[YYMAXRHS
+ YYMAXLEFT
- 1].yystate
.yyloc
= yyopt
->yystate
->yyloc
;]])[
1739 yychar_current
= yychar
;
1740 yylval_current
= yylval
;
1741 yylloc_current
= yylloc
;
1742 yychar
= yyopt
->yyrawchar
;
1743 yylval
= yyopt
->yyval
;
1744 yylloc
= yyopt
->yyloc
;
1745 yyflag
= yyuserAction (yyopt
->yyrule
, yynrhs
,
1746 yyrhsVals
+ YYMAXRHS
+ YYMAXLEFT
- 1,
1747 yyvalp
, yylocp
, yystackp
]b4_user_args
[);
1748 yychar
= yychar_current
;
1749 yylval
= yylval_current
;
1750 yylloc
= yylloc_current
;
1756 yyreportTree (yySemanticOption
* yyx
, int yyindent
)
1758 int yynrhs
= yyrhsLength (yyx
->yyrule
);
1761 yyGLRState
* yystates
[1 + YYMAXRHS
];
1762 yyGLRState yyleftmost_state
;
1764 for (yyi
= yynrhs
, yys
= yyx
->yystate
; 0 < yyi
; yyi
-= 1, yys
= yys
->yypred
)
1765 yystates
[yyi
] = yys
;
1768 yyleftmost_state
.yyposn
= 0;
1769 yystates
[0] = &yyleftmost_state
;
1774 if (yyx
->yystate
->yyposn
< yys
->yyposn
+ 1)
1775 YYFPRINTF (stderr
, "%*s%s -> <Rule %d, empty>\n",
1776 yyindent
, "", yytokenName (yylhsNonterm (yyx
->yyrule
)),
1779 YYFPRINTF (stderr
, "%*s%s -> <Rule %d, tokens %lu .. %lu>\n",
1780 yyindent
, "", yytokenName (yylhsNonterm (yyx
->yyrule
)),
1781 yyx
->yyrule
- 1, (unsigned long int) (yys
->yyposn
+ 1),
1782 (unsigned long int) yyx
->yystate
->yyposn
);
1783 for (yyi
= 1; yyi
<= yynrhs
; yyi
+= 1)
1785 if (yystates
[yyi
]->yyresolved
)
1787 if (yystates
[yyi
-1]->yyposn
+1 > yystates
[yyi
]->yyposn
)
1788 YYFPRINTF (stderr
, "%*s%s <empty>\n", yyindent
+2, "",
1789 yytokenName (yyrhs
[yyprhs
[yyx
->yyrule
]+yyi
-1]));
1791 YYFPRINTF (stderr
, "%*s%s <tokens %lu .. %lu>\n", yyindent
+2, "",
1792 yytokenName (yyrhs
[yyprhs
[yyx
->yyrule
]+yyi
-1]),
1793 (unsigned long int) (yystates
[yyi
- 1]->yyposn
+ 1),
1794 (unsigned long int) yystates
[yyi
]->yyposn
);
1797 yyreportTree (yystates
[yyi
]->yysemantics
.yyfirstVal
, yyindent
+2);
1802 /*ARGSUSED*/ static YYRESULTTAG
1803 yyreportAmbiguity (yySemanticOption
* yyx0
,
1804 yySemanticOption
* yyx1
]b4_pure_formals
[)
1810 YYFPRINTF (stderr
, "Ambiguity detected.\n");
1811 YYFPRINTF (stderr
, "Option 1,\n");
1812 yyreportTree (yyx0
, 2);
1813 YYFPRINTF (stderr
, "\nOption 2,\n");
1814 yyreportTree (yyx1
, 2);
1815 YYFPRINTF (stderr
, "\n");
1818 yyerror (]b4_yyerror_args
[YY_("syntax is ambiguous"));
1822 /** Starting at and including state S1, resolve the location for each of the
1823 * previous N1 states that is unresolved. The first semantic option of a state
1824 * is always chosen. */
1826 yyresolveLocations (yyGLRState
* yys1
, int yyn1
,
1827 yyGLRStack
*yystackp
]b4_user_formals
[)
1831 yyresolveLocations (yys1
->yypred
, yyn1
- 1, yystackp
]b4_user_args
[);
1832 if (!yys1
->yyresolved
)
1834 yySemanticOption
*yyoption
;
1835 yyGLRStackItem yyrhsloc
[1 + YYMAXRHS
];
1838 YYSTYPE yylval_current
;
1839 YYLTYPE yylloc_current
;
1840 yyoption
= yys1
->yysemantics
.yyfirstVal
;
1841 YYASSERT (yyoption
!= NULL
);
1842 yynrhs
= yyrhsLength (yyoption
->yyrule
);
1847 yyresolveLocations (yyoption
->yystate
, yynrhs
,
1848 yystackp
]b4_user_args
[);
1849 for (yys
= yyoption
->yystate
, yyn
= yynrhs
;
1851 yys
= yys
->yypred
, yyn
-= 1)
1852 yyrhsloc
[yyn
].yystate
.yyloc
= yys
->yyloc
;
1856 /* Both yyresolveAction and yyresolveLocations traverse the GSS
1857 in reverse rightmost order. It is only necessary to invoke
1858 yyresolveLocations on a subforest for which yyresolveAction
1859 would have been invoked next had an ambiguity not been
1860 detected. Thus the location of the previous state (but not
1861 necessarily the previous state itself) is guaranteed to be
1862 resolved already. */
1863 yyGLRState
*yyprevious
= yyoption
->yystate
;
1864 yyrhsloc
[0].yystate
.yyloc
= yyprevious
->yyloc
;
1866 yychar_current
= yychar
;
1867 yylval_current
= yylval
;
1868 yylloc_current
= yylloc
;
1869 yychar
= yyoption
->yyrawchar
;
1870 yylval
= yyoption
->yyval
;
1871 yylloc
= yyoption
->yyloc
;
1872 YYLLOC_DEFAULT ((yys1
->yyloc
), yyrhsloc
, yynrhs
);
1873 yychar
= yychar_current
;
1874 yylval
= yylval_current
;
1875 yylloc
= yylloc_current
;
1880 /** Resolve the ambiguity represented in state S, perform the indicated
1881 * actions, and set the semantic value of S. If result != yyok, the chain of
1882 * semantic options in S has been cleared instead or it has been left
1883 * unmodified except that redundant options may have been removed. Regardless
1884 * of whether result = yyok, S has been left with consistent data so that
1885 * yydestroyGLRState can be invoked if necessary. */
1887 yyresolveValue (yyGLRState
* yys
, yyGLRStack
* yystackp
]b4_user_formals
[)
1889 yySemanticOption
* yyoptionList
= yys
->yysemantics
.yyfirstVal
;
1890 yySemanticOption
* yybest
;
1891 yySemanticOption
** yypp
;
1895 YYLTYPE
*yylocp
= &yys
->yyloc
;
1897 yybest
= yyoptionList
;
1899 for (yypp
= &yyoptionList
->yynext
; *yypp
!= NULL
; )
1901 yySemanticOption
* yyp
= *yypp
;
1903 if (yyidenticalOptions (yybest
, yyp
))
1905 yymergeOptionSets (yybest
, yyp
);
1906 *yypp
= yyp
->yynext
;
1910 switch (yypreference (yybest
, yyp
))
1913 yyresolveLocations (yys
, 1, yystackp
]b4_user_args
[);
1914 return yyreportAmbiguity (yybest
, yyp
]b4_pure_args
[);
1926 /* This cannot happen so it is not worth a YYASSERT (yyfalse),
1927 but some compilers complain if the default case is
1931 yypp
= &yyp
->yynext
;
1937 yySemanticOption
* yyp
;
1938 int yyprec
= yydprec
[yybest
->yyrule
];
1939 yyflag
= yyresolveAction (yybest
, yystackp
, &yysval
,
1940 yylocp
]b4_user_args
[);
1942 for (yyp
= yybest
->yynext
; yyp
!= NULL
; yyp
= yyp
->yynext
)
1944 if (yyprec
== yydprec
[yyp
->yyrule
])
1946 YYSTYPE yysval_other
;
1948 yyflag
= yyresolveAction (yyp
, yystackp
, &yysval_other
,
1949 &yydummy
]b4_user_args
[);
1952 yydestruct ("Cleanup: discarding incompletely merged value for",
1953 yystos
[yys
->yylrState
],
1954 &yysval
]b4_locations_if([, yylocp
])[]b4_user_args
[);
1957 yyuserMerge (yymerger
[yyp
->yyrule
], &yysval
, &yysval_other
);
1962 yyflag
= yyresolveAction (yybest
, yystackp
, &yysval
, yylocp
]b4_user_args
[);
1966 yys
->yyresolved
= yytrue
;
1967 yys
->yysemantics
.yysval
= yysval
;
1970 yys
->yysemantics
.yyfirstVal
= NULL
;
1975 yyresolveStack (yyGLRStack
* yystackp
]b4_user_formals
[)
1977 if (yystackp
->yysplitPoint
!= NULL
)
1982 for (yyn
= 0, yys
= yystackp
->yytops
.yystates
[0];
1983 yys
!= yystackp
->yysplitPoint
;
1984 yys
= yys
->yypred
, yyn
+= 1)
1986 YYCHK (yyresolveStates (yystackp
->yytops
.yystates
[0], yyn
, yystackp
1993 yycompressStack (yyGLRStack
* yystackp
)
1995 yyGLRState
* yyp
, *yyq
, *yyr
;
1997 if (yystackp
->yytops
.yysize
!= 1 || yystackp
->yysplitPoint
== NULL
)
2000 for (yyp
= yystackp
->yytops
.yystates
[0], yyq
= yyp
->yypred
, yyr
= NULL
;
2001 yyp
!= yystackp
->yysplitPoint
;
2002 yyr
= yyp
, yyp
= yyq
, yyq
= yyp
->yypred
)
2005 yystackp
->yyspaceLeft
+= yystackp
->yynextFree
- yystackp
->yyitems
;
2006 yystackp
->yynextFree
= ((yyGLRStackItem
*) yystackp
->yysplitPoint
) + 1;
2007 yystackp
->yyspaceLeft
-= yystackp
->yynextFree
- yystackp
->yyitems
;
2008 yystackp
->yysplitPoint
= NULL
;
2009 yystackp
->yylastDeleted
= NULL
;
2013 yystackp
->yynextFree
->yystate
= *yyr
;
2015 yystackp
->yynextFree
->yystate
.yypred
= &yystackp
->yynextFree
[-1].yystate
;
2016 yystackp
->yytops
.yystates
[0] = &yystackp
->yynextFree
->yystate
;
2017 yystackp
->yynextFree
+= 1;
2018 yystackp
->yyspaceLeft
-= 1;
2023 yyprocessOneStack (yyGLRStack
* yystackp
, size_t yyk
,
2024 size_t yyposn
]b4_pure_formals
[)
2027 const short int* yyconflicts
;
2030 while (yystackp
->yytops
.yystates
[yyk
] != NULL
)
2032 yyStateNum yystate
= yystackp
->yytops
.yystates
[yyk
]->yylrState
;
2033 YYDPRINTF ((stderr
, "Stack %lu Entering state %d\n",
2034 (unsigned long int) yyk
, yystate
));
2036 YYASSERT (yystate
!= YYFINAL
);
2038 if (yyisDefaultedState (yystate
))
2040 yyrule
= yydefaultAction (yystate
);
2043 YYDPRINTF ((stderr
, "Stack %lu dies.\n",
2044 (unsigned long int) yyk
));
2045 yymarkStackDeleted (yystackp
, yyk
);
2048 YYCHK (yyglrReduce (yystackp
, yyk
, yyrule
, yyfalse
]b4_user_args
[));
2053 yystackp
->yytops
.yylookaheadNeeds
[yyk
] = yytrue
;
2054 if (yychar
== YYEMPTY
)
2056 YYDPRINTF ((stderr
, "Reading a token: "));
2060 if (yychar
<= YYEOF
)
2062 yychar
= yytoken
= YYEOF
;
2063 YYDPRINTF ((stderr
, "Now at end of input.\n"));
2067 yytoken
= YYTRANSLATE (yychar
);
2068 YY_SYMBOL_PRINT ("Next token is", yytoken
, &yylval
, &yylloc
);
2071 yygetLRActions (yystate
, yytoken
, &yyaction
, &yyconflicts
);
2073 while (*yyconflicts
!= 0)
2075 size_t yynewStack
= yysplitStack (yystackp
, yyk
);
2076 YYDPRINTF ((stderr
, "Splitting off stack %lu from %lu.\n",
2077 (unsigned long int) yynewStack
,
2078 (unsigned long int) yyk
));
2079 YYCHK (yyglrReduce (yystackp
, yynewStack
,
2080 *yyconflicts
, yyfalse
]b4_user_args
[));
2081 YYCHK (yyprocessOneStack (yystackp
, yynewStack
,
2082 yyposn
]b4_pure_args
[));
2086 if (yyisShiftAction (yyaction
))
2088 else if (yyisErrorAction (yyaction
))
2090 YYDPRINTF ((stderr
, "Stack %lu dies.\n",
2091 (unsigned long int) yyk
));
2092 yymarkStackDeleted (yystackp
, yyk
);
2096 YYCHK (yyglrReduce (yystackp
, yyk
, -yyaction
,
2097 yyfalse
]b4_user_args
[));
2103 /*ARGSUSED*/ static void
2104 yyreportSyntaxError (yyGLRStack
* yystackp
]b4_user_formals
[)
2106 if (yystackp
->yyerrState
== 0)
2110 yyn
= yypact
[yystackp
->yytops
.yystates
[0]->yylrState
];
2111 if (YYPACT_NINF
< yyn
&& yyn
<= YYLAST
)
2113 yySymbol yytoken
= YYTRANSLATE (yychar
);
2114 size_t yysize0
= yytnamerr (NULL
, yytokenName (yytoken
));
2115 size_t yysize
= yysize0
;
2117 yybool yysize_overflow
= yyfalse
;
2119 enum { YYERROR_VERBOSE_ARGS_MAXIMUM
= 5 };
2120 char const *yyarg
[YYERROR_VERBOSE_ARGS_MAXIMUM
];
2124 static char const yyunexpected
[] = "syntax error, unexpected %s";
2125 static char const yyexpecting
[] = ", expecting %s";
2126 static char const yyor
[] = " or %s";
2127 char yyformat
[sizeof yyunexpected
2128 + sizeof yyexpecting
- 1
2129 + ((YYERROR_VERBOSE_ARGS_MAXIMUM
- 2)
2130 * (sizeof yyor
- 1))];
2131 char const *yyprefix
= yyexpecting
;
2133 /* Start YYX at -YYN if negative to avoid negative indexes in
2135 int yyxbegin
= yyn
< 0 ? -yyn
: 0;
2137 /* Stay within bounds of both yycheck and yytname. */
2138 int yychecklim
= YYLAST
- yyn
+ 1;
2139 int yyxend
= yychecklim
< YYNTOKENS
? yychecklim
: YYNTOKENS
;
2142 yyarg
[0] = yytokenName (yytoken
);
2143 yyfmt
= yystpcpy (yyformat
, yyunexpected
);
2145 for (yyx
= yyxbegin
; yyx
< yyxend
; ++yyx
)
2146 if (yycheck
[yyx
+ yyn
] == yyx
&& yyx
!= YYTERROR
)
2148 if (yycount
== YYERROR_VERBOSE_ARGS_MAXIMUM
)
2152 yyformat
[sizeof yyunexpected
- 1] = '\0';
2155 yyarg
[yycount
++] = yytokenName (yyx
);
2156 yysize1
= yysize
+ yytnamerr (NULL
, yytokenName (yyx
));
2157 yysize_overflow
|= yysize1
< yysize
;
2159 yyfmt
= yystpcpy (yyfmt
, yyprefix
);
2163 yyf
= YY_(yyformat
);
2164 yysize1
= yysize
+ strlen (yyf
);
2165 yysize_overflow
|= yysize1
< yysize
;
2168 if (!yysize_overflow
)
2169 yymsg
= (char *) YYMALLOC (yysize
);
2175 while ((*yyp
= *yyf
))
2177 if (*yyp
== '%' && yyf
[1] == 's' && yyi
< yycount
)
2179 yyp
+= yytnamerr (yyp
, yyarg
[yyi
++]);
2188 yyerror (]b4_lyyerror_args
[yymsg
);
2193 yyerror (]b4_lyyerror_args
[YY_("syntax error"));
2194 yyMemoryExhausted (yystackp
);
2198 #endif /* YYERROR_VERBOSE */
2199 yyerror (]b4_lyyerror_args
[YY_("syntax error"));
2204 /* Recover from a syntax error on *YYSTACKP, assuming that *YYSTACKP->YYTOKENP,
2205 yylval, and yylloc are the syntactic category, semantic value, and location
2206 of the lookahead. */
2207 /*ARGSUSED*/ static void
2208 yyrecoverSyntaxError (yyGLRStack
* yystackp
]b4_user_formals
[)
2213 if (yystackp
->yyerrState
== 3)
2214 /* We just shifted the error token and (perhaps) took some
2215 reductions. Skip tokens until we can proceed. */
2216 while (YYID (yytrue
))
2219 if (yychar
== YYEOF
)
2220 yyFail (yystackp
][]b4_lpure_args
[, NULL
);
2221 if (yychar
!= YYEMPTY
)
2222 {]b4_locations_if([[
2223 /* We throw away the lookahead, but the error range
2224 of the shifted error token must take it into account. */
2225 yyGLRState
*yys
= yystackp
->yytops
.yystates
[0];
2226 yyGLRStackItem yyerror_range
[3];
2227 yyerror_range
[1].yystate
.yyloc
= yys
->yyloc
;
2228 yyerror_range
[2].yystate
.yyloc
= yylloc
;
2229 YYLLOC_DEFAULT ((yys
->yyloc
), yyerror_range
, 2);]])[
2230 yytoken
= YYTRANSLATE (yychar
);
2231 yydestruct ("Error: discarding",
2232 yytoken
, &yylval
]b4_locations_if([, &yylloc
])[]b4_user_args
[);
2234 YYDPRINTF ((stderr
, "Reading a token: "));
2236 if (yychar
<= YYEOF
)
2238 yychar
= yytoken
= YYEOF
;
2239 YYDPRINTF ((stderr
, "Now at end of input.\n"));
2243 yytoken
= YYTRANSLATE (yychar
);
2244 YY_SYMBOL_PRINT ("Next token is", yytoken
, &yylval
, &yylloc
);
2246 yyj
= yypact
[yystackp
->yytops
.yystates
[0]->yylrState
];
2247 if (yyis_pact_ninf (yyj
))
2250 if (yyj
< 0 || YYLAST
< yyj
|| yycheck
[yyj
] != yytoken
)
2252 if (yydefact
[yystackp
->yytops
.yystates
[0]->yylrState
] != 0)
2255 else if (yytable
[yyj
] != 0 && ! yyis_table_ninf (yytable
[yyj
]))
2259 /* Reduce to one stack. */
2260 for (yyk
= 0; yyk
< yystackp
->yytops
.yysize
; yyk
+= 1)
2261 if (yystackp
->yytops
.yystates
[yyk
] != NULL
)
2263 if (yyk
>= yystackp
->yytops
.yysize
)
2264 yyFail (yystackp
][]b4_lpure_args
[, NULL
);
2265 for (yyk
+= 1; yyk
< yystackp
->yytops
.yysize
; yyk
+= 1)
2266 yymarkStackDeleted (yystackp
, yyk
);
2267 yyremoveDeletes (yystackp
);
2268 yycompressStack (yystackp
);
2270 /* Now pop stack until we find a state that shifts the error token. */
2271 yystackp
->yyerrState
= 3;
2272 while (yystackp
->yytops
.yystates
[0] != NULL
)
2274 yyGLRState
*yys
= yystackp
->yytops
.yystates
[0];
2275 yyj
= yypact
[yys
->yylrState
];
2276 if (! yyis_pact_ninf (yyj
))
2279 if (0 <= yyj
&& yyj
<= YYLAST
&& yycheck
[yyj
] == YYTERROR
2280 && yyisShiftAction (yytable
[yyj
]))
2282 /* Shift the error token having adjusted its location. */
2283 YYLTYPE yyerrloc
;]b4_locations_if([[
2284 yystackp
->yyerror_range
[2].yystate
.yyloc
= yylloc
;
2285 YYLLOC_DEFAULT (yyerrloc
, (yystackp
->yyerror_range
), 2);]])[
2286 YY_SYMBOL_PRINT ("Shifting", yystos
[yytable
[yyj
]],
2287 &yylval
, &yyerrloc
);
2288 yyglrShift (yystackp
, 0, yytable
[yyj
],
2289 yys
->yyposn
, &yylval
, &yyerrloc
);
2290 yys
= yystackp
->yytops
.yystates
[0];
2294 ]b4_locations_if([[ yystackp
->yyerror_range
[1].yystate
.yyloc
= yys
->yyloc
;]])[
2295 if (yys
->yypred
!= NULL
)
2296 yydestroyGLRState ("Error: popping", yys
]b4_user_args
[);
2297 yystackp
->yytops
.yystates
[0] = yys
->yypred
;
2298 yystackp
->yynextFree
-= 1;
2299 yystackp
->yyspaceLeft
+= 1;
2301 if (yystackp
->yytops
.yystates
[0] == NULL
)
2302 yyFail (yystackp
][]b4_lpure_args
[, NULL
);
2305 #define YYCHK1(YYE) \
2315 goto yyuser_error; \
2326 ]b4_c_ansi_function_def([yyparse
], [int], b4_parse_param
)[
2330 yyGLRStack
* const yystackp
= &yystack
;
2333 YYDPRINTF ((stderr
, "Starting parse\n"));
2336 yylval
= yyval_default
;
2338 #if YYLTYPE_IS_TRIVIAL
2339 yylloc
.first_line
= yylloc
.last_line
= ]b4_location_initial_line
[;
2340 yylloc
.first_column
= yylloc
.last_column
= ]b4_location_initial_column
[;
2343 m4_ifdef([b4_initial_action
], [
2344 m4_pushdef([b4_at_dollar
], [yylloc
])dnl
2345 m4_pushdef([b4_dollar_dollar
], [yylval
])dnl
2346 /* User initialization code. */
2347 b4_user_initial_action
2348 m4_popdef([b4_dollar_dollar
])dnl
2349 m4_popdef([b4_at_dollar
])])dnl
2351 if (! yyinitGLRStack (yystackp
, YYINITDEPTH
))
2352 goto yyexhaustedlab
;
2353 switch (YYSETJMP (yystack
.yyexception_buffer
))
2356 case 1: goto yyabortlab
;
2357 case 2: goto yyexhaustedlab
;
2358 default: goto yybuglab
;
2360 yyglrShift (&yystack
, 0, 0, 0, &yylval
, &yylloc
);
2363 while (YYID (yytrue
))
2365 /* For efficiency, we have two loops, the first of which is
2366 specialized to deterministic operation (single stack, no
2367 potential ambiguity). */
2369 while (YYID (yytrue
))
2373 const short int* yyconflicts
;
2375 yyStateNum yystate
= yystack
.yytops
.yystates
[0]->yylrState
;
2376 YYDPRINTF ((stderr
, "Entering state %d\n", yystate
));
2377 if (yystate
== YYFINAL
)
2379 if (yyisDefaultedState (yystate
))
2381 yyrule
= yydefaultAction (yystate
);
2384 ]b4_locations_if([[ yystack
.yyerror_range
[1].yystate
.yyloc
= yylloc
;]])[
2385 yyreportSyntaxError (&yystack
]b4_user_args
[);
2388 YYCHK1 (yyglrReduce (&yystack
, 0, yyrule
, yytrue
]b4_user_args
[));
2393 if (yychar
== YYEMPTY
)
2395 YYDPRINTF ((stderr
, "Reading a token: "));
2399 if (yychar
<= YYEOF
)
2401 yychar
= yytoken
= YYEOF
;
2402 YYDPRINTF ((stderr
, "Now at end of input.\n"));
2406 yytoken
= YYTRANSLATE (yychar
);
2407 YY_SYMBOL_PRINT ("Next token is", yytoken
, &yylval
, &yylloc
);
2410 yygetLRActions (yystate
, yytoken
, &yyaction
, &yyconflicts
);
2411 if (*yyconflicts
!= 0)
2413 if (yyisShiftAction (yyaction
))
2415 YY_SYMBOL_PRINT ("Shifting", yytoken
, &yylval
, &yylloc
);
2418 yyglrShift (&yystack
, 0, yyaction
, yyposn
, &yylval
, &yylloc
);
2419 if (0 < yystack
.yyerrState
)
2420 yystack
.yyerrState
-= 1;
2422 else if (yyisErrorAction (yyaction
))
2424 ]b4_locations_if([[ yystack
.yyerror_range
[1].yystate
.yyloc
= yylloc
;]])[
2425 yyreportSyntaxError (&yystack
]b4_user_args
[);
2429 YYCHK1 (yyglrReduce (&yystack
, 0, -yyaction
, yytrue
]b4_user_args
[));
2433 while (YYID (yytrue
))
2435 yySymbol yytoken_to_shift
;
2438 for (yys
= 0; yys
< yystack
.yytops
.yysize
; yys
+= 1)
2439 yystackp
->yytops
.yylookaheadNeeds
[yys
] = yychar
!= YYEMPTY
;
2441 /* yyprocessOneStack returns one of three things:
2443 - An error flag. If the caller is yyprocessOneStack, it
2444 immediately returns as well. When the caller is finally
2445 yyparse, it jumps to an error label via YYCHK1.
2447 - yyok, but yyprocessOneStack has invoked yymarkStackDeleted
2448 (&yystack, yys), which sets the top state of yys to NULL. Thus,
2449 yyparse's following invocation of yyremoveDeletes will remove
2452 - yyok, when ready to shift a token.
2454 Except in the first case, yyparse will invoke yyremoveDeletes and
2455 then shift the next token onto all remaining stacks. This
2456 synchronization of the shift (that is, after all preceding
2457 reductions on all stacks) helps prevent double destructor calls
2458 on yylval in the event of memory exhaustion. */
2460 for (yys
= 0; yys
< yystack
.yytops
.yysize
; yys
+= 1)
2461 YYCHK1 (yyprocessOneStack (&yystack
, yys
, yyposn
]b4_lpure_args
[));
2462 yyremoveDeletes (&yystack
);
2463 if (yystack
.yytops
.yysize
== 0)
2465 yyundeleteLastStack (&yystack
);
2466 if (yystack
.yytops
.yysize
== 0)
2467 yyFail (&yystack
][]b4_lpure_args
[, YY_("syntax error"));
2468 YYCHK1 (yyresolveStack (&yystack
]b4_user_args
[));
2469 YYDPRINTF ((stderr
, "Returning to deterministic operation.\n"));
2470 ]b4_locations_if([[ yystack
.yyerror_range
[1].yystate
.yyloc
= yylloc
;]])[
2471 yyreportSyntaxError (&yystack
]b4_user_args
[);
2475 /* If any yyglrShift call fails, it will fail after shifting. Thus,
2476 a copy of yylval will already be on stack 0 in the event of a
2477 failure in the following loop. Thus, yychar is set to YYEMPTY
2478 before the loop to make sure the user destructor for yylval isn't
2480 yytoken_to_shift
= YYTRANSLATE (yychar
);
2483 for (yys
= 0; yys
< yystack
.yytops
.yysize
; yys
+= 1)
2486 const short int* yyconflicts
;
2487 yyStateNum yystate
= yystack
.yytops
.yystates
[yys
]->yylrState
;
2488 yygetLRActions (yystate
, yytoken_to_shift
, &yyaction
,
2490 /* Note that yyconflicts were handled by yyprocessOneStack. */
2491 YYDPRINTF ((stderr
, "On stack %lu, ", (unsigned long int) yys
));
2492 YY_SYMBOL_PRINT ("shifting", yytoken_to_shift
, &yylval
, &yylloc
);
2493 yyglrShift (&yystack
, yys
, yyaction
, yyposn
,
2495 YYDPRINTF ((stderr
, "Stack %lu now in state #%d\n",
2496 (unsigned long int) yys
,
2497 yystack
.yytops
.yystates
[yys
]->yylrState
));
2500 if (yystack
.yytops
.yysize
== 1)
2502 YYCHK1 (yyresolveStack (&yystack
]b4_user_args
[));
2503 YYDPRINTF ((stderr
, "Returning to deterministic operation.\n"));
2504 yycompressStack (&yystack
);
2510 yyrecoverSyntaxError (&yystack
]b4_user_args
[);
2511 yyposn
= yystack
.yytops
.yystates
[0]->yyposn
;
2527 yyerror (]b4_lyyerror_args
[YY_("memory exhausted"));
2532 if (yychar
!= YYEMPTY
)
2533 yydestruct ("Cleanup: discarding lookahead",
2534 YYTRANSLATE (yychar
),
2535 &yylval
]b4_locations_if([, &yylloc
])[]b4_user_args
[);
2537 /* If the stack is well-formed, pop the stack until it is empty,
2538 destroying its entries as we go. But free the stack regardless
2539 of whether it is well-formed. */
2540 if (yystack
.yyitems
)
2542 yyGLRState
** yystates
= yystack
.yytops
.yystates
;
2545 size_t yysize
= yystack
.yytops
.yysize
;
2547 for (yyk
= 0; yyk
< yysize
; yyk
+= 1)
2550 while (yystates
[yyk
])
2552 yyGLRState
*yys
= yystates
[yyk
];
2553 ]b4_locations_if([[ yystack
.yyerror_range
[1].yystate
.yyloc
= yys
->yyloc
;]]
2554 )[ if (yys
->yypred
!= NULL
)
2555 yydestroyGLRState ("Cleanup: popping", yys
]b4_user_args
[);
2556 yystates
[yyk
] = yys
->yypred
;
2557 yystack
.yynextFree
-= 1;
2558 yystack
.yyspaceLeft
+= 1;
2563 yyfreeGLRStack (&yystack
);
2566 /* Make sure YYID is used. */
2567 return YYID (yyresult
);
2570 /* DEBUGGING ONLY */
2572 static void yypstack (yyGLRStack
* yystackp
, size_t yyk
)
2573 __attribute__ ((__unused__
));
2574 static void yypdumpstack (yyGLRStack
* yystackp
) __attribute__ ((__unused__
));
2577 yy_yypstack (yyGLRState
* yys
)
2581 yy_yypstack (yys
->yypred
);
2582 fprintf (stderr
, " -> ");
2584 fprintf (stderr
, "%d@@%lu", yys
->yylrState
, (unsigned long int) yys
->yyposn
);
2588 yypstates (yyGLRState
* yyst
)
2591 fprintf (stderr
, "<null>");
2594 fprintf (stderr
, "\n");
2598 yypstack (yyGLRStack
* yystackp
, size_t yyk
)
2600 yypstates (yystackp
->yytops
.yystates
[yyk
]);
2603 #define YYINDEX(YYX) \
2604 ((YYX) == NULL ? -1 : (yyGLRStackItem*) (YYX) - yystackp->yyitems)
2608 yypdumpstack (yyGLRStack
* yystackp
)
2610 yyGLRStackItem
* yyp
;
2612 for (yyp
= yystackp
->yyitems
; yyp
< yystackp
->yynextFree
; yyp
+= 1)
2614 fprintf (stderr
, "%3lu. ", (unsigned long int) (yyp
- yystackp
->yyitems
));
2615 if (*(yybool
*) yyp
)
2617 fprintf (stderr
, "Res: %d, LR State: %d, posn: %lu, pred: %ld",
2618 yyp
->yystate
.yyresolved
, yyp
->yystate
.yylrState
,
2619 (unsigned long int) yyp
->yystate
.yyposn
,
2620 (long int) YYINDEX (yyp
->yystate
.yypred
));
2621 if (! yyp
->yystate
.yyresolved
)
2622 fprintf (stderr
, ", firstVal: %ld",
2623 (long int) YYINDEX (yyp
->yystate
.yysemantics
.yyfirstVal
));
2627 fprintf (stderr
, "Option. rule: %d, state: %ld, next: %ld",
2628 yyp
->yyoption
.yyrule
- 1,
2629 (long int) YYINDEX (yyp
->yyoption
.yystate
),
2630 (long int) YYINDEX (yyp
->yyoption
.yynext
));
2632 fprintf (stderr
, "\n");
2634 fprintf (stderr
, "Tops:");
2635 for (yyi
= 0; yyi
< yystackp
->yytops
.yysize
; yyi
+= 1)
2636 fprintf (stderr
, "%lu: %ld; ", (unsigned long int) yyi
,
2637 (long int) YYINDEX (yystackp
->yytops
.yystates
[yyi
]));
2638 fprintf (stderr
, "\n");
2645 dnl glr
.cc produces its own header
.
2647 m4_if(b4_skeleton
, ["glr.c"],
2649 [@
output(b4_spec_defines_file@
)
2650 b4_copyright([Skeleton interface
for Bison GLR parsers in C
],
2651 [2002, 2003, 2004, 2005, 2006])
2653 b4_shared_declarations
2655 extern YYSTYPE b4_prefix
[]lval
;
2657 b4_locations_if([b4_pure_if([],
2658 [extern YYLTYPE b4_prefix
[]lloc
;])