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
],
166 [b4_percent_code_get([[requires]])[]dnl
168 b4_token_enums(b4_tokens
)
171 ]m4_ifdef([b4_stype
],
172 [[typedef union ]b4_union_name
[
176 # define YYSTYPE_IS_TRIVIAL 1]],
177 [m4_if(b4_tag_seen_flag
, 0,
178 [[typedef int YYSTYPE
;
179 # define YYSTYPE_IS_TRIVIAL 1]])])[
182 #if ! defined YYLTYPE && ! defined YYLTYPE_IS_DECLARED
183 typedef struct YYLTYPE
190 # define YYLTYPE_IS_DECLARED 1
191 # define YYLTYPE_IS_TRIVIAL 1
194 ]b4_percent_code_get([[provides]])[]dnl
202 # We do want M4 expansion after # for CPP macros.
205 @
output(b4_parser_file_name@
)@
206 b4_copyright([Skeleton implementation
for Bison GLR parsers in C
],
209 /* C GLR parser skeleton written by Paul Hilfinger. */
213 b4_percent_code_get([[top]])[]dnl
214 m4_if(b4_prefix
, [yy
], [],
215 [/* Substitute the variable and function names. */
216 #define yyparse b4_prefix[]parse
217 #define yylex b4_prefix[]lex
218 #define yyerror b4_prefix[]error
219 #define yylval b4_prefix[]lval
220 #define yychar b4_prefix[]char
221 #define yydebug b4_prefix[]debug
222 #define yynerrs b4_prefix[]nerrs
223 #define yylloc b4_prefix[]lloc])[
225 /* Copy the first part of user declarations. */
226 ]b4_user_pre_prologue
[
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])],
569 [YYSTYPE yylval
;]b4_locations_if([[
575 static const int YYEOF
= 0;
576 static const int YYEMPTY
= -2;
578 typedef enum { yyok
, yyaccept
, yyabort
, yyerr
} YYRESULTTAG
;
581 do { YYRESULTTAG yyflag = YYE; if (yyflag != yyok) return yyflag; } \
587 # define YYFPRINTF fprintf
590 # define YYDPRINTF(Args) \
596 ]b4_yy_symbol_print_generate([b4_c_ansi_function_def
])[
598 # define YY_SYMBOL_PRINT(Title, Type, Value, Location) \
602 YYFPRINTF (stderr, "%s ", Title); \
603 yy_symbol_print (stderr, Type, Value]b4_locuser_args([Location])[); \
604 YYFPRINTF (stderr, "\n"); \
608 /* Nonzero means print parse trace. It is left uninitialized so that
609 multiple parsers can coexist. */
614 # define YYDPRINTF(Args)
615 # define YY_SYMBOL_PRINT(Title, Type, Value, Location)
617 #endif /* !YYDEBUG */
619 /* YYINITDEPTH -- initial size of the parser's stacks. */
621 # define YYINITDEPTH ]b4_stack_depth_init[
624 /* YYMAXDEPTH -- maximum size the stacks can grow to (effective only
625 if the built-in stack extension method is used).
627 Do not make this value too large; the results are undefined if
628 SIZE_MAX < YYMAXDEPTH * sizeof (GLRStackItem)
629 evaluated with infinite-precision integer arithmetic. */
632 # define YYMAXDEPTH ]b4_stack_depth_max[
635 /* Minimum number of free items on the stack allowed after an
636 allocation. This is to allow allocation and initialization
637 to be completed by functions that call yyexpandGLRStack before the
638 stack is expanded, thus insuring that all necessary pointers get
639 properly redirected to new data. */
642 #ifndef YYSTACKEXPANDABLE
643 # if (! defined __cplusplus \
644 || (]b4_locations_if([[defined YYLTYPE_IS_TRIVIAL && YYLTYPE_IS_TRIVIAL \
645 && ]])[defined YYSTYPE_IS_TRIVIAL && YYSTYPE_IS_TRIVIAL))
646 # define YYSTACKEXPANDABLE 1
648 # define YYSTACKEXPANDABLE 0
652 #if YYSTACKEXPANDABLE
653 # define YY_RESERVE_GLRSTACK(Yystack) \
655 if (Yystack->yyspaceLeft < YYHEADROOM) \
656 yyexpandGLRStack (Yystack); \
659 # define YY_RESERVE_GLRSTACK(Yystack) \
661 if (Yystack->yyspaceLeft < YYHEADROOM) \
662 yyMemoryExhausted (Yystack); \
670 # if defined __GLIBC__ && defined _STRING_H && defined _GNU_SOURCE
671 # define yystpcpy stpcpy
673 /* Copy YYSRC to YYDEST, returning the address of the terminating '\0' in
676 yystpcpy (char *yydest
, const char *yysrc
)
679 const char *yys
= yysrc
;
681 while ((*yyd
++ = *yys
++) != '\0')
690 /* Copy to YYRES the contents of YYSTR after stripping away unnecessary
691 quotes and backslashes, so that it's suitable for yyerror. The
692 heuristic is that double-quoting is unnecessary unless the string
693 contains an apostrophe, a comma, or backslash (other than
694 backslash-backslash). YYSTR is taken from yytname. If YYRES is
695 null, do not copy; instead, return the length of what the result
698 yytnamerr (char *yyres
, const char *yystr
)
703 char const *yyp
= yystr
;
710 goto do_not_strip_quotes
;
714 goto do_not_strip_quotes
;
727 do_not_strip_quotes
: ;
731 return strlen (yystr
);
733 return yystpcpy (yyres
, yystr
) - yyres
;
737 #endif /* !YYERROR_VERBOSE */
739 /** State numbers, as in LALR(1) machine */
740 typedef int yyStateNum
;
742 /** Rule numbers, as in LALR(1) machine */
743 typedef int yyRuleNum
;
745 /** Grammar symbol */
746 typedef short int yySymbol
;
748 /** Item references, as in LALR(1) machine */
749 typedef short int yyItemNum
;
751 typedef struct yyGLRState yyGLRState
;
752 typedef struct yyGLRStateSet yyGLRStateSet
;
753 typedef struct yySemanticOption yySemanticOption
;
754 typedef union yyGLRStackItem yyGLRStackItem
;
755 typedef struct yyGLRStack yyGLRStack
;
758 /** Type tag: always true. */
760 /** Type tag for yysemantics. If true, yysval applies, otherwise
761 * yyfirstVal applies. */
763 /** Number of corresponding LALR(1) machine state. */
764 yyStateNum yylrState
;
765 /** Preceding state in this stack */
767 /** Source position of the first token produced by my symbol */
770 /** First in a chain of alternative reductions producing the
771 * non-terminal corresponding to this state, threaded through
773 yySemanticOption
* yyfirstVal
;
774 /** Semantic value for this state. */
776 } yysemantics
;]b4_locations_if([[
777 /** Source location for this state. */
781 struct yyGLRStateSet
{
782 yyGLRState
** yystates
;
783 /** During nondeterministic operation, yylookaheadNeeds tracks which
784 * stacks have actually needed the current lookahead. During deterministic
785 * operation, yylookaheadNeeds[0] is not maintained since it would merely
786 * duplicate yychar != YYEMPTY. */
787 yybool
* yylookaheadNeeds
;
788 size_t yysize
, yycapacity
;
791 struct yySemanticOption
{
792 /** Type tag: always false. */
794 /** Rule number for this reduction */
796 /** The last RHS state in the list of states to be reduced. */
798 /** The lookahead for this reduction. */
800 YYSTYPE yyval
;]b4_locations_if([[
802 /** Next sibling in chain of options. To facilitate merging,
803 * options are chained in decreasing order by address. */
804 yySemanticOption
* yynext
;
807 /** Type of the items in the GLR stack. The yyisState field
808 * indicates which item of the union is valid. */
809 union yyGLRStackItem
{
811 yySemanticOption yyoption
;
816 ]b4_locations_if([[ /* To compute the location of the error token. */
817 yyGLRStackItem yyerror_range
[3];]])[
822 YYSTYPE yyval
;]b4_locations_if([[
825 YYJMP_BUF yyexception_buffer
;
826 yyGLRStackItem
* yyitems
;
827 yyGLRStackItem
* yynextFree
;
829 yyGLRState
* yysplitPoint
;
830 yyGLRState
* yylastDeleted
;
831 yyGLRStateSet yytops
;
834 #if YYSTACKEXPANDABLE
835 static void yyexpandGLRStack (yyGLRStack
* yystackp
);
838 static void yyFail (yyGLRStack
* yystackp
]b4_pure_formals
[, const char* yymsg
)
839 __attribute__ ((__noreturn__
));
841 yyFail (yyGLRStack
* yystackp
]b4_pure_formals
[, const char* yymsg
)
843 if (yymsg
!= YY_NULL
)
844 yyerror (]b4_yyerror_args
[yymsg
);
845 YYLONGJMP (yystackp
->yyexception_buffer
, 1);
848 static void yyMemoryExhausted (yyGLRStack
* yystackp
)
849 __attribute__ ((__noreturn__
));
851 yyMemoryExhausted (yyGLRStack
* yystackp
)
853 YYLONGJMP (yystackp
->yyexception_buffer
, 2);
856 #if YYDEBUG || YYERROR_VERBOSE
857 /** A printable representation of TOKEN. */
858 static inline const char*
859 yytokenName (yySymbol yytoken
)
861 if (yytoken
== YYEMPTY
)
864 return yytname
[yytoken
];
868 /** Fill in YYVSP[YYLOW1 .. YYLOW0-1] from the chain of states starting
869 * at YYVSP[YYLOW0].yystate.yypred. Leaves YYVSP[YYLOW1].yystate.yypred
870 * containing the pointer to the next state in the chain. */
871 static void yyfillin (yyGLRStackItem
*, int, int) __attribute__ ((__unused__
));
873 yyfillin (yyGLRStackItem
*yyvsp
, int yylow0
, int yylow1
)
876 yyGLRState
*s
= yyvsp
[yylow0
].yystate
.yypred
;
877 for (i
= yylow0
-1; i
>= yylow1
; i
-= 1)
879 YYASSERT (s
->yyresolved
);
880 yyvsp
[i
].yystate
.yyresolved
= yytrue
;
881 yyvsp
[i
].yystate
.yysemantics
.yysval
= s
->yysemantics
.yysval
;]b4_locations_if([[
882 yyvsp
[i
].yystate
.yyloc
= s
->yyloc
;]])[
883 s
= yyvsp
[i
].yystate
.yypred
= s
->yypred
;
887 /* Do nothing if YYNORMAL or if *YYLOW <= YYLOW1. Otherwise, fill in
888 * YYVSP[YYLOW1 .. *YYLOW-1] as in yyfillin and set *YYLOW = YYLOW1.
889 * For convenience, always return YYLOW1. */
890 static inline int yyfill (yyGLRStackItem
*, int *, int, yybool
)
891 __attribute__ ((__unused__
));
893 yyfill (yyGLRStackItem
*yyvsp
, int *yylow
, int yylow1
, yybool yynormal
)
895 if (!yynormal
&& yylow1
< *yylow
)
897 yyfillin (yyvsp
, *yylow
, yylow1
);
903 /** Perform user action for rule number YYN, with RHS length YYRHSLEN,
904 * and top stack item YYVSP. YYLVALP points to place to put semantic
905 * value ($$), and yylocp points to place for location information
906 * (@@$). Returns yyok for normal return, yyaccept for YYACCEPT,
907 * yyerr for YYERROR, yyabort for YYABORT. */
908 /*ARGSUSED*/ static YYRESULTTAG
909 yyuserAction (yyRuleNum yyn
, int yyrhslen
, yyGLRStackItem
* yyvsp
,
910 yyGLRStack
* yystackp
,
911 YYSTYPE
* yyvalp
]b4_locuser_formals
[)
913 yybool yynormal
__attribute__ ((__unused__
)) =
914 (yystackp
->yysplitPoint
== YY_NULL
);
916 ]b4_parse_param_use
[]dnl
918 # define yyerrok (yystackp->yyerrState = 0)
920 # define YYACCEPT return yyaccept
922 # define YYABORT return yyabort
924 # define YYERROR return yyerrok, yyerr
926 # define YYRECOVERING() (yystackp->yyerrState != 0)
928 # define yyclearin (yychar = YYEMPTY)
930 # define YYFILL(N) yyfill (yyvsp, &yylow, N, yynormal)
932 # define YYBACKUP(Token, Value) \
933 return yyerror (]b4_yyerror_args[YY_("syntax error: cannot back up")), \
938 *yyvalp
= yyval_default
;
940 *yyvalp
= yyvsp
[YYFILL (1-yyrhslen
)].yystate
.yysemantics
.yysval
;]b4_locations_if([[
941 YYLLOC_DEFAULT ((*yylocp
), (yyvsp
- yyrhslen
), yyrhslen
);
942 yystackp
->yyerror_range
[1].yystate
.yyloc
= *yylocp
;
961 /*ARGSUSED*/ static void
962 yyuserMerge (int yyn
, YYSTYPE
* yy0
, YYSTYPE
* yy1
)
974 /* Bison grammar-table manipulation. */
976 ]b4_yydestruct_generate([b4_c_ansi_function_def
])[
978 /** Number of symbols composing the right hand side of rule #RULE. */
980 yyrhsLength (yyRuleNum yyrule
)
986 yydestroyGLRState (char const *yymsg
, yyGLRState
*yys
]b4_user_formals
[)
989 yydestruct (yymsg
, yystos
[yys
->yylrState
],
990 &yys
->yysemantics
.yysval
]b4_locuser_args([&yys
->yyloc
])[);
996 if (yys
->yysemantics
.yyfirstVal
)
997 YYFPRINTF (stderr
, "%s unresolved ", yymsg
);
999 YYFPRINTF (stderr
, "%s incomplete ", yymsg
);
1000 yy_symbol_print (stderr
, yystos
[yys
->yylrState
],
1001 YY_NULL
]b4_locuser_args([&yys
->yyloc
])[);
1002 YYFPRINTF (stderr
, "\n");
1006 if (yys
->yysemantics
.yyfirstVal
)
1008 yySemanticOption
*yyoption
= yys
->yysemantics
.yyfirstVal
;
1011 for (yyrh
= yyoption
->yystate
, yyn
= yyrhsLength (yyoption
->yyrule
);
1013 yyrh
= yyrh
->yypred
, yyn
-= 1)
1014 yydestroyGLRState (yymsg
, yyrh
]b4_user_args
[);
1019 /** Left-hand-side symbol for rule #RULE. */
1020 static inline yySymbol
1021 yylhsNonterm (yyRuleNum yyrule
)
1023 return yyr1
[yyrule
];
1026 #define yypact_value_is_default(yystate) \
1027 ]b4_table_value_equals([[pact]], [[yystate]], [b4_pact_ninf])[
1029 /** True iff LR state STATE has only a default reduction (regardless
1031 static inline yybool
1032 yyisDefaultedState (yyStateNum yystate
)
1034 return yypact_value_is_default (yypact
[yystate
]);
1037 /** The default reduction for STATE, assuming it has one. */
1038 static inline yyRuleNum
1039 yydefaultAction (yyStateNum yystate
)
1041 return yydefact
[yystate
];
1044 #define yytable_value_is_error(yytable_value) \
1045 ]b4_table_value_equals([[table]], [[yytable_value]], [b4_table_ninf])[
1047 /** Set *YYACTION to the action to take in YYSTATE on seeing YYTOKEN.
1049 * R < 0: Reduce on rule -R.
1051 * R > 0: Shift to state R.
1052 * Set *CONFLICTS to a pointer into yyconfl to 0-terminated list of
1053 * conflicting reductions.
1056 yygetLRActions (yyStateNum yystate
, int yytoken
,
1057 int* yyaction
, const short int** yyconflicts
)
1059 int yyindex
= yypact
[yystate
] + yytoken
;
1060 if (yypact_value_is_default (yypact
[yystate
])
1061 || yyindex
< 0 || YYLAST
< yyindex
|| yycheck
[yyindex
] != yytoken
)
1063 *yyaction
= -yydefact
[yystate
];
1064 *yyconflicts
= yyconfl
;
1066 else if (! yytable_value_is_error (yytable
[yyindex
]))
1068 *yyaction
= yytable
[yyindex
];
1069 *yyconflicts
= yyconfl
+ yyconflp
[yyindex
];
1074 *yyconflicts
= yyconfl
+ yyconflp
[yyindex
];
1078 static inline yyStateNum
1079 yyLRgotoState (yyStateNum yystate
, yySymbol yylhs
)
1082 yyr
= yypgoto
[yylhs
- YYNTOKENS
] + yystate
;
1083 if (0 <= yyr
&& yyr
<= YYLAST
&& yycheck
[yyr
] == yystate
)
1084 return yytable
[yyr
];
1086 return yydefgoto
[yylhs
- YYNTOKENS
];
1089 static inline yybool
1090 yyisShiftAction (int yyaction
)
1092 return 0 < yyaction
;
1095 static inline yybool
1096 yyisErrorAction (int yyaction
)
1098 return yyaction
== 0;
1103 /** Return a fresh GLRStackItem. Callers should call
1104 * YY_RESERVE_GLRSTACK afterwards to make sure there is sufficient
1107 static inline yyGLRStackItem
*
1108 yynewGLRStackItem (yyGLRStack
* yystackp
, yybool yyisState
)
1110 yyGLRStackItem
* yynewItem
= yystackp
->yynextFree
;
1111 yystackp
->yyspaceLeft
-= 1;
1112 yystackp
->yynextFree
+= 1;
1113 yynewItem
->yystate
.yyisState
= yyisState
;
1117 /** Add a new semantic action that will execute the action for rule
1118 * RULENUM on the semantic values in RHS to the list of
1119 * alternative actions for STATE. Assumes that RHS comes from
1120 * stack #K of *STACKP. */
1122 yyaddDeferredAction (yyGLRStack
* yystackp
, size_t yyk
, yyGLRState
* yystate
,
1123 yyGLRState
* rhs
, yyRuleNum yyrule
)
1125 yySemanticOption
* yynewOption
=
1126 &yynewGLRStackItem (yystackp
, yyfalse
)->yyoption
;
1127 yynewOption
->yystate
= rhs
;
1128 yynewOption
->yyrule
= yyrule
;
1129 if (yystackp
->yytops
.yylookaheadNeeds
[yyk
])
1131 yynewOption
->yyrawchar
= yychar
;
1132 yynewOption
->yyval
= yylval
;]b4_locations_if([
1133 yynewOption
->yyloc
= yylloc
;])[
1136 yynewOption
->yyrawchar
= YYEMPTY
;
1137 yynewOption
->yynext
= yystate
->yysemantics
.yyfirstVal
;
1138 yystate
->yysemantics
.yyfirstVal
= yynewOption
;
1140 YY_RESERVE_GLRSTACK (yystackp
);
1145 /** Initialize SET to a singleton set containing an empty stack. */
1147 yyinitStateSet (yyGLRStateSet
* yyset
)
1150 yyset
->yycapacity
= 16;
1151 yyset
->yystates
= (yyGLRState
**) YYMALLOC (16 * sizeof yyset
->yystates
[0]);
1152 if (! yyset
->yystates
)
1154 yyset
->yystates
[0] = YY_NULL
;
1155 yyset
->yylookaheadNeeds
=
1156 (yybool
*) YYMALLOC (16 * sizeof yyset
->yylookaheadNeeds
[0]);
1157 if (! yyset
->yylookaheadNeeds
)
1159 YYFREE (yyset
->yystates
);
1165 static void yyfreeStateSet (yyGLRStateSet
* yyset
)
1167 YYFREE (yyset
->yystates
);
1168 YYFREE (yyset
->yylookaheadNeeds
);
1171 /** Initialize STACK to a single empty stack, with total maximum
1172 * capacity for all stacks of SIZE. */
1174 yyinitGLRStack (yyGLRStack
* yystackp
, size_t yysize
)
1176 yystackp
->yyerrState
= 0;
1178 yystackp
->yyspaceLeft
= yysize
;
1180 (yyGLRStackItem
*) YYMALLOC (yysize
* sizeof yystackp
->yynextFree
[0]);
1181 if (!yystackp
->yyitems
)
1183 yystackp
->yynextFree
= yystackp
->yyitems
;
1184 yystackp
->yysplitPoint
= YY_NULL
;
1185 yystackp
->yylastDeleted
= YY_NULL
;
1186 return yyinitStateSet (&yystackp
->yytops
);
1190 #if YYSTACKEXPANDABLE
1191 # define YYRELOC(YYFROMITEMS,YYTOITEMS,YYX,YYTYPE) \
1192 &((YYTOITEMS) - ((YYFROMITEMS) - (yyGLRStackItem*) (YYX)))->YYTYPE
1194 /** If STACK is expandable, extend it. WARNING: Pointers into the
1195 stack from outside should be considered invalid after this call.
1196 We always expand when there are 1 or fewer items left AFTER an
1197 allocation, so that we can avoid having external pointers exist
1198 across an allocation. */
1200 yyexpandGLRStack (yyGLRStack
* yystackp
)
1202 yyGLRStackItem
* yynewItems
;
1203 yyGLRStackItem
* yyp0
, *yyp1
;
1206 size_t yysize
= yystackp
->yynextFree
- yystackp
->yyitems
;
1207 if (YYMAXDEPTH
- YYHEADROOM
< yysize
)
1208 yyMemoryExhausted (yystackp
);
1209 yynewSize
= 2*yysize
;
1210 if (YYMAXDEPTH
< yynewSize
)
1211 yynewSize
= YYMAXDEPTH
;
1212 yynewItems
= (yyGLRStackItem
*) YYMALLOC (yynewSize
* sizeof yynewItems
[0]);
1214 yyMemoryExhausted (yystackp
);
1215 for (yyp0
= yystackp
->yyitems
, yyp1
= yynewItems
, yyn
= yysize
;
1217 yyn
-= 1, yyp0
+= 1, yyp1
+= 1)
1220 if (*(yybool
*) yyp0
)
1222 yyGLRState
* yys0
= &yyp0
->yystate
;
1223 yyGLRState
* yys1
= &yyp1
->yystate
;
1224 if (yys0
->yypred
!= YY_NULL
)
1226 YYRELOC (yyp0
, yyp1
, yys0
->yypred
, yystate
);
1227 if (! yys0
->yyresolved
&& yys0
->yysemantics
.yyfirstVal
!= YY_NULL
)
1228 yys1
->yysemantics
.yyfirstVal
=
1229 YYRELOC (yyp0
, yyp1
, yys0
->yysemantics
.yyfirstVal
, yyoption
);
1233 yySemanticOption
* yyv0
= &yyp0
->yyoption
;
1234 yySemanticOption
* yyv1
= &yyp1
->yyoption
;
1235 if (yyv0
->yystate
!= YY_NULL
)
1236 yyv1
->yystate
= YYRELOC (yyp0
, yyp1
, yyv0
->yystate
, yystate
);
1237 if (yyv0
->yynext
!= YY_NULL
)
1238 yyv1
->yynext
= YYRELOC (yyp0
, yyp1
, yyv0
->yynext
, yyoption
);
1241 if (yystackp
->yysplitPoint
!= YY_NULL
)
1242 yystackp
->yysplitPoint
= YYRELOC (yystackp
->yyitems
, yynewItems
,
1243 yystackp
->yysplitPoint
, yystate
);
1245 for (yyn
= 0; yyn
< yystackp
->yytops
.yysize
; yyn
+= 1)
1246 if (yystackp
->yytops
.yystates
[yyn
] != YY_NULL
)
1247 yystackp
->yytops
.yystates
[yyn
] =
1248 YYRELOC (yystackp
->yyitems
, yynewItems
,
1249 yystackp
->yytops
.yystates
[yyn
], yystate
);
1250 YYFREE (yystackp
->yyitems
);
1251 yystackp
->yyitems
= yynewItems
;
1252 yystackp
->yynextFree
= yynewItems
+ yysize
;
1253 yystackp
->yyspaceLeft
= yynewSize
- yysize
;
1258 yyfreeGLRStack (yyGLRStack
* yystackp
)
1260 YYFREE (yystackp
->yyitems
);
1261 yyfreeStateSet (&yystackp
->yytops
);
1264 /** Assuming that S is a GLRState somewhere on STACK, update the
1265 * splitpoint of STACK, if needed, so that it is at least as deep as
1268 yyupdateSplit (yyGLRStack
* yystackp
, yyGLRState
* yys
)
1270 if (yystackp
->yysplitPoint
!= YY_NULL
&& yystackp
->yysplitPoint
> yys
)
1271 yystackp
->yysplitPoint
= yys
;
1274 /** Invalidate stack #K in STACK. */
1276 yymarkStackDeleted (yyGLRStack
* yystackp
, size_t yyk
)
1278 if (yystackp
->yytops
.yystates
[yyk
] != YY_NULL
)
1279 yystackp
->yylastDeleted
= yystackp
->yytops
.yystates
[yyk
];
1280 yystackp
->yytops
.yystates
[yyk
] = YY_NULL
;
1283 /** Undelete the last stack that was marked as deleted. Can only be
1284 done once after a deletion, and only when all other stacks have
1287 yyundeleteLastStack (yyGLRStack
* yystackp
)
1289 if (yystackp
->yylastDeleted
== YY_NULL
|| yystackp
->yytops
.yysize
!= 0)
1291 yystackp
->yytops
.yystates
[0] = yystackp
->yylastDeleted
;
1292 yystackp
->yytops
.yysize
= 1;
1293 YYDPRINTF ((stderr
, "Restoring last deleted stack as stack #0.\n"));
1294 yystackp
->yylastDeleted
= YY_NULL
;
1298 yyremoveDeletes (yyGLRStack
* yystackp
)
1302 while (yyj
< yystackp
->yytops
.yysize
)
1304 if (yystackp
->yytops
.yystates
[yyi
] == YY_NULL
)
1308 YYDPRINTF ((stderr
, "Removing dead stacks.\n"));
1310 yystackp
->yytops
.yysize
-= 1;
1314 yystackp
->yytops
.yystates
[yyj
] = yystackp
->yytops
.yystates
[yyi
];
1315 /* In the current implementation, it's unnecessary to copy
1316 yystackp->yytops.yylookaheadNeeds[yyi] since, after
1317 yyremoveDeletes returns, the parser immediately either enters
1318 deterministic operation or shifts a token. However, it doesn't
1319 hurt, and the code might evolve to need it. */
1320 yystackp
->yytops
.yylookaheadNeeds
[yyj
] =
1321 yystackp
->yytops
.yylookaheadNeeds
[yyi
];
1324 YYDPRINTF ((stderr
, "Rename stack %lu -> %lu.\n",
1325 (unsigned long int) yyi
, (unsigned long int) yyj
));
1333 /** Shift to a new state on stack #K of STACK, corresponding to LR state
1334 * LRSTATE, at input position POSN, with (resolved) semantic value SVAL. */
1336 yyglrShift (yyGLRStack
* yystackp
, size_t yyk
, yyStateNum yylrState
,
1338 YYSTYPE
* yyvalp
]b4_locations_if([, YYLTYPE
* yylocp
])[)
1340 yyGLRState
* yynewState
= &yynewGLRStackItem (yystackp
, yytrue
)->yystate
;
1342 yynewState
->yylrState
= yylrState
;
1343 yynewState
->yyposn
= yyposn
;
1344 yynewState
->yyresolved
= yytrue
;
1345 yynewState
->yypred
= yystackp
->yytops
.yystates
[yyk
];
1346 yynewState
->yysemantics
.yysval
= *yyvalp
;]b4_locations_if([
1347 yynewState
->yyloc
= *yylocp
;])[
1348 yystackp
->yytops
.yystates
[yyk
] = yynewState
;
1350 YY_RESERVE_GLRSTACK (yystackp
);
1353 /** Shift stack #K of YYSTACK, to a new state corresponding to LR
1354 * state YYLRSTATE, at input position YYPOSN, with the (unresolved)
1355 * semantic value of YYRHS under the action for YYRULE. */
1357 yyglrShiftDefer (yyGLRStack
* yystackp
, size_t yyk
, yyStateNum yylrState
,
1358 size_t yyposn
, yyGLRState
* rhs
, yyRuleNum yyrule
)
1360 yyGLRState
* yynewState
= &yynewGLRStackItem (yystackp
, yytrue
)->yystate
;
1362 yynewState
->yylrState
= yylrState
;
1363 yynewState
->yyposn
= yyposn
;
1364 yynewState
->yyresolved
= yyfalse
;
1365 yynewState
->yypred
= yystackp
->yytops
.yystates
[yyk
];
1366 yynewState
->yysemantics
.yyfirstVal
= YY_NULL
;
1367 yystackp
->yytops
.yystates
[yyk
] = yynewState
;
1369 /* Invokes YY_RESERVE_GLRSTACK. */
1370 yyaddDeferredAction (yystackp
, yyk
, yynewState
, rhs
, yyrule
);
1373 /** Pop the symbols consumed by reduction #RULE from the top of stack
1374 * #K of STACK, and perform the appropriate semantic action on their
1375 * semantic values. Assumes that all ambiguities in semantic values
1376 * have been previously resolved. Set *VALP to the resulting value,
1377 * and *LOCP to the computed location (if any). Return value is as
1378 * for userAction. */
1379 static inline YYRESULTTAG
1380 yydoAction (yyGLRStack
* yystackp
, size_t yyk
, yyRuleNum yyrule
,
1381 YYSTYPE
* yyvalp
]b4_locuser_formals
[)
1383 int yynrhs
= yyrhsLength (yyrule
);
1385 if (yystackp
->yysplitPoint
== YY_NULL
)
1387 /* Standard special case: single stack. */
1388 yyGLRStackItem
* rhs
= (yyGLRStackItem
*) yystackp
->yytops
.yystates
[yyk
];
1389 YYASSERT (yyk
== 0);
1390 yystackp
->yynextFree
-= yynrhs
;
1391 yystackp
->yyspaceLeft
+= yynrhs
;
1392 yystackp
->yytops
.yystates
[0] = & yystackp
->yynextFree
[-1].yystate
;
1393 return yyuserAction (yyrule
, yynrhs
, rhs
, yystackp
,
1394 yyvalp
]b4_locuser_args
[);
1398 /* At present, doAction is never called in nondeterministic
1399 * mode, so this branch is never taken. It is here in
1400 * anticipation of a future feature that will allow immediate
1401 * evaluation of selected actions in nondeterministic mode. */
1404 yyGLRStackItem yyrhsVals
[YYMAXRHS
+ YYMAXLEFT
+ 1];
1405 yys
= yyrhsVals
[YYMAXRHS
+ YYMAXLEFT
].yystate
.yypred
1406 = yystackp
->yytops
.yystates
[yyk
];]b4_locations_if([[
1408 /* Set default location. */
1409 yyrhsVals
[YYMAXRHS
+ YYMAXLEFT
- 1].yystate
.yyloc
= yys
->yyloc
;]])[
1410 for (yyi
= 0; yyi
< yynrhs
; yyi
+= 1)
1415 yyupdateSplit (yystackp
, yys
);
1416 yystackp
->yytops
.yystates
[yyk
] = yys
;
1417 return yyuserAction (yyrule
, yynrhs
, yyrhsVals
+ YYMAXRHS
+ YYMAXLEFT
- 1,
1418 yystackp
, yyvalp
]b4_locuser_args
[);
1423 # define YY_REDUCE_PRINT(Args)
1425 # define YY_REDUCE_PRINT(Args) \
1428 yy_reduce_print Args; \
1431 /*----------------------------------------------------------.
1432 | Report that the RULE is going to be reduced on stack #K. |
1433 `----------------------------------------------------------*/
1435 /*ARGSUSED*/ static inline void
1436 yy_reduce_print (yyGLRStack
* yystackp
, size_t yyk
, yyRuleNum yyrule
,
1437 YYSTYPE
* yyvalp
]b4_locuser_formals
[)
1439 int yynrhs
= yyrhsLength (yyrule
);
1440 yybool yynormal
__attribute__ ((__unused__
)) =
1441 (yystackp
->yysplitPoint
== YY_NULL
);
1442 yyGLRStackItem
* yyvsp
= (yyGLRStackItem
*) yystackp
->yytops
.yystates
[yyk
];
1445 YYUSE (yyvalp
);]b4_locations_if([
1447 ]b4_parse_param_use
[]dnl
1448 [ YYFPRINTF (stderr
, "Reducing stack %lu by rule %d (line %lu):\n",
1449 (unsigned long int) yyk
, yyrule
- 1,
1450 (unsigned long int) yyrline
[yyrule
]);
1451 /* The symbols being reduced. */
1452 for (yyi
= 0; yyi
< yynrhs
; yyi
++)
1454 YYFPRINTF (stderr
, " $%d = ", yyi
+ 1);
1455 yy_symbol_print (stderr
, yyrhs
[yyprhs
[yyrule
] + yyi
],
1456 &]b4_rhs_value(yynrhs
, yyi
+ 1)[
1457 ]b4_locations_if([, &]b4_rhs_location(yynrhs
, yyi
+ 1))[]dnl
1459 YYFPRINTF (stderr
, "\n");
1464 /** Pop items off stack #K of STACK according to grammar rule RULE,
1465 * and push back on the resulting nonterminal symbol. Perform the
1466 * semantic action associated with RULE and store its value with the
1467 * newly pushed state, if FORCEEVAL or if STACK is currently
1468 * unambiguous. Otherwise, store the deferred semantic action with
1469 * the new state. If the new state would have an identical input
1470 * position, LR state, and predecessor to an existing state on the stack,
1471 * it is identified with that existing state, eliminating stack #K from
1472 * the STACK. In this case, the (necessarily deferred) semantic value is
1473 * added to the options for the existing state's semantic value.
1475 static inline YYRESULTTAG
1476 yyglrReduce (yyGLRStack
* yystackp
, size_t yyk
, yyRuleNum yyrule
,
1477 yybool yyforceEval
]b4_user_formals
[)
1479 size_t yyposn
= yystackp
->yytops
.yystates
[yyk
]->yyposn
;
1481 if (yyforceEval
|| yystackp
->yysplitPoint
== YY_NULL
)
1483 YYSTYPE yysval
;]b4_locations_if([
1486 YY_REDUCE_PRINT ((yystackp
, yyk
, yyrule
, &yysval
]b4_locuser_args([&yyloc
])[));
1487 YYCHK (yydoAction (yystackp
, yyk
, yyrule
, &yysval
]b4_locuser_args([&yyloc
])[));
1488 YY_SYMBOL_PRINT ("-> $$ =", yyr1
[yyrule
], &yysval
, &yyloc
);
1489 yyglrShift (yystackp
, yyk
,
1490 yyLRgotoState (yystackp
->yytops
.yystates
[yyk
]->yylrState
,
1491 yylhsNonterm (yyrule
)),
1492 yyposn
, &yysval
]b4_locations_if([, &yyloc
])[);
1498 yyGLRState
* yys
, *yys0
= yystackp
->yytops
.yystates
[yyk
];
1499 yyStateNum yynewLRState
;
1501 for (yys
= yystackp
->yytops
.yystates
[yyk
], yyn
= yyrhsLength (yyrule
);
1507 yyupdateSplit (yystackp
, yys
);
1508 yynewLRState
= yyLRgotoState (yys
->yylrState
, yylhsNonterm (yyrule
));
1510 "Reduced stack %lu by rule #%d; action deferred. Now in state %d.\n",
1511 (unsigned long int) yyk
, yyrule
- 1, yynewLRState
));
1512 for (yyi
= 0; yyi
< yystackp
->yytops
.yysize
; yyi
+= 1)
1513 if (yyi
!= yyk
&& yystackp
->yytops
.yystates
[yyi
] != YY_NULL
)
1515 yyGLRState
*yysplit
= yystackp
->yysplitPoint
;
1516 yyGLRState
*yyp
= yystackp
->yytops
.yystates
[yyi
];
1517 while (yyp
!= yys
&& yyp
!= yysplit
&& yyp
->yyposn
>= yyposn
)
1519 if (yyp
->yylrState
== yynewLRState
&& yyp
->yypred
== yys
)
1521 yyaddDeferredAction (yystackp
, yyk
, yyp
, yys0
, yyrule
);
1522 yymarkStackDeleted (yystackp
, yyk
);
1523 YYDPRINTF ((stderr
, "Merging stack %lu into stack %lu.\n",
1524 (unsigned long int) yyk
,
1525 (unsigned long int) yyi
));
1531 yystackp
->yytops
.yystates
[yyk
] = yys
;
1532 yyglrShiftDefer (yystackp
, yyk
, yynewLRState
, yyposn
, yys0
, yyrule
);
1538 yysplitStack (yyGLRStack
* yystackp
, size_t yyk
)
1540 if (yystackp
->yysplitPoint
== YY_NULL
)
1542 YYASSERT (yyk
== 0);
1543 yystackp
->yysplitPoint
= yystackp
->yytops
.yystates
[yyk
];
1545 if (yystackp
->yytops
.yysize
>= yystackp
->yytops
.yycapacity
)
1547 yyGLRState
** yynewStates
;
1548 yybool
* yynewLookaheadNeeds
;
1550 yynewStates
= YY_NULL
;
1552 if (yystackp
->yytops
.yycapacity
1553 > (YYSIZEMAX
/ (2 * sizeof yynewStates
[0])))
1554 yyMemoryExhausted (yystackp
);
1555 yystackp
->yytops
.yycapacity
*= 2;
1558 (yyGLRState
**) YYREALLOC (yystackp
->yytops
.yystates
,
1559 (yystackp
->yytops
.yycapacity
1560 * sizeof yynewStates
[0]));
1561 if (yynewStates
== YY_NULL
)
1562 yyMemoryExhausted (yystackp
);
1563 yystackp
->yytops
.yystates
= yynewStates
;
1565 yynewLookaheadNeeds
=
1566 (yybool
*) YYREALLOC (yystackp
->yytops
.yylookaheadNeeds
,
1567 (yystackp
->yytops
.yycapacity
1568 * sizeof yynewLookaheadNeeds
[0]));
1569 if (yynewLookaheadNeeds
== YY_NULL
)
1570 yyMemoryExhausted (yystackp
);
1571 yystackp
->yytops
.yylookaheadNeeds
= yynewLookaheadNeeds
;
1573 yystackp
->yytops
.yystates
[yystackp
->yytops
.yysize
]
1574 = yystackp
->yytops
.yystates
[yyk
];
1575 yystackp
->yytops
.yylookaheadNeeds
[yystackp
->yytops
.yysize
]
1576 = yystackp
->yytops
.yylookaheadNeeds
[yyk
];
1577 yystackp
->yytops
.yysize
+= 1;
1578 return yystackp
->yytops
.yysize
-1;
1581 /** True iff Y0 and Y1 represent identical options at the top level.
1582 * That is, they represent the same rule applied to RHS symbols
1583 * that produce the same terminal symbols. */
1585 yyidenticalOptions (yySemanticOption
* yyy0
, yySemanticOption
* yyy1
)
1587 if (yyy0
->yyrule
== yyy1
->yyrule
)
1589 yyGLRState
*yys0
, *yys1
;
1591 for (yys0
= yyy0
->yystate
, yys1
= yyy1
->yystate
,
1592 yyn
= yyrhsLength (yyy0
->yyrule
);
1594 yys0
= yys0
->yypred
, yys1
= yys1
->yypred
, yyn
-= 1)
1595 if (yys0
->yyposn
!= yys1
->yyposn
)
1603 /** Assuming identicalOptions (Y0,Y1), destructively merge the
1604 * alternative semantic values for the RHS-symbols of Y1 and Y0. */
1606 yymergeOptionSets (yySemanticOption
* yyy0
, yySemanticOption
* yyy1
)
1608 yyGLRState
*yys0
, *yys1
;
1610 for (yys0
= yyy0
->yystate
, yys1
= yyy1
->yystate
,
1611 yyn
= yyrhsLength (yyy0
->yyrule
);
1613 yys0
= yys0
->yypred
, yys1
= yys1
->yypred
, yyn
-= 1)
1617 else if (yys0
->yyresolved
)
1619 yys1
->yyresolved
= yytrue
;
1620 yys1
->yysemantics
.yysval
= yys0
->yysemantics
.yysval
;
1622 else if (yys1
->yyresolved
)
1624 yys0
->yyresolved
= yytrue
;
1625 yys0
->yysemantics
.yysval
= yys1
->yysemantics
.yysval
;
1629 yySemanticOption
** yyz0p
= &yys0
->yysemantics
.yyfirstVal
;
1630 yySemanticOption
* yyz1
= yys1
->yysemantics
.yyfirstVal
;
1631 while (YYID (yytrue
))
1633 if (yyz1
== *yyz0p
|| yyz1
== YY_NULL
)
1635 else if (*yyz0p
== YY_NULL
)
1640 else if (*yyz0p
< yyz1
)
1642 yySemanticOption
* yyz
= *yyz0p
;
1644 yyz1
= yyz1
->yynext
;
1645 (*yyz0p
)->yynext
= yyz
;
1647 yyz0p
= &(*yyz0p
)->yynext
;
1649 yys1
->yysemantics
.yyfirstVal
= yys0
->yysemantics
.yyfirstVal
;
1654 /** Y0 and Y1 represent two possible actions to take in a given
1655 * parsing state; return 0 if no combination is possible,
1656 * 1 if user-mergeable, 2 if Y0 is preferred, 3 if Y1 is preferred. */
1658 yypreference (yySemanticOption
* y0
, yySemanticOption
* y1
)
1660 yyRuleNum r0
= y0
->yyrule
, r1
= y1
->yyrule
;
1661 int p0
= yydprec
[r0
], p1
= yydprec
[r1
];
1665 if (yymerger
[r0
] == 0 || yymerger
[r0
] != yymerger
[r1
])
1670 if (p0
== 0 || p1
== 0)
1679 static YYRESULTTAG
yyresolveValue (yyGLRState
* yys
,
1680 yyGLRStack
* yystackp
]b4_user_formals
[);
1683 /** Resolve the previous N states starting at and including state S. If result
1684 * != yyok, some states may have been left unresolved possibly with empty
1685 * semantic option chains. Regardless of whether result = yyok, each state
1686 * has been left with consistent data so that yydestroyGLRState can be invoked
1689 yyresolveStates (yyGLRState
* yys
, int yyn
,
1690 yyGLRStack
* yystackp
]b4_user_formals
[)
1694 YYASSERT (yys
->yypred
);
1695 YYCHK (yyresolveStates (yys
->yypred
, yyn
-1, yystackp
]b4_user_args
[));
1696 if (! yys
->yyresolved
)
1697 YYCHK (yyresolveValue (yys
, yystackp
]b4_user_args
[));
1702 /** Resolve the states for the RHS of OPT, perform its user action, and return
1703 * the semantic value and location. Regardless of whether result = yyok, all
1704 * RHS states have been destroyed (assuming the user action destroys all RHS
1705 * semantic values if invoked). */
1707 yyresolveAction (yySemanticOption
* yyopt
, yyGLRStack
* yystackp
,
1708 YYSTYPE
* yyvalp
]b4_locuser_formals
[)
1710 yyGLRStackItem yyrhsVals
[YYMAXRHS
+ YYMAXLEFT
+ 1];
1711 int yynrhs
= yyrhsLength (yyopt
->yyrule
);
1712 YYRESULTTAG yyflag
=
1713 yyresolveStates (yyopt
->yystate
, yynrhs
, yystackp
]b4_user_args
[);
1717 for (yys
= yyopt
->yystate
; yynrhs
> 0; yys
= yys
->yypred
, yynrhs
-= 1)
1718 yydestroyGLRState ("Cleanup: popping", yys
]b4_user_args
[);
1722 yyrhsVals
[YYMAXRHS
+ YYMAXLEFT
].yystate
.yypred
= yyopt
->yystate
;]b4_locations_if([[
1724 /* Set default location. */
1725 yyrhsVals
[YYMAXRHS
+ YYMAXLEFT
- 1].yystate
.yyloc
= yyopt
->yystate
->yyloc
;]])[
1727 int yychar_current
= yychar
;
1728 YYSTYPE yylval_current
= yylval
;]b4_locations_if([
1729 YYLTYPE yylloc_current
= yylloc
;])[
1730 yychar
= yyopt
->yyrawchar
;
1731 yylval
= yyopt
->yyval
;]b4_locations_if([
1732 yylloc
= yyopt
->yyloc
;])[
1733 yyflag
= yyuserAction (yyopt
->yyrule
, yynrhs
,
1734 yyrhsVals
+ YYMAXRHS
+ YYMAXLEFT
- 1,
1735 yystackp
, yyvalp
]b4_locuser_args
[);
1736 yychar
= yychar_current
;
1737 yylval
= yylval_current
;]b4_locations_if([
1738 yylloc
= yylloc_current
;])[
1745 yyreportTree (yySemanticOption
* yyx
, int yyindent
)
1747 int yynrhs
= yyrhsLength (yyx
->yyrule
);
1750 yyGLRState
* yystates
[1 + YYMAXRHS
];
1751 yyGLRState yyleftmost_state
;
1753 for (yyi
= yynrhs
, yys
= yyx
->yystate
; 0 < yyi
; yyi
-= 1, yys
= yys
->yypred
)
1754 yystates
[yyi
] = yys
;
1757 yyleftmost_state
.yyposn
= 0;
1758 yystates
[0] = &yyleftmost_state
;
1763 if (yyx
->yystate
->yyposn
< yys
->yyposn
+ 1)
1764 YYFPRINTF (stderr
, "%*s%s -> <Rule %d, empty>\n",
1765 yyindent
, "", yytokenName (yylhsNonterm (yyx
->yyrule
)),
1768 YYFPRINTF (stderr
, "%*s%s -> <Rule %d, tokens %lu .. %lu>\n",
1769 yyindent
, "", yytokenName (yylhsNonterm (yyx
->yyrule
)),
1770 yyx
->yyrule
- 1, (unsigned long int) (yys
->yyposn
+ 1),
1771 (unsigned long int) yyx
->yystate
->yyposn
);
1772 for (yyi
= 1; yyi
<= yynrhs
; yyi
+= 1)
1774 if (yystates
[yyi
]->yyresolved
)
1776 if (yystates
[yyi
-1]->yyposn
+1 > yystates
[yyi
]->yyposn
)
1777 YYFPRINTF (stderr
, "%*s%s <empty>\n", yyindent
+2, "",
1778 yytokenName (yyrhs
[yyprhs
[yyx
->yyrule
]+yyi
-1]));
1780 YYFPRINTF (stderr
, "%*s%s <tokens %lu .. %lu>\n", yyindent
+2, "",
1781 yytokenName (yyrhs
[yyprhs
[yyx
->yyrule
]+yyi
-1]),
1782 (unsigned long int) (yystates
[yyi
- 1]->yyposn
+ 1),
1783 (unsigned long int) yystates
[yyi
]->yyposn
);
1786 yyreportTree (yystates
[yyi
]->yysemantics
.yyfirstVal
, yyindent
+2);
1791 /*ARGSUSED*/ static YYRESULTTAG
1792 yyreportAmbiguity (yySemanticOption
* yyx0
,
1793 yySemanticOption
* yyx1
]b4_pure_formals
[)
1799 YYFPRINTF (stderr
, "Ambiguity detected.\n");
1800 YYFPRINTF (stderr
, "Option 1,\n");
1801 yyreportTree (yyx0
, 2);
1802 YYFPRINTF (stderr
, "\nOption 2,\n");
1803 yyreportTree (yyx1
, 2);
1804 YYFPRINTF (stderr
, "\n");
1807 yyerror (]b4_yyerror_args
[YY_("syntax is ambiguous"));
1809 }]b4_locations_if([[
1811 /** Starting at and including state S1, resolve the location for each of the
1812 * previous N1 states that is unresolved. The first semantic option of a state
1813 * is always chosen. */
1815 yyresolveLocations (yyGLRState
* yys1
, int yyn1
,
1816 yyGLRStack
*yystackp
]b4_user_formals
[)
1820 yyresolveLocations (yys1
->yypred
, yyn1
- 1, yystackp
]b4_user_args
[);
1821 if (!yys1
->yyresolved
)
1823 yyGLRStackItem yyrhsloc
[1 + YYMAXRHS
];
1825 yySemanticOption
*yyoption
= yys1
->yysemantics
.yyfirstVal
;
1826 YYASSERT (yyoption
!= YY_NULL
);
1827 yynrhs
= yyrhsLength (yyoption
->yyrule
);
1832 yyresolveLocations (yyoption
->yystate
, yynrhs
,
1833 yystackp
]b4_user_args
[);
1834 for (yys
= yyoption
->yystate
, yyn
= yynrhs
;
1836 yys
= yys
->yypred
, yyn
-= 1)
1837 yyrhsloc
[yyn
].yystate
.yyloc
= yys
->yyloc
;
1841 /* Both yyresolveAction and yyresolveLocations traverse the GSS
1842 in reverse rightmost order. It is only necessary to invoke
1843 yyresolveLocations on a subforest for which yyresolveAction
1844 would have been invoked next had an ambiguity not been
1845 detected. Thus the location of the previous state (but not
1846 necessarily the previous state itself) is guaranteed to be
1847 resolved already. */
1848 yyGLRState
*yyprevious
= yyoption
->yystate
;
1849 yyrhsloc
[0].yystate
.yyloc
= yyprevious
->yyloc
;
1852 int yychar_current
= yychar
;
1853 YYSTYPE yylval_current
= yylval
;
1854 YYLTYPE yylloc_current
= yylloc
;
1855 yychar
= yyoption
->yyrawchar
;
1856 yylval
= yyoption
->yyval
;
1857 yylloc
= yyoption
->yyloc
;
1858 YYLLOC_DEFAULT ((yys1
->yyloc
), yyrhsloc
, yynrhs
);
1859 yychar
= yychar_current
;
1860 yylval
= yylval_current
;
1861 yylloc
= yylloc_current
;
1867 /** Resolve the ambiguity represented in state S, perform the indicated
1868 * actions, and set the semantic value of S. If result != yyok, the chain of
1869 * semantic options in S has been cleared instead or it has been left
1870 * unmodified except that redundant options may have been removed. Regardless
1871 * of whether result = yyok, S has been left with consistent data so that
1872 * yydestroyGLRState can be invoked if necessary. */
1874 yyresolveValue (yyGLRState
* yys
, yyGLRStack
* yystackp
]b4_user_formals
[)
1876 yySemanticOption
* yyoptionList
= yys
->yysemantics
.yyfirstVal
;
1877 yySemanticOption
* yybest
= yyoptionList
;
1878 yySemanticOption
** yypp
;
1879 yybool yymerge
= yyfalse
;
1881 YYRESULTTAG yyflag
;]b4_locations_if([
1882 YYLTYPE
*yylocp
= &yys
->yyloc
;])[
1884 for (yypp
= &yyoptionList
->yynext
; *yypp
!= YY_NULL
; )
1886 yySemanticOption
* yyp
= *yypp
;
1888 if (yyidenticalOptions (yybest
, yyp
))
1890 yymergeOptionSets (yybest
, yyp
);
1891 *yypp
= yyp
->yynext
;
1895 switch (yypreference (yybest
, yyp
))
1897 case 0:]b4_locations_if([[
1898 yyresolveLocations (yys
, 1, yystackp
]b4_user_args
[);]])[
1899 return yyreportAmbiguity (yybest
, yyp
]b4_pure_args
[);
1911 /* This cannot happen so it is not worth a YYASSERT (yyfalse),
1912 but some compilers complain if the default case is
1916 yypp
= &yyp
->yynext
;
1922 yySemanticOption
* yyp
;
1923 int yyprec
= yydprec
[yybest
->yyrule
];
1924 yyflag
= yyresolveAction (yybest
, yystackp
, &yysval
]b4_locuser_args
[);
1926 for (yyp
= yybest
->yynext
; yyp
!= YY_NULL
; yyp
= yyp
->yynext
)
1928 if (yyprec
== yydprec
[yyp
->yyrule
])
1930 YYSTYPE yysval_other
;]b4_locations_if([
1932 yyflag
= yyresolveAction (yyp
, yystackp
, &yysval_other
]b4_locuser_args([&yydummy
])[);
1935 yydestruct ("Cleanup: discarding incompletely merged value for",
1936 yystos
[yys
->yylrState
],
1937 &yysval
]b4_locuser_args
[);
1940 yyuserMerge (yymerger
[yyp
->yyrule
], &yysval
, &yysval_other
);
1945 yyflag
= yyresolveAction (yybest
, yystackp
, &yysval
]b4_locuser_args([yylocp
])[);
1949 yys
->yyresolved
= yytrue
;
1950 yys
->yysemantics
.yysval
= yysval
;
1953 yys
->yysemantics
.yyfirstVal
= YY_NULL
;
1958 yyresolveStack (yyGLRStack
* yystackp
]b4_user_formals
[)
1960 if (yystackp
->yysplitPoint
!= YY_NULL
)
1965 for (yyn
= 0, yys
= yystackp
->yytops
.yystates
[0];
1966 yys
!= yystackp
->yysplitPoint
;
1967 yys
= yys
->yypred
, yyn
+= 1)
1969 YYCHK (yyresolveStates (yystackp
->yytops
.yystates
[0], yyn
, yystackp
1976 yycompressStack (yyGLRStack
* yystackp
)
1978 yyGLRState
* yyp
, *yyq
, *yyr
;
1980 if (yystackp
->yytops
.yysize
!= 1 || yystackp
->yysplitPoint
== YY_NULL
)
1983 for (yyp
= yystackp
->yytops
.yystates
[0], yyq
= yyp
->yypred
, yyr
= YY_NULL
;
1984 yyp
!= yystackp
->yysplitPoint
;
1985 yyr
= yyp
, yyp
= yyq
, yyq
= yyp
->yypred
)
1988 yystackp
->yyspaceLeft
+= yystackp
->yynextFree
- yystackp
->yyitems
;
1989 yystackp
->yynextFree
= ((yyGLRStackItem
*) yystackp
->yysplitPoint
) + 1;
1990 yystackp
->yyspaceLeft
-= yystackp
->yynextFree
- yystackp
->yyitems
;
1991 yystackp
->yysplitPoint
= YY_NULL
;
1992 yystackp
->yylastDeleted
= YY_NULL
;
1994 while (yyr
!= YY_NULL
)
1996 yystackp
->yynextFree
->yystate
= *yyr
;
1998 yystackp
->yynextFree
->yystate
.yypred
= &yystackp
->yynextFree
[-1].yystate
;
1999 yystackp
->yytops
.yystates
[0] = &yystackp
->yynextFree
->yystate
;
2000 yystackp
->yynextFree
+= 1;
2001 yystackp
->yyspaceLeft
-= 1;
2006 yyprocessOneStack (yyGLRStack
* yystackp
, size_t yyk
,
2007 size_t yyposn
]b4_pure_formals
[)
2010 const short int* yyconflicts
;
2013 while (yystackp
->yytops
.yystates
[yyk
] != YY_NULL
)
2015 yyStateNum yystate
= yystackp
->yytops
.yystates
[yyk
]->yylrState
;
2016 YYDPRINTF ((stderr
, "Stack %lu Entering state %d\n",
2017 (unsigned long int) yyk
, yystate
));
2019 YYASSERT (yystate
!= YYFINAL
);
2021 if (yyisDefaultedState (yystate
))
2023 yyrule
= yydefaultAction (yystate
);
2026 YYDPRINTF ((stderr
, "Stack %lu dies.\n",
2027 (unsigned long int) yyk
));
2028 yymarkStackDeleted (yystackp
, yyk
);
2031 YYCHK (yyglrReduce (yystackp
, yyk
, yyrule
, yyfalse
]b4_user_args
[));
2036 yystackp
->yytops
.yylookaheadNeeds
[yyk
] = yytrue
;
2037 if (yychar
== YYEMPTY
)
2039 YYDPRINTF ((stderr
, "Reading a token: "));
2043 if (yychar
<= YYEOF
)
2045 yychar
= yytoken
= YYEOF
;
2046 YYDPRINTF ((stderr
, "Now at end of input.\n"));
2050 yytoken
= YYTRANSLATE (yychar
);
2051 YY_SYMBOL_PRINT ("Next token is", yytoken
, &yylval
, &yylloc
);
2054 yygetLRActions (yystate
, yytoken
, &yyaction
, &yyconflicts
);
2056 while (*yyconflicts
!= 0)
2058 size_t yynewStack
= yysplitStack (yystackp
, yyk
);
2059 YYDPRINTF ((stderr
, "Splitting off stack %lu from %lu.\n",
2060 (unsigned long int) yynewStack
,
2061 (unsigned long int) yyk
));
2062 YYCHK (yyglrReduce (yystackp
, yynewStack
,
2063 *yyconflicts
, yyfalse
]b4_user_args
[));
2064 YYCHK (yyprocessOneStack (yystackp
, yynewStack
,
2065 yyposn
]b4_pure_args
[));
2069 if (yyisShiftAction (yyaction
))
2071 else if (yyisErrorAction (yyaction
))
2073 YYDPRINTF ((stderr
, "Stack %lu dies.\n",
2074 (unsigned long int) yyk
));
2075 yymarkStackDeleted (yystackp
, yyk
);
2079 YYCHK (yyglrReduce (yystackp
, yyk
, -yyaction
,
2080 yyfalse
]b4_user_args
[));
2086 /*ARGSUSED*/ static void
2087 yyreportSyntaxError (yyGLRStack
* yystackp
]b4_user_formals
[)
2089 if (yystackp
->yyerrState
!= 0)
2091 #if ! YYERROR_VERBOSE
2092 yyerror (]b4_lyyerror_args
[YY_("syntax error"));
2094 yySymbol yytoken
= yychar
== YYEMPTY
? YYEMPTY
: YYTRANSLATE (yychar
);
2095 size_t yysize0
= yytnamerr (YY_NULL
, yytokenName (yytoken
));
2096 size_t yysize
= yysize0
;
2098 yybool yysize_overflow
= yyfalse
;
2099 char* yymsg
= YY_NULL
;
2100 enum { YYERROR_VERBOSE_ARGS_MAXIMUM
= 5 };
2101 /* Internationalized format string. */
2102 const char *yyformat
= YY_NULL
;
2103 /* Arguments of yyformat. */
2104 char const *yyarg
[YYERROR_VERBOSE_ARGS_MAXIMUM
];
2105 /* Number of reported tokens (one for the "unexpected", one per
2109 /* There are many possibilities here to consider:
2110 - If this state is a consistent state with a default action, then
2111 the only way this function was invoked is if the default action
2112 is an error action. In that case, don't check for expected
2113 tokens because there are none.
2114 - The only way there can be no lookahead present (in yychar) is if
2115 this state is a consistent state with a default action. Thus,
2116 detecting the absence of a lookahead is sufficient to determine
2117 that there is no unexpected or expected token to report. In that
2118 case, just report a simple "syntax error".
2119 - Don't assume there isn't a lookahead just because this state is a
2120 consistent state with a default action. There might have been a
2121 previous inconsistent state, consistent state with a non-default
2122 action, or user semantic action that manipulated yychar.
2123 - Of course, the expected token list depends on states to have
2124 correct lookahead information, and it depends on the parser not
2125 to perform extra reductions after fetching a lookahead from the
2126 scanner and before detecting a syntax error. Thus, state merging
2127 (from LALR or IELR) and default reductions corrupt the expected
2128 token list. However, the list is correct for canonical LR with
2129 one exception: it will still contain any token that will not be
2130 accepted due to an error action in a later state.
2132 if (yytoken
!= YYEMPTY
)
2134 int yyn
= yypact
[yystackp
->yytops
.yystates
[0]->yylrState
];
2135 yyarg
[yycount
++] = yytokenName (yytoken
);
2136 if (!yypact_value_is_default (yyn
))
2138 /* Start YYX at -YYN if negative to avoid negative indexes in
2139 YYCHECK. In other words, skip the first -YYN actions for this
2140 state because they are default actions. */
2141 int yyxbegin
= yyn
< 0 ? -yyn
: 0;
2142 /* Stay within bounds of both yycheck and yytname. */
2143 int yychecklim
= YYLAST
- yyn
+ 1;
2144 int yyxend
= yychecklim
< YYNTOKENS
? yychecklim
: YYNTOKENS
;
2146 for (yyx
= yyxbegin
; yyx
< yyxend
; ++yyx
)
2147 if (yycheck
[yyx
+ yyn
] == yyx
&& yyx
!= YYTERROR
2148 && !yytable_value_is_error (yytable
[yyx
+ yyn
]))
2150 if (yycount
== YYERROR_VERBOSE_ARGS_MAXIMUM
)
2156 yyarg
[yycount
++] = yytokenName (yyx
);
2157 yysize1
= yysize
+ yytnamerr (YY_NULL
, yytokenName (yyx
));
2158 yysize_overflow
|= yysize1
< yysize
;
2166 #define YYCASE_(N, S) \
2170 YYCASE_(0, YY_("syntax error"));
2171 YYCASE_(1, YY_("syntax error, unexpected %s"));
2172 YYCASE_(2, YY_("syntax error, unexpected %s, expecting %s"));
2173 YYCASE_(3, YY_("syntax error, unexpected %s, expecting %s or %s"));
2174 YYCASE_(4, YY_("syntax error, unexpected %s, expecting %s or %s or %s"));
2175 YYCASE_(5, YY_("syntax error, unexpected %s, expecting %s or %s or %s or %s"));
2179 yysize1
= yysize
+ strlen (yyformat
);
2180 yysize_overflow
|= yysize1
< yysize
;
2183 if (!yysize_overflow
)
2184 yymsg
= (char *) YYMALLOC (yysize
);
2190 while ((*yyp
= *yyformat
))
2192 if (*yyp
== '%' && yyformat
[1] == 's' && yyi
< yycount
)
2194 yyp
+= yytnamerr (yyp
, yyarg
[yyi
++]);
2203 yyerror (]b4_lyyerror_args
[yymsg
);
2208 yyerror (]b4_lyyerror_args
[YY_("syntax error"));
2209 yyMemoryExhausted (yystackp
);
2211 #endif /* YYERROR_VERBOSE */
2215 /* Recover from a syntax error on *YYSTACKP, assuming that *YYSTACKP->YYTOKENP,
2216 yylval, and yylloc are the syntactic category, semantic value, and location
2217 of the lookahead. */
2218 /*ARGSUSED*/ static void
2219 yyrecoverSyntaxError (yyGLRStack
* yystackp
]b4_user_formals
[)
2224 if (yystackp
->yyerrState
== 3)
2225 /* We just shifted the error token and (perhaps) took some
2226 reductions. Skip tokens until we can proceed. */
2227 while (YYID (yytrue
))
2230 if (yychar
== YYEOF
)
2231 yyFail (yystackp
][]b4_lpure_args
[, YY_NULL
);
2232 if (yychar
!= YYEMPTY
)
2233 {]b4_locations_if([[
2234 /* We throw away the lookahead, but the error range
2235 of the shifted error token must take it into account. */
2236 yyGLRState
*yys
= yystackp
->yytops
.yystates
[0];
2237 yyGLRStackItem yyerror_range
[3];
2238 yyerror_range
[1].yystate
.yyloc
= yys
->yyloc
;
2239 yyerror_range
[2].yystate
.yyloc
= yylloc
;
2240 YYLLOC_DEFAULT ((yys
->yyloc
), yyerror_range
, 2);]])[
2241 yytoken
= YYTRANSLATE (yychar
);
2242 yydestruct ("Error: discarding",
2243 yytoken
, &yylval
]b4_locuser_args([&yylloc
])[);
2245 YYDPRINTF ((stderr
, "Reading a token: "));
2247 if (yychar
<= YYEOF
)
2249 yychar
= yytoken
= YYEOF
;
2250 YYDPRINTF ((stderr
, "Now at end of input.\n"));
2254 yytoken
= YYTRANSLATE (yychar
);
2255 YY_SYMBOL_PRINT ("Next token is", yytoken
, &yylval
, &yylloc
);
2257 yyj
= yypact
[yystackp
->yytops
.yystates
[0]->yylrState
];
2258 if (yypact_value_is_default (yyj
))
2261 if (yyj
< 0 || YYLAST
< yyj
|| yycheck
[yyj
] != yytoken
)
2263 if (yydefact
[yystackp
->yytops
.yystates
[0]->yylrState
] != 0)
2266 else if (! yytable_value_is_error (yytable
[yyj
]))
2270 /* Reduce to one stack. */
2271 for (yyk
= 0; yyk
< yystackp
->yytops
.yysize
; yyk
+= 1)
2272 if (yystackp
->yytops
.yystates
[yyk
] != YY_NULL
)
2274 if (yyk
>= yystackp
->yytops
.yysize
)
2275 yyFail (yystackp
][]b4_lpure_args
[, YY_NULL
);
2276 for (yyk
+= 1; yyk
< yystackp
->yytops
.yysize
; yyk
+= 1)
2277 yymarkStackDeleted (yystackp
, yyk
);
2278 yyremoveDeletes (yystackp
);
2279 yycompressStack (yystackp
);
2281 /* Now pop stack until we find a state that shifts the error token. */
2282 yystackp
->yyerrState
= 3;
2283 while (yystackp
->yytops
.yystates
[0] != YY_NULL
)
2285 yyGLRState
*yys
= yystackp
->yytops
.yystates
[0];
2286 yyj
= yypact
[yys
->yylrState
];
2287 if (! yypact_value_is_default (yyj
))
2290 if (0 <= yyj
&& yyj
<= YYLAST
&& yycheck
[yyj
] == YYTERROR
2291 && yyisShiftAction (yytable
[yyj
]))
2293 /* Shift the error token. */]b4_locations_if([[
2294 /* First adjust its location.*/
2296 yystackp
->yyerror_range
[2].yystate
.yyloc
= yylloc
;
2297 YYLLOC_DEFAULT (yyerrloc
, (yystackp
->yyerror_range
), 2);]])[
2298 YY_SYMBOL_PRINT ("Shifting", yystos
[yytable
[yyj
]],
2299 &yylval
, &yyerrloc
);
2300 yyglrShift (yystackp
, 0, yytable
[yyj
],
2301 yys
->yyposn
, &yylval
]b4_locations_if([, &yyerrloc
])[);
2302 yys
= yystackp
->yytops
.yystates
[0];
2305 }]b4_locations_if([[
2306 yystackp
->yyerror_range
[1].yystate
.yyloc
= yys
->yyloc
;]])[
2307 if (yys
->yypred
!= YY_NULL
)
2308 yydestroyGLRState ("Error: popping", yys
]b4_user_args
[);
2309 yystackp
->yytops
.yystates
[0] = yys
->yypred
;
2310 yystackp
->yynextFree
-= 1;
2311 yystackp
->yyspaceLeft
+= 1;
2313 if (yystackp
->yytops
.yystates
[0] == YY_NULL
)
2314 yyFail (yystackp
][]b4_lpure_args
[, YY_NULL
);
2317 #define YYCHK1(YYE) \
2327 goto yyuser_error; \
2338 ]b4_c_ansi_function_def([yyparse
], [int], b4_parse_param
)[
2342 yyGLRStack
* const yystackp
= &yystack
;
2345 YYDPRINTF ((stderr
, "Starting parse\n"));
2348 yylval
= yyval_default
;
2350 #if defined YYLTYPE_IS_TRIVIAL && YYLTYPE_IS_TRIVIAL
2351 yylloc
.first_line
= yylloc
.last_line
= ]b4_location_initial_line
[;
2352 yylloc
.first_column
= yylloc
.last_column
= ]b4_location_initial_column
[;
2355 m4_ifdef([b4_initial_action
], [
2356 m4_pushdef([b4_at_dollar
], [yylloc
])dnl
2357 m4_pushdef([b4_dollar_dollar
], [yylval
])dnl
2358 /* User initialization code. */
2359 b4_user_initial_action
2360 m4_popdef([b4_dollar_dollar
])dnl
2361 m4_popdef([b4_at_dollar
])])dnl
2363 if (! yyinitGLRStack (yystackp
, YYINITDEPTH
))
2364 goto yyexhaustedlab
;
2365 switch (YYSETJMP (yystack
.yyexception_buffer
))
2368 case 1: goto yyabortlab
;
2369 case 2: goto yyexhaustedlab
;
2370 default: goto yybuglab
;
2372 yyglrShift (&yystack
, 0, 0, 0, &yylval
]b4_locations_if([, &yylloc
])[);
2375 while (YYID (yytrue
))
2377 /* For efficiency, we have two loops, the first of which is
2378 specialized to deterministic operation (single stack, no
2379 potential ambiguity). */
2381 while (YYID (yytrue
))
2385 const short int* yyconflicts
;
2387 yyStateNum yystate
= yystack
.yytops
.yystates
[0]->yylrState
;
2388 YYDPRINTF ((stderr
, "Entering state %d\n", yystate
));
2389 if (yystate
== YYFINAL
)
2391 if (yyisDefaultedState (yystate
))
2393 yyrule
= yydefaultAction (yystate
);
2396 ]b4_locations_if([[ yystack
.yyerror_range
[1].yystate
.yyloc
= yylloc
;]])[
2397 yyreportSyntaxError (&yystack
]b4_user_args
[);
2400 YYCHK1 (yyglrReduce (&yystack
, 0, yyrule
, yytrue
]b4_user_args
[));
2405 if (yychar
== YYEMPTY
)
2407 YYDPRINTF ((stderr
, "Reading a token: "));
2411 if (yychar
<= YYEOF
)
2413 yychar
= yytoken
= YYEOF
;
2414 YYDPRINTF ((stderr
, "Now at end of input.\n"));
2418 yytoken
= YYTRANSLATE (yychar
);
2419 YY_SYMBOL_PRINT ("Next token is", yytoken
, &yylval
, &yylloc
);
2422 yygetLRActions (yystate
, yytoken
, &yyaction
, &yyconflicts
);
2423 if (*yyconflicts
!= 0)
2425 if (yyisShiftAction (yyaction
))
2427 YY_SYMBOL_PRINT ("Shifting", yytoken
, &yylval
, &yylloc
);
2430 yyglrShift (&yystack
, 0, yyaction
, yyposn
, &yylval
]b4_locations_if([, &yylloc
])[);
2431 if (0 < yystack
.yyerrState
)
2432 yystack
.yyerrState
-= 1;
2434 else if (yyisErrorAction (yyaction
))
2436 ]b4_locations_if([[ yystack
.yyerror_range
[1].yystate
.yyloc
= yylloc
;]])[
2437 yyreportSyntaxError (&yystack
]b4_user_args
[);
2441 YYCHK1 (yyglrReduce (&yystack
, 0, -yyaction
, yytrue
]b4_user_args
[));
2445 while (YYID (yytrue
))
2447 yySymbol yytoken_to_shift
;
2450 for (yys
= 0; yys
< yystack
.yytops
.yysize
; yys
+= 1)
2451 yystackp
->yytops
.yylookaheadNeeds
[yys
] = yychar
!= YYEMPTY
;
2453 /* yyprocessOneStack returns one of three things:
2455 - An error flag. If the caller is yyprocessOneStack, it
2456 immediately returns as well. When the caller is finally
2457 yyparse, it jumps to an error label via YYCHK1.
2459 - yyok, but yyprocessOneStack has invoked yymarkStackDeleted
2460 (&yystack, yys), which sets the top state of yys to NULL. Thus,
2461 yyparse's following invocation of yyremoveDeletes will remove
2464 - yyok, when ready to shift a token.
2466 Except in the first case, yyparse will invoke yyremoveDeletes and
2467 then shift the next token onto all remaining stacks. This
2468 synchronization of the shift (that is, after all preceding
2469 reductions on all stacks) helps prevent double destructor calls
2470 on yylval in the event of memory exhaustion. */
2472 for (yys
= 0; yys
< yystack
.yytops
.yysize
; yys
+= 1)
2473 YYCHK1 (yyprocessOneStack (&yystack
, yys
, yyposn
]b4_lpure_args
[));
2474 yyremoveDeletes (&yystack
);
2475 if (yystack
.yytops
.yysize
== 0)
2477 yyundeleteLastStack (&yystack
);
2478 if (yystack
.yytops
.yysize
== 0)
2479 yyFail (&yystack
][]b4_lpure_args
[, YY_("syntax error"));
2480 YYCHK1 (yyresolveStack (&yystack
]b4_user_args
[));
2481 YYDPRINTF ((stderr
, "Returning to deterministic operation.\n"));
2482 ]b4_locations_if([[ yystack
.yyerror_range
[1].yystate
.yyloc
= yylloc
;]])[
2483 yyreportSyntaxError (&yystack
]b4_user_args
[);
2487 /* If any yyglrShift call fails, it will fail after shifting. Thus,
2488 a copy of yylval will already be on stack 0 in the event of a
2489 failure in the following loop. Thus, yychar is set to YYEMPTY
2490 before the loop to make sure the user destructor for yylval isn't
2492 yytoken_to_shift
= YYTRANSLATE (yychar
);
2495 for (yys
= 0; yys
< yystack
.yytops
.yysize
; yys
+= 1)
2498 const short int* yyconflicts
;
2499 yyStateNum yystate
= yystack
.yytops
.yystates
[yys
]->yylrState
;
2500 yygetLRActions (yystate
, yytoken_to_shift
, &yyaction
,
2502 /* Note that yyconflicts were handled by yyprocessOneStack. */
2503 YYDPRINTF ((stderr
, "On stack %lu, ", (unsigned long int) yys
));
2504 YY_SYMBOL_PRINT ("shifting", yytoken_to_shift
, &yylval
, &yylloc
);
2505 yyglrShift (&yystack
, yys
, yyaction
, yyposn
,
2506 &yylval
]b4_locations_if([, &yylloc
])[);
2507 YYDPRINTF ((stderr
, "Stack %lu now in state #%d\n",
2508 (unsigned long int) yys
,
2509 yystack
.yytops
.yystates
[yys
]->yylrState
));
2512 if (yystack
.yytops
.yysize
== 1)
2514 YYCHK1 (yyresolveStack (&yystack
]b4_user_args
[));
2515 YYDPRINTF ((stderr
, "Returning to deterministic operation.\n"));
2516 yycompressStack (&yystack
);
2522 yyrecoverSyntaxError (&yystack
]b4_user_args
[);
2523 yyposn
= yystack
.yytops
.yystates
[0]->yyposn
;
2539 yyerror (]b4_lyyerror_args
[YY_("memory exhausted"));
2544 if (yychar
!= YYEMPTY
)
2545 yydestruct ("Cleanup: discarding lookahead",
2546 YYTRANSLATE (yychar
), &yylval
]b4_locuser_args([&yylloc
])[);
2548 /* If the stack is well-formed, pop the stack until it is empty,
2549 destroying its entries as we go. But free the stack regardless
2550 of whether it is well-formed. */
2551 if (yystack
.yyitems
)
2553 yyGLRState
** yystates
= yystack
.yytops
.yystates
;
2556 size_t yysize
= yystack
.yytops
.yysize
;
2558 for (yyk
= 0; yyk
< yysize
; yyk
+= 1)
2561 while (yystates
[yyk
])
2563 yyGLRState
*yys
= yystates
[yyk
];
2564 ]b4_locations_if([[ yystack
.yyerror_range
[1].yystate
.yyloc
= yys
->yyloc
;]]
2565 )[ if (yys
->yypred
!= YY_NULL
)
2566 yydestroyGLRState ("Cleanup: popping", yys
]b4_user_args
[);
2567 yystates
[yyk
] = yys
->yypred
;
2568 yystack
.yynextFree
-= 1;
2569 yystack
.yyspaceLeft
+= 1;
2574 yyfreeGLRStack (&yystack
);
2577 /* Make sure YYID is used. */
2578 return YYID (yyresult
);
2581 /* DEBUGGING ONLY */
2583 static void yypstack (yyGLRStack
* yystackp
, size_t yyk
)
2584 __attribute__ ((__unused__
));
2585 static void yypdumpstack (yyGLRStack
* yystackp
) __attribute__ ((__unused__
));
2588 yy_yypstack (yyGLRState
* yys
)
2592 yy_yypstack (yys
->yypred
);
2593 YYFPRINTF (stderr
, " -> ");
2595 YYFPRINTF (stderr
, "%d@@%lu", yys
->yylrState
,
2596 (unsigned long int) yys
->yyposn
);
2600 yypstates (yyGLRState
* yyst
)
2602 if (yyst
== YY_NULL
)
2603 YYFPRINTF (stderr
, "<null>");
2606 YYFPRINTF (stderr
, "\n");
2610 yypstack (yyGLRStack
* yystackp
, size_t yyk
)
2612 yypstates (yystackp
->yytops
.yystates
[yyk
]);
2615 #define YYINDEX(YYX) \
2616 ((YYX) == YY_NULL ? -1 : (yyGLRStackItem*) (YYX) - yystackp->yyitems)
2620 yypdumpstack (yyGLRStack
* yystackp
)
2622 yyGLRStackItem
* yyp
;
2624 for (yyp
= yystackp
->yyitems
; yyp
< yystackp
->yynextFree
; yyp
+= 1)
2626 YYFPRINTF (stderr
, "%3lu. ",
2627 (unsigned long int) (yyp
- yystackp
->yyitems
));
2628 if (*(yybool
*) yyp
)
2630 YYFPRINTF (stderr
, "Res: %d, LR State: %d, posn: %lu, pred: %ld",
2631 yyp
->yystate
.yyresolved
, yyp
->yystate
.yylrState
,
2632 (unsigned long int) yyp
->yystate
.yyposn
,
2633 (long int) YYINDEX (yyp
->yystate
.yypred
));
2634 if (! yyp
->yystate
.yyresolved
)
2635 YYFPRINTF (stderr
, ", firstVal: %ld",
2636 (long int) YYINDEX (yyp
->yystate
2637 .yysemantics
.yyfirstVal
));
2641 YYFPRINTF (stderr
, "Option. rule: %d, state: %ld, next: %ld",
2642 yyp
->yyoption
.yyrule
- 1,
2643 (long int) YYINDEX (yyp
->yyoption
.yystate
),
2644 (long int) YYINDEX (yyp
->yyoption
.yynext
));
2646 YYFPRINTF (stderr
, "\n");
2648 YYFPRINTF (stderr
, "Tops:");
2649 for (yyi
= 0; yyi
< yystackp
->yytops
.yysize
; yyi
+= 1)
2650 YYFPRINTF (stderr
, "%lu: %ld; ", (unsigned long int) yyi
,
2651 (long int) YYINDEX (yystackp
->yytops
.yystates
[yyi
]));
2652 YYFPRINTF (stderr
, "\n");
2659 dnl glr
.cc produces its own header
.
2661 m4_if(b4_skeleton
, ["glr.c"],
2663 [@
output(b4_spec_defines_file@
)@
2664 b4_copyright([Skeleton interface
for Bison GLR parsers in C
],
2667 b4_shared_declarations
2670 [[extern YYSTYPE
]b4_prefix
[lval
;]])
2672 b4_locations_if([b4_pure_if([],
2673 [extern YYLTYPE
]b4_prefix
[lloc
;])