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
])
95 ## ----------------- ##
96 ## Semantic Values. ##
97 ## ----------------- ##
100 # b4_lhs_value([TYPE])
101 # --------------------
102 # Expansion of $<TYPE>$.
103 m4_define([b4_lhs_value
],
104 [((*yyvalp
)[]m4_ifval([$
1], [.$
1]))])
107 # b4_rhs_value(RULE-LENGTH, NUM, [TYPE])
108 # --------------------------------------
109 # Expansion of $<TYPE>NUM, where the current rule has RULE-LENGTH
111 m4_define([b4_rhs_value
],
112 [(((yyGLRStackItem
const *)yyvsp
)@
{YYFILL (($
2) - ($
1))@
}.yystate
.yysemantics
.yysval
[]m4_ifval([$
3], [.$
3]))])
123 m4_define([b4_lhs_location
],
127 # b4_rhs_location(RULE-LENGTH, NUM)
128 # ---------------------------------
129 # Expansion of @NUM, where the current rule has RULE-LENGTH symbols
131 m4_define([b4_rhs_location
],
132 [(((yyGLRStackItem
const *)yyvsp
)@
{YYFILL (($
2) - ($
1))@
}.yystate
.yyloc
)])
140 # We do want M4 expansion after # for CPP macros.
143 @output @output_parser_name@
144 b4_copyright([Skeleton parser
for GLR parsing with Bison
],
145 [2002, 2003, 2004, 2005])
147 /* This is the parser code for GLR (Generalized LR) parser. */
151 m4_if(b4_prefix
[], [yy
], [],
152 [/* Substitute the variable and function names. */
153 #define yyparse b4_prefix[]parse
154 #define yylex b4_prefix[]lex
155 #define yyerror b4_prefix[]error
156 #define yylval b4_prefix[]lval
157 #define yychar b4_prefix[]char
158 #define yydebug b4_prefix[]debug
159 #define yynerrs b4_prefix[]nerrs
160 #define yylloc b4_prefix[]lloc])
162 dnl
# b4_shared_declarations
163 dnl
# ----------------------
164 dnl
# Declaration that might either go into the header (if --defines)
165 dnl
# or open coded in the parser body.
166 m4_define([b4_shared_declarations
],
167 [b4_token_enums(b4_tokens
)[
169 /* Copy the first part of user declarations. */
172 #if ! defined (YYSTYPE) && ! defined (YYSTYPE_IS_DECLARED)
173 ]m4_ifdef([b4_stype
],
174 [b4_syncline([b4_stype_line
], [b4_file_name
])
175 typedef union m4_bregexp(b4_stype
, [^{], [YYSTYPE
])b4_stype YYSTYPE
;
176 /* Line __line__ of glr.c. */
177 b4_syncline([@oline@
], [@ofile@
])],
178 [typedef int YYSTYPE
;])[
179 # define YYSTYPE_IS_DECLARED 1
180 # define YYSTYPE_IS_TRIVIAL 1
183 #if ! defined (YYLTYPE) && ! defined (YYLTYPE_IS_DECLARED)
184 typedef struct YYLTYPE
195 # define YYLTYPE_IS_DECLARED 1
196 # define YYLTYPE_IS_TRIVIAL 1
200 m4_if(b4_defines_flag
, 0,
201 [b4_shared_declarations
],
202 [#include @output_header_name@])[
204 /* Enabling traces. */
206 # define YYDEBUG ]b4_debug[
209 /* Enabling verbose error messages. */
210 #ifdef YYERROR_VERBOSE
211 # undef YYERROR_VERBOSE
212 # define YYERROR_VERBOSE 1
214 # define YYERROR_VERBOSE ]b4_error_verbose[
217 /* Enabling the token table. */
218 #ifndef YYTOKEN_TABLE
219 # define YYTOKEN_TABLE ]b4_token_table[
222 /* Default (constant) value used for initialization for null
223 right-hand sides. Unlike the standard yacc.c template,
224 here we set the default value of $$ to a zeroed-out value.
225 Since the default value is undefined, this behavior is
226 technically correct. */
227 static YYSTYPE yyval_default
;
229 /* Copy the second part of user declarations. */
232 ]/* Line __line__ of glr.c. */
233 b4_syncline([@oline@
], [@ofile@
])
243 # include <libintl.h> /* INFRINGES ON USER NAME SPACE */
244 # define YY_(msgid) dgettext ("bison-runtime", msgid)
248 # define YY_(msgid) msgid
252 /* Suppress unused-variable warnings by "using" E. */
254 # define YYUSE(e) ((void) (e))
256 # define YYUSE(e) /* empty */
259 /* Identity function, used to suppress warnings about constant conditions. */
263 ]b4_c_function_def([YYID
], [static int], [[int i
], [i
]])[
273 # define YYMALLOC malloc
276 # define YYREALLOC realloc
279 #define YYSIZEMAX ((size_t) -1)
284 typedef unsigned char yybool
;
291 # define YYJMP_BUF jmp_buf
292 # define YYSETJMP(env) setjmp (env)
293 # define YYLONGJMP(env, val) longjmp (env, val)
300 #ifndef __attribute__
301 /* This feature is available in gcc versions 2.5 and later. */
302 # if (!defined (__GNUC__) || __GNUC__ < 2 \
303 || (__GNUC__ == 2 && __GNUC_MINOR__ < 5) || __STRICT_ANSI__)
304 # define __attribute__(Spec) /* empty */
308 ]b4_location_if([#define YYOPTIONAL_LOC(Name) Name],[
310 # define YYOPTIONAL_LOC(Name) /* empty */
312 # define YYOPTIONAL_LOC(Name) Name __attribute__ ((__unused__))
316 # define YYASSERT(condition) ((void) ((condition) || (abort (), 0)))
319 /* YYFINAL -- State number of the termination state. */
320 #define YYFINAL ]b4_final_state_number[
321 /* YYLAST -- Last index in YYTABLE. */
322 #define YYLAST ]b4_last[
324 /* YYNTOKENS -- Number of terminals. */
325 #define YYNTOKENS ]b4_tokens_number[
326 /* YYNNTS -- Number of nonterminals. */
327 #define YYNNTS ]b4_nterms_number[
328 /* YYNRULES -- Number of rules. */
329 #define YYNRULES ]b4_rules_number[
330 /* YYNRULES -- Number of states. */
331 #define YYNSTATES ]b4_states_number[
332 /* YYMAXRHS -- Maximum number of symbols on right-hand side of rule. */
333 #define YYMAXRHS ]b4_r2_max[
334 /* YYMAXLEFT -- Maximum number of symbols to the left of a handle
335 accessed by $0, $-1, etc., in any rule. */
336 #define YYMAXLEFT ]b4_max_left_semantic_context[
338 /* YYTRANSLATE(X) -- Bison symbol number corresponding to X. */
339 #define YYUNDEFTOK ]b4_undef_token_number[
340 #define YYMAXUTOK ]b4_user_token_number_max[
342 #define YYTRANSLATE(YYX) \
343 ((YYX <= 0) ? YYEOF : \
344 (unsigned int) (YYX) <= YYMAXUTOK ? yytranslate[YYX] : YYUNDEFTOK)
346 /* YYTRANSLATE[YYLEX] -- Bison symbol number corresponding to YYLEX. */
347 static const ]b4_int_type_for([b4_translate
])[ yytranslate
[] =
353 /* YYPRHS[YYN] -- Index of the first RHS symbol of rule number YYN in
355 static const ]b4_int_type_for([b4_prhs
])[ yyprhs
[] =
360 /* YYRHS -- A `-1'-separated list of the rules' RHS. */
361 static const ]b4_int_type_for([b4_rhs
])[ yyrhs
[] =
366 /* YYRLINE[YYN] -- source line where rule number YYN was defined. */
367 static const ]b4_int_type_for([b4_rline
])[ yyrline
[] =
373 #if YYDEBUG || YYERROR_VERBOSE || YYTOKEN_TABLE
374 /* YYTNAME[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM.
375 First, the terminals, then, starting at YYNTOKENS, nonterminals. */
376 static const char *const yytname
[] =
382 /* YYR1[YYN] -- Symbol number of symbol that rule YYN derives. */
383 static const ]b4_int_type_for([b4_r1
])[ yyr1
[] =
388 /* YYR2[YYN] -- Number of symbols composing right hand side of rule YYN. */
389 static const ]b4_int_type_for([b4_r2
])[ yyr2
[] =
394 /* YYDPREC[RULE-NUM] -- Dynamic precedence of rule #RULE-NUM (0 if none). */
395 static const ]b4_int_type_for([b4_dprec
])[ yydprec
[] =
400 /* YYMERGER[RULE-NUM] -- Index of merging function for rule #RULE-NUM. */
401 static const ]b4_int_type_for([b4_merger
])[ yymerger
[] =
406 /* YYDEFACT[S] -- default rule to reduce with in state S when YYTABLE
407 doesn't specify something else to do. Zero means the default is an
409 static const ]b4_int_type_for([b4_defact
])[ yydefact
[] =
414 /* YYPDEFGOTO[NTERM-NUM]. */
415 static const ]b4_int_type_for([b4_defgoto
])[ yydefgoto
[] =
420 /* YYPACT[STATE-NUM] -- Index in YYTABLE of the portion describing
422 #define YYPACT_NINF ]b4_pact_ninf[
423 static const ]b4_int_type_for([b4_pact
])[ yypact
[] =
428 /* YYPGOTO[NTERM-NUM]. */
429 static const ]b4_int_type_for([b4_pgoto
])[ yypgoto
[] =
434 /* YYTABLE[YYPACT[STATE-NUM]]. What to do in state STATE-NUM. If
435 positive, shift that token. If negative, reduce the rule which
436 number is the opposite. If zero, do what YYDEFACT says.
437 If YYTABLE_NINF, syntax error. */
438 #define YYTABLE_NINF ]b4_table_ninf[
439 static const ]b4_int_type_for([b4_table
])[ yytable
[] =
444 /* YYCONFLP[YYPACT[STATE-NUM]] -- Pointer into YYCONFL of start of
445 list of conflicting reductions corresponding to action entry for
446 state STATE-NUM in yytable. 0 means no conflicts. The list in
447 yyconfl is terminated by a rule number of 0. */
448 static const ]b4_int_type_for([b4_conflict_list_heads
])[ yyconflp
[] =
450 ]b4_conflict_list_heads
[
453 /* YYCONFL[I] -- lists of conflicting rule numbers, each terminated by
454 0, pointed into by YYCONFLP. */
455 ]dnl Do
not use b4_int_type_for here
, since there are places where
456 dnl pointers onto yyconfl are taken
, which type is
"short int *".
457 dnl We probably ought to introduce a type
for confl
.
458 [static const short int yyconfl
[] =
460 ]b4_conflicting_rules
[
463 static const ]b4_int_type_for([b4_check
])[ yycheck
[] =
468 /* YYSTOS[STATE-NUM] -- The (internal number of the) accessing
469 symbol of state STATE-NUM. */
470 static const ]b4_int_type_for([b4_stos
])[ yystos
[] =
476 /* Prevent warning if -Wmissing-prototypes. */
477 ]b4_c_ansi_function_decl([yyparse
], [int], b4_parse_param
)[
479 /* Error token number */
482 /* YYLLOC_DEFAULT -- Set CURRENT to span from RHS[1] to RHS[N].
483 If N is 0, then set CURRENT to the empty location which ends
484 the previous symbol: RHS[0] (always defined). */
487 #define YYRHSLOC(Rhs, K) ((Rhs)[K].yystate.yyloc)
488 #ifndef YYLLOC_DEFAULT
489 # define YYLLOC_DEFAULT(Current, Rhs, N) \
493 (Current).first_line = YYRHSLOC (Rhs, 1).first_line; \
494 (Current).first_column = YYRHSLOC (Rhs, 1).first_column; \
495 (Current).last_line = YYRHSLOC (Rhs, N).last_line; \
496 (Current).last_column = YYRHSLOC (Rhs, N).last_column; \
500 (Current).first_line = (Current).last_line = \
501 YYRHSLOC (Rhs, 0).last_line; \
502 (Current).first_column = (Current).last_column = \
503 YYRHSLOC (Rhs, 0).last_column; \
507 /* YY_LOCATION_PRINT -- Print the location on the stream.
508 This macro was not mandated originally: define only if we know
509 we won't break user code: when these are the locations we know. */
511 # define YY_LOCATION_PRINT(File, Loc) \
512 fprintf (File, "%d.%d-%d.%d", \
513 (Loc).first_line, (Loc).first_column, \
514 (Loc).last_line, (Loc).last_column)
517 #ifndef YYLLOC_DEFAULT
518 # define YYLLOC_DEFAULT(Current, Rhs, N) ((void) 0)
522 #ifndef YY_LOCATION_PRINT
523 # define YY_LOCATION_PRINT(File, Loc) ((void) 0)
527 /* YYLEX -- calling `yylex' with the right arguments. */
528 #define YYLEX ]b4_c_function_call([yylex], [int], b4_lex_param)[
533 #define yynerrs (yystackp->yyerrcnt)
535 #define yychar (yystackp->yyrawchar)
537 #define yylval (yystackp->yyval)
539 #define yylloc (yystackp->yyloc)
540 m4_if(b4_prefix
[], [yy
], [],
541 [#define b4_prefix[]nerrs yynerrs
542 #define b4_prefix[]char yychar
543 #define b4_prefix[]lval yylval
544 #define b4_prefix[]lloc yylloc])],
552 static const int YYEOF
= 0;
553 static const int YYEMPTY
= -2;
555 typedef enum { yyok
, yyaccept
, yyabort
, yyerr
} YYRESULTTAG
;
558 do { YYRESULTTAG yyflag = YYE; if (yyflag != yyok) return yyflag; } \
563 #if ! defined (YYFPRINTF)
564 # define YYFPRINTF fprintf
567 # define YYDPRINTF(Args) \
573 ]b4_yy_symbol_print_generate([b4_c_ansi_function_def
])[
575 # define YY_SYMBOL_PRINT(Title, Type, Value, Location) \
579 YYFPRINTF (stderr, "%s ", Title); \
580 yy_symbol_print (stderr, Type, \
581 Value]b4_location_if([, Location])[]b4_user_args[); \
582 YYFPRINTF (stderr, "\n"); \
586 /* Nonzero means print parse trace. It is left uninitialized so that
587 multiple parsers can coexist. */
592 # define YYDPRINTF(Args)
593 # define YY_SYMBOL_PRINT(Title, Type, Value, Location)
595 #endif /* !YYDEBUG */
597 /* YYINITDEPTH -- initial size of the parser's stacks. */
599 # define YYINITDEPTH ]b4_stack_depth_init[
602 /* YYMAXDEPTH -- maximum size the stacks can grow to (effective only
603 if the built-in stack extension method is used).
605 Do not make this value too large; the results are undefined if
606 SIZE_MAX < YYMAXDEPTH * sizeof (GLRStackItem)
607 evaluated with infinite-precision integer arithmetic. */
610 # define YYMAXDEPTH ]b4_stack_depth_max[
613 /* Minimum number of free items on the stack allowed after an
614 allocation. This is to allow allocation and initialization
615 to be completed by functions that call yyexpandGLRStack before the
616 stack is expanded, thus insuring that all necessary pointers get
617 properly redirected to new data. */
620 #ifndef YYSTACKEXPANDABLE
621 # if (! defined (__cplusplus) \
622 || (]b4_location_if([[defined (YYLTYPE_IS_TRIVIAL) && YYLTYPE_IS_TRIVIAL \
623 && ]])[defined (YYSTYPE_IS_TRIVIAL) && YYSTYPE_IS_TRIVIAL))
624 # define YYSTACKEXPANDABLE 1
626 # define YYSTACKEXPANDABLE 0
630 #if YYSTACKEXPANDABLE
631 # define YY_RESERVE_GLRSTACK(Yystack) \
633 if (Yystack->yyspaceLeft < YYHEADROOM) \
634 yyexpandGLRStack (Yystack); \
637 # define YY_RESERVE_GLRSTACK(Yystack) \
639 if (Yystack->yyspaceLeft < YYHEADROOM) \
640 yyMemoryExhausted (Yystack); \
648 # if defined (__GLIBC__) && defined (_STRING_H) && defined (_GNU_SOURCE)
649 # define yystpcpy stpcpy
651 /* Copy YYSRC to YYDEST, returning the address of the terminating '\0' in
654 yystpcpy (char *yydest
, const char *yysrc
)
657 const char *yys
= yysrc
;
659 while ((*yyd
++ = *yys
++) != '\0')
668 /* Copy to YYRES the contents of YYSTR after stripping away unnecessary
669 quotes and backslashes, so that it's suitable for yyerror. The
670 heuristic is that double-quoting is unnecessary unless the string
671 contains an apostrophe, a comma, or backslash (other than
672 backslash-backslash). YYSTR is taken from yytname. If YYRES is
673 null, do not copy; instead, return the length of what the result
676 yytnamerr (char *yyres
, const char *yystr
)
681 char const *yyp
= yystr
;
688 goto do_not_strip_quotes
;
692 goto do_not_strip_quotes
;
705 do_not_strip_quotes
: ;
709 return strlen (yystr
);
711 return yystpcpy (yyres
, yystr
) - yyres
;
715 #endif /* !YYERROR_VERBOSE */
717 /** State numbers, as in LALR(1) machine */
718 typedef int yyStateNum
;
720 /** Rule numbers, as in LALR(1) machine */
721 typedef int yyRuleNum
;
723 /** Grammar symbol */
724 typedef short int yySymbol
;
726 /** Item references, as in LALR(1) machine */
727 typedef short int yyItemNum
;
729 typedef struct yyGLRState yyGLRState
;
730 typedef struct yyGLRStateSet yyGLRStateSet
;
731 typedef struct yySemanticOption yySemanticOption
;
732 typedef union yyGLRStackItem yyGLRStackItem
;
733 typedef struct yyGLRStack yyGLRStack
;
736 /** Type tag: always true. */
738 /** Type tag for yysemantics. If true, yysval applies, otherwise
739 * yyfirstVal applies. */
741 /** Number of corresponding LALR(1) machine state. */
742 yyStateNum yylrState
;
743 /** Preceding state in this stack */
745 /** Source position of the first token produced by my symbol */
748 /** First in a chain of alternative reductions producing the
749 * non-terminal corresponding to this state, threaded through
751 yySemanticOption
* yyfirstVal
;
752 /** Semantic value for this state. */
755 /** Source location for this state. */
759 struct yyGLRStateSet
{
760 yyGLRState
** yystates
;
761 size_t yysize
, yycapacity
;
764 struct yySemanticOption
{
765 /** Type tag: always false. */
767 /** Rule number for this reduction */
769 /** The last RHS state in the list of states to be reduced. */
771 /** Next sibling in chain of options. To facilitate merging,
772 * options are chained in decreasing order by address. */
773 yySemanticOption
* yynext
;
776 /** Type of the items in the GLR stack. The yyisState field
777 * indicates which item of the union is valid. */
778 union yyGLRStackItem
{
780 yySemanticOption yyoption
;
785 ]b4_location_if([[ /* To compute the location of the error token. */
786 yyGLRStackItem yyerror_range
[3];]])[
795 YYJMP_BUF yyexception_buffer
;
796 yyGLRStackItem
* yyitems
;
797 yyGLRStackItem
* yynextFree
;
799 yyGLRState
* yysplitPoint
;
800 yyGLRState
* yylastDeleted
;
801 yyGLRStateSet yytops
;
804 #if YYSTACKEXPANDABLE
805 static void yyexpandGLRStack (yyGLRStack
* yystackp
);
808 static void yyFail (yyGLRStack
* yystackp
]b4_pure_formals
[, const char* yymsg
)
809 __attribute__ ((__noreturn__
));
811 yyFail (yyGLRStack
* yystackp
]b4_pure_formals
[, const char* yymsg
)
814 yyerror (]b4_yyerror_args
[yymsg
);
815 YYLONGJMP (yystackp
->yyexception_buffer
, 1);
818 static void yyMemoryExhausted (yyGLRStack
* yystackp
)
819 __attribute__ ((__noreturn__
));
821 yyMemoryExhausted (yyGLRStack
* yystackp
)
823 YYLONGJMP (yystackp
->yyexception_buffer
, 2);
826 #if YYDEBUG || YYERROR_VERBOSE
827 /** A printable representation of TOKEN. */
828 static inline const char*
829 yytokenName (yySymbol yytoken
)
831 if (yytoken
== YYEMPTY
)
834 return yytname
[yytoken
];
838 /** Fill in YYVSP[YYLOW1 .. YYLOW0-1] from the chain of states starting
839 * at YYVSP[YYLOW0].yystate.yypred. Leaves YYVSP[YYLOW1].yystate.yypred
840 * containing the pointer to the next state in the chain. */
841 static void yyfillin (yyGLRStackItem
*, int, int) __attribute__ ((__unused__
));
843 yyfillin (yyGLRStackItem
*yyvsp
, int yylow0
, int yylow1
)
847 s
= yyvsp
[yylow0
].yystate
.yypred
;
848 for (i
= yylow0
-1; i
>= yylow1
; i
-= 1)
850 YYASSERT (s
->yyresolved
);
851 yyvsp
[i
].yystate
.yyresolved
= yytrue
;
852 yyvsp
[i
].yystate
.yysemantics
.yysval
= s
->yysemantics
.yysval
;
853 yyvsp
[i
].yystate
.yyloc
= s
->yyloc
;
854 s
= yyvsp
[i
].yystate
.yypred
= s
->yypred
;
858 /* Do nothing if YYNORMAL or if *YYLOW <= YYLOW1. Otherwise, fill in
859 * YYVSP[YYLOW1 .. *YYLOW-1] as in yyfillin and set *YYLOW = YYLOW1.
860 * For convenience, always return YYLOW1. */
861 static inline int yyfill (yyGLRStackItem
*, int *, int, yybool
)
862 __attribute__ ((__unused__
));
864 yyfill (yyGLRStackItem
*yyvsp
, int *yylow
, int yylow1
, yybool yynormal
)
866 if (!yynormal
&& yylow1
< *yylow
)
868 yyfillin (yyvsp
, *yylow
, yylow1
);
874 /** Perform user action for rule number YYN, with RHS length YYRHSLEN,
875 * and top stack item YYVSP. YYLVALP points to place to put semantic
876 * value ($$), and yylocp points to place for location information
877 * (@@$). Returns yyok for normal return, yyaccept for YYACCEPT,
878 * yyerr for YYERROR, yyabort for YYABORT. */
879 /*ARGSUSED*/ static YYRESULTTAG
880 yyuserAction (yyRuleNum yyn
, int yyrhslen
, yyGLRStackItem
* yyvsp
,
882 YYLTYPE
* YYOPTIONAL_LOC (yylocp
),
886 yybool yynormal
__attribute__ ((__unused__
)) =
887 (yystackp
->yysplitPoint
== NULL
);
889 ]b4_parse_param_use
[]dnl
891 # define yyerrok (yystackp->yyerrState = 0)
893 # define YYACCEPT return yyaccept
895 # define YYABORT return yyabort
897 # define YYERROR return yyerrok, yyerr
899 # define YYRECOVERING (yystackp->yyerrState != 0)
901 # define yyclearin (yychar = *(yystackp->yytokenp) = YYEMPTY)
903 # define YYFILL(N) yyfill (yyvsp, &yylow, N, yynormal)
905 # define YYBACKUP(Token, Value) \
906 return yyerror (]b4_yyerror_args[YY_("syntax error: cannot back up")), \
911 *yyvalp
= yyval_default
;
913 *yyvalp
= yyvsp
[YYFILL (1-yyrhslen
)].yystate
.yysemantics
.yysval
;
914 YYLLOC_DEFAULT (*yylocp
, yyvsp
- yyrhslen
, yyrhslen
);
915 ]b4_location_if([[ yystackp
->yyerror_range
[1].yystate
.yyloc
= *yylocp
;
920 /* Line __line__ of glr.c. */
921 b4_syncline([@oline@
], [@ofile@
])[
936 /*ARGSUSED*/ static void
937 yyuserMerge (int yyn
, YYSTYPE
* yy0
, YYSTYPE
* yy1
)
949 /* Bison grammar-table manipulation. */
951 ]b4_yydestruct_generate([b4_c_ansi_function_def
])[
953 /** Number of symbols composing the right hand side of rule #RULE. */
955 yyrhsLength (yyRuleNum yyrule
)
961 yydestroyGLRState (char const *yymsg
, yyGLRState
*yys
]b4_user_formals
[)
964 yydestruct (yymsg
, yystos
[yys
->yylrState
],
965 &yys
->yysemantics
.yysval
]b4_location_if([, &yys
->yyloc
])[]b4_user_args
[);
971 YYFPRINTF (stderr
, "%s unresolved ", yymsg
);
972 yy_symbol_print (stderr
, yystos
[yys
->yylrState
],
973 &yys
->yysemantics
.yysval
]b4_location_if([, &yys
->yyloc
])[]b4_user_args
[);
974 YYFPRINTF (stderr
, "\n");
978 if (yys
->yysemantics
.yyfirstVal
)
980 yySemanticOption
*yyoption
= yys
->yysemantics
.yyfirstVal
;
983 for (yyrh
= yyoption
->yystate
, yyn
= yyrhsLength (yyoption
->yyrule
);
985 yyrh
= yyrh
->yypred
, yyn
-= 1)
986 yydestroyGLRState (yymsg
, yyrh
]b4_user_args
[);
991 /** Left-hand-side symbol for rule #RULE. */
992 static inline yySymbol
993 yylhsNonterm (yyRuleNum yyrule
)
998 #define yyis_pact_ninf(yystate) \
999 ]m4_if(m4_eval(b4_pact_ninf < b4_pact_min), [1],
1001 [((yystate
) == YYPACT_NINF
)])[
1003 /** True iff LR state STATE has only a default reduction (regardless
1005 static inline yybool
1006 yyisDefaultedState (yyStateNum yystate
)
1008 return yyis_pact_ninf (yypact
[yystate
]);
1011 /** The default reduction for STATE, assuming it has one. */
1012 static inline yyRuleNum
1013 yydefaultAction (yyStateNum yystate
)
1015 return yydefact
[yystate
];
1018 #define yyis_table_ninf(yytable_value) \
1019 ]m4_if(m4_eval(b4_table_ninf < b4_table_min), [1],
1021 [((yytable_value
) == YYTABLE_NINF
)])[
1023 /** Set *YYACTION to the action to take in YYSTATE on seeing YYTOKEN.
1025 * R < 0: Reduce on rule -R.
1027 * R > 0: Shift to state R.
1028 * Set *CONFLICTS to a pointer into yyconfl to 0-terminated list of
1029 * conflicting reductions.
1032 yygetLRActions (yyStateNum yystate
, int yytoken
,
1033 int* yyaction
, const short int** yyconflicts
)
1035 int yyindex
= yypact
[yystate
] + yytoken
;
1036 if (yyindex
< 0 || YYLAST
< yyindex
|| yycheck
[yyindex
] != yytoken
)
1038 *yyaction
= -yydefact
[yystate
];
1039 *yyconflicts
= yyconfl
;
1041 else if (! yyis_table_ninf (yytable
[yyindex
]))
1043 *yyaction
= yytable
[yyindex
];
1044 *yyconflicts
= yyconfl
+ yyconflp
[yyindex
];
1049 *yyconflicts
= yyconfl
+ yyconflp
[yyindex
];
1053 static inline yyStateNum
1054 yyLRgotoState (yyStateNum yystate
, yySymbol yylhs
)
1057 yyr
= yypgoto
[yylhs
- YYNTOKENS
] + yystate
;
1058 if (0 <= yyr
&& yyr
<= YYLAST
&& yycheck
[yyr
] == yystate
)
1059 return yytable
[yyr
];
1061 return yydefgoto
[yylhs
- YYNTOKENS
];
1064 static inline yybool
1065 yyisShiftAction (int yyaction
)
1067 return 0 < yyaction
;
1070 static inline yybool
1071 yyisErrorAction (int yyaction
)
1073 return yyaction
== 0;
1078 /** Return a fresh GLRStackItem. Callers should call
1079 * YY_RESERVE_GLRSTACK afterwards to make sure there is sufficient
1082 static inline yyGLRStackItem
*
1083 yynewGLRStackItem (yyGLRStack
* yystackp
, yybool yyisState
)
1085 yyGLRStackItem
* yynewItem
= yystackp
->yynextFree
;
1086 yystackp
->yyspaceLeft
-= 1;
1087 yystackp
->yynextFree
+= 1;
1088 yynewItem
->yystate
.yyisState
= yyisState
;
1093 yyaddDeferredAction (yyGLRStack
* yystackp
, yyGLRState
* yystate
,
1094 yyGLRState
* rhs
, yyRuleNum yyrule
)
1096 yySemanticOption
* yynewOption
=
1097 &yynewGLRStackItem (yystackp
, yyfalse
)->yyoption
;
1098 yynewOption
->yystate
= rhs
;
1099 yynewOption
->yyrule
= yyrule
;
1100 yynewOption
->yynext
= yystate
->yysemantics
.yyfirstVal
;
1101 yystate
->yysemantics
.yyfirstVal
= yynewOption
;
1103 YY_RESERVE_GLRSTACK (yystackp
);
1108 /** Initialize SET to a singleton set containing an empty stack. */
1110 yyinitStateSet (yyGLRStateSet
* yyset
)
1113 yyset
->yycapacity
= 16;
1114 yyset
->yystates
= (yyGLRState
**) YYMALLOC (16 * sizeof yyset
->yystates
[0]);
1115 if (! yyset
->yystates
)
1117 yyset
->yystates
[0] = NULL
;
1121 static void yyfreeStateSet (yyGLRStateSet
* yyset
)
1123 YYFREE (yyset
->yystates
);
1126 /** Initialize STACK to a single empty stack, with total maximum
1127 * capacity for all stacks of SIZE. */
1129 yyinitGLRStack (yyGLRStack
* yystackp
, size_t yysize
)
1131 yystackp
->yyerrState
= 0;
1133 yystackp
->yyspaceLeft
= yysize
;
1135 (yyGLRStackItem
*) YYMALLOC (yysize
* sizeof yystackp
->yynextFree
[0]);
1136 if (!yystackp
->yyitems
)
1138 yystackp
->yynextFree
= yystackp
->yyitems
;
1139 yystackp
->yysplitPoint
= NULL
;
1140 yystackp
->yylastDeleted
= NULL
;
1141 return yyinitStateSet (&yystackp
->yytops
);
1145 #if YYSTACKEXPANDABLE
1146 # define YYRELOC(YYFROMITEMS,YYTOITEMS,YYX,YYTYPE) \
1147 &((YYTOITEMS) - ((YYFROMITEMS) - (yyGLRStackItem*) (YYX)))->YYTYPE
1149 /** If STACK is expandable, extend it. WARNING: Pointers into the
1150 stack from outside should be considered invalid after this call.
1151 We always expand when there are 1 or fewer items left AFTER an
1152 allocation, so that we can avoid having external pointers exist
1153 across an allocation. */
1155 yyexpandGLRStack (yyGLRStack
* yystackp
)
1157 yyGLRStackItem
* yynewItems
;
1158 yyGLRStackItem
* yyp0
, *yyp1
;
1159 size_t yysize
, yynewSize
;
1161 yysize
= yystackp
->yynextFree
- yystackp
->yyitems
;
1162 if (YYMAXDEPTH
<= yysize
)
1163 yyMemoryExhausted (yystackp
);
1164 yynewSize
= 2*yysize
;
1165 if (YYMAXDEPTH
< yynewSize
)
1166 yynewSize
= YYMAXDEPTH
;
1167 yynewItems
= (yyGLRStackItem
*) YYMALLOC (yynewSize
* sizeof yynewItems
[0]);
1169 yyMemoryExhausted (yystackp
);
1170 for (yyp0
= yystackp
->yyitems
, yyp1
= yynewItems
, yyn
= yysize
;
1172 yyn
-= 1, yyp0
+= 1, yyp1
+= 1)
1175 if (*(yybool
*) yyp0
)
1177 yyGLRState
* yys0
= &yyp0
->yystate
;
1178 yyGLRState
* yys1
= &yyp1
->yystate
;
1179 if (yys0
->yypred
!= NULL
)
1181 YYRELOC (yyp0
, yyp1
, yys0
->yypred
, yystate
);
1182 if (! yys0
->yyresolved
&& yys0
->yysemantics
.yyfirstVal
!= NULL
)
1183 yys1
->yysemantics
.yyfirstVal
=
1184 YYRELOC(yyp0
, yyp1
, yys0
->yysemantics
.yyfirstVal
, yyoption
);
1188 yySemanticOption
* yyv0
= &yyp0
->yyoption
;
1189 yySemanticOption
* yyv1
= &yyp1
->yyoption
;
1190 if (yyv0
->yystate
!= NULL
)
1191 yyv1
->yystate
= YYRELOC (yyp0
, yyp1
, yyv0
->yystate
, yystate
);
1192 if (yyv0
->yynext
!= NULL
)
1193 yyv1
->yynext
= YYRELOC (yyp0
, yyp1
, yyv0
->yynext
, yyoption
);
1196 if (yystackp
->yysplitPoint
!= NULL
)
1197 yystackp
->yysplitPoint
= YYRELOC (yystackp
->yyitems
, yynewItems
,
1198 yystackp
->yysplitPoint
, yystate
);
1200 for (yyn
= 0; yyn
< yystackp
->yytops
.yysize
; yyn
+= 1)
1201 if (yystackp
->yytops
.yystates
[yyn
] != NULL
)
1202 yystackp
->yytops
.yystates
[yyn
] =
1203 YYRELOC (yystackp
->yyitems
, yynewItems
,
1204 yystackp
->yytops
.yystates
[yyn
], yystate
);
1205 YYFREE (yystackp
->yyitems
);
1206 yystackp
->yyitems
= yynewItems
;
1207 yystackp
->yynextFree
= yynewItems
+ yysize
;
1208 yystackp
->yyspaceLeft
= yynewSize
- yysize
;
1213 yyfreeGLRStack (yyGLRStack
* yystackp
)
1215 YYFREE (yystackp
->yyitems
);
1216 yyfreeStateSet (&yystackp
->yytops
);
1219 /** Assuming that S is a GLRState somewhere on STACK, update the
1220 * splitpoint of STACK, if needed, so that it is at least as deep as
1223 yyupdateSplit (yyGLRStack
* yystackp
, yyGLRState
* yys
)
1225 if (yystackp
->yysplitPoint
!= NULL
&& yystackp
->yysplitPoint
> yys
)
1226 yystackp
->yysplitPoint
= yys
;
1229 /** Invalidate stack #K in STACK. */
1231 yymarkStackDeleted (yyGLRStack
* yystackp
, size_t yyk
)
1233 if (yystackp
->yytops
.yystates
[yyk
] != NULL
)
1234 yystackp
->yylastDeleted
= yystackp
->yytops
.yystates
[yyk
];
1235 yystackp
->yytops
.yystates
[yyk
] = NULL
;
1238 /** Undelete the last stack that was marked as deleted. Can only be
1239 done once after a deletion, and only when all other stacks have
1242 yyundeleteLastStack (yyGLRStack
* yystackp
)
1244 if (yystackp
->yylastDeleted
== NULL
|| yystackp
->yytops
.yysize
!= 0)
1246 yystackp
->yytops
.yystates
[0] = yystackp
->yylastDeleted
;
1247 yystackp
->yytops
.yysize
= 1;
1248 YYDPRINTF ((stderr
, "Restoring last deleted stack as stack #0.\n"));
1249 yystackp
->yylastDeleted
= NULL
;
1253 yyremoveDeletes (yyGLRStack
* yystackp
)
1257 while (yyj
< yystackp
->yytops
.yysize
)
1259 if (yystackp
->yytops
.yystates
[yyi
] == NULL
)
1263 YYDPRINTF ((stderr
, "Removing dead stacks.\n"));
1265 yystackp
->yytops
.yysize
-= 1;
1269 yystackp
->yytops
.yystates
[yyj
] = yystackp
->yytops
.yystates
[yyi
];
1272 YYDPRINTF ((stderr
, "Rename stack %lu -> %lu.\n",
1273 (unsigned long int) yyi
, (unsigned long int) yyj
));
1281 /** Shift to a new state on stack #K of STACK, corresponding to LR state
1282 * LRSTATE, at input position POSN, with (resolved) semantic value SVAL. */
1284 yyglrShift (yyGLRStack
* yystackp
, size_t yyk
, yyStateNum yylrState
,
1286 YYSTYPE
* yyvalp
, YYLTYPE
* yylocp
)
1288 yyGLRState
* yynewState
= &yynewGLRStackItem (yystackp
, yytrue
)->yystate
;
1290 yynewState
->yylrState
= yylrState
;
1291 yynewState
->yyposn
= yyposn
;
1292 yynewState
->yyresolved
= yytrue
;
1293 yynewState
->yypred
= yystackp
->yytops
.yystates
[yyk
];
1294 yynewState
->yysemantics
.yysval
= *yyvalp
;
1295 yynewState
->yyloc
= *yylocp
;
1296 yystackp
->yytops
.yystates
[yyk
] = yynewState
;
1298 YY_RESERVE_GLRSTACK (yystackp
);
1301 /** Shift stack #K of YYSTACK, to a new state corresponding to LR
1302 * state YYLRSTATE, at input position YYPOSN, with the (unresolved)
1303 * semantic value of YYRHS under the action for YYRULE. */
1305 yyglrShiftDefer (yyGLRStack
* yystackp
, size_t yyk
, yyStateNum yylrState
,
1306 size_t yyposn
, yyGLRState
* rhs
, yyRuleNum yyrule
)
1308 yyGLRState
* yynewState
= &yynewGLRStackItem (yystackp
, yytrue
)->yystate
;
1310 yynewState
->yylrState
= yylrState
;
1311 yynewState
->yyposn
= yyposn
;
1312 yynewState
->yyresolved
= yyfalse
;
1313 yynewState
->yypred
= yystackp
->yytops
.yystates
[yyk
];
1314 yynewState
->yysemantics
.yyfirstVal
= NULL
;
1315 yystackp
->yytops
.yystates
[yyk
] = yynewState
;
1317 /* Invokes YY_RESERVE_GLRSTACK. */
1318 yyaddDeferredAction (yystackp
, yynewState
, rhs
, yyrule
);
1321 /** Pop the symbols consumed by reduction #RULE from the top of stack
1322 * #K of STACK, and perform the appropriate semantic action on their
1323 * semantic values. Assumes that all ambiguities in semantic values
1324 * have been previously resolved. Set *VALP to the resulting value,
1325 * and *LOCP to the computed location (if any). Return value is as
1326 * for userAction. */
1327 static inline YYRESULTTAG
1328 yydoAction (yyGLRStack
* yystackp
, size_t yyk
, yyRuleNum yyrule
,
1329 YYSTYPE
* yyvalp
, YYLTYPE
* yylocp
]b4_user_formals
[)
1331 int yynrhs
= yyrhsLength (yyrule
);
1333 if (yystackp
->yysplitPoint
== NULL
)
1335 /* Standard special case: single stack. */
1336 yyGLRStackItem
* rhs
= (yyGLRStackItem
*) yystackp
->yytops
.yystates
[yyk
];
1337 YYASSERT (yyk
== 0);
1338 yystackp
->yynextFree
-= yynrhs
;
1339 yystackp
->yyspaceLeft
+= yynrhs
;
1340 yystackp
->yytops
.yystates
[0] = & yystackp
->yynextFree
[-1].yystate
;
1341 return yyuserAction (yyrule
, yynrhs
, rhs
,
1342 yyvalp
, yylocp
, yystackp
]b4_user_args
[);
1346 /* At present, doAction is never called in nondeterministic
1347 * mode, so this branch is never taken. It is here in
1348 * anticipation of a future feature that will allow immediate
1349 * evaluation of selected actions in nondeterministic mode. */
1352 yyGLRStackItem yyrhsVals
[YYMAXRHS
+ YYMAXLEFT
+ 1];
1353 yys
= yyrhsVals
[YYMAXRHS
+ YYMAXLEFT
].yystate
.yypred
1354 = yystackp
->yytops
.yystates
[yyk
];]b4_location_if([[
1356 /* Set default location. */
1357 yyrhsVals
[YYMAXRHS
+ YYMAXLEFT
- 1].yystate
.yyloc
= yys
->yyloc
;]])[
1358 for (yyi
= 0; yyi
< yynrhs
; yyi
+= 1)
1363 yyupdateSplit (yystackp
, yys
);
1364 yystackp
->yytops
.yystates
[yyk
] = yys
;
1365 return yyuserAction (yyrule
, yynrhs
, yyrhsVals
+ YYMAXRHS
+ YYMAXLEFT
- 1,
1366 yyvalp
, yylocp
, yystackp
]b4_user_args
[);
1371 # define YY_REDUCE_PRINT(Args)
1373 # define YY_REDUCE_PRINT(Args) \
1376 yy_reduce_print Args; \
1379 /*----------------------------------------------------------.
1380 | Report that the RULE is going to be reduced on stack #K. |
1381 `----------------------------------------------------------*/
1383 /*ARGSUSED*/ static inline void
1384 yy_reduce_print (yyGLRStack
* yystackp
, size_t yyk
, yyRuleNum yyrule
,
1385 YYSTYPE
* yyvalp
, YYLTYPE
* yylocp
]b4_user_formals
[)
1387 int yynrhs
= yyrhsLength (yyrule
);
1388 yybool yynormal
__attribute__ ((__unused__
)) =
1389 (yystackp
->yysplitPoint
== NULL
);
1390 yyGLRStackItem
* yyvsp
= (yyGLRStackItem
*) yystackp
->yytops
.yystates
[yyk
];
1395 ]b4_parse_param_use
[]dnl
1396 [ YYFPRINTF (stderr
, "Reducing stack %lu by rule %d (line %lu):\n",
1397 (unsigned long int) yyk
, yyrule
- 1,
1398 (unsigned long int) yyrline
[yyrule
]);
1399 /* The symbols being reduced. */
1400 for (yyi
= 0; yyi
< yynrhs
; yyi
++)
1402 fprintf (stderr
, " $%d = ", yyi
+ 1);
1403 yy_symbol_print (stderr
, yyrhs
[yyprhs
[yyrule
] + yyi
],
1404 &]b4_rhs_value(yynrhs
, yyi
+ 1)[
1405 ]b4_location_if([, &]b4_rhs_location(yynrhs
, yyi
+ 1))[]dnl
1407 fprintf (stderr
, "\n");
1412 /** Pop items off stack #K of STACK according to grammar rule RULE,
1413 * and push back on the resulting nonterminal symbol. Perform the
1414 * semantic action associated with RULE and store its value with the
1415 * newly pushed state, if FORCEEVAL or if STACK is currently
1416 * unambiguous. Otherwise, store the deferred semantic action with
1417 * the new state. If the new state would have an identical input
1418 * position, LR state, and predecessor to an existing state on the stack,
1419 * it is identified with that existing state, eliminating stack #K from
1420 * the STACK. In this case, the (necessarily deferred) semantic value is
1421 * added to the options for the existing state's semantic value.
1423 static inline YYRESULTTAG
1424 yyglrReduce (yyGLRStack
* yystackp
, size_t yyk
, yyRuleNum yyrule
,
1425 yybool yyforceEval
]b4_user_formals
[)
1427 size_t yyposn
= yystackp
->yytops
.yystates
[yyk
]->yyposn
;
1429 if (yyforceEval
|| yystackp
->yysplitPoint
== NULL
)
1434 YY_REDUCE_PRINT ((yystackp
, yyk
, yyrule
, &yysval
, &yyloc
]b4_user_args
[));
1435 YYCHK (yydoAction (yystackp
, yyk
, yyrule
, &yysval
,
1436 &yyloc
]b4_user_args
[));
1437 YY_SYMBOL_PRINT ("-> $$ =", yyr1
[yyrule
], &yysval
, &yyloc
);
1438 yyglrShift (yystackp
, yyk
,
1439 yyLRgotoState (yystackp
->yytops
.yystates
[yyk
]->yylrState
,
1440 yylhsNonterm (yyrule
)),
1441 yyposn
, &yysval
, &yyloc
);
1447 yyGLRState
* yys
, *yys0
= yystackp
->yytops
.yystates
[yyk
];
1448 yyStateNum yynewLRState
;
1450 for (yys
= yystackp
->yytops
.yystates
[yyk
], yyn
= yyrhsLength (yyrule
);
1456 yyupdateSplit (yystackp
, yys
);
1457 yynewLRState
= yyLRgotoState (yys
->yylrState
, yylhsNonterm (yyrule
));
1459 "Reduced stack %lu by rule #%d; action deferred. Now in state %d.\n",
1460 (unsigned long int) yyk
, yyrule
- 1, yynewLRState
));
1461 for (yyi
= 0; yyi
< yystackp
->yytops
.yysize
; yyi
+= 1)
1462 if (yyi
!= yyk
&& yystackp
->yytops
.yystates
[yyi
] != NULL
)
1464 yyGLRState
* yyp
, *yysplit
= yystackp
->yysplitPoint
;
1465 yyp
= yystackp
->yytops
.yystates
[yyi
];
1466 while (yyp
!= yys
&& yyp
!= yysplit
&& yyp
->yyposn
>= yyposn
)
1468 if (yyp
->yylrState
== yynewLRState
&& yyp
->yypred
== yys
)
1470 yyaddDeferredAction (yystackp
, yyp
, yys0
, yyrule
);
1471 yymarkStackDeleted (yystackp
, yyk
);
1472 YYDPRINTF ((stderr
, "Merging stack %lu into stack %lu.\n",
1473 (unsigned long int) yyk
,
1474 (unsigned long int) yyi
));
1480 yystackp
->yytops
.yystates
[yyk
] = yys
;
1481 yyglrShiftDefer (yystackp
, yyk
, yynewLRState
, yyposn
, yys0
, yyrule
);
1487 yysplitStack (yyGLRStack
* yystackp
, size_t yyk
)
1489 if (yystackp
->yysplitPoint
== NULL
)
1491 YYASSERT (yyk
== 0);
1492 yystackp
->yysplitPoint
= yystackp
->yytops
.yystates
[yyk
];
1494 if (yystackp
->yytops
.yysize
>= yystackp
->yytops
.yycapacity
)
1496 yyGLRState
** yynewStates
;
1497 if (! ((yystackp
->yytops
.yycapacity
1498 <= (YYSIZEMAX
/ (2 * sizeof yynewStates
[0])))
1500 (yyGLRState
**) YYREALLOC (yystackp
->yytops
.yystates
,
1501 ((yystackp
->yytops
.yycapacity
*= 2)
1502 * sizeof yynewStates
[0])))))
1503 yyMemoryExhausted (yystackp
);
1504 yystackp
->yytops
.yystates
= yynewStates
;
1506 yystackp
->yytops
.yystates
[yystackp
->yytops
.yysize
]
1507 = yystackp
->yytops
.yystates
[yyk
];
1508 yystackp
->yytops
.yysize
+= 1;
1509 return yystackp
->yytops
.yysize
-1;
1512 /** True iff Y0 and Y1 represent identical options at the top level.
1513 * That is, they represent the same rule applied to RHS symbols
1514 * that produce the same terminal symbols. */
1516 yyidenticalOptions (yySemanticOption
* yyy0
, yySemanticOption
* yyy1
)
1518 if (yyy0
->yyrule
== yyy1
->yyrule
)
1520 yyGLRState
*yys0
, *yys1
;
1522 for (yys0
= yyy0
->yystate
, yys1
= yyy1
->yystate
,
1523 yyn
= yyrhsLength (yyy0
->yyrule
);
1525 yys0
= yys0
->yypred
, yys1
= yys1
->yypred
, yyn
-= 1)
1526 if (yys0
->yyposn
!= yys1
->yyposn
)
1534 /** Assuming identicalOptions (Y0,Y1), destructively merge the
1535 * alternative semantic values for the RHS-symbols of Y1 and Y0. */
1537 yymergeOptionSets (yySemanticOption
* yyy0
, yySemanticOption
* yyy1
)
1539 yyGLRState
*yys0
, *yys1
;
1541 for (yys0
= yyy0
->yystate
, yys1
= yyy1
->yystate
,
1542 yyn
= yyrhsLength (yyy0
->yyrule
);
1544 yys0
= yys0
->yypred
, yys1
= yys1
->yypred
, yyn
-= 1)
1548 else if (yys0
->yyresolved
)
1550 yys1
->yyresolved
= yytrue
;
1551 yys1
->yysemantics
.yysval
= yys0
->yysemantics
.yysval
;
1553 else if (yys1
->yyresolved
)
1555 yys0
->yyresolved
= yytrue
;
1556 yys0
->yysemantics
.yysval
= yys1
->yysemantics
.yysval
;
1560 yySemanticOption
** yyz0p
;
1561 yySemanticOption
* yyz1
;
1562 yyz0p
= &yys0
->yysemantics
.yyfirstVal
;
1563 yyz1
= yys1
->yysemantics
.yyfirstVal
;
1564 while (YYID (yytrue
))
1566 if (yyz1
== *yyz0p
|| yyz1
== NULL
)
1568 else if (*yyz0p
== NULL
)
1573 else if (*yyz0p
< yyz1
)
1575 yySemanticOption
* yyz
= *yyz0p
;
1577 yyz1
= yyz1
->yynext
;
1578 (*yyz0p
)->yynext
= yyz
;
1580 yyz0p
= &(*yyz0p
)->yynext
;
1582 yys1
->yysemantics
.yyfirstVal
= yys0
->yysemantics
.yyfirstVal
;
1587 /** Y0 and Y1 represent two possible actions to take in a given
1588 * parsing state; return 0 if no combination is possible,
1589 * 1 if user-mergeable, 2 if Y0 is preferred, 3 if Y1 is preferred. */
1591 yypreference (yySemanticOption
* y0
, yySemanticOption
* y1
)
1593 yyRuleNum r0
= y0
->yyrule
, r1
= y1
->yyrule
;
1594 int p0
= yydprec
[r0
], p1
= yydprec
[r1
];
1598 if (yymerger
[r0
] == 0 || yymerger
[r0
] != yymerger
[r1
])
1603 if (p0
== 0 || p1
== 0)
1612 static YYRESULTTAG
yyresolveValue (yySemanticOption
* yyoptionList
,
1613 yyGLRStack
* yystackp
, YYSTYPE
* yyvalp
,
1614 YYLTYPE
* yylocp
]b4_user_formals
[);
1617 yyresolveStates (yyGLRState
* yys
, int yyn
,
1618 yyGLRStack
* yystackp
]b4_user_formals
[)
1623 YYASSERT (yys
->yypred
);
1624 yyflag
= yyresolveStates (yys
->yypred
, yyn
-1, yystackp
]b4_user_args
[);
1627 if (! yys
->yyresolved
)
1629 yyflag
= yyresolveValue (yys
->yysemantics
.yyfirstVal
, yystackp
,
1630 &yys
->yysemantics
.yysval
, &yys
->yyloc
1634 yys
->yyresolved
= yytrue
;
1641 yyresolveAction (yySemanticOption
* yyopt
, yyGLRStack
* yystackp
,
1642 YYSTYPE
* yyvalp
, YYLTYPE
* yylocp
]b4_user_formals
[)
1644 yyGLRStackItem yyrhsVals
[YYMAXRHS
+ YYMAXLEFT
+ 1];
1647 yynrhs
= yyrhsLength (yyopt
->yyrule
);
1648 YYCHK (yyresolveStates (yyopt
->yystate
, yynrhs
, yystackp
]b4_user_args
[));
1649 yyrhsVals
[YYMAXRHS
+ YYMAXLEFT
].yystate
.yypred
= yyopt
->yystate
;]b4_location_if([[
1651 /* Set default location. */
1652 yyrhsVals
[YYMAXRHS
+ YYMAXLEFT
- 1].yystate
.yyloc
= yyopt
->yystate
->yyloc
;]])[
1653 return yyuserAction (yyopt
->yyrule
, yynrhs
,
1654 yyrhsVals
+ YYMAXRHS
+ YYMAXLEFT
- 1,
1655 yyvalp
, yylocp
, yystackp
]b4_user_args
[);
1660 yyreportTree (yySemanticOption
* yyx
, int yyindent
)
1662 int yynrhs
= yyrhsLength (yyx
->yyrule
);
1665 yyGLRState
* yystates
[YYMAXRHS
];
1666 yyGLRState yyleftmost_state
;
1668 for (yyi
= yynrhs
, yys
= yyx
->yystate
; 0 < yyi
; yyi
-= 1, yys
= yys
->yypred
)
1669 yystates
[yyi
] = yys
;
1672 yyleftmost_state
.yyposn
= 0;
1673 yystates
[0] = &yyleftmost_state
;
1678 if (yyx
->yystate
->yyposn
< yys
->yyposn
+ 1)
1679 YYFPRINTF (stderr
, "%*s%s -> <Rule %d, empty>\n",
1680 yyindent
, "", yytokenName (yylhsNonterm (yyx
->yyrule
)),
1683 YYFPRINTF (stderr
, "%*s%s -> <Rule %d, tokens %lu .. %lu>\n",
1684 yyindent
, "", yytokenName (yylhsNonterm (yyx
->yyrule
)),
1685 yyx
->yyrule
, (unsigned long int) (yys
->yyposn
+ 1),
1686 (unsigned long int) yyx
->yystate
->yyposn
);
1687 for (yyi
= 1; yyi
<= yynrhs
; yyi
+= 1)
1689 if (yystates
[yyi
]->yyresolved
)
1691 if (yystates
[yyi
-1]->yyposn
+1 > yystates
[yyi
]->yyposn
)
1692 YYFPRINTF (stderr
, "%*s%s <empty>\n", yyindent
+2, "",
1693 yytokenName (yyrhs
[yyprhs
[yyx
->yyrule
]+yyi
-1]));
1695 YYFPRINTF (stderr
, "%*s%s <tokens %lu .. %lu>\n", yyindent
+2, "",
1696 yytokenName (yyrhs
[yyprhs
[yyx
->yyrule
]+yyi
-1]),
1697 (unsigned long int) (yystates
[yyi
- 1]->yyposn
+ 1),
1698 (unsigned long int) yystates
[yyi
]->yyposn
);
1701 yyreportTree (yystates
[yyi
]->yysemantics
.yyfirstVal
, yyindent
+2);
1706 static void yyreportAmbiguity (yySemanticOption
* yyx0
, yySemanticOption
* yyx1
,
1707 yyGLRStack
* yystackp
]b4_pure_formals
[)
1708 __attribute__ ((__noreturn__
));
1710 yyreportAmbiguity (yySemanticOption
* yyx0
, yySemanticOption
* yyx1
,
1711 yyGLRStack
* yystackp
]b4_pure_formals
[)
1717 YYFPRINTF (stderr
, "Ambiguity detected.\n");
1718 YYFPRINTF (stderr
, "Option 1,\n");
1719 yyreportTree (yyx0
, 2);
1720 YYFPRINTF (stderr
, "\nOption 2,\n");
1721 yyreportTree (yyx1
, 2);
1722 YYFPRINTF (stderr
, "\n");
1724 yyFail (yystackp
][]b4_pure_args
[, YY_("syntax is ambiguous"));
1728 /** Resolve the ambiguity represented by OPTIONLIST, perform the indicated
1729 * actions, and return the result. */
1731 yyresolveValue (yySemanticOption
* yyoptionList
, yyGLRStack
* yystackp
,
1732 YYSTYPE
* yyvalp
, YYLTYPE
* yylocp
]b4_user_formals
[)
1734 yySemanticOption
* yybest
;
1735 yySemanticOption
** yypp
;
1738 yybest
= yyoptionList
;
1740 for (yypp
= &yyoptionList
->yynext
; *yypp
!= NULL
; )
1742 yySemanticOption
* yyp
= *yypp
;
1744 if (yyidenticalOptions (yybest
, yyp
))
1746 yymergeOptionSets (yybest
, yyp
);
1747 *yypp
= yyp
->yynext
;
1751 switch (yypreference (yybest
, yyp
))
1754 yyreportAmbiguity (yybest
, yyp
, yystackp
]b4_pure_args
[);
1766 /* This cannot happen so it is not worth a YYASSERT (yyfalse),
1767 but some compilers complain if the default case is
1771 yypp
= &yyp
->yynext
;
1777 yySemanticOption
* yyp
;
1778 int yyprec
= yydprec
[yybest
->yyrule
];
1779 YYCHK (yyresolveAction (yybest
, yystackp
, yyvalp
, yylocp
]b4_user_args
[));
1780 for (yyp
= yybest
->yynext
; yyp
!= NULL
; yyp
= yyp
->yynext
)
1782 if (yyprec
== yydprec
[yyp
->yyrule
])
1786 YYCHK (yyresolveAction (yyp
, yystackp
, &yyval1
,
1787 &yydummy
]b4_user_args
[));
1788 yyuserMerge (yymerger
[yyp
->yyrule
], yyvalp
, &yyval1
);
1794 return yyresolveAction (yybest
, yystackp
, yyvalp
, yylocp
]b4_user_args
[);
1798 yyresolveStack (yyGLRStack
* yystackp
]b4_user_formals
[)
1800 if (yystackp
->yysplitPoint
!= NULL
)
1805 for (yyn
= 0, yys
= yystackp
->yytops
.yystates
[0];
1806 yys
!= yystackp
->yysplitPoint
;
1807 yys
= yys
->yypred
, yyn
+= 1)
1809 YYCHK (yyresolveStates (yystackp
->yytops
.yystates
[0], yyn
, yystackp
1816 yycompressStack (yyGLRStack
* yystackp
)
1818 yyGLRState
* yyp
, *yyq
, *yyr
;
1820 if (yystackp
->yytops
.yysize
!= 1 || yystackp
->yysplitPoint
== NULL
)
1823 for (yyp
= yystackp
->yytops
.yystates
[0], yyq
= yyp
->yypred
, yyr
= NULL
;
1824 yyp
!= yystackp
->yysplitPoint
;
1825 yyr
= yyp
, yyp
= yyq
, yyq
= yyp
->yypred
)
1828 yystackp
->yyspaceLeft
+= yystackp
->yynextFree
- yystackp
->yyitems
;
1829 yystackp
->yynextFree
= ((yyGLRStackItem
*) yystackp
->yysplitPoint
) + 1;
1830 yystackp
->yyspaceLeft
-= yystackp
->yynextFree
- yystackp
->yyitems
;
1831 yystackp
->yysplitPoint
= NULL
;
1832 yystackp
->yylastDeleted
= NULL
;
1836 yystackp
->yynextFree
->yystate
= *yyr
;
1838 yystackp
->yynextFree
->yystate
.yypred
= &yystackp
->yynextFree
[-1].yystate
;
1839 yystackp
->yytops
.yystates
[0] = &yystackp
->yynextFree
->yystate
;
1840 yystackp
->yynextFree
+= 1;
1841 yystackp
->yyspaceLeft
-= 1;
1846 yyprocessOneStack (yyGLRStack
* yystackp
, size_t yyk
,
1847 size_t yyposn
]b4_pure_formals
[)
1850 const short int* yyconflicts
;
1852 yySymbol
* const yytokenp
= yystackp
->yytokenp
;
1854 while (yystackp
->yytops
.yystates
[yyk
] != NULL
)
1856 yyStateNum yystate
= yystackp
->yytops
.yystates
[yyk
]->yylrState
;
1857 YYDPRINTF ((stderr
, "Stack %lu Entering state %d\n",
1858 (unsigned long int) yyk
, yystate
));
1860 YYASSERT (yystate
!= YYFINAL
);
1862 if (yyisDefaultedState (yystate
))
1864 yyrule
= yydefaultAction (yystate
);
1867 YYDPRINTF ((stderr
, "Stack %lu dies.\n",
1868 (unsigned long int) yyk
));
1869 yymarkStackDeleted (yystackp
, yyk
);
1872 YYCHK (yyglrReduce (yystackp
, yyk
, yyrule
, yyfalse
]b4_user_args
[));
1876 if (*yytokenp
== YYEMPTY
)
1878 YYDPRINTF ((stderr
, "Reading a token: "));
1880 *yytokenp
= YYTRANSLATE (yychar
);
1881 YY_SYMBOL_PRINT ("Next token is", *yytokenp
, &yylval
, &yylloc
);
1883 yygetLRActions (yystate
, *yytokenp
, &yyaction
, &yyconflicts
);
1885 while (*yyconflicts
!= 0)
1887 size_t yynewStack
= yysplitStack (yystackp
, yyk
);
1888 YYDPRINTF ((stderr
, "Splitting off stack %lu from %lu.\n",
1889 (unsigned long int) yynewStack
,
1890 (unsigned long int) yyk
));
1891 YYCHK (yyglrReduce (yystackp
, yynewStack
,
1892 *yyconflicts
, yyfalse
]b4_user_args
[));
1893 YYCHK (yyprocessOneStack (yystackp
, yynewStack
,
1894 yyposn
]b4_pure_args
[));
1898 if (yyisShiftAction (yyaction
))
1900 else if (yyisErrorAction (yyaction
))
1902 YYDPRINTF ((stderr
, "Stack %lu dies.\n",
1903 (unsigned long int) yyk
));
1904 yymarkStackDeleted (yystackp
, yyk
);
1908 YYCHK (yyglrReduce (yystackp
, yyk
, -yyaction
,
1909 yyfalse
]b4_user_args
[));
1915 /*ARGSUSED*/ static void
1916 yyreportSyntaxError (yyGLRStack
* yystackp
]b4_user_formals
[)
1918 if (yystackp
->yyerrState
== 0)
1921 yySymbol
* const yytokenp
= yystackp
->yytokenp
;
1923 yyn
= yypact
[yystackp
->yytops
.yystates
[0]->yylrState
];
1924 if (YYPACT_NINF
< yyn
&& yyn
< YYLAST
)
1926 size_t yysize0
= yytnamerr (NULL
, yytokenName (*yytokenp
));
1927 size_t yysize
= yysize0
;
1929 yybool yysize_overflow
= yyfalse
;
1931 enum { YYERROR_VERBOSE_ARGS_MAXIMUM
= 5 };
1932 char const *yyarg
[YYERROR_VERBOSE_ARGS_MAXIMUM
];
1936 static char const yyunexpected
[] = "syntax error, unexpected %s";
1937 static char const yyexpecting
[] = ", expecting %s";
1938 static char const yyor
[] = " or %s";
1939 char yyformat
[sizeof yyunexpected
1940 + sizeof yyexpecting
- 1
1941 + ((YYERROR_VERBOSE_ARGS_MAXIMUM
- 2)
1942 * (sizeof yyor
- 1))];
1943 char const *yyprefix
= yyexpecting
;
1945 /* Start YYX at -YYN if negative to avoid negative indexes in
1947 int yyxbegin
= yyn
< 0 ? -yyn
: 0;
1949 /* Stay within bounds of both yycheck and yytname. */
1950 int yychecklim
= YYLAST
- yyn
;
1951 int yyxend
= yychecklim
< YYNTOKENS
? yychecklim
: YYNTOKENS
;
1954 yyarg
[0] = yytokenName (*yytokenp
);
1955 yyfmt
= yystpcpy (yyformat
, yyunexpected
);
1957 for (yyx
= yyxbegin
; yyx
< yyxend
; ++yyx
)
1958 if (yycheck
[yyx
+ yyn
] == yyx
&& yyx
!= YYTERROR
)
1960 if (yycount
== YYERROR_VERBOSE_ARGS_MAXIMUM
)
1964 yyformat
[sizeof yyunexpected
- 1] = '\0';
1967 yyarg
[yycount
++] = yytokenName (yyx
);
1968 yysize1
= yysize
+ yytnamerr (NULL
, yytokenName (yyx
));
1969 yysize_overflow
|= yysize1
< yysize
;
1971 yyfmt
= yystpcpy (yyfmt
, yyprefix
);
1975 yyf
= YY_(yyformat
);
1976 yysize1
= yysize
+ strlen (yyf
);
1977 yysize_overflow
|= yysize1
< yysize
;
1980 if (!yysize_overflow
)
1981 yymsg
= (char *) YYMALLOC (yysize
);
1987 while ((*yyp
= *yyf
))
1989 if (*yyp
== '%' && yyf
[1] == 's' && yyi
< yycount
)
1991 yyp
+= yytnamerr (yyp
, yyarg
[yyi
++]);
2000 yyerror (]b4_lyyerror_args
[yymsg
);
2005 yyerror (]b4_lyyerror_args
[YY_("syntax error"));
2006 yyMemoryExhausted (yystackp
);
2010 #endif /* YYERROR_VERBOSE */
2011 yyerror (]b4_lyyerror_args
[YY_("syntax error"));
2016 /* Recover from a syntax error on *YYSTACKP, assuming that *YYSTACKP->YYTOKENP,
2017 yylval, and yylloc are the syntactic category, semantic value, and location
2018 of the look-ahead. */
2019 /*ARGSUSED*/ static void
2020 yyrecoverSyntaxError (yyGLRStack
* yystackp
]b4_user_formals
[)
2022 yySymbol
* const yytokenp
= yystackp
->yytokenp
;
2026 if (yystackp
->yyerrState
== 3)
2027 /* We just shifted the error token and (perhaps) took some
2028 reductions. Skip tokens until we can proceed. */
2029 while (YYID (yytrue
))
2031 if (*yytokenp
== YYEOF
)
2032 yyFail (yystackp
][]b4_lpure_args
[, NULL
);
2033 if (*yytokenp
!= YYEMPTY
)
2035 /* We throw away the lookahead, but the error range
2036 of the shifted error token must take it into account. */
2037 yyGLRState
*yys
= yystackp
->yytops
.yystates
[0];
2038 yyGLRStackItem yyerror_range
[3];
2039 yyerror_range
[1].yystate
.yyloc
= yys
->yyloc
;
2040 yyerror_range
[2].yystate
.yyloc
= yylloc
;
2041 YYLLOC_DEFAULT (yys
->yyloc
, yyerror_range
, 2);]])[
2042 yydestruct ("Error: discarding",
2043 *yytokenp
, &yylval
]b4_location_if([, &yylloc
])[]b4_user_args
[);
2045 YYDPRINTF ((stderr
, "Reading a token: "));
2047 *yytokenp
= YYTRANSLATE (yychar
);
2048 YY_SYMBOL_PRINT ("Next token is", *yytokenp
, &yylval
, &yylloc
);
2049 yyj
= yypact
[yystackp
->yytops
.yystates
[0]->yylrState
];
2050 if (yyis_pact_ninf (yyj
))
2053 if (yyj
< 0 || YYLAST
< yyj
|| yycheck
[yyj
] != *yytokenp
)
2055 if (yydefact
[yystackp
->yytops
.yystates
[0]->yylrState
] != 0)
2058 else if (yytable
[yyj
] != 0 && ! yyis_table_ninf (yytable
[yyj
]))
2062 /* Reduce to one stack. */
2063 for (yyk
= 0; yyk
< yystackp
->yytops
.yysize
; yyk
+= 1)
2064 if (yystackp
->yytops
.yystates
[yyk
] != NULL
)
2066 if (yyk
>= yystackp
->yytops
.yysize
)
2067 yyFail (yystackp
][]b4_lpure_args
[, NULL
);
2068 for (yyk
+= 1; yyk
< yystackp
->yytops
.yysize
; yyk
+= 1)
2069 yymarkStackDeleted (yystackp
, yyk
);
2070 yyremoveDeletes (yystackp
);
2071 yycompressStack (yystackp
);
2073 /* Now pop stack until we find a state that shifts the error token. */
2074 yystackp
->yyerrState
= 3;
2075 while (yystackp
->yytops
.yystates
[0] != NULL
)
2077 yyGLRState
*yys
= yystackp
->yytops
.yystates
[0];
2078 yyj
= yypact
[yys
->yylrState
];
2079 if (! yyis_pact_ninf (yyj
))
2082 if (0 <= yyj
&& yyj
<= YYLAST
&& yycheck
[yyj
] == YYTERROR
2083 && yyisShiftAction (yytable
[yyj
]))
2085 /* Shift the error token having adjusted its location. */
2086 YYLTYPE yyerrloc
;]b4_location_if([[
2087 yystackp
->yyerror_range
[2].yystate
.yyloc
= yylloc
;
2088 YYLLOC_DEFAULT (yyerrloc
, yystackp
->yyerror_range
, 2);]])[
2089 YY_SYMBOL_PRINT ("Shifting", yystos
[yytable
[yyj
]],
2090 &yylval
, &yyerrloc
);
2091 yyglrShift (yystackp
, 0, yytable
[yyj
],
2092 yys
->yyposn
, &yylval
, &yyerrloc
);
2093 yys
= yystackp
->yytops
.yystates
[0];
2097 ]b4_location_if([[ yystackp
->yyerror_range
[1].yystate
.yyloc
= yys
->yyloc
;]])[
2098 yydestroyGLRState ("Error: popping", yys
]b4_user_args
[);
2099 yystackp
->yytops
.yystates
[0] = yys
->yypred
;
2100 yystackp
->yynextFree
-= 1;
2101 yystackp
->yyspaceLeft
+= 1;
2103 if (yystackp
->yytops
.yystates
[0] == NULL
)
2104 yyFail (yystackp
][]b4_lpure_args
[, NULL
);
2107 #define YYCHK1(YYE) \
2117 goto yyuser_error; \
2128 ]b4_c_ansi_function_def([yyparse
], [int], b4_parse_param
)[
2133 yyGLRStack
* const yystackp
= &yystack
;
2136 YYDPRINTF ((stderr
, "Starting parse\n"));
2139 yylval
= yyval_default
;
2141 #if YYLTYPE_IS_TRIVIAL
2142 yylloc
.first_line
= yylloc
.last_line
= 1;
2143 yylloc
.first_column
= yylloc
.last_column
= 0;
2146 m4_ifdef([b4_initial_action
], [
2147 m4_pushdef([b4_at_dollar
], [yylloc
])dnl
2148 m4_pushdef([b4_dollar_dollar
], [yylval
])dnl
2149 /* User initialization code. */
2151 m4_popdef([b4_dollar_dollar
])dnl
2152 m4_popdef([b4_at_dollar
])dnl
2153 /* Line __line__ of glr.c. */
2154 b4_syncline([@oline@
], [@ofile@
])])dnl
2156 if (! yyinitGLRStack (yystackp
, YYINITDEPTH
))
2157 goto yyexhaustedlab
;
2158 switch (YYSETJMP (yystack
.yyexception_buffer
))
2161 case 1: goto yyabortlab
;
2162 case 2: goto yyexhaustedlab
;
2163 default: goto yybuglab
;
2165 yystack
.yytokenp
= &yytoken
;
2166 yyglrShift (&yystack
, 0, 0, 0, &yylval
, &yylloc
);
2169 while (YYID (yytrue
))
2171 /* For efficiency, we have two loops, the first of which is
2172 specialized to deterministic operation (single stack, no
2173 potential ambiguity). */
2175 while (YYID (yytrue
))
2179 const short int* yyconflicts
;
2181 yyStateNum yystate
= yystack
.yytops
.yystates
[0]->yylrState
;
2182 YYDPRINTF ((stderr
, "Entering state %d\n", yystate
));
2183 if (yystate
== YYFINAL
)
2185 if (yyisDefaultedState (yystate
))
2187 yyrule
= yydefaultAction (yystate
);
2190 ]b4_location_if([[ yystack
.yyerror_range
[1].yystate
.yyloc
= yylloc
;]])[
2191 yyreportSyntaxError (&yystack
]b4_user_args
[);
2194 YYCHK1 (yyglrReduce (&yystack
, 0, yyrule
, yytrue
]b4_user_args
[));
2198 if (yytoken
== YYEMPTY
)
2200 YYDPRINTF ((stderr
, "Reading a token: "));
2202 yytoken
= YYTRANSLATE (yychar
);
2203 YY_SYMBOL_PRINT ("Next token is", yytoken
, &yylval
, &yylloc
);
2205 yygetLRActions (yystate
, yytoken
, &yyaction
, &yyconflicts
);
2206 if (*yyconflicts
!= 0)
2208 if (yyisShiftAction (yyaction
))
2210 YY_SYMBOL_PRINT ("Shifting", yytoken
, &yylval
, &yylloc
);
2211 if (yytoken
!= YYEOF
)
2214 yyglrShift (&yystack
, 0, yyaction
, yyposn
, &yylval
, &yylloc
);
2215 if (0 < yystack
.yyerrState
)
2216 yystack
.yyerrState
-= 1;
2218 else if (yyisErrorAction (yyaction
))
2220 ]b4_location_if([[ yystack
.yyerror_range
[1].yystate
.yyloc
= yylloc
;]])[
2221 yyreportSyntaxError (&yystack
]b4_user_args
[);
2225 YYCHK1 (yyglrReduce (&yystack
, 0, -yyaction
, yytrue
]b4_user_args
[));
2229 while (YYID (yytrue
))
2231 yySymbol yytoken_to_shift
;
2233 size_t yyn
= yystack
.yytops
.yysize
;
2235 /* yyprocessOneStack returns one of three things:
2237 - An error flag. If the caller is yyprocessOneStack, it
2238 immediately returns as well. When the caller is finally
2239 yyparse, it jumps to an error label via YYCHK1.
2241 - yyok, but yyprocessOneStack has invoked yymarkStackDeleted
2242 (&yystack, yys), which sets the top state of yys to NULL. Thus,
2243 yyparse's following invocation of yyremoveDeletes will remove
2246 - yyok, when ready to shift a token.
2248 Except in the first case, yyparse will invoke yyremoveDeletes and
2249 then shift the next token onto all remaining stacks. This
2250 synchronization of the shift (that is, after all preceding
2251 reductions on all stacks) helps prevents double destructor calls
2252 on yylval in the event of memory exhaustion. */
2254 for (yys
= 0; yys
< yyn
; yys
+= 1)
2255 YYCHK1 (yyprocessOneStack (&yystack
, yys
, yyposn
]b4_lpure_args
[));
2256 yyremoveDeletes (&yystack
);
2257 yyn
= yystack
.yytops
.yysize
;
2259 /* If any yyglrShift call fails, it will fail after shifting. Thus,
2260 a copy of yylval will already be on stack 0 in the event of a
2261 failure in the following loop. Thus, yytoken is set to YYEMPTY
2262 before the loop to make sure the user destructor for yylval isn't
2264 yytoken_to_shift
= yytoken
;
2267 for (yys
= 0; yys
< yyn
; yys
+= 1)
2270 const short int* yyconflicts
;
2271 yyStateNum yystate
= yystack
.yytops
.yystates
[yys
]->yylrState
;
2272 yygetLRActions (yystate
, yytoken_to_shift
, &yyaction
,
2274 /* Note that yyconflicts were handled by yyprocessOneStack. */
2275 YYDPRINTF ((stderr
, "On stack %lu, ", (unsigned long int) yys
));
2276 YY_SYMBOL_PRINT ("shifting", yytoken_to_shift
, &yylval
, &yylloc
);
2277 yyglrShift (&yystack
, yys
, yyaction
, yyposn
,
2279 YYDPRINTF ((stderr
, "Stack %lu now in state #%d\n",
2280 (unsigned long int) yys
,
2281 yystack
.yytops
.yystates
[yys
]->yylrState
));
2283 if (yystack
.yytops
.yysize
== 0)
2285 yyundeleteLastStack (&yystack
);
2286 if (yystack
.yytops
.yysize
== 0)
2287 yyFail (&yystack
][]b4_lpure_args
[, YY_("syntax error"));
2288 YYCHK1 (yyresolveStack (&yystack
]b4_user_args
[));
2289 YYDPRINTF ((stderr
, "Returning to deterministic operation.\n"));
2290 ]b4_location_if([[ yystack
.yyerror_range
[1].yystate
.yyloc
= yylloc
;]])[
2291 yyreportSyntaxError (&yystack
]b4_user_args
[);
2294 else if (yystack
.yytops
.yysize
== 1)
2296 YYCHK1 (yyresolveStack (&yystack
]b4_user_args
[));
2297 YYDPRINTF ((stderr
, "Returning to deterministic operation.\n"));
2298 yycompressStack (&yystack
);
2304 yyrecoverSyntaxError (&yystack
]b4_user_args
[);
2305 yyposn
= yystack
.yytops
.yystates
[0]->yyposn
;
2321 yyerror (]b4_lyyerror_args
[YY_("memory exhausted"));
2326 if (yytoken
!= YYEOF
&& yytoken
!= YYEMPTY
)
2327 yydestruct ("Cleanup: discarding lookahead",
2328 yytoken
, &yylval
]b4_location_if([, &yylloc
])[]b4_user_args
[);
2330 /* If the stack is well-formed, pop the stack until it is empty,
2331 destroying its entries as we go. But free the stack regardless
2332 of whether it is well-formed. */
2333 if (yystack
.yyitems
)
2335 yyGLRState
** yystates
= yystack
.yytops
.yystates
;
2338 size_t yysize
= yystack
.yytops
.yysize
;
2340 for (yyk
= 0; yyk
< yysize
; yyk
+= 1)
2343 while (yystates
[yyk
])
2345 yyGLRState
*yys
= yystates
[yyk
];
2346 ]b4_location_if([[ yystack
.yyerror_range
[1].yystate
.yyloc
= yys
->yyloc
;]]
2347 )[ yydestroyGLRState ("Cleanup: popping", yys
]b4_user_args
[);
2348 yystates
[yyk
] = yys
->yypred
;
2349 yystack
.yynextFree
-= 1;
2350 yystack
.yyspaceLeft
+= 1;
2355 yyfreeGLRStack (&yystack
);
2361 /* DEBUGGING ONLY */
2363 static void yypstack (yyGLRStack
* yystackp
, size_t yyk
)
2364 __attribute__ ((__unused__
));
2365 static void yypdumpstack (yyGLRStack
* yystackp
) __attribute__ ((__unused__
));
2368 yy_yypstack (yyGLRState
* yys
)
2372 yy_yypstack (yys
->yypred
);
2373 fprintf (stderr
, " -> ");
2375 fprintf (stderr
, "%d@@%lu", yys
->yylrState
, (unsigned long int) yys
->yyposn
);
2379 yypstates (yyGLRState
* yyst
)
2382 fprintf (stderr
, "<null>");
2385 fprintf (stderr
, "\n");
2389 yypstack (yyGLRStack
* yystackp
, size_t yyk
)
2391 yypstates (yystackp
->yytops
.yystates
[yyk
]);
2394 #define YYINDEX(YYX) \
2395 ((YYX) == NULL ? -1 : (yyGLRStackItem*) (YYX) - yystackp->yyitems)
2399 yypdumpstack (yyGLRStack
* yystackp
)
2401 yyGLRStackItem
* yyp
;
2403 for (yyp
= yystackp
->yyitems
; yyp
< yystackp
->yynextFree
; yyp
+= 1)
2405 fprintf (stderr
, "%3lu. ", (unsigned long int) (yyp
- yystackp
->yyitems
));
2406 if (*(yybool
*) yyp
)
2408 fprintf (stderr
, "Res: %d, LR State: %d, posn: %lu, pred: %ld",
2409 yyp
->yystate
.yyresolved
, yyp
->yystate
.yylrState
,
2410 (unsigned long int) yyp
->yystate
.yyposn
,
2411 (long int) YYINDEX (yyp
->yystate
.yypred
));
2412 if (! yyp
->yystate
.yyresolved
)
2413 fprintf (stderr
, ", firstVal: %ld",
2414 (long int) YYINDEX (yyp
->yystate
.yysemantics
.yyfirstVal
));
2418 fprintf (stderr
, "Option. rule: %d, state: %ld, next: %ld",
2419 yyp
->yyoption
.yyrule
,
2420 (long int) YYINDEX (yyp
->yyoption
.yystate
),
2421 (long int) YYINDEX (yyp
->yyoption
.yynext
));
2423 fprintf (stderr
, "\n");
2425 fprintf (stderr
, "Tops:");
2426 for (yyi
= 0; yyi
< yystackp
->yytops
.yysize
; yyi
+= 1)
2427 fprintf (stderr
, "%lu: %ld; ", (unsigned long int) yyi
,
2428 (long int) YYINDEX (yystackp
->yytops
.yystates
[yyi
]));
2429 fprintf (stderr
, "\n");
2435 m4_if(b4_defines_flag
, 0, [],
2436 [@output @output_header_name@
2437 b4_copyright([Skeleton parser
for GLR parsing with Bison
],
2438 [2002, 2003, 2004, 2005])[
2440 /* C GLR parser skeleton written by Paul Hilfinger. */
2443 b4_shared_declarations
2445 extern YYSTYPE b4_prefix
[]lval
;
2447 b4_location_if([b4_pure_if([],
2448 [extern YYLTYPE b4_prefix
[]lloc
;])