1 m4_divert(-1) -*- C
-*-
3 # GLR skeleton for Bison
4 # Copyright (C) 2002, 2003, 2004, 2005 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 ## ---------------- ##
24 ## ---------------- ##
27 m4_define_default([b4_stack_depth_max
], [10000])
28 m4_define_default([b4_stack_depth_init
], [200])
32 ## ------------------------ ##
33 ## Pure/impure interfaces. ##
34 ## ------------------------ ##
39 # The possible parse-params formal arguments preceded by a comma.
41 # This is not shared with yacc.c in c.m4 because GLR relies on ISO C
42 # formal argument declarations.
43 m4_define([b4_user_formals
],
44 [m4_ifset([b4_parse_param
], [, b4_c_ansi_formals(b4_parse_param
)])])
49 # Accumule in b4_lex_param all the yylex arguments.
50 # Yes, this is quite ugly...
51 m4_define([b4_lex_param
],
52 m4_dquote(b4_pure_if([[[[YYSTYPE
*]], [[&yylval
]]][]dnl
53 b4_location_if([, [[YYLTYPE
*], [&yylloc
]]])])dnl
54 m4_ifdef([b4_lex_param
], [, ]b4_lex_param
)))
59 # Optional effective arguments passed to yyerror: user args plus yylloc, and
61 m4_define([b4_yyerror_args
],
62 [b4_pure_if([b4_location_if([yylocp
, ])])dnl
63 m4_ifset([b4_parse_param
], [b4_c_args(b4_parse_param
), ])])
68 # Same as above, but on the look-ahead, hence &yylloc instead of yylocp.
69 m4_define([b4_lyyerror_args
],
70 [b4_pure_if([b4_location_if([&yylloc
, ])])dnl
71 m4_ifset([b4_parse_param
], [b4_c_args(b4_parse_param
), ])])
76 # Same as b4_yyerror_args, but with a leading comma.
77 m4_define([b4_pure_args
],
78 [b4_pure_if([b4_location_if([, yylocp
])])[]b4_user_args
])
83 # Same as above, but on the look-ahead, hence &yylloc instead of yylocp.
84 m4_define([b4_lpure_args
],
85 [b4_pure_if([b4_location_if([, &yylloc
])])[]b4_user_args
])
90 # Arguments passed to yyerror: user formals plus yylocp.
91 m4_define([b4_pure_formals
],
92 [b4_pure_if([b4_location_if([, YYLTYPE
*yylocp
])])[]b4_user_formals
])
97 # Same as above, but on the look-ahead, hence yyllocp instead of yylocp.
98 m4_define([b4_lpure_formals
],
99 [b4_pure_if([b4_location_if([YYLTYPE
*yyllocp
])])[]b4_user_formals
])
102 ## ----------------- ##
103 ## Semantic Values. ##
104 ## ----------------- ##
107 # b4_lhs_value([TYPE])
108 # --------------------
109 # Expansion of $<TYPE>$.
110 m4_define([b4_lhs_value
],
111 [((*yyvalp
)[]m4_ifval([$
1], [.$
1]))])
114 # b4_rhs_value(RULE-LENGTH, NUM, [TYPE])
115 # --------------------------------------
116 # Expansion of $<TYPE>NUM, where the current rule has RULE-LENGTH
118 m4_define([b4_rhs_value
],
119 [(((yyGLRStackItem
const *)yyvsp
)@
{YYFILL (($
2) - ($
1))@
}.yystate
.yysemantics
.yysval
[]m4_ifval([$
3], [.$
3]))])
130 m4_define([b4_lhs_location
],
134 # b4_rhs_location(RULE-LENGTH, NUM)
135 # ---------------------------------
136 # Expansion of @NUM, where the current rule has RULE-LENGTH symbols
138 m4_define([b4_rhs_location
],
139 [(((yyGLRStackItem
const *)yyvsp
)@
{YYFILL (($
2) - ($
1))@
}.yystate
.yyloc
)])
147 # We do want M4 expansion after # for CPP macros.
150 @output @output_parser_name@
151 b4_copyright([Skeleton parser
for GLR parsing with Bison
],
152 [2002, 2003, 2004, 2005])
154 /* This is the parser code for GLR (Generalized LR) parser. */
158 m4_if(b4_prefix
[], [yy
], [],
159 [/* Substitute the variable and function names. */
160 #define yyparse b4_prefix[]parse
161 #define yylex b4_prefix[]lex
162 #define yyerror b4_prefix[]error
163 #define yylval b4_prefix[]lval
164 #define yychar b4_prefix[]char
165 #define yydebug b4_prefix[]debug
166 #define yynerrs b4_prefix[]nerrs
167 #define yylloc b4_prefix[]lloc])
169 dnl
# b4_shared_declarations
170 dnl
# ----------------------
171 dnl
# Declaration that might either go into the header (if --defines)
172 dnl
# or open coded in the parser body.
173 m4_define([b4_shared_declarations
],
174 [b4_token_enums(b4_tokens
)[
176 /* Copy the first part of user declarations. */
179 #if ! defined (YYSTYPE) && ! defined (YYSTYPE_IS_DECLARED)
180 ]m4_ifdef([b4_stype
],
181 [b4_syncline([b4_stype_line
], [b4_file_name
])
182 typedef union m4_bregexp(b4_stype
, [^{], [YYSTYPE
])b4_stype YYSTYPE
;
183 /* Line __line__ of glr.c. */
184 b4_syncline([@oline@
], [@ofile@
])],
185 [typedef int YYSTYPE
;])[
186 # define YYSTYPE_IS_DECLARED 1
187 # define YYSTYPE_IS_TRIVIAL 1
190 #if ! defined (YYLTYPE) && ! defined (YYLTYPE_IS_DECLARED)
191 typedef struct YYLTYPE
202 # define YYLTYPE_IS_DECLARED 1
203 # define YYLTYPE_IS_TRIVIAL 1
207 m4_if(b4_defines_flag
, 0,
208 [b4_shared_declarations
],
209 [#include @output_header_name@])[
211 /* Enabling traces. */
213 # define YYDEBUG ]b4_debug[
216 /* Enabling verbose error messages. */
217 #ifdef YYERROR_VERBOSE
218 # undef YYERROR_VERBOSE
219 # define YYERROR_VERBOSE 1
221 # define YYERROR_VERBOSE ]b4_error_verbose[
224 /* Enabling the token table. */
225 #ifndef YYTOKEN_TABLE
226 # define YYTOKEN_TABLE ]b4_token_table[
229 /* Default (constant) value used for initialization for null
230 right-hand sides. Unlike the standard yacc.c template,
231 here we set the default value of $$ to a zeroed-out value.
232 Since the default value is undefined, this behavior is
233 technically correct. */
234 static YYSTYPE yyval_default
;
236 /* Copy the second part of user declarations. */
239 ]/* Line __line__ of glr.c. */
240 b4_syncline([@oline@
], [@ofile@
])
250 # include <libintl.h> /* INFRINGES ON USER NAME SPACE */
251 # define YY_(msgid) dgettext ("bison-runtime", msgid)
255 # define YY_(msgid) msgid
259 /* Suppress unused-variable warnings by "using" E. */
261 # define YYUSE(e) ((void) (e))
263 # define YYUSE(e) /* empty */
266 /* Identity function, used to suppress warnings about constant conditions. */
270 ]b4_c_function_def([YYID
], [static int], [[int i
], [i
]])[
280 # define YYMALLOC malloc
283 # define YYREALLOC realloc
286 #define YYSIZEMAX ((size_t) -1)
291 typedef unsigned char yybool
;
298 # define YYJMP_BUF jmp_buf
299 # define YYSETJMP(env) setjmp (env)
300 # define YYLONGJMP(env, val) longjmp (env, val)
307 #ifndef __attribute__
308 /* This feature is available in gcc versions 2.5 and later. */
309 # if (!defined (__GNUC__) || __GNUC__ < 2 \
310 || (__GNUC__ == 2 && __GNUC_MINOR__ < 5) || __STRICT_ANSI__)
311 # define __attribute__(Spec) /* empty */
315 ]b4_location_if([#define YYOPTIONAL_LOC(Name) Name],[
317 # define YYOPTIONAL_LOC(Name) /* empty */
319 # define YYOPTIONAL_LOC(Name) Name __attribute__ ((__unused__))
323 # define YYASSERT(condition) ((void) ((condition) || (abort (), 0)))
326 /* YYFINAL -- State number of the termination state. */
327 #define YYFINAL ]b4_final_state_number[
328 /* YYLAST -- Last index in YYTABLE. */
329 #define YYLAST ]b4_last[
331 /* YYNTOKENS -- Number of terminals. */
332 #define YYNTOKENS ]b4_tokens_number[
333 /* YYNNTS -- Number of nonterminals. */
334 #define YYNNTS ]b4_nterms_number[
335 /* YYNRULES -- Number of rules. */
336 #define YYNRULES ]b4_rules_number[
337 /* YYNRULES -- Number of states. */
338 #define YYNSTATES ]b4_states_number[
339 /* YYMAXRHS -- Maximum number of symbols on right-hand side of rule. */
340 #define YYMAXRHS ]b4_r2_max[
341 /* YYMAXLEFT -- Maximum number of symbols to the left of a handle
342 accessed by $0, $-1, etc., in any rule. */
343 #define YYMAXLEFT ]b4_max_left_semantic_context[
345 /* YYTRANSLATE(X) -- Bison symbol number corresponding to X. */
346 #define YYUNDEFTOK ]b4_undef_token_number[
347 #define YYMAXUTOK ]b4_user_token_number_max[
349 #define YYTRANSLATE(YYX) \
350 ((YYX <= 0) ? YYEOF : \
351 (unsigned int) (YYX) <= YYMAXUTOK ? yytranslate[YYX] : YYUNDEFTOK)
353 /* YYTRANSLATE[YYLEX] -- Bison symbol number corresponding to YYLEX. */
354 static const ]b4_int_type_for([b4_translate
])[ yytranslate
[] =
360 /* YYPRHS[YYN] -- Index of the first RHS symbol of rule number YYN in
362 static const ]b4_int_type_for([b4_prhs
])[ yyprhs
[] =
367 /* YYRHS -- A `-1'-separated list of the rules' RHS. */
368 static const ]b4_int_type_for([b4_rhs
])[ yyrhs
[] =
373 /* YYRLINE[YYN] -- source line where rule number YYN was defined. */
374 static const ]b4_int_type_for([b4_rline
])[ yyrline
[] =
380 #if YYDEBUG || YYERROR_VERBOSE || YYTOKEN_TABLE
381 /* YYTNAME[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM.
382 First, the terminals, then, starting at YYNTOKENS, nonterminals. */
383 static const char *const yytname
[] =
389 /* YYR1[YYN] -- Symbol number of symbol that rule YYN derives. */
390 static const ]b4_int_type_for([b4_r1
])[ yyr1
[] =
395 /* YYR2[YYN] -- Number of symbols composing right hand side of rule YYN. */
396 static const ]b4_int_type_for([b4_r2
])[ yyr2
[] =
401 /* YYDPREC[RULE-NUM] -- Dynamic precedence of rule #RULE-NUM (0 if none). */
402 static const ]b4_int_type_for([b4_dprec
])[ yydprec
[] =
407 /* YYMERGER[RULE-NUM] -- Index of merging function for rule #RULE-NUM. */
408 static const ]b4_int_type_for([b4_merger
])[ yymerger
[] =
413 /* YYDEFACT[S] -- default rule to reduce with in state S when YYTABLE
414 doesn't specify something else to do. Zero means the default is an
416 static const ]b4_int_type_for([b4_defact
])[ yydefact
[] =
421 /* YYPDEFGOTO[NTERM-NUM]. */
422 static const ]b4_int_type_for([b4_defgoto
])[ yydefgoto
[] =
427 /* YYPACT[STATE-NUM] -- Index in YYTABLE of the portion describing
429 #define YYPACT_NINF ]b4_pact_ninf[
430 static const ]b4_int_type_for([b4_pact
])[ yypact
[] =
435 /* YYPGOTO[NTERM-NUM]. */
436 static const ]b4_int_type_for([b4_pgoto
])[ yypgoto
[] =
441 /* YYTABLE[YYPACT[STATE-NUM]]. What to do in state STATE-NUM. If
442 positive, shift that token. If negative, reduce the rule which
443 number is the opposite. If zero, do what YYDEFACT says.
444 If YYTABLE_NINF, syntax error. */
445 #define YYTABLE_NINF ]b4_table_ninf[
446 static const ]b4_int_type_for([b4_table
])[ yytable
[] =
451 /* YYCONFLP[YYPACT[STATE-NUM]] -- Pointer into YYCONFL of start of
452 list of conflicting reductions corresponding to action entry for
453 state STATE-NUM in yytable. 0 means no conflicts. The list in
454 yyconfl is terminated by a rule number of 0. */
455 static const ]b4_int_type_for([b4_conflict_list_heads
])[ yyconflp
[] =
457 ]b4_conflict_list_heads
[
460 /* YYCONFL[I] -- lists of conflicting rule numbers, each terminated by
461 0, pointed into by YYCONFLP. */
462 ]dnl Do
not use b4_int_type_for here
, since there are places where
463 dnl pointers onto yyconfl are taken
, which type is
"short int *".
464 dnl We probably ought to introduce a type
for confl
.
465 [static const short int yyconfl
[] =
467 ]b4_conflicting_rules
[
470 static const ]b4_int_type_for([b4_check
])[ yycheck
[] =
475 /* YYSTOS[STATE-NUM] -- The (internal number of the) accessing
476 symbol of state STATE-NUM. */
477 static const ]b4_int_type_for([b4_stos
])[ yystos
[] =
483 /* Prevent warning if -Wmissing-prototypes. */
484 ]b4_c_ansi_function_decl([yyparse
], [int], b4_parse_param
)[
486 /* Error token number */
489 /* YYLLOC_DEFAULT -- Set CURRENT to span from RHS[1] to RHS[N].
490 If N is 0, then set CURRENT to the empty location which ends
491 the previous symbol: RHS[0] (always defined). */
494 #define YYRHSLOC(Rhs, K) ((Rhs)[K].yystate.yyloc)
495 #ifndef YYLLOC_DEFAULT
496 # define YYLLOC_DEFAULT(Current, Rhs, N) \
500 (Current).first_line = YYRHSLOC (Rhs, 1).first_line; \
501 (Current).first_column = YYRHSLOC (Rhs, 1).first_column; \
502 (Current).last_line = YYRHSLOC (Rhs, N).last_line; \
503 (Current).last_column = YYRHSLOC (Rhs, N).last_column; \
507 (Current).first_line = (Current).last_line = \
508 YYRHSLOC (Rhs, 0).last_line; \
509 (Current).first_column = (Current).last_column = \
510 YYRHSLOC (Rhs, 0).last_column; \
514 /* YY_LOCATION_PRINT -- Print the location on the stream.
515 This macro was not mandated originally: define only if we know
516 we won't break user code: when these are the locations we know. */
518 # define YY_LOCATION_PRINT(File, Loc) \
519 fprintf (File, "%d.%d-%d.%d", \
520 (Loc).first_line, (Loc).first_column, \
521 (Loc).last_line, (Loc).last_column)
524 #ifndef YYLLOC_DEFAULT
525 # define YYLLOC_DEFAULT(Current, Rhs, N) ((void) 0)
529 #ifndef YY_LOCATION_PRINT
530 # define YY_LOCATION_PRINT(File, Loc) ((void) 0)
534 /* YYLEX -- calling `yylex' with the right arguments. */
535 #define YYLEX ]b4_c_function_call([yylex], [int], b4_lex_param)[
540 #define yynerrs (yystackp->yyerrcnt)
542 #define yychar (yystackp->yyrawchar)
544 #define yylval (yystackp->yyval)
546 #define yylloc (yystackp->yyloc)
547 m4_if(b4_prefix
[], [yy
], [],
548 [#define b4_prefix[]nerrs yynerrs
549 #define b4_prefix[]char yychar
550 #define b4_prefix[]lval yylval
551 #define b4_prefix[]lloc yylloc])],
559 static const int YYEOF
= 0;
560 static const int YYEMPTY
= -2;
562 typedef enum { yyok
, yyaccept
, yyabort
, yyerr
} YYRESULTTAG
;
565 do { YYRESULTTAG yyflag = YYE; if (yyflag != yyok) return yyflag; } \
570 #if ! defined (YYFPRINTF)
571 # define YYFPRINTF fprintf
574 # define YYDPRINTF(Args) \
580 ]b4_yysymprint_generate([b4_c_ansi_function_def
])[
582 # define YY_SYMBOL_PRINT(Title, Type, Value, Location) \
586 YYFPRINTF (stderr, "%s ", Title); \
587 yysymprint (stderr, \
588 Type, Value]b4_location_if([, Location])[]b4_user_args[); \
589 YYFPRINTF (stderr, "\n"); \
593 /* Nonzero means print parse trace. It is left uninitialized so that
594 multiple parsers can coexist. */
599 # define YYDPRINTF(Args)
600 # define YY_SYMBOL_PRINT(Title, Type, Value, Location)
602 #endif /* !YYDEBUG */
604 /* YYINITDEPTH -- initial size of the parser's stacks. */
606 # define YYINITDEPTH ]b4_stack_depth_init[
609 /* YYMAXDEPTH -- maximum size the stacks can grow to (effective only
610 if the built-in stack extension method is used).
612 Do not make this value too large; the results are undefined if
613 SIZE_MAX < YYMAXDEPTH * sizeof (GLRStackItem)
614 evaluated with infinite-precision integer arithmetic. */
617 # define YYMAXDEPTH ]b4_stack_depth_max[
620 /* Minimum number of free items on the stack allowed after an
621 allocation. This is to allow allocation and initialization
622 to be completed by functions that call yyexpandGLRStack before the
623 stack is expanded, thus insuring that all necessary pointers get
624 properly redirected to new data. */
627 #ifndef YYSTACKEXPANDABLE
628 # if (! defined (__cplusplus) \
629 || (]b4_location_if([[defined (YYLTYPE_IS_TRIVIAL) && YYLTYPE_IS_TRIVIAL \
630 && ]])[defined (YYSTYPE_IS_TRIVIAL) && YYSTYPE_IS_TRIVIAL))
631 # define YYSTACKEXPANDABLE 1
633 # define YYSTACKEXPANDABLE 0
637 #if YYSTACKEXPANDABLE
638 # define YY_RESERVE_GLRSTACK(Yystack) \
640 if (Yystack->yyspaceLeft < YYHEADROOM) \
641 yyexpandGLRStack (Yystack); \
644 # define YY_RESERVE_GLRSTACK(Yystack) \
646 if (Yystack->yyspaceLeft < YYHEADROOM) \
647 yyMemoryExhausted (Yystack); \
655 # if defined (__GLIBC__) && defined (_STRING_H) && defined (_GNU_SOURCE)
656 # define yystpcpy stpcpy
658 /* Copy YYSRC to YYDEST, returning the address of the terminating '\0' in
661 yystpcpy (char *yydest
, const char *yysrc
)
664 const char *yys
= yysrc
;
666 while ((*yyd
++ = *yys
++) != '\0')
675 /* Copy to YYRES the contents of YYSTR after stripping away unnecessary
676 quotes and backslashes, so that it's suitable for yyerror. The
677 heuristic is that double-quoting is unnecessary unless the string
678 contains an apostrophe, a comma, or backslash (other than
679 backslash-backslash). YYSTR is taken from yytname. If YYRES is
680 null, do not copy; instead, return the length of what the result
683 yytnamerr (char *yyres
, const char *yystr
)
688 char const *yyp
= yystr
;
695 goto do_not_strip_quotes
;
699 goto do_not_strip_quotes
;
712 do_not_strip_quotes
: ;
716 return strlen (yystr
);
718 return yystpcpy (yyres
, yystr
) - yyres
;
722 #endif /* !YYERROR_VERBOSE */
724 /** State numbers, as in LALR(1) machine */
725 typedef int yyStateNum
;
727 /** Rule numbers, as in LALR(1) machine */
728 typedef int yyRuleNum
;
730 /** Grammar symbol */
731 typedef short int yySymbol
;
733 /** Item references, as in LALR(1) machine */
734 typedef short int yyItemNum
;
736 typedef struct yyGLRState yyGLRState
;
737 typedef struct yyGLRStateSet yyGLRStateSet
;
738 typedef struct yySemanticOption yySemanticOption
;
739 typedef union yyGLRStackItem yyGLRStackItem
;
740 typedef struct yyGLRStack yyGLRStack
;
743 /** Type tag: always true. */
745 /** Type tag for yysemantics. If true, yysval applies, otherwise
746 * yyfirstVal applies. */
748 /** Number of corresponding LALR(1) machine state. */
749 yyStateNum yylrState
;
750 /** Preceding state in this stack */
752 /** Source position of the first token produced by my symbol */
755 /** First in a chain of alternative reductions producing the
756 * non-terminal corresponding to this state, threaded through
758 yySemanticOption
* yyfirstVal
;
759 /** Semantic value for this state. */
762 /** Source location for this state. */
766 struct yyGLRStateSet
{
767 yyGLRState
** yystates
;
768 size_t yysize
, yycapacity
;
771 struct yySemanticOption
{
772 /** Type tag: always false. */
774 /** Rule number for this reduction */
776 /** The last RHS state in the list of states to be reduced. */
778 /** Next sibling in chain of options. To facilitate merging,
779 * options are chained in decreasing order by address. */
780 yySemanticOption
* yynext
;
783 /** Type of the items in the GLR stack. The yyisState field
784 * indicates which item of the union is valid. */
785 union yyGLRStackItem
{
787 yySemanticOption yyoption
;
792 ]b4_location_if([[ /* To compute the location of the error token. */
793 yyGLRStackItem yyerror_range
[3];]])[
802 YYJMP_BUF yyexception_buffer
;
803 yyGLRStackItem
* yyitems
;
804 yyGLRStackItem
* yynextFree
;
806 yyGLRState
* yysplitPoint
;
807 yyGLRState
* yylastDeleted
;
808 yyGLRStateSet yytops
;
811 #if YYSTACKEXPANDABLE
812 static void yyexpandGLRStack (yyGLRStack
* yystackp
);
815 static void yyFail (yyGLRStack
* yystackp
]b4_pure_formals
[, const char* yymsg
)
816 __attribute__ ((__noreturn__
));
818 yyFail (yyGLRStack
* yystackp
]b4_pure_formals
[, const char* yymsg
)
821 yyerror (]b4_yyerror_args
[yymsg
);
822 YYLONGJMP (yystackp
->yyexception_buffer
, 1);
825 static void yyMemoryExhausted (yyGLRStack
* yystackp
)
826 __attribute__ ((__noreturn__
));
828 yyMemoryExhausted (yyGLRStack
* yystackp
)
830 YYLONGJMP (yystackp
->yyexception_buffer
, 2);
833 #if YYDEBUG || YYERROR_VERBOSE
834 /** A printable representation of TOKEN. */
835 static inline const char*
836 yytokenName (yySymbol yytoken
)
838 if (yytoken
== YYEMPTY
)
841 return yytname
[yytoken
];
845 /** Fill in YYVSP[YYLOW1 .. YYLOW0-1] from the chain of states starting
846 * at YYVSP[YYLOW0].yystate.yypred. Leaves YYVSP[YYLOW1].yystate.yypred
847 * containing the pointer to the next state in the chain. */
848 static void yyfillin (yyGLRStackItem
*, int, int) __attribute__ ((__unused__
));
850 yyfillin (yyGLRStackItem
*yyvsp
, int yylow0
, int yylow1
)
854 s
= yyvsp
[yylow0
].yystate
.yypred
;
855 for (i
= yylow0
-1; i
>= yylow1
; i
-= 1)
857 YYASSERT (s
->yyresolved
);
858 yyvsp
[i
].yystate
.yyresolved
= yytrue
;
859 yyvsp
[i
].yystate
.yysemantics
.yysval
= s
->yysemantics
.yysval
;
860 yyvsp
[i
].yystate
.yyloc
= s
->yyloc
;
861 s
= yyvsp
[i
].yystate
.yypred
= s
->yypred
;
865 /* Do nothing if YYNORMAL or if *YYLOW <= YYLOW1. Otherwise, fill in
866 * YYVSP[YYLOW1 .. *YYLOW-1] as in yyfillin and set *YYLOW = YYLOW1.
867 * For convenience, always return YYLOW1. */
868 static inline int yyfill (yyGLRStackItem
*, int *, int, yybool
)
869 __attribute__ ((__unused__
));
871 yyfill (yyGLRStackItem
*yyvsp
, int *yylow
, int yylow1
, yybool yynormal
)
873 if (!yynormal
&& yylow1
< *yylow
)
875 yyfillin (yyvsp
, *yylow
, yylow1
);
881 /** Perform user action for rule number YYN, with RHS length YYRHSLEN,
882 * and top stack item YYVSP. YYLVALP points to place to put semantic
883 * value ($$), and yylocp points to place for location information
884 * (@@$). Returns yyok for normal return, yyaccept for YYACCEPT,
885 * yyerr for YYERROR, yyabort for YYABORT. */
886 /*ARGSUSED*/ static YYRESULTTAG
887 yyuserAction (yyRuleNum yyn
, int yyrhslen
, yyGLRStackItem
* yyvsp
,
889 YYLTYPE
* YYOPTIONAL_LOC (yylocp
),
893 yybool yynormal
__attribute__ ((__unused__
)) =
894 (yystackp
->yysplitPoint
== NULL
);
896 ]b4_parse_param_use
[]dnl
898 # define yyerrok (yystackp->yyerrState = 0)
900 # define YYACCEPT return yyaccept
902 # define YYABORT return yyabort
904 # define YYERROR return yyerrok, yyerr
906 # define YYRECOVERING (yystackp->yyerrState != 0)
908 # define yyclearin (yychar = *(yystackp->yytokenp) = YYEMPTY)
910 # define YYFILL(N) yyfill (yyvsp, &yylow, N, yynormal)
912 # define YYBACKUP(Token, Value) \
913 return yyerror (]b4_yyerror_args[YY_("syntax error: cannot back up")), \
918 *yyvalp
= yyval_default
;
920 *yyvalp
= yyvsp
[YYFILL (1-yyrhslen
)].yystate
.yysemantics
.yysval
;
921 YYLLOC_DEFAULT (*yylocp
, yyvsp
- yyrhslen
, yyrhslen
);
922 ]b4_location_if([[ yystackp
->yyerror_range
[1].yystate
.yyloc
= *yylocp
;
927 /* Line __line__ of glr.c. */
928 b4_syncline([@oline@
], [@ofile@
])[
943 /*ARGSUSED*/ static void
944 yyuserMerge (int yyn
, YYSTYPE
* yy0
, YYSTYPE
* yy1
)
956 /* Bison grammar-table manipulation. */
958 ]b4_yydestruct_generate([b4_c_ansi_function_def
])[
960 /** Number of symbols composing the right hand side of rule #RULE. */
962 yyrhsLength (yyRuleNum yyrule
)
968 yydestroyGLRState (char const *yymsg
, yyGLRState
*yys
]b4_user_formals
[)
971 yydestruct (yymsg
, yystos
[yys
->yylrState
],
972 &yys
->yysemantics
.yysval
]b4_location_if([, &yys
->yyloc
])[]b4_user_args
[);
978 YYFPRINTF (stderr
, "%s unresolved ", yymsg
);
979 yysymprint (stderr
, yystos
[yys
->yylrState
],
980 &yys
->yysemantics
.yysval
]b4_location_if([, &yys
->yyloc
])[]b4_user_args
[);
981 YYFPRINTF (stderr
, "\n");
985 if (yys
->yysemantics
.yyfirstVal
)
987 yySemanticOption
*yyoption
= yys
->yysemantics
.yyfirstVal
;
990 for (yyrh
= yyoption
->yystate
, yyn
= yyrhsLength (yyoption
->yyrule
);
992 yyrh
= yyrh
->yypred
, yyn
-= 1)
993 yydestroyGLRState (yymsg
, yyrh
]b4_user_args
[);
998 /** Left-hand-side symbol for rule #RULE. */
999 static inline yySymbol
1000 yylhsNonterm (yyRuleNum yyrule
)
1002 return yyr1
[yyrule
];
1005 #define yyis_pact_ninf(yystate) \
1006 ]m4_if(m4_eval(b4_pact_ninf < b4_pact_min), [1],
1008 [((yystate
) == YYPACT_NINF
)])[
1010 /** True iff LR state STATE has only a default reduction (regardless
1012 static inline yybool
1013 yyisDefaultedState (yyStateNum yystate
)
1015 return yyis_pact_ninf (yypact
[yystate
]);
1018 /** The default reduction for STATE, assuming it has one. */
1019 static inline yyRuleNum
1020 yydefaultAction (yyStateNum yystate
)
1022 return yydefact
[yystate
];
1025 #define yyis_table_ninf(yytable_value) \
1026 ]m4_if(m4_eval(b4_table_ninf < b4_table_min), [1],
1028 [((yytable_value
) == YYTABLE_NINF
)])[
1030 /** Set *YYACTION to the action to take in YYSTATE on seeing YYTOKEN.
1032 * R < 0: Reduce on rule -R.
1034 * R > 0: Shift to state R.
1035 * Set *CONFLICTS to a pointer into yyconfl to 0-terminated list of
1036 * conflicting reductions.
1039 yygetLRActions (yyStateNum yystate
, int yytoken
,
1040 int* yyaction
, const short int** yyconflicts
)
1042 int yyindex
= yypact
[yystate
] + yytoken
;
1043 if (yyindex
< 0 || YYLAST
< yyindex
|| yycheck
[yyindex
] != yytoken
)
1045 *yyaction
= -yydefact
[yystate
];
1046 *yyconflicts
= yyconfl
;
1048 else if (! yyis_table_ninf (yytable
[yyindex
]))
1050 *yyaction
= yytable
[yyindex
];
1051 *yyconflicts
= yyconfl
+ yyconflp
[yyindex
];
1056 *yyconflicts
= yyconfl
+ yyconflp
[yyindex
];
1060 static inline yyStateNum
1061 yyLRgotoState (yyStateNum yystate
, yySymbol yylhs
)
1064 yyr
= yypgoto
[yylhs
- YYNTOKENS
] + yystate
;
1065 if (0 <= yyr
&& yyr
<= YYLAST
&& yycheck
[yyr
] == yystate
)
1066 return yytable
[yyr
];
1068 return yydefgoto
[yylhs
- YYNTOKENS
];
1071 static inline yybool
1072 yyisShiftAction (int yyaction
)
1074 return 0 < yyaction
;
1077 static inline yybool
1078 yyisErrorAction (int yyaction
)
1080 return yyaction
== 0;
1085 /** Return a fresh GLRStackItem. Callers should call
1086 * YY_RESERVE_GLRSTACK afterwards to make sure there is sufficient
1089 static inline yyGLRStackItem
*
1090 yynewGLRStackItem (yyGLRStack
* yystackp
, yybool yyisState
)
1092 yyGLRStackItem
* yynewItem
= yystackp
->yynextFree
;
1093 yystackp
->yyspaceLeft
-= 1;
1094 yystackp
->yynextFree
+= 1;
1095 yynewItem
->yystate
.yyisState
= yyisState
;
1100 yyaddDeferredAction (yyGLRStack
* yystackp
, yyGLRState
* yystate
,
1101 yyGLRState
* rhs
, yyRuleNum yyrule
)
1103 yySemanticOption
* yynewOption
=
1104 &yynewGLRStackItem (yystackp
, yyfalse
)->yyoption
;
1105 yynewOption
->yystate
= rhs
;
1106 yynewOption
->yyrule
= yyrule
;
1107 yynewOption
->yynext
= yystate
->yysemantics
.yyfirstVal
;
1108 yystate
->yysemantics
.yyfirstVal
= yynewOption
;
1110 YY_RESERVE_GLRSTACK (yystackp
);
1115 /** Initialize SET to a singleton set containing an empty stack. */
1117 yyinitStateSet (yyGLRStateSet
* yyset
)
1120 yyset
->yycapacity
= 16;
1121 yyset
->yystates
= (yyGLRState
**) YYMALLOC (16 * sizeof yyset
->yystates
[0]);
1122 if (! yyset
->yystates
)
1124 yyset
->yystates
[0] = NULL
;
1128 static void yyfreeStateSet (yyGLRStateSet
* yyset
)
1130 YYFREE (yyset
->yystates
);
1133 /** Initialize STACK to a single empty stack, with total maximum
1134 * capacity for all stacks of SIZE. */
1136 yyinitGLRStack (yyGLRStack
* yystackp
, size_t yysize
)
1138 yystackp
->yyerrState
= 0;
1140 yystackp
->yyspaceLeft
= yysize
;
1142 (yyGLRStackItem
*) YYMALLOC (yysize
* sizeof yystackp
->yynextFree
[0]);
1143 if (!yystackp
->yyitems
)
1145 yystackp
->yynextFree
= yystackp
->yyitems
;
1146 yystackp
->yysplitPoint
= NULL
;
1147 yystackp
->yylastDeleted
= NULL
;
1148 return yyinitStateSet (&yystackp
->yytops
);
1152 #if YYSTACKEXPANDABLE
1153 # define YYRELOC(YYFROMITEMS,YYTOITEMS,YYX,YYTYPE) \
1154 &((YYTOITEMS) - ((YYFROMITEMS) - (yyGLRStackItem*) (YYX)))->YYTYPE
1156 /** If STACK is expandable, extend it. WARNING: Pointers into the
1157 stack from outside should be considered invalid after this call.
1158 We always expand when there are 1 or fewer items left AFTER an
1159 allocation, so that we can avoid having external pointers exist
1160 across an allocation. */
1162 yyexpandGLRStack (yyGLRStack
* yystackp
)
1164 yyGLRStackItem
* yynewItems
;
1165 yyGLRStackItem
* yyp0
, *yyp1
;
1166 size_t yysize
, yynewSize
;
1168 yysize
= yystackp
->yynextFree
- yystackp
->yyitems
;
1169 if (YYMAXDEPTH
<= yysize
)
1170 yyMemoryExhausted (yystackp
);
1171 yynewSize
= 2*yysize
;
1172 if (YYMAXDEPTH
< yynewSize
)
1173 yynewSize
= YYMAXDEPTH
;
1174 yynewItems
= (yyGLRStackItem
*) YYMALLOC (yynewSize
* sizeof yynewItems
[0]);
1176 yyMemoryExhausted (yystackp
);
1177 for (yyp0
= yystackp
->yyitems
, yyp1
= yynewItems
, yyn
= yysize
;
1179 yyn
-= 1, yyp0
+= 1, yyp1
+= 1)
1182 if (*(yybool
*) yyp0
)
1184 yyGLRState
* yys0
= &yyp0
->yystate
;
1185 yyGLRState
* yys1
= &yyp1
->yystate
;
1186 if (yys0
->yypred
!= NULL
)
1188 YYRELOC (yyp0
, yyp1
, yys0
->yypred
, yystate
);
1189 if (! yys0
->yyresolved
&& yys0
->yysemantics
.yyfirstVal
!= NULL
)
1190 yys1
->yysemantics
.yyfirstVal
=
1191 YYRELOC(yyp0
, yyp1
, yys0
->yysemantics
.yyfirstVal
, yyoption
);
1195 yySemanticOption
* yyv0
= &yyp0
->yyoption
;
1196 yySemanticOption
* yyv1
= &yyp1
->yyoption
;
1197 if (yyv0
->yystate
!= NULL
)
1198 yyv1
->yystate
= YYRELOC (yyp0
, yyp1
, yyv0
->yystate
, yystate
);
1199 if (yyv0
->yynext
!= NULL
)
1200 yyv1
->yynext
= YYRELOC (yyp0
, yyp1
, yyv0
->yynext
, yyoption
);
1203 if (yystackp
->yysplitPoint
!= NULL
)
1204 yystackp
->yysplitPoint
= YYRELOC (yystackp
->yyitems
, yynewItems
,
1205 yystackp
->yysplitPoint
, yystate
);
1207 for (yyn
= 0; yyn
< yystackp
->yytops
.yysize
; yyn
+= 1)
1208 if (yystackp
->yytops
.yystates
[yyn
] != NULL
)
1209 yystackp
->yytops
.yystates
[yyn
] =
1210 YYRELOC (yystackp
->yyitems
, yynewItems
,
1211 yystackp
->yytops
.yystates
[yyn
], yystate
);
1212 YYFREE (yystackp
->yyitems
);
1213 yystackp
->yyitems
= yynewItems
;
1214 yystackp
->yynextFree
= yynewItems
+ yysize
;
1215 yystackp
->yyspaceLeft
= yynewSize
- yysize
;
1220 yyfreeGLRStack (yyGLRStack
* yystackp
)
1222 YYFREE (yystackp
->yyitems
);
1223 yyfreeStateSet (&yystackp
->yytops
);
1226 /** Assuming that S is a GLRState somewhere on STACK, update the
1227 * splitpoint of STACK, if needed, so that it is at least as deep as
1230 yyupdateSplit (yyGLRStack
* yystackp
, yyGLRState
* yys
)
1232 if (yystackp
->yysplitPoint
!= NULL
&& yystackp
->yysplitPoint
> yys
)
1233 yystackp
->yysplitPoint
= yys
;
1236 /** Invalidate stack #K in STACK. */
1238 yymarkStackDeleted (yyGLRStack
* yystackp
, size_t yyk
)
1240 if (yystackp
->yytops
.yystates
[yyk
] != NULL
)
1241 yystackp
->yylastDeleted
= yystackp
->yytops
.yystates
[yyk
];
1242 yystackp
->yytops
.yystates
[yyk
] = NULL
;
1245 /** Undelete the last stack that was marked as deleted. Can only be
1246 done once after a deletion, and only when all other stacks have
1249 yyundeleteLastStack (yyGLRStack
* yystackp
)
1251 if (yystackp
->yylastDeleted
== NULL
|| yystackp
->yytops
.yysize
!= 0)
1253 yystackp
->yytops
.yystates
[0] = yystackp
->yylastDeleted
;
1254 yystackp
->yytops
.yysize
= 1;
1255 YYDPRINTF ((stderr
, "Restoring last deleted stack as stack #0.\n"));
1256 yystackp
->yylastDeleted
= NULL
;
1260 yyremoveDeletes (yyGLRStack
* yystackp
)
1264 while (yyj
< yystackp
->yytops
.yysize
)
1266 if (yystackp
->yytops
.yystates
[yyi
] == NULL
)
1270 YYDPRINTF ((stderr
, "Removing dead stacks.\n"));
1272 yystackp
->yytops
.yysize
-= 1;
1276 yystackp
->yytops
.yystates
[yyj
] = yystackp
->yytops
.yystates
[yyi
];
1279 YYDPRINTF ((stderr
, "Rename stack %lu -> %lu.\n",
1280 (unsigned long int) yyi
, (unsigned long int) yyj
));
1288 /** Shift to a new state on stack #K of STACK, corresponding to LR state
1289 * LRSTATE, at input position POSN, with (resolved) semantic value SVAL. */
1291 yyglrShift (yyGLRStack
* yystackp
, size_t yyk
, yyStateNum yylrState
,
1293 YYSTYPE
* yyvalp
, YYLTYPE
* yylocp
)
1295 yyGLRState
* yynewState
= &yynewGLRStackItem (yystackp
, yytrue
)->yystate
;
1297 yynewState
->yylrState
= yylrState
;
1298 yynewState
->yyposn
= yyposn
;
1299 yynewState
->yyresolved
= yytrue
;
1300 yynewState
->yypred
= yystackp
->yytops
.yystates
[yyk
];
1301 yynewState
->yysemantics
.yysval
= *yyvalp
;
1302 yynewState
->yyloc
= *yylocp
;
1303 yystackp
->yytops
.yystates
[yyk
] = yynewState
;
1305 YY_RESERVE_GLRSTACK (yystackp
);
1308 /** Shift stack #K of YYSTACK, to a new state corresponding to LR
1309 * state YYLRSTATE, at input position YYPOSN, with the (unresolved)
1310 * semantic value of YYRHS under the action for YYRULE. */
1312 yyglrShiftDefer (yyGLRStack
* yystackp
, size_t yyk
, yyStateNum yylrState
,
1313 size_t yyposn
, yyGLRState
* rhs
, yyRuleNum yyrule
)
1315 yyGLRState
* yynewState
= &yynewGLRStackItem (yystackp
, yytrue
)->yystate
;
1317 yynewState
->yylrState
= yylrState
;
1318 yynewState
->yyposn
= yyposn
;
1319 yynewState
->yyresolved
= yyfalse
;
1320 yynewState
->yypred
= yystackp
->yytops
.yystates
[yyk
];
1321 yynewState
->yysemantics
.yyfirstVal
= NULL
;
1322 yystackp
->yytops
.yystates
[yyk
] = yynewState
;
1324 /* Invokes YY_RESERVE_GLRSTACK. */
1325 yyaddDeferredAction (yystackp
, yynewState
, rhs
, yyrule
);
1328 /** Pop the symbols consumed by reduction #RULE from the top of stack
1329 * #K of STACK, and perform the appropriate semantic action on their
1330 * semantic values. Assumes that all ambiguities in semantic values
1331 * have been previously resolved. Set *VALP to the resulting value,
1332 * and *LOCP to the computed location (if any). Return value is as
1333 * for userAction. */
1334 static inline YYRESULTTAG
1335 yydoAction (yyGLRStack
* yystackp
, size_t yyk
, yyRuleNum yyrule
,
1336 YYSTYPE
* yyvalp
, YYLTYPE
* yylocp
]b4_user_formals
[)
1338 int yynrhs
= yyrhsLength (yyrule
);
1340 if (yystackp
->yysplitPoint
== NULL
)
1342 /* Standard special case: single stack. */
1343 yyGLRStackItem
* rhs
= (yyGLRStackItem
*) yystackp
->yytops
.yystates
[yyk
];
1344 YYASSERT (yyk
== 0);
1345 yystackp
->yynextFree
-= yynrhs
;
1346 yystackp
->yyspaceLeft
+= yynrhs
;
1347 yystackp
->yytops
.yystates
[0] = & yystackp
->yynextFree
[-1].yystate
;
1348 return yyuserAction (yyrule
, yynrhs
, rhs
,
1349 yyvalp
, yylocp
, yystackp
]b4_user_args
[);
1353 /* At present, doAction is never called in nondeterministic
1354 * mode, so this branch is never taken. It is here in
1355 * anticipation of a future feature that will allow immediate
1356 * evaluation of selected actions in nondeterministic mode. */
1359 yyGLRStackItem yyrhsVals
[YYMAXRHS
+ YYMAXLEFT
+ 1];
1360 yys
= yyrhsVals
[YYMAXRHS
+ YYMAXLEFT
].yystate
.yypred
1361 = yystackp
->yytops
.yystates
[yyk
];]b4_location_if([[
1363 /* Set default location. */
1364 yyrhsVals
[YYMAXRHS
+ YYMAXLEFT
- 1].yystate
.yyloc
= yys
->yyloc
;]])[
1365 for (yyi
= 0; yyi
< yynrhs
; yyi
+= 1)
1370 yyupdateSplit (yystackp
, yys
);
1371 yystackp
->yytops
.yystates
[yyk
] = yys
;
1372 return yyuserAction (yyrule
, yynrhs
, yyrhsVals
+ YYMAXRHS
+ YYMAXLEFT
- 1,
1373 yyvalp
, yylocp
, yystackp
]b4_user_args
[);
1378 # define YY_REDUCE_PRINT(Args)
1380 # define YY_REDUCE_PRINT(Args) \
1383 yy_reduce_print Args; \
1386 /*----------------------------------------------------------.
1387 | Report that the RULE is going to be reduced on stack #K. |
1388 `----------------------------------------------------------*/
1390 /*ARGSUSED*/ static inline void
1391 yy_reduce_print (yyGLRStack
* yystackp
, size_t yyk
, yyRuleNum yyrule
,
1392 YYSTYPE
* yyvalp
, YYLTYPE
* yylocp
]b4_user_formals
[)
1394 int yynrhs
= yyrhsLength (yyrule
);
1395 yybool yynormal
__attribute__ ((__unused__
)) =
1396 (yystackp
->yysplitPoint
== NULL
);
1397 yyGLRStackItem
* yyvsp
= (yyGLRStackItem
*) yystackp
->yytops
.yystates
[yyk
];
1402 ]b4_parse_param_use
[]dnl
1403 [ YYFPRINTF (stderr
, "Reducing stack %lu by rule %d (line %lu):\n",
1404 (unsigned long int) yyk
, yyrule
- 1,
1405 (unsigned long int) yyrline
[yyrule
]);
1406 /* The symbols being reduced. */
1407 for (yyi
= 0; yyi
< yynrhs
; yyi
++)
1409 fprintf (stderr
, " $%d = ", yyi
+ 1);
1410 yysymprint (stderr
, yyrhs
[yyprhs
[yyrule
] + yyi
],
1411 &]b4_rhs_value(yynrhs
, yyi
+ 1)[
1412 ]b4_location_if([, &]b4_rhs_location(yynrhs
, yyi
+ 1))[]dnl
1414 fprintf (stderr
, "\n");
1419 /** Pop items off stack #K of STACK according to grammar rule RULE,
1420 * and push back on the resulting nonterminal symbol. Perform the
1421 * semantic action associated with RULE and store its value with the
1422 * newly pushed state, if FORCEEVAL or if STACK is currently
1423 * unambiguous. Otherwise, store the deferred semantic action with
1424 * the new state. If the new state would have an identical input
1425 * position, LR state, and predecessor to an existing state on the stack,
1426 * it is identified with that existing state, eliminating stack #K from
1427 * the STACK. In this case, the (necessarily deferred) semantic value is
1428 * added to the options for the existing state's semantic value.
1430 static inline YYRESULTTAG
1431 yyglrReduce (yyGLRStack
* yystackp
, size_t yyk
, yyRuleNum yyrule
,
1432 yybool yyforceEval
]b4_user_formals
[)
1434 size_t yyposn
= yystackp
->yytops
.yystates
[yyk
]->yyposn
;
1436 if (yyforceEval
|| yystackp
->yysplitPoint
== NULL
)
1441 YY_REDUCE_PRINT ((yystackp
, yyk
, yyrule
, &yysval
, &yyloc
]b4_user_args
[));
1442 YYCHK (yydoAction (yystackp
, yyk
, yyrule
, &yysval
,
1443 &yyloc
]b4_user_args
[));
1444 YY_SYMBOL_PRINT ("-> $$ =", yyr1
[yyrule
], &yysval
, &yyloc
);
1445 yyglrShift (yystackp
, yyk
,
1446 yyLRgotoState (yystackp
->yytops
.yystates
[yyk
]->yylrState
,
1447 yylhsNonterm (yyrule
)),
1448 yyposn
, &yysval
, &yyloc
);
1454 yyGLRState
* yys
, *yys0
= yystackp
->yytops
.yystates
[yyk
];
1455 yyStateNum yynewLRState
;
1457 for (yys
= yystackp
->yytops
.yystates
[yyk
], yyn
= yyrhsLength (yyrule
);
1463 yyupdateSplit (yystackp
, yys
);
1464 yynewLRState
= yyLRgotoState (yys
->yylrState
, yylhsNonterm (yyrule
));
1466 "Reduced stack %lu by rule #%d; action deferred. Now in state %d.\n",
1467 (unsigned long int) yyk
, yyrule
- 1, yynewLRState
));
1468 for (yyi
= 0; yyi
< yystackp
->yytops
.yysize
; yyi
+= 1)
1469 if (yyi
!= yyk
&& yystackp
->yytops
.yystates
[yyi
] != NULL
)
1471 yyGLRState
* yyp
, *yysplit
= yystackp
->yysplitPoint
;
1472 yyp
= yystackp
->yytops
.yystates
[yyi
];
1473 while (yyp
!= yys
&& yyp
!= yysplit
&& yyp
->yyposn
>= yyposn
)
1475 if (yyp
->yylrState
== yynewLRState
&& yyp
->yypred
== yys
)
1477 yyaddDeferredAction (yystackp
, yyp
, yys0
, yyrule
);
1478 yymarkStackDeleted (yystackp
, yyk
);
1479 YYDPRINTF ((stderr
, "Merging stack %lu into stack %lu.\n",
1480 (unsigned long int) yyk
,
1481 (unsigned long int) yyi
));
1487 yystackp
->yytops
.yystates
[yyk
] = yys
;
1488 yyglrShiftDefer (yystackp
, yyk
, yynewLRState
, yyposn
, yys0
, yyrule
);
1494 yysplitStack (yyGLRStack
* yystackp
, size_t yyk
)
1496 if (yystackp
->yysplitPoint
== NULL
)
1498 YYASSERT (yyk
== 0);
1499 yystackp
->yysplitPoint
= yystackp
->yytops
.yystates
[yyk
];
1501 if (yystackp
->yytops
.yysize
>= yystackp
->yytops
.yycapacity
)
1503 yyGLRState
** yynewStates
;
1504 if (! ((yystackp
->yytops
.yycapacity
1505 <= (YYSIZEMAX
/ (2 * sizeof yynewStates
[0])))
1507 (yyGLRState
**) YYREALLOC (yystackp
->yytops
.yystates
,
1508 ((yystackp
->yytops
.yycapacity
*= 2)
1509 * sizeof yynewStates
[0])))))
1510 yyMemoryExhausted (yystackp
);
1511 yystackp
->yytops
.yystates
= yynewStates
;
1513 yystackp
->yytops
.yystates
[yystackp
->yytops
.yysize
]
1514 = yystackp
->yytops
.yystates
[yyk
];
1515 yystackp
->yytops
.yysize
+= 1;
1516 return yystackp
->yytops
.yysize
-1;
1519 /** True iff Y0 and Y1 represent identical options at the top level.
1520 * That is, they represent the same rule applied to RHS symbols
1521 * that produce the same terminal symbols. */
1523 yyidenticalOptions (yySemanticOption
* yyy0
, yySemanticOption
* yyy1
)
1525 if (yyy0
->yyrule
== yyy1
->yyrule
)
1527 yyGLRState
*yys0
, *yys1
;
1529 for (yys0
= yyy0
->yystate
, yys1
= yyy1
->yystate
,
1530 yyn
= yyrhsLength (yyy0
->yyrule
);
1532 yys0
= yys0
->yypred
, yys1
= yys1
->yypred
, yyn
-= 1)
1533 if (yys0
->yyposn
!= yys1
->yyposn
)
1541 /** Assuming identicalOptions (Y0,Y1), destructively merge the
1542 * alternative semantic values for the RHS-symbols of Y1 and Y0. */
1544 yymergeOptionSets (yySemanticOption
* yyy0
, yySemanticOption
* yyy1
)
1546 yyGLRState
*yys0
, *yys1
;
1548 for (yys0
= yyy0
->yystate
, yys1
= yyy1
->yystate
,
1549 yyn
= yyrhsLength (yyy0
->yyrule
);
1551 yys0
= yys0
->yypred
, yys1
= yys1
->yypred
, yyn
-= 1)
1555 else if (yys0
->yyresolved
)
1557 yys1
->yyresolved
= yytrue
;
1558 yys1
->yysemantics
.yysval
= yys0
->yysemantics
.yysval
;
1560 else if (yys1
->yyresolved
)
1562 yys0
->yyresolved
= yytrue
;
1563 yys0
->yysemantics
.yysval
= yys1
->yysemantics
.yysval
;
1567 yySemanticOption
** yyz0p
;
1568 yySemanticOption
* yyz1
;
1569 yyz0p
= &yys0
->yysemantics
.yyfirstVal
;
1570 yyz1
= yys1
->yysemantics
.yyfirstVal
;
1571 while (YYID (yytrue
))
1573 if (yyz1
== *yyz0p
|| yyz1
== NULL
)
1575 else if (*yyz0p
== NULL
)
1580 else if (*yyz0p
< yyz1
)
1582 yySemanticOption
* yyz
= *yyz0p
;
1584 yyz1
= yyz1
->yynext
;
1585 (*yyz0p
)->yynext
= yyz
;
1587 yyz0p
= &(*yyz0p
)->yynext
;
1589 yys1
->yysemantics
.yyfirstVal
= yys0
->yysemantics
.yyfirstVal
;
1594 /** Y0 and Y1 represent two possible actions to take in a given
1595 * parsing state; return 0 if no combination is possible,
1596 * 1 if user-mergeable, 2 if Y0 is preferred, 3 if Y1 is preferred. */
1598 yypreference (yySemanticOption
* y0
, yySemanticOption
* y1
)
1600 yyRuleNum r0
= y0
->yyrule
, r1
= y1
->yyrule
;
1601 int p0
= yydprec
[r0
], p1
= yydprec
[r1
];
1605 if (yymerger
[r0
] == 0 || yymerger
[r0
] != yymerger
[r1
])
1610 if (p0
== 0 || p1
== 0)
1619 static YYRESULTTAG
yyresolveValue (yySemanticOption
* yyoptionList
,
1620 yyGLRStack
* yystackp
, YYSTYPE
* yyvalp
,
1621 YYLTYPE
* yylocp
]b4_user_formals
[);
1624 yyresolveStates (yyGLRState
* yys
, int yyn
,
1625 yyGLRStack
* yystackp
]b4_user_formals
[)
1630 YYASSERT (yys
->yypred
);
1631 yyflag
= yyresolveStates (yys
->yypred
, yyn
-1, yystackp
]b4_user_args
[);
1634 if (! yys
->yyresolved
)
1636 yyflag
= yyresolveValue (yys
->yysemantics
.yyfirstVal
, yystackp
,
1637 &yys
->yysemantics
.yysval
, &yys
->yyloc
1641 yys
->yyresolved
= yytrue
;
1648 yyresolveAction (yySemanticOption
* yyopt
, yyGLRStack
* yystackp
,
1649 YYSTYPE
* yyvalp
, YYLTYPE
* yylocp
]b4_user_formals
[)
1651 yyGLRStackItem yyrhsVals
[YYMAXRHS
+ YYMAXLEFT
+ 1];
1654 yynrhs
= yyrhsLength (yyopt
->yyrule
);
1655 YYCHK (yyresolveStates (yyopt
->yystate
, yynrhs
, yystackp
]b4_user_args
[));
1656 yyrhsVals
[YYMAXRHS
+ YYMAXLEFT
].yystate
.yypred
= yyopt
->yystate
;]b4_location_if([[
1658 /* Set default location. */
1659 yyrhsVals
[YYMAXRHS
+ YYMAXLEFT
- 1].yystate
.yyloc
= yyopt
->yystate
->yyloc
;]])[
1660 return yyuserAction (yyopt
->yyrule
, yynrhs
,
1661 yyrhsVals
+ YYMAXRHS
+ YYMAXLEFT
- 1,
1662 yyvalp
, yylocp
, yystackp
]b4_user_args
[);
1667 yyreportTree (yySemanticOption
* yyx
, int yyindent
)
1669 int yynrhs
= yyrhsLength (yyx
->yyrule
);
1672 yyGLRState
* yystates
[YYMAXRHS
];
1673 yyGLRState yyleftmost_state
;
1675 for (yyi
= yynrhs
, yys
= yyx
->yystate
; 0 < yyi
; yyi
-= 1, yys
= yys
->yypred
)
1676 yystates
[yyi
] = yys
;
1679 yyleftmost_state
.yyposn
= 0;
1680 yystates
[0] = &yyleftmost_state
;
1685 if (yyx
->yystate
->yyposn
< yys
->yyposn
+ 1)
1686 YYFPRINTF (stderr
, "%*s%s -> <Rule %d, empty>\n",
1687 yyindent
, "", yytokenName (yylhsNonterm (yyx
->yyrule
)),
1690 YYFPRINTF (stderr
, "%*s%s -> <Rule %d, tokens %lu .. %lu>\n",
1691 yyindent
, "", yytokenName (yylhsNonterm (yyx
->yyrule
)),
1692 yyx
->yyrule
, (unsigned long int) (yys
->yyposn
+ 1),
1693 (unsigned long int) yyx
->yystate
->yyposn
);
1694 for (yyi
= 1; yyi
<= yynrhs
; yyi
+= 1)
1696 if (yystates
[yyi
]->yyresolved
)
1698 if (yystates
[yyi
-1]->yyposn
+1 > yystates
[yyi
]->yyposn
)
1699 YYFPRINTF (stderr
, "%*s%s <empty>\n", yyindent
+2, "",
1700 yytokenName (yyrhs
[yyprhs
[yyx
->yyrule
]+yyi
-1]));
1702 YYFPRINTF (stderr
, "%*s%s <tokens %lu .. %lu>\n", yyindent
+2, "",
1703 yytokenName (yyrhs
[yyprhs
[yyx
->yyrule
]+yyi
-1]),
1704 (unsigned long int) (yystates
[yyi
- 1]->yyposn
+ 1),
1705 (unsigned long int) yystates
[yyi
]->yyposn
);
1708 yyreportTree (yystates
[yyi
]->yysemantics
.yyfirstVal
, yyindent
+2);
1713 static void yyreportAmbiguity (yySemanticOption
* yyx0
, yySemanticOption
* yyx1
,
1714 yyGLRStack
* yystackp
]b4_pure_formals
[)
1715 __attribute__ ((__noreturn__
));
1717 yyreportAmbiguity (yySemanticOption
* yyx0
, yySemanticOption
* yyx1
,
1718 yyGLRStack
* yystackp
]b4_pure_formals
[)
1724 YYFPRINTF (stderr
, "Ambiguity detected.\n");
1725 YYFPRINTF (stderr
, "Option 1,\n");
1726 yyreportTree (yyx0
, 2);
1727 YYFPRINTF (stderr
, "\nOption 2,\n");
1728 yyreportTree (yyx1
, 2);
1729 YYFPRINTF (stderr
, "\n");
1731 yyFail (yystackp
][]b4_pure_args
[, YY_("syntax is ambiguous"));
1735 /** Resolve the ambiguity represented by OPTIONLIST, perform the indicated
1736 * actions, and return the result. */
1738 yyresolveValue (yySemanticOption
* yyoptionList
, yyGLRStack
* yystackp
,
1739 YYSTYPE
* yyvalp
, YYLTYPE
* yylocp
]b4_user_formals
[)
1741 yySemanticOption
* yybest
;
1742 yySemanticOption
** yypp
;
1745 yybest
= yyoptionList
;
1747 for (yypp
= &yyoptionList
->yynext
; *yypp
!= NULL
; )
1749 yySemanticOption
* yyp
= *yypp
;
1751 if (yyidenticalOptions (yybest
, yyp
))
1753 yymergeOptionSets (yybest
, yyp
);
1754 *yypp
= yyp
->yynext
;
1758 switch (yypreference (yybest
, yyp
))
1761 yyreportAmbiguity (yybest
, yyp
, yystackp
]b4_pure_args
[);
1773 /* This cannot happen so it is not worth a YYASSERT (yyfalse),
1774 but some compilers complain if the default case is
1778 yypp
= &yyp
->yynext
;
1784 yySemanticOption
* yyp
;
1785 int yyprec
= yydprec
[yybest
->yyrule
];
1786 YYCHK (yyresolveAction (yybest
, yystackp
, yyvalp
, yylocp
]b4_user_args
[));
1787 for (yyp
= yybest
->yynext
; yyp
!= NULL
; yyp
= yyp
->yynext
)
1789 if (yyprec
== yydprec
[yyp
->yyrule
])
1793 YYCHK (yyresolveAction (yyp
, yystackp
, &yyval1
,
1794 &yydummy
]b4_user_args
[));
1795 yyuserMerge (yymerger
[yyp
->yyrule
], yyvalp
, &yyval1
);
1801 return yyresolveAction (yybest
, yystackp
, yyvalp
, yylocp
]b4_user_args
[);
1805 yyresolveStack (yyGLRStack
* yystackp
]b4_user_formals
[)
1807 if (yystackp
->yysplitPoint
!= NULL
)
1812 for (yyn
= 0, yys
= yystackp
->yytops
.yystates
[0];
1813 yys
!= yystackp
->yysplitPoint
;
1814 yys
= yys
->yypred
, yyn
+= 1)
1816 YYCHK (yyresolveStates (yystackp
->yytops
.yystates
[0], yyn
, yystackp
1823 yycompressStack (yyGLRStack
* yystackp
)
1825 yyGLRState
* yyp
, *yyq
, *yyr
;
1827 if (yystackp
->yytops
.yysize
!= 1 || yystackp
->yysplitPoint
== NULL
)
1830 for (yyp
= yystackp
->yytops
.yystates
[0], yyq
= yyp
->yypred
, yyr
= NULL
;
1831 yyp
!= yystackp
->yysplitPoint
;
1832 yyr
= yyp
, yyp
= yyq
, yyq
= yyp
->yypred
)
1835 yystackp
->yyspaceLeft
+= yystackp
->yynextFree
- yystackp
->yyitems
;
1836 yystackp
->yynextFree
= ((yyGLRStackItem
*) yystackp
->yysplitPoint
) + 1;
1837 yystackp
->yyspaceLeft
-= yystackp
->yynextFree
- yystackp
->yyitems
;
1838 yystackp
->yysplitPoint
= NULL
;
1839 yystackp
->yylastDeleted
= NULL
;
1843 yystackp
->yynextFree
->yystate
= *yyr
;
1845 yystackp
->yynextFree
->yystate
.yypred
= &yystackp
->yynextFree
[-1].yystate
;
1846 yystackp
->yytops
.yystates
[0] = &yystackp
->yynextFree
->yystate
;
1847 yystackp
->yynextFree
+= 1;
1848 yystackp
->yyspaceLeft
-= 1;
1853 yyprocessOneStack (yyGLRStack
* yystackp
, size_t yyk
,
1854 size_t yyposn
]b4_pure_formals
[)
1857 const short int* yyconflicts
;
1859 yySymbol
* const yytokenp
= yystackp
->yytokenp
;
1861 while (yystackp
->yytops
.yystates
[yyk
] != NULL
)
1863 yyStateNum yystate
= yystackp
->yytops
.yystates
[yyk
]->yylrState
;
1864 YYDPRINTF ((stderr
, "Stack %lu Entering state %d\n",
1865 (unsigned long int) yyk
, yystate
));
1867 YYASSERT (yystate
!= YYFINAL
);
1869 if (yyisDefaultedState (yystate
))
1871 yyrule
= yydefaultAction (yystate
);
1874 YYDPRINTF ((stderr
, "Stack %lu dies.\n",
1875 (unsigned long int) yyk
));
1876 yymarkStackDeleted (yystackp
, yyk
);
1879 YYCHK (yyglrReduce (yystackp
, yyk
, yyrule
, yyfalse
]b4_user_args
[));
1883 if (*yytokenp
== YYEMPTY
)
1885 YYDPRINTF ((stderr
, "Reading a token: "));
1887 *yytokenp
= YYTRANSLATE (yychar
);
1888 YY_SYMBOL_PRINT ("Next token is", *yytokenp
, &yylval
, &yylloc
);
1890 yygetLRActions (yystate
, *yytokenp
, &yyaction
, &yyconflicts
);
1892 while (*yyconflicts
!= 0)
1894 size_t yynewStack
= yysplitStack (yystackp
, yyk
);
1895 YYDPRINTF ((stderr
, "Splitting off stack %lu from %lu.\n",
1896 (unsigned long int) yynewStack
,
1897 (unsigned long int) yyk
));
1898 YYCHK (yyglrReduce (yystackp
, yynewStack
,
1899 *yyconflicts
, yyfalse
]b4_user_args
[));
1900 YYCHK (yyprocessOneStack (yystackp
, yynewStack
,
1901 yyposn
]b4_pure_args
[));
1905 if (yyisShiftAction (yyaction
))
1907 else if (yyisErrorAction (yyaction
))
1909 YYDPRINTF ((stderr
, "Stack %lu dies.\n",
1910 (unsigned long int) yyk
));
1911 yymarkStackDeleted (yystackp
, yyk
);
1915 YYCHK (yyglrReduce (yystackp
, yyk
, -yyaction
,
1916 yyfalse
]b4_user_args
[));
1922 /*ARGSUSED*/ static void
1923 yyreportSyntaxError (yyGLRStack
* yystackp
]b4_user_formals
[)
1925 if (yystackp
->yyerrState
== 0)
1928 yySymbol
* const yytokenp
= yystackp
->yytokenp
;
1930 yyn
= yypact
[yystackp
->yytops
.yystates
[0]->yylrState
];
1931 if (YYPACT_NINF
< yyn
&& yyn
< YYLAST
)
1933 size_t yysize0
= yytnamerr (NULL
, yytokenName (*yytokenp
));
1934 size_t yysize
= yysize0
;
1936 yybool yysize_overflow
= yyfalse
;
1938 enum { YYERROR_VERBOSE_ARGS_MAXIMUM
= 5 };
1939 char const *yyarg
[YYERROR_VERBOSE_ARGS_MAXIMUM
];
1943 static char const yyunexpected
[] = "syntax error, unexpected %s";
1944 static char const yyexpecting
[] = ", expecting %s";
1945 static char const yyor
[] = " or %s";
1946 char yyformat
[sizeof yyunexpected
1947 + sizeof yyexpecting
- 1
1948 + ((YYERROR_VERBOSE_ARGS_MAXIMUM
- 2)
1949 * (sizeof yyor
- 1))];
1950 char const *yyprefix
= yyexpecting
;
1952 /* Start YYX at -YYN if negative to avoid negative indexes in
1954 int yyxbegin
= yyn
< 0 ? -yyn
: 0;
1956 /* Stay within bounds of both yycheck and yytname. */
1957 int yychecklim
= YYLAST
- yyn
;
1958 int yyxend
= yychecklim
< YYNTOKENS
? yychecklim
: YYNTOKENS
;
1961 yyarg
[0] = yytokenName (*yytokenp
);
1962 yyfmt
= yystpcpy (yyformat
, yyunexpected
);
1964 for (yyx
= yyxbegin
; yyx
< yyxend
; ++yyx
)
1965 if (yycheck
[yyx
+ yyn
] == yyx
&& yyx
!= YYTERROR
)
1967 if (yycount
== YYERROR_VERBOSE_ARGS_MAXIMUM
)
1971 yyformat
[sizeof yyunexpected
- 1] = '\0';
1974 yyarg
[yycount
++] = yytokenName (yyx
);
1975 yysize1
= yysize
+ yytnamerr (NULL
, yytokenName (yyx
));
1976 yysize_overflow
|= yysize1
< yysize
;
1978 yyfmt
= yystpcpy (yyfmt
, yyprefix
);
1982 yyf
= YY_(yyformat
);
1983 yysize1
= yysize
+ strlen (yyf
);
1984 yysize_overflow
|= yysize1
< yysize
;
1987 if (!yysize_overflow
)
1988 yymsg
= (char *) YYMALLOC (yysize
);
1994 while ((*yyp
= *yyf
))
1996 if (*yyp
== '%' && yyf
[1] == 's' && yyi
< yycount
)
1998 yyp
+= yytnamerr (yyp
, yyarg
[yyi
++]);
2007 yyerror (]b4_lyyerror_args
[yymsg
);
2012 yyerror (]b4_lyyerror_args
[YY_("syntax error"));
2013 yyMemoryExhausted (yystackp
);
2017 #endif /* YYERROR_VERBOSE */
2018 yyerror (]b4_lyyerror_args
[YY_("syntax error"));
2023 /* Recover from a syntax error on *YYSTACKP, assuming that *YYSTACKP->YYTOKENP,
2024 yylval, and yylloc are the syntactic category, semantic value, and location
2025 of the look-ahead. */
2026 /*ARGSUSED*/ static void
2027 yyrecoverSyntaxError (yyGLRStack
* yystackp
]b4_user_formals
[)
2029 yySymbol
* const yytokenp
= yystackp
->yytokenp
;
2033 if (yystackp
->yyerrState
== 3)
2034 /* We just shifted the error token and (perhaps) took some
2035 reductions. Skip tokens until we can proceed. */
2036 while (YYID (yytrue
))
2038 if (*yytokenp
== YYEOF
)
2039 yyFail (yystackp
][]b4_lpure_args
[, NULL
);
2040 if (*yytokenp
!= YYEMPTY
)
2042 /* We throw away the lookahead, but the error range
2043 of the shifted error token must take it into account. */
2044 yyGLRState
*yys
= yystackp
->yytops
.yystates
[0];
2045 yyGLRStackItem yyerror_range
[3];
2046 yyerror_range
[1].yystate
.yyloc
= yys
->yyloc
;
2047 yyerror_range
[2].yystate
.yyloc
= yylloc
;
2048 YYLLOC_DEFAULT (yys
->yyloc
, yyerror_range
, 2);]])[
2049 yydestruct ("Error: discarding",
2050 *yytokenp
, &yylval
]b4_location_if([, &yylloc
])[]b4_user_args
[);
2052 YYDPRINTF ((stderr
, "Reading a token: "));
2054 *yytokenp
= YYTRANSLATE (yychar
);
2055 YY_SYMBOL_PRINT ("Next token is", *yytokenp
, &yylval
, &yylloc
);
2056 yyj
= yypact
[yystackp
->yytops
.yystates
[0]->yylrState
];
2057 if (yyis_pact_ninf (yyj
))
2060 if (yyj
< 0 || YYLAST
< yyj
|| yycheck
[yyj
] != *yytokenp
)
2062 if (yydefact
[yystackp
->yytops
.yystates
[0]->yylrState
] != 0)
2065 else if (yytable
[yyj
] != 0 && ! yyis_table_ninf (yytable
[yyj
]))
2069 /* Reduce to one stack. */
2070 for (yyk
= 0; yyk
< yystackp
->yytops
.yysize
; yyk
+= 1)
2071 if (yystackp
->yytops
.yystates
[yyk
] != NULL
)
2073 if (yyk
>= yystackp
->yytops
.yysize
)
2074 yyFail (yystackp
][]b4_lpure_args
[, NULL
);
2075 for (yyk
+= 1; yyk
< yystackp
->yytops
.yysize
; yyk
+= 1)
2076 yymarkStackDeleted (yystackp
, yyk
);
2077 yyremoveDeletes (yystackp
);
2078 yycompressStack (yystackp
);
2080 /* Now pop stack until we find a state that shifts the error token. */
2081 yystackp
->yyerrState
= 3;
2082 while (yystackp
->yytops
.yystates
[0] != NULL
)
2084 yyGLRState
*yys
= yystackp
->yytops
.yystates
[0];
2085 yyj
= yypact
[yys
->yylrState
];
2086 if (! yyis_pact_ninf (yyj
))
2089 if (0 <= yyj
&& yyj
<= YYLAST
&& yycheck
[yyj
] == YYTERROR
2090 && yyisShiftAction (yytable
[yyj
]))
2092 /* Shift the error token having adjusted its location. */
2093 YYLTYPE yyerrloc
;]b4_location_if([[
2094 yystackp
->yyerror_range
[2].yystate
.yyloc
= yylloc
;
2095 YYLLOC_DEFAULT (yyerrloc
, yystackp
->yyerror_range
, 2);]])[
2096 YY_SYMBOL_PRINT ("Shifting", yystos
[yytable
[yyj
]],
2097 &yylval
, &yyerrloc
);
2098 yyglrShift (yystackp
, 0, yytable
[yyj
],
2099 yys
->yyposn
, &yylval
, &yyerrloc
);
2100 yys
= yystackp
->yytops
.yystates
[0];
2104 ]b4_location_if([[ yystackp
->yyerror_range
[1].yystate
.yyloc
= yys
->yyloc
;]])[
2105 yydestroyGLRState ("Error: popping", yys
]b4_user_args
[);
2106 yystackp
->yytops
.yystates
[0] = yys
->yypred
;
2107 yystackp
->yynextFree
-= 1;
2108 yystackp
->yyspaceLeft
+= 1;
2110 if (yystackp
->yytops
.yystates
[0] == NULL
)
2111 yyFail (yystackp
][]b4_lpure_args
[, NULL
);
2114 #define YYCHK1(YYE) \
2124 goto yyuser_error; \
2135 ]b4_c_ansi_function_def([yyparse
], [int], b4_parse_param
)[
2140 yyGLRStack
* const yystackp
= &yystack
;
2143 YYDPRINTF ((stderr
, "Starting parse\n"));
2146 yylval
= yyval_default
;
2148 #if YYLTYPE_IS_TRIVIAL
2149 yylloc
.first_line
= yylloc
.last_line
= 1;
2150 yylloc
.first_column
= yylloc
.last_column
= 0;
2153 m4_ifdef([b4_initial_action
], [
2154 m4_pushdef([b4_at_dollar
], [yylloc
])dnl
2155 m4_pushdef([b4_dollar_dollar
], [yylval
])dnl
2156 /* User initialization code. */
2158 m4_popdef([b4_dollar_dollar
])dnl
2159 m4_popdef([b4_at_dollar
])dnl
2160 /* Line __line__ of glr.c. */
2161 b4_syncline([@oline@
], [@ofile@
])])dnl
2163 if (! yyinitGLRStack (yystackp
, YYINITDEPTH
))
2164 goto yyexhaustedlab
;
2165 switch (YYSETJMP (yystack
.yyexception_buffer
))
2168 case 1: goto yyabortlab
;
2169 case 2: goto yyexhaustedlab
;
2170 default: goto yybuglab
;
2172 yystack
.yytokenp
= &yytoken
;
2173 yyglrShift (&yystack
, 0, 0, 0, &yylval
, &yylloc
);
2176 while (YYID (yytrue
))
2178 /* For efficiency, we have two loops, the first of which is
2179 specialized to deterministic operation (single stack, no
2180 potential ambiguity). */
2182 while (YYID (yytrue
))
2186 const short int* yyconflicts
;
2188 yyStateNum yystate
= yystack
.yytops
.yystates
[0]->yylrState
;
2189 YYDPRINTF ((stderr
, "Entering state %d\n", yystate
));
2190 if (yystate
== YYFINAL
)
2192 if (yyisDefaultedState (yystate
))
2194 yyrule
= yydefaultAction (yystate
);
2197 ]b4_location_if([[ yystack
.yyerror_range
[1].yystate
.yyloc
= yylloc
;]])[
2198 yyreportSyntaxError (&yystack
]b4_user_args
[);
2201 YYCHK1 (yyglrReduce (&yystack
, 0, yyrule
, yytrue
]b4_user_args
[));
2205 if (yytoken
== YYEMPTY
)
2207 YYDPRINTF ((stderr
, "Reading a token: "));
2209 yytoken
= YYTRANSLATE (yychar
);
2210 YY_SYMBOL_PRINT ("Next token is", yytoken
, &yylval
, &yylloc
);
2212 yygetLRActions (yystate
, yytoken
, &yyaction
, &yyconflicts
);
2213 if (*yyconflicts
!= 0)
2215 if (yyisShiftAction (yyaction
))
2217 YY_SYMBOL_PRINT ("Shifting", yytoken
, &yylval
, &yylloc
);
2218 if (yytoken
!= YYEOF
)
2221 yyglrShift (&yystack
, 0, yyaction
, yyposn
, &yylval
, &yylloc
);
2222 if (0 < yystack
.yyerrState
)
2223 yystack
.yyerrState
-= 1;
2225 else if (yyisErrorAction (yyaction
))
2227 ]b4_location_if([[ yystack
.yyerror_range
[1].yystate
.yyloc
= yylloc
;]])[
2228 yyreportSyntaxError (&yystack
]b4_user_args
[);
2232 YYCHK1 (yyglrReduce (&yystack
, 0, -yyaction
, yytrue
]b4_user_args
[));
2236 while (YYID (yytrue
))
2238 yySymbol yytoken_to_shift
;
2240 size_t yyn
= yystack
.yytops
.yysize
;
2242 /* yyprocessOneStack returns one of three things:
2244 - An error flag. If the caller is yyprocessOneStack, it
2245 immediately returns as well. When the caller is finally
2246 yyparse, it jumps to an error label via YYCHK1.
2248 - yyok, but yyprocessOneStack has invoked yymarkStackDeleted
2249 (&yystack, yys), which sets the top state of yys to NULL. Thus,
2250 yyparse's following invocation of yyremoveDeletes will remove
2253 - yyok, when ready to shift a token.
2255 Except in the first case, yyparse will invoke yyremoveDeletes and
2256 then shift the next token onto all remaining stacks. This
2257 synchronization of the shift (that is, after all preceding
2258 reductions on all stacks) helps prevents double destructor calls
2259 on yylval in the event of memory exhaustion. */
2261 for (yys
= 0; yys
< yyn
; yys
+= 1)
2262 YYCHK1 (yyprocessOneStack (&yystack
, yys
, yyposn
]b4_lpure_args
[));
2263 yyremoveDeletes (&yystack
);
2264 yyn
= yystack
.yytops
.yysize
;
2266 /* If any yyglrShift call fails, it will fail after shifting. Thus,
2267 a copy of yylval will already be on stack 0 in the event of a
2268 failure in the following loop. Thus, yytoken is set to YYEMPTY
2269 before the loop to make sure the user destructor for yylval isn't
2271 yytoken_to_shift
= yytoken
;
2274 for (yys
= 0; yys
< yyn
; yys
+= 1)
2277 const short int* yyconflicts
;
2278 yyStateNum yystate
= yystack
.yytops
.yystates
[yys
]->yylrState
;
2279 yygetLRActions (yystate
, yytoken_to_shift
, &yyaction
,
2281 /* Note that yyconflicts were handled by yyprocessOneStack. */
2282 YYDPRINTF ((stderr
, "On stack %lu, ", (unsigned long int) yys
));
2283 YY_SYMBOL_PRINT ("shifting", yytoken_to_shift
, &yylval
, &yylloc
);
2284 yyglrShift (&yystack
, yys
, yyaction
, yyposn
,
2286 YYDPRINTF ((stderr
, "Stack %lu now in state #%d\n",
2287 (unsigned long int) yys
,
2288 yystack
.yytops
.yystates
[yys
]->yylrState
));
2290 if (yystack
.yytops
.yysize
== 0)
2292 yyundeleteLastStack (&yystack
);
2293 if (yystack
.yytops
.yysize
== 0)
2294 yyFail (&yystack
][]b4_lpure_args
[, YY_("syntax error"));
2295 YYCHK1 (yyresolveStack (&yystack
]b4_user_args
[));
2296 YYDPRINTF ((stderr
, "Returning to deterministic operation.\n"));
2297 ]b4_location_if([[ yystack
.yyerror_range
[1].yystate
.yyloc
= yylloc
;]])[
2298 yyreportSyntaxError (&yystack
]b4_user_args
[);
2301 else if (yystack
.yytops
.yysize
== 1)
2303 YYCHK1 (yyresolveStack (&yystack
]b4_user_args
[));
2304 YYDPRINTF ((stderr
, "Returning to deterministic operation.\n"));
2305 yycompressStack (&yystack
);
2311 yyrecoverSyntaxError (&yystack
]b4_user_args
[);
2312 yyposn
= yystack
.yytops
.yystates
[0]->yyposn
;
2328 yyerror (]b4_lyyerror_args
[YY_("memory exhausted"));
2333 if (yytoken
!= YYEOF
&& yytoken
!= YYEMPTY
)
2334 yydestruct ("Cleanup: discarding lookahead",
2335 yytoken
, &yylval
]b4_location_if([, &yylloc
])[]b4_user_args
[);
2337 /* If the stack is well-formed, pop the stack until it is empty,
2338 destroying its entries as we go. But free the stack regardless
2339 of whether it is well-formed. */
2340 if (yystack
.yyitems
)
2342 yyGLRState
** yystates
= yystack
.yytops
.yystates
;
2345 size_t yysize
= yystack
.yytops
.yysize
;
2347 for (yyk
= 0; yyk
< yysize
; yyk
+= 1)
2350 while (yystates
[yyk
])
2352 yyGLRState
*yys
= yystates
[yyk
];
2353 ]b4_location_if([[ yystack
.yyerror_range
[1].yystate
.yyloc
= yys
->yyloc
;]]
2354 )[ yydestroyGLRState ("Cleanup: popping", yys
]b4_user_args
[);
2355 yystates
[yyk
] = yys
->yypred
;
2356 yystack
.yynextFree
-= 1;
2357 yystack
.yyspaceLeft
+= 1;
2362 yyfreeGLRStack (&yystack
);
2368 /* DEBUGGING ONLY */
2370 static void yypstack (yyGLRStack
* yystackp
, size_t yyk
)
2371 __attribute__ ((__unused__
));
2372 static void yypdumpstack (yyGLRStack
* yystackp
) __attribute__ ((__unused__
));
2375 yy_yypstack (yyGLRState
* yys
)
2379 yy_yypstack (yys
->yypred
);
2380 fprintf (stderr
, " -> ");
2382 fprintf (stderr
, "%d@@%lu", yys
->yylrState
, (unsigned long int) yys
->yyposn
);
2386 yypstates (yyGLRState
* yyst
)
2389 fprintf (stderr
, "<null>");
2392 fprintf (stderr
, "\n");
2396 yypstack (yyGLRStack
* yystackp
, size_t yyk
)
2398 yypstates (yystackp
->yytops
.yystates
[yyk
]);
2401 #define YYINDEX(YYX) \
2402 ((YYX) == NULL ? -1 : (yyGLRStackItem*) (YYX) - yystackp->yyitems)
2406 yypdumpstack (yyGLRStack
* yystackp
)
2408 yyGLRStackItem
* yyp
;
2410 for (yyp
= yystackp
->yyitems
; yyp
< yystackp
->yynextFree
; yyp
+= 1)
2412 fprintf (stderr
, "%3lu. ", (unsigned long int) (yyp
- yystackp
->yyitems
));
2413 if (*(yybool
*) yyp
)
2415 fprintf (stderr
, "Res: %d, LR State: %d, posn: %lu, pred: %ld",
2416 yyp
->yystate
.yyresolved
, yyp
->yystate
.yylrState
,
2417 (unsigned long int) yyp
->yystate
.yyposn
,
2418 (long int) YYINDEX (yyp
->yystate
.yypred
));
2419 if (! yyp
->yystate
.yyresolved
)
2420 fprintf (stderr
, ", firstVal: %ld",
2421 (long int) YYINDEX (yyp
->yystate
.yysemantics
.yyfirstVal
));
2425 fprintf (stderr
, "Option. rule: %d, state: %ld, next: %ld",
2426 yyp
->yyoption
.yyrule
,
2427 (long int) YYINDEX (yyp
->yyoption
.yystate
),
2428 (long int) YYINDEX (yyp
->yyoption
.yynext
));
2430 fprintf (stderr
, "\n");
2432 fprintf (stderr
, "Tops:");
2433 for (yyi
= 0; yyi
< yystackp
->yytops
.yysize
; yyi
+= 1)
2434 fprintf (stderr
, "%lu: %ld; ", (unsigned long int) yyi
,
2435 (long int) YYINDEX (yystackp
->yytops
.yystates
[yyi
]));
2436 fprintf (stderr
, "\n");
2442 m4_if(b4_defines_flag
, 0, [],
2443 [@output @output_header_name@
2444 b4_copyright([Skeleton parser
for GLR parsing with Bison
],
2445 [2002, 2003, 2004, 2005])[
2447 /* As a special exception, when this parser skeleton is copied by
2448 Bison into a Bison output file, you may use that output file
2449 without restriction. This special exception was added by the Free
2450 Software Foundation for C GLR parsers in version 2.2 of Bison. */
2452 /* C GLR parser skeleton written by Paul Hilfinger. */
2455 b4_shared_declarations
2457 extern YYSTYPE b4_prefix
[]lval
;
2459 b4_location_if([b4_pure_if([],
2460 [extern YYLTYPE b4_prefix
[]lloc
;])