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
22 # b4_lhs_value([TYPE])
23 # --------------------
24 # Expansion of $<TYPE>$.
25 m4_define([b4_lhs_value
],
26 [(*yyvalp
)[]m4_ifval([$
1], [.$
1])])
29 # b4_rhs_value(RULE-LENGTH, NUM, [TYPE])
30 # --------------------------------------
31 # Expansion of $<TYPE>NUM, where the current rule has RULE-LENGTH
33 m4_define([b4_rhs_value
],
34 [yyvsp@
<:@
m4_eval([$
2 - $
1])@
:>@
.yystate
.yysemantics
.yysval
[]m4_ifval([$
3], [.$
3])])
42 # b4_location_if(IF-TRUE, IF-FALSE)
43 # ---------------------------------
44 # Expand IF-TRUE, if locations are used, IF-FALSE otherwise.
45 m4_define([b4_location_if
],
46 [m4_if(b4_locations_flag
, [1],
54 m4_define([b4_lhs_location
],
58 # b4_rhs_location(RULE-LENGTH, NUM)
59 # ---------------------------------
60 # Expansion of @NUM, where the current rule has RULE-LENGTH symbols
62 m4_define([b4_rhs_location
],
63 [yyvsp@
<:@
m4_eval([$
2 - $
1])@
:>@
.yystate
.yyloc
])
71 # b4_pure_if(IF-TRUE, IF-FALSE)
72 # -----------------------------
73 # Expand IF-TRUE, if %pure-parser, IF-FALSE otherwise.
74 m4_define([b4_pure_if
],
80 ## ------------------- ##
81 ## Output file names. ##
82 ## ------------------- ##
84 m4_define_default([b4_input_suffix
], [.y
])
86 m4_define_default([b4_output_parser_suffix
],
87 [m4_translit(b4_input_suffix
, [yY
], [cC
])])
89 m4_define_default([b4_output_parser_name
],
90 [b4_output_prefix
[]b4_output_infix
[]b4_output_parser_suffix
[]])
93 m4_define_default([b4_output_header_suffix
],
94 [m4_translit(b4_input_suffix
, [yY
], [hH
])])
96 m4_define_default([b4_output_header_name
],
97 [b4_output_prefix
[]b4_output_infix
[]b4_output_header_suffix
[]])
99 m4_define_default([b4_header_guard
],
100 [m4_bpatsubst(m4_toupper([BISON_
]b4_output_header_name
),
101 [[^ABCDEFGHIJKLMNOPQRSTUVWXYZ
]], [_
])])
105 #output "b4_output_parser_name"
106 b4_copyright([Skeleton parser
for GLR parsing with Bison
], [2002])
108 /* This is the parser code for GLR (Generalized LR) parser. */
110 /* FIXME: minimize these */
118 /* Identify Bison output. */
122 #define YYPURE ]b4_pure[
124 /* Using locations. */
125 #define YYLSP_NEEDED ]b4_locations_flag[
127 ]m4_if(b4_prefix
[], [yy
], [],
128 [/* If NAME_PREFIX is specified substitute the variables and functions
130 #define yyparse b4_prefix[]parse
131 #define yylex b4_prefix[]lex
132 #define yyerror b4_prefix[]error
133 #define yylval b4_prefix[]lval
134 #define yychar b4_prefix[]char
135 #define yydebug b4_prefix[]debug
136 #define yynerrs b4_prefix[]nerrs
137 b4_location_if([#define yylloc b4_prefix[]lloc])])
139 b4_token_defines(b4_tokens
)
141 /* Copy the first part of user declarations. */
144 /* Enabling traces. */
146 # define YYDEBUG ]b4_debug[
149 /* Enabling verbose error messages. */
150 #ifdef YYERROR_VERBOSE
151 # undef YYERROR_VERBOSE
152 # define YYERROR_VERBOSE 1
154 # define YYERROR_VERBOSE ]b4_error_verbose[
158 ]m4_ifdef([b4_stype
],
159 [#line b4_stype_line "b4_filename"
160 typedef union b4_stype yystype
;
161 /* Line __line__ of __file__. */
162 #line __oline__ "__ofile__"],
163 [typedef int yystype
;])[
164 # define YYSTYPE yystype
165 # define YYSTYPE_IS_TRIVIAL 1
169 typedef struct yyltype
177 # define YYLTYPE ]b4_ltype[
178 # define YYLTYPE_IS_TRIVIAL 1
181 /* Default (constant) values used for initialization for null
182 right-hand sides. Unlike the standard bison.simple template,
183 here we set the default values of the $$ and $@ to zeroed-out
184 values. Since the default value of these quantities is undefined,
185 this behavior is technically correct. */
186 static YYSTYPE yyval_default
;
187 static YYLTYPE yyloc_default
;
189 /* Copy the second part of user declarations. */
192 ]/* Line __line__ of __file__. */
193 #line __oline__ "__ofile__"
195 #if ! defined (__cplusplus)
201 #if defined (__STDC__) || defined (__cplusplus)
202 typedef signed char yysigned_char
;
204 typedef short yysigned_char
;
211 #ifndef __attribute__
212 /* This feature is available in gcc versions 2.5 and later. */
213 # if !defined (__GNUC__) || __GNUC__ < 2 || \
214 (__GNUC__ == 2 && __GNUC_MINOR__ < 5) || __STRICT_ANSI__
215 # define __attribute__(Spec) /* empty */
219 #ifndef ATTRIBUTE_UNUSED
220 # define ATTRIBUTE_UNUSED __attribute__ ((__unused__))
223 #if ! defined (__GNUC__)
227 /* YYFINAL -- State number of the termination state. */
228 #define YYFINAL ]b4_final_state_number[
229 #define YYLAST ]b4_last[
231 /* YYNTOKENS -- Number of terminals. */
232 #define YYNTOKENS ]b4_tokens_number[
233 /* YYNNTS -- Number of nonterminals. */
234 #define YYNNTS ]b4_nterms_number[
235 /* YYNRULES -- Number of rules. */
236 #define YYNRULES ]b4_rules_number[
237 /* YYNRULES -- Number of states. */
238 #define YYNSTATES ]b4_states_number[
239 /* YYMAXRHS -- Maximum number of symbols on right-hand side of rule. */
240 #define YYMAXRHS ]b4_r2_max[
242 /* YYTRANSLATE(X) -- Bison symbol number corresponding to X. */
243 #define YYUNDEFTOK ]b4_undef_token_number[
244 #define YYMAXUTOK ]b4_user_token_number_max[
246 #define YYTRANSLATE(YYX) \
247 ((unsigned)(YYX) <= YYMAXUTOK ? yytranslate[YYX] : YYUNDEFTOK)
249 /* YYTRANSLATE[YYLEX] -- Bison symbol number corresponding to YYLEX. */
250 static const ]b4_int_type_for([b4_translate
])[ yytranslate
[] =
256 /* YYPRHS[YYN] -- Index of the first RHS symbol of rule number YYN in
258 static const ]b4_int_type_for([b4_prhs
])[ yyprhs
[] =
263 /* YYRHS -- A `-1'-separated list of the rules' RHS. */
264 static const ]b4_int_type_for([b4_rhs
])[ yyrhs
[] =
269 /* YYRLINE[YYN] -- source line where rule number YYN was defined. */
270 static const ]b4_int_type_for([b4_rline
])[ yyrline
[] =
276 #if (YYDEBUG) || YYERROR_VERBOSE
277 /* YYTNME[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM.
278 First, the terminals, then, starting at YYNTOKENS, nonterminals. */
279 static const char *const yytname
[] =
284 #define yytname_size ((int) (sizeof (yytname) / sizeof (yytname[0])))
287 /* YYR1[YYN] -- Symbol number of symbol that rule YYN derives. */
288 static const ]b4_int_type_for([b4_r1
])[ yyr1
[] =
293 /* YYR2[YYN] -- Number of symbols composing right hand side of rule YYN. */
294 static const ]b4_int_type_for([b4_r2
])[ yyr2
[] =
299 /* YYDPREC[RULE-NUM] -- Dynamic precedence of rule #RULE-NUM (0 if none). */
300 static const ]b4_int_type_for([b4_dprec
])[ yydprec
[] =
305 /* YYMERGER[RULE-NUM] -- Index of merging function for rule #RULE-NUM. */
306 static const ]b4_int_type_for([b4_merger
])[ yymerger
[] =
311 /* YYDEFACT[S] -- default rule to reduce with in state S when YYTABLE
312 doesn't specify something else to do. Zero means the default is an
314 static const ]b4_int_type_for([b4_defact
])[ yydefact
[] =
319 /* YYPDEFGOTO[NTERM-NUM]. */
320 static const ]b4_int_type_for([b4_defgoto
])[ yydefgoto
[] =
325 /* YYPACT[STATE-NUM] -- Index in YYTABLE of the portion describing
327 #define YYPACT_NINF ]b4_pact_ninf[
328 static const ]b4_int_type_for([b4_pact
])[ yypact
[] =
333 /* YYPGOTO[NTERM-NUM]. */
334 static const ]b4_int_type_for([b4_pgoto
])[ yypgoto
[] =
339 /* YYTABLE[YYPACT[STATE-NUM]]. What to do in state STATE-NUM. If
340 positive, shift that token. If negative, reduce the rule which
341 number is the opposite. If zero, do what YYDEFACT says.
342 If YYTABLE_NINF, parse error. */
343 #define YYTABLE_NINF ]b4_table_ninf[
344 static const ]b4_int_type_for([b4_table
])[ yytable
[] =
349 /* YYCONFLP[YYPACT[STATE-NUM]] -- Pointer into YYCONFL of start of
350 list of conflicting reductions corresponding to action entry for
351 state STATE-NUM in yytable. 0 means no conflicts. The list in
352 yyconfl is terminated by a rule number of 0. */
353 static const ]b4_int_type_for([b4_conflict_list_heads
])[ yyconflp
[] =
355 ]b4_conflict_list_heads
[
358 /* YYCONFL[I] -- lists of conflicting rule numbers, each terminated by
359 0, pointed into by YYCONFLP. */
360 ]dnl Do
not use b4_int_type_for here
, since there are places where
361 dnl pointers onto yyconfl are taken
, which type is
"short *".
362 dnl We probably ought to introduce a type
for confl
.
363 [static const short yyconfl
[] =
365 ]b4_conflicting_rules
[
368 static const ]b4_int_type_for([b4_check
])[ yycheck
[] =
374 /* The user can define YYPARSE_PARAM as the name of an argument to be passed
375 into yyparse. The argument should have type void *.
376 It should actually point to an object.
377 Grammar actions can access the variable by casting it
378 to the proper pointer type. */
381 # define YYPARSE_PARAM_ARG void *YYPARSE_PARAM
382 #else /* !YYPARSE_PARAM */
383 # define YYPARSE_PARAM_ARG void
384 #endif /* !YYPARSE_PARAM */
386 /* Prevent warning if -Wstrict-prototypes. */
388 # ifdef YYPARSE_PARAM
389 int yyparse (void *);
395 /* Error token number */
398 /* YYLLOC_DEFAULT -- Compute the default location (before the actions
401 #define YYRHSLOC(yyRhs,YYK) (yyRhs[YYK].yystate.yyloc)
403 #ifndef YYLLOC_DEFAULT
404 # define YYLLOC_DEFAULT(yyCurrent, yyRhs, YYN) \
405 yyCurrent.first_line = YYRHSLOC(yyRhs,1).first_line; \
406 yyCurrent.first_column = YYRHSLOC(yyRhs,1).first_column; \
407 yyCurrent.last_line = YYRHSLOC(yyRhs,YYN).last_line; \
408 yyCurrent.last_column = YYRHSLOC(yyRhs,YYN).last_column;
411 /* YYLEX -- calling `yylex' with the right arguments. */
416 # define YYLEX yylex (yylvalp, b4_location_if([yyllocp, ])YYLEX_PARAM)
418 # define YYLEX yylex (yylvalp[]b4_location_if([, yyllocp]))
420 [#define YYLEX yylex ()])
425 #define yynerrs (yystack->yyerrcnt)
427 #define yychar (yystack->yyrawchar)],
435 static const int YYEOF
= 0;
436 static const int YYEMPTY
= -2;
438 typedef enum { yyok
, yyaccept
, yyabort
, yyerr
} YYRESULTTAG
;
441 do { YYRESULTTAG yyflag = YYE; if (yyflag != yyok) return yyflag; } \
446 #if ! defined (YYFPRINTF)
447 # define YYFPRINTF fprintf
450 # define YYDPRINTF(Args) \
455 /* Nonzero means print parse trace. It is left uninitialized so that
456 multiple parsers can coexist. */
459 /* Avoid empty `if' bodies. */
460 # define YYDPRINTF(Args) {}
461 #endif /* !YYDEBUG */
463 /* YYINITDEPTH -- initial size of the parser's stacks. */
465 # define YYINITDEPTH ]b4_initdepth[
468 /* YYMAXDEPTH -- maximum size the stacks can grow to (effective only
469 if the built-in stack extension method is used).
471 Do not make this value too large; the results are undefined if
472 SIZE_MAX < YYMAXDEPTH * sizeof (GLRStackItem)
473 evaluated with infinite-precision integer arithmetic. */
480 # define YYMAXDEPTH ]b4_maxdepth[
483 /* Minimum number of free items on the stack allowed after an
484 allocation. This is to allow allocation and initialization
485 to be completed by functions that call expandGLRStack before the
486 stack is expanded, thus insuring that all necessary pointers get
487 properly redirected to new data. */
490 #if ! defined (YYSTACKEXPANDABLE) \
491 && (! defined (__cplusplus) || (YYLTYPE_IS_TRIVIAL && YYSTYPE_IS_TRIVIAL))
492 #define YYSTACKEXPANDABLE 1
494 #define YYSTACKEXPANDABLE 0
497 /** State numbers, as in LALR(1) machine */
498 typedef int yyStateNum
;
500 /** Rule numbers, as in LALR(1) machine */
501 typedef int yyRuleNum
;
503 /** Grammar symbol */
504 typedef short yySymbol
;
506 /** Item references, as in LALR(1) machine */
507 typedef short yyItemNum
;
509 typedef struct yyGLRState yyGLRState
;
510 typedef struct yySemanticOption yySemanticOption
;
511 typedef union yyGLRStackItem yyGLRStackItem
;
512 typedef struct yyGLRStack yyGLRStack
;
513 typedef struct yyGLRStateSet yyGLRStateSet
;
518 yyStateNum yylrState
;
522 yySemanticOption
* yyfirstVal
;
528 struct yyGLRStateSet
{
529 yyGLRState
** yystates
;
530 size_t yysize
, yycapacity
;
533 struct yySemanticOption
{
537 yySemanticOption
* yynext
;
540 union yyGLRStackItem
{
542 yySemanticOption yyoption
;
554 jmp_buf yyexception_buffer
;
555 yyGLRStackItem
* yyitems
;
556 yyGLRStackItem
* yynextFree
;
558 yyGLRState
* yysplitPoint
;
559 yyGLRState
* yylastDeleted
;
560 yyGLRStateSet yytops
;
563 static void yyinitGLRStack (yyGLRStack
* yystack
, size_t yysize
);
564 static void yyexpandGLRStack (yyGLRStack
* yystack
);
565 static void yyfreeGLRStack (yyGLRStack
* yystack
);
568 yyFail (yyGLRStack
* yystack
, const char* yyformat
, ...)
570 if (yyformat
!= NULL
)
574 va_start (yyap
, yyformat
);
575 yystack
->yyerrflag
= 1;
576 vsprintf (yymsg
, yyformat
, yyap
);
579 longjmp (yystack
->yyexception_buffer
, 1);
582 #if YYDEBUG || YYERROR_VERBOSE
583 /** A printable representation of TOKEN. Valid until next call to
585 static inline const char*
586 yytokenName (yySymbol yytoken
)
588 return yytname
[yytoken
];
592 /** Perform user action for rule number YYN, with RHS length YYRHSLEN,
593 * and top stack item YYVSP. YYLVALP points to place to put semantic
594 * value ($$), and yylocp points to place for location information
595 * (@$). Returns yyok for normal return, yyaccept for YYACCEPT,
596 * yyerr for YYERROR, yyabort for YYABORT. */
598 yyuserAction (yyRuleNum yyn
, int yyrhslen
, yyGLRStackItem
* yyvsp
,
599 YYSTYPE
* yyvalp
, YYLTYPE
* yylocp
, yyGLRStack
* yystack
)
601 /* Avoid `unused' warnings in there are no $n. */
606 *yyvalp
= yyval_default
;
607 *yylocp
= yyloc_default
;
611 *yyvalp
= yyvsp
[1-yyrhslen
].yystate
.yysemantics
.yysval
;
612 *yylocp
= yyvsp
[1-yyrhslen
].yystate
.yyloc
;
615 # define yyval (*yyvalp)
617 # define yyerrok (yystack->yyerrState = 0)
619 # define YYACCEPT return yyaccept
621 # define YYABORT return yyabort
623 # define YYERROR return yyerr
625 # define YYRECOVERING (yystack->yyerrState != 0)
627 # define yyclearin (yychar = *(yystack->yytokenp) = YYEMPTY)
629 # define YYBACKUP(Token, Value) \
631 yyerror ("syntax error: cannot back up"); \
650 /* Line __line__ of __file__. */
651 #line __oline__ "__ofile__"
656 yyuserMerge (int yyn
, YYSTYPE
* yy0
, YYSTYPE
* yy1
)
658 YYSTYPE yyval
= *yy0
;
659 /* `Use' the arguments. */
670 /* Bison grammar-table manipulation */
672 /** Number of symbols composing the right hand side of rule #RULE. */
674 yyrhsLength (yyRuleNum yyrule
)
679 /** Left-hand-side symbol for rule #RULE. */
680 static inline yySymbol
681 yylhsNonterm (yyRuleNum yyrule
)
686 /** True iff LR state STATE has only a default reduction (regardless
689 yyisDefaultedState (yyStateNum yystate
)
691 return yypact
[yystate
] == YYPACT_NINF
;
694 /** The default reduction for STATE, assuming it has one. */
695 static inline yyRuleNum
696 yydefaultAction (yyStateNum yystate
)
698 return yydefact
[yystate
];
701 /** Set *YYACTION to the action to take in YYSTATE on seeing YYTOKEN.
703 * R < 0: Reduce on rule -R.
705 * R > 0: Shift to state R.
706 * Set *CONFLICTS to a pointer into yyconfl to 0-terminated list of
707 * conflicting reductions.
710 yygetLRActions (yyStateNum yystate
, int yytoken
,
711 int* yyaction
, const short** yyconflicts
)
713 int yyindex
= yypact
[yystate
] + yytoken
;
714 if (yyindex
< 0 || YYLAST
< yyindex
|| yycheck
[yyindex
] != yytoken
)
716 *yyaction
= -yydefact
[yystate
];
717 *yyconflicts
= yyconfl
;
719 else if (yytable
[yyindex
] != YYTABLE_NINF
)
721 *yyaction
= yytable
[yyindex
];
722 *yyconflicts
= yyconfl
+ yyconflp
[yyindex
];
727 *yyconflicts
= yyconfl
+ yyconflp
[yyindex
];
731 static inline yyStateNum
732 yyLRgotoState (yyStateNum yystate
, yySymbol yylhs
)
735 yyr
= yypgoto
[yylhs
- YYNTOKENS
] + yystate
;
736 if (0 <= yyr
&& yyr
<= YYLAST
&& yycheck
[yyr
] == yystate
)
739 return yydefgoto
[yylhs
- YYNTOKENS
];
743 yyisShiftAction (int yyaction
)
749 yyisErrorAction (int yyaction
)
751 return yyaction
== 0;
756 /** True iff the semantic value of the edge leading to STATE is
759 yyhasResolvedValue (yyGLRState
* yystate
)
761 return yystate
->yyresolved
;
765 yyaddDeferredAction (yyGLRStack
* yystack
, yyGLRState
* yystate
,
766 yyGLRState
* rhs
, yyRuleNum yyrule
)
768 yySemanticOption
* yynewItem
;
769 yynewItem
= &yystack
->yynextFree
->yyoption
;
770 yystack
->yyspaceLeft
-= 1;
771 yystack
->yynextFree
+= 1;
772 yynewItem
->yyisState
= yyfalse
;
773 yynewItem
->yystate
= rhs
;
774 yynewItem
->yyrule
= yyrule
;
775 yynewItem
->yynext
= yystate
->yysemantics
.yyfirstVal
;
776 yystate
->yysemantics
.yyfirstVal
= yynewItem
;
777 if (yystack
->yyspaceLeft
< YYHEADROOM
)
778 yyexpandGLRStack (yystack
);
783 /** Initialize SET to a singleton set containing an empty stack. */
785 yyinitStateSet (yyGLRStateSet
* yyset
)
788 yyset
->yycapacity
= 16;
789 yyset
->yystates
= (yyGLRState
**) malloc (16 * sizeof (yyset
->yystates
[0]));
790 yyset
->yystates
[0] = NULL
;
793 static void yyfreeStateSet (yyGLRStateSet
* yyset
)
795 free (yyset
->yystates
);
798 /** Initialize STACK to a single empty stack, with total maximum
799 * capacity for all stacks of SIZE. */
801 yyinitGLRStack (yyGLRStack
* yystack
, size_t yysize
)
803 yystack
->yyerrflag
= 0;
804 yystack
->yyerrState
= 0;
806 yystack
->yyspaceLeft
= yysize
;
807 yystack
->yynextFree
= yystack
->yyitems
=
808 (yyGLRStackItem
*) malloc (yysize
* sizeof (yystack
->yynextFree
[0]));
809 yystack
->yysplitPoint
= NULL
;
810 yystack
->yylastDeleted
= NULL
;
811 yyinitStateSet (&yystack
->yytops
);
814 #define YYRELOC(YYFROMITEMS,YYTOITEMS,YYX,YYTYPE) \
815 &((YYTOITEMS) - ((YYFROMITEMS) - (yyGLRStackItem*) (YYX)))->YYTYPE
817 /** If STACK is expandable, extend it. WARNING: Pointers into the
818 stack from outside should be considered invalid after this call.
819 We always expand when there are 1 or fewer items left AFTER an
820 allocation, so that we can avoid having external pointers exist
821 across an allocation. */
823 yyexpandGLRStack (yyGLRStack
* yystack
)
825 #if YYSTACKEXPANDABLE
826 yyGLRStack yynewStack
;
827 yyGLRStackItem
* yyp0
, *yyp1
;
828 size_t yysize
, yynewSize
;
830 yysize
= yystack
->yynextFree
- yystack
->yyitems
;
831 if (yysize
>= YYMAXDEPTH
)
832 yyFail (yystack
, "parsing stack overflow (%d items)", yysize
);
833 yynewSize
= 2*yysize
;
834 if (yynewSize
> YYMAXDEPTH
)
835 yynewSize
= YYMAXDEPTH
;
836 yyinitGLRStack (&yynewStack
, yynewSize
);
837 for (yyp0
= yystack
->yyitems
, yyp1
= yynewStack
.yyitems
, yyn
= yysize
;
839 yyn
-= 1, yyp0
+= 1, yyp1
+= 1)
844 yyGLRState
* yys0
= &yyp0
->yystate
;
845 yyGLRState
* yys1
= &yyp1
->yystate
;
846 if (yys0
->yypred
!= NULL
)
848 YYRELOC (yyp0
, yyp1
, yys0
->yypred
, yystate
);
849 if (! yys0
->yyresolved
&& yys0
->yysemantics
.yyfirstVal
!= NULL
)
850 yys1
->yysemantics
.yyfirstVal
=
851 YYRELOC(yyp0
, yyp1
, yys0
->yysemantics
.yyfirstVal
, yyoption
);
855 yySemanticOption
* yyv0
= &yyp0
->yyoption
;
856 yySemanticOption
* yyv1
= &yyp1
->yyoption
;
857 if (yyv0
->yystate
!= NULL
)
858 yyv1
->yystate
= YYRELOC (yyp0
, yyp1
, yyv0
->yystate
, yystate
);
859 if (yyv0
->yynext
!= NULL
)
860 yyv1
->yynext
= YYRELOC (yyp0
, yyp1
, yyv0
->yynext
, yyoption
);
863 if (yystack
->yysplitPoint
!= NULL
)
864 yystack
->yysplitPoint
= YYRELOC (yystack
->yyitems
, yynewStack
.yyitems
,
865 yystack
->yysplitPoint
, yystate
);
867 for (yyn
= 0; yyn
< yystack
->yytops
.yysize
; yyn
+= 1)
868 if (yystack
->yytops
.yystates
[yyn
] != NULL
)
869 yystack
->yytops
.yystates
[yyn
] =
870 YYRELOC (yystack
->yyitems
, yynewStack
.yyitems
,
871 yystack
->yytops
.yystates
[yyn
], yystate
);
872 free (yystack
->yyitems
);
873 yystack
->yyitems
= yynewStack
.yyitems
;
874 yystack
->yynextFree
= yynewStack
.yynextFree
+ yysize
;
875 yystack
->yyspaceLeft
= yynewStack
.yyspaceLeft
- yysize
;
879 yyFail (yystack
, "parsing stack overflow (%d items)", yysize
);
885 yyfreeGLRStack (yyGLRStack
* yystack
)
887 free (yystack
->yyitems
);
888 yyfreeStateSet (&yystack
->yytops
);
891 /** Assuming that S is a GLRState somewhere on STACK, update the
892 * splitpoint of STACK, if needed, so that it is at least as deep as
895 yyupdateSplit (yyGLRStack
* yystack
, yyGLRState
* yys
)
897 if (yystack
->yysplitPoint
!= NULL
&& yystack
->yysplitPoint
> yys
)
898 yystack
->yysplitPoint
= yys
;
901 /** Invalidate stack #K in STACK. */
903 yymarkStackDeleted (yyGLRStack
* yystack
, int yyk
)
905 if (yystack
->yytops
.yystates
[yyk
] != NULL
)
906 yystack
->yylastDeleted
= yystack
->yytops
.yystates
[yyk
];
907 yystack
->yytops
.yystates
[yyk
] = NULL
;
910 /** Undelete the last stack that was marked as deleted. Can only be
911 done once after a deletion, and only when all other stacks have
914 yyundeleteLastStack (yyGLRStack
* yystack
)
916 if (yystack
->yylastDeleted
== NULL
|| yystack
->yytops
.yysize
!= 0)
918 yystack
->yytops
.yystates
[0] = yystack
->yylastDeleted
;
919 yystack
->yytops
.yysize
= 1;
920 YYDPRINTF ((stderr
, "Restoring last deleted stack as stack #0.\n"));
921 yystack
->yylastDeleted
= NULL
;
925 yyremoveDeletes (yyGLRStack
* yystack
)
929 while (yyj
< yystack
->yytops
.yysize
)
931 if (yystack
->yytops
.yystates
[yyi
] == NULL
)
934 YYDPRINTF ((stderr
, "Removing dead stacks.\n"));
935 yystack
->yytops
.yysize
-= 1;
939 yystack
->yytops
.yystates
[yyj
] = yystack
->yytops
.yystates
[yyi
];
941 YYDPRINTF ((stderr
, "Rename stack %d -> %d.\n", yyi
, yyj
));
948 /** Shift to a new state on stack #K of STACK, corresponding to LR state
949 * LRSTATE, at input position POSN, with (resolved) semantic value SVAL. */
951 yyglrShift (yyGLRStack
* yystack
, int yyk
, yyStateNum yylrState
, size_t yyposn
,
952 YYSTYPE yysval
, YYLTYPE
* yylocp
)
954 yyGLRStackItem
* yynewItem
;
956 yynewItem
= yystack
->yynextFree
;
957 yystack
->yynextFree
+= 1;
958 yystack
->yyspaceLeft
-= 1;
959 yynewItem
->yystate
.yyisState
= yytrue
;
960 yynewItem
->yystate
.yylrState
= yylrState
;
961 yynewItem
->yystate
.yyposn
= yyposn
;
962 yynewItem
->yystate
.yyresolved
= yytrue
;
963 yynewItem
->yystate
.yypred
= yystack
->yytops
.yystates
[yyk
];
964 yystack
->yytops
.yystates
[yyk
] = &yynewItem
->yystate
;
965 yynewItem
->yystate
.yysemantics
.yysval
= yysval
;
966 yynewItem
->yystate
.yyloc
= *yylocp
;
967 if (yystack
->yyspaceLeft
< YYHEADROOM
)
968 yyexpandGLRStack (yystack
);
971 /** Shift to a new state on stack #K of STACK, to a new state
972 * corresponding to LR state LRSTATE, at input position POSN, with
973 * the (unresolved) semantic value of RHS under the action for RULE. */
975 yyglrShiftDefer (yyGLRStack
* yystack
, int yyk
, yyStateNum yylrState
,
976 size_t yyposn
, yyGLRState
* rhs
, yyRuleNum yyrule
)
978 yyGLRStackItem
* yynewItem
;
980 yynewItem
= yystack
->yynextFree
;
981 yynewItem
->yystate
.yyisState
= yytrue
;
982 yynewItem
->yystate
.yylrState
= yylrState
;
983 yynewItem
->yystate
.yyposn
= yyposn
;
984 yynewItem
->yystate
.yyresolved
= yyfalse
;
985 yynewItem
->yystate
.yypred
= yystack
->yytops
.yystates
[yyk
];
986 yynewItem
->yystate
.yysemantics
.yyfirstVal
= NULL
;
987 yystack
->yytops
.yystates
[yyk
] = &yynewItem
->yystate
;
988 yystack
->yynextFree
+= 1;
989 yystack
->yyspaceLeft
-= 1;
990 yyaddDeferredAction (yystack
, &yynewItem
->yystate
, rhs
, yyrule
);
993 /** Pop the symbols consumed by reduction #RULE from the top of stack
994 * #K of STACK, and perform the appropriate semantic action on their
995 * semantic values. Assumes that all ambiguities in semantic values
996 * have been previously resolved. Set *VALP to the resulting value,
997 * and *LOCP to the computed location (if any). Return value is as
1000 yydoAction (yyGLRStack
* yystack
, int yyk
, yyRuleNum yyrule
,
1001 YYSTYPE
* yyvalp
, YYLTYPE
* yylocp
)
1003 int yynrhs
= yyrhsLength (yyrule
);
1005 if (yystack
->yysplitPoint
== NULL
)
1007 /* Standard special case: single stack. */
1008 yyGLRStackItem
* rhs
= (yyGLRStackItem
*) yystack
->yytops
.yystates
[yyk
];
1010 yystack
->yynextFree
-= yynrhs
;
1011 yystack
->yyspaceLeft
+= yynrhs
;
1012 yystack
->yytops
.yystates
[0] = & yystack
->yynextFree
[-1].yystate
;
1015 *yyvalp
= yyval_default
;
1016 *yylocp
= yyloc_default
;
1020 *yyvalp
= rhs
[1-yynrhs
].yystate
.yysemantics
.yysval
;
1021 *yylocp
= rhs
[1-yynrhs
].yystate
.yyloc
;
1023 return yyuserAction (yyrule
, yynrhs
, rhs
, yyvalp
, yylocp
, yystack
);
1029 yyGLRStackItem yyrhsVals
[YYMAXRHS
];
1030 for (yyi
= yynrhs
-1, yys
= yystack
->yytops
.yystates
[yyk
]; yyi
>= 0;
1031 yyi
-= 1, yys
= yys
->yypred
)
1033 assert (yys
->yypred
!= NULL
);
1034 yyrhsVals
[yyi
].yystate
.yyresolved
= yytrue
;
1035 yyrhsVals
[yyi
].yystate
.yysemantics
.yysval
= yys
->yysemantics
.yysval
;
1036 yyrhsVals
[yyi
].yystate
.yyloc
= yys
->yyloc
;
1038 yyupdateSplit (yystack
, yys
);
1039 yystack
->yytops
.yystates
[yyk
] = yys
;
1042 *yyvalp
= yyval_default
;
1043 *yylocp
= yyloc_default
;
1047 *yyvalp
= yyrhsVals
[0].yystate
.yysemantics
.yysval
;
1048 *yylocp
= yyrhsVals
[0].yystate
.yyloc
;
1050 return yyuserAction (yyrule
, yynrhs
, yyrhsVals
+ (yynrhs
-1),
1051 yyvalp
, yylocp
, yystack
);
1055 /** Pop items off stack #K of STACK according to grammar rule RULE,
1056 * and push back on the resulting nonterminal symbol. Perform the
1057 * semantic action associated with RULE and store its value with the
1058 * newly pushed state, if FORCEEVAL or if STACK is currently
1059 * unambiguous. Otherwise, store the deferred semantic action with
1060 * the new state. If the new state would have an identical input
1061 * position, LR state, and predecessor to an existing state on the stack,
1062 * it is identified with that existing state, eliminating stack #K from
1063 * the STACK. In this case, the (necessarily deferred) semantic value is
1064 * added to the options for the existing state's semantic value.
1066 static inline YYRESULTTAG
1067 yyglrReduce (yyGLRStack
* yystack
, size_t yyk
, yyRuleNum yyrule
,
1070 size_t yyposn
= yystack
->yytops
.yystates
[yyk
]->yyposn
;
1072 if (yyforceEval
|| yystack
->yysplitPoint
== NULL
)
1081 YYDPRINTF ((stderr
, "Reducing stack %d by rule %d (line %d),",
1082 yyk
, yyrule
- 1, yyrline
[yyrule
]));
1083 /* Print the symbols being reduced, and their result. */
1084 for (yyi
= yyprhs
[yyrule
]; yyrhs
[yyi
] >= 0; yyi
++)
1085 YYFPRINTF (stderr
, "%s ", yytokenName (yyrhs
[yyi
]));
1086 YYFPRINTF (stderr
, " -> %s\n", yytokenName (yyr1
[yyrule
]));
1089 YYCHK (yydoAction (yystack
, yyk
, yyrule
, &yysval
, &yyloc
));
1090 yyglrShift (yystack
, yyk
,
1091 yyLRgotoState (yystack
->yytops
.yystates
[yyk
]->yylrState
,
1092 yylhsNonterm (yyrule
)),
1093 yyposn
, yysval
, &yyloc
);
1094 YYDPRINTF ((stderr
, "Stack %d entering state %d\n",
1095 yyk
, yystack
->yytops
.yystates
[yyk
]->yylrState
));
1101 yyGLRState
* yys
, *yys0
= yystack
->yytops
.yystates
[yyk
];
1102 yyStateNum yynewLRState
;
1104 for (yys
= yystack
->yytops
.yystates
[yyk
], yyn
= yyrhsLength (yyrule
);
1108 assert (yys
!= NULL
);
1110 yyupdateSplit (yystack
, yys
);
1111 yynewLRState
= yyLRgotoState (yys
->yylrState
, yylhsNonterm (yyrule
));
1113 "Reduced stack %d by rule #%d; action deferred. "
1114 "Now in state %d.\n",
1115 yyk
, yyrule
-1, yynewLRState
));
1116 for (yyi
= 0; yyi
< yystack
->yytops
.yysize
; yyi
+= 1)
1117 if (yyi
!= yyk
&& yystack
->yytops
.yystates
[yyi
] != NULL
)
1119 yyGLRState
* yyp
, *yysplit
= yystack
->yysplitPoint
;
1120 yyp
= yystack
->yytops
.yystates
[yyi
];
1121 while (yyp
!= yys
&& yyp
!= yysplit
&& yyp
->yyposn
>= yyposn
)
1123 if (yyp
->yylrState
== yynewLRState
&& yyp
->yypred
== yys
)
1125 yyaddDeferredAction (yystack
, yyp
, yys0
, yyrule
);
1126 yymarkStackDeleted (yystack
, yyk
);
1127 YYDPRINTF ((stderr
, "Merging stack %d into stack %d.\n",
1134 yystack
->yytops
.yystates
[yyk
] = yys
;
1135 yyglrShiftDefer (yystack
, yyk
, yynewLRState
, yyposn
, yys0
, yyrule
);
1141 yysplitStack (yyGLRStack
* yystack
, int yyk
)
1143 if (yystack
->yysplitPoint
== NULL
)
1146 yystack
->yysplitPoint
= yystack
->yytops
.yystates
[yyk
];
1148 if (yystack
->yytops
.yysize
>= yystack
->yytops
.yycapacity
)
1150 yystack
->yytops
.yycapacity
*= 2;
1151 yystack
->yytops
.yystates
=
1152 (yyGLRState
**) realloc (yystack
->yytops
.yystates
,
1153 yystack
->yytops
.yycapacity
1154 * sizeof (yyGLRState
*));
1156 yystack
->yytops
.yystates
[yystack
->yytops
.yysize
]
1157 = yystack
->yytops
.yystates
[yyk
];
1158 yystack
->yytops
.yysize
+= 1;
1159 return yystack
->yytops
.yysize
-1;
1162 /** True iff Y0 and Y1 represent identical options at the top level.
1163 * That is, they represent the same rule applied to RHS symbols
1164 * that produce the same terminal symbols. */
1166 yyidenticalOptions (yySemanticOption
* yyy0
, yySemanticOption
* yyy1
)
1168 if (yyy0
->yyrule
== yyy1
->yyrule
)
1170 yyGLRState
*yys0
, *yys1
;
1172 for (yys0
= yyy0
->yystate
, yys1
= yyy1
->yystate
,
1173 yyn
= yyrhsLength (yyy0
->yyrule
);
1175 yys0
= yys0
->yypred
, yys1
= yys1
->yypred
, yyn
-= 1)
1176 if (yys0
->yyposn
!= yys1
->yyposn
)
1184 /** Assuming identicalOptions (Y0,Y1), (destructively) merge the
1185 * alternative semantic values for the RHS-symbols of Y1 into the
1186 * corresponding semantic value sets of the symbols of Y0. */
1188 yymergeOptionSets (yySemanticOption
* yyy0
, yySemanticOption
* yyy1
)
1190 yyGLRState
*yys0
, *yys1
;
1192 for (yys0
= yyy0
->yystate
, yys1
= yyy1
->yystate
,
1193 yyn
= yyrhsLength (yyy0
->yyrule
);
1195 yys0
= yys0
->yypred
, yys1
= yys1
->yypred
, yyn
-= 1)
1198 else if (! yys0
->yyresolved
&& ! yys1
->yyresolved
)
1200 yySemanticOption
* yyz
;
1201 for (yyz
= yys0
->yysemantics
.yyfirstVal
; yyz
->yynext
!= NULL
;
1204 yyz
->yynext
= yys1
->yysemantics
.yyfirstVal
;
1208 /** Y0 and Y1 represent two possible actions to take in a given
1209 * parsing state; return 0 if no combination is possible,
1210 * 1 if user-mergeable, 2 if Y0 is preferred, 3 if Y1 is preferred. */
1212 yypreference (yySemanticOption
* y0
, yySemanticOption
* y1
)
1214 yyRuleNum r0
= y0
->yyrule
, r1
= y1
->yyrule
;
1215 int p0
= yydprec
[r0
], p1
= yydprec
[r1
];
1219 if (yymerger
[r0
] == 0 || yymerger
[r0
] != yymerger
[r1
])
1224 if (p0
== 0 || p1
== 0)
1233 static YYRESULTTAG
yyresolveValue (yySemanticOption
* yyoptionList
,
1234 yyGLRStack
* yystack
, YYSTYPE
* yyvalp
,
1238 yyresolveStates (yyGLRState
* yys
, int yyn
, yyGLRStack
* yystack
)
1243 assert (yys
->yypred
!= NULL
);
1244 yyflag
= yyresolveStates (yys
->yypred
, yyn
-1, yystack
);
1247 if (! yys
->yyresolved
)
1249 yyflag
= yyresolveValue (yys
->yysemantics
.yyfirstVal
, yystack
,
1250 &yys
->yysemantics
.yysval
, &yys
->yyloc
);
1253 yys
->yyresolved
= yytrue
;
1260 yyresolveAction (yySemanticOption
* yyopt
, yyGLRStack
* yystack
,
1261 YYSTYPE
* yyvalp
, YYLTYPE
* yylocp
)
1263 yyGLRStackItem yyrhsVals
[YYMAXRHS
];
1267 yynrhs
= yyrhsLength (yyopt
->yyrule
);
1268 YYCHK (yyresolveStates (yyopt
->yystate
, yynrhs
, yystack
));
1269 for (yyi
= yynrhs
-1, yys
= yyopt
->yystate
; yyi
>= 0;
1270 yyi
-= 1, yys
= yys
->yypred
)
1272 assert (yys
->yypred
!= NULL
);
1273 yyrhsVals
[yyi
].yystate
.yyresolved
= yytrue
;
1274 yyrhsVals
[yyi
].yystate
.yysemantics
.yysval
= yys
->yysemantics
.yysval
;
1275 yyrhsVals
[yyi
].yystate
.yyloc
= yys
->yyloc
;
1277 return yyuserAction (yyopt
->yyrule
, yynrhs
, yyrhsVals
+ (yynrhs
-1),
1278 yyvalp
, yylocp
, yystack
);
1282 static yyGLRState YYLEFTMOST_STATE
=
1284 0, 0, -1, NULL
, 0, { NULL
},
1287 #if YYLTYPE_IS_TRIVIAL
1288 ]b4_location_if([ 0, 0, 0, 0])[
1293 static void yyreportTree (yySemanticOption
* yyx
, int yyindent
)
1295 int yynrhs
= yyrhsLength (yyx
->yyrule
);
1298 yyGLRState
* yystates
[YYMAXRHS
];
1300 for (yyi
= yynrhs
, yys
= yyx
->yystate
; yyi
> 0; yyi
-= 1, yys
= yys
->yypred
)
1301 yystates
[yyi
] = yys
;
1303 yystates
[0] = &YYLEFTMOST_STATE
;
1307 if (yys
->yyposn
+1 > yyx
->yystate
->yyposn
)
1308 YYFPRINTF (stderr
, "%*s%s -> <Rule %d, empty>\n",
1309 yyindent
, "", yytokenName (yylhsNonterm (yyx
->yyrule
)),
1312 YYFPRINTF (stderr
, "%*s%s -> <Rule %d, tokens %d .. %d>\n",
1313 yyindent
, "", yytokenName (yylhsNonterm (yyx
->yyrule
)),
1314 yyx
->yyrule
, yys
->yyposn
+1, yyx
->yystate
->yyposn
);
1315 for (yyi
= 1; yyi
<= yynrhs
; yyi
+= 1)
1317 if (yystates
[yyi
]->yyresolved
)
1319 if (yystates
[yyi
-1]->yyposn
+1 > yystates
[yyi
]->yyposn
)
1320 YYFPRINTF (stderr
, "%*s%s <empty>\n", yyindent
+2, "",
1321 yytokenName (yyrhs
[yyprhs
[yyx
->yyrule
]+yyi
-1]));
1323 YYFPRINTF (stderr
, "%*s%s <tokens %d .. %d>\n", yyindent
+2, "",
1324 yytokenName (yyrhs
[yyprhs
[yyx
->yyrule
]+yyi
-1]),
1325 yystates
[yyi
-1]->yyposn
+1, yystates
[yyi
]->yyposn
);
1328 yyreportTree (yystates
[yyi
]->yysemantics
.yyfirstVal
, yyindent
+2);
1334 yyreportAmbiguity (yySemanticOption
* yyx0
, yySemanticOption
* yyx1
,
1335 yyGLRStack
* yystack
)
1337 /* `Unused' warnings. */
1342 YYFPRINTF (stderr
, "Ambiguity detected.\n");
1343 YYFPRINTF (stderr
, "Option 1,\n");
1344 yyreportTree (yyx0
, 2);
1345 YYFPRINTF (stderr
, "\nOption 2,\n");
1346 yyreportTree (yyx1
, 2);
1347 YYFPRINTF (stderr
, "\n");
1349 yyFail (yystack
, "ambiguity detected");
1353 /** Resolve the ambiguity represented by OPTIONLIST, perform the indicated
1354 * actions, and return the result. */
1356 yyresolveValue (yySemanticOption
* yyoptionList
, yyGLRStack
* yystack
,
1357 YYSTYPE
* yyvalp
, YYLTYPE
* yylocp
)
1359 yySemanticOption
* yybest
;
1360 yySemanticOption
* yyp
;
1363 yybest
= yyoptionList
;
1365 for (yyp
= yyoptionList
->yynext
; yyp
!= NULL
; yyp
= yyp
->yynext
)
1367 if (yyidenticalOptions (yybest
, yyp
))
1368 yymergeOptionSets (yybest
, yyp
);
1370 switch (yypreference (yybest
, yyp
))
1373 yyreportAmbiguity (yybest
, yyp
, yystack
);
1389 int yyprec
= yydprec
[yybest
->yyrule
];
1390 YYCHK (yyresolveAction (yybest
, yystack
, yyvalp
, yylocp
));
1391 for (yyp
= yybest
->yynext
; yyp
!= NULL
; yyp
= yyp
->yynext
)
1393 if (yyprec
== yydprec
[yyp
->yyrule
])
1397 YYCHK (yyresolveAction (yyp
, yystack
, &yyval1
, &yydummy
));
1398 *yyvalp
= yyuserMerge (yymerger
[yyp
->yyrule
], yyvalp
, &yyval1
);
1404 return yyresolveAction (yybest
, yystack
, yyvalp
, yylocp
);
1408 yyresolveStack (yyGLRStack
* yystack
)
1410 if (yystack
->yysplitPoint
!= NULL
)
1415 for (yyn
= 0, yys
= yystack
->yytops
.yystates
[0];
1416 yys
!= yystack
->yysplitPoint
;
1417 yys
= yys
->yypred
, yyn
+= 1)
1419 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
)
1459 const short* yyconflicts
;
1461 yySymbol
* const yytokenp
= yystack
->yytokenp
;
1463 while (yystack
->yytops
.yystates
[yyk
] != NULL
)
1465 yyStateNum yystate
= yystack
->yytops
.yystates
[yyk
]->yylrState
;
1467 assert (yystate
!= YYFINAL
);
1468 if (yyisDefaultedState (yystate
))
1470 yyrule
= yydefaultAction (yystate
);
1473 YYDPRINTF ((stderr
, "Stack %d dies.\n", yyk
));
1474 yymarkStackDeleted (yystack
, yyk
);
1477 YYCHK (yyglrReduce (yystack
, yyk
, yyrule
, yyfalse
));
1481 if (*yytokenp
== YYEMPTY
)
1483 YYDPRINTF ((stderr
, "Reading a token: "));
1485 *yytokenp
= YYTRANSLATE(yychar
);
1486 YYDPRINTF ((stderr
, "Next token is %s\n",
1487 yytokenName (*yytokenp
)));
1489 yygetLRActions (yystate
, *yytokenp
, &yyaction
, &yyconflicts
);
1491 while (*yyconflicts
!= 0)
1493 int yynewStack
= yysplitStack (yystack
, yyk
);
1494 YYDPRINTF ((stderr
, "Splitting off stack %d from %d.\n",
1496 YYCHK (yyglrReduce (yystack
, yynewStack
, *yyconflicts
, yyfalse
));
1497 YYCHK (yyprocessOneStack (yystack
, yynewStack
, yyposn
,
1502 if (yyisShiftAction (yyaction
))
1504 YYDPRINTF ((stderr
, "Shifting token %s on stack %d, ",
1505 yytokenName (*yytokenp
), yyk
));
1506 yyglrShift (yystack
, yyk
, yyaction
, yyposn
+1, *yylvalp
, yyllocp
);
1507 YYDPRINTF ((stderr
, "which is now in state #%d\n",
1508 yystack
->yytops
.yystates
[yyk
]->yylrState
));
1511 else if (yyisErrorAction (yyaction
))
1513 YYDPRINTF ((stderr
, "Stack %d dies.\n", yyk
));
1514 yymarkStackDeleted (yystack
, yyk
);
1518 YYCHK (yyglrReduce (yystack
, yyk
, -yyaction
, yyfalse
));
1525 yyreportParseError (yyGLRStack
* yystack
, YYSTYPE
* yylvalp
, YYLTYPE
* yyllocp
)
1527 /* `Unused' warnings. */
1531 if (yystack
->yyerrState
== 0)
1534 yySymbol
* const yytokenp
= yystack
->yytokenp
;
1535 int yyn
, yyx
, yycount
;
1537 const char* yyprefix
;
1540 yyn
= yypact
[yystack
->yytops
.yystates
[0]->yylrState
];
1541 if (YYPACT_NINF
< yyn
&& yyn
< YYLAST
)
1544 /* Start YYX at -YYN if negative to avoid negative indexes in
1546 yysize
= sizeof ("parse error, unexpected ")
1547 + strlen (yytokenName (*yytokenp
));
1548 yyprefix
= ", expecting ";
1549 for (yyx
= yyn
< 0 ? -yyn
: 0; yyx
< yytname_size
&& yycount
<= 5;
1551 if (yycheck
[yyx
+ yyn
] == yyx
&& yyx
!= YYTERROR
)
1552 yysize
+= strlen (yytokenName (yyx
)) + strlen (yyprefix
),
1553 yycount
+= 1, yyprefix
= " or ";
1554 yymsg
= yyp
= (char*) malloc (yysize
);
1555 yyp
+= sprintf (yyp
, "parse error, unexpected %s",
1556 yytokenName (*yytokenp
));
1559 yyprefix
= ", expecting ";
1560 for (yyx
= yyn
< 0 ? -yyn
: 0; yyx
< yytname_size
; yyx
+= 1)
1561 if (yycheck
[yyx
+ yyn
] == yyx
&& yyx
!= YYTERROR
)
1563 yyp
+= sprintf (yyp
, "%s%s", yyprefix
, yytokenName (yyx
));
1572 yyerror ("parse error");
1577 /* Recover from a syntax error on YYSTACK, assuming that YYTOKENP,
1578 YYLVALP, and YYLLOCP point to the syntactic category, semantic
1579 value, and location of the lookahead. */
1581 yyrecoverParseError (yyGLRStack
* yystack
, YYSTYPE
* yylvalp
, YYLTYPE
* yyllocp
)
1583 yySymbol
* const yytokenp
= yystack
->yytokenp
;
1587 if (yystack
->yyerrState
== 0)
1588 yystack
->yyerrState
= 3;
1589 else if (yystack
->yyerrState
== 3)
1590 /* We just shifted the error token and (perhaps) took some
1591 reductions. Skip tokens until we can proceed. */
1594 if (*yytokenp
== YYEOF
)
1595 yyFail (yystack
, NULL
);
1596 if (*yytokenp
!= YYEMPTY
)
1597 YYDPRINTF ((stderr
, "Discarding token %s\n",
1598 yytokenName (*yytokenp
)));
1599 YYDPRINTF ((stderr
, "Reading a token: "));
1601 *yytokenp
= YYTRANSLATE (yychar
);
1602 YYDPRINTF ((stderr
, "Next token is %s\n", yytokenName (*yytokenp
)));
1603 yyj
= yypact
[yystack
->yytops
.yystates
[0]->yylrState
];
1604 if (yyj
== YYPACT_NINF
)
1605 /* Something's not right; we shouldn't be here. */
1606 yyFail (yystack
, NULL
);
1608 if (yyj
< 0 || YYLAST
< yyj
|| yycheck
[yyj
] != *yytokenp
)
1610 if (yydefact
[yystack
->yytops
.yystates
[0]->yylrState
] != 0)
1613 else if (yytable
[yyj
] != 0 && yytable
[yyj
] != YYTABLE_NINF
)
1617 /* Reduce to one stack. */
1618 for (yyk
= 0; yyk
< yystack
->yytops
.yysize
; yyk
+= 1)
1619 if (yystack
->yytops
.yystates
[yyk
] != NULL
)
1621 if (yyk
>= yystack
->yytops
.yysize
)
1622 yyFail (yystack
, NULL
);
1623 for (yyk
+= 1; yyk
< yystack
->yytops
.yysize
; yyk
+= 1)
1624 yymarkStackDeleted (yystack
, yyk
);
1625 yyremoveDeletes (yystack
);
1626 yycompressStack (yystack
);
1628 /* Now pop stack until we find a state that shifts the error token. */
1629 while (yystack
->yytops
.yystates
[0] != NULL
)
1631 yyj
= yypact
[yystack
->yytops
.yystates
[0]->yylrState
] + YYTERROR
;
1632 if (yyj
!= YYPACT_NINF
+ YYTERROR
&& yyj
>= 0 && yyj
<= YYLAST
&&
1633 yycheck
[yyj
] == YYTERROR
&& yyisShiftAction (yytable
[yyj
]))
1635 yyglrShift (yystack
, 0, yytable
[yyj
],
1636 yystack
->yytops
.yystates
[0]->yyposn
, *yylvalp
, yyllocp
);
1639 yystack
->yytops
.yystates
[0] = yystack
->yytops
.yystates
[0]->yypred
;
1640 yystack
->yynextFree
-= 1;
1641 yystack
->yyspaceLeft
+= 1;
1643 if (yystack
->yytops
.yystates
[0] == NULL
)
1644 yyFail (yystack
, NULL
);
1647 #define YYCHK1(YYE) \
1653 yystack.yyerrflag = 1; \
1656 yystack.yyerrflag = 0; \
1659 goto yyuser_error; \
1664 yyparse (YYPARSE_PARAM_ARG
)
1674 #define yychar (yystack.yyrawchar)
1677 YYSTYPE
* const yylvalp
= &yylval
;
1678 YYLTYPE
* const yyllocp
= &yylloc
;
1680 yyinitGLRStack (&yystack
, YYINITDEPTH
);
1681 yystack
.yytokenp
= &yytoken
;
1683 YYDPRINTF ((stderr
, "Starting parse\n"));
1685 if (setjmp (yystack
.yyexception_buffer
) != 0)
1688 yyglrShift (&yystack
, 0, 0, 0, yyval_default
, &yyloc_default
);
1694 /* For efficiency, we have two loops, of which the first of which
1695 * is specialized to deterministic operation (single stack, no
1696 * potential ambiguity). */
1703 const short* yyconflicts
;
1705 yyStateNum yystate
= yystack
.yytops
.yystates
[0]->yylrState
;
1706 if (yystate
== YYFINAL
)
1708 if (yyisDefaultedState (yystate
))
1710 yyrule
= yydefaultAction (yystate
);
1713 yyreportParseError (&yystack
, yylvalp
, yyllocp
);
1716 YYCHK1 (yyglrReduce (&yystack
, 0, yyrule
, yytrue
));
1720 if (yytoken
== YYEMPTY
)
1722 YYDPRINTF ((stderr
, "Reading a token: "));
1724 yytoken
= YYTRANSLATE (yychar
);
1725 YYDPRINTF ((stderr
, "Next token is %s\n",
1726 yytokenName (yytoken
)));
1728 yygetLRActions (yystate
, yytoken
, &yyaction
, &yyconflicts
);
1729 if (*yyconflicts
!= 0)
1731 if (yyisShiftAction (yyaction
))
1733 YYDPRINTF ((stderr
, "Shifting token %s, ",
1734 yytokenName (yytoken
)));
1735 if (yytoken
!= YYEOF
)
1738 yyglrShift (&yystack
, 0, yyaction
, yyposn
, yylval
, yyllocp
);
1739 if (yystack
.yyerrState
> 0)
1740 yystack
.yyerrState
-= 1;
1741 YYDPRINTF ((stderr
, "Entering state %d\n",
1742 yystack
.yytops
.yystates
[0]->yylrState
));
1744 else if (yyisErrorAction (yyaction
))
1746 yyreportParseError (&yystack
, yylvalp
, yyllocp
);
1750 YYCHK1 (yyglrReduce (&yystack
, 0, -yyaction
, yytrue
));
1757 int yyn
= yystack
.yytops
.yysize
;
1758 for (yys
= 0; yys
< yyn
; yys
+= 1)
1759 YYCHK1 (yyprocessOneStack (&yystack
, yys
, yyposn
,
1763 yyremoveDeletes (&yystack
);
1764 if (yystack
.yytops
.yysize
== 0)
1766 yyundeleteLastStack (&yystack
);
1767 if (yystack
.yytops
.yysize
== 0)
1768 yyFail (&yystack
, "parse error");
1769 YYCHK1 (yyresolveStack (&yystack
));
1770 YYDPRINTF ((stderr
, "Returning to deterministic operation.\n"));
1771 yyreportParseError (&yystack
, yylvalp
, yyllocp
);
1774 else if (yystack
.yytops
.yysize
== 1)
1776 YYCHK1 (yyresolveStack (&yystack
));
1777 YYDPRINTF ((stderr
, "Returning to deterministic operation.\n"));
1778 yycompressStack (&yystack
);
1784 yyrecoverParseError (&yystack
, yylvalp
, yyllocp
);
1785 yyposn
= yystack
.yytops
.yystates
[0]->yyposn
;
1790 yyfreeGLRStack (&yystack
);
1791 return yystack
.yyerrflag
;
1794 /* DEBUGGING ONLY */
1795 static void yypstack (yyGLRStack
* yystack
, int yyk
) ATTRIBUTE_UNUSED
;
1796 static void yypdumpstack (yyGLRStack
* yystack
) ATTRIBUTE_UNUSED
;
1799 yy_yypstack (yyGLRState
* yys
)
1803 yy_yypstack (yys
->yypred
);
1804 fprintf (stderr
, " -> ");
1806 fprintf (stderr
, "%d@%lu", yys
->yylrState
, (unsigned long) yys
->yyposn
);
1810 yypstates (yyGLRState
* yyst
)
1813 fprintf (stderr
, "<null>");
1816 fprintf (stderr
, "\n");
1820 yypstack (yyGLRStack
* yystack
, int yyk
)
1822 yypstates (yystack
->yytops
.yystates
[yyk
]);
1825 #define YYINDEX(YYX) \
1826 ((YYX) == NULL ? -1 : (yyGLRStackItem*) (YYX) - yystack->yyitems)
1830 yypdumpstack (yyGLRStack
* yystack
)
1832 yyGLRStackItem
* yyp
;
1834 for (yyp
= yystack
->yyitems
; yyp
< yystack
->yynextFree
; yyp
+= 1)
1836 fprintf (stderr
, "%3lu. ", (unsigned long) (yyp
- yystack
->yyitems
));
1839 fprintf (stderr
, "Res: %d, LR State: %d, posn: %lu, pred: %ld",
1840 yyp
->yystate
.yyresolved
, yyp
->yystate
.yylrState
,
1841 (unsigned long) yyp
->yystate
.yyposn
,
1842 (long) YYINDEX (yyp
->yystate
.yypred
));
1843 if (! yyp
->yystate
.yyresolved
)
1844 fprintf (stderr
, ", firstVal: %ld",
1845 (long) YYINDEX (yyp
->yystate
.yysemantics
.yyfirstVal
));
1849 fprintf (stderr
, "Option. rule: %d, state: %ld, next: %ld",
1850 yyp
->yyoption
.yyrule
,
1851 (long) YYINDEX (yyp
->yyoption
.yystate
),
1852 (long) YYINDEX (yyp
->yyoption
.yynext
));
1854 fprintf (stderr
, "\n");
1856 fprintf (stderr
, "Tops:");
1857 for (yyi
= 0; yyi
< yystack
->yytops
.yysize
; yyi
+= 1)
1858 fprintf (stderr
, "%lu: %ld; ", (unsigned long) yyi
,
1859 (long) YYINDEX (yystack
->yytops
.yystates
[yyi
]));
1860 fprintf (stderr
, "\n");
1866 m4_if(b4_defines_flag
, 0, [],
1867 [#output "b4_output_header_name"
1868 b4_copyright([Skeleton parser
for GLR parsing with Bison
], [2002])
1869 #ifndef b4_header_guard
1870 # define b4_header_guard
1872 b4_token_defines(b4_tokens
)
1875 m4_ifdef([b4_stype
],
1876 [#line b4_stype_line "b4_filename"
1877 typedef union b4_stype yystype
;
1878 /* Line __line__ of __file__. */
1879 #line __oline__ "__ofile__"],
1880 [typedef int yystype
;])
1881 # define YYSTYPE yystype
1885 [extern YYSTYPE b4_prefix
[]lval
;])
1889 typedef struct yyltype
1896 # define YYLTYPE yyltype
1900 [extern YYLTYPE b4_prefix
[]lloc
;])
1902 #endif /* not b4_header_guard */