3 # GLR skeleton for Bison
5 # Copyright (C) 2002-2012 Free Software Foundation, Inc.
7 # This program is free software: you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License as published by
9 # the Free Software Foundation, either version 3 of the License, or
10 # (at your option) any later version.
12 # This program is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
17 # You should have received a copy of the GNU General Public License
18 # along with this program. If not, see <http://www.gnu.org/licenses/>.
21 m4_include(b4_pkgdatadir
/[c
.m4
])
23 ## ---------------- ##
25 ## ---------------- ##
28 m4_define_default([b4_stack_depth_max
], [10000])
29 m4_define_default([b4_stack_depth_init
], [200])
33 ## ------------------------ ##
34 ## Pure/impure interfaces. ##
35 ## ------------------------ ##
37 b4_define_flag_if([pure
])
38 # If glr.cc is including this file and thus has already set b4_pure_flag,
39 # do not change the value of b4_pure_flag, and do not record a use of api.pure.
40 m4_ifndef([b4_pure_flag
],
41 [b4_percent_define_default([[api
.pure
]], [[false]])
42 m4_define([b4_pure_flag
],
43 [b4_percent_define_flag_if([[api
.pure
]], [[1]], [[0]])])])
47 # The possible parse-params formal arguments preceded by a comma.
49 # This is not shared with yacc.c in c.m4 because GLR relies on ISO C
50 # formal argument declarations.
51 m4_define([b4_user_formals
],
52 [m4_ifset([b4_parse_param
], [, b4_c_ansi_formals(b4_parse_param
)])])
57 # Accumule in b4_lex_param all the yylex arguments.
58 # Yes, this is quite ugly...
59 m4_define([b4_lex_param
],
60 m4_dquote(b4_pure_if([[[[YYSTYPE
*]], [[&yylval
]]][]dnl
61 b4_locations_if([, [[YYLTYPE
*], [&yylloc
]]])])dnl
62 m4_ifdef([b4_lex_param
], [, ]b4_lex_param
)))
67 # Optional effective arguments passed to yyerror: user args plus yylloc, and
69 m4_define([b4_yyerror_args
],
70 [b4_pure_if([b4_locations_if([yylocp
, ])])dnl
71 m4_ifset([b4_parse_param
], [b4_c_args(b4_parse_param
), ])])
76 # Same as above, but on the lookahead, hence &yylloc instead of yylocp.
77 m4_define([b4_lyyerror_args
],
78 [b4_pure_if([b4_locations_if([&yylloc
, ])])dnl
79 m4_ifset([b4_parse_param
], [b4_c_args(b4_parse_param
), ])])
84 # Same as b4_yyerror_args, but with a leading comma.
85 m4_define([b4_pure_args
],
86 [b4_pure_if([b4_locations_if([, yylocp
])])[]b4_user_args
])
91 # Same as above, but on the lookahead, hence &yylloc instead of yylocp.
92 m4_define([b4_lpure_args
],
93 [b4_pure_if([b4_locations_if([, &yylloc
])])[]b4_user_args
])
99 # Arguments passed to yyerror: user formals plus yylocp with leading comma.
100 m4_define([b4_pure_formals
],
101 [b4_pure_if([b4_locations_if([, YYLTYPE
*yylocp
])])[]b4_user_formals
])
104 # b4_locuser_formals(LOC = yylocp)
105 # --------------------------------
106 m4_define([b4_locuser_formals
],
107 [b4_locations_if([, YYLTYPE
*m4_default([$
1], [yylocp
])])[]b4_user_formals
])
110 # b4_locuser_args(LOC = yylocp)
111 # -----------------------------
112 m4_define([b4_locuser_args
],
113 [b4_locations_if([, m4_default([$
1], [yylocp
])])[]b4_user_args
])
117 ## ----------------- ##
118 ## Semantic Values. ##
119 ## ----------------- ##
122 # b4_lhs_value([TYPE])
123 # --------------------
124 # Expansion of $<TYPE>$.
125 m4_define([b4_lhs_value
],
126 [((*yyvalp
)[]m4_ifval([$
1], [.$
1]))])
129 # b4_rhs_value(RULE-LENGTH, NUM, [TYPE])
130 # --------------------------------------
131 # Expansion of $<TYPE>NUM, where the current rule has RULE-LENGTH
133 m4_define([b4_rhs_value
],
134 [(((yyGLRStackItem
const *)yyvsp
)@
{YYFILL (($
2) - ($
1))@
}.yystate
.yysemantics
.yysval
[]m4_ifval([$
3], [.$
3]))])
145 m4_define([b4_lhs_location
],
149 # b4_rhs_location(RULE-LENGTH, NUM)
150 # ---------------------------------
151 # Expansion of @NUM, where the current rule has RULE-LENGTH symbols
153 m4_define([b4_rhs_location
],
154 [(((yyGLRStackItem
const *)yyvsp
)@
{YYFILL (($
2) - ($
1))@
}.yystate
.yyloc
)])
161 # b4_shared_declarations
162 # ----------------------
163 # Declaration that might either go into the header (if --defines)
164 # or open coded in the parser body.
165 m4_define([b4_shared_declarations
],
167 ]b4_percent_code_get([[requires]])[
168 ]b4_token_enums(b4_tokens
)[
169 ]b4_declare_yylstype
[
170 ]b4_c_ansi_function_decl(b4_prefix
[parse
], [int], b4_parse_param
)[
171 ]b4_percent_code_get([[provides]])[]dnl
179 # We do want M4 expansion after # for CPP macros.
182 @
output(b4_parser_file_name@
)@
183 b4_copyright([Skeleton implementation
for Bison GLR parsers in C
],
186 /* C GLR parser skeleton written by Paul Hilfinger. */
190 b4_percent_code_get([[top]])[
191 ]m4_if(b4_prefix
, [yy
], [],
192 [[/* Substitute the variable and function names. */
193 #define yyparse ]b4_prefix[parse
194 #define yylex ]b4_prefix[lex
195 #define yyerror ]b4_prefix[error
196 #define yylval ]b4_prefix[lval
197 #define yychar ]b4_prefix[char
198 #define yydebug ]b4_prefix[debug
199 #define yynerrs ]b4_prefix[nerrs]b4_locations_if([[
200 #define yylloc ]b4_prefix[lloc]])])[
202 /* Copy the first part of user declarations. */
203 ]b4_user_pre_prologue
[
207 ]b4_defines_if([[#include "@basename(]b4_spec_defines_file[@)"]],
208 [b4_shared_declarations
])[
210 /* Enabling verbose error messages. */
211 #ifdef YYERROR_VERBOSE
212 # undef YYERROR_VERBOSE
213 # define YYERROR_VERBOSE 1
215 # define YYERROR_VERBOSE ]b4_error_verbose_flag[
218 /* Default (constant) value used for initialization for null
219 right-hand sides. Unlike the standard yacc.c template,
220 here we set the default value of $$ to a zeroed-out value.
221 Since the default value is undefined, this behavior is
222 technically correct. */
223 static YYSTYPE yyval_default
;
225 /* Copy the second part of user declarations. */
226 ]b4_user_post_prologue
227 b4_percent_code_get
[]dnl
234 # if defined YYENABLE_NLS && YYENABLE_NLS
236 # include <libintl.h> /* INFRINGES ON USER NAME SPACE */
237 # define YY_(msgid) dgettext ("bison-runtime", msgid)
241 # define YY_(msgid) msgid
245 /* Suppress unused-variable warnings by "using" E. */
246 #if ! defined lint || defined __GNUC__
247 # define YYUSE(e) ((void) (e))
249 # define YYUSE(e) /* empty */
252 /* Identity function, used to suppress warnings about constant conditions. */
256 ]b4_c_function_def([YYID
], [static int], [[int i
], [i
]])[
266 # define YYMALLOC malloc
269 # define YYREALLOC realloc
272 #define YYSIZEMAX ((size_t) -1)
277 typedef unsigned char yybool
;
284 # define YYJMP_BUF jmp_buf
285 # define YYSETJMP(env) setjmp (env)
286 # define YYLONGJMP(env, val) longjmp (env, val)
293 #ifndef __attribute__
294 /* This feature is available in gcc versions 2.5 and later. */
295 # if (! defined __GNUC__ || __GNUC__ < 2 \
296 || (__GNUC__ == 2 && __GNUC_MINOR__ < 5))
297 # define __attribute__(Spec) /* empty */
301 ]b4_locations_if([#define YYOPTIONAL_LOC(Name) Name],[
303 # define YYOPTIONAL_LOC(Name) /* empty */
305 # define YYOPTIONAL_LOC(Name) Name __attribute__ ((__unused__))
309 # define YYASSERT(condition) ((void) ((condition) || (abort (), 0)))
312 /* YYFINAL -- State number of the termination state. */
313 #define YYFINAL ]b4_final_state_number[
314 /* YYLAST -- Last index in YYTABLE. */
315 #define YYLAST ]b4_last[
317 /* YYNTOKENS -- Number of terminals. */
318 #define YYNTOKENS ]b4_tokens_number[
319 /* YYNNTS -- Number of nonterminals. */
320 #define YYNNTS ]b4_nterms_number[
321 /* YYNRULES -- Number of rules. */
322 #define YYNRULES ]b4_rules_number[
323 /* YYNRULES -- Number of states. */
324 #define YYNSTATES ]b4_states_number[
325 /* YYMAXRHS -- Maximum number of symbols on right-hand side of rule. */
326 #define YYMAXRHS ]b4_r2_max[
327 /* YYMAXLEFT -- Maximum number of symbols to the left of a handle
328 accessed by $0, $-1, etc., in any rule. */
329 #define YYMAXLEFT ]b4_max_left_semantic_context[
331 /* YYTRANSLATE(X) -- Bison symbol number corresponding to X. */
332 #define YYUNDEFTOK ]b4_undef_token_number[
333 #define YYMAXUTOK ]b4_user_token_number_max[
335 #define YYTRANSLATE(YYX) \
336 ((unsigned int) (YYX) <= YYMAXUTOK ? yytranslate[YYX] : YYUNDEFTOK)
338 /* YYTRANSLATE[YYLEX] -- Bison symbol number corresponding to YYLEX. */
339 static const ]b4_int_type_for([b4_translate
])[ yytranslate
[] =
345 /* YYPRHS[YYN] -- Index of the first RHS symbol of rule number YYN in
347 static const ]b4_int_type_for([b4_prhs
])[ yyprhs
[] =
352 /* YYRHS -- A `-1'-separated list of the rules' RHS. */
353 static const ]b4_int_type_for([b4_rhs
])[ yyrhs
[] =
358 /* YYRLINE[YYN] -- source line where rule number YYN was defined. */
359 static const ]b4_int_type_for([b4_rline
])[ yyrline
[] =
365 #if YYDEBUG || YYERROR_VERBOSE || ]b4_token_table_flag[
366 /* YYTNAME[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM.
367 First, the terminals, then, starting at YYNTOKENS, nonterminals. */
368 static const char *const yytname
[] =
374 /* YYR1[YYN] -- Symbol number of symbol that rule YYN derives. */
375 static const ]b4_int_type_for([b4_r1
])[ yyr1
[] =
380 /* YYR2[YYN] -- Number of symbols composing right hand side of rule YYN. */
381 static const ]b4_int_type_for([b4_r2
])[ yyr2
[] =
386 /* YYDPREC[RULE-NUM] -- Dynamic precedence of rule #RULE-NUM (0 if none). */
387 static const ]b4_int_type_for([b4_dprec
])[ yydprec
[] =
392 /* YYMERGER[RULE-NUM] -- Index of merging function for rule #RULE-NUM. */
393 static const ]b4_int_type_for([b4_merger
])[ yymerger
[] =
398 /* YYDEFACT[S] -- default reduction number in state S. Performed when
399 YYTABLE doesn't specify something else to do. Zero means the default
401 static const ]b4_int_type_for([b4_defact
])[ yydefact
[] =
406 /* YYPDEFGOTO[NTERM-NUM]. */
407 static const ]b4_int_type_for([b4_defgoto
])[ yydefgoto
[] =
412 /* YYPACT[STATE-NUM] -- Index in YYTABLE of the portion describing
414 #define YYPACT_NINF ]b4_pact_ninf[
415 static const ]b4_int_type_for([b4_pact
])[ yypact
[] =
420 /* YYPGOTO[NTERM-NUM]. */
421 static const ]b4_int_type_for([b4_pgoto
])[ yypgoto
[] =
426 /* YYTABLE[YYPACT[STATE-NUM]]. What to do in state STATE-NUM. If
427 positive, shift that token. If negative, reduce the rule which
428 number is the opposite. If YYTABLE_NINF, syntax error. */
429 #define YYTABLE_NINF ]b4_table_ninf[
430 static const ]b4_int_type_for([b4_table
])[ yytable
[] =
435 /* YYCONFLP[YYPACT[STATE-NUM]] -- Pointer into YYCONFL of start of
436 list of conflicting reductions corresponding to action entry for
437 state STATE-NUM in yytable. 0 means no conflicts. The list in
438 yyconfl is terminated by a rule number of 0. */
439 static const ]b4_int_type_for([b4_conflict_list_heads
])[ yyconflp
[] =
441 ]b4_conflict_list_heads
[
444 /* YYCONFL[I] -- lists of conflicting rule numbers, each terminated by
445 0, pointed into by YYCONFLP. */
446 ]dnl Do
not use b4_int_type_for here
, since there are places where
447 dnl pointers onto yyconfl are taken
, which type is
"short int *".
448 dnl We probably ought to introduce a type
for confl
.
449 [static const short int yyconfl
[] =
451 ]b4_conflicting_rules
[
454 static const ]b4_int_type_for([b4_check
])[ yycheck
[] =
459 /* YYSTOS[STATE-NUM] -- The (internal number of the) accessing
460 symbol of state STATE-NUM. */
461 static const ]b4_int_type_for([b4_stos
])[ yystos
[] =
467 /* Error token number */
470 /* YYLLOC_DEFAULT -- Set CURRENT to span from RHS[1] to RHS[N].
471 If N is 0, then set CURRENT to the empty location which ends
472 the previous symbol: RHS[0] (always defined). */
475 #define YYRHSLOC(Rhs, K) ((Rhs)[K].yystate.yyloc)
476 #ifndef YYLLOC_DEFAULT
477 # define YYLLOC_DEFAULT(Current, Rhs, N) \
481 (Current).first_line = YYRHSLOC (Rhs, 1).first_line; \
482 (Current).first_column = YYRHSLOC (Rhs, 1).first_column; \
483 (Current).last_line = YYRHSLOC (Rhs, N).last_line; \
484 (Current).last_column = YYRHSLOC (Rhs, N).last_column; \
488 (Current).first_line = (Current).last_line = \
489 YYRHSLOC (Rhs, 0).last_line; \
490 (Current).first_column = (Current).last_column = \
491 YYRHSLOC (Rhs, 0).last_column; \
495 /* YY_LOCATION_PRINT -- Print the location on the stream.
496 This macro was not mandated originally: define only if we know
497 we won't break user code: when these are the locations we know. */
499 # define YY_LOCATION_PRINT(File, Loc) \
500 fprintf (File, "%d.%d-%d.%d", \
501 (Loc).first_line, (Loc).first_column, \
502 (Loc).last_line, (Loc).last_column)
505 #ifndef YYLLOC_DEFAULT
506 # define YYLLOC_DEFAULT(Current, Rhs, N) ((void) 0)
510 #ifndef YY_LOCATION_PRINT
511 # define YY_LOCATION_PRINT(File, Loc) ((void) 0)
515 /* YYLEX -- calling `yylex' with the right arguments. */
516 #define YYLEX ]b4_c_function_call([yylex], [int], b4_lex_param)[
521 #define yynerrs (yystackp->yyerrcnt)
523 #define yychar (yystackp->yyrawchar)
525 #define yylval (yystackp->yyval)
527 #define yylloc (yystackp->yyloc)
528 m4_if(b4_prefix
[], [yy
], [],
529 [#define b4_prefix[]nerrs yynerrs
530 #define b4_prefix[]char yychar
531 #define b4_prefix[]lval yylval
532 #define b4_prefix[]lloc yylloc])],
533 [YYSTYPE yylval
;]b4_locations_if([[
539 static const int YYEOF
= 0;
540 static const int YYEMPTY
= -2;
542 typedef enum { yyok
, yyaccept
, yyabort
, yyerr
} YYRESULTTAG
;
545 do { YYRESULTTAG yyflag = YYE; if (yyflag != yyok) return yyflag; } \
551 # define YYFPRINTF fprintf
554 # define YYDPRINTF(Args) \
560 ]b4_yy_symbol_print_generate([b4_c_ansi_function_def
])[
562 # define YY_SYMBOL_PRINT(Title, Type, Value, Location) \
566 YYFPRINTF (stderr, "%s ", Title); \
567 yy_symbol_print (stderr, Type, Value]b4_locuser_args([Location])[); \
568 YYFPRINTF (stderr, "\n"); \
572 /* Nonzero means print parse trace. It is left uninitialized so that
573 multiple parsers can coexist. */
578 # define YYDPRINTF(Args)
579 # define YY_SYMBOL_PRINT(Title, Type, Value, Location)
581 #endif /* !YYDEBUG */
583 /* YYINITDEPTH -- initial size of the parser's stacks. */
585 # define YYINITDEPTH ]b4_stack_depth_init[
588 /* YYMAXDEPTH -- maximum size the stacks can grow to (effective only
589 if the built-in stack extension method is used).
591 Do not make this value too large; the results are undefined if
592 SIZE_MAX < YYMAXDEPTH * sizeof (GLRStackItem)
593 evaluated with infinite-precision integer arithmetic. */
596 # define YYMAXDEPTH ]b4_stack_depth_max[
599 /* Minimum number of free items on the stack allowed after an
600 allocation. This is to allow allocation and initialization
601 to be completed by functions that call yyexpandGLRStack before the
602 stack is expanded, thus insuring that all necessary pointers get
603 properly redirected to new data. */
606 #ifndef YYSTACKEXPANDABLE
607 # if (! defined __cplusplus \
608 || (]b4_locations_if([[defined YYLTYPE_IS_TRIVIAL && YYLTYPE_IS_TRIVIAL \
609 && ]])[defined YYSTYPE_IS_TRIVIAL && YYSTYPE_IS_TRIVIAL))
610 # define YYSTACKEXPANDABLE 1
612 # define YYSTACKEXPANDABLE 0
616 #if YYSTACKEXPANDABLE
617 # define YY_RESERVE_GLRSTACK(Yystack) \
619 if (Yystack->yyspaceLeft < YYHEADROOM) \
620 yyexpandGLRStack (Yystack); \
623 # define YY_RESERVE_GLRSTACK(Yystack) \
625 if (Yystack->yyspaceLeft < YYHEADROOM) \
626 yyMemoryExhausted (Yystack); \
634 # if defined __GLIBC__ && defined _STRING_H && defined _GNU_SOURCE
635 # define yystpcpy stpcpy
637 /* Copy YYSRC to YYDEST, returning the address of the terminating '\0' in
640 yystpcpy (char *yydest
, const char *yysrc
)
643 const char *yys
= yysrc
;
645 while ((*yyd
++ = *yys
++) != '\0')
654 /* Copy to YYRES the contents of YYSTR after stripping away unnecessary
655 quotes and backslashes, so that it's suitable for yyerror. The
656 heuristic is that double-quoting is unnecessary unless the string
657 contains an apostrophe, a comma, or backslash (other than
658 backslash-backslash). YYSTR is taken from yytname. If YYRES is
659 null, do not copy; instead, return the length of what the result
662 yytnamerr (char *yyres
, const char *yystr
)
667 char const *yyp
= yystr
;
674 goto do_not_strip_quotes
;
678 goto do_not_strip_quotes
;
691 do_not_strip_quotes
: ;
695 return strlen (yystr
);
697 return yystpcpy (yyres
, yystr
) - yyres
;
701 #endif /* !YYERROR_VERBOSE */
703 /** State numbers, as in LALR(1) machine */
704 typedef int yyStateNum
;
706 /** Rule numbers, as in LALR(1) machine */
707 typedef int yyRuleNum
;
709 /** Grammar symbol */
710 typedef short int yySymbol
;
712 /** Item references, as in LALR(1) machine */
713 typedef short int yyItemNum
;
715 typedef struct yyGLRState yyGLRState
;
716 typedef struct yyGLRStateSet yyGLRStateSet
;
717 typedef struct yySemanticOption yySemanticOption
;
718 typedef union yyGLRStackItem yyGLRStackItem
;
719 typedef struct yyGLRStack yyGLRStack
;
722 /** Type tag: always true. */
724 /** Type tag for yysemantics. If true, yysval applies, otherwise
725 * yyfirstVal applies. */
727 /** Number of corresponding LALR(1) machine state. */
728 yyStateNum yylrState
;
729 /** Preceding state in this stack */
731 /** Source position of the first token produced by my symbol */
734 /** First in a chain of alternative reductions producing the
735 * non-terminal corresponding to this state, threaded through
737 yySemanticOption
* yyfirstVal
;
738 /** Semantic value for this state. */
740 } yysemantics
;]b4_locations_if([[
741 /** Source location for this state. */
745 struct yyGLRStateSet
{
746 yyGLRState
** yystates
;
747 /** During nondeterministic operation, yylookaheadNeeds tracks which
748 * stacks have actually needed the current lookahead. During deterministic
749 * operation, yylookaheadNeeds[0] is not maintained since it would merely
750 * duplicate yychar != YYEMPTY. */
751 yybool
* yylookaheadNeeds
;
752 size_t yysize
, yycapacity
;
755 struct yySemanticOption
{
756 /** Type tag: always false. */
758 /** Rule number for this reduction */
760 /** The last RHS state in the list of states to be reduced. */
762 /** The lookahead for this reduction. */
764 YYSTYPE yyval
;]b4_locations_if([[
766 /** Next sibling in chain of options. To facilitate merging,
767 * options are chained in decreasing order by address. */
768 yySemanticOption
* yynext
;
771 /** Type of the items in the GLR stack. The yyisState field
772 * indicates which item of the union is valid. */
773 union yyGLRStackItem
{
775 yySemanticOption yyoption
;
780 ]b4_locations_if([[ /* To compute the location of the error token. */
781 yyGLRStackItem yyerror_range
[3];]])[
786 YYSTYPE yyval
;]b4_locations_if([[
789 YYJMP_BUF yyexception_buffer
;
790 yyGLRStackItem
* yyitems
;
791 yyGLRStackItem
* yynextFree
;
793 yyGLRState
* yysplitPoint
;
794 yyGLRState
* yylastDeleted
;
795 yyGLRStateSet yytops
;
798 #if YYSTACKEXPANDABLE
799 static void yyexpandGLRStack (yyGLRStack
* yystackp
);
802 static void yyFail (yyGLRStack
* yystackp
]b4_pure_formals
[, const char* yymsg
)
803 __attribute__ ((__noreturn__
));
805 yyFail (yyGLRStack
* yystackp
]b4_pure_formals
[, const char* yymsg
)
807 if (yymsg
!= YY_NULL
)
808 yyerror (]b4_yyerror_args
[yymsg
);
809 YYLONGJMP (yystackp
->yyexception_buffer
, 1);
812 static void yyMemoryExhausted (yyGLRStack
* yystackp
)
813 __attribute__ ((__noreturn__
));
815 yyMemoryExhausted (yyGLRStack
* yystackp
)
817 YYLONGJMP (yystackp
->yyexception_buffer
, 2);
820 #if YYDEBUG || YYERROR_VERBOSE
821 /** A printable representation of TOKEN. */
822 static inline const char*
823 yytokenName (yySymbol yytoken
)
825 if (yytoken
== YYEMPTY
)
828 return yytname
[yytoken
];
832 /** Fill in YYVSP[YYLOW1 .. YYLOW0-1] from the chain of states starting
833 * at YYVSP[YYLOW0].yystate.yypred. Leaves YYVSP[YYLOW1].yystate.yypred
834 * containing the pointer to the next state in the chain. */
835 static void yyfillin (yyGLRStackItem
*, int, int) __attribute__ ((__unused__
));
837 yyfillin (yyGLRStackItem
*yyvsp
, int yylow0
, int yylow1
)
840 yyGLRState
*s
= yyvsp
[yylow0
].yystate
.yypred
;
841 for (i
= yylow0
-1; i
>= yylow1
; i
-= 1)
843 YYASSERT (s
->yyresolved
);
844 yyvsp
[i
].yystate
.yyresolved
= yytrue
;
845 yyvsp
[i
].yystate
.yysemantics
.yysval
= s
->yysemantics
.yysval
;]b4_locations_if([[
846 yyvsp
[i
].yystate
.yyloc
= s
->yyloc
;]])[
847 s
= yyvsp
[i
].yystate
.yypred
= s
->yypred
;
851 /* Do nothing if YYNORMAL or if *YYLOW <= YYLOW1. Otherwise, fill in
852 * YYVSP[YYLOW1 .. *YYLOW-1] as in yyfillin and set *YYLOW = YYLOW1.
853 * For convenience, always return YYLOW1. */
854 static inline int yyfill (yyGLRStackItem
*, int *, int, yybool
)
855 __attribute__ ((__unused__
));
857 yyfill (yyGLRStackItem
*yyvsp
, int *yylow
, int yylow1
, yybool yynormal
)
859 if (!yynormal
&& yylow1
< *yylow
)
861 yyfillin (yyvsp
, *yylow
, yylow1
);
867 /** Perform user action for rule number YYN, with RHS length YYRHSLEN,
868 * and top stack item YYVSP. YYLVALP points to place to put semantic
869 * value ($$), and yylocp points to place for location information
870 * (@@$). Returns yyok for normal return, yyaccept for YYACCEPT,
871 * yyerr for YYERROR, yyabort for YYABORT. */
872 /*ARGSUSED*/ static YYRESULTTAG
873 yyuserAction (yyRuleNum yyn
, int yyrhslen
, yyGLRStackItem
* yyvsp
,
874 yyGLRStack
* yystackp
,
875 YYSTYPE
* yyvalp
]b4_locuser_formals
[)
877 yybool yynormal
__attribute__ ((__unused__
)) =
878 (yystackp
->yysplitPoint
== YY_NULL
);
880 ]b4_parse_param_use
[]dnl
882 # define yyerrok (yystackp->yyerrState = 0)
884 # define YYACCEPT return yyaccept
886 # define YYABORT return yyabort
888 # define YYERROR return yyerrok, yyerr
890 # define YYRECOVERING() (yystackp->yyerrState != 0)
892 # define yyclearin (yychar = YYEMPTY)
894 # define YYFILL(N) yyfill (yyvsp, &yylow, N, yynormal)
896 # define YYBACKUP(Token, Value) \
897 return yyerror (]b4_yyerror_args[YY_("syntax error: cannot back up")), \
902 *yyvalp
= yyval_default
;
904 *yyvalp
= yyvsp
[YYFILL (1-yyrhslen
)].yystate
.yysemantics
.yysval
;]b4_locations_if([[
905 YYLLOC_DEFAULT ((*yylocp
), (yyvsp
- yyrhslen
), yyrhslen
);
906 yystackp
->yyerror_range
[1].yystate
.yyloc
= *yylocp
;
925 /*ARGSUSED*/ static void
926 yyuserMerge (int yyn
, YYSTYPE
* yy0
, YYSTYPE
* yy1
)
938 /* Bison grammar-table manipulation. */
940 ]b4_yydestruct_generate([b4_c_ansi_function_def
])[
942 /** Number of symbols composing the right hand side of rule #RULE. */
944 yyrhsLength (yyRuleNum yyrule
)
950 yydestroyGLRState (char const *yymsg
, yyGLRState
*yys
]b4_user_formals
[)
953 yydestruct (yymsg
, yystos
[yys
->yylrState
],
954 &yys
->yysemantics
.yysval
]b4_locuser_args([&yys
->yyloc
])[);
960 if (yys
->yysemantics
.yyfirstVal
)
961 YYFPRINTF (stderr
, "%s unresolved ", yymsg
);
963 YYFPRINTF (stderr
, "%s incomplete ", yymsg
);
964 yy_symbol_print (stderr
, yystos
[yys
->yylrState
],
965 YY_NULL
]b4_locuser_args([&yys
->yyloc
])[);
966 YYFPRINTF (stderr
, "\n");
970 if (yys
->yysemantics
.yyfirstVal
)
972 yySemanticOption
*yyoption
= yys
->yysemantics
.yyfirstVal
;
975 for (yyrh
= yyoption
->yystate
, yyn
= yyrhsLength (yyoption
->yyrule
);
977 yyrh
= yyrh
->yypred
, yyn
-= 1)
978 yydestroyGLRState (yymsg
, yyrh
]b4_user_args
[);
983 /** Left-hand-side symbol for rule #RULE. */
984 static inline yySymbol
985 yylhsNonterm (yyRuleNum yyrule
)
990 #define yypact_value_is_default(yystate) \
991 ]b4_table_value_equals([[pact]], [[yystate]], [b4_pact_ninf])[
993 /** True iff LR state STATE has only a default reduction (regardless
996 yyisDefaultedState (yyStateNum yystate
)
998 return yypact_value_is_default (yypact
[yystate
]);
1001 /** The default reduction for STATE, assuming it has one. */
1002 static inline yyRuleNum
1003 yydefaultAction (yyStateNum yystate
)
1005 return yydefact
[yystate
];
1008 #define yytable_value_is_error(yytable_value) \
1009 ]b4_table_value_equals([[table]], [[yytable_value]], [b4_table_ninf])[
1011 /** Set *YYACTION to the action to take in YYSTATE on seeing YYTOKEN.
1013 * R < 0: Reduce on rule -R.
1015 * R > 0: Shift to state R.
1016 * Set *CONFLICTS to a pointer into yyconfl to 0-terminated list of
1017 * conflicting reductions.
1020 yygetLRActions (yyStateNum yystate
, int yytoken
,
1021 int* yyaction
, const short int** yyconflicts
)
1023 int yyindex
= yypact
[yystate
] + yytoken
;
1024 if (yypact_value_is_default (yypact
[yystate
])
1025 || yyindex
< 0 || YYLAST
< yyindex
|| yycheck
[yyindex
] != yytoken
)
1027 *yyaction
= -yydefact
[yystate
];
1028 *yyconflicts
= yyconfl
;
1030 else if (! yytable_value_is_error (yytable
[yyindex
]))
1032 *yyaction
= yytable
[yyindex
];
1033 *yyconflicts
= yyconfl
+ yyconflp
[yyindex
];
1038 *yyconflicts
= yyconfl
+ yyconflp
[yyindex
];
1042 static inline yyStateNum
1043 yyLRgotoState (yyStateNum yystate
, yySymbol yylhs
)
1046 yyr
= yypgoto
[yylhs
- YYNTOKENS
] + yystate
;
1047 if (0 <= yyr
&& yyr
<= YYLAST
&& yycheck
[yyr
] == yystate
)
1048 return yytable
[yyr
];
1050 return yydefgoto
[yylhs
- YYNTOKENS
];
1053 static inline yybool
1054 yyisShiftAction (int yyaction
)
1056 return 0 < yyaction
;
1059 static inline yybool
1060 yyisErrorAction (int yyaction
)
1062 return yyaction
== 0;
1067 /** Return a fresh GLRStackItem. Callers should call
1068 * YY_RESERVE_GLRSTACK afterwards to make sure there is sufficient
1071 static inline yyGLRStackItem
*
1072 yynewGLRStackItem (yyGLRStack
* yystackp
, yybool yyisState
)
1074 yyGLRStackItem
* yynewItem
= yystackp
->yynextFree
;
1075 yystackp
->yyspaceLeft
-= 1;
1076 yystackp
->yynextFree
+= 1;
1077 yynewItem
->yystate
.yyisState
= yyisState
;
1081 /** Add a new semantic action that will execute the action for rule
1082 * RULENUM on the semantic values in RHS to the list of
1083 * alternative actions for STATE. Assumes that RHS comes from
1084 * stack #K of *STACKP. */
1086 yyaddDeferredAction (yyGLRStack
* yystackp
, size_t yyk
, yyGLRState
* yystate
,
1087 yyGLRState
* rhs
, yyRuleNum yyrule
)
1089 yySemanticOption
* yynewOption
=
1090 &yynewGLRStackItem (yystackp
, yyfalse
)->yyoption
;
1091 yynewOption
->yystate
= rhs
;
1092 yynewOption
->yyrule
= yyrule
;
1093 if (yystackp
->yytops
.yylookaheadNeeds
[yyk
])
1095 yynewOption
->yyrawchar
= yychar
;
1096 yynewOption
->yyval
= yylval
;]b4_locations_if([
1097 yynewOption
->yyloc
= yylloc
;])[
1100 yynewOption
->yyrawchar
= YYEMPTY
;
1101 yynewOption
->yynext
= yystate
->yysemantics
.yyfirstVal
;
1102 yystate
->yysemantics
.yyfirstVal
= yynewOption
;
1104 YY_RESERVE_GLRSTACK (yystackp
);
1109 /** Initialize SET to a singleton set containing an empty stack. */
1111 yyinitStateSet (yyGLRStateSet
* yyset
)
1114 yyset
->yycapacity
= 16;
1115 yyset
->yystates
= (yyGLRState
**) YYMALLOC (16 * sizeof yyset
->yystates
[0]);
1116 if (! yyset
->yystates
)
1118 yyset
->yystates
[0] = YY_NULL
;
1119 yyset
->yylookaheadNeeds
=
1120 (yybool
*) YYMALLOC (16 * sizeof yyset
->yylookaheadNeeds
[0]);
1121 if (! yyset
->yylookaheadNeeds
)
1123 YYFREE (yyset
->yystates
);
1129 static void yyfreeStateSet (yyGLRStateSet
* yyset
)
1131 YYFREE (yyset
->yystates
);
1132 YYFREE (yyset
->yylookaheadNeeds
);
1135 /** Initialize STACK to a single empty stack, with total maximum
1136 * capacity for all stacks of SIZE. */
1138 yyinitGLRStack (yyGLRStack
* yystackp
, size_t yysize
)
1140 yystackp
->yyerrState
= 0;
1142 yystackp
->yyspaceLeft
= yysize
;
1144 (yyGLRStackItem
*) YYMALLOC (yysize
* sizeof yystackp
->yynextFree
[0]);
1145 if (!yystackp
->yyitems
)
1147 yystackp
->yynextFree
= yystackp
->yyitems
;
1148 yystackp
->yysplitPoint
= YY_NULL
;
1149 yystackp
->yylastDeleted
= YY_NULL
;
1150 return yyinitStateSet (&yystackp
->yytops
);
1154 #if YYSTACKEXPANDABLE
1155 # define YYRELOC(YYFROMITEMS,YYTOITEMS,YYX,YYTYPE) \
1156 &((YYTOITEMS) - ((YYFROMITEMS) - (yyGLRStackItem*) (YYX)))->YYTYPE
1158 /** If STACK is expandable, extend it. WARNING: Pointers into the
1159 stack from outside should be considered invalid after this call.
1160 We always expand when there are 1 or fewer items left AFTER an
1161 allocation, so that we can avoid having external pointers exist
1162 across an allocation. */
1164 yyexpandGLRStack (yyGLRStack
* yystackp
)
1166 yyGLRStackItem
* yynewItems
;
1167 yyGLRStackItem
* yyp0
, *yyp1
;
1170 size_t yysize
= yystackp
->yynextFree
- yystackp
->yyitems
;
1171 if (YYMAXDEPTH
- YYHEADROOM
< yysize
)
1172 yyMemoryExhausted (yystackp
);
1173 yynewSize
= 2*yysize
;
1174 if (YYMAXDEPTH
< yynewSize
)
1175 yynewSize
= YYMAXDEPTH
;
1176 yynewItems
= (yyGLRStackItem
*) YYMALLOC (yynewSize
* sizeof yynewItems
[0]);
1178 yyMemoryExhausted (yystackp
);
1179 for (yyp0
= yystackp
->yyitems
, yyp1
= yynewItems
, yyn
= yysize
;
1181 yyn
-= 1, yyp0
+= 1, yyp1
+= 1)
1184 if (*(yybool
*) yyp0
)
1186 yyGLRState
* yys0
= &yyp0
->yystate
;
1187 yyGLRState
* yys1
= &yyp1
->yystate
;
1188 if (yys0
->yypred
!= YY_NULL
)
1190 YYRELOC (yyp0
, yyp1
, yys0
->yypred
, yystate
);
1191 if (! yys0
->yyresolved
&& yys0
->yysemantics
.yyfirstVal
!= YY_NULL
)
1192 yys1
->yysemantics
.yyfirstVal
=
1193 YYRELOC (yyp0
, yyp1
, yys0
->yysemantics
.yyfirstVal
, yyoption
);
1197 yySemanticOption
* yyv0
= &yyp0
->yyoption
;
1198 yySemanticOption
* yyv1
= &yyp1
->yyoption
;
1199 if (yyv0
->yystate
!= YY_NULL
)
1200 yyv1
->yystate
= YYRELOC (yyp0
, yyp1
, yyv0
->yystate
, yystate
);
1201 if (yyv0
->yynext
!= YY_NULL
)
1202 yyv1
->yynext
= YYRELOC (yyp0
, yyp1
, yyv0
->yynext
, yyoption
);
1205 if (yystackp
->yysplitPoint
!= YY_NULL
)
1206 yystackp
->yysplitPoint
= YYRELOC (yystackp
->yyitems
, yynewItems
,
1207 yystackp
->yysplitPoint
, yystate
);
1209 for (yyn
= 0; yyn
< yystackp
->yytops
.yysize
; yyn
+= 1)
1210 if (yystackp
->yytops
.yystates
[yyn
] != YY_NULL
)
1211 yystackp
->yytops
.yystates
[yyn
] =
1212 YYRELOC (yystackp
->yyitems
, yynewItems
,
1213 yystackp
->yytops
.yystates
[yyn
], yystate
);
1214 YYFREE (yystackp
->yyitems
);
1215 yystackp
->yyitems
= yynewItems
;
1216 yystackp
->yynextFree
= yynewItems
+ yysize
;
1217 yystackp
->yyspaceLeft
= yynewSize
- yysize
;
1222 yyfreeGLRStack (yyGLRStack
* yystackp
)
1224 YYFREE (yystackp
->yyitems
);
1225 yyfreeStateSet (&yystackp
->yytops
);
1228 /** Assuming that S is a GLRState somewhere on STACK, update the
1229 * splitpoint of STACK, if needed, so that it is at least as deep as
1232 yyupdateSplit (yyGLRStack
* yystackp
, yyGLRState
* yys
)
1234 if (yystackp
->yysplitPoint
!= YY_NULL
&& yystackp
->yysplitPoint
> yys
)
1235 yystackp
->yysplitPoint
= yys
;
1238 /** Invalidate stack #K in STACK. */
1240 yymarkStackDeleted (yyGLRStack
* yystackp
, size_t yyk
)
1242 if (yystackp
->yytops
.yystates
[yyk
] != YY_NULL
)
1243 yystackp
->yylastDeleted
= yystackp
->yytops
.yystates
[yyk
];
1244 yystackp
->yytops
.yystates
[yyk
] = YY_NULL
;
1247 /** Undelete the last stack that was marked as deleted. Can only be
1248 done once after a deletion, and only when all other stacks have
1251 yyundeleteLastStack (yyGLRStack
* yystackp
)
1253 if (yystackp
->yylastDeleted
== YY_NULL
|| yystackp
->yytops
.yysize
!= 0)
1255 yystackp
->yytops
.yystates
[0] = yystackp
->yylastDeleted
;
1256 yystackp
->yytops
.yysize
= 1;
1257 YYDPRINTF ((stderr
, "Restoring last deleted stack as stack #0.\n"));
1258 yystackp
->yylastDeleted
= YY_NULL
;
1262 yyremoveDeletes (yyGLRStack
* yystackp
)
1266 while (yyj
< yystackp
->yytops
.yysize
)
1268 if (yystackp
->yytops
.yystates
[yyi
] == YY_NULL
)
1272 YYDPRINTF ((stderr
, "Removing dead stacks.\n"));
1274 yystackp
->yytops
.yysize
-= 1;
1278 yystackp
->yytops
.yystates
[yyj
] = yystackp
->yytops
.yystates
[yyi
];
1279 /* In the current implementation, it's unnecessary to copy
1280 yystackp->yytops.yylookaheadNeeds[yyi] since, after
1281 yyremoveDeletes returns, the parser immediately either enters
1282 deterministic operation or shifts a token. However, it doesn't
1283 hurt, and the code might evolve to need it. */
1284 yystackp
->yytops
.yylookaheadNeeds
[yyj
] =
1285 yystackp
->yytops
.yylookaheadNeeds
[yyi
];
1288 YYDPRINTF ((stderr
, "Rename stack %lu -> %lu.\n",
1289 (unsigned long int) yyi
, (unsigned long int) yyj
));
1297 /** Shift to a new state on stack #K of STACK, corresponding to LR state
1298 * LRSTATE, at input position POSN, with (resolved) semantic value SVAL. */
1300 yyglrShift (yyGLRStack
* yystackp
, size_t yyk
, yyStateNum yylrState
,
1302 YYSTYPE
* yyvalp
]b4_locations_if([, YYLTYPE
* yylocp
])[)
1304 yyGLRState
* yynewState
= &yynewGLRStackItem (yystackp
, yytrue
)->yystate
;
1306 yynewState
->yylrState
= yylrState
;
1307 yynewState
->yyposn
= yyposn
;
1308 yynewState
->yyresolved
= yytrue
;
1309 yynewState
->yypred
= yystackp
->yytops
.yystates
[yyk
];
1310 yynewState
->yysemantics
.yysval
= *yyvalp
;]b4_locations_if([
1311 yynewState
->yyloc
= *yylocp
;])[
1312 yystackp
->yytops
.yystates
[yyk
] = yynewState
;
1314 YY_RESERVE_GLRSTACK (yystackp
);
1317 /** Shift stack #K of YYSTACK, to a new state corresponding to LR
1318 * state YYLRSTATE, at input position YYPOSN, with the (unresolved)
1319 * semantic value of YYRHS under the action for YYRULE. */
1321 yyglrShiftDefer (yyGLRStack
* yystackp
, size_t yyk
, yyStateNum yylrState
,
1322 size_t yyposn
, yyGLRState
* rhs
, yyRuleNum yyrule
)
1324 yyGLRState
* yynewState
= &yynewGLRStackItem (yystackp
, yytrue
)->yystate
;
1326 yynewState
->yylrState
= yylrState
;
1327 yynewState
->yyposn
= yyposn
;
1328 yynewState
->yyresolved
= yyfalse
;
1329 yynewState
->yypred
= yystackp
->yytops
.yystates
[yyk
];
1330 yynewState
->yysemantics
.yyfirstVal
= YY_NULL
;
1331 yystackp
->yytops
.yystates
[yyk
] = yynewState
;
1333 /* Invokes YY_RESERVE_GLRSTACK. */
1334 yyaddDeferredAction (yystackp
, yyk
, yynewState
, rhs
, yyrule
);
1337 /** Pop the symbols consumed by reduction #RULE from the top of stack
1338 * #K of STACK, and perform the appropriate semantic action on their
1339 * semantic values. Assumes that all ambiguities in semantic values
1340 * have been previously resolved. Set *VALP to the resulting value,
1341 * and *LOCP to the computed location (if any). Return value is as
1342 * for userAction. */
1343 static inline YYRESULTTAG
1344 yydoAction (yyGLRStack
* yystackp
, size_t yyk
, yyRuleNum yyrule
,
1345 YYSTYPE
* yyvalp
]b4_locuser_formals
[)
1347 int yynrhs
= yyrhsLength (yyrule
);
1349 if (yystackp
->yysplitPoint
== YY_NULL
)
1351 /* Standard special case: single stack. */
1352 yyGLRStackItem
* rhs
= (yyGLRStackItem
*) yystackp
->yytops
.yystates
[yyk
];
1353 YYASSERT (yyk
== 0);
1354 yystackp
->yynextFree
-= yynrhs
;
1355 yystackp
->yyspaceLeft
+= yynrhs
;
1356 yystackp
->yytops
.yystates
[0] = & yystackp
->yynextFree
[-1].yystate
;
1357 return yyuserAction (yyrule
, yynrhs
, rhs
, yystackp
,
1358 yyvalp
]b4_locuser_args
[);
1362 /* At present, doAction is never called in nondeterministic
1363 * mode, so this branch is never taken. It is here in
1364 * anticipation of a future feature that will allow immediate
1365 * evaluation of selected actions in nondeterministic mode. */
1368 yyGLRStackItem yyrhsVals
[YYMAXRHS
+ YYMAXLEFT
+ 1];
1369 yys
= yyrhsVals
[YYMAXRHS
+ YYMAXLEFT
].yystate
.yypred
1370 = yystackp
->yytops
.yystates
[yyk
];]b4_locations_if([[
1372 /* Set default location. */
1373 yyrhsVals
[YYMAXRHS
+ YYMAXLEFT
- 1].yystate
.yyloc
= yys
->yyloc
;]])[
1374 for (yyi
= 0; yyi
< yynrhs
; yyi
+= 1)
1379 yyupdateSplit (yystackp
, yys
);
1380 yystackp
->yytops
.yystates
[yyk
] = yys
;
1381 return yyuserAction (yyrule
, yynrhs
, yyrhsVals
+ YYMAXRHS
+ YYMAXLEFT
- 1,
1382 yystackp
, yyvalp
]b4_locuser_args
[);
1387 # define YY_REDUCE_PRINT(Args)
1389 # define YY_REDUCE_PRINT(Args) \
1392 yy_reduce_print Args; \
1395 /*----------------------------------------------------------.
1396 | Report that the RULE is going to be reduced on stack #K. |
1397 `----------------------------------------------------------*/
1399 /*ARGSUSED*/ static inline void
1400 yy_reduce_print (yyGLRStack
* yystackp
, size_t yyk
, yyRuleNum yyrule
,
1401 YYSTYPE
* yyvalp
]b4_locuser_formals
[)
1403 int yynrhs
= yyrhsLength (yyrule
);
1404 yybool yynormal
__attribute__ ((__unused__
)) =
1405 (yystackp
->yysplitPoint
== YY_NULL
);
1406 yyGLRStackItem
* yyvsp
= (yyGLRStackItem
*) yystackp
->yytops
.yystates
[yyk
];
1409 YYUSE (yyvalp
);]b4_locations_if([
1411 ]b4_parse_param_use
[]dnl
1412 [ YYFPRINTF (stderr
, "Reducing stack %lu by rule %d (line %lu):\n",
1413 (unsigned long int) yyk
, yyrule
- 1,
1414 (unsigned long int) yyrline
[yyrule
]);
1415 /* The symbols being reduced. */
1416 for (yyi
= 0; yyi
< yynrhs
; yyi
++)
1418 YYFPRINTF (stderr
, " $%d = ", yyi
+ 1);
1419 yy_symbol_print (stderr
, yyrhs
[yyprhs
[yyrule
] + yyi
],
1420 &]b4_rhs_value(yynrhs
, yyi
+ 1)[
1421 ]b4_locations_if([, &]b4_rhs_location(yynrhs
, yyi
+ 1))[]dnl
1423 YYFPRINTF (stderr
, "\n");
1428 /** Pop items off stack #K of STACK according to grammar rule RULE,
1429 * and push back on the resulting nonterminal symbol. Perform the
1430 * semantic action associated with RULE and store its value with the
1431 * newly pushed state, if FORCEEVAL or if STACK is currently
1432 * unambiguous. Otherwise, store the deferred semantic action with
1433 * the new state. If the new state would have an identical input
1434 * position, LR state, and predecessor to an existing state on the stack,
1435 * it is identified with that existing state, eliminating stack #K from
1436 * the STACK. In this case, the (necessarily deferred) semantic value is
1437 * added to the options for the existing state's semantic value.
1439 static inline YYRESULTTAG
1440 yyglrReduce (yyGLRStack
* yystackp
, size_t yyk
, yyRuleNum yyrule
,
1441 yybool yyforceEval
]b4_user_formals
[)
1443 size_t yyposn
= yystackp
->yytops
.yystates
[yyk
]->yyposn
;
1445 if (yyforceEval
|| yystackp
->yysplitPoint
== YY_NULL
)
1447 YYSTYPE yysval
;]b4_locations_if([
1450 YY_REDUCE_PRINT ((yystackp
, yyk
, yyrule
, &yysval
]b4_locuser_args([&yyloc
])[));
1451 YYCHK (yydoAction (yystackp
, yyk
, yyrule
, &yysval
]b4_locuser_args([&yyloc
])[));
1452 YY_SYMBOL_PRINT ("-> $$ =", yyr1
[yyrule
], &yysval
, &yyloc
);
1453 yyglrShift (yystackp
, yyk
,
1454 yyLRgotoState (yystackp
->yytops
.yystates
[yyk
]->yylrState
,
1455 yylhsNonterm (yyrule
)),
1456 yyposn
, &yysval
]b4_locations_if([, &yyloc
])[);
1462 yyGLRState
* yys
, *yys0
= yystackp
->yytops
.yystates
[yyk
];
1463 yyStateNum yynewLRState
;
1465 for (yys
= yystackp
->yytops
.yystates
[yyk
], yyn
= yyrhsLength (yyrule
);
1471 yyupdateSplit (yystackp
, yys
);
1472 yynewLRState
= yyLRgotoState (yys
->yylrState
, yylhsNonterm (yyrule
));
1474 "Reduced stack %lu by rule #%d; action deferred. Now in state %d.\n",
1475 (unsigned long int) yyk
, yyrule
- 1, yynewLRState
));
1476 for (yyi
= 0; yyi
< yystackp
->yytops
.yysize
; yyi
+= 1)
1477 if (yyi
!= yyk
&& yystackp
->yytops
.yystates
[yyi
] != YY_NULL
)
1479 yyGLRState
*yysplit
= yystackp
->yysplitPoint
;
1480 yyGLRState
*yyp
= yystackp
->yytops
.yystates
[yyi
];
1481 while (yyp
!= yys
&& yyp
!= yysplit
&& yyp
->yyposn
>= yyposn
)
1483 if (yyp
->yylrState
== yynewLRState
&& yyp
->yypred
== yys
)
1485 yyaddDeferredAction (yystackp
, yyk
, yyp
, yys0
, yyrule
);
1486 yymarkStackDeleted (yystackp
, yyk
);
1487 YYDPRINTF ((stderr
, "Merging stack %lu into stack %lu.\n",
1488 (unsigned long int) yyk
,
1489 (unsigned long int) yyi
));
1495 yystackp
->yytops
.yystates
[yyk
] = yys
;
1496 yyglrShiftDefer (yystackp
, yyk
, yynewLRState
, yyposn
, yys0
, yyrule
);
1502 yysplitStack (yyGLRStack
* yystackp
, size_t yyk
)
1504 if (yystackp
->yysplitPoint
== YY_NULL
)
1506 YYASSERT (yyk
== 0);
1507 yystackp
->yysplitPoint
= yystackp
->yytops
.yystates
[yyk
];
1509 if (yystackp
->yytops
.yysize
>= yystackp
->yytops
.yycapacity
)
1511 yyGLRState
** yynewStates
;
1512 yybool
* yynewLookaheadNeeds
;
1514 yynewStates
= YY_NULL
;
1516 if (yystackp
->yytops
.yycapacity
1517 > (YYSIZEMAX
/ (2 * sizeof yynewStates
[0])))
1518 yyMemoryExhausted (yystackp
);
1519 yystackp
->yytops
.yycapacity
*= 2;
1522 (yyGLRState
**) YYREALLOC (yystackp
->yytops
.yystates
,
1523 (yystackp
->yytops
.yycapacity
1524 * sizeof yynewStates
[0]));
1525 if (yynewStates
== YY_NULL
)
1526 yyMemoryExhausted (yystackp
);
1527 yystackp
->yytops
.yystates
= yynewStates
;
1529 yynewLookaheadNeeds
=
1530 (yybool
*) YYREALLOC (yystackp
->yytops
.yylookaheadNeeds
,
1531 (yystackp
->yytops
.yycapacity
1532 * sizeof yynewLookaheadNeeds
[0]));
1533 if (yynewLookaheadNeeds
== YY_NULL
)
1534 yyMemoryExhausted (yystackp
);
1535 yystackp
->yytops
.yylookaheadNeeds
= yynewLookaheadNeeds
;
1537 yystackp
->yytops
.yystates
[yystackp
->yytops
.yysize
]
1538 = yystackp
->yytops
.yystates
[yyk
];
1539 yystackp
->yytops
.yylookaheadNeeds
[yystackp
->yytops
.yysize
]
1540 = yystackp
->yytops
.yylookaheadNeeds
[yyk
];
1541 yystackp
->yytops
.yysize
+= 1;
1542 return yystackp
->yytops
.yysize
-1;
1545 /** True iff Y0 and Y1 represent identical options at the top level.
1546 * That is, they represent the same rule applied to RHS symbols
1547 * that produce the same terminal symbols. */
1549 yyidenticalOptions (yySemanticOption
* yyy0
, yySemanticOption
* yyy1
)
1551 if (yyy0
->yyrule
== yyy1
->yyrule
)
1553 yyGLRState
*yys0
, *yys1
;
1555 for (yys0
= yyy0
->yystate
, yys1
= yyy1
->yystate
,
1556 yyn
= yyrhsLength (yyy0
->yyrule
);
1558 yys0
= yys0
->yypred
, yys1
= yys1
->yypred
, yyn
-= 1)
1559 if (yys0
->yyposn
!= yys1
->yyposn
)
1567 /** Assuming identicalOptions (Y0,Y1), destructively merge the
1568 * alternative semantic values for the RHS-symbols of Y1 and Y0. */
1570 yymergeOptionSets (yySemanticOption
* yyy0
, yySemanticOption
* yyy1
)
1572 yyGLRState
*yys0
, *yys1
;
1574 for (yys0
= yyy0
->yystate
, yys1
= yyy1
->yystate
,
1575 yyn
= yyrhsLength (yyy0
->yyrule
);
1577 yys0
= yys0
->yypred
, yys1
= yys1
->yypred
, yyn
-= 1)
1581 else if (yys0
->yyresolved
)
1583 yys1
->yyresolved
= yytrue
;
1584 yys1
->yysemantics
.yysval
= yys0
->yysemantics
.yysval
;
1586 else if (yys1
->yyresolved
)
1588 yys0
->yyresolved
= yytrue
;
1589 yys0
->yysemantics
.yysval
= yys1
->yysemantics
.yysval
;
1593 yySemanticOption
** yyz0p
= &yys0
->yysemantics
.yyfirstVal
;
1594 yySemanticOption
* yyz1
= yys1
->yysemantics
.yyfirstVal
;
1595 while (YYID (yytrue
))
1597 if (yyz1
== *yyz0p
|| yyz1
== YY_NULL
)
1599 else if (*yyz0p
== YY_NULL
)
1604 else if (*yyz0p
< yyz1
)
1606 yySemanticOption
* yyz
= *yyz0p
;
1608 yyz1
= yyz1
->yynext
;
1609 (*yyz0p
)->yynext
= yyz
;
1611 yyz0p
= &(*yyz0p
)->yynext
;
1613 yys1
->yysemantics
.yyfirstVal
= yys0
->yysemantics
.yyfirstVal
;
1618 /** Y0 and Y1 represent two possible actions to take in a given
1619 * parsing state; return 0 if no combination is possible,
1620 * 1 if user-mergeable, 2 if Y0 is preferred, 3 if Y1 is preferred. */
1622 yypreference (yySemanticOption
* y0
, yySemanticOption
* y1
)
1624 yyRuleNum r0
= y0
->yyrule
, r1
= y1
->yyrule
;
1625 int p0
= yydprec
[r0
], p1
= yydprec
[r1
];
1629 if (yymerger
[r0
] == 0 || yymerger
[r0
] != yymerger
[r1
])
1634 if (p0
== 0 || p1
== 0)
1643 static YYRESULTTAG
yyresolveValue (yyGLRState
* yys
,
1644 yyGLRStack
* yystackp
]b4_user_formals
[);
1647 /** Resolve the previous N states starting at and including state S. If result
1648 * != yyok, some states may have been left unresolved possibly with empty
1649 * semantic option chains. Regardless of whether result = yyok, each state
1650 * has been left with consistent data so that yydestroyGLRState can be invoked
1653 yyresolveStates (yyGLRState
* yys
, int yyn
,
1654 yyGLRStack
* yystackp
]b4_user_formals
[)
1658 YYASSERT (yys
->yypred
);
1659 YYCHK (yyresolveStates (yys
->yypred
, yyn
-1, yystackp
]b4_user_args
[));
1660 if (! yys
->yyresolved
)
1661 YYCHK (yyresolveValue (yys
, yystackp
]b4_user_args
[));
1666 /** Resolve the states for the RHS of OPT, perform its user action, and return
1667 * the semantic value and location. Regardless of whether result = yyok, all
1668 * RHS states have been destroyed (assuming the user action destroys all RHS
1669 * semantic values if invoked). */
1671 yyresolveAction (yySemanticOption
* yyopt
, yyGLRStack
* yystackp
,
1672 YYSTYPE
* yyvalp
]b4_locuser_formals
[)
1674 yyGLRStackItem yyrhsVals
[YYMAXRHS
+ YYMAXLEFT
+ 1];
1675 int yynrhs
= yyrhsLength (yyopt
->yyrule
);
1676 YYRESULTTAG yyflag
=
1677 yyresolveStates (yyopt
->yystate
, yynrhs
, yystackp
]b4_user_args
[);
1681 for (yys
= yyopt
->yystate
; yynrhs
> 0; yys
= yys
->yypred
, yynrhs
-= 1)
1682 yydestroyGLRState ("Cleanup: popping", yys
]b4_user_args
[);
1686 yyrhsVals
[YYMAXRHS
+ YYMAXLEFT
].yystate
.yypred
= yyopt
->yystate
;]b4_locations_if([[
1688 /* Set default location. */
1689 yyrhsVals
[YYMAXRHS
+ YYMAXLEFT
- 1].yystate
.yyloc
= yyopt
->yystate
->yyloc
;]])[
1691 int yychar_current
= yychar
;
1692 YYSTYPE yylval_current
= yylval
;]b4_locations_if([
1693 YYLTYPE yylloc_current
= yylloc
;])[
1694 yychar
= yyopt
->yyrawchar
;
1695 yylval
= yyopt
->yyval
;]b4_locations_if([
1696 yylloc
= yyopt
->yyloc
;])[
1697 yyflag
= yyuserAction (yyopt
->yyrule
, yynrhs
,
1698 yyrhsVals
+ YYMAXRHS
+ YYMAXLEFT
- 1,
1699 yystackp
, yyvalp
]b4_locuser_args
[);
1700 yychar
= yychar_current
;
1701 yylval
= yylval_current
;]b4_locations_if([
1702 yylloc
= yylloc_current
;])[
1709 yyreportTree (yySemanticOption
* yyx
, int yyindent
)
1711 int yynrhs
= yyrhsLength (yyx
->yyrule
);
1714 yyGLRState
* yystates
[1 + YYMAXRHS
];
1715 yyGLRState yyleftmost_state
;
1717 for (yyi
= yynrhs
, yys
= yyx
->yystate
; 0 < yyi
; yyi
-= 1, yys
= yys
->yypred
)
1718 yystates
[yyi
] = yys
;
1721 yyleftmost_state
.yyposn
= 0;
1722 yystates
[0] = &yyleftmost_state
;
1727 if (yyx
->yystate
->yyposn
< yys
->yyposn
+ 1)
1728 YYFPRINTF (stderr
, "%*s%s -> <Rule %d, empty>\n",
1729 yyindent
, "", yytokenName (yylhsNonterm (yyx
->yyrule
)),
1732 YYFPRINTF (stderr
, "%*s%s -> <Rule %d, tokens %lu .. %lu>\n",
1733 yyindent
, "", yytokenName (yylhsNonterm (yyx
->yyrule
)),
1734 yyx
->yyrule
- 1, (unsigned long int) (yys
->yyposn
+ 1),
1735 (unsigned long int) yyx
->yystate
->yyposn
);
1736 for (yyi
= 1; yyi
<= yynrhs
; yyi
+= 1)
1738 if (yystates
[yyi
]->yyresolved
)
1740 if (yystates
[yyi
-1]->yyposn
+1 > yystates
[yyi
]->yyposn
)
1741 YYFPRINTF (stderr
, "%*s%s <empty>\n", yyindent
+2, "",
1742 yytokenName (yyrhs
[yyprhs
[yyx
->yyrule
]+yyi
-1]));
1744 YYFPRINTF (stderr
, "%*s%s <tokens %lu .. %lu>\n", yyindent
+2, "",
1745 yytokenName (yyrhs
[yyprhs
[yyx
->yyrule
]+yyi
-1]),
1746 (unsigned long int) (yystates
[yyi
- 1]->yyposn
+ 1),
1747 (unsigned long int) yystates
[yyi
]->yyposn
);
1750 yyreportTree (yystates
[yyi
]->yysemantics
.yyfirstVal
, yyindent
+2);
1755 /*ARGSUSED*/ static YYRESULTTAG
1756 yyreportAmbiguity (yySemanticOption
* yyx0
,
1757 yySemanticOption
* yyx1
]b4_pure_formals
[)
1763 YYFPRINTF (stderr
, "Ambiguity detected.\n");
1764 YYFPRINTF (stderr
, "Option 1,\n");
1765 yyreportTree (yyx0
, 2);
1766 YYFPRINTF (stderr
, "\nOption 2,\n");
1767 yyreportTree (yyx1
, 2);
1768 YYFPRINTF (stderr
, "\n");
1771 yyerror (]b4_yyerror_args
[YY_("syntax is ambiguous"));
1773 }]b4_locations_if([[
1775 /** Starting at and including state S1, resolve the location for each of the
1776 * previous N1 states that is unresolved. The first semantic option of a state
1777 * is always chosen. */
1779 yyresolveLocations (yyGLRState
* yys1
, int yyn1
,
1780 yyGLRStack
*yystackp
]b4_user_formals
[)
1784 yyresolveLocations (yys1
->yypred
, yyn1
- 1, yystackp
]b4_user_args
[);
1785 if (!yys1
->yyresolved
)
1787 yyGLRStackItem yyrhsloc
[1 + YYMAXRHS
];
1789 yySemanticOption
*yyoption
= yys1
->yysemantics
.yyfirstVal
;
1790 YYASSERT (yyoption
!= YY_NULL
);
1791 yynrhs
= yyrhsLength (yyoption
->yyrule
);
1796 yyresolveLocations (yyoption
->yystate
, yynrhs
,
1797 yystackp
]b4_user_args
[);
1798 for (yys
= yyoption
->yystate
, yyn
= yynrhs
;
1800 yys
= yys
->yypred
, yyn
-= 1)
1801 yyrhsloc
[yyn
].yystate
.yyloc
= yys
->yyloc
;
1805 /* Both yyresolveAction and yyresolveLocations traverse the GSS
1806 in reverse rightmost order. It is only necessary to invoke
1807 yyresolveLocations on a subforest for which yyresolveAction
1808 would have been invoked next had an ambiguity not been
1809 detected. Thus the location of the previous state (but not
1810 necessarily the previous state itself) is guaranteed to be
1811 resolved already. */
1812 yyGLRState
*yyprevious
= yyoption
->yystate
;
1813 yyrhsloc
[0].yystate
.yyloc
= yyprevious
->yyloc
;
1816 int yychar_current
= yychar
;
1817 YYSTYPE yylval_current
= yylval
;
1818 YYLTYPE yylloc_current
= yylloc
;
1819 yychar
= yyoption
->yyrawchar
;
1820 yylval
= yyoption
->yyval
;
1821 yylloc
= yyoption
->yyloc
;
1822 YYLLOC_DEFAULT ((yys1
->yyloc
), yyrhsloc
, yynrhs
);
1823 yychar
= yychar_current
;
1824 yylval
= yylval_current
;
1825 yylloc
= yylloc_current
;
1831 /** Resolve the ambiguity represented in state S, perform the indicated
1832 * actions, and set the semantic value of S. If result != yyok, the chain of
1833 * semantic options in S has been cleared instead or it has been left
1834 * unmodified except that redundant options may have been removed. Regardless
1835 * of whether result = yyok, S has been left with consistent data so that
1836 * yydestroyGLRState can be invoked if necessary. */
1838 yyresolveValue (yyGLRState
* yys
, yyGLRStack
* yystackp
]b4_user_formals
[)
1840 yySemanticOption
* yyoptionList
= yys
->yysemantics
.yyfirstVal
;
1841 yySemanticOption
* yybest
= yyoptionList
;
1842 yySemanticOption
** yypp
;
1843 yybool yymerge
= yyfalse
;
1845 YYRESULTTAG yyflag
;]b4_locations_if([
1846 YYLTYPE
*yylocp
= &yys
->yyloc
;])[
1848 for (yypp
= &yyoptionList
->yynext
; *yypp
!= YY_NULL
; )
1850 yySemanticOption
* yyp
= *yypp
;
1852 if (yyidenticalOptions (yybest
, yyp
))
1854 yymergeOptionSets (yybest
, yyp
);
1855 *yypp
= yyp
->yynext
;
1859 switch (yypreference (yybest
, yyp
))
1861 case 0:]b4_locations_if([[
1862 yyresolveLocations (yys
, 1, yystackp
]b4_user_args
[);]])[
1863 return yyreportAmbiguity (yybest
, yyp
]b4_pure_args
[);
1875 /* This cannot happen so it is not worth a YYASSERT (yyfalse),
1876 but some compilers complain if the default case is
1880 yypp
= &yyp
->yynext
;
1886 yySemanticOption
* yyp
;
1887 int yyprec
= yydprec
[yybest
->yyrule
];
1888 yyflag
= yyresolveAction (yybest
, yystackp
, &yysval
]b4_locuser_args
[);
1890 for (yyp
= yybest
->yynext
; yyp
!= YY_NULL
; yyp
= yyp
->yynext
)
1892 if (yyprec
== yydprec
[yyp
->yyrule
])
1894 YYSTYPE yysval_other
;]b4_locations_if([
1896 yyflag
= yyresolveAction (yyp
, yystackp
, &yysval_other
]b4_locuser_args([&yydummy
])[);
1899 yydestruct ("Cleanup: discarding incompletely merged value for",
1900 yystos
[yys
->yylrState
],
1901 &yysval
]b4_locuser_args
[);
1904 yyuserMerge (yymerger
[yyp
->yyrule
], &yysval
, &yysval_other
);
1909 yyflag
= yyresolveAction (yybest
, yystackp
, &yysval
]b4_locuser_args([yylocp
])[);
1913 yys
->yyresolved
= yytrue
;
1914 yys
->yysemantics
.yysval
= yysval
;
1917 yys
->yysemantics
.yyfirstVal
= YY_NULL
;
1922 yyresolveStack (yyGLRStack
* yystackp
]b4_user_formals
[)
1924 if (yystackp
->yysplitPoint
!= YY_NULL
)
1929 for (yyn
= 0, yys
= yystackp
->yytops
.yystates
[0];
1930 yys
!= yystackp
->yysplitPoint
;
1931 yys
= yys
->yypred
, yyn
+= 1)
1933 YYCHK (yyresolveStates (yystackp
->yytops
.yystates
[0], yyn
, yystackp
1940 yycompressStack (yyGLRStack
* yystackp
)
1942 yyGLRState
* yyp
, *yyq
, *yyr
;
1944 if (yystackp
->yytops
.yysize
!= 1 || yystackp
->yysplitPoint
== YY_NULL
)
1947 for (yyp
= yystackp
->yytops
.yystates
[0], yyq
= yyp
->yypred
, yyr
= YY_NULL
;
1948 yyp
!= yystackp
->yysplitPoint
;
1949 yyr
= yyp
, yyp
= yyq
, yyq
= yyp
->yypred
)
1952 yystackp
->yyspaceLeft
+= yystackp
->yynextFree
- yystackp
->yyitems
;
1953 yystackp
->yynextFree
= ((yyGLRStackItem
*) yystackp
->yysplitPoint
) + 1;
1954 yystackp
->yyspaceLeft
-= yystackp
->yynextFree
- yystackp
->yyitems
;
1955 yystackp
->yysplitPoint
= YY_NULL
;
1956 yystackp
->yylastDeleted
= YY_NULL
;
1958 while (yyr
!= YY_NULL
)
1960 yystackp
->yynextFree
->yystate
= *yyr
;
1962 yystackp
->yynextFree
->yystate
.yypred
= &yystackp
->yynextFree
[-1].yystate
;
1963 yystackp
->yytops
.yystates
[0] = &yystackp
->yynextFree
->yystate
;
1964 yystackp
->yynextFree
+= 1;
1965 yystackp
->yyspaceLeft
-= 1;
1970 yyprocessOneStack (yyGLRStack
* yystackp
, size_t yyk
,
1971 size_t yyposn
]b4_pure_formals
[)
1974 const short int* yyconflicts
;
1977 while (yystackp
->yytops
.yystates
[yyk
] != YY_NULL
)
1979 yyStateNum yystate
= yystackp
->yytops
.yystates
[yyk
]->yylrState
;
1980 YYDPRINTF ((stderr
, "Stack %lu Entering state %d\n",
1981 (unsigned long int) yyk
, yystate
));
1983 YYASSERT (yystate
!= YYFINAL
);
1985 if (yyisDefaultedState (yystate
))
1987 yyrule
= yydefaultAction (yystate
);
1990 YYDPRINTF ((stderr
, "Stack %lu dies.\n",
1991 (unsigned long int) yyk
));
1992 yymarkStackDeleted (yystackp
, yyk
);
1995 YYCHK (yyglrReduce (yystackp
, yyk
, yyrule
, yyfalse
]b4_user_args
[));
2000 yystackp
->yytops
.yylookaheadNeeds
[yyk
] = yytrue
;
2001 if (yychar
== YYEMPTY
)
2003 YYDPRINTF ((stderr
, "Reading a token: "));
2007 if (yychar
<= YYEOF
)
2009 yychar
= yytoken
= YYEOF
;
2010 YYDPRINTF ((stderr
, "Now at end of input.\n"));
2014 yytoken
= YYTRANSLATE (yychar
);
2015 YY_SYMBOL_PRINT ("Next token is", yytoken
, &yylval
, &yylloc
);
2018 yygetLRActions (yystate
, yytoken
, &yyaction
, &yyconflicts
);
2020 while (*yyconflicts
!= 0)
2022 size_t yynewStack
= yysplitStack (yystackp
, yyk
);
2023 YYDPRINTF ((stderr
, "Splitting off stack %lu from %lu.\n",
2024 (unsigned long int) yynewStack
,
2025 (unsigned long int) yyk
));
2026 YYCHK (yyglrReduce (yystackp
, yynewStack
,
2027 *yyconflicts
, yyfalse
]b4_user_args
[));
2028 YYCHK (yyprocessOneStack (yystackp
, yynewStack
,
2029 yyposn
]b4_pure_args
[));
2033 if (yyisShiftAction (yyaction
))
2035 else if (yyisErrorAction (yyaction
))
2037 YYDPRINTF ((stderr
, "Stack %lu dies.\n",
2038 (unsigned long int) yyk
));
2039 yymarkStackDeleted (yystackp
, yyk
);
2043 YYCHK (yyglrReduce (yystackp
, yyk
, -yyaction
,
2044 yyfalse
]b4_user_args
[));
2050 /*ARGSUSED*/ static void
2051 yyreportSyntaxError (yyGLRStack
* yystackp
]b4_user_formals
[)
2053 if (yystackp
->yyerrState
!= 0)
2055 #if ! YYERROR_VERBOSE
2056 yyerror (]b4_lyyerror_args
[YY_("syntax error"));
2058 yySymbol yytoken
= yychar
== YYEMPTY
? YYEMPTY
: YYTRANSLATE (yychar
);
2059 size_t yysize0
= yytnamerr (YY_NULL
, yytokenName (yytoken
));
2060 size_t yysize
= yysize0
;
2062 yybool yysize_overflow
= yyfalse
;
2063 char* yymsg
= YY_NULL
;
2064 enum { YYERROR_VERBOSE_ARGS_MAXIMUM
= 5 };
2065 /* Internationalized format string. */
2066 const char *yyformat
= YY_NULL
;
2067 /* Arguments of yyformat. */
2068 char const *yyarg
[YYERROR_VERBOSE_ARGS_MAXIMUM
];
2069 /* Number of reported tokens (one for the "unexpected", one per
2073 /* There are many possibilities here to consider:
2074 - If this state is a consistent state with a default action, then
2075 the only way this function was invoked is if the default action
2076 is an error action. In that case, don't check for expected
2077 tokens because there are none.
2078 - The only way there can be no lookahead present (in yychar) is if
2079 this state is a consistent state with a default action. Thus,
2080 detecting the absence of a lookahead is sufficient to determine
2081 that there is no unexpected or expected token to report. In that
2082 case, just report a simple "syntax error".
2083 - Don't assume there isn't a lookahead just because this state is a
2084 consistent state with a default action. There might have been a
2085 previous inconsistent state, consistent state with a non-default
2086 action, or user semantic action that manipulated yychar.
2087 - Of course, the expected token list depends on states to have
2088 correct lookahead information, and it depends on the parser not
2089 to perform extra reductions after fetching a lookahead from the
2090 scanner and before detecting a syntax error. Thus, state merging
2091 (from LALR or IELR) and default reductions corrupt the expected
2092 token list. However, the list is correct for canonical LR with
2093 one exception: it will still contain any token that will not be
2094 accepted due to an error action in a later state.
2096 if (yytoken
!= YYEMPTY
)
2098 int yyn
= yypact
[yystackp
->yytops
.yystates
[0]->yylrState
];
2099 yyarg
[yycount
++] = yytokenName (yytoken
);
2100 if (!yypact_value_is_default (yyn
))
2102 /* Start YYX at -YYN if negative to avoid negative indexes in
2103 YYCHECK. In other words, skip the first -YYN actions for this
2104 state because they are default actions. */
2105 int yyxbegin
= yyn
< 0 ? -yyn
: 0;
2106 /* Stay within bounds of both yycheck and yytname. */
2107 int yychecklim
= YYLAST
- yyn
+ 1;
2108 int yyxend
= yychecklim
< YYNTOKENS
? yychecklim
: YYNTOKENS
;
2110 for (yyx
= yyxbegin
; yyx
< yyxend
; ++yyx
)
2111 if (yycheck
[yyx
+ yyn
] == yyx
&& yyx
!= YYTERROR
2112 && !yytable_value_is_error (yytable
[yyx
+ yyn
]))
2114 if (yycount
== YYERROR_VERBOSE_ARGS_MAXIMUM
)
2120 yyarg
[yycount
++] = yytokenName (yyx
);
2121 yysize1
= yysize
+ yytnamerr (YY_NULL
, yytokenName (yyx
));
2122 yysize_overflow
|= yysize1
< yysize
;
2130 #define YYCASE_(N, S) \
2134 YYCASE_(0, YY_("syntax error"));
2135 YYCASE_(1, YY_("syntax error, unexpected %s"));
2136 YYCASE_(2, YY_("syntax error, unexpected %s, expecting %s"));
2137 YYCASE_(3, YY_("syntax error, unexpected %s, expecting %s or %s"));
2138 YYCASE_(4, YY_("syntax error, unexpected %s, expecting %s or %s or %s"));
2139 YYCASE_(5, YY_("syntax error, unexpected %s, expecting %s or %s or %s or %s"));
2143 yysize1
= yysize
+ strlen (yyformat
);
2144 yysize_overflow
|= yysize1
< yysize
;
2147 if (!yysize_overflow
)
2148 yymsg
= (char *) YYMALLOC (yysize
);
2154 while ((*yyp
= *yyformat
))
2156 if (*yyp
== '%' && yyformat
[1] == 's' && yyi
< yycount
)
2158 yyp
+= yytnamerr (yyp
, yyarg
[yyi
++]);
2167 yyerror (]b4_lyyerror_args
[yymsg
);
2172 yyerror (]b4_lyyerror_args
[YY_("syntax error"));
2173 yyMemoryExhausted (yystackp
);
2175 #endif /* YYERROR_VERBOSE */
2179 /* Recover from a syntax error on *YYSTACKP, assuming that *YYSTACKP->YYTOKENP,
2180 yylval, and yylloc are the syntactic category, semantic value, and location
2181 of the lookahead. */
2182 /*ARGSUSED*/ static void
2183 yyrecoverSyntaxError (yyGLRStack
* yystackp
]b4_user_formals
[)
2188 if (yystackp
->yyerrState
== 3)
2189 /* We just shifted the error token and (perhaps) took some
2190 reductions. Skip tokens until we can proceed. */
2191 while (YYID (yytrue
))
2194 if (yychar
== YYEOF
)
2195 yyFail (yystackp
][]b4_lpure_args
[, YY_NULL
);
2196 if (yychar
!= YYEMPTY
)
2197 {]b4_locations_if([[
2198 /* We throw away the lookahead, but the error range
2199 of the shifted error token must take it into account. */
2200 yyGLRState
*yys
= yystackp
->yytops
.yystates
[0];
2201 yyGLRStackItem yyerror_range
[3];
2202 yyerror_range
[1].yystate
.yyloc
= yys
->yyloc
;
2203 yyerror_range
[2].yystate
.yyloc
= yylloc
;
2204 YYLLOC_DEFAULT ((yys
->yyloc
), yyerror_range
, 2);]])[
2205 yytoken
= YYTRANSLATE (yychar
);
2206 yydestruct ("Error: discarding",
2207 yytoken
, &yylval
]b4_locuser_args([&yylloc
])[);
2209 YYDPRINTF ((stderr
, "Reading a token: "));
2211 if (yychar
<= YYEOF
)
2213 yychar
= yytoken
= YYEOF
;
2214 YYDPRINTF ((stderr
, "Now at end of input.\n"));
2218 yytoken
= YYTRANSLATE (yychar
);
2219 YY_SYMBOL_PRINT ("Next token is", yytoken
, &yylval
, &yylloc
);
2221 yyj
= yypact
[yystackp
->yytops
.yystates
[0]->yylrState
];
2222 if (yypact_value_is_default (yyj
))
2225 if (yyj
< 0 || YYLAST
< yyj
|| yycheck
[yyj
] != yytoken
)
2227 if (yydefact
[yystackp
->yytops
.yystates
[0]->yylrState
] != 0)
2230 else if (! yytable_value_is_error (yytable
[yyj
]))
2234 /* Reduce to one stack. */
2235 for (yyk
= 0; yyk
< yystackp
->yytops
.yysize
; yyk
+= 1)
2236 if (yystackp
->yytops
.yystates
[yyk
] != YY_NULL
)
2238 if (yyk
>= yystackp
->yytops
.yysize
)
2239 yyFail (yystackp
][]b4_lpure_args
[, YY_NULL
);
2240 for (yyk
+= 1; yyk
< yystackp
->yytops
.yysize
; yyk
+= 1)
2241 yymarkStackDeleted (yystackp
, yyk
);
2242 yyremoveDeletes (yystackp
);
2243 yycompressStack (yystackp
);
2245 /* Now pop stack until we find a state that shifts the error token. */
2246 yystackp
->yyerrState
= 3;
2247 while (yystackp
->yytops
.yystates
[0] != YY_NULL
)
2249 yyGLRState
*yys
= yystackp
->yytops
.yystates
[0];
2250 yyj
= yypact
[yys
->yylrState
];
2251 if (! yypact_value_is_default (yyj
))
2254 if (0 <= yyj
&& yyj
<= YYLAST
&& yycheck
[yyj
] == YYTERROR
2255 && yyisShiftAction (yytable
[yyj
]))
2257 /* Shift the error token. */]b4_locations_if([[
2258 /* First adjust its location.*/
2260 yystackp
->yyerror_range
[2].yystate
.yyloc
= yylloc
;
2261 YYLLOC_DEFAULT (yyerrloc
, (yystackp
->yyerror_range
), 2);]])[
2262 YY_SYMBOL_PRINT ("Shifting", yystos
[yytable
[yyj
]],
2263 &yylval
, &yyerrloc
);
2264 yyglrShift (yystackp
, 0, yytable
[yyj
],
2265 yys
->yyposn
, &yylval
]b4_locations_if([, &yyerrloc
])[);
2266 yys
= yystackp
->yytops
.yystates
[0];
2269 }]b4_locations_if([[
2270 yystackp
->yyerror_range
[1].yystate
.yyloc
= yys
->yyloc
;]])[
2271 if (yys
->yypred
!= YY_NULL
)
2272 yydestroyGLRState ("Error: popping", yys
]b4_user_args
[);
2273 yystackp
->yytops
.yystates
[0] = yys
->yypred
;
2274 yystackp
->yynextFree
-= 1;
2275 yystackp
->yyspaceLeft
+= 1;
2277 if (yystackp
->yytops
.yystates
[0] == YY_NULL
)
2278 yyFail (yystackp
][]b4_lpure_args
[, YY_NULL
);
2281 #define YYCHK1(YYE) \
2291 goto yyuser_error; \
2302 ]b4_c_ansi_function_def([yyparse
], [int], b4_parse_param
)[
2306 yyGLRStack
* const yystackp
= &yystack
;
2309 YYDPRINTF ((stderr
, "Starting parse\n"));
2312 yylval
= yyval_default
;
2314 #if defined YYLTYPE_IS_TRIVIAL && YYLTYPE_IS_TRIVIAL
2315 yylloc
.first_line
= yylloc
.last_line
= ]b4_location_initial_line
[;
2316 yylloc
.first_column
= yylloc
.last_column
= ]b4_location_initial_column
[;
2319 m4_ifdef([b4_initial_action
], [
2320 m4_pushdef([b4_at_dollar
], [yylloc
])dnl
2321 m4_pushdef([b4_dollar_dollar
], [yylval
])dnl
2322 /* User initialization code. */
2323 b4_user_initial_action
2324 m4_popdef([b4_dollar_dollar
])dnl
2325 m4_popdef([b4_at_dollar
])])dnl
2327 if (! yyinitGLRStack (yystackp
, YYINITDEPTH
))
2328 goto yyexhaustedlab
;
2329 switch (YYSETJMP (yystack
.yyexception_buffer
))
2332 case 1: goto yyabortlab
;
2333 case 2: goto yyexhaustedlab
;
2334 default: goto yybuglab
;
2336 yyglrShift (&yystack
, 0, 0, 0, &yylval
]b4_locations_if([, &yylloc
])[);
2339 while (YYID (yytrue
))
2341 /* For efficiency, we have two loops, the first of which is
2342 specialized to deterministic operation (single stack, no
2343 potential ambiguity). */
2345 while (YYID (yytrue
))
2349 const short int* yyconflicts
;
2351 yyStateNum yystate
= yystack
.yytops
.yystates
[0]->yylrState
;
2352 YYDPRINTF ((stderr
, "Entering state %d\n", yystate
));
2353 if (yystate
== YYFINAL
)
2355 if (yyisDefaultedState (yystate
))
2357 yyrule
= yydefaultAction (yystate
);
2360 ]b4_locations_if([[ yystack
.yyerror_range
[1].yystate
.yyloc
= yylloc
;]])[
2361 yyreportSyntaxError (&yystack
]b4_user_args
[);
2364 YYCHK1 (yyglrReduce (&yystack
, 0, yyrule
, yytrue
]b4_user_args
[));
2369 if (yychar
== YYEMPTY
)
2371 YYDPRINTF ((stderr
, "Reading a token: "));
2375 if (yychar
<= YYEOF
)
2377 yychar
= yytoken
= YYEOF
;
2378 YYDPRINTF ((stderr
, "Now at end of input.\n"));
2382 yytoken
= YYTRANSLATE (yychar
);
2383 YY_SYMBOL_PRINT ("Next token is", yytoken
, &yylval
, &yylloc
);
2386 yygetLRActions (yystate
, yytoken
, &yyaction
, &yyconflicts
);
2387 if (*yyconflicts
!= 0)
2389 if (yyisShiftAction (yyaction
))
2391 YY_SYMBOL_PRINT ("Shifting", yytoken
, &yylval
, &yylloc
);
2394 yyglrShift (&yystack
, 0, yyaction
, yyposn
, &yylval
]b4_locations_if([, &yylloc
])[);
2395 if (0 < yystack
.yyerrState
)
2396 yystack
.yyerrState
-= 1;
2398 else if (yyisErrorAction (yyaction
))
2400 ]b4_locations_if([[ yystack
.yyerror_range
[1].yystate
.yyloc
= yylloc
;]])[
2401 yyreportSyntaxError (&yystack
]b4_user_args
[);
2405 YYCHK1 (yyglrReduce (&yystack
, 0, -yyaction
, yytrue
]b4_user_args
[));
2409 while (YYID (yytrue
))
2411 yySymbol yytoken_to_shift
;
2414 for (yys
= 0; yys
< yystack
.yytops
.yysize
; yys
+= 1)
2415 yystackp
->yytops
.yylookaheadNeeds
[yys
] = yychar
!= YYEMPTY
;
2417 /* yyprocessOneStack returns one of three things:
2419 - An error flag. If the caller is yyprocessOneStack, it
2420 immediately returns as well. When the caller is finally
2421 yyparse, it jumps to an error label via YYCHK1.
2423 - yyok, but yyprocessOneStack has invoked yymarkStackDeleted
2424 (&yystack, yys), which sets the top state of yys to NULL. Thus,
2425 yyparse's following invocation of yyremoveDeletes will remove
2428 - yyok, when ready to shift a token.
2430 Except in the first case, yyparse will invoke yyremoveDeletes and
2431 then shift the next token onto all remaining stacks. This
2432 synchronization of the shift (that is, after all preceding
2433 reductions on all stacks) helps prevent double destructor calls
2434 on yylval in the event of memory exhaustion. */
2436 for (yys
= 0; yys
< yystack
.yytops
.yysize
; yys
+= 1)
2437 YYCHK1 (yyprocessOneStack (&yystack
, yys
, yyposn
]b4_lpure_args
[));
2438 yyremoveDeletes (&yystack
);
2439 if (yystack
.yytops
.yysize
== 0)
2441 yyundeleteLastStack (&yystack
);
2442 if (yystack
.yytops
.yysize
== 0)
2443 yyFail (&yystack
][]b4_lpure_args
[, YY_("syntax error"));
2444 YYCHK1 (yyresolveStack (&yystack
]b4_user_args
[));
2445 YYDPRINTF ((stderr
, "Returning to deterministic operation.\n"));
2446 ]b4_locations_if([[ yystack
.yyerror_range
[1].yystate
.yyloc
= yylloc
;]])[
2447 yyreportSyntaxError (&yystack
]b4_user_args
[);
2451 /* If any yyglrShift call fails, it will fail after shifting. Thus,
2452 a copy of yylval will already be on stack 0 in the event of a
2453 failure in the following loop. Thus, yychar is set to YYEMPTY
2454 before the loop to make sure the user destructor for yylval isn't
2456 yytoken_to_shift
= YYTRANSLATE (yychar
);
2459 for (yys
= 0; yys
< yystack
.yytops
.yysize
; yys
+= 1)
2462 const short int* yyconflicts
;
2463 yyStateNum yystate
= yystack
.yytops
.yystates
[yys
]->yylrState
;
2464 yygetLRActions (yystate
, yytoken_to_shift
, &yyaction
,
2466 /* Note that yyconflicts were handled by yyprocessOneStack. */
2467 YYDPRINTF ((stderr
, "On stack %lu, ", (unsigned long int) yys
));
2468 YY_SYMBOL_PRINT ("shifting", yytoken_to_shift
, &yylval
, &yylloc
);
2469 yyglrShift (&yystack
, yys
, yyaction
, yyposn
,
2470 &yylval
]b4_locations_if([, &yylloc
])[);
2471 YYDPRINTF ((stderr
, "Stack %lu now in state #%d\n",
2472 (unsigned long int) yys
,
2473 yystack
.yytops
.yystates
[yys
]->yylrState
));
2476 if (yystack
.yytops
.yysize
== 1)
2478 YYCHK1 (yyresolveStack (&yystack
]b4_user_args
[));
2479 YYDPRINTF ((stderr
, "Returning to deterministic operation.\n"));
2480 yycompressStack (&yystack
);
2486 yyrecoverSyntaxError (&yystack
]b4_user_args
[);
2487 yyposn
= yystack
.yytops
.yystates
[0]->yyposn
;
2503 yyerror (]b4_lyyerror_args
[YY_("memory exhausted"));
2508 if (yychar
!= YYEMPTY
)
2509 yydestruct ("Cleanup: discarding lookahead",
2510 YYTRANSLATE (yychar
), &yylval
]b4_locuser_args([&yylloc
])[);
2512 /* If the stack is well-formed, pop the stack until it is empty,
2513 destroying its entries as we go. But free the stack regardless
2514 of whether it is well-formed. */
2515 if (yystack
.yyitems
)
2517 yyGLRState
** yystates
= yystack
.yytops
.yystates
;
2520 size_t yysize
= yystack
.yytops
.yysize
;
2522 for (yyk
= 0; yyk
< yysize
; yyk
+= 1)
2525 while (yystates
[yyk
])
2527 yyGLRState
*yys
= yystates
[yyk
];
2528 ]b4_locations_if([[ yystack
.yyerror_range
[1].yystate
.yyloc
= yys
->yyloc
;]]
2529 )[ if (yys
->yypred
!= YY_NULL
)
2530 yydestroyGLRState ("Cleanup: popping", yys
]b4_user_args
[);
2531 yystates
[yyk
] = yys
->yypred
;
2532 yystack
.yynextFree
-= 1;
2533 yystack
.yyspaceLeft
+= 1;
2538 yyfreeGLRStack (&yystack
);
2541 /* Make sure YYID is used. */
2542 return YYID (yyresult
);
2545 /* DEBUGGING ONLY */
2547 static void yypstack (yyGLRStack
* yystackp
, size_t yyk
)
2548 __attribute__ ((__unused__
));
2549 static void yypdumpstack (yyGLRStack
* yystackp
) __attribute__ ((__unused__
));
2552 yy_yypstack (yyGLRState
* yys
)
2556 yy_yypstack (yys
->yypred
);
2557 YYFPRINTF (stderr
, " -> ");
2559 YYFPRINTF (stderr
, "%d@@%lu", yys
->yylrState
,
2560 (unsigned long int) yys
->yyposn
);
2564 yypstates (yyGLRState
* yyst
)
2566 if (yyst
== YY_NULL
)
2567 YYFPRINTF (stderr
, "<null>");
2570 YYFPRINTF (stderr
, "\n");
2574 yypstack (yyGLRStack
* yystackp
, size_t yyk
)
2576 yypstates (yystackp
->yytops
.yystates
[yyk
]);
2579 #define YYINDEX(YYX) \
2580 ((YYX) == YY_NULL ? -1 : (yyGLRStackItem*) (YYX) - yystackp->yyitems)
2584 yypdumpstack (yyGLRStack
* yystackp
)
2586 yyGLRStackItem
* yyp
;
2588 for (yyp
= yystackp
->yyitems
; yyp
< yystackp
->yynextFree
; yyp
+= 1)
2590 YYFPRINTF (stderr
, "%3lu. ",
2591 (unsigned long int) (yyp
- yystackp
->yyitems
));
2592 if (*(yybool
*) yyp
)
2594 YYFPRINTF (stderr
, "Res: %d, LR State: %d, posn: %lu, pred: %ld",
2595 yyp
->yystate
.yyresolved
, yyp
->yystate
.yylrState
,
2596 (unsigned long int) yyp
->yystate
.yyposn
,
2597 (long int) YYINDEX (yyp
->yystate
.yypred
));
2598 if (! yyp
->yystate
.yyresolved
)
2599 YYFPRINTF (stderr
, ", firstVal: %ld",
2600 (long int) YYINDEX (yyp
->yystate
2601 .yysemantics
.yyfirstVal
));
2605 YYFPRINTF (stderr
, "Option. rule: %d, state: %ld, next: %ld",
2606 yyp
->yyoption
.yyrule
- 1,
2607 (long int) YYINDEX (yyp
->yyoption
.yystate
),
2608 (long int) YYINDEX (yyp
->yyoption
.yynext
));
2610 YYFPRINTF (stderr
, "\n");
2612 YYFPRINTF (stderr
, "Tops:");
2613 for (yyi
= 0; yyi
< yystackp
->yytops
.yysize
; yyi
+= 1)
2614 YYFPRINTF (stderr
, "%lu: %ld; ", (unsigned long int) yyi
,
2615 (long int) YYINDEX (yystackp
->yytops
.yystates
[yyi
]));
2616 YYFPRINTF (stderr
, "\n");
2623 dnl glr
.cc produces its own header
.
2625 m4_if(b4_skeleton
, ["glr.c"],
2627 [@
output(b4_spec_defines_file@
)@
2628 b4_copyright([Skeleton interface
for Bison GLR parsers in C
],
2631 ]b4_cpp_guard_open([b4_spec_defines_file
])[
2632 ]b4_shared_declarations
[
2633 ]b4_cpp_guard_close([b4_spec_defines_file
])[