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
]], [_
])])
115 #output "b4_output_parser_name"
116 b4_copyright([Skeleton parser
for GLR parsing with Bison
], [2002])
118 /* This is the parser code for GLR (Generalized LR) parser. */
120 /* FIXME: minimize these */
128 /* Identify Bison output. */
132 #define YYPURE ]b4_pure[
134 /* Using locations. */
135 #define YYLSP_NEEDED ]b4_locations_flag[
137 ]m4_if(b4_prefix
[], [yy
], [],
138 [/* If NAME_PREFIX is specified substitute the variables and functions
140 #define yyparse b4_prefix[]parse
141 #define yylex b4_prefix[]lex
142 #define yyerror b4_prefix[]error
143 #define yylval b4_prefix[]lval
144 #define yychar b4_prefix[]char
145 #define yydebug b4_prefix[]debug
146 #define yynerrs b4_prefix[]nerrs
147 b4_location_if([#define yylloc b4_prefix[]lloc])])
149 b4_token_defines(b4_tokens
)
151 /* Copy the first part of user declarations. */
154 /* Enabling traces. */
156 # define YYDEBUG ]b4_debug[
159 /* Enabling verbose error messages. */
160 #ifdef YYERROR_VERBOSE
161 # undef YYERROR_VERBOSE
162 # define YYERROR_VERBOSE 1
164 # define YYERROR_VERBOSE ]b4_error_verbose[
168 ]m4_ifdef([b4_stype
],
169 [#line b4_stype_line "b4_filename"
170 typedef union b4_stype yystype
;
171 /* Line __line__ of __file__. */
172 #line __oline__ "__ofile__"],
173 [typedef int yystype
;])[
174 # define YYSTYPE yystype
175 # define YYSTYPE_IS_TRIVIAL 1
179 typedef struct yyltype
186 # define YYLTYPE ]b4_location_type[
187 # define YYLTYPE_IS_TRIVIAL 1
190 /* Default (constant) values used for initialization for null
191 right-hand sides. Unlike the standard bison.simple template,
192 here we set the default values of the $$ and $@ to zeroed-out
193 values. Since the default value of these quantities is undefined,
194 this behavior is technically correct. */
195 static YYSTYPE yyval_default
;
196 static YYLTYPE yyloc_default
;
198 /* Copy the second part of user declarations. */
201 ]/* Line __line__ of __file__. */
202 #line __oline__ "__ofile__"
204 #if ! defined (__cplusplus)
210 #if defined (__STDC__) || defined (__cplusplus)
211 typedef signed char yysigned_char
;
213 typedef short yysigned_char
;
220 #ifndef __attribute__
221 /* This feature is available in gcc versions 2.5 and later. */
222 # if !defined (__GNUC__) || __GNUC__ < 2 || \
223 (__GNUC__ == 2 && __GNUC_MINOR__ < 5) || __STRICT_ANSI__
224 # define __attribute__(Spec) /* empty */
228 #ifndef ATTRIBUTE_UNUSED
229 # define ATTRIBUTE_UNUSED __attribute__ ((__unused__))
232 #if ! defined (__GNUC__)
236 /* YYFINAL -- State number of the termination state. */
237 #define YYFINAL ]b4_final_state_number[
238 /* YYLAST -- Last index in YYTABLE. */
239 #define YYLAST ]b4_last[
241 /* YYNTOKENS -- Number of terminals. */
242 #define YYNTOKENS ]b4_tokens_number[
243 /* YYNNTS -- Number of nonterminals. */
244 #define YYNNTS ]b4_nterms_number[
245 /* YYNRULES -- Number of rules. */
246 #define YYNRULES ]b4_rules_number[
247 /* YYNRULES -- Number of states. */
248 #define YYNSTATES ]b4_states_number[
249 /* YYMAXRHS -- Maximum number of symbols on right-hand side of rule. */
250 #define YYMAXRHS ]b4_r2_max[
252 /* YYTRANSLATE(X) -- Bison symbol number corresponding to X. */
253 #define YYUNDEFTOK ]b4_undef_token_number[
254 #define YYMAXUTOK ]b4_user_token_number_max[
256 #define YYTRANSLATE(YYX) \
257 ((unsigned)(YYX) <= YYMAXUTOK ? yytranslate[YYX] : YYUNDEFTOK)
259 /* YYTRANSLATE[YYLEX] -- Bison symbol number corresponding to YYLEX. */
260 static const ]b4_int_type_for([b4_translate
])[ yytranslate
[] =
266 /* YYPRHS[YYN] -- Index of the first RHS symbol of rule number YYN in
268 static const ]b4_int_type_for([b4_prhs
])[ yyprhs
[] =
273 /* YYRHS -- A `-1'-separated list of the rules' RHS. */
274 static const ]b4_int_type_for([b4_rhs
])[ yyrhs
[] =
279 /* YYRLINE[YYN] -- source line where rule number YYN was defined. */
280 static const ]b4_int_type_for([b4_rline
])[ yyrline
[] =
286 #if (YYDEBUG) || YYERROR_VERBOSE
287 /* YYTNME[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM.
288 First, the terminals, then, starting at YYNTOKENS, nonterminals. */
289 static const char *const yytname
[] =
294 #define yytname_size ((int) (sizeof (yytname) / sizeof (yytname[0])))
297 /* YYR1[YYN] -- Symbol number of symbol that rule YYN derives. */
298 static const ]b4_int_type_for([b4_r1
])[ yyr1
[] =
303 /* YYR2[YYN] -- Number of symbols composing right hand side of rule YYN. */
304 static const ]b4_int_type_for([b4_r2
])[ yyr2
[] =
309 /* YYDPREC[RULE-NUM] -- Dynamic precedence of rule #RULE-NUM (0 if none). */
310 static const ]b4_int_type_for([b4_dprec
])[ yydprec
[] =
315 /* YYMERGER[RULE-NUM] -- Index of merging function for rule #RULE-NUM. */
316 static const ]b4_int_type_for([b4_merger
])[ yymerger
[] =
321 /* YYDEFACT[S] -- default rule to reduce with in state S when YYTABLE
322 doesn't specify something else to do. Zero means the default is an
324 static const ]b4_int_type_for([b4_defact
])[ yydefact
[] =
329 /* YYPDEFGOTO[NTERM-NUM]. */
330 static const ]b4_int_type_for([b4_defgoto
])[ yydefgoto
[] =
335 /* YYPACT[STATE-NUM] -- Index in YYTABLE of the portion describing
337 #define YYPACT_NINF ]b4_pact_ninf[
338 static const ]b4_int_type_for([b4_pact
])[ yypact
[] =
343 /* YYPGOTO[NTERM-NUM]. */
344 static const ]b4_int_type_for([b4_pgoto
])[ yypgoto
[] =
349 /* YYTABLE[YYPACT[STATE-NUM]]. What to do in state STATE-NUM. If
350 positive, shift that token. If negative, reduce the rule which
351 number is the opposite. If zero, do what YYDEFACT says.
352 If YYTABLE_NINF, parse error. */
353 #define YYTABLE_NINF ]b4_table_ninf[
354 static const ]b4_int_type_for([b4_table
])[ yytable
[] =
359 /* YYCONFLP[YYPACT[STATE-NUM]] -- Pointer into YYCONFL of start of
360 list of conflicting reductions corresponding to action entry for
361 state STATE-NUM in yytable. 0 means no conflicts. The list in
362 yyconfl is terminated by a rule number of 0. */
363 static const ]b4_int_type_for([b4_conflict_list_heads
])[ yyconflp
[] =
365 ]b4_conflict_list_heads
[
368 /* YYCONFL[I] -- lists of conflicting rule numbers, each terminated by
369 0, pointed into by YYCONFLP. */
370 ]dnl Do
not use b4_int_type_for here
, since there are places where
371 dnl pointers onto yyconfl are taken
, which type is
"short *".
372 dnl We probably ought to introduce a type
for confl
.
373 [static const short yyconfl
[] =
375 ]b4_conflicting_rules
[
378 static const ]b4_int_type_for([b4_check
])[ yycheck
[] =
384 /* Prevent warning if -Wmissing-prototypes. */
385 ]b4_c_ansi_function_decl([yyparse
], [int], b4_parse_param
)
387 m4_ifset([b4_parse_param
],
388 [#define YY_USER_FORMALS , b4_c_ansi_formals(b4_parse_param)
389 #define YY_USER_ARGS , b4_c_args(b4_parse_param)],
390 [#define YY_USER_FORMALS
391 #define YY_USER_ARGS])
394 [/* Error token number */
397 /* YYLLOC_DEFAULT -- Compute the default location (before the actions
400 #define YYRHSLOC(yyRhs,YYK) (yyRhs[YYK].yystate.yyloc)
402 #ifndef YYLLOC_DEFAULT
403 # define YYLLOC_DEFAULT(yyCurrent, yyRhs, YYN) \
404 yyCurrent.first_line = YYRHSLOC(yyRhs,1).first_line; \
405 yyCurrent.first_column = YYRHSLOC(yyRhs,1).first_column; \
406 yyCurrent.last_line = YYRHSLOC(yyRhs,YYN).last_line; \
407 yyCurrent.last_column = YYRHSLOC(yyRhs,YYN).last_column;
410 /* YYLEX -- calling `yylex' with the right arguments. */
411 #define YYLEX ]b4_c_function_call([yylex], [int], b4_lex_param)[
416 #define yynerrs (yystack->yyerrcnt)
418 #define yychar (yystack->yyrawchar)],
426 static const int YYEOF
= 0;
427 static const int YYEMPTY
= -2;
429 typedef enum { yyok
, yyaccept
, yyabort
, yyerr
} YYRESULTTAG
;
432 do { YYRESULTTAG yyflag = YYE; if (yyflag != yyok) return yyflag; } \
437 #if ! defined (YYFPRINTF)
438 # define YYFPRINTF fprintf
441 # define YYDPRINTF(Args) \
446 /* Nonzero means print parse trace. It is left uninitialized so that
447 multiple parsers can coexist. */
450 /* Avoid empty `if' bodies. */
451 # define YYDPRINTF(Args) {}
452 #endif /* !YYDEBUG */
454 /* YYINITDEPTH -- initial size of the parser's stacks. */
456 # define YYINITDEPTH ]b4_stack_depth_init[
459 /* YYMAXDEPTH -- maximum size the stacks can grow to (effective only
460 if the built-in stack extension method is used).
462 Do not make this value too large; the results are undefined if
463 SIZE_MAX < YYMAXDEPTH * sizeof (GLRStackItem)
464 evaluated with infinite-precision integer arithmetic. */
471 # define YYMAXDEPTH ]b4_stack_depth_max[
474 /* Minimum number of free items on the stack allowed after an
475 allocation. This is to allow allocation and initialization
476 to be completed by functions that call expandGLRStack before the
477 stack is expanded, thus insuring that all necessary pointers get
478 properly redirected to new data. */
481 #if ! defined (YYSTACKEXPANDABLE) \
482 && (! defined (__cplusplus) || (YYLTYPE_IS_TRIVIAL && YYSTYPE_IS_TRIVIAL))
483 #define YYSTACKEXPANDABLE 1
485 #define YYSTACKEXPANDABLE 0
488 /** State numbers, as in LALR(1) machine */
489 typedef int yyStateNum
;
491 /** Rule numbers, as in LALR(1) machine */
492 typedef int yyRuleNum
;
494 /** Grammar symbol */
495 typedef short yySymbol
;
497 /** Item references, as in LALR(1) machine */
498 typedef short yyItemNum
;
500 typedef struct yyGLRState yyGLRState
;
501 typedef struct yySemanticOption yySemanticOption
;
502 typedef union yyGLRStackItem yyGLRStackItem
;
503 typedef struct yyGLRStack yyGLRStack
;
504 typedef struct yyGLRStateSet yyGLRStateSet
;
509 yyStateNum yylrState
;
513 yySemanticOption
* yyfirstVal
;
519 struct yyGLRStateSet
{
520 yyGLRState
** yystates
;
521 size_t yysize
, yycapacity
;
524 struct yySemanticOption
{
528 yySemanticOption
* yynext
;
531 union yyGLRStackItem
{
533 yySemanticOption yyoption
;
545 jmp_buf yyexception_buffer
;
546 yyGLRStackItem
* yyitems
;
547 yyGLRStackItem
* yynextFree
;
549 yyGLRState
* yysplitPoint
;
550 yyGLRState
* yylastDeleted
;
551 yyGLRStateSet yytops
;
554 static void yyinitGLRStack (yyGLRStack
* yystack
, size_t yysize
);
555 static void yyexpandGLRStack (yyGLRStack
* yystack
);
556 static void yyfreeGLRStack (yyGLRStack
* yystack
);
559 yyFail (yyGLRStack
* yystack
, const char* yyformat
, ...)
561 if (yyformat
!= NULL
)
565 va_start (yyap
, yyformat
);
566 yystack
->yyerrflag
= 1;
567 vsprintf (yymsg
, yyformat
, yyap
);
570 longjmp (yystack
->yyexception_buffer
, 1);
573 #if YYDEBUG || YYERROR_VERBOSE
574 /** A printable representation of TOKEN. Valid until next call to
576 static inline const char*
577 yytokenName (yySymbol yytoken
)
579 return yytname
[yytoken
];
583 /** Perform user action for rule number YYN, with RHS length YYRHSLEN,
584 * and top stack item YYVSP. YYLVALP points to place to put semantic
585 * value ($$), and yylocp points to place for location information
586 * (@$). Returns yyok for normal return, yyaccept for YYACCEPT,
587 * yyerr for YYERROR, yyabort for YYABORT. */
589 yyuserAction (yyRuleNum yyn
, int yyrhslen
, yyGLRStackItem
* yyvsp
,
590 YYSTYPE
* yyvalp
, YYLTYPE
* yylocp
, yyGLRStack
* yystack
593 /* Avoid `unused' warnings in there are no $n. */
598 *yyvalp
= yyval_default
;
599 *yylocp
= yyloc_default
;
603 *yyvalp
= yyvsp
[1-yyrhslen
].yystate
.yysemantics
.yysval
;
604 *yylocp
= yyvsp
[1-yyrhslen
].yystate
.yyloc
;
607 # define yyval (*yyvalp)
609 # define yyerrok (yystack->yyerrState = 0)
611 # define YYACCEPT return yyaccept
613 # define YYABORT return yyabort
615 # define YYERROR return yyerr
617 # define YYRECOVERING (yystack->yyerrState != 0)
619 # define yyclearin (yychar = *(yystack->yytokenp) = YYEMPTY)
621 # define YYBACKUP(Token, Value) \
623 yyerror ("syntax error: cannot back up"); \
642 /* Line __line__ of __file__. */
643 #line __oline__ "__ofile__"
648 yyuserMerge (int yyn
, YYSTYPE
* yy0
, YYSTYPE
* yy1
)
650 YYSTYPE yyval
= *yy0
;
651 /* `Use' the arguments. */
662 /* Bison grammar-table manipulation */
664 /** Number of symbols composing the right hand side of rule #RULE. */
666 yyrhsLength (yyRuleNum yyrule
)
671 /** Left-hand-side symbol for rule #RULE. */
672 static inline yySymbol
673 yylhsNonterm (yyRuleNum yyrule
)
678 /** True iff LR state STATE has only a default reduction (regardless
681 yyisDefaultedState (yyStateNum yystate
)
683 return yypact
[yystate
] == YYPACT_NINF
;
686 /** The default reduction for STATE, assuming it has one. */
687 static inline yyRuleNum
688 yydefaultAction (yyStateNum yystate
)
690 return yydefact
[yystate
];
693 /** Set *YYACTION to the action to take in YYSTATE on seeing YYTOKEN.
695 * R < 0: Reduce on rule -R.
697 * R > 0: Shift to state R.
698 * Set *CONFLICTS to a pointer into yyconfl to 0-terminated list of
699 * conflicting reductions.
702 yygetLRActions (yyStateNum yystate
, int yytoken
,
703 int* yyaction
, const short** yyconflicts
)
705 int yyindex
= yypact
[yystate
] + yytoken
;
706 if (yyindex
< 0 || YYLAST
< yyindex
|| yycheck
[yyindex
] != yytoken
)
708 *yyaction
= -yydefact
[yystate
];
709 *yyconflicts
= yyconfl
;
711 else if (yytable
[yyindex
] != YYTABLE_NINF
)
713 *yyaction
= yytable
[yyindex
];
714 *yyconflicts
= yyconfl
+ yyconflp
[yyindex
];
719 *yyconflicts
= yyconfl
+ yyconflp
[yyindex
];
723 static inline yyStateNum
724 yyLRgotoState (yyStateNum yystate
, yySymbol yylhs
)
727 yyr
= yypgoto
[yylhs
- YYNTOKENS
] + yystate
;
728 if (0 <= yyr
&& yyr
<= YYLAST
&& yycheck
[yyr
] == yystate
)
731 return yydefgoto
[yylhs
- YYNTOKENS
];
735 yyisShiftAction (int yyaction
)
741 yyisErrorAction (int yyaction
)
743 return yyaction
== 0;
748 /** True iff the semantic value of the edge leading to STATE is
751 yyhasResolvedValue (yyGLRState
* yystate
)
753 return yystate
->yyresolved
;
757 yyaddDeferredAction (yyGLRStack
* yystack
, yyGLRState
* yystate
,
758 yyGLRState
* rhs
, yyRuleNum yyrule
)
760 yySemanticOption
* yynewItem
;
761 yynewItem
= &yystack
->yynextFree
->yyoption
;
762 yystack
->yyspaceLeft
-= 1;
763 yystack
->yynextFree
+= 1;
764 yynewItem
->yyisState
= yyfalse
;
765 yynewItem
->yystate
= rhs
;
766 yynewItem
->yyrule
= yyrule
;
767 yynewItem
->yynext
= yystate
->yysemantics
.yyfirstVal
;
768 yystate
->yysemantics
.yyfirstVal
= yynewItem
;
769 if (yystack
->yyspaceLeft
< YYHEADROOM
)
770 yyexpandGLRStack (yystack
);
775 /** Initialize SET to a singleton set containing an empty stack. */
777 yyinitStateSet (yyGLRStateSet
* yyset
)
780 yyset
->yycapacity
= 16;
781 yyset
->yystates
= (yyGLRState
**) malloc (16 * sizeof (yyset
->yystates
[0]));
782 yyset
->yystates
[0] = NULL
;
785 static void yyfreeStateSet (yyGLRStateSet
* yyset
)
787 free (yyset
->yystates
);
790 /** Initialize STACK to a single empty stack, with total maximum
791 * capacity for all stacks of SIZE. */
793 yyinitGLRStack (yyGLRStack
* yystack
, size_t yysize
)
795 yystack
->yyerrflag
= 0;
796 yystack
->yyerrState
= 0;
798 yystack
->yyspaceLeft
= yysize
;
799 yystack
->yynextFree
= yystack
->yyitems
=
800 (yyGLRStackItem
*) malloc (yysize
* sizeof (yystack
->yynextFree
[0]));
801 yystack
->yysplitPoint
= NULL
;
802 yystack
->yylastDeleted
= NULL
;
803 yyinitStateSet (&yystack
->yytops
);
806 #define YYRELOC(YYFROMITEMS,YYTOITEMS,YYX,YYTYPE) \
807 &((YYTOITEMS) - ((YYFROMITEMS) - (yyGLRStackItem*) (YYX)))->YYTYPE
809 /** If STACK is expandable, extend it. WARNING: Pointers into the
810 stack from outside should be considered invalid after this call.
811 We always expand when there are 1 or fewer items left AFTER an
812 allocation, so that we can avoid having external pointers exist
813 across an allocation. */
815 yyexpandGLRStack (yyGLRStack
* yystack
)
817 #if YYSTACKEXPANDABLE
818 yyGLRStack yynewStack
;
819 yyGLRStackItem
* yyp0
, *yyp1
;
820 size_t yysize
, yynewSize
;
822 yysize
= yystack
->yynextFree
- yystack
->yyitems
;
823 if (YYMAXDEPTH
<= yysize
)
824 yyFail (yystack
, "parsing stack overflow (%d items)", yysize
);
825 yynewSize
= 2*yysize
;
826 if (YYMAXDEPTH
< yynewSize
)
827 yynewSize
= YYMAXDEPTH
;
828 yyinitGLRStack (&yynewStack
, yynewSize
);
829 for (yyp0
= yystack
->yyitems
, yyp1
= yynewStack
.yyitems
, yyn
= yysize
;
831 yyn
-= 1, yyp0
+= 1, yyp1
+= 1)
836 yyGLRState
* yys0
= &yyp0
->yystate
;
837 yyGLRState
* yys1
= &yyp1
->yystate
;
838 if (yys0
->yypred
!= NULL
)
840 YYRELOC (yyp0
, yyp1
, yys0
->yypred
, yystate
);
841 if (! yys0
->yyresolved
&& yys0
->yysemantics
.yyfirstVal
!= NULL
)
842 yys1
->yysemantics
.yyfirstVal
=
843 YYRELOC(yyp0
, yyp1
, yys0
->yysemantics
.yyfirstVal
, yyoption
);
847 yySemanticOption
* yyv0
= &yyp0
->yyoption
;
848 yySemanticOption
* yyv1
= &yyp1
->yyoption
;
849 if (yyv0
->yystate
!= NULL
)
850 yyv1
->yystate
= YYRELOC (yyp0
, yyp1
, yyv0
->yystate
, yystate
);
851 if (yyv0
->yynext
!= NULL
)
852 yyv1
->yynext
= YYRELOC (yyp0
, yyp1
, yyv0
->yynext
, yyoption
);
855 if (yystack
->yysplitPoint
!= NULL
)
856 yystack
->yysplitPoint
= YYRELOC (yystack
->yyitems
, yynewStack
.yyitems
,
857 yystack
->yysplitPoint
, yystate
);
859 for (yyn
= 0; yyn
< yystack
->yytops
.yysize
; yyn
+= 1)
860 if (yystack
->yytops
.yystates
[yyn
] != NULL
)
861 yystack
->yytops
.yystates
[yyn
] =
862 YYRELOC (yystack
->yyitems
, yynewStack
.yyitems
,
863 yystack
->yytops
.yystates
[yyn
], yystate
);
864 free (yystack
->yyitems
);
865 yystack
->yyitems
= yynewStack
.yyitems
;
866 yystack
->yynextFree
= yynewStack
.yynextFree
+ yysize
;
867 yystack
->yyspaceLeft
= yynewStack
.yyspaceLeft
- yysize
;
871 yyFail (yystack
, "parsing stack overflow (%d items)", yysize
);
877 yyfreeGLRStack (yyGLRStack
* yystack
)
879 free (yystack
->yyitems
);
880 yyfreeStateSet (&yystack
->yytops
);
883 /** Assuming that S is a GLRState somewhere on STACK, update the
884 * splitpoint of STACK, if needed, so that it is at least as deep as
887 yyupdateSplit (yyGLRStack
* yystack
, yyGLRState
* yys
)
889 if (yystack
->yysplitPoint
!= NULL
&& yystack
->yysplitPoint
> yys
)
890 yystack
->yysplitPoint
= yys
;
893 /** Invalidate stack #K in STACK. */
895 yymarkStackDeleted (yyGLRStack
* yystack
, int yyk
)
897 if (yystack
->yytops
.yystates
[yyk
] != NULL
)
898 yystack
->yylastDeleted
= yystack
->yytops
.yystates
[yyk
];
899 yystack
->yytops
.yystates
[yyk
] = NULL
;
902 /** Undelete the last stack that was marked as deleted. Can only be
903 done once after a deletion, and only when all other stacks have
906 yyundeleteLastStack (yyGLRStack
* yystack
)
908 if (yystack
->yylastDeleted
== NULL
|| yystack
->yytops
.yysize
!= 0)
910 yystack
->yytops
.yystates
[0] = yystack
->yylastDeleted
;
911 yystack
->yytops
.yysize
= 1;
912 YYDPRINTF ((stderr
, "Restoring last deleted stack as stack #0.\n"));
913 yystack
->yylastDeleted
= NULL
;
917 yyremoveDeletes (yyGLRStack
* yystack
)
921 while (yyj
< yystack
->yytops
.yysize
)
923 if (yystack
->yytops
.yystates
[yyi
] == NULL
)
926 YYDPRINTF ((stderr
, "Removing dead stacks.\n"));
927 yystack
->yytops
.yysize
-= 1;
931 yystack
->yytops
.yystates
[yyj
] = yystack
->yytops
.yystates
[yyi
];
933 YYDPRINTF ((stderr
, "Rename stack %d -> %d.\n", yyi
, yyj
));
940 /** Shift to a new state on stack #K of STACK, corresponding to LR state
941 * LRSTATE, at input position POSN, with (resolved) semantic value SVAL. */
943 yyglrShift (yyGLRStack
* yystack
, int yyk
, yyStateNum yylrState
, size_t yyposn
,
944 YYSTYPE yysval
, YYLTYPE
* yylocp
)
946 yyGLRStackItem
* yynewItem
;
948 yynewItem
= yystack
->yynextFree
;
949 yystack
->yynextFree
+= 1;
950 yystack
->yyspaceLeft
-= 1;
951 yynewItem
->yystate
.yyisState
= yytrue
;
952 yynewItem
->yystate
.yylrState
= yylrState
;
953 yynewItem
->yystate
.yyposn
= yyposn
;
954 yynewItem
->yystate
.yyresolved
= yytrue
;
955 yynewItem
->yystate
.yypred
= yystack
->yytops
.yystates
[yyk
];
956 yystack
->yytops
.yystates
[yyk
] = &yynewItem
->yystate
;
957 yynewItem
->yystate
.yysemantics
.yysval
= yysval
;
958 yynewItem
->yystate
.yyloc
= *yylocp
;
959 if (yystack
->yyspaceLeft
< YYHEADROOM
)
960 yyexpandGLRStack (yystack
);
963 /** Shift to a new state on stack #K of STACK, to a new state
964 * corresponding to LR state LRSTATE, at input position POSN, with
965 * the (unresolved) semantic value of RHS under the action for RULE. */
967 yyglrShiftDefer (yyGLRStack
* yystack
, int yyk
, yyStateNum yylrState
,
968 size_t yyposn
, yyGLRState
* rhs
, yyRuleNum yyrule
)
970 yyGLRStackItem
* yynewItem
;
972 yynewItem
= yystack
->yynextFree
;
973 yynewItem
->yystate
.yyisState
= yytrue
;
974 yynewItem
->yystate
.yylrState
= yylrState
;
975 yynewItem
->yystate
.yyposn
= yyposn
;
976 yynewItem
->yystate
.yyresolved
= yyfalse
;
977 yynewItem
->yystate
.yypred
= yystack
->yytops
.yystates
[yyk
];
978 yynewItem
->yystate
.yysemantics
.yyfirstVal
= NULL
;
979 yystack
->yytops
.yystates
[yyk
] = &yynewItem
->yystate
;
980 yystack
->yynextFree
+= 1;
981 yystack
->yyspaceLeft
-= 1;
982 yyaddDeferredAction (yystack
, &yynewItem
->yystate
, rhs
, yyrule
);
985 /** Pop the symbols consumed by reduction #RULE from the top of stack
986 * #K of STACK, and perform the appropriate semantic action on their
987 * semantic values. Assumes that all ambiguities in semantic values
988 * have been previously resolved. Set *VALP to the resulting value,
989 * and *LOCP to the computed location (if any). Return value is as
992 yydoAction (yyGLRStack
* yystack
, int yyk
, yyRuleNum yyrule
,
993 YYSTYPE
* yyvalp
, YYLTYPE
* yylocp YY_USER_FORMALS
)
995 int yynrhs
= yyrhsLength (yyrule
);
997 if (yystack
->yysplitPoint
== NULL
)
999 /* Standard special case: single stack. */
1000 yyGLRStackItem
* rhs
= (yyGLRStackItem
*) yystack
->yytops
.yystates
[yyk
];
1002 yystack
->yynextFree
-= yynrhs
;
1003 yystack
->yyspaceLeft
+= yynrhs
;
1004 yystack
->yytops
.yystates
[0] = & yystack
->yynextFree
[-1].yystate
;
1007 *yyvalp
= yyval_default
;
1008 *yylocp
= yyloc_default
;
1012 *yyvalp
= rhs
[1-yynrhs
].yystate
.yysemantics
.yysval
;
1013 *yylocp
= rhs
[1-yynrhs
].yystate
.yyloc
;
1015 return yyuserAction (yyrule
, yynrhs
, rhs
,
1016 yyvalp
, yylocp
, yystack YY_USER_ARGS
);
1022 yyGLRStackItem yyrhsVals
[YYMAXRHS
];
1023 for (yyi
= yynrhs
-1, yys
= yystack
->yytops
.yystates
[yyk
]; 0 <= yyi
;
1024 yyi
-= 1, yys
= yys
->yypred
)
1026 assert (yys
->yypred
!= NULL
);
1027 yyrhsVals
[yyi
].yystate
.yyresolved
= yytrue
;
1028 yyrhsVals
[yyi
].yystate
.yysemantics
.yysval
= yys
->yysemantics
.yysval
;
1029 yyrhsVals
[yyi
].yystate
.yyloc
= yys
->yyloc
;
1031 yyupdateSplit (yystack
, yys
);
1032 yystack
->yytops
.yystates
[yyk
] = yys
;
1035 *yyvalp
= yyval_default
;
1036 *yylocp
= yyloc_default
;
1040 *yyvalp
= yyrhsVals
[0].yystate
.yysemantics
.yysval
;
1041 *yylocp
= yyrhsVals
[0].yystate
.yyloc
;
1043 return yyuserAction (yyrule
, yynrhs
, yyrhsVals
+ (yynrhs
-1),
1044 yyvalp
, yylocp
, yystack YY_USER_ARGS
);
1049 # define YY_REDUCE_PRINT(K, Rule)
1051 # define YY_REDUCE_PRINT(K, Rule) \
1054 yy_reduce_print (K, Rule); \
1057 /*----------------------------------------------------------.
1058 | Report that the RULE is going to be reduced on stack #K. |
1059 `----------------------------------------------------------*/
1062 yy_reduce_print (size_t yyk
, yyRuleNum yyrule
)
1065 YYDPRINTF ((stderr
, "Reducing stack %d by rule %d (line %d),",
1066 yyk
, yyrule
- 1, yyrline
[yyrule
]));
1067 /* Print the symbols being reduced, and their result. */
1068 for (yyi
= yyprhs
[yyrule
]; 0 <= yyrhs
[yyi
]; yyi
++)
1069 YYFPRINTF (stderr
, "%s ", yytokenName (yyrhs
[yyi
]));
1070 YYFPRINTF (stderr
, " -> %s\n", yytokenName (yyr1
[yyrule
]));
1074 /** Pop items off stack #K of STACK according to grammar rule RULE,
1075 * and push back on the resulting nonterminal symbol. Perform the
1076 * semantic action associated with RULE and store its value with the
1077 * newly pushed state, if FORCEEVAL or if STACK is currently
1078 * unambiguous. Otherwise, store the deferred semantic action with
1079 * the new state. If the new state would have an identical input
1080 * position, LR state, and predecessor to an existing state on the stack,
1081 * it is identified with that existing state, eliminating stack #K from
1082 * the STACK. In this case, the (necessarily deferred) semantic value is
1083 * added to the options for the existing state's semantic value.
1085 static inline YYRESULTTAG
1086 yyglrReduce (yyGLRStack
* yystack
, size_t yyk
, yyRuleNum yyrule
,
1087 bool yyforceEval YY_USER_FORMALS
)
1089 size_t yyposn
= yystack
->yytops
.yystates
[yyk
]->yyposn
;
1091 if (yyforceEval
|| yystack
->yysplitPoint
== NULL
)
1096 YY_REDUCE_PRINT (yyk
, yyrule
);
1097 YYCHK (yydoAction (yystack
, yyk
, yyrule
, &yysval
, &yyloc YY_USER_ARGS
));
1098 yyglrShift (yystack
, yyk
,
1099 yyLRgotoState (yystack
->yytops
.yystates
[yyk
]->yylrState
,
1100 yylhsNonterm (yyrule
)),
1101 yyposn
, yysval
, &yyloc
);
1102 YYDPRINTF ((stderr
, "Stack %d entering state %d\n",
1103 yyk
, yystack
->yytops
.yystates
[yyk
]->yylrState
));
1109 yyGLRState
* yys
, *yys0
= yystack
->yytops
.yystates
[yyk
];
1110 yyStateNum yynewLRState
;
1112 for (yys
= yystack
->yytops
.yystates
[yyk
], yyn
= yyrhsLength (yyrule
);
1116 assert (yys
!= NULL
);
1118 yyupdateSplit (yystack
, yys
);
1119 yynewLRState
= yyLRgotoState (yys
->yylrState
, yylhsNonterm (yyrule
));
1121 "Reduced stack %d by rule #%d; action deferred. "
1122 "Now in state %d.\n",
1123 yyk
, yyrule
-1, yynewLRState
));
1124 for (yyi
= 0; yyi
< yystack
->yytops
.yysize
; yyi
+= 1)
1125 if (yyi
!= yyk
&& yystack
->yytops
.yystates
[yyi
] != NULL
)
1127 yyGLRState
* yyp
, *yysplit
= yystack
->yysplitPoint
;
1128 yyp
= yystack
->yytops
.yystates
[yyi
];
1129 while (yyp
!= yys
&& yyp
!= yysplit
&& yyp
->yyposn
>= yyposn
)
1131 if (yyp
->yylrState
== yynewLRState
&& yyp
->yypred
== yys
)
1133 yyaddDeferredAction (yystack
, yyp
, yys0
, yyrule
);
1134 yymarkStackDeleted (yystack
, yyk
);
1135 YYDPRINTF ((stderr
, "Merging stack %d into stack %d.\n",
1142 yystack
->yytops
.yystates
[yyk
] = yys
;
1143 yyglrShiftDefer (yystack
, yyk
, yynewLRState
, yyposn
, yys0
, yyrule
);
1149 yysplitStack (yyGLRStack
* yystack
, int yyk
)
1151 if (yystack
->yysplitPoint
== NULL
)
1154 yystack
->yysplitPoint
= yystack
->yytops
.yystates
[yyk
];
1156 if (yystack
->yytops
.yysize
>= yystack
->yytops
.yycapacity
)
1158 yystack
->yytops
.yycapacity
*= 2;
1159 yystack
->yytops
.yystates
=
1160 (yyGLRState
**) realloc (yystack
->yytops
.yystates
,
1161 yystack
->yytops
.yycapacity
1162 * sizeof (yyGLRState
*));
1164 yystack
->yytops
.yystates
[yystack
->yytops
.yysize
]
1165 = yystack
->yytops
.yystates
[yyk
];
1166 yystack
->yytops
.yysize
+= 1;
1167 return yystack
->yytops
.yysize
-1;
1170 /** True iff Y0 and Y1 represent identical options at the top level.
1171 * That is, they represent the same rule applied to RHS symbols
1172 * that produce the same terminal symbols. */
1174 yyidenticalOptions (yySemanticOption
* yyy0
, yySemanticOption
* yyy1
)
1176 if (yyy0
->yyrule
== yyy1
->yyrule
)
1178 yyGLRState
*yys0
, *yys1
;
1180 for (yys0
= yyy0
->yystate
, yys1
= yyy1
->yystate
,
1181 yyn
= yyrhsLength (yyy0
->yyrule
);
1183 yys0
= yys0
->yypred
, yys1
= yys1
->yypred
, yyn
-= 1)
1184 if (yys0
->yyposn
!= yys1
->yyposn
)
1192 /** Assuming identicalOptions (Y0,Y1), (destructively) merge the
1193 * alternative semantic values for the RHS-symbols of Y1 into the
1194 * corresponding semantic value sets of the symbols of Y0. */
1196 yymergeOptionSets (yySemanticOption
* yyy0
, yySemanticOption
* yyy1
)
1198 yyGLRState
*yys0
, *yys1
;
1200 for (yys0
= yyy0
->yystate
, yys1
= yyy1
->yystate
,
1201 yyn
= yyrhsLength (yyy0
->yyrule
);
1203 yys0
= yys0
->yypred
, yys1
= yys1
->yypred
, yyn
-= 1)
1206 else if (! yys0
->yyresolved
&& ! yys1
->yyresolved
)
1208 yySemanticOption
* yyz
;
1209 for (yyz
= yys0
->yysemantics
.yyfirstVal
; yyz
->yynext
!= NULL
;
1212 yyz
->yynext
= yys1
->yysemantics
.yyfirstVal
;
1216 /** Y0 and Y1 represent two possible actions to take in a given
1217 * parsing state; return 0 if no combination is possible,
1218 * 1 if user-mergeable, 2 if Y0 is preferred, 3 if Y1 is preferred. */
1220 yypreference (yySemanticOption
* y0
, yySemanticOption
* y1
)
1222 yyRuleNum r0
= y0
->yyrule
, r1
= y1
->yyrule
;
1223 int p0
= yydprec
[r0
], p1
= yydprec
[r1
];
1227 if (yymerger
[r0
] == 0 || yymerger
[r0
] != yymerger
[r1
])
1232 if (p0
== 0 || p1
== 0)
1241 static YYRESULTTAG
yyresolveValue (yySemanticOption
* yyoptionList
,
1242 yyGLRStack
* yystack
, YYSTYPE
* yyvalp
,
1243 YYLTYPE
* yylocp YY_USER_FORMALS
);
1246 yyresolveStates (yyGLRState
* yys
, int yyn
, yyGLRStack
* yystack YY_USER_FORMALS
)
1251 assert (yys
->yypred
!= NULL
);
1252 yyflag
= yyresolveStates (yys
->yypred
, yyn
-1, yystack YY_USER_ARGS
);
1255 if (! yys
->yyresolved
)
1257 yyflag
= yyresolveValue (yys
->yysemantics
.yyfirstVal
, yystack
,
1258 &yys
->yysemantics
.yysval
, &yys
->yyloc
1262 yys
->yyresolved
= yytrue
;
1269 yyresolveAction (yySemanticOption
* yyopt
, yyGLRStack
* yystack
,
1270 YYSTYPE
* yyvalp
, YYLTYPE
* yylocp YY_USER_FORMALS
)
1272 yyGLRStackItem yyrhsVals
[YYMAXRHS
];
1276 yynrhs
= yyrhsLength (yyopt
->yyrule
);
1277 YYCHK (yyresolveStates (yyopt
->yystate
, yynrhs
, yystack YY_USER_ARGS
));
1278 for (yyi
= yynrhs
-1, yys
= yyopt
->yystate
; 0 <= yyi
;
1279 yyi
-= 1, yys
= yys
->yypred
)
1281 assert (yys
->yypred
!= NULL
);
1282 yyrhsVals
[yyi
].yystate
.yyresolved
= yytrue
;
1283 yyrhsVals
[yyi
].yystate
.yysemantics
.yysval
= yys
->yysemantics
.yysval
;
1284 yyrhsVals
[yyi
].yystate
.yyloc
= yys
->yyloc
;
1286 return yyuserAction (yyopt
->yyrule
, yynrhs
, yyrhsVals
+ (yynrhs
-1),
1287 yyvalp
, yylocp
, yystack YY_USER_ARGS
);
1291 static yyGLRState YYLEFTMOST_STATE
=
1293 0, 0, -1, NULL
, 0, { NULL
},
1296 #if YYLTYPE_IS_TRIVIAL
1297 ]b4_location_if([ 0, 0, 0, 0])[
1303 yyreportTree (yySemanticOption
* yyx
, int yyindent
)
1305 int yynrhs
= yyrhsLength (yyx
->yyrule
);
1308 yyGLRState
* yystates
[YYMAXRHS
];
1310 for (yyi
= yynrhs
, yys
= yyx
->yystate
; 0 < yyi
; yyi
-= 1, yys
= yys
->yypred
)
1311 yystates
[yyi
] = yys
;
1313 yystates
[0] = &YYLEFTMOST_STATE
;
1317 if (yyx
->yystate
->yyposn
< yys
->yyposn
+ 1)
1318 YYFPRINTF (stderr
, "%*s%s -> <Rule %d, empty>\n",
1319 yyindent
, "", yytokenName (yylhsNonterm (yyx
->yyrule
)),
1322 YYFPRINTF (stderr
, "%*s%s -> <Rule %d, tokens %d .. %d>\n",
1323 yyindent
, "", yytokenName (yylhsNonterm (yyx
->yyrule
)),
1324 yyx
->yyrule
, yys
->yyposn
+1, yyx
->yystate
->yyposn
);
1325 for (yyi
= 1; yyi
<= yynrhs
; yyi
+= 1)
1327 if (yystates
[yyi
]->yyresolved
)
1329 if (yystates
[yyi
-1]->yyposn
+1 > yystates
[yyi
]->yyposn
)
1330 YYFPRINTF (stderr
, "%*s%s <empty>\n", yyindent
+2, "",
1331 yytokenName (yyrhs
[yyprhs
[yyx
->yyrule
]+yyi
-1]));
1333 YYFPRINTF (stderr
, "%*s%s <tokens %d .. %d>\n", yyindent
+2, "",
1334 yytokenName (yyrhs
[yyprhs
[yyx
->yyrule
]+yyi
-1]),
1335 yystates
[yyi
-1]->yyposn
+1, yystates
[yyi
]->yyposn
);
1338 yyreportTree (yystates
[yyi
]->yysemantics
.yyfirstVal
, yyindent
+2);
1344 yyreportAmbiguity (yySemanticOption
* yyx0
, yySemanticOption
* yyx1
,
1345 yyGLRStack
* yystack
)
1347 /* `Unused' warnings. */
1352 YYFPRINTF (stderr
, "Ambiguity detected.\n");
1353 YYFPRINTF (stderr
, "Option 1,\n");
1354 yyreportTree (yyx0
, 2);
1355 YYFPRINTF (stderr
, "\nOption 2,\n");
1356 yyreportTree (yyx1
, 2);
1357 YYFPRINTF (stderr
, "\n");
1359 yyFail (yystack
, "ambiguity detected");
1363 /** Resolve the ambiguity represented by OPTIONLIST, perform the indicated
1364 * actions, and return the result. */
1366 yyresolveValue (yySemanticOption
* yyoptionList
, yyGLRStack
* yystack
,
1367 YYSTYPE
* yyvalp
, YYLTYPE
* yylocp YY_USER_FORMALS
)
1369 yySemanticOption
* yybest
;
1370 yySemanticOption
* yyp
;
1373 yybest
= yyoptionList
;
1375 for (yyp
= yyoptionList
->yynext
; yyp
!= NULL
; yyp
= yyp
->yynext
)
1377 if (yyidenticalOptions (yybest
, yyp
))
1378 yymergeOptionSets (yybest
, yyp
);
1380 switch (yypreference (yybest
, yyp
))
1383 yyreportAmbiguity (yybest
, yyp
, yystack
);
1399 int yyprec
= yydprec
[yybest
->yyrule
];
1400 YYCHK (yyresolveAction (yybest
, yystack
, yyvalp
, yylocp YY_USER_ARGS
));
1401 for (yyp
= yybest
->yynext
; yyp
!= NULL
; yyp
= yyp
->yynext
)
1403 if (yyprec
== yydprec
[yyp
->yyrule
])
1407 YYCHK (yyresolveAction (yyp
, yystack
, &yyval1
, &yydummy YY_USER_ARGS
));
1408 *yyvalp
= yyuserMerge (yymerger
[yyp
->yyrule
], yyvalp
, &yyval1
);
1414 return yyresolveAction (yybest
, yystack
, yyvalp
, yylocp YY_USER_ARGS
);
1418 yyresolveStack (yyGLRStack
* yystack YY_USER_FORMALS
)
1420 if (yystack
->yysplitPoint
!= NULL
)
1425 for (yyn
= 0, yys
= yystack
->yytops
.yystates
[0];
1426 yys
!= yystack
->yysplitPoint
;
1427 yys
= yys
->yypred
, yyn
+= 1)
1429 YYCHK (yyresolveStates (yystack
->yytops
.yystates
[0], yyn
, yystack
1436 yycompressStack (yyGLRStack
* yystack
)
1438 yyGLRState
* yyp
, *yyq
, *yyr
;
1440 if (yystack
->yytops
.yysize
!= 1 || yystack
->yysplitPoint
== NULL
)
1443 for (yyp
= yystack
->yytops
.yystates
[0], yyq
= yyp
->yypred
, yyr
= NULL
;
1444 yyp
!= yystack
->yysplitPoint
;
1445 yyr
= yyp
, yyp
= yyq
, yyq
= yyp
->yypred
)
1448 yystack
->yyspaceLeft
+= yystack
->yynextFree
- yystack
->yyitems
;
1449 yystack
->yynextFree
= ((yyGLRStackItem
*) yystack
->yysplitPoint
) + 1;
1450 yystack
->yyspaceLeft
-= yystack
->yynextFree
- yystack
->yyitems
;
1451 yystack
->yysplitPoint
= NULL
;
1452 yystack
->yylastDeleted
= NULL
;
1456 yystack
->yynextFree
->yystate
= *yyr
;
1458 yystack
->yynextFree
->yystate
.yypred
= & yystack
->yynextFree
[-1].yystate
;
1459 yystack
->yytops
.yystates
[0] = &yystack
->yynextFree
->yystate
;
1460 yystack
->yynextFree
+= 1;
1461 yystack
->yyspaceLeft
-= 1;
1466 yyprocessOneStack (yyGLRStack
* yystack
, int yyk
,
1467 size_t yyposn
, YYSTYPE
* yylvalp
, YYLTYPE
* yyllocp
1471 const short* yyconflicts
;
1473 yySymbol
* const yytokenp
= yystack
->yytokenp
;
1475 while (yystack
->yytops
.yystates
[yyk
] != NULL
)
1477 yyStateNum yystate
= yystack
->yytops
.yystates
[yyk
]->yylrState
;
1479 assert (yystate
!= YYFINAL
);
1480 if (yyisDefaultedState (yystate
))
1482 yyrule
= yydefaultAction (yystate
);
1485 YYDPRINTF ((stderr
, "Stack %d dies.\n", yyk
));
1486 yymarkStackDeleted (yystack
, yyk
);
1489 YYCHK (yyglrReduce (yystack
, yyk
, yyrule
, yyfalse YY_USER_ARGS
));
1493 if (*yytokenp
== YYEMPTY
)
1495 YYDPRINTF ((stderr
, "Reading a token: "));
1497 *yytokenp
= YYTRANSLATE(yychar
);
1498 YYDPRINTF ((stderr
, "Next token is %s\n",
1499 yytokenName (*yytokenp
)));
1501 yygetLRActions (yystate
, *yytokenp
, &yyaction
, &yyconflicts
);
1503 while (*yyconflicts
!= 0)
1505 int yynewStack
= yysplitStack (yystack
, yyk
);
1506 YYDPRINTF ((stderr
, "Splitting off stack %d from %d.\n",
1508 YYCHK (yyglrReduce (yystack
, yynewStack
,
1509 *yyconflicts
, yyfalse YY_USER_ARGS
));
1510 YYCHK (yyprocessOneStack (yystack
, yynewStack
, yyposn
,
1511 yylvalp
, yyllocp YY_USER_ARGS
));
1515 if (yyisShiftAction (yyaction
))
1517 YYDPRINTF ((stderr
, "Shifting token %s on stack %d, ",
1518 yytokenName (*yytokenp
), yyk
));
1519 yyglrShift (yystack
, yyk
, yyaction
, yyposn
+1, *yylvalp
, yyllocp
);
1520 YYDPRINTF ((stderr
, "which is now in state #%d\n",
1521 yystack
->yytops
.yystates
[yyk
]->yylrState
));
1524 else if (yyisErrorAction (yyaction
))
1526 YYDPRINTF ((stderr
, "Stack %d dies.\n", yyk
));
1527 yymarkStackDeleted (yystack
, yyk
);
1531 YYCHK (yyglrReduce (yystack
, yyk
, -yyaction
, yyfalse YY_USER_ARGS
));
1538 yyreportParseError (yyGLRStack
* yystack
, YYSTYPE
* yylvalp
, YYLTYPE
* yyllocp
)
1540 /* `Unused' warnings. */
1544 if (yystack
->yyerrState
== 0)
1547 yySymbol
* const yytokenp
= yystack
->yytokenp
;
1548 int yyn
, yyx
, yycount
;
1550 const char* yyprefix
;
1553 yyn
= yypact
[yystack
->yytops
.yystates
[0]->yylrState
];
1554 if (YYPACT_NINF
< yyn
&& yyn
< YYLAST
)
1557 /* Start YYX at -YYN if negative to avoid negative indexes in
1559 yysize
= sizeof ("parse error, unexpected ")
1560 + strlen (yytokenName (*yytokenp
));
1561 yyprefix
= ", expecting ";
1562 for (yyx
= yyn
< 0 ? -yyn
: 0; yyx
< yytname_size
&& yycount
<= 5;
1564 if (yycheck
[yyx
+ yyn
] == yyx
&& yyx
!= YYTERROR
)
1565 yysize
+= strlen (yytokenName (yyx
)) + strlen (yyprefix
),
1566 yycount
+= 1, yyprefix
= " or ";
1567 yymsg
= yyp
= (char*) malloc (yysize
);
1568 sprintf (yyp
, "parse error, unexpected %s",
1569 yytokenName (*yytokenp
));
1570 yyp
+= strlen (yyp
);
1573 yyprefix
= ", expecting ";
1574 for (yyx
= yyn
< 0 ? -yyn
: 0; yyx
< yytname_size
; yyx
+= 1)
1575 if (yycheck
[yyx
+ yyn
] == yyx
&& yyx
!= YYTERROR
)
1577 sprintf (yyp
, "%s%s", yyprefix
, yytokenName (yyx
));
1578 yyp
+= strlen (yyp
);
1587 yyerror ("parse error");
1592 /* Recover from a syntax error on YYSTACK, assuming that YYTOKENP,
1593 YYLVALP, and YYLLOCP point to the syntactic category, semantic
1594 value, and location of the lookahead. */
1596 yyrecoverParseError (yyGLRStack
* yystack
, YYSTYPE
* yylvalp
, YYLTYPE
* yyllocp
)
1598 yySymbol
* const yytokenp
= yystack
->yytokenp
;
1602 if (yystack
->yyerrState
== 0)
1603 yystack
->yyerrState
= 3;
1604 else if (yystack
->yyerrState
== 3)
1605 /* We just shifted the error token and (perhaps) took some
1606 reductions. Skip tokens until we can proceed. */
1609 if (*yytokenp
== YYEOF
)
1610 yyFail (yystack
, NULL
);
1611 if (*yytokenp
!= YYEMPTY
)
1612 YYDPRINTF ((stderr
, "Discarding token %s\n",
1613 yytokenName (*yytokenp
)));
1614 YYDPRINTF ((stderr
, "Reading a token: "));
1616 *yytokenp
= YYTRANSLATE (yychar
);
1617 YYDPRINTF ((stderr
, "Next token is %s\n", yytokenName (*yytokenp
)));
1618 yyj
= yypact
[yystack
->yytops
.yystates
[0]->yylrState
];
1619 if (yyj
== YYPACT_NINF
)
1620 /* Something's not right; we shouldn't be here. */
1621 yyFail (yystack
, NULL
);
1623 if (yyj
< 0 || YYLAST
< yyj
|| yycheck
[yyj
] != *yytokenp
)
1625 if (yydefact
[yystack
->yytops
.yystates
[0]->yylrState
] != 0)
1628 else if (yytable
[yyj
] != 0 && yytable
[yyj
] != YYTABLE_NINF
)
1632 /* Reduce to one stack. */
1633 for (yyk
= 0; yyk
< yystack
->yytops
.yysize
; yyk
+= 1)
1634 if (yystack
->yytops
.yystates
[yyk
] != NULL
)
1636 if (yyk
>= yystack
->yytops
.yysize
)
1637 yyFail (yystack
, NULL
);
1638 for (yyk
+= 1; yyk
< yystack
->yytops
.yysize
; yyk
+= 1)
1639 yymarkStackDeleted (yystack
, yyk
);
1640 yyremoveDeletes (yystack
);
1641 yycompressStack (yystack
);
1643 /* Now pop stack until we find a state that shifts the error token. */
1644 while (yystack
->yytops
.yystates
[0] != NULL
)
1646 yyj
= yypact
[yystack
->yytops
.yystates
[0]->yylrState
] + YYTERROR
;
1647 if (yyj
!= YYPACT_NINF
+ YYTERROR
&& yyj
>= 0 && yyj
<= YYLAST
&&
1648 yycheck
[yyj
] == YYTERROR
&& yyisShiftAction (yytable
[yyj
]))
1650 yyglrShift (yystack
, 0, yytable
[yyj
],
1651 yystack
->yytops
.yystates
[0]->yyposn
, *yylvalp
, yyllocp
);
1654 yystack
->yytops
.yystates
[0] = yystack
->yytops
.yystates
[0]->yypred
;
1655 yystack
->yynextFree
-= 1;
1656 yystack
->yyspaceLeft
+= 1;
1658 if (yystack
->yytops
.yystates
[0] == NULL
)
1659 yyFail (yystack
, NULL
);
1662 #define YYCHK1(YYE) \
1668 yystack.yyerrflag = 1; \
1671 yystack.yyerrflag = 0; \
1674 goto yyuser_error; \
1683 ]b4_c_ansi_function_def([yyparse
], [int], b4_parse_param
)[
1693 #define yychar (yystack.yyrawchar)
1696 YYSTYPE
* const yylvalp
= &yylval
;
1697 YYLTYPE
* const yyllocp
= &yylloc
;
1699 yyinitGLRStack (&yystack
, YYINITDEPTH
);
1700 yystack
.yytokenp
= &yytoken
;
1702 YYDPRINTF ((stderr
, "Starting parse\n"));
1704 if (setjmp (yystack
.yyexception_buffer
) != 0)
1707 yyglrShift (&yystack
, 0, 0, 0, yyval_default
, &yyloc_default
);
1713 /* For efficiency, we have two loops, the first of which is
1714 specialized to deterministic operation (single stack, no
1715 potential ambiguity). */
1722 const short* yyconflicts
;
1724 yyStateNum yystate
= yystack
.yytops
.yystates
[0]->yylrState
;
1725 if (yystate
== YYFINAL
)
1727 if (yyisDefaultedState (yystate
))
1729 yyrule
= yydefaultAction (yystate
);
1732 yyreportParseError (&yystack
, yylvalp
, yyllocp
);
1735 YYCHK1 (yyglrReduce (&yystack
, 0, yyrule
, yytrue YY_USER_ARGS
));
1739 if (yytoken
== YYEMPTY
)
1741 YYDPRINTF ((stderr
, "Reading a token: "));
1743 yytoken
= YYTRANSLATE (yychar
);
1744 YYDPRINTF ((stderr
, "Next token is %s\n",
1745 yytokenName (yytoken
)));
1747 yygetLRActions (yystate
, yytoken
, &yyaction
, &yyconflicts
);
1748 if (*yyconflicts
!= 0)
1750 if (yyisShiftAction (yyaction
))
1752 YYDPRINTF ((stderr
, "Shifting token %s, ",
1753 yytokenName (yytoken
)));
1754 if (yytoken
!= YYEOF
)
1757 yyglrShift (&yystack
, 0, yyaction
, yyposn
, yylval
, yyllocp
);
1758 if (0 < yystack
.yyerrState
)
1759 yystack
.yyerrState
-= 1;
1760 YYDPRINTF ((stderr
, "Entering state %d\n",
1761 yystack
.yytops
.yystates
[0]->yylrState
));
1763 else if (yyisErrorAction (yyaction
))
1765 yyreportParseError (&yystack
, yylvalp
, yyllocp
);
1769 YYCHK1 (yyglrReduce (&yystack
, 0, -yyaction
, yytrue YY_USER_ARGS
));
1776 int yyn
= yystack
.yytops
.yysize
;
1777 for (yys
= 0; yys
< yyn
; yys
+= 1)
1778 YYCHK1 (yyprocessOneStack (&yystack
, yys
, yyposn
,
1779 yylvalp
, yyllocp YY_USER_ARGS
));
1782 yyremoveDeletes (&yystack
);
1783 if (yystack
.yytops
.yysize
== 0)
1785 yyundeleteLastStack (&yystack
);
1786 if (yystack
.yytops
.yysize
== 0)
1787 yyFail (&yystack
, "parse error");
1788 YYCHK1 (yyresolveStack (&yystack YY_USER_ARGS
));
1789 YYDPRINTF ((stderr
, "Returning to deterministic operation.\n"));
1790 yyreportParseError (&yystack
, yylvalp
, yyllocp
);
1793 else if (yystack
.yytops
.yysize
== 1)
1795 YYCHK1 (yyresolveStack (&yystack YY_USER_ARGS
));
1796 YYDPRINTF ((stderr
, "Returning to deterministic operation.\n"));
1797 yycompressStack (&yystack
);
1803 yyrecoverParseError (&yystack
, yylvalp
, yyllocp
);
1804 yyposn
= yystack
.yytops
.yystates
[0]->yyposn
;
1809 yyfreeGLRStack (&yystack
);
1810 return yystack
.yyerrflag
;
1813 /* DEBUGGING ONLY */
1814 static void yypstack (yyGLRStack
* yystack
, int yyk
) ATTRIBUTE_UNUSED
;
1815 static void yypdumpstack (yyGLRStack
* yystack
) ATTRIBUTE_UNUSED
;
1818 yy_yypstack (yyGLRState
* yys
)
1822 yy_yypstack (yys
->yypred
);
1823 fprintf (stderr
, " -> ");
1825 fprintf (stderr
, "%d@%lu", yys
->yylrState
, (unsigned long) yys
->yyposn
);
1829 yypstates (yyGLRState
* yyst
)
1832 fprintf (stderr
, "<null>");
1835 fprintf (stderr
, "\n");
1839 yypstack (yyGLRStack
* yystack
, int yyk
)
1841 yypstates (yystack
->yytops
.yystates
[yyk
]);
1844 #define YYINDEX(YYX) \
1845 ((YYX) == NULL ? -1 : (yyGLRStackItem*) (YYX) - yystack->yyitems)
1849 yypdumpstack (yyGLRStack
* yystack
)
1851 yyGLRStackItem
* yyp
;
1853 for (yyp
= yystack
->yyitems
; yyp
< yystack
->yynextFree
; yyp
+= 1)
1855 fprintf (stderr
, "%3lu. ", (unsigned long) (yyp
- yystack
->yyitems
));
1858 fprintf (stderr
, "Res: %d, LR State: %d, posn: %lu, pred: %ld",
1859 yyp
->yystate
.yyresolved
, yyp
->yystate
.yylrState
,
1860 (unsigned long) yyp
->yystate
.yyposn
,
1861 (long) YYINDEX (yyp
->yystate
.yypred
));
1862 if (! yyp
->yystate
.yyresolved
)
1863 fprintf (stderr
, ", firstVal: %ld",
1864 (long) YYINDEX (yyp
->yystate
.yysemantics
.yyfirstVal
));
1868 fprintf (stderr
, "Option. rule: %d, state: %ld, next: %ld",
1869 yyp
->yyoption
.yyrule
,
1870 (long) YYINDEX (yyp
->yyoption
.yystate
),
1871 (long) YYINDEX (yyp
->yyoption
.yynext
));
1873 fprintf (stderr
, "\n");
1875 fprintf (stderr
, "Tops:");
1876 for (yyi
= 0; yyi
< yystack
->yytops
.yysize
; yyi
+= 1)
1877 fprintf (stderr
, "%lu: %ld; ", (unsigned long) yyi
,
1878 (long) YYINDEX (yystack
->yytops
.yystates
[yyi
]));
1879 fprintf (stderr
, "\n");
1884 m4_if(b4_defines_flag
, 0, [],
1885 [#output "b4_output_header_name"
1886 b4_copyright([Skeleton parser
for GLR parsing with Bison
], [2002])
1887 #ifndef b4_header_guard
1888 # define b4_header_guard
1890 b4_token_defines(b4_tokens
)
1893 m4_ifdef([b4_stype
],
1894 [#line b4_stype_line "b4_filename"
1895 typedef union b4_stype yystype
;
1896 /* Line __line__ of __file__. */
1897 #line __oline__ "__ofile__"],
1898 [typedef int yystype
;])
1899 # define YYSTYPE yystype
1903 [extern YYSTYPE b4_prefix
[]lval
;])
1907 typedef struct yyltype
1914 # define YYLTYPE yyltype
1918 [extern YYLTYPE b4_prefix
[]lloc
;])
1920 #endif /* not b4_header_guard */