1 m4_divert(-1) -*- C
-*-
4 # GLR skeleton for Bison
5 # Copyright (C) 2002 Free Software Foundation, Inc.
7 # This program is free software; you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; either version 2 of the License, or
10 # (at your option) any later version.
12 # This program is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
17 # You should have received a copy of the GNU General Public License
18 # along with this program; if not, write to the Free Software
19 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
23 ## ---------------- ##
25 ## ---------------- ##
28 m4_define_default([b4_stack_depth_max
], [10000])
29 m4_define_default([b4_stack_depth_init
], [200])
32 m4_define_default([b4_location_type
], [yyltype
])
36 ## ------------------------ ##
37 ## Pure/impure interfaces. ##
38 ## ------------------------ ##
43 # Accumule in b4_lex_param all the yylex arguments.
44 # Yes, this is quite ugly...
45 m4_define([b4_lex_param
],
46 m4_dquote(b4_pure_if([[[[YYSTYPE
*]], [[yylvalp]]][]dnl
47 b4_location_if([, [[YYLTYPE
*], [yyllocp
]]])])dnl
48 m4_ifdef([b4_lex_param
], [, ]b4_lex_param
)))
53 m4_define([b4_user_formals
],
54 [m4_ifset([b4_parse_param
], [, b4_c_ansi_formals(b4_parse_param
)])])
59 # Arguments passed to yyerror: user args plus yylloc.
60 m4_define([b4_yyerror_args
],
61 [b4_pure_if([b4_location_if([yylocp
, ])])dnl
62 m4_ifset([b4_parse_param
], [b4_c_args(b4_parse_param
), ])])
67 # Same as above, but on the lookahead, hence yyllocp instead of yylocp.
68 m4_define([b4_lyyerror_args
],
69 [b4_pure_if([b4_location_if([yyllocp
, ])])dnl
70 m4_ifset([b4_parse_param
], [b4_c_args(b4_parse_param
), ])])
75 # Arguments needed by yyerror: user args plus yylloc.
76 m4_define([b4_pure_args
],
77 [b4_pure_if([b4_location_if([, yylocp
])])[]b4_user_args
])
82 # Arguments passed to yyerror: user formals plus yyllocp.
83 m4_define([b4_pure_formals
],
84 [b4_pure_if([b4_location_if([, YYLTYPE
*yylocp
])])[]b4_user_formals
])
89 # Same as above, but on the lookahead, hence yyllocp instead of yylocp.
90 m4_define([b4_lpure_args
],
91 [b4_pure_if([b4_location_if([, yyllocp
])])[]b4_user_args
])
96 # Same as above, but on the lookahead, hence yyllocp instead of yylocp.
97 m4_define([b4_lpure_formals
],
98 [b4_pure_if([b4_location_if([YYLTYPE
*yyllocp
])])[]b4_user_formals
])
101 ## ----------------- ##
102 ## Semantic Values. ##
103 ## ----------------- ##
106 # b4_lhs_value([TYPE])
107 # --------------------
108 # Expansion of $<TYPE>$.
109 m4_define([b4_lhs_value
],
110 [(*yyvalp
)[]m4_ifval([$
1], [.$
1])])
113 # b4_rhs_value(RULE-LENGTH, NUM, [TYPE])
114 # --------------------------------------
115 # Expansion of $<TYPE>NUM, where the current rule has RULE-LENGTH
117 m4_define([b4_rhs_value
],
118 [yyvsp@
{m4_eval([$
2 - $
1])@
}.yystate
.yysemantics
.yysval
[]m4_ifval([$
3], [.$
3])])
129 m4_define([b4_lhs_location
],
133 # b4_rhs_location(RULE-LENGTH, NUM)
134 # ---------------------------------
135 # Expansion of @NUM, where the current rule has RULE-LENGTH symbols
137 m4_define([b4_rhs_location
],
138 [yyvsp@
{m4_eval([$
2 - $
1])@
}.yystate
.yyloc
])
141 # We do want M4 expansion after # for CPP macros.
144 @output @output_parser_name@
145 b4_copyright([Skeleton parser
for GLR parsing with Bison
], [2002])
147 /* This is the parser code for GLR (Generalized LR) parser. */
157 m4_if(b4_prefix
[], [yy
], [],
158 [/* If NAME_PREFIX is specified substitute the variables and functions
160 #define yyparse b4_prefix[]parse
161 #define yylex b4_prefix[]lex
162 #define yyerror b4_prefix[]error
163 #define yylval b4_prefix[]lval
164 #define yychar b4_prefix[]char
165 #define yydebug b4_prefix[]debug
166 #define yynerrs b4_prefix[]nerrs
167 b4_location_if([#define yylloc b4_prefix[]lloc])])
169 b4_token_defines(b4_tokens
)
171 /* Copy the first part of user declarations. */
174 /* Enabling traces. */
176 # define YYDEBUG ]b4_debug[
179 /* Enabling verbose error messages. */
180 #ifdef YYERROR_VERBOSE
181 # undef YYERROR_VERBOSE
182 # define YYERROR_VERBOSE 1
184 # define YYERROR_VERBOSE ]b4_error_verbose[
188 ]m4_ifdef([b4_stype
],
189 [b4_syncline([b4_stype_line
], [b4_filename
])
190 typedef union b4_stype yystype
;
191 /* Line __line__ of __file__. */
192 b4_syncline([@oline@
], [@ofile@
])],
193 [typedef int yystype
;])[
194 # define YYSTYPE yystype
195 # define YYSTYPE_IS_TRIVIAL 1
199 typedef struct yyltype
206 # define YYLTYPE ]b4_location_type[
207 # define YYLTYPE_IS_TRIVIAL 1
210 /* Default (constant) values used for initialization for null
211 right-hand sides. Unlike the standard bison.simple template,
212 here we set the default values of $$ and $@@ to zeroed-out
213 values. Since the default value of these quantities is undefined,
214 this behavior is technically correct. */
215 static YYSTYPE yyval_default
;
216 static YYLTYPE yyloc_default
;
218 /* Copy the second part of user declarations. */
221 ]/* Line __line__ of __file__. */
222 b4_syncline([@oline@
], [@ofile@
])
224 #if ! defined (__cplusplus)
234 #ifndef __attribute__
235 /* This feature is available in gcc versions 2.5 and later. */
236 # if !defined (__GNUC__) || __GNUC__ < 2 || \
237 (__GNUC__ == 2 && __GNUC_MINOR__ < 5) || __STRICT_ANSI__
238 # define __attribute__(Spec) /* empty */
242 #ifndef ATTRIBUTE_UNUSED
243 # define ATTRIBUTE_UNUSED __attribute__ ((__unused__))
246 /* YYFINAL -- State number of the termination state. */
247 #define YYFINAL ]b4_final_state_number[
248 /* YYLAST -- Last index in YYTABLE. */
249 #define YYLAST ]b4_last[
251 /* YYNTOKENS -- Number of terminals. */
252 #define YYNTOKENS ]b4_tokens_number[
253 /* YYNNTS -- Number of nonterminals. */
254 #define YYNNTS ]b4_nterms_number[
255 /* YYNRULES -- Number of rules. */
256 #define YYNRULES ]b4_rules_number[
257 /* YYNRULES -- Number of states. */
258 #define YYNSTATES ]b4_states_number[
259 /* YYMAXRHS -- Maximum number of symbols on right-hand side of rule. */
260 #define YYMAXRHS ]b4_r2_max[
262 /* YYTRANSLATE(X) -- Bison symbol number corresponding to X. */
263 #define YYUNDEFTOK ]b4_undef_token_number[
264 #define YYMAXUTOK ]b4_user_token_number_max[
266 #define YYTRANSLATE(YYX) \
267 ((YYX <= 0) ? YYEOF : \
268 (unsigned)(YYX) <= YYMAXUTOK ? yytranslate[YYX] : YYUNDEFTOK)
270 /* YYTRANSLATE[YYLEX] -- Bison symbol number corresponding to YYLEX. */
271 static const ]b4_int_type_for([b4_translate
])[ yytranslate
[] =
277 /* YYPRHS[YYN] -- Index of the first RHS symbol of rule number YYN in
279 static const ]b4_int_type_for([b4_prhs
])[ yyprhs
[] =
284 /* YYRHS -- A `-1'-separated list of the rules' RHS. */
285 static const ]b4_int_type_for([b4_rhs
])[ yyrhs
[] =
290 /* YYRLINE[YYN] -- source line where rule number YYN was defined. */
291 static const ]b4_int_type_for([b4_rline
])[ yyrline
[] =
297 #if (YYDEBUG) || YYERROR_VERBOSE
298 /* YYTNME[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM.
299 First, the terminals, then, starting at YYNTOKENS, nonterminals. */
300 static const char *const yytname
[] =
305 #define yytname_size ((int) (sizeof (yytname) / sizeof (yytname[0])))
308 /* YYR1[YYN] -- Symbol number of symbol that rule YYN derives. */
309 static const ]b4_int_type_for([b4_r1
])[ yyr1
[] =
314 /* YYR2[YYN] -- Number of symbols composing right hand side of rule YYN. */
315 static const ]b4_int_type_for([b4_r2
])[ yyr2
[] =
320 /* YYDPREC[RULE-NUM] -- Dynamic precedence of rule #RULE-NUM (0 if none). */
321 static const ]b4_int_type_for([b4_dprec
])[ yydprec
[] =
326 /* YYMERGER[RULE-NUM] -- Index of merging function for rule #RULE-NUM. */
327 static const ]b4_int_type_for([b4_merger
])[ yymerger
[] =
332 /* YYDEFACT[S] -- default rule to reduce with in state S when YYTABLE
333 doesn't specify something else to do. Zero means the default is an
335 static const ]b4_int_type_for([b4_defact
])[ yydefact
[] =
340 /* YYPDEFGOTO[NTERM-NUM]. */
341 static const ]b4_int_type_for([b4_defgoto
])[ yydefgoto
[] =
346 /* YYPACT[STATE-NUM] -- Index in YYTABLE of the portion describing
348 #define YYPACT_NINF ]b4_pact_ninf[
349 static const ]b4_int_type_for([b4_pact
])[ yypact
[] =
354 /* YYPGOTO[NTERM-NUM]. */
355 static const ]b4_int_type_for([b4_pgoto
])[ yypgoto
[] =
360 /* YYTABLE[YYPACT[STATE-NUM]]. What to do in state STATE-NUM. If
361 positive, shift that token. If negative, reduce the rule which
362 number is the opposite. If zero, do what YYDEFACT says.
363 If YYTABLE_NINF, syntax error. */
364 #define YYTABLE_NINF ]b4_table_ninf[
365 static const ]b4_int_type_for([b4_table
])[ yytable
[] =
370 /* YYCONFLP[YYPACT[STATE-NUM]] -- Pointer into YYCONFL of start of
371 list of conflicting reductions corresponding to action entry for
372 state STATE-NUM in yytable. 0 means no conflicts. The list in
373 yyconfl is terminated by a rule number of 0. */
374 static const ]b4_int_type_for([b4_conflict_list_heads
])[ yyconflp
[] =
376 ]b4_conflict_list_heads
[
379 /* YYCONFL[I] -- lists of conflicting rule numbers, each terminated by
380 0, pointed into by YYCONFLP. */
381 ]dnl Do
not use b4_int_type_for here
, since there are places where
382 dnl pointers onto yyconfl are taken
, which type is
"short *".
383 dnl We probably ought to introduce a type
for confl
.
384 [static const short yyconfl
[] =
386 ]b4_conflicting_rules
[
389 static const ]b4_int_type_for([b4_check
])[ yycheck
[] =
394 /* YYSTOS[STATE-NUM] -- The (internal number of the) accessing
395 symbol of state STATE-NUM. */
396 static const ]b4_int_type_for([b4_stos
])[ yystos
[] =
402 /* Prevent warning if -Wmissing-prototypes. */
403 ]b4_c_ansi_function_decl([yyparse
], [int], b4_parse_param
)[
405 /* Error token number */
408 /* YYLLOC_DEFAULT -- Compute the default location (before the actions
411 #define YYRHSLOC(yyRhs,YYK) (yyRhs[YYK].yystate.yyloc)
413 #ifndef YYLLOC_DEFAULT
414 # define YYLLOC_DEFAULT(yyCurrent, yyRhs, YYN) \
415 yyCurrent.first_line = YYRHSLOC(yyRhs,1).first_line; \
416 yyCurrent.first_column = YYRHSLOC(yyRhs,1).first_column; \
417 yyCurrent.last_line = YYRHSLOC(yyRhs,YYN).last_line; \
418 yyCurrent.last_column = YYRHSLOC(yyRhs,YYN).last_column;
421 /* YYLEX -- calling `yylex' with the right arguments. */
422 #define YYLEX ]b4_c_function_call([yylex], [int], b4_lex_param)[
427 #define yynerrs (yystack->yyerrcnt)
429 #define yychar (yystack->yyrawchar)],
437 static const int YYEOF
= 0;
438 static const int YYEMPTY
= -2;
440 typedef enum { yyok
, yyaccept
, yyabort
, yyerr
} YYRESULTTAG
;
443 do { YYRESULTTAG yyflag = YYE; if (yyflag != yyok) return yyflag; } \
448 #if ! defined (YYFPRINTF)
449 # define YYFPRINTF fprintf
452 # define YYDPRINTF(Args) \
458 ]b4_yysymprint_generate([b4_c_ansi_function_def
])[
460 # define YYDSYMPRINT(Args) \
466 # define YYDSYMPRINTF(Title, Token, Value, Location) \
470 YYFPRINTF (stderr, "%s ", Title); \
471 yysymprint (stderr, \
472 Token, Value]b4_location_if([, Location])[); \
473 YYFPRINTF (stderr, "\n"); \
477 /* Nonzero means print parse trace. It is left uninitialized so that
478 multiple parsers can coexist. */
483 /* Avoid empty `if' bodies. */
484 # define YYDPRINTF(Args) {}
485 # define YYDSYMPRINT(Args) {}
486 # define YYDSYMPRINTF(Title, Token, Value, Location) {}
488 #endif /* !YYDEBUG */
490 /* YYINITDEPTH -- initial size of the parser's stacks. */
492 # define YYINITDEPTH ]b4_stack_depth_init[
495 /* YYMAXDEPTH -- maximum size the stacks can grow to (effective only
496 if the built-in stack extension method is used).
498 Do not make this value too large; the results are undefined if
499 SIZE_MAX < YYMAXDEPTH * sizeof (GLRStackItem)
500 evaluated with infinite-precision integer arithmetic. */
507 # define YYMAXDEPTH ]b4_stack_depth_max[
510 /* Minimum number of free items on the stack allowed after an
511 allocation. This is to allow allocation and initialization
512 to be completed by functions that call expandGLRStack before the
513 stack is expanded, thus insuring that all necessary pointers get
514 properly redirected to new data. */
517 #if ! defined (YYSTACKEXPANDABLE) \
518 && (! defined (__cplusplus) || (YYLTYPE_IS_TRIVIAL && YYSTYPE_IS_TRIVIAL))
519 #define YYSTACKEXPANDABLE 1
521 #define YYSTACKEXPANDABLE 0
524 /** State numbers, as in LALR(1) machine */
525 typedef int yyStateNum
;
527 /** Rule numbers, as in LALR(1) machine */
528 typedef int yyRuleNum
;
530 /** Grammar symbol */
531 typedef short yySymbol
;
533 /** Item references, as in LALR(1) machine */
534 typedef short yyItemNum
;
536 typedef struct yyGLRState yyGLRState
;
537 typedef struct yySemanticOption yySemanticOption
;
538 typedef union yyGLRStackItem yyGLRStackItem
;
539 typedef struct yyGLRStack yyGLRStack
;
540 typedef struct yyGLRStateSet yyGLRStateSet
;
545 yyStateNum yylrState
;
549 yySemanticOption
* yyfirstVal
;
555 struct yyGLRStateSet
{
556 yyGLRState
** yystates
;
557 size_t yysize
, yycapacity
;
560 struct yySemanticOption
{
564 yySemanticOption
* yynext
;
567 union yyGLRStackItem
{
569 yySemanticOption yyoption
;
581 jmp_buf yyexception_buffer
;
582 yyGLRStackItem
* yyitems
;
583 yyGLRStackItem
* yynextFree
;
585 yyGLRState
* yysplitPoint
;
586 yyGLRState
* yylastDeleted
;
587 yyGLRStateSet yytops
;
590 static void yyinitGLRStack (yyGLRStack
* yystack
, size_t yysize
);
591 static void yyexpandGLRStack (yyGLRStack
* yystack
]b4_pure_formals
[);
592 static void yyfreeGLRStack (yyGLRStack
* yystack
);
595 yyFail (yyGLRStack
* yystack
]b4_pure_formals
[, const char* yyformat
, ...)
597 yystack
->yyerrflag
= 1;
598 if (yyformat
!= NULL
)
602 va_start (yyap
, yyformat
);
603 vsprintf (yymsg
, yyformat
, yyap
);
604 yyerror (]b4_yyerror_args
[yymsg
);
606 longjmp (yystack
->yyexception_buffer
, 1);
609 #if YYDEBUG || YYERROR_VERBOSE
610 /** A printable representation of TOKEN. Valid until next call to
612 static inline const char*
613 yytokenName (yySymbol yytoken
)
615 return yytname
[yytoken
];
619 /** Perform user action for rule number YYN, with RHS length YYRHSLEN,
620 * and top stack item YYVSP. YYLVALP points to place to put semantic
621 * value ($$), and yylocp points to place for location information
622 * (@@$). Returns yyok for normal return, yyaccept for YYACCEPT,
623 * yyerr for YYERROR, yyabort for YYABORT. */
625 yyuserAction (yyRuleNum yyn
, int yyrhslen
, yyGLRStackItem
* yyvsp
,
626 YYSTYPE
* yyvalp
, YYLTYPE
* yylocp
, yyGLRStack
* yystack
629 /* Avoid `unused' warnings in there are no $n. */
634 *yyvalp
= yyval_default
;
635 *yylocp
= yyloc_default
;
639 *yyvalp
= yyvsp
[1-yyrhslen
].yystate
.yysemantics
.yysval
;
640 *yylocp
= yyvsp
[1-yyrhslen
].yystate
.yyloc
;
643 # define yyerrok (yystack->yyerrState = 0)
645 # define YYACCEPT return yyaccept
647 # define YYABORT return yyabort
649 # define YYERROR return yyerr
651 # define YYRECOVERING (yystack->yyerrState != 0)
653 # define yyclearin (yychar = *(yystack->yytokenp) = YYEMPTY)
655 # define YYBACKUP(Token, Value) \
657 yyerror (]b4_yyerror_args["syntax error: cannot back up"); \
675 /* Line __line__ of __file__. */
676 b4_syncline([@oline@
], [@ofile@
])
681 yyuserMerge (int yyn
, YYSTYPE
* yy0
, YYSTYPE
* yy1
)
683 YYSTYPE yyval
= *yy0
;
684 /* `Use' the arguments. */
695 /* Bison grammar-table manipulation. */
697 ]b4_yydestruct_generate([b4_c_ansi_function_def
])[
699 /** Number of symbols composing the right hand side of rule #RULE. */
701 yyrhsLength (yyRuleNum yyrule
)
706 /** Left-hand-side symbol for rule #RULE. */
707 static inline yySymbol
708 yylhsNonterm (yyRuleNum yyrule
)
713 #define yyis_pact_ninf(yystate) \
714 ]m4_if(m4_eval(b4_pact_ninf < b4_pact_min), 1,
716 ((yystate
) == YYPACT_NINF
))[
718 /** True iff LR state STATE has only a default reduction (regardless
721 yyisDefaultedState (yyStateNum yystate
)
723 return yyis_pact_ninf (yypact
[yystate
]);
726 /** The default reduction for STATE, assuming it has one. */
727 static inline yyRuleNum
728 yydefaultAction (yyStateNum yystate
)
730 return yydefact
[yystate
];
733 #define yyis_table_ninf(yyindex) \
734 ]m4_if(m4_eval(b4_table_ninf < b4_table_min), 1,
736 ((yyindex
) == YYTABLE_NINF
))[
738 /** Set *YYACTION to the action to take in YYSTATE on seeing YYTOKEN.
740 * R < 0: Reduce on rule -R.
742 * R > 0: Shift to state R.
743 * Set *CONFLICTS to a pointer into yyconfl to 0-terminated list of
744 * conflicting reductions.
747 yygetLRActions (yyStateNum yystate
, int yytoken
,
748 int* yyaction
, const short** yyconflicts
)
750 int yyindex
= yypact
[yystate
] + yytoken
;
751 if (yyindex
< 0 || YYLAST
< yyindex
|| yycheck
[yyindex
] != yytoken
)
753 *yyaction
= -yydefact
[yystate
];
754 *yyconflicts
= yyconfl
;
756 else if (! yyis_table_ninf (yyindex
))
758 *yyaction
= yytable
[yyindex
];
759 *yyconflicts
= yyconfl
+ yyconflp
[yyindex
];
764 *yyconflicts
= yyconfl
+ yyconflp
[yyindex
];
768 static inline yyStateNum
769 yyLRgotoState (yyStateNum yystate
, yySymbol yylhs
)
772 yyr
= yypgoto
[yylhs
- YYNTOKENS
] + yystate
;
773 if (0 <= yyr
&& yyr
<= YYLAST
&& yycheck
[yyr
] == yystate
)
776 return yydefgoto
[yylhs
- YYNTOKENS
];
780 yyisShiftAction (int yyaction
)
786 yyisErrorAction (int yyaction
)
788 return yyaction
== 0;
793 /** True iff the semantic value of the edge leading to STATE is
796 yyhasResolvedValue (yyGLRState
* yystate
)
798 return yystate
->yyresolved
;
802 yyaddDeferredAction (yyGLRStack
* yystack
, yyGLRState
* yystate
,
803 yyGLRState
* rhs
, yyRuleNum yyrule
]b4_pure_formals
[)
805 yySemanticOption
* yynewItem
;
806 yynewItem
= &yystack
->yynextFree
->yyoption
;
807 yystack
->yyspaceLeft
-= 1;
808 yystack
->yynextFree
+= 1;
809 yynewItem
->yyisState
= yyfalse
;
810 yynewItem
->yystate
= rhs
;
811 yynewItem
->yyrule
= yyrule
;
812 yynewItem
->yynext
= yystate
->yysemantics
.yyfirstVal
;
813 yystate
->yysemantics
.yyfirstVal
= yynewItem
;
814 if (yystack
->yyspaceLeft
< YYHEADROOM
)
815 yyexpandGLRStack (yystack
]b4_pure_args
[);
820 /** Initialize SET to a singleton set containing an empty stack. */
822 yyinitStateSet (yyGLRStateSet
* yyset
)
825 yyset
->yycapacity
= 16;
826 yyset
->yystates
= (yyGLRState
**) malloc (16 * sizeof (yyset
->yystates
[0]));
827 yyset
->yystates
[0] = NULL
;
830 static void yyfreeStateSet (yyGLRStateSet
* yyset
)
832 free (yyset
->yystates
);
835 /** Initialize STACK to a single empty stack, with total maximum
836 * capacity for all stacks of SIZE. */
838 yyinitGLRStack (yyGLRStack
* yystack
, size_t yysize
)
840 yystack
->yyerrflag
= 0;
841 yystack
->yyerrState
= 0;
843 yystack
->yyspaceLeft
= yysize
;
844 yystack
->yynextFree
= yystack
->yyitems
=
845 (yyGLRStackItem
*) malloc (yysize
* sizeof (yystack
->yynextFree
[0]));
846 yystack
->yysplitPoint
= NULL
;
847 yystack
->yylastDeleted
= NULL
;
848 yyinitStateSet (&yystack
->yytops
);
851 #define YYRELOC(YYFROMITEMS,YYTOITEMS,YYX,YYTYPE) \
852 &((YYTOITEMS) - ((YYFROMITEMS) - (yyGLRStackItem*) (YYX)))->YYTYPE
854 /** If STACK is expandable, extend it. WARNING: Pointers into the
855 stack from outside should be considered invalid after this call.
856 We always expand when there are 1 or fewer items left AFTER an
857 allocation, so that we can avoid having external pointers exist
858 across an allocation. */
860 yyexpandGLRStack (yyGLRStack
* yystack
]b4_pure_formals
[)
862 #if YYSTACKEXPANDABLE
863 yyGLRStack yynewStack
;
864 yyGLRStackItem
* yyp0
, *yyp1
;
865 size_t yysize
, yynewSize
;
867 yysize
= yystack
->yynextFree
- yystack
->yyitems
;
868 if (YYMAXDEPTH
<= yysize
)
869 yyFail (yystack
][]b4_pure_args
[, "parser stack overflow");
870 yynewSize
= 2*yysize
;
871 if (YYMAXDEPTH
< yynewSize
)
872 yynewSize
= YYMAXDEPTH
;
873 yyinitGLRStack (&yynewStack
, yynewSize
);
874 for (yyp0
= yystack
->yyitems
, yyp1
= yynewStack
.yyitems
, yyn
= yysize
;
876 yyn
-= 1, yyp0
+= 1, yyp1
+= 1)
881 yyGLRState
* yys0
= &yyp0
->yystate
;
882 yyGLRState
* yys1
= &yyp1
->yystate
;
883 if (yys0
->yypred
!= NULL
)
885 YYRELOC (yyp0
, yyp1
, yys0
->yypred
, yystate
);
886 if (! yys0
->yyresolved
&& yys0
->yysemantics
.yyfirstVal
!= NULL
)
887 yys1
->yysemantics
.yyfirstVal
=
888 YYRELOC(yyp0
, yyp1
, yys0
->yysemantics
.yyfirstVal
, yyoption
);
892 yySemanticOption
* yyv0
= &yyp0
->yyoption
;
893 yySemanticOption
* yyv1
= &yyp1
->yyoption
;
894 if (yyv0
->yystate
!= NULL
)
895 yyv1
->yystate
= YYRELOC (yyp0
, yyp1
, yyv0
->yystate
, yystate
);
896 if (yyv0
->yynext
!= NULL
)
897 yyv1
->yynext
= YYRELOC (yyp0
, yyp1
, yyv0
->yynext
, yyoption
);
900 if (yystack
->yysplitPoint
!= NULL
)
901 yystack
->yysplitPoint
= YYRELOC (yystack
->yyitems
, yynewStack
.yyitems
,
902 yystack
->yysplitPoint
, yystate
);
904 for (yyn
= 0; yyn
< yystack
->yytops
.yysize
; yyn
+= 1)
905 if (yystack
->yytops
.yystates
[yyn
] != NULL
)
906 yystack
->yytops
.yystates
[yyn
] =
907 YYRELOC (yystack
->yyitems
, yynewStack
.yyitems
,
908 yystack
->yytops
.yystates
[yyn
], yystate
);
909 free (yystack
->yyitems
);
910 yystack
->yyitems
= yynewStack
.yyitems
;
911 yystack
->yynextFree
= yynewStack
.yynextFree
+ yysize
;
912 yystack
->yyspaceLeft
= yynewStack
.yyspaceLeft
- yysize
;
916 yyFail (yystack
][]b4_lpure_args
[, "parser stack overflow");
921 yyfreeGLRStack (yyGLRStack
* yystack
)
923 free (yystack
->yyitems
);
924 yyfreeStateSet (&yystack
->yytops
);
927 /** Assuming that S is a GLRState somewhere on STACK, update the
928 * splitpoint of STACK, if needed, so that it is at least as deep as
931 yyupdateSplit (yyGLRStack
* yystack
, yyGLRState
* yys
)
933 if (yystack
->yysplitPoint
!= NULL
&& yystack
->yysplitPoint
> yys
)
934 yystack
->yysplitPoint
= yys
;
937 /** Invalidate stack #K in STACK. */
939 yymarkStackDeleted (yyGLRStack
* yystack
, int yyk
)
941 if (yystack
->yytops
.yystates
[yyk
] != NULL
)
942 yystack
->yylastDeleted
= yystack
->yytops
.yystates
[yyk
];
943 yystack
->yytops
.yystates
[yyk
] = NULL
;
946 /** Undelete the last stack that was marked as deleted. Can only be
947 done once after a deletion, and only when all other stacks have
950 yyundeleteLastStack (yyGLRStack
* yystack
)
952 if (yystack
->yylastDeleted
== NULL
|| yystack
->yytops
.yysize
!= 0)
954 yystack
->yytops
.yystates
[0] = yystack
->yylastDeleted
;
955 yystack
->yytops
.yysize
= 1;
956 YYDPRINTF ((stderr
, "Restoring last deleted stack as stack #0.\n"));
957 yystack
->yylastDeleted
= NULL
;
961 yyremoveDeletes (yyGLRStack
* yystack
)
965 while (yyj
< yystack
->yytops
.yysize
)
967 if (yystack
->yytops
.yystates
[yyi
] == NULL
)
970 YYDPRINTF ((stderr
, "Removing dead stacks.\n"));
971 yystack
->yytops
.yysize
-= 1;
975 yystack
->yytops
.yystates
[yyj
] = yystack
->yytops
.yystates
[yyi
];
977 YYDPRINTF ((stderr
, "Rename stack %d -> %d.\n", yyi
, yyj
));
984 /** Shift to a new state on stack #K of STACK, corresponding to LR state
985 * LRSTATE, at input position POSN, with (resolved) semantic value SVAL. */
987 yyglrShift (yyGLRStack
* yystack
, int yyk
, yyStateNum yylrState
, size_t yyposn
,
988 YYSTYPE yysval
, YYLTYPE
* yylocp
]b4_user_formals
[)
990 yyGLRStackItem
* yynewItem
;
992 yynewItem
= yystack
->yynextFree
;
993 yystack
->yynextFree
+= 1;
994 yystack
->yyspaceLeft
-= 1;
995 yynewItem
->yystate
.yyisState
= yytrue
;
996 yynewItem
->yystate
.yylrState
= yylrState
;
997 yynewItem
->yystate
.yyposn
= yyposn
;
998 yynewItem
->yystate
.yyresolved
= yytrue
;
999 yynewItem
->yystate
.yypred
= yystack
->yytops
.yystates
[yyk
];
1000 yystack
->yytops
.yystates
[yyk
] = &yynewItem
->yystate
;
1001 yynewItem
->yystate
.yysemantics
.yysval
= yysval
;
1002 yynewItem
->yystate
.yyloc
= *yylocp
;
1003 if (yystack
->yyspaceLeft
< YYHEADROOM
)
1004 yyexpandGLRStack (yystack
]b4_pure_args
[);
1007 /** Shift to a new state on stack #K of STACK, to a new state
1008 * corresponding to LR state LRSTATE, at input position POSN, with
1009 * the (unresolved) semantic value of RHS under the action for RULE. */
1011 yyglrShiftDefer (yyGLRStack
* yystack
, int yyk
, yyStateNum yylrState
,
1012 size_t yyposn
, yyGLRState
* rhs
, yyRuleNum yyrule
]b4_pure_formals
[)
1014 yyGLRStackItem
* yynewItem
;
1016 yynewItem
= yystack
->yynextFree
;
1017 yynewItem
->yystate
.yyisState
= yytrue
;
1018 yynewItem
->yystate
.yylrState
= yylrState
;
1019 yynewItem
->yystate
.yyposn
= yyposn
;
1020 yynewItem
->yystate
.yyresolved
= yyfalse
;
1021 yynewItem
->yystate
.yypred
= yystack
->yytops
.yystates
[yyk
];
1022 yynewItem
->yystate
.yysemantics
.yyfirstVal
= NULL
;
1023 yystack
->yytops
.yystates
[yyk
] = &yynewItem
->yystate
;
1024 yystack
->yynextFree
+= 1;
1025 yystack
->yyspaceLeft
-= 1;
1026 yyaddDeferredAction (yystack
, &yynewItem
->yystate
, rhs
, yyrule
]b4_pure_args
[);
1029 /** Pop the symbols consumed by reduction #RULE from the top of stack
1030 * #K of STACK, and perform the appropriate semantic action on their
1031 * semantic values. Assumes that all ambiguities in semantic values
1032 * have been previously resolved. Set *VALP to the resulting value,
1033 * and *LOCP to the computed location (if any). Return value is as
1034 * for userAction. */
1035 static inline YYRESULTTAG
1036 yydoAction (yyGLRStack
* yystack
, int yyk
, yyRuleNum yyrule
,
1037 YYSTYPE
* yyvalp
, YYLTYPE
* yylocp
]b4_user_formals
[)
1039 int yynrhs
= yyrhsLength (yyrule
);
1041 if (yystack
->yysplitPoint
== NULL
)
1043 /* Standard special case: single stack. */
1044 yyGLRStackItem
* rhs
= (yyGLRStackItem
*) yystack
->yytops
.yystates
[yyk
];
1046 yystack
->yynextFree
-= yynrhs
;
1047 yystack
->yyspaceLeft
+= yynrhs
;
1048 yystack
->yytops
.yystates
[0] = & yystack
->yynextFree
[-1].yystate
;
1051 *yyvalp
= yyval_default
;
1052 *yylocp
= yyloc_default
;
1056 *yyvalp
= rhs
[1-yynrhs
].yystate
.yysemantics
.yysval
;
1057 *yylocp
= rhs
[1-yynrhs
].yystate
.yyloc
;
1059 return yyuserAction (yyrule
, yynrhs
, rhs
,
1060 yyvalp
, yylocp
, yystack
]b4_user_args
[);
1066 yyGLRStackItem yyrhsVals
[YYMAXRHS
];
1067 for (yyi
= yynrhs
-1, yys
= yystack
->yytops
.yystates
[yyk
]; 0 <= yyi
;
1068 yyi
-= 1, yys
= yys
->yypred
)
1070 assert (yys
->yypred
!= NULL
);
1071 yyrhsVals
[yyi
].yystate
.yyresolved
= yytrue
;
1072 yyrhsVals
[yyi
].yystate
.yysemantics
.yysval
= yys
->yysemantics
.yysval
;
1073 yyrhsVals
[yyi
].yystate
.yyloc
= yys
->yyloc
;
1075 yyupdateSplit (yystack
, yys
);
1076 yystack
->yytops
.yystates
[yyk
] = yys
;
1079 *yyvalp
= yyval_default
;
1080 *yylocp
= yyloc_default
;
1084 *yyvalp
= yyrhsVals
[0].yystate
.yysemantics
.yysval
;
1085 *yylocp
= yyrhsVals
[0].yystate
.yyloc
;
1087 return yyuserAction (yyrule
, yynrhs
, yyrhsVals
+ (yynrhs
-1),
1088 yyvalp
, yylocp
, yystack
]b4_user_args
[);
1093 # define YY_REDUCE_PRINT(K, Rule)
1095 # define YY_REDUCE_PRINT(K, Rule) \
1098 yy_reduce_print (K, Rule); \
1101 /*----------------------------------------------------------.
1102 | Report that the RULE is going to be reduced on stack #K. |
1103 `----------------------------------------------------------*/
1106 yy_reduce_print (size_t yyk
, yyRuleNum yyrule
)
1109 YYDPRINTF ((stderr
, "Reducing stack %d by rule %d (line %d), ",
1110 yyk
, yyrule
- 1, yyrline
[yyrule
]));
1111 /* Print the symbols being reduced, and their result. */
1112 for (yyi
= yyprhs
[yyrule
]; 0 <= yyrhs
[yyi
]; yyi
++)
1113 YYFPRINTF (stderr
, "%s ", yytokenName (yyrhs
[yyi
]));
1114 YYFPRINTF (stderr
, "-> %s\n", yytokenName (yyr1
[yyrule
]));
1118 /** Pop items off stack #K of STACK according to grammar rule RULE,
1119 * and push back on the resulting nonterminal symbol. Perform the
1120 * semantic action associated with RULE and store its value with the
1121 * newly pushed state, if FORCEEVAL or if STACK is currently
1122 * unambiguous. Otherwise, store the deferred semantic action with
1123 * the new state. If the new state would have an identical input
1124 * position, LR state, and predecessor to an existing state on the stack,
1125 * it is identified with that existing state, eliminating stack #K from
1126 * the STACK. In this case, the (necessarily deferred) semantic value is
1127 * added to the options for the existing state's semantic value.
1129 static inline YYRESULTTAG
1130 yyglrReduce (yyGLRStack
* yystack
, size_t yyk
, yyRuleNum yyrule
,
1131 bool yyforceEval
]b4_pure_formals
[)
1133 size_t yyposn
= yystack
->yytops
.yystates
[yyk
]->yyposn
;
1135 if (yyforceEval
|| yystack
->yysplitPoint
== NULL
)
1140 YY_REDUCE_PRINT (yyk
, yyrule
);
1141 YYCHK (yydoAction (yystack
, yyk
, yyrule
, &yysval
, &yyloc
]b4_user_args
[));
1142 yyglrShift (yystack
, yyk
,
1143 yyLRgotoState (yystack
->yytops
.yystates
[yyk
]->yylrState
,
1144 yylhsNonterm (yyrule
)),
1145 yyposn
, yysval
, &yyloc
]b4_user_args
[);
1146 YYDPRINTF ((stderr
, "Stack %d entering state %d\n",
1147 yyk
, yystack
->yytops
.yystates
[yyk
]->yylrState
));
1153 yyGLRState
* yys
, *yys0
= yystack
->yytops
.yystates
[yyk
];
1154 yyStateNum yynewLRState
;
1156 for (yys
= yystack
->yytops
.yystates
[yyk
], yyn
= yyrhsLength (yyrule
);
1160 assert (yys
!= NULL
);
1162 yyupdateSplit (yystack
, yys
);
1163 yynewLRState
= yyLRgotoState (yys
->yylrState
, yylhsNonterm (yyrule
));
1165 "Reduced stack %d by rule #%d; action deferred. "
1166 "Now in state %d.\n",
1167 yyk
, yyrule
-1, yynewLRState
));
1168 for (yyi
= 0; yyi
< yystack
->yytops
.yysize
; yyi
+= 1)
1169 if (yyi
!= yyk
&& yystack
->yytops
.yystates
[yyi
] != NULL
)
1171 yyGLRState
* yyp
, *yysplit
= yystack
->yysplitPoint
;
1172 yyp
= yystack
->yytops
.yystates
[yyi
];
1173 while (yyp
!= yys
&& yyp
!= yysplit
&& yyp
->yyposn
>= yyposn
)
1175 if (yyp
->yylrState
== yynewLRState
&& yyp
->yypred
== yys
)
1177 yyaddDeferredAction (yystack
, yyp
, yys0
, yyrule
]b4_pure_args
[);
1178 yymarkStackDeleted (yystack
, yyk
);
1179 YYDPRINTF ((stderr
, "Merging stack %d into stack %d.\n",
1186 yystack
->yytops
.yystates
[yyk
] = yys
;
1187 yyglrShiftDefer (yystack
, yyk
, yynewLRState
, yyposn
, yys0
, yyrule
]b4_pure_args
[);
1193 yysplitStack (yyGLRStack
* yystack
, int yyk
)
1195 if (yystack
->yysplitPoint
== NULL
)
1198 yystack
->yysplitPoint
= yystack
->yytops
.yystates
[yyk
];
1200 if (yystack
->yytops
.yysize
>= yystack
->yytops
.yycapacity
)
1202 yystack
->yytops
.yycapacity
*= 2;
1203 yystack
->yytops
.yystates
=
1204 (yyGLRState
**) realloc (yystack
->yytops
.yystates
,
1205 yystack
->yytops
.yycapacity
1206 * sizeof (yyGLRState
*));
1208 yystack
->yytops
.yystates
[yystack
->yytops
.yysize
]
1209 = yystack
->yytops
.yystates
[yyk
];
1210 yystack
->yytops
.yysize
+= 1;
1211 return yystack
->yytops
.yysize
-1;
1214 /** True iff Y0 and Y1 represent identical options at the top level.
1215 * That is, they represent the same rule applied to RHS symbols
1216 * that produce the same terminal symbols. */
1218 yyidenticalOptions (yySemanticOption
* yyy0
, yySemanticOption
* yyy1
)
1220 if (yyy0
->yyrule
== yyy1
->yyrule
)
1222 yyGLRState
*yys0
, *yys1
;
1224 for (yys0
= yyy0
->yystate
, yys1
= yyy1
->yystate
,
1225 yyn
= yyrhsLength (yyy0
->yyrule
);
1227 yys0
= yys0
->yypred
, yys1
= yys1
->yypred
, yyn
-= 1)
1228 if (yys0
->yyposn
!= yys1
->yyposn
)
1236 /** Assuming identicalOptions (Y0,Y1), (destructively) merge the
1237 * alternative semantic values for the RHS-symbols of Y1 into the
1238 * corresponding semantic value sets of the symbols of Y0. */
1240 yymergeOptionSets (yySemanticOption
* yyy0
, yySemanticOption
* yyy1
)
1242 yyGLRState
*yys0
, *yys1
;
1244 for (yys0
= yyy0
->yystate
, yys1
= yyy1
->yystate
,
1245 yyn
= yyrhsLength (yyy0
->yyrule
);
1247 yys0
= yys0
->yypred
, yys1
= yys1
->yypred
, yyn
-= 1)
1250 else if (! yys0
->yyresolved
&& ! yys1
->yyresolved
)
1252 yySemanticOption
* yyz
;
1253 for (yyz
= yys0
->yysemantics
.yyfirstVal
; yyz
->yynext
!= NULL
;
1256 yyz
->yynext
= yys1
->yysemantics
.yyfirstVal
;
1260 /** Y0 and Y1 represent two possible actions to take in a given
1261 * parsing state; return 0 if no combination is possible,
1262 * 1 if user-mergeable, 2 if Y0 is preferred, 3 if Y1 is preferred. */
1264 yypreference (yySemanticOption
* y0
, yySemanticOption
* y1
)
1266 yyRuleNum r0
= y0
->yyrule
, r1
= y1
->yyrule
;
1267 int p0
= yydprec
[r0
], p1
= yydprec
[r1
];
1271 if (yymerger
[r0
] == 0 || yymerger
[r0
] != yymerger
[r1
])
1276 if (p0
== 0 || p1
== 0)
1285 static YYRESULTTAG
yyresolveValue (yySemanticOption
* yyoptionList
,
1286 yyGLRStack
* yystack
, YYSTYPE
* yyvalp
,
1287 YYLTYPE
* yylocp
]b4_user_formals
[);
1290 yyresolveStates (yyGLRState
* yys
, int yyn
, yyGLRStack
* yystack
]b4_user_formals
[)
1295 assert (yys
->yypred
!= NULL
);
1296 yyflag
= yyresolveStates (yys
->yypred
, yyn
-1, yystack
]b4_user_args
[);
1299 if (! yys
->yyresolved
)
1301 yyflag
= yyresolveValue (yys
->yysemantics
.yyfirstVal
, yystack
,
1302 &yys
->yysemantics
.yysval
, &yys
->yyloc
1306 yys
->yyresolved
= yytrue
;
1313 yyresolveAction (yySemanticOption
* yyopt
, yyGLRStack
* yystack
,
1314 YYSTYPE
* yyvalp
, YYLTYPE
* yylocp
]b4_user_formals
[)
1316 yyGLRStackItem yyrhsVals
[YYMAXRHS
];
1320 yynrhs
= yyrhsLength (yyopt
->yyrule
);
1321 YYCHK (yyresolveStates (yyopt
->yystate
, yynrhs
, yystack
]b4_user_args
[));
1322 for (yyi
= yynrhs
-1, yys
= yyopt
->yystate
; 0 <= yyi
;
1323 yyi
-= 1, yys
= yys
->yypred
)
1325 assert (yys
->yypred
!= NULL
);
1326 yyrhsVals
[yyi
].yystate
.yyresolved
= yytrue
;
1327 yyrhsVals
[yyi
].yystate
.yysemantics
.yysval
= yys
->yysemantics
.yysval
;
1328 yyrhsVals
[yyi
].yystate
.yyloc
= yys
->yyloc
;
1330 return yyuserAction (yyopt
->yyrule
, yynrhs
, yyrhsVals
+ (yynrhs
-1),
1331 yyvalp
, yylocp
, yystack
]b4_user_args
[);
1336 yyreportTree (yySemanticOption
* yyx
, int yyindent
)
1338 int yynrhs
= yyrhsLength (yyx
->yyrule
);
1341 yyGLRState
* yystates
[YYMAXRHS
];
1342 yyGLRState yyleftmost_state
;
1344 for (yyi
= yynrhs
, yys
= yyx
->yystate
; 0 < yyi
; yyi
-= 1, yys
= yys
->yypred
)
1345 yystates
[yyi
] = yys
;
1348 yyleftmost_state
.yyposn
= 0;
1349 yystates
[0] = &yyleftmost_state
;
1354 if (yyx
->yystate
->yyposn
< yys
->yyposn
+ 1)
1355 YYFPRINTF (stderr
, "%*s%s -> <Rule %d, empty>\n",
1356 yyindent
, "", yytokenName (yylhsNonterm (yyx
->yyrule
)),
1359 YYFPRINTF (stderr
, "%*s%s -> <Rule %d, tokens %d .. %d>\n",
1360 yyindent
, "", yytokenName (yylhsNonterm (yyx
->yyrule
)),
1361 yyx
->yyrule
, yys
->yyposn
+1, yyx
->yystate
->yyposn
);
1362 for (yyi
= 1; yyi
<= yynrhs
; yyi
+= 1)
1364 if (yystates
[yyi
]->yyresolved
)
1366 if (yystates
[yyi
-1]->yyposn
+1 > yystates
[yyi
]->yyposn
)
1367 YYFPRINTF (stderr
, "%*s%s <empty>\n", yyindent
+2, "",
1368 yytokenName (yyrhs
[yyprhs
[yyx
->yyrule
]+yyi
-1]));
1370 YYFPRINTF (stderr
, "%*s%s <tokens %d .. %d>\n", yyindent
+2, "",
1371 yytokenName (yyrhs
[yyprhs
[yyx
->yyrule
]+yyi
-1]),
1372 yystates
[yyi
-1]->yyposn
+1, yystates
[yyi
]->yyposn
);
1375 yyreportTree (yystates
[yyi
]->yysemantics
.yyfirstVal
, yyindent
+2);
1381 yyreportAmbiguity (yySemanticOption
* yyx0
, yySemanticOption
* yyx1
,
1382 yyGLRStack
* yystack
]b4_pure_formals
[)
1384 /* `Unused' warnings. */
1389 YYFPRINTF (stderr
, "Ambiguity detected.\n");
1390 YYFPRINTF (stderr
, "Option 1,\n");
1391 yyreportTree (yyx0
, 2);
1392 YYFPRINTF (stderr
, "\nOption 2,\n");
1393 yyreportTree (yyx1
, 2);
1394 YYFPRINTF (stderr
, "\n");
1396 yyFail (yystack
][]b4_pure_args
[, "ambiguity detected");
1400 /** Resolve the ambiguity represented by OPTIONLIST, perform the indicated
1401 * actions, and return the result. */
1403 yyresolveValue (yySemanticOption
* yyoptionList
, yyGLRStack
* yystack
,
1404 YYSTYPE
* yyvalp
, YYLTYPE
* yylocp
]b4_user_formals
[)
1406 yySemanticOption
* yybest
;
1407 yySemanticOption
* yyp
;
1410 yybest
= yyoptionList
;
1412 for (yyp
= yyoptionList
->yynext
; yyp
!= NULL
; yyp
= yyp
->yynext
)
1414 if (yyidenticalOptions (yybest
, yyp
))
1415 yymergeOptionSets (yybest
, yyp
);
1417 switch (yypreference (yybest
, yyp
))
1420 yyreportAmbiguity (yybest
, yyp
, yystack
]b4_pure_args
[);
1436 int yyprec
= yydprec
[yybest
->yyrule
];
1437 YYCHK (yyresolveAction (yybest
, yystack
, yyvalp
, yylocp
]b4_user_args
[));
1438 for (yyp
= yybest
->yynext
; yyp
!= NULL
; yyp
= yyp
->yynext
)
1440 if (yyprec
== yydprec
[yyp
->yyrule
])
1444 YYCHK (yyresolveAction (yyp
, yystack
, &yyval1
, &yydummy
]b4_user_args
[));
1445 *yyvalp
= yyuserMerge (yymerger
[yyp
->yyrule
], yyvalp
, &yyval1
);
1451 return yyresolveAction (yybest
, yystack
, yyvalp
, yylocp
]b4_user_args
[);
1455 yyresolveStack (yyGLRStack
* yystack
]b4_user_formals
[)
1457 if (yystack
->yysplitPoint
!= NULL
)
1462 for (yyn
= 0, yys
= yystack
->yytops
.yystates
[0];
1463 yys
!= yystack
->yysplitPoint
;
1464 yys
= yys
->yypred
, yyn
+= 1)
1466 YYCHK (yyresolveStates (yystack
->yytops
.yystates
[0], yyn
, yystack
1473 yycompressStack (yyGLRStack
* yystack
)
1475 yyGLRState
* yyp
, *yyq
, *yyr
;
1477 if (yystack
->yytops
.yysize
!= 1 || yystack
->yysplitPoint
== NULL
)
1480 for (yyp
= yystack
->yytops
.yystates
[0], yyq
= yyp
->yypred
, yyr
= NULL
;
1481 yyp
!= yystack
->yysplitPoint
;
1482 yyr
= yyp
, yyp
= yyq
, yyq
= yyp
->yypred
)
1485 yystack
->yyspaceLeft
+= yystack
->yynextFree
- yystack
->yyitems
;
1486 yystack
->yynextFree
= ((yyGLRStackItem
*) yystack
->yysplitPoint
) + 1;
1487 yystack
->yyspaceLeft
-= yystack
->yynextFree
- yystack
->yyitems
;
1488 yystack
->yysplitPoint
= NULL
;
1489 yystack
->yylastDeleted
= NULL
;
1493 yystack
->yynextFree
->yystate
= *yyr
;
1495 yystack
->yynextFree
->yystate
.yypred
= & yystack
->yynextFree
[-1].yystate
;
1496 yystack
->yytops
.yystates
[0] = &yystack
->yynextFree
->yystate
;
1497 yystack
->yynextFree
+= 1;
1498 yystack
->yyspaceLeft
-= 1;
1503 yyprocessOneStack (yyGLRStack
* yystack
, int yyk
,
1504 size_t yyposn
, YYSTYPE
* yylvalp
, YYLTYPE
* yyllocp
1508 const short* yyconflicts
;
1510 yySymbol
* const yytokenp
= yystack
->yytokenp
;
1512 while (yystack
->yytops
.yystates
[yyk
] != NULL
)
1514 yyStateNum yystate
= yystack
->yytops
.yystates
[yyk
]->yylrState
;
1516 assert (yystate
!= YYFINAL
);
1517 if (yyisDefaultedState (yystate
))
1519 yyrule
= yydefaultAction (yystate
);
1522 YYDPRINTF ((stderr
, "Stack %d dies.\n", yyk
));
1523 yymarkStackDeleted (yystack
, yyk
);
1526 YYCHK (yyglrReduce (yystack
, yyk
, yyrule
, yyfalse
]b4_lpure_args
[));
1530 if (*yytokenp
== YYEMPTY
)
1532 YYDPRINTF ((stderr
, "Reading a token: "));
1534 *yytokenp
= YYTRANSLATE (yychar
);
1535 YYDSYMPRINTF ("Next token is", *yytokenp
, yylvalp
, yyllocp
);
1537 yygetLRActions (yystate
, *yytokenp
, &yyaction
, &yyconflicts
);
1539 while (*yyconflicts
!= 0)
1541 int yynewStack
= yysplitStack (yystack
, yyk
);
1542 YYDPRINTF ((stderr
, "Splitting off stack %d from %d.\n",
1544 YYCHK (yyglrReduce (yystack
, yynewStack
,
1545 *yyconflicts
, yyfalse
]b4_lpure_args
[));
1546 YYCHK (yyprocessOneStack (yystack
, yynewStack
, yyposn
,
1547 yylvalp
, yyllocp
]b4_user_args
[));
1551 if (yyisShiftAction (yyaction
))
1553 YYDPRINTF ((stderr
, "Shifting token %s on stack %d, ",
1554 yytokenName (*yytokenp
), yyk
));
1555 yyglrShift (yystack
, yyk
, yyaction
, yyposn
+1,
1556 *yylvalp
, yyllocp
]b4_user_args
[);
1557 YYDPRINTF ((stderr
, "which is now in state #%d\n",
1558 yystack
->yytops
.yystates
[yyk
]->yylrState
));
1561 else if (yyisErrorAction (yyaction
))
1563 YYDPRINTF ((stderr
, "Stack %d dies.\n", yyk
));
1564 yymarkStackDeleted (yystack
, yyk
);
1568 YYCHK (yyglrReduce (yystack
, yyk
, -yyaction
, yyfalse
]b4_lpure_args
[));
1575 yyreportParseError (yyGLRStack
* yystack
,
1576 YYSTYPE
* yylvalp
, YYLTYPE
* yyllocp
]b4_user_formals
[)
1578 /* `Unused' warnings. */
1582 if (yystack
->yyerrState
== 0)
1585 yySymbol
* const yytokenp
= yystack
->yytokenp
;
1586 int yyn
, yyx
, yycount
;
1588 const char* yyprefix
;
1591 yyn
= yypact
[yystack
->yytops
.yystates
[0]->yylrState
];
1592 if (YYPACT_NINF
< yyn
&& yyn
< YYLAST
)
1595 /* Start YYX at -YYN if negative to avoid negative indexes in
1597 yysize
= sizeof ("syntax error, unexpected ")
1598 + strlen (yytokenName (*yytokenp
));
1599 yyprefix
= ", expecting ";
1600 for (yyx
= yyn
< 0 ? -yyn
: 0; yyx
< yytname_size
&& yycount
<= 5;
1602 if (yycheck
[yyx
+ yyn
] == yyx
&& yyx
!= YYTERROR
)
1603 yysize
+= strlen (yytokenName (yyx
)) + strlen (yyprefix
),
1604 yycount
+= 1, yyprefix
= " or ";
1605 yymsg
= yyp
= (char*) malloc (yysize
);
1606 sprintf (yyp
, "syntax error, unexpected %s",
1607 yytokenName (*yytokenp
));
1608 yyp
+= strlen (yyp
);
1611 yyprefix
= ", expecting ";
1612 for (yyx
= yyn
< 0 ? -yyn
: 0; yyx
< yytname_size
; yyx
+= 1)
1613 if (yycheck
[yyx
+ yyn
] == yyx
&& yyx
!= YYTERROR
)
1615 sprintf (yyp
, "%s%s", yyprefix
, yytokenName (yyx
));
1616 yyp
+= strlen (yyp
);
1620 yyerror (]b4_lyyerror_args
[yymsg
);
1625 yyerror (]b4_lyyerror_args
["syntax error");
1630 /* Recover from a syntax error on YYSTACK, assuming that YYTOKENP,
1631 YYLVALP, and YYLLOCP point to the syntactic category, semantic
1632 value, and location of the lookahead. */
1634 yyrecoverParseError (yyGLRStack
* yystack
,
1635 YYSTYPE
* yylvalp
, YYLTYPE
* yyllocp
]b4_user_formals
[)
1637 yySymbol
* const yytokenp
= yystack
->yytokenp
;
1641 if (yystack
->yyerrState
== 0)
1642 yystack
->yyerrState
= 3;
1643 else if (yystack
->yyerrState
== 3)
1644 /* We just shifted the error token and (perhaps) took some
1645 reductions. Skip tokens until we can proceed. */
1648 if (*yytokenp
== YYEOF
)
1650 /* Now pop stack until we find a state that shifts the
1652 while (yystack
->yytops
.yystates
[0] != NULL
)
1654 yyGLRState
*yys
= yystack
->yytops
.yystates
[0];
1655 YYDSYMPRINTF ("Error: popping",
1656 yystos
[yys
->yylrState
],
1657 &yys
->yysemantics
.yysval
, &yys
->yyloc
);
1658 yydestruct (yystos
[yys
->yylrState
],
1659 &yys
->yysemantics
.yysval
]b4_location_if([, &yys
->yyloc
])[);
1660 yystack
->yytops
.yystates
[0] = yys
->yypred
;
1661 yystack
->yynextFree
-= 1;
1662 yystack
->yyspaceLeft
+= 1;
1664 yyFail (yystack
][]b4_lpure_args
[, NULL
);
1666 if (*yytokenp
!= YYEMPTY
)
1668 YYDSYMPRINTF ("Error: discarding", *yytokenp
, yylvalp
, yyllocp
);
1669 yydestruct (*yytokenp
, yylvalp
]b4_location_if([, yyllocp
])[);
1671 YYDPRINTF ((stderr
, "Reading a token: "));
1673 *yytokenp
= YYTRANSLATE (yychar
);
1674 YYDSYMPRINTF ("Next token is", *yytokenp
, yylvalp
, yyllocp
);
1675 yyj
= yypact
[yystack
->yytops
.yystates
[0]->yylrState
];
1676 if (yyis_pact_ninf (yyj
))
1677 /* Something's not right; we shouldn't be here. */
1678 yyFail (yystack
][]b4_lpure_args
[, NULL
);
1680 if (yyj
< 0 || YYLAST
< yyj
|| yycheck
[yyj
] != *yytokenp
)
1682 if (yydefact
[yystack
->yytops
.yystates
[0]->yylrState
] != 0)
1685 else if (yytable
[yyj
] != 0 && ! yyis_table_ninf (yytable
[yyj
]))
1689 /* Reduce to one stack. */
1690 for (yyk
= 0; yyk
< yystack
->yytops
.yysize
; yyk
+= 1)
1691 if (yystack
->yytops
.yystates
[yyk
] != NULL
)
1693 if (yyk
>= yystack
->yytops
.yysize
)
1694 yyFail (yystack
][]b4_lpure_args
[, NULL
);
1695 for (yyk
+= 1; yyk
< yystack
->yytops
.yysize
; yyk
+= 1)
1696 yymarkStackDeleted (yystack
, yyk
);
1697 yyremoveDeletes (yystack
);
1698 yycompressStack (yystack
);
1700 /* Now pop stack until we find a state that shifts the error token. */
1701 while (yystack
->yytops
.yystates
[0] != NULL
)
1703 yyGLRState
*yys
= yystack
->yytops
.yystates
[0];
1704 yyj
= yypact
[yys
->yylrState
];
1705 if (! yyis_pact_ninf (yyj
))
1708 if (0 <= yyj
&& yyj
<= YYLAST
&& yycheck
[yyj
] == YYTERROR
1709 && yyisShiftAction (yytable
[yyj
]))
1711 YYDPRINTF ((stderr
, "Shifting error token, "));
1712 yyglrShift (yystack
, 0, yytable
[yyj
],
1713 yys
->yyposn
, *yylvalp
, yyllocp
]b4_user_args
[);
1714 YYDPRINTF ((stderr
, "Entering state %d\n",
1715 yystack
->yytops
.yystates
[0]->yylrState
));
1719 YYDSYMPRINTF ("Error: popping",
1720 yystos
[yys
->yylrState
],
1721 &yys
->yysemantics
.yysval
, &yys
->yyloc
);
1722 yydestruct (yystos
[yys
->yylrState
],
1723 &yys
->yysemantics
.yysval
]b4_location_if([, &yys
->yyloc
])[);
1724 yystack
->yytops
.yystates
[0] = yys
->yypred
;
1725 yystack
->yynextFree
-= 1;
1726 yystack
->yyspaceLeft
+= 1;
1728 if (yystack
->yytops
.yystates
[0] == NULL
)
1729 yyFail (yystack
][]b4_lpure_args
[, NULL
);
1732 #define YYCHK1(YYE) \
1738 yystack.yyerrflag = 1; \
1741 yystack.yyerrflag = 0; \
1744 goto yyuser_error; \
1753 ]b4_c_ansi_function_def([yyparse
], [int], b4_parse_param
)[
1763 #define yychar (yystack.yyrawchar)
1766 YYSTYPE
* const yylvalp
= &yylval
;
1767 YYLTYPE
* const yyllocp
= &yylloc
;
1769 yyinitGLRStack (&yystack
, YYINITDEPTH
);
1770 yystack
.yytokenp
= &yytoken
;
1772 YYDPRINTF ((stderr
, "Starting parse\n"));
1774 if (setjmp (yystack
.yyexception_buffer
) != 0)
1777 yyglrShift (&yystack
, 0, 0, 0, yyval_default
, &yyloc_default
]b4_user_args
[);
1783 /* For efficiency, we have two loops, the first of which is
1784 specialized to deterministic operation (single stack, no
1785 potential ambiguity). */
1792 const short* yyconflicts
;
1794 yyStateNum yystate
= yystack
.yytops
.yystates
[0]->yylrState
;
1795 if (yystate
== YYFINAL
)
1797 if (yyisDefaultedState (yystate
))
1799 yyrule
= yydefaultAction (yystate
);
1802 yyreportParseError (&yystack
, yylvalp
, yyllocp
]b4_user_args
[);
1805 YYCHK1 (yyglrReduce (&yystack
, 0, yyrule
, yytrue
]b4_lpure_args
[));
1809 if (yytoken
== YYEMPTY
)
1811 YYDPRINTF ((stderr
, "Reading a token: "));
1813 yytoken
= YYTRANSLATE (yychar
);
1814 YYDSYMPRINTF ("Next token is", yytoken
, yylvalp
, yyllocp
);
1816 yygetLRActions (yystate
, yytoken
, &yyaction
, &yyconflicts
);
1817 if (*yyconflicts
!= 0)
1819 if (yyisShiftAction (yyaction
))
1821 YYDPRINTF ((stderr
, "Shifting token %s, ",
1822 yytokenName (yytoken
)));
1823 if (yytoken
!= YYEOF
)
1826 yyglrShift (&yystack
, 0, yyaction
, yyposn
,
1827 yylval
, yyllocp
]b4_user_args
[);
1828 if (0 < yystack
.yyerrState
)
1829 yystack
.yyerrState
-= 1;
1830 YYDPRINTF ((stderr
, "Entering state %d\n",
1831 yystack
.yytops
.yystates
[0]->yylrState
));
1833 else if (yyisErrorAction (yyaction
))
1835 yyreportParseError (&yystack
, yylvalp
, yyllocp
]b4_user_args
[);
1839 YYCHK1 (yyglrReduce (&yystack
, 0, -yyaction
, yytrue
]b4_lpure_args
[));
1846 int yyn
= yystack
.yytops
.yysize
;
1847 for (yys
= 0; yys
< yyn
; yys
+= 1)
1848 YYCHK1 (yyprocessOneStack (&yystack
, yys
, yyposn
,
1849 yylvalp
, yyllocp
]b4_user_args
[));
1852 yyremoveDeletes (&yystack
);
1853 if (yystack
.yytops
.yysize
== 0)
1855 yyundeleteLastStack (&yystack
);
1856 if (yystack
.yytops
.yysize
== 0)
1857 yyFail (&yystack
][]b4_lpure_args
[, "syntax error");
1858 YYCHK1 (yyresolveStack (&yystack
]b4_user_args
[));
1859 YYDPRINTF ((stderr
, "Returning to deterministic operation.\n"));
1860 yyreportParseError (&yystack
, yylvalp
, yyllocp
]b4_user_args
[);
1863 else if (yystack
.yytops
.yysize
== 1)
1865 YYCHK1 (yyresolveStack (&yystack
]b4_user_args
[));
1866 YYDPRINTF ((stderr
, "Returning to deterministic operation.\n"));
1867 yycompressStack (&yystack
);
1873 yyrecoverParseError (&yystack
, yylvalp
, yyllocp
]b4_user_args
[);
1874 yyposn
= yystack
.yytops
.yystates
[0]->yyposn
;
1879 yyfreeGLRStack (&yystack
);
1880 return yystack
.yyerrflag
;
1883 /* DEBUGGING ONLY */
1884 static void yypstack (yyGLRStack
* yystack
, int yyk
) ATTRIBUTE_UNUSED
;
1885 static void yypdumpstack (yyGLRStack
* yystack
) ATTRIBUTE_UNUSED
;
1888 yy_yypstack (yyGLRState
* yys
)
1892 yy_yypstack (yys
->yypred
);
1893 fprintf (stderr
, " -> ");
1895 fprintf (stderr
, "%d@@%lu", yys
->yylrState
, (unsigned long) yys
->yyposn
);
1899 yypstates (yyGLRState
* yyst
)
1902 fprintf (stderr
, "<null>");
1905 fprintf (stderr
, "\n");
1909 yypstack (yyGLRStack
* yystack
, int yyk
)
1911 yypstates (yystack
->yytops
.yystates
[yyk
]);
1914 #define YYINDEX(YYX) \
1915 ((YYX) == NULL ? -1 : (yyGLRStackItem*) (YYX) - yystack->yyitems)
1919 yypdumpstack (yyGLRStack
* yystack
)
1921 yyGLRStackItem
* yyp
;
1923 for (yyp
= yystack
->yyitems
; yyp
< yystack
->yynextFree
; yyp
+= 1)
1925 fprintf (stderr
, "%3lu. ", (unsigned long) (yyp
- yystack
->yyitems
));
1928 fprintf (stderr
, "Res: %d, LR State: %d, posn: %lu, pred: %ld",
1929 yyp
->yystate
.yyresolved
, yyp
->yystate
.yylrState
,
1930 (unsigned long) yyp
->yystate
.yyposn
,
1931 (long) YYINDEX (yyp
->yystate
.yypred
));
1932 if (! yyp
->yystate
.yyresolved
)
1933 fprintf (stderr
, ", firstVal: %ld",
1934 (long) YYINDEX (yyp
->yystate
.yysemantics
.yyfirstVal
));
1938 fprintf (stderr
, "Option. rule: %d, state: %ld, next: %ld",
1939 yyp
->yyoption
.yyrule
,
1940 (long) YYINDEX (yyp
->yyoption
.yystate
),
1941 (long) YYINDEX (yyp
->yyoption
.yynext
));
1943 fprintf (stderr
, "\n");
1945 fprintf (stderr
, "Tops:");
1946 for (yyi
= 0; yyi
< yystack
->yytops
.yysize
; yyi
+= 1)
1947 fprintf (stderr
, "%lu: %ld; ", (unsigned long) yyi
,
1948 (long) YYINDEX (yystack
->yytops
.yystates
[yyi
]));
1949 fprintf (stderr
, "\n");
1954 m4_if(b4_defines_flag
, 0, [],
1955 [@output @output_header_name@
1956 b4_copyright([Skeleton parser
for GLR parsing with Bison
], [2002])
1958 b4_token_defines(b4_tokens
)
1961 m4_ifdef([b4_stype
],
1962 [b4_syncline([b4_stype_line
], [b4_filename
])
1963 typedef union b4_stype yystype
;
1964 /* Line __line__ of __file__. */
1965 b4_syncline([@oline@
], [@ofile@
])],
1966 [typedef int yystype
;])
1967 # define YYSTYPE yystype
1968 # define YYSTYPE_IS_TRIVIAL 1
1972 [extern YYSTYPE b4_prefix
[]lval
;])
1976 typedef struct yyltype
1983 # define YYLTYPE yyltype
1987 [extern YYLTYPE b4_prefix
[]lloc
;])