3 # GLR skeleton for Bison
5 # Copyright (C) 2002-2012 Free Software Foundation, Inc.
7 # This program is free software: you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License as published by
9 # the Free Software Foundation, either version 3 of the License, or
10 # (at your option) any later version.
12 # This program is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
17 # You should have received a copy of the GNU General Public License
18 # along with this program. If not, see <http://www.gnu.org/licenses/>.
21 m4_include(b4_pkgdatadir
/[c
.m4
])
23 ## ---------------- ##
25 ## ---------------- ##
28 m4_define_default([b4_stack_depth_max
], [10000])
29 m4_define_default([b4_stack_depth_init
], [200])
33 ## ------------------------ ##
34 ## Pure/impure interfaces. ##
35 ## ------------------------ ##
37 b4_define_flag_if([pure
])
38 # If glr.cc is including this file and thus has already set b4_pure_flag,
39 # do not change the value of b4_pure_flag, and do not record a use of api.pure.
40 m4_ifndef([b4_pure_flag
],
41 [b4_percent_define_default([[api
.pure
]], [[false]])
42 m4_define([b4_pure_flag
],
43 [b4_percent_define_flag_if([[api
.pure
]], [[1]], [[0]])])])
47 # The possible parse-params formal arguments preceded by a comma.
49 # This is not shared with yacc.c in c.m4 because GLR relies on ISO C
50 # formal argument declarations.
51 m4_define([b4_user_formals
],
52 [m4_ifset([b4_parse_param
], [, b4_c_ansi_formals(b4_parse_param
)])])
57 # Accumule in b4_lex_param all the yylex arguments.
58 # Yes, this is quite ugly...
59 m4_define([b4_lex_param
],
60 m4_dquote(b4_pure_if([[[[YYSTYPE
*]], [[&yylval
]]][]dnl
61 b4_locations_if([, [[YYLTYPE
*], [&yylloc
]]])])dnl
62 m4_ifdef([b4_lex_param
], [, ]b4_lex_param
)))
67 # Optional effective arguments passed to yyerror: user args plus yylloc, and
69 m4_define([b4_yyerror_args
],
70 [b4_pure_if([b4_locations_if([yylocp
, ])])dnl
71 m4_ifset([b4_parse_param
], [b4_c_args(b4_parse_param
), ])])
76 # Same as above, but on the lookahead, hence &yylloc instead of yylocp.
77 m4_define([b4_lyyerror_args
],
78 [b4_pure_if([b4_locations_if([&yylloc
, ])])dnl
79 m4_ifset([b4_parse_param
], [b4_c_args(b4_parse_param
), ])])
84 # Same as b4_yyerror_args, but with a leading comma.
85 m4_define([b4_pure_args
],
86 [b4_pure_if([b4_locations_if([, yylocp
])])[]b4_user_args
])
91 # Same as above, but on the lookahead, hence &yylloc instead of yylocp.
92 m4_define([b4_lpure_args
],
93 [b4_pure_if([b4_locations_if([, &yylloc
])])[]b4_user_args
])
99 # Arguments passed to yyerror: user formals plus yylocp with leading comma.
100 m4_define([b4_pure_formals
],
101 [b4_pure_if([b4_locations_if([, YYLTYPE
*yylocp
])])[]b4_user_formals
])
104 # b4_locuser_formals(LOC = yylocp)
105 # --------------------------------
106 m4_define([b4_locuser_formals
],
107 [b4_locations_if([, YYLTYPE
*m4_default([$
1], [yylocp
])])[]b4_user_formals
])
110 # b4_locuser_args(LOC = yylocp)
111 # -----------------------------
112 m4_define([b4_locuser_args
],
113 [b4_locations_if([, m4_default([$
1], [yylocp
])])[]b4_user_args
])
117 ## ----------------- ##
118 ## Semantic Values. ##
119 ## ----------------- ##
122 # b4_lhs_value([TYPE])
123 # --------------------
124 # Expansion of $<TYPE>$.
125 m4_define([b4_lhs_value
],
126 [b4_symbol_value([(*yyvalp
)], [$
1])])
129 # b4_rhs_data(RULE-LENGTH, NUM)
130 # -----------------------------
131 # Expand to the semantic stack place that contains value and location
132 # of symbol number NUM in a rule of length RULE-LENGTH.
133 m4_define([b4_rhs_data
],
134 [((yyGLRStackItem
const *)yyvsp
)@
{YYFILL (b4_subtract([$
2], [$
1]))@
}.yystate
])
137 # b4_rhs_value(RULE-LENGTH, NUM, [TYPE])
138 # --------------------------------------
139 # Expansion of $<TYPE>NUM, where the current rule has RULE-LENGTH
141 m4_define([b4_rhs_value
],
142 [b4_symbol_value([b4_rhs_data([$
1], [$
2]).yysemantics
.yysval
], [$
3])])
153 m4_define([b4_lhs_location
],
157 # b4_rhs_location(RULE-LENGTH, NUM)
158 # ---------------------------------
159 # Expansion of @NUM, where the current rule has RULE-LENGTH symbols
161 m4_define([b4_rhs_location
],
162 [(b4_rhs_data([$
1], [$
2]).yyloc
)])
169 # b4_shared_declarations
170 # ----------------------
171 # Declaration that might either go into the header (if --defines)
172 # or open coded in the parser body.
173 m4_define([b4_shared_declarations
],
175 ]b4_percent_code_get([[requires]])[
176 ]b4_token_enums(b4_tokens
)[
177 ]b4_declare_yylstype
[
178 ]b4_c_ansi_function_decl(b4_prefix
[parse
], [int], b4_parse_param
)[
179 ]b4_percent_code_get([[provides]])[]dnl
187 # We do want M4 expansion after # for CPP macros.
190 @
output(b4_parser_file_name@
)@
191 b4_copyright([Skeleton implementation
for Bison GLR parsers in C
],
194 /* C GLR parser skeleton written by Paul Hilfinger. */
198 b4_percent_code_get([[top]])[
199 ]m4_if(b4_api_prefix
, [yy
], [],
200 [[/* Substitute the type names. */
201 #define YYSTYPE ]b4_api_PREFIX[STYPE
202 #define YYSTYPE_IS_TRIVIAL ]b4_api_PREFIX[STYPE_IS_TRIVIAL
203 #define YYSTYPE_IS_DECLARED ]b4_api_PREFIX[STYPE_IS_DECLARED]b4_locations_if([[
204 #define YYLTYPE ]b4_api_PREFIX[LTYPE
205 #define YYLTYPE_IS_TRIVIAL ]b4_api_PREFIX[LTYPE_IS_TRIVIAL
206 #define YYLTYPE_IS_DECLARED ]b4_api_PREFIX[LTYPE_IS_DECLARED]])])[
207 ]m4_if(b4_prefix
, [yy
], [],
208 [[/* Substitute the variable and function names. */
209 #define yyparse ]b4_prefix[parse
210 #define yylex ]b4_prefix[lex
211 #define yyerror ]b4_prefix[error
212 #define yylval ]b4_prefix[lval
213 #define yychar ]b4_prefix[char
214 #define yydebug ]b4_prefix[debug
215 #define yynerrs ]b4_prefix[nerrs]b4_locations_if([[
216 #define yylloc ]b4_prefix[lloc]])])[
218 /* Copy the first part of user declarations. */
219 ]b4_user_pre_prologue
[
223 ]b4_defines_if([[#include "@basename(]b4_spec_defines_file[@)"]],
224 [b4_shared_declarations
])[
226 /* Enabling verbose error messages. */
227 #ifdef YYERROR_VERBOSE
228 # undef YYERROR_VERBOSE
229 # define YYERROR_VERBOSE 1
231 # define YYERROR_VERBOSE ]b4_error_verbose_if([1], [0])[
234 /* Default (constant) value used for initialization for null
235 right-hand sides. Unlike the standard yacc.c template,
236 here we set the default value of $$ to a zeroed-out value.
237 Since the default value is undefined, this behavior is
238 technically correct. */
239 static YYSTYPE yyval_default
;
241 /* Copy the second part of user declarations. */
242 ]b4_user_post_prologue
243 b4_percent_code_get
[]dnl
250 # if defined YYENABLE_NLS && YYENABLE_NLS
252 # include <libintl.h> /* INFRINGES ON USER NAME SPACE */
253 # define YY_(msgid) dgettext ("bison-runtime", msgid)
257 # define YY_(msgid) msgid
261 /* Suppress unused-variable warnings by "using" E. */
262 #if ! defined lint || defined __GNUC__
263 # define YYUSE(e) ((void) (e))
265 # define YYUSE(e) /* empty */
268 /* Identity function, used to suppress warnings about constant conditions. */
272 ]b4_c_function_def([YYID
], [static int], [[int i
], [i
]])[
282 # define YYMALLOC malloc
285 # define YYREALLOC realloc
288 #define YYSIZEMAX ((size_t) -1)
293 typedef unsigned char yybool
;
300 # define YYJMP_BUF jmp_buf
301 # define YYSETJMP(env) setjmp (env)
302 # define YYLONGJMP(env, val) longjmp (env, val)
309 #ifndef __attribute__
310 /* This feature is available in gcc versions 2.5 and later. */
311 # if (! defined __GNUC__ || __GNUC__ < 2 \
312 || (__GNUC__ == 2 && __GNUC_MINOR__ < 5))
313 # define __attribute__(Spec) /* empty */
317 ]b4_locations_if([#define YYOPTIONAL_LOC(Name) Name],[
319 # define YYOPTIONAL_LOC(Name) /* empty */
321 # define YYOPTIONAL_LOC(Name) Name __attribute__ ((__unused__))
325 # define YYASSERT(condition) ((void) ((condition) || (abort (), 0)))
328 /* YYFINAL -- State number of the termination state. */
329 #define YYFINAL ]b4_final_state_number[
330 /* YYLAST -- Last index in YYTABLE. */
331 #define YYLAST ]b4_last[
333 /* YYNTOKENS -- Number of terminals. */
334 #define YYNTOKENS ]b4_tokens_number[
335 /* YYNNTS -- Number of nonterminals. */
336 #define YYNNTS ]b4_nterms_number[
337 /* YYNRULES -- Number of rules. */
338 #define YYNRULES ]b4_rules_number[
339 /* YYNRULES -- Number of states. */
340 #define YYNSTATES ]b4_states_number[
341 /* YYMAXRHS -- Maximum number of symbols on right-hand side of rule. */
342 #define YYMAXRHS ]b4_r2_max[
343 /* YYMAXLEFT -- Maximum number of symbols to the left of a handle
344 accessed by $0, $-1, etc., in any rule. */
345 #define YYMAXLEFT ]b4_max_left_semantic_context[
347 /* YYTRANSLATE(X) -- Bison symbol number corresponding to X. */
348 #define YYUNDEFTOK ]b4_undef_token_number[
349 #define YYMAXUTOK ]b4_user_token_number_max[
351 #define YYTRANSLATE(YYX) \
352 ((unsigned int) (YYX) <= YYMAXUTOK ? yytranslate[YYX] : YYUNDEFTOK)
354 /* YYTRANSLATE[YYLEX] -- Bison symbol number corresponding to YYLEX. */
355 static const ]b4_int_type_for([b4_translate
])[ yytranslate
[] =
361 /* YYRLINE[YYN] -- source line where rule number YYN was defined. */
362 static const ]b4_int_type_for([b4_rline
])[ yyrline
[] =
368 #if YYDEBUG || YYERROR_VERBOSE || ]b4_token_table_flag[
369 /* YYTNAME[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM.
370 First, the terminals, then, starting at YYNTOKENS, nonterminals. */
371 static const char *const yytname
[] =
377 #define YYPACT_NINF ]b4_pact_ninf[
378 #define YYTABLE_NINF ]b4_table_ninf[
380 ]b4_parser_tables_define
[
382 /* YYDPREC[RULE-NUM] -- Dynamic precedence of rule #RULE-NUM (0 if none). */
383 static const ]b4_int_type_for([b4_dprec
])[ yydprec
[] =
388 /* YYMERGER[RULE-NUM] -- Index of merging function for rule #RULE-NUM. */
389 static const ]b4_int_type_for([b4_merger
])[ yymerger
[] =
394 /* YYIMMEDIATE[RULE-NUM] -- True iff rule #RULE-NUM is not to be deferred, as
395 in the case of predicates. */
396 static const yybool yyimmediate
[] =
401 /* YYCONFLP[YYPACT[STATE-NUM]] -- Pointer into YYCONFL of start of
402 list of conflicting reductions corresponding to action entry for
403 state STATE-NUM in yytable. 0 means no conflicts. The list in
404 yyconfl is terminated by a rule number of 0. */
405 static const ]b4_int_type_for([b4_conflict_list_heads
])[ yyconflp
[] =
407 ]b4_conflict_list_heads
[
410 /* YYCONFL[I] -- lists of conflicting rule numbers, each terminated by
411 0, pointed into by YYCONFLP. */
412 ]dnl Do
not use b4_int_type_for here
, since there are places where
413 dnl pointers onto yyconfl are taken
, which type is
"short int *".
414 dnl We probably ought to introduce a type
for confl
.
415 [static const short int yyconfl
[] =
417 ]b4_conflicting_rules
[
420 /* Error token number */
423 /* YYLLOC_DEFAULT -- Set CURRENT to span from RHS[1] to RHS[N].
424 If N is 0, then set CURRENT to the empty location which ends
425 the previous symbol: RHS[0] (always defined). */
428 #define YYRHSLOC(Rhs, K) ((Rhs)[K].yystate.yyloc)
429 #ifndef YYLLOC_DEFAULT
430 # define YYLLOC_DEFAULT(Current, Rhs, N) \
434 (Current).first_line = YYRHSLOC (Rhs, 1).first_line; \
435 (Current).first_column = YYRHSLOC (Rhs, 1).first_column; \
436 (Current).last_line = YYRHSLOC (Rhs, N).last_line; \
437 (Current).last_column = YYRHSLOC (Rhs, N).last_column; \
441 (Current).first_line = (Current).last_line = \
442 YYRHSLOC (Rhs, 0).last_line; \
443 (Current).first_column = (Current).last_column = \
444 YYRHSLOC (Rhs, 0).last_column; \
448 /* YY_LOCATION_PRINT -- Print the location on the stream.
449 This macro was not mandated originally: define only if we know
450 we won't break user code: when these are the locations we know. */
452 # define YY_LOCATION_PRINT(File, Loc) \
453 fprintf (File, "%d.%d-%d.%d", \
454 (Loc).first_line, (Loc).first_column, \
455 (Loc).last_line, (Loc).last_column)
458 #ifndef YYLLOC_DEFAULT
459 # define YYLLOC_DEFAULT(Current, Rhs, N) ((void) 0)
463 #ifndef YY_LOCATION_PRINT
464 # define YY_LOCATION_PRINT(File, Loc) ((void) 0)
468 /* YYLEX -- calling `yylex' with the right arguments. */
469 #define YYLEX ]b4_c_function_call([yylex], [int], b4_lex_param)[
474 #define yynerrs (yystackp->yyerrcnt)
476 #define yychar (yystackp->yyrawchar)
478 #define yylval (yystackp->yyval)
480 #define yylloc (yystackp->yyloc)
481 m4_if(b4_prefix
[], [yy
], [],
482 [#define b4_prefix[]nerrs yynerrs
483 #define b4_prefix[]char yychar
484 #define b4_prefix[]lval yylval
485 #define b4_prefix[]lloc yylloc])],
486 [YYSTYPE yylval
;]b4_locations_if([[
492 static const int YYEOF
= 0;
493 static const int YYEMPTY
= -2;
495 typedef enum { yyok
, yyaccept
, yyabort
, yyerr
} YYRESULTTAG
;
499 YYRESULTTAG yychk_flag = YYE; \
500 if (yychk_flag != yyok) \
507 # define YYFPRINTF fprintf
510 # define YYDPRINTF(Args) \
516 ]b4_yy_symbol_print_generate([b4_c_ansi_function_def
])[
518 # define YY_SYMBOL_PRINT(Title, Type, Value, Location) \
522 YYFPRINTF (stderr, "%s ", Title); \
523 yy_symbol_print (stderr, Type, Value]b4_locuser_args([Location])[); \
524 YYFPRINTF (stderr, "\n"); \
528 /* Nonzero means print parse trace. It is left uninitialized so that
529 multiple parsers can coexist. */
534 # define YYDPRINTF(Args)
535 # define YY_SYMBOL_PRINT(Title, Type, Value, Location)
537 #endif /* !YYDEBUG */
539 /* YYINITDEPTH -- initial size of the parser's stacks. */
541 # define YYINITDEPTH ]b4_stack_depth_init[
544 /* YYMAXDEPTH -- maximum size the stacks can grow to (effective only
545 if the built-in stack extension method is used).
547 Do not make this value too large; the results are undefined if
548 SIZE_MAX < YYMAXDEPTH * sizeof (GLRStackItem)
549 evaluated with infinite-precision integer arithmetic. */
552 # define YYMAXDEPTH ]b4_stack_depth_max[
555 /* Minimum number of free items on the stack allowed after an
556 allocation. This is to allow allocation and initialization
557 to be completed by functions that call yyexpandGLRStack before the
558 stack is expanded, thus insuring that all necessary pointers get
559 properly redirected to new data. */
562 #ifndef YYSTACKEXPANDABLE
563 # define YYSTACKEXPANDABLE 1
566 #if YYSTACKEXPANDABLE
567 # define YY_RESERVE_GLRSTACK(Yystack) \
569 if (Yystack->yyspaceLeft < YYHEADROOM) \
570 yyexpandGLRStack (Yystack); \
573 # define YY_RESERVE_GLRSTACK(Yystack) \
575 if (Yystack->yyspaceLeft < YYHEADROOM) \
576 yyMemoryExhausted (Yystack); \
584 # if defined __GLIBC__ && defined _STRING_H && defined _GNU_SOURCE
585 # define yystpcpy stpcpy
587 /* Copy YYSRC to YYDEST, returning the address of the terminating '\0' in
590 yystpcpy (char *yydest
, const char *yysrc
)
593 const char *yys
= yysrc
;
595 while ((*yyd
++ = *yys
++) != '\0')
604 /* Copy to YYRES the contents of YYSTR after stripping away unnecessary
605 quotes and backslashes, so that it's suitable for yyerror. The
606 heuristic is that double-quoting is unnecessary unless the string
607 contains an apostrophe, a comma, or backslash (other than
608 backslash-backslash). YYSTR is taken from yytname. If YYRES is
609 null, do not copy; instead, return the length of what the result
612 yytnamerr (char *yyres
, const char *yystr
)
617 char const *yyp
= yystr
;
624 goto do_not_strip_quotes
;
628 goto do_not_strip_quotes
;
641 do_not_strip_quotes
: ;
645 return strlen (yystr
);
647 return yystpcpy (yyres
, yystr
) - yyres
;
651 #endif /* !YYERROR_VERBOSE */
653 /** State numbers, as in LALR(1) machine */
654 typedef int yyStateNum
;
656 /** Rule numbers, as in LALR(1) machine */
657 typedef int yyRuleNum
;
659 /** Grammar symbol */
660 typedef int yySymbol
;
662 /** Item references, as in LALR(1) machine */
663 typedef short int yyItemNum
;
665 typedef struct yyGLRState yyGLRState
;
666 typedef struct yyGLRStateSet yyGLRStateSet
;
667 typedef struct yySemanticOption yySemanticOption
;
668 typedef union yyGLRStackItem yyGLRStackItem
;
669 typedef struct yyGLRStack yyGLRStack
;
672 /** Type tag: always true. */
674 /** Type tag for yysemantics. If true, yysval applies, otherwise
675 * yyfirstVal applies. */
677 /** Number of corresponding LALR(1) machine state. */
678 yyStateNum yylrState
;
679 /** Preceding state in this stack */
681 /** Source position of the last token produced by my symbol */
684 /** First in a chain of alternative reductions producing the
685 * non-terminal corresponding to this state, threaded through
687 yySemanticOption
* yyfirstVal
;
688 /** Semantic value for this state. */
690 } yysemantics
;]b4_locations_if([[
691 /** Source location for this state. */
695 struct yyGLRStateSet
{
696 yyGLRState
** yystates
;
697 /** During nondeterministic operation, yylookaheadNeeds tracks which
698 * stacks have actually needed the current lookahead. During deterministic
699 * operation, yylookaheadNeeds[0] is not maintained since it would merely
700 * duplicate yychar != YYEMPTY. */
701 yybool
* yylookaheadNeeds
;
702 size_t yysize
, yycapacity
;
705 struct yySemanticOption
{
706 /** Type tag: always false. */
708 /** Rule number for this reduction */
710 /** The last RHS state in the list of states to be reduced. */
712 /** The lookahead for this reduction. */
714 YYSTYPE yyval
;]b4_locations_if([[
716 /** Next sibling in chain of options. To facilitate merging,
717 * options are chained in decreasing order by address. */
718 yySemanticOption
* yynext
;
721 /** Type of the items in the GLR stack. The yyisState field
722 * indicates which item of the union is valid. */
723 union yyGLRStackItem
{
725 yySemanticOption yyoption
;
730 ]b4_locations_if([[ /* To compute the location of the error token. */
731 yyGLRStackItem yyerror_range
[3];]])[
736 YYSTYPE yyval
;]b4_locations_if([[
739 YYJMP_BUF yyexception_buffer
;
740 yyGLRStackItem
* yyitems
;
741 yyGLRStackItem
* yynextFree
;
743 yyGLRState
* yysplitPoint
;
744 yyGLRState
* yylastDeleted
;
745 yyGLRStateSet yytops
;
748 #if YYSTACKEXPANDABLE
749 static void yyexpandGLRStack (yyGLRStack
* yystackp
);
752 static void yyFail (yyGLRStack
* yystackp
]b4_pure_formals
[, const char* yymsg
)
753 __attribute__ ((__noreturn__
));
755 yyFail (yyGLRStack
* yystackp
]b4_pure_formals
[, const char* yymsg
)
757 if (yymsg
!= YY_NULL
)
758 yyerror (]b4_yyerror_args
[yymsg
);
759 YYLONGJMP (yystackp
->yyexception_buffer
, 1);
762 static void yyMemoryExhausted (yyGLRStack
* yystackp
)
763 __attribute__ ((__noreturn__
));
765 yyMemoryExhausted (yyGLRStack
* yystackp
)
767 YYLONGJMP (yystackp
->yyexception_buffer
, 2);
770 #if YYDEBUG || YYERROR_VERBOSE
771 /** A printable representation of TOKEN. */
772 static inline const char*
773 yytokenName (yySymbol yytoken
)
775 if (yytoken
== YYEMPTY
)
778 return yytname
[yytoken
];
782 /** Fill in YYVSP[YYLOW1 .. YYLOW0-1] from the chain of states starting
783 * at YYVSP[YYLOW0].yystate.yypred. Leaves YYVSP[YYLOW1].yystate.yypred
784 * containing the pointer to the next state in the chain. */
785 static void yyfillin (yyGLRStackItem
*, int, int) __attribute__ ((__unused__
));
787 yyfillin (yyGLRStackItem
*yyvsp
, int yylow0
, int yylow1
)
790 yyGLRState
*s
= yyvsp
[yylow0
].yystate
.yypred
;
791 for (i
= yylow0
-1; i
>= yylow1
; i
-= 1)
794 yyvsp
[i
].yystate
.yylrState
= s
->yylrState
;
796 yyvsp
[i
].yystate
.yyresolved
= s
->yyresolved
;
798 yyvsp
[i
].yystate
.yysemantics
.yysval
= s
->yysemantics
.yysval
;
800 /* The effect of using yysval or yyloc (in an immediate rule) is
802 yyvsp
[i
].yystate
.yysemantics
.yyfirstVal
= YY_NULL
;]b4_locations_if([[
803 yyvsp
[i
].yystate
.yyloc
= s
->yyloc
;]])[
804 s
= yyvsp
[i
].yystate
.yypred
= s
->yypred
;
808 /* Do nothing if YYNORMAL or if *YYLOW <= YYLOW1. Otherwise, fill in
809 * YYVSP[YYLOW1 .. *YYLOW-1] as in yyfillin and set *YYLOW = YYLOW1.
810 * For convenience, always return YYLOW1. */
811 static inline int yyfill (yyGLRStackItem
*, int *, int, yybool
)
812 __attribute__ ((__unused__
));
814 yyfill (yyGLRStackItem
*yyvsp
, int *yylow
, int yylow1
, yybool yynormal
)
816 if (!yynormal
&& yylow1
< *yylow
)
818 yyfillin (yyvsp
, *yylow
, yylow1
);
824 /** Perform user action for rule number YYN, with RHS length YYRHSLEN,
825 * and top stack item YYVSP. YYLVALP points to place to put semantic
826 * value ($$), and yylocp points to place for location information
827 * (@@$). Returns yyok for normal return, yyaccept for YYACCEPT,
828 * yyerr for YYERROR, yyabort for YYABORT. */
829 /*ARGSUSED*/ static YYRESULTTAG
830 yyuserAction (yyRuleNum yyn
, int yyrhslen
, yyGLRStackItem
* yyvsp
,
831 yyGLRStack
* yystackp
,
832 YYSTYPE
* yyvalp
]b4_locuser_formals
[)
834 yybool yynormal
__attribute__ ((__unused__
)) =
835 (yystackp
->yysplitPoint
== YY_NULL
);
837 ]b4_parse_param_use([yyvalp
], [yylocp
])dnl
839 # define yyerrok (yystackp->yyerrState = 0)
841 # define YYACCEPT return yyaccept
843 # define YYABORT return yyabort
845 # define YYERROR return yyerrok, yyerr
847 # define YYRECOVERING() (yystackp->yyerrState != 0)
849 # define yyclearin (yychar = YYEMPTY)
851 # define YYFILL(N) yyfill (yyvsp, &yylow, N, yynormal)
853 # define YYBACKUP(Token, Value) \
854 return yyerror (]b4_yyerror_args[YY_("syntax error: cannot back up")), \
859 *yyvalp
= yyval_default
;
861 *yyvalp
= yyvsp
[YYFILL (1-yyrhslen
)].yystate
.yysemantics
.yysval
;]b4_locations_if([[
862 YYLLOC_DEFAULT ((*yylocp
), (yyvsp
- yyrhslen
), yyrhslen
);
863 yystackp
->yyerror_range
[1].yystate
.yyloc
= *yylocp
;
882 /*ARGSUSED*/ static void
883 yyuserMerge (int yyn
, YYSTYPE
* yy0
, YYSTYPE
* yy1
)
895 /* Bison grammar-table manipulation. */
897 ]b4_yydestruct_generate([b4_c_ansi_function_def
])[
899 /** Number of symbols composing the right hand side of rule #RULE. */
901 yyrhsLength (yyRuleNum yyrule
)
907 yydestroyGLRState (char const *yymsg
, yyGLRState
*yys
]b4_user_formals
[)
910 yydestruct (yymsg
, yystos
[yys
->yylrState
],
911 &yys
->yysemantics
.yysval
]b4_locuser_args([&yys
->yyloc
])[);
917 if (yys
->yysemantics
.yyfirstVal
)
918 YYFPRINTF (stderr
, "%s unresolved ", yymsg
);
920 YYFPRINTF (stderr
, "%s incomplete ", yymsg
);
921 yy_symbol_print (stderr
, yystos
[yys
->yylrState
],
922 YY_NULL
]b4_locuser_args([&yys
->yyloc
])[);
923 YYFPRINTF (stderr
, "\n");
927 if (yys
->yysemantics
.yyfirstVal
)
929 yySemanticOption
*yyoption
= yys
->yysemantics
.yyfirstVal
;
932 for (yyrh
= yyoption
->yystate
, yyn
= yyrhsLength (yyoption
->yyrule
);
934 yyrh
= yyrh
->yypred
, yyn
-= 1)
935 yydestroyGLRState (yymsg
, yyrh
]b4_user_args
[);
940 /** Left-hand-side symbol for rule #YYRULE. */
941 static inline yySymbol
942 yylhsNonterm (yyRuleNum yyrule
)
947 #define yypact_value_is_default(yystate) \
948 ]b4_table_value_equals([[pact]], [[yystate]], [b4_pact_ninf])[
950 /** True iff LR state YYSTATE has only a default reduction (regardless
953 yyisDefaultedState (yyStateNum yystate
)
955 return yypact_value_is_default (yypact
[yystate
]);
958 /** The default reduction for YYSTATE, assuming it has one. */
959 static inline yyRuleNum
960 yydefaultAction (yyStateNum yystate
)
962 return yydefact
[yystate
];
965 #define yytable_value_is_error(yytable_value) \
966 ]b4_table_value_equals([[table]], [[yytable_value]], [b4_table_ninf])[
968 /** Set *YYACTION to the action to take in YYSTATE on seeing YYTOKEN.
970 * R < 0: Reduce on rule -R.
972 * R > 0: Shift to state R.
973 * Set *YYCONFLICTS to a pointer into yyconfl to a 0-terminated list
974 * of conflicting reductions.
977 yygetLRActions (yyStateNum yystate
, int yytoken
,
978 int* yyaction
, const short int** yyconflicts
)
980 int yyindex
= yypact
[yystate
] + yytoken
;
981 if (yypact_value_is_default (yypact
[yystate
])
982 || yyindex
< 0 || YYLAST
< yyindex
|| yycheck
[yyindex
] != yytoken
)
984 *yyaction
= -yydefact
[yystate
];
985 *yyconflicts
= yyconfl
;
987 else if (! yytable_value_is_error (yytable
[yyindex
]))
989 *yyaction
= yytable
[yyindex
];
990 *yyconflicts
= yyconfl
+ yyconflp
[yyindex
];
995 *yyconflicts
= yyconfl
+ yyconflp
[yyindex
];
999 static inline yyStateNum
1000 yyLRgotoState (yyStateNum yystate
, yySymbol yylhs
)
1002 int yyr
= yypgoto
[yylhs
- YYNTOKENS
] + yystate
;
1003 if (0 <= yyr
&& yyr
<= YYLAST
&& yycheck
[yyr
] == yystate
)
1004 return yytable
[yyr
];
1006 return yydefgoto
[yylhs
- YYNTOKENS
];
1009 static inline yybool
1010 yyisShiftAction (int yyaction
)
1012 return 0 < yyaction
;
1015 static inline yybool
1016 yyisErrorAction (int yyaction
)
1018 return yyaction
== 0;
1023 /** Return a fresh GLRStackItem in YYSTACKP. The item is an LR state
1024 * if YYISSTATE, and otherwise a semantic option. Callers should call
1025 * YY_RESERVE_GLRSTACK afterwards to make sure there is sufficient
1028 static inline yyGLRStackItem
*
1029 yynewGLRStackItem (yyGLRStack
* yystackp
, yybool yyisState
)
1031 yyGLRStackItem
* yynewItem
= yystackp
->yynextFree
;
1032 yystackp
->yyspaceLeft
-= 1;
1033 yystackp
->yynextFree
+= 1;
1034 yynewItem
->yystate
.yyisState
= yyisState
;
1038 /** Add a new semantic action that will execute the action for rule
1039 * YYRULE on the semantic values in YYRHS to the list of
1040 * alternative actions for YYSTATE. Assumes that YYRHS comes from
1041 * stack #YYK of *YYSTACKP. */
1043 yyaddDeferredAction (yyGLRStack
* yystackp
, size_t yyk
, yyGLRState
* yystate
,
1044 yyGLRState
* yyrhs
, yyRuleNum yyrule
)
1046 yySemanticOption
* yynewOption
=
1047 &yynewGLRStackItem (yystackp
, yyfalse
)->yyoption
;
1048 yynewOption
->yystate
= yyrhs
;
1049 yynewOption
->yyrule
= yyrule
;
1050 if (yystackp
->yytops
.yylookaheadNeeds
[yyk
])
1052 yynewOption
->yyrawchar
= yychar
;
1053 yynewOption
->yyval
= yylval
;]b4_locations_if([
1054 yynewOption
->yyloc
= yylloc
;])[
1057 yynewOption
->yyrawchar
= YYEMPTY
;
1058 yynewOption
->yynext
= yystate
->yysemantics
.yyfirstVal
;
1059 yystate
->yysemantics
.yyfirstVal
= yynewOption
;
1061 YY_RESERVE_GLRSTACK (yystackp
);
1066 /** Initialize YYSET to a singleton set containing an empty stack. */
1068 yyinitStateSet (yyGLRStateSet
* yyset
)
1071 yyset
->yycapacity
= 16;
1072 yyset
->yystates
= (yyGLRState
**) YYMALLOC (16 * sizeof yyset
->yystates
[0]);
1073 if (! yyset
->yystates
)
1075 yyset
->yystates
[0] = YY_NULL
;
1076 yyset
->yylookaheadNeeds
=
1077 (yybool
*) YYMALLOC (16 * sizeof yyset
->yylookaheadNeeds
[0]);
1078 if (! yyset
->yylookaheadNeeds
)
1080 YYFREE (yyset
->yystates
);
1086 static void yyfreeStateSet (yyGLRStateSet
* yyset
)
1088 YYFREE (yyset
->yystates
);
1089 YYFREE (yyset
->yylookaheadNeeds
);
1092 /** Initialize *YYSTACKP to a single empty stack, with total maximum
1093 * capacity for all stacks of YYSIZE. */
1095 yyinitGLRStack (yyGLRStack
* yystackp
, size_t yysize
)
1097 yystackp
->yyerrState
= 0;
1099 yystackp
->yyspaceLeft
= yysize
;
1101 (yyGLRStackItem
*) YYMALLOC (yysize
* sizeof yystackp
->yynextFree
[0]);
1102 if (!yystackp
->yyitems
)
1104 yystackp
->yynextFree
= yystackp
->yyitems
;
1105 yystackp
->yysplitPoint
= YY_NULL
;
1106 yystackp
->yylastDeleted
= YY_NULL
;
1107 return yyinitStateSet (&yystackp
->yytops
);
1111 #if YYSTACKEXPANDABLE
1112 # define YYRELOC(YYFROMITEMS,YYTOITEMS,YYX,YYTYPE) \
1113 &((YYTOITEMS) - ((YYFROMITEMS) - (yyGLRStackItem*) (YYX)))->YYTYPE
1115 /** If *YYSTACKP is expandable, extend it. WARNING: Pointers into the
1116 stack from outside should be considered invalid after this call.
1117 We always expand when there are 1 or fewer items left AFTER an
1118 allocation, so that we can avoid having external pointers exist
1119 across an allocation. */
1121 yyexpandGLRStack (yyGLRStack
* yystackp
)
1123 yyGLRStackItem
* yynewItems
;
1124 yyGLRStackItem
* yyp0
, *yyp1
;
1127 size_t yysize
= yystackp
->yynextFree
- yystackp
->yyitems
;
1128 if (YYMAXDEPTH
- YYHEADROOM
< yysize
)
1129 yyMemoryExhausted (yystackp
);
1130 yynewSize
= 2*yysize
;
1131 if (YYMAXDEPTH
< yynewSize
)
1132 yynewSize
= YYMAXDEPTH
;
1133 yynewItems
= (yyGLRStackItem
*) YYMALLOC (yynewSize
* sizeof yynewItems
[0]);
1135 yyMemoryExhausted (yystackp
);
1136 for (yyp0
= yystackp
->yyitems
, yyp1
= yynewItems
, yyn
= yysize
;
1138 yyn
-= 1, yyp0
+= 1, yyp1
+= 1)
1141 if (*(yybool
*) yyp0
)
1143 yyGLRState
* yys0
= &yyp0
->yystate
;
1144 yyGLRState
* yys1
= &yyp1
->yystate
;
1145 if (yys0
->yypred
!= YY_NULL
)
1147 YYRELOC (yyp0
, yyp1
, yys0
->yypred
, yystate
);
1148 if (! yys0
->yyresolved
&& yys0
->yysemantics
.yyfirstVal
!= YY_NULL
)
1149 yys1
->yysemantics
.yyfirstVal
=
1150 YYRELOC (yyp0
, yyp1
, yys0
->yysemantics
.yyfirstVal
, yyoption
);
1154 yySemanticOption
* yyv0
= &yyp0
->yyoption
;
1155 yySemanticOption
* yyv1
= &yyp1
->yyoption
;
1156 if (yyv0
->yystate
!= YY_NULL
)
1157 yyv1
->yystate
= YYRELOC (yyp0
, yyp1
, yyv0
->yystate
, yystate
);
1158 if (yyv0
->yynext
!= YY_NULL
)
1159 yyv1
->yynext
= YYRELOC (yyp0
, yyp1
, yyv0
->yynext
, yyoption
);
1162 if (yystackp
->yysplitPoint
!= YY_NULL
)
1163 yystackp
->yysplitPoint
= YYRELOC (yystackp
->yyitems
, yynewItems
,
1164 yystackp
->yysplitPoint
, yystate
);
1166 for (yyn
= 0; yyn
< yystackp
->yytops
.yysize
; yyn
+= 1)
1167 if (yystackp
->yytops
.yystates
[yyn
] != YY_NULL
)
1168 yystackp
->yytops
.yystates
[yyn
] =
1169 YYRELOC (yystackp
->yyitems
, yynewItems
,
1170 yystackp
->yytops
.yystates
[yyn
], yystate
);
1171 YYFREE (yystackp
->yyitems
);
1172 yystackp
->yyitems
= yynewItems
;
1173 yystackp
->yynextFree
= yynewItems
+ yysize
;
1174 yystackp
->yyspaceLeft
= yynewSize
- yysize
;
1179 yyfreeGLRStack (yyGLRStack
* yystackp
)
1181 YYFREE (yystackp
->yyitems
);
1182 yyfreeStateSet (&yystackp
->yytops
);
1185 /** Assuming that YYS is a GLRState somewhere on *YYSTACKP, update the
1186 * splitpoint of *YYSTACKP, if needed, so that it is at least as deep as
1189 yyupdateSplit (yyGLRStack
* yystackp
, yyGLRState
* yys
)
1191 if (yystackp
->yysplitPoint
!= YY_NULL
&& yystackp
->yysplitPoint
> yys
)
1192 yystackp
->yysplitPoint
= yys
;
1195 /** Invalidate stack #YYK in *YYSTACKP. */
1197 yymarkStackDeleted (yyGLRStack
* yystackp
, size_t yyk
)
1199 if (yystackp
->yytops
.yystates
[yyk
] != YY_NULL
)
1200 yystackp
->yylastDeleted
= yystackp
->yytops
.yystates
[yyk
];
1201 yystackp
->yytops
.yystates
[yyk
] = YY_NULL
;
1204 /** Undelete the last stack in *YYSTACKP that was marked as deleted. Can
1205 only be done once after a deletion, and only when all other stacks have
1208 yyundeleteLastStack (yyGLRStack
* yystackp
)
1210 if (yystackp
->yylastDeleted
== YY_NULL
|| yystackp
->yytops
.yysize
!= 0)
1212 yystackp
->yytops
.yystates
[0] = yystackp
->yylastDeleted
;
1213 yystackp
->yytops
.yysize
= 1;
1214 YYDPRINTF ((stderr
, "Restoring last deleted stack as stack #0.\n"));
1215 yystackp
->yylastDeleted
= YY_NULL
;
1219 yyremoveDeletes (yyGLRStack
* yystackp
)
1223 while (yyj
< yystackp
->yytops
.yysize
)
1225 if (yystackp
->yytops
.yystates
[yyi
] == YY_NULL
)
1229 YYDPRINTF ((stderr
, "Removing dead stacks.\n"));
1231 yystackp
->yytops
.yysize
-= 1;
1235 yystackp
->yytops
.yystates
[yyj
] = yystackp
->yytops
.yystates
[yyi
];
1236 /* In the current implementation, it's unnecessary to copy
1237 yystackp->yytops.yylookaheadNeeds[yyi] since, after
1238 yyremoveDeletes returns, the parser immediately either enters
1239 deterministic operation or shifts a token. However, it doesn't
1240 hurt, and the code might evolve to need it. */
1241 yystackp
->yytops
.yylookaheadNeeds
[yyj
] =
1242 yystackp
->yytops
.yylookaheadNeeds
[yyi
];
1245 YYDPRINTF ((stderr
, "Rename stack %lu -> %lu.\n",
1246 (unsigned long int) yyi
, (unsigned long int) yyj
));
1254 /** Shift to a new state on stack #YYK of *YYSTACKP, corresponding to LR
1255 * state YYLRSTATE, at input position YYPOSN, with (resolved) semantic
1256 * value *YYVALP and source location *YYLOCP. */
1258 yyglrShift (yyGLRStack
* yystackp
, size_t yyk
, yyStateNum yylrState
,
1260 YYSTYPE
* yyvalp
]b4_locations_if([, YYLTYPE
* yylocp
])[)
1262 yyGLRState
* yynewState
= &yynewGLRStackItem (yystackp
, yytrue
)->yystate
;
1264 yynewState
->yylrState
= yylrState
;
1265 yynewState
->yyposn
= yyposn
;
1266 yynewState
->yyresolved
= yytrue
;
1267 yynewState
->yypred
= yystackp
->yytops
.yystates
[yyk
];
1268 yynewState
->yysemantics
.yysval
= *yyvalp
;]b4_locations_if([
1269 yynewState
->yyloc
= *yylocp
;])[
1270 yystackp
->yytops
.yystates
[yyk
] = yynewState
;
1272 YY_RESERVE_GLRSTACK (yystackp
);
1275 /** Shift stack #YYK of *YYSTACKP, to a new state corresponding to LR
1276 * state YYLRSTATE, at input position YYPOSN, with the (unresolved)
1277 * semantic value of YYRHS under the action for YYRULE. */
1279 yyglrShiftDefer (yyGLRStack
* yystackp
, size_t yyk
, yyStateNum yylrState
,
1280 size_t yyposn
, yyGLRState
* yyrhs
, yyRuleNum yyrule
)
1282 yyGLRState
* yynewState
= &yynewGLRStackItem (yystackp
, yytrue
)->yystate
;
1284 yynewState
->yylrState
= yylrState
;
1285 yynewState
->yyposn
= yyposn
;
1286 yynewState
->yyresolved
= yyfalse
;
1287 yynewState
->yypred
= yystackp
->yytops
.yystates
[yyk
];
1288 yynewState
->yysemantics
.yyfirstVal
= YY_NULL
;
1289 yystackp
->yytops
.yystates
[yyk
] = yynewState
;
1291 /* Invokes YY_RESERVE_GLRSTACK. */
1292 yyaddDeferredAction (yystackp
, yyk
, yynewState
, yyrhs
, yyrule
);
1296 # define YY_REDUCE_PRINT(Args)
1298 # define YY_REDUCE_PRINT(Args) \
1301 yy_reduce_print Args; \
1304 /*----------------------------------------------------------------------.
1305 | Report that stack #YYK of *YYSTACKP is going to be reduced by YYRULE. |
1306 `----------------------------------------------------------------------*/
1308 /*ARGSUSED*/ static inline void
1309 yy_reduce_print (int yynormal
, yyGLRStackItem
* yyvsp
, size_t yyk
,
1310 yyRuleNum yyrule
]b4_user_formals
[)
1312 int yynrhs
= yyrhsLength (yyrule
);]b4_locations_if([
1315 YYFPRINTF (stderr
, "Reducing stack %lu by rule %d (line %lu):\n",
1316 (unsigned long int) yyk
, yyrule
- 1,
1317 (unsigned long int) yyrline
[yyrule
]);
1319 yyfillin (yyvsp
, 1, -yynrhs
);
1320 /* The symbols being reduced. */
1321 for (yyi
= 0; yyi
< yynrhs
; yyi
++)
1323 YYFPRINTF (stderr
, " $%d = ", yyi
+ 1);
1324 yy_symbol_print (stderr
,
1325 yystos
[yyvsp
[yyi
- yynrhs
+ 1].yystate
.yylrState
],
1326 &yyvsp
[yyi
- yynrhs
+ 1].yystate
.yysemantics
.yysval
1327 ]b4_locations_if([, &]b4_rhs_location(yynrhs
, yyi
+ 1))[]dnl
1329 if (!yyvsp
[yyi
- yynrhs
+ 1].yystate
.yyresolved
)
1330 YYFPRINTF (stderr
, " (unresolved)");
1331 YYFPRINTF (stderr
, "\n");
1336 /** Pop the symbols consumed by reduction #YYRULE from the top of stack
1337 * #YYK of *YYSTACKP, and perform the appropriate semantic action on their
1338 * semantic values. Assumes that all ambiguities in semantic values
1339 * have been previously resolved. Set *YYVALP to the resulting value,
1340 * and *YYLOCP to the computed location (if any). Return value is as
1341 * for userAction. */
1342 static inline YYRESULTTAG
1343 yydoAction (yyGLRStack
* yystackp
, size_t yyk
, yyRuleNum yyrule
,
1344 YYSTYPE
* yyvalp
]b4_locuser_formals
[)
1346 int yynrhs
= yyrhsLength (yyrule
);
1348 if (yystackp
->yysplitPoint
== YY_NULL
)
1350 /* Standard special case: single stack. */
1351 yyGLRStackItem
* yyrhs
= (yyGLRStackItem
*) yystackp
->yytops
.yystates
[yyk
];
1352 YYASSERT (yyk
== 0);
1353 yystackp
->yynextFree
-= yynrhs
;
1354 yystackp
->yyspaceLeft
+= yynrhs
;
1355 yystackp
->yytops
.yystates
[0] = & yystackp
->yynextFree
[-1].yystate
;
1356 YY_REDUCE_PRINT ((1, yyrhs
, yyk
, yyrule
]b4_user_args
[));
1357 return yyuserAction (yyrule
, yynrhs
, yyrhs
, yystackp
,
1358 yyvalp
]b4_locuser_args
[);
1364 yyGLRStackItem yyrhsVals
[YYMAXRHS
+ YYMAXLEFT
+ 1];
1365 yys
= yyrhsVals
[YYMAXRHS
+ YYMAXLEFT
].yystate
.yypred
1366 = yystackp
->yytops
.yystates
[yyk
];]b4_locations_if([[
1368 /* Set default location. */
1369 yyrhsVals
[YYMAXRHS
+ YYMAXLEFT
- 1].yystate
.yyloc
= yys
->yyloc
;]])[
1370 for (yyi
= 0; yyi
< yynrhs
; yyi
+= 1)
1375 yyupdateSplit (yystackp
, yys
);
1376 yystackp
->yytops
.yystates
[yyk
] = yys
;
1377 YY_REDUCE_PRINT ((0, yyrhsVals
+ YYMAXRHS
+ YYMAXLEFT
- 1, yyk
, yyrule
]b4_user_args
[));
1378 return yyuserAction (yyrule
, yynrhs
, yyrhsVals
+ YYMAXRHS
+ YYMAXLEFT
- 1,
1379 yystackp
, yyvalp
]b4_locuser_args
[);
1383 /** Pop items off stack #YYK of *YYSTACKP according to grammar rule YYRULE,
1384 * and push back on the resulting nonterminal symbol. Perform the
1385 * semantic action associated with YYRULE and store its value with the
1386 * newly pushed state, if YYFORCEEVAL or if *YYSTACKP is currently
1387 * unambiguous. Otherwise, store the deferred semantic action with
1388 * the new state. If the new state would have an identical input
1389 * position, LR state, and predecessor to an existing state on the stack,
1390 * it is identified with that existing state, eliminating stack #YYK from
1391 * *YYSTACKP. In this case, the semantic value is
1392 * added to the options for the existing state's semantic value.
1394 static inline YYRESULTTAG
1395 yyglrReduce (yyGLRStack
* yystackp
, size_t yyk
, yyRuleNum yyrule
,
1396 yybool yyforceEval
]b4_user_formals
[)
1398 size_t yyposn
= yystackp
->yytops
.yystates
[yyk
]->yyposn
;
1400 if (yyforceEval
|| yystackp
->yysplitPoint
== YY_NULL
)
1403 YYSTYPE yysval
;]b4_locations_if([
1406 yyflag
= yydoAction (yystackp
, yyk
, yyrule
, &yysval
]b4_locuser_args([&yyloc
])[);
1407 if (yyflag
== yyerr
&& yystackp
->yysplitPoint
!= YY_NULL
)
1409 YYDPRINTF ((stderr
, "Parse on stack %lu rejected by rule #%d.\n",
1410 (unsigned long int) yyk
, yyrule
- 1));
1414 YY_SYMBOL_PRINT ("-> $$ =", yyr1
[yyrule
], &yysval
, &yyloc
);
1415 yyglrShift (yystackp
, yyk
,
1416 yyLRgotoState (yystackp
->yytops
.yystates
[yyk
]->yylrState
,
1417 yylhsNonterm (yyrule
)),
1418 yyposn
, &yysval
]b4_locations_if([, &yyloc
])[);
1424 yyGLRState
* yys
, *yys0
= yystackp
->yytops
.yystates
[yyk
];
1425 yyStateNum yynewLRState
;
1427 for (yys
= yystackp
->yytops
.yystates
[yyk
], yyn
= yyrhsLength (yyrule
);
1433 yyupdateSplit (yystackp
, yys
);
1434 yynewLRState
= yyLRgotoState (yys
->yylrState
, yylhsNonterm (yyrule
));
1436 "Reduced stack %lu by rule #%d; action deferred. "
1437 "Now in state %d.\n",
1438 (unsigned long int) yyk
, yyrule
- 1, yynewLRState
));
1439 for (yyi
= 0; yyi
< yystackp
->yytops
.yysize
; yyi
+= 1)
1440 if (yyi
!= yyk
&& yystackp
->yytops
.yystates
[yyi
] != YY_NULL
)
1442 yyGLRState
*yysplit
= yystackp
->yysplitPoint
;
1443 yyGLRState
*yyp
= yystackp
->yytops
.yystates
[yyi
];
1444 while (yyp
!= yys
&& yyp
!= yysplit
&& yyp
->yyposn
>= yyposn
)
1446 if (yyp
->yylrState
== yynewLRState
&& yyp
->yypred
== yys
)
1448 yyaddDeferredAction (yystackp
, yyk
, yyp
, yys0
, yyrule
);
1449 yymarkStackDeleted (yystackp
, yyk
);
1450 YYDPRINTF ((stderr
, "Merging stack %lu into stack %lu.\n",
1451 (unsigned long int) yyk
,
1452 (unsigned long int) yyi
));
1458 yystackp
->yytops
.yystates
[yyk
] = yys
;
1459 yyglrShiftDefer (yystackp
, yyk
, yynewLRState
, yyposn
, yys0
, yyrule
);
1465 yysplitStack (yyGLRStack
* yystackp
, size_t yyk
)
1467 if (yystackp
->yysplitPoint
== YY_NULL
)
1469 YYASSERT (yyk
== 0);
1470 yystackp
->yysplitPoint
= yystackp
->yytops
.yystates
[yyk
];
1472 if (yystackp
->yytops
.yysize
>= yystackp
->yytops
.yycapacity
)
1474 yyGLRState
** yynewStates
;
1475 yybool
* yynewLookaheadNeeds
;
1477 yynewStates
= YY_NULL
;
1479 if (yystackp
->yytops
.yycapacity
1480 > (YYSIZEMAX
/ (2 * sizeof yynewStates
[0])))
1481 yyMemoryExhausted (yystackp
);
1482 yystackp
->yytops
.yycapacity
*= 2;
1485 (yyGLRState
**) YYREALLOC (yystackp
->yytops
.yystates
,
1486 (yystackp
->yytops
.yycapacity
1487 * sizeof yynewStates
[0]));
1488 if (yynewStates
== YY_NULL
)
1489 yyMemoryExhausted (yystackp
);
1490 yystackp
->yytops
.yystates
= yynewStates
;
1492 yynewLookaheadNeeds
=
1493 (yybool
*) YYREALLOC (yystackp
->yytops
.yylookaheadNeeds
,
1494 (yystackp
->yytops
.yycapacity
1495 * sizeof yynewLookaheadNeeds
[0]));
1496 if (yynewLookaheadNeeds
== YY_NULL
)
1497 yyMemoryExhausted (yystackp
);
1498 yystackp
->yytops
.yylookaheadNeeds
= yynewLookaheadNeeds
;
1500 yystackp
->yytops
.yystates
[yystackp
->yytops
.yysize
]
1501 = yystackp
->yytops
.yystates
[yyk
];
1502 yystackp
->yytops
.yylookaheadNeeds
[yystackp
->yytops
.yysize
]
1503 = yystackp
->yytops
.yylookaheadNeeds
[yyk
];
1504 yystackp
->yytops
.yysize
+= 1;
1505 return yystackp
->yytops
.yysize
-1;
1508 /** True iff YYY0 and YYY1 represent identical options at the top level.
1509 * That is, they represent the same rule applied to RHS symbols
1510 * that produce the same terminal symbols. */
1512 yyidenticalOptions (yySemanticOption
* yyy0
, yySemanticOption
* yyy1
)
1514 if (yyy0
->yyrule
== yyy1
->yyrule
)
1516 yyGLRState
*yys0
, *yys1
;
1518 for (yys0
= yyy0
->yystate
, yys1
= yyy1
->yystate
,
1519 yyn
= yyrhsLength (yyy0
->yyrule
);
1521 yys0
= yys0
->yypred
, yys1
= yys1
->yypred
, yyn
-= 1)
1522 if (yys0
->yyposn
!= yys1
->yyposn
)
1530 /** Assuming identicalOptions (YYY0,YYY1), destructively merge the
1531 * alternative semantic values for the RHS-symbols of YYY1 and YYY0. */
1533 yymergeOptionSets (yySemanticOption
* yyy0
, yySemanticOption
* yyy1
)
1535 yyGLRState
*yys0
, *yys1
;
1537 for (yys0
= yyy0
->yystate
, yys1
= yyy1
->yystate
,
1538 yyn
= yyrhsLength (yyy0
->yyrule
);
1540 yys0
= yys0
->yypred
, yys1
= yys1
->yypred
, yyn
-= 1)
1544 else if (yys0
->yyresolved
)
1546 yys1
->yyresolved
= yytrue
;
1547 yys1
->yysemantics
.yysval
= yys0
->yysemantics
.yysval
;
1549 else if (yys1
->yyresolved
)
1551 yys0
->yyresolved
= yytrue
;
1552 yys0
->yysemantics
.yysval
= yys1
->yysemantics
.yysval
;
1556 yySemanticOption
** yyz0p
= &yys0
->yysemantics
.yyfirstVal
;
1557 yySemanticOption
* yyz1
= yys1
->yysemantics
.yyfirstVal
;
1558 while (YYID (yytrue
))
1560 if (yyz1
== *yyz0p
|| yyz1
== YY_NULL
)
1562 else if (*yyz0p
== YY_NULL
)
1567 else if (*yyz0p
< yyz1
)
1569 yySemanticOption
* yyz
= *yyz0p
;
1571 yyz1
= yyz1
->yynext
;
1572 (*yyz0p
)->yynext
= yyz
;
1574 yyz0p
= &(*yyz0p
)->yynext
;
1576 yys1
->yysemantics
.yyfirstVal
= yys0
->yysemantics
.yyfirstVal
;
1581 /** Y0 and Y1 represent two possible actions to take in a given
1582 * parsing state; return 0 if no combination is possible,
1583 * 1 if user-mergeable, 2 if Y0 is preferred, 3 if Y1 is preferred. */
1585 yypreference (yySemanticOption
* y0
, yySemanticOption
* y1
)
1587 yyRuleNum r0
= y0
->yyrule
, r1
= y1
->yyrule
;
1588 int p0
= yydprec
[r0
], p1
= yydprec
[r1
];
1592 if (yymerger
[r0
] == 0 || yymerger
[r0
] != yymerger
[r1
])
1597 if (p0
== 0 || p1
== 0)
1606 static YYRESULTTAG
yyresolveValue (yyGLRState
* yys
,
1607 yyGLRStack
* yystackp
]b4_user_formals
[);
1610 /** Resolve the previous YYN states starting at and including state YYS
1611 * on *YYSTACKP. If result != yyok, some states may have been left
1612 * unresolved possibly with empty semantic option chains. Regardless
1613 * of whether result = yyok, each state has been left with consistent
1614 * data so that yydestroyGLRState can be invoked if necessary. */
1616 yyresolveStates (yyGLRState
* yys
, int yyn
,
1617 yyGLRStack
* yystackp
]b4_user_formals
[)
1621 YYASSERT (yys
->yypred
);
1622 YYCHK (yyresolveStates (yys
->yypred
, yyn
-1, yystackp
]b4_user_args
[));
1623 if (! yys
->yyresolved
)
1624 YYCHK (yyresolveValue (yys
, yystackp
]b4_user_args
[));
1629 /** Resolve the states for the RHS of YYOPT on *YYSTACKP, perform its
1630 * user action, and return the semantic value and location in *YYVALP
1631 * and *YYLOCP. Regardless of whether result = yyok, all RHS states
1632 * have been destroyed (assuming the user action destroys all RHS
1633 * semantic values if invoked). */
1635 yyresolveAction (yySemanticOption
* yyopt
, yyGLRStack
* yystackp
,
1636 YYSTYPE
* yyvalp
]b4_locuser_formals
[)
1638 yyGLRStackItem yyrhsVals
[YYMAXRHS
+ YYMAXLEFT
+ 1];
1639 int yynrhs
= yyrhsLength (yyopt
->yyrule
);
1640 YYRESULTTAG yyflag
=
1641 yyresolveStates (yyopt
->yystate
, yynrhs
, yystackp
]b4_user_args
[);
1645 for (yys
= yyopt
->yystate
; yynrhs
> 0; yys
= yys
->yypred
, yynrhs
-= 1)
1646 yydestroyGLRState ("Cleanup: popping", yys
]b4_user_args
[);
1650 yyrhsVals
[YYMAXRHS
+ YYMAXLEFT
].yystate
.yypred
= yyopt
->yystate
;]b4_locations_if([[
1652 /* Set default location. */
1653 yyrhsVals
[YYMAXRHS
+ YYMAXLEFT
- 1].yystate
.yyloc
= yyopt
->yystate
->yyloc
;]])[
1655 int yychar_current
= yychar
;
1656 YYSTYPE yylval_current
= yylval
;]b4_locations_if([
1657 YYLTYPE yylloc_current
= yylloc
;])[
1658 yychar
= yyopt
->yyrawchar
;
1659 yylval
= yyopt
->yyval
;]b4_locations_if([
1660 yylloc
= yyopt
->yyloc
;])[
1661 yyflag
= yyuserAction (yyopt
->yyrule
, yynrhs
,
1662 yyrhsVals
+ YYMAXRHS
+ YYMAXLEFT
- 1,
1663 yystackp
, yyvalp
]b4_locuser_args
[);
1664 yychar
= yychar_current
;
1665 yylval
= yylval_current
;]b4_locations_if([
1666 yylloc
= yylloc_current
;])[
1673 yyreportTree (yySemanticOption
* yyx
, int yyindent
)
1675 int yynrhs
= yyrhsLength (yyx
->yyrule
);
1678 yyGLRState
* yystates
[1 + YYMAXRHS
];
1679 yyGLRState yyleftmost_state
;
1681 for (yyi
= yynrhs
, yys
= yyx
->yystate
; 0 < yyi
; yyi
-= 1, yys
= yys
->yypred
)
1682 yystates
[yyi
] = yys
;
1685 yyleftmost_state
.yyposn
= 0;
1686 yystates
[0] = &yyleftmost_state
;
1691 if (yyx
->yystate
->yyposn
< yys
->yyposn
+ 1)
1692 YYFPRINTF (stderr
, "%*s%s -> <Rule %d, empty>\n",
1693 yyindent
, "", yytokenName (yylhsNonterm (yyx
->yyrule
)),
1696 YYFPRINTF (stderr
, "%*s%s -> <Rule %d, tokens %lu .. %lu>\n",
1697 yyindent
, "", yytokenName (yylhsNonterm (yyx
->yyrule
)),
1698 yyx
->yyrule
- 1, (unsigned long int) (yys
->yyposn
+ 1),
1699 (unsigned long int) yyx
->yystate
->yyposn
);
1700 for (yyi
= 1; yyi
<= yynrhs
; yyi
+= 1)
1702 if (yystates
[yyi
]->yyresolved
)
1704 if (yystates
[yyi
-1]->yyposn
+1 > yystates
[yyi
]->yyposn
)
1705 YYFPRINTF (stderr
, "%*s%s <empty>\n", yyindent
+2, "",
1706 yytokenName (yystos
[yystates
[yyi
]->yylrState
]));
1708 YYFPRINTF (stderr
, "%*s%s <tokens %lu .. %lu>\n", yyindent
+2, "",
1709 yytokenName (yystos
[yystates
[yyi
]->yylrState
]),
1710 (unsigned long int) (yystates
[yyi
-1]->yyposn
+ 1),
1711 (unsigned long int) yystates
[yyi
]->yyposn
);
1714 yyreportTree (yystates
[yyi
]->yysemantics
.yyfirstVal
, yyindent
+2);
1719 /*ARGSUSED*/ static YYRESULTTAG
1720 yyreportAmbiguity (yySemanticOption
* yyx0
,
1721 yySemanticOption
* yyx1
]b4_pure_formals
[)
1727 YYFPRINTF (stderr
, "Ambiguity detected.\n");
1728 YYFPRINTF (stderr
, "Option 1,\n");
1729 yyreportTree (yyx0
, 2);
1730 YYFPRINTF (stderr
, "\nOption 2,\n");
1731 yyreportTree (yyx1
, 2);
1732 YYFPRINTF (stderr
, "\n");
1735 yyerror (]b4_yyerror_args
[YY_("syntax is ambiguous"));
1737 }]b4_locations_if([[
1739 /** Resolve the locations for each of the YYN1 states in *YYSTACKP,
1740 * ending at YYS1. Has no effect on previously resolved states.
1741 * The first semantic option of a state is always chosen. */
1743 yyresolveLocations (yyGLRState
* yys1
, int yyn1
,
1744 yyGLRStack
*yystackp
]b4_user_formals
[)
1748 yyresolveLocations (yys1
->yypred
, yyn1
- 1, yystackp
]b4_user_args
[);
1749 if (!yys1
->yyresolved
)
1751 yyGLRStackItem yyrhsloc
[1 + YYMAXRHS
];
1753 yySemanticOption
*yyoption
= yys1
->yysemantics
.yyfirstVal
;
1754 YYASSERT (yyoption
!= YY_NULL
);
1755 yynrhs
= yyrhsLength (yyoption
->yyrule
);
1760 yyresolveLocations (yyoption
->yystate
, yynrhs
,
1761 yystackp
]b4_user_args
[);
1762 for (yys
= yyoption
->yystate
, yyn
= yynrhs
;
1764 yys
= yys
->yypred
, yyn
-= 1)
1765 yyrhsloc
[yyn
].yystate
.yyloc
= yys
->yyloc
;
1769 /* Both yyresolveAction and yyresolveLocations traverse the GSS
1770 in reverse rightmost order. It is only necessary to invoke
1771 yyresolveLocations on a subforest for which yyresolveAction
1772 would have been invoked next had an ambiguity not been
1773 detected. Thus the location of the previous state (but not
1774 necessarily the previous state itself) is guaranteed to be
1775 resolved already. */
1776 yyGLRState
*yyprevious
= yyoption
->yystate
;
1777 yyrhsloc
[0].yystate
.yyloc
= yyprevious
->yyloc
;
1780 int yychar_current
= yychar
;
1781 YYSTYPE yylval_current
= yylval
;
1782 YYLTYPE yylloc_current
= yylloc
;
1783 yychar
= yyoption
->yyrawchar
;
1784 yylval
= yyoption
->yyval
;
1785 yylloc
= yyoption
->yyloc
;
1786 YYLLOC_DEFAULT ((yys1
->yyloc
), yyrhsloc
, yynrhs
);
1787 yychar
= yychar_current
;
1788 yylval
= yylval_current
;
1789 yylloc
= yylloc_current
;
1795 /** Resolve the ambiguity represented in state YYS in *YYSTACKP,
1796 * perform the indicated actions, and set the semantic value of YYS.
1797 * If result != yyok, the chain of semantic options in YYS has been
1798 * cleared instead or it has been left unmodified except that
1799 * redundant options may have been removed. Regardless of whether
1800 * result = yyok, YYS has been left with consistent data so that
1801 * yydestroyGLRState can be invoked if necessary. */
1803 yyresolveValue (yyGLRState
* yys
, yyGLRStack
* yystackp
]b4_user_formals
[)
1805 yySemanticOption
* yyoptionList
= yys
->yysemantics
.yyfirstVal
;
1806 yySemanticOption
* yybest
= yyoptionList
;
1807 yySemanticOption
** yypp
;
1808 yybool yymerge
= yyfalse
;
1810 YYRESULTTAG yyflag
;]b4_locations_if([
1811 YYLTYPE
*yylocp
= &yys
->yyloc
;])[
1813 for (yypp
= &yyoptionList
->yynext
; *yypp
!= YY_NULL
; )
1815 yySemanticOption
* yyp
= *yypp
;
1817 if (yyidenticalOptions (yybest
, yyp
))
1819 yymergeOptionSets (yybest
, yyp
);
1820 *yypp
= yyp
->yynext
;
1824 switch (yypreference (yybest
, yyp
))
1826 case 0:]b4_locations_if([[
1827 yyresolveLocations (yys
, 1, yystackp
]b4_user_args
[);]])[
1828 return yyreportAmbiguity (yybest
, yyp
]b4_pure_args
[);
1840 /* This cannot happen so it is not worth a YYASSERT (yyfalse),
1841 but some compilers complain if the default case is
1845 yypp
= &yyp
->yynext
;
1851 yySemanticOption
* yyp
;
1852 int yyprec
= yydprec
[yybest
->yyrule
];
1853 yyflag
= yyresolveAction (yybest
, yystackp
, &yysval
]b4_locuser_args
[);
1855 for (yyp
= yybest
->yynext
; yyp
!= YY_NULL
; yyp
= yyp
->yynext
)
1857 if (yyprec
== yydprec
[yyp
->yyrule
])
1859 YYSTYPE yysval_other
;]b4_locations_if([
1861 yyflag
= yyresolveAction (yyp
, yystackp
, &yysval_other
]b4_locuser_args([&yydummy
])[);
1864 yydestruct ("Cleanup: discarding incompletely merged value for",
1865 yystos
[yys
->yylrState
],
1866 &yysval
]b4_locuser_args
[);
1869 yyuserMerge (yymerger
[yyp
->yyrule
], &yysval
, &yysval_other
);
1874 yyflag
= yyresolveAction (yybest
, yystackp
, &yysval
]b4_locuser_args([yylocp
])[);
1878 yys
->yyresolved
= yytrue
;
1879 yys
->yysemantics
.yysval
= yysval
;
1882 yys
->yysemantics
.yyfirstVal
= YY_NULL
;
1887 yyresolveStack (yyGLRStack
* yystackp
]b4_user_formals
[)
1889 if (yystackp
->yysplitPoint
!= YY_NULL
)
1894 for (yyn
= 0, yys
= yystackp
->yytops
.yystates
[0];
1895 yys
!= yystackp
->yysplitPoint
;
1896 yys
= yys
->yypred
, yyn
+= 1)
1898 YYCHK (yyresolveStates (yystackp
->yytops
.yystates
[0], yyn
, yystackp
1905 yycompressStack (yyGLRStack
* yystackp
)
1907 yyGLRState
* yyp
, *yyq
, *yyr
;
1909 if (yystackp
->yytops
.yysize
!= 1 || yystackp
->yysplitPoint
== YY_NULL
)
1912 for (yyp
= yystackp
->yytops
.yystates
[0], yyq
= yyp
->yypred
, yyr
= YY_NULL
;
1913 yyp
!= yystackp
->yysplitPoint
;
1914 yyr
= yyp
, yyp
= yyq
, yyq
= yyp
->yypred
)
1917 yystackp
->yyspaceLeft
+= yystackp
->yynextFree
- yystackp
->yyitems
;
1918 yystackp
->yynextFree
= ((yyGLRStackItem
*) yystackp
->yysplitPoint
) + 1;
1919 yystackp
->yyspaceLeft
-= yystackp
->yynextFree
- yystackp
->yyitems
;
1920 yystackp
->yysplitPoint
= YY_NULL
;
1921 yystackp
->yylastDeleted
= YY_NULL
;
1923 while (yyr
!= YY_NULL
)
1925 yystackp
->yynextFree
->yystate
= *yyr
;
1927 yystackp
->yynextFree
->yystate
.yypred
= &yystackp
->yynextFree
[-1].yystate
;
1928 yystackp
->yytops
.yystates
[0] = &yystackp
->yynextFree
->yystate
;
1929 yystackp
->yynextFree
+= 1;
1930 yystackp
->yyspaceLeft
-= 1;
1935 yyprocessOneStack (yyGLRStack
* yystackp
, size_t yyk
,
1936 size_t yyposn
]b4_pure_formals
[)
1938 while (yystackp
->yytops
.yystates
[yyk
] != YY_NULL
)
1940 yyStateNum yystate
= yystackp
->yytops
.yystates
[yyk
]->yylrState
;
1941 YYDPRINTF ((stderr
, "Stack %lu Entering state %d\n",
1942 (unsigned long int) yyk
, yystate
));
1944 YYASSERT (yystate
!= YYFINAL
);
1946 if (yyisDefaultedState (yystate
))
1949 yyRuleNum yyrule
= yydefaultAction (yystate
);
1952 YYDPRINTF ((stderr
, "Stack %lu dies.\n",
1953 (unsigned long int) yyk
));
1954 yymarkStackDeleted (yystackp
, yyk
);
1957 yyflag
= yyglrReduce (yystackp
, yyk
, yyrule
, yyimmediate
[yyrule
]]b4_user_args
[);
1958 if (yyflag
== yyerr
)
1962 "(predicate failure or explicit user error).\n",
1963 (unsigned long int) yyk
));
1964 yymarkStackDeleted (yystackp
, yyk
);
1974 const short int* yyconflicts
;
1976 yystackp
->yytops
.yylookaheadNeeds
[yyk
] = yytrue
;
1977 if (yychar
== YYEMPTY
)
1979 YYDPRINTF ((stderr
, "Reading a token: "));
1983 if (yychar
<= YYEOF
)
1985 yychar
= yytoken
= YYEOF
;
1986 YYDPRINTF ((stderr
, "Now at end of input.\n"));
1990 yytoken
= YYTRANSLATE (yychar
);
1991 YY_SYMBOL_PRINT ("Next token is", yytoken
, &yylval
, &yylloc
);
1994 yygetLRActions (yystate
, yytoken
, &yyaction
, &yyconflicts
);
1996 while (*yyconflicts
!= 0)
1999 size_t yynewStack
= yysplitStack (yystackp
, yyk
);
2000 YYDPRINTF ((stderr
, "Splitting off stack %lu from %lu.\n",
2001 (unsigned long int) yynewStack
,
2002 (unsigned long int) yyk
));
2003 yyflag
= yyglrReduce (yystackp
, yynewStack
,
2005 yyimmediate
[*yyconflicts
]]b4_user_args
[);
2007 YYCHK (yyprocessOneStack (yystackp
, yynewStack
,
2008 yyposn
]b4_pure_args
[));
2009 else if (yyflag
== yyerr
)
2011 YYDPRINTF ((stderr
, "Stack %lu dies.\n",
2012 (unsigned long int) yynewStack
));
2013 yymarkStackDeleted (yystackp
, yynewStack
);
2020 if (yyisShiftAction (yyaction
))
2022 else if (yyisErrorAction (yyaction
))
2024 YYDPRINTF ((stderr
, "Stack %lu dies.\n",
2025 (unsigned long int) yyk
));
2026 yymarkStackDeleted (yystackp
, yyk
);
2031 YYRESULTTAG yyflag
= yyglrReduce (yystackp
, yyk
, -yyaction
,
2032 yyimmediate
[-yyaction
]]b4_user_args
[);
2033 if (yyflag
== yyerr
)
2037 "(predicate failure or explicit user error).\n",
2038 (unsigned long int) yyk
));
2039 yymarkStackDeleted (yystackp
, yyk
);
2042 else if (yyflag
!= yyok
)
2050 /*ARGSUSED*/ static void
2051 yyreportSyntaxError (yyGLRStack
* yystackp
]b4_user_formals
[)
2053 if (yystackp
->yyerrState
!= 0)
2055 #if ! YYERROR_VERBOSE
2056 yyerror (]b4_lyyerror_args
[YY_("syntax error"));
2058 yySymbol yytoken
= yychar
== YYEMPTY
? YYEMPTY
: YYTRANSLATE (yychar
);
2059 size_t yysize0
= yytnamerr (YY_NULL
, yytokenName (yytoken
));
2060 size_t yysize
= yysize0
;
2062 yybool yysize_overflow
= yyfalse
;
2063 char* yymsg
= YY_NULL
;
2064 enum { YYERROR_VERBOSE_ARGS_MAXIMUM
= 5 };
2065 /* Internationalized format string. */
2066 const char *yyformat
= YY_NULL
;
2067 /* Arguments of yyformat. */
2068 char const *yyarg
[YYERROR_VERBOSE_ARGS_MAXIMUM
];
2069 /* Number of reported tokens (one for the "unexpected", one per
2073 /* There are many possibilities here to consider:
2074 - If this state is a consistent state with a default action, then
2075 the only way this function was invoked is if the default action
2076 is an error action. In that case, don't check for expected
2077 tokens because there are none.
2078 - The only way there can be no lookahead present (in yychar) is if
2079 this state is a consistent state with a default action. Thus,
2080 detecting the absence of a lookahead is sufficient to determine
2081 that there is no unexpected or expected token to report. In that
2082 case, just report a simple "syntax error".
2083 - Don't assume there isn't a lookahead just because this state is a
2084 consistent state with a default action. There might have been a
2085 previous inconsistent state, consistent state with a non-default
2086 action, or user semantic action that manipulated yychar.
2087 - Of course, the expected token list depends on states to have
2088 correct lookahead information, and it depends on the parser not
2089 to perform extra reductions after fetching a lookahead from the
2090 scanner and before detecting a syntax error. Thus, state merging
2091 (from LALR or IELR) and default reductions corrupt the expected
2092 token list. However, the list is correct for canonical LR with
2093 one exception: it will still contain any token that will not be
2094 accepted due to an error action in a later state.
2096 if (yytoken
!= YYEMPTY
)
2098 int yyn
= yypact
[yystackp
->yytops
.yystates
[0]->yylrState
];
2099 yyarg
[yycount
++] = yytokenName (yytoken
);
2100 if (!yypact_value_is_default (yyn
))
2102 /* Start YYX at -YYN if negative to avoid negative indexes in
2103 YYCHECK. In other words, skip the first -YYN actions for this
2104 state because they are default actions. */
2105 int yyxbegin
= yyn
< 0 ? -yyn
: 0;
2106 /* Stay within bounds of both yycheck and yytname. */
2107 int yychecklim
= YYLAST
- yyn
+ 1;
2108 int yyxend
= yychecklim
< YYNTOKENS
? yychecklim
: YYNTOKENS
;
2110 for (yyx
= yyxbegin
; yyx
< yyxend
; ++yyx
)
2111 if (yycheck
[yyx
+ yyn
] == yyx
&& yyx
!= YYTERROR
2112 && !yytable_value_is_error (yytable
[yyx
+ yyn
]))
2114 if (yycount
== YYERROR_VERBOSE_ARGS_MAXIMUM
)
2120 yyarg
[yycount
++] = yytokenName (yyx
);
2121 yysize1
= yysize
+ yytnamerr (YY_NULL
, yytokenName (yyx
));
2122 yysize_overflow
|= yysize1
< yysize
;
2130 #define YYCASE_(N, S) \
2134 YYCASE_(0, YY_("syntax error"));
2135 YYCASE_(1, YY_("syntax error, unexpected %s"));
2136 YYCASE_(2, YY_("syntax error, unexpected %s, expecting %s"));
2137 YYCASE_(3, YY_("syntax error, unexpected %s, expecting %s or %s"));
2138 YYCASE_(4, YY_("syntax error, unexpected %s, expecting %s or %s or %s"));
2139 YYCASE_(5, YY_("syntax error, unexpected %s, expecting %s or %s or %s or %s"));
2143 yysize1
= yysize
+ strlen (yyformat
);
2144 yysize_overflow
|= yysize1
< yysize
;
2147 if (!yysize_overflow
)
2148 yymsg
= (char *) YYMALLOC (yysize
);
2154 while ((*yyp
= *yyformat
))
2156 if (*yyp
== '%' && yyformat
[1] == 's' && yyi
< yycount
)
2158 yyp
+= yytnamerr (yyp
, yyarg
[yyi
++]);
2167 yyerror (]b4_lyyerror_args
[yymsg
);
2172 yyerror (]b4_lyyerror_args
[YY_("syntax error"));
2173 yyMemoryExhausted (yystackp
);
2175 #endif /* YYERROR_VERBOSE */
2179 /* Recover from a syntax error on *YYSTACKP, assuming that *YYSTACKP->YYTOKENP,
2180 yylval, and yylloc are the syntactic category, semantic value, and location
2181 of the lookahead. */
2182 /*ARGSUSED*/ static void
2183 yyrecoverSyntaxError (yyGLRStack
* yystackp
]b4_user_formals
[)
2188 if (yystackp
->yyerrState
== 3)
2189 /* We just shifted the error token and (perhaps) took some
2190 reductions. Skip tokens until we can proceed. */
2191 while (YYID (yytrue
))
2194 if (yychar
== YYEOF
)
2195 yyFail (yystackp
][]b4_lpure_args
[, YY_NULL
);
2196 if (yychar
!= YYEMPTY
)
2197 {]b4_locations_if([[
2198 /* We throw away the lookahead, but the error range
2199 of the shifted error token must take it into account. */
2200 yyGLRState
*yys
= yystackp
->yytops
.yystates
[0];
2201 yyGLRStackItem yyerror_range
[3];
2202 yyerror_range
[1].yystate
.yyloc
= yys
->yyloc
;
2203 yyerror_range
[2].yystate
.yyloc
= yylloc
;
2204 YYLLOC_DEFAULT ((yys
->yyloc
), yyerror_range
, 2);]])[
2205 yytoken
= YYTRANSLATE (yychar
);
2206 yydestruct ("Error: discarding",
2207 yytoken
, &yylval
]b4_locuser_args([&yylloc
])[);
2209 YYDPRINTF ((stderr
, "Reading a token: "));
2211 if (yychar
<= YYEOF
)
2213 yychar
= yytoken
= YYEOF
;
2214 YYDPRINTF ((stderr
, "Now at end of input.\n"));
2218 yytoken
= YYTRANSLATE (yychar
);
2219 YY_SYMBOL_PRINT ("Next token is", yytoken
, &yylval
, &yylloc
);
2221 yyj
= yypact
[yystackp
->yytops
.yystates
[0]->yylrState
];
2222 if (yypact_value_is_default (yyj
))
2225 if (yyj
< 0 || YYLAST
< yyj
|| yycheck
[yyj
] != yytoken
)
2227 if (yydefact
[yystackp
->yytops
.yystates
[0]->yylrState
] != 0)
2230 else if (! yytable_value_is_error (yytable
[yyj
]))
2234 /* Reduce to one stack. */
2235 for (yyk
= 0; yyk
< yystackp
->yytops
.yysize
; yyk
+= 1)
2236 if (yystackp
->yytops
.yystates
[yyk
] != YY_NULL
)
2238 if (yyk
>= yystackp
->yytops
.yysize
)
2239 yyFail (yystackp
][]b4_lpure_args
[, YY_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] != YY_NULL
)
2249 yyGLRState
*yys
= yystackp
->yytops
.yystates
[0];
2250 yyj
= yypact
[yys
->yylrState
];
2251 if (! yypact_value_is_default (yyj
))
2254 if (0 <= yyj
&& yyj
<= YYLAST
&& yycheck
[yyj
] == YYTERROR
2255 && yyisShiftAction (yytable
[yyj
]))
2257 /* Shift the error token. */]b4_locations_if([[
2258 /* First adjust its location.*/
2260 yystackp
->yyerror_range
[2].yystate
.yyloc
= yylloc
;
2261 YYLLOC_DEFAULT (yyerrloc
, (yystackp
->yyerror_range
), 2);]])[
2262 YY_SYMBOL_PRINT ("Shifting", yystos
[yytable
[yyj
]],
2263 &yylval
, &yyerrloc
);
2264 yyglrShift (yystackp
, 0, yytable
[yyj
],
2265 yys
->yyposn
, &yylval
]b4_locations_if([, &yyerrloc
])[);
2266 yys
= yystackp
->yytops
.yystates
[0];
2269 }]b4_locations_if([[
2270 yystackp
->yyerror_range
[1].yystate
.yyloc
= yys
->yyloc
;]])[
2271 if (yys
->yypred
!= YY_NULL
)
2272 yydestroyGLRState ("Error: popping", yys
]b4_user_args
[);
2273 yystackp
->yytops
.yystates
[0] = yys
->yypred
;
2274 yystackp
->yynextFree
-= 1;
2275 yystackp
->yyspaceLeft
+= 1;
2277 if (yystackp
->yytops
.yystates
[0] == YY_NULL
)
2278 yyFail (yystackp
][]b4_lpure_args
[, YY_NULL
);
2281 #define YYCHK1(YYE) \
2291 goto yyuser_error; \
2301 ]b4_c_ansi_function_def([yyparse
], [int], b4_parse_param
)[
2305 yyGLRStack
* const yystackp
= &yystack
;
2308 YYDPRINTF ((stderr
, "Starting parse\n"));
2311 yylval
= yyval_default
;
2313 #if defined YYLTYPE_IS_TRIVIAL && YYLTYPE_IS_TRIVIAL
2314 yylloc
.first_line
= yylloc
.last_line
= ]b4_location_initial_line
[;
2315 yylloc
.first_column
= yylloc
.last_column
= ]b4_location_initial_column
[;
2318 m4_ifdef([b4_initial_action
], [
2319 m4_pushdef([b4_at_dollar
], [yylloc
])dnl
2320 m4_pushdef([b4_dollar_dollar
], [yylval
])dnl
2321 /* User initialization code. */
2322 b4_user_initial_action
2323 m4_popdef([b4_dollar_dollar
])dnl
2324 m4_popdef([b4_at_dollar
])])dnl
2326 if (! yyinitGLRStack (yystackp
, YYINITDEPTH
))
2327 goto yyexhaustedlab
;
2328 switch (YYSETJMP (yystack
.yyexception_buffer
))
2331 case 1: goto yyabortlab
;
2332 case 2: goto yyexhaustedlab
;
2333 default: goto yybuglab
;
2335 yyglrShift (&yystack
, 0, 0, 0, &yylval
]b4_locations_if([, &yylloc
])[);
2338 while (YYID (yytrue
))
2340 /* For efficiency, we have two loops, the first of which is
2341 specialized to deterministic operation (single stack, no
2342 potential ambiguity). */
2344 while (YYID (yytrue
))
2348 const short int* yyconflicts
;
2350 yyStateNum yystate
= yystack
.yytops
.yystates
[0]->yylrState
;
2351 YYDPRINTF ((stderr
, "Entering state %d\n", yystate
));
2352 if (yystate
== YYFINAL
)
2354 if (yyisDefaultedState (yystate
))
2356 yyrule
= yydefaultAction (yystate
);
2359 ]b4_locations_if([[ yystack
.yyerror_range
[1].yystate
.yyloc
= yylloc
;]])[
2360 yyreportSyntaxError (&yystack
]b4_user_args
[);
2363 YYCHK1 (yyglrReduce (&yystack
, 0, yyrule
, yytrue
]b4_user_args
[));
2368 if (yychar
== YYEMPTY
)
2370 YYDPRINTF ((stderr
, "Reading a token: "));
2374 if (yychar
<= YYEOF
)
2376 yychar
= yytoken
= YYEOF
;
2377 YYDPRINTF ((stderr
, "Now at end of input.\n"));
2381 yytoken
= YYTRANSLATE (yychar
);
2382 YY_SYMBOL_PRINT ("Next token is", yytoken
, &yylval
, &yylloc
);
2385 yygetLRActions (yystate
, yytoken
, &yyaction
, &yyconflicts
);
2386 if (*yyconflicts
!= 0)
2388 if (yyisShiftAction (yyaction
))
2390 YY_SYMBOL_PRINT ("Shifting", yytoken
, &yylval
, &yylloc
);
2393 yyglrShift (&yystack
, 0, yyaction
, yyposn
, &yylval
]b4_locations_if([, &yylloc
])[);
2394 if (0 < yystack
.yyerrState
)
2395 yystack
.yyerrState
-= 1;
2397 else if (yyisErrorAction (yyaction
))
2399 ]b4_locations_if([[ yystack
.yyerror_range
[1].yystate
.yyloc
= yylloc
;]])[
2400 yyreportSyntaxError (&yystack
]b4_user_args
[);
2404 YYCHK1 (yyglrReduce (&yystack
, 0, -yyaction
, yytrue
]b4_user_args
[));
2408 while (YYID (yytrue
))
2410 yySymbol yytoken_to_shift
;
2413 for (yys
= 0; yys
< yystack
.yytops
.yysize
; yys
+= 1)
2414 yystackp
->yytops
.yylookaheadNeeds
[yys
] = yychar
!= YYEMPTY
;
2416 /* yyprocessOneStack returns one of three things:
2418 - An error flag. If the caller is yyprocessOneStack, it
2419 immediately returns as well. When the caller is finally
2420 yyparse, it jumps to an error label via YYCHK1.
2422 - yyok, but yyprocessOneStack has invoked yymarkStackDeleted
2423 (&yystack, yys), which sets the top state of yys to NULL. Thus,
2424 yyparse's following invocation of yyremoveDeletes will remove
2427 - yyok, when ready to shift a token.
2429 Except in the first case, yyparse will invoke yyremoveDeletes and
2430 then shift the next token onto all remaining stacks. This
2431 synchronization of the shift (that is, after all preceding
2432 reductions on all stacks) helps prevent double destructor calls
2433 on yylval in the event of memory exhaustion. */
2435 for (yys
= 0; yys
< yystack
.yytops
.yysize
; yys
+= 1)
2436 YYCHK1 (yyprocessOneStack (&yystack
, yys
, yyposn
]b4_lpure_args
[));
2437 yyremoveDeletes (&yystack
);
2438 if (yystack
.yytops
.yysize
== 0)
2440 yyundeleteLastStack (&yystack
);
2441 if (yystack
.yytops
.yysize
== 0)
2442 yyFail (&yystack
][]b4_lpure_args
[, YY_("syntax error"));
2443 YYCHK1 (yyresolveStack (&yystack
]b4_user_args
[));
2444 YYDPRINTF ((stderr
, "Returning to deterministic operation.\n"));
2445 ]b4_locations_if([[ yystack
.yyerror_range
[1].yystate
.yyloc
= yylloc
;]])[
2446 yyreportSyntaxError (&yystack
]b4_user_args
[);
2450 /* If any yyglrShift call fails, it will fail after shifting. Thus,
2451 a copy of yylval will already be on stack 0 in the event of a
2452 failure in the following loop. Thus, yychar is set to YYEMPTY
2453 before the loop to make sure the user destructor for yylval isn't
2455 yytoken_to_shift
= YYTRANSLATE (yychar
);
2458 for (yys
= 0; yys
< yystack
.yytops
.yysize
; yys
+= 1)
2461 const short int* yyconflicts
;
2462 yyStateNum yystate
= yystack
.yytops
.yystates
[yys
]->yylrState
;
2463 yygetLRActions (yystate
, yytoken_to_shift
, &yyaction
,
2465 /* Note that yyconflicts were handled by yyprocessOneStack. */
2466 YYDPRINTF ((stderr
, "On stack %lu, ", (unsigned long int) yys
));
2467 YY_SYMBOL_PRINT ("shifting", yytoken_to_shift
, &yylval
, &yylloc
);
2468 yyglrShift (&yystack
, yys
, yyaction
, yyposn
,
2469 &yylval
]b4_locations_if([, &yylloc
])[);
2470 YYDPRINTF ((stderr
, "Stack %lu now in state #%d\n",
2471 (unsigned long int) yys
,
2472 yystack
.yytops
.yystates
[yys
]->yylrState
));
2475 if (yystack
.yytops
.yysize
== 1)
2477 YYCHK1 (yyresolveStack (&yystack
]b4_user_args
[));
2478 YYDPRINTF ((stderr
, "Returning to deterministic operation.\n"));
2479 yycompressStack (&yystack
);
2485 yyrecoverSyntaxError (&yystack
]b4_user_args
[);
2486 yyposn
= yystack
.yytops
.yystates
[0]->yyposn
;
2502 yyerror (]b4_lyyerror_args
[YY_("memory exhausted"));
2507 if (yychar
!= YYEMPTY
)
2508 yydestruct ("Cleanup: discarding lookahead",
2509 YYTRANSLATE (yychar
), &yylval
]b4_locuser_args([&yylloc
])[);
2511 /* If the stack is well-formed, pop the stack until it is empty,
2512 destroying its entries as we go. But free the stack regardless
2513 of whether it is well-formed. */
2514 if (yystack
.yyitems
)
2516 yyGLRState
** yystates
= yystack
.yytops
.yystates
;
2519 size_t yysize
= yystack
.yytops
.yysize
;
2521 for (yyk
= 0; yyk
< yysize
; yyk
+= 1)
2524 while (yystates
[yyk
])
2526 yyGLRState
*yys
= yystates
[yyk
];
2527 ]b4_locations_if([[ yystack
.yyerror_range
[1].yystate
.yyloc
= yys
->yyloc
;]]
2528 )[ if (yys
->yypred
!= YY_NULL
)
2529 yydestroyGLRState ("Cleanup: popping", yys
]b4_user_args
[);
2530 yystates
[yyk
] = yys
->yypred
;
2531 yystack
.yynextFree
-= 1;
2532 yystack
.yyspaceLeft
+= 1;
2537 yyfreeGLRStack (&yystack
);
2540 /* Make sure YYID is used. */
2541 return YYID (yyresult
);
2544 /* DEBUGGING ONLY */
2546 static void yypstack (yyGLRStack
* yystackp
, size_t yyk
)
2547 __attribute__ ((__unused__
));
2548 static void yypdumpstack (yyGLRStack
* yystackp
) __attribute__ ((__unused__
));
2551 yy_yypstack (yyGLRState
* yys
)
2555 yy_yypstack (yys
->yypred
);
2556 YYFPRINTF (stderr
, " -> ");
2558 YYFPRINTF (stderr
, "%d@@%lu", yys
->yylrState
,
2559 (unsigned long int) yys
->yyposn
);
2563 yypstates (yyGLRState
* yyst
)
2565 if (yyst
== YY_NULL
)
2566 YYFPRINTF (stderr
, "<null>");
2569 YYFPRINTF (stderr
, "\n");
2573 yypstack (yyGLRStack
* yystackp
, size_t yyk
)
2575 yypstates (yystackp
->yytops
.yystates
[yyk
]);
2578 #define YYINDEX(YYX) \
2579 ((YYX) == YY_NULL ? -1 : (yyGLRStackItem*) (YYX) - yystackp->yyitems)
2583 yypdumpstack (yyGLRStack
* yystackp
)
2585 yyGLRStackItem
* yyp
;
2587 for (yyp
= yystackp
->yyitems
; yyp
< yystackp
->yynextFree
; yyp
+= 1)
2589 YYFPRINTF (stderr
, "%3lu. ",
2590 (unsigned long int) (yyp
- yystackp
->yyitems
));
2591 if (*(yybool
*) yyp
)
2593 YYFPRINTF (stderr
, "Res: %d, LR State: %d, posn: %lu, pred: %ld",
2594 yyp
->yystate
.yyresolved
, yyp
->yystate
.yylrState
,
2595 (unsigned long int) yyp
->yystate
.yyposn
,
2596 (long int) YYINDEX (yyp
->yystate
.yypred
));
2597 if (! yyp
->yystate
.yyresolved
)
2598 YYFPRINTF (stderr
, ", firstVal: %ld",
2599 (long int) YYINDEX (yyp
->yystate
2600 .yysemantics
.yyfirstVal
));
2604 YYFPRINTF (stderr
, "Option. rule: %d, state: %ld, next: %ld",
2605 yyp
->yyoption
.yyrule
- 1,
2606 (long int) YYINDEX (yyp
->yyoption
.yystate
),
2607 (long int) YYINDEX (yyp
->yyoption
.yynext
));
2609 YYFPRINTF (stderr
, "\n");
2611 YYFPRINTF (stderr
, "Tops:");
2612 for (yyi
= 0; yyi
< yystackp
->yytops
.yysize
; yyi
+= 1)
2613 YYFPRINTF (stderr
, "%lu: %ld; ", (unsigned long int) yyi
,
2614 (long int) YYINDEX (yystackp
->yytops
.yystates
[yyi
]));
2615 YYFPRINTF (stderr
, "\n");
2620 dnl glr
.cc produces its own header
.
2622 m4_if(b4_skeleton
, ["glr.c"],
2624 [@
output(b4_spec_defines_file@
)@
2625 b4_copyright([Skeleton interface
for Bison GLR parsers in C
],
2628 ]b4_cpp_guard_open([b4_spec_defines_file
])[
2629 ]b4_shared_declarations
[
2630 ]b4_cpp_guard_close([b4_spec_defines_file
])[