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)
205 #ifndef __attribute__
206 /* This feature is available in gcc versions 2.5 and later. */
207 # if !defined (__GNUC__) || __GNUC__ < 2 || \
208 (__GNUC__ == 2 && __GNUC_MINOR__ < 5) || __STRICT_ANSI__
209 # define __attribute__(Spec) /* empty */
213 #ifndef ATTRIBUTE_UNUSED
214 # define ATTRIBUTE_UNUSED __attribute__ ((__unused__))
217 #if ! defined (__GNUC__)
221 /* YYFINAL -- State number of the termination state. */
222 #define YYFINAL ]b4_final_state_number[
223 #define YYLAST ]b4_last[
225 /* YYNTOKENS -- Number of terminals. */
226 #define YYNTOKENS ]b4_tokens_number[
227 /* YYNNTS -- Number of nonterminals. */
228 #define YYNNTS ]b4_nterms_number[
229 /* YYNRULES -- Number of rules. */
230 #define YYNRULES ]b4_rules_number[
231 /* YYNRULES -- Number of states. */
232 #define YYNSTATES ]b4_states_number[
233 /* YYMAXRHS -- Maximum number of symbols on right-hand side of rule. */
234 #define YYMAXRHS ]b4_r2_max[
236 /* YYTRANSLATE(X) -- Bison symbol number corresponding to X. */
237 #define YYUNDEFTOK ]b4_undef_token_number[
238 #define YYMAXUTOK ]b4_user_token_number_max[
240 #define YYTRANSLATE(YYX) \
241 ((unsigned)(YYX) <= YYMAXUTOK ? yytranslate[YYX] : YYUNDEFTOK)
243 /* YYTRANSLATE[YYLEX] -- Bison symbol number corresponding to YYLEX. */
244 static const ]b4_int_type_for([b4_translate
])[ yytranslate
[] =
250 /* YYPRHS[YYN] -- Index of the first RHS symbol of rule number YYN in
252 static const ]b4_int_type_for([b4_prhs
])[ yyprhs
[] =
257 /* YYRHS -- A `-1'-separated list of the rules' RHS. */
258 static const ]b4_int_type_for([b4_rhs
])[ yyrhs
[] =
263 /* YYRLINE[YYN] -- source line where rule number YYN was defined. */
264 static const ]b4_int_type_for([b4_rline
])[ yyrline
[] =
270 #if (YYDEBUG) || YYERROR_VERBOSE
271 /* YYTNME[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM.
272 First, the terminals, then, starting at YYNTOKENS, nonterminals. */
273 static const char *const yytname
[] =
278 #define yytname_size ((int) (sizeof (yytname) / sizeof (yytname[0])))
281 /* YYR1[YYN] -- Symbol number of symbol that rule YYN derives. */
282 static const ]b4_int_type_for([b4_r1
])[ yyr1
[] =
287 /* YYR2[YYN] -- Number of symbols composing right hand side of rule YYN. */
288 static const ]b4_int_type_for([b4_r2
])[ yyr2
[] =
293 /* YYDPREC[RULE-NUM] -- Dynamic precedence of rule #RULE-NUM (0 if none). */
294 static const ]b4_int_type_for([b4_dprec
])[ yydprec
[] =
299 /* YYMERGER[RULE-NUM] -- Index of merging function for rule #RULE-NUM. */
300 static const ]b4_int_type_for([b4_merger
])[ yymerger
[] =
305 /* YYDEFACT[S] -- default rule to reduce with in state S when YYTABLE
306 doesn't specify something else to do. Zero means the default is an
308 static const ]b4_int_type_for([b4_defact
])[ yydefact
[] =
313 /* YYPDEFGOTO[NTERM-NUM]. */
314 static const ]b4_int_type_for([b4_defgoto
])[ yydefgoto
[] =
319 /* YYPACT[STATE-NUM] -- Index in YYTABLE of the portion describing
321 #define YYPACT_NINF ]b4_pact_ninf[
322 static const ]b4_int_type_for([b4_pact
])[ yypact
[] =
327 /* YYPGOTO[NTERM-NUM]. */
328 static const ]b4_int_type_for([b4_pgoto
])[ yypgoto
[] =
333 /* YYTABLE[YYPACT[STATE-NUM]]. What to do in state STATE-NUM. If
334 positive, shift that token. If negative, reduce the rule which
335 number is the opposite. If zero, do what YYDEFACT says.
336 If YYTABLE_NINF, parse error. */
337 #define YYTABLE_NINF ]b4_table_ninf[
338 static const ]b4_int_type_for([b4_table
])[ yytable
[] =
343 /* YYCONFLP[YYPACT[STATE-NUM]] -- Pointer into YYCONFL of start of
344 list of conflicting reductions corresponding to action entry for
345 state STATE-NUM in yytable. 0 means no conflicts. The list in
346 yyconfl is terminated by a rule number of 0. */
347 static const ]b4_int_type_for([b4_conflict_list_heads
])[ yyconflp
[] =
349 ]b4_conflict_list_heads
[
352 /* YYCONFL[I] -- lists of conflicting rule numbers, each terminated by
353 0, pointed into by YYCONFLP. */
354 ]dnl Do
not use b4_int_type_for here
, since there are places where
355 dnl pointers onto yyconfl are taken
, which type is
"short *".
356 dnl We probably ought to introduce a type
for confl
.
357 [static const short yyconfl
[] =
359 ]b4_conflicting_rules
[
362 static const ]b4_int_type_for([b4_check
])[ yycheck
[] =
368 /* The user can define YYPARSE_PARAM as the name of an argument to be passed
369 into yyparse. The argument should have type void *.
370 It should actually point to an object.
371 Grammar actions can access the variable by casting it
372 to the proper pointer type. */
375 # define YYPARSE_PARAM_ARG void *YYPARSE_PARAM
376 #else /* !YYPARSE_PARAM */
377 # define YYPARSE_PARAM_ARG void
378 #endif /* !YYPARSE_PARAM */
380 /* Prevent warning if -Wstrict-prototypes. */
382 # ifdef YYPARSE_PARAM
383 int yyparse (void *);
389 /* Error token number */
392 /* YYLLOC_DEFAULT -- Compute the default location (before the actions
395 #define YYRHSLOC(yyRhs,YYK) (yyRhs[YYK].yystate.yyloc)
397 #ifndef YYLLOC_DEFAULT
398 # define YYLLOC_DEFAULT(yyCurrent, yyRhs, YYN) \
399 yyCurrent.first_line = YYRHSLOC(yyRhs,1).first_line; \
400 yyCurrent.first_column = YYRHSLOC(yyRhs,1).first_column; \
401 yyCurrent.last_line = YYRHSLOC(yyRhs,YYN).last_line; \
402 yyCurrent.last_column = YYRHSLOC(yyRhs,YYN).last_column;
405 /* YYLEX -- calling `yylex' with the right arguments. */
410 # define YYLEX yylex (yylvalp, b4_location_if([yyllocp, ])YYLEX_PARAM)
412 # define YYLEX yylex (yylvalp[]b4_location_if([, yyllocp]))
414 [#define YYLEX yylex ()])
419 #define yynerrs (yystack->yyerrcnt)
421 #define yychar (yystack->yyrawchar)],
429 static const int YYEOF
= 0;
430 static const int YYEMPTY
= -2;
432 typedef enum { yyok
, yyaccept
, yyabort
, yyerr
} YYRESULTTAG
;
435 do { YYRESULTTAG yyflag = YYE; if (yyflag != yyok) return yyflag; } \
440 #if ! defined (YYFPRINTF)
441 # define YYFPRINTF fprintf
444 # define YYDPRINTF(Args) \
449 /* Nonzero means print parse trace. It is left uninitialized so that
450 multiple parsers can coexist. */
453 /* Avoid empty `if' bodies. */
454 # define YYDPRINTF(Args) {}
455 #endif /* !YYDEBUG */
457 /* YYINITDEPTH -- initial size of the parser's stacks. */
459 # define YYINITDEPTH ]b4_initdepth[
462 /* YYMAXDEPTH -- maximum size the stacks can grow to (effective only
463 if the built-in stack extension method is used).
465 Do not make this value too large; the results are undefined if
466 SIZE_MAX < YYMAXDEPTH * sizeof (GLRStackItem)
467 evaluated with infinite-precision integer arithmetic. */
474 # define YYMAXDEPTH ]b4_maxdepth[
477 /* Minimum number of free items on the stack allowed after an
478 allocation. This is to allow allocation and initialization
479 to be completed by functions that call expandGLRStack before the
480 stack is expanded, thus insuring that all necessary pointers get
481 properly redirected to new data. */
484 #if ! defined (YYSTACKEXPANDABLE) \
485 && (! defined (__cplusplus) || (YYLTYPE_IS_TRIVIAL && YYSTYPE_IS_TRIVIAL))
486 #define YYSTACKEXPANDABLE 1
488 #define YYSTACKEXPANDABLE 0
491 /** State numbers, as in LALR(1) machine */
492 typedef int yyStateNum
;
494 /** Rule numbers, as in LALR(1) machine */
495 typedef int yyRuleNum
;
497 /** Grammar symbol */
498 typedef short yySymbol
;
500 /** Item references, as in LALR(1) machine */
501 typedef short yyItemNum
;
503 typedef struct yyGLRState yyGLRState
;
504 typedef struct yySemanticOption yySemanticOption
;
505 typedef union yyGLRStackItem yyGLRStackItem
;
506 typedef struct yyGLRStack yyGLRStack
;
507 typedef struct yyGLRStateSet yyGLRStateSet
;
512 yyStateNum yylrState
;
516 yySemanticOption
* yyfirstVal
;
522 struct yyGLRStateSet
{
523 yyGLRState
** yystates
;
524 size_t yysize
, yycapacity
;
527 struct yySemanticOption
{
531 yySemanticOption
* yynext
;
534 union yyGLRStackItem
{
536 yySemanticOption yyoption
;
548 jmp_buf yyexception_buffer
;
549 yyGLRStackItem
* yyitems
;
550 yyGLRStackItem
* yynextFree
;
552 yyGLRState
* yysplitPoint
;
553 yyGLRState
* yylastDeleted
;
554 yyGLRStateSet yytops
;
557 static void yyinitGLRStack (yyGLRStack
* yystack
, size_t yysize
);
558 static void yyexpandGLRStack (yyGLRStack
* yystack
);
559 static void yyfreeGLRStack (yyGLRStack
* yystack
);
562 yyFail (yyGLRStack
* yystack
, const char* yyformat
, ...)
564 if (yyformat
!= NULL
)
568 va_start (yyap
, yyformat
);
569 yystack
->yyerrflag
= 1;
570 vsprintf (yymsg
, yyformat
, yyap
);
573 longjmp (yystack
->yyexception_buffer
, 1);
576 #if YYDEBUG || YYERROR_VERBOSE
577 /** A printable representation of TOKEN. Valid until next call to
579 static inline const char*
580 yytokenName (yySymbol yytoken
)
582 return yytname
[yytoken
];
586 /** Perform user action for rule number YYN, with RHS length YYRHSLEN,
587 * and top stack item YYVSP. YYLVALP points to place to put semantic
588 * value ($$), and yylocp points to place for location information
589 * (@$). Returns yyok for normal return, yyaccept for YYACCEPT,
590 * yyerr for YYERROR, yyabort for YYABORT. */
592 yyuserAction (yyRuleNum yyn
, int yyrhslen
, yyGLRStackItem
* yyvsp
,
593 YYSTYPE
* yyvalp
, YYLTYPE
* yylocp
, yyGLRStack
* yystack
)
595 /* Avoid `unused' warnings in there are no $n. */
600 *yyvalp
= yyval_default
;
601 *yylocp
= yyloc_default
;
605 *yyvalp
= yyvsp
[1-yyrhslen
].yystate
.yysemantics
.yysval
;
606 *yylocp
= yyvsp
[1-yyrhslen
].yystate
.yyloc
;
609 # define yyval (*yyvalp)
611 # define yyerrok (yystack->yyerrState = 0)
613 # define YYACCEPT return yyaccept
615 # define YYABORT return yyabort
617 # define YYERROR return yyerr
619 # define YYRECOVERING (yystack->yyerrState != 0)
621 # define yyclearin (yychar = *(yystack->yytokenp) = YYEMPTY)
623 # define YYBACKUP(Token, Value) \
625 yyerror ("syntax error: cannot back up"); \
644 /* Line __line__ of __file__. */
645 #line __oline__ "__ofile__"
650 yyuserMerge (int yyn
, YYSTYPE
* yy0
, YYSTYPE
* yy1
)
652 YYSTYPE yyval
= *yy0
;
653 /* `Use' the arguments. */
664 /* Bison grammar-table manipulation */
666 /** Number of symbols composing the right hand side of rule #RULE. */
668 yyrhsLength (yyRuleNum yyrule
)
673 /** Left-hand-side symbol for rule #RULE. */
674 static inline yySymbol
675 yylhsNonterm (yyRuleNum yyrule
)
680 /** True iff LR state STATE has only a default reduction (regardless
683 yyisDefaultedState (yyStateNum yystate
)
685 return yypact
[yystate
] == YYPACT_NINF
;
688 /** The default reduction for STATE, assuming it has one. */
689 static inline yyRuleNum
690 yydefaultAction (yyStateNum yystate
)
692 return yydefact
[yystate
];
695 /** Set *YYACTION to the action to take in YYSTATE on seeing YYTOKEN.
697 * R < 0: Reduce on rule -R.
699 * R > 0: Shift to state R.
700 * Set *CONFLICTS to a pointer into yyconfl to 0-terminated list of
701 * conflicting reductions.
704 yygetLRActions (yyStateNum yystate
, int yytoken
,
705 int* yyaction
, const short** yyconflicts
)
707 int yyindex
= yypact
[yystate
] + yytoken
;
708 if (yyindex
< 0 || YYLAST
< yyindex
|| yycheck
[yyindex
] != yytoken
)
710 *yyaction
= -yydefact
[yystate
];
711 *yyconflicts
= yyconfl
;
713 else if (yytable
[yyindex
] != YYTABLE_NINF
)
715 *yyaction
= yytable
[yyindex
];
716 *yyconflicts
= yyconfl
+ yyconflp
[yyindex
];
721 *yyconflicts
= yyconfl
+ yyconflp
[yyindex
];
725 static inline yyStateNum
726 yyLRgotoState (yyStateNum yystate
, yySymbol yylhs
)
729 yyr
= yypgoto
[yylhs
- YYNTOKENS
] + yystate
;
730 if (0 <= yyr
&& yyr
<= YYLAST
&& yycheck
[yyr
] == yystate
)
733 return yydefgoto
[yylhs
- YYNTOKENS
];
737 yyisShiftAction (int yyaction
)
743 yyisErrorAction (int yyaction
)
745 return yyaction
== 0;
750 /** True iff the semantic value of the edge leading to STATE is
753 yyhasResolvedValue (yyGLRState
* yystate
)
755 return yystate
->yyresolved
;
759 yyaddDeferredAction (yyGLRStack
* yystack
, yyGLRState
* yystate
,
760 yyGLRState
* yyrhs
, yyRuleNum yyrule
)
762 yySemanticOption
* yynewItem
;
763 yynewItem
= &yystack
->yynextFree
->yyoption
;
764 yystack
->yyspaceLeft
-= 1;
765 yystack
->yynextFree
+= 1;
766 yynewItem
->yyisState
= yyfalse
;
767 yynewItem
->yystate
= yyrhs
;
768 yynewItem
->yyrule
= yyrule
;
769 yynewItem
->yynext
= yystate
->yysemantics
.yyfirstVal
;
770 yystate
->yysemantics
.yyfirstVal
= yynewItem
;
771 if (yystack
->yyspaceLeft
< YYHEADROOM
)
772 yyexpandGLRStack (yystack
);
777 /** Initialize SET to a singleton set containing an empty stack. */
779 yyinitStateSet (yyGLRStateSet
* yyset
)
782 yyset
->yycapacity
= 16;
783 yyset
->yystates
= (yyGLRState
**) malloc (16 * sizeof (yyset
->yystates
[0]));
784 yyset
->yystates
[0] = NULL
;
787 static void yyfreeStateSet (yyGLRStateSet
* yyset
)
789 free (yyset
->yystates
);
792 /** Initialize STACK to a single empty stack, with total maximum
793 * capacity for all stacks of SIZE. */
795 yyinitGLRStack (yyGLRStack
* yystack
, size_t yysize
)
797 yystack
->yyerrflag
= 0;
798 yystack
->yyerrState
= 0;
800 yystack
->yyspaceLeft
= yysize
;
801 yystack
->yynextFree
= yystack
->yyitems
=
802 (yyGLRStackItem
*) malloc (yysize
* sizeof (yystack
->yynextFree
[0]));
803 yystack
->yysplitPoint
= NULL
;
804 yystack
->yylastDeleted
= NULL
;
805 yyinitStateSet (&yystack
->yytops
);
808 #define YYRELOC(YYFROMITEMS,YYTOITEMS,YYX,YYTYPE) \
809 &((YYTOITEMS) - ((YYFROMITEMS) - (yyGLRStackItem*) (YYX)))->YYTYPE
811 /** If STACK is expandable, extend it. WARNING: Pointers into the
812 stack from outside should be considered invalid after this call.
813 We always expand when there are 1 or fewer items left AFTER an
814 allocation, so that we can avoid having external pointers exist
815 across an allocation. */
817 yyexpandGLRStack (yyGLRStack
* yystack
)
819 #if YYSTACKEXPANDABLE
820 yyGLRStack yynewStack
;
821 yyGLRStackItem
* yyp0
, *yyp1
;
822 size_t yysize
, yynewSize
;
824 yysize
= yystack
->yynextFree
- yystack
->yyitems
;
825 if (yysize
>= YYMAXDEPTH
)
826 yyFail (yystack
, "parsing stack overflow (%d items)", yysize
);
827 yynewSize
= 2*yysize
;
828 if (yynewSize
> YYMAXDEPTH
)
829 yynewSize
= YYMAXDEPTH
;
830 yyinitGLRStack (&yynewStack
, yynewSize
);
831 for (yyp0
= yystack
->yyitems
, yyp1
= yynewStack
.yyitems
, yyn
= yysize
;
833 yyn
-= 1, yyp0
+= 1, yyp1
+= 1)
838 yyGLRState
* yys0
= &yyp0
->yystate
;
839 yyGLRState
* yys1
= &yyp1
->yystate
;
840 if (yys0
->yypred
!= NULL
)
842 YYRELOC (yyp0
, yyp1
, yys0
->yypred
, yystate
);
843 if (! yys0
->yyresolved
&& yys0
->yysemantics
.yyfirstVal
!= NULL
)
844 yys1
->yysemantics
.yyfirstVal
=
845 YYRELOC(yyp0
, yyp1
, yys0
->yysemantics
.yyfirstVal
, yyoption
);
849 yySemanticOption
* yyv0
= &yyp0
->yyoption
;
850 yySemanticOption
* yyv1
= &yyp1
->yyoption
;
851 if (yyv0
->yystate
!= NULL
)
852 yyv1
->yystate
= YYRELOC (yyp0
, yyp1
, yyv0
->yystate
, yystate
);
853 if (yyv0
->yynext
!= NULL
)
854 yyv1
->yynext
= YYRELOC (yyp0
, yyp1
, yyv0
->yynext
, yyoption
);
857 if (yystack
->yysplitPoint
!= NULL
)
858 yystack
->yysplitPoint
= YYRELOC (yystack
->yyitems
, yynewStack
.yyitems
,
859 yystack
->yysplitPoint
, yystate
);
861 for (yyn
= 0; yyn
< yystack
->yytops
.yysize
; yyn
+= 1)
862 if (yystack
->yytops
.yystates
[yyn
] != NULL
)
863 yystack
->yytops
.yystates
[yyn
] =
864 YYRELOC (yystack
->yyitems
, yynewStack
.yyitems
,
865 yystack
->yytops
.yystates
[yyn
], yystate
);
866 free (yystack
->yyitems
);
867 yystack
->yyitems
= yynewStack
.yyitems
;
868 yystack
->yynextFree
= yynewStack
.yynextFree
+ yysize
;
869 yystack
->yyspaceLeft
= yynewStack
.yyspaceLeft
- yysize
;
873 yyFail (yystack
, "parsing stack overflow (%d items)", yysize
);
879 yyfreeGLRStack (yyGLRStack
* yystack
)
881 free (yystack
->yyitems
);
882 yyfreeStateSet (&yystack
->yytops
);
885 /** Assuming that S is a GLRState somewhere on STACK, update the
886 * splitpoint of STACK, if needed, so that it is at least as deep as
889 yyupdateSplit (yyGLRStack
* yystack
, yyGLRState
* yys
)
891 if (yystack
->yysplitPoint
!= NULL
&& yystack
->yysplitPoint
> yys
)
892 yystack
->yysplitPoint
= yys
;
895 /** Invalidate stack #K in STACK. */
897 yymarkStackDeleted (yyGLRStack
* yystack
, int yyk
)
899 if (yystack
->yytops
.yystates
[yyk
] != NULL
)
900 yystack
->yylastDeleted
= yystack
->yytops
.yystates
[yyk
];
901 yystack
->yytops
.yystates
[yyk
] = NULL
;
904 /** Undelete the last stack that was marked as deleted. Can only be
905 done once after a deletion, and only when all other stacks have
908 yyundeleteLastStack (yyGLRStack
* yystack
)
910 if (yystack
->yylastDeleted
== NULL
|| yystack
->yytops
.yysize
!= 0)
912 yystack
->yytops
.yystates
[0] = yystack
->yylastDeleted
;
913 yystack
->yytops
.yysize
= 1;
914 YYDPRINTF ((stderr
, "Restoring last deleted stack as stack #0.\n"));
915 yystack
->yylastDeleted
= NULL
;
919 yyremoveDeletes (yyGLRStack
* yystack
)
923 while (yyj
< yystack
->yytops
.yysize
)
925 if (yystack
->yytops
.yystates
[yyi
] == NULL
)
928 YYDPRINTF ((stderr
, "Removing dead stacks.\n"));
929 yystack
->yytops
.yysize
-= 1;
933 yystack
->yytops
.yystates
[yyj
] = yystack
->yytops
.yystates
[yyi
];
935 YYDPRINTF ((stderr
, "Rename stack %d -> %d.\n", yyi
, yyj
));
942 /** Shift to a new state on stack #K of STACK, corresponding to LR state
943 * LRSTATE, at input position POSN, with (resolved) semantic value SVAL. */
945 yyglrShift (yyGLRStack
* yystack
, int yyk
, yyStateNum yylrState
, size_t yyposn
,
946 YYSTYPE yysval
, YYLTYPE
* yylocp
)
948 yyGLRStackItem
* yynewItem
;
950 yynewItem
= yystack
->yynextFree
;
951 yystack
->yynextFree
+= 1;
952 yystack
->yyspaceLeft
-= 1;
953 yynewItem
->yystate
.yyisState
= yytrue
;
954 yynewItem
->yystate
.yylrState
= yylrState
;
955 yynewItem
->yystate
.yyposn
= yyposn
;
956 yynewItem
->yystate
.yyresolved
= yytrue
;
957 yynewItem
->yystate
.yypred
= yystack
->yytops
.yystates
[yyk
];
958 yystack
->yytops
.yystates
[yyk
] = &yynewItem
->yystate
;
959 yynewItem
->yystate
.yysemantics
.yysval
= yysval
;
960 yynewItem
->yystate
.yyloc
= *yylocp
;
961 if (yystack
->yyspaceLeft
< YYHEADROOM
)
962 yyexpandGLRStack (yystack
);
965 /** Shift to a new state on stack #K of STACK, to a new state
966 * corresponding to LR state LRSTATE, at input position POSN, with
967 * the (unresolved) semantic value of RHS under the action for RULE. */
969 yyglrShiftDefer (yyGLRStack
* yystack
, int yyk
, yyStateNum yylrState
,
970 size_t yyposn
, yyGLRState
* yyrhs
, yyRuleNum yyrule
)
972 yyGLRStackItem
* yynewItem
;
974 yynewItem
= yystack
->yynextFree
;
975 yynewItem
->yystate
.yyisState
= yytrue
;
976 yynewItem
->yystate
.yylrState
= yylrState
;
977 yynewItem
->yystate
.yyposn
= yyposn
;
978 yynewItem
->yystate
.yyresolved
= yyfalse
;
979 yynewItem
->yystate
.yypred
= yystack
->yytops
.yystates
[yyk
];
980 yynewItem
->yystate
.yysemantics
.yyfirstVal
= NULL
;
981 yystack
->yytops
.yystates
[yyk
] = &yynewItem
->yystate
;
982 yystack
->yynextFree
+= 1;
983 yystack
->yyspaceLeft
-= 1;
984 yyaddDeferredAction (yystack
, &yynewItem
->yystate
, yyrhs
, yyrule
);
987 /** Pop the symbols consumed by reduction #RULE from the top of stack
988 * #K of STACK, and perform the appropriate semantic action on their
989 * semantic values. Assumes that all ambiguities in semantic values
990 * have been previously resolved. Set *VALP to the resulting value,
991 * and *LOCP to the computed location (if any). Return value is as
994 yydoAction (yyGLRStack
* yystack
, int yyk
, yyRuleNum yyrule
,
995 YYSTYPE
* yyvalp
, YYLTYPE
* yylocp
)
997 int yynrhs
= yyrhsLength (yyrule
);
999 if (yystack
->yysplitPoint
== NULL
)
1001 /* Standard special case: single stack. */
1002 yyGLRStackItem
* yyrhs
= (yyGLRStackItem
*) yystack
->yytops
.yystates
[yyk
];
1004 yystack
->yynextFree
-= yynrhs
;
1005 yystack
->yyspaceLeft
+= yynrhs
;
1006 yystack
->yytops
.yystates
[0] = & yystack
->yynextFree
[-1].yystate
;
1009 *yyvalp
= yyval_default
;
1010 *yylocp
= yyloc_default
;
1014 *yyvalp
= yyrhs
[1-yynrhs
].yystate
.yysemantics
.yysval
;
1015 *yylocp
= yyrhs
[1-yynrhs
].yystate
.yyloc
;
1017 return yyuserAction (yyrule
, yynrhs
, yyrhs
, yyvalp
, yylocp
, yystack
);
1023 yyGLRStackItem yyrhsVals
[YYMAXRHS
];
1024 for (yyi
= yynrhs
-1, yys
= yystack
->yytops
.yystates
[yyk
]; yyi
>= 0;
1025 yyi
-= 1, yys
= yys
->yypred
)
1027 assert (yys
->yypred
!= NULL
);
1028 yyrhsVals
[yyi
].yystate
.yyresolved
= yytrue
;
1029 yyrhsVals
[yyi
].yystate
.yysemantics
.yysval
= yys
->yysemantics
.yysval
;
1030 yyrhsVals
[yyi
].yystate
.yyloc
= yys
->yyloc
;
1032 yyupdateSplit (yystack
, yys
);
1033 yystack
->yytops
.yystates
[yyk
] = yys
;
1036 *yyvalp
= yyval_default
;
1037 *yylocp
= yyloc_default
;
1041 *yyvalp
= yyrhsVals
[0].yystate
.yysemantics
.yysval
;
1042 *yylocp
= yyrhsVals
[0].yystate
.yyloc
;
1044 return yyuserAction (yyrule
, yynrhs
, yyrhsVals
+ (yynrhs
-1),
1045 yyvalp
, yylocp
, yystack
);
1049 /** Pop items off stack #K of STACK according to grammar rule RULE,
1050 * and push back on the resulting nonterminal symbol. Perform the
1051 * semantic action associated with RULE and store its value with the
1052 * newly pushed state, if FORCEEVAL or if STACK is currently
1053 * unambiguous. Otherwise, store the deferred semantic action with
1054 * the new state. If the new state would have an identical input
1055 * position, LR state, and predecessor to an existing state on the stack,
1056 * it is identified with that existing state, eliminating stack #K from
1057 * the STACK. In this case, the (necessarily deferred) semantic value is
1058 * added to the options for the existing state's semantic value.
1060 static inline YYRESULTTAG
1061 yyglrReduce (yyGLRStack
* yystack
, size_t yyk
, yyRuleNum yyrule
,
1064 size_t yyposn
= yystack
->yytops
.yystates
[yyk
]->yyposn
;
1066 if (yyforceEval
|| yystack
->yysplitPoint
== NULL
)
1075 YYDPRINTF ((stderr
, "Reducing stack %d by rule %d (line %d),",
1076 yyk
, yyrule
- 1, yyrline
[yyrule
]));
1077 /* Print the symbols being reduced, and their result. */
1078 for (yyi
= yyprhs
[yyrule
]; yyrhs
[yyi
] >= 0; yyi
++)
1079 YYFPRINTF (stderr
, "%s ", yytokenName (yyrhs
[yyi
]));
1080 YYFPRINTF (stderr
, " -> %s\n", yytokenName (yyr1
[yyrule
]));
1083 YYCHK (yydoAction (yystack
, yyk
, yyrule
, &yysval
, &yyloc
));
1084 yyglrShift (yystack
, yyk
,
1085 yyLRgotoState (yystack
->yytops
.yystates
[yyk
]->yylrState
,
1086 yylhsNonterm (yyrule
)),
1087 yyposn
, yysval
, &yyloc
);
1088 YYDPRINTF ((stderr
, "Stack %d entering state %d\n",
1089 yyk
, yystack
->yytops
.yystates
[yyk
]->yylrState
));
1095 yyGLRState
* yys
, *yys0
= yystack
->yytops
.yystates
[yyk
];
1096 yyStateNum yynewLRState
;
1098 for (yys
= yystack
->yytops
.yystates
[yyk
], yyn
= yyrhsLength (yyrule
);
1102 assert (yys
!= NULL
);
1104 yyupdateSplit (yystack
, yys
);
1105 yynewLRState
= yyLRgotoState (yys
->yylrState
, yylhsNonterm (yyrule
));
1107 "Reduced stack %d by rule #%d; action deferred. "
1108 "Now in state %d.\n",
1109 yyk
, yyrule
-1, yynewLRState
));
1110 for (yyi
= 0; yyi
< yystack
->yytops
.yysize
; yyi
+= 1)
1111 if (yyi
!= yyk
&& yystack
->yytops
.yystates
[yyi
] != NULL
)
1113 yyGLRState
* yyp
, *yysplit
= yystack
->yysplitPoint
;
1114 yyp
= yystack
->yytops
.yystates
[yyi
];
1115 while (yyp
!= yys
&& yyp
!= yysplit
&& yyp
->yyposn
>= yyposn
)
1117 if (yyp
->yylrState
== yynewLRState
&& yyp
->yypred
== yys
)
1119 yyaddDeferredAction (yystack
, yyp
, yys0
, yyrule
);
1120 yymarkStackDeleted (yystack
, yyk
);
1121 YYDPRINTF ((stderr
, "Merging stack %d into stack %d.\n",
1128 yystack
->yytops
.yystates
[yyk
] = yys
;
1129 yyglrShiftDefer (yystack
, yyk
, yynewLRState
, yyposn
, yys0
, yyrule
);
1135 yysplitStack (yyGLRStack
* yystack
, int yyk
)
1137 if (yystack
->yysplitPoint
== NULL
)
1140 yystack
->yysplitPoint
= yystack
->yytops
.yystates
[yyk
];
1142 if (yystack
->yytops
.yysize
>= yystack
->yytops
.yycapacity
)
1144 yystack
->yytops
.yycapacity
*= 2;
1145 yystack
->yytops
.yystates
=
1146 (yyGLRState
**) realloc (yystack
->yytops
.yystates
,
1147 yystack
->yytops
.yycapacity
1148 * sizeof (yyGLRState
*));
1150 yystack
->yytops
.yystates
[yystack
->yytops
.yysize
]
1151 = yystack
->yytops
.yystates
[yyk
];
1152 yystack
->yytops
.yysize
+= 1;
1153 return yystack
->yytops
.yysize
-1;
1156 /** True iff Y0 and Y1 represent identical options at the top level.
1157 * That is, they represent the same rule applied to RHS symbols
1158 * that produce the same terminal symbols. */
1160 yyidenticalOptions (yySemanticOption
* yyy0
, yySemanticOption
* yyy1
)
1162 if (yyy0
->yyrule
== yyy1
->yyrule
)
1164 yyGLRState
*yys0
, *yys1
;
1166 for (yys0
= yyy0
->yystate
, yys1
= yyy1
->yystate
,
1167 yyn
= yyrhsLength (yyy0
->yyrule
);
1169 yys0
= yys0
->yypred
, yys1
= yys1
->yypred
, yyn
-= 1)
1170 if (yys0
->yyposn
!= yys1
->yyposn
)
1178 /** Assuming identicalOptions (Y0,Y1), (destructively) merge the
1179 * alternative semantic values for the RHS-symbols of Y1 into the
1180 * corresponding semantic value sets of the symbols of Y0. */
1182 yymergeOptionSets (yySemanticOption
* yyy0
, yySemanticOption
* yyy1
)
1184 yyGLRState
*yys0
, *yys1
;
1186 for (yys0
= yyy0
->yystate
, yys1
= yyy1
->yystate
,
1187 yyn
= yyrhsLength (yyy0
->yyrule
);
1189 yys0
= yys0
->yypred
, yys1
= yys1
->yypred
, yyn
-= 1)
1192 else if (! yys0
->yyresolved
&& ! yys1
->yyresolved
)
1194 yySemanticOption
* yyz
;
1195 for (yyz
= yys0
->yysemantics
.yyfirstVal
; yyz
->yynext
!= NULL
;
1198 yyz
->yynext
= yys1
->yysemantics
.yyfirstVal
;
1202 /** Y0 and Y1 represent two possible actions to take in a given
1203 * parsing state; return 0 if no combination is possible,
1204 * 1 if user-mergeable, 2 if Y0 is preferred, 3 if Y1 is preferred. */
1206 yypreference (yySemanticOption
* y0
, yySemanticOption
* y1
)
1208 yyRuleNum r0
= y0
->yyrule
, r1
= y1
->yyrule
;
1209 int p0
= yydprec
[r0
], p1
= yydprec
[r1
];
1213 if (yymerger
[r0
] == 0 || yymerger
[r0
] != yymerger
[r1
])
1218 if (p0
== 0 || p1
== 0)
1227 static YYRESULTTAG
yyresolveValue (yySemanticOption
* yyoptionList
,
1228 yyGLRStack
* yystack
, YYSTYPE
* yyvalp
,
1232 yyresolveStates (yyGLRState
* yys
, int yyn
, yyGLRStack
* yystack
)
1237 assert (yys
->yypred
!= NULL
);
1238 yyflag
= yyresolveStates (yys
->yypred
, yyn
-1, yystack
);
1241 if (! yys
->yyresolved
)
1243 yyflag
= yyresolveValue (yys
->yysemantics
.yyfirstVal
, yystack
,
1244 &yys
->yysemantics
.yysval
, &yys
->yyloc
);
1247 yys
->yyresolved
= yytrue
;
1254 yyresolveAction (yySemanticOption
* yyopt
, yyGLRStack
* yystack
,
1255 YYSTYPE
* yyvalp
, YYLTYPE
* yylocp
)
1257 yyGLRStackItem yyrhsVals
[YYMAXRHS
];
1261 yynrhs
= yyrhsLength (yyopt
->yyrule
);
1262 YYCHK (yyresolveStates (yyopt
->yystate
, yynrhs
, yystack
));
1263 for (yyi
= yynrhs
-1, yys
= yyopt
->yystate
; yyi
>= 0;
1264 yyi
-= 1, yys
= yys
->yypred
)
1266 assert (yys
->yypred
!= NULL
);
1267 yyrhsVals
[yyi
].yystate
.yyresolved
= yytrue
;
1268 yyrhsVals
[yyi
].yystate
.yysemantics
.yysval
= yys
->yysemantics
.yysval
;
1269 yyrhsVals
[yyi
].yystate
.yyloc
= yys
->yyloc
;
1271 return yyuserAction (yyopt
->yyrule
, yynrhs
, yyrhsVals
+ (yynrhs
-1),
1272 yyvalp
, yylocp
, yystack
);
1276 static yyGLRState YYLEFTMOST_STATE
= { 0, 0, -1, NULL
, 0, { NULL
} };
1278 static void yyreportTree (yySemanticOption
* yyx
, int yyindent
)
1280 int yynrhs
= yyrhsLength (yyx
->yyrule
);
1283 yyGLRState
* yystates
[YYMAXRHS
];
1285 for (yyi
= yynrhs
, yys
= yyx
->yystate
; yyi
> 0; yyi
-= 1, yys
= yys
->yypred
)
1286 yystates
[yyi
] = yys
;
1288 yystates
[0] = &YYLEFTMOST_STATE
;
1292 if (yys
->yyposn
+1 > yyx
->yystate
->yyposn
)
1293 YYFPRINTF (stderr
, "%*s%s -> <Rule %d, empty>\n",
1294 yyindent
, "", yytokenName (yylhsNonterm (yyx
->yyrule
)),
1297 YYFPRINTF (stderr
, "%*s%s -> <Rule %d, tokens %d .. %d>\n",
1298 yyindent
, "", yytokenName (yylhsNonterm (yyx
->yyrule
)),
1299 yyx
->yyrule
, yys
->yyposn
+1, yyx
->yystate
->yyposn
);
1300 for (yyi
= 1; yyi
<= yynrhs
; yyi
+= 1)
1302 if (yystates
[yyi
]->yyresolved
)
1304 if (yystates
[yyi
-1]->yyposn
+1 > yystates
[yyi
]->yyposn
)
1305 YYFPRINTF (stderr
, "%*s%s <empty>\n", yyindent
+2, "",
1306 yytokenName (yyrhs
[yyprhs
[yyx
->yyrule
]+yyi
-1]));
1308 YYFPRINTF (stderr
, "%*s%s <tokens %d .. %d>\n", yyindent
+2, "",
1309 yytokenName (yyrhs
[yyprhs
[yyx
->yyrule
]+yyi
-1]),
1310 yystates
[yyi
-1]->yyposn
+1, yystates
[yyi
]->yyposn
);
1313 yyreportTree (yystates
[yyi
]->yysemantics
.yyfirstVal
, yyindent
+2);
1319 yyreportAmbiguity (yySemanticOption
* yyx0
, yySemanticOption
* yyx1
,
1320 yyGLRStack
* yystack
)
1322 /* `Unused' warnings. */
1327 YYFPRINTF (stderr
, "Ambiguity detected.\n");
1328 YYFPRINTF (stderr
, "Option 1,\n");
1329 yyreportTree (yyx0
, 2);
1330 YYFPRINTF (stderr
, "\nOption 2,\n");
1331 yyreportTree (yyx1
, 2);
1332 YYFPRINTF (stderr
, "\n");
1334 yyFail (yystack
, "ambiguity detected");
1338 /** Resolve the ambiguity represented by OPTIONLIST, perform the indicated
1339 * actions, and return the result. */
1341 yyresolveValue (yySemanticOption
* yyoptionList
, yyGLRStack
* yystack
,
1342 YYSTYPE
* yyvalp
, YYLTYPE
* yylocp
)
1344 yySemanticOption
* yybest
;
1345 yySemanticOption
* yyp
;
1348 yybest
= yyoptionList
;
1350 for (yyp
= yyoptionList
->yynext
; yyp
!= NULL
; yyp
= yyp
->yynext
)
1352 if (yyidenticalOptions (yybest
, yyp
))
1353 yymergeOptionSets (yybest
, yyp
);
1355 switch (yypreference (yybest
, yyp
))
1358 yyreportAmbiguity (yybest
, yyp
, yystack
);
1374 int yyprec
= yydprec
[yybest
->yyrule
];
1375 YYCHK (yyresolveAction (yybest
, yystack
, yyvalp
, yylocp
));
1376 for (yyp
= yybest
->yynext
; yyp
!= NULL
; yyp
= yyp
->yynext
)
1378 if (yyprec
== yydprec
[yyp
->yyrule
])
1382 YYCHK (yyresolveAction (yyp
, yystack
, &yyval1
, &yydummy
));
1383 *yyvalp
= yyuserMerge (yymerger
[yyp
->yyrule
], yyvalp
, &yyval1
);
1389 return yyresolveAction (yybest
, yystack
, yyvalp
, yylocp
);
1393 yyresolveStack (yyGLRStack
* yystack
)
1395 if (yystack
->yysplitPoint
!= NULL
)
1400 for (yyn
= 0, yys
= yystack
->yytops
.yystates
[0];
1401 yys
!= yystack
->yysplitPoint
;
1402 yys
= yys
->yypred
, yyn
+= 1)
1404 YYCHK (yyresolveStates (yystack
->yytops
.yystates
[0], yyn
, yystack
));
1410 yycompressStack (yyGLRStack
* yystack
)
1412 yyGLRState
* yyp
, *yyq
, *yyr
;
1414 if (yystack
->yytops
.yysize
!= 1 || yystack
->yysplitPoint
== NULL
)
1417 for (yyp
= yystack
->yytops
.yystates
[0], yyq
= yyp
->yypred
, yyr
= NULL
;
1418 yyp
!= yystack
->yysplitPoint
;
1419 yyr
= yyp
, yyp
= yyq
, yyq
= yyp
->yypred
)
1422 yystack
->yyspaceLeft
+= yystack
->yynextFree
- yystack
->yyitems
;
1423 yystack
->yynextFree
= ((yyGLRStackItem
*) yystack
->yysplitPoint
) + 1;
1424 yystack
->yyspaceLeft
-= yystack
->yynextFree
- yystack
->yyitems
;
1425 yystack
->yysplitPoint
= NULL
;
1426 yystack
->yylastDeleted
= NULL
;
1430 yystack
->yynextFree
->yystate
= *yyr
;
1432 yystack
->yynextFree
->yystate
.yypred
= & yystack
->yynextFree
[-1].yystate
;
1433 yystack
->yytops
.yystates
[0] = &yystack
->yynextFree
->yystate
;
1434 yystack
->yynextFree
+= 1;
1435 yystack
->yyspaceLeft
-= 1;
1440 yyprocessOneStack (yyGLRStack
* yystack
, int yyk
,
1441 size_t yyposn
, YYSTYPE
* yylvalp
, YYLTYPE
* yyllocp
)
1444 const short* yyconflicts
;
1446 yySymbol
* const yytokenp
= yystack
->yytokenp
;
1448 while (yystack
->yytops
.yystates
[yyk
] != NULL
)
1450 yyStateNum yystate
= yystack
->yytops
.yystates
[yyk
]->yylrState
;
1452 assert (yystate
!= YYFINAL
);
1453 if (yyisDefaultedState (yystate
))
1455 yyrule
= yydefaultAction (yystate
);
1458 YYDPRINTF ((stderr
, "Stack %d dies.\n", yyk
));
1459 yymarkStackDeleted (yystack
, yyk
);
1462 YYCHK (yyglrReduce (yystack
, yyk
, yyrule
, yyfalse
));
1466 if (*yytokenp
== YYEMPTY
)
1468 YYDPRINTF ((stderr
, "Reading a token: "));
1470 *yytokenp
= YYTRANSLATE(yychar
);
1471 YYDPRINTF ((stderr
, "Next token is %s\n",
1472 yytokenName (*yytokenp
)));
1474 yygetLRActions (yystate
, *yytokenp
, &yyaction
, &yyconflicts
);
1476 while (*yyconflicts
!= 0)
1478 int yynewStack
= yysplitStack (yystack
, yyk
);
1479 YYDPRINTF ((stderr
, "Splitting off stack %d from %d.\n",
1481 YYCHK (yyglrReduce (yystack
, yynewStack
, *yyconflicts
, yyfalse
));
1482 YYCHK (yyprocessOneStack (yystack
, yynewStack
, yyposn
,
1487 if (yyisShiftAction (yyaction
))
1489 YYDPRINTF ((stderr
, "Shifting token %s on stack %d, ",
1490 yytokenName (*yytokenp
), yyk
));
1491 yyglrShift (yystack
, yyk
, yyaction
, yyposn
+1, *yylvalp
, yyllocp
);
1492 YYDPRINTF ((stderr
, "which is now in state #%d\n",
1493 yystack
->yytops
.yystates
[yyk
]->yylrState
));
1496 else if (yyisErrorAction (yyaction
))
1498 YYDPRINTF ((stderr
, "Stack %d dies.\n", yyk
));
1499 yymarkStackDeleted (yystack
, yyk
);
1503 YYCHK (yyglrReduce (yystack
, yyk
, -yyaction
, yyfalse
));
1510 yyreportParseError (yyGLRStack
* yystack
, YYSTYPE
* yylvalp
, YYLTYPE
* yyllocp
)
1512 /* `Unused' warnings. */
1516 if (yystack
->yyerrState
== 0)
1519 yySymbol
* const yytokenp
= yystack
->yytokenp
;
1520 int yyn
, yyx
, yycount
;
1522 const char* yyprefix
;
1525 yyn
= yypact
[yystack
->yytops
.yystates
[0]->yylrState
];
1526 if (YYPACT_NINF
< yyn
&& yyn
< YYLAST
)
1529 /* Start YYX at -YYN if negative to avoid negative indexes in
1531 yysize
= sizeof ("parse error, unexpected ")
1532 + strlen (yytokenName (*yytokenp
));
1533 yyprefix
= ", expecting ";
1534 for (yyx
= yyn
< 0 ? -yyn
: 0; yyx
< yytname_size
&& yycount
<= 5;
1536 if (yycheck
[yyx
+ yyn
] == yyx
&& yyx
!= YYTERROR
)
1537 yysize
+= strlen (yytokenName (yyx
)) + strlen (yyprefix
),
1538 yycount
+= 1, yyprefix
= " or ";
1539 yymsg
= yyp
= (char*) malloc (yysize
);
1540 yyp
+= sprintf (yyp
, "parse error, unexpected %s",
1541 yytokenName (*yytokenp
));
1544 yyprefix
= ", expecting ";
1545 for (yyx
= yyn
< 0 ? -yyn
: 0; yyx
< yytname_size
; yyx
+= 1)
1546 if (yycheck
[yyx
+ yyn
] == yyx
&& yyx
!= YYTERROR
)
1548 yyp
+= sprintf (yyp
, "%s%s", yyprefix
, yytokenName (yyx
));
1557 yyerror ("parse error");
1562 /* Recover from a syntax error on YYSTACK, assuming that YYTOKENP,
1563 YYLVALP, and YYLLOCP point to the syntactic category, semantic
1564 value, and location of the lookahead. */
1566 yyrecoverParseError (yyGLRStack
* yystack
, YYSTYPE
* yylvalp
, YYLTYPE
* yyllocp
)
1568 yySymbol
* const yytokenp
= yystack
->yytokenp
;
1572 if (yystack
->yyerrState
== 0)
1573 yystack
->yyerrState
= 3;
1574 else if (yystack
->yyerrState
== 3)
1575 /* We just shifted the error token and (perhaps) took some
1576 reductions. Skip tokens until we can proceed. */
1579 if (*yytokenp
== YYEOF
)
1580 yyFail (yystack
, NULL
);
1581 if (*yytokenp
!= YYEMPTY
)
1582 YYDPRINTF ((stderr
, "Discarding token %s\n",
1583 yytokenName (*yytokenp
)));
1584 YYDPRINTF ((stderr
, "Reading a token: "));
1586 *yytokenp
= YYTRANSLATE (yychar
);
1587 YYDPRINTF ((stderr
, "Next token is %s\n", yytokenName (*yytokenp
)));
1588 yyj
= yypact
[yystack
->yytops
.yystates
[0]->yylrState
];
1589 if (yyj
== YYPACT_NINF
)
1590 /* Something's not right; we shouldn't be here. */
1591 yyFail (yystack
, NULL
);
1593 if (yyj
< 0 || YYLAST
< yyj
|| yycheck
[yyj
] != *yytokenp
)
1595 if (yydefact
[yystack
->yytops
.yystates
[0]->yylrState
] != 0)
1598 else if (yytable
[yyj
] != 0 && yytable
[yyj
] != YYTABLE_NINF
)
1602 /* Reduce to one stack. */
1603 for (yyk
= 0; yyk
< yystack
->yytops
.yysize
; yyk
+= 1)
1604 if (yystack
->yytops
.yystates
[yyk
] != NULL
)
1606 if (yyk
>= yystack
->yytops
.yysize
)
1607 yyFail (yystack
, NULL
);
1608 for (yyk
+= 1; yyk
< yystack
->yytops
.yysize
; yyk
+= 1)
1609 yymarkStackDeleted (yystack
, yyk
);
1610 yyremoveDeletes (yystack
);
1611 yycompressStack (yystack
);
1613 /* Now pop stack until we find a state that shifts the error token. */
1614 while (yystack
->yytops
.yystates
[0] != NULL
)
1616 yyj
= yypact
[yystack
->yytops
.yystates
[0]->yylrState
] + YYTERROR
;
1617 if (yyj
!= YYPACT_NINF
+ YYTERROR
&& yyj
>= 0 && yyj
<= YYLAST
&&
1618 yycheck
[yyj
] == YYTERROR
&& yyisShiftAction (yytable
[yyj
]))
1620 yyglrShift (yystack
, 0, yytable
[yyj
],
1621 yystack
->yytops
.yystates
[0]->yyposn
, *yylvalp
, yyllocp
);
1624 yystack
->yytops
.yystates
[0] = yystack
->yytops
.yystates
[0]->yypred
;
1625 yystack
->yynextFree
-= 1;
1626 yystack
->yyspaceLeft
+= 1;
1628 if (yystack
->yytops
.yystates
[0] == NULL
)
1629 yyFail (yystack
, NULL
);
1632 #define YYCHK1(YYE) \
1638 yystack.yyerrflag = 1; \
1641 yystack.yyerrflag = 0; \
1644 goto yyuser_error; \
1649 yyparse (YYPARSE_PARAM_ARG
)
1659 #define yychar (yystack.yyrawchar)
1662 YYSTYPE
* const yylvalp
= &yylval
;
1663 YYLTYPE
* const yyllocp
= &yylloc
;
1665 yyinitGLRStack (&yystack
, YYINITDEPTH
);
1666 yystack
.yytokenp
= &yytoken
;
1668 YYDPRINTF ((stderr
, "Starting parse\n"));
1670 if (setjmp (yystack
.yyexception_buffer
) != 0)
1673 yyglrShift (&yystack
, 0, 0, 0, yyval_default
, &yyloc_default
);
1679 /* For efficiency, we have two loops, of which the first of which
1680 * is specialized to deterministic operation (single stack, no
1681 * potential ambiguity). */
1688 const short* yyconflicts
;
1690 yyStateNum yystate
= yystack
.yytops
.yystates
[0]->yylrState
;
1691 if (yystate
== YYFINAL
)
1693 if (yyisDefaultedState (yystate
))
1695 yyrule
= yydefaultAction (yystate
);
1698 yyreportParseError (&yystack
, yylvalp
, yyllocp
);
1701 YYCHK1 (yyglrReduce (&yystack
, 0, yyrule
, yytrue
));
1705 if (yytoken
== YYEMPTY
)
1707 YYDPRINTF ((stderr
, "Reading a token: "));
1709 yytoken
= YYTRANSLATE (yychar
);
1710 YYDPRINTF ((stderr
, "Next token is %s\n",
1711 yytokenName (yytoken
)));
1713 yygetLRActions (yystate
, yytoken
, &yyaction
, &yyconflicts
);
1714 if (*yyconflicts
!= 0)
1716 if (yyisShiftAction (yyaction
))
1718 YYDPRINTF ((stderr
, "Shifting token %s, ",
1719 yytokenName (yytoken
)));
1720 if (yytoken
!= YYEOF
)
1723 yyglrShift (&yystack
, 0, yyaction
, yyposn
, yylval
, yyllocp
);
1724 if (yystack
.yyerrState
> 0)
1725 yystack
.yyerrState
-= 1;
1726 YYDPRINTF ((stderr
, "Entering state %d\n",
1727 yystack
.yytops
.yystates
[0]->yylrState
));
1729 else if (yyisErrorAction (yyaction
))
1731 yyreportParseError (&yystack
, yylvalp
, yyllocp
);
1735 YYCHK1 (yyglrReduce (&yystack
, 0, -yyaction
, yytrue
));
1742 int yyn
= yystack
.yytops
.yysize
;
1743 for (yys
= 0; yys
< yyn
; yys
+= 1)
1744 YYCHK1 (yyprocessOneStack (&yystack
, yys
, yyposn
,
1748 yyremoveDeletes (&yystack
);
1749 if (yystack
.yytops
.yysize
== 0)
1751 yyundeleteLastStack (&yystack
);
1752 if (yystack
.yytops
.yysize
== 0)
1753 yyFail (&yystack
, "parse error");
1754 YYCHK1 (yyresolveStack (&yystack
));
1755 YYDPRINTF ((stderr
, "Returning to deterministic operation.\n"));
1756 yyreportParseError (&yystack
, yylvalp
, yyllocp
);
1759 else if (yystack
.yytops
.yysize
== 1)
1761 YYCHK1 (yyresolveStack (&yystack
));
1762 YYDPRINTF ((stderr
, "Returning to deterministic operation.\n"));
1763 yycompressStack (&yystack
);
1769 yyrecoverParseError (&yystack
, yylvalp
, yyllocp
);
1770 yyposn
= yystack
.yytops
.yystates
[0]->yyposn
;
1775 yyfreeGLRStack (&yystack
);
1776 return yystack
.yyerrflag
;
1779 /* DEBUGGING ONLY */
1780 static void yypstack (yyGLRStack
* yystack
, int yyk
) ATTRIBUTE_UNUSED
;
1781 static void yypdumpstack (yyGLRStack
* yystack
) ATTRIBUTE_UNUSED
;
1784 yy_yypstack (yyGLRState
* yys
)
1788 yy_yypstack (yys
->yypred
);
1789 fprintf (stderr
, " -> ");
1791 fprintf (stderr
, "%d@%lu", yys
->yylrState
, (unsigned long) yys
->yyposn
);
1795 yypstates (yyGLRState
* yyst
)
1798 fprintf (stderr
, "<null>");
1801 fprintf (stderr
, "\n");
1805 yypstack (yyGLRStack
* yystack
, int yyk
)
1807 yypstates (yystack
->yytops
.yystates
[yyk
]);
1810 #define YYINDEX(YYX) \
1811 ((YYX) == NULL ? -1 : (yyGLRStackItem*) (YYX) - yystack->yyitems)
1815 yypdumpstack (yyGLRStack
* yystack
)
1817 yyGLRStackItem
* yyp
;
1819 for (yyp
= yystack
->yyitems
; yyp
< yystack
->yynextFree
; yyp
+= 1)
1821 fprintf (stderr
, "%3lu. ", (unsigned long) (yyp
- yystack
->yyitems
));
1824 fprintf (stderr
, "Res: %d, LR State: %d, posn: %lu, pred: %ld",
1825 yyp
->yystate
.yyresolved
, yyp
->yystate
.yylrState
,
1826 (unsigned long) yyp
->yystate
.yyposn
,
1827 (long) YYINDEX (yyp
->yystate
.yypred
));
1828 if (! yyp
->yystate
.yyresolved
)
1829 fprintf (stderr
, ", firstVal: %ld",
1830 (long) YYINDEX (yyp
->yystate
.yysemantics
.yyfirstVal
));
1834 fprintf (stderr
, "Option. rule: %d, state: %ld, next: %ld",
1835 yyp
->yyoption
.yyrule
,
1836 (long) YYINDEX (yyp
->yyoption
.yystate
),
1837 (long) YYINDEX (yyp
->yyoption
.yynext
));
1839 fprintf (stderr
, "\n");
1841 fprintf (stderr
, "Tops:");
1842 for (yyi
= 0; yyi
< yystack
->yytops
.yysize
; yyi
+= 1)
1843 fprintf (stderr
, "%lu: %ld; ", (unsigned long) yyi
,
1844 (long) YYINDEX (yystack
->yytops
.yystates
[yyi
]));
1845 fprintf (stderr
, "\n");
1851 m4_if(b4_defines_flag
, 0, [],
1852 [#output "b4_output_header_name"
1853 b4_copyright([Skeleton parser
for GLR parsing with Bison
], [2002])
1854 #ifndef b4_header_guard
1855 # define b4_header_guard
1857 b4_token_defines(b4_tokens
)
1860 m4_ifdef([b4_stype
],
1861 [#line b4_stype_line "b4_filename"
1862 typedef union b4_stype yystype
;
1863 /* Line __line__ of __file__. */
1864 #line __oline__ "__ofile__"],
1865 [typedef int yystype
;])
1866 # define YYSTYPE yystype
1870 [extern YYSTYPE b4_prefix
[]lval
;])
1874 typedef struct yyltype
1881 # define YYLTYPE yyltype
1885 [extern YYLTYPE b4_prefix
[]lloc
;])
1887 #endif /* not b4_header_guard */