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]])[
167 ]b4_token_enums(b4_tokens
)[
168 ]b4_declare_yylstype
[
169 ]b4_percent_code_get([[provides]])[]dnl
177 # We do want M4 expansion after # for CPP macros.
180 @
output(b4_parser_file_name@
)@
181 b4_copyright([Skeleton implementation
for Bison GLR parsers in C
],
184 /* C GLR parser skeleton written by Paul Hilfinger. */
188 b4_percent_code_get([[top]])[]dnl
189 m4_if(b4_prefix
, [yy
], [],
190 [/* Substitute the variable and function names. */
191 #define yyparse b4_prefix[]parse
192 #define yylex b4_prefix[]lex
193 #define yyerror b4_prefix[]error
194 #define yylval b4_prefix[]lval
195 #define yychar b4_prefix[]char
196 #define yydebug b4_prefix[]debug
197 #define yynerrs b4_prefix[]nerrs
198 #define yylloc b4_prefix[]lloc])[
200 /* Copy the first part of user declarations. */
201 ]b4_user_pre_prologue
[
205 ]b4_defines_if([[#include "@basename(]b4_spec_defines_file[@)"]],
206 [b4_shared_declarations
])[
208 /* Enabling traces. */
210 # define YYDEBUG ]b4_debug_flag[
213 /* Enabling verbose error messages. */
214 #ifdef YYERROR_VERBOSE
215 # undef YYERROR_VERBOSE
216 # define YYERROR_VERBOSE 1
218 # define YYERROR_VERBOSE ]b4_error_verbose_flag[
221 /* Enabling the token table. */
222 #ifndef YYTOKEN_TABLE
223 # define YYTOKEN_TABLE ]b4_token_table[
226 /* Default (constant) value used for initialization for null
227 right-hand sides. Unlike the standard yacc.c template,
228 here we set the default value of $$ to a zeroed-out value.
229 Since the default value is undefined, this behavior is
230 technically correct. */
231 static YYSTYPE yyval_default
;
233 /* Copy the second part of user declarations. */
234 ]b4_user_post_prologue
235 b4_percent_code_get
[]dnl
242 # if defined YYENABLE_NLS && YYENABLE_NLS
244 # include <libintl.h> /* INFRINGES ON USER NAME SPACE */
245 # define YY_(msgid) dgettext ("bison-runtime", msgid)
249 # define YY_(msgid) msgid
253 /* Suppress unused-variable warnings by "using" E. */
254 #if ! defined lint || defined __GNUC__
255 # define YYUSE(e) ((void) (e))
257 # define YYUSE(e) /* empty */
260 /* Identity function, used to suppress warnings about constant conditions. */
264 ]b4_c_function_def([YYID
], [static int], [[int i
], [i
]])[
274 # define YYMALLOC malloc
277 # define YYREALLOC realloc
280 #define YYSIZEMAX ((size_t) -1)
285 typedef unsigned char yybool
;
292 # define YYJMP_BUF jmp_buf
293 # define YYSETJMP(env) setjmp (env)
294 # define YYLONGJMP(env, val) longjmp (env, val)
301 #ifndef __attribute__
302 /* This feature is available in gcc versions 2.5 and later. */
303 # if (! defined __GNUC__ || __GNUC__ < 2 \
304 || (__GNUC__ == 2 && __GNUC_MINOR__ < 5))
305 # define __attribute__(Spec) /* empty */
309 ]b4_locations_if([#define YYOPTIONAL_LOC(Name) Name],[
311 # define YYOPTIONAL_LOC(Name) /* empty */
313 # define YYOPTIONAL_LOC(Name) Name __attribute__ ((__unused__))
317 # define YYASSERT(condition) ((void) ((condition) || (abort (), 0)))
320 /* YYFINAL -- State number of the termination state. */
321 #define YYFINAL ]b4_final_state_number[
322 /* YYLAST -- Last index in YYTABLE. */
323 #define YYLAST ]b4_last[
325 /* YYNTOKENS -- Number of terminals. */
326 #define YYNTOKENS ]b4_tokens_number[
327 /* YYNNTS -- Number of nonterminals. */
328 #define YYNNTS ]b4_nterms_number[
329 /* YYNRULES -- Number of rules. */
330 #define YYNRULES ]b4_rules_number[
331 /* YYNRULES -- Number of states. */
332 #define YYNSTATES ]b4_states_number[
333 /* YYMAXRHS -- Maximum number of symbols on right-hand side of rule. */
334 #define YYMAXRHS ]b4_r2_max[
335 /* YYMAXLEFT -- Maximum number of symbols to the left of a handle
336 accessed by $0, $-1, etc., in any rule. */
337 #define YYMAXLEFT ]b4_max_left_semantic_context[
339 /* YYTRANSLATE(X) -- Bison symbol number corresponding to X. */
340 #define YYUNDEFTOK ]b4_undef_token_number[
341 #define YYMAXUTOK ]b4_user_token_number_max[
343 #define YYTRANSLATE(YYX) \
344 ((unsigned int) (YYX) <= YYMAXUTOK ? yytranslate[YYX] : YYUNDEFTOK)
346 /* YYTRANSLATE[YYLEX] -- Bison symbol number corresponding to YYLEX. */
347 static const ]b4_int_type_for([b4_translate
])[ yytranslate
[] =
353 /* YYPRHS[YYN] -- Index of the first RHS symbol of rule number YYN in
355 static const ]b4_int_type_for([b4_prhs
])[ yyprhs
[] =
360 /* YYRHS -- A `-1'-separated list of the rules' RHS. */
361 static const ]b4_int_type_for([b4_rhs
])[ yyrhs
[] =
366 /* YYRLINE[YYN] -- source line where rule number YYN was defined. */
367 static const ]b4_int_type_for([b4_rline
])[ yyrline
[] =
373 #if YYDEBUG || YYERROR_VERBOSE || YYTOKEN_TABLE
374 /* YYTNAME[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM.
375 First, the terminals, then, starting at YYNTOKENS, nonterminals. */
376 static const char *const yytname
[] =
382 /* YYR1[YYN] -- Symbol number of symbol that rule YYN derives. */
383 static const ]b4_int_type_for([b4_r1
])[ yyr1
[] =
388 /* YYR2[YYN] -- Number of symbols composing right hand side of rule YYN. */
389 static const ]b4_int_type_for([b4_r2
])[ yyr2
[] =
394 /* YYDPREC[RULE-NUM] -- Dynamic precedence of rule #RULE-NUM (0 if none). */
395 static const ]b4_int_type_for([b4_dprec
])[ yydprec
[] =
400 /* YYMERGER[RULE-NUM] -- Index of merging function for rule #RULE-NUM. */
401 static const ]b4_int_type_for([b4_merger
])[ yymerger
[] =
406 /* YYDEFACT[S] -- default reduction number in state S. Performed when
407 YYTABLE doesn't specify something else to do. Zero means the default
409 static const ]b4_int_type_for([b4_defact
])[ yydefact
[] =
414 /* YYPDEFGOTO[NTERM-NUM]. */
415 static const ]b4_int_type_for([b4_defgoto
])[ yydefgoto
[] =
420 /* YYPACT[STATE-NUM] -- Index in YYTABLE of the portion describing
422 #define YYPACT_NINF ]b4_pact_ninf[
423 static const ]b4_int_type_for([b4_pact
])[ yypact
[] =
428 /* YYPGOTO[NTERM-NUM]. */
429 static const ]b4_int_type_for([b4_pgoto
])[ yypgoto
[] =
434 /* YYTABLE[YYPACT[STATE-NUM]]. What to do in state STATE-NUM. If
435 positive, shift that token. If negative, reduce the rule which
436 number is the opposite. If YYTABLE_NINF, syntax error. */
437 #define YYTABLE_NINF ]b4_table_ninf[
438 static const ]b4_int_type_for([b4_table
])[ yytable
[] =
443 /* YYCONFLP[YYPACT[STATE-NUM]] -- Pointer into YYCONFL of start of
444 list of conflicting reductions corresponding to action entry for
445 state STATE-NUM in yytable. 0 means no conflicts. The list in
446 yyconfl is terminated by a rule number of 0. */
447 static const ]b4_int_type_for([b4_conflict_list_heads
])[ yyconflp
[] =
449 ]b4_conflict_list_heads
[
452 /* YYCONFL[I] -- lists of conflicting rule numbers, each terminated by
453 0, pointed into by YYCONFLP. */
454 ]dnl Do
not use b4_int_type_for here
, since there are places where
455 dnl pointers onto yyconfl are taken
, which type is
"short int *".
456 dnl We probably ought to introduce a type
for confl
.
457 [static const short int yyconfl
[] =
459 ]b4_conflicting_rules
[
462 static const ]b4_int_type_for([b4_check
])[ yycheck
[] =
467 /* YYSTOS[STATE-NUM] -- The (internal number of the) accessing
468 symbol of state STATE-NUM. */
469 static const ]b4_int_type_for([b4_stos
])[ yystos
[] =
475 /* Prevent warning if -Wmissing-prototypes. */
476 ]b4_c_ansi_function_decl([yyparse
], [int], b4_parse_param
)[
478 /* Error token number */
481 /* YYLLOC_DEFAULT -- Set CURRENT to span from RHS[1] to RHS[N].
482 If N is 0, then set CURRENT to the empty location which ends
483 the previous symbol: RHS[0] (always defined). */
486 #define YYRHSLOC(Rhs, K) ((Rhs)[K].yystate.yyloc)
487 #ifndef YYLLOC_DEFAULT
488 # define YYLLOC_DEFAULT(Current, Rhs, N) \
492 (Current).first_line = YYRHSLOC (Rhs, 1).first_line; \
493 (Current).first_column = YYRHSLOC (Rhs, 1).first_column; \
494 (Current).last_line = YYRHSLOC (Rhs, N).last_line; \
495 (Current).last_column = YYRHSLOC (Rhs, N).last_column; \
499 (Current).first_line = (Current).last_line = \
500 YYRHSLOC (Rhs, 0).last_line; \
501 (Current).first_column = (Current).last_column = \
502 YYRHSLOC (Rhs, 0).last_column; \
506 /* YY_LOCATION_PRINT -- Print the location on the stream.
507 This macro was not mandated originally: define only if we know
508 we won't break user code: when these are the locations we know. */
510 # define YY_LOCATION_PRINT(File, Loc) \
511 fprintf (File, "%d.%d-%d.%d", \
512 (Loc).first_line, (Loc).first_column, \
513 (Loc).last_line, (Loc).last_column)
516 #ifndef YYLLOC_DEFAULT
517 # define YYLLOC_DEFAULT(Current, Rhs, N) ((void) 0)
521 #ifndef YY_LOCATION_PRINT
522 # define YY_LOCATION_PRINT(File, Loc) ((void) 0)
526 /* YYLEX -- calling `yylex' with the right arguments. */
527 #define YYLEX ]b4_c_function_call([yylex], [int], b4_lex_param)[
532 #define yynerrs (yystackp->yyerrcnt)
534 #define yychar (yystackp->yyrawchar)
536 #define yylval (yystackp->yyval)
538 #define yylloc (yystackp->yyloc)
539 m4_if(b4_prefix
[], [yy
], [],
540 [#define b4_prefix[]nerrs yynerrs
541 #define b4_prefix[]char yychar
542 #define b4_prefix[]lval yylval
543 #define b4_prefix[]lloc yylloc])],
544 [YYSTYPE yylval
;]b4_locations_if([[
550 static const int YYEOF
= 0;
551 static const int YYEMPTY
= -2;
553 typedef enum { yyok
, yyaccept
, yyabort
, yyerr
} YYRESULTTAG
;
556 do { YYRESULTTAG yyflag = YYE; if (yyflag != yyok) return yyflag; } \
562 # define YYFPRINTF fprintf
565 # define YYDPRINTF(Args) \
571 ]b4_yy_symbol_print_generate([b4_c_ansi_function_def
])[
573 # define YY_SYMBOL_PRINT(Title, Type, Value, Location) \
577 YYFPRINTF (stderr, "%s ", Title); \
578 yy_symbol_print (stderr, Type, Value]b4_locuser_args([Location])[); \
579 YYFPRINTF (stderr, "\n"); \
583 /* Nonzero means print parse trace. It is left uninitialized so that
584 multiple parsers can coexist. */
589 # define YYDPRINTF(Args)
590 # define YY_SYMBOL_PRINT(Title, Type, Value, Location)
592 #endif /* !YYDEBUG */
594 /* YYINITDEPTH -- initial size of the parser's stacks. */
596 # define YYINITDEPTH ]b4_stack_depth_init[
599 /* YYMAXDEPTH -- maximum size the stacks can grow to (effective only
600 if the built-in stack extension method is used).
602 Do not make this value too large; the results are undefined if
603 SIZE_MAX < YYMAXDEPTH * sizeof (GLRStackItem)
604 evaluated with infinite-precision integer arithmetic. */
607 # define YYMAXDEPTH ]b4_stack_depth_max[
610 /* Minimum number of free items on the stack allowed after an
611 allocation. This is to allow allocation and initialization
612 to be completed by functions that call yyexpandGLRStack before the
613 stack is expanded, thus insuring that all necessary pointers get
614 properly redirected to new data. */
617 #ifndef YYSTACKEXPANDABLE
618 # if (! defined __cplusplus \
619 || (]b4_locations_if([[defined YYLTYPE_IS_TRIVIAL && YYLTYPE_IS_TRIVIAL \
620 && ]])[defined YYSTYPE_IS_TRIVIAL && YYSTYPE_IS_TRIVIAL))
621 # define YYSTACKEXPANDABLE 1
623 # define YYSTACKEXPANDABLE 0
627 #if YYSTACKEXPANDABLE
628 # define YY_RESERVE_GLRSTACK(Yystack) \
630 if (Yystack->yyspaceLeft < YYHEADROOM) \
631 yyexpandGLRStack (Yystack); \
634 # define YY_RESERVE_GLRSTACK(Yystack) \
636 if (Yystack->yyspaceLeft < YYHEADROOM) \
637 yyMemoryExhausted (Yystack); \
645 # if defined __GLIBC__ && defined _STRING_H && defined _GNU_SOURCE
646 # define yystpcpy stpcpy
648 /* Copy YYSRC to YYDEST, returning the address of the terminating '\0' in
651 yystpcpy (char *yydest
, const char *yysrc
)
654 const char *yys
= yysrc
;
656 while ((*yyd
++ = *yys
++) != '\0')
665 /* Copy to YYRES the contents of YYSTR after stripping away unnecessary
666 quotes and backslashes, so that it's suitable for yyerror. The
667 heuristic is that double-quoting is unnecessary unless the string
668 contains an apostrophe, a comma, or backslash (other than
669 backslash-backslash). YYSTR is taken from yytname. If YYRES is
670 null, do not copy; instead, return the length of what the result
673 yytnamerr (char *yyres
, const char *yystr
)
678 char const *yyp
= yystr
;
685 goto do_not_strip_quotes
;
689 goto do_not_strip_quotes
;
702 do_not_strip_quotes
: ;
706 return strlen (yystr
);
708 return yystpcpy (yyres
, yystr
) - yyres
;
712 #endif /* !YYERROR_VERBOSE */
714 /** State numbers, as in LALR(1) machine */
715 typedef int yyStateNum
;
717 /** Rule numbers, as in LALR(1) machine */
718 typedef int yyRuleNum
;
720 /** Grammar symbol */
721 typedef short int yySymbol
;
723 /** Item references, as in LALR(1) machine */
724 typedef short int yyItemNum
;
726 typedef struct yyGLRState yyGLRState
;
727 typedef struct yyGLRStateSet yyGLRStateSet
;
728 typedef struct yySemanticOption yySemanticOption
;
729 typedef union yyGLRStackItem yyGLRStackItem
;
730 typedef struct yyGLRStack yyGLRStack
;
733 /** Type tag: always true. */
735 /** Type tag for yysemantics. If true, yysval applies, otherwise
736 * yyfirstVal applies. */
738 /** Number of corresponding LALR(1) machine state. */
739 yyStateNum yylrState
;
740 /** Preceding state in this stack */
742 /** Source position of the first token produced by my symbol */
745 /** First in a chain of alternative reductions producing the
746 * non-terminal corresponding to this state, threaded through
748 yySemanticOption
* yyfirstVal
;
749 /** Semantic value for this state. */
751 } yysemantics
;]b4_locations_if([[
752 /** Source location for this state. */
756 struct yyGLRStateSet
{
757 yyGLRState
** yystates
;
758 /** During nondeterministic operation, yylookaheadNeeds tracks which
759 * stacks have actually needed the current lookahead. During deterministic
760 * operation, yylookaheadNeeds[0] is not maintained since it would merely
761 * duplicate yychar != YYEMPTY. */
762 yybool
* yylookaheadNeeds
;
763 size_t yysize
, yycapacity
;
766 struct yySemanticOption
{
767 /** Type tag: always false. */
769 /** Rule number for this reduction */
771 /** The last RHS state in the list of states to be reduced. */
773 /** The lookahead for this reduction. */
775 YYSTYPE yyval
;]b4_locations_if([[
777 /** Next sibling in chain of options. To facilitate merging,
778 * options are chained in decreasing order by address. */
779 yySemanticOption
* yynext
;
782 /** Type of the items in the GLR stack. The yyisState field
783 * indicates which item of the union is valid. */
784 union yyGLRStackItem
{
786 yySemanticOption yyoption
;
791 ]b4_locations_if([[ /* To compute the location of the error token. */
792 yyGLRStackItem yyerror_range
[3];]])[
797 YYSTYPE yyval
;]b4_locations_if([[
800 YYJMP_BUF yyexception_buffer
;
801 yyGLRStackItem
* yyitems
;
802 yyGLRStackItem
* yynextFree
;
804 yyGLRState
* yysplitPoint
;
805 yyGLRState
* yylastDeleted
;
806 yyGLRStateSet yytops
;
809 #if YYSTACKEXPANDABLE
810 static void yyexpandGLRStack (yyGLRStack
* yystackp
);
813 static void yyFail (yyGLRStack
* yystackp
]b4_pure_formals
[, const char* yymsg
)
814 __attribute__ ((__noreturn__
));
816 yyFail (yyGLRStack
* yystackp
]b4_pure_formals
[, const char* yymsg
)
818 if (yymsg
!= YY_NULL
)
819 yyerror (]b4_yyerror_args
[yymsg
);
820 YYLONGJMP (yystackp
->yyexception_buffer
, 1);
823 static void yyMemoryExhausted (yyGLRStack
* yystackp
)
824 __attribute__ ((__noreturn__
));
826 yyMemoryExhausted (yyGLRStack
* yystackp
)
828 YYLONGJMP (yystackp
->yyexception_buffer
, 2);
831 #if YYDEBUG || YYERROR_VERBOSE
832 /** A printable representation of TOKEN. */
833 static inline const char*
834 yytokenName (yySymbol yytoken
)
836 if (yytoken
== YYEMPTY
)
839 return yytname
[yytoken
];
843 /** Fill in YYVSP[YYLOW1 .. YYLOW0-1] from the chain of states starting
844 * at YYVSP[YYLOW0].yystate.yypred. Leaves YYVSP[YYLOW1].yystate.yypred
845 * containing the pointer to the next state in the chain. */
846 static void yyfillin (yyGLRStackItem
*, int, int) __attribute__ ((__unused__
));
848 yyfillin (yyGLRStackItem
*yyvsp
, int yylow0
, int yylow1
)
851 yyGLRState
*s
= yyvsp
[yylow0
].yystate
.yypred
;
852 for (i
= yylow0
-1; i
>= yylow1
; i
-= 1)
854 YYASSERT (s
->yyresolved
);
855 yyvsp
[i
].yystate
.yyresolved
= yytrue
;
856 yyvsp
[i
].yystate
.yysemantics
.yysval
= s
->yysemantics
.yysval
;]b4_locations_if([[
857 yyvsp
[i
].yystate
.yyloc
= s
->yyloc
;]])[
858 s
= yyvsp
[i
].yystate
.yypred
= s
->yypred
;
862 /* Do nothing if YYNORMAL or if *YYLOW <= YYLOW1. Otherwise, fill in
863 * YYVSP[YYLOW1 .. *YYLOW-1] as in yyfillin and set *YYLOW = YYLOW1.
864 * For convenience, always return YYLOW1. */
865 static inline int yyfill (yyGLRStackItem
*, int *, int, yybool
)
866 __attribute__ ((__unused__
));
868 yyfill (yyGLRStackItem
*yyvsp
, int *yylow
, int yylow1
, yybool yynormal
)
870 if (!yynormal
&& yylow1
< *yylow
)
872 yyfillin (yyvsp
, *yylow
, yylow1
);
878 /** Perform user action for rule number YYN, with RHS length YYRHSLEN,
879 * and top stack item YYVSP. YYLVALP points to place to put semantic
880 * value ($$), and yylocp points to place for location information
881 * (@@$). Returns yyok for normal return, yyaccept for YYACCEPT,
882 * yyerr for YYERROR, yyabort for YYABORT. */
883 /*ARGSUSED*/ static YYRESULTTAG
884 yyuserAction (yyRuleNum yyn
, int yyrhslen
, yyGLRStackItem
* yyvsp
,
885 yyGLRStack
* yystackp
,
886 YYSTYPE
* yyvalp
]b4_locuser_formals
[)
888 yybool yynormal
__attribute__ ((__unused__
)) =
889 (yystackp
->yysplitPoint
== YY_NULL
);
891 ]b4_parse_param_use
[]dnl
893 # define yyerrok (yystackp->yyerrState = 0)
895 # define YYACCEPT return yyaccept
897 # define YYABORT return yyabort
899 # define YYERROR return yyerrok, yyerr
901 # define YYRECOVERING() (yystackp->yyerrState != 0)
903 # define yyclearin (yychar = YYEMPTY)
905 # define YYFILL(N) yyfill (yyvsp, &yylow, N, yynormal)
907 # define YYBACKUP(Token, Value) \
908 return yyerror (]b4_yyerror_args[YY_("syntax error: cannot back up")), \
913 *yyvalp
= yyval_default
;
915 *yyvalp
= yyvsp
[YYFILL (1-yyrhslen
)].yystate
.yysemantics
.yysval
;]b4_locations_if([[
916 YYLLOC_DEFAULT ((*yylocp
), (yyvsp
- yyrhslen
), yyrhslen
);
917 yystackp
->yyerror_range
[1].yystate
.yyloc
= *yylocp
;
936 /*ARGSUSED*/ static void
937 yyuserMerge (int yyn
, YYSTYPE
* yy0
, YYSTYPE
* yy1
)
949 /* Bison grammar-table manipulation. */
951 ]b4_yydestruct_generate([b4_c_ansi_function_def
])[
953 /** Number of symbols composing the right hand side of rule #RULE. */
955 yyrhsLength (yyRuleNum yyrule
)
961 yydestroyGLRState (char const *yymsg
, yyGLRState
*yys
]b4_user_formals
[)
964 yydestruct (yymsg
, yystos
[yys
->yylrState
],
965 &yys
->yysemantics
.yysval
]b4_locuser_args([&yys
->yyloc
])[);
971 if (yys
->yysemantics
.yyfirstVal
)
972 YYFPRINTF (stderr
, "%s unresolved ", yymsg
);
974 YYFPRINTF (stderr
, "%s incomplete ", yymsg
);
975 yy_symbol_print (stderr
, yystos
[yys
->yylrState
],
976 YY_NULL
]b4_locuser_args([&yys
->yyloc
])[);
977 YYFPRINTF (stderr
, "\n");
981 if (yys
->yysemantics
.yyfirstVal
)
983 yySemanticOption
*yyoption
= yys
->yysemantics
.yyfirstVal
;
986 for (yyrh
= yyoption
->yystate
, yyn
= yyrhsLength (yyoption
->yyrule
);
988 yyrh
= yyrh
->yypred
, yyn
-= 1)
989 yydestroyGLRState (yymsg
, yyrh
]b4_user_args
[);
994 /** Left-hand-side symbol for rule #RULE. */
995 static inline yySymbol
996 yylhsNonterm (yyRuleNum yyrule
)
1001 #define yypact_value_is_default(yystate) \
1002 ]b4_table_value_equals([[pact]], [[yystate]], [b4_pact_ninf])[
1004 /** True iff LR state STATE has only a default reduction (regardless
1006 static inline yybool
1007 yyisDefaultedState (yyStateNum yystate
)
1009 return yypact_value_is_default (yypact
[yystate
]);
1012 /** The default reduction for STATE, assuming it has one. */
1013 static inline yyRuleNum
1014 yydefaultAction (yyStateNum yystate
)
1016 return yydefact
[yystate
];
1019 #define yytable_value_is_error(yytable_value) \
1020 ]b4_table_value_equals([[table]], [[yytable_value]], [b4_table_ninf])[
1022 /** Set *YYACTION to the action to take in YYSTATE on seeing YYTOKEN.
1024 * R < 0: Reduce on rule -R.
1026 * R > 0: Shift to state R.
1027 * Set *CONFLICTS to a pointer into yyconfl to 0-terminated list of
1028 * conflicting reductions.
1031 yygetLRActions (yyStateNum yystate
, int yytoken
,
1032 int* yyaction
, const short int** yyconflicts
)
1034 int yyindex
= yypact
[yystate
] + yytoken
;
1035 if (yypact_value_is_default (yypact
[yystate
])
1036 || yyindex
< 0 || YYLAST
< yyindex
|| yycheck
[yyindex
] != yytoken
)
1038 *yyaction
= -yydefact
[yystate
];
1039 *yyconflicts
= yyconfl
;
1041 else if (! yytable_value_is_error (yytable
[yyindex
]))
1043 *yyaction
= yytable
[yyindex
];
1044 *yyconflicts
= yyconfl
+ yyconflp
[yyindex
];
1049 *yyconflicts
= yyconfl
+ yyconflp
[yyindex
];
1053 static inline yyStateNum
1054 yyLRgotoState (yyStateNum yystate
, yySymbol yylhs
)
1057 yyr
= yypgoto
[yylhs
- YYNTOKENS
] + yystate
;
1058 if (0 <= yyr
&& yyr
<= YYLAST
&& yycheck
[yyr
] == yystate
)
1059 return yytable
[yyr
];
1061 return yydefgoto
[yylhs
- YYNTOKENS
];
1064 static inline yybool
1065 yyisShiftAction (int yyaction
)
1067 return 0 < yyaction
;
1070 static inline yybool
1071 yyisErrorAction (int yyaction
)
1073 return yyaction
== 0;
1078 /** Return a fresh GLRStackItem. Callers should call
1079 * YY_RESERVE_GLRSTACK afterwards to make sure there is sufficient
1082 static inline yyGLRStackItem
*
1083 yynewGLRStackItem (yyGLRStack
* yystackp
, yybool yyisState
)
1085 yyGLRStackItem
* yynewItem
= yystackp
->yynextFree
;
1086 yystackp
->yyspaceLeft
-= 1;
1087 yystackp
->yynextFree
+= 1;
1088 yynewItem
->yystate
.yyisState
= yyisState
;
1092 /** Add a new semantic action that will execute the action for rule
1093 * RULENUM on the semantic values in RHS to the list of
1094 * alternative actions for STATE. Assumes that RHS comes from
1095 * stack #K of *STACKP. */
1097 yyaddDeferredAction (yyGLRStack
* yystackp
, size_t yyk
, yyGLRState
* yystate
,
1098 yyGLRState
* rhs
, yyRuleNum yyrule
)
1100 yySemanticOption
* yynewOption
=
1101 &yynewGLRStackItem (yystackp
, yyfalse
)->yyoption
;
1102 yynewOption
->yystate
= rhs
;
1103 yynewOption
->yyrule
= yyrule
;
1104 if (yystackp
->yytops
.yylookaheadNeeds
[yyk
])
1106 yynewOption
->yyrawchar
= yychar
;
1107 yynewOption
->yyval
= yylval
;]b4_locations_if([
1108 yynewOption
->yyloc
= yylloc
;])[
1111 yynewOption
->yyrawchar
= YYEMPTY
;
1112 yynewOption
->yynext
= yystate
->yysemantics
.yyfirstVal
;
1113 yystate
->yysemantics
.yyfirstVal
= yynewOption
;
1115 YY_RESERVE_GLRSTACK (yystackp
);
1120 /** Initialize SET to a singleton set containing an empty stack. */
1122 yyinitStateSet (yyGLRStateSet
* yyset
)
1125 yyset
->yycapacity
= 16;
1126 yyset
->yystates
= (yyGLRState
**) YYMALLOC (16 * sizeof yyset
->yystates
[0]);
1127 if (! yyset
->yystates
)
1129 yyset
->yystates
[0] = YY_NULL
;
1130 yyset
->yylookaheadNeeds
=
1131 (yybool
*) YYMALLOC (16 * sizeof yyset
->yylookaheadNeeds
[0]);
1132 if (! yyset
->yylookaheadNeeds
)
1134 YYFREE (yyset
->yystates
);
1140 static void yyfreeStateSet (yyGLRStateSet
* yyset
)
1142 YYFREE (yyset
->yystates
);
1143 YYFREE (yyset
->yylookaheadNeeds
);
1146 /** Initialize STACK to a single empty stack, with total maximum
1147 * capacity for all stacks of SIZE. */
1149 yyinitGLRStack (yyGLRStack
* yystackp
, size_t yysize
)
1151 yystackp
->yyerrState
= 0;
1153 yystackp
->yyspaceLeft
= yysize
;
1155 (yyGLRStackItem
*) YYMALLOC (yysize
* sizeof yystackp
->yynextFree
[0]);
1156 if (!yystackp
->yyitems
)
1158 yystackp
->yynextFree
= yystackp
->yyitems
;
1159 yystackp
->yysplitPoint
= YY_NULL
;
1160 yystackp
->yylastDeleted
= YY_NULL
;
1161 return yyinitStateSet (&yystackp
->yytops
);
1165 #if YYSTACKEXPANDABLE
1166 # define YYRELOC(YYFROMITEMS,YYTOITEMS,YYX,YYTYPE) \
1167 &((YYTOITEMS) - ((YYFROMITEMS) - (yyGLRStackItem*) (YYX)))->YYTYPE
1169 /** If STACK is expandable, extend it. WARNING: Pointers into the
1170 stack from outside should be considered invalid after this call.
1171 We always expand when there are 1 or fewer items left AFTER an
1172 allocation, so that we can avoid having external pointers exist
1173 across an allocation. */
1175 yyexpandGLRStack (yyGLRStack
* yystackp
)
1177 yyGLRStackItem
* yynewItems
;
1178 yyGLRStackItem
* yyp0
, *yyp1
;
1181 size_t yysize
= yystackp
->yynextFree
- yystackp
->yyitems
;
1182 if (YYMAXDEPTH
- YYHEADROOM
< yysize
)
1183 yyMemoryExhausted (yystackp
);
1184 yynewSize
= 2*yysize
;
1185 if (YYMAXDEPTH
< yynewSize
)
1186 yynewSize
= YYMAXDEPTH
;
1187 yynewItems
= (yyGLRStackItem
*) YYMALLOC (yynewSize
* sizeof yynewItems
[0]);
1189 yyMemoryExhausted (yystackp
);
1190 for (yyp0
= yystackp
->yyitems
, yyp1
= yynewItems
, yyn
= yysize
;
1192 yyn
-= 1, yyp0
+= 1, yyp1
+= 1)
1195 if (*(yybool
*) yyp0
)
1197 yyGLRState
* yys0
= &yyp0
->yystate
;
1198 yyGLRState
* yys1
= &yyp1
->yystate
;
1199 if (yys0
->yypred
!= YY_NULL
)
1201 YYRELOC (yyp0
, yyp1
, yys0
->yypred
, yystate
);
1202 if (! yys0
->yyresolved
&& yys0
->yysemantics
.yyfirstVal
!= YY_NULL
)
1203 yys1
->yysemantics
.yyfirstVal
=
1204 YYRELOC (yyp0
, yyp1
, yys0
->yysemantics
.yyfirstVal
, yyoption
);
1208 yySemanticOption
* yyv0
= &yyp0
->yyoption
;
1209 yySemanticOption
* yyv1
= &yyp1
->yyoption
;
1210 if (yyv0
->yystate
!= YY_NULL
)
1211 yyv1
->yystate
= YYRELOC (yyp0
, yyp1
, yyv0
->yystate
, yystate
);
1212 if (yyv0
->yynext
!= YY_NULL
)
1213 yyv1
->yynext
= YYRELOC (yyp0
, yyp1
, yyv0
->yynext
, yyoption
);
1216 if (yystackp
->yysplitPoint
!= YY_NULL
)
1217 yystackp
->yysplitPoint
= YYRELOC (yystackp
->yyitems
, yynewItems
,
1218 yystackp
->yysplitPoint
, yystate
);
1220 for (yyn
= 0; yyn
< yystackp
->yytops
.yysize
; yyn
+= 1)
1221 if (yystackp
->yytops
.yystates
[yyn
] != YY_NULL
)
1222 yystackp
->yytops
.yystates
[yyn
] =
1223 YYRELOC (yystackp
->yyitems
, yynewItems
,
1224 yystackp
->yytops
.yystates
[yyn
], yystate
);
1225 YYFREE (yystackp
->yyitems
);
1226 yystackp
->yyitems
= yynewItems
;
1227 yystackp
->yynextFree
= yynewItems
+ yysize
;
1228 yystackp
->yyspaceLeft
= yynewSize
- yysize
;
1233 yyfreeGLRStack (yyGLRStack
* yystackp
)
1235 YYFREE (yystackp
->yyitems
);
1236 yyfreeStateSet (&yystackp
->yytops
);
1239 /** Assuming that S is a GLRState somewhere on STACK, update the
1240 * splitpoint of STACK, if needed, so that it is at least as deep as
1243 yyupdateSplit (yyGLRStack
* yystackp
, yyGLRState
* yys
)
1245 if (yystackp
->yysplitPoint
!= YY_NULL
&& yystackp
->yysplitPoint
> yys
)
1246 yystackp
->yysplitPoint
= yys
;
1249 /** Invalidate stack #K in STACK. */
1251 yymarkStackDeleted (yyGLRStack
* yystackp
, size_t yyk
)
1253 if (yystackp
->yytops
.yystates
[yyk
] != YY_NULL
)
1254 yystackp
->yylastDeleted
= yystackp
->yytops
.yystates
[yyk
];
1255 yystackp
->yytops
.yystates
[yyk
] = YY_NULL
;
1258 /** Undelete the last stack that was marked as deleted. Can only be
1259 done once after a deletion, and only when all other stacks have
1262 yyundeleteLastStack (yyGLRStack
* yystackp
)
1264 if (yystackp
->yylastDeleted
== YY_NULL
|| yystackp
->yytops
.yysize
!= 0)
1266 yystackp
->yytops
.yystates
[0] = yystackp
->yylastDeleted
;
1267 yystackp
->yytops
.yysize
= 1;
1268 YYDPRINTF ((stderr
, "Restoring last deleted stack as stack #0.\n"));
1269 yystackp
->yylastDeleted
= YY_NULL
;
1273 yyremoveDeletes (yyGLRStack
* yystackp
)
1277 while (yyj
< yystackp
->yytops
.yysize
)
1279 if (yystackp
->yytops
.yystates
[yyi
] == YY_NULL
)
1283 YYDPRINTF ((stderr
, "Removing dead stacks.\n"));
1285 yystackp
->yytops
.yysize
-= 1;
1289 yystackp
->yytops
.yystates
[yyj
] = yystackp
->yytops
.yystates
[yyi
];
1290 /* In the current implementation, it's unnecessary to copy
1291 yystackp->yytops.yylookaheadNeeds[yyi] since, after
1292 yyremoveDeletes returns, the parser immediately either enters
1293 deterministic operation or shifts a token. However, it doesn't
1294 hurt, and the code might evolve to need it. */
1295 yystackp
->yytops
.yylookaheadNeeds
[yyj
] =
1296 yystackp
->yytops
.yylookaheadNeeds
[yyi
];
1299 YYDPRINTF ((stderr
, "Rename stack %lu -> %lu.\n",
1300 (unsigned long int) yyi
, (unsigned long int) yyj
));
1308 /** Shift to a new state on stack #K of STACK, corresponding to LR state
1309 * LRSTATE, at input position POSN, with (resolved) semantic value SVAL. */
1311 yyglrShift (yyGLRStack
* yystackp
, size_t yyk
, yyStateNum yylrState
,
1313 YYSTYPE
* yyvalp
]b4_locations_if([, YYLTYPE
* yylocp
])[)
1315 yyGLRState
* yynewState
= &yynewGLRStackItem (yystackp
, yytrue
)->yystate
;
1317 yynewState
->yylrState
= yylrState
;
1318 yynewState
->yyposn
= yyposn
;
1319 yynewState
->yyresolved
= yytrue
;
1320 yynewState
->yypred
= yystackp
->yytops
.yystates
[yyk
];
1321 yynewState
->yysemantics
.yysval
= *yyvalp
;]b4_locations_if([
1322 yynewState
->yyloc
= *yylocp
;])[
1323 yystackp
->yytops
.yystates
[yyk
] = yynewState
;
1325 YY_RESERVE_GLRSTACK (yystackp
);
1328 /** Shift stack #K of YYSTACK, to a new state corresponding to LR
1329 * state YYLRSTATE, at input position YYPOSN, with the (unresolved)
1330 * semantic value of YYRHS under the action for YYRULE. */
1332 yyglrShiftDefer (yyGLRStack
* yystackp
, size_t yyk
, yyStateNum yylrState
,
1333 size_t yyposn
, yyGLRState
* rhs
, yyRuleNum yyrule
)
1335 yyGLRState
* yynewState
= &yynewGLRStackItem (yystackp
, yytrue
)->yystate
;
1337 yynewState
->yylrState
= yylrState
;
1338 yynewState
->yyposn
= yyposn
;
1339 yynewState
->yyresolved
= yyfalse
;
1340 yynewState
->yypred
= yystackp
->yytops
.yystates
[yyk
];
1341 yynewState
->yysemantics
.yyfirstVal
= YY_NULL
;
1342 yystackp
->yytops
.yystates
[yyk
] = yynewState
;
1344 /* Invokes YY_RESERVE_GLRSTACK. */
1345 yyaddDeferredAction (yystackp
, yyk
, yynewState
, rhs
, yyrule
);
1348 /** Pop the symbols consumed by reduction #RULE from the top of stack
1349 * #K of STACK, and perform the appropriate semantic action on their
1350 * semantic values. Assumes that all ambiguities in semantic values
1351 * have been previously resolved. Set *VALP to the resulting value,
1352 * and *LOCP to the computed location (if any). Return value is as
1353 * for userAction. */
1354 static inline YYRESULTTAG
1355 yydoAction (yyGLRStack
* yystackp
, size_t yyk
, yyRuleNum yyrule
,
1356 YYSTYPE
* yyvalp
]b4_locuser_formals
[)
1358 int yynrhs
= yyrhsLength (yyrule
);
1360 if (yystackp
->yysplitPoint
== YY_NULL
)
1362 /* Standard special case: single stack. */
1363 yyGLRStackItem
* rhs
= (yyGLRStackItem
*) yystackp
->yytops
.yystates
[yyk
];
1364 YYASSERT (yyk
== 0);
1365 yystackp
->yynextFree
-= yynrhs
;
1366 yystackp
->yyspaceLeft
+= yynrhs
;
1367 yystackp
->yytops
.yystates
[0] = & yystackp
->yynextFree
[-1].yystate
;
1368 return yyuserAction (yyrule
, yynrhs
, rhs
, yystackp
,
1369 yyvalp
]b4_locuser_args
[);
1373 /* At present, doAction is never called in nondeterministic
1374 * mode, so this branch is never taken. It is here in
1375 * anticipation of a future feature that will allow immediate
1376 * evaluation of selected actions in nondeterministic mode. */
1379 yyGLRStackItem yyrhsVals
[YYMAXRHS
+ YYMAXLEFT
+ 1];
1380 yys
= yyrhsVals
[YYMAXRHS
+ YYMAXLEFT
].yystate
.yypred
1381 = yystackp
->yytops
.yystates
[yyk
];]b4_locations_if([[
1383 /* Set default location. */
1384 yyrhsVals
[YYMAXRHS
+ YYMAXLEFT
- 1].yystate
.yyloc
= yys
->yyloc
;]])[
1385 for (yyi
= 0; yyi
< yynrhs
; yyi
+= 1)
1390 yyupdateSplit (yystackp
, yys
);
1391 yystackp
->yytops
.yystates
[yyk
] = yys
;
1392 return yyuserAction (yyrule
, yynrhs
, yyrhsVals
+ YYMAXRHS
+ YYMAXLEFT
- 1,
1393 yystackp
, yyvalp
]b4_locuser_args
[);
1398 # define YY_REDUCE_PRINT(Args)
1400 # define YY_REDUCE_PRINT(Args) \
1403 yy_reduce_print Args; \
1406 /*----------------------------------------------------------.
1407 | Report that the RULE is going to be reduced on stack #K. |
1408 `----------------------------------------------------------*/
1410 /*ARGSUSED*/ static inline void
1411 yy_reduce_print (yyGLRStack
* yystackp
, size_t yyk
, yyRuleNum yyrule
,
1412 YYSTYPE
* yyvalp
]b4_locuser_formals
[)
1414 int yynrhs
= yyrhsLength (yyrule
);
1415 yybool yynormal
__attribute__ ((__unused__
)) =
1416 (yystackp
->yysplitPoint
== YY_NULL
);
1417 yyGLRStackItem
* yyvsp
= (yyGLRStackItem
*) yystackp
->yytops
.yystates
[yyk
];
1420 YYUSE (yyvalp
);]b4_locations_if([
1422 ]b4_parse_param_use
[]dnl
1423 [ YYFPRINTF (stderr
, "Reducing stack %lu by rule %d (line %lu):\n",
1424 (unsigned long int) yyk
, yyrule
- 1,
1425 (unsigned long int) yyrline
[yyrule
]);
1426 /* The symbols being reduced. */
1427 for (yyi
= 0; yyi
< yynrhs
; yyi
++)
1429 YYFPRINTF (stderr
, " $%d = ", yyi
+ 1);
1430 yy_symbol_print (stderr
, yyrhs
[yyprhs
[yyrule
] + yyi
],
1431 &]b4_rhs_value(yynrhs
, yyi
+ 1)[
1432 ]b4_locations_if([, &]b4_rhs_location(yynrhs
, yyi
+ 1))[]dnl
1434 YYFPRINTF (stderr
, "\n");
1439 /** Pop items off stack #K of STACK according to grammar rule RULE,
1440 * and push back on the resulting nonterminal symbol. Perform the
1441 * semantic action associated with RULE and store its value with the
1442 * newly pushed state, if FORCEEVAL or if STACK is currently
1443 * unambiguous. Otherwise, store the deferred semantic action with
1444 * the new state. If the new state would have an identical input
1445 * position, LR state, and predecessor to an existing state on the stack,
1446 * it is identified with that existing state, eliminating stack #K from
1447 * the STACK. In this case, the (necessarily deferred) semantic value is
1448 * added to the options for the existing state's semantic value.
1450 static inline YYRESULTTAG
1451 yyglrReduce (yyGLRStack
* yystackp
, size_t yyk
, yyRuleNum yyrule
,
1452 yybool yyforceEval
]b4_user_formals
[)
1454 size_t yyposn
= yystackp
->yytops
.yystates
[yyk
]->yyposn
;
1456 if (yyforceEval
|| yystackp
->yysplitPoint
== YY_NULL
)
1458 YYSTYPE yysval
;]b4_locations_if([
1461 YY_REDUCE_PRINT ((yystackp
, yyk
, yyrule
, &yysval
]b4_locuser_args([&yyloc
])[));
1462 YYCHK (yydoAction (yystackp
, yyk
, yyrule
, &yysval
]b4_locuser_args([&yyloc
])[));
1463 YY_SYMBOL_PRINT ("-> $$ =", yyr1
[yyrule
], &yysval
, &yyloc
);
1464 yyglrShift (yystackp
, yyk
,
1465 yyLRgotoState (yystackp
->yytops
.yystates
[yyk
]->yylrState
,
1466 yylhsNonterm (yyrule
)),
1467 yyposn
, &yysval
]b4_locations_if([, &yyloc
])[);
1473 yyGLRState
* yys
, *yys0
= yystackp
->yytops
.yystates
[yyk
];
1474 yyStateNum yynewLRState
;
1476 for (yys
= yystackp
->yytops
.yystates
[yyk
], yyn
= yyrhsLength (yyrule
);
1482 yyupdateSplit (yystackp
, yys
);
1483 yynewLRState
= yyLRgotoState (yys
->yylrState
, yylhsNonterm (yyrule
));
1485 "Reduced stack %lu by rule #%d; action deferred. Now in state %d.\n",
1486 (unsigned long int) yyk
, yyrule
- 1, yynewLRState
));
1487 for (yyi
= 0; yyi
< yystackp
->yytops
.yysize
; yyi
+= 1)
1488 if (yyi
!= yyk
&& yystackp
->yytops
.yystates
[yyi
] != YY_NULL
)
1490 yyGLRState
*yysplit
= yystackp
->yysplitPoint
;
1491 yyGLRState
*yyp
= yystackp
->yytops
.yystates
[yyi
];
1492 while (yyp
!= yys
&& yyp
!= yysplit
&& yyp
->yyposn
>= yyposn
)
1494 if (yyp
->yylrState
== yynewLRState
&& yyp
->yypred
== yys
)
1496 yyaddDeferredAction (yystackp
, yyk
, yyp
, yys0
, yyrule
);
1497 yymarkStackDeleted (yystackp
, yyk
);
1498 YYDPRINTF ((stderr
, "Merging stack %lu into stack %lu.\n",
1499 (unsigned long int) yyk
,
1500 (unsigned long int) yyi
));
1506 yystackp
->yytops
.yystates
[yyk
] = yys
;
1507 yyglrShiftDefer (yystackp
, yyk
, yynewLRState
, yyposn
, yys0
, yyrule
);
1513 yysplitStack (yyGLRStack
* yystackp
, size_t yyk
)
1515 if (yystackp
->yysplitPoint
== YY_NULL
)
1517 YYASSERT (yyk
== 0);
1518 yystackp
->yysplitPoint
= yystackp
->yytops
.yystates
[yyk
];
1520 if (yystackp
->yytops
.yysize
>= yystackp
->yytops
.yycapacity
)
1522 yyGLRState
** yynewStates
;
1523 yybool
* yynewLookaheadNeeds
;
1525 yynewStates
= YY_NULL
;
1527 if (yystackp
->yytops
.yycapacity
1528 > (YYSIZEMAX
/ (2 * sizeof yynewStates
[0])))
1529 yyMemoryExhausted (yystackp
);
1530 yystackp
->yytops
.yycapacity
*= 2;
1533 (yyGLRState
**) YYREALLOC (yystackp
->yytops
.yystates
,
1534 (yystackp
->yytops
.yycapacity
1535 * sizeof yynewStates
[0]));
1536 if (yynewStates
== YY_NULL
)
1537 yyMemoryExhausted (yystackp
);
1538 yystackp
->yytops
.yystates
= yynewStates
;
1540 yynewLookaheadNeeds
=
1541 (yybool
*) YYREALLOC (yystackp
->yytops
.yylookaheadNeeds
,
1542 (yystackp
->yytops
.yycapacity
1543 * sizeof yynewLookaheadNeeds
[0]));
1544 if (yynewLookaheadNeeds
== YY_NULL
)
1545 yyMemoryExhausted (yystackp
);
1546 yystackp
->yytops
.yylookaheadNeeds
= yynewLookaheadNeeds
;
1548 yystackp
->yytops
.yystates
[yystackp
->yytops
.yysize
]
1549 = yystackp
->yytops
.yystates
[yyk
];
1550 yystackp
->yytops
.yylookaheadNeeds
[yystackp
->yytops
.yysize
]
1551 = yystackp
->yytops
.yylookaheadNeeds
[yyk
];
1552 yystackp
->yytops
.yysize
+= 1;
1553 return yystackp
->yytops
.yysize
-1;
1556 /** True iff Y0 and Y1 represent identical options at the top level.
1557 * That is, they represent the same rule applied to RHS symbols
1558 * that produce the same terminal symbols. */
1560 yyidenticalOptions (yySemanticOption
* yyy0
, yySemanticOption
* yyy1
)
1562 if (yyy0
->yyrule
== yyy1
->yyrule
)
1564 yyGLRState
*yys0
, *yys1
;
1566 for (yys0
= yyy0
->yystate
, yys1
= yyy1
->yystate
,
1567 yyn
= yyrhsLength (yyy0
->yyrule
);
1569 yys0
= yys0
->yypred
, yys1
= yys1
->yypred
, yyn
-= 1)
1570 if (yys0
->yyposn
!= yys1
->yyposn
)
1578 /** Assuming identicalOptions (Y0,Y1), destructively merge the
1579 * alternative semantic values for the RHS-symbols of Y1 and Y0. */
1581 yymergeOptionSets (yySemanticOption
* yyy0
, yySemanticOption
* yyy1
)
1583 yyGLRState
*yys0
, *yys1
;
1585 for (yys0
= yyy0
->yystate
, yys1
= yyy1
->yystate
,
1586 yyn
= yyrhsLength (yyy0
->yyrule
);
1588 yys0
= yys0
->yypred
, yys1
= yys1
->yypred
, yyn
-= 1)
1592 else if (yys0
->yyresolved
)
1594 yys1
->yyresolved
= yytrue
;
1595 yys1
->yysemantics
.yysval
= yys0
->yysemantics
.yysval
;
1597 else if (yys1
->yyresolved
)
1599 yys0
->yyresolved
= yytrue
;
1600 yys0
->yysemantics
.yysval
= yys1
->yysemantics
.yysval
;
1604 yySemanticOption
** yyz0p
= &yys0
->yysemantics
.yyfirstVal
;
1605 yySemanticOption
* yyz1
= yys1
->yysemantics
.yyfirstVal
;
1606 while (YYID (yytrue
))
1608 if (yyz1
== *yyz0p
|| yyz1
== YY_NULL
)
1610 else if (*yyz0p
== YY_NULL
)
1615 else if (*yyz0p
< yyz1
)
1617 yySemanticOption
* yyz
= *yyz0p
;
1619 yyz1
= yyz1
->yynext
;
1620 (*yyz0p
)->yynext
= yyz
;
1622 yyz0p
= &(*yyz0p
)->yynext
;
1624 yys1
->yysemantics
.yyfirstVal
= yys0
->yysemantics
.yyfirstVal
;
1629 /** Y0 and Y1 represent two possible actions to take in a given
1630 * parsing state; return 0 if no combination is possible,
1631 * 1 if user-mergeable, 2 if Y0 is preferred, 3 if Y1 is preferred. */
1633 yypreference (yySemanticOption
* y0
, yySemanticOption
* y1
)
1635 yyRuleNum r0
= y0
->yyrule
, r1
= y1
->yyrule
;
1636 int p0
= yydprec
[r0
], p1
= yydprec
[r1
];
1640 if (yymerger
[r0
] == 0 || yymerger
[r0
] != yymerger
[r1
])
1645 if (p0
== 0 || p1
== 0)
1654 static YYRESULTTAG
yyresolveValue (yyGLRState
* yys
,
1655 yyGLRStack
* yystackp
]b4_user_formals
[);
1658 /** Resolve the previous N states starting at and including state S. If result
1659 * != yyok, some states may have been left unresolved possibly with empty
1660 * semantic option chains. Regardless of whether result = yyok, each state
1661 * has been left with consistent data so that yydestroyGLRState can be invoked
1664 yyresolveStates (yyGLRState
* yys
, int yyn
,
1665 yyGLRStack
* yystackp
]b4_user_formals
[)
1669 YYASSERT (yys
->yypred
);
1670 YYCHK (yyresolveStates (yys
->yypred
, yyn
-1, yystackp
]b4_user_args
[));
1671 if (! yys
->yyresolved
)
1672 YYCHK (yyresolveValue (yys
, yystackp
]b4_user_args
[));
1677 /** Resolve the states for the RHS of OPT, perform its user action, and return
1678 * the semantic value and location. Regardless of whether result = yyok, all
1679 * RHS states have been destroyed (assuming the user action destroys all RHS
1680 * semantic values if invoked). */
1682 yyresolveAction (yySemanticOption
* yyopt
, yyGLRStack
* yystackp
,
1683 YYSTYPE
* yyvalp
]b4_locuser_formals
[)
1685 yyGLRStackItem yyrhsVals
[YYMAXRHS
+ YYMAXLEFT
+ 1];
1686 int yynrhs
= yyrhsLength (yyopt
->yyrule
);
1687 YYRESULTTAG yyflag
=
1688 yyresolveStates (yyopt
->yystate
, yynrhs
, yystackp
]b4_user_args
[);
1692 for (yys
= yyopt
->yystate
; yynrhs
> 0; yys
= yys
->yypred
, yynrhs
-= 1)
1693 yydestroyGLRState ("Cleanup: popping", yys
]b4_user_args
[);
1697 yyrhsVals
[YYMAXRHS
+ YYMAXLEFT
].yystate
.yypred
= yyopt
->yystate
;]b4_locations_if([[
1699 /* Set default location. */
1700 yyrhsVals
[YYMAXRHS
+ YYMAXLEFT
- 1].yystate
.yyloc
= yyopt
->yystate
->yyloc
;]])[
1702 int yychar_current
= yychar
;
1703 YYSTYPE yylval_current
= yylval
;]b4_locations_if([
1704 YYLTYPE yylloc_current
= yylloc
;])[
1705 yychar
= yyopt
->yyrawchar
;
1706 yylval
= yyopt
->yyval
;]b4_locations_if([
1707 yylloc
= yyopt
->yyloc
;])[
1708 yyflag
= yyuserAction (yyopt
->yyrule
, yynrhs
,
1709 yyrhsVals
+ YYMAXRHS
+ YYMAXLEFT
- 1,
1710 yystackp
, yyvalp
]b4_locuser_args
[);
1711 yychar
= yychar_current
;
1712 yylval
= yylval_current
;]b4_locations_if([
1713 yylloc
= yylloc_current
;])[
1720 yyreportTree (yySemanticOption
* yyx
, int yyindent
)
1722 int yynrhs
= yyrhsLength (yyx
->yyrule
);
1725 yyGLRState
* yystates
[1 + YYMAXRHS
];
1726 yyGLRState yyleftmost_state
;
1728 for (yyi
= yynrhs
, yys
= yyx
->yystate
; 0 < yyi
; yyi
-= 1, yys
= yys
->yypred
)
1729 yystates
[yyi
] = yys
;
1732 yyleftmost_state
.yyposn
= 0;
1733 yystates
[0] = &yyleftmost_state
;
1738 if (yyx
->yystate
->yyposn
< yys
->yyposn
+ 1)
1739 YYFPRINTF (stderr
, "%*s%s -> <Rule %d, empty>\n",
1740 yyindent
, "", yytokenName (yylhsNonterm (yyx
->yyrule
)),
1743 YYFPRINTF (stderr
, "%*s%s -> <Rule %d, tokens %lu .. %lu>\n",
1744 yyindent
, "", yytokenName (yylhsNonterm (yyx
->yyrule
)),
1745 yyx
->yyrule
- 1, (unsigned long int) (yys
->yyposn
+ 1),
1746 (unsigned long int) yyx
->yystate
->yyposn
);
1747 for (yyi
= 1; yyi
<= yynrhs
; yyi
+= 1)
1749 if (yystates
[yyi
]->yyresolved
)
1751 if (yystates
[yyi
-1]->yyposn
+1 > yystates
[yyi
]->yyposn
)
1752 YYFPRINTF (stderr
, "%*s%s <empty>\n", yyindent
+2, "",
1753 yytokenName (yyrhs
[yyprhs
[yyx
->yyrule
]+yyi
-1]));
1755 YYFPRINTF (stderr
, "%*s%s <tokens %lu .. %lu>\n", yyindent
+2, "",
1756 yytokenName (yyrhs
[yyprhs
[yyx
->yyrule
]+yyi
-1]),
1757 (unsigned long int) (yystates
[yyi
- 1]->yyposn
+ 1),
1758 (unsigned long int) yystates
[yyi
]->yyposn
);
1761 yyreportTree (yystates
[yyi
]->yysemantics
.yyfirstVal
, yyindent
+2);
1766 /*ARGSUSED*/ static YYRESULTTAG
1767 yyreportAmbiguity (yySemanticOption
* yyx0
,
1768 yySemanticOption
* yyx1
]b4_pure_formals
[)
1774 YYFPRINTF (stderr
, "Ambiguity detected.\n");
1775 YYFPRINTF (stderr
, "Option 1,\n");
1776 yyreportTree (yyx0
, 2);
1777 YYFPRINTF (stderr
, "\nOption 2,\n");
1778 yyreportTree (yyx1
, 2);
1779 YYFPRINTF (stderr
, "\n");
1782 yyerror (]b4_yyerror_args
[YY_("syntax is ambiguous"));
1784 }]b4_locations_if([[
1786 /** Starting at and including state S1, resolve the location for each of the
1787 * previous N1 states that is unresolved. The first semantic option of a state
1788 * is always chosen. */
1790 yyresolveLocations (yyGLRState
* yys1
, int yyn1
,
1791 yyGLRStack
*yystackp
]b4_user_formals
[)
1795 yyresolveLocations (yys1
->yypred
, yyn1
- 1, yystackp
]b4_user_args
[);
1796 if (!yys1
->yyresolved
)
1798 yyGLRStackItem yyrhsloc
[1 + YYMAXRHS
];
1800 yySemanticOption
*yyoption
= yys1
->yysemantics
.yyfirstVal
;
1801 YYASSERT (yyoption
!= YY_NULL
);
1802 yynrhs
= yyrhsLength (yyoption
->yyrule
);
1807 yyresolveLocations (yyoption
->yystate
, yynrhs
,
1808 yystackp
]b4_user_args
[);
1809 for (yys
= yyoption
->yystate
, yyn
= yynrhs
;
1811 yys
= yys
->yypred
, yyn
-= 1)
1812 yyrhsloc
[yyn
].yystate
.yyloc
= yys
->yyloc
;
1816 /* Both yyresolveAction and yyresolveLocations traverse the GSS
1817 in reverse rightmost order. It is only necessary to invoke
1818 yyresolveLocations on a subforest for which yyresolveAction
1819 would have been invoked next had an ambiguity not been
1820 detected. Thus the location of the previous state (but not
1821 necessarily the previous state itself) is guaranteed to be
1822 resolved already. */
1823 yyGLRState
*yyprevious
= yyoption
->yystate
;
1824 yyrhsloc
[0].yystate
.yyloc
= yyprevious
->yyloc
;
1827 int yychar_current
= yychar
;
1828 YYSTYPE yylval_current
= yylval
;
1829 YYLTYPE yylloc_current
= yylloc
;
1830 yychar
= yyoption
->yyrawchar
;
1831 yylval
= yyoption
->yyval
;
1832 yylloc
= yyoption
->yyloc
;
1833 YYLLOC_DEFAULT ((yys1
->yyloc
), yyrhsloc
, yynrhs
);
1834 yychar
= yychar_current
;
1835 yylval
= yylval_current
;
1836 yylloc
= yylloc_current
;
1842 /** Resolve the ambiguity represented in state S, perform the indicated
1843 * actions, and set the semantic value of S. If result != yyok, the chain of
1844 * semantic options in S has been cleared instead or it has been left
1845 * unmodified except that redundant options may have been removed. Regardless
1846 * of whether result = yyok, S has been left with consistent data so that
1847 * yydestroyGLRState can be invoked if necessary. */
1849 yyresolveValue (yyGLRState
* yys
, yyGLRStack
* yystackp
]b4_user_formals
[)
1851 yySemanticOption
* yyoptionList
= yys
->yysemantics
.yyfirstVal
;
1852 yySemanticOption
* yybest
= yyoptionList
;
1853 yySemanticOption
** yypp
;
1854 yybool yymerge
= yyfalse
;
1856 YYRESULTTAG yyflag
;]b4_locations_if([
1857 YYLTYPE
*yylocp
= &yys
->yyloc
;])[
1859 for (yypp
= &yyoptionList
->yynext
; *yypp
!= YY_NULL
; )
1861 yySemanticOption
* yyp
= *yypp
;
1863 if (yyidenticalOptions (yybest
, yyp
))
1865 yymergeOptionSets (yybest
, yyp
);
1866 *yypp
= yyp
->yynext
;
1870 switch (yypreference (yybest
, yyp
))
1872 case 0:]b4_locations_if([[
1873 yyresolveLocations (yys
, 1, yystackp
]b4_user_args
[);]])[
1874 return yyreportAmbiguity (yybest
, yyp
]b4_pure_args
[);
1886 /* This cannot happen so it is not worth a YYASSERT (yyfalse),
1887 but some compilers complain if the default case is
1891 yypp
= &yyp
->yynext
;
1897 yySemanticOption
* yyp
;
1898 int yyprec
= yydprec
[yybest
->yyrule
];
1899 yyflag
= yyresolveAction (yybest
, yystackp
, &yysval
]b4_locuser_args
[);
1901 for (yyp
= yybest
->yynext
; yyp
!= YY_NULL
; yyp
= yyp
->yynext
)
1903 if (yyprec
== yydprec
[yyp
->yyrule
])
1905 YYSTYPE yysval_other
;]b4_locations_if([
1907 yyflag
= yyresolveAction (yyp
, yystackp
, &yysval_other
]b4_locuser_args([&yydummy
])[);
1910 yydestruct ("Cleanup: discarding incompletely merged value for",
1911 yystos
[yys
->yylrState
],
1912 &yysval
]b4_locuser_args
[);
1915 yyuserMerge (yymerger
[yyp
->yyrule
], &yysval
, &yysval_other
);
1920 yyflag
= yyresolveAction (yybest
, yystackp
, &yysval
]b4_locuser_args([yylocp
])[);
1924 yys
->yyresolved
= yytrue
;
1925 yys
->yysemantics
.yysval
= yysval
;
1928 yys
->yysemantics
.yyfirstVal
= YY_NULL
;
1933 yyresolveStack (yyGLRStack
* yystackp
]b4_user_formals
[)
1935 if (yystackp
->yysplitPoint
!= YY_NULL
)
1940 for (yyn
= 0, yys
= yystackp
->yytops
.yystates
[0];
1941 yys
!= yystackp
->yysplitPoint
;
1942 yys
= yys
->yypred
, yyn
+= 1)
1944 YYCHK (yyresolveStates (yystackp
->yytops
.yystates
[0], yyn
, yystackp
1951 yycompressStack (yyGLRStack
* yystackp
)
1953 yyGLRState
* yyp
, *yyq
, *yyr
;
1955 if (yystackp
->yytops
.yysize
!= 1 || yystackp
->yysplitPoint
== YY_NULL
)
1958 for (yyp
= yystackp
->yytops
.yystates
[0], yyq
= yyp
->yypred
, yyr
= YY_NULL
;
1959 yyp
!= yystackp
->yysplitPoint
;
1960 yyr
= yyp
, yyp
= yyq
, yyq
= yyp
->yypred
)
1963 yystackp
->yyspaceLeft
+= yystackp
->yynextFree
- yystackp
->yyitems
;
1964 yystackp
->yynextFree
= ((yyGLRStackItem
*) yystackp
->yysplitPoint
) + 1;
1965 yystackp
->yyspaceLeft
-= yystackp
->yynextFree
- yystackp
->yyitems
;
1966 yystackp
->yysplitPoint
= YY_NULL
;
1967 yystackp
->yylastDeleted
= YY_NULL
;
1969 while (yyr
!= YY_NULL
)
1971 yystackp
->yynextFree
->yystate
= *yyr
;
1973 yystackp
->yynextFree
->yystate
.yypred
= &yystackp
->yynextFree
[-1].yystate
;
1974 yystackp
->yytops
.yystates
[0] = &yystackp
->yynextFree
->yystate
;
1975 yystackp
->yynextFree
+= 1;
1976 yystackp
->yyspaceLeft
-= 1;
1981 yyprocessOneStack (yyGLRStack
* yystackp
, size_t yyk
,
1982 size_t yyposn
]b4_pure_formals
[)
1985 const short int* yyconflicts
;
1988 while (yystackp
->yytops
.yystates
[yyk
] != YY_NULL
)
1990 yyStateNum yystate
= yystackp
->yytops
.yystates
[yyk
]->yylrState
;
1991 YYDPRINTF ((stderr
, "Stack %lu Entering state %d\n",
1992 (unsigned long int) yyk
, yystate
));
1994 YYASSERT (yystate
!= YYFINAL
);
1996 if (yyisDefaultedState (yystate
))
1998 yyrule
= yydefaultAction (yystate
);
2001 YYDPRINTF ((stderr
, "Stack %lu dies.\n",
2002 (unsigned long int) yyk
));
2003 yymarkStackDeleted (yystackp
, yyk
);
2006 YYCHK (yyglrReduce (yystackp
, yyk
, yyrule
, yyfalse
]b4_user_args
[));
2011 yystackp
->yytops
.yylookaheadNeeds
[yyk
] = yytrue
;
2012 if (yychar
== YYEMPTY
)
2014 YYDPRINTF ((stderr
, "Reading a token: "));
2018 if (yychar
<= YYEOF
)
2020 yychar
= yytoken
= YYEOF
;
2021 YYDPRINTF ((stderr
, "Now at end of input.\n"));
2025 yytoken
= YYTRANSLATE (yychar
);
2026 YY_SYMBOL_PRINT ("Next token is", yytoken
, &yylval
, &yylloc
);
2029 yygetLRActions (yystate
, yytoken
, &yyaction
, &yyconflicts
);
2031 while (*yyconflicts
!= 0)
2033 size_t yynewStack
= yysplitStack (yystackp
, yyk
);
2034 YYDPRINTF ((stderr
, "Splitting off stack %lu from %lu.\n",
2035 (unsigned long int) yynewStack
,
2036 (unsigned long int) yyk
));
2037 YYCHK (yyglrReduce (yystackp
, yynewStack
,
2038 *yyconflicts
, yyfalse
]b4_user_args
[));
2039 YYCHK (yyprocessOneStack (yystackp
, yynewStack
,
2040 yyposn
]b4_pure_args
[));
2044 if (yyisShiftAction (yyaction
))
2046 else if (yyisErrorAction (yyaction
))
2048 YYDPRINTF ((stderr
, "Stack %lu dies.\n",
2049 (unsigned long int) yyk
));
2050 yymarkStackDeleted (yystackp
, yyk
);
2054 YYCHK (yyglrReduce (yystackp
, yyk
, -yyaction
,
2055 yyfalse
]b4_user_args
[));
2061 /*ARGSUSED*/ static void
2062 yyreportSyntaxError (yyGLRStack
* yystackp
]b4_user_formals
[)
2064 if (yystackp
->yyerrState
!= 0)
2066 #if ! YYERROR_VERBOSE
2067 yyerror (]b4_lyyerror_args
[YY_("syntax error"));
2069 yySymbol yytoken
= yychar
== YYEMPTY
? YYEMPTY
: YYTRANSLATE (yychar
);
2070 size_t yysize0
= yytnamerr (YY_NULL
, yytokenName (yytoken
));
2071 size_t yysize
= yysize0
;
2073 yybool yysize_overflow
= yyfalse
;
2074 char* yymsg
= YY_NULL
;
2075 enum { YYERROR_VERBOSE_ARGS_MAXIMUM
= 5 };
2076 /* Internationalized format string. */
2077 const char *yyformat
= YY_NULL
;
2078 /* Arguments of yyformat. */
2079 char const *yyarg
[YYERROR_VERBOSE_ARGS_MAXIMUM
];
2080 /* Number of reported tokens (one for the "unexpected", one per
2084 /* There are many possibilities here to consider:
2085 - If this state is a consistent state with a default action, then
2086 the only way this function was invoked is if the default action
2087 is an error action. In that case, don't check for expected
2088 tokens because there are none.
2089 - The only way there can be no lookahead present (in yychar) is if
2090 this state is a consistent state with a default action. Thus,
2091 detecting the absence of a lookahead is sufficient to determine
2092 that there is no unexpected or expected token to report. In that
2093 case, just report a simple "syntax error".
2094 - Don't assume there isn't a lookahead just because this state is a
2095 consistent state with a default action. There might have been a
2096 previous inconsistent state, consistent state with a non-default
2097 action, or user semantic action that manipulated yychar.
2098 - Of course, the expected token list depends on states to have
2099 correct lookahead information, and it depends on the parser not
2100 to perform extra reductions after fetching a lookahead from the
2101 scanner and before detecting a syntax error. Thus, state merging
2102 (from LALR or IELR) and default reductions corrupt the expected
2103 token list. However, the list is correct for canonical LR with
2104 one exception: it will still contain any token that will not be
2105 accepted due to an error action in a later state.
2107 if (yytoken
!= YYEMPTY
)
2109 int yyn
= yypact
[yystackp
->yytops
.yystates
[0]->yylrState
];
2110 yyarg
[yycount
++] = yytokenName (yytoken
);
2111 if (!yypact_value_is_default (yyn
))
2113 /* Start YYX at -YYN if negative to avoid negative indexes in
2114 YYCHECK. In other words, skip the first -YYN actions for this
2115 state because they are default actions. */
2116 int yyxbegin
= yyn
< 0 ? -yyn
: 0;
2117 /* Stay within bounds of both yycheck and yytname. */
2118 int yychecklim
= YYLAST
- yyn
+ 1;
2119 int yyxend
= yychecklim
< YYNTOKENS
? yychecklim
: YYNTOKENS
;
2121 for (yyx
= yyxbegin
; yyx
< yyxend
; ++yyx
)
2122 if (yycheck
[yyx
+ yyn
] == yyx
&& yyx
!= YYTERROR
2123 && !yytable_value_is_error (yytable
[yyx
+ yyn
]))
2125 if (yycount
== YYERROR_VERBOSE_ARGS_MAXIMUM
)
2131 yyarg
[yycount
++] = yytokenName (yyx
);
2132 yysize1
= yysize
+ yytnamerr (YY_NULL
, yytokenName (yyx
));
2133 yysize_overflow
|= yysize1
< yysize
;
2141 #define YYCASE_(N, S) \
2145 YYCASE_(0, YY_("syntax error"));
2146 YYCASE_(1, YY_("syntax error, unexpected %s"));
2147 YYCASE_(2, YY_("syntax error, unexpected %s, expecting %s"));
2148 YYCASE_(3, YY_("syntax error, unexpected %s, expecting %s or %s"));
2149 YYCASE_(4, YY_("syntax error, unexpected %s, expecting %s or %s or %s"));
2150 YYCASE_(5, YY_("syntax error, unexpected %s, expecting %s or %s or %s or %s"));
2154 yysize1
= yysize
+ strlen (yyformat
);
2155 yysize_overflow
|= yysize1
< yysize
;
2158 if (!yysize_overflow
)
2159 yymsg
= (char *) YYMALLOC (yysize
);
2165 while ((*yyp
= *yyformat
))
2167 if (*yyp
== '%' && yyformat
[1] == 's' && yyi
< yycount
)
2169 yyp
+= yytnamerr (yyp
, yyarg
[yyi
++]);
2178 yyerror (]b4_lyyerror_args
[yymsg
);
2183 yyerror (]b4_lyyerror_args
[YY_("syntax error"));
2184 yyMemoryExhausted (yystackp
);
2186 #endif /* YYERROR_VERBOSE */
2190 /* Recover from a syntax error on *YYSTACKP, assuming that *YYSTACKP->YYTOKENP,
2191 yylval, and yylloc are the syntactic category, semantic value, and location
2192 of the lookahead. */
2193 /*ARGSUSED*/ static void
2194 yyrecoverSyntaxError (yyGLRStack
* yystackp
]b4_user_formals
[)
2199 if (yystackp
->yyerrState
== 3)
2200 /* We just shifted the error token and (perhaps) took some
2201 reductions. Skip tokens until we can proceed. */
2202 while (YYID (yytrue
))
2205 if (yychar
== YYEOF
)
2206 yyFail (yystackp
][]b4_lpure_args
[, YY_NULL
);
2207 if (yychar
!= YYEMPTY
)
2208 {]b4_locations_if([[
2209 /* We throw away the lookahead, but the error range
2210 of the shifted error token must take it into account. */
2211 yyGLRState
*yys
= yystackp
->yytops
.yystates
[0];
2212 yyGLRStackItem yyerror_range
[3];
2213 yyerror_range
[1].yystate
.yyloc
= yys
->yyloc
;
2214 yyerror_range
[2].yystate
.yyloc
= yylloc
;
2215 YYLLOC_DEFAULT ((yys
->yyloc
), yyerror_range
, 2);]])[
2216 yytoken
= YYTRANSLATE (yychar
);
2217 yydestruct ("Error: discarding",
2218 yytoken
, &yylval
]b4_locuser_args([&yylloc
])[);
2220 YYDPRINTF ((stderr
, "Reading a token: "));
2222 if (yychar
<= YYEOF
)
2224 yychar
= yytoken
= YYEOF
;
2225 YYDPRINTF ((stderr
, "Now at end of input.\n"));
2229 yytoken
= YYTRANSLATE (yychar
);
2230 YY_SYMBOL_PRINT ("Next token is", yytoken
, &yylval
, &yylloc
);
2232 yyj
= yypact
[yystackp
->yytops
.yystates
[0]->yylrState
];
2233 if (yypact_value_is_default (yyj
))
2236 if (yyj
< 0 || YYLAST
< yyj
|| yycheck
[yyj
] != yytoken
)
2238 if (yydefact
[yystackp
->yytops
.yystates
[0]->yylrState
] != 0)
2241 else if (! yytable_value_is_error (yytable
[yyj
]))
2245 /* Reduce to one stack. */
2246 for (yyk
= 0; yyk
< yystackp
->yytops
.yysize
; yyk
+= 1)
2247 if (yystackp
->yytops
.yystates
[yyk
] != YY_NULL
)
2249 if (yyk
>= yystackp
->yytops
.yysize
)
2250 yyFail (yystackp
][]b4_lpure_args
[, YY_NULL
);
2251 for (yyk
+= 1; yyk
< yystackp
->yytops
.yysize
; yyk
+= 1)
2252 yymarkStackDeleted (yystackp
, yyk
);
2253 yyremoveDeletes (yystackp
);
2254 yycompressStack (yystackp
);
2256 /* Now pop stack until we find a state that shifts the error token. */
2257 yystackp
->yyerrState
= 3;
2258 while (yystackp
->yytops
.yystates
[0] != YY_NULL
)
2260 yyGLRState
*yys
= yystackp
->yytops
.yystates
[0];
2261 yyj
= yypact
[yys
->yylrState
];
2262 if (! yypact_value_is_default (yyj
))
2265 if (0 <= yyj
&& yyj
<= YYLAST
&& yycheck
[yyj
] == YYTERROR
2266 && yyisShiftAction (yytable
[yyj
]))
2268 /* Shift the error token. */]b4_locations_if([[
2269 /* First adjust its location.*/
2271 yystackp
->yyerror_range
[2].yystate
.yyloc
= yylloc
;
2272 YYLLOC_DEFAULT (yyerrloc
, (yystackp
->yyerror_range
), 2);]])[
2273 YY_SYMBOL_PRINT ("Shifting", yystos
[yytable
[yyj
]],
2274 &yylval
, &yyerrloc
);
2275 yyglrShift (yystackp
, 0, yytable
[yyj
],
2276 yys
->yyposn
, &yylval
]b4_locations_if([, &yyerrloc
])[);
2277 yys
= yystackp
->yytops
.yystates
[0];
2280 }]b4_locations_if([[
2281 yystackp
->yyerror_range
[1].yystate
.yyloc
= yys
->yyloc
;]])[
2282 if (yys
->yypred
!= YY_NULL
)
2283 yydestroyGLRState ("Error: popping", yys
]b4_user_args
[);
2284 yystackp
->yytops
.yystates
[0] = yys
->yypred
;
2285 yystackp
->yynextFree
-= 1;
2286 yystackp
->yyspaceLeft
+= 1;
2288 if (yystackp
->yytops
.yystates
[0] == YY_NULL
)
2289 yyFail (yystackp
][]b4_lpure_args
[, YY_NULL
);
2292 #define YYCHK1(YYE) \
2302 goto yyuser_error; \
2313 ]b4_c_ansi_function_def([yyparse
], [int], b4_parse_param
)[
2317 yyGLRStack
* const yystackp
= &yystack
;
2320 YYDPRINTF ((stderr
, "Starting parse\n"));
2323 yylval
= yyval_default
;
2325 #if defined YYLTYPE_IS_TRIVIAL && YYLTYPE_IS_TRIVIAL
2326 yylloc
.first_line
= yylloc
.last_line
= ]b4_location_initial_line
[;
2327 yylloc
.first_column
= yylloc
.last_column
= ]b4_location_initial_column
[;
2330 m4_ifdef([b4_initial_action
], [
2331 m4_pushdef([b4_at_dollar
], [yylloc
])dnl
2332 m4_pushdef([b4_dollar_dollar
], [yylval
])dnl
2333 /* User initialization code. */
2334 b4_user_initial_action
2335 m4_popdef([b4_dollar_dollar
])dnl
2336 m4_popdef([b4_at_dollar
])])dnl
2338 if (! yyinitGLRStack (yystackp
, YYINITDEPTH
))
2339 goto yyexhaustedlab
;
2340 switch (YYSETJMP (yystack
.yyexception_buffer
))
2343 case 1: goto yyabortlab
;
2344 case 2: goto yyexhaustedlab
;
2345 default: goto yybuglab
;
2347 yyglrShift (&yystack
, 0, 0, 0, &yylval
]b4_locations_if([, &yylloc
])[);
2350 while (YYID (yytrue
))
2352 /* For efficiency, we have two loops, the first of which is
2353 specialized to deterministic operation (single stack, no
2354 potential ambiguity). */
2356 while (YYID (yytrue
))
2360 const short int* yyconflicts
;
2362 yyStateNum yystate
= yystack
.yytops
.yystates
[0]->yylrState
;
2363 YYDPRINTF ((stderr
, "Entering state %d\n", yystate
));
2364 if (yystate
== YYFINAL
)
2366 if (yyisDefaultedState (yystate
))
2368 yyrule
= yydefaultAction (yystate
);
2371 ]b4_locations_if([[ yystack
.yyerror_range
[1].yystate
.yyloc
= yylloc
;]])[
2372 yyreportSyntaxError (&yystack
]b4_user_args
[);
2375 YYCHK1 (yyglrReduce (&yystack
, 0, yyrule
, yytrue
]b4_user_args
[));
2380 if (yychar
== YYEMPTY
)
2382 YYDPRINTF ((stderr
, "Reading a token: "));
2386 if (yychar
<= YYEOF
)
2388 yychar
= yytoken
= YYEOF
;
2389 YYDPRINTF ((stderr
, "Now at end of input.\n"));
2393 yytoken
= YYTRANSLATE (yychar
);
2394 YY_SYMBOL_PRINT ("Next token is", yytoken
, &yylval
, &yylloc
);
2397 yygetLRActions (yystate
, yytoken
, &yyaction
, &yyconflicts
);
2398 if (*yyconflicts
!= 0)
2400 if (yyisShiftAction (yyaction
))
2402 YY_SYMBOL_PRINT ("Shifting", yytoken
, &yylval
, &yylloc
);
2405 yyglrShift (&yystack
, 0, yyaction
, yyposn
, &yylval
]b4_locations_if([, &yylloc
])[);
2406 if (0 < yystack
.yyerrState
)
2407 yystack
.yyerrState
-= 1;
2409 else if (yyisErrorAction (yyaction
))
2411 ]b4_locations_if([[ yystack
.yyerror_range
[1].yystate
.yyloc
= yylloc
;]])[
2412 yyreportSyntaxError (&yystack
]b4_user_args
[);
2416 YYCHK1 (yyglrReduce (&yystack
, 0, -yyaction
, yytrue
]b4_user_args
[));
2420 while (YYID (yytrue
))
2422 yySymbol yytoken_to_shift
;
2425 for (yys
= 0; yys
< yystack
.yytops
.yysize
; yys
+= 1)
2426 yystackp
->yytops
.yylookaheadNeeds
[yys
] = yychar
!= YYEMPTY
;
2428 /* yyprocessOneStack returns one of three things:
2430 - An error flag. If the caller is yyprocessOneStack, it
2431 immediately returns as well. When the caller is finally
2432 yyparse, it jumps to an error label via YYCHK1.
2434 - yyok, but yyprocessOneStack has invoked yymarkStackDeleted
2435 (&yystack, yys), which sets the top state of yys to NULL. Thus,
2436 yyparse's following invocation of yyremoveDeletes will remove
2439 - yyok, when ready to shift a token.
2441 Except in the first case, yyparse will invoke yyremoveDeletes and
2442 then shift the next token onto all remaining stacks. This
2443 synchronization of the shift (that is, after all preceding
2444 reductions on all stacks) helps prevent double destructor calls
2445 on yylval in the event of memory exhaustion. */
2447 for (yys
= 0; yys
< yystack
.yytops
.yysize
; yys
+= 1)
2448 YYCHK1 (yyprocessOneStack (&yystack
, yys
, yyposn
]b4_lpure_args
[));
2449 yyremoveDeletes (&yystack
);
2450 if (yystack
.yytops
.yysize
== 0)
2452 yyundeleteLastStack (&yystack
);
2453 if (yystack
.yytops
.yysize
== 0)
2454 yyFail (&yystack
][]b4_lpure_args
[, YY_("syntax error"));
2455 YYCHK1 (yyresolveStack (&yystack
]b4_user_args
[));
2456 YYDPRINTF ((stderr
, "Returning to deterministic operation.\n"));
2457 ]b4_locations_if([[ yystack
.yyerror_range
[1].yystate
.yyloc
= yylloc
;]])[
2458 yyreportSyntaxError (&yystack
]b4_user_args
[);
2462 /* If any yyglrShift call fails, it will fail after shifting. Thus,
2463 a copy of yylval will already be on stack 0 in the event of a
2464 failure in the following loop. Thus, yychar is set to YYEMPTY
2465 before the loop to make sure the user destructor for yylval isn't
2467 yytoken_to_shift
= YYTRANSLATE (yychar
);
2470 for (yys
= 0; yys
< yystack
.yytops
.yysize
; yys
+= 1)
2473 const short int* yyconflicts
;
2474 yyStateNum yystate
= yystack
.yytops
.yystates
[yys
]->yylrState
;
2475 yygetLRActions (yystate
, yytoken_to_shift
, &yyaction
,
2477 /* Note that yyconflicts were handled by yyprocessOneStack. */
2478 YYDPRINTF ((stderr
, "On stack %lu, ", (unsigned long int) yys
));
2479 YY_SYMBOL_PRINT ("shifting", yytoken_to_shift
, &yylval
, &yylloc
);
2480 yyglrShift (&yystack
, yys
, yyaction
, yyposn
,
2481 &yylval
]b4_locations_if([, &yylloc
])[);
2482 YYDPRINTF ((stderr
, "Stack %lu now in state #%d\n",
2483 (unsigned long int) yys
,
2484 yystack
.yytops
.yystates
[yys
]->yylrState
));
2487 if (yystack
.yytops
.yysize
== 1)
2489 YYCHK1 (yyresolveStack (&yystack
]b4_user_args
[));
2490 YYDPRINTF ((stderr
, "Returning to deterministic operation.\n"));
2491 yycompressStack (&yystack
);
2497 yyrecoverSyntaxError (&yystack
]b4_user_args
[);
2498 yyposn
= yystack
.yytops
.yystates
[0]->yyposn
;
2514 yyerror (]b4_lyyerror_args
[YY_("memory exhausted"));
2519 if (yychar
!= YYEMPTY
)
2520 yydestruct ("Cleanup: discarding lookahead",
2521 YYTRANSLATE (yychar
), &yylval
]b4_locuser_args([&yylloc
])[);
2523 /* If the stack is well-formed, pop the stack until it is empty,
2524 destroying its entries as we go. But free the stack regardless
2525 of whether it is well-formed. */
2526 if (yystack
.yyitems
)
2528 yyGLRState
** yystates
= yystack
.yytops
.yystates
;
2531 size_t yysize
= yystack
.yytops
.yysize
;
2533 for (yyk
= 0; yyk
< yysize
; yyk
+= 1)
2536 while (yystates
[yyk
])
2538 yyGLRState
*yys
= yystates
[yyk
];
2539 ]b4_locations_if([[ yystack
.yyerror_range
[1].yystate
.yyloc
= yys
->yyloc
;]]
2540 )[ if (yys
->yypred
!= YY_NULL
)
2541 yydestroyGLRState ("Cleanup: popping", yys
]b4_user_args
[);
2542 yystates
[yyk
] = yys
->yypred
;
2543 yystack
.yynextFree
-= 1;
2544 yystack
.yyspaceLeft
+= 1;
2549 yyfreeGLRStack (&yystack
);
2552 /* Make sure YYID is used. */
2553 return YYID (yyresult
);
2556 /* DEBUGGING ONLY */
2558 static void yypstack (yyGLRStack
* yystackp
, size_t yyk
)
2559 __attribute__ ((__unused__
));
2560 static void yypdumpstack (yyGLRStack
* yystackp
) __attribute__ ((__unused__
));
2563 yy_yypstack (yyGLRState
* yys
)
2567 yy_yypstack (yys
->yypred
);
2568 YYFPRINTF (stderr
, " -> ");
2570 YYFPRINTF (stderr
, "%d@@%lu", yys
->yylrState
,
2571 (unsigned long int) yys
->yyposn
);
2575 yypstates (yyGLRState
* yyst
)
2577 if (yyst
== YY_NULL
)
2578 YYFPRINTF (stderr
, "<null>");
2581 YYFPRINTF (stderr
, "\n");
2585 yypstack (yyGLRStack
* yystackp
, size_t yyk
)
2587 yypstates (yystackp
->yytops
.yystates
[yyk
]);
2590 #define YYINDEX(YYX) \
2591 ((YYX) == YY_NULL ? -1 : (yyGLRStackItem*) (YYX) - yystackp->yyitems)
2595 yypdumpstack (yyGLRStack
* yystackp
)
2597 yyGLRStackItem
* yyp
;
2599 for (yyp
= yystackp
->yyitems
; yyp
< yystackp
->yynextFree
; yyp
+= 1)
2601 YYFPRINTF (stderr
, "%3lu. ",
2602 (unsigned long int) (yyp
- yystackp
->yyitems
));
2603 if (*(yybool
*) yyp
)
2605 YYFPRINTF (stderr
, "Res: %d, LR State: %d, posn: %lu, pred: %ld",
2606 yyp
->yystate
.yyresolved
, yyp
->yystate
.yylrState
,
2607 (unsigned long int) yyp
->yystate
.yyposn
,
2608 (long int) YYINDEX (yyp
->yystate
.yypred
));
2609 if (! yyp
->yystate
.yyresolved
)
2610 YYFPRINTF (stderr
, ", firstVal: %ld",
2611 (long int) YYINDEX (yyp
->yystate
2612 .yysemantics
.yyfirstVal
));
2616 YYFPRINTF (stderr
, "Option. rule: %d, state: %ld, next: %ld",
2617 yyp
->yyoption
.yyrule
- 1,
2618 (long int) YYINDEX (yyp
->yyoption
.yystate
),
2619 (long int) YYINDEX (yyp
->yyoption
.yynext
));
2621 YYFPRINTF (stderr
, "\n");
2623 YYFPRINTF (stderr
, "Tops:");
2624 for (yyi
= 0; yyi
< yystackp
->yytops
.yysize
; yyi
+= 1)
2625 YYFPRINTF (stderr
, "%lu: %ld; ", (unsigned long int) yyi
,
2626 (long int) YYINDEX (yystackp
->yytops
.yystates
[yyi
]));
2627 YYFPRINTF (stderr
, "\n");
2634 dnl glr
.cc produces its own header
.
2636 m4_if(b4_skeleton
, ["glr.c"],
2638 [@
output(b4_spec_defines_file@
)@
2639 b4_copyright([Skeleton interface
for Bison GLR parsers in C
],
2642 b4_shared_declarations
2645 [[extern YYSTYPE
]b4_prefix
[lval
;]])
2647 b4_locations_if([b4_pure_if([],
2648 [extern YYLTYPE
]b4_prefix
[lloc
;])