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 */
117 /* Identify Bison output. */
121 #define YYPURE ]b4_pure[
123 /* Using locations. */
124 #define YYLSP_NEEDED ]b4_locations_flag[
126 ]m4_if(b4_prefix
[], [yy
], [],
127 [/* If NAME_PREFIX is specified substitute the variables and functions
129 #define yyparse b4_prefix[]parse
130 #define yylex b4_prefix[]lex
131 #define yyerror b4_prefix[]error
132 #define yylval b4_prefix[]lval
133 #define yychar b4_prefix[]char
134 #define yydebug b4_prefix[]debug
135 #define yynerrs b4_prefix[]nerrs
136 b4_location_if([#define yylloc b4_prefix[]lloc])])
138 /* Copy the first part of user declarations. */
141 b4_token_defines(b4_tokens
)[
143 /* Enabling traces. */
145 # define YYDEBUG ]b4_debug[
148 /* Enabling verbose error messages. */
149 #ifdef YYERROR_VERBOSE
150 # undef YYERROR_VERBOSE
151 # define YYERROR_VERBOSE 1
153 # define YYERROR_VERBOSE ]b4_error_verbose[
157 ]m4_ifdef([b4_stype
],
158 [#line b4_stype_line "b4_filename"
159 typedef union b4_stype yystype
;
160 /* Line __line__ of __file__. */
161 #line __oline__ "__ofile__"],
162 [typedef int yystype
;])[
163 # define YYSTYPE yystype
164 # define YYSTYPE_IS_TRIVIAL 1
168 typedef struct yyltype
174 int yylast_column
;])[
176 # define YYLTYPE ]b4_ltype[
177 # define YYLTYPE_IS_TRIVIAL 1
180 /* Default (constant) values used for initialization for null
181 right-hand sides. Unlike the standard bison.simple template,
182 here we set the default values of the $$ and $@ to zeroed-out
183 values. Since the default value of these quantities is undefined,
184 this behavior is technically correct. */
185 static YYSTYPE yyval_default
;
186 static YYLTYPE yyloc_default
;
188 /* Copy the second part of user declarations. */
191 ]/* Line __line__ of __file__. */
192 #line __oline__ "__ofile__"
194 #if ! defined (__cplusplus)
204 #ifndef __attribute__
205 /* This feature is available in gcc versions 2.5 and later. */
206 # if !defined (__GNUC__) || __GNUC__ < 2 || \
207 (__GNUC__ == 2 && __GNUC_MINOR__ < 5) || __STRICT_ANSI__
208 # define __attribute__(Spec) /* empty */
212 #ifndef ATTRIBUTE_UNUSED
213 # define ATTRIBUTE_UNUSED __attribute__ ((__unused__))
216 #if ! defined (__GNUC__)
220 /* YYFINAL -- State number of the termination state. */
221 #define YYFINAL ]b4_final_state_number[
222 #define YYFLAG ]b4_flag[
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_uint_type(b4_translate_max
)[ yytranslate
[] =
250 /* YYPRHS[YYN] -- Index of the first RHS symbol of rule number YYN in
252 static const ]b4_uint_type(b4_prhs_max
)[ yyprhs
[] =
257 /* YYRHS -- A `-1'-separated list of the rules' RHS. */
258 static const ]b4_sint_type(b4_rhs_max
)[ yyrhs
[] =
263 /* YYRLINE[YYN] -- source line where rule number YYN was defined. */
264 static const ]b4_uint_type(b4_rline_max
)[ 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_uint_type(b4_r1_max
)[ yyr1
[] =
287 /* YYR2[YYN] -- Number of symbols composing right hand side of rule YYN. */
288 static const ]b4_uint_type(b4_r2_max
)[ yyr2
[] =
293 /* YYDPREC[RULE-NUM] -- Dynamic precedence of rule #RULE-NUM (0 if none). */
294 static const short yydprec
[] =
299 /* YYMERGER[RULE-NUM] -- Index of merging function for rule #RULE-NUM. */
300 static const short 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 short yydefact
[] =
313 /* YYPGOTO[NTERM-NUM]. */
314 static const short yydefgoto
[] =
319 /* YYPACT[STATE-NUM] -- Index in YYTABLE of the portion describing
321 static const short yypact
[] =
326 /* YYPGOTO[NTERM-NUM]. */
327 static const short yypgoto
[] =
332 /* YYTABLE[YYPACT[STATE-NUM]]. What to do in state STATE-NUM. If
333 positive, shift that token. If negative, reduce the rule which
334 number is the opposite. If zero, do what YYDEFACT says. */
335 static const short yytable
[] =
340 /* YYCONFLP[YYPACT[STATE-NUM]] -- pointer into yyconfl of start of list
341 of conflicting reductions corresponding to action entry for state
342 STATE-NUM in yytable. 0 means no conflicts. The list in yyconfl
343 is terminated by a rule number of 0. */
344 static const short yyconflp
[] =
346 ]b4_conflict_list_heads
[
349 /* YYCONFL[I] -- lists of conflicting rule numbers, each terminated
350 by 0, pointed into by YYCONFLP. */
351 static const short yyconfl
[] =
353 ]b4_conflicting_rules
[
356 static const short yycheck
[] =
362 /* The user can define YYPARSE_PARAM as the name of an argument to be passed
363 into yyparse. The argument should have type void *.
364 It should actually point to an object.
365 Grammar actions can access the variable by casting it
366 to the proper pointer type. */
369 # define YYPARSE_PARAM_ARG void *YYPARSE_PARAM
370 #else /* !YYPARSE_PARAM */
371 # define YYPARSE_PARAM_ARG void
372 #endif /* !YYPARSE_PARAM */
374 /* Prevent warning if -Wstrict-prototypes. */
376 # ifdef YYPARSE_PARAM
377 int yyparse (void *);
383 /* Error token number */
386 /* YYLLOC_DEFAULT -- Compute the default location (before the actions
389 #define YYRHSLOC(yyRhs,YYK) (yyRhs[YYK].yystate.yyloc)
391 #ifndef YYLLOC_DEFAULT
392 # define YYLLOC_DEFAULT(yyCurrent, yyRhs, YYN) \
393 yyCurrent.yyfirst_line = YYRHSLOC(yyRhs,1).yyfirst_line; \
394 yyCurrent.yyfirst_column = YYRHSLOC(yyRhs,1).yyfirst_column; \
395 yyCurrent.yylast_line = YYRHSLOC(yyRhs,YYN).yylast_line; \
396 yyCurrent.yylast_column = YYRHSLOC(yyRhs,YYN).yylast_column;
399 /* YYLEX -- calling `yylex' with the right arguments. */
404 # define YYLEX yylex (yylvalp, b4_location_if([yyllocp, ])YYLEX_PARAM)
406 # define YYLEX yylex (yylvalp[]b4_location_if([, yyllocp]))
408 [#define YYLEX yylex ()])
413 #define yynerrs (yystack->yyerrcnt)
415 #define yychar (yystack->yyrawchar)],
423 static const int YYEOF
= 0;
424 static const int YYEMPTY
= -2;
426 typedef enum { yyok
, yyaccept
, yyabort
, yyerr
} YYRESULTTAG
;
429 do { YYRESULTTAG yyflag = YYE; if (yyflag != yyok) return yyflag; } \
434 #if ! defined (YYFPRINTF)
435 # define YYFPRINTF fprintf
438 # define YYDPRINTF(Args) \
443 /* Nonzero means print parse trace. It is left uninitialized so that
444 multiple parsers can coexist. */
447 /* Avoid empty `if' bodies. */
448 # define YYDPRINTF(Args) {}
449 #endif /* !YYDEBUG */
451 /* YYINITDEPTH -- initial size of the parser's stacks. */
453 # define YYINITDEPTH ]b4_initdepth[
456 /* YYMAXDEPTH -- maximum size the stacks can grow to (effective only
457 if the built-in stack extension method is used).
459 Do not make this value too large; the results are undefined if
460 SIZE_MAX < YYMAXDEPTH * sizeof (GLRStackItem)
461 evaluated with infinite-precision integer arithmetic. */
468 # define YYMAXDEPTH ]b4_maxdepth[
471 /* Minimum number of free items on the stack allowed after an
472 allocation. This is to allow allocation and initialization
473 to be completed by functions that call expandGLRStack before the
474 stack is expanded, thus insuring that all necessary pointers get
475 properly redirected to new data. */
478 #if ! defined (YYSTACKEXPANDABLE) \
479 && (! defined (__cplusplus) || (YYLTYPE_IS_TRIVIAL && YYSTYPE_IS_TRIVIAL))
480 #define YYSTACKEXPANDABLE 1
482 #define YYSTACKEXPANDABLE 0
485 /** State numbers, as in LALR(1) machine */
486 typedef int yyStateNum
;
488 /** Rule numbers, as in LALR(1) machine */
489 typedef int yyRuleNum
;
491 /** Grammar symbol */
492 typedef short yySymbol
;
494 /** Item references, as in LALR(1) machine */
495 typedef short yyItemNum
;
497 typedef struct yyGLRState yyGLRState
;
498 typedef struct yySemanticOption yySemanticOption
;
499 typedef union yyGLRStackItem yyGLRStackItem
;
500 typedef struct yyGLRStack yyGLRStack
;
501 typedef struct yyGLRStateSet yyGLRStateSet
;
506 yyStateNum yylrState
;
510 yySemanticOption
* yyfirstVal
;
516 struct yyGLRStateSet
{
517 yyGLRState
** yystates
;
518 size_t yysize
, yycapacity
;
521 struct yySemanticOption
{
525 yySemanticOption
* yynext
;
528 union yyGLRStackItem
{
530 yySemanticOption yyoption
;
542 jmp_buf yyexception_buffer
;
543 yyGLRStackItem
* yyitems
;
544 yyGLRStackItem
* yynextFree
;
546 yyGLRState
* yysplitPoint
;
547 yyGLRState
* yylastDeleted
;
548 yyGLRStateSet yytops
;
551 static void yyinitGLRStack (yyGLRStack
* yystack
, size_t yysize
);
552 static void yyexpandGLRStack (yyGLRStack
* yystack
);
553 static void yyfreeGLRStack (yyGLRStack
* yystack
);
556 yyFail (yyGLRStack
* yystack
, const char* yyformat
, ...)
558 if (yyformat
!= NULL
)
562 va_start (yyap
, yyformat
);
563 yystack
->yyerrflag
= 1;
564 vsprintf (yymsg
, yyformat
, yyap
);
567 longjmp (yystack
->yyexception_buffer
, 1);
570 #if YYDEBUG || YYERROR_VERBOSE
571 /** A printable representation of TOKEN. Valid until next call to
573 static inline const char*
574 yytokenName (yySymbol yytoken
)
576 return yytname
[yytoken
];
580 /** Perform user action for rule number YYN, with RHS length YYRHSLEN,
581 * and top stack item YYVSP. YYLVALP points to place to put semantic
582 * value ($$), and yylocp points to place for location information
583 * (@$). Returns yyok for normal return, yyaccept for YYACCEPT,
584 * yyerr for YYERROR, yyabort for YYABORT. */
586 yyuserAction (yyRuleNum yyn
, int yyrhslen
, yyGLRStackItem
* yyvsp
,
587 YYSTYPE
* yyvalp
, YYLTYPE
* yylocp
, yyGLRStack
* yystack
)
589 /* Avoid `unused' warnings in there are no $n. */
594 *yyvalp
= yyval_default
;
595 *yylocp
= yyloc_default
;
599 *yyvalp
= yyvsp
[1-yyrhslen
].yystate
.yysemantics
.yysval
;
600 *yylocp
= yyvsp
[1-yyrhslen
].yystate
.yyloc
;
603 # define yyval (*yyvalp)
605 # define yyerrok (yystack->yyerrState = 0)
607 # define YYACCEPT return yyaccept
609 # define YYABORT return yyabort
611 # define YYERROR return yyerr
613 # define YYRECOVERING (yystack->yyerrState != 0)
615 # define yyclearin (yychar = *(yystack->yytokenp) = YYEMPTY)
617 # define YYBACKUP(Token, Value) \
619 yyerror ("syntax error: cannot back up"); \
638 /* Line __line__ of __file__. */
639 #line __oline__ "__ofile__"
644 yyuserMerge (int yyn
, YYSTYPE
* yy0
, YYSTYPE
* yy1
)
646 YYSTYPE yyval
= *yy0
;
647 /* `Use' the arguments. */
658 /* Bison grammar-table manipulation */
660 /** Number of symbols composing the right hand side of rule #RULE. */
662 yyrhsLength (yyRuleNum yyrule
)
667 /** Left-hand-side symbol for rule #RULE. */
668 static inline yySymbol
669 yylhsNonterm (yyRuleNum yyrule
)
674 /** True iff LR state STATE has only a default reduction (regardless
677 yyisDefaultedState (yyStateNum yystate
)
679 return yypact
[yystate
] == YYFLAG
;
682 /** The default reduction for STATE, assuming it has one. */
683 static inline yyRuleNum
684 yydefaultAction (yyStateNum yystate
)
686 return yydefact
[yystate
];
689 /** Set *ACTION to the action to take in STATE on seeing TOKEN.
691 * R < 0: Reduce on rule -R.
693 * R > 0: Shift to state R.
694 * Set *CONFLICTS to a pointer into yyconfl to 0-terminated list of
695 * conflicting reductions.
698 yygetLRActions (yyStateNum yystate
, int yytoken
,
699 int* yyaction
, const short** yyconflicts
)
701 int yyindex
= yypact
[yystate
] + yytoken
;
702 if (yyindex
< 0 || yyindex
> YYLAST
|| yycheck
[yyindex
] != yytoken
)
704 *yyaction
= -yydefact
[yystate
];
705 *yyconflicts
= yyconfl
;
709 *yyaction
= yytable
[yyindex
];
710 *yyconflicts
= yyconfl
+ yyconflp
[yyindex
];
714 static inline yyStateNum
715 yyLRgotoState (yyStateNum yystate
, yySymbol yylhs
)
718 yyr
= yypgoto
[yylhs
- YYNTOKENS
] + yystate
;
719 if (yyr
>= 0 && yyr
<= YYLAST
&& yycheck
[yyr
] == yystate
)
722 return yydefgoto
[yylhs
- YYNTOKENS
];
726 yyisShiftAction (int yyaction
)
732 yyisErrorAction (int yyaction
)
734 return yyaction
== 0 || yyaction
== YYFLAG
;
739 /** True iff the semantic value of the edge leading to STATE is
742 yyhasResolvedValue (yyGLRState
* yystate
)
744 return yystate
->yyresolved
;
748 yyaddDeferredAction (yyGLRStack
* yystack
, yyGLRState
* yystate
,
749 yyGLRState
* yyrhs
, yyRuleNum yyrule
)
751 yySemanticOption
* yynewItem
;
752 yynewItem
= &yystack
->yynextFree
->yyoption
;
753 yystack
->yyspaceLeft
-= 1;
754 yystack
->yynextFree
+= 1;
755 yynewItem
->yyisState
= yyfalse
;
756 yynewItem
->yystate
= yyrhs
;
757 yynewItem
->yyrule
= yyrule
;
758 yynewItem
->yynext
= yystate
->yysemantics
.yyfirstVal
;
759 yystate
->yysemantics
.yyfirstVal
= yynewItem
;
760 if (yystack
->yyspaceLeft
< YYHEADROOM
)
761 yyexpandGLRStack (yystack
);
766 /** Initialize SET to a singleton set containing an empty stack. */
768 yyinitStateSet (yyGLRStateSet
* yyset
)
771 yyset
->yycapacity
= 16;
772 yyset
->yystates
= (yyGLRState
**) malloc (16 * sizeof (yyset
->yystates
[0]));
773 yyset
->yystates
[0] = NULL
;
776 static void yyfreeStateSet (yyGLRStateSet
* yyset
)
778 free (yyset
->yystates
);
781 /** Initialize STACK to a single empty stack, with total maximum
782 * capacity for all stacks of SIZE. */
784 yyinitGLRStack (yyGLRStack
* yystack
, size_t yysize
)
786 yystack
->yyerrflag
= 0;
787 yystack
->yyerrState
= 0;
789 yystack
->yyspaceLeft
= yysize
;
790 yystack
->yynextFree
= yystack
->yyitems
=
791 (yyGLRStackItem
*) malloc (yysize
* sizeof (yystack
->yynextFree
[0]));
792 yystack
->yysplitPoint
= NULL
;
793 yystack
->yylastDeleted
= NULL
;
794 yyinitStateSet (&yystack
->yytops
);
797 #define YYRELOC(YYFROMITEMS,YYTOITEMS,YYX,YYTYPE) \
798 &((YYTOITEMS) - ((YYFROMITEMS) - (yyGLRStackItem*) (YYX)))->YYTYPE
800 /** If STACK is expandable, extend it. WARNING: Pointers into the
801 stack from outside should be considered invalid after this call.
802 We always expand when there are 1 or fewer items left AFTER an
803 allocation, so that we can avoid having external pointers exist
804 across an allocation. */
806 yyexpandGLRStack (yyGLRStack
* yystack
)
808 #if YYSTACKEXPANDABLE
809 yyGLRStack yynewStack
;
810 yyGLRStackItem
* yyp0
, *yyp1
;
811 size_t yysize
, yynewSize
;
813 yysize
= yystack
->yynextFree
- yystack
->yyitems
;
814 if (yysize
>= YYMAXDEPTH
)
815 yyFail (yystack
, "parsing stack overflow (%d items)", yysize
);
816 yynewSize
= 2*yysize
;
817 if (yynewSize
> YYMAXDEPTH
)
818 yynewSize
= YYMAXDEPTH
;
819 yyinitGLRStack (&yynewStack
, yynewSize
);
820 for (yyp0
= yystack
->yyitems
, yyp1
= yynewStack
.yyitems
, yyn
= yysize
;
822 yyn
-= 1, yyp0
+= 1, yyp1
+= 1)
827 yyGLRState
* yys0
= &yyp0
->yystate
;
828 yyGLRState
* yys1
= &yyp1
->yystate
;
829 if (yys0
->yypred
!= NULL
)
831 YYRELOC (yyp0
, yyp1
, yys0
->yypred
, yystate
);
832 if (! yys0
->yyresolved
&& yys0
->yysemantics
.yyfirstVal
!= NULL
)
833 yys1
->yysemantics
.yyfirstVal
=
834 YYRELOC(yyp0
, yyp1
, yys0
->yysemantics
.yyfirstVal
, yyoption
);
838 yySemanticOption
* yyv0
= &yyp0
->yyoption
;
839 yySemanticOption
* yyv1
= &yyp1
->yyoption
;
840 if (yyv0
->yystate
!= NULL
)
841 yyv1
->yystate
= YYRELOC (yyp0
, yyp1
, yyv0
->yystate
, yystate
);
842 if (yyv0
->yynext
!= NULL
)
843 yyv1
->yynext
= YYRELOC (yyp0
, yyp1
, yyv0
->yynext
, yyoption
);
846 if (yystack
->yysplitPoint
!= NULL
)
847 yystack
->yysplitPoint
= YYRELOC (yystack
->yyitems
, yynewStack
.yyitems
,
848 yystack
->yysplitPoint
, yystate
);
850 for (yyn
= 0; yyn
< yystack
->yytops
.yysize
; yyn
+= 1)
851 if (yystack
->yytops
.yystates
[yyn
] != NULL
)
852 yystack
->yytops
.yystates
[yyn
] =
853 YYRELOC (yystack
->yyitems
, yynewStack
.yyitems
,
854 yystack
->yytops
.yystates
[yyn
], yystate
);
855 free (yystack
->yyitems
);
856 yystack
->yyitems
= yynewStack
.yyitems
;
857 yystack
->yynextFree
= yynewStack
.yynextFree
+ yysize
;
858 yystack
->yyspaceLeft
= yynewStack
.yyspaceLeft
- yysize
;
862 yyFail (yystack
, "parsing stack overflow (%d items)", yysize
);
868 yyfreeGLRStack (yyGLRStack
* yystack
)
870 free (yystack
->yyitems
);
871 yyfreeStateSet (&yystack
->yytops
);
874 /** Assuming that S is a GLRState somewhere on STACK, update the
875 * splitpoint of STACK, if needed, so that it is at least as deep as
878 yyupdateSplit (yyGLRStack
* yystack
, yyGLRState
* yys
)
880 if (yystack
->yysplitPoint
!= NULL
&& yystack
->yysplitPoint
> yys
)
881 yystack
->yysplitPoint
= yys
;
884 /** Invalidate stack #K in STACK. */
886 yymarkStackDeleted (yyGLRStack
* yystack
, int yyk
)
888 if (yystack
->yytops
.yystates
[yyk
] != NULL
)
889 yystack
->yylastDeleted
= yystack
->yytops
.yystates
[yyk
];
890 yystack
->yytops
.yystates
[yyk
] = NULL
;
893 /** Undelete the last stack that was marked as deleted. Can only be
894 done once after a deletion, and only when all other stacks have
897 yyundeleteLastStack (yyGLRStack
* yystack
)
899 if (yystack
->yylastDeleted
== NULL
|| yystack
->yytops
.yysize
!= 0)
901 yystack
->yytops
.yystates
[0] = yystack
->yylastDeleted
;
902 yystack
->yytops
.yysize
= 1;
903 YYDPRINTF ((stderr
, "Restoring last deleted stack as stack #0.\n"));
904 yystack
->yylastDeleted
= NULL
;
908 yyremoveDeletes (yyGLRStack
* yystack
)
912 while (yyj
< yystack
->yytops
.yysize
)
914 if (yystack
->yytops
.yystates
[yyi
] == NULL
)
917 YYDPRINTF ((stderr
, "Removing dead stacks.\n"));
918 yystack
->yytops
.yysize
-= 1;
922 yystack
->yytops
.yystates
[yyj
] = yystack
->yytops
.yystates
[yyi
];
924 YYDPRINTF ((stderr
, "Rename stack %d -> %d.\n", yyi
, yyj
));
931 /** Shift to a new state on stack #K of STACK, corresponding to LR state
932 * LRSTATE, at input position POSN, with (resolved) semantic value SVAL. */
934 yyglrShift (yyGLRStack
* yystack
, int yyk
, yyStateNum yylrState
, size_t yyposn
,
935 YYSTYPE yysval
, YYLTYPE
* yylocp
)
937 yyGLRStackItem
* yynewItem
;
939 yynewItem
= yystack
->yynextFree
;
940 yystack
->yynextFree
+= 1;
941 yystack
->yyspaceLeft
-= 1;
942 yynewItem
->yystate
.yyisState
= yytrue
;
943 yynewItem
->yystate
.yylrState
= yylrState
;
944 yynewItem
->yystate
.yyposn
= yyposn
;
945 yynewItem
->yystate
.yyresolved
= yytrue
;
946 yynewItem
->yystate
.yypred
= yystack
->yytops
.yystates
[yyk
];
947 yystack
->yytops
.yystates
[yyk
] = &yynewItem
->yystate
;
948 yynewItem
->yystate
.yysemantics
.yysval
= yysval
;
949 yynewItem
->yystate
.yyloc
= *yylocp
;
950 if (yystack
->yyspaceLeft
< YYHEADROOM
)
951 yyexpandGLRStack (yystack
);
954 /** Shift to a new state on stack #K of STACK, to a new state
955 * corresponding to LR state LRSTATE, at input position POSN, with
956 * the (unresolved) semantic value of RHS under the action for RULE. */
958 yyglrShiftDefer (yyGLRStack
* yystack
, int yyk
, yyStateNum yylrState
,
959 size_t yyposn
, yyGLRState
* yyrhs
, yyRuleNum yyrule
)
961 yyGLRStackItem
* yynewItem
;
963 yynewItem
= yystack
->yynextFree
;
964 yynewItem
->yystate
.yyisState
= yytrue
;
965 yynewItem
->yystate
.yylrState
= yylrState
;
966 yynewItem
->yystate
.yyposn
= yyposn
;
967 yynewItem
->yystate
.yyresolved
= yyfalse
;
968 yynewItem
->yystate
.yypred
= yystack
->yytops
.yystates
[yyk
];
969 yynewItem
->yystate
.yysemantics
.yyfirstVal
= NULL
;
970 yystack
->yytops
.yystates
[yyk
] = &yynewItem
->yystate
;
971 yystack
->yynextFree
+= 1;
972 yystack
->yyspaceLeft
-= 1;
973 yyaddDeferredAction (yystack
, &yynewItem
->yystate
, yyrhs
, yyrule
);
976 /** Pop the symbols consumed by reduction #RULE from the top of stack
977 * #K of STACK, and perform the appropriate semantic action on their
978 * semantic values. Assumes that all ambiguities in semantic values
979 * have been previously resolved. Set *VALP to the resulting value,
980 * and *LOCP to the computed location (if any). Return value is as
983 yydoAction (yyGLRStack
* yystack
, int yyk
, yyRuleNum yyrule
,
984 YYSTYPE
* yyvalp
, YYLTYPE
* yylocp
)
986 int yynrhs
= yyrhsLength (yyrule
);
988 if (yystack
->yysplitPoint
== NULL
)
990 /* Standard special case: single stack. */
991 yyGLRStackItem
* yyrhs
= (yyGLRStackItem
*) yystack
->yytops
.yystates
[yyk
];
993 yystack
->yynextFree
-= yynrhs
;
994 yystack
->yyspaceLeft
+= yynrhs
;
995 yystack
->yytops
.yystates
[0] = & yystack
->yynextFree
[-1].yystate
;
998 *yyvalp
= yyval_default
;
999 *yylocp
= yyloc_default
;
1003 *yyvalp
= yyrhs
[1-yynrhs
].yystate
.yysemantics
.yysval
;
1004 *yylocp
= yyrhs
[1-yynrhs
].yystate
.yyloc
;
1006 return yyuserAction (yyrule
, yynrhs
, yyrhs
, yyvalp
, yylocp
, yystack
);
1012 yyGLRStackItem yyrhsVals
[YYMAXRHS
];
1013 for (yyi
= yynrhs
-1, yys
= yystack
->yytops
.yystates
[yyk
]; yyi
>= 0;
1014 yyi
-= 1, yys
= yys
->yypred
)
1016 assert (yys
->yypred
!= NULL
);
1017 yyrhsVals
[yyi
].yystate
.yyresolved
= yytrue
;
1018 yyrhsVals
[yyi
].yystate
.yysemantics
.yysval
= yys
->yysemantics
.yysval
;
1019 yyrhsVals
[yyi
].yystate
.yyloc
= yys
->yyloc
;
1021 yyupdateSplit (yystack
, yys
);
1022 yystack
->yytops
.yystates
[yyk
] = yys
;
1025 *yyvalp
= yyval_default
;
1026 *yylocp
= yyloc_default
;
1030 *yyvalp
= yyrhsVals
[0].yystate
.yysemantics
.yysval
;
1031 *yylocp
= yyrhsVals
[0].yystate
.yyloc
;
1033 return yyuserAction (yyrule
, yynrhs
, yyrhsVals
+ (yynrhs
-1),
1034 yyvalp
, yylocp
, yystack
);
1038 /** Pop items off stack #K of STACK according to grammar rule RULE,
1039 * and push back on the resulting nonterminal symbol. Perform the
1040 * semantic action associated with RULE and store its value with the
1041 * newly pushed state, if FORCEEVAL or if STACK is currently
1042 * unambiguous. Otherwise, store the deferred semantic action with
1043 * the new state. If the new state would have an identical input
1044 * position, LR state, and predecessor to an existing state on the stack,
1045 * it is identified with that existing state, eliminating stack #K from
1046 * the STACK. In this case, the (necessarily deferred) semantic value is
1047 * added to the options for the existing state's semantic value.
1049 static inline YYRESULTTAG
1050 yyglrReduce (yyGLRStack
* yystack
, size_t yyk
, yyRuleNum yyrule
,
1053 size_t yyposn
= yystack
->yytops
.yystates
[yyk
]->yyposn
;
1055 if (yyforceEval
|| yystack
->yysplitPoint
== NULL
)
1060 YYCHK (yydoAction (yystack
, yyk
, yyrule
, &yysval
, &yyloc
));
1061 yyglrShift (yystack
, yyk
,
1062 yyLRgotoState (yystack
->yytops
.yystates
[yyk
]->yylrState
,
1063 yylhsNonterm (yyrule
)),
1064 yyposn
, yysval
, &yyloc
);
1065 YYDPRINTF ((stderr
, "Reduced stack %d by rule #%d. Now in state %d.\n",
1066 yyk
, yyrule
-1, yystack
->yytops
.yystates
[yyk
]->yylrState
));
1072 yyGLRState
* yys
, *yys0
= yystack
->yytops
.yystates
[yyk
];
1073 yyStateNum yynewLRState
;
1075 for (yys
= yystack
->yytops
.yystates
[yyk
], yyn
= yyrhsLength (yyrule
);
1079 assert (yys
!= NULL
);
1081 yyupdateSplit (yystack
, yys
);
1082 yynewLRState
= yyLRgotoState (yys
->yylrState
, yylhsNonterm (yyrule
));
1084 "Reduced stack %d by rule #%d; action deferred. "
1085 "Now in state %d.\n",
1086 yyk
, yyrule
-1, yynewLRState
));
1087 for (yyi
= 0; yyi
< yystack
->yytops
.yysize
; yyi
+= 1)
1088 if (yyi
!= yyk
&& yystack
->yytops
.yystates
[yyi
] != NULL
)
1090 yyGLRState
* yyp
, *yysplit
= yystack
->yysplitPoint
;
1091 yyp
= yystack
->yytops
.yystates
[yyi
];
1092 while (yyp
!= yys
&& yyp
!= yysplit
&& yyp
->yyposn
>= yyposn
)
1094 if (yyp
->yylrState
== yynewLRState
&& yyp
->yypred
== yys
)
1096 yyaddDeferredAction (yystack
, yyp
, yys0
, yyrule
);
1097 yymarkStackDeleted (yystack
, yyk
);
1098 YYDPRINTF ((stderr
, "Merging stack %d into stack %d.\n",
1105 yystack
->yytops
.yystates
[yyk
] = yys
;
1106 yyglrShiftDefer (yystack
, yyk
, yynewLRState
, yyposn
, yys0
, yyrule
);
1112 yysplitStack (yyGLRStack
* yystack
, int yyk
)
1114 if (yystack
->yysplitPoint
== NULL
)
1117 yystack
->yysplitPoint
= yystack
->yytops
.yystates
[yyk
];
1119 if (yystack
->yytops
.yysize
>= yystack
->yytops
.yycapacity
)
1121 yystack
->yytops
.yycapacity
*= 2;
1122 yystack
->yytops
.yystates
=
1123 (yyGLRState
**) realloc (yystack
->yytops
.yystates
,
1124 yystack
->yytops
.yycapacity
1125 * sizeof (yyGLRState
*));
1127 yystack
->yytops
.yystates
[yystack
->yytops
.yysize
]
1128 = yystack
->yytops
.yystates
[yyk
];
1129 yystack
->yytops
.yysize
+= 1;
1130 return yystack
->yytops
.yysize
-1;
1133 /** True iff Y0 and Y1 represent identical options at the top level.
1134 * That is, they represent the same rule applied to RHS symbols
1135 * that produce the same terminal symbols. */
1137 yyidenticalOptions (yySemanticOption
* yyy0
, yySemanticOption
* yyy1
)
1139 if (yyy0
->yyrule
== yyy1
->yyrule
)
1141 yyGLRState
*yys0
, *yys1
;
1143 for (yys0
= yyy0
->yystate
, yys1
= yyy1
->yystate
,
1144 yyn
= yyrhsLength (yyy0
->yyrule
);
1146 yys0
= yys0
->yypred
, yys1
= yys1
->yypred
, yyn
-= 1)
1147 if (yys0
->yyposn
!= yys1
->yyposn
)
1155 /** Assuming identicalOptions (Y0,Y1), (destructively) merge the
1156 * alternative semantic values for the RHS-symbols of Y1 into the
1157 * corresponding semantic value sets of the symbols of Y0. */
1159 yymergeOptionSets (yySemanticOption
* yyy0
, yySemanticOption
* yyy1
)
1161 yyGLRState
*yys0
, *yys1
;
1163 for (yys0
= yyy0
->yystate
, yys1
= yyy1
->yystate
,
1164 yyn
= yyrhsLength (yyy0
->yyrule
);
1166 yys0
= yys0
->yypred
, yys1
= yys1
->yypred
, yyn
-= 1)
1169 else if (! yys0
->yyresolved
&& ! yys1
->yyresolved
)
1171 yySemanticOption
* yyz
;
1172 for (yyz
= yys0
->yysemantics
.yyfirstVal
; yyz
->yynext
!= NULL
;
1175 yyz
->yynext
= yys1
->yysemantics
.yyfirstVal
;
1179 /** Y0 and Y1 represent two possible actions to take in a given
1180 * parsing state; return 0 if no combination is possible,
1181 * 1 if user-mergeable, 2 if Y0 is preferred, 3 if Y1 is preferred. */
1183 yypreference (yySemanticOption
* y0
, yySemanticOption
* y1
)
1185 yyRuleNum r0
= y0
->yyrule
, r1
= y1
->yyrule
;
1186 int p0
= yydprec
[r0
], p1
= yydprec
[r1
];
1190 if (yymerger
[r0
] == 0 || yymerger
[r0
] != yymerger
[r1
])
1195 if (p0
== 0 || p1
== 0)
1204 static YYRESULTTAG
yyresolveValue (yySemanticOption
* yyoptionList
,
1205 yyGLRStack
* yystack
, YYSTYPE
* yyvalp
,
1209 yyresolveStates (yyGLRState
* yys
, int yyn
, yyGLRStack
* yystack
)
1214 assert (yys
->yypred
!= NULL
);
1215 yyflag
= yyresolveStates (yys
->yypred
, yyn
-1, yystack
);
1218 if (! yys
->yyresolved
)
1220 yyflag
= yyresolveValue (yys
->yysemantics
.yyfirstVal
, yystack
,
1221 &yys
->yysemantics
.yysval
, &yys
->yyloc
);
1224 yys
->yyresolved
= yytrue
;
1231 yyresolveAction (yySemanticOption
* yyopt
, yyGLRStack
* yystack
,
1232 YYSTYPE
* yyvalp
, YYLTYPE
* yylocp
)
1234 yyGLRStackItem yyrhsVals
[YYMAXRHS
];
1238 yynrhs
= yyrhsLength (yyopt
->yyrule
);
1239 YYCHK (yyresolveStates (yyopt
->yystate
, yynrhs
, yystack
));
1240 for (yyi
= yynrhs
-1, yys
= yyopt
->yystate
; yyi
>= 0;
1241 yyi
-= 1, yys
= yys
->yypred
)
1243 assert (yys
->yypred
!= NULL
);
1244 yyrhsVals
[yyi
].yystate
.yyresolved
= yytrue
;
1245 yyrhsVals
[yyi
].yystate
.yysemantics
.yysval
= yys
->yysemantics
.yysval
;
1246 yyrhsVals
[yyi
].yystate
.yyloc
= yys
->yyloc
;
1248 return yyuserAction (yyopt
->yyrule
, yynrhs
, yyrhsVals
+ (yynrhs
-1),
1249 yyvalp
, yylocp
, yystack
);
1253 static yyGLRState YYLEFTMOST_STATE
= { 0, NULL
, -1, 0, { NULL
} };
1255 static void yyreportTree (yySemanticOption
* yyx
, int yyindent
)
1257 int yynrhs
= yyrhsLength (yyx
->yyrule
);
1260 yyGLRState
* yystates
[YYMAXRHS
];
1262 for (yyi
= yynrhs
, yys
= yyx
->yystate
; yyi
> 0; yyi
-= 1, yys
= yys
->yypred
)
1263 yystates
[yyi
] = yys
;
1265 yystates
[0] = &YYLEFTMOST_STATE
;
1269 if (yys
->yyposn
+1 > yyx
->yystate
->yyposn
)
1270 YYFPRINTF (stderr
, "%*s%s -> <Rule %d, empty>\n",
1271 yyindent
, "", yytokenName (yylhsNonterm (yyx
->yyrule
)),
1274 YYFPRINTF (stderr
, "%*s%s -> <Rule %d, tokens %d .. %d>\n",
1275 yyindent
, "", yytokenName (yylhsNonterm (yyx
->yyrule
)),
1276 yyx
->yyrule
, yys
->yyposn
+1, yyx
->yystate
->yyposn
);
1277 for (yyi
= 1; yyi
<= yynrhs
; yyi
+= 1)
1279 if (yystates
[yyi
]->yyresolved
)
1281 if (yystates
[yyi
-1]->yyposn
+1 > yystates
[yyi
]->yyposn
)
1282 YYFPRINTF (stderr
, "%*s%s <empty>\n", yyindent
+2, "",
1283 yytokenName (yyrhs
[yyprhs
[yyx
->yyrule
]+yyi
-1]));
1285 YYFPRINTF (stderr
, "%*s%s <tokens %d .. %d>\n", yyindent
+2, "",
1286 yytokenName (yyrhs
[yyprhs
[yyx
->yyrule
]+yyi
-1]),
1287 yystates
[yyi
-1]->yyposn
+1, yystates
[yyi
]->yyposn
);
1290 yyreportTree (yystates
[yyi
]->yysemantics
.yyfirstVal
, yyindent
+2);
1296 yyreportAmbiguity (yySemanticOption
* yyx0
, yySemanticOption
* yyx1
,
1297 yyGLRStack
* yystack
)
1299 /* `Unused' warnings. */
1304 YYFPRINTF (stderr
, "Ambiguity detected.\n");
1305 YYFPRINTF (stderr
, "Option 1,\n");
1306 yyreportTree (yyx0
, 2);
1307 YYFPRINTF (stderr
, "\nOption 2,\n");
1308 yyreportTree (yyx1
, 2);
1309 YYFPRINTF (stderr
, "\n");
1311 yyFail (yystack
, "ambiguity detected");
1315 /** Resolve the ambiguity represented by OPTIONLIST, perform the indicated
1316 * actions, and return the result. */
1318 yyresolveValue (yySemanticOption
* yyoptionList
, yyGLRStack
* yystack
,
1319 YYSTYPE
* yyvalp
, YYLTYPE
* yylocp
)
1321 yySemanticOption
* yybest
;
1322 yySemanticOption
* yyp
;
1325 yybest
= yyoptionList
;
1327 for (yyp
= yyoptionList
->yynext
; yyp
!= NULL
; yyp
= yyp
->yynext
)
1329 if (yyidenticalOptions (yybest
, yyp
))
1330 yymergeOptionSets (yybest
, yyp
);
1332 switch (yypreference (yybest
, yyp
))
1335 yyreportAmbiguity (yybest
, yyp
, yystack
);
1351 int yyprec
= yydprec
[yybest
->yyrule
];
1352 YYCHK (yyresolveAction (yybest
, yystack
, yyvalp
, yylocp
));
1353 for (yyp
= yybest
->yynext
; yyp
!= NULL
; yyp
= yyp
->yynext
)
1355 if (yyprec
== yydprec
[yyp
->yyrule
])
1359 YYCHK (yyresolveAction (yyp
, yystack
, &yyval1
, &yydummy
));
1360 *yyvalp
= yyuserMerge (yymerger
[yyp
->yyrule
], yyvalp
, &yyval1
);
1366 return yyresolveAction (yybest
, yystack
, yyvalp
, yylocp
);
1370 yyresolveStack (yyGLRStack
* yystack
)
1372 if (yystack
->yysplitPoint
!= NULL
)
1377 for (yyn
= 0, yys
= yystack
->yytops
.yystates
[0];
1378 yys
!= yystack
->yysplitPoint
;
1379 yys
= yys
->yypred
, yyn
+= 1)
1381 YYCHK (yyresolveStates (yystack
->yytops
.yystates
[0], yyn
, yystack
));
1387 yycompressStack (yyGLRStack
* yystack
)
1389 yyGLRState
* yyp
, *yyq
, *yyr
;
1391 if (yystack
->yytops
.yysize
!= 1 || yystack
->yysplitPoint
== NULL
)
1394 for (yyp
= yystack
->yytops
.yystates
[0], yyq
= yyp
->yypred
, yyr
= NULL
;
1395 yyp
!= yystack
->yysplitPoint
;
1396 yyr
= yyp
, yyp
= yyq
, yyq
= yyp
->yypred
)
1399 yystack
->yyspaceLeft
+= yystack
->yynextFree
- yystack
->yyitems
;
1400 yystack
->yynextFree
= ((yyGLRStackItem
*) yystack
->yysplitPoint
) + 1;
1401 yystack
->yyspaceLeft
-= yystack
->yynextFree
- yystack
->yyitems
;
1402 yystack
->yysplitPoint
= NULL
;
1403 yystack
->yylastDeleted
= NULL
;
1407 yystack
->yynextFree
->yystate
= *yyr
;
1409 yystack
->yynextFree
->yystate
.yypred
= & yystack
->yynextFree
[-1].yystate
;
1410 yystack
->yytops
.yystates
[0] = &yystack
->yynextFree
->yystate
;
1411 yystack
->yynextFree
+= 1;
1412 yystack
->yyspaceLeft
-= 1;
1417 yyprocessOneStack (yyGLRStack
* yystack
, int yyk
,
1418 size_t yyposn
, YYSTYPE
* yylvalp
, YYLTYPE
* yyllocp
)
1421 const short* yyconflicts
;
1423 yySymbol
* const yytokenp
= yystack
->yytokenp
;
1425 while (yystack
->yytops
.yystates
[yyk
] != NULL
)
1427 yyStateNum yystate
= yystack
->yytops
.yystates
[yyk
]->yylrState
;
1429 assert (yystate
!= YYFINAL
);
1430 if (yyisDefaultedState (yystate
))
1432 yyrule
= yydefaultAction (yystate
);
1435 YYDPRINTF ((stderr
, "Stack %d dies.\n", yyk
));
1436 yymarkStackDeleted (yystack
, yyk
);
1439 YYCHK (yyglrReduce (yystack
, yyk
, yyrule
, yyfalse
));
1443 if (*yytokenp
== YYEMPTY
)
1446 *yytokenp
= YYTRANSLATE(yychar
);
1447 YYDPRINTF ((stderr
, "Read token %s\n", yytokenName (*yytokenp
)));
1449 yygetLRActions (yystate
, *yytokenp
, &yyaction
, &yyconflicts
);
1451 while (*yyconflicts
!= 0)
1453 int yynewStack
= yysplitStack (yystack
, yyk
);
1454 YYDPRINTF ((stderr
, "Splitting off stack %d from %d.\n",
1456 YYCHK (yyglrReduce (yystack
, yynewStack
, *yyconflicts
, yyfalse
));
1457 YYCHK (yyprocessOneStack (yystack
, yynewStack
, yyposn
,
1462 if (yyisShiftAction (yyaction
))
1464 YYDPRINTF ((stderr
, "Shifted token %s on stack %d, ",
1465 yytokenName (*yytokenp
), yyk
));
1466 yyglrShift (yystack
, yyk
, yyaction
, yyposn
+1, *yylvalp
, yyllocp
);
1467 YYDPRINTF ((stderr
, "which is now in state #%d\n",
1468 yystack
->yytops
.yystates
[yyk
]->yylrState
));
1471 else if (yyisErrorAction (yyaction
))
1473 YYDPRINTF ((stderr
, "Stack %d dies.\n", yyk
));
1474 yymarkStackDeleted (yystack
, yyk
);
1478 YYCHK (yyglrReduce (yystack
, yyk
, -yyaction
, yyfalse
));
1485 yyreportParseError (yyGLRStack
* yystack
, YYSTYPE
* yylvalp
, YYLTYPE
* yyllocp
)
1487 /* `Unused' warnings. */
1491 if (yystack
->yyerrState
== 0)
1494 yySymbol
* const yytokenp
= yystack
->yytokenp
;
1495 int yyn
, yyx
, yycount
, yysize
;
1496 const char* yyprefix
;
1499 yyn
= yypact
[yystack
->yytops
.yystates
[0]->yylrState
];
1500 if (yyn
> YYFLAG
&& yyn
< YYLAST
)
1503 /* Start YYX at -YYN if negative to avoid negative indexes in
1505 yysize
= sizeof ("parse error, unexpected ")
1506 + strlen (yytokenName (*yytokenp
));
1507 yyprefix
= ", expecting ";
1508 for (yyx
= yyn
< 0 ? -yyn
: 0; yyx
< yytname_size
&& yycount
<= 5;
1510 if (yycheck
[yyx
+ yyn
] == yyx
)
1511 yysize
+= strlen (yytokenName (yyx
)) + strlen (yyprefix
),
1512 yycount
+= 1, yyprefix
= " or ";
1513 yymsg
= yyp
= (char*) malloc (yysize
);
1514 yyp
+= sprintf (yyp
, "parse error, unexpected %s",
1515 yytokenName (*yytokenp
));
1518 yyprefix
= ", expecting ";
1519 for (yyx
= yyn
< 0 ? -yyn
: 0; yyx
< yytname_size
; yyx
+= 1)
1520 if (yycheck
[yyx
+ yyn
] == yyx
)
1522 yyp
+= sprintf (yyp
, "%s%s", yyprefix
, yytokenName (yyx
));
1531 yyerror ("parse error");
1536 /* Recover from a syntax error on STACK, assuming that TOKENP,
1537 YYLVALP, and YYLLOCP point to the syntactic category, semantic
1538 value, and location of the lookahead.
1539 NOTE: This uses the panic-mode recovery algorithm described in the
1540 Bison documentation, which differs from what is in bison.simple.
1541 Specifically, this routine performs no reductions before shifting
1544 yyrecoverParseError (yyGLRStack
* yystack
, YYSTYPE
* yylvalp
, YYLTYPE
* yyllocp
)
1546 yySymbol
* const yytokenp
= yystack
->yytokenp
;
1550 if (yystack
->yyerrState
== 0)
1551 yystack
->yyerrState
= 3;
1552 else if (yystack
->yyerrState
== 3)
1554 /* We just shifted the error token and (perhaps) took some
1555 reductions. Skip tokens until we can proceed. */
1557 if (*yytokenp
== YYEOF
)
1558 yyFail (yystack
, NULL
);
1559 if (*yytokenp
!= YYEMPTY
)
1560 YYDPRINTF ((stderr
, "Discarding token %s\n",
1561 yytokenName (*yytokenp
)));
1563 *yytokenp
= YYTRANSLATE (yychar
);
1564 YYDPRINTF ((stderr
, "Read token %s\n", yytokenName (*yytokenp
)));
1565 yyj
= yypact
[yystack
->yytops
.yystates
[0]->yylrState
];
1567 /* Something's not right; we shouldn't be here */
1568 yyFail (yystack
, NULL
);
1570 if (yyj
< 0 || yyj
> YYLAST
|| yycheck
[yyj
] != *yytokenp
)
1572 if (yydefact
[yystack
->yytops
.yystates
[0]->yylrState
] != 0)
1575 else if (yytable
[yyj
] != 0 && yytable
[yyj
] != YYFLAG
)
1580 /* Reduce to one stack */
1581 for (yyk
= 0; yyk
< yystack
->yytops
.yysize
; yyk
+= 1)
1582 if (yystack
->yytops
.yystates
[yyk
] != NULL
)
1584 if (yyk
>= yystack
->yytops
.yysize
)
1585 yyFail (yystack
, NULL
);
1586 for (yyk
+= 1; yyk
< yystack
->yytops
.yysize
; yyk
+= 1)
1587 yymarkStackDeleted (yystack
, yyk
);
1588 yyremoveDeletes (yystack
);
1589 yycompressStack (yystack
);
1591 /* Now pop stack until we find a state that shifts the error token. */
1592 while (yystack
->yytops
.yystates
[0] != NULL
)
1594 yyj
= yypact
[yystack
->yytops
.yystates
[0]->yylrState
] + YYTERROR
;
1595 if (yyj
!= YYFLAG
+ YYTERROR
&& yyj
>= 0 && yyj
<= YYLAST
&&
1596 yycheck
[yyj
] == YYTERROR
&& yyisShiftAction (yytable
[yyj
]))
1598 yyglrShift (yystack
, 0, yytable
[yyj
],
1599 yystack
->yytops
.yystates
[0]->yyposn
, *yylvalp
, yyllocp
);
1602 yystack
->yytops
.yystates
[0] = yystack
->yytops
.yystates
[0]->yypred
;
1603 yystack
->yynextFree
-= 1;
1604 yystack
->yyspaceLeft
+= 1;
1606 if (yystack
->yytops
.yystates
[0] == NULL
)
1607 yyFail (yystack
, NULL
);
1610 #define YYCHK1(YYE) \
1616 yystack.yyerrflag = 1; \
1619 yystack.yyerrflag = 0; \
1622 goto yyuser_error; \
1627 yyparse (YYPARSE_PARAM_ARG
)
1637 #define yychar (yystack.yyrawchar)
1640 YYSTYPE
* const yylvalp
= &yylval
;
1641 YYLTYPE
* const yyllocp
= &yylloc
;
1643 yyinitGLRStack (&yystack
, YYINITDEPTH
);
1644 yystack
.yytokenp
= &yytoken
;
1646 if (setjmp (yystack
.yyexception_buffer
) != 0)
1649 yyglrShift (&yystack
, 0, 0, 0, yyval_default
, &yyloc_default
);
1655 /* For efficiency, we have two loops, of which the first of which
1656 * is specialized to deterministic operation (single stack, no
1657 * potential ambiguity). */
1664 const short* yyconflicts
;
1666 yyStateNum yystate
= yystack
.yytops
.yystates
[0]->yylrState
;
1667 if (yystate
== YYFINAL
)
1669 if (yyisDefaultedState (yystate
))
1671 yyrule
= yydefaultAction (yystate
);
1674 yyreportParseError (&yystack
, yylvalp
, yyllocp
);
1677 YYCHK1 (yyglrReduce (&yystack
, 0, yyrule
, yytrue
));
1681 if (yytoken
== YYEMPTY
)
1684 yytoken
= YYTRANSLATE (yychar
);
1685 YYDPRINTF ((stderr
, "Read token %s\n",
1686 yytokenName (yytoken
)));
1688 yygetLRActions (yystate
, yytoken
, &yyaction
, &yyconflicts
);
1689 if (*yyconflicts
!= 0)
1691 if (yyisShiftAction (yyaction
))
1693 YYDPRINTF ((stderr
, "Shifted token %s. ",
1694 yytokenName (yytoken
)));
1695 if (yytoken
!= YYEOF
)
1698 yyglrShift (&yystack
, 0, yyaction
, yyposn
, yylval
, yyllocp
);
1699 if (yystack
.yyerrState
> 0)
1700 yystack
.yyerrState
-= 1;
1701 YYDPRINTF ((stderr
, "Now in state #%d\n",
1702 yystack
.yytops
.yystates
[0]->yylrState
));
1704 else if (yyisErrorAction (yyaction
))
1706 yyreportParseError (&yystack
, yylvalp
, yyllocp
);
1710 YYCHK1 (yyglrReduce (&yystack
, 0, -yyaction
, yytrue
));
1717 int yyn
= yystack
.yytops
.yysize
;
1718 for (yys
= 0; yys
< yyn
; yys
+= 1)
1719 YYCHK1 (yyprocessOneStack (&yystack
, yys
, yyposn
,
1723 yyremoveDeletes (&yystack
);
1724 if (yystack
.yytops
.yysize
== 0)
1726 yyundeleteLastStack (&yystack
);
1727 if (yystack
.yytops
.yysize
== 0)
1728 yyFail (&yystack
, "parse error");
1729 YYCHK1 (yyresolveStack (&yystack
));
1730 YYDPRINTF ((stderr
, "Returning to deterministic operation.\n"));
1731 yyreportParseError (&yystack
, yylvalp
, yyllocp
);
1734 else if (yystack
.yytops
.yysize
== 1)
1736 YYCHK1 (yyresolveStack (&yystack
));
1737 YYDPRINTF ((stderr
, "Returning to deterministic operation.\n"));
1738 yycompressStack (&yystack
);
1744 yyrecoverParseError (&yystack
, yylvalp
, yyllocp
);
1745 yyposn
= yystack
.yytops
.yystates
[0]->yyposn
;
1750 yyfreeGLRStack (&yystack
);
1751 return yystack
.yyerrflag
;
1754 /* DEBUGGING ONLY */
1755 static void yypstack (yyGLRStack
* yystack
, int yyk
) ATTRIBUTE_UNUSED
;
1756 static void yypdumpstack (yyGLRStack
* yystack
) ATTRIBUTE_UNUSED
;
1759 yypstates (yyGLRState
* yyst
)
1762 yy_yypstack (yyGLRState
* yys
)
1764 if (yys
->yypred
== NULL
)
1765 fprintf (stderr
, "%d@%d", yys
->yylrState
, yys
->yyposn
);
1768 yy_yypstack (yys
->yypred
);
1769 fprintf (stderr
, " -> %d@%d", yys
->yylrState
, yys
->yyposn
);
1774 fprintf (stderr
, "<null>");
1777 fprintf (stderr
, "\n");
1781 yypstack (yyGLRStack
* yystack
, int yyk
)
1783 yypstates (yystack
->yytops
.yystates
[yyk
]);
1786 #define YYINDEX(YYX) \
1787 ((YYX) == NULL ? -1 : (yyGLRStackItem*) (YYX) - yystack->yyitems)
1791 yypdumpstack (yyGLRStack
* yystack
)
1793 yyGLRStackItem
* yyp
;
1795 for (yyp
= yystack
->yyitems
; yyp
< yystack
->yynextFree
; yyp
+= 1)
1797 fprintf (stderr
, "%3d. ", yyp
- yystack
->yyitems
);
1800 fprintf (stderr
, "Res: %d, LR State: %d, posn: %d, pred: %d",
1801 yyp
->yystate
.yyresolved
, yyp
->yystate
.yylrState
,
1802 yyp
->yystate
.yyposn
,
1803 YYINDEX(yyp
->yystate
.yypred
));
1804 if (! yyp
->yystate
.yyresolved
)
1805 fprintf (stderr
, ", firstVal: %d",
1806 YYINDEX (yyp
->yystate
.yysemantics
.yyfirstVal
));
1810 fprintf (stderr
, "Option. rule: %d, state: %d, next: %d",
1811 yyp
->yyoption
.yyrule
, YYINDEX (yyp
->yyoption
.yystate
),
1812 YYINDEX (yyp
->yyoption
.yynext
));
1814 fprintf (stderr
, "\n");
1816 fprintf (stderr
, "Tops:");
1817 for (yyi
= 0; yyi
< yystack
->yytops
.yysize
; yyi
+= 1)
1818 fprintf (stderr
, "%d: %d; ", yyi
, YYINDEX (yystack
->yytops
.yystates
[yyi
]));
1819 fprintf (stderr
, "\n");
1825 m4_if(b4_defines_flag
, 0, [],
1826 [#output "b4_output_header_name"
1827 b4_copyright([Skeleton parser
for GLR parsing with Bison
], [2002])
1828 #ifndef b4_header_guard
1829 # define b4_header_guard
1831 b4_token_defines(b4_tokens
)
1834 m4_ifdef([b4_stype
],
1835 [#line b4_stype_line "b4_filename"
1836 typedef union b4_stype yystype
;
1837 /* Line __line__ of __file__. */
1838 #line __oline__ "__ofile__"],
1839 [typedef int yystype
;])
1840 # define YYSTYPE yystype
1844 [extern YYSTYPE b4_prefix
[]lval
;])
1848 typedef struct yyltype
1855 # define YYLTYPE yyltype
1859 [extern YYLTYPE b4_prefix
[]lloc
;])
1861 #endif /* not b4_header_guard */