1 m4_divert(-1) -*- C
-*-
3 # GLR skeleton for Bison
4 # Copyright (C) 2002, 2003, 2004, 2005, 2006 Free Software Foundation, Inc.
6 # This program is free software; you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation; either version 2 of the License, or
9 # (at your option) any later version.
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License
17 # along with this program; if not, write to the Free Software
18 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
22 m4_include(b4_pkgdatadir
/[c
.m4
])
24 ## ---------------- ##
26 ## ---------------- ##
29 m4_define_default([b4_stack_depth_max
], [10000])
30 m4_define_default([b4_stack_depth_init
], [200])
34 ## ------------------------ ##
35 ## Pure/impure interfaces. ##
36 ## ------------------------ ##
41 # The possible parse-params formal arguments preceded by a comma.
43 # This is not shared with yacc.c in c.m4 because GLR relies on ISO C
44 # formal argument declarations.
45 m4_define([b4_user_formals
],
46 [m4_ifset([b4_parse_param
], [, b4_c_ansi_formals(b4_parse_param
)])])
51 # Accumule in b4_lex_param all the yylex arguments.
52 # Yes, this is quite ugly...
53 m4_define([b4_lex_param
],
54 m4_dquote(b4_pure_if([[[[YYSTYPE
*]], [[&yylval
]]][]dnl
55 b4_location_if([, [[YYLTYPE
*], [&yylloc
]]])])dnl
56 m4_ifdef([b4_lex_param
], [, ]b4_lex_param
)))
61 # Optional effective arguments passed to yyerror: user args plus yylloc, and
63 m4_define([b4_yyerror_args
],
64 [b4_pure_if([b4_location_if([yylocp
, ])])dnl
65 m4_ifset([b4_parse_param
], [b4_c_args(b4_parse_param
), ])])
70 # Same as above, but on the look-ahead, hence &yylloc instead of yylocp.
71 m4_define([b4_lyyerror_args
],
72 [b4_pure_if([b4_location_if([&yylloc
, ])])dnl
73 m4_ifset([b4_parse_param
], [b4_c_args(b4_parse_param
), ])])
78 # Same as b4_yyerror_args, but with a leading comma.
79 m4_define([b4_pure_args
],
80 [b4_pure_if([b4_location_if([, yylocp
])])[]b4_user_args
])
85 # Same as above, but on the look-ahead, hence &yylloc instead of yylocp.
86 m4_define([b4_lpure_args
],
87 [b4_pure_if([b4_location_if([, &yylloc
])])[]b4_user_args
])
92 # Arguments passed to yyerror: user formals plus yylocp.
93 m4_define([b4_pure_formals
],
94 [b4_pure_if([b4_location_if([, YYLTYPE
*yylocp
])])[]b4_user_formals
])
97 ## ----------------- ##
98 ## Semantic Values. ##
99 ## ----------------- ##
102 # b4_lhs_value([TYPE])
103 # --------------------
104 # Expansion of $<TYPE>$.
105 m4_define([b4_lhs_value
],
106 [((*yyvalp
)[]m4_ifval([$
1], [.$
1]))])
109 # b4_rhs_value(RULE-LENGTH, NUM, [TYPE])
110 # --------------------------------------
111 # Expansion of $<TYPE>NUM, where the current rule has RULE-LENGTH
113 m4_define([b4_rhs_value
],
114 [(((yyGLRStackItem
const *)yyvsp
)@
{YYFILL (($
2) - ($
1))@
}.yystate
.yysemantics
.yysval
[]m4_ifval([$
3], [.$
3]))])
125 m4_define([b4_lhs_location
],
129 # b4_rhs_location(RULE-LENGTH, NUM)
130 # ---------------------------------
131 # Expansion of @NUM, where the current rule has RULE-LENGTH symbols
133 m4_define([b4_rhs_location
],
134 [(((yyGLRStackItem
const *)yyvsp
)@
{YYFILL (($
2) - ($
1))@
}.yystate
.yyloc
)])
142 # We do want M4 expansion after # for CPP macros.
145 @output @output_parser_name@
146 b4_copyright([Skeleton parser
for GLR parsing with Bison
],
147 [2002, 2003, 2004, 2005, 2006])
149 /* This is the parser code for GLR (Generalized LR) parser. */
153 m4_if(b4_prefix
[], [yy
], [],
154 [/* Substitute the variable and function names. */
155 #define yyparse b4_prefix[]parse
156 #define yylex b4_prefix[]lex
157 #define yyerror b4_prefix[]error
158 #define yylval b4_prefix[]lval
159 #define yychar b4_prefix[]char
160 #define yydebug b4_prefix[]debug
161 #define yynerrs b4_prefix[]nerrs
162 #define yylloc b4_prefix[]lloc])
164 dnl
# b4_shared_declarations
165 dnl
# ----------------------
166 dnl
# Declaration that might either go into the header (if --defines)
167 dnl
# or open coded in the parser body.
168 m4_define([b4_shared_declarations
],
169 [b4_token_enums(b4_tokens
)[
171 /* Copy the first part of user declarations. */
174 #if ! defined (YYSTYPE) && ! defined (YYSTYPE_IS_DECLARED)
175 ]m4_ifdef([b4_stype
],
176 [b4_syncline([b4_stype_line
], [b4_file_name
])
177 typedef union m4_bregexp(b4_stype
, [^{], [YYSTYPE
])b4_stype YYSTYPE
;
178 /* Line __line__ of glr.c. */
179 b4_syncline([@oline@
], [@ofile@
])],
180 [typedef int YYSTYPE
;])[
181 # define YYSTYPE_IS_DECLARED 1
182 # define YYSTYPE_IS_TRIVIAL 1
185 #if ! defined (YYLTYPE) && ! defined (YYLTYPE_IS_DECLARED)
186 typedef struct YYLTYPE
197 # define YYLTYPE_IS_DECLARED 1
198 # define YYLTYPE_IS_TRIVIAL 1
202 m4_if(b4_defines_flag
, 0,
203 [b4_shared_declarations
],
204 [#include @output_header_name@])[
206 /* Enabling traces. */
208 # define YYDEBUG ]b4_debug[
211 /* Enabling verbose error messages. */
212 #ifdef YYERROR_VERBOSE
213 # undef YYERROR_VERBOSE
214 # define YYERROR_VERBOSE 1
216 # define YYERROR_VERBOSE ]b4_error_verbose[
219 /* Enabling the token table. */
220 #ifndef YYTOKEN_TABLE
221 # define YYTOKEN_TABLE ]b4_token_table[
224 /* Default (constant) value used for initialization for null
225 right-hand sides. Unlike the standard yacc.c template,
226 here we set the default value of $$ to a zeroed-out value.
227 Since the default value is undefined, this behavior is
228 technically correct. */
229 static YYSTYPE yyval_default
;
231 /* Copy the second part of user declarations. */
234 ]/* Line __line__ of glr.c. */
235 b4_syncline([@oline@
], [@ofile@
])
245 # include <libintl.h> /* INFRINGES ON USER NAME SPACE */
246 # define YY_(msgid) dgettext ("bison-runtime", msgid)
250 # define YY_(msgid) msgid
254 /* Suppress unused-variable warnings by "using" E. */
256 # define YYUSE(e) ((void) (e))
258 # define YYUSE(e) /* empty */
261 /* Identity function, used to suppress warnings about constant conditions. */
265 ]b4_c_function_def([YYID
], [static int], [[int i
], [i
]])[
275 # define YYMALLOC malloc
278 # define YYREALLOC realloc
281 #define YYSIZEMAX ((size_t) -1)
286 typedef unsigned char yybool
;
293 # define YYJMP_BUF jmp_buf
294 # define YYSETJMP(env) setjmp (env)
295 # define YYLONGJMP(env, val) longjmp (env, val)
302 #ifndef __attribute__
303 /* This feature is available in gcc versions 2.5 and later. */
304 # if (!defined (__GNUC__) || __GNUC__ < 2 \
305 || (__GNUC__ == 2 && __GNUC_MINOR__ < 5) || __STRICT_ANSI__)
306 # define __attribute__(Spec) /* empty */
310 ]b4_location_if([#define YYOPTIONAL_LOC(Name) Name],[
312 # define YYOPTIONAL_LOC(Name) /* empty */
314 # define YYOPTIONAL_LOC(Name) Name __attribute__ ((__unused__))
318 # define YYASSERT(condition) ((void) ((condition) || (abort (), 0)))
321 /* YYFINAL -- State number of the termination state. */
322 #define YYFINAL ]b4_final_state_number[
323 /* YYLAST -- Last index in YYTABLE. */
324 #define YYLAST ]b4_last[
326 /* YYNTOKENS -- Number of terminals. */
327 #define YYNTOKENS ]b4_tokens_number[
328 /* YYNNTS -- Number of nonterminals. */
329 #define YYNNTS ]b4_nterms_number[
330 /* YYNRULES -- Number of rules. */
331 #define YYNRULES ]b4_rules_number[
332 /* YYNRULES -- Number of states. */
333 #define YYNSTATES ]b4_states_number[
334 /* YYMAXRHS -- Maximum number of symbols on right-hand side of rule. */
335 #define YYMAXRHS ]b4_r2_max[
336 /* YYMAXLEFT -- Maximum number of symbols to the left of a handle
337 accessed by $0, $-1, etc., in any rule. */
338 #define YYMAXLEFT ]b4_max_left_semantic_context[
340 /* YYTRANSLATE(X) -- Bison symbol number corresponding to X. */
341 #define YYUNDEFTOK ]b4_undef_token_number[
342 #define YYMAXUTOK ]b4_user_token_number_max[
344 #define YYTRANSLATE(YYX) \
345 ((YYX <= 0) ? YYEOF : \
346 (unsigned int) (YYX) <= YYMAXUTOK ? yytranslate[YYX] : YYUNDEFTOK)
348 /* YYTRANSLATE[YYLEX] -- Bison symbol number corresponding to YYLEX. */
349 static const ]b4_int_type_for([b4_translate
])[ yytranslate
[] =
355 /* YYPRHS[YYN] -- Index of the first RHS symbol of rule number YYN in
357 static const ]b4_int_type_for([b4_prhs
])[ yyprhs
[] =
362 /* YYRHS -- A `-1'-separated list of the rules' RHS. */
363 static const ]b4_int_type_for([b4_rhs
])[ yyrhs
[] =
368 /* YYRLINE[YYN] -- source line where rule number YYN was defined. */
369 static const ]b4_int_type_for([b4_rline
])[ yyrline
[] =
375 #if YYDEBUG || YYERROR_VERBOSE || YYTOKEN_TABLE
376 /* YYTNAME[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM.
377 First, the terminals, then, starting at YYNTOKENS, nonterminals. */
378 static const char *const yytname
[] =
384 /* YYR1[YYN] -- Symbol number of symbol that rule YYN derives. */
385 static const ]b4_int_type_for([b4_r1
])[ yyr1
[] =
390 /* YYR2[YYN] -- Number of symbols composing right hand side of rule YYN. */
391 static const ]b4_int_type_for([b4_r2
])[ yyr2
[] =
396 /* YYDPREC[RULE-NUM] -- Dynamic precedence of rule #RULE-NUM (0 if none). */
397 static const ]b4_int_type_for([b4_dprec
])[ yydprec
[] =
402 /* YYMERGER[RULE-NUM] -- Index of merging function for rule #RULE-NUM. */
403 static const ]b4_int_type_for([b4_merger
])[ yymerger
[] =
408 /* YYDEFACT[S] -- default rule to reduce with in state S when YYTABLE
409 doesn't specify something else to do. Zero means the default is an
411 static const ]b4_int_type_for([b4_defact
])[ yydefact
[] =
416 /* YYPDEFGOTO[NTERM-NUM]. */
417 static const ]b4_int_type_for([b4_defgoto
])[ yydefgoto
[] =
422 /* YYPACT[STATE-NUM] -- Index in YYTABLE of the portion describing
424 #define YYPACT_NINF ]b4_pact_ninf[
425 static const ]b4_int_type_for([b4_pact
])[ yypact
[] =
430 /* YYPGOTO[NTERM-NUM]. */
431 static const ]b4_int_type_for([b4_pgoto
])[ yypgoto
[] =
436 /* YYTABLE[YYPACT[STATE-NUM]]. What to do in state STATE-NUM. If
437 positive, shift that token. If negative, reduce the rule which
438 number is the opposite. If zero, do what YYDEFACT says.
439 If YYTABLE_NINF, syntax error. */
440 #define YYTABLE_NINF ]b4_table_ninf[
441 static const ]b4_int_type_for([b4_table
])[ yytable
[] =
446 /* YYCONFLP[YYPACT[STATE-NUM]] -- Pointer into YYCONFL of start of
447 list of conflicting reductions corresponding to action entry for
448 state STATE-NUM in yytable. 0 means no conflicts. The list in
449 yyconfl is terminated by a rule number of 0. */
450 static const ]b4_int_type_for([b4_conflict_list_heads
])[ yyconflp
[] =
452 ]b4_conflict_list_heads
[
455 /* YYCONFL[I] -- lists of conflicting rule numbers, each terminated by
456 0, pointed into by YYCONFLP. */
457 ]dnl Do
not use b4_int_type_for here
, since there are places where
458 dnl pointers onto yyconfl are taken
, which type is
"short int *".
459 dnl We probably ought to introduce a type
for confl
.
460 [static const short int yyconfl
[] =
462 ]b4_conflicting_rules
[
465 static const ]b4_int_type_for([b4_check
])[ yycheck
[] =
470 /* YYSTOS[STATE-NUM] -- The (internal number of the) accessing
471 symbol of state STATE-NUM. */
472 static const ]b4_int_type_for([b4_stos
])[ yystos
[] =
478 /* Prevent warning if -Wmissing-prototypes. */
479 ]b4_c_ansi_function_decl([yyparse
], [int], b4_parse_param
)[
481 /* Error token number */
484 /* YYLLOC_DEFAULT -- Set CURRENT to span from RHS[1] to RHS[N].
485 If N is 0, then set CURRENT to the empty location which ends
486 the previous symbol: RHS[0] (always defined). */
489 #define YYRHSLOC(Rhs, K) ((Rhs)[K].yystate.yyloc)
490 #ifndef YYLLOC_DEFAULT
491 # define YYLLOC_DEFAULT(Current, Rhs, N) \
495 (Current).first_line = YYRHSLOC (Rhs, 1).first_line; \
496 (Current).first_column = YYRHSLOC (Rhs, 1).first_column; \
497 (Current).last_line = YYRHSLOC (Rhs, N).last_line; \
498 (Current).last_column = YYRHSLOC (Rhs, N).last_column; \
502 (Current).first_line = (Current).last_line = \
503 YYRHSLOC (Rhs, 0).last_line; \
504 (Current).first_column = (Current).last_column = \
505 YYRHSLOC (Rhs, 0).last_column; \
509 /* YY_LOCATION_PRINT -- Print the location on the stream.
510 This macro was not mandated originally: define only if we know
511 we won't break user code: when these are the locations we know. */
513 # define YY_LOCATION_PRINT(File, Loc) \
514 fprintf (File, "%d.%d-%d.%d", \
515 (Loc).first_line, (Loc).first_column, \
516 (Loc).last_line, (Loc).last_column)
519 #ifndef YYLLOC_DEFAULT
520 # define YYLLOC_DEFAULT(Current, Rhs, N) ((void) 0)
524 #ifndef YY_LOCATION_PRINT
525 # define YY_LOCATION_PRINT(File, Loc) ((void) 0)
529 /* YYLEX -- calling `yylex' with the right arguments. */
530 #define YYLEX ]b4_c_function_call([yylex], [int], b4_lex_param)[
535 #define yynerrs (yystackp->yyerrcnt)
537 #define yychar (yystackp->yyrawchar)
539 #define yylval (yystackp->yyval)
541 #define yylloc (yystackp->yyloc)
542 m4_if(b4_prefix
[], [yy
], [],
543 [#define b4_prefix[]nerrs yynerrs
544 #define b4_prefix[]char yychar
545 #define b4_prefix[]lval yylval
546 #define b4_prefix[]lloc yylloc])],
554 static const int YYEOF
= 0;
555 static const int YYEMPTY
= -2;
557 typedef enum { yyok
, yyaccept
, yyabort
, yyerr
} YYRESULTTAG
;
560 do { YYRESULTTAG yyflag = YYE; if (yyflag != yyok) return yyflag; } \
565 #if ! defined (YYFPRINTF)
566 # define YYFPRINTF fprintf
569 # define YYDPRINTF(Args) \
575 ]b4_yy_symbol_print_generate([b4_c_ansi_function_def
])[
577 # define YY_SYMBOL_PRINT(Title, Type, Value, Location) \
581 YYFPRINTF (stderr, "%s ", Title); \
582 yy_symbol_print (stderr, Type, \
583 Value]b4_location_if([, Location])[]b4_user_args[); \
584 YYFPRINTF (stderr, "\n"); \
588 /* Nonzero means print parse trace. It is left uninitialized so that
589 multiple parsers can coexist. */
594 # define YYDPRINTF(Args)
595 # define YY_SYMBOL_PRINT(Title, Type, Value, Location)
597 #endif /* !YYDEBUG */
599 /* YYINITDEPTH -- initial size of the parser's stacks. */
601 # define YYINITDEPTH ]b4_stack_depth_init[
604 /* YYMAXDEPTH -- maximum size the stacks can grow to (effective only
605 if the built-in stack extension method is used).
607 Do not make this value too large; the results are undefined if
608 SIZE_MAX < YYMAXDEPTH * sizeof (GLRStackItem)
609 evaluated with infinite-precision integer arithmetic. */
612 # define YYMAXDEPTH ]b4_stack_depth_max[
615 /* Minimum number of free items on the stack allowed after an
616 allocation. This is to allow allocation and initialization
617 to be completed by functions that call yyexpandGLRStack before the
618 stack is expanded, thus insuring that all necessary pointers get
619 properly redirected to new data. */
622 #ifndef YYSTACKEXPANDABLE
623 # if (! defined (__cplusplus) \
624 || (]b4_location_if([[defined (YYLTYPE_IS_TRIVIAL) && YYLTYPE_IS_TRIVIAL \
625 && ]])[defined (YYSTYPE_IS_TRIVIAL) && YYSTYPE_IS_TRIVIAL))
626 # define YYSTACKEXPANDABLE 1
628 # define YYSTACKEXPANDABLE 0
632 #if YYSTACKEXPANDABLE
633 # define YY_RESERVE_GLRSTACK(Yystack) \
635 if (Yystack->yyspaceLeft < YYHEADROOM) \
636 yyexpandGLRStack (Yystack); \
639 # define YY_RESERVE_GLRSTACK(Yystack) \
641 if (Yystack->yyspaceLeft < YYHEADROOM) \
642 yyMemoryExhausted (Yystack); \
650 # if defined (__GLIBC__) && defined (_STRING_H) && defined (_GNU_SOURCE)
651 # define yystpcpy stpcpy
653 /* Copy YYSRC to YYDEST, returning the address of the terminating '\0' in
656 yystpcpy (char *yydest
, const char *yysrc
)
659 const char *yys
= yysrc
;
661 while ((*yyd
++ = *yys
++) != '\0')
670 /* Copy to YYRES the contents of YYSTR after stripping away unnecessary
671 quotes and backslashes, so that it's suitable for yyerror. The
672 heuristic is that double-quoting is unnecessary unless the string
673 contains an apostrophe, a comma, or backslash (other than
674 backslash-backslash). YYSTR is taken from yytname. If YYRES is
675 null, do not copy; instead, return the length of what the result
678 yytnamerr (char *yyres
, const char *yystr
)
683 char const *yyp
= yystr
;
690 goto do_not_strip_quotes
;
694 goto do_not_strip_quotes
;
707 do_not_strip_quotes
: ;
711 return strlen (yystr
);
713 return yystpcpy (yyres
, yystr
) - yyres
;
717 #endif /* !YYERROR_VERBOSE */
719 /** State numbers, as in LALR(1) machine */
720 typedef int yyStateNum
;
722 /** Rule numbers, as in LALR(1) machine */
723 typedef int yyRuleNum
;
725 /** Grammar symbol */
726 typedef short int yySymbol
;
728 /** Item references, as in LALR(1) machine */
729 typedef short int yyItemNum
;
731 typedef struct yyGLRState yyGLRState
;
732 typedef struct yyGLRStateSet yyGLRStateSet
;
733 typedef struct yySemanticOption yySemanticOption
;
734 typedef union yyGLRStackItem yyGLRStackItem
;
735 typedef struct yyGLRStack yyGLRStack
;
738 /** Type tag: always true. */
740 /** Type tag for yysemantics. If true, yysval applies, otherwise
741 * yyfirstVal applies. */
743 /** Number of corresponding LALR(1) machine state. */
744 yyStateNum yylrState
;
745 /** Preceding state in this stack */
747 /** Source position of the first token produced by my symbol */
750 /** First in a chain of alternative reductions producing the
751 * non-terminal corresponding to this state, threaded through
753 yySemanticOption
* yyfirstVal
;
754 /** Semantic value for this state. */
757 /** Source location for this state. */
761 struct yyGLRStateSet
{
762 yyGLRState
** yystates
;
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 /** Next sibling in chain of options. To facilitate merging,
774 * options are chained in decreasing order by address. */
775 yySemanticOption
* yynext
;
778 /** Type of the items in the GLR stack. The yyisState field
779 * indicates which item of the union is valid. */
780 union yyGLRStackItem
{
782 yySemanticOption yyoption
;
787 ]b4_location_if([[ /* To compute the location of the error token. */
788 yyGLRStackItem yyerror_range
[3];]])[
797 YYJMP_BUF yyexception_buffer
;
798 yyGLRStackItem
* yyitems
;
799 yyGLRStackItem
* yynextFree
;
801 yyGLRState
* yysplitPoint
;
802 yyGLRState
* yylastDeleted
;
803 yyGLRStateSet yytops
;
806 #if YYSTACKEXPANDABLE
807 static void yyexpandGLRStack (yyGLRStack
* yystackp
);
810 static void yyFail (yyGLRStack
* yystackp
]b4_pure_formals
[, const char* yymsg
)
811 __attribute__ ((__noreturn__
));
813 yyFail (yyGLRStack
* yystackp
]b4_pure_formals
[, const char* yymsg
)
816 yyerror (]b4_yyerror_args
[yymsg
);
817 YYLONGJMP (yystackp
->yyexception_buffer
, 1);
820 static void yyMemoryExhausted (yyGLRStack
* yystackp
)
821 __attribute__ ((__noreturn__
));
823 yyMemoryExhausted (yyGLRStack
* yystackp
)
825 YYLONGJMP (yystackp
->yyexception_buffer
, 2);
828 #if YYDEBUG || YYERROR_VERBOSE
829 /** A printable representation of TOKEN. */
830 static inline const char*
831 yytokenName (yySymbol yytoken
)
833 if (yytoken
== YYEMPTY
)
836 return yytname
[yytoken
];
840 /** Fill in YYVSP[YYLOW1 .. YYLOW0-1] from the chain of states starting
841 * at YYVSP[YYLOW0].yystate.yypred. Leaves YYVSP[YYLOW1].yystate.yypred
842 * containing the pointer to the next state in the chain. */
843 static void yyfillin (yyGLRStackItem
*, int, int) __attribute__ ((__unused__
));
845 yyfillin (yyGLRStackItem
*yyvsp
, int yylow0
, int yylow1
)
849 s
= yyvsp
[yylow0
].yystate
.yypred
;
850 for (i
= yylow0
-1; i
>= yylow1
; i
-= 1)
852 YYASSERT (s
->yyresolved
);
853 yyvsp
[i
].yystate
.yyresolved
= yytrue
;
854 yyvsp
[i
].yystate
.yysemantics
.yysval
= s
->yysemantics
.yysval
;
855 yyvsp
[i
].yystate
.yyloc
= s
->yyloc
;
856 s
= yyvsp
[i
].yystate
.yypred
= s
->yypred
;
860 /* Do nothing if YYNORMAL or if *YYLOW <= YYLOW1. Otherwise, fill in
861 * YYVSP[YYLOW1 .. *YYLOW-1] as in yyfillin and set *YYLOW = YYLOW1.
862 * For convenience, always return YYLOW1. */
863 static inline int yyfill (yyGLRStackItem
*, int *, int, yybool
)
864 __attribute__ ((__unused__
));
866 yyfill (yyGLRStackItem
*yyvsp
, int *yylow
, int yylow1
, yybool yynormal
)
868 if (!yynormal
&& yylow1
< *yylow
)
870 yyfillin (yyvsp
, *yylow
, yylow1
);
876 /** Perform user action for rule number YYN, with RHS length YYRHSLEN,
877 * and top stack item YYVSP. YYLVALP points to place to put semantic
878 * value ($$), and yylocp points to place for location information
879 * (@@$). Returns yyok for normal return, yyaccept for YYACCEPT,
880 * yyerr for YYERROR, yyabort for YYABORT. */
881 /*ARGSUSED*/ static YYRESULTTAG
882 yyuserAction (yyRuleNum yyn
, int yyrhslen
, yyGLRStackItem
* yyvsp
,
884 YYLTYPE
* YYOPTIONAL_LOC (yylocp
),
888 yybool yynormal
__attribute__ ((__unused__
)) =
889 (yystackp
->yysplitPoint
== 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 = *(yystackp->yytokenp) = 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
;
916 YYLLOC_DEFAULT (*yylocp
, yyvsp
- yyrhslen
, yyrhslen
);
917 ]b4_location_if([[ yystackp
->yyerror_range
[1].yystate
.yyloc
= *yylocp
;
922 /* Line __line__ of glr.c. */
923 b4_syncline([@oline@
], [@ofile@
])[
938 /*ARGSUSED*/ static void
939 yyuserMerge (int yyn
, YYSTYPE
* yy0
, YYSTYPE
* yy1
)
951 /* Bison grammar-table manipulation. */
953 ]b4_yydestruct_generate([b4_c_ansi_function_def
])[
955 /** Number of symbols composing the right hand side of rule #RULE. */
957 yyrhsLength (yyRuleNum yyrule
)
963 yydestroyGLRState (char const *yymsg
, yyGLRState
*yys
]b4_user_formals
[)
966 yydestruct (yymsg
, yystos
[yys
->yylrState
],
967 &yys
->yysemantics
.yysval
]b4_location_if([, &yys
->yyloc
])[]b4_user_args
[);
973 YYFPRINTF (stderr
, "%s unresolved ", yymsg
);
974 yy_symbol_print (stderr
, yystos
[yys
->yylrState
],
975 &yys
->yysemantics
.yysval
]b4_location_if([, &yys
->yyloc
])[]b4_user_args
[);
976 YYFPRINTF (stderr
, "\n");
980 if (yys
->yysemantics
.yyfirstVal
)
982 yySemanticOption
*yyoption
= yys
->yysemantics
.yyfirstVal
;
985 for (yyrh
= yyoption
->yystate
, yyn
= yyrhsLength (yyoption
->yyrule
);
987 yyrh
= yyrh
->yypred
, yyn
-= 1)
988 yydestroyGLRState (yymsg
, yyrh
]b4_user_args
[);
993 /** Left-hand-side symbol for rule #RULE. */
994 static inline yySymbol
995 yylhsNonterm (yyRuleNum yyrule
)
1000 #define yyis_pact_ninf(yystate) \
1001 ]m4_if(m4_eval(b4_pact_ninf < b4_pact_min), [1],
1003 [((yystate
) == YYPACT_NINF
)])[
1005 /** True iff LR state STATE has only a default reduction (regardless
1007 static inline yybool
1008 yyisDefaultedState (yyStateNum yystate
)
1010 return yyis_pact_ninf (yypact
[yystate
]);
1013 /** The default reduction for STATE, assuming it has one. */
1014 static inline yyRuleNum
1015 yydefaultAction (yyStateNum yystate
)
1017 return yydefact
[yystate
];
1020 #define yyis_table_ninf(yytable_value) \
1021 ]m4_if(m4_eval(b4_table_ninf < b4_table_min), [1],
1023 [((yytable_value
) == YYTABLE_NINF
)])[
1025 /** Set *YYACTION to the action to take in YYSTATE on seeing YYTOKEN.
1027 * R < 0: Reduce on rule -R.
1029 * R > 0: Shift to state R.
1030 * Set *CONFLICTS to a pointer into yyconfl to 0-terminated list of
1031 * conflicting reductions.
1034 yygetLRActions (yyStateNum yystate
, int yytoken
,
1035 int* yyaction
, const short int** yyconflicts
)
1037 int yyindex
= yypact
[yystate
] + yytoken
;
1038 if (yyindex
< 0 || YYLAST
< yyindex
|| yycheck
[yyindex
] != yytoken
)
1040 *yyaction
= -yydefact
[yystate
];
1041 *yyconflicts
= yyconfl
;
1043 else if (! yyis_table_ninf (yytable
[yyindex
]))
1045 *yyaction
= yytable
[yyindex
];
1046 *yyconflicts
= yyconfl
+ yyconflp
[yyindex
];
1051 *yyconflicts
= yyconfl
+ yyconflp
[yyindex
];
1055 static inline yyStateNum
1056 yyLRgotoState (yyStateNum yystate
, yySymbol yylhs
)
1059 yyr
= yypgoto
[yylhs
- YYNTOKENS
] + yystate
;
1060 if (0 <= yyr
&& yyr
<= YYLAST
&& yycheck
[yyr
] == yystate
)
1061 return yytable
[yyr
];
1063 return yydefgoto
[yylhs
- YYNTOKENS
];
1066 static inline yybool
1067 yyisShiftAction (int yyaction
)
1069 return 0 < yyaction
;
1072 static inline yybool
1073 yyisErrorAction (int yyaction
)
1075 return yyaction
== 0;
1080 /** Return a fresh GLRStackItem. Callers should call
1081 * YY_RESERVE_GLRSTACK afterwards to make sure there is sufficient
1084 static inline yyGLRStackItem
*
1085 yynewGLRStackItem (yyGLRStack
* yystackp
, yybool yyisState
)
1087 yyGLRStackItem
* yynewItem
= yystackp
->yynextFree
;
1088 yystackp
->yyspaceLeft
-= 1;
1089 yystackp
->yynextFree
+= 1;
1090 yynewItem
->yystate
.yyisState
= yyisState
;
1095 yyaddDeferredAction (yyGLRStack
* yystackp
, yyGLRState
* yystate
,
1096 yyGLRState
* rhs
, yyRuleNum yyrule
)
1098 yySemanticOption
* yynewOption
=
1099 &yynewGLRStackItem (yystackp
, yyfalse
)->yyoption
;
1100 yynewOption
->yystate
= rhs
;
1101 yynewOption
->yyrule
= yyrule
;
1102 yynewOption
->yynext
= yystate
->yysemantics
.yyfirstVal
;
1103 yystate
->yysemantics
.yyfirstVal
= yynewOption
;
1105 YY_RESERVE_GLRSTACK (yystackp
);
1110 /** Initialize SET to a singleton set containing an empty stack. */
1112 yyinitStateSet (yyGLRStateSet
* yyset
)
1115 yyset
->yycapacity
= 16;
1116 yyset
->yystates
= (yyGLRState
**) YYMALLOC (16 * sizeof yyset
->yystates
[0]);
1117 if (! yyset
->yystates
)
1119 yyset
->yystates
[0] = NULL
;
1123 static void yyfreeStateSet (yyGLRStateSet
* yyset
)
1125 YYFREE (yyset
->yystates
);
1128 /** Initialize STACK to a single empty stack, with total maximum
1129 * capacity for all stacks of SIZE. */
1131 yyinitGLRStack (yyGLRStack
* yystackp
, size_t yysize
)
1133 yystackp
->yyerrState
= 0;
1135 yystackp
->yyspaceLeft
= yysize
;
1137 (yyGLRStackItem
*) YYMALLOC (yysize
* sizeof yystackp
->yynextFree
[0]);
1138 if (!yystackp
->yyitems
)
1140 yystackp
->yynextFree
= yystackp
->yyitems
;
1141 yystackp
->yysplitPoint
= NULL
;
1142 yystackp
->yylastDeleted
= NULL
;
1143 return yyinitStateSet (&yystackp
->yytops
);
1147 #if YYSTACKEXPANDABLE
1148 # define YYRELOC(YYFROMITEMS,YYTOITEMS,YYX,YYTYPE) \
1149 &((YYTOITEMS) - ((YYFROMITEMS) - (yyGLRStackItem*) (YYX)))->YYTYPE
1151 /** If STACK is expandable, extend it. WARNING: Pointers into the
1152 stack from outside should be considered invalid after this call.
1153 We always expand when there are 1 or fewer items left AFTER an
1154 allocation, so that we can avoid having external pointers exist
1155 across an allocation. */
1157 yyexpandGLRStack (yyGLRStack
* yystackp
)
1159 yyGLRStackItem
* yynewItems
;
1160 yyGLRStackItem
* yyp0
, *yyp1
;
1161 size_t yysize
, yynewSize
;
1163 yysize
= yystackp
->yynextFree
- yystackp
->yyitems
;
1164 if (YYMAXDEPTH
<= yysize
)
1165 yyMemoryExhausted (yystackp
);
1166 yynewSize
= 2*yysize
;
1167 if (YYMAXDEPTH
< yynewSize
)
1168 yynewSize
= YYMAXDEPTH
;
1169 yynewItems
= (yyGLRStackItem
*) YYMALLOC (yynewSize
* sizeof yynewItems
[0]);
1171 yyMemoryExhausted (yystackp
);
1172 for (yyp0
= yystackp
->yyitems
, yyp1
= yynewItems
, yyn
= yysize
;
1174 yyn
-= 1, yyp0
+= 1, yyp1
+= 1)
1177 if (*(yybool
*) yyp0
)
1179 yyGLRState
* yys0
= &yyp0
->yystate
;
1180 yyGLRState
* yys1
= &yyp1
->yystate
;
1181 if (yys0
->yypred
!= NULL
)
1183 YYRELOC (yyp0
, yyp1
, yys0
->yypred
, yystate
);
1184 if (! yys0
->yyresolved
&& yys0
->yysemantics
.yyfirstVal
!= NULL
)
1185 yys1
->yysemantics
.yyfirstVal
=
1186 YYRELOC(yyp0
, yyp1
, yys0
->yysemantics
.yyfirstVal
, yyoption
);
1190 yySemanticOption
* yyv0
= &yyp0
->yyoption
;
1191 yySemanticOption
* yyv1
= &yyp1
->yyoption
;
1192 if (yyv0
->yystate
!= NULL
)
1193 yyv1
->yystate
= YYRELOC (yyp0
, yyp1
, yyv0
->yystate
, yystate
);
1194 if (yyv0
->yynext
!= NULL
)
1195 yyv1
->yynext
= YYRELOC (yyp0
, yyp1
, yyv0
->yynext
, yyoption
);
1198 if (yystackp
->yysplitPoint
!= NULL
)
1199 yystackp
->yysplitPoint
= YYRELOC (yystackp
->yyitems
, yynewItems
,
1200 yystackp
->yysplitPoint
, yystate
);
1202 for (yyn
= 0; yyn
< yystackp
->yytops
.yysize
; yyn
+= 1)
1203 if (yystackp
->yytops
.yystates
[yyn
] != NULL
)
1204 yystackp
->yytops
.yystates
[yyn
] =
1205 YYRELOC (yystackp
->yyitems
, yynewItems
,
1206 yystackp
->yytops
.yystates
[yyn
], yystate
);
1207 YYFREE (yystackp
->yyitems
);
1208 yystackp
->yyitems
= yynewItems
;
1209 yystackp
->yynextFree
= yynewItems
+ yysize
;
1210 yystackp
->yyspaceLeft
= yynewSize
- yysize
;
1215 yyfreeGLRStack (yyGLRStack
* yystackp
)
1217 YYFREE (yystackp
->yyitems
);
1218 yyfreeStateSet (&yystackp
->yytops
);
1221 /** Assuming that S is a GLRState somewhere on STACK, update the
1222 * splitpoint of STACK, if needed, so that it is at least as deep as
1225 yyupdateSplit (yyGLRStack
* yystackp
, yyGLRState
* yys
)
1227 if (yystackp
->yysplitPoint
!= NULL
&& yystackp
->yysplitPoint
> yys
)
1228 yystackp
->yysplitPoint
= yys
;
1231 /** Invalidate stack #K in STACK. */
1233 yymarkStackDeleted (yyGLRStack
* yystackp
, size_t yyk
)
1235 if (yystackp
->yytops
.yystates
[yyk
] != NULL
)
1236 yystackp
->yylastDeleted
= yystackp
->yytops
.yystates
[yyk
];
1237 yystackp
->yytops
.yystates
[yyk
] = NULL
;
1240 /** Undelete the last stack that was marked as deleted. Can only be
1241 done once after a deletion, and only when all other stacks have
1244 yyundeleteLastStack (yyGLRStack
* yystackp
)
1246 if (yystackp
->yylastDeleted
== NULL
|| yystackp
->yytops
.yysize
!= 0)
1248 yystackp
->yytops
.yystates
[0] = yystackp
->yylastDeleted
;
1249 yystackp
->yytops
.yysize
= 1;
1250 YYDPRINTF ((stderr
, "Restoring last deleted stack as stack #0.\n"));
1251 yystackp
->yylastDeleted
= NULL
;
1255 yyremoveDeletes (yyGLRStack
* yystackp
)
1259 while (yyj
< yystackp
->yytops
.yysize
)
1261 if (yystackp
->yytops
.yystates
[yyi
] == NULL
)
1265 YYDPRINTF ((stderr
, "Removing dead stacks.\n"));
1267 yystackp
->yytops
.yysize
-= 1;
1271 yystackp
->yytops
.yystates
[yyj
] = yystackp
->yytops
.yystates
[yyi
];
1274 YYDPRINTF ((stderr
, "Rename stack %lu -> %lu.\n",
1275 (unsigned long int) yyi
, (unsigned long int) yyj
));
1283 /** Shift to a new state on stack #K of STACK, corresponding to LR state
1284 * LRSTATE, at input position POSN, with (resolved) semantic value SVAL. */
1286 yyglrShift (yyGLRStack
* yystackp
, size_t yyk
, yyStateNum yylrState
,
1288 YYSTYPE
* yyvalp
, YYLTYPE
* yylocp
)
1290 yyGLRState
* yynewState
= &yynewGLRStackItem (yystackp
, yytrue
)->yystate
;
1292 yynewState
->yylrState
= yylrState
;
1293 yynewState
->yyposn
= yyposn
;
1294 yynewState
->yyresolved
= yytrue
;
1295 yynewState
->yypred
= yystackp
->yytops
.yystates
[yyk
];
1296 yynewState
->yysemantics
.yysval
= *yyvalp
;
1297 yynewState
->yyloc
= *yylocp
;
1298 yystackp
->yytops
.yystates
[yyk
] = yynewState
;
1300 YY_RESERVE_GLRSTACK (yystackp
);
1303 /** Shift stack #K of YYSTACK, to a new state corresponding to LR
1304 * state YYLRSTATE, at input position YYPOSN, with the (unresolved)
1305 * semantic value of YYRHS under the action for YYRULE. */
1307 yyglrShiftDefer (yyGLRStack
* yystackp
, size_t yyk
, yyStateNum yylrState
,
1308 size_t yyposn
, yyGLRState
* rhs
, yyRuleNum yyrule
)
1310 yyGLRState
* yynewState
= &yynewGLRStackItem (yystackp
, yytrue
)->yystate
;
1312 yynewState
->yylrState
= yylrState
;
1313 yynewState
->yyposn
= yyposn
;
1314 yynewState
->yyresolved
= yyfalse
;
1315 yynewState
->yypred
= yystackp
->yytops
.yystates
[yyk
];
1316 yynewState
->yysemantics
.yyfirstVal
= NULL
;
1317 yystackp
->yytops
.yystates
[yyk
] = yynewState
;
1319 /* Invokes YY_RESERVE_GLRSTACK. */
1320 yyaddDeferredAction (yystackp
, yynewState
, rhs
, yyrule
);
1323 /** Pop the symbols consumed by reduction #RULE from the top of stack
1324 * #K of STACK, and perform the appropriate semantic action on their
1325 * semantic values. Assumes that all ambiguities in semantic values
1326 * have been previously resolved. Set *VALP to the resulting value,
1327 * and *LOCP to the computed location (if any). Return value is as
1328 * for userAction. */
1329 static inline YYRESULTTAG
1330 yydoAction (yyGLRStack
* yystackp
, size_t yyk
, yyRuleNum yyrule
,
1331 YYSTYPE
* yyvalp
, YYLTYPE
* yylocp
]b4_user_formals
[)
1333 int yynrhs
= yyrhsLength (yyrule
);
1335 if (yystackp
->yysplitPoint
== NULL
)
1337 /* Standard special case: single stack. */
1338 yyGLRStackItem
* rhs
= (yyGLRStackItem
*) yystackp
->yytops
.yystates
[yyk
];
1339 YYASSERT (yyk
== 0);
1340 yystackp
->yynextFree
-= yynrhs
;
1341 yystackp
->yyspaceLeft
+= yynrhs
;
1342 yystackp
->yytops
.yystates
[0] = & yystackp
->yynextFree
[-1].yystate
;
1343 return yyuserAction (yyrule
, yynrhs
, rhs
,
1344 yyvalp
, yylocp
, yystackp
]b4_user_args
[);
1348 /* At present, doAction is never called in nondeterministic
1349 * mode, so this branch is never taken. It is here in
1350 * anticipation of a future feature that will allow immediate
1351 * evaluation of selected actions in nondeterministic mode. */
1354 yyGLRStackItem yyrhsVals
[YYMAXRHS
+ YYMAXLEFT
+ 1];
1355 yys
= yyrhsVals
[YYMAXRHS
+ YYMAXLEFT
].yystate
.yypred
1356 = yystackp
->yytops
.yystates
[yyk
];]b4_location_if([[
1358 /* Set default location. */
1359 yyrhsVals
[YYMAXRHS
+ YYMAXLEFT
- 1].yystate
.yyloc
= yys
->yyloc
;]])[
1360 for (yyi
= 0; yyi
< yynrhs
; yyi
+= 1)
1365 yyupdateSplit (yystackp
, yys
);
1366 yystackp
->yytops
.yystates
[yyk
] = yys
;
1367 return yyuserAction (yyrule
, yynrhs
, yyrhsVals
+ YYMAXRHS
+ YYMAXLEFT
- 1,
1368 yyvalp
, yylocp
, yystackp
]b4_user_args
[);
1373 # define YY_REDUCE_PRINT(Args)
1375 # define YY_REDUCE_PRINT(Args) \
1378 yy_reduce_print Args; \
1381 /*----------------------------------------------------------.
1382 | Report that the RULE is going to be reduced on stack #K. |
1383 `----------------------------------------------------------*/
1385 /*ARGSUSED*/ static inline void
1386 yy_reduce_print (yyGLRStack
* yystackp
, size_t yyk
, yyRuleNum yyrule
,
1387 YYSTYPE
* yyvalp
, YYLTYPE
* yylocp
]b4_user_formals
[)
1389 int yynrhs
= yyrhsLength (yyrule
);
1390 yybool yynormal
__attribute__ ((__unused__
)) =
1391 (yystackp
->yysplitPoint
== NULL
);
1392 yyGLRStackItem
* yyvsp
= (yyGLRStackItem
*) yystackp
->yytops
.yystates
[yyk
];
1397 ]b4_parse_param_use
[]dnl
1398 [ YYFPRINTF (stderr
, "Reducing stack %lu by rule %d (line %lu):\n",
1399 (unsigned long int) yyk
, yyrule
- 1,
1400 (unsigned long int) yyrline
[yyrule
]);
1401 /* The symbols being reduced. */
1402 for (yyi
= 0; yyi
< yynrhs
; yyi
++)
1404 fprintf (stderr
, " $%d = ", yyi
+ 1);
1405 yy_symbol_print (stderr
, yyrhs
[yyprhs
[yyrule
] + yyi
],
1406 &]b4_rhs_value(yynrhs
, yyi
+ 1)[
1407 ]b4_location_if([, &]b4_rhs_location(yynrhs
, yyi
+ 1))[]dnl
1409 fprintf (stderr
, "\n");
1414 /** Pop items off stack #K of STACK according to grammar rule RULE,
1415 * and push back on the resulting nonterminal symbol. Perform the
1416 * semantic action associated with RULE and store its value with the
1417 * newly pushed state, if FORCEEVAL or if STACK is currently
1418 * unambiguous. Otherwise, store the deferred semantic action with
1419 * the new state. If the new state would have an identical input
1420 * position, LR state, and predecessor to an existing state on the stack,
1421 * it is identified with that existing state, eliminating stack #K from
1422 * the STACK. In this case, the (necessarily deferred) semantic value is
1423 * added to the options for the existing state's semantic value.
1425 static inline YYRESULTTAG
1426 yyglrReduce (yyGLRStack
* yystackp
, size_t yyk
, yyRuleNum yyrule
,
1427 yybool yyforceEval
]b4_user_formals
[)
1429 size_t yyposn
= yystackp
->yytops
.yystates
[yyk
]->yyposn
;
1431 if (yyforceEval
|| yystackp
->yysplitPoint
== NULL
)
1436 YY_REDUCE_PRINT ((yystackp
, yyk
, yyrule
, &yysval
, &yyloc
]b4_user_args
[));
1437 YYCHK (yydoAction (yystackp
, yyk
, yyrule
, &yysval
,
1438 &yyloc
]b4_user_args
[));
1439 YY_SYMBOL_PRINT ("-> $$ =", yyr1
[yyrule
], &yysval
, &yyloc
);
1440 yyglrShift (yystackp
, yyk
,
1441 yyLRgotoState (yystackp
->yytops
.yystates
[yyk
]->yylrState
,
1442 yylhsNonterm (yyrule
)),
1443 yyposn
, &yysval
, &yyloc
);
1449 yyGLRState
* yys
, *yys0
= yystackp
->yytops
.yystates
[yyk
];
1450 yyStateNum yynewLRState
;
1452 for (yys
= yystackp
->yytops
.yystates
[yyk
], yyn
= yyrhsLength (yyrule
);
1458 yyupdateSplit (yystackp
, yys
);
1459 yynewLRState
= yyLRgotoState (yys
->yylrState
, yylhsNonterm (yyrule
));
1461 "Reduced stack %lu by rule #%d; action deferred. Now in state %d.\n",
1462 (unsigned long int) yyk
, yyrule
- 1, yynewLRState
));
1463 for (yyi
= 0; yyi
< yystackp
->yytops
.yysize
; yyi
+= 1)
1464 if (yyi
!= yyk
&& yystackp
->yytops
.yystates
[yyi
] != NULL
)
1466 yyGLRState
* yyp
, *yysplit
= yystackp
->yysplitPoint
;
1467 yyp
= yystackp
->yytops
.yystates
[yyi
];
1468 while (yyp
!= yys
&& yyp
!= yysplit
&& yyp
->yyposn
>= yyposn
)
1470 if (yyp
->yylrState
== yynewLRState
&& yyp
->yypred
== yys
)
1472 yyaddDeferredAction (yystackp
, yyp
, yys0
, yyrule
);
1473 yymarkStackDeleted (yystackp
, yyk
);
1474 YYDPRINTF ((stderr
, "Merging stack %lu into stack %lu.\n",
1475 (unsigned long int) yyk
,
1476 (unsigned long int) yyi
));
1482 yystackp
->yytops
.yystates
[yyk
] = yys
;
1483 yyglrShiftDefer (yystackp
, yyk
, yynewLRState
, yyposn
, yys0
, yyrule
);
1489 yysplitStack (yyGLRStack
* yystackp
, size_t yyk
)
1491 if (yystackp
->yysplitPoint
== NULL
)
1493 YYASSERT (yyk
== 0);
1494 yystackp
->yysplitPoint
= yystackp
->yytops
.yystates
[yyk
];
1496 if (yystackp
->yytops
.yysize
>= yystackp
->yytops
.yycapacity
)
1498 yyGLRState
** yynewStates
;
1499 if (! ((yystackp
->yytops
.yycapacity
1500 <= (YYSIZEMAX
/ (2 * sizeof yynewStates
[0])))
1502 (yyGLRState
**) YYREALLOC (yystackp
->yytops
.yystates
,
1503 ((yystackp
->yytops
.yycapacity
*= 2)
1504 * sizeof yynewStates
[0])))))
1505 yyMemoryExhausted (yystackp
);
1506 yystackp
->yytops
.yystates
= yynewStates
;
1508 yystackp
->yytops
.yystates
[yystackp
->yytops
.yysize
]
1509 = yystackp
->yytops
.yystates
[yyk
];
1510 yystackp
->yytops
.yysize
+= 1;
1511 return yystackp
->yytops
.yysize
-1;
1514 /** True iff Y0 and Y1 represent identical options at the top level.
1515 * That is, they represent the same rule applied to RHS symbols
1516 * that produce the same terminal symbols. */
1518 yyidenticalOptions (yySemanticOption
* yyy0
, yySemanticOption
* yyy1
)
1520 if (yyy0
->yyrule
== yyy1
->yyrule
)
1522 yyGLRState
*yys0
, *yys1
;
1524 for (yys0
= yyy0
->yystate
, yys1
= yyy1
->yystate
,
1525 yyn
= yyrhsLength (yyy0
->yyrule
);
1527 yys0
= yys0
->yypred
, yys1
= yys1
->yypred
, yyn
-= 1)
1528 if (yys0
->yyposn
!= yys1
->yyposn
)
1536 /** Assuming identicalOptions (Y0,Y1), destructively merge the
1537 * alternative semantic values for the RHS-symbols of Y1 and Y0. */
1539 yymergeOptionSets (yySemanticOption
* yyy0
, yySemanticOption
* yyy1
)
1541 yyGLRState
*yys0
, *yys1
;
1543 for (yys0
= yyy0
->yystate
, yys1
= yyy1
->yystate
,
1544 yyn
= yyrhsLength (yyy0
->yyrule
);
1546 yys0
= yys0
->yypred
, yys1
= yys1
->yypred
, yyn
-= 1)
1550 else if (yys0
->yyresolved
)
1552 yys1
->yyresolved
= yytrue
;
1553 yys1
->yysemantics
.yysval
= yys0
->yysemantics
.yysval
;
1555 else if (yys1
->yyresolved
)
1557 yys0
->yyresolved
= yytrue
;
1558 yys0
->yysemantics
.yysval
= yys1
->yysemantics
.yysval
;
1562 yySemanticOption
** yyz0p
;
1563 yySemanticOption
* yyz1
;
1564 yyz0p
= &yys0
->yysemantics
.yyfirstVal
;
1565 yyz1
= yys1
->yysemantics
.yyfirstVal
;
1566 while (YYID (yytrue
))
1568 if (yyz1
== *yyz0p
|| yyz1
== NULL
)
1570 else if (*yyz0p
== NULL
)
1575 else if (*yyz0p
< yyz1
)
1577 yySemanticOption
* yyz
= *yyz0p
;
1579 yyz1
= yyz1
->yynext
;
1580 (*yyz0p
)->yynext
= yyz
;
1582 yyz0p
= &(*yyz0p
)->yynext
;
1584 yys1
->yysemantics
.yyfirstVal
= yys0
->yysemantics
.yyfirstVal
;
1589 /** Y0 and Y1 represent two possible actions to take in a given
1590 * parsing state; return 0 if no combination is possible,
1591 * 1 if user-mergeable, 2 if Y0 is preferred, 3 if Y1 is preferred. */
1593 yypreference (yySemanticOption
* y0
, yySemanticOption
* y1
)
1595 yyRuleNum r0
= y0
->yyrule
, r1
= y1
->yyrule
;
1596 int p0
= yydprec
[r0
], p1
= yydprec
[r1
];
1600 if (yymerger
[r0
] == 0 || yymerger
[r0
] != yymerger
[r1
])
1605 if (p0
== 0 || p1
== 0)
1614 static YYRESULTTAG
yyresolveValue (yySemanticOption
* yyoptionList
,
1615 yyGLRStack
* yystackp
, YYSTYPE
* yyvalp
,
1616 YYLTYPE
* yylocp
]b4_user_formals
[);
1619 yyresolveStates (yyGLRState
* yys
, int yyn
,
1620 yyGLRStack
* yystackp
]b4_user_formals
[)
1625 YYASSERT (yys
->yypred
);
1626 yyflag
= yyresolveStates (yys
->yypred
, yyn
-1, yystackp
]b4_user_args
[);
1629 if (! yys
->yyresolved
)
1631 yyflag
= yyresolveValue (yys
->yysemantics
.yyfirstVal
, yystackp
,
1632 &yys
->yysemantics
.yysval
, &yys
->yyloc
1636 yys
->yyresolved
= yytrue
;
1643 yyresolveAction (yySemanticOption
* yyopt
, yyGLRStack
* yystackp
,
1644 YYSTYPE
* yyvalp
, YYLTYPE
* yylocp
]b4_user_formals
[)
1646 yyGLRStackItem yyrhsVals
[YYMAXRHS
+ YYMAXLEFT
+ 1];
1649 yynrhs
= yyrhsLength (yyopt
->yyrule
);
1650 YYCHK (yyresolveStates (yyopt
->yystate
, yynrhs
, yystackp
]b4_user_args
[));
1651 yyrhsVals
[YYMAXRHS
+ YYMAXLEFT
].yystate
.yypred
= yyopt
->yystate
;]b4_location_if([[
1653 /* Set default location. */
1654 yyrhsVals
[YYMAXRHS
+ YYMAXLEFT
- 1].yystate
.yyloc
= yyopt
->yystate
->yyloc
;]])[
1655 return yyuserAction (yyopt
->yyrule
, yynrhs
,
1656 yyrhsVals
+ YYMAXRHS
+ YYMAXLEFT
- 1,
1657 yyvalp
, yylocp
, yystackp
]b4_user_args
[);
1662 yyreportTree (yySemanticOption
* yyx
, int yyindent
)
1664 int yynrhs
= yyrhsLength (yyx
->yyrule
);
1667 yyGLRState
* yystates
[YYMAXRHS
];
1668 yyGLRState yyleftmost_state
;
1670 for (yyi
= yynrhs
, yys
= yyx
->yystate
; 0 < yyi
; yyi
-= 1, yys
= yys
->yypred
)
1671 yystates
[yyi
] = yys
;
1674 yyleftmost_state
.yyposn
= 0;
1675 yystates
[0] = &yyleftmost_state
;
1680 if (yyx
->yystate
->yyposn
< yys
->yyposn
+ 1)
1681 YYFPRINTF (stderr
, "%*s%s -> <Rule %d, empty>\n",
1682 yyindent
, "", yytokenName (yylhsNonterm (yyx
->yyrule
)),
1685 YYFPRINTF (stderr
, "%*s%s -> <Rule %d, tokens %lu .. %lu>\n",
1686 yyindent
, "", yytokenName (yylhsNonterm (yyx
->yyrule
)),
1687 yyx
->yyrule
, (unsigned long int) (yys
->yyposn
+ 1),
1688 (unsigned long int) yyx
->yystate
->yyposn
);
1689 for (yyi
= 1; yyi
<= yynrhs
; yyi
+= 1)
1691 if (yystates
[yyi
]->yyresolved
)
1693 if (yystates
[yyi
-1]->yyposn
+1 > yystates
[yyi
]->yyposn
)
1694 YYFPRINTF (stderr
, "%*s%s <empty>\n", yyindent
+2, "",
1695 yytokenName (yyrhs
[yyprhs
[yyx
->yyrule
]+yyi
-1]));
1697 YYFPRINTF (stderr
, "%*s%s <tokens %lu .. %lu>\n", yyindent
+2, "",
1698 yytokenName (yyrhs
[yyprhs
[yyx
->yyrule
]+yyi
-1]),
1699 (unsigned long int) (yystates
[yyi
- 1]->yyposn
+ 1),
1700 (unsigned long int) yystates
[yyi
]->yyposn
);
1703 yyreportTree (yystates
[yyi
]->yysemantics
.yyfirstVal
, yyindent
+2);
1708 static void yyreportAmbiguity (yySemanticOption
* yyx0
, yySemanticOption
* yyx1
,
1709 yyGLRStack
* yystackp
]b4_pure_formals
[)
1710 __attribute__ ((__noreturn__
));
1712 yyreportAmbiguity (yySemanticOption
* yyx0
, yySemanticOption
* yyx1
,
1713 yyGLRStack
* yystackp
]b4_pure_formals
[)
1719 YYFPRINTF (stderr
, "Ambiguity detected.\n");
1720 YYFPRINTF (stderr
, "Option 1,\n");
1721 yyreportTree (yyx0
, 2);
1722 YYFPRINTF (stderr
, "\nOption 2,\n");
1723 yyreportTree (yyx1
, 2);
1724 YYFPRINTF (stderr
, "\n");
1726 yyFail (yystackp
][]b4_pure_args
[, YY_("syntax is ambiguous"));
1730 /** Resolve the ambiguity represented by OPTIONLIST, perform the indicated
1731 * actions, and return the result. */
1733 yyresolveValue (yySemanticOption
* yyoptionList
, yyGLRStack
* yystackp
,
1734 YYSTYPE
* yyvalp
, YYLTYPE
* yylocp
]b4_user_formals
[)
1736 yySemanticOption
* yybest
;
1737 yySemanticOption
** yypp
;
1740 yybest
= yyoptionList
;
1742 for (yypp
= &yyoptionList
->yynext
; *yypp
!= NULL
; )
1744 yySemanticOption
* yyp
= *yypp
;
1746 if (yyidenticalOptions (yybest
, yyp
))
1748 yymergeOptionSets (yybest
, yyp
);
1749 *yypp
= yyp
->yynext
;
1753 switch (yypreference (yybest
, yyp
))
1756 yyreportAmbiguity (yybest
, yyp
, yystackp
]b4_pure_args
[);
1768 /* This cannot happen so it is not worth a YYASSERT (yyfalse),
1769 but some compilers complain if the default case is
1773 yypp
= &yyp
->yynext
;
1779 yySemanticOption
* yyp
;
1780 int yyprec
= yydprec
[yybest
->yyrule
];
1781 YYCHK (yyresolveAction (yybest
, yystackp
, yyvalp
, yylocp
]b4_user_args
[));
1782 for (yyp
= yybest
->yynext
; yyp
!= NULL
; yyp
= yyp
->yynext
)
1784 if (yyprec
== yydprec
[yyp
->yyrule
])
1788 YYCHK (yyresolveAction (yyp
, yystackp
, &yyval1
,
1789 &yydummy
]b4_user_args
[));
1790 yyuserMerge (yymerger
[yyp
->yyrule
], yyvalp
, &yyval1
);
1796 return yyresolveAction (yybest
, yystackp
, yyvalp
, yylocp
]b4_user_args
[);
1800 yyresolveStack (yyGLRStack
* yystackp
]b4_user_formals
[)
1802 if (yystackp
->yysplitPoint
!= NULL
)
1807 for (yyn
= 0, yys
= yystackp
->yytops
.yystates
[0];
1808 yys
!= yystackp
->yysplitPoint
;
1809 yys
= yys
->yypred
, yyn
+= 1)
1811 YYCHK (yyresolveStates (yystackp
->yytops
.yystates
[0], yyn
, yystackp
1818 yycompressStack (yyGLRStack
* yystackp
)
1820 yyGLRState
* yyp
, *yyq
, *yyr
;
1822 if (yystackp
->yytops
.yysize
!= 1 || yystackp
->yysplitPoint
== NULL
)
1825 for (yyp
= yystackp
->yytops
.yystates
[0], yyq
= yyp
->yypred
, yyr
= NULL
;
1826 yyp
!= yystackp
->yysplitPoint
;
1827 yyr
= yyp
, yyp
= yyq
, yyq
= yyp
->yypred
)
1830 yystackp
->yyspaceLeft
+= yystackp
->yynextFree
- yystackp
->yyitems
;
1831 yystackp
->yynextFree
= ((yyGLRStackItem
*) yystackp
->yysplitPoint
) + 1;
1832 yystackp
->yyspaceLeft
-= yystackp
->yynextFree
- yystackp
->yyitems
;
1833 yystackp
->yysplitPoint
= NULL
;
1834 yystackp
->yylastDeleted
= NULL
;
1838 yystackp
->yynextFree
->yystate
= *yyr
;
1840 yystackp
->yynextFree
->yystate
.yypred
= &yystackp
->yynextFree
[-1].yystate
;
1841 yystackp
->yytops
.yystates
[0] = &yystackp
->yynextFree
->yystate
;
1842 yystackp
->yynextFree
+= 1;
1843 yystackp
->yyspaceLeft
-= 1;
1848 yyprocessOneStack (yyGLRStack
* yystackp
, size_t yyk
,
1849 size_t yyposn
]b4_pure_formals
[)
1852 const short int* yyconflicts
;
1854 yySymbol
* const yytokenp
= yystackp
->yytokenp
;
1856 while (yystackp
->yytops
.yystates
[yyk
] != NULL
)
1858 yyStateNum yystate
= yystackp
->yytops
.yystates
[yyk
]->yylrState
;
1859 YYDPRINTF ((stderr
, "Stack %lu Entering state %d\n",
1860 (unsigned long int) yyk
, yystate
));
1862 YYASSERT (yystate
!= YYFINAL
);
1864 if (yyisDefaultedState (yystate
))
1866 yyrule
= yydefaultAction (yystate
);
1869 YYDPRINTF ((stderr
, "Stack %lu dies.\n",
1870 (unsigned long int) yyk
));
1871 yymarkStackDeleted (yystackp
, yyk
);
1874 YYCHK (yyglrReduce (yystackp
, yyk
, yyrule
, yyfalse
]b4_user_args
[));
1878 if (*yytokenp
== YYEMPTY
)
1880 YYDPRINTF ((stderr
, "Reading a token: "));
1882 *yytokenp
= YYTRANSLATE (yychar
);
1883 YY_SYMBOL_PRINT ("Next token is", *yytokenp
, &yylval
, &yylloc
);
1885 yygetLRActions (yystate
, *yytokenp
, &yyaction
, &yyconflicts
);
1887 while (*yyconflicts
!= 0)
1889 size_t yynewStack
= yysplitStack (yystackp
, yyk
);
1890 YYDPRINTF ((stderr
, "Splitting off stack %lu from %lu.\n",
1891 (unsigned long int) yynewStack
,
1892 (unsigned long int) yyk
));
1893 YYCHK (yyglrReduce (yystackp
, yynewStack
,
1894 *yyconflicts
, yyfalse
]b4_user_args
[));
1895 YYCHK (yyprocessOneStack (yystackp
, yynewStack
,
1896 yyposn
]b4_pure_args
[));
1900 if (yyisShiftAction (yyaction
))
1902 else if (yyisErrorAction (yyaction
))
1904 YYDPRINTF ((stderr
, "Stack %lu dies.\n",
1905 (unsigned long int) yyk
));
1906 yymarkStackDeleted (yystackp
, yyk
);
1910 YYCHK (yyglrReduce (yystackp
, yyk
, -yyaction
,
1911 yyfalse
]b4_user_args
[));
1917 /*ARGSUSED*/ static void
1918 yyreportSyntaxError (yyGLRStack
* yystackp
]b4_user_formals
[)
1920 if (yystackp
->yyerrState
== 0)
1923 yySymbol
* const yytokenp
= yystackp
->yytokenp
;
1925 yyn
= yypact
[yystackp
->yytops
.yystates
[0]->yylrState
];
1926 if (YYPACT_NINF
< yyn
&& yyn
< YYLAST
)
1928 size_t yysize0
= yytnamerr (NULL
, yytokenName (*yytokenp
));
1929 size_t yysize
= yysize0
;
1931 yybool yysize_overflow
= yyfalse
;
1933 enum { YYERROR_VERBOSE_ARGS_MAXIMUM
= 5 };
1934 char const *yyarg
[YYERROR_VERBOSE_ARGS_MAXIMUM
];
1938 static char const yyunexpected
[] = "syntax error, unexpected %s";
1939 static char const yyexpecting
[] = ", expecting %s";
1940 static char const yyor
[] = " or %s";
1941 char yyformat
[sizeof yyunexpected
1942 + sizeof yyexpecting
- 1
1943 + ((YYERROR_VERBOSE_ARGS_MAXIMUM
- 2)
1944 * (sizeof yyor
- 1))];
1945 char const *yyprefix
= yyexpecting
;
1947 /* Start YYX at -YYN if negative to avoid negative indexes in
1949 int yyxbegin
= yyn
< 0 ? -yyn
: 0;
1951 /* Stay within bounds of both yycheck and yytname. */
1952 int yychecklim
= YYLAST
- yyn
;
1953 int yyxend
= yychecklim
< YYNTOKENS
? yychecklim
: YYNTOKENS
;
1956 yyarg
[0] = yytokenName (*yytokenp
);
1957 yyfmt
= yystpcpy (yyformat
, yyunexpected
);
1959 for (yyx
= yyxbegin
; yyx
< yyxend
; ++yyx
)
1960 if (yycheck
[yyx
+ yyn
] == yyx
&& yyx
!= YYTERROR
)
1962 if (yycount
== YYERROR_VERBOSE_ARGS_MAXIMUM
)
1966 yyformat
[sizeof yyunexpected
- 1] = '\0';
1969 yyarg
[yycount
++] = yytokenName (yyx
);
1970 yysize1
= yysize
+ yytnamerr (NULL
, yytokenName (yyx
));
1971 yysize_overflow
|= yysize1
< yysize
;
1973 yyfmt
= yystpcpy (yyfmt
, yyprefix
);
1977 yyf
= YY_(yyformat
);
1978 yysize1
= yysize
+ strlen (yyf
);
1979 yysize_overflow
|= yysize1
< yysize
;
1982 if (!yysize_overflow
)
1983 yymsg
= (char *) YYMALLOC (yysize
);
1989 while ((*yyp
= *yyf
))
1991 if (*yyp
== '%' && yyf
[1] == 's' && yyi
< yycount
)
1993 yyp
+= yytnamerr (yyp
, yyarg
[yyi
++]);
2002 yyerror (]b4_lyyerror_args
[yymsg
);
2007 yyerror (]b4_lyyerror_args
[YY_("syntax error"));
2008 yyMemoryExhausted (yystackp
);
2012 #endif /* YYERROR_VERBOSE */
2013 yyerror (]b4_lyyerror_args
[YY_("syntax error"));
2018 /* Recover from a syntax error on *YYSTACKP, assuming that *YYSTACKP->YYTOKENP,
2019 yylval, and yylloc are the syntactic category, semantic value, and location
2020 of the look-ahead. */
2021 /*ARGSUSED*/ static void
2022 yyrecoverSyntaxError (yyGLRStack
* yystackp
]b4_user_formals
[)
2024 yySymbol
* const yytokenp
= yystackp
->yytokenp
;
2028 if (yystackp
->yyerrState
== 3)
2029 /* We just shifted the error token and (perhaps) took some
2030 reductions. Skip tokens until we can proceed. */
2031 while (YYID (yytrue
))
2033 if (*yytokenp
== YYEOF
)
2034 yyFail (yystackp
][]b4_lpure_args
[, NULL
);
2035 if (*yytokenp
!= YYEMPTY
)
2037 /* We throw away the lookahead, but the error range
2038 of the shifted error token must take it into account. */
2039 yyGLRState
*yys
= yystackp
->yytops
.yystates
[0];
2040 yyGLRStackItem yyerror_range
[3];
2041 yyerror_range
[1].yystate
.yyloc
= yys
->yyloc
;
2042 yyerror_range
[2].yystate
.yyloc
= yylloc
;
2043 YYLLOC_DEFAULT (yys
->yyloc
, yyerror_range
, 2);]])[
2044 yydestruct ("Error: discarding",
2045 *yytokenp
, &yylval
]b4_location_if([, &yylloc
])[]b4_user_args
[);
2047 YYDPRINTF ((stderr
, "Reading a token: "));
2049 *yytokenp
= YYTRANSLATE (yychar
);
2050 YY_SYMBOL_PRINT ("Next token is", *yytokenp
, &yylval
, &yylloc
);
2051 yyj
= yypact
[yystackp
->yytops
.yystates
[0]->yylrState
];
2052 if (yyis_pact_ninf (yyj
))
2055 if (yyj
< 0 || YYLAST
< yyj
|| yycheck
[yyj
] != *yytokenp
)
2057 if (yydefact
[yystackp
->yytops
.yystates
[0]->yylrState
] != 0)
2060 else if (yytable
[yyj
] != 0 && ! yyis_table_ninf (yytable
[yyj
]))
2064 /* Reduce to one stack. */
2065 for (yyk
= 0; yyk
< yystackp
->yytops
.yysize
; yyk
+= 1)
2066 if (yystackp
->yytops
.yystates
[yyk
] != NULL
)
2068 if (yyk
>= yystackp
->yytops
.yysize
)
2069 yyFail (yystackp
][]b4_lpure_args
[, NULL
);
2070 for (yyk
+= 1; yyk
< yystackp
->yytops
.yysize
; yyk
+= 1)
2071 yymarkStackDeleted (yystackp
, yyk
);
2072 yyremoveDeletes (yystackp
);
2073 yycompressStack (yystackp
);
2075 /* Now pop stack until we find a state that shifts the error token. */
2076 yystackp
->yyerrState
= 3;
2077 while (yystackp
->yytops
.yystates
[0] != NULL
)
2079 yyGLRState
*yys
= yystackp
->yytops
.yystates
[0];
2080 yyj
= yypact
[yys
->yylrState
];
2081 if (! yyis_pact_ninf (yyj
))
2084 if (0 <= yyj
&& yyj
<= YYLAST
&& yycheck
[yyj
] == YYTERROR
2085 && yyisShiftAction (yytable
[yyj
]))
2087 /* Shift the error token having adjusted its location. */
2088 YYLTYPE yyerrloc
;]b4_location_if([[
2089 yystackp
->yyerror_range
[2].yystate
.yyloc
= yylloc
;
2090 YYLLOC_DEFAULT (yyerrloc
, yystackp
->yyerror_range
, 2);]])[
2091 YY_SYMBOL_PRINT ("Shifting", yystos
[yytable
[yyj
]],
2092 &yylval
, &yyerrloc
);
2093 yyglrShift (yystackp
, 0, yytable
[yyj
],
2094 yys
->yyposn
, &yylval
, &yyerrloc
);
2095 yys
= yystackp
->yytops
.yystates
[0];
2099 ]b4_location_if([[ yystackp
->yyerror_range
[1].yystate
.yyloc
= yys
->yyloc
;]])[
2100 yydestroyGLRState ("Error: popping", yys
]b4_user_args
[);
2101 yystackp
->yytops
.yystates
[0] = yys
->yypred
;
2102 yystackp
->yynextFree
-= 1;
2103 yystackp
->yyspaceLeft
+= 1;
2105 if (yystackp
->yytops
.yystates
[0] == NULL
)
2106 yyFail (yystackp
][]b4_lpure_args
[, NULL
);
2109 #define YYCHK1(YYE) \
2119 goto yyuser_error; \
2130 ]b4_c_ansi_function_def([yyparse
], [int], b4_parse_param
)[
2135 yyGLRStack
* const yystackp
= &yystack
;
2138 YYDPRINTF ((stderr
, "Starting parse\n"));
2141 yylval
= yyval_default
;
2143 #if YYLTYPE_IS_TRIVIAL
2144 yylloc
.first_line
= yylloc
.last_line
= 1;
2145 yylloc
.first_column
= yylloc
.last_column
= 0;
2148 m4_ifdef([b4_initial_action
], [
2149 m4_pushdef([b4_at_dollar
], [yylloc
])dnl
2150 m4_pushdef([b4_dollar_dollar
], [yylval
])dnl
2151 /* User initialization code. */
2153 m4_popdef([b4_dollar_dollar
])dnl
2154 m4_popdef([b4_at_dollar
])dnl
2155 /* Line __line__ of glr.c. */
2156 b4_syncline([@oline@
], [@ofile@
])])dnl
2158 if (! yyinitGLRStack (yystackp
, YYINITDEPTH
))
2159 goto yyexhaustedlab
;
2160 switch (YYSETJMP (yystack
.yyexception_buffer
))
2163 case 1: goto yyabortlab
;
2164 case 2: goto yyexhaustedlab
;
2165 default: goto yybuglab
;
2167 yystack
.yytokenp
= &yytoken
;
2168 yyglrShift (&yystack
, 0, 0, 0, &yylval
, &yylloc
);
2171 while (YYID (yytrue
))
2173 /* For efficiency, we have two loops, the first of which is
2174 specialized to deterministic operation (single stack, no
2175 potential ambiguity). */
2177 while (YYID (yytrue
))
2181 const short int* yyconflicts
;
2183 yyStateNum yystate
= yystack
.yytops
.yystates
[0]->yylrState
;
2184 YYDPRINTF ((stderr
, "Entering state %d\n", yystate
));
2185 if (yystate
== YYFINAL
)
2187 if (yyisDefaultedState (yystate
))
2189 yyrule
= yydefaultAction (yystate
);
2192 ]b4_location_if([[ yystack
.yyerror_range
[1].yystate
.yyloc
= yylloc
;]])[
2193 yyreportSyntaxError (&yystack
]b4_user_args
[);
2196 YYCHK1 (yyglrReduce (&yystack
, 0, yyrule
, yytrue
]b4_user_args
[));
2200 if (yytoken
== YYEMPTY
)
2202 YYDPRINTF ((stderr
, "Reading a token: "));
2204 yytoken
= YYTRANSLATE (yychar
);
2205 YY_SYMBOL_PRINT ("Next token is", yytoken
, &yylval
, &yylloc
);
2207 yygetLRActions (yystate
, yytoken
, &yyaction
, &yyconflicts
);
2208 if (*yyconflicts
!= 0)
2210 if (yyisShiftAction (yyaction
))
2212 YY_SYMBOL_PRINT ("Shifting", yytoken
, &yylval
, &yylloc
);
2213 if (yytoken
!= YYEOF
)
2216 yyglrShift (&yystack
, 0, yyaction
, yyposn
, &yylval
, &yylloc
);
2217 if (0 < yystack
.yyerrState
)
2218 yystack
.yyerrState
-= 1;
2220 else if (yyisErrorAction (yyaction
))
2222 ]b4_location_if([[ yystack
.yyerror_range
[1].yystate
.yyloc
= yylloc
;]])[
2223 yyreportSyntaxError (&yystack
]b4_user_args
[);
2227 YYCHK1 (yyglrReduce (&yystack
, 0, -yyaction
, yytrue
]b4_user_args
[));
2231 while (YYID (yytrue
))
2233 yySymbol yytoken_to_shift
;
2235 size_t yyn
= yystack
.yytops
.yysize
;
2237 /* yyprocessOneStack returns one of three things:
2239 - An error flag. If the caller is yyprocessOneStack, it
2240 immediately returns as well. When the caller is finally
2241 yyparse, it jumps to an error label via YYCHK1.
2243 - yyok, but yyprocessOneStack has invoked yymarkStackDeleted
2244 (&yystack, yys), which sets the top state of yys to NULL. Thus,
2245 yyparse's following invocation of yyremoveDeletes will remove
2248 - yyok, when ready to shift a token.
2250 Except in the first case, yyparse will invoke yyremoveDeletes and
2251 then shift the next token onto all remaining stacks. This
2252 synchronization of the shift (that is, after all preceding
2253 reductions on all stacks) helps prevents double destructor calls
2254 on yylval in the event of memory exhaustion. */
2256 for (yys
= 0; yys
< yyn
; yys
+= 1)
2257 YYCHK1 (yyprocessOneStack (&yystack
, yys
, yyposn
]b4_lpure_args
[));
2258 yyremoveDeletes (&yystack
);
2259 yyn
= yystack
.yytops
.yysize
;
2261 /* If any yyglrShift call fails, it will fail after shifting. Thus,
2262 a copy of yylval will already be on stack 0 in the event of a
2263 failure in the following loop. Thus, yytoken is set to YYEMPTY
2264 before the loop to make sure the user destructor for yylval isn't
2266 yytoken_to_shift
= yytoken
;
2269 for (yys
= 0; yys
< yyn
; yys
+= 1)
2272 const short int* yyconflicts
;
2273 yyStateNum yystate
= yystack
.yytops
.yystates
[yys
]->yylrState
;
2274 yygetLRActions (yystate
, yytoken_to_shift
, &yyaction
,
2276 /* Note that yyconflicts were handled by yyprocessOneStack. */
2277 YYDPRINTF ((stderr
, "On stack %lu, ", (unsigned long int) yys
));
2278 YY_SYMBOL_PRINT ("shifting", yytoken_to_shift
, &yylval
, &yylloc
);
2279 yyglrShift (&yystack
, yys
, yyaction
, yyposn
,
2281 YYDPRINTF ((stderr
, "Stack %lu now in state #%d\n",
2282 (unsigned long int) yys
,
2283 yystack
.yytops
.yystates
[yys
]->yylrState
));
2285 if (yystack
.yytops
.yysize
== 0)
2287 yyundeleteLastStack (&yystack
);
2288 if (yystack
.yytops
.yysize
== 0)
2289 yyFail (&yystack
][]b4_lpure_args
[, YY_("syntax error"));
2290 YYCHK1 (yyresolveStack (&yystack
]b4_user_args
[));
2291 YYDPRINTF ((stderr
, "Returning to deterministic operation.\n"));
2292 ]b4_location_if([[ yystack
.yyerror_range
[1].yystate
.yyloc
= yylloc
;]])[
2293 yyreportSyntaxError (&yystack
]b4_user_args
[);
2296 else if (yystack
.yytops
.yysize
== 1)
2298 YYCHK1 (yyresolveStack (&yystack
]b4_user_args
[));
2299 YYDPRINTF ((stderr
, "Returning to deterministic operation.\n"));
2300 yycompressStack (&yystack
);
2306 yyrecoverSyntaxError (&yystack
]b4_user_args
[);
2307 yyposn
= yystack
.yytops
.yystates
[0]->yyposn
;
2323 yyerror (]b4_lyyerror_args
[YY_("memory exhausted"));
2328 if (yytoken
!= YYEOF
&& yytoken
!= YYEMPTY
)
2329 yydestruct ("Cleanup: discarding lookahead",
2330 yytoken
, &yylval
]b4_location_if([, &yylloc
])[]b4_user_args
[);
2332 /* If the stack is well-formed, pop the stack until it is empty,
2333 destroying its entries as we go. But free the stack regardless
2334 of whether it is well-formed. */
2335 if (yystack
.yyitems
)
2337 yyGLRState
** yystates
= yystack
.yytops
.yystates
;
2340 size_t yysize
= yystack
.yytops
.yysize
;
2342 for (yyk
= 0; yyk
< yysize
; yyk
+= 1)
2345 while (yystates
[yyk
])
2347 yyGLRState
*yys
= yystates
[yyk
];
2348 ]b4_location_if([[ yystack
.yyerror_range
[1].yystate
.yyloc
= yys
->yyloc
;]]
2349 )[ yydestroyGLRState ("Cleanup: popping", yys
]b4_user_args
[);
2350 yystates
[yyk
] = yys
->yypred
;
2351 yystack
.yynextFree
-= 1;
2352 yystack
.yyspaceLeft
+= 1;
2357 yyfreeGLRStack (&yystack
);
2363 /* DEBUGGING ONLY */
2365 static void yypstack (yyGLRStack
* yystackp
, size_t yyk
)
2366 __attribute__ ((__unused__
));
2367 static void yypdumpstack (yyGLRStack
* yystackp
) __attribute__ ((__unused__
));
2370 yy_yypstack (yyGLRState
* yys
)
2374 yy_yypstack (yys
->yypred
);
2375 fprintf (stderr
, " -> ");
2377 fprintf (stderr
, "%d@@%lu", yys
->yylrState
, (unsigned long int) yys
->yyposn
);
2381 yypstates (yyGLRState
* yyst
)
2384 fprintf (stderr
, "<null>");
2387 fprintf (stderr
, "\n");
2391 yypstack (yyGLRStack
* yystackp
, size_t yyk
)
2393 yypstates (yystackp
->yytops
.yystates
[yyk
]);
2396 #define YYINDEX(YYX) \
2397 ((YYX) == NULL ? -1 : (yyGLRStackItem*) (YYX) - yystackp->yyitems)
2401 yypdumpstack (yyGLRStack
* yystackp
)
2403 yyGLRStackItem
* yyp
;
2405 for (yyp
= yystackp
->yyitems
; yyp
< yystackp
->yynextFree
; yyp
+= 1)
2407 fprintf (stderr
, "%3lu. ", (unsigned long int) (yyp
- yystackp
->yyitems
));
2408 if (*(yybool
*) yyp
)
2410 fprintf (stderr
, "Res: %d, LR State: %d, posn: %lu, pred: %ld",
2411 yyp
->yystate
.yyresolved
, yyp
->yystate
.yylrState
,
2412 (unsigned long int) yyp
->yystate
.yyposn
,
2413 (long int) YYINDEX (yyp
->yystate
.yypred
));
2414 if (! yyp
->yystate
.yyresolved
)
2415 fprintf (stderr
, ", firstVal: %ld",
2416 (long int) YYINDEX (yyp
->yystate
.yysemantics
.yyfirstVal
));
2420 fprintf (stderr
, "Option. rule: %d, state: %ld, next: %ld",
2421 yyp
->yyoption
.yyrule
,
2422 (long int) YYINDEX (yyp
->yyoption
.yystate
),
2423 (long int) YYINDEX (yyp
->yyoption
.yynext
));
2425 fprintf (stderr
, "\n");
2427 fprintf (stderr
, "Tops:");
2428 for (yyi
= 0; yyi
< yystackp
->yytops
.yysize
; yyi
+= 1)
2429 fprintf (stderr
, "%lu: %ld; ", (unsigned long int) yyi
,
2430 (long int) YYINDEX (yystackp
->yytops
.yystates
[yyi
]));
2431 fprintf (stderr
, "\n");
2437 m4_if(b4_defines_flag
, 0, [],
2438 [@output @output_header_name@
2439 b4_copyright([Skeleton parser
for GLR parsing with Bison
],
2440 [2002, 2003, 2004, 2005, 2006])[
2442 /* C GLR parser skeleton written by Paul Hilfinger. */
2445 b4_shared_declarations
2447 extern YYSTYPE b4_prefix
[]lval
;
2449 b4_location_if([b4_pure_if([],
2450 [extern YYLTYPE b4_prefix
[]lloc
;])