1 m4_divert(-1) -*- C
-*-
3 # GLR skeleton for Bison
4 # Copyright (C) 2002 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., 59 Temple Place, Suite 330, 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 # Accumule in b4_lex_param all the yylex arguments.
40 # Yes, this is quite ugly...
41 m4_define([b4_lex_param
],
42 m4_dquote(b4_pure_if([[[[YYSTYPE
*]], [[yylvalp]]][]dnl
43 b4_location_if([, [[YYLTYPE
*], [yyllocp
]]])])dnl
44 m4_ifdef([b4_lex_param
], [, ]b4_lex_param
)))
49 m4_define([b4_user_formals
],
50 [m4_ifset([b4_parse_param
], [, b4_c_ansi_formals(b4_parse_param
)])])
55 # Arguments passed to yyerror: user args plus yylloc.
56 m4_define([b4_yyerror_args
],
57 [b4_pure_if([b4_location_if([yylocp
, ])])dnl
58 m4_ifset([b4_parse_param
], [b4_c_args(b4_parse_param
), ])])
63 # Same as above, but on the lookahead, hence yyllocp instead of yylocp.
64 m4_define([b4_lyyerror_args
],
65 [b4_pure_if([b4_location_if([yyllocp
, ])])dnl
66 m4_ifset([b4_parse_param
], [b4_c_args(b4_parse_param
), ])])
71 # Arguments needed by yyerror: user args plus yylloc.
72 m4_define([b4_pure_args
],
73 [b4_pure_if([b4_location_if([, yylocp
])])[]b4_user_args
])
78 # Arguments passed to yyerror: user formals plus yyllocp.
79 m4_define([b4_pure_formals
],
80 [b4_pure_if([b4_location_if([, YYLTYPE
*yylocp
])])[]b4_user_formals
])
85 # Same as above, but on the lookahead, hence yyllocp instead of yylocp.
86 m4_define([b4_lpure_args
],
87 [b4_pure_if([b4_location_if([, yyllocp
])])[]b4_user_args
])
92 # Same as above, but on the lookahead, hence yyllocp instead of yylocp.
93 m4_define([b4_lpure_formals
],
94 [b4_pure_if([b4_location_if([YYLTYPE
*yyllocp
])])[]b4_user_formals
])
97 ## ----------------- ##
98 ## Semantic Values. ##
99 ## ----------------- ##
102 # b4_lhs_value([TYPE])
103 # --------------------
104 # Expansion of $<TYPE>$.
105 m4_define([b4_lhs_value
],
106 [(*yyvalp
)[]m4_ifval([$
1], [.$
1])])
109 # b4_rhs_value(RULE-LENGTH, NUM, [TYPE])
110 # --------------------------------------
111 # Expansion of $<TYPE>NUM, where the current rule has RULE-LENGTH
113 m4_define([b4_rhs_value
],
114 [yyvsp@
{m4_eval([$
2 - $
1])@
}.yystate
.yysemantics
.yysval
[]m4_ifval([$
3], [.$
3])])
125 m4_define([b4_lhs_location
],
129 # b4_rhs_location(RULE-LENGTH, NUM)
130 # ---------------------------------
131 # Expansion of @NUM, where the current rule has RULE-LENGTH symbols
133 m4_define([b4_rhs_location
],
134 [yyvsp@
{m4_eval([$
2 - $
1])@
}.yystate
.yyloc
])
137 # We do want M4 expansion after # for CPP macros.
140 @output @output_parser_name@
141 b4_copyright([Skeleton parser
for GLR parsing with Bison
], [2002])
143 /* This is the parser code for GLR (Generalized LR) parser. */
152 m4_if(b4_prefix
[], [yy
], [],
153 [/* If NAME_PREFIX is specified substitute the variables and functions
155 #define yyparse b4_prefix[]parse
156 #define yylex b4_prefix[]lex
157 #define yyerror b4_prefix[]error
158 #define yylval b4_prefix[]lval
159 #define yychar b4_prefix[]char
160 #define yydebug b4_prefix[]debug
161 #define yynerrs b4_prefix[]nerrs
162 b4_location_if([#define yylloc b4_prefix[]lloc])])
164 b4_token_defines(b4_tokens
)
166 /* Copy the first part of user declarations. */
169 /* Enabling traces. */
171 # define YYDEBUG ]b4_debug[
174 /* Enabling verbose error messages. */
175 #ifdef YYERROR_VERBOSE
176 # undef YYERROR_VERBOSE
177 # define YYERROR_VERBOSE 1
179 # define YYERROR_VERBOSE ]b4_error_verbose[
182 #if ! defined (YYSTYPE) && ! defined (YYSTYPE_IS_DECLARED)
183 ]m4_ifdef([b4_stype
],
184 [b4_syncline([b4_stype_line
], [b4_filename
])
185 typedef union m4_bregexp(b4_stype
, [^{], [YYSTYPE
])b4_stype YYSTYPE
;
186 /* Line __line__ of glr.c. */
187 b4_syncline([@oline@
], [@ofile@
])],
188 [typedef int YYSTYPE
;])[
189 # define YYSTYPE_IS_DECLARED 1
190 # define YYSTYPE_IS_TRIVIAL 1
193 #if ! defined (YYLTYPE) && ! defined (YYLTYPE_IS_DECLARED)
194 typedef struct YYLTYPE
201 # define YYLTYPE_IS_DECLARED 1
202 # define YYLTYPE_IS_TRIVIAL 1
205 /* Default (constant) values used for initialization for null
206 right-hand sides. Unlike the standard yacc.c template,
207 here we set the default values of $$ and $@@ to zeroed-out
208 values. Since the default value of these quantities is undefined,
209 this behavior is technically correct. */
210 static YYSTYPE yyval_default
;
211 static YYLTYPE yyloc_default
;
213 /* Copy the second part of user declarations. */
216 ]/* Line __line__ of glr.c. */
217 b4_syncline([@oline@
], [@ofile@
])
219 #if ! defined (__cplusplus)
229 #ifndef __attribute__
230 /* This feature is available in gcc versions 2.5 and later. */
231 # if !defined (__GNUC__) || __GNUC__ < 2 || \
232 (__GNUC__ == 2 && __GNUC_MINOR__ < 5) || __STRICT_ANSI__
233 # define __attribute__(Spec) /* empty */
237 #ifndef ATTRIBUTE_UNUSED
238 # define ATTRIBUTE_UNUSED __attribute__ ((__unused__))
241 /* YYFINAL -- State number of the termination state. */
242 #define YYFINAL ]b4_final_state_number[
243 /* YYLAST -- Last index in YYTABLE. */
244 #define YYLAST ]b4_last[
246 /* YYNTOKENS -- Number of terminals. */
247 #define YYNTOKENS ]b4_tokens_number[
248 /* YYNNTS -- Number of nonterminals. */
249 #define YYNNTS ]b4_nterms_number[
250 /* YYNRULES -- Number of rules. */
251 #define YYNRULES ]b4_rules_number[
252 /* YYNRULES -- Number of states. */
253 #define YYNSTATES ]b4_states_number[
254 /* YYMAXRHS -- Maximum number of symbols on right-hand side of rule. */
255 #define YYMAXRHS ]b4_r2_max[
257 /* YYTRANSLATE(X) -- Bison symbol number corresponding to X. */
258 #define YYUNDEFTOK ]b4_undef_token_number[
259 #define YYMAXUTOK ]b4_user_token_number_max[
261 #define YYTRANSLATE(YYX) \
262 ((YYX <= 0) ? YYEOF : \
263 (unsigned)(YYX) <= YYMAXUTOK ? yytranslate[YYX] : YYUNDEFTOK)
265 /* YYTRANSLATE[YYLEX] -- Bison symbol number corresponding to YYLEX. */
266 static const ]b4_int_type_for([b4_translate
])[ yytranslate
[] =
272 /* YYPRHS[YYN] -- Index of the first RHS symbol of rule number YYN in
274 static const ]b4_int_type_for([b4_prhs
])[ yyprhs
[] =
279 /* YYRHS -- A `-1'-separated list of the rules' RHS. */
280 static const ]b4_int_type_for([b4_rhs
])[ yyrhs
[] =
285 /* YYRLINE[YYN] -- source line where rule number YYN was defined. */
286 static const ]b4_int_type_for([b4_rline
])[ yyrline
[] =
292 #if (YYDEBUG) || YYERROR_VERBOSE
293 /* YYTNME[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM.
294 First, the terminals, then, starting at YYNTOKENS, nonterminals. */
295 static const char *const yytname
[] =
300 #define yytname_size ((int) (sizeof (yytname) / sizeof (yytname[0])))
303 /* YYR1[YYN] -- Symbol number of symbol that rule YYN derives. */
304 static const ]b4_int_type_for([b4_r1
])[ yyr1
[] =
309 /* YYR2[YYN] -- Number of symbols composing right hand side of rule YYN. */
310 static const ]b4_int_type_for([b4_r2
])[ yyr2
[] =
315 /* YYDPREC[RULE-NUM] -- Dynamic precedence of rule #RULE-NUM (0 if none). */
316 static const ]b4_int_type_for([b4_dprec
])[ yydprec
[] =
321 /* YYMERGER[RULE-NUM] -- Index of merging function for rule #RULE-NUM. */
322 static const ]b4_int_type_for([b4_merger
])[ yymerger
[] =
327 /* YYDEFACT[S] -- default rule to reduce with in state S when YYTABLE
328 doesn't specify something else to do. Zero means the default is an
330 static const ]b4_int_type_for([b4_defact
])[ yydefact
[] =
335 /* YYPDEFGOTO[NTERM-NUM]. */
336 static const ]b4_int_type_for([b4_defgoto
])[ yydefgoto
[] =
341 /* YYPACT[STATE-NUM] -- Index in YYTABLE of the portion describing
343 #define YYPACT_NINF ]b4_pact_ninf[
344 static const ]b4_int_type_for([b4_pact
])[ yypact
[] =
349 /* YYPGOTO[NTERM-NUM]. */
350 static const ]b4_int_type_for([b4_pgoto
])[ yypgoto
[] =
355 /* YYTABLE[YYPACT[STATE-NUM]]. What to do in state STATE-NUM. If
356 positive, shift that token. If negative, reduce the rule which
357 number is the opposite. If zero, do what YYDEFACT says.
358 If YYTABLE_NINF, syntax error. */
359 #define YYTABLE_NINF ]b4_table_ninf[
360 static const ]b4_int_type_for([b4_table
])[ yytable
[] =
365 /* YYCONFLP[YYPACT[STATE-NUM]] -- Pointer into YYCONFL of start of
366 list of conflicting reductions corresponding to action entry for
367 state STATE-NUM in yytable. 0 means no conflicts. The list in
368 yyconfl is terminated by a rule number of 0. */
369 static const ]b4_int_type_for([b4_conflict_list_heads
])[ yyconflp
[] =
371 ]b4_conflict_list_heads
[
374 /* YYCONFL[I] -- lists of conflicting rule numbers, each terminated by
375 0, pointed into by YYCONFLP. */
376 ]dnl Do
not use b4_int_type_for here
, since there are places where
377 dnl pointers onto yyconfl are taken
, which type is
"short *".
378 dnl We probably ought to introduce a type
for confl
.
379 [static const short yyconfl
[] =
381 ]b4_conflicting_rules
[
384 static const ]b4_int_type_for([b4_check
])[ yycheck
[] =
389 /* YYSTOS[STATE-NUM] -- The (internal number of the) accessing
390 symbol of state STATE-NUM. */
391 static const ]b4_int_type_for([b4_stos
])[ yystos
[] =
397 /* Prevent warning if -Wmissing-prototypes. */
398 ]b4_c_ansi_function_decl([yyparse
], [int], b4_parse_param
)[
400 /* Error token number */
403 /* YYLLOC_DEFAULT -- Compute the default location (before the actions
406 #define YYRHSLOC(yyRhs,YYK) (yyRhs[YYK].yystate.yyloc)
408 #ifndef YYLLOC_DEFAULT
409 # define YYLLOC_DEFAULT(yyCurrent, yyRhs, YYN) \
410 yyCurrent.first_line = YYRHSLOC(yyRhs,1).first_line; \
411 yyCurrent.first_column = YYRHSLOC(yyRhs,1).first_column; \
412 yyCurrent.last_line = YYRHSLOC(yyRhs,YYN).last_line; \
413 yyCurrent.last_column = YYRHSLOC(yyRhs,YYN).last_column;
416 /* YYLEX -- calling `yylex' with the right arguments. */
417 #define YYLEX ]b4_c_function_call([yylex], [int], b4_lex_param)[
422 #define yynerrs (yystack->yyerrcnt)
424 #define yychar (yystack->yyrawchar)],
432 static const int YYEOF
= 0;
433 static const int YYEMPTY
= -2;
435 typedef enum { yyok
, yyaccept
, yyabort
, yyerr
} YYRESULTTAG
;
438 do { YYRESULTTAG yyflag = YYE; if (yyflag != yyok) return yyflag; } \
443 #if ! defined (YYFPRINTF)
444 # define YYFPRINTF fprintf
447 # define YYDPRINTF(Args) \
453 ]b4_yysymprint_generate([b4_c_ansi_function_def
])[
455 # define YYDSYMPRINT(Args) \
461 # define YYDSYMPRINTF(Title, Token, Value, Location) \
465 YYFPRINTF (stderr, "%s ", Title); \
466 yysymprint (stderr, \
467 Token, Value]b4_location_if([, Location])[); \
468 YYFPRINTF (stderr, "\n"); \
472 /* Nonzero means print parse trace. It is left uninitialized so that
473 multiple parsers can coexist. */
478 /* Avoid empty `if' bodies. */
479 # define YYDPRINTF(Args)
480 # define YYDSYMPRINT(Args)
481 # define YYDSYMPRINTF(Title, Token, Value, Location)
483 #endif /* !YYDEBUG */
485 /* YYINITDEPTH -- initial size of the parser's stacks. */
487 # define YYINITDEPTH ]b4_stack_depth_init[
490 /* YYMAXDEPTH -- maximum size the stacks can grow to (effective only
491 if the built-in stack extension method is used).
493 Do not make this value too large; the results are undefined if
494 SIZE_MAX < YYMAXDEPTH * sizeof (GLRStackItem)
495 evaluated with infinite-precision integer arithmetic. */
502 # define YYMAXDEPTH ]b4_stack_depth_max[
505 /* Minimum number of free items on the stack allowed after an
506 allocation. This is to allow allocation and initialization
507 to be completed by functions that call expandGLRStack before the
508 stack is expanded, thus insuring that all necessary pointers get
509 properly redirected to new data. */
512 #if (! defined (YYSTACKEXPANDABLE) \
513 && (! defined (__cplusplus) \
514 || (]b4_location_if([YYLTYPE_IS_TRIVIAL && ])[YYSTYPE_IS_TRIVIAL)))
515 #define YYSTACKEXPANDABLE 1
517 #define YYSTACKEXPANDABLE 0
520 /** State numbers, as in LALR(1) machine */
521 typedef int yyStateNum
;
523 /** Rule numbers, as in LALR(1) machine */
524 typedef int yyRuleNum
;
526 /** Grammar symbol */
527 typedef short yySymbol
;
529 /** Item references, as in LALR(1) machine */
530 typedef short yyItemNum
;
532 typedef struct yyGLRState yyGLRState
;
533 typedef struct yySemanticOption yySemanticOption
;
534 typedef union yyGLRStackItem yyGLRStackItem
;
535 typedef struct yyGLRStack yyGLRStack
;
536 typedef struct yyGLRStateSet yyGLRStateSet
;
541 yyStateNum yylrState
;
545 yySemanticOption
* yyfirstVal
;
551 struct yyGLRStateSet
{
552 yyGLRState
** yystates
;
553 size_t yysize
, yycapacity
;
556 struct yySemanticOption
{
560 yySemanticOption
* yynext
;
563 union yyGLRStackItem
{
565 yySemanticOption yyoption
;
577 jmp_buf yyexception_buffer
;
578 yyGLRStackItem
* yyitems
;
579 yyGLRStackItem
* yynextFree
;
581 yyGLRState
* yysplitPoint
;
582 yyGLRState
* yylastDeleted
;
583 yyGLRStateSet yytops
;
586 static void yyinitGLRStack (yyGLRStack
* yystack
, size_t yysize
);
587 static void yyexpandGLRStack (yyGLRStack
* yystack
]b4_pure_formals
[);
588 static void yyfreeGLRStack (yyGLRStack
* yystack
);
591 yyFail (yyGLRStack
* yystack
]b4_pure_formals
[, const char* yyformat
, ...)
593 yystack
->yyerrflag
= 1;
594 if (yyformat
!= NULL
)
598 va_start (yyap
, yyformat
);
599 vsprintf (yymsg
, yyformat
, yyap
);
600 yyerror (]b4_yyerror_args
[yymsg
);
602 longjmp (yystack
->yyexception_buffer
, 1);
605 #if YYDEBUG || YYERROR_VERBOSE
606 /** A printable representation of TOKEN. Valid until next call to
608 static inline const char*
609 yytokenName (yySymbol yytoken
)
611 return yytname
[yytoken
];
615 /** Perform user action for rule number YYN, with RHS length YYRHSLEN,
616 * and top stack item YYVSP. YYLVALP points to place to put semantic
617 * value ($$), and yylocp points to place for location information
618 * (@@$). Returns yyok for normal return, yyaccept for YYACCEPT,
619 * yyerr for YYERROR, yyabort for YYABORT. */
621 yyuserAction (yyRuleNum yyn
, int yyrhslen
, yyGLRStackItem
* yyvsp
,
622 YYSTYPE
* yyvalp
, YYLTYPE
* yylocp
, yyGLRStack
* yystack
625 /* Avoid `unused' warnings in there are no $n. */
630 *yyvalp
= yyval_default
;
631 *yylocp
= yyloc_default
;
635 *yyvalp
= yyvsp
[1-yyrhslen
].yystate
.yysemantics
.yysval
;
636 *yylocp
= yyvsp
[1-yyrhslen
].yystate
.yyloc
;
639 # define yyerrok (yystack->yyerrState = 0)
641 # define YYACCEPT return yyaccept
643 # define YYABORT return yyabort
645 # define YYERROR return yyerr
647 # define YYRECOVERING (yystack->yyerrState != 0)
649 # define yyclearin (yychar = *(yystack->yytokenp) = YYEMPTY)
651 # define YYBACKUP(Token, Value) \
653 yyerror (]b4_yyerror_args["syntax error: cannot back up"); \
671 /* Line __line__ of glr.c. */
672 b4_syncline([@oline@
], [@ofile@
])
677 yyuserMerge (int yyn
, YYSTYPE
* yy0
, YYSTYPE
* yy1
)
679 YYSTYPE yyval
= *yy0
;
680 /* `Use' the arguments. */
691 /* Bison grammar-table manipulation. */
693 ]b4_yydestruct_generate([b4_c_ansi_function_def
])[
695 /** Number of symbols composing the right hand side of rule #RULE. */
697 yyrhsLength (yyRuleNum yyrule
)
702 /** Left-hand-side symbol for rule #RULE. */
703 static inline yySymbol
704 yylhsNonterm (yyRuleNum yyrule
)
709 #define yyis_pact_ninf(yystate) \
710 ]m4_if(m4_eval(b4_pact_ninf < b4_pact_min), 1,
712 ((yystate
) == YYPACT_NINF
))[
714 /** True iff LR state STATE has only a default reduction (regardless
717 yyisDefaultedState (yyStateNum yystate
)
719 return yyis_pact_ninf (yypact
[yystate
]);
722 /** The default reduction for STATE, assuming it has one. */
723 static inline yyRuleNum
724 yydefaultAction (yyStateNum yystate
)
726 return yydefact
[yystate
];
729 #define yyis_table_ninf(yytable_value) \
730 ]m4_if(m4_eval(b4_table_ninf < b4_table_min), 1,
732 ((yytable_value
) == YYTABLE_NINF
))[
734 /** Set *YYACTION to the action to take in YYSTATE on seeing YYTOKEN.
736 * R < 0: Reduce on rule -R.
738 * R > 0: Shift to state R.
739 * Set *CONFLICTS to a pointer into yyconfl to 0-terminated list of
740 * conflicting reductions.
743 yygetLRActions (yyStateNum yystate
, int yytoken
,
744 int* yyaction
, const short** yyconflicts
)
746 int yyindex
= yypact
[yystate
] + yytoken
;
747 if (yyindex
< 0 || YYLAST
< yyindex
|| yycheck
[yyindex
] != yytoken
)
749 *yyaction
= -yydefact
[yystate
];
750 *yyconflicts
= yyconfl
;
752 else if (! yyis_table_ninf (yytable
[yyindex
]))
754 *yyaction
= yytable
[yyindex
];
755 *yyconflicts
= yyconfl
+ yyconflp
[yyindex
];
760 *yyconflicts
= yyconfl
+ yyconflp
[yyindex
];
764 static inline yyStateNum
765 yyLRgotoState (yyStateNum yystate
, yySymbol yylhs
)
768 yyr
= yypgoto
[yylhs
- YYNTOKENS
] + yystate
;
769 if (0 <= yyr
&& yyr
<= YYLAST
&& yycheck
[yyr
] == yystate
)
772 return yydefgoto
[yylhs
- YYNTOKENS
];
776 yyisShiftAction (int yyaction
)
782 yyisErrorAction (int yyaction
)
784 return yyaction
== 0;
790 yyaddDeferredAction (yyGLRStack
* yystack
, yyGLRState
* yystate
,
791 yyGLRState
* rhs
, yyRuleNum yyrule
]b4_pure_formals
[)
793 yySemanticOption
* yynewItem
;
794 yynewItem
= &yystack
->yynextFree
->yyoption
;
795 yystack
->yyspaceLeft
-= 1;
796 yystack
->yynextFree
+= 1;
797 yynewItem
->yyisState
= yyfalse
;
798 yynewItem
->yystate
= rhs
;
799 yynewItem
->yyrule
= yyrule
;
800 yynewItem
->yynext
= yystate
->yysemantics
.yyfirstVal
;
801 yystate
->yysemantics
.yyfirstVal
= yynewItem
;
802 if (yystack
->yyspaceLeft
< YYHEADROOM
)
803 yyexpandGLRStack (yystack
]b4_pure_args
[);
808 /** Initialize SET to a singleton set containing an empty stack. */
810 yyinitStateSet (yyGLRStateSet
* yyset
)
813 yyset
->yycapacity
= 16;
814 yyset
->yystates
= (yyGLRState
**) malloc (16 * sizeof (yyset
->yystates
[0]));
815 yyset
->yystates
[0] = NULL
;
818 static void yyfreeStateSet (yyGLRStateSet
* yyset
)
820 free (yyset
->yystates
);
823 /** Initialize STACK to a single empty stack, with total maximum
824 * capacity for all stacks of SIZE. */
826 yyinitGLRStack (yyGLRStack
* yystack
, size_t yysize
)
828 yystack
->yyerrflag
= 0;
829 yystack
->yyerrState
= 0;
831 yystack
->yyspaceLeft
= yysize
;
832 yystack
->yynextFree
= yystack
->yyitems
=
833 (yyGLRStackItem
*) malloc (yysize
* sizeof (yystack
->yynextFree
[0]));
834 yystack
->yysplitPoint
= NULL
;
835 yystack
->yylastDeleted
= NULL
;
836 yyinitStateSet (&yystack
->yytops
);
839 #define YYRELOC(YYFROMITEMS,YYTOITEMS,YYX,YYTYPE) \
840 &((YYTOITEMS) - ((YYFROMITEMS) - (yyGLRStackItem*) (YYX)))->YYTYPE
842 /** If STACK is expandable, extend it. WARNING: Pointers into the
843 stack from outside should be considered invalid after this call.
844 We always expand when there are 1 or fewer items left AFTER an
845 allocation, so that we can avoid having external pointers exist
846 across an allocation. */
848 yyexpandGLRStack (yyGLRStack
* yystack
]b4_pure_formals
[)
850 #if YYSTACKEXPANDABLE
851 yyGLRStack yynewStack
;
852 yyGLRStackItem
* yyp0
, *yyp1
;
853 size_t yysize
, yynewSize
;
855 yysize
= yystack
->yynextFree
- yystack
->yyitems
;
856 if (YYMAXDEPTH
<= yysize
)
857 yyFail (yystack
][]b4_pure_args
[, "parser stack overflow");
858 yynewSize
= 2*yysize
;
859 if (YYMAXDEPTH
< yynewSize
)
860 yynewSize
= YYMAXDEPTH
;
861 yyinitGLRStack (&yynewStack
, yynewSize
);
862 for (yyp0
= yystack
->yyitems
, yyp1
= yynewStack
.yyitems
, yyn
= yysize
;
864 yyn
-= 1, yyp0
+= 1, yyp1
+= 1)
869 yyGLRState
* yys0
= &yyp0
->yystate
;
870 yyGLRState
* yys1
= &yyp1
->yystate
;
871 if (yys0
->yypred
!= NULL
)
873 YYRELOC (yyp0
, yyp1
, yys0
->yypred
, yystate
);
874 if (! yys0
->yyresolved
&& yys0
->yysemantics
.yyfirstVal
!= NULL
)
875 yys1
->yysemantics
.yyfirstVal
=
876 YYRELOC(yyp0
, yyp1
, yys0
->yysemantics
.yyfirstVal
, yyoption
);
880 yySemanticOption
* yyv0
= &yyp0
->yyoption
;
881 yySemanticOption
* yyv1
= &yyp1
->yyoption
;
882 if (yyv0
->yystate
!= NULL
)
883 yyv1
->yystate
= YYRELOC (yyp0
, yyp1
, yyv0
->yystate
, yystate
);
884 if (yyv0
->yynext
!= NULL
)
885 yyv1
->yynext
= YYRELOC (yyp0
, yyp1
, yyv0
->yynext
, yyoption
);
888 if (yystack
->yysplitPoint
!= NULL
)
889 yystack
->yysplitPoint
= YYRELOC (yystack
->yyitems
, yynewStack
.yyitems
,
890 yystack
->yysplitPoint
, yystate
);
892 for (yyn
= 0; yyn
< yystack
->yytops
.yysize
; yyn
+= 1)
893 if (yystack
->yytops
.yystates
[yyn
] != NULL
)
894 yystack
->yytops
.yystates
[yyn
] =
895 YYRELOC (yystack
->yyitems
, yynewStack
.yyitems
,
896 yystack
->yytops
.yystates
[yyn
], yystate
);
897 free (yystack
->yyitems
);
898 yystack
->yyitems
= yynewStack
.yyitems
;
899 yystack
->yynextFree
= yynewStack
.yynextFree
+ yysize
;
900 yystack
->yyspaceLeft
= yynewStack
.yyspaceLeft
- yysize
;
904 yyFail (yystack
][]b4_lpure_args
[, "parser stack overflow");
909 yyfreeGLRStack (yyGLRStack
* yystack
)
911 free (yystack
->yyitems
);
912 yyfreeStateSet (&yystack
->yytops
);
915 /** Assuming that S is a GLRState somewhere on STACK, update the
916 * splitpoint of STACK, if needed, so that it is at least as deep as
919 yyupdateSplit (yyGLRStack
* yystack
, yyGLRState
* yys
)
921 if (yystack
->yysplitPoint
!= NULL
&& yystack
->yysplitPoint
> yys
)
922 yystack
->yysplitPoint
= yys
;
925 /** Invalidate stack #K in STACK. */
927 yymarkStackDeleted (yyGLRStack
* yystack
, int yyk
)
929 if (yystack
->yytops
.yystates
[yyk
] != NULL
)
930 yystack
->yylastDeleted
= yystack
->yytops
.yystates
[yyk
];
931 yystack
->yytops
.yystates
[yyk
] = NULL
;
934 /** Undelete the last stack that was marked as deleted. Can only be
935 done once after a deletion, and only when all other stacks have
938 yyundeleteLastStack (yyGLRStack
* yystack
)
940 if (yystack
->yylastDeleted
== NULL
|| yystack
->yytops
.yysize
!= 0)
942 yystack
->yytops
.yystates
[0] = yystack
->yylastDeleted
;
943 yystack
->yytops
.yysize
= 1;
944 YYDPRINTF ((stderr
, "Restoring last deleted stack as stack #0.\n"));
945 yystack
->yylastDeleted
= NULL
;
949 yyremoveDeletes (yyGLRStack
* yystack
)
953 while (yyj
< yystack
->yytops
.yysize
)
955 if (yystack
->yytops
.yystates
[yyi
] == NULL
)
959 YYDPRINTF ((stderr
, "Removing dead stacks.\n"));
961 yystack
->yytops
.yysize
-= 1;
965 yystack
->yytops
.yystates
[yyj
] = yystack
->yytops
.yystates
[yyi
];
968 YYDPRINTF ((stderr
, "Rename stack %d -> %d.\n", yyi
, yyj
));
976 /** Shift to a new state on stack #K of STACK, corresponding to LR state
977 * LRSTATE, at input position POSN, with (resolved) semantic value SVAL. */
979 yyglrShift (yyGLRStack
* yystack
, int yyk
, yyStateNum yylrState
, size_t yyposn
,
980 YYSTYPE yysval
, YYLTYPE
* yylocp
]b4_user_formals
[)
982 yyGLRStackItem
* yynewItem
;
984 yynewItem
= yystack
->yynextFree
;
985 yystack
->yynextFree
+= 1;
986 yystack
->yyspaceLeft
-= 1;
987 yynewItem
->yystate
.yyisState
= yytrue
;
988 yynewItem
->yystate
.yylrState
= yylrState
;
989 yynewItem
->yystate
.yyposn
= yyposn
;
990 yynewItem
->yystate
.yyresolved
= yytrue
;
991 yynewItem
->yystate
.yypred
= yystack
->yytops
.yystates
[yyk
];
992 yystack
->yytops
.yystates
[yyk
] = &yynewItem
->yystate
;
993 yynewItem
->yystate
.yysemantics
.yysval
= yysval
;
994 yynewItem
->yystate
.yyloc
= *yylocp
;
995 if (yystack
->yyspaceLeft
< YYHEADROOM
)
996 yyexpandGLRStack (yystack
]b4_pure_args
[);
999 /** Shift to a new state on stack #K of STACK, to a new state
1000 * corresponding to LR state LRSTATE, at input position POSN, with
1001 * the (unresolved) semantic value of RHS under the action for RULE. */
1003 yyglrShiftDefer (yyGLRStack
* yystack
, int yyk
, yyStateNum yylrState
,
1004 size_t yyposn
, yyGLRState
* rhs
, yyRuleNum yyrule
]b4_pure_formals
[)
1006 yyGLRStackItem
* yynewItem
;
1008 yynewItem
= yystack
->yynextFree
;
1009 yynewItem
->yystate
.yyisState
= yytrue
;
1010 yynewItem
->yystate
.yylrState
= yylrState
;
1011 yynewItem
->yystate
.yyposn
= yyposn
;
1012 yynewItem
->yystate
.yyresolved
= yyfalse
;
1013 yynewItem
->yystate
.yypred
= yystack
->yytops
.yystates
[yyk
];
1014 yynewItem
->yystate
.yysemantics
.yyfirstVal
= NULL
;
1015 yystack
->yytops
.yystates
[yyk
] = &yynewItem
->yystate
;
1016 yystack
->yynextFree
+= 1;
1017 yystack
->yyspaceLeft
-= 1;
1018 yyaddDeferredAction (yystack
, &yynewItem
->yystate
, rhs
, yyrule
]b4_pure_args
[);
1021 /** Pop the symbols consumed by reduction #RULE from the top of stack
1022 * #K of STACK, and perform the appropriate semantic action on their
1023 * semantic values. Assumes that all ambiguities in semantic values
1024 * have been previously resolved. Set *VALP to the resulting value,
1025 * and *LOCP to the computed location (if any). Return value is as
1026 * for userAction. */
1027 static inline YYRESULTTAG
1028 yydoAction (yyGLRStack
* yystack
, int yyk
, yyRuleNum yyrule
,
1029 YYSTYPE
* yyvalp
, YYLTYPE
* yylocp
]b4_user_formals
[)
1031 int yynrhs
= yyrhsLength (yyrule
);
1033 if (yystack
->yysplitPoint
== NULL
)
1035 /* Standard special case: single stack. */
1036 yyGLRStackItem
* rhs
= (yyGLRStackItem
*) yystack
->yytops
.yystates
[yyk
];
1039 yystack
->yynextFree
-= yynrhs
;
1040 yystack
->yyspaceLeft
+= yynrhs
;
1041 yystack
->yytops
.yystates
[0] = & yystack
->yynextFree
[-1].yystate
;
1044 *yyvalp
= yyval_default
;
1045 *yylocp
= yyloc_default
;
1049 *yyvalp
= rhs
[1-yynrhs
].yystate
.yysemantics
.yysval
;
1050 *yylocp
= rhs
[1-yynrhs
].yystate
.yyloc
;
1052 return yyuserAction (yyrule
, yynrhs
, rhs
,
1053 yyvalp
, yylocp
, yystack
]b4_user_args
[);
1059 yyGLRStackItem yyrhsVals
[YYMAXRHS
];
1060 for (yyi
= yynrhs
-1, yys
= yystack
->yytops
.yystates
[yyk
]; 0 <= yyi
;
1061 yyi
-= 1, yys
= yys
->yypred
)
1065 yyrhsVals
[yyi
].yystate
.yyresolved
= yytrue
;
1066 yyrhsVals
[yyi
].yystate
.yysemantics
.yysval
= yys
->yysemantics
.yysval
;
1067 yyrhsVals
[yyi
].yystate
.yyloc
= yys
->yyloc
;
1069 yyupdateSplit (yystack
, yys
);
1070 yystack
->yytops
.yystates
[yyk
] = yys
;
1073 *yyvalp
= yyval_default
;
1074 *yylocp
= yyloc_default
;
1078 *yyvalp
= yyrhsVals
[0].yystate
.yysemantics
.yysval
;
1079 *yylocp
= yyrhsVals
[0].yystate
.yyloc
;
1081 return yyuserAction (yyrule
, yynrhs
, yyrhsVals
+ (yynrhs
-1),
1082 yyvalp
, yylocp
, yystack
]b4_user_args
[);
1087 # define YY_REDUCE_PRINT(K, Rule)
1089 # define YY_REDUCE_PRINT(K, Rule) \
1092 yy_reduce_print (K, Rule); \
1095 /*----------------------------------------------------------.
1096 | Report that the RULE is going to be reduced on stack #K. |
1097 `----------------------------------------------------------*/
1100 yy_reduce_print (size_t yyk
, yyRuleNum yyrule
)
1103 unsigned int yylineno
= yyrline
[yyrule
];
1104 YYFPRINTF (stderr
, "Reducing stack %d by rule %d (line %u), ",
1105 yyk
, yyrule
- 1, yylineno
);
1106 /* Print the symbols being reduced, and their result. */
1107 for (yyi
= yyprhs
[yyrule
]; 0 <= yyrhs
[yyi
]; yyi
++)
1108 YYFPRINTF (stderr
, "%s ", yytokenName (yyrhs
[yyi
]));
1109 YYFPRINTF (stderr
, "-> %s\n", yytokenName (yyr1
[yyrule
]));
1113 /** Pop items off stack #K of STACK according to grammar rule RULE,
1114 * and push back on the resulting nonterminal symbol. Perform the
1115 * semantic action associated with RULE and store its value with the
1116 * newly pushed state, if FORCEEVAL or if STACK is currently
1117 * unambiguous. Otherwise, store the deferred semantic action with
1118 * the new state. If the new state would have an identical input
1119 * position, LR state, and predecessor to an existing state on the stack,
1120 * it is identified with that existing state, eliminating stack #K from
1121 * the STACK. In this case, the (necessarily deferred) semantic value is
1122 * added to the options for the existing state's semantic value.
1124 static inline YYRESULTTAG
1125 yyglrReduce (yyGLRStack
* yystack
, size_t yyk
, yyRuleNum yyrule
,
1126 bool yyforceEval
]b4_pure_formals
[)
1128 size_t yyposn
= yystack
->yytops
.yystates
[yyk
]->yyposn
;
1130 if (yyforceEval
|| yystack
->yysplitPoint
== NULL
)
1135 YY_REDUCE_PRINT (yyk
, yyrule
);
1136 YYCHK (yydoAction (yystack
, yyk
, yyrule
, &yysval
, &yyloc
]b4_user_args
[));
1137 yyglrShift (yystack
, yyk
,
1138 yyLRgotoState (yystack
->yytops
.yystates
[yyk
]->yylrState
,
1139 yylhsNonterm (yyrule
)),
1140 yyposn
, yysval
, &yyloc
]b4_user_args
[);
1146 yyGLRState
* yys
, *yys0
= yystack
->yytops
.yystates
[yyk
];
1147 yyStateNum yynewLRState
;
1149 for (yys
= yystack
->yytops
.yystates
[yyk
], yyn
= yyrhsLength (yyrule
);
1156 yyupdateSplit (yystack
, yys
);
1157 yynewLRState
= yyLRgotoState (yys
->yylrState
, yylhsNonterm (yyrule
));
1159 "Reduced stack %d by rule #%d; action deferred. "
1160 "Now in state %d.\n",
1161 yyk
, yyrule
-1, yynewLRState
));
1162 for (yyi
= 0; yyi
< yystack
->yytops
.yysize
; yyi
+= 1)
1163 if (yyi
!= yyk
&& yystack
->yytops
.yystates
[yyi
] != NULL
)
1165 yyGLRState
* yyp
, *yysplit
= yystack
->yysplitPoint
;
1166 yyp
= yystack
->yytops
.yystates
[yyi
];
1167 while (yyp
!= yys
&& yyp
!= yysplit
&& yyp
->yyposn
>= yyposn
)
1169 if (yyp
->yylrState
== yynewLRState
&& yyp
->yypred
== yys
)
1171 yyaddDeferredAction (yystack
, yyp
, yys0
, yyrule
]b4_pure_args
[);
1172 yymarkStackDeleted (yystack
, yyk
);
1173 YYDPRINTF ((stderr
, "Merging stack %d into stack %d.\n",
1180 yystack
->yytops
.yystates
[yyk
] = yys
;
1181 yyglrShiftDefer (yystack
, yyk
, yynewLRState
, yyposn
, yys0
, yyrule
]b4_pure_args
[);
1187 yysplitStack (yyGLRStack
* yystack
, int yyk
)
1189 if (yystack
->yysplitPoint
== NULL
)
1193 yystack
->yysplitPoint
= yystack
->yytops
.yystates
[yyk
];
1195 if (yystack
->yytops
.yysize
>= yystack
->yytops
.yycapacity
)
1197 yystack
->yytops
.yycapacity
*= 2;
1198 yystack
->yytops
.yystates
=
1199 (yyGLRState
**) realloc (yystack
->yytops
.yystates
,
1200 yystack
->yytops
.yycapacity
1201 * sizeof (yyGLRState
*));
1203 yystack
->yytops
.yystates
[yystack
->yytops
.yysize
]
1204 = yystack
->yytops
.yystates
[yyk
];
1205 yystack
->yytops
.yysize
+= 1;
1206 return yystack
->yytops
.yysize
-1;
1209 /** True iff Y0 and Y1 represent identical options at the top level.
1210 * That is, they represent the same rule applied to RHS symbols
1211 * that produce the same terminal symbols. */
1213 yyidenticalOptions (yySemanticOption
* yyy0
, yySemanticOption
* yyy1
)
1215 if (yyy0
->yyrule
== yyy1
->yyrule
)
1217 yyGLRState
*yys0
, *yys1
;
1219 for (yys0
= yyy0
->yystate
, yys1
= yyy1
->yystate
,
1220 yyn
= yyrhsLength (yyy0
->yyrule
);
1222 yys0
= yys0
->yypred
, yys1
= yys1
->yypred
, yyn
-= 1)
1223 if (yys0
->yyposn
!= yys1
->yyposn
)
1231 /** Assuming identicalOptions (Y0,Y1), (destructively) merge the
1232 * alternative semantic values for the RHS-symbols of Y1 into the
1233 * corresponding semantic value sets of the symbols of Y0. */
1235 yymergeOptionSets (yySemanticOption
* yyy0
, yySemanticOption
* yyy1
)
1237 yyGLRState
*yys0
, *yys1
;
1239 for (yys0
= yyy0
->yystate
, yys1
= yyy1
->yystate
,
1240 yyn
= yyrhsLength (yyy0
->yyrule
);
1242 yys0
= yys0
->yypred
, yys1
= yys1
->yypred
, yyn
-= 1)
1245 else if (! yys0
->yyresolved
&& ! yys1
->yyresolved
)
1247 yySemanticOption
* yyz
;
1248 for (yyz
= yys0
->yysemantics
.yyfirstVal
; yyz
->yynext
!= NULL
;
1251 yyz
->yynext
= yys1
->yysemantics
.yyfirstVal
;
1255 /** Y0 and Y1 represent two possible actions to take in a given
1256 * parsing state; return 0 if no combination is possible,
1257 * 1 if user-mergeable, 2 if Y0 is preferred, 3 if Y1 is preferred. */
1259 yypreference (yySemanticOption
* y0
, yySemanticOption
* y1
)
1261 yyRuleNum r0
= y0
->yyrule
, r1
= y1
->yyrule
;
1262 int p0
= yydprec
[r0
], p1
= yydprec
[r1
];
1266 if (yymerger
[r0
] == 0 || yymerger
[r0
] != yymerger
[r1
])
1271 if (p0
== 0 || p1
== 0)
1280 static YYRESULTTAG
yyresolveValue (yySemanticOption
* yyoptionList
,
1281 yyGLRStack
* yystack
, YYSTYPE
* yyvalp
,
1282 YYLTYPE
* yylocp
]b4_user_formals
[);
1285 yyresolveStates (yyGLRState
* yys
, int yyn
, yyGLRStack
* yystack
]b4_user_formals
[)
1292 yyflag
= yyresolveStates (yys
->yypred
, yyn
-1, yystack
]b4_user_args
[);
1295 if (! yys
->yyresolved
)
1297 yyflag
= yyresolveValue (yys
->yysemantics
.yyfirstVal
, yystack
,
1298 &yys
->yysemantics
.yysval
, &yys
->yyloc
1302 yys
->yyresolved
= yytrue
;
1309 yyresolveAction (yySemanticOption
* yyopt
, yyGLRStack
* yystack
,
1310 YYSTYPE
* yyvalp
, YYLTYPE
* yylocp
]b4_user_formals
[)
1312 yyGLRStackItem yyrhsVals
[YYMAXRHS
];
1316 yynrhs
= yyrhsLength (yyopt
->yyrule
);
1317 YYCHK (yyresolveStates (yyopt
->yystate
, yynrhs
, yystack
]b4_user_args
[));
1318 for (yyi
= yynrhs
-1, yys
= yyopt
->yystate
; 0 <= yyi
;
1319 yyi
-= 1, yys
= yys
->yypred
)
1323 yyrhsVals
[yyi
].yystate
.yyresolved
= yytrue
;
1324 yyrhsVals
[yyi
].yystate
.yysemantics
.yysval
= yys
->yysemantics
.yysval
;
1325 yyrhsVals
[yyi
].yystate
.yyloc
= yys
->yyloc
;
1327 return yyuserAction (yyopt
->yyrule
, yynrhs
, yyrhsVals
+ (yynrhs
-1),
1328 yyvalp
, yylocp
, yystack
]b4_user_args
[);
1333 yyreportTree (yySemanticOption
* yyx
, int yyindent
)
1335 int yynrhs
= yyrhsLength (yyx
->yyrule
);
1338 yyGLRState
* yystates
[YYMAXRHS
];
1339 yyGLRState yyleftmost_state
;
1341 for (yyi
= yynrhs
, yys
= yyx
->yystate
; 0 < yyi
; yyi
-= 1, yys
= yys
->yypred
)
1342 yystates
[yyi
] = yys
;
1345 yyleftmost_state
.yyposn
= 0;
1346 yystates
[0] = &yyleftmost_state
;
1351 if (yyx
->yystate
->yyposn
< yys
->yyposn
+ 1)
1352 YYFPRINTF (stderr
, "%*s%s -> <Rule %d, empty>\n",
1353 yyindent
, "", yytokenName (yylhsNonterm (yyx
->yyrule
)),
1356 YYFPRINTF (stderr
, "%*s%s -> <Rule %d, tokens %d .. %d>\n",
1357 yyindent
, "", yytokenName (yylhsNonterm (yyx
->yyrule
)),
1358 yyx
->yyrule
, yys
->yyposn
+1, yyx
->yystate
->yyposn
);
1359 for (yyi
= 1; yyi
<= yynrhs
; yyi
+= 1)
1361 if (yystates
[yyi
]->yyresolved
)
1363 if (yystates
[yyi
-1]->yyposn
+1 > yystates
[yyi
]->yyposn
)
1364 YYFPRINTF (stderr
, "%*s%s <empty>\n", yyindent
+2, "",
1365 yytokenName (yyrhs
[yyprhs
[yyx
->yyrule
]+yyi
-1]));
1367 YYFPRINTF (stderr
, "%*s%s <tokens %d .. %d>\n", yyindent
+2, "",
1368 yytokenName (yyrhs
[yyprhs
[yyx
->yyrule
]+yyi
-1]),
1369 yystates
[yyi
-1]->yyposn
+1, yystates
[yyi
]->yyposn
);
1372 yyreportTree (yystates
[yyi
]->yysemantics
.yyfirstVal
, yyindent
+2);
1378 yyreportAmbiguity (yySemanticOption
* yyx0
, yySemanticOption
* yyx1
,
1379 yyGLRStack
* yystack
]b4_pure_formals
[)
1381 /* `Unused' warnings. */
1386 YYFPRINTF (stderr
, "Ambiguity detected.\n");
1387 YYFPRINTF (stderr
, "Option 1,\n");
1388 yyreportTree (yyx0
, 2);
1389 YYFPRINTF (stderr
, "\nOption 2,\n");
1390 yyreportTree (yyx1
, 2);
1391 YYFPRINTF (stderr
, "\n");
1393 yyFail (yystack
][]b4_pure_args
[, "ambiguity detected");
1397 /** Resolve the ambiguity represented by OPTIONLIST, perform the indicated
1398 * actions, and return the result. */
1400 yyresolveValue (yySemanticOption
* yyoptionList
, yyGLRStack
* yystack
,
1401 YYSTYPE
* yyvalp
, YYLTYPE
* yylocp
]b4_user_formals
[)
1403 yySemanticOption
* yybest
;
1404 yySemanticOption
* yyp
;
1407 yybest
= yyoptionList
;
1409 for (yyp
= yyoptionList
->yynext
; yyp
!= NULL
; yyp
= yyp
->yynext
)
1411 if (yyidenticalOptions (yybest
, yyp
))
1412 yymergeOptionSets (yybest
, yyp
);
1414 switch (yypreference (yybest
, yyp
))
1417 yyreportAmbiguity (yybest
, yyp
, yystack
]b4_pure_args
[);
1433 int yyprec
= yydprec
[yybest
->yyrule
];
1434 YYCHK (yyresolveAction (yybest
, yystack
, yyvalp
, yylocp
]b4_user_args
[));
1435 for (yyp
= yybest
->yynext
; yyp
!= NULL
; yyp
= yyp
->yynext
)
1437 if (yyprec
== yydprec
[yyp
->yyrule
])
1441 YYCHK (yyresolveAction (yyp
, yystack
, &yyval1
, &yydummy
]b4_user_args
[));
1442 *yyvalp
= yyuserMerge (yymerger
[yyp
->yyrule
], yyvalp
, &yyval1
);
1448 return yyresolveAction (yybest
, yystack
, yyvalp
, yylocp
]b4_user_args
[);
1452 yyresolveStack (yyGLRStack
* yystack
]b4_user_formals
[)
1454 if (yystack
->yysplitPoint
!= NULL
)
1459 for (yyn
= 0, yys
= yystack
->yytops
.yystates
[0];
1460 yys
!= yystack
->yysplitPoint
;
1461 yys
= yys
->yypred
, yyn
+= 1)
1463 YYCHK (yyresolveStates (yystack
->yytops
.yystates
[0], yyn
, yystack
1470 yycompressStack (yyGLRStack
* yystack
)
1472 yyGLRState
* yyp
, *yyq
, *yyr
;
1474 if (yystack
->yytops
.yysize
!= 1 || yystack
->yysplitPoint
== NULL
)
1477 for (yyp
= yystack
->yytops
.yystates
[0], yyq
= yyp
->yypred
, yyr
= NULL
;
1478 yyp
!= yystack
->yysplitPoint
;
1479 yyr
= yyp
, yyp
= yyq
, yyq
= yyp
->yypred
)
1482 yystack
->yyspaceLeft
+= yystack
->yynextFree
- yystack
->yyitems
;
1483 yystack
->yynextFree
= ((yyGLRStackItem
*) yystack
->yysplitPoint
) + 1;
1484 yystack
->yyspaceLeft
-= yystack
->yynextFree
- yystack
->yyitems
;
1485 yystack
->yysplitPoint
= NULL
;
1486 yystack
->yylastDeleted
= NULL
;
1490 yystack
->yynextFree
->yystate
= *yyr
;
1492 yystack
->yynextFree
->yystate
.yypred
= & yystack
->yynextFree
[-1].yystate
;
1493 yystack
->yytops
.yystates
[0] = &yystack
->yynextFree
->yystate
;
1494 yystack
->yynextFree
+= 1;
1495 yystack
->yyspaceLeft
-= 1;
1500 yyprocessOneStack (yyGLRStack
* yystack
, int yyk
,
1501 size_t yyposn
, YYSTYPE
* yylvalp
, YYLTYPE
* yyllocp
1505 const short* yyconflicts
;
1507 yySymbol
* const yytokenp
= yystack
->yytokenp
;
1509 while (yystack
->yytops
.yystates
[yyk
] != NULL
)
1511 yyStateNum yystate
= yystack
->yytops
.yystates
[yyk
]->yylrState
;
1512 YYDPRINTF ((stderr
, "Stack %d Entering state %d\n", yyk
, yystate
));
1514 if (yystate
== YYFINAL
)
1516 if (yyisDefaultedState (yystate
))
1518 yyrule
= yydefaultAction (yystate
);
1521 YYDPRINTF ((stderr
, "Stack %d dies.\n", yyk
));
1522 yymarkStackDeleted (yystack
, yyk
);
1525 YYCHK (yyglrReduce (yystack
, yyk
, yyrule
, yyfalse
]b4_lpure_args
[));
1529 if (*yytokenp
== YYEMPTY
)
1531 YYDPRINTF ((stderr
, "Reading a token: "));
1533 *yytokenp
= YYTRANSLATE (yychar
);
1534 YYDSYMPRINTF ("Next token is", *yytokenp
, yylvalp
, yyllocp
);
1536 yygetLRActions (yystate
, *yytokenp
, &yyaction
, &yyconflicts
);
1538 while (*yyconflicts
!= 0)
1540 int yynewStack
= yysplitStack (yystack
, yyk
);
1541 YYDPRINTF ((stderr
, "Splitting off stack %d from %d.\n",
1543 YYCHK (yyglrReduce (yystack
, yynewStack
,
1544 *yyconflicts
, yyfalse
]b4_lpure_args
[));
1545 YYCHK (yyprocessOneStack (yystack
, yynewStack
, yyposn
,
1546 yylvalp
, yyllocp
]b4_user_args
[));
1550 if (yyisShiftAction (yyaction
))
1552 YYDPRINTF ((stderr
, "Shifting token %s on stack %d, ",
1553 yytokenName (*yytokenp
), yyk
));
1554 yyglrShift (yystack
, yyk
, yyaction
, yyposn
+1,
1555 *yylvalp
, yyllocp
]b4_user_args
[);
1556 YYDPRINTF ((stderr
, "which is now in state #%d\n",
1557 yystack
->yytops
.yystates
[yyk
]->yylrState
));
1560 else if (yyisErrorAction (yyaction
))
1562 YYDPRINTF ((stderr
, "Stack %d dies.\n", yyk
));
1563 yymarkStackDeleted (yystack
, yyk
);
1567 YYCHK (yyglrReduce (yystack
, yyk
, -yyaction
, yyfalse
]b4_lpure_args
[));
1574 yyreportSyntaxError (yyGLRStack
* yystack
,
1575 YYSTYPE
* yylvalp
, YYLTYPE
* yyllocp
]b4_user_formals
[)
1577 /* `Unused' warnings. */
1581 if (yystack
->yyerrState
== 0)
1584 yySymbol
* const yytokenp
= yystack
->yytokenp
;
1585 int yyn
, yyx
, yycount
;
1587 const char* yyprefix
;
1590 yyn
= yypact
[yystack
->yytops
.yystates
[0]->yylrState
];
1591 if (YYPACT_NINF
< yyn
&& yyn
< YYLAST
)
1594 /* Start YYX at -YYN if negative to avoid negative indexes in
1596 yysize
= sizeof ("syntax error, unexpected ")
1597 + strlen (yytokenName (*yytokenp
));
1598 yyprefix
= ", expecting ";
1599 for (yyx
= yyn
< 0 ? -yyn
: 0; yyx
< yytname_size
&& yycount
<= 5;
1601 if (yycheck
[yyx
+ yyn
] == yyx
&& yyx
!= YYTERROR
)
1602 yysize
+= strlen (yytokenName (yyx
)) + strlen (yyprefix
),
1603 yycount
+= 1, yyprefix
= " or ";
1604 yymsg
= yyp
= (char*) malloc (yysize
);
1605 sprintf (yyp
, "syntax error, unexpected %s",
1606 yytokenName (*yytokenp
));
1607 yyp
+= strlen (yyp
);
1610 yyprefix
= ", expecting ";
1611 for (yyx
= yyn
< 0 ? -yyn
: 0; yyx
< yytname_size
; yyx
+= 1)
1612 if (yycheck
[yyx
+ yyn
] == yyx
&& yyx
!= YYTERROR
)
1614 sprintf (yyp
, "%s%s", yyprefix
, yytokenName (yyx
));
1615 yyp
+= strlen (yyp
);
1619 yyerror (]b4_lyyerror_args
[yymsg
);
1624 yyerror (]b4_lyyerror_args
["syntax error");
1629 /* Recover from a syntax error on YYSTACK, assuming that YYTOKENP,
1630 YYLVALP, and YYLLOCP point to the syntactic category, semantic
1631 value, and location of the lookahead. */
1633 yyrecoverSyntaxError (yyGLRStack
* yystack
,
1634 YYSTYPE
* yylvalp
, YYLTYPE
* yyllocp
]b4_user_formals
[)
1636 yySymbol
* const yytokenp
= yystack
->yytokenp
;
1640 if (yystack
->yyerrState
== 0)
1641 yystack
->yyerrState
= 3;
1642 else if (yystack
->yyerrState
== 3)
1643 /* We just shifted the error token and (perhaps) took some
1644 reductions. Skip tokens until we can proceed. */
1647 if (*yytokenp
== YYEOF
)
1649 /* Now pop stack until we find a state that shifts the
1651 while (yystack
->yytops
.yystates
[0] != NULL
)
1653 yyGLRState
*yys
= yystack
->yytops
.yystates
[0];
1654 YYDSYMPRINTF ("Error: popping",
1655 yystos
[yys
->yylrState
],
1656 &yys
->yysemantics
.yysval
, &yys
->yyloc
);
1657 yydestruct (yystos
[yys
->yylrState
],
1658 &yys
->yysemantics
.yysval
]b4_location_if([, &yys
->yyloc
])[);
1659 yystack
->yytops
.yystates
[0] = yys
->yypred
;
1660 yystack
->yynextFree
-= 1;
1661 yystack
->yyspaceLeft
+= 1;
1663 yyFail (yystack
][]b4_lpure_args
[, NULL
);
1665 if (*yytokenp
!= YYEMPTY
)
1667 YYDSYMPRINTF ("Error: discarding", *yytokenp
, yylvalp
, yyllocp
);
1668 yydestruct (*yytokenp
, yylvalp
]b4_location_if([, yyllocp
])[);
1670 YYDPRINTF ((stderr
, "Reading a token: "));
1672 *yytokenp
= YYTRANSLATE (yychar
);
1673 YYDSYMPRINTF ("Next token is", *yytokenp
, yylvalp
, yyllocp
);
1674 yyj
= yypact
[yystack
->yytops
.yystates
[0]->yylrState
];
1675 if (yyis_pact_ninf (yyj
))
1676 /* Something's not right; we shouldn't be here. */
1677 yyFail (yystack
][]b4_lpure_args
[, NULL
);
1679 if (yyj
< 0 || YYLAST
< yyj
|| yycheck
[yyj
] != *yytokenp
)
1681 if (yydefact
[yystack
->yytops
.yystates
[0]->yylrState
] != 0)
1684 else if (yytable
[yyj
] != 0 && ! yyis_table_ninf (yytable
[yyj
]))
1688 /* Reduce to one stack. */
1689 for (yyk
= 0; yyk
< yystack
->yytops
.yysize
; yyk
+= 1)
1690 if (yystack
->yytops
.yystates
[yyk
] != NULL
)
1692 if (yyk
>= yystack
->yytops
.yysize
)
1693 yyFail (yystack
][]b4_lpure_args
[, NULL
);
1694 for (yyk
+= 1; yyk
< yystack
->yytops
.yysize
; yyk
+= 1)
1695 yymarkStackDeleted (yystack
, yyk
);
1696 yyremoveDeletes (yystack
);
1697 yycompressStack (yystack
);
1699 /* Now pop stack until we find a state that shifts the error token. */
1700 while (yystack
->yytops
.yystates
[0] != NULL
)
1702 yyGLRState
*yys
= yystack
->yytops
.yystates
[0];
1703 yyj
= yypact
[yys
->yylrState
];
1704 if (! yyis_pact_ninf (yyj
))
1707 if (0 <= yyj
&& yyj
<= YYLAST
&& yycheck
[yyj
] == YYTERROR
1708 && yyisShiftAction (yytable
[yyj
]))
1710 YYDPRINTF ((stderr
, "Shifting error token, "));
1711 yyglrShift (yystack
, 0, yytable
[yyj
],
1712 yys
->yyposn
, *yylvalp
, yyllocp
]b4_user_args
[);
1716 YYDSYMPRINTF ("Error: popping",
1717 yystos
[yys
->yylrState
],
1718 &yys
->yysemantics
.yysval
, &yys
->yyloc
);
1719 yydestruct (yystos
[yys
->yylrState
],
1720 &yys
->yysemantics
.yysval
]b4_location_if([, &yys
->yyloc
])[);
1721 yystack
->yytops
.yystates
[0] = yys
->yypred
;
1722 yystack
->yynextFree
-= 1;
1723 yystack
->yyspaceLeft
+= 1;
1725 if (yystack
->yytops
.yystates
[0] == NULL
)
1726 yyFail (yystack
][]b4_lpure_args
[, NULL
);
1729 #define YYCHK1(YYE) \
1735 yystack.yyerrflag = 1; \
1738 yystack.yyerrflag = 0; \
1741 goto yyuser_error; \
1750 ]b4_c_ansi_function_def([yyparse
], [int], b4_parse_param
)[
1760 #define yychar (yystack.yyrawchar)
1763 YYSTYPE
* const yylvalp
= &yylval
;
1764 YYLTYPE
* const yyllocp
= &yylloc
;
1766 yyinitGLRStack (&yystack
, YYINITDEPTH
);
1767 yystack
.yytokenp
= &yytoken
;
1769 YYDPRINTF ((stderr
, "Starting parse\n"));
1771 if (setjmp (yystack
.yyexception_buffer
) != 0)
1774 yyglrShift (&yystack
, 0, 0, 0, yyval_default
, &yyloc_default
]b4_user_args
[);
1780 /* For efficiency, we have two loops, the first of which is
1781 specialized to deterministic operation (single stack, no
1782 potential ambiguity). */
1788 const short* yyconflicts
;
1790 yyStateNum yystate
= yystack
.yytops
.yystates
[0]->yylrState
;
1791 YYDPRINTF ((stderr
, "Entering state %d\n", yystate
));
1792 if (yystate
== YYFINAL
)
1794 if (yyisDefaultedState (yystate
))
1796 yyrule
= yydefaultAction (yystate
);
1799 yyreportSyntaxError (&yystack
, yylvalp
, yyllocp
]b4_user_args
[);
1802 YYCHK1 (yyglrReduce (&yystack
, 0, yyrule
, yytrue
]b4_lpure_args
[));
1806 if (yytoken
== YYEMPTY
)
1808 YYDPRINTF ((stderr
, "Reading a token: "));
1810 yytoken
= YYTRANSLATE (yychar
);
1811 YYDSYMPRINTF ("Next token is", yytoken
, yylvalp
, yyllocp
);
1813 yygetLRActions (yystate
, yytoken
, &yyaction
, &yyconflicts
);
1814 if (*yyconflicts
!= 0)
1816 if (yyisShiftAction (yyaction
))
1818 YYDPRINTF ((stderr
, "Shifting token %s, ",
1819 yytokenName (yytoken
)));
1820 if (yytoken
!= YYEOF
)
1823 yyglrShift (&yystack
, 0, yyaction
, yyposn
,
1824 yylval
, yyllocp
]b4_user_args
[);
1825 if (0 < yystack
.yyerrState
)
1826 yystack
.yyerrState
-= 1;
1828 else if (yyisErrorAction (yyaction
))
1830 yyreportSyntaxError (&yystack
, yylvalp
, yyllocp
]b4_user_args
[);
1834 YYCHK1 (yyglrReduce (&yystack
, 0, -yyaction
, yytrue
]b4_lpure_args
[));
1841 int yyn
= yystack
.yytops
.yysize
;
1842 for (yys
= 0; yys
< yyn
; yys
+= 1)
1843 YYCHK1 (yyprocessOneStack (&yystack
, yys
, yyposn
,
1844 yylvalp
, yyllocp
]b4_user_args
[));
1847 yyremoveDeletes (&yystack
);
1848 if (yystack
.yytops
.yysize
== 0)
1850 yyundeleteLastStack (&yystack
);
1851 if (yystack
.yytops
.yysize
== 0)
1852 yyFail (&yystack
][]b4_lpure_args
[, "syntax error");
1853 YYCHK1 (yyresolveStack (&yystack
]b4_user_args
[));
1854 YYDPRINTF ((stderr
, "Returning to deterministic operation.\n"));
1855 yyreportSyntaxError (&yystack
, yylvalp
, yyllocp
]b4_user_args
[);
1858 else if (yystack
.yytops
.yysize
== 1)
1860 YYCHK1 (yyresolveStack (&yystack
]b4_user_args
[));
1861 YYDPRINTF ((stderr
, "Returning to deterministic operation.\n"));
1862 yycompressStack (&yystack
);
1868 yyrecoverSyntaxError (&yystack
, yylvalp
, yyllocp
]b4_user_args
[);
1869 yyposn
= yystack
.yytops
.yystates
[0]->yyposn
;
1874 yyfreeGLRStack (&yystack
);
1875 return yystack
.yyerrflag
;
1878 /* DEBUGGING ONLY */
1879 static void yypstack (yyGLRStack
* yystack
, int yyk
) ATTRIBUTE_UNUSED
;
1880 static void yypdumpstack (yyGLRStack
* yystack
) ATTRIBUTE_UNUSED
;
1883 yy_yypstack (yyGLRState
* yys
)
1887 yy_yypstack (yys
->yypred
);
1888 fprintf (stderr
, " -> ");
1890 fprintf (stderr
, "%d@@%lu", yys
->yylrState
, (unsigned long) yys
->yyposn
);
1894 yypstates (yyGLRState
* yyst
)
1897 fprintf (stderr
, "<null>");
1900 fprintf (stderr
, "\n");
1904 yypstack (yyGLRStack
* yystack
, int yyk
)
1906 yypstates (yystack
->yytops
.yystates
[yyk
]);
1909 #define YYINDEX(YYX) \
1910 ((YYX) == NULL ? -1 : (yyGLRStackItem*) (YYX) - yystack->yyitems)
1914 yypdumpstack (yyGLRStack
* yystack
)
1916 yyGLRStackItem
* yyp
;
1918 for (yyp
= yystack
->yyitems
; yyp
< yystack
->yynextFree
; yyp
+= 1)
1920 fprintf (stderr
, "%3lu. ", (unsigned long) (yyp
- yystack
->yyitems
));
1923 fprintf (stderr
, "Res: %d, LR State: %d, posn: %lu, pred: %ld",
1924 yyp
->yystate
.yyresolved
, yyp
->yystate
.yylrState
,
1925 (unsigned long) yyp
->yystate
.yyposn
,
1926 (long) YYINDEX (yyp
->yystate
.yypred
));
1927 if (! yyp
->yystate
.yyresolved
)
1928 fprintf (stderr
, ", firstVal: %ld",
1929 (long) YYINDEX (yyp
->yystate
.yysemantics
.yyfirstVal
));
1933 fprintf (stderr
, "Option. rule: %d, state: %ld, next: %ld",
1934 yyp
->yyoption
.yyrule
,
1935 (long) YYINDEX (yyp
->yyoption
.yystate
),
1936 (long) YYINDEX (yyp
->yyoption
.yynext
));
1938 fprintf (stderr
, "\n");
1940 fprintf (stderr
, "Tops:");
1941 for (yyi
= 0; yyi
< yystack
->yytops
.yysize
; yyi
+= 1)
1942 fprintf (stderr
, "%lu: %ld; ", (unsigned long) yyi
,
1943 (long) YYINDEX (yystack
->yytops
.yystates
[yyi
]));
1944 fprintf (stderr
, "\n");
1949 m4_if(b4_defines_flag
, 0, [],
1950 [@output @output_header_name@
1951 b4_copyright([Skeleton parser
for GLR parsing with Bison
], [2002])
1953 b4_token_defines(b4_tokens
)
1955 #if ! defined (YYSTYPE) && ! defined (YYSTYPE_IS_DECLARED)
1956 m4_ifdef([b4_stype
],
1957 [b4_syncline([b4_stype_line
], [b4_filename
])
1958 typedef union m4_bregexp(b4_stype
, [^{], [YYSTYPE
])b4_stype YYSTYPE
;
1959 /* Line __line__ of glr.c. */
1960 b4_syncline([@oline@
], [@ofile@
])],
1961 [typedef int YYSTYPE
;])
1962 # define YYSTYPE_IS_DECLARED 1
1963 # define YYSTYPE_IS_TRIVIAL 1
1967 [extern YYSTYPE b4_prefix
[]lval
;])
1970 [#if ! defined (YYLTYPE) && ! defined (YYLTYPE_IS_DECLARED)
1971 typedef struct YYLTYPE
1978 # define YYLTYPE_IS_DECLARED 1
1979 # define YYLTYPE_IS_TRIVIAL 1
1983 [extern YYLTYPE b4_prefix
[]lloc
;])