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
)])
162 # We do want M4 expansion after # for CPP macros.
165 @
output(b4_parser_file_name@
)@
166 b4_copyright([Skeleton implementation
for Bison GLR parsers in C
],
169 /* C GLR parser skeleton written by Paul Hilfinger. */
173 b4_percent_code_get([[top]])[]dnl
174 m4_if(b4_prefix
, [yy
], [],
175 [/* Substitute the variable and function names. */
176 #define yyparse b4_prefix[]parse
177 #define yylex b4_prefix[]lex
178 #define yyerror b4_prefix[]error
179 #define yylval b4_prefix[]lval
180 #define yychar b4_prefix[]char
181 #define yydebug b4_prefix[]debug
182 #define yynerrs b4_prefix[]nerrs
183 #define yylloc b4_prefix[]lloc])[
185 /* Copy the first part of user declarations. */
186 ]b4_user_pre_prologue
190 dnl
# b4_shared_declarations
191 dnl
# ----------------------
192 dnl
# Declaration that might either go into the header (if --defines)
193 dnl
# or open coded in the parser body.
194 m4_define([b4_shared_declarations
],
195 [b4_percent_code_get([[requires]])[]dnl
197 b4_token_enums(b4_tokens
)
200 ]m4_ifdef([b4_stype
],
201 [[typedef union ]b4_union_name
[
205 # define YYSTYPE_IS_TRIVIAL 1]],
206 [m4_if(b4_tag_seen_flag
, 0,
207 [[typedef int YYSTYPE
;
208 # define YYSTYPE_IS_TRIVIAL 1]])])[
211 #if ! defined YYLTYPE && ! defined YYLTYPE_IS_DECLARED
212 typedef struct YYLTYPE
223 # define YYLTYPE_IS_DECLARED 1
224 # define YYLTYPE_IS_TRIVIAL 1
227 ]b4_percent_code_get([[provides]])[]dnl
230 b4_defines_if([[#include "@basename(]b4_spec_defines_file[@)"]],
231 [b4_shared_declarations
])[
233 /* Enabling traces. */
235 # define YYDEBUG ]b4_debug_flag[
238 /* Enabling verbose error messages. */
239 #ifdef YYERROR_VERBOSE
240 # undef YYERROR_VERBOSE
241 # define YYERROR_VERBOSE 1
243 # define YYERROR_VERBOSE ]b4_error_verbose_flag[
246 /* Enabling the token table. */
247 #ifndef YYTOKEN_TABLE
248 # define YYTOKEN_TABLE ]b4_token_table[
251 /* Default (constant) value used for initialization for null
252 right-hand sides. Unlike the standard yacc.c template,
253 here we set the default value of $$ to a zeroed-out value.
254 Since the default value is undefined, this behavior is
255 technically correct. */
256 static YYSTYPE yyval_default
;
258 /* Copy the second part of user declarations. */
259 ]b4_user_post_prologue
260 b4_percent_code_get
[]dnl
267 # if defined YYENABLE_NLS && YYENABLE_NLS
269 # include <libintl.h> /* INFRINGES ON USER NAME SPACE */
270 # define YY_(msgid) dgettext ("bison-runtime", msgid)
274 # define YY_(msgid) msgid
278 /* Suppress unused-variable warnings by "using" E. */
279 #if ! defined lint || defined __GNUC__
280 # define YYUSE(e) ((void) (e))
282 # define YYUSE(e) /* empty */
285 /* Identity function, used to suppress warnings about constant conditions. */
289 ]b4_c_function_def([YYID
], [static int], [[int i
], [i
]])[
299 # define YYMALLOC malloc
302 # define YYREALLOC realloc
305 #define YYSIZEMAX ((size_t) -1)
310 typedef unsigned char yybool
;
317 # define YYJMP_BUF jmp_buf
318 # define YYSETJMP(env) setjmp (env)
319 # define YYLONGJMP(env, val) longjmp (env, val)
326 #ifndef __attribute__
327 /* This feature is available in gcc versions 2.5 and later. */
328 # if (! defined __GNUC__ || __GNUC__ < 2 \
329 || (__GNUC__ == 2 && __GNUC_MINOR__ < 5))
330 # define __attribute__(Spec) /* empty */
334 ]b4_locations_if([#define YYOPTIONAL_LOC(Name) Name],[
336 # define YYOPTIONAL_LOC(Name) /* empty */
338 # define YYOPTIONAL_LOC(Name) Name __attribute__ ((__unused__))
342 # define YYASSERT(condition) ((void) ((condition) || (abort (), 0)))
345 /* YYFINAL -- State number of the termination state. */
346 #define YYFINAL ]b4_final_state_number[
347 /* YYLAST -- Last index in YYTABLE. */
348 #define YYLAST ]b4_last[
350 /* YYNTOKENS -- Number of terminals. */
351 #define YYNTOKENS ]b4_tokens_number[
352 /* YYNNTS -- Number of nonterminals. */
353 #define YYNNTS ]b4_nterms_number[
354 /* YYNRULES -- Number of rules. */
355 #define YYNRULES ]b4_rules_number[
356 /* YYNRULES -- Number of states. */
357 #define YYNSTATES ]b4_states_number[
358 /* YYMAXRHS -- Maximum number of symbols on right-hand side of rule. */
359 #define YYMAXRHS ]b4_r2_max[
360 /* YYMAXLEFT -- Maximum number of symbols to the left of a handle
361 accessed by $0, $-1, etc., in any rule. */
362 #define YYMAXLEFT ]b4_max_left_semantic_context[
364 /* YYTRANSLATE(X) -- Bison symbol number corresponding to X. */
365 #define YYUNDEFTOK ]b4_undef_token_number[
366 #define YYMAXUTOK ]b4_user_token_number_max[
368 #define YYTRANSLATE(YYX) \
369 ((unsigned int) (YYX) <= YYMAXUTOK ? yytranslate[YYX] : YYUNDEFTOK)
371 /* YYTRANSLATE[YYLEX] -- Bison symbol number corresponding to YYLEX. */
372 static const ]b4_int_type_for([b4_translate
])[ yytranslate
[] =
378 /* YYPRHS[YYN] -- Index of the first RHS symbol of rule number YYN in
380 static const ]b4_int_type_for([b4_prhs
])[ yyprhs
[] =
385 /* YYRHS -- A `-1'-separated list of the rules' RHS. */
386 static const ]b4_int_type_for([b4_rhs
])[ yyrhs
[] =
391 /* YYRLINE[YYN] -- source line where rule number YYN was defined. */
392 static const ]b4_int_type_for([b4_rline
])[ yyrline
[] =
398 #if YYDEBUG || YYERROR_VERBOSE || YYTOKEN_TABLE
399 /* YYTNAME[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM.
400 First, the terminals, then, starting at YYNTOKENS, nonterminals. */
401 static const char *const yytname
[] =
407 /* YYR1[YYN] -- Symbol number of symbol that rule YYN derives. */
408 static const ]b4_int_type_for([b4_r1
])[ yyr1
[] =
413 /* YYR2[YYN] -- Number of symbols composing right hand side of rule YYN. */
414 static const ]b4_int_type_for([b4_r2
])[ yyr2
[] =
419 /* YYDPREC[RULE-NUM] -- Dynamic precedence of rule #RULE-NUM (0 if none). */
420 static const ]b4_int_type_for([b4_dprec
])[ yydprec
[] =
425 /* YYMERGER[RULE-NUM] -- Index of merging function for rule #RULE-NUM. */
426 static const ]b4_int_type_for([b4_merger
])[ yymerger
[] =
431 /* YYDEFACT[S] -- default reduction number in state S. Performed when
432 YYTABLE doesn't specify something else to do. Zero means the default
434 static const ]b4_int_type_for([b4_defact
])[ yydefact
[] =
439 /* YYPDEFGOTO[NTERM-NUM]. */
440 static const ]b4_int_type_for([b4_defgoto
])[ yydefgoto
[] =
445 /* YYPACT[STATE-NUM] -- Index in YYTABLE of the portion describing
447 #define YYPACT_NINF ]b4_pact_ninf[
448 static const ]b4_int_type_for([b4_pact
])[ yypact
[] =
453 /* YYPGOTO[NTERM-NUM]. */
454 static const ]b4_int_type_for([b4_pgoto
])[ yypgoto
[] =
459 /* YYTABLE[YYPACT[STATE-NUM]]. What to do in state STATE-NUM. If
460 positive, shift that token. If negative, reduce the rule which
461 number is the opposite. If YYTABLE_NINF, syntax error. */
462 #define YYTABLE_NINF ]b4_table_ninf[
463 static const ]b4_int_type_for([b4_table
])[ yytable
[] =
468 /* YYCONFLP[YYPACT[STATE-NUM]] -- Pointer into YYCONFL of start of
469 list of conflicting reductions corresponding to action entry for
470 state STATE-NUM in yytable. 0 means no conflicts. The list in
471 yyconfl is terminated by a rule number of 0. */
472 static const ]b4_int_type_for([b4_conflict_list_heads
])[ yyconflp
[] =
474 ]b4_conflict_list_heads
[
477 /* YYCONFL[I] -- lists of conflicting rule numbers, each terminated by
478 0, pointed into by YYCONFLP. */
479 ]dnl Do
not use b4_int_type_for here
, since there are places where
480 dnl pointers onto yyconfl are taken
, which type is
"short int *".
481 dnl We probably ought to introduce a type
for confl
.
482 [static const short int yyconfl
[] =
484 ]b4_conflicting_rules
[
487 static const ]b4_int_type_for([b4_check
])[ yycheck
[] =
492 /* YYSTOS[STATE-NUM] -- The (internal number of the) accessing
493 symbol of state STATE-NUM. */
494 static const ]b4_int_type_for([b4_stos
])[ yystos
[] =
500 /* Prevent warning if -Wmissing-prototypes. */
501 ]b4_c_ansi_function_decl([yyparse
], [int], b4_parse_param
)[
503 /* Error token number */
506 /* YYLLOC_DEFAULT -- Set CURRENT to span from RHS[1] to RHS[N].
507 If N is 0, then set CURRENT to the empty location which ends
508 the previous symbol: RHS[0] (always defined). */
511 #define YYRHSLOC(Rhs, K) ((Rhs)[K].yystate.yyloc)
512 #ifndef YYLLOC_DEFAULT
513 # define YYLLOC_DEFAULT(Current, Rhs, N) \
517 (Current).first_line = YYRHSLOC (Rhs, 1).first_line; \
518 (Current).first_column = YYRHSLOC (Rhs, 1).first_column; \
519 (Current).last_line = YYRHSLOC (Rhs, N).last_line; \
520 (Current).last_column = YYRHSLOC (Rhs, N).last_column; \
524 (Current).first_line = (Current).last_line = \
525 YYRHSLOC (Rhs, 0).last_line; \
526 (Current).first_column = (Current).last_column = \
527 YYRHSLOC (Rhs, 0).last_column; \
531 /* YY_LOCATION_PRINT -- Print the location on the stream.
532 This macro was not mandated originally: define only if we know
533 we won't break user code: when these are the locations we know. */
535 # define YY_LOCATION_PRINT(File, Loc) \
536 fprintf (File, "%d.%d-%d.%d", \
537 (Loc).first_line, (Loc).first_column, \
538 (Loc).last_line, (Loc).last_column)
541 #ifndef YYLLOC_DEFAULT
542 # define YYLLOC_DEFAULT(Current, Rhs, N) ((void) 0)
546 #ifndef YY_LOCATION_PRINT
547 # define YY_LOCATION_PRINT(File, Loc) ((void) 0)
551 /* YYLEX -- calling `yylex' with the right arguments. */
552 #define YYLEX ]b4_c_function_call([yylex], [int], b4_lex_param)[
557 #define yynerrs (yystackp->yyerrcnt)
559 #define yychar (yystackp->yyrawchar)
561 #define yylval (yystackp->yyval)
563 #define yylloc (yystackp->yyloc)
564 m4_if(b4_prefix
[], [yy
], [],
565 [#define b4_prefix[]nerrs yynerrs
566 #define b4_prefix[]char yychar
567 #define b4_prefix[]lval yylval
568 #define b4_prefix[]lloc yylloc])],
576 static const int YYEOF
= 0;
577 static const int YYEMPTY
= -2;
579 typedef enum { yyok
, yyaccept
, yyabort
, yyerr
} YYRESULTTAG
;
582 do { YYRESULTTAG yyflag = YYE; if (yyflag != yyok) return yyflag; } \
588 # define YYFPRINTF fprintf
591 # define YYDPRINTF(Args) \
597 ]b4_yy_symbol_print_generate([b4_c_ansi_function_def
])[
599 # define YY_SYMBOL_PRINT(Title, Type, Value, Location) \
603 YYFPRINTF (stderr, "%s ", Title); \
604 yy_symbol_print (stderr, Type, Value]b4_locuser_args([Location])[); \
605 YYFPRINTF (stderr, "\n"); \
609 /* Nonzero means print parse trace. It is left uninitialized so that
610 multiple parsers can coexist. */
615 # define YYDPRINTF(Args)
616 # define YY_SYMBOL_PRINT(Title, Type, Value, Location)
618 #endif /* !YYDEBUG */
620 /* YYINITDEPTH -- initial size of the parser's stacks. */
622 # define YYINITDEPTH ]b4_stack_depth_init[
625 /* YYMAXDEPTH -- maximum size the stacks can grow to (effective only
626 if the built-in stack extension method is used).
628 Do not make this value too large; the results are undefined if
629 SIZE_MAX < YYMAXDEPTH * sizeof (GLRStackItem)
630 evaluated with infinite-precision integer arithmetic. */
633 # define YYMAXDEPTH ]b4_stack_depth_max[
636 /* Minimum number of free items on the stack allowed after an
637 allocation. This is to allow allocation and initialization
638 to be completed by functions that call yyexpandGLRStack before the
639 stack is expanded, thus insuring that all necessary pointers get
640 properly redirected to new data. */
643 #ifndef YYSTACKEXPANDABLE
644 # if (! defined __cplusplus \
645 || (]b4_locations_if([[defined YYLTYPE_IS_TRIVIAL && YYLTYPE_IS_TRIVIAL \
646 && ]])[defined YYSTYPE_IS_TRIVIAL && YYSTYPE_IS_TRIVIAL))
647 # define YYSTACKEXPANDABLE 1
649 # define YYSTACKEXPANDABLE 0
653 #if YYSTACKEXPANDABLE
654 # define YY_RESERVE_GLRSTACK(Yystack) \
656 if (Yystack->yyspaceLeft < YYHEADROOM) \
657 yyexpandGLRStack (Yystack); \
660 # define YY_RESERVE_GLRSTACK(Yystack) \
662 if (Yystack->yyspaceLeft < YYHEADROOM) \
663 yyMemoryExhausted (Yystack); \
671 # if defined __GLIBC__ && defined _STRING_H && defined _GNU_SOURCE
672 # define yystpcpy stpcpy
674 /* Copy YYSRC to YYDEST, returning the address of the terminating '\0' in
677 yystpcpy (char *yydest
, const char *yysrc
)
680 const char *yys
= yysrc
;
682 while ((*yyd
++ = *yys
++) != '\0')
691 /* Copy to YYRES the contents of YYSTR after stripping away unnecessary
692 quotes and backslashes, so that it's suitable for yyerror. The
693 heuristic is that double-quoting is unnecessary unless the string
694 contains an apostrophe, a comma, or backslash (other than
695 backslash-backslash). YYSTR is taken from yytname. If YYRES is
696 null, do not copy; instead, return the length of what the result
699 yytnamerr (char *yyres
, const char *yystr
)
704 char const *yyp
= yystr
;
711 goto do_not_strip_quotes
;
715 goto do_not_strip_quotes
;
728 do_not_strip_quotes
: ;
732 return strlen (yystr
);
734 return yystpcpy (yyres
, yystr
) - yyres
;
738 #endif /* !YYERROR_VERBOSE */
740 /** State numbers, as in LALR(1) machine */
741 typedef int yyStateNum
;
743 /** Rule numbers, as in LALR(1) machine */
744 typedef int yyRuleNum
;
746 /** Grammar symbol */
747 typedef short int yySymbol
;
749 /** Item references, as in LALR(1) machine */
750 typedef short int yyItemNum
;
752 typedef struct yyGLRState yyGLRState
;
753 typedef struct yyGLRStateSet yyGLRStateSet
;
754 typedef struct yySemanticOption yySemanticOption
;
755 typedef union yyGLRStackItem yyGLRStackItem
;
756 typedef struct yyGLRStack yyGLRStack
;
759 /** Type tag: always true. */
761 /** Type tag for yysemantics. If true, yysval applies, otherwise
762 * yyfirstVal applies. */
764 /** Number of corresponding LALR(1) machine state. */
765 yyStateNum yylrState
;
766 /** Preceding state in this stack */
768 /** Source position of the first token produced by my symbol */
771 /** First in a chain of alternative reductions producing the
772 * non-terminal corresponding to this state, threaded through
774 yySemanticOption
* yyfirstVal
;
775 /** Semantic value for this state. */
778 /** Source location for this state. */
782 struct yyGLRStateSet
{
783 yyGLRState
** yystates
;
784 /** During nondeterministic operation, yylookaheadNeeds tracks which
785 * stacks have actually needed the current lookahead. During deterministic
786 * operation, yylookaheadNeeds[0] is not maintained since it would merely
787 * duplicate yychar != YYEMPTY. */
788 yybool
* yylookaheadNeeds
;
789 size_t yysize
, yycapacity
;
792 struct yySemanticOption
{
793 /** Type tag: always false. */
795 /** Rule number for this reduction */
797 /** The last RHS state in the list of states to be reduced. */
799 /** The lookahead for this reduction. */
803 /** Next sibling in chain of options. To facilitate merging,
804 * options are chained in decreasing order by address. */
805 yySemanticOption
* yynext
;
808 /** Type of the items in the GLR stack. The yyisState field
809 * indicates which item of the union is valid. */
810 union yyGLRStackItem
{
812 yySemanticOption yyoption
;
817 ]b4_locations_if([[ /* To compute the location of the error token. */
818 yyGLRStackItem yyerror_range
[3];]])[
826 YYJMP_BUF yyexception_buffer
;
827 yyGLRStackItem
* yyitems
;
828 yyGLRStackItem
* yynextFree
;
830 yyGLRState
* yysplitPoint
;
831 yyGLRState
* yylastDeleted
;
832 yyGLRStateSet yytops
;
835 #if YYSTACKEXPANDABLE
836 static void yyexpandGLRStack (yyGLRStack
* yystackp
);
839 static void yyFail (yyGLRStack
* yystackp
]b4_pure_formals
[, const char* yymsg
)
840 __attribute__ ((__noreturn__
));
842 yyFail (yyGLRStack
* yystackp
]b4_pure_formals
[, const char* yymsg
)
844 if (yymsg
!= YY_NULL
)
845 yyerror (]b4_yyerror_args
[yymsg
);
846 YYLONGJMP (yystackp
->yyexception_buffer
, 1);
849 static void yyMemoryExhausted (yyGLRStack
* yystackp
)
850 __attribute__ ((__noreturn__
));
852 yyMemoryExhausted (yyGLRStack
* yystackp
)
854 YYLONGJMP (yystackp
->yyexception_buffer
, 2);
857 #if YYDEBUG || YYERROR_VERBOSE
858 /** A printable representation of TOKEN. */
859 static inline const char*
860 yytokenName (yySymbol yytoken
)
862 if (yytoken
== YYEMPTY
)
865 return yytname
[yytoken
];
869 /** Fill in YYVSP[YYLOW1 .. YYLOW0-1] from the chain of states starting
870 * at YYVSP[YYLOW0].yystate.yypred. Leaves YYVSP[YYLOW1].yystate.yypred
871 * containing the pointer to the next state in the chain. */
872 static void yyfillin (yyGLRStackItem
*, int, int) __attribute__ ((__unused__
));
874 yyfillin (yyGLRStackItem
*yyvsp
, int yylow0
, int yylow1
)
878 s
= yyvsp
[yylow0
].yystate
.yypred
;
879 for (i
= yylow0
-1; i
>= yylow1
; i
-= 1)
881 YYASSERT (s
->yyresolved
);
882 yyvsp
[i
].yystate
.yyresolved
= yytrue
;
883 yyvsp
[i
].yystate
.yysemantics
.yysval
= s
->yysemantics
.yysval
;
884 yyvsp
[i
].yystate
.yyloc
= s
->yyloc
;
885 s
= yyvsp
[i
].yystate
.yypred
= s
->yypred
;
889 /* Do nothing if YYNORMAL or if *YYLOW <= YYLOW1. Otherwise, fill in
890 * YYVSP[YYLOW1 .. *YYLOW-1] as in yyfillin and set *YYLOW = YYLOW1.
891 * For convenience, always return YYLOW1. */
892 static inline int yyfill (yyGLRStackItem
*, int *, int, yybool
)
893 __attribute__ ((__unused__
));
895 yyfill (yyGLRStackItem
*yyvsp
, int *yylow
, int yylow1
, yybool yynormal
)
897 if (!yynormal
&& yylow1
< *yylow
)
899 yyfillin (yyvsp
, *yylow
, yylow1
);
905 /** Perform user action for rule number YYN, with RHS length YYRHSLEN,
906 * and top stack item YYVSP. YYLVALP points to place to put semantic
907 * value ($$), and yylocp points to place for location information
908 * (@@$). Returns yyok for normal return, yyaccept for YYACCEPT,
909 * yyerr for YYERROR, yyabort for YYABORT. */
910 /*ARGSUSED*/ static YYRESULTTAG
911 yyuserAction (yyRuleNum yyn
, int yyrhslen
, yyGLRStackItem
* yyvsp
,
912 yyGLRStack
* yystackp
,
913 YYSTYPE
* yyvalp
]b4_locuser_formals
[)
915 yybool yynormal
__attribute__ ((__unused__
)) =
916 (yystackp
->yysplitPoint
== YY_NULL
);
918 ]b4_parse_param_use
[]dnl
920 # define yyerrok (yystackp->yyerrState = 0)
922 # define YYACCEPT return yyaccept
924 # define YYABORT return yyabort
926 # define YYERROR return yyerrok, yyerr
928 # define YYRECOVERING() (yystackp->yyerrState != 0)
930 # define yyclearin (yychar = YYEMPTY)
932 # define YYFILL(N) yyfill (yyvsp, &yylow, N, yynormal)
934 # define YYBACKUP(Token, Value) \
935 return yyerror (]b4_yyerror_args[YY_("syntax error: cannot back up")), \
940 *yyvalp
= yyval_default
;
942 *yyvalp
= yyvsp
[YYFILL (1-yyrhslen
)].yystate
.yysemantics
.yysval
;]b4_locations_if([[
943 YYLLOC_DEFAULT ((*yylocp
), (yyvsp
- yyrhslen
), yyrhslen
);
944 yystackp
->yyerror_range
[1].yystate
.yyloc
= *yylocp
;
963 /*ARGSUSED*/ static void
964 yyuserMerge (int yyn
, YYSTYPE
* yy0
, YYSTYPE
* yy1
)
976 /* Bison grammar-table manipulation. */
978 ]b4_yydestruct_generate([b4_c_ansi_function_def
])[
980 /** Number of symbols composing the right hand side of rule #RULE. */
982 yyrhsLength (yyRuleNum yyrule
)
988 yydestroyGLRState (char const *yymsg
, yyGLRState
*yys
]b4_user_formals
[)
991 yydestruct (yymsg
, yystos
[yys
->yylrState
],
992 &yys
->yysemantics
.yysval
]b4_locuser_args([&yys
->yyloc
])[);
998 if (yys
->yysemantics
.yyfirstVal
)
999 YYFPRINTF (stderr
, "%s unresolved ", yymsg
);
1001 YYFPRINTF (stderr
, "%s incomplete ", yymsg
);
1002 yy_symbol_print (stderr
, yystos
[yys
->yylrState
],
1003 YY_NULL
]b4_locuser_args([&yys
->yyloc
])[);
1004 YYFPRINTF (stderr
, "\n");
1008 if (yys
->yysemantics
.yyfirstVal
)
1010 yySemanticOption
*yyoption
= yys
->yysemantics
.yyfirstVal
;
1013 for (yyrh
= yyoption
->yystate
, yyn
= yyrhsLength (yyoption
->yyrule
);
1015 yyrh
= yyrh
->yypred
, yyn
-= 1)
1016 yydestroyGLRState (yymsg
, yyrh
]b4_user_args
[);
1021 /** Left-hand-side symbol for rule #RULE. */
1022 static inline yySymbol
1023 yylhsNonterm (yyRuleNum yyrule
)
1025 return yyr1
[yyrule
];
1028 #define yypact_value_is_default(yystate) \
1029 ]b4_table_value_equals([[pact]], [[yystate]], [b4_pact_ninf])[
1031 /** True iff LR state STATE has only a default reduction (regardless
1033 static inline yybool
1034 yyisDefaultedState (yyStateNum yystate
)
1036 return yypact_value_is_default (yypact
[yystate
]);
1039 /** The default reduction for STATE, assuming it has one. */
1040 static inline yyRuleNum
1041 yydefaultAction (yyStateNum yystate
)
1043 return yydefact
[yystate
];
1046 #define yytable_value_is_error(yytable_value) \
1047 ]b4_table_value_equals([[table]], [[yytable_value]], [b4_table_ninf])[
1049 /** Set *YYACTION to the action to take in YYSTATE on seeing YYTOKEN.
1051 * R < 0: Reduce on rule -R.
1053 * R > 0: Shift to state R.
1054 * Set *CONFLICTS to a pointer into yyconfl to 0-terminated list of
1055 * conflicting reductions.
1058 yygetLRActions (yyStateNum yystate
, int yytoken
,
1059 int* yyaction
, const short int** yyconflicts
)
1061 int yyindex
= yypact
[yystate
] + yytoken
;
1062 if (yypact_value_is_default (yypact
[yystate
])
1063 || yyindex
< 0 || YYLAST
< yyindex
|| yycheck
[yyindex
] != yytoken
)
1065 *yyaction
= -yydefact
[yystate
];
1066 *yyconflicts
= yyconfl
;
1068 else if (! yytable_value_is_error (yytable
[yyindex
]))
1070 *yyaction
= yytable
[yyindex
];
1071 *yyconflicts
= yyconfl
+ yyconflp
[yyindex
];
1076 *yyconflicts
= yyconfl
+ yyconflp
[yyindex
];
1080 static inline yyStateNum
1081 yyLRgotoState (yyStateNum yystate
, yySymbol yylhs
)
1084 yyr
= yypgoto
[yylhs
- YYNTOKENS
] + yystate
;
1085 if (0 <= yyr
&& yyr
<= YYLAST
&& yycheck
[yyr
] == yystate
)
1086 return yytable
[yyr
];
1088 return yydefgoto
[yylhs
- YYNTOKENS
];
1091 static inline yybool
1092 yyisShiftAction (int yyaction
)
1094 return 0 < yyaction
;
1097 static inline yybool
1098 yyisErrorAction (int yyaction
)
1100 return yyaction
== 0;
1105 /** Return a fresh GLRStackItem. Callers should call
1106 * YY_RESERVE_GLRSTACK afterwards to make sure there is sufficient
1109 static inline yyGLRStackItem
*
1110 yynewGLRStackItem (yyGLRStack
* yystackp
, yybool yyisState
)
1112 yyGLRStackItem
* yynewItem
= yystackp
->yynextFree
;
1113 yystackp
->yyspaceLeft
-= 1;
1114 yystackp
->yynextFree
+= 1;
1115 yynewItem
->yystate
.yyisState
= yyisState
;
1119 /** Add a new semantic action that will execute the action for rule
1120 * RULENUM on the semantic values in RHS to the list of
1121 * alternative actions for STATE. Assumes that RHS comes from
1122 * stack #K of *STACKP. */
1124 yyaddDeferredAction (yyGLRStack
* yystackp
, size_t yyk
, yyGLRState
* yystate
,
1125 yyGLRState
* rhs
, yyRuleNum yyrule
)
1127 yySemanticOption
* yynewOption
=
1128 &yynewGLRStackItem (yystackp
, yyfalse
)->yyoption
;
1129 yynewOption
->yystate
= rhs
;
1130 yynewOption
->yyrule
= yyrule
;
1131 if (yystackp
->yytops
.yylookaheadNeeds
[yyk
])
1133 yynewOption
->yyrawchar
= yychar
;
1134 yynewOption
->yyval
= yylval
;]b4_locations_if([
1135 yynewOption
->yyloc
= yylloc
;])[
1138 yynewOption
->yyrawchar
= YYEMPTY
;
1139 yynewOption
->yynext
= yystate
->yysemantics
.yyfirstVal
;
1140 yystate
->yysemantics
.yyfirstVal
= yynewOption
;
1142 YY_RESERVE_GLRSTACK (yystackp
);
1147 /** Initialize SET to a singleton set containing an empty stack. */
1149 yyinitStateSet (yyGLRStateSet
* yyset
)
1152 yyset
->yycapacity
= 16;
1153 yyset
->yystates
= (yyGLRState
**) YYMALLOC (16 * sizeof yyset
->yystates
[0]);
1154 if (! yyset
->yystates
)
1156 yyset
->yystates
[0] = YY_NULL
;
1157 yyset
->yylookaheadNeeds
=
1158 (yybool
*) YYMALLOC (16 * sizeof yyset
->yylookaheadNeeds
[0]);
1159 if (! yyset
->yylookaheadNeeds
)
1161 YYFREE (yyset
->yystates
);
1167 static void yyfreeStateSet (yyGLRStateSet
* yyset
)
1169 YYFREE (yyset
->yystates
);
1170 YYFREE (yyset
->yylookaheadNeeds
);
1173 /** Initialize STACK to a single empty stack, with total maximum
1174 * capacity for all stacks of SIZE. */
1176 yyinitGLRStack (yyGLRStack
* yystackp
, size_t yysize
)
1178 yystackp
->yyerrState
= 0;
1180 yystackp
->yyspaceLeft
= yysize
;
1182 (yyGLRStackItem
*) YYMALLOC (yysize
* sizeof yystackp
->yynextFree
[0]);
1183 if (!yystackp
->yyitems
)
1185 yystackp
->yynextFree
= yystackp
->yyitems
;
1186 yystackp
->yysplitPoint
= YY_NULL
;
1187 yystackp
->yylastDeleted
= YY_NULL
;
1188 return yyinitStateSet (&yystackp
->yytops
);
1192 #if YYSTACKEXPANDABLE
1193 # define YYRELOC(YYFROMITEMS,YYTOITEMS,YYX,YYTYPE) \
1194 &((YYTOITEMS) - ((YYFROMITEMS) - (yyGLRStackItem*) (YYX)))->YYTYPE
1196 /** If STACK is expandable, extend it. WARNING: Pointers into the
1197 stack from outside should be considered invalid after this call.
1198 We always expand when there are 1 or fewer items left AFTER an
1199 allocation, so that we can avoid having external pointers exist
1200 across an allocation. */
1202 yyexpandGLRStack (yyGLRStack
* yystackp
)
1204 yyGLRStackItem
* yynewItems
;
1205 yyGLRStackItem
* yyp0
, *yyp1
;
1206 size_t yysize
, yynewSize
;
1208 yysize
= yystackp
->yynextFree
- yystackp
->yyitems
;
1209 if (YYMAXDEPTH
- YYHEADROOM
< yysize
)
1210 yyMemoryExhausted (yystackp
);
1211 yynewSize
= 2*yysize
;
1212 if (YYMAXDEPTH
< yynewSize
)
1213 yynewSize
= YYMAXDEPTH
;
1214 yynewItems
= (yyGLRStackItem
*) YYMALLOC (yynewSize
* sizeof yynewItems
[0]);
1216 yyMemoryExhausted (yystackp
);
1217 for (yyp0
= yystackp
->yyitems
, yyp1
= yynewItems
, yyn
= yysize
;
1219 yyn
-= 1, yyp0
+= 1, yyp1
+= 1)
1222 if (*(yybool
*) yyp0
)
1224 yyGLRState
* yys0
= &yyp0
->yystate
;
1225 yyGLRState
* yys1
= &yyp1
->yystate
;
1226 if (yys0
->yypred
!= YY_NULL
)
1228 YYRELOC (yyp0
, yyp1
, yys0
->yypred
, yystate
);
1229 if (! yys0
->yyresolved
&& yys0
->yysemantics
.yyfirstVal
!= YY_NULL
)
1230 yys1
->yysemantics
.yyfirstVal
=
1231 YYRELOC(yyp0
, yyp1
, yys0
->yysemantics
.yyfirstVal
, yyoption
);
1235 yySemanticOption
* yyv0
= &yyp0
->yyoption
;
1236 yySemanticOption
* yyv1
= &yyp1
->yyoption
;
1237 if (yyv0
->yystate
!= YY_NULL
)
1238 yyv1
->yystate
= YYRELOC (yyp0
, yyp1
, yyv0
->yystate
, yystate
);
1239 if (yyv0
->yynext
!= YY_NULL
)
1240 yyv1
->yynext
= YYRELOC (yyp0
, yyp1
, yyv0
->yynext
, yyoption
);
1243 if (yystackp
->yysplitPoint
!= YY_NULL
)
1244 yystackp
->yysplitPoint
= YYRELOC (yystackp
->yyitems
, yynewItems
,
1245 yystackp
->yysplitPoint
, yystate
);
1247 for (yyn
= 0; yyn
< yystackp
->yytops
.yysize
; yyn
+= 1)
1248 if (yystackp
->yytops
.yystates
[yyn
] != YY_NULL
)
1249 yystackp
->yytops
.yystates
[yyn
] =
1250 YYRELOC (yystackp
->yyitems
, yynewItems
,
1251 yystackp
->yytops
.yystates
[yyn
], yystate
);
1252 YYFREE (yystackp
->yyitems
);
1253 yystackp
->yyitems
= yynewItems
;
1254 yystackp
->yynextFree
= yynewItems
+ yysize
;
1255 yystackp
->yyspaceLeft
= yynewSize
- yysize
;
1260 yyfreeGLRStack (yyGLRStack
* yystackp
)
1262 YYFREE (yystackp
->yyitems
);
1263 yyfreeStateSet (&yystackp
->yytops
);
1266 /** Assuming that S is a GLRState somewhere on STACK, update the
1267 * splitpoint of STACK, if needed, so that it is at least as deep as
1270 yyupdateSplit (yyGLRStack
* yystackp
, yyGLRState
* yys
)
1272 if (yystackp
->yysplitPoint
!= YY_NULL
&& yystackp
->yysplitPoint
> yys
)
1273 yystackp
->yysplitPoint
= yys
;
1276 /** Invalidate stack #K in STACK. */
1278 yymarkStackDeleted (yyGLRStack
* yystackp
, size_t yyk
)
1280 if (yystackp
->yytops
.yystates
[yyk
] != YY_NULL
)
1281 yystackp
->yylastDeleted
= yystackp
->yytops
.yystates
[yyk
];
1282 yystackp
->yytops
.yystates
[yyk
] = YY_NULL
;
1285 /** Undelete the last stack that was marked as deleted. Can only be
1286 done once after a deletion, and only when all other stacks have
1289 yyundeleteLastStack (yyGLRStack
* yystackp
)
1291 if (yystackp
->yylastDeleted
== YY_NULL
|| yystackp
->yytops
.yysize
!= 0)
1293 yystackp
->yytops
.yystates
[0] = yystackp
->yylastDeleted
;
1294 yystackp
->yytops
.yysize
= 1;
1295 YYDPRINTF ((stderr
, "Restoring last deleted stack as stack #0.\n"));
1296 yystackp
->yylastDeleted
= YY_NULL
;
1300 yyremoveDeletes (yyGLRStack
* yystackp
)
1304 while (yyj
< yystackp
->yytops
.yysize
)
1306 if (yystackp
->yytops
.yystates
[yyi
] == YY_NULL
)
1310 YYDPRINTF ((stderr
, "Removing dead stacks.\n"));
1312 yystackp
->yytops
.yysize
-= 1;
1316 yystackp
->yytops
.yystates
[yyj
] = yystackp
->yytops
.yystates
[yyi
];
1317 /* In the current implementation, it's unnecessary to copy
1318 yystackp->yytops.yylookaheadNeeds[yyi] since, after
1319 yyremoveDeletes returns, the parser immediately either enters
1320 deterministic operation or shifts a token. However, it doesn't
1321 hurt, and the code might evolve to need it. */
1322 yystackp
->yytops
.yylookaheadNeeds
[yyj
] =
1323 yystackp
->yytops
.yylookaheadNeeds
[yyi
];
1326 YYDPRINTF ((stderr
, "Rename stack %lu -> %lu.\n",
1327 (unsigned long int) yyi
, (unsigned long int) yyj
));
1335 /** Shift to a new state on stack #K of STACK, corresponding to LR state
1336 * LRSTATE, at input position POSN, with (resolved) semantic value SVAL. */
1338 yyglrShift (yyGLRStack
* yystackp
, size_t yyk
, yyStateNum yylrState
,
1340 YYSTYPE
* yyvalp
]b4_locations_if([, YYLTYPE
* yylocp
])[)
1342 yyGLRState
* yynewState
= &yynewGLRStackItem (yystackp
, yytrue
)->yystate
;
1344 yynewState
->yylrState
= yylrState
;
1345 yynewState
->yyposn
= yyposn
;
1346 yynewState
->yyresolved
= yytrue
;
1347 yynewState
->yypred
= yystackp
->yytops
.yystates
[yyk
];
1348 yynewState
->yysemantics
.yysval
= *yyvalp
;]b4_locations_if([
1349 yynewState
->yyloc
= *yylocp
;])[
1350 yystackp
->yytops
.yystates
[yyk
] = yynewState
;
1352 YY_RESERVE_GLRSTACK (yystackp
);
1355 /** Shift stack #K of YYSTACK, to a new state corresponding to LR
1356 * state YYLRSTATE, at input position YYPOSN, with the (unresolved)
1357 * semantic value of YYRHS under the action for YYRULE. */
1359 yyglrShiftDefer (yyGLRStack
* yystackp
, size_t yyk
, yyStateNum yylrState
,
1360 size_t yyposn
, yyGLRState
* rhs
, yyRuleNum yyrule
)
1362 yyGLRState
* yynewState
= &yynewGLRStackItem (yystackp
, yytrue
)->yystate
;
1364 yynewState
->yylrState
= yylrState
;
1365 yynewState
->yyposn
= yyposn
;
1366 yynewState
->yyresolved
= yyfalse
;
1367 yynewState
->yypred
= yystackp
->yytops
.yystates
[yyk
];
1368 yynewState
->yysemantics
.yyfirstVal
= YY_NULL
;
1369 yystackp
->yytops
.yystates
[yyk
] = yynewState
;
1371 /* Invokes YY_RESERVE_GLRSTACK. */
1372 yyaddDeferredAction (yystackp
, yyk
, yynewState
, rhs
, yyrule
);
1375 /** Pop the symbols consumed by reduction #RULE from the top of stack
1376 * #K of STACK, and perform the appropriate semantic action on their
1377 * semantic values. Assumes that all ambiguities in semantic values
1378 * have been previously resolved. Set *VALP to the resulting value,
1379 * and *LOCP to the computed location (if any). Return value is as
1380 * for userAction. */
1381 static inline YYRESULTTAG
1382 yydoAction (yyGLRStack
* yystackp
, size_t yyk
, yyRuleNum yyrule
,
1383 YYSTYPE
* yyvalp
]b4_locuser_formals
[)
1385 int yynrhs
= yyrhsLength (yyrule
);
1387 if (yystackp
->yysplitPoint
== YY_NULL
)
1389 /* Standard special case: single stack. */
1390 yyGLRStackItem
* rhs
= (yyGLRStackItem
*) yystackp
->yytops
.yystates
[yyk
];
1391 YYASSERT (yyk
== 0);
1392 yystackp
->yynextFree
-= yynrhs
;
1393 yystackp
->yyspaceLeft
+= yynrhs
;
1394 yystackp
->yytops
.yystates
[0] = & yystackp
->yynextFree
[-1].yystate
;
1395 return yyuserAction (yyrule
, yynrhs
, rhs
, yystackp
,
1396 yyvalp
]b4_locuser_args
[);
1400 /* At present, doAction is never called in nondeterministic
1401 * mode, so this branch is never taken. It is here in
1402 * anticipation of a future feature that will allow immediate
1403 * evaluation of selected actions in nondeterministic mode. */
1406 yyGLRStackItem yyrhsVals
[YYMAXRHS
+ YYMAXLEFT
+ 1];
1407 yys
= yyrhsVals
[YYMAXRHS
+ YYMAXLEFT
].yystate
.yypred
1408 = yystackp
->yytops
.yystates
[yyk
];]b4_locations_if([[
1410 /* Set default location. */
1411 yyrhsVals
[YYMAXRHS
+ YYMAXLEFT
- 1].yystate
.yyloc
= yys
->yyloc
;]])[
1412 for (yyi
= 0; yyi
< yynrhs
; yyi
+= 1)
1417 yyupdateSplit (yystackp
, yys
);
1418 yystackp
->yytops
.yystates
[yyk
] = yys
;
1419 return yyuserAction (yyrule
, yynrhs
, yyrhsVals
+ YYMAXRHS
+ YYMAXLEFT
- 1,
1420 yystackp
, yyvalp
]b4_locuser_args
[);
1425 # define YY_REDUCE_PRINT(Args)
1427 # define YY_REDUCE_PRINT(Args) \
1430 yy_reduce_print Args; \
1433 /*----------------------------------------------------------.
1434 | Report that the RULE is going to be reduced on stack #K. |
1435 `----------------------------------------------------------*/
1437 /*ARGSUSED*/ static inline void
1438 yy_reduce_print (yyGLRStack
* yystackp
, size_t yyk
, yyRuleNum yyrule
,
1439 YYSTYPE
* yyvalp
]b4_locuser_formals
[)
1441 int yynrhs
= yyrhsLength (yyrule
);
1442 yybool yynormal
__attribute__ ((__unused__
)) =
1443 (yystackp
->yysplitPoint
== YY_NULL
);
1444 yyGLRStackItem
* yyvsp
= (yyGLRStackItem
*) yystackp
->yytops
.yystates
[yyk
];
1447 YYUSE (yyvalp
);]b4_locations_if([
1449 ]b4_parse_param_use
[]dnl
1450 [ YYFPRINTF (stderr
, "Reducing stack %lu by rule %d (line %lu):\n",
1451 (unsigned long int) yyk
, yyrule
- 1,
1452 (unsigned long int) yyrline
[yyrule
]);
1453 /* The symbols being reduced. */
1454 for (yyi
= 0; yyi
< yynrhs
; yyi
++)
1456 YYFPRINTF (stderr
, " $%d = ", yyi
+ 1);
1457 yy_symbol_print (stderr
, yyrhs
[yyprhs
[yyrule
] + yyi
],
1458 &]b4_rhs_value(yynrhs
, yyi
+ 1)[
1459 ]b4_locations_if([, &]b4_rhs_location(yynrhs
, yyi
+ 1))[]dnl
1461 YYFPRINTF (stderr
, "\n");
1466 /** Pop items off stack #K of STACK according to grammar rule RULE,
1467 * and push back on the resulting nonterminal symbol. Perform the
1468 * semantic action associated with RULE and store its value with the
1469 * newly pushed state, if FORCEEVAL or if STACK is currently
1470 * unambiguous. Otherwise, store the deferred semantic action with
1471 * the new state. If the new state would have an identical input
1472 * position, LR state, and predecessor to an existing state on the stack,
1473 * it is identified with that existing state, eliminating stack #K from
1474 * the STACK. In this case, the (necessarily deferred) semantic value is
1475 * added to the options for the existing state's semantic value.
1477 static inline YYRESULTTAG
1478 yyglrReduce (yyGLRStack
* yystackp
, size_t yyk
, yyRuleNum yyrule
,
1479 yybool yyforceEval
]b4_user_formals
[)
1481 size_t yyposn
= yystackp
->yytops
.yystates
[yyk
]->yyposn
;
1483 if (yyforceEval
|| yystackp
->yysplitPoint
== YY_NULL
)
1485 YYSTYPE yysval
;]b4_locations_if([
1488 YY_REDUCE_PRINT ((yystackp
, yyk
, yyrule
, &yysval
]b4_locuser_args([&yyloc
])[));
1489 YYCHK (yydoAction (yystackp
, yyk
, yyrule
, &yysval
]b4_locuser_args([&yyloc
])[));
1490 YY_SYMBOL_PRINT ("-> $$ =", yyr1
[yyrule
], &yysval
, &yyloc
);
1491 yyglrShift (yystackp
, yyk
,
1492 yyLRgotoState (yystackp
->yytops
.yystates
[yyk
]->yylrState
,
1493 yylhsNonterm (yyrule
)),
1494 yyposn
, &yysval
]b4_locations_if([, &yyloc
])[);
1500 yyGLRState
* yys
, *yys0
= yystackp
->yytops
.yystates
[yyk
];
1501 yyStateNum yynewLRState
;
1503 for (yys
= yystackp
->yytops
.yystates
[yyk
], yyn
= yyrhsLength (yyrule
);
1509 yyupdateSplit (yystackp
, yys
);
1510 yynewLRState
= yyLRgotoState (yys
->yylrState
, yylhsNonterm (yyrule
));
1512 "Reduced stack %lu by rule #%d; action deferred. Now in state %d.\n",
1513 (unsigned long int) yyk
, yyrule
- 1, yynewLRState
));
1514 for (yyi
= 0; yyi
< yystackp
->yytops
.yysize
; yyi
+= 1)
1515 if (yyi
!= yyk
&& yystackp
->yytops
.yystates
[yyi
] != YY_NULL
)
1517 yyGLRState
* yyp
, *yysplit
= yystackp
->yysplitPoint
;
1518 yyp
= yystackp
->yytops
.yystates
[yyi
];
1519 while (yyp
!= yys
&& yyp
!= yysplit
&& yyp
->yyposn
>= yyposn
)
1521 if (yyp
->yylrState
== yynewLRState
&& yyp
->yypred
== yys
)
1523 yyaddDeferredAction (yystackp
, yyk
, yyp
, yys0
, yyrule
);
1524 yymarkStackDeleted (yystackp
, yyk
);
1525 YYDPRINTF ((stderr
, "Merging stack %lu into stack %lu.\n",
1526 (unsigned long int) yyk
,
1527 (unsigned long int) yyi
));
1533 yystackp
->yytops
.yystates
[yyk
] = yys
;
1534 yyglrShiftDefer (yystackp
, yyk
, yynewLRState
, yyposn
, yys0
, yyrule
);
1540 yysplitStack (yyGLRStack
* yystackp
, size_t yyk
)
1542 if (yystackp
->yysplitPoint
== YY_NULL
)
1544 YYASSERT (yyk
== 0);
1545 yystackp
->yysplitPoint
= yystackp
->yytops
.yystates
[yyk
];
1547 if (yystackp
->yytops
.yysize
>= yystackp
->yytops
.yycapacity
)
1549 yyGLRState
** yynewStates
;
1550 yybool
* yynewLookaheadNeeds
;
1552 yynewStates
= YY_NULL
;
1554 if (yystackp
->yytops
.yycapacity
1555 > (YYSIZEMAX
/ (2 * sizeof yynewStates
[0])))
1556 yyMemoryExhausted (yystackp
);
1557 yystackp
->yytops
.yycapacity
*= 2;
1560 (yyGLRState
**) YYREALLOC (yystackp
->yytops
.yystates
,
1561 (yystackp
->yytops
.yycapacity
1562 * sizeof yynewStates
[0]));
1563 if (yynewStates
== YY_NULL
)
1564 yyMemoryExhausted (yystackp
);
1565 yystackp
->yytops
.yystates
= yynewStates
;
1567 yynewLookaheadNeeds
=
1568 (yybool
*) YYREALLOC (yystackp
->yytops
.yylookaheadNeeds
,
1569 (yystackp
->yytops
.yycapacity
1570 * sizeof yynewLookaheadNeeds
[0]));
1571 if (yynewLookaheadNeeds
== YY_NULL
)
1572 yyMemoryExhausted (yystackp
);
1573 yystackp
->yytops
.yylookaheadNeeds
= yynewLookaheadNeeds
;
1575 yystackp
->yytops
.yystates
[yystackp
->yytops
.yysize
]
1576 = yystackp
->yytops
.yystates
[yyk
];
1577 yystackp
->yytops
.yylookaheadNeeds
[yystackp
->yytops
.yysize
]
1578 = yystackp
->yytops
.yylookaheadNeeds
[yyk
];
1579 yystackp
->yytops
.yysize
+= 1;
1580 return yystackp
->yytops
.yysize
-1;
1583 /** True iff Y0 and Y1 represent identical options at the top level.
1584 * That is, they represent the same rule applied to RHS symbols
1585 * that produce the same terminal symbols. */
1587 yyidenticalOptions (yySemanticOption
* yyy0
, yySemanticOption
* yyy1
)
1589 if (yyy0
->yyrule
== yyy1
->yyrule
)
1591 yyGLRState
*yys0
, *yys1
;
1593 for (yys0
= yyy0
->yystate
, yys1
= yyy1
->yystate
,
1594 yyn
= yyrhsLength (yyy0
->yyrule
);
1596 yys0
= yys0
->yypred
, yys1
= yys1
->yypred
, yyn
-= 1)
1597 if (yys0
->yyposn
!= yys1
->yyposn
)
1605 /** Assuming identicalOptions (Y0,Y1), destructively merge the
1606 * alternative semantic values for the RHS-symbols of Y1 and Y0. */
1608 yymergeOptionSets (yySemanticOption
* yyy0
, yySemanticOption
* yyy1
)
1610 yyGLRState
*yys0
, *yys1
;
1612 for (yys0
= yyy0
->yystate
, yys1
= yyy1
->yystate
,
1613 yyn
= yyrhsLength (yyy0
->yyrule
);
1615 yys0
= yys0
->yypred
, yys1
= yys1
->yypred
, yyn
-= 1)
1619 else if (yys0
->yyresolved
)
1621 yys1
->yyresolved
= yytrue
;
1622 yys1
->yysemantics
.yysval
= yys0
->yysemantics
.yysval
;
1624 else if (yys1
->yyresolved
)
1626 yys0
->yyresolved
= yytrue
;
1627 yys0
->yysemantics
.yysval
= yys1
->yysemantics
.yysval
;
1631 yySemanticOption
** yyz0p
;
1632 yySemanticOption
* yyz1
;
1633 yyz0p
= &yys0
->yysemantics
.yyfirstVal
;
1634 yyz1
= yys1
->yysemantics
.yyfirstVal
;
1635 while (YYID (yytrue
))
1637 if (yyz1
== *yyz0p
|| yyz1
== YY_NULL
)
1639 else if (*yyz0p
== YY_NULL
)
1644 else if (*yyz0p
< yyz1
)
1646 yySemanticOption
* yyz
= *yyz0p
;
1648 yyz1
= yyz1
->yynext
;
1649 (*yyz0p
)->yynext
= yyz
;
1651 yyz0p
= &(*yyz0p
)->yynext
;
1653 yys1
->yysemantics
.yyfirstVal
= yys0
->yysemantics
.yyfirstVal
;
1658 /** Y0 and Y1 represent two possible actions to take in a given
1659 * parsing state; return 0 if no combination is possible,
1660 * 1 if user-mergeable, 2 if Y0 is preferred, 3 if Y1 is preferred. */
1662 yypreference (yySemanticOption
* y0
, yySemanticOption
* y1
)
1664 yyRuleNum r0
= y0
->yyrule
, r1
= y1
->yyrule
;
1665 int p0
= yydprec
[r0
], p1
= yydprec
[r1
];
1669 if (yymerger
[r0
] == 0 || yymerger
[r0
] != yymerger
[r1
])
1674 if (p0
== 0 || p1
== 0)
1683 static YYRESULTTAG
yyresolveValue (yyGLRState
* yys
,
1684 yyGLRStack
* yystackp
]b4_user_formals
[);
1687 /** Resolve the previous N states starting at and including state S. If result
1688 * != yyok, some states may have been left unresolved possibly with empty
1689 * semantic option chains. Regardless of whether result = yyok, each state
1690 * has been left with consistent data so that yydestroyGLRState can be invoked
1693 yyresolveStates (yyGLRState
* yys
, int yyn
,
1694 yyGLRStack
* yystackp
]b4_user_formals
[)
1698 YYASSERT (yys
->yypred
);
1699 YYCHK (yyresolveStates (yys
->yypred
, yyn
-1, yystackp
]b4_user_args
[));
1700 if (! yys
->yyresolved
)
1701 YYCHK (yyresolveValue (yys
, yystackp
]b4_user_args
[));
1706 /** Resolve the states for the RHS of OPT, perform its user action, and return
1707 * the semantic value and location. Regardless of whether result = yyok, all
1708 * RHS states have been destroyed (assuming the user action destroys all RHS
1709 * semantic values if invoked). */
1711 yyresolveAction (yySemanticOption
* yyopt
, yyGLRStack
* yystackp
,
1712 YYSTYPE
* yyvalp
]b4_locuser_formals
[)
1714 yyGLRStackItem yyrhsVals
[YYMAXRHS
+ YYMAXLEFT
+ 1];
1717 YYSTYPE yylval_current
;]b4_locations_if([
1718 YYLTYPE yylloc_current
;])[
1721 yynrhs
= yyrhsLength (yyopt
->yyrule
);
1722 yyflag
= yyresolveStates (yyopt
->yystate
, yynrhs
, yystackp
]b4_user_args
[);
1726 for (yys
= yyopt
->yystate
; yynrhs
> 0; yys
= yys
->yypred
, yynrhs
-= 1)
1727 yydestroyGLRState ("Cleanup: popping", yys
]b4_user_args
[);
1731 yyrhsVals
[YYMAXRHS
+ YYMAXLEFT
].yystate
.yypred
= yyopt
->yystate
;]b4_locations_if([[
1733 /* Set default location. */
1734 yyrhsVals
[YYMAXRHS
+ YYMAXLEFT
- 1].yystate
.yyloc
= yyopt
->yystate
->yyloc
;]])[
1735 yychar_current
= yychar
;
1736 yylval_current
= yylval
;]b4_locations_if([
1737 yylloc_current
= yylloc
;])[
1738 yychar
= yyopt
->yyrawchar
;
1739 yylval
= yyopt
->yyval
;]b4_locations_if([
1740 yylloc
= yyopt
->yyloc
;])[
1741 yyflag
= yyuserAction (yyopt
->yyrule
, yynrhs
,
1742 yyrhsVals
+ YYMAXRHS
+ YYMAXLEFT
- 1,
1743 yystackp
, yyvalp
]b4_locuser_args
[);
1744 yychar
= yychar_current
;
1745 yylval
= yylval_current
;]b4_locations_if([
1746 yylloc
= yylloc_current
;])[
1752 yyreportTree (yySemanticOption
* yyx
, int yyindent
)
1754 int yynrhs
= yyrhsLength (yyx
->yyrule
);
1757 yyGLRState
* yystates
[1 + YYMAXRHS
];
1758 yyGLRState yyleftmost_state
;
1760 for (yyi
= yynrhs
, yys
= yyx
->yystate
; 0 < yyi
; yyi
-= 1, yys
= yys
->yypred
)
1761 yystates
[yyi
] = yys
;
1764 yyleftmost_state
.yyposn
= 0;
1765 yystates
[0] = &yyleftmost_state
;
1770 if (yyx
->yystate
->yyposn
< yys
->yyposn
+ 1)
1771 YYFPRINTF (stderr
, "%*s%s -> <Rule %d, empty>\n",
1772 yyindent
, "", yytokenName (yylhsNonterm (yyx
->yyrule
)),
1775 YYFPRINTF (stderr
, "%*s%s -> <Rule %d, tokens %lu .. %lu>\n",
1776 yyindent
, "", yytokenName (yylhsNonterm (yyx
->yyrule
)),
1777 yyx
->yyrule
- 1, (unsigned long int) (yys
->yyposn
+ 1),
1778 (unsigned long int) yyx
->yystate
->yyposn
);
1779 for (yyi
= 1; yyi
<= yynrhs
; yyi
+= 1)
1781 if (yystates
[yyi
]->yyresolved
)
1783 if (yystates
[yyi
-1]->yyposn
+1 > yystates
[yyi
]->yyposn
)
1784 YYFPRINTF (stderr
, "%*s%s <empty>\n", yyindent
+2, "",
1785 yytokenName (yyrhs
[yyprhs
[yyx
->yyrule
]+yyi
-1]));
1787 YYFPRINTF (stderr
, "%*s%s <tokens %lu .. %lu>\n", yyindent
+2, "",
1788 yytokenName (yyrhs
[yyprhs
[yyx
->yyrule
]+yyi
-1]),
1789 (unsigned long int) (yystates
[yyi
- 1]->yyposn
+ 1),
1790 (unsigned long int) yystates
[yyi
]->yyposn
);
1793 yyreportTree (yystates
[yyi
]->yysemantics
.yyfirstVal
, yyindent
+2);
1798 /*ARGSUSED*/ static YYRESULTTAG
1799 yyreportAmbiguity (yySemanticOption
* yyx0
,
1800 yySemanticOption
* yyx1
]b4_pure_formals
[)
1806 YYFPRINTF (stderr
, "Ambiguity detected.\n");
1807 YYFPRINTF (stderr
, "Option 1,\n");
1808 yyreportTree (yyx0
, 2);
1809 YYFPRINTF (stderr
, "\nOption 2,\n");
1810 yyreportTree (yyx1
, 2);
1811 YYFPRINTF (stderr
, "\n");
1814 yyerror (]b4_yyerror_args
[YY_("syntax is ambiguous"));
1816 }]b4_locations_if([[
1818 /** Starting at and including state S1, resolve the location for each of the
1819 * previous N1 states that is unresolved. The first semantic option of a state
1820 * is always chosen. */
1822 yyresolveLocations (yyGLRState
* yys1
, int yyn1
,
1823 yyGLRStack
*yystackp
]b4_user_formals
[)
1827 yyresolveLocations (yys1
->yypred
, yyn1
- 1, yystackp
]b4_user_args
[);
1828 if (!yys1
->yyresolved
)
1830 yySemanticOption
*yyoption
;
1831 yyGLRStackItem yyrhsloc
[1 + YYMAXRHS
];
1834 YYSTYPE yylval_current
;
1835 YYLTYPE yylloc_current
;
1836 yyoption
= yys1
->yysemantics
.yyfirstVal
;
1837 YYASSERT (yyoption
!= YY_NULL
);
1838 yynrhs
= yyrhsLength (yyoption
->yyrule
);
1843 yyresolveLocations (yyoption
->yystate
, yynrhs
,
1844 yystackp
]b4_user_args
[);
1845 for (yys
= yyoption
->yystate
, yyn
= yynrhs
;
1847 yys
= yys
->yypred
, yyn
-= 1)
1848 yyrhsloc
[yyn
].yystate
.yyloc
= yys
->yyloc
;
1852 /* Both yyresolveAction and yyresolveLocations traverse the GSS
1853 in reverse rightmost order. It is only necessary to invoke
1854 yyresolveLocations on a subforest for which yyresolveAction
1855 would have been invoked next had an ambiguity not been
1856 detected. Thus the location of the previous state (but not
1857 necessarily the previous state itself) is guaranteed to be
1858 resolved already. */
1859 yyGLRState
*yyprevious
= yyoption
->yystate
;
1860 yyrhsloc
[0].yystate
.yyloc
= yyprevious
->yyloc
;
1862 yychar_current
= yychar
;
1863 yylval_current
= yylval
;
1864 yylloc_current
= yylloc
;
1865 yychar
= yyoption
->yyrawchar
;
1866 yylval
= yyoption
->yyval
;
1867 yylloc
= yyoption
->yyloc
;
1868 YYLLOC_DEFAULT ((yys1
->yyloc
), yyrhsloc
, yynrhs
);
1869 yychar
= yychar_current
;
1870 yylval
= yylval_current
;
1871 yylloc
= yylloc_current
;
1876 /** Resolve the ambiguity represented in state S, perform the indicated
1877 * actions, and set the semantic value of S. If result != yyok, the chain of
1878 * semantic options in S has been cleared instead or it has been left
1879 * unmodified except that redundant options may have been removed. Regardless
1880 * of whether result = yyok, S has been left with consistent data so that
1881 * yydestroyGLRState can be invoked if necessary. */
1883 yyresolveValue (yyGLRState
* yys
, yyGLRStack
* yystackp
]b4_user_formals
[)
1885 yySemanticOption
* yyoptionList
= yys
->yysemantics
.yyfirstVal
;
1886 yySemanticOption
* yybest
= yyoptionList
;
1887 yySemanticOption
** yypp
;
1888 yybool yymerge
= yyfalse
;
1890 YYRESULTTAG yyflag
;]b4_locations_if([
1891 YYLTYPE
*yylocp
= &yys
->yyloc
;])[
1893 for (yypp
= &yyoptionList
->yynext
; *yypp
!= YY_NULL
; )
1895 yySemanticOption
* yyp
= *yypp
;
1897 if (yyidenticalOptions (yybest
, yyp
))
1899 yymergeOptionSets (yybest
, yyp
);
1900 *yypp
= yyp
->yynext
;
1904 switch (yypreference (yybest
, yyp
))
1906 case 0:]b4_locations_if([[
1907 yyresolveLocations (yys
, 1, yystackp
]b4_user_args
[);]])[
1908 return yyreportAmbiguity (yybest
, yyp
]b4_pure_args
[);
1920 /* This cannot happen so it is not worth a YYASSERT (yyfalse),
1921 but some compilers complain if the default case is
1925 yypp
= &yyp
->yynext
;
1931 yySemanticOption
* yyp
;
1932 int yyprec
= yydprec
[yybest
->yyrule
];
1933 yyflag
= yyresolveAction (yybest
, yystackp
, &yysval
]b4_locuser_args
[);
1935 for (yyp
= yybest
->yynext
; yyp
!= YY_NULL
; yyp
= yyp
->yynext
)
1937 if (yyprec
== yydprec
[yyp
->yyrule
])
1939 YYSTYPE yysval_other
;]b4_locations_if([
1941 yyflag
= yyresolveAction (yyp
, yystackp
, &yysval_other
]b4_locuser_args([&yydummy
])[);
1944 yydestruct ("Cleanup: discarding incompletely merged value for",
1945 yystos
[yys
->yylrState
],
1946 &yysval
]b4_locuser_args
[);
1949 yyuserMerge (yymerger
[yyp
->yyrule
], &yysval
, &yysval_other
);
1954 yyflag
= yyresolveAction (yybest
, yystackp
, &yysval
]b4_locuser_args([yylocp
])[);
1958 yys
->yyresolved
= yytrue
;
1959 yys
->yysemantics
.yysval
= yysval
;
1962 yys
->yysemantics
.yyfirstVal
= YY_NULL
;
1967 yyresolveStack (yyGLRStack
* yystackp
]b4_user_formals
[)
1969 if (yystackp
->yysplitPoint
!= YY_NULL
)
1974 for (yyn
= 0, yys
= yystackp
->yytops
.yystates
[0];
1975 yys
!= yystackp
->yysplitPoint
;
1976 yys
= yys
->yypred
, yyn
+= 1)
1978 YYCHK (yyresolveStates (yystackp
->yytops
.yystates
[0], yyn
, yystackp
1985 yycompressStack (yyGLRStack
* yystackp
)
1987 yyGLRState
* yyp
, *yyq
, *yyr
;
1989 if (yystackp
->yytops
.yysize
!= 1 || yystackp
->yysplitPoint
== YY_NULL
)
1992 for (yyp
= yystackp
->yytops
.yystates
[0], yyq
= yyp
->yypred
, yyr
= YY_NULL
;
1993 yyp
!= yystackp
->yysplitPoint
;
1994 yyr
= yyp
, yyp
= yyq
, yyq
= yyp
->yypred
)
1997 yystackp
->yyspaceLeft
+= yystackp
->yynextFree
- yystackp
->yyitems
;
1998 yystackp
->yynextFree
= ((yyGLRStackItem
*) yystackp
->yysplitPoint
) + 1;
1999 yystackp
->yyspaceLeft
-= yystackp
->yynextFree
- yystackp
->yyitems
;
2000 yystackp
->yysplitPoint
= YY_NULL
;
2001 yystackp
->yylastDeleted
= YY_NULL
;
2003 while (yyr
!= YY_NULL
)
2005 yystackp
->yynextFree
->yystate
= *yyr
;
2007 yystackp
->yynextFree
->yystate
.yypred
= &yystackp
->yynextFree
[-1].yystate
;
2008 yystackp
->yytops
.yystates
[0] = &yystackp
->yynextFree
->yystate
;
2009 yystackp
->yynextFree
+= 1;
2010 yystackp
->yyspaceLeft
-= 1;
2015 yyprocessOneStack (yyGLRStack
* yystackp
, size_t yyk
,
2016 size_t yyposn
]b4_pure_formals
[)
2019 const short int* yyconflicts
;
2022 while (yystackp
->yytops
.yystates
[yyk
] != YY_NULL
)
2024 yyStateNum yystate
= yystackp
->yytops
.yystates
[yyk
]->yylrState
;
2025 YYDPRINTF ((stderr
, "Stack %lu Entering state %d\n",
2026 (unsigned long int) yyk
, yystate
));
2028 YYASSERT (yystate
!= YYFINAL
);
2030 if (yyisDefaultedState (yystate
))
2032 yyrule
= yydefaultAction (yystate
);
2035 YYDPRINTF ((stderr
, "Stack %lu dies.\n",
2036 (unsigned long int) yyk
));
2037 yymarkStackDeleted (yystackp
, yyk
);
2040 YYCHK (yyglrReduce (yystackp
, yyk
, yyrule
, yyfalse
]b4_user_args
[));
2045 yystackp
->yytops
.yylookaheadNeeds
[yyk
] = yytrue
;
2046 if (yychar
== YYEMPTY
)
2048 YYDPRINTF ((stderr
, "Reading a token: "));
2052 if (yychar
<= YYEOF
)
2054 yychar
= yytoken
= YYEOF
;
2055 YYDPRINTF ((stderr
, "Now at end of input.\n"));
2059 yytoken
= YYTRANSLATE (yychar
);
2060 YY_SYMBOL_PRINT ("Next token is", yytoken
, &yylval
, &yylloc
);
2063 yygetLRActions (yystate
, yytoken
, &yyaction
, &yyconflicts
);
2065 while (*yyconflicts
!= 0)
2067 size_t yynewStack
= yysplitStack (yystackp
, yyk
);
2068 YYDPRINTF ((stderr
, "Splitting off stack %lu from %lu.\n",
2069 (unsigned long int) yynewStack
,
2070 (unsigned long int) yyk
));
2071 YYCHK (yyglrReduce (yystackp
, yynewStack
,
2072 *yyconflicts
, yyfalse
]b4_user_args
[));
2073 YYCHK (yyprocessOneStack (yystackp
, yynewStack
,
2074 yyposn
]b4_pure_args
[));
2078 if (yyisShiftAction (yyaction
))
2080 else if (yyisErrorAction (yyaction
))
2082 YYDPRINTF ((stderr
, "Stack %lu dies.\n",
2083 (unsigned long int) yyk
));
2084 yymarkStackDeleted (yystackp
, yyk
);
2088 YYCHK (yyglrReduce (yystackp
, yyk
, -yyaction
,
2089 yyfalse
]b4_user_args
[));
2095 /*ARGSUSED*/ static void
2096 yyreportSyntaxError (yyGLRStack
* yystackp
]b4_user_formals
[)
2098 if (yystackp
->yyerrState
!= 0)
2100 #if ! YYERROR_VERBOSE
2101 yyerror (]b4_lyyerror_args
[YY_("syntax error"));
2103 yySymbol yytoken
= yychar
== YYEMPTY
? YYEMPTY
: YYTRANSLATE (yychar
);
2104 size_t yysize0
= yytnamerr (YY_NULL
, yytokenName (yytoken
));
2105 size_t yysize
= yysize0
;
2107 yybool yysize_overflow
= yyfalse
;
2108 char* yymsg
= YY_NULL
;
2109 enum { YYERROR_VERBOSE_ARGS_MAXIMUM
= 5 };
2110 /* Internationalized format string. */
2111 const char *yyformat
= YY_NULL
;
2112 /* Arguments of yyformat. */
2113 char const *yyarg
[YYERROR_VERBOSE_ARGS_MAXIMUM
];
2114 /* Number of reported tokens (one for the "unexpected", one per
2118 /* There are many possibilities here to consider:
2119 - If this state is a consistent state with a default action, then
2120 the only way this function was invoked is if the default action
2121 is an error action. In that case, don't check for expected
2122 tokens because there are none.
2123 - The only way there can be no lookahead present (in yychar) is if
2124 this state is a consistent state with a default action. Thus,
2125 detecting the absence of a lookahead is sufficient to determine
2126 that there is no unexpected or expected token to report. In that
2127 case, just report a simple "syntax error".
2128 - Don't assume there isn't a lookahead just because this state is a
2129 consistent state with a default action. There might have been a
2130 previous inconsistent state, consistent state with a non-default
2131 action, or user semantic action that manipulated yychar.
2132 - Of course, the expected token list depends on states to have
2133 correct lookahead information, and it depends on the parser not
2134 to perform extra reductions after fetching a lookahead from the
2135 scanner and before detecting a syntax error. Thus, state merging
2136 (from LALR or IELR) and default reductions corrupt the expected
2137 token list. However, the list is correct for canonical LR with
2138 one exception: it will still contain any token that will not be
2139 accepted due to an error action in a later state.
2141 if (yytoken
!= YYEMPTY
)
2143 int yyn
= yypact
[yystackp
->yytops
.yystates
[0]->yylrState
];
2144 yyarg
[yycount
++] = yytokenName (yytoken
);
2145 if (!yypact_value_is_default (yyn
))
2147 /* Start YYX at -YYN if negative to avoid negative indexes in
2148 YYCHECK. In other words, skip the first -YYN actions for this
2149 state because they are default actions. */
2150 int yyxbegin
= yyn
< 0 ? -yyn
: 0;
2151 /* Stay within bounds of both yycheck and yytname. */
2152 int yychecklim
= YYLAST
- yyn
+ 1;
2153 int yyxend
= yychecklim
< YYNTOKENS
? yychecklim
: YYNTOKENS
;
2155 for (yyx
= yyxbegin
; yyx
< yyxend
; ++yyx
)
2156 if (yycheck
[yyx
+ yyn
] == yyx
&& yyx
!= YYTERROR
2157 && !yytable_value_is_error (yytable
[yyx
+ yyn
]))
2159 if (yycount
== YYERROR_VERBOSE_ARGS_MAXIMUM
)
2165 yyarg
[yycount
++] = yytokenName (yyx
);
2166 yysize1
= yysize
+ yytnamerr (YY_NULL
, yytokenName (yyx
));
2167 yysize_overflow
|= yysize1
< yysize
;
2175 #define YYCASE_(N, S) \
2179 YYCASE_(0, YY_("syntax error"));
2180 YYCASE_(1, YY_("syntax error, unexpected %s"));
2181 YYCASE_(2, YY_("syntax error, unexpected %s, expecting %s"));
2182 YYCASE_(3, YY_("syntax error, unexpected %s, expecting %s or %s"));
2183 YYCASE_(4, YY_("syntax error, unexpected %s, expecting %s or %s or %s"));
2184 YYCASE_(5, YY_("syntax error, unexpected %s, expecting %s or %s or %s or %s"));
2188 yysize1
= yysize
+ strlen (yyformat
);
2189 yysize_overflow
|= yysize1
< yysize
;
2192 if (!yysize_overflow
)
2193 yymsg
= (char *) YYMALLOC (yysize
);
2199 while ((*yyp
= *yyformat
))
2201 if (*yyp
== '%' && yyformat
[1] == 's' && yyi
< yycount
)
2203 yyp
+= yytnamerr (yyp
, yyarg
[yyi
++]);
2212 yyerror (]b4_lyyerror_args
[yymsg
);
2217 yyerror (]b4_lyyerror_args
[YY_("syntax error"));
2218 yyMemoryExhausted (yystackp
);
2220 #endif /* YYERROR_VERBOSE */
2224 /* Recover from a syntax error on *YYSTACKP, assuming that *YYSTACKP->YYTOKENP,
2225 yylval, and yylloc are the syntactic category, semantic value, and location
2226 of the lookahead. */
2227 /*ARGSUSED*/ static void
2228 yyrecoverSyntaxError (yyGLRStack
* yystackp
]b4_user_formals
[)
2233 if (yystackp
->yyerrState
== 3)
2234 /* We just shifted the error token and (perhaps) took some
2235 reductions. Skip tokens until we can proceed. */
2236 while (YYID (yytrue
))
2239 if (yychar
== YYEOF
)
2240 yyFail (yystackp
][]b4_lpure_args
[, YY_NULL
);
2241 if (yychar
!= YYEMPTY
)
2242 {]b4_locations_if([[
2243 /* We throw away the lookahead, but the error range
2244 of the shifted error token must take it into account. */
2245 yyGLRState
*yys
= yystackp
->yytops
.yystates
[0];
2246 yyGLRStackItem yyerror_range
[3];
2247 yyerror_range
[1].yystate
.yyloc
= yys
->yyloc
;
2248 yyerror_range
[2].yystate
.yyloc
= yylloc
;
2249 YYLLOC_DEFAULT ((yys
->yyloc
), yyerror_range
, 2);]])[
2250 yytoken
= YYTRANSLATE (yychar
);
2251 yydestruct ("Error: discarding",
2252 yytoken
, &yylval
]b4_locuser_args([&yylloc
])[);
2254 YYDPRINTF ((stderr
, "Reading a token: "));
2256 if (yychar
<= YYEOF
)
2258 yychar
= yytoken
= YYEOF
;
2259 YYDPRINTF ((stderr
, "Now at end of input.\n"));
2263 yytoken
= YYTRANSLATE (yychar
);
2264 YY_SYMBOL_PRINT ("Next token is", yytoken
, &yylval
, &yylloc
);
2266 yyj
= yypact
[yystackp
->yytops
.yystates
[0]->yylrState
];
2267 if (yypact_value_is_default (yyj
))
2270 if (yyj
< 0 || YYLAST
< yyj
|| yycheck
[yyj
] != yytoken
)
2272 if (yydefact
[yystackp
->yytops
.yystates
[0]->yylrState
] != 0)
2275 else if (! yytable_value_is_error (yytable
[yyj
]))
2279 /* Reduce to one stack. */
2280 for (yyk
= 0; yyk
< yystackp
->yytops
.yysize
; yyk
+= 1)
2281 if (yystackp
->yytops
.yystates
[yyk
] != YY_NULL
)
2283 if (yyk
>= yystackp
->yytops
.yysize
)
2284 yyFail (yystackp
][]b4_lpure_args
[, YY_NULL
);
2285 for (yyk
+= 1; yyk
< yystackp
->yytops
.yysize
; yyk
+= 1)
2286 yymarkStackDeleted (yystackp
, yyk
);
2287 yyremoveDeletes (yystackp
);
2288 yycompressStack (yystackp
);
2290 /* Now pop stack until we find a state that shifts the error token. */
2291 yystackp
->yyerrState
= 3;
2292 while (yystackp
->yytops
.yystates
[0] != YY_NULL
)
2294 yyGLRState
*yys
= yystackp
->yytops
.yystates
[0];
2295 yyj
= yypact
[yys
->yylrState
];
2296 if (! yypact_value_is_default (yyj
))
2299 if (0 <= yyj
&& yyj
<= YYLAST
&& yycheck
[yyj
] == YYTERROR
2300 && yyisShiftAction (yytable
[yyj
]))
2302 /* Shift the error token. */]b4_locations_if([[
2303 /* First adjust its location.*/
2305 yystackp
->yyerror_range
[2].yystate
.yyloc
= yylloc
;
2306 YYLLOC_DEFAULT (yyerrloc
, (yystackp
->yyerror_range
), 2);]])[
2307 YY_SYMBOL_PRINT ("Shifting", yystos
[yytable
[yyj
]],
2308 &yylval
, &yyerrloc
);
2309 yyglrShift (yystackp
, 0, yytable
[yyj
],
2310 yys
->yyposn
, &yylval
]b4_locations_if([, &yyerrloc
])[);
2311 yys
= yystackp
->yytops
.yystates
[0];
2314 }]b4_locations_if([[
2315 yystackp
->yyerror_range
[1].yystate
.yyloc
= yys
->yyloc
;]])[
2316 if (yys
->yypred
!= YY_NULL
)
2317 yydestroyGLRState ("Error: popping", yys
]b4_user_args
[);
2318 yystackp
->yytops
.yystates
[0] = yys
->yypred
;
2319 yystackp
->yynextFree
-= 1;
2320 yystackp
->yyspaceLeft
+= 1;
2322 if (yystackp
->yytops
.yystates
[0] == YY_NULL
)
2323 yyFail (yystackp
][]b4_lpure_args
[, YY_NULL
);
2326 #define YYCHK1(YYE) \
2336 goto yyuser_error; \
2347 ]b4_c_ansi_function_def([yyparse
], [int], b4_parse_param
)[
2351 yyGLRStack
* const yystackp
= &yystack
;
2354 YYDPRINTF ((stderr
, "Starting parse\n"));
2357 yylval
= yyval_default
;
2359 #if defined YYLTYPE_IS_TRIVIAL && YYLTYPE_IS_TRIVIAL
2360 yylloc
.first_line
= yylloc
.last_line
= ]b4_location_initial_line
[;
2361 yylloc
.first_column
= yylloc
.last_column
= ]b4_location_initial_column
[;
2364 m4_ifdef([b4_initial_action
], [
2365 m4_pushdef([b4_at_dollar
], [yylloc
])dnl
2366 m4_pushdef([b4_dollar_dollar
], [yylval
])dnl
2367 /* User initialization code. */
2368 b4_user_initial_action
2369 m4_popdef([b4_dollar_dollar
])dnl
2370 m4_popdef([b4_at_dollar
])])dnl
2372 if (! yyinitGLRStack (yystackp
, YYINITDEPTH
))
2373 goto yyexhaustedlab
;
2374 switch (YYSETJMP (yystack
.yyexception_buffer
))
2377 case 1: goto yyabortlab
;
2378 case 2: goto yyexhaustedlab
;
2379 default: goto yybuglab
;
2381 yyglrShift (&yystack
, 0, 0, 0, &yylval
]b4_locations_if([, &yylloc
])[);
2384 while (YYID (yytrue
))
2386 /* For efficiency, we have two loops, the first of which is
2387 specialized to deterministic operation (single stack, no
2388 potential ambiguity). */
2390 while (YYID (yytrue
))
2394 const short int* yyconflicts
;
2396 yyStateNum yystate
= yystack
.yytops
.yystates
[0]->yylrState
;
2397 YYDPRINTF ((stderr
, "Entering state %d\n", yystate
));
2398 if (yystate
== YYFINAL
)
2400 if (yyisDefaultedState (yystate
))
2402 yyrule
= yydefaultAction (yystate
);
2405 ]b4_locations_if([[ yystack
.yyerror_range
[1].yystate
.yyloc
= yylloc
;]])[
2406 yyreportSyntaxError (&yystack
]b4_user_args
[);
2409 YYCHK1 (yyglrReduce (&yystack
, 0, yyrule
, yytrue
]b4_user_args
[));
2414 if (yychar
== YYEMPTY
)
2416 YYDPRINTF ((stderr
, "Reading a token: "));
2420 if (yychar
<= YYEOF
)
2422 yychar
= yytoken
= YYEOF
;
2423 YYDPRINTF ((stderr
, "Now at end of input.\n"));
2427 yytoken
= YYTRANSLATE (yychar
);
2428 YY_SYMBOL_PRINT ("Next token is", yytoken
, &yylval
, &yylloc
);
2431 yygetLRActions (yystate
, yytoken
, &yyaction
, &yyconflicts
);
2432 if (*yyconflicts
!= 0)
2434 if (yyisShiftAction (yyaction
))
2436 YY_SYMBOL_PRINT ("Shifting", yytoken
, &yylval
, &yylloc
);
2439 yyglrShift (&yystack
, 0, yyaction
, yyposn
, &yylval
]b4_locations_if([, &yylloc
])[);
2440 if (0 < yystack
.yyerrState
)
2441 yystack
.yyerrState
-= 1;
2443 else if (yyisErrorAction (yyaction
))
2445 ]b4_locations_if([[ yystack
.yyerror_range
[1].yystate
.yyloc
= yylloc
;]])[
2446 yyreportSyntaxError (&yystack
]b4_user_args
[);
2450 YYCHK1 (yyglrReduce (&yystack
, 0, -yyaction
, yytrue
]b4_user_args
[));
2454 while (YYID (yytrue
))
2456 yySymbol yytoken_to_shift
;
2459 for (yys
= 0; yys
< yystack
.yytops
.yysize
; yys
+= 1)
2460 yystackp
->yytops
.yylookaheadNeeds
[yys
] = yychar
!= YYEMPTY
;
2462 /* yyprocessOneStack returns one of three things:
2464 - An error flag. If the caller is yyprocessOneStack, it
2465 immediately returns as well. When the caller is finally
2466 yyparse, it jumps to an error label via YYCHK1.
2468 - yyok, but yyprocessOneStack has invoked yymarkStackDeleted
2469 (&yystack, yys), which sets the top state of yys to NULL. Thus,
2470 yyparse's following invocation of yyremoveDeletes will remove
2473 - yyok, when ready to shift a token.
2475 Except in the first case, yyparse will invoke yyremoveDeletes and
2476 then shift the next token onto all remaining stacks. This
2477 synchronization of the shift (that is, after all preceding
2478 reductions on all stacks) helps prevent double destructor calls
2479 on yylval in the event of memory exhaustion. */
2481 for (yys
= 0; yys
< yystack
.yytops
.yysize
; yys
+= 1)
2482 YYCHK1 (yyprocessOneStack (&yystack
, yys
, yyposn
]b4_lpure_args
[));
2483 yyremoveDeletes (&yystack
);
2484 if (yystack
.yytops
.yysize
== 0)
2486 yyundeleteLastStack (&yystack
);
2487 if (yystack
.yytops
.yysize
== 0)
2488 yyFail (&yystack
][]b4_lpure_args
[, YY_("syntax error"));
2489 YYCHK1 (yyresolveStack (&yystack
]b4_user_args
[));
2490 YYDPRINTF ((stderr
, "Returning to deterministic operation.\n"));
2491 ]b4_locations_if([[ yystack
.yyerror_range
[1].yystate
.yyloc
= yylloc
;]])[
2492 yyreportSyntaxError (&yystack
]b4_user_args
[);
2496 /* If any yyglrShift call fails, it will fail after shifting. Thus,
2497 a copy of yylval will already be on stack 0 in the event of a
2498 failure in the following loop. Thus, yychar is set to YYEMPTY
2499 before the loop to make sure the user destructor for yylval isn't
2501 yytoken_to_shift
= YYTRANSLATE (yychar
);
2504 for (yys
= 0; yys
< yystack
.yytops
.yysize
; yys
+= 1)
2507 const short int* yyconflicts
;
2508 yyStateNum yystate
= yystack
.yytops
.yystates
[yys
]->yylrState
;
2509 yygetLRActions (yystate
, yytoken_to_shift
, &yyaction
,
2511 /* Note that yyconflicts were handled by yyprocessOneStack. */
2512 YYDPRINTF ((stderr
, "On stack %lu, ", (unsigned long int) yys
));
2513 YY_SYMBOL_PRINT ("shifting", yytoken_to_shift
, &yylval
, &yylloc
);
2514 yyglrShift (&yystack
, yys
, yyaction
, yyposn
,
2515 &yylval
]b4_locations_if([, &yylloc
])[);
2516 YYDPRINTF ((stderr
, "Stack %lu now in state #%d\n",
2517 (unsigned long int) yys
,
2518 yystack
.yytops
.yystates
[yys
]->yylrState
));
2521 if (yystack
.yytops
.yysize
== 1)
2523 YYCHK1 (yyresolveStack (&yystack
]b4_user_args
[));
2524 YYDPRINTF ((stderr
, "Returning to deterministic operation.\n"));
2525 yycompressStack (&yystack
);
2531 yyrecoverSyntaxError (&yystack
]b4_user_args
[);
2532 yyposn
= yystack
.yytops
.yystates
[0]->yyposn
;
2548 yyerror (]b4_lyyerror_args
[YY_("memory exhausted"));
2553 if (yychar
!= YYEMPTY
)
2554 yydestruct ("Cleanup: discarding lookahead",
2555 YYTRANSLATE (yychar
), &yylval
]b4_locuser_args([&yylloc
])[);
2557 /* If the stack is well-formed, pop the stack until it is empty,
2558 destroying its entries as we go. But free the stack regardless
2559 of whether it is well-formed. */
2560 if (yystack
.yyitems
)
2562 yyGLRState
** yystates
= yystack
.yytops
.yystates
;
2565 size_t yysize
= yystack
.yytops
.yysize
;
2567 for (yyk
= 0; yyk
< yysize
; yyk
+= 1)
2570 while (yystates
[yyk
])
2572 yyGLRState
*yys
= yystates
[yyk
];
2573 ]b4_locations_if([[ yystack
.yyerror_range
[1].yystate
.yyloc
= yys
->yyloc
;]]
2574 )[ if (yys
->yypred
!= YY_NULL
)
2575 yydestroyGLRState ("Cleanup: popping", yys
]b4_user_args
[);
2576 yystates
[yyk
] = yys
->yypred
;
2577 yystack
.yynextFree
-= 1;
2578 yystack
.yyspaceLeft
+= 1;
2583 yyfreeGLRStack (&yystack
);
2586 /* Make sure YYID is used. */
2587 return YYID (yyresult
);
2590 /* DEBUGGING ONLY */
2592 static void yypstack (yyGLRStack
* yystackp
, size_t yyk
)
2593 __attribute__ ((__unused__
));
2594 static void yypdumpstack (yyGLRStack
* yystackp
) __attribute__ ((__unused__
));
2597 yy_yypstack (yyGLRState
* yys
)
2601 yy_yypstack (yys
->yypred
);
2602 YYFPRINTF (stderr
, " -> ");
2604 YYFPRINTF (stderr
, "%d@@%lu", yys
->yylrState
,
2605 (unsigned long int) yys
->yyposn
);
2609 yypstates (yyGLRState
* yyst
)
2611 if (yyst
== YY_NULL
)
2612 YYFPRINTF (stderr
, "<null>");
2615 YYFPRINTF (stderr
, "\n");
2619 yypstack (yyGLRStack
* yystackp
, size_t yyk
)
2621 yypstates (yystackp
->yytops
.yystates
[yyk
]);
2624 #define YYINDEX(YYX) \
2625 ((YYX) == YY_NULL ? -1 : (yyGLRStackItem*) (YYX) - yystackp->yyitems)
2629 yypdumpstack (yyGLRStack
* yystackp
)
2631 yyGLRStackItem
* yyp
;
2633 for (yyp
= yystackp
->yyitems
; yyp
< yystackp
->yynextFree
; yyp
+= 1)
2635 YYFPRINTF (stderr
, "%3lu. ",
2636 (unsigned long int) (yyp
- yystackp
->yyitems
));
2637 if (*(yybool
*) yyp
)
2639 YYFPRINTF (stderr
, "Res: %d, LR State: %d, posn: %lu, pred: %ld",
2640 yyp
->yystate
.yyresolved
, yyp
->yystate
.yylrState
,
2641 (unsigned long int) yyp
->yystate
.yyposn
,
2642 (long int) YYINDEX (yyp
->yystate
.yypred
));
2643 if (! yyp
->yystate
.yyresolved
)
2644 YYFPRINTF (stderr
, ", firstVal: %ld",
2645 (long int) YYINDEX (yyp
->yystate
2646 .yysemantics
.yyfirstVal
));
2650 YYFPRINTF (stderr
, "Option. rule: %d, state: %ld, next: %ld",
2651 yyp
->yyoption
.yyrule
- 1,
2652 (long int) YYINDEX (yyp
->yyoption
.yystate
),
2653 (long int) YYINDEX (yyp
->yyoption
.yynext
));
2655 YYFPRINTF (stderr
, "\n");
2657 YYFPRINTF (stderr
, "Tops:");
2658 for (yyi
= 0; yyi
< yystackp
->yytops
.yysize
; yyi
+= 1)
2659 YYFPRINTF (stderr
, "%lu: %ld; ", (unsigned long int) yyi
,
2660 (long int) YYINDEX (yystackp
->yytops
.yystates
[yyi
]));
2661 YYFPRINTF (stderr
, "\n");
2668 dnl glr
.cc produces its own header
.
2670 m4_if(b4_skeleton
, ["glr.c"],
2672 [@
output(b4_spec_defines_file@
)@
2673 b4_copyright([Skeleton interface
for Bison GLR parsers in C
],
2676 b4_shared_declarations
2679 [[extern YYSTYPE
]b4_prefix
[lval
;]])
2681 b4_locations_if([b4_pure_if([],
2682 [extern YYLTYPE
]b4_prefix
[lloc
;])