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
])
34 # Accumule in b4_lex_param all the yylex arguments.
35 # Yes, this is quite ugly...
36 m4_define([b4_lex_param
],
37 m4_dquote(b4_pure_if([[[[YYSTYPE
*]], [[yylvalp]]][]dnl
38 b4_location_if([, [[YYLTYPE
*], [yyllocp
]]])])dnl
39 m4_ifdef([b4_lex_param
], [, ]b4_lex_param
)))
41 # Yes, this is quite ugly...
42 m4_define_default([b4_parse_param
])
43 m4_ifdef([b4_parse_param
],
44 [m4_define([b4_parse_param
],
49 ## ----------------- ##
50 ## Semantic Values. ##
51 ## ----------------- ##
54 # b4_lhs_value([TYPE])
55 # --------------------
56 # Expansion of $<TYPE>$.
57 m4_define([b4_lhs_value
],
58 [(*yyvalp
)[]m4_ifval([$
1], [.$
1])])
61 # b4_rhs_value(RULE-LENGTH, NUM, [TYPE])
62 # --------------------------------------
63 # Expansion of $<TYPE>NUM, where the current rule has RULE-LENGTH
65 m4_define([b4_rhs_value
],
66 [yyvsp@
<:@
m4_eval([$
2 - $
1])@
:>@
.yystate
.yysemantics
.yysval
[]m4_ifval([$
3], [.$
3])])
77 m4_define([b4_lhs_location
],
81 # b4_rhs_location(RULE-LENGTH, NUM)
82 # ---------------------------------
83 # Expansion of @NUM, where the current rule has RULE-LENGTH symbols
85 m4_define([b4_rhs_location
],
86 [yyvsp@
<:@
m4_eval([$
2 - $
1])@
:>@
.yystate
.yyloc
])
90 ## ------------------- ##
91 ## Output file names. ##
92 ## ------------------- ##
94 m4_define_default([b4_input_suffix
], [.y
])
96 m4_define_default([b4_output_parser_suffix
],
97 [m4_translit(b4_input_suffix
, [yY
], [cC
])])
99 m4_define_default([b4_output_parser_name
],
100 [b4_output_prefix
[]b4_output_infix
[]b4_output_parser_suffix
[]])
103 m4_define_default([b4_output_header_suffix
],
104 [m4_translit(b4_input_suffix
, [yY
], [hH
])])
106 m4_define_default([b4_output_header_name
],
107 [b4_output_prefix
[]b4_output_infix
[]b4_output_header_suffix
[]])
109 m4_define_default([b4_header_guard
],
110 [m4_bpatsubst(m4_toupper([BISON_
]b4_output_header_name
),
111 [[^ABCDEFGHIJKLMNOPQRSTUVWXYZ
]], [_
])])
114 # We do want M4 expansion after # for CPP macros.
117 #output "b4_output_parser_name"
118 b4_copyright([Skeleton parser
for GLR parsing with Bison
], [2002])
120 /* This is the parser code for GLR (Generalized LR) parser. */
122 /* FIXME: minimize these */
130 /* Identify Bison output. */
134 #define YYPURE ]b4_pure[
136 /* Using locations. */
137 #define YYLSP_NEEDED ]b4_locations_flag[
139 ]m4_if(b4_prefix
[], [yy
], [],
140 [/* If NAME_PREFIX is specified substitute the variables and functions
142 #define yyparse b4_prefix[]parse
143 #define yylex b4_prefix[]lex
144 #define yyerror b4_prefix[]error
145 #define yylval b4_prefix[]lval
146 #define yychar b4_prefix[]char
147 #define yydebug b4_prefix[]debug
148 #define yynerrs b4_prefix[]nerrs
149 b4_location_if([#define yylloc b4_prefix[]lloc])])
151 b4_token_defines(b4_tokens
)
153 /* Copy the first part of user declarations. */
156 /* Enabling traces. */
158 # define YYDEBUG ]b4_debug[
161 /* Enabling verbose error messages. */
162 #ifdef YYERROR_VERBOSE
163 # undef YYERROR_VERBOSE
164 # define YYERROR_VERBOSE 1
166 # define YYERROR_VERBOSE ]b4_error_verbose[
170 ]m4_ifdef([b4_stype
],
171 [#line b4_stype_line "b4_filename"
172 typedef union b4_stype yystype
;
173 /* Line __line__ of __file__. */
174 #line __oline__ "__ofile__"],
175 [typedef int yystype
;])[
176 # define YYSTYPE yystype
177 # define YYSTYPE_IS_TRIVIAL 1
181 typedef struct yyltype
188 # define YYLTYPE ]b4_location_type[
189 # define YYLTYPE_IS_TRIVIAL 1
192 /* Default (constant) values used for initialization for null
193 right-hand sides. Unlike the standard bison.simple template,
194 here we set the default values of the $$ and $@ to zeroed-out
195 values. Since the default value of these quantities is undefined,
196 this behavior is technically correct. */
197 static YYSTYPE yyval_default
;
198 static YYLTYPE yyloc_default
;
200 /* Copy the second part of user declarations. */
203 ]/* Line __line__ of __file__. */
204 #line __oline__ "__ofile__"
206 #if ! defined (__cplusplus)
216 #ifndef __attribute__
217 /* This feature is available in gcc versions 2.5 and later. */
218 # if !defined (__GNUC__) || __GNUC__ < 2 || \
219 (__GNUC__ == 2 && __GNUC_MINOR__ < 5) || __STRICT_ANSI__
220 # define __attribute__(Spec) /* empty */
224 #ifndef ATTRIBUTE_UNUSED
225 # define ATTRIBUTE_UNUSED __attribute__ ((__unused__))
228 #if ! defined (__GNUC__)
232 /* YYFINAL -- State number of the termination state. */
233 #define YYFINAL ]b4_final_state_number[
234 /* YYLAST -- Last index in YYTABLE. */
235 #define YYLAST ]b4_last[
237 /* YYNTOKENS -- Number of terminals. */
238 #define YYNTOKENS ]b4_tokens_number[
239 /* YYNNTS -- Number of nonterminals. */
240 #define YYNNTS ]b4_nterms_number[
241 /* YYNRULES -- Number of rules. */
242 #define YYNRULES ]b4_rules_number[
243 /* YYNRULES -- Number of states. */
244 #define YYNSTATES ]b4_states_number[
245 /* YYMAXRHS -- Maximum number of symbols on right-hand side of rule. */
246 #define YYMAXRHS ]b4_r2_max[
248 /* YYTRANSLATE(X) -- Bison symbol number corresponding to X. */
249 #define YYUNDEFTOK ]b4_undef_token_number[
250 #define YYMAXUTOK ]b4_user_token_number_max[
252 #define YYTRANSLATE(YYX) \
253 ((unsigned)(YYX) <= YYMAXUTOK ? yytranslate[YYX] : YYUNDEFTOK)
255 /* YYTRANSLATE[YYLEX] -- Bison symbol number corresponding to YYLEX. */
256 static const ]b4_int_type_for([b4_translate
])[ yytranslate
[] =
262 /* YYPRHS[YYN] -- Index of the first RHS symbol of rule number YYN in
264 static const ]b4_int_type_for([b4_prhs
])[ yyprhs
[] =
269 /* YYRHS -- A `-1'-separated list of the rules' RHS. */
270 static const ]b4_int_type_for([b4_rhs
])[ yyrhs
[] =
275 /* YYRLINE[YYN] -- source line where rule number YYN was defined. */
276 static const ]b4_int_type_for([b4_rline
])[ yyrline
[] =
282 #if (YYDEBUG) || YYERROR_VERBOSE
283 /* YYTNME[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM.
284 First, the terminals, then, starting at YYNTOKENS, nonterminals. */
285 static const char *const yytname
[] =
290 #define yytname_size ((int) (sizeof (yytname) / sizeof (yytname[0])))
293 /* YYR1[YYN] -- Symbol number of symbol that rule YYN derives. */
294 static const ]b4_int_type_for([b4_r1
])[ yyr1
[] =
299 /* YYR2[YYN] -- Number of symbols composing right hand side of rule YYN. */
300 static const ]b4_int_type_for([b4_r2
])[ yyr2
[] =
305 /* YYDPREC[RULE-NUM] -- Dynamic precedence of rule #RULE-NUM (0 if none). */
306 static const ]b4_int_type_for([b4_dprec
])[ yydprec
[] =
311 /* YYMERGER[RULE-NUM] -- Index of merging function for rule #RULE-NUM. */
312 static const ]b4_int_type_for([b4_merger
])[ yymerger
[] =
317 /* YYDEFACT[S] -- default rule to reduce with in state S when YYTABLE
318 doesn't specify something else to do. Zero means the default is an
320 static const ]b4_int_type_for([b4_defact
])[ yydefact
[] =
325 /* YYPDEFGOTO[NTERM-NUM]. */
326 static const ]b4_int_type_for([b4_defgoto
])[ yydefgoto
[] =
331 /* YYPACT[STATE-NUM] -- Index in YYTABLE of the portion describing
333 #define YYPACT_NINF ]b4_pact_ninf[
334 static const ]b4_int_type_for([b4_pact
])[ yypact
[] =
339 /* YYPGOTO[NTERM-NUM]. */
340 static const ]b4_int_type_for([b4_pgoto
])[ yypgoto
[] =
345 /* YYTABLE[YYPACT[STATE-NUM]]. What to do in state STATE-NUM. If
346 positive, shift that token. If negative, reduce the rule which
347 number is the opposite. If zero, do what YYDEFACT says.
348 If YYTABLE_NINF, parse error. */
349 #define YYTABLE_NINF ]b4_table_ninf[
350 static const ]b4_int_type_for([b4_table
])[ yytable
[] =
355 /* YYCONFLP[YYPACT[STATE-NUM]] -- Pointer into YYCONFL of start of
356 list of conflicting reductions corresponding to action entry for
357 state STATE-NUM in yytable. 0 means no conflicts. The list in
358 yyconfl is terminated by a rule number of 0. */
359 static const ]b4_int_type_for([b4_conflict_list_heads
])[ yyconflp
[] =
361 ]b4_conflict_list_heads
[
364 /* YYCONFL[I] -- lists of conflicting rule numbers, each terminated by
365 0, pointed into by YYCONFLP. */
366 ]dnl Do
not use b4_int_type_for here
, since there are places where
367 dnl pointers onto yyconfl are taken
, which type is
"short *".
368 dnl We probably ought to introduce a type
for confl
.
369 [static const short yyconfl
[] =
371 ]b4_conflicting_rules
[
374 static const ]b4_int_type_for([b4_check
])[ yycheck
[] =
380 /* Prevent warning if -Wmissing-prototypes. */
381 ]b4_c_ansi_function_decl([yyparse
], [int], b4_parse_param
)
383 m4_ifset([b4_parse_param
],
384 [#define YY_USER_FORMALS , b4_c_ansi_formals(b4_parse_param)
385 #define YY_USER_ARGS , b4_c_args(b4_parse_param)],
386 [#define YY_USER_FORMALS
387 #define YY_USER_ARGS])
390 [/* Error token number */
393 /* YYLLOC_DEFAULT -- Compute the default location (before the actions
396 #define YYRHSLOC(yyRhs,YYK) (yyRhs[YYK].yystate.yyloc)
398 #ifndef YYLLOC_DEFAULT
399 # define YYLLOC_DEFAULT(yyCurrent, yyRhs, YYN) \
400 yyCurrent.first_line = YYRHSLOC(yyRhs,1).first_line; \
401 yyCurrent.first_column = YYRHSLOC(yyRhs,1).first_column; \
402 yyCurrent.last_line = YYRHSLOC(yyRhs,YYN).last_line; \
403 yyCurrent.last_column = YYRHSLOC(yyRhs,YYN).last_column;
406 /* YYLEX -- calling `yylex' with the right arguments. */
407 #define YYLEX ]b4_c_function_call([yylex], [int], b4_lex_param)[
412 #define yynerrs (yystack->yyerrcnt)
414 #define yychar (yystack->yyrawchar)],
422 static const int YYEOF
= 0;
423 static const int YYEMPTY
= -2;
425 typedef enum { yyok
, yyaccept
, yyabort
, yyerr
} YYRESULTTAG
;
428 do { YYRESULTTAG yyflag = YYE; if (yyflag != yyok) return yyflag; } \
433 #if ! defined (YYFPRINTF)
434 # define YYFPRINTF fprintf
437 # define YYDPRINTF(Args) \
442 /* Nonzero means print parse trace. It is left uninitialized so that
443 multiple parsers can coexist. */
446 /* Avoid empty `if' bodies. */
447 # define YYDPRINTF(Args) {}
448 #endif /* !YYDEBUG */
450 /* YYINITDEPTH -- initial size of the parser's stacks. */
452 # define YYINITDEPTH ]b4_stack_depth_init[
455 /* YYMAXDEPTH -- maximum size the stacks can grow to (effective only
456 if the built-in stack extension method is used).
458 Do not make this value too large; the results are undefined if
459 SIZE_MAX < YYMAXDEPTH * sizeof (GLRStackItem)
460 evaluated with infinite-precision integer arithmetic. */
467 # define YYMAXDEPTH ]b4_stack_depth_max[
470 /* Minimum number of free items on the stack allowed after an
471 allocation. This is to allow allocation and initialization
472 to be completed by functions that call expandGLRStack before the
473 stack is expanded, thus insuring that all necessary pointers get
474 properly redirected to new data. */
477 #if ! defined (YYSTACKEXPANDABLE) \
478 && (! defined (__cplusplus) || (YYLTYPE_IS_TRIVIAL && YYSTYPE_IS_TRIVIAL))
479 #define YYSTACKEXPANDABLE 1
481 #define YYSTACKEXPANDABLE 0
484 /** State numbers, as in LALR(1) machine */
485 typedef int yyStateNum
;
487 /** Rule numbers, as in LALR(1) machine */
488 typedef int yyRuleNum
;
490 /** Grammar symbol */
491 typedef short yySymbol
;
493 /** Item references, as in LALR(1) machine */
494 typedef short yyItemNum
;
496 typedef struct yyGLRState yyGLRState
;
497 typedef struct yySemanticOption yySemanticOption
;
498 typedef union yyGLRStackItem yyGLRStackItem
;
499 typedef struct yyGLRStack yyGLRStack
;
500 typedef struct yyGLRStateSet yyGLRStateSet
;
505 yyStateNum yylrState
;
509 yySemanticOption
* yyfirstVal
;
515 struct yyGLRStateSet
{
516 yyGLRState
** yystates
;
517 size_t yysize
, yycapacity
;
520 struct yySemanticOption
{
524 yySemanticOption
* yynext
;
527 union yyGLRStackItem
{
529 yySemanticOption yyoption
;
541 jmp_buf yyexception_buffer
;
542 yyGLRStackItem
* yyitems
;
543 yyGLRStackItem
* yynextFree
;
545 yyGLRState
* yysplitPoint
;
546 yyGLRState
* yylastDeleted
;
547 yyGLRStateSet yytops
;
550 static void yyinitGLRStack (yyGLRStack
* yystack
, size_t yysize
);
551 static void yyexpandGLRStack (yyGLRStack
* yystack
);
552 static void yyfreeGLRStack (yyGLRStack
* yystack
);
555 yyFail (yyGLRStack
* yystack
, const char* yyformat
, ...)
557 if (yyformat
!= NULL
)
561 va_start (yyap
, yyformat
);
562 yystack
->yyerrflag
= 1;
563 vsprintf (yymsg
, yyformat
, yyap
);
566 longjmp (yystack
->yyexception_buffer
, 1);
569 #if YYDEBUG || YYERROR_VERBOSE
570 /** A printable representation of TOKEN. Valid until next call to
572 static inline const char*
573 yytokenName (yySymbol yytoken
)
575 return yytname
[yytoken
];
579 /** Perform user action for rule number YYN, with RHS length YYRHSLEN,
580 * and top stack item YYVSP. YYLVALP points to place to put semantic
581 * value ($$), and yylocp points to place for location information
582 * (@$). Returns yyok for normal return, yyaccept for YYACCEPT,
583 * yyerr for YYERROR, yyabort for YYABORT. */
585 yyuserAction (yyRuleNum yyn
, int yyrhslen
, yyGLRStackItem
* yyvsp
,
586 YYSTYPE
* yyvalp
, YYLTYPE
* yylocp
, yyGLRStack
* yystack
589 /* Avoid `unused' warnings in there are no $n. */
594 *yyvalp
= yyval_default
;
595 *yylocp
= yyloc_default
;
599 *yyvalp
= yyvsp
[1-yyrhslen
].yystate
.yysemantics
.yysval
;
600 *yylocp
= yyvsp
[1-yyrhslen
].yystate
.yyloc
;
603 # define yyval (*yyvalp)
605 # define yyerrok (yystack->yyerrState = 0)
607 # define YYACCEPT return yyaccept
609 # define YYABORT return yyabort
611 # define YYERROR return yyerr
613 # define YYRECOVERING (yystack->yyerrState != 0)
615 # define yyclearin (yychar = *(yystack->yytokenp) = YYEMPTY)
617 # define YYBACKUP(Token, Value) \
619 yyerror ("syntax error: cannot back up"); \
638 /* Line __line__ of __file__. */
639 #line __oline__ "__ofile__"
644 yyuserMerge (int yyn
, YYSTYPE
* yy0
, YYSTYPE
* yy1
)
646 YYSTYPE yyval
= *yy0
;
647 /* `Use' the arguments. */
658 /* Bison grammar-table manipulation */
660 /** Number of symbols composing the right hand side of rule #RULE. */
662 yyrhsLength (yyRuleNum yyrule
)
667 /** Left-hand-side symbol for rule #RULE. */
668 static inline yySymbol
669 yylhsNonterm (yyRuleNum yyrule
)
674 /** True iff LR state STATE has only a default reduction (regardless
677 yyisDefaultedState (yyStateNum yystate
)
679 return yypact
[yystate
] == YYPACT_NINF
;
682 /** The default reduction for STATE, assuming it has one. */
683 static inline yyRuleNum
684 yydefaultAction (yyStateNum yystate
)
686 return yydefact
[yystate
];
689 /** Set *YYACTION to the action to take in YYSTATE on seeing YYTOKEN.
691 * R < 0: Reduce on rule -R.
693 * R > 0: Shift to state R.
694 * Set *CONFLICTS to a pointer into yyconfl to 0-terminated list of
695 * conflicting reductions.
698 yygetLRActions (yyStateNum yystate
, int yytoken
,
699 int* yyaction
, const short** yyconflicts
)
701 int yyindex
= yypact
[yystate
] + yytoken
;
702 if (yyindex
< 0 || YYLAST
< yyindex
|| yycheck
[yyindex
] != yytoken
)
704 *yyaction
= -yydefact
[yystate
];
705 *yyconflicts
= yyconfl
;
707 else if (yytable
[yyindex
] != YYTABLE_NINF
)
709 *yyaction
= yytable
[yyindex
];
710 *yyconflicts
= yyconfl
+ yyconflp
[yyindex
];
715 *yyconflicts
= yyconfl
+ yyconflp
[yyindex
];
719 static inline yyStateNum
720 yyLRgotoState (yyStateNum yystate
, yySymbol yylhs
)
723 yyr
= yypgoto
[yylhs
- YYNTOKENS
] + yystate
;
724 if (0 <= yyr
&& yyr
<= YYLAST
&& yycheck
[yyr
] == yystate
)
727 return yydefgoto
[yylhs
- YYNTOKENS
];
731 yyisShiftAction (int yyaction
)
737 yyisErrorAction (int yyaction
)
739 return yyaction
== 0;
744 /** True iff the semantic value of the edge leading to STATE is
747 yyhasResolvedValue (yyGLRState
* yystate
)
749 return yystate
->yyresolved
;
753 yyaddDeferredAction (yyGLRStack
* yystack
, yyGLRState
* yystate
,
754 yyGLRState
* rhs
, yyRuleNum yyrule
)
756 yySemanticOption
* yynewItem
;
757 yynewItem
= &yystack
->yynextFree
->yyoption
;
758 yystack
->yyspaceLeft
-= 1;
759 yystack
->yynextFree
+= 1;
760 yynewItem
->yyisState
= yyfalse
;
761 yynewItem
->yystate
= rhs
;
762 yynewItem
->yyrule
= yyrule
;
763 yynewItem
->yynext
= yystate
->yysemantics
.yyfirstVal
;
764 yystate
->yysemantics
.yyfirstVal
= yynewItem
;
765 if (yystack
->yyspaceLeft
< YYHEADROOM
)
766 yyexpandGLRStack (yystack
);
771 /** Initialize SET to a singleton set containing an empty stack. */
773 yyinitStateSet (yyGLRStateSet
* yyset
)
776 yyset
->yycapacity
= 16;
777 yyset
->yystates
= (yyGLRState
**) malloc (16 * sizeof (yyset
->yystates
[0]));
778 yyset
->yystates
[0] = NULL
;
781 static void yyfreeStateSet (yyGLRStateSet
* yyset
)
783 free (yyset
->yystates
);
786 /** Initialize STACK to a single empty stack, with total maximum
787 * capacity for all stacks of SIZE. */
789 yyinitGLRStack (yyGLRStack
* yystack
, size_t yysize
)
791 yystack
->yyerrflag
= 0;
792 yystack
->yyerrState
= 0;
794 yystack
->yyspaceLeft
= yysize
;
795 yystack
->yynextFree
= yystack
->yyitems
=
796 (yyGLRStackItem
*) malloc (yysize
* sizeof (yystack
->yynextFree
[0]));
797 yystack
->yysplitPoint
= NULL
;
798 yystack
->yylastDeleted
= NULL
;
799 yyinitStateSet (&yystack
->yytops
);
802 #define YYRELOC(YYFROMITEMS,YYTOITEMS,YYX,YYTYPE) \
803 &((YYTOITEMS) - ((YYFROMITEMS) - (yyGLRStackItem*) (YYX)))->YYTYPE
805 /** If STACK is expandable, extend it. WARNING: Pointers into the
806 stack from outside should be considered invalid after this call.
807 We always expand when there are 1 or fewer items left AFTER an
808 allocation, so that we can avoid having external pointers exist
809 across an allocation. */
811 yyexpandGLRStack (yyGLRStack
* yystack
)
813 #if YYSTACKEXPANDABLE
814 yyGLRStack yynewStack
;
815 yyGLRStackItem
* yyp0
, *yyp1
;
816 size_t yysize
, yynewSize
;
818 yysize
= yystack
->yynextFree
- yystack
->yyitems
;
819 if (YYMAXDEPTH
<= yysize
)
820 yyFail (yystack
, "parsing stack overflow (%d items)", yysize
);
821 yynewSize
= 2*yysize
;
822 if (YYMAXDEPTH
< yynewSize
)
823 yynewSize
= YYMAXDEPTH
;
824 yyinitGLRStack (&yynewStack
, yynewSize
);
825 for (yyp0
= yystack
->yyitems
, yyp1
= yynewStack
.yyitems
, yyn
= yysize
;
827 yyn
-= 1, yyp0
+= 1, yyp1
+= 1)
832 yyGLRState
* yys0
= &yyp0
->yystate
;
833 yyGLRState
* yys1
= &yyp1
->yystate
;
834 if (yys0
->yypred
!= NULL
)
836 YYRELOC (yyp0
, yyp1
, yys0
->yypred
, yystate
);
837 if (! yys0
->yyresolved
&& yys0
->yysemantics
.yyfirstVal
!= NULL
)
838 yys1
->yysemantics
.yyfirstVal
=
839 YYRELOC(yyp0
, yyp1
, yys0
->yysemantics
.yyfirstVal
, yyoption
);
843 yySemanticOption
* yyv0
= &yyp0
->yyoption
;
844 yySemanticOption
* yyv1
= &yyp1
->yyoption
;
845 if (yyv0
->yystate
!= NULL
)
846 yyv1
->yystate
= YYRELOC (yyp0
, yyp1
, yyv0
->yystate
, yystate
);
847 if (yyv0
->yynext
!= NULL
)
848 yyv1
->yynext
= YYRELOC (yyp0
, yyp1
, yyv0
->yynext
, yyoption
);
851 if (yystack
->yysplitPoint
!= NULL
)
852 yystack
->yysplitPoint
= YYRELOC (yystack
->yyitems
, yynewStack
.yyitems
,
853 yystack
->yysplitPoint
, yystate
);
855 for (yyn
= 0; yyn
< yystack
->yytops
.yysize
; yyn
+= 1)
856 if (yystack
->yytops
.yystates
[yyn
] != NULL
)
857 yystack
->yytops
.yystates
[yyn
] =
858 YYRELOC (yystack
->yyitems
, yynewStack
.yyitems
,
859 yystack
->yytops
.yystates
[yyn
], yystate
);
860 free (yystack
->yyitems
);
861 yystack
->yyitems
= yynewStack
.yyitems
;
862 yystack
->yynextFree
= yynewStack
.yynextFree
+ yysize
;
863 yystack
->yyspaceLeft
= yynewStack
.yyspaceLeft
- yysize
;
867 yyFail (yystack
, "parsing stack overflow (%d items)", yysize
);
873 yyfreeGLRStack (yyGLRStack
* yystack
)
875 free (yystack
->yyitems
);
876 yyfreeStateSet (&yystack
->yytops
);
879 /** Assuming that S is a GLRState somewhere on STACK, update the
880 * splitpoint of STACK, if needed, so that it is at least as deep as
883 yyupdateSplit (yyGLRStack
* yystack
, yyGLRState
* yys
)
885 if (yystack
->yysplitPoint
!= NULL
&& yystack
->yysplitPoint
> yys
)
886 yystack
->yysplitPoint
= yys
;
889 /** Invalidate stack #K in STACK. */
891 yymarkStackDeleted (yyGLRStack
* yystack
, int yyk
)
893 if (yystack
->yytops
.yystates
[yyk
] != NULL
)
894 yystack
->yylastDeleted
= yystack
->yytops
.yystates
[yyk
];
895 yystack
->yytops
.yystates
[yyk
] = NULL
;
898 /** Undelete the last stack that was marked as deleted. Can only be
899 done once after a deletion, and only when all other stacks have
902 yyundeleteLastStack (yyGLRStack
* yystack
)
904 if (yystack
->yylastDeleted
== NULL
|| yystack
->yytops
.yysize
!= 0)
906 yystack
->yytops
.yystates
[0] = yystack
->yylastDeleted
;
907 yystack
->yytops
.yysize
= 1;
908 YYDPRINTF ((stderr
, "Restoring last deleted stack as stack #0.\n"));
909 yystack
->yylastDeleted
= NULL
;
913 yyremoveDeletes (yyGLRStack
* yystack
)
917 while (yyj
< yystack
->yytops
.yysize
)
919 if (yystack
->yytops
.yystates
[yyi
] == NULL
)
922 YYDPRINTF ((stderr
, "Removing dead stacks.\n"));
923 yystack
->yytops
.yysize
-= 1;
927 yystack
->yytops
.yystates
[yyj
] = yystack
->yytops
.yystates
[yyi
];
929 YYDPRINTF ((stderr
, "Rename stack %d -> %d.\n", yyi
, yyj
));
936 /** Shift to a new state on stack #K of STACK, corresponding to LR state
937 * LRSTATE, at input position POSN, with (resolved) semantic value SVAL. */
939 yyglrShift (yyGLRStack
* yystack
, int yyk
, yyStateNum yylrState
, size_t yyposn
,
940 YYSTYPE yysval
, YYLTYPE
* yylocp
)
942 yyGLRStackItem
* yynewItem
;
944 yynewItem
= yystack
->yynextFree
;
945 yystack
->yynextFree
+= 1;
946 yystack
->yyspaceLeft
-= 1;
947 yynewItem
->yystate
.yyisState
= yytrue
;
948 yynewItem
->yystate
.yylrState
= yylrState
;
949 yynewItem
->yystate
.yyposn
= yyposn
;
950 yynewItem
->yystate
.yyresolved
= yytrue
;
951 yynewItem
->yystate
.yypred
= yystack
->yytops
.yystates
[yyk
];
952 yystack
->yytops
.yystates
[yyk
] = &yynewItem
->yystate
;
953 yynewItem
->yystate
.yysemantics
.yysval
= yysval
;
954 yynewItem
->yystate
.yyloc
= *yylocp
;
955 if (yystack
->yyspaceLeft
< YYHEADROOM
)
956 yyexpandGLRStack (yystack
);
959 /** Shift to a new state on stack #K of STACK, to a new state
960 * corresponding to LR state LRSTATE, at input position POSN, with
961 * the (unresolved) semantic value of RHS under the action for RULE. */
963 yyglrShiftDefer (yyGLRStack
* yystack
, int yyk
, yyStateNum yylrState
,
964 size_t yyposn
, yyGLRState
* rhs
, yyRuleNum yyrule
)
966 yyGLRStackItem
* yynewItem
;
968 yynewItem
= yystack
->yynextFree
;
969 yynewItem
->yystate
.yyisState
= yytrue
;
970 yynewItem
->yystate
.yylrState
= yylrState
;
971 yynewItem
->yystate
.yyposn
= yyposn
;
972 yynewItem
->yystate
.yyresolved
= yyfalse
;
973 yynewItem
->yystate
.yypred
= yystack
->yytops
.yystates
[yyk
];
974 yynewItem
->yystate
.yysemantics
.yyfirstVal
= NULL
;
975 yystack
->yytops
.yystates
[yyk
] = &yynewItem
->yystate
;
976 yystack
->yynextFree
+= 1;
977 yystack
->yyspaceLeft
-= 1;
978 yyaddDeferredAction (yystack
, &yynewItem
->yystate
, rhs
, yyrule
);
981 /** Pop the symbols consumed by reduction #RULE from the top of stack
982 * #K of STACK, and perform the appropriate semantic action on their
983 * semantic values. Assumes that all ambiguities in semantic values
984 * have been previously resolved. Set *VALP to the resulting value,
985 * and *LOCP to the computed location (if any). Return value is as
988 yydoAction (yyGLRStack
* yystack
, int yyk
, yyRuleNum yyrule
,
989 YYSTYPE
* yyvalp
, YYLTYPE
* yylocp YY_USER_FORMALS
)
991 int yynrhs
= yyrhsLength (yyrule
);
993 if (yystack
->yysplitPoint
== NULL
)
995 /* Standard special case: single stack. */
996 yyGLRStackItem
* rhs
= (yyGLRStackItem
*) yystack
->yytops
.yystates
[yyk
];
998 yystack
->yynextFree
-= yynrhs
;
999 yystack
->yyspaceLeft
+= yynrhs
;
1000 yystack
->yytops
.yystates
[0] = & yystack
->yynextFree
[-1].yystate
;
1003 *yyvalp
= yyval_default
;
1004 *yylocp
= yyloc_default
;
1008 *yyvalp
= rhs
[1-yynrhs
].yystate
.yysemantics
.yysval
;
1009 *yylocp
= rhs
[1-yynrhs
].yystate
.yyloc
;
1011 return yyuserAction (yyrule
, yynrhs
, rhs
,
1012 yyvalp
, yylocp
, yystack YY_USER_ARGS
);
1018 yyGLRStackItem yyrhsVals
[YYMAXRHS
];
1019 for (yyi
= yynrhs
-1, yys
= yystack
->yytops
.yystates
[yyk
]; 0 <= yyi
;
1020 yyi
-= 1, yys
= yys
->yypred
)
1022 assert (yys
->yypred
!= NULL
);
1023 yyrhsVals
[yyi
].yystate
.yyresolved
= yytrue
;
1024 yyrhsVals
[yyi
].yystate
.yysemantics
.yysval
= yys
->yysemantics
.yysval
;
1025 yyrhsVals
[yyi
].yystate
.yyloc
= yys
->yyloc
;
1027 yyupdateSplit (yystack
, yys
);
1028 yystack
->yytops
.yystates
[yyk
] = yys
;
1031 *yyvalp
= yyval_default
;
1032 *yylocp
= yyloc_default
;
1036 *yyvalp
= yyrhsVals
[0].yystate
.yysemantics
.yysval
;
1037 *yylocp
= yyrhsVals
[0].yystate
.yyloc
;
1039 return yyuserAction (yyrule
, yynrhs
, yyrhsVals
+ (yynrhs
-1),
1040 yyvalp
, yylocp
, yystack YY_USER_ARGS
);
1045 # define YY_REDUCE_PRINT(K, Rule)
1047 # define YY_REDUCE_PRINT(K, Rule) \
1050 yy_reduce_print (K, Rule); \
1053 /*----------------------------------------------------------.
1054 | Report that the RULE is going to be reduced on stack #K. |
1055 `----------------------------------------------------------*/
1058 yy_reduce_print (size_t yyk
, yyRuleNum yyrule
)
1061 YYDPRINTF ((stderr
, "Reducing stack %d by rule %d (line %d),",
1062 yyk
, yyrule
- 1, yyrline
[yyrule
]));
1063 /* Print the symbols being reduced, and their result. */
1064 for (yyi
= yyprhs
[yyrule
]; 0 <= yyrhs
[yyi
]; yyi
++)
1065 YYFPRINTF (stderr
, "%s ", yytokenName (yyrhs
[yyi
]));
1066 YYFPRINTF (stderr
, " -> %s\n", yytokenName (yyr1
[yyrule
]));
1070 /** Pop items off stack #K of STACK according to grammar rule RULE,
1071 * and push back on the resulting nonterminal symbol. Perform the
1072 * semantic action associated with RULE and store its value with the
1073 * newly pushed state, if FORCEEVAL or if STACK is currently
1074 * unambiguous. Otherwise, store the deferred semantic action with
1075 * the new state. If the new state would have an identical input
1076 * position, LR state, and predecessor to an existing state on the stack,
1077 * it is identified with that existing state, eliminating stack #K from
1078 * the STACK. In this case, the (necessarily deferred) semantic value is
1079 * added to the options for the existing state's semantic value.
1081 static inline YYRESULTTAG
1082 yyglrReduce (yyGLRStack
* yystack
, size_t yyk
, yyRuleNum yyrule
,
1083 bool yyforceEval YY_USER_FORMALS
)
1085 size_t yyposn
= yystack
->yytops
.yystates
[yyk
]->yyposn
;
1087 if (yyforceEval
|| yystack
->yysplitPoint
== NULL
)
1092 YY_REDUCE_PRINT (yyk
, yyrule
);
1093 YYCHK (yydoAction (yystack
, yyk
, yyrule
, &yysval
, &yyloc YY_USER_ARGS
));
1094 yyglrShift (yystack
, yyk
,
1095 yyLRgotoState (yystack
->yytops
.yystates
[yyk
]->yylrState
,
1096 yylhsNonterm (yyrule
)),
1097 yyposn
, yysval
, &yyloc
);
1098 YYDPRINTF ((stderr
, "Stack %d entering state %d\n",
1099 yyk
, yystack
->yytops
.yystates
[yyk
]->yylrState
));
1105 yyGLRState
* yys
, *yys0
= yystack
->yytops
.yystates
[yyk
];
1106 yyStateNum yynewLRState
;
1108 for (yys
= yystack
->yytops
.yystates
[yyk
], yyn
= yyrhsLength (yyrule
);
1112 assert (yys
!= NULL
);
1114 yyupdateSplit (yystack
, yys
);
1115 yynewLRState
= yyLRgotoState (yys
->yylrState
, yylhsNonterm (yyrule
));
1117 "Reduced stack %d by rule #%d; action deferred. "
1118 "Now in state %d.\n",
1119 yyk
, yyrule
-1, yynewLRState
));
1120 for (yyi
= 0; yyi
< yystack
->yytops
.yysize
; yyi
+= 1)
1121 if (yyi
!= yyk
&& yystack
->yytops
.yystates
[yyi
] != NULL
)
1123 yyGLRState
* yyp
, *yysplit
= yystack
->yysplitPoint
;
1124 yyp
= yystack
->yytops
.yystates
[yyi
];
1125 while (yyp
!= yys
&& yyp
!= yysplit
&& yyp
->yyposn
>= yyposn
)
1127 if (yyp
->yylrState
== yynewLRState
&& yyp
->yypred
== yys
)
1129 yyaddDeferredAction (yystack
, yyp
, yys0
, yyrule
);
1130 yymarkStackDeleted (yystack
, yyk
);
1131 YYDPRINTF ((stderr
, "Merging stack %d into stack %d.\n",
1138 yystack
->yytops
.yystates
[yyk
] = yys
;
1139 yyglrShiftDefer (yystack
, yyk
, yynewLRState
, yyposn
, yys0
, yyrule
);
1145 yysplitStack (yyGLRStack
* yystack
, int yyk
)
1147 if (yystack
->yysplitPoint
== NULL
)
1150 yystack
->yysplitPoint
= yystack
->yytops
.yystates
[yyk
];
1152 if (yystack
->yytops
.yysize
>= yystack
->yytops
.yycapacity
)
1154 yystack
->yytops
.yycapacity
*= 2;
1155 yystack
->yytops
.yystates
=
1156 (yyGLRState
**) realloc (yystack
->yytops
.yystates
,
1157 yystack
->yytops
.yycapacity
1158 * sizeof (yyGLRState
*));
1160 yystack
->yytops
.yystates
[yystack
->yytops
.yysize
]
1161 = yystack
->yytops
.yystates
[yyk
];
1162 yystack
->yytops
.yysize
+= 1;
1163 return yystack
->yytops
.yysize
-1;
1166 /** True iff Y0 and Y1 represent identical options at the top level.
1167 * That is, they represent the same rule applied to RHS symbols
1168 * that produce the same terminal symbols. */
1170 yyidenticalOptions (yySemanticOption
* yyy0
, yySemanticOption
* yyy1
)
1172 if (yyy0
->yyrule
== yyy1
->yyrule
)
1174 yyGLRState
*yys0
, *yys1
;
1176 for (yys0
= yyy0
->yystate
, yys1
= yyy1
->yystate
,
1177 yyn
= yyrhsLength (yyy0
->yyrule
);
1179 yys0
= yys0
->yypred
, yys1
= yys1
->yypred
, yyn
-= 1)
1180 if (yys0
->yyposn
!= yys1
->yyposn
)
1188 /** Assuming identicalOptions (Y0,Y1), (destructively) merge the
1189 * alternative semantic values for the RHS-symbols of Y1 into the
1190 * corresponding semantic value sets of the symbols of Y0. */
1192 yymergeOptionSets (yySemanticOption
* yyy0
, yySemanticOption
* yyy1
)
1194 yyGLRState
*yys0
, *yys1
;
1196 for (yys0
= yyy0
->yystate
, yys1
= yyy1
->yystate
,
1197 yyn
= yyrhsLength (yyy0
->yyrule
);
1199 yys0
= yys0
->yypred
, yys1
= yys1
->yypred
, yyn
-= 1)
1202 else if (! yys0
->yyresolved
&& ! yys1
->yyresolved
)
1204 yySemanticOption
* yyz
;
1205 for (yyz
= yys0
->yysemantics
.yyfirstVal
; yyz
->yynext
!= NULL
;
1208 yyz
->yynext
= yys1
->yysemantics
.yyfirstVal
;
1212 /** Y0 and Y1 represent two possible actions to take in a given
1213 * parsing state; return 0 if no combination is possible,
1214 * 1 if user-mergeable, 2 if Y0 is preferred, 3 if Y1 is preferred. */
1216 yypreference (yySemanticOption
* y0
, yySemanticOption
* y1
)
1218 yyRuleNum r0
= y0
->yyrule
, r1
= y1
->yyrule
;
1219 int p0
= yydprec
[r0
], p1
= yydprec
[r1
];
1223 if (yymerger
[r0
] == 0 || yymerger
[r0
] != yymerger
[r1
])
1228 if (p0
== 0 || p1
== 0)
1237 static YYRESULTTAG
yyresolveValue (yySemanticOption
* yyoptionList
,
1238 yyGLRStack
* yystack
, YYSTYPE
* yyvalp
,
1239 YYLTYPE
* yylocp YY_USER_FORMALS
);
1242 yyresolveStates (yyGLRState
* yys
, int yyn
, yyGLRStack
* yystack YY_USER_FORMALS
)
1247 assert (yys
->yypred
!= NULL
);
1248 yyflag
= yyresolveStates (yys
->yypred
, yyn
-1, yystack YY_USER_ARGS
);
1251 if (! yys
->yyresolved
)
1253 yyflag
= yyresolveValue (yys
->yysemantics
.yyfirstVal
, yystack
,
1254 &yys
->yysemantics
.yysval
, &yys
->yyloc
1258 yys
->yyresolved
= yytrue
;
1265 yyresolveAction (yySemanticOption
* yyopt
, yyGLRStack
* yystack
,
1266 YYSTYPE
* yyvalp
, YYLTYPE
* yylocp YY_USER_FORMALS
)
1268 yyGLRStackItem yyrhsVals
[YYMAXRHS
];
1272 yynrhs
= yyrhsLength (yyopt
->yyrule
);
1273 YYCHK (yyresolveStates (yyopt
->yystate
, yynrhs
, yystack YY_USER_ARGS
));
1274 for (yyi
= yynrhs
-1, yys
= yyopt
->yystate
; 0 <= yyi
;
1275 yyi
-= 1, yys
= yys
->yypred
)
1277 assert (yys
->yypred
!= NULL
);
1278 yyrhsVals
[yyi
].yystate
.yyresolved
= yytrue
;
1279 yyrhsVals
[yyi
].yystate
.yysemantics
.yysval
= yys
->yysemantics
.yysval
;
1280 yyrhsVals
[yyi
].yystate
.yyloc
= yys
->yyloc
;
1282 return yyuserAction (yyopt
->yyrule
, yynrhs
, yyrhsVals
+ (yynrhs
-1),
1283 yyvalp
, yylocp
, yystack YY_USER_ARGS
);
1288 yyreportTree (yySemanticOption
* yyx
, int yyindent
)
1290 int yynrhs
= yyrhsLength (yyx
->yyrule
);
1293 yyGLRState
* yystates
[YYMAXRHS
];
1294 yyGLRState yyleftmost_state
;
1296 for (yyi
= yynrhs
, yys
= yyx
->yystate
; 0 < yyi
; yyi
-= 1, yys
= yys
->yypred
)
1297 yystates
[yyi
] = yys
;
1300 yyleftmost_state
.yyposn
= 0;
1301 yystates
[0] = &yyleftmost_state
;
1306 if (yyx
->yystate
->yyposn
< yys
->yyposn
+ 1)
1307 YYFPRINTF (stderr
, "%*s%s -> <Rule %d, empty>\n",
1308 yyindent
, "", yytokenName (yylhsNonterm (yyx
->yyrule
)),
1311 YYFPRINTF (stderr
, "%*s%s -> <Rule %d, tokens %d .. %d>\n",
1312 yyindent
, "", yytokenName (yylhsNonterm (yyx
->yyrule
)),
1313 yyx
->yyrule
, yys
->yyposn
+1, yyx
->yystate
->yyposn
);
1314 for (yyi
= 1; yyi
<= yynrhs
; yyi
+= 1)
1316 if (yystates
[yyi
]->yyresolved
)
1318 if (yystates
[yyi
-1]->yyposn
+1 > yystates
[yyi
]->yyposn
)
1319 YYFPRINTF (stderr
, "%*s%s <empty>\n", yyindent
+2, "",
1320 yytokenName (yyrhs
[yyprhs
[yyx
->yyrule
]+yyi
-1]));
1322 YYFPRINTF (stderr
, "%*s%s <tokens %d .. %d>\n", yyindent
+2, "",
1323 yytokenName (yyrhs
[yyprhs
[yyx
->yyrule
]+yyi
-1]),
1324 yystates
[yyi
-1]->yyposn
+1, yystates
[yyi
]->yyposn
);
1327 yyreportTree (yystates
[yyi
]->yysemantics
.yyfirstVal
, yyindent
+2);
1333 yyreportAmbiguity (yySemanticOption
* yyx0
, yySemanticOption
* yyx1
,
1334 yyGLRStack
* yystack
)
1336 /* `Unused' warnings. */
1341 YYFPRINTF (stderr
, "Ambiguity detected.\n");
1342 YYFPRINTF (stderr
, "Option 1,\n");
1343 yyreportTree (yyx0
, 2);
1344 YYFPRINTF (stderr
, "\nOption 2,\n");
1345 yyreportTree (yyx1
, 2);
1346 YYFPRINTF (stderr
, "\n");
1348 yyFail (yystack
, "ambiguity detected");
1352 /** Resolve the ambiguity represented by OPTIONLIST, perform the indicated
1353 * actions, and return the result. */
1355 yyresolveValue (yySemanticOption
* yyoptionList
, yyGLRStack
* yystack
,
1356 YYSTYPE
* yyvalp
, YYLTYPE
* yylocp YY_USER_FORMALS
)
1358 yySemanticOption
* yybest
;
1359 yySemanticOption
* yyp
;
1362 yybest
= yyoptionList
;
1364 for (yyp
= yyoptionList
->yynext
; yyp
!= NULL
; yyp
= yyp
->yynext
)
1366 if (yyidenticalOptions (yybest
, yyp
))
1367 yymergeOptionSets (yybest
, yyp
);
1369 switch (yypreference (yybest
, yyp
))
1372 yyreportAmbiguity (yybest
, yyp
, yystack
);
1388 int yyprec
= yydprec
[yybest
->yyrule
];
1389 YYCHK (yyresolveAction (yybest
, yystack
, yyvalp
, yylocp YY_USER_ARGS
));
1390 for (yyp
= yybest
->yynext
; yyp
!= NULL
; yyp
= yyp
->yynext
)
1392 if (yyprec
== yydprec
[yyp
->yyrule
])
1396 YYCHK (yyresolveAction (yyp
, yystack
, &yyval1
, &yydummy YY_USER_ARGS
));
1397 *yyvalp
= yyuserMerge (yymerger
[yyp
->yyrule
], yyvalp
, &yyval1
);
1403 return yyresolveAction (yybest
, yystack
, yyvalp
, yylocp YY_USER_ARGS
);
1407 yyresolveStack (yyGLRStack
* yystack YY_USER_FORMALS
)
1409 if (yystack
->yysplitPoint
!= NULL
)
1414 for (yyn
= 0, yys
= yystack
->yytops
.yystates
[0];
1415 yys
!= yystack
->yysplitPoint
;
1416 yys
= yys
->yypred
, yyn
+= 1)
1418 YYCHK (yyresolveStates (yystack
->yytops
.yystates
[0], yyn
, yystack
1425 yycompressStack (yyGLRStack
* yystack
)
1427 yyGLRState
* yyp
, *yyq
, *yyr
;
1429 if (yystack
->yytops
.yysize
!= 1 || yystack
->yysplitPoint
== NULL
)
1432 for (yyp
= yystack
->yytops
.yystates
[0], yyq
= yyp
->yypred
, yyr
= NULL
;
1433 yyp
!= yystack
->yysplitPoint
;
1434 yyr
= yyp
, yyp
= yyq
, yyq
= yyp
->yypred
)
1437 yystack
->yyspaceLeft
+= yystack
->yynextFree
- yystack
->yyitems
;
1438 yystack
->yynextFree
= ((yyGLRStackItem
*) yystack
->yysplitPoint
) + 1;
1439 yystack
->yyspaceLeft
-= yystack
->yynextFree
- yystack
->yyitems
;
1440 yystack
->yysplitPoint
= NULL
;
1441 yystack
->yylastDeleted
= NULL
;
1445 yystack
->yynextFree
->yystate
= *yyr
;
1447 yystack
->yynextFree
->yystate
.yypred
= & yystack
->yynextFree
[-1].yystate
;
1448 yystack
->yytops
.yystates
[0] = &yystack
->yynextFree
->yystate
;
1449 yystack
->yynextFree
+= 1;
1450 yystack
->yyspaceLeft
-= 1;
1455 yyprocessOneStack (yyGLRStack
* yystack
, int yyk
,
1456 size_t yyposn
, YYSTYPE
* yylvalp
, YYLTYPE
* yyllocp
1460 const short* yyconflicts
;
1462 yySymbol
* const yytokenp
= yystack
->yytokenp
;
1464 while (yystack
->yytops
.yystates
[yyk
] != NULL
)
1466 yyStateNum yystate
= yystack
->yytops
.yystates
[yyk
]->yylrState
;
1468 assert (yystate
!= YYFINAL
);
1469 if (yyisDefaultedState (yystate
))
1471 yyrule
= yydefaultAction (yystate
);
1474 YYDPRINTF ((stderr
, "Stack %d dies.\n", yyk
));
1475 yymarkStackDeleted (yystack
, yyk
);
1478 YYCHK (yyglrReduce (yystack
, yyk
, yyrule
, yyfalse YY_USER_ARGS
));
1482 if (*yytokenp
== YYEMPTY
)
1484 YYDPRINTF ((stderr
, "Reading a token: "));
1486 *yytokenp
= YYTRANSLATE(yychar
);
1487 YYDPRINTF ((stderr
, "Next token is %s\n",
1488 yytokenName (*yytokenp
)));
1490 yygetLRActions (yystate
, *yytokenp
, &yyaction
, &yyconflicts
);
1492 while (*yyconflicts
!= 0)
1494 int yynewStack
= yysplitStack (yystack
, yyk
);
1495 YYDPRINTF ((stderr
, "Splitting off stack %d from %d.\n",
1497 YYCHK (yyglrReduce (yystack
, yynewStack
,
1498 *yyconflicts
, yyfalse YY_USER_ARGS
));
1499 YYCHK (yyprocessOneStack (yystack
, yynewStack
, yyposn
,
1500 yylvalp
, yyllocp YY_USER_ARGS
));
1504 if (yyisShiftAction (yyaction
))
1506 YYDPRINTF ((stderr
, "Shifting token %s on stack %d, ",
1507 yytokenName (*yytokenp
), yyk
));
1508 yyglrShift (yystack
, yyk
, yyaction
, yyposn
+1, *yylvalp
, yyllocp
);
1509 YYDPRINTF ((stderr
, "which is now in state #%d\n",
1510 yystack
->yytops
.yystates
[yyk
]->yylrState
));
1513 else if (yyisErrorAction (yyaction
))
1515 YYDPRINTF ((stderr
, "Stack %d dies.\n", yyk
));
1516 yymarkStackDeleted (yystack
, yyk
);
1520 YYCHK (yyglrReduce (yystack
, yyk
, -yyaction
, yyfalse YY_USER_ARGS
));
1527 yyreportParseError (yyGLRStack
* yystack
, YYSTYPE
* yylvalp
, YYLTYPE
* yyllocp
)
1529 /* `Unused' warnings. */
1533 if (yystack
->yyerrState
== 0)
1536 yySymbol
* const yytokenp
= yystack
->yytokenp
;
1537 int yyn
, yyx
, yycount
;
1539 const char* yyprefix
;
1542 yyn
= yypact
[yystack
->yytops
.yystates
[0]->yylrState
];
1543 if (YYPACT_NINF
< yyn
&& yyn
< YYLAST
)
1546 /* Start YYX at -YYN if negative to avoid negative indexes in
1548 yysize
= sizeof ("parse error, unexpected ")
1549 + strlen (yytokenName (*yytokenp
));
1550 yyprefix
= ", expecting ";
1551 for (yyx
= yyn
< 0 ? -yyn
: 0; yyx
< yytname_size
&& yycount
<= 5;
1553 if (yycheck
[yyx
+ yyn
] == yyx
&& yyx
!= YYTERROR
)
1554 yysize
+= strlen (yytokenName (yyx
)) + strlen (yyprefix
),
1555 yycount
+= 1, yyprefix
= " or ";
1556 yymsg
= yyp
= (char*) malloc (yysize
);
1557 sprintf (yyp
, "parse error, unexpected %s",
1558 yytokenName (*yytokenp
));
1559 yyp
+= strlen (yyp
);
1562 yyprefix
= ", expecting ";
1563 for (yyx
= yyn
< 0 ? -yyn
: 0; yyx
< yytname_size
; yyx
+= 1)
1564 if (yycheck
[yyx
+ yyn
] == yyx
&& yyx
!= YYTERROR
)
1566 sprintf (yyp
, "%s%s", yyprefix
, yytokenName (yyx
));
1567 yyp
+= strlen (yyp
);
1576 yyerror ("parse error");
1581 /* Recover from a syntax error on YYSTACK, assuming that YYTOKENP,
1582 YYLVALP, and YYLLOCP point to the syntactic category, semantic
1583 value, and location of the lookahead. */
1585 yyrecoverParseError (yyGLRStack
* yystack
, YYSTYPE
* yylvalp
, YYLTYPE
* yyllocp
)
1587 yySymbol
* const yytokenp
= yystack
->yytokenp
;
1591 if (yystack
->yyerrState
== 0)
1592 yystack
->yyerrState
= 3;
1593 else if (yystack
->yyerrState
== 3)
1594 /* We just shifted the error token and (perhaps) took some
1595 reductions. Skip tokens until we can proceed. */
1598 if (*yytokenp
== YYEOF
)
1599 yyFail (yystack
, NULL
);
1600 if (*yytokenp
!= YYEMPTY
)
1601 YYDPRINTF ((stderr
, "Discarding token %s\n",
1602 yytokenName (*yytokenp
)));
1603 YYDPRINTF ((stderr
, "Reading a token: "));
1605 *yytokenp
= YYTRANSLATE (yychar
);
1606 YYDPRINTF ((stderr
, "Next token is %s\n", yytokenName (*yytokenp
)));
1607 yyj
= yypact
[yystack
->yytops
.yystates
[0]->yylrState
];
1608 if (yyj
== YYPACT_NINF
)
1609 /* Something's not right; we shouldn't be here. */
1610 yyFail (yystack
, NULL
);
1612 if (yyj
< 0 || YYLAST
< yyj
|| yycheck
[yyj
] != *yytokenp
)
1614 if (yydefact
[yystack
->yytops
.yystates
[0]->yylrState
] != 0)
1617 else if (yytable
[yyj
] != 0 && yytable
[yyj
] != YYTABLE_NINF
)
1621 /* Reduce to one stack. */
1622 for (yyk
= 0; yyk
< yystack
->yytops
.yysize
; yyk
+= 1)
1623 if (yystack
->yytops
.yystates
[yyk
] != NULL
)
1625 if (yyk
>= yystack
->yytops
.yysize
)
1626 yyFail (yystack
, NULL
);
1627 for (yyk
+= 1; yyk
< yystack
->yytops
.yysize
; yyk
+= 1)
1628 yymarkStackDeleted (yystack
, yyk
);
1629 yyremoveDeletes (yystack
);
1630 yycompressStack (yystack
);
1632 /* Now pop stack until we find a state that shifts the error token. */
1633 while (yystack
->yytops
.yystates
[0] != NULL
)
1635 yyj
= yypact
[yystack
->yytops
.yystates
[0]->yylrState
] + YYTERROR
;
1636 if (yyj
!= YYPACT_NINF
+ YYTERROR
&& yyj
>= 0 && yyj
<= YYLAST
&&
1637 yycheck
[yyj
] == YYTERROR
&& yyisShiftAction (yytable
[yyj
]))
1639 yyglrShift (yystack
, 0, yytable
[yyj
],
1640 yystack
->yytops
.yystates
[0]->yyposn
, *yylvalp
, yyllocp
);
1643 yystack
->yytops
.yystates
[0] = yystack
->yytops
.yystates
[0]->yypred
;
1644 yystack
->yynextFree
-= 1;
1645 yystack
->yyspaceLeft
+= 1;
1647 if (yystack
->yytops
.yystates
[0] == NULL
)
1648 yyFail (yystack
, NULL
);
1651 #define YYCHK1(YYE) \
1657 yystack.yyerrflag = 1; \
1660 yystack.yyerrflag = 0; \
1663 goto yyuser_error; \
1672 ]b4_c_ansi_function_def([yyparse
], [int], b4_parse_param
)[
1682 #define yychar (yystack.yyrawchar)
1685 YYSTYPE
* const yylvalp
= &yylval
;
1686 YYLTYPE
* const yyllocp
= &yylloc
;
1688 yyinitGLRStack (&yystack
, YYINITDEPTH
);
1689 yystack
.yytokenp
= &yytoken
;
1691 YYDPRINTF ((stderr
, "Starting parse\n"));
1693 if (setjmp (yystack
.yyexception_buffer
) != 0)
1696 yyglrShift (&yystack
, 0, 0, 0, yyval_default
, &yyloc_default
);
1702 /* For efficiency, we have two loops, the first of which is
1703 specialized to deterministic operation (single stack, no
1704 potential ambiguity). */
1711 const short* yyconflicts
;
1713 yyStateNum yystate
= yystack
.yytops
.yystates
[0]->yylrState
;
1714 if (yystate
== YYFINAL
)
1716 if (yyisDefaultedState (yystate
))
1718 yyrule
= yydefaultAction (yystate
);
1721 yyreportParseError (&yystack
, yylvalp
, yyllocp
);
1724 YYCHK1 (yyglrReduce (&yystack
, 0, yyrule
, yytrue YY_USER_ARGS
));
1728 if (yytoken
== YYEMPTY
)
1730 YYDPRINTF ((stderr
, "Reading a token: "));
1732 yytoken
= YYTRANSLATE (yychar
);
1733 YYDPRINTF ((stderr
, "Next token is %s\n",
1734 yytokenName (yytoken
)));
1736 yygetLRActions (yystate
, yytoken
, &yyaction
, &yyconflicts
);
1737 if (*yyconflicts
!= 0)
1739 if (yyisShiftAction (yyaction
))
1741 YYDPRINTF ((stderr
, "Shifting token %s, ",
1742 yytokenName (yytoken
)));
1743 if (yytoken
!= YYEOF
)
1746 yyglrShift (&yystack
, 0, yyaction
, yyposn
, yylval
, yyllocp
);
1747 if (0 < yystack
.yyerrState
)
1748 yystack
.yyerrState
-= 1;
1749 YYDPRINTF ((stderr
, "Entering state %d\n",
1750 yystack
.yytops
.yystates
[0]->yylrState
));
1752 else if (yyisErrorAction (yyaction
))
1754 yyreportParseError (&yystack
, yylvalp
, yyllocp
);
1758 YYCHK1 (yyglrReduce (&yystack
, 0, -yyaction
, yytrue YY_USER_ARGS
));
1765 int yyn
= yystack
.yytops
.yysize
;
1766 for (yys
= 0; yys
< yyn
; yys
+= 1)
1767 YYCHK1 (yyprocessOneStack (&yystack
, yys
, yyposn
,
1768 yylvalp
, yyllocp YY_USER_ARGS
));
1771 yyremoveDeletes (&yystack
);
1772 if (yystack
.yytops
.yysize
== 0)
1774 yyundeleteLastStack (&yystack
);
1775 if (yystack
.yytops
.yysize
== 0)
1776 yyFail (&yystack
, "parse error");
1777 YYCHK1 (yyresolveStack (&yystack YY_USER_ARGS
));
1778 YYDPRINTF ((stderr
, "Returning to deterministic operation.\n"));
1779 yyreportParseError (&yystack
, yylvalp
, yyllocp
);
1782 else if (yystack
.yytops
.yysize
== 1)
1784 YYCHK1 (yyresolveStack (&yystack YY_USER_ARGS
));
1785 YYDPRINTF ((stderr
, "Returning to deterministic operation.\n"));
1786 yycompressStack (&yystack
);
1792 yyrecoverParseError (&yystack
, yylvalp
, yyllocp
);
1793 yyposn
= yystack
.yytops
.yystates
[0]->yyposn
;
1798 yyfreeGLRStack (&yystack
);
1799 return yystack
.yyerrflag
;
1802 /* DEBUGGING ONLY */
1803 static void yypstack (yyGLRStack
* yystack
, int yyk
) ATTRIBUTE_UNUSED
;
1804 static void yypdumpstack (yyGLRStack
* yystack
) ATTRIBUTE_UNUSED
;
1807 yy_yypstack (yyGLRState
* yys
)
1811 yy_yypstack (yys
->yypred
);
1812 fprintf (stderr
, " -> ");
1814 fprintf (stderr
, "%d@%lu", yys
->yylrState
, (unsigned long) yys
->yyposn
);
1818 yypstates (yyGLRState
* yyst
)
1821 fprintf (stderr
, "<null>");
1824 fprintf (stderr
, "\n");
1828 yypstack (yyGLRStack
* yystack
, int yyk
)
1830 yypstates (yystack
->yytops
.yystates
[yyk
]);
1833 #define YYINDEX(YYX) \
1834 ((YYX) == NULL ? -1 : (yyGLRStackItem*) (YYX) - yystack->yyitems)
1838 yypdumpstack (yyGLRStack
* yystack
)
1840 yyGLRStackItem
* yyp
;
1842 for (yyp
= yystack
->yyitems
; yyp
< yystack
->yynextFree
; yyp
+= 1)
1844 fprintf (stderr
, "%3lu. ", (unsigned long) (yyp
- yystack
->yyitems
));
1847 fprintf (stderr
, "Res: %d, LR State: %d, posn: %lu, pred: %ld",
1848 yyp
->yystate
.yyresolved
, yyp
->yystate
.yylrState
,
1849 (unsigned long) yyp
->yystate
.yyposn
,
1850 (long) YYINDEX (yyp
->yystate
.yypred
));
1851 if (! yyp
->yystate
.yyresolved
)
1852 fprintf (stderr
, ", firstVal: %ld",
1853 (long) YYINDEX (yyp
->yystate
.yysemantics
.yyfirstVal
));
1857 fprintf (stderr
, "Option. rule: %d, state: %ld, next: %ld",
1858 yyp
->yyoption
.yyrule
,
1859 (long) YYINDEX (yyp
->yyoption
.yystate
),
1860 (long) YYINDEX (yyp
->yyoption
.yynext
));
1862 fprintf (stderr
, "\n");
1864 fprintf (stderr
, "Tops:");
1865 for (yyi
= 0; yyi
< yystack
->yytops
.yysize
; yyi
+= 1)
1866 fprintf (stderr
, "%lu: %ld; ", (unsigned long) yyi
,
1867 (long) YYINDEX (yystack
->yytops
.yystates
[yyi
]));
1868 fprintf (stderr
, "\n");
1873 m4_if(b4_defines_flag
, 0, [],
1874 [#output "b4_output_header_name"
1875 b4_copyright([Skeleton parser
for GLR parsing with Bison
], [2002])
1876 #ifndef b4_header_guard
1877 # define b4_header_guard
1879 b4_token_defines(b4_tokens
)
1882 m4_ifdef([b4_stype
],
1883 [#line b4_stype_line "b4_filename"
1884 typedef union b4_stype yystype
;
1885 /* Line __line__ of __file__. */
1886 #line __oline__ "__ofile__"],
1887 [typedef int yystype
;])
1888 # define YYSTYPE yystype
1892 [extern YYSTYPE b4_prefix
[]lval
;])
1896 typedef struct yyltype
1903 # define YYLTYPE yyltype
1907 [extern YYLTYPE b4_prefix
[]lloc
;])
1909 #endif /* not b4_header_guard */