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 [((*yyvalp
)[]m4_ifval([$
1], [.$
1]))])
129 # b4_rhs_value(RULE-LENGTH, NUM, [TYPE])
130 # --------------------------------------
131 # Expansion of $<TYPE>NUM, where the current rule has RULE-LENGTH
133 m4_define([b4_rhs_value
],
134 [(((yyGLRStackItem
const *)yyvsp
)@
{YYFILL (($
2) - ($
1))@
}.yystate
.yysemantics
.yysval
[]m4_ifval([$
3], [.$
3]))])
145 m4_define([b4_lhs_location
],
149 # b4_rhs_location(RULE-LENGTH, NUM)
150 # ---------------------------------
151 # Expansion of @NUM, where the current rule has RULE-LENGTH symbols
153 m4_define([b4_rhs_location
],
154 [(((yyGLRStackItem
const *)yyvsp
)@
{YYFILL (($
2) - ($
1))@
}.yystate
.yyloc
)])
161 # b4_shared_declarations
162 # ----------------------
163 # Declaration that might either go into the header (if --defines)
164 # or open coded in the parser body.
165 m4_define([b4_shared_declarations
],
167 ]b4_percent_code_get([[requires]])[
168 ]b4_token_enums(b4_tokens
)[
169 ]b4_declare_yylstype
[
170 ]b4_c_ansi_function_decl(b4_prefix
[parse
], [int], b4_parse_param
)[
171 ]b4_percent_code_get([[provides]])[]dnl
179 # We do want M4 expansion after # for CPP macros.
182 @
output(b4_parser_file_name@
)@
183 b4_copyright([Skeleton implementation
for Bison GLR parsers in C
],
186 /* C GLR parser skeleton written by Paul Hilfinger. */
190 b4_percent_code_get([[top]])[
191 ]m4_if(b4_api_prefix
, [yy
], [],
192 [[/* Substitute the type names. */
193 #define YYSTYPE ]b4_api_PREFIX[STYPE
194 #define YYSTYPE_IS_TRIVIAL ]b4_api_PREFIX[STYPE_IS_TRIVIAL
195 #define YYSTYPE_IS_DECLARED ]b4_api_PREFIX[STYPE_IS_DECLARED]b4_locations_if([[
196 #define YYLTYPE ]b4_api_PREFIX[LTYPE
197 #define YYLTYPE_IS_TRIVIAL ]b4_api_PREFIX[LTYPE_IS_TRIVIAL
198 #define YYLTYPE_IS_DECLARED ]b4_api_PREFIX[LTYPE_IS_DECLARED]])])[
199 ]m4_if(b4_prefix
, [yy
], [],
200 [[/* Substitute the variable and function names. */
201 #define yyparse ]b4_prefix[parse
202 #define yylex ]b4_prefix[lex
203 #define yyerror ]b4_prefix[error
204 #define yylval ]b4_prefix[lval
205 #define yychar ]b4_prefix[char
206 #define yydebug ]b4_prefix[debug
207 #define yynerrs ]b4_prefix[nerrs]b4_locations_if([[
208 #define yylloc ]b4_prefix[lloc]])])[
210 /* Copy the first part of user declarations. */
211 ]b4_user_pre_prologue
[
215 ]b4_defines_if([[#include "@basename(]b4_spec_defines_file[@)"]],
216 [b4_shared_declarations
])[
218 /* Enabling verbose error messages. */
219 #ifdef YYERROR_VERBOSE
220 # undef YYERROR_VERBOSE
221 # define YYERROR_VERBOSE 1
223 # define YYERROR_VERBOSE ]b4_error_verbose_flag[
226 /* Default (constant) value used for initialization for null
227 right-hand sides. Unlike the standard yacc.c template,
228 here we set the default value of $$ to a zeroed-out value.
229 Since the default value is undefined, this behavior is
230 technically correct. */
231 static YYSTYPE yyval_default
;
233 /* Copy the second part of user declarations. */
234 ]b4_user_post_prologue
235 b4_percent_code_get
[]dnl
242 # if defined YYENABLE_NLS && YYENABLE_NLS
244 # include <libintl.h> /* INFRINGES ON USER NAME SPACE */
245 # define YY_(msgid) dgettext ("bison-runtime", msgid)
249 # define YY_(msgid) msgid
253 /* Suppress unused-variable warnings by "using" E. */
254 #if ! defined lint || defined __GNUC__
255 # define YYUSE(e) ((void) (e))
257 # define YYUSE(e) /* empty */
260 /* Identity function, used to suppress warnings about constant conditions. */
264 ]b4_c_function_def([YYID
], [static int], [[int i
], [i
]])[
274 # define YYMALLOC malloc
277 # define YYREALLOC realloc
280 #define YYSIZEMAX ((size_t) -1)
285 typedef unsigned char yybool
;
292 # define YYJMP_BUF jmp_buf
293 # define YYSETJMP(env) setjmp (env)
294 # define YYLONGJMP(env, val) longjmp (env, val)
301 #ifndef __attribute__
302 /* This feature is available in gcc versions 2.5 and later. */
303 # if (! defined __GNUC__ || __GNUC__ < 2 \
304 || (__GNUC__ == 2 && __GNUC_MINOR__ < 5))
305 # define __attribute__(Spec) /* empty */
309 ]b4_locations_if([#define YYOPTIONAL_LOC(Name) Name],[
311 # define YYOPTIONAL_LOC(Name) /* empty */
313 # define YYOPTIONAL_LOC(Name) Name __attribute__ ((__unused__))
317 # define YYASSERT(condition) ((void) ((condition) || (abort (), 0)))
320 /* YYFINAL -- State number of the termination state. */
321 #define YYFINAL ]b4_final_state_number[
322 /* YYLAST -- Last index in YYTABLE. */
323 #define YYLAST ]b4_last[
325 /* YYNTOKENS -- Number of terminals. */
326 #define YYNTOKENS ]b4_tokens_number[
327 /* YYNNTS -- Number of nonterminals. */
328 #define YYNNTS ]b4_nterms_number[
329 /* YYNRULES -- Number of rules. */
330 #define YYNRULES ]b4_rules_number[
331 /* YYNRULES -- Number of states. */
332 #define YYNSTATES ]b4_states_number[
333 /* YYMAXRHS -- Maximum number of symbols on right-hand side of rule. */
334 #define YYMAXRHS ]b4_r2_max[
335 /* YYMAXLEFT -- Maximum number of symbols to the left of a handle
336 accessed by $0, $-1, etc., in any rule. */
337 #define YYMAXLEFT ]b4_max_left_semantic_context[
339 /* YYTRANSLATE(X) -- Bison symbol number corresponding to X. */
340 #define YYUNDEFTOK ]b4_undef_token_number[
341 #define YYMAXUTOK ]b4_user_token_number_max[
343 #define YYTRANSLATE(YYX) \
344 ((unsigned int) (YYX) <= YYMAXUTOK ? yytranslate[YYX] : YYUNDEFTOK)
346 /* YYTRANSLATE[YYLEX] -- Bison symbol number corresponding to YYLEX. */
347 static const ]b4_int_type_for([b4_translate
])[ yytranslate
[] =
352 #if ]b4_api_PREFIX[DEBUG
353 /* YYPRHS[YYN] -- Index of the first RHS symbol of rule number YYN in
355 static const ]b4_int_type_for([b4_prhs
])[ yyprhs
[] =
360 /* YYRHS -- A `-1'-separated list of the rules' RHS. */
361 static const ]b4_int_type_for([b4_rhs
])[ yyrhs
[] =
366 /* YYRLINE[YYN] -- source line where rule number YYN was defined. */
367 static const ]b4_int_type_for([b4_rline
])[ yyrline
[] =
373 #if ]b4_api_PREFIX[DEBUG || YYERROR_VERBOSE || ]b4_token_table_flag[
374 /* YYTNAME[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM.
375 First, the terminals, then, starting at YYNTOKENS, nonterminals. */
376 static const char *const yytname
[] =
382 /* YYR1[YYN] -- Symbol number of symbol that rule YYN derives. */
383 static const ]b4_int_type_for([b4_r1
])[ yyr1
[] =
388 /* YYR2[YYN] -- Number of symbols composing right hand side of rule YYN. */
389 static const ]b4_int_type_for([b4_r2
])[ yyr2
[] =
394 /* YYDPREC[RULE-NUM] -- Dynamic precedence of rule #RULE-NUM (0 if none). */
395 static const ]b4_int_type_for([b4_dprec
])[ yydprec
[] =
400 /* YYMERGER[RULE-NUM] -- Index of merging function for rule #RULE-NUM. */
401 static const ]b4_int_type_for([b4_merger
])[ yymerger
[] =
406 /* YYDEFACT[S] -- default reduction number in state S. Performed when
407 YYTABLE doesn't specify something else to do. Zero means the default
409 static const ]b4_int_type_for([b4_defact
])[ yydefact
[] =
414 /* YYPDEFGOTO[NTERM-NUM]. */
415 static const ]b4_int_type_for([b4_defgoto
])[ yydefgoto
[] =
420 /* YYPACT[STATE-NUM] -- Index in YYTABLE of the portion describing
422 #define YYPACT_NINF ]b4_pact_ninf[
423 static const ]b4_int_type_for([b4_pact
])[ yypact
[] =
428 /* YYPGOTO[NTERM-NUM]. */
429 static const ]b4_int_type_for([b4_pgoto
])[ yypgoto
[] =
434 /* YYTABLE[YYPACT[STATE-NUM]]. What to do in state STATE-NUM. If
435 positive, shift that token. If negative, reduce the rule which
436 number is the opposite. If YYTABLE_NINF, syntax error. */
437 #define YYTABLE_NINF ]b4_table_ninf[
438 static const ]b4_int_type_for([b4_table
])[ yytable
[] =
443 /* YYCONFLP[YYPACT[STATE-NUM]] -- Pointer into YYCONFL of start of
444 list of conflicting reductions corresponding to action entry for
445 state STATE-NUM in yytable. 0 means no conflicts. The list in
446 yyconfl is terminated by a rule number of 0. */
447 static const ]b4_int_type_for([b4_conflict_list_heads
])[ yyconflp
[] =
449 ]b4_conflict_list_heads
[
452 /* YYCONFL[I] -- lists of conflicting rule numbers, each terminated by
453 0, pointed into by YYCONFLP. */
454 ]dnl Do
not use b4_int_type_for here
, since there are places where
455 dnl pointers onto yyconfl are taken
, which type is
"short int *".
456 dnl We probably ought to introduce a type
for confl
.
457 [static const short int yyconfl
[] =
459 ]b4_conflicting_rules
[
462 static const ]b4_int_type_for([b4_check
])[ yycheck
[] =
467 /* YYSTOS[STATE-NUM] -- The (internal number of the) accessing
468 symbol of state STATE-NUM. */
469 static const ]b4_int_type_for([b4_stos
])[ yystos
[] =
475 /* Error token number */
478 /* YYLLOC_DEFAULT -- Set CURRENT to span from RHS[1] to RHS[N].
479 If N is 0, then set CURRENT to the empty location which ends
480 the previous symbol: RHS[0] (always defined). */
483 #define YYRHSLOC(Rhs, K) ((Rhs)[K].yystate.yyloc)
484 #ifndef YYLLOC_DEFAULT
485 # define YYLLOC_DEFAULT(Current, Rhs, N) \
489 (Current).first_line = YYRHSLOC (Rhs, 1).first_line; \
490 (Current).first_column = YYRHSLOC (Rhs, 1).first_column; \
491 (Current).last_line = YYRHSLOC (Rhs, N).last_line; \
492 (Current).last_column = YYRHSLOC (Rhs, N).last_column; \
496 (Current).first_line = (Current).last_line = \
497 YYRHSLOC (Rhs, 0).last_line; \
498 (Current).first_column = (Current).last_column = \
499 YYRHSLOC (Rhs, 0).last_column; \
503 /* YY_LOCATION_PRINT -- Print the location on the stream.
504 This macro was not mandated originally: define only if we know
505 we won't break user code: when these are the locations we know. */
507 # define YY_LOCATION_PRINT(File, Loc) \
508 fprintf (File, "%d.%d-%d.%d", \
509 (Loc).first_line, (Loc).first_column, \
510 (Loc).last_line, (Loc).last_column)
513 #ifndef YYLLOC_DEFAULT
514 # define YYLLOC_DEFAULT(Current, Rhs, N) ((void) 0)
518 #ifndef YY_LOCATION_PRINT
519 # define YY_LOCATION_PRINT(File, Loc) ((void) 0)
523 /* YYLEX -- calling `yylex' with the right arguments. */
524 #define YYLEX ]b4_c_function_call([yylex], [int], b4_lex_param)[
529 #define yynerrs (yystackp->yyerrcnt)
531 #define yychar (yystackp->yyrawchar)
533 #define yylval (yystackp->yyval)
535 #define yylloc (yystackp->yyloc)
536 m4_if(b4_prefix
[], [yy
], [],
537 [#define b4_prefix[]nerrs yynerrs
538 #define b4_prefix[]char yychar
539 #define b4_prefix[]lval yylval
540 #define b4_prefix[]lloc yylloc])],
541 [YYSTYPE yylval
;]b4_locations_if([[
547 static const int YYEOF
= 0;
548 static const int YYEMPTY
= -2;
550 typedef enum { yyok
, yyaccept
, yyabort
, yyerr
} YYRESULTTAG
;
553 do { YYRESULTTAG yyflag = YYE; if (yyflag != yyok) return yyflag; } \
556 #if ]b4_api_PREFIX[DEBUG
559 # define YYFPRINTF fprintf
562 # define YYDPRINTF(Args) \
568 ]b4_yy_symbol_print_generate([b4_c_ansi_function_def
])[
570 # define YY_SYMBOL_PRINT(Title, Type, Value, Location) \
574 YYFPRINTF (stderr, "%s ", Title); \
575 yy_symbol_print (stderr, Type, Value]b4_locuser_args([Location])[); \
576 YYFPRINTF (stderr, "\n"); \
580 /* Nonzero means print parse trace. It is left uninitialized so that
581 multiple parsers can coexist. */
584 #else /* !]b4_api_PREFIX[DEBUG */
586 # define YYDPRINTF(Args)
587 # define YY_SYMBOL_PRINT(Title, Type, Value, Location)
589 #endif /* !]b4_api_PREFIX[DEBUG */
591 /* YYINITDEPTH -- initial size of the parser's stacks. */
593 # define YYINITDEPTH ]b4_stack_depth_init[
596 /* YYMAXDEPTH -- maximum size the stacks can grow to (effective only
597 if the built-in stack extension method is used).
599 Do not make this value too large; the results are undefined if
600 SIZE_MAX < YYMAXDEPTH * sizeof (GLRStackItem)
601 evaluated with infinite-precision integer arithmetic. */
604 # define YYMAXDEPTH ]b4_stack_depth_max[
607 /* Minimum number of free items on the stack allowed after an
608 allocation. This is to allow allocation and initialization
609 to be completed by functions that call yyexpandGLRStack before the
610 stack is expanded, thus insuring that all necessary pointers get
611 properly redirected to new data. */
614 #ifndef YYSTACKEXPANDABLE
615 # if (! defined __cplusplus \
616 || (]b4_locations_if([[defined YYLTYPE_IS_TRIVIAL && YYLTYPE_IS_TRIVIAL \
617 && ]])[defined YYSTYPE_IS_TRIVIAL && YYSTYPE_IS_TRIVIAL))
618 # define YYSTACKEXPANDABLE 1
620 # define YYSTACKEXPANDABLE 0
624 #if YYSTACKEXPANDABLE
625 # define YY_RESERVE_GLRSTACK(Yystack) \
627 if (Yystack->yyspaceLeft < YYHEADROOM) \
628 yyexpandGLRStack (Yystack); \
631 # define YY_RESERVE_GLRSTACK(Yystack) \
633 if (Yystack->yyspaceLeft < YYHEADROOM) \
634 yyMemoryExhausted (Yystack); \
642 # if defined __GLIBC__ && defined _STRING_H && defined _GNU_SOURCE
643 # define yystpcpy stpcpy
645 /* Copy YYSRC to YYDEST, returning the address of the terminating '\0' in
648 yystpcpy (char *yydest
, const char *yysrc
)
651 const char *yys
= yysrc
;
653 while ((*yyd
++ = *yys
++) != '\0')
662 /* Copy to YYRES the contents of YYSTR after stripping away unnecessary
663 quotes and backslashes, so that it's suitable for yyerror. The
664 heuristic is that double-quoting is unnecessary unless the string
665 contains an apostrophe, a comma, or backslash (other than
666 backslash-backslash). YYSTR is taken from yytname. If YYRES is
667 null, do not copy; instead, return the length of what the result
670 yytnamerr (char *yyres
, const char *yystr
)
675 char const *yyp
= yystr
;
682 goto do_not_strip_quotes
;
686 goto do_not_strip_quotes
;
699 do_not_strip_quotes
: ;
703 return strlen (yystr
);
705 return yystpcpy (yyres
, yystr
) - yyres
;
709 #endif /* !YYERROR_VERBOSE */
711 /** State numbers, as in LALR(1) machine */
712 typedef int yyStateNum
;
714 /** Rule numbers, as in LALR(1) machine */
715 typedef int yyRuleNum
;
717 /** Grammar symbol */
718 typedef short int yySymbol
;
720 /** Item references, as in LALR(1) machine */
721 typedef short int yyItemNum
;
723 typedef struct yyGLRState yyGLRState
;
724 typedef struct yyGLRStateSet yyGLRStateSet
;
725 typedef struct yySemanticOption yySemanticOption
;
726 typedef union yyGLRStackItem yyGLRStackItem
;
727 typedef struct yyGLRStack yyGLRStack
;
730 /** Type tag: always true. */
732 /** Type tag for yysemantics. If true, yysval applies, otherwise
733 * yyfirstVal applies. */
735 /** Number of corresponding LALR(1) machine state. */
736 yyStateNum yylrState
;
737 /** Preceding state in this stack */
739 /** Source position of the first token produced by my symbol */
742 /** First in a chain of alternative reductions producing the
743 * non-terminal corresponding to this state, threaded through
745 yySemanticOption
* yyfirstVal
;
746 /** Semantic value for this state. */
748 } yysemantics
;]b4_locations_if([[
749 /** Source location for this state. */
753 struct yyGLRStateSet
{
754 yyGLRState
** yystates
;
755 /** During nondeterministic operation, yylookaheadNeeds tracks which
756 * stacks have actually needed the current lookahead. During deterministic
757 * operation, yylookaheadNeeds[0] is not maintained since it would merely
758 * duplicate yychar != YYEMPTY. */
759 yybool
* yylookaheadNeeds
;
760 size_t yysize
, yycapacity
;
763 struct yySemanticOption
{
764 /** Type tag: always false. */
766 /** Rule number for this reduction */
768 /** The last RHS state in the list of states to be reduced. */
770 /** The lookahead for this reduction. */
772 YYSTYPE yyval
;]b4_locations_if([[
774 /** Next sibling in chain of options. To facilitate merging,
775 * options are chained in decreasing order by address. */
776 yySemanticOption
* yynext
;
779 /** Type of the items in the GLR stack. The yyisState field
780 * indicates which item of the union is valid. */
781 union yyGLRStackItem
{
783 yySemanticOption yyoption
;
788 ]b4_locations_if([[ /* To compute the location of the error token. */
789 yyGLRStackItem yyerror_range
[3];]])[
794 YYSTYPE yyval
;]b4_locations_if([[
797 YYJMP_BUF yyexception_buffer
;
798 yyGLRStackItem
* yyitems
;
799 yyGLRStackItem
* yynextFree
;
801 yyGLRState
* yysplitPoint
;
802 yyGLRState
* yylastDeleted
;
803 yyGLRStateSet yytops
;
806 #if YYSTACKEXPANDABLE
807 static void yyexpandGLRStack (yyGLRStack
* yystackp
);
810 static void yyFail (yyGLRStack
* yystackp
]b4_pure_formals
[, const char* yymsg
)
811 __attribute__ ((__noreturn__
));
813 yyFail (yyGLRStack
* yystackp
]b4_pure_formals
[, const char* yymsg
)
815 if (yymsg
!= YY_NULL
)
816 yyerror (]b4_yyerror_args
[yymsg
);
817 YYLONGJMP (yystackp
->yyexception_buffer
, 1);
820 static void yyMemoryExhausted (yyGLRStack
* yystackp
)
821 __attribute__ ((__noreturn__
));
823 yyMemoryExhausted (yyGLRStack
* yystackp
)
825 YYLONGJMP (yystackp
->yyexception_buffer
, 2);
828 #if ]b4_api_PREFIX[DEBUG || YYERROR_VERBOSE
829 /** A printable representation of TOKEN. */
830 static inline const char*
831 yytokenName (yySymbol yytoken
)
833 if (yytoken
== YYEMPTY
)
836 return yytname
[yytoken
];
840 /** Fill in YYVSP[YYLOW1 .. YYLOW0-1] from the chain of states starting
841 * at YYVSP[YYLOW0].yystate.yypred. Leaves YYVSP[YYLOW1].yystate.yypred
842 * containing the pointer to the next state in the chain. */
843 static void yyfillin (yyGLRStackItem
*, int, int) __attribute__ ((__unused__
));
845 yyfillin (yyGLRStackItem
*yyvsp
, int yylow0
, int yylow1
)
848 yyGLRState
*s
= yyvsp
[yylow0
].yystate
.yypred
;
849 for (i
= yylow0
-1; i
>= yylow1
; i
-= 1)
851 YYASSERT (s
->yyresolved
);
852 yyvsp
[i
].yystate
.yyresolved
= yytrue
;
853 yyvsp
[i
].yystate
.yysemantics
.yysval
= s
->yysemantics
.yysval
;]b4_locations_if([[
854 yyvsp
[i
].yystate
.yyloc
= s
->yyloc
;]])[
855 s
= yyvsp
[i
].yystate
.yypred
= s
->yypred
;
859 /* Do nothing if YYNORMAL or if *YYLOW <= YYLOW1. Otherwise, fill in
860 * YYVSP[YYLOW1 .. *YYLOW-1] as in yyfillin and set *YYLOW = YYLOW1.
861 * For convenience, always return YYLOW1. */
862 static inline int yyfill (yyGLRStackItem
*, int *, int, yybool
)
863 __attribute__ ((__unused__
));
865 yyfill (yyGLRStackItem
*yyvsp
, int *yylow
, int yylow1
, yybool yynormal
)
867 if (!yynormal
&& yylow1
< *yylow
)
869 yyfillin (yyvsp
, *yylow
, yylow1
);
875 /** Perform user action for rule number YYN, with RHS length YYRHSLEN,
876 * and top stack item YYVSP. YYLVALP points to place to put semantic
877 * value ($$), and yylocp points to place for location information
878 * (@@$). Returns yyok for normal return, yyaccept for YYACCEPT,
879 * yyerr for YYERROR, yyabort for YYABORT. */
880 /*ARGSUSED*/ static YYRESULTTAG
881 yyuserAction (yyRuleNum yyn
, int yyrhslen
, yyGLRStackItem
* yyvsp
,
882 yyGLRStack
* yystackp
,
883 YYSTYPE
* yyvalp
]b4_locuser_formals
[)
885 yybool yynormal
__attribute__ ((__unused__
)) =
886 (yystackp
->yysplitPoint
== YY_NULL
);
888 ]b4_parse_param_use
[]dnl
890 # define yyerrok (yystackp->yyerrState = 0)
892 # define YYACCEPT return yyaccept
894 # define YYABORT return yyabort
896 # define YYERROR return yyerrok, yyerr
898 # define YYRECOVERING() (yystackp->yyerrState != 0)
900 # define yyclearin (yychar = YYEMPTY)
902 # define YYFILL(N) yyfill (yyvsp, &yylow, N, yynormal)
904 # define YYBACKUP(Token, Value) \
905 return yyerror (]b4_yyerror_args[YY_("syntax error: cannot back up")), \
910 *yyvalp
= yyval_default
;
912 *yyvalp
= yyvsp
[YYFILL (1-yyrhslen
)].yystate
.yysemantics
.yysval
;]b4_locations_if([[
913 YYLLOC_DEFAULT ((*yylocp
), (yyvsp
- yyrhslen
), yyrhslen
);
914 yystackp
->yyerror_range
[1].yystate
.yyloc
= *yylocp
;
933 /*ARGSUSED*/ static void
934 yyuserMerge (int yyn
, YYSTYPE
* yy0
, YYSTYPE
* yy1
)
946 /* Bison grammar-table manipulation. */
948 ]b4_yydestruct_generate([b4_c_ansi_function_def
])[
950 /** Number of symbols composing the right hand side of rule #RULE. */
952 yyrhsLength (yyRuleNum yyrule
)
958 yydestroyGLRState (char const *yymsg
, yyGLRState
*yys
]b4_user_formals
[)
961 yydestruct (yymsg
, yystos
[yys
->yylrState
],
962 &yys
->yysemantics
.yysval
]b4_locuser_args([&yys
->yyloc
])[);
965 #if ]b4_api_PREFIX[DEBUG
968 if (yys
->yysemantics
.yyfirstVal
)
969 YYFPRINTF (stderr
, "%s unresolved ", yymsg
);
971 YYFPRINTF (stderr
, "%s incomplete ", yymsg
);
972 yy_symbol_print (stderr
, yystos
[yys
->yylrState
],
973 YY_NULL
]b4_locuser_args([&yys
->yyloc
])[);
974 YYFPRINTF (stderr
, "\n");
978 if (yys
->yysemantics
.yyfirstVal
)
980 yySemanticOption
*yyoption
= yys
->yysemantics
.yyfirstVal
;
983 for (yyrh
= yyoption
->yystate
, yyn
= yyrhsLength (yyoption
->yyrule
);
985 yyrh
= yyrh
->yypred
, yyn
-= 1)
986 yydestroyGLRState (yymsg
, yyrh
]b4_user_args
[);
991 /** Left-hand-side symbol for rule #RULE. */
992 static inline yySymbol
993 yylhsNonterm (yyRuleNum yyrule
)
998 #define yypact_value_is_default(yystate) \
999 ]b4_table_value_equals([[pact]], [[yystate]], [b4_pact_ninf])[
1001 /** True iff LR state STATE has only a default reduction (regardless
1003 static inline yybool
1004 yyisDefaultedState (yyStateNum yystate
)
1006 return yypact_value_is_default (yypact
[yystate
]);
1009 /** The default reduction for STATE, assuming it has one. */
1010 static inline yyRuleNum
1011 yydefaultAction (yyStateNum yystate
)
1013 return yydefact
[yystate
];
1016 #define yytable_value_is_error(yytable_value) \
1017 ]b4_table_value_equals([[table]], [[yytable_value]], [b4_table_ninf])[
1019 /** Set *YYACTION to the action to take in YYSTATE on seeing YYTOKEN.
1021 * R < 0: Reduce on rule -R.
1023 * R > 0: Shift to state R.
1024 * Set *CONFLICTS to a pointer into yyconfl to 0-terminated list of
1025 * conflicting reductions.
1028 yygetLRActions (yyStateNum yystate
, int yytoken
,
1029 int* yyaction
, const short int** yyconflicts
)
1031 int yyindex
= yypact
[yystate
] + yytoken
;
1032 if (yypact_value_is_default (yypact
[yystate
])
1033 || yyindex
< 0 || YYLAST
< yyindex
|| yycheck
[yyindex
] != yytoken
)
1035 *yyaction
= -yydefact
[yystate
];
1036 *yyconflicts
= yyconfl
;
1038 else if (! yytable_value_is_error (yytable
[yyindex
]))
1040 *yyaction
= yytable
[yyindex
];
1041 *yyconflicts
= yyconfl
+ yyconflp
[yyindex
];
1046 *yyconflicts
= yyconfl
+ yyconflp
[yyindex
];
1050 static inline yyStateNum
1051 yyLRgotoState (yyStateNum yystate
, yySymbol yylhs
)
1054 yyr
= yypgoto
[yylhs
- YYNTOKENS
] + yystate
;
1055 if (0 <= yyr
&& yyr
<= YYLAST
&& yycheck
[yyr
] == yystate
)
1056 return yytable
[yyr
];
1058 return yydefgoto
[yylhs
- YYNTOKENS
];
1061 static inline yybool
1062 yyisShiftAction (int yyaction
)
1064 return 0 < yyaction
;
1067 static inline yybool
1068 yyisErrorAction (int yyaction
)
1070 return yyaction
== 0;
1075 /** Return a fresh GLRStackItem. Callers should call
1076 * YY_RESERVE_GLRSTACK afterwards to make sure there is sufficient
1079 static inline yyGLRStackItem
*
1080 yynewGLRStackItem (yyGLRStack
* yystackp
, yybool yyisState
)
1082 yyGLRStackItem
* yynewItem
= yystackp
->yynextFree
;
1083 yystackp
->yyspaceLeft
-= 1;
1084 yystackp
->yynextFree
+= 1;
1085 yynewItem
->yystate
.yyisState
= yyisState
;
1089 /** Add a new semantic action that will execute the action for rule
1090 * RULENUM on the semantic values in RHS to the list of
1091 * alternative actions for STATE. Assumes that RHS comes from
1092 * stack #K of *STACKP. */
1094 yyaddDeferredAction (yyGLRStack
* yystackp
, size_t yyk
, yyGLRState
* yystate
,
1095 yyGLRState
* rhs
, yyRuleNum yyrule
)
1097 yySemanticOption
* yynewOption
=
1098 &yynewGLRStackItem (yystackp
, yyfalse
)->yyoption
;
1099 yynewOption
->yystate
= rhs
;
1100 yynewOption
->yyrule
= yyrule
;
1101 if (yystackp
->yytops
.yylookaheadNeeds
[yyk
])
1103 yynewOption
->yyrawchar
= yychar
;
1104 yynewOption
->yyval
= yylval
;]b4_locations_if([
1105 yynewOption
->yyloc
= yylloc
;])[
1108 yynewOption
->yyrawchar
= YYEMPTY
;
1109 yynewOption
->yynext
= yystate
->yysemantics
.yyfirstVal
;
1110 yystate
->yysemantics
.yyfirstVal
= yynewOption
;
1112 YY_RESERVE_GLRSTACK (yystackp
);
1117 /** Initialize SET to a singleton set containing an empty stack. */
1119 yyinitStateSet (yyGLRStateSet
* yyset
)
1122 yyset
->yycapacity
= 16;
1123 yyset
->yystates
= (yyGLRState
**) YYMALLOC (16 * sizeof yyset
->yystates
[0]);
1124 if (! yyset
->yystates
)
1126 yyset
->yystates
[0] = YY_NULL
;
1127 yyset
->yylookaheadNeeds
=
1128 (yybool
*) YYMALLOC (16 * sizeof yyset
->yylookaheadNeeds
[0]);
1129 if (! yyset
->yylookaheadNeeds
)
1131 YYFREE (yyset
->yystates
);
1137 static void yyfreeStateSet (yyGLRStateSet
* yyset
)
1139 YYFREE (yyset
->yystates
);
1140 YYFREE (yyset
->yylookaheadNeeds
);
1143 /** Initialize STACK to a single empty stack, with total maximum
1144 * capacity for all stacks of SIZE. */
1146 yyinitGLRStack (yyGLRStack
* yystackp
, size_t yysize
)
1148 yystackp
->yyerrState
= 0;
1150 yystackp
->yyspaceLeft
= yysize
;
1152 (yyGLRStackItem
*) YYMALLOC (yysize
* sizeof yystackp
->yynextFree
[0]);
1153 if (!yystackp
->yyitems
)
1155 yystackp
->yynextFree
= yystackp
->yyitems
;
1156 yystackp
->yysplitPoint
= YY_NULL
;
1157 yystackp
->yylastDeleted
= YY_NULL
;
1158 return yyinitStateSet (&yystackp
->yytops
);
1162 #if YYSTACKEXPANDABLE
1163 # define YYRELOC(YYFROMITEMS,YYTOITEMS,YYX,YYTYPE) \
1164 &((YYTOITEMS) - ((YYFROMITEMS) - (yyGLRStackItem*) (YYX)))->YYTYPE
1166 /** If STACK is expandable, extend it. WARNING: Pointers into the
1167 stack from outside should be considered invalid after this call.
1168 We always expand when there are 1 or fewer items left AFTER an
1169 allocation, so that we can avoid having external pointers exist
1170 across an allocation. */
1172 yyexpandGLRStack (yyGLRStack
* yystackp
)
1174 yyGLRStackItem
* yynewItems
;
1175 yyGLRStackItem
* yyp0
, *yyp1
;
1178 size_t yysize
= yystackp
->yynextFree
- yystackp
->yyitems
;
1179 if (YYMAXDEPTH
- YYHEADROOM
< yysize
)
1180 yyMemoryExhausted (yystackp
);
1181 yynewSize
= 2*yysize
;
1182 if (YYMAXDEPTH
< yynewSize
)
1183 yynewSize
= YYMAXDEPTH
;
1184 yynewItems
= (yyGLRStackItem
*) YYMALLOC (yynewSize
* sizeof yynewItems
[0]);
1186 yyMemoryExhausted (yystackp
);
1187 for (yyp0
= yystackp
->yyitems
, yyp1
= yynewItems
, yyn
= yysize
;
1189 yyn
-= 1, yyp0
+= 1, yyp1
+= 1)
1192 if (*(yybool
*) yyp0
)
1194 yyGLRState
* yys0
= &yyp0
->yystate
;
1195 yyGLRState
* yys1
= &yyp1
->yystate
;
1196 if (yys0
->yypred
!= YY_NULL
)
1198 YYRELOC (yyp0
, yyp1
, yys0
->yypred
, yystate
);
1199 if (! yys0
->yyresolved
&& yys0
->yysemantics
.yyfirstVal
!= YY_NULL
)
1200 yys1
->yysemantics
.yyfirstVal
=
1201 YYRELOC (yyp0
, yyp1
, yys0
->yysemantics
.yyfirstVal
, yyoption
);
1205 yySemanticOption
* yyv0
= &yyp0
->yyoption
;
1206 yySemanticOption
* yyv1
= &yyp1
->yyoption
;
1207 if (yyv0
->yystate
!= YY_NULL
)
1208 yyv1
->yystate
= YYRELOC (yyp0
, yyp1
, yyv0
->yystate
, yystate
);
1209 if (yyv0
->yynext
!= YY_NULL
)
1210 yyv1
->yynext
= YYRELOC (yyp0
, yyp1
, yyv0
->yynext
, yyoption
);
1213 if (yystackp
->yysplitPoint
!= YY_NULL
)
1214 yystackp
->yysplitPoint
= YYRELOC (yystackp
->yyitems
, yynewItems
,
1215 yystackp
->yysplitPoint
, yystate
);
1217 for (yyn
= 0; yyn
< yystackp
->yytops
.yysize
; yyn
+= 1)
1218 if (yystackp
->yytops
.yystates
[yyn
] != YY_NULL
)
1219 yystackp
->yytops
.yystates
[yyn
] =
1220 YYRELOC (yystackp
->yyitems
, yynewItems
,
1221 yystackp
->yytops
.yystates
[yyn
], yystate
);
1222 YYFREE (yystackp
->yyitems
);
1223 yystackp
->yyitems
= yynewItems
;
1224 yystackp
->yynextFree
= yynewItems
+ yysize
;
1225 yystackp
->yyspaceLeft
= yynewSize
- yysize
;
1230 yyfreeGLRStack (yyGLRStack
* yystackp
)
1232 YYFREE (yystackp
->yyitems
);
1233 yyfreeStateSet (&yystackp
->yytops
);
1236 /** Assuming that S is a GLRState somewhere on STACK, update the
1237 * splitpoint of STACK, if needed, so that it is at least as deep as
1240 yyupdateSplit (yyGLRStack
* yystackp
, yyGLRState
* yys
)
1242 if (yystackp
->yysplitPoint
!= YY_NULL
&& yystackp
->yysplitPoint
> yys
)
1243 yystackp
->yysplitPoint
= yys
;
1246 /** Invalidate stack #K in STACK. */
1248 yymarkStackDeleted (yyGLRStack
* yystackp
, size_t yyk
)
1250 if (yystackp
->yytops
.yystates
[yyk
] != YY_NULL
)
1251 yystackp
->yylastDeleted
= yystackp
->yytops
.yystates
[yyk
];
1252 yystackp
->yytops
.yystates
[yyk
] = YY_NULL
;
1255 /** Undelete the last stack that was marked as deleted. Can only be
1256 done once after a deletion, and only when all other stacks have
1259 yyundeleteLastStack (yyGLRStack
* yystackp
)
1261 if (yystackp
->yylastDeleted
== YY_NULL
|| yystackp
->yytops
.yysize
!= 0)
1263 yystackp
->yytops
.yystates
[0] = yystackp
->yylastDeleted
;
1264 yystackp
->yytops
.yysize
= 1;
1265 YYDPRINTF ((stderr
, "Restoring last deleted stack as stack #0.\n"));
1266 yystackp
->yylastDeleted
= YY_NULL
;
1270 yyremoveDeletes (yyGLRStack
* yystackp
)
1274 while (yyj
< yystackp
->yytops
.yysize
)
1276 if (yystackp
->yytops
.yystates
[yyi
] == YY_NULL
)
1280 YYDPRINTF ((stderr
, "Removing dead stacks.\n"));
1282 yystackp
->yytops
.yysize
-= 1;
1286 yystackp
->yytops
.yystates
[yyj
] = yystackp
->yytops
.yystates
[yyi
];
1287 /* In the current implementation, it's unnecessary to copy
1288 yystackp->yytops.yylookaheadNeeds[yyi] since, after
1289 yyremoveDeletes returns, the parser immediately either enters
1290 deterministic operation or shifts a token. However, it doesn't
1291 hurt, and the code might evolve to need it. */
1292 yystackp
->yytops
.yylookaheadNeeds
[yyj
] =
1293 yystackp
->yytops
.yylookaheadNeeds
[yyi
];
1296 YYDPRINTF ((stderr
, "Rename stack %lu -> %lu.\n",
1297 (unsigned long int) yyi
, (unsigned long int) yyj
));
1305 /** Shift to a new state on stack #K of STACK, corresponding to LR state
1306 * LRSTATE, at input position POSN, with (resolved) semantic value SVAL. */
1308 yyglrShift (yyGLRStack
* yystackp
, size_t yyk
, yyStateNum yylrState
,
1310 YYSTYPE
* yyvalp
]b4_locations_if([, YYLTYPE
* yylocp
])[)
1312 yyGLRState
* yynewState
= &yynewGLRStackItem (yystackp
, yytrue
)->yystate
;
1314 yynewState
->yylrState
= yylrState
;
1315 yynewState
->yyposn
= yyposn
;
1316 yynewState
->yyresolved
= yytrue
;
1317 yynewState
->yypred
= yystackp
->yytops
.yystates
[yyk
];
1318 yynewState
->yysemantics
.yysval
= *yyvalp
;]b4_locations_if([
1319 yynewState
->yyloc
= *yylocp
;])[
1320 yystackp
->yytops
.yystates
[yyk
] = yynewState
;
1322 YY_RESERVE_GLRSTACK (yystackp
);
1325 /** Shift stack #K of YYSTACK, to a new state corresponding to LR
1326 * state YYLRSTATE, at input position YYPOSN, with the (unresolved)
1327 * semantic value of YYRHS under the action for YYRULE. */
1329 yyglrShiftDefer (yyGLRStack
* yystackp
, size_t yyk
, yyStateNum yylrState
,
1330 size_t yyposn
, yyGLRState
* rhs
, yyRuleNum yyrule
)
1332 yyGLRState
* yynewState
= &yynewGLRStackItem (yystackp
, yytrue
)->yystate
;
1334 yynewState
->yylrState
= yylrState
;
1335 yynewState
->yyposn
= yyposn
;
1336 yynewState
->yyresolved
= yyfalse
;
1337 yynewState
->yypred
= yystackp
->yytops
.yystates
[yyk
];
1338 yynewState
->yysemantics
.yyfirstVal
= YY_NULL
;
1339 yystackp
->yytops
.yystates
[yyk
] = yynewState
;
1341 /* Invokes YY_RESERVE_GLRSTACK. */
1342 yyaddDeferredAction (yystackp
, yyk
, yynewState
, rhs
, yyrule
);
1345 /** Pop the symbols consumed by reduction #RULE from the top of stack
1346 * #K of STACK, and perform the appropriate semantic action on their
1347 * semantic values. Assumes that all ambiguities in semantic values
1348 * have been previously resolved. Set *VALP to the resulting value,
1349 * and *LOCP to the computed location (if any). Return value is as
1350 * for userAction. */
1351 static inline YYRESULTTAG
1352 yydoAction (yyGLRStack
* yystackp
, size_t yyk
, yyRuleNum yyrule
,
1353 YYSTYPE
* yyvalp
]b4_locuser_formals
[)
1355 int yynrhs
= yyrhsLength (yyrule
);
1357 if (yystackp
->yysplitPoint
== YY_NULL
)
1359 /* Standard special case: single stack. */
1360 yyGLRStackItem
* rhs
= (yyGLRStackItem
*) yystackp
->yytops
.yystates
[yyk
];
1361 YYASSERT (yyk
== 0);
1362 yystackp
->yynextFree
-= yynrhs
;
1363 yystackp
->yyspaceLeft
+= yynrhs
;
1364 yystackp
->yytops
.yystates
[0] = & yystackp
->yynextFree
[-1].yystate
;
1365 return yyuserAction (yyrule
, yynrhs
, rhs
, yystackp
,
1366 yyvalp
]b4_locuser_args
[);
1370 /* At present, doAction is never called in nondeterministic
1371 * mode, so this branch is never taken. It is here in
1372 * anticipation of a future feature that will allow immediate
1373 * evaluation of selected actions in nondeterministic mode. */
1376 yyGLRStackItem yyrhsVals
[YYMAXRHS
+ YYMAXLEFT
+ 1];
1377 yys
= yyrhsVals
[YYMAXRHS
+ YYMAXLEFT
].yystate
.yypred
1378 = yystackp
->yytops
.yystates
[yyk
];]b4_locations_if([[
1380 /* Set default location. */
1381 yyrhsVals
[YYMAXRHS
+ YYMAXLEFT
- 1].yystate
.yyloc
= yys
->yyloc
;]])[
1382 for (yyi
= 0; yyi
< yynrhs
; yyi
+= 1)
1387 yyupdateSplit (yystackp
, yys
);
1388 yystackp
->yytops
.yystates
[yyk
] = yys
;
1389 return yyuserAction (yyrule
, yynrhs
, yyrhsVals
+ YYMAXRHS
+ YYMAXLEFT
- 1,
1390 yystackp
, yyvalp
]b4_locuser_args
[);
1394 #if !]b4_api_PREFIX[DEBUG
1395 # define YY_REDUCE_PRINT(Args)
1397 # define YY_REDUCE_PRINT(Args) \
1400 yy_reduce_print Args; \
1403 /*----------------------------------------------------------.
1404 | Report that the RULE is going to be reduced on stack #K. |
1405 `----------------------------------------------------------*/
1407 /*ARGSUSED*/ static inline void
1408 yy_reduce_print (yyGLRStack
* yystackp
, size_t yyk
, yyRuleNum yyrule
,
1409 YYSTYPE
* yyvalp
]b4_locuser_formals
[)
1411 int yynrhs
= yyrhsLength (yyrule
);
1412 yybool yynormal
__attribute__ ((__unused__
)) =
1413 (yystackp
->yysplitPoint
== YY_NULL
);
1414 yyGLRStackItem
* yyvsp
= (yyGLRStackItem
*) yystackp
->yytops
.yystates
[yyk
];
1417 YYUSE (yyvalp
);]b4_locations_if([
1419 ]b4_parse_param_use
[]dnl
1420 [ YYFPRINTF (stderr
, "Reducing stack %lu by rule %d (line %lu):\n",
1421 (unsigned long int) yyk
, yyrule
- 1,
1422 (unsigned long int) yyrline
[yyrule
]);
1423 /* The symbols being reduced. */
1424 for (yyi
= 0; yyi
< yynrhs
; yyi
++)
1426 YYFPRINTF (stderr
, " $%d = ", yyi
+ 1);
1427 yy_symbol_print (stderr
, yyrhs
[yyprhs
[yyrule
] + yyi
],
1428 &]b4_rhs_value(yynrhs
, yyi
+ 1)[
1429 ]b4_locations_if([, &]b4_rhs_location(yynrhs
, yyi
+ 1))[]dnl
1431 YYFPRINTF (stderr
, "\n");
1436 /** Pop items off stack #K of STACK according to grammar rule RULE,
1437 * and push back on the resulting nonterminal symbol. Perform the
1438 * semantic action associated with RULE and store its value with the
1439 * newly pushed state, if FORCEEVAL or if STACK is currently
1440 * unambiguous. Otherwise, store the deferred semantic action with
1441 * the new state. If the new state would have an identical input
1442 * position, LR state, and predecessor to an existing state on the stack,
1443 * it is identified with that existing state, eliminating stack #K from
1444 * the STACK. In this case, the (necessarily deferred) semantic value is
1445 * added to the options for the existing state's semantic value.
1447 static inline YYRESULTTAG
1448 yyglrReduce (yyGLRStack
* yystackp
, size_t yyk
, yyRuleNum yyrule
,
1449 yybool yyforceEval
]b4_user_formals
[)
1451 size_t yyposn
= yystackp
->yytops
.yystates
[yyk
]->yyposn
;
1453 if (yyforceEval
|| yystackp
->yysplitPoint
== YY_NULL
)
1455 YYSTYPE yysval
;]b4_locations_if([
1458 YY_REDUCE_PRINT ((yystackp
, yyk
, yyrule
, &yysval
]b4_locuser_args([&yyloc
])[));
1459 YYCHK (yydoAction (yystackp
, yyk
, yyrule
, &yysval
]b4_locuser_args([&yyloc
])[));
1460 YY_SYMBOL_PRINT ("-> $$ =", yyr1
[yyrule
], &yysval
, &yyloc
);
1461 yyglrShift (yystackp
, yyk
,
1462 yyLRgotoState (yystackp
->yytops
.yystates
[yyk
]->yylrState
,
1463 yylhsNonterm (yyrule
)),
1464 yyposn
, &yysval
]b4_locations_if([, &yyloc
])[);
1470 yyGLRState
* yys
, *yys0
= yystackp
->yytops
.yystates
[yyk
];
1471 yyStateNum yynewLRState
;
1473 for (yys
= yystackp
->yytops
.yystates
[yyk
], yyn
= yyrhsLength (yyrule
);
1479 yyupdateSplit (yystackp
, yys
);
1480 yynewLRState
= yyLRgotoState (yys
->yylrState
, yylhsNonterm (yyrule
));
1482 "Reduced stack %lu by rule #%d; action deferred. Now in state %d.\n",
1483 (unsigned long int) yyk
, yyrule
- 1, yynewLRState
));
1484 for (yyi
= 0; yyi
< yystackp
->yytops
.yysize
; yyi
+= 1)
1485 if (yyi
!= yyk
&& yystackp
->yytops
.yystates
[yyi
] != YY_NULL
)
1487 yyGLRState
*yysplit
= yystackp
->yysplitPoint
;
1488 yyGLRState
*yyp
= yystackp
->yytops
.yystates
[yyi
];
1489 while (yyp
!= yys
&& yyp
!= yysplit
&& yyp
->yyposn
>= yyposn
)
1491 if (yyp
->yylrState
== yynewLRState
&& yyp
->yypred
== yys
)
1493 yyaddDeferredAction (yystackp
, yyk
, yyp
, yys0
, yyrule
);
1494 yymarkStackDeleted (yystackp
, yyk
);
1495 YYDPRINTF ((stderr
, "Merging stack %lu into stack %lu.\n",
1496 (unsigned long int) yyk
,
1497 (unsigned long int) yyi
));
1503 yystackp
->yytops
.yystates
[yyk
] = yys
;
1504 yyglrShiftDefer (yystackp
, yyk
, yynewLRState
, yyposn
, yys0
, yyrule
);
1510 yysplitStack (yyGLRStack
* yystackp
, size_t yyk
)
1512 if (yystackp
->yysplitPoint
== YY_NULL
)
1514 YYASSERT (yyk
== 0);
1515 yystackp
->yysplitPoint
= yystackp
->yytops
.yystates
[yyk
];
1517 if (yystackp
->yytops
.yysize
>= yystackp
->yytops
.yycapacity
)
1519 yyGLRState
** yynewStates
;
1520 yybool
* yynewLookaheadNeeds
;
1522 yynewStates
= YY_NULL
;
1524 if (yystackp
->yytops
.yycapacity
1525 > (YYSIZEMAX
/ (2 * sizeof yynewStates
[0])))
1526 yyMemoryExhausted (yystackp
);
1527 yystackp
->yytops
.yycapacity
*= 2;
1530 (yyGLRState
**) YYREALLOC (yystackp
->yytops
.yystates
,
1531 (yystackp
->yytops
.yycapacity
1532 * sizeof yynewStates
[0]));
1533 if (yynewStates
== YY_NULL
)
1534 yyMemoryExhausted (yystackp
);
1535 yystackp
->yytops
.yystates
= yynewStates
;
1537 yynewLookaheadNeeds
=
1538 (yybool
*) YYREALLOC (yystackp
->yytops
.yylookaheadNeeds
,
1539 (yystackp
->yytops
.yycapacity
1540 * sizeof yynewLookaheadNeeds
[0]));
1541 if (yynewLookaheadNeeds
== YY_NULL
)
1542 yyMemoryExhausted (yystackp
);
1543 yystackp
->yytops
.yylookaheadNeeds
= yynewLookaheadNeeds
;
1545 yystackp
->yytops
.yystates
[yystackp
->yytops
.yysize
]
1546 = yystackp
->yytops
.yystates
[yyk
];
1547 yystackp
->yytops
.yylookaheadNeeds
[yystackp
->yytops
.yysize
]
1548 = yystackp
->yytops
.yylookaheadNeeds
[yyk
];
1549 yystackp
->yytops
.yysize
+= 1;
1550 return yystackp
->yytops
.yysize
-1;
1553 /** True iff Y0 and Y1 represent identical options at the top level.
1554 * That is, they represent the same rule applied to RHS symbols
1555 * that produce the same terminal symbols. */
1557 yyidenticalOptions (yySemanticOption
* yyy0
, yySemanticOption
* yyy1
)
1559 if (yyy0
->yyrule
== yyy1
->yyrule
)
1561 yyGLRState
*yys0
, *yys1
;
1563 for (yys0
= yyy0
->yystate
, yys1
= yyy1
->yystate
,
1564 yyn
= yyrhsLength (yyy0
->yyrule
);
1566 yys0
= yys0
->yypred
, yys1
= yys1
->yypred
, yyn
-= 1)
1567 if (yys0
->yyposn
!= yys1
->yyposn
)
1575 /** Assuming identicalOptions (Y0,Y1), destructively merge the
1576 * alternative semantic values for the RHS-symbols of Y1 and Y0. */
1578 yymergeOptionSets (yySemanticOption
* yyy0
, yySemanticOption
* yyy1
)
1580 yyGLRState
*yys0
, *yys1
;
1582 for (yys0
= yyy0
->yystate
, yys1
= yyy1
->yystate
,
1583 yyn
= yyrhsLength (yyy0
->yyrule
);
1585 yys0
= yys0
->yypred
, yys1
= yys1
->yypred
, yyn
-= 1)
1589 else if (yys0
->yyresolved
)
1591 yys1
->yyresolved
= yytrue
;
1592 yys1
->yysemantics
.yysval
= yys0
->yysemantics
.yysval
;
1594 else if (yys1
->yyresolved
)
1596 yys0
->yyresolved
= yytrue
;
1597 yys0
->yysemantics
.yysval
= yys1
->yysemantics
.yysval
;
1601 yySemanticOption
** yyz0p
= &yys0
->yysemantics
.yyfirstVal
;
1602 yySemanticOption
* yyz1
= yys1
->yysemantics
.yyfirstVal
;
1603 while (YYID (yytrue
))
1605 if (yyz1
== *yyz0p
|| yyz1
== YY_NULL
)
1607 else if (*yyz0p
== YY_NULL
)
1612 else if (*yyz0p
< yyz1
)
1614 yySemanticOption
* yyz
= *yyz0p
;
1616 yyz1
= yyz1
->yynext
;
1617 (*yyz0p
)->yynext
= yyz
;
1619 yyz0p
= &(*yyz0p
)->yynext
;
1621 yys1
->yysemantics
.yyfirstVal
= yys0
->yysemantics
.yyfirstVal
;
1626 /** Y0 and Y1 represent two possible actions to take in a given
1627 * parsing state; return 0 if no combination is possible,
1628 * 1 if user-mergeable, 2 if Y0 is preferred, 3 if Y1 is preferred. */
1630 yypreference (yySemanticOption
* y0
, yySemanticOption
* y1
)
1632 yyRuleNum r0
= y0
->yyrule
, r1
= y1
->yyrule
;
1633 int p0
= yydprec
[r0
], p1
= yydprec
[r1
];
1637 if (yymerger
[r0
] == 0 || yymerger
[r0
] != yymerger
[r1
])
1642 if (p0
== 0 || p1
== 0)
1651 static YYRESULTTAG
yyresolveValue (yyGLRState
* yys
,
1652 yyGLRStack
* yystackp
]b4_user_formals
[);
1655 /** Resolve the previous N states starting at and including state S. If result
1656 * != yyok, some states may have been left unresolved possibly with empty
1657 * semantic option chains. Regardless of whether result = yyok, each state
1658 * has been left with consistent data so that yydestroyGLRState can be invoked
1661 yyresolveStates (yyGLRState
* yys
, int yyn
,
1662 yyGLRStack
* yystackp
]b4_user_formals
[)
1666 YYASSERT (yys
->yypred
);
1667 YYCHK (yyresolveStates (yys
->yypred
, yyn
-1, yystackp
]b4_user_args
[));
1668 if (! yys
->yyresolved
)
1669 YYCHK (yyresolveValue (yys
, yystackp
]b4_user_args
[));
1674 /** Resolve the states for the RHS of OPT, perform its user action, and return
1675 * the semantic value and location. Regardless of whether result = yyok, all
1676 * RHS states have been destroyed (assuming the user action destroys all RHS
1677 * semantic values if invoked). */
1679 yyresolveAction (yySemanticOption
* yyopt
, yyGLRStack
* yystackp
,
1680 YYSTYPE
* yyvalp
]b4_locuser_formals
[)
1682 yyGLRStackItem yyrhsVals
[YYMAXRHS
+ YYMAXLEFT
+ 1];
1683 int yynrhs
= yyrhsLength (yyopt
->yyrule
);
1684 YYRESULTTAG yyflag
=
1685 yyresolveStates (yyopt
->yystate
, yynrhs
, yystackp
]b4_user_args
[);
1689 for (yys
= yyopt
->yystate
; yynrhs
> 0; yys
= yys
->yypred
, yynrhs
-= 1)
1690 yydestroyGLRState ("Cleanup: popping", yys
]b4_user_args
[);
1694 yyrhsVals
[YYMAXRHS
+ YYMAXLEFT
].yystate
.yypred
= yyopt
->yystate
;]b4_locations_if([[
1696 /* Set default location. */
1697 yyrhsVals
[YYMAXRHS
+ YYMAXLEFT
- 1].yystate
.yyloc
= yyopt
->yystate
->yyloc
;]])[
1699 int yychar_current
= yychar
;
1700 YYSTYPE yylval_current
= yylval
;]b4_locations_if([
1701 YYLTYPE yylloc_current
= yylloc
;])[
1702 yychar
= yyopt
->yyrawchar
;
1703 yylval
= yyopt
->yyval
;]b4_locations_if([
1704 yylloc
= yyopt
->yyloc
;])[
1705 yyflag
= yyuserAction (yyopt
->yyrule
, yynrhs
,
1706 yyrhsVals
+ YYMAXRHS
+ YYMAXLEFT
- 1,
1707 yystackp
, yyvalp
]b4_locuser_args
[);
1708 yychar
= yychar_current
;
1709 yylval
= yylval_current
;]b4_locations_if([
1710 yylloc
= yylloc_current
;])[
1715 #if ]b4_api_PREFIX[DEBUG
1717 yyreportTree (yySemanticOption
* yyx
, int yyindent
)
1719 int yynrhs
= yyrhsLength (yyx
->yyrule
);
1722 yyGLRState
* yystates
[1 + YYMAXRHS
];
1723 yyGLRState yyleftmost_state
;
1725 for (yyi
= yynrhs
, yys
= yyx
->yystate
; 0 < yyi
; yyi
-= 1, yys
= yys
->yypred
)
1726 yystates
[yyi
] = yys
;
1729 yyleftmost_state
.yyposn
= 0;
1730 yystates
[0] = &yyleftmost_state
;
1735 if (yyx
->yystate
->yyposn
< yys
->yyposn
+ 1)
1736 YYFPRINTF (stderr
, "%*s%s -> <Rule %d, empty>\n",
1737 yyindent
, "", yytokenName (yylhsNonterm (yyx
->yyrule
)),
1740 YYFPRINTF (stderr
, "%*s%s -> <Rule %d, tokens %lu .. %lu>\n",
1741 yyindent
, "", yytokenName (yylhsNonterm (yyx
->yyrule
)),
1742 yyx
->yyrule
- 1, (unsigned long int) (yys
->yyposn
+ 1),
1743 (unsigned long int) yyx
->yystate
->yyposn
);
1744 for (yyi
= 1; yyi
<= yynrhs
; yyi
+= 1)
1746 if (yystates
[yyi
]->yyresolved
)
1748 if (yystates
[yyi
-1]->yyposn
+1 > yystates
[yyi
]->yyposn
)
1749 YYFPRINTF (stderr
, "%*s%s <empty>\n", yyindent
+2, "",
1750 yytokenName (yyrhs
[yyprhs
[yyx
->yyrule
]+yyi
-1]));
1752 YYFPRINTF (stderr
, "%*s%s <tokens %lu .. %lu>\n", yyindent
+2, "",
1753 yytokenName (yyrhs
[yyprhs
[yyx
->yyrule
]+yyi
-1]),
1754 (unsigned long int) (yystates
[yyi
- 1]->yyposn
+ 1),
1755 (unsigned long int) yystates
[yyi
]->yyposn
);
1758 yyreportTree (yystates
[yyi
]->yysemantics
.yyfirstVal
, yyindent
+2);
1763 /*ARGSUSED*/ static YYRESULTTAG
1764 yyreportAmbiguity (yySemanticOption
* yyx0
,
1765 yySemanticOption
* yyx1
]b4_pure_formals
[)
1770 #if ]b4_api_PREFIX[DEBUG
1771 YYFPRINTF (stderr
, "Ambiguity detected.\n");
1772 YYFPRINTF (stderr
, "Option 1,\n");
1773 yyreportTree (yyx0
, 2);
1774 YYFPRINTF (stderr
, "\nOption 2,\n");
1775 yyreportTree (yyx1
, 2);
1776 YYFPRINTF (stderr
, "\n");
1779 yyerror (]b4_yyerror_args
[YY_("syntax is ambiguous"));
1781 }]b4_locations_if([[
1783 /** Starting at and including state S1, resolve the location for each of the
1784 * previous N1 states that is unresolved. The first semantic option of a state
1785 * is always chosen. */
1787 yyresolveLocations (yyGLRState
* yys1
, int yyn1
,
1788 yyGLRStack
*yystackp
]b4_user_formals
[)
1792 yyresolveLocations (yys1
->yypred
, yyn1
- 1, yystackp
]b4_user_args
[);
1793 if (!yys1
->yyresolved
)
1795 yyGLRStackItem yyrhsloc
[1 + YYMAXRHS
];
1797 yySemanticOption
*yyoption
= yys1
->yysemantics
.yyfirstVal
;
1798 YYASSERT (yyoption
!= YY_NULL
);
1799 yynrhs
= yyrhsLength (yyoption
->yyrule
);
1804 yyresolveLocations (yyoption
->yystate
, yynrhs
,
1805 yystackp
]b4_user_args
[);
1806 for (yys
= yyoption
->yystate
, yyn
= yynrhs
;
1808 yys
= yys
->yypred
, yyn
-= 1)
1809 yyrhsloc
[yyn
].yystate
.yyloc
= yys
->yyloc
;
1813 /* Both yyresolveAction and yyresolveLocations traverse the GSS
1814 in reverse rightmost order. It is only necessary to invoke
1815 yyresolveLocations on a subforest for which yyresolveAction
1816 would have been invoked next had an ambiguity not been
1817 detected. Thus the location of the previous state (but not
1818 necessarily the previous state itself) is guaranteed to be
1819 resolved already. */
1820 yyGLRState
*yyprevious
= yyoption
->yystate
;
1821 yyrhsloc
[0].yystate
.yyloc
= yyprevious
->yyloc
;
1824 int yychar_current
= yychar
;
1825 YYSTYPE yylval_current
= yylval
;
1826 YYLTYPE yylloc_current
= yylloc
;
1827 yychar
= yyoption
->yyrawchar
;
1828 yylval
= yyoption
->yyval
;
1829 yylloc
= yyoption
->yyloc
;
1830 YYLLOC_DEFAULT ((yys1
->yyloc
), yyrhsloc
, yynrhs
);
1831 yychar
= yychar_current
;
1832 yylval
= yylval_current
;
1833 yylloc
= yylloc_current
;
1839 /** Resolve the ambiguity represented in state S, perform the indicated
1840 * actions, and set the semantic value of S. If result != yyok, the chain of
1841 * semantic options in S has been cleared instead or it has been left
1842 * unmodified except that redundant options may have been removed. Regardless
1843 * of whether result = yyok, S has been left with consistent data so that
1844 * yydestroyGLRState can be invoked if necessary. */
1846 yyresolveValue (yyGLRState
* yys
, yyGLRStack
* yystackp
]b4_user_formals
[)
1848 yySemanticOption
* yyoptionList
= yys
->yysemantics
.yyfirstVal
;
1849 yySemanticOption
* yybest
= yyoptionList
;
1850 yySemanticOption
** yypp
;
1851 yybool yymerge
= yyfalse
;
1853 YYRESULTTAG yyflag
;]b4_locations_if([
1854 YYLTYPE
*yylocp
= &yys
->yyloc
;])[
1856 for (yypp
= &yyoptionList
->yynext
; *yypp
!= YY_NULL
; )
1858 yySemanticOption
* yyp
= *yypp
;
1860 if (yyidenticalOptions (yybest
, yyp
))
1862 yymergeOptionSets (yybest
, yyp
);
1863 *yypp
= yyp
->yynext
;
1867 switch (yypreference (yybest
, yyp
))
1869 case 0:]b4_locations_if([[
1870 yyresolveLocations (yys
, 1, yystackp
]b4_user_args
[);]])[
1871 return yyreportAmbiguity (yybest
, yyp
]b4_pure_args
[);
1883 /* This cannot happen so it is not worth a YYASSERT (yyfalse),
1884 but some compilers complain if the default case is
1888 yypp
= &yyp
->yynext
;
1894 yySemanticOption
* yyp
;
1895 int yyprec
= yydprec
[yybest
->yyrule
];
1896 yyflag
= yyresolveAction (yybest
, yystackp
, &yysval
]b4_locuser_args
[);
1898 for (yyp
= yybest
->yynext
; yyp
!= YY_NULL
; yyp
= yyp
->yynext
)
1900 if (yyprec
== yydprec
[yyp
->yyrule
])
1902 YYSTYPE yysval_other
;]b4_locations_if([
1904 yyflag
= yyresolveAction (yyp
, yystackp
, &yysval_other
]b4_locuser_args([&yydummy
])[);
1907 yydestruct ("Cleanup: discarding incompletely merged value for",
1908 yystos
[yys
->yylrState
],
1909 &yysval
]b4_locuser_args
[);
1912 yyuserMerge (yymerger
[yyp
->yyrule
], &yysval
, &yysval_other
);
1917 yyflag
= yyresolveAction (yybest
, yystackp
, &yysval
]b4_locuser_args([yylocp
])[);
1921 yys
->yyresolved
= yytrue
;
1922 yys
->yysemantics
.yysval
= yysval
;
1925 yys
->yysemantics
.yyfirstVal
= YY_NULL
;
1930 yyresolveStack (yyGLRStack
* yystackp
]b4_user_formals
[)
1932 if (yystackp
->yysplitPoint
!= YY_NULL
)
1937 for (yyn
= 0, yys
= yystackp
->yytops
.yystates
[0];
1938 yys
!= yystackp
->yysplitPoint
;
1939 yys
= yys
->yypred
, yyn
+= 1)
1941 YYCHK (yyresolveStates (yystackp
->yytops
.yystates
[0], yyn
, yystackp
1948 yycompressStack (yyGLRStack
* yystackp
)
1950 yyGLRState
* yyp
, *yyq
, *yyr
;
1952 if (yystackp
->yytops
.yysize
!= 1 || yystackp
->yysplitPoint
== YY_NULL
)
1955 for (yyp
= yystackp
->yytops
.yystates
[0], yyq
= yyp
->yypred
, yyr
= YY_NULL
;
1956 yyp
!= yystackp
->yysplitPoint
;
1957 yyr
= yyp
, yyp
= yyq
, yyq
= yyp
->yypred
)
1960 yystackp
->yyspaceLeft
+= yystackp
->yynextFree
- yystackp
->yyitems
;
1961 yystackp
->yynextFree
= ((yyGLRStackItem
*) yystackp
->yysplitPoint
) + 1;
1962 yystackp
->yyspaceLeft
-= yystackp
->yynextFree
- yystackp
->yyitems
;
1963 yystackp
->yysplitPoint
= YY_NULL
;
1964 yystackp
->yylastDeleted
= YY_NULL
;
1966 while (yyr
!= YY_NULL
)
1968 yystackp
->yynextFree
->yystate
= *yyr
;
1970 yystackp
->yynextFree
->yystate
.yypred
= &yystackp
->yynextFree
[-1].yystate
;
1971 yystackp
->yytops
.yystates
[0] = &yystackp
->yynextFree
->yystate
;
1972 yystackp
->yynextFree
+= 1;
1973 yystackp
->yyspaceLeft
-= 1;
1978 yyprocessOneStack (yyGLRStack
* yystackp
, size_t yyk
,
1979 size_t yyposn
]b4_pure_formals
[)
1982 const short int* yyconflicts
;
1985 while (yystackp
->yytops
.yystates
[yyk
] != YY_NULL
)
1987 yyStateNum yystate
= yystackp
->yytops
.yystates
[yyk
]->yylrState
;
1988 YYDPRINTF ((stderr
, "Stack %lu Entering state %d\n",
1989 (unsigned long int) yyk
, yystate
));
1991 YYASSERT (yystate
!= YYFINAL
);
1993 if (yyisDefaultedState (yystate
))
1995 yyrule
= yydefaultAction (yystate
);
1998 YYDPRINTF ((stderr
, "Stack %lu dies.\n",
1999 (unsigned long int) yyk
));
2000 yymarkStackDeleted (yystackp
, yyk
);
2003 YYCHK (yyglrReduce (yystackp
, yyk
, yyrule
, yyfalse
]b4_user_args
[));
2008 yystackp
->yytops
.yylookaheadNeeds
[yyk
] = yytrue
;
2009 if (yychar
== YYEMPTY
)
2011 YYDPRINTF ((stderr
, "Reading a token: "));
2015 if (yychar
<= YYEOF
)
2017 yychar
= yytoken
= YYEOF
;
2018 YYDPRINTF ((stderr
, "Now at end of input.\n"));
2022 yytoken
= YYTRANSLATE (yychar
);
2023 YY_SYMBOL_PRINT ("Next token is", yytoken
, &yylval
, &yylloc
);
2026 yygetLRActions (yystate
, yytoken
, &yyaction
, &yyconflicts
);
2028 while (*yyconflicts
!= 0)
2030 size_t yynewStack
= yysplitStack (yystackp
, yyk
);
2031 YYDPRINTF ((stderr
, "Splitting off stack %lu from %lu.\n",
2032 (unsigned long int) yynewStack
,
2033 (unsigned long int) yyk
));
2034 YYCHK (yyglrReduce (yystackp
, yynewStack
,
2035 *yyconflicts
, yyfalse
]b4_user_args
[));
2036 YYCHK (yyprocessOneStack (yystackp
, yynewStack
,
2037 yyposn
]b4_pure_args
[));
2041 if (yyisShiftAction (yyaction
))
2043 else if (yyisErrorAction (yyaction
))
2045 YYDPRINTF ((stderr
, "Stack %lu dies.\n",
2046 (unsigned long int) yyk
));
2047 yymarkStackDeleted (yystackp
, yyk
);
2051 YYCHK (yyglrReduce (yystackp
, yyk
, -yyaction
,
2052 yyfalse
]b4_user_args
[));
2058 /*ARGSUSED*/ static void
2059 yyreportSyntaxError (yyGLRStack
* yystackp
]b4_user_formals
[)
2061 if (yystackp
->yyerrState
!= 0)
2063 #if ! YYERROR_VERBOSE
2064 yyerror (]b4_lyyerror_args
[YY_("syntax error"));
2066 yySymbol yytoken
= yychar
== YYEMPTY
? YYEMPTY
: YYTRANSLATE (yychar
);
2067 size_t yysize0
= yytnamerr (YY_NULL
, yytokenName (yytoken
));
2068 size_t yysize
= yysize0
;
2070 yybool yysize_overflow
= yyfalse
;
2071 char* yymsg
= YY_NULL
;
2072 enum { YYERROR_VERBOSE_ARGS_MAXIMUM
= 5 };
2073 /* Internationalized format string. */
2074 const char *yyformat
= YY_NULL
;
2075 /* Arguments of yyformat. */
2076 char const *yyarg
[YYERROR_VERBOSE_ARGS_MAXIMUM
];
2077 /* Number of reported tokens (one for the "unexpected", one per
2081 /* There are many possibilities here to consider:
2082 - If this state is a consistent state with a default action, then
2083 the only way this function was invoked is if the default action
2084 is an error action. In that case, don't check for expected
2085 tokens because there are none.
2086 - The only way there can be no lookahead present (in yychar) is if
2087 this state is a consistent state with a default action. Thus,
2088 detecting the absence of a lookahead is sufficient to determine
2089 that there is no unexpected or expected token to report. In that
2090 case, just report a simple "syntax error".
2091 - Don't assume there isn't a lookahead just because this state is a
2092 consistent state with a default action. There might have been a
2093 previous inconsistent state, consistent state with a non-default
2094 action, or user semantic action that manipulated yychar.
2095 - Of course, the expected token list depends on states to have
2096 correct lookahead information, and it depends on the parser not
2097 to perform extra reductions after fetching a lookahead from the
2098 scanner and before detecting a syntax error. Thus, state merging
2099 (from LALR or IELR) and default reductions corrupt the expected
2100 token list. However, the list is correct for canonical LR with
2101 one exception: it will still contain any token that will not be
2102 accepted due to an error action in a later state.
2104 if (yytoken
!= YYEMPTY
)
2106 int yyn
= yypact
[yystackp
->yytops
.yystates
[0]->yylrState
];
2107 yyarg
[yycount
++] = yytokenName (yytoken
);
2108 if (!yypact_value_is_default (yyn
))
2110 /* Start YYX at -YYN if negative to avoid negative indexes in
2111 YYCHECK. In other words, skip the first -YYN actions for this
2112 state because they are default actions. */
2113 int yyxbegin
= yyn
< 0 ? -yyn
: 0;
2114 /* Stay within bounds of both yycheck and yytname. */
2115 int yychecklim
= YYLAST
- yyn
+ 1;
2116 int yyxend
= yychecklim
< YYNTOKENS
? yychecklim
: YYNTOKENS
;
2118 for (yyx
= yyxbegin
; yyx
< yyxend
; ++yyx
)
2119 if (yycheck
[yyx
+ yyn
] == yyx
&& yyx
!= YYTERROR
2120 && !yytable_value_is_error (yytable
[yyx
+ yyn
]))
2122 if (yycount
== YYERROR_VERBOSE_ARGS_MAXIMUM
)
2128 yyarg
[yycount
++] = yytokenName (yyx
);
2129 yysize1
= yysize
+ yytnamerr (YY_NULL
, yytokenName (yyx
));
2130 yysize_overflow
|= yysize1
< yysize
;
2138 #define YYCASE_(N, S) \
2142 YYCASE_(0, YY_("syntax error"));
2143 YYCASE_(1, YY_("syntax error, unexpected %s"));
2144 YYCASE_(2, YY_("syntax error, unexpected %s, expecting %s"));
2145 YYCASE_(3, YY_("syntax error, unexpected %s, expecting %s or %s"));
2146 YYCASE_(4, YY_("syntax error, unexpected %s, expecting %s or %s or %s"));
2147 YYCASE_(5, YY_("syntax error, unexpected %s, expecting %s or %s or %s or %s"));
2151 yysize1
= yysize
+ strlen (yyformat
);
2152 yysize_overflow
|= yysize1
< yysize
;
2155 if (!yysize_overflow
)
2156 yymsg
= (char *) YYMALLOC (yysize
);
2162 while ((*yyp
= *yyformat
))
2164 if (*yyp
== '%' && yyformat
[1] == 's' && yyi
< yycount
)
2166 yyp
+= yytnamerr (yyp
, yyarg
[yyi
++]);
2175 yyerror (]b4_lyyerror_args
[yymsg
);
2180 yyerror (]b4_lyyerror_args
[YY_("syntax error"));
2181 yyMemoryExhausted (yystackp
);
2183 #endif /* YYERROR_VERBOSE */
2187 /* Recover from a syntax error on *YYSTACKP, assuming that *YYSTACKP->YYTOKENP,
2188 yylval, and yylloc are the syntactic category, semantic value, and location
2189 of the lookahead. */
2190 /*ARGSUSED*/ static void
2191 yyrecoverSyntaxError (yyGLRStack
* yystackp
]b4_user_formals
[)
2196 if (yystackp
->yyerrState
== 3)
2197 /* We just shifted the error token and (perhaps) took some
2198 reductions. Skip tokens until we can proceed. */
2199 while (YYID (yytrue
))
2202 if (yychar
== YYEOF
)
2203 yyFail (yystackp
][]b4_lpure_args
[, YY_NULL
);
2204 if (yychar
!= YYEMPTY
)
2205 {]b4_locations_if([[
2206 /* We throw away the lookahead, but the error range
2207 of the shifted error token must take it into account. */
2208 yyGLRState
*yys
= yystackp
->yytops
.yystates
[0];
2209 yyGLRStackItem yyerror_range
[3];
2210 yyerror_range
[1].yystate
.yyloc
= yys
->yyloc
;
2211 yyerror_range
[2].yystate
.yyloc
= yylloc
;
2212 YYLLOC_DEFAULT ((yys
->yyloc
), yyerror_range
, 2);]])[
2213 yytoken
= YYTRANSLATE (yychar
);
2214 yydestruct ("Error: discarding",
2215 yytoken
, &yylval
]b4_locuser_args([&yylloc
])[);
2217 YYDPRINTF ((stderr
, "Reading a token: "));
2219 if (yychar
<= YYEOF
)
2221 yychar
= yytoken
= YYEOF
;
2222 YYDPRINTF ((stderr
, "Now at end of input.\n"));
2226 yytoken
= YYTRANSLATE (yychar
);
2227 YY_SYMBOL_PRINT ("Next token is", yytoken
, &yylval
, &yylloc
);
2229 yyj
= yypact
[yystackp
->yytops
.yystates
[0]->yylrState
];
2230 if (yypact_value_is_default (yyj
))
2233 if (yyj
< 0 || YYLAST
< yyj
|| yycheck
[yyj
] != yytoken
)
2235 if (yydefact
[yystackp
->yytops
.yystates
[0]->yylrState
] != 0)
2238 else if (! yytable_value_is_error (yytable
[yyj
]))
2242 /* Reduce to one stack. */
2243 for (yyk
= 0; yyk
< yystackp
->yytops
.yysize
; yyk
+= 1)
2244 if (yystackp
->yytops
.yystates
[yyk
] != YY_NULL
)
2246 if (yyk
>= yystackp
->yytops
.yysize
)
2247 yyFail (yystackp
][]b4_lpure_args
[, YY_NULL
);
2248 for (yyk
+= 1; yyk
< yystackp
->yytops
.yysize
; yyk
+= 1)
2249 yymarkStackDeleted (yystackp
, yyk
);
2250 yyremoveDeletes (yystackp
);
2251 yycompressStack (yystackp
);
2253 /* Now pop stack until we find a state that shifts the error token. */
2254 yystackp
->yyerrState
= 3;
2255 while (yystackp
->yytops
.yystates
[0] != YY_NULL
)
2257 yyGLRState
*yys
= yystackp
->yytops
.yystates
[0];
2258 yyj
= yypact
[yys
->yylrState
];
2259 if (! yypact_value_is_default (yyj
))
2262 if (0 <= yyj
&& yyj
<= YYLAST
&& yycheck
[yyj
] == YYTERROR
2263 && yyisShiftAction (yytable
[yyj
]))
2265 /* Shift the error token. */]b4_locations_if([[
2266 /* First adjust its location.*/
2268 yystackp
->yyerror_range
[2].yystate
.yyloc
= yylloc
;
2269 YYLLOC_DEFAULT (yyerrloc
, (yystackp
->yyerror_range
), 2);]])[
2270 YY_SYMBOL_PRINT ("Shifting", yystos
[yytable
[yyj
]],
2271 &yylval
, &yyerrloc
);
2272 yyglrShift (yystackp
, 0, yytable
[yyj
],
2273 yys
->yyposn
, &yylval
]b4_locations_if([, &yyerrloc
])[);
2274 yys
= yystackp
->yytops
.yystates
[0];
2277 }]b4_locations_if([[
2278 yystackp
->yyerror_range
[1].yystate
.yyloc
= yys
->yyloc
;]])[
2279 if (yys
->yypred
!= YY_NULL
)
2280 yydestroyGLRState ("Error: popping", yys
]b4_user_args
[);
2281 yystackp
->yytops
.yystates
[0] = yys
->yypred
;
2282 yystackp
->yynextFree
-= 1;
2283 yystackp
->yyspaceLeft
+= 1;
2285 if (yystackp
->yytops
.yystates
[0] == YY_NULL
)
2286 yyFail (yystackp
][]b4_lpure_args
[, YY_NULL
);
2289 #define YYCHK1(YYE) \
2299 goto yyuser_error; \
2310 ]b4_c_ansi_function_def([yyparse
], [int], b4_parse_param
)[
2314 yyGLRStack
* const yystackp
= &yystack
;
2317 YYDPRINTF ((stderr
, "Starting parse\n"));
2320 yylval
= yyval_default
;
2322 #if defined YYLTYPE_IS_TRIVIAL && YYLTYPE_IS_TRIVIAL
2323 yylloc
.first_line
= yylloc
.last_line
= ]b4_location_initial_line
[;
2324 yylloc
.first_column
= yylloc
.last_column
= ]b4_location_initial_column
[;
2327 m4_ifdef([b4_initial_action
], [
2328 m4_pushdef([b4_at_dollar
], [yylloc
])dnl
2329 m4_pushdef([b4_dollar_dollar
], [yylval
])dnl
2330 /* User initialization code. */
2331 b4_user_initial_action
2332 m4_popdef([b4_dollar_dollar
])dnl
2333 m4_popdef([b4_at_dollar
])])dnl
2335 if (! yyinitGLRStack (yystackp
, YYINITDEPTH
))
2336 goto yyexhaustedlab
;
2337 switch (YYSETJMP (yystack
.yyexception_buffer
))
2340 case 1: goto yyabortlab
;
2341 case 2: goto yyexhaustedlab
;
2342 default: goto yybuglab
;
2344 yyglrShift (&yystack
, 0, 0, 0, &yylval
]b4_locations_if([, &yylloc
])[);
2347 while (YYID (yytrue
))
2349 /* For efficiency, we have two loops, the first of which is
2350 specialized to deterministic operation (single stack, no
2351 potential ambiguity). */
2353 while (YYID (yytrue
))
2357 const short int* yyconflicts
;
2359 yyStateNum yystate
= yystack
.yytops
.yystates
[0]->yylrState
;
2360 YYDPRINTF ((stderr
, "Entering state %d\n", yystate
));
2361 if (yystate
== YYFINAL
)
2363 if (yyisDefaultedState (yystate
))
2365 yyrule
= yydefaultAction (yystate
);
2368 ]b4_locations_if([[ yystack
.yyerror_range
[1].yystate
.yyloc
= yylloc
;]])[
2369 yyreportSyntaxError (&yystack
]b4_user_args
[);
2372 YYCHK1 (yyglrReduce (&yystack
, 0, yyrule
, yytrue
]b4_user_args
[));
2377 if (yychar
== YYEMPTY
)
2379 YYDPRINTF ((stderr
, "Reading a token: "));
2383 if (yychar
<= YYEOF
)
2385 yychar
= yytoken
= YYEOF
;
2386 YYDPRINTF ((stderr
, "Now at end of input.\n"));
2390 yytoken
= YYTRANSLATE (yychar
);
2391 YY_SYMBOL_PRINT ("Next token is", yytoken
, &yylval
, &yylloc
);
2394 yygetLRActions (yystate
, yytoken
, &yyaction
, &yyconflicts
);
2395 if (*yyconflicts
!= 0)
2397 if (yyisShiftAction (yyaction
))
2399 YY_SYMBOL_PRINT ("Shifting", yytoken
, &yylval
, &yylloc
);
2402 yyglrShift (&yystack
, 0, yyaction
, yyposn
, &yylval
]b4_locations_if([, &yylloc
])[);
2403 if (0 < yystack
.yyerrState
)
2404 yystack
.yyerrState
-= 1;
2406 else if (yyisErrorAction (yyaction
))
2408 ]b4_locations_if([[ yystack
.yyerror_range
[1].yystate
.yyloc
= yylloc
;]])[
2409 yyreportSyntaxError (&yystack
]b4_user_args
[);
2413 YYCHK1 (yyglrReduce (&yystack
, 0, -yyaction
, yytrue
]b4_user_args
[));
2417 while (YYID (yytrue
))
2419 yySymbol yytoken_to_shift
;
2422 for (yys
= 0; yys
< yystack
.yytops
.yysize
; yys
+= 1)
2423 yystackp
->yytops
.yylookaheadNeeds
[yys
] = yychar
!= YYEMPTY
;
2425 /* yyprocessOneStack returns one of three things:
2427 - An error flag. If the caller is yyprocessOneStack, it
2428 immediately returns as well. When the caller is finally
2429 yyparse, it jumps to an error label via YYCHK1.
2431 - yyok, but yyprocessOneStack has invoked yymarkStackDeleted
2432 (&yystack, yys), which sets the top state of yys to NULL. Thus,
2433 yyparse's following invocation of yyremoveDeletes will remove
2436 - yyok, when ready to shift a token.
2438 Except in the first case, yyparse will invoke yyremoveDeletes and
2439 then shift the next token onto all remaining stacks. This
2440 synchronization of the shift (that is, after all preceding
2441 reductions on all stacks) helps prevent double destructor calls
2442 on yylval in the event of memory exhaustion. */
2444 for (yys
= 0; yys
< yystack
.yytops
.yysize
; yys
+= 1)
2445 YYCHK1 (yyprocessOneStack (&yystack
, yys
, yyposn
]b4_lpure_args
[));
2446 yyremoveDeletes (&yystack
);
2447 if (yystack
.yytops
.yysize
== 0)
2449 yyundeleteLastStack (&yystack
);
2450 if (yystack
.yytops
.yysize
== 0)
2451 yyFail (&yystack
][]b4_lpure_args
[, YY_("syntax error"));
2452 YYCHK1 (yyresolveStack (&yystack
]b4_user_args
[));
2453 YYDPRINTF ((stderr
, "Returning to deterministic operation.\n"));
2454 ]b4_locations_if([[ yystack
.yyerror_range
[1].yystate
.yyloc
= yylloc
;]])[
2455 yyreportSyntaxError (&yystack
]b4_user_args
[);
2459 /* If any yyglrShift call fails, it will fail after shifting. Thus,
2460 a copy of yylval will already be on stack 0 in the event of a
2461 failure in the following loop. Thus, yychar is set to YYEMPTY
2462 before the loop to make sure the user destructor for yylval isn't
2464 yytoken_to_shift
= YYTRANSLATE (yychar
);
2467 for (yys
= 0; yys
< yystack
.yytops
.yysize
; yys
+= 1)
2470 const short int* yyconflicts
;
2471 yyStateNum yystate
= yystack
.yytops
.yystates
[yys
]->yylrState
;
2472 yygetLRActions (yystate
, yytoken_to_shift
, &yyaction
,
2474 /* Note that yyconflicts were handled by yyprocessOneStack. */
2475 YYDPRINTF ((stderr
, "On stack %lu, ", (unsigned long int) yys
));
2476 YY_SYMBOL_PRINT ("shifting", yytoken_to_shift
, &yylval
, &yylloc
);
2477 yyglrShift (&yystack
, yys
, yyaction
, yyposn
,
2478 &yylval
]b4_locations_if([, &yylloc
])[);
2479 YYDPRINTF ((stderr
, "Stack %lu now in state #%d\n",
2480 (unsigned long int) yys
,
2481 yystack
.yytops
.yystates
[yys
]->yylrState
));
2484 if (yystack
.yytops
.yysize
== 1)
2486 YYCHK1 (yyresolveStack (&yystack
]b4_user_args
[));
2487 YYDPRINTF ((stderr
, "Returning to deterministic operation.\n"));
2488 yycompressStack (&yystack
);
2494 yyrecoverSyntaxError (&yystack
]b4_user_args
[);
2495 yyposn
= yystack
.yytops
.yystates
[0]->yyposn
;
2511 yyerror (]b4_lyyerror_args
[YY_("memory exhausted"));
2516 if (yychar
!= YYEMPTY
)
2517 yydestruct ("Cleanup: discarding lookahead",
2518 YYTRANSLATE (yychar
), &yylval
]b4_locuser_args([&yylloc
])[);
2520 /* If the stack is well-formed, pop the stack until it is empty,
2521 destroying its entries as we go. But free the stack regardless
2522 of whether it is well-formed. */
2523 if (yystack
.yyitems
)
2525 yyGLRState
** yystates
= yystack
.yytops
.yystates
;
2528 size_t yysize
= yystack
.yytops
.yysize
;
2530 for (yyk
= 0; yyk
< yysize
; yyk
+= 1)
2533 while (yystates
[yyk
])
2535 yyGLRState
*yys
= yystates
[yyk
];
2536 ]b4_locations_if([[ yystack
.yyerror_range
[1].yystate
.yyloc
= yys
->yyloc
;]]
2537 )[ if (yys
->yypred
!= YY_NULL
)
2538 yydestroyGLRState ("Cleanup: popping", yys
]b4_user_args
[);
2539 yystates
[yyk
] = yys
->yypred
;
2540 yystack
.yynextFree
-= 1;
2541 yystack
.yyspaceLeft
+= 1;
2546 yyfreeGLRStack (&yystack
);
2549 /* Make sure YYID is used. */
2550 return YYID (yyresult
);
2553 /* DEBUGGING ONLY */
2554 #if ]b4_api_PREFIX[DEBUG
2555 static void yypstack (yyGLRStack
* yystackp
, size_t yyk
)
2556 __attribute__ ((__unused__
));
2557 static void yypdumpstack (yyGLRStack
* yystackp
) __attribute__ ((__unused__
));
2560 yy_yypstack (yyGLRState
* yys
)
2564 yy_yypstack (yys
->yypred
);
2565 YYFPRINTF (stderr
, " -> ");
2567 YYFPRINTF (stderr
, "%d@@%lu", yys
->yylrState
,
2568 (unsigned long int) yys
->yyposn
);
2572 yypstates (yyGLRState
* yyst
)
2574 if (yyst
== YY_NULL
)
2575 YYFPRINTF (stderr
, "<null>");
2578 YYFPRINTF (stderr
, "\n");
2582 yypstack (yyGLRStack
* yystackp
, size_t yyk
)
2584 yypstates (yystackp
->yytops
.yystates
[yyk
]);
2587 #define YYINDEX(YYX) \
2588 ((YYX) == YY_NULL ? -1 : (yyGLRStackItem*) (YYX) - yystackp->yyitems)
2592 yypdumpstack (yyGLRStack
* yystackp
)
2594 yyGLRStackItem
* yyp
;
2596 for (yyp
= yystackp
->yyitems
; yyp
< yystackp
->yynextFree
; yyp
+= 1)
2598 YYFPRINTF (stderr
, "%3lu. ",
2599 (unsigned long int) (yyp
- yystackp
->yyitems
));
2600 if (*(yybool
*) yyp
)
2602 YYFPRINTF (stderr
, "Res: %d, LR State: %d, posn: %lu, pred: %ld",
2603 yyp
->yystate
.yyresolved
, yyp
->yystate
.yylrState
,
2604 (unsigned long int) yyp
->yystate
.yyposn
,
2605 (long int) YYINDEX (yyp
->yystate
.yypred
));
2606 if (! yyp
->yystate
.yyresolved
)
2607 YYFPRINTF (stderr
, ", firstVal: %ld",
2608 (long int) YYINDEX (yyp
->yystate
2609 .yysemantics
.yyfirstVal
));
2613 YYFPRINTF (stderr
, "Option. rule: %d, state: %ld, next: %ld",
2614 yyp
->yyoption
.yyrule
- 1,
2615 (long int) YYINDEX (yyp
->yyoption
.yystate
),
2616 (long int) YYINDEX (yyp
->yyoption
.yynext
));
2618 YYFPRINTF (stderr
, "\n");
2620 YYFPRINTF (stderr
, "Tops:");
2621 for (yyi
= 0; yyi
< yystackp
->yytops
.yysize
; yyi
+= 1)
2622 YYFPRINTF (stderr
, "%lu: %ld; ", (unsigned long int) yyi
,
2623 (long int) YYINDEX (yystackp
->yytops
.yystates
[yyi
]));
2624 YYFPRINTF (stderr
, "\n");
2631 dnl glr
.cc produces its own header
.
2633 m4_if(b4_skeleton
, ["glr.c"],
2635 [@
output(b4_spec_defines_file@
)@
2636 b4_copyright([Skeleton interface
for Bison GLR parsers in C
],
2639 ]b4_cpp_guard_open([b4_spec_defines_file
])[
2640 ]b4_shared_declarations
[
2641 ]b4_cpp_guard_close([b4_spec_defines_file
])[