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 /* YYPDEFGOTO[NTERM-NUM]. */
314 static const short yydefgoto
[] =
319 /* YYPACT[STATE-NUM] -- Index in YYTABLE of the portion describing
321 #define YYPACT_NINF ]b4_pact_ninf[
322 static const ]b4_sint_type(b4_pact_max
)[ yypact
[] =
327 /* YYPGOTO[NTERM-NUM]. */
328 static const short 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 #define YYTABLE_NINF ]b4_table_ninf[
337 static const ]b4_sint_type(b4_table_max
)[ yytable
[] =
342 /* YYCONFLP[YYPACT[STATE-NUM]] -- pointer into yyconfl of start of list
343 of conflicting reductions corresponding to action entry for state
344 STATE-NUM in yytable. 0 means no conflicts. The list in yyconfl
345 is terminated by a rule number of 0. */
346 static const short yyconflp
[] =
348 ]b4_conflict_list_heads
[
351 /* YYCONFL[I] -- lists of conflicting rule numbers, each terminated
352 by 0, pointed into by YYCONFLP. */
353 static const short yyconfl
[] =
355 ]b4_conflicting_rules
[
358 static const short yycheck
[] =
364 /* The user can define YYPARSE_PARAM as the name of an argument to be passed
365 into yyparse. The argument should have type void *.
366 It should actually point to an object.
367 Grammar actions can access the variable by casting it
368 to the proper pointer type. */
371 # define YYPARSE_PARAM_ARG void *YYPARSE_PARAM
372 #else /* !YYPARSE_PARAM */
373 # define YYPARSE_PARAM_ARG void
374 #endif /* !YYPARSE_PARAM */
376 /* Prevent warning if -Wstrict-prototypes. */
378 # ifdef YYPARSE_PARAM
379 int yyparse (void *);
385 /* Error token number */
388 /* YYLLOC_DEFAULT -- Compute the default location (before the actions
391 #define YYRHSLOC(yyRhs,YYK) (yyRhs[YYK].yystate.yyloc)
393 #ifndef YYLLOC_DEFAULT
394 # define YYLLOC_DEFAULT(yyCurrent, yyRhs, YYN) \
395 yyCurrent.yyfirst_line = YYRHSLOC(yyRhs,1).yyfirst_line; \
396 yyCurrent.yyfirst_column = YYRHSLOC(yyRhs,1).yyfirst_column; \
397 yyCurrent.yylast_line = YYRHSLOC(yyRhs,YYN).yylast_line; \
398 yyCurrent.yylast_column = YYRHSLOC(yyRhs,YYN).yylast_column;
401 /* YYLEX -- calling `yylex' with the right arguments. */
406 # define YYLEX yylex (yylvalp, b4_location_if([yyllocp, ])YYLEX_PARAM)
408 # define YYLEX yylex (yylvalp[]b4_location_if([, yyllocp]))
410 [#define YYLEX yylex ()])
415 #define yynerrs (yystack->yyerrcnt)
417 #define yychar (yystack->yyrawchar)],
425 static const int YYEOF
= 0;
426 static const int YYEMPTY
= -2;
428 typedef enum { yyok
, yyaccept
, yyabort
, yyerr
} YYRESULTTAG
;
431 do { YYRESULTTAG yyflag = YYE; if (yyflag != yyok) return yyflag; } \
436 #if ! defined (YYFPRINTF)
437 # define YYFPRINTF fprintf
440 # define YYDPRINTF(Args) \
445 /* Nonzero means print parse trace. It is left uninitialized so that
446 multiple parsers can coexist. */
449 /* Avoid empty `if' bodies. */
450 # define YYDPRINTF(Args) {}
451 #endif /* !YYDEBUG */
453 /* YYINITDEPTH -- initial size of the parser's stacks. */
455 # define YYINITDEPTH ]b4_initdepth[
458 /* YYMAXDEPTH -- maximum size the stacks can grow to (effective only
459 if the built-in stack extension method is used).
461 Do not make this value too large; the results are undefined if
462 SIZE_MAX < YYMAXDEPTH * sizeof (GLRStackItem)
463 evaluated with infinite-precision integer arithmetic. */
470 # define YYMAXDEPTH ]b4_maxdepth[
473 /* Minimum number of free items on the stack allowed after an
474 allocation. This is to allow allocation and initialization
475 to be completed by functions that call expandGLRStack before the
476 stack is expanded, thus insuring that all necessary pointers get
477 properly redirected to new data. */
480 #if ! defined (YYSTACKEXPANDABLE) \
481 && (! defined (__cplusplus) || (YYLTYPE_IS_TRIVIAL && YYSTYPE_IS_TRIVIAL))
482 #define YYSTACKEXPANDABLE 1
484 #define YYSTACKEXPANDABLE 0
487 /** State numbers, as in LALR(1) machine */
488 typedef int yyStateNum
;
490 /** Rule numbers, as in LALR(1) machine */
491 typedef int yyRuleNum
;
493 /** Grammar symbol */
494 typedef short yySymbol
;
496 /** Item references, as in LALR(1) machine */
497 typedef short yyItemNum
;
499 typedef struct yyGLRState yyGLRState
;
500 typedef struct yySemanticOption yySemanticOption
;
501 typedef union yyGLRStackItem yyGLRStackItem
;
502 typedef struct yyGLRStack yyGLRStack
;
503 typedef struct yyGLRStateSet yyGLRStateSet
;
508 yyStateNum yylrState
;
512 yySemanticOption
* yyfirstVal
;
518 struct yyGLRStateSet
{
519 yyGLRState
** yystates
;
520 size_t yysize
, yycapacity
;
523 struct yySemanticOption
{
527 yySemanticOption
* yynext
;
530 union yyGLRStackItem
{
532 yySemanticOption yyoption
;
544 jmp_buf yyexception_buffer
;
545 yyGLRStackItem
* yyitems
;
546 yyGLRStackItem
* yynextFree
;
548 yyGLRState
* yysplitPoint
;
549 yyGLRState
* yylastDeleted
;
550 yyGLRStateSet yytops
;
553 static void yyinitGLRStack (yyGLRStack
* yystack
, size_t yysize
);
554 static void yyexpandGLRStack (yyGLRStack
* yystack
);
555 static void yyfreeGLRStack (yyGLRStack
* yystack
);
558 yyFail (yyGLRStack
* yystack
, const char* yyformat
, ...)
560 if (yyformat
!= NULL
)
564 va_start (yyap
, yyformat
);
565 yystack
->yyerrflag
= 1;
566 vsprintf (yymsg
, yyformat
, yyap
);
569 longjmp (yystack
->yyexception_buffer
, 1);
572 #if YYDEBUG || YYERROR_VERBOSE
573 /** A printable representation of TOKEN. Valid until next call to
575 static inline const char*
576 yytokenName (yySymbol yytoken
)
578 return yytname
[yytoken
];
582 /** Perform user action for rule number YYN, with RHS length YYRHSLEN,
583 * and top stack item YYVSP. YYLVALP points to place to put semantic
584 * value ($$), and yylocp points to place for location information
585 * (@$). Returns yyok for normal return, yyaccept for YYACCEPT,
586 * yyerr for YYERROR, yyabort for YYABORT. */
588 yyuserAction (yyRuleNum yyn
, int yyrhslen
, yyGLRStackItem
* yyvsp
,
589 YYSTYPE
* yyvalp
, YYLTYPE
* yylocp
, yyGLRStack
* yystack
)
591 /* Avoid `unused' warnings in there are no $n. */
596 *yyvalp
= yyval_default
;
597 *yylocp
= yyloc_default
;
601 *yyvalp
= yyvsp
[1-yyrhslen
].yystate
.yysemantics
.yysval
;
602 *yylocp
= yyvsp
[1-yyrhslen
].yystate
.yyloc
;
605 # define yyval (*yyvalp)
607 # define yyerrok (yystack->yyerrState = 0)
609 # define YYACCEPT return yyaccept
611 # define YYABORT return yyabort
613 # define YYERROR return yyerr
615 # define YYRECOVERING (yystack->yyerrState != 0)
617 # define yyclearin (yychar = *(yystack->yytokenp) = YYEMPTY)
619 # define YYBACKUP(Token, Value) \
621 yyerror ("syntax error: cannot back up"); \
640 /* Line __line__ of __file__. */
641 #line __oline__ "__ofile__"
646 yyuserMerge (int yyn
, YYSTYPE
* yy0
, YYSTYPE
* yy1
)
648 YYSTYPE yyval
= *yy0
;
649 /* `Use' the arguments. */
660 /* Bison grammar-table manipulation */
662 /** Number of symbols composing the right hand side of rule #RULE. */
664 yyrhsLength (yyRuleNum yyrule
)
669 /** Left-hand-side symbol for rule #RULE. */
670 static inline yySymbol
671 yylhsNonterm (yyRuleNum yyrule
)
676 /** True iff LR state STATE has only a default reduction (regardless
679 yyisDefaultedState (yyStateNum yystate
)
681 return yypact
[yystate
] == YYPACT_NINF
;
684 /** The default reduction for STATE, assuming it has one. */
685 static inline yyRuleNum
686 yydefaultAction (yyStateNum yystate
)
688 return yydefact
[yystate
];
691 /** Set *ACTION to the action to take in STATE on seeing TOKEN.
693 * R < 0: Reduce on rule -R.
695 * R > 0: Shift to state R.
696 * Set *CONFLICTS to a pointer into yyconfl to 0-terminated list of
697 * conflicting reductions.
700 yygetLRActions (yyStateNum yystate
, int yytoken
,
701 int* yyaction
, const short** yyconflicts
)
703 int yyindex
= yypact
[yystate
] + yytoken
;
704 if (yyindex
< 0 || yyindex
> YYLAST
|| yycheck
[yyindex
] != yytoken
)
706 *yyaction
= -yydefact
[yystate
];
707 *yyconflicts
= yyconfl
;
711 *yyaction
= yytable
[yyindex
];
712 *yyconflicts
= yyconfl
+ yyconflp
[yyindex
];
716 static inline yyStateNum
717 yyLRgotoState (yyStateNum yystate
, yySymbol yylhs
)
720 yyr
= yypgoto
[yylhs
- YYNTOKENS
] + yystate
;
721 if (yyr
>= 0 && yyr
<= YYLAST
&& yycheck
[yyr
] == yystate
)
724 return yydefgoto
[yylhs
- YYNTOKENS
];
728 yyisShiftAction (int yyaction
)
734 yyisErrorAction (int yyaction
)
736 return yyaction
== 0 || yyaction
== YYPACT_NINF
;
741 /** True iff the semantic value of the edge leading to STATE is
744 yyhasResolvedValue (yyGLRState
* yystate
)
746 return yystate
->yyresolved
;
750 yyaddDeferredAction (yyGLRStack
* yystack
, yyGLRState
* yystate
,
751 yyGLRState
* yyrhs
, yyRuleNum yyrule
)
753 yySemanticOption
* yynewItem
;
754 yynewItem
= &yystack
->yynextFree
->yyoption
;
755 yystack
->yyspaceLeft
-= 1;
756 yystack
->yynextFree
+= 1;
757 yynewItem
->yyisState
= yyfalse
;
758 yynewItem
->yystate
= yyrhs
;
759 yynewItem
->yyrule
= yyrule
;
760 yynewItem
->yynext
= yystate
->yysemantics
.yyfirstVal
;
761 yystate
->yysemantics
.yyfirstVal
= yynewItem
;
762 if (yystack
->yyspaceLeft
< YYHEADROOM
)
763 yyexpandGLRStack (yystack
);
768 /** Initialize SET to a singleton set containing an empty stack. */
770 yyinitStateSet (yyGLRStateSet
* yyset
)
773 yyset
->yycapacity
= 16;
774 yyset
->yystates
= (yyGLRState
**) malloc (16 * sizeof (yyset
->yystates
[0]));
775 yyset
->yystates
[0] = NULL
;
778 static void yyfreeStateSet (yyGLRStateSet
* yyset
)
780 free (yyset
->yystates
);
783 /** Initialize STACK to a single empty stack, with total maximum
784 * capacity for all stacks of SIZE. */
786 yyinitGLRStack (yyGLRStack
* yystack
, size_t yysize
)
788 yystack
->yyerrflag
= 0;
789 yystack
->yyerrState
= 0;
791 yystack
->yyspaceLeft
= yysize
;
792 yystack
->yynextFree
= yystack
->yyitems
=
793 (yyGLRStackItem
*) malloc (yysize
* sizeof (yystack
->yynextFree
[0]));
794 yystack
->yysplitPoint
= NULL
;
795 yystack
->yylastDeleted
= NULL
;
796 yyinitStateSet (&yystack
->yytops
);
799 #define YYRELOC(YYFROMITEMS,YYTOITEMS,YYX,YYTYPE) \
800 &((YYTOITEMS) - ((YYFROMITEMS) - (yyGLRStackItem*) (YYX)))->YYTYPE
802 /** If STACK is expandable, extend it. WARNING: Pointers into the
803 stack from outside should be considered invalid after this call.
804 We always expand when there are 1 or fewer items left AFTER an
805 allocation, so that we can avoid having external pointers exist
806 across an allocation. */
808 yyexpandGLRStack (yyGLRStack
* yystack
)
810 #if YYSTACKEXPANDABLE
811 yyGLRStack yynewStack
;
812 yyGLRStackItem
* yyp0
, *yyp1
;
813 size_t yysize
, yynewSize
;
815 yysize
= yystack
->yynextFree
- yystack
->yyitems
;
816 if (yysize
>= YYMAXDEPTH
)
817 yyFail (yystack
, "parsing stack overflow (%d items)", yysize
);
818 yynewSize
= 2*yysize
;
819 if (yynewSize
> YYMAXDEPTH
)
820 yynewSize
= YYMAXDEPTH
;
821 yyinitGLRStack (&yynewStack
, yynewSize
);
822 for (yyp0
= yystack
->yyitems
, yyp1
= yynewStack
.yyitems
, yyn
= yysize
;
824 yyn
-= 1, yyp0
+= 1, yyp1
+= 1)
829 yyGLRState
* yys0
= &yyp0
->yystate
;
830 yyGLRState
* yys1
= &yyp1
->yystate
;
831 if (yys0
->yypred
!= NULL
)
833 YYRELOC (yyp0
, yyp1
, yys0
->yypred
, yystate
);
834 if (! yys0
->yyresolved
&& yys0
->yysemantics
.yyfirstVal
!= NULL
)
835 yys1
->yysemantics
.yyfirstVal
=
836 YYRELOC(yyp0
, yyp1
, yys0
->yysemantics
.yyfirstVal
, yyoption
);
840 yySemanticOption
* yyv0
= &yyp0
->yyoption
;
841 yySemanticOption
* yyv1
= &yyp1
->yyoption
;
842 if (yyv0
->yystate
!= NULL
)
843 yyv1
->yystate
= YYRELOC (yyp0
, yyp1
, yyv0
->yystate
, yystate
);
844 if (yyv0
->yynext
!= NULL
)
845 yyv1
->yynext
= YYRELOC (yyp0
, yyp1
, yyv0
->yynext
, yyoption
);
848 if (yystack
->yysplitPoint
!= NULL
)
849 yystack
->yysplitPoint
= YYRELOC (yystack
->yyitems
, yynewStack
.yyitems
,
850 yystack
->yysplitPoint
, yystate
);
852 for (yyn
= 0; yyn
< yystack
->yytops
.yysize
; yyn
+= 1)
853 if (yystack
->yytops
.yystates
[yyn
] != NULL
)
854 yystack
->yytops
.yystates
[yyn
] =
855 YYRELOC (yystack
->yyitems
, yynewStack
.yyitems
,
856 yystack
->yytops
.yystates
[yyn
], yystate
);
857 free (yystack
->yyitems
);
858 yystack
->yyitems
= yynewStack
.yyitems
;
859 yystack
->yynextFree
= yynewStack
.yynextFree
+ yysize
;
860 yystack
->yyspaceLeft
= yynewStack
.yyspaceLeft
- yysize
;
864 yyFail (yystack
, "parsing stack overflow (%d items)", yysize
);
870 yyfreeGLRStack (yyGLRStack
* yystack
)
872 free (yystack
->yyitems
);
873 yyfreeStateSet (&yystack
->yytops
);
876 /** Assuming that S is a GLRState somewhere on STACK, update the
877 * splitpoint of STACK, if needed, so that it is at least as deep as
880 yyupdateSplit (yyGLRStack
* yystack
, yyGLRState
* yys
)
882 if (yystack
->yysplitPoint
!= NULL
&& yystack
->yysplitPoint
> yys
)
883 yystack
->yysplitPoint
= yys
;
886 /** Invalidate stack #K in STACK. */
888 yymarkStackDeleted (yyGLRStack
* yystack
, int yyk
)
890 if (yystack
->yytops
.yystates
[yyk
] != NULL
)
891 yystack
->yylastDeleted
= yystack
->yytops
.yystates
[yyk
];
892 yystack
->yytops
.yystates
[yyk
] = NULL
;
895 /** Undelete the last stack that was marked as deleted. Can only be
896 done once after a deletion, and only when all other stacks have
899 yyundeleteLastStack (yyGLRStack
* yystack
)
901 if (yystack
->yylastDeleted
== NULL
|| yystack
->yytops
.yysize
!= 0)
903 yystack
->yytops
.yystates
[0] = yystack
->yylastDeleted
;
904 yystack
->yytops
.yysize
= 1;
905 YYDPRINTF ((stderr
, "Restoring last deleted stack as stack #0.\n"));
906 yystack
->yylastDeleted
= NULL
;
910 yyremoveDeletes (yyGLRStack
* yystack
)
914 while (yyj
< yystack
->yytops
.yysize
)
916 if (yystack
->yytops
.yystates
[yyi
] == NULL
)
919 YYDPRINTF ((stderr
, "Removing dead stacks.\n"));
920 yystack
->yytops
.yysize
-= 1;
924 yystack
->yytops
.yystates
[yyj
] = yystack
->yytops
.yystates
[yyi
];
926 YYDPRINTF ((stderr
, "Rename stack %d -> %d.\n", yyi
, yyj
));
933 /** Shift to a new state on stack #K of STACK, corresponding to LR state
934 * LRSTATE, at input position POSN, with (resolved) semantic value SVAL. */
936 yyglrShift (yyGLRStack
* yystack
, int yyk
, yyStateNum yylrState
, size_t yyposn
,
937 YYSTYPE yysval
, YYLTYPE
* yylocp
)
939 yyGLRStackItem
* yynewItem
;
941 yynewItem
= yystack
->yynextFree
;
942 yystack
->yynextFree
+= 1;
943 yystack
->yyspaceLeft
-= 1;
944 yynewItem
->yystate
.yyisState
= yytrue
;
945 yynewItem
->yystate
.yylrState
= yylrState
;
946 yynewItem
->yystate
.yyposn
= yyposn
;
947 yynewItem
->yystate
.yyresolved
= yytrue
;
948 yynewItem
->yystate
.yypred
= yystack
->yytops
.yystates
[yyk
];
949 yystack
->yytops
.yystates
[yyk
] = &yynewItem
->yystate
;
950 yynewItem
->yystate
.yysemantics
.yysval
= yysval
;
951 yynewItem
->yystate
.yyloc
= *yylocp
;
952 if (yystack
->yyspaceLeft
< YYHEADROOM
)
953 yyexpandGLRStack (yystack
);
956 /** Shift to a new state on stack #K of STACK, to a new state
957 * corresponding to LR state LRSTATE, at input position POSN, with
958 * the (unresolved) semantic value of RHS under the action for RULE. */
960 yyglrShiftDefer (yyGLRStack
* yystack
, int yyk
, yyStateNum yylrState
,
961 size_t yyposn
, yyGLRState
* yyrhs
, yyRuleNum yyrule
)
963 yyGLRStackItem
* yynewItem
;
965 yynewItem
= yystack
->yynextFree
;
966 yynewItem
->yystate
.yyisState
= yytrue
;
967 yynewItem
->yystate
.yylrState
= yylrState
;
968 yynewItem
->yystate
.yyposn
= yyposn
;
969 yynewItem
->yystate
.yyresolved
= yyfalse
;
970 yynewItem
->yystate
.yypred
= yystack
->yytops
.yystates
[yyk
];
971 yynewItem
->yystate
.yysemantics
.yyfirstVal
= NULL
;
972 yystack
->yytops
.yystates
[yyk
] = &yynewItem
->yystate
;
973 yystack
->yynextFree
+= 1;
974 yystack
->yyspaceLeft
-= 1;
975 yyaddDeferredAction (yystack
, &yynewItem
->yystate
, yyrhs
, yyrule
);
978 /** Pop the symbols consumed by reduction #RULE from the top of stack
979 * #K of STACK, and perform the appropriate semantic action on their
980 * semantic values. Assumes that all ambiguities in semantic values
981 * have been previously resolved. Set *VALP to the resulting value,
982 * and *LOCP to the computed location (if any). Return value is as
985 yydoAction (yyGLRStack
* yystack
, int yyk
, yyRuleNum yyrule
,
986 YYSTYPE
* yyvalp
, YYLTYPE
* yylocp
)
988 int yynrhs
= yyrhsLength (yyrule
);
990 if (yystack
->yysplitPoint
== NULL
)
992 /* Standard special case: single stack. */
993 yyGLRStackItem
* yyrhs
= (yyGLRStackItem
*) yystack
->yytops
.yystates
[yyk
];
995 yystack
->yynextFree
-= yynrhs
;
996 yystack
->yyspaceLeft
+= yynrhs
;
997 yystack
->yytops
.yystates
[0] = & yystack
->yynextFree
[-1].yystate
;
1000 *yyvalp
= yyval_default
;
1001 *yylocp
= yyloc_default
;
1005 *yyvalp
= yyrhs
[1-yynrhs
].yystate
.yysemantics
.yysval
;
1006 *yylocp
= yyrhs
[1-yynrhs
].yystate
.yyloc
;
1008 return yyuserAction (yyrule
, yynrhs
, yyrhs
, yyvalp
, yylocp
, yystack
);
1014 yyGLRStackItem yyrhsVals
[YYMAXRHS
];
1015 for (yyi
= yynrhs
-1, yys
= yystack
->yytops
.yystates
[yyk
]; yyi
>= 0;
1016 yyi
-= 1, yys
= yys
->yypred
)
1018 assert (yys
->yypred
!= NULL
);
1019 yyrhsVals
[yyi
].yystate
.yyresolved
= yytrue
;
1020 yyrhsVals
[yyi
].yystate
.yysemantics
.yysval
= yys
->yysemantics
.yysval
;
1021 yyrhsVals
[yyi
].yystate
.yyloc
= yys
->yyloc
;
1023 yyupdateSplit (yystack
, yys
);
1024 yystack
->yytops
.yystates
[yyk
] = yys
;
1027 *yyvalp
= yyval_default
;
1028 *yylocp
= yyloc_default
;
1032 *yyvalp
= yyrhsVals
[0].yystate
.yysemantics
.yysval
;
1033 *yylocp
= yyrhsVals
[0].yystate
.yyloc
;
1035 return yyuserAction (yyrule
, yynrhs
, yyrhsVals
+ (yynrhs
-1),
1036 yyvalp
, yylocp
, yystack
);
1040 /** Pop items off stack #K of STACK according to grammar rule RULE,
1041 * and push back on the resulting nonterminal symbol. Perform the
1042 * semantic action associated with RULE and store its value with the
1043 * newly pushed state, if FORCEEVAL or if STACK is currently
1044 * unambiguous. Otherwise, store the deferred semantic action with
1045 * the new state. If the new state would have an identical input
1046 * position, LR state, and predecessor to an existing state on the stack,
1047 * it is identified with that existing state, eliminating stack #K from
1048 * the STACK. In this case, the (necessarily deferred) semantic value is
1049 * added to the options for the existing state's semantic value.
1051 static inline YYRESULTTAG
1052 yyglrReduce (yyGLRStack
* yystack
, size_t yyk
, yyRuleNum yyrule
,
1055 size_t yyposn
= yystack
->yytops
.yystates
[yyk
]->yyposn
;
1057 if (yyforceEval
|| yystack
->yysplitPoint
== NULL
)
1062 YYCHK (yydoAction (yystack
, yyk
, yyrule
, &yysval
, &yyloc
));
1063 yyglrShift (yystack
, yyk
,
1064 yyLRgotoState (yystack
->yytops
.yystates
[yyk
]->yylrState
,
1065 yylhsNonterm (yyrule
)),
1066 yyposn
, yysval
, &yyloc
);
1067 YYDPRINTF ((stderr
, "Reduced stack %d by rule #%d. Now in state %d.\n",
1068 yyk
, yyrule
-1, yystack
->yytops
.yystates
[yyk
]->yylrState
));
1074 yyGLRState
* yys
, *yys0
= yystack
->yytops
.yystates
[yyk
];
1075 yyStateNum yynewLRState
;
1077 for (yys
= yystack
->yytops
.yystates
[yyk
], yyn
= yyrhsLength (yyrule
);
1081 assert (yys
!= NULL
);
1083 yyupdateSplit (yystack
, yys
);
1084 yynewLRState
= yyLRgotoState (yys
->yylrState
, yylhsNonterm (yyrule
));
1086 "Reduced stack %d by rule #%d; action deferred. "
1087 "Now in state %d.\n",
1088 yyk
, yyrule
-1, yynewLRState
));
1089 for (yyi
= 0; yyi
< yystack
->yytops
.yysize
; yyi
+= 1)
1090 if (yyi
!= yyk
&& yystack
->yytops
.yystates
[yyi
] != NULL
)
1092 yyGLRState
* yyp
, *yysplit
= yystack
->yysplitPoint
;
1093 yyp
= yystack
->yytops
.yystates
[yyi
];
1094 while (yyp
!= yys
&& yyp
!= yysplit
&& yyp
->yyposn
>= yyposn
)
1096 if (yyp
->yylrState
== yynewLRState
&& yyp
->yypred
== yys
)
1098 yyaddDeferredAction (yystack
, yyp
, yys0
, yyrule
);
1099 yymarkStackDeleted (yystack
, yyk
);
1100 YYDPRINTF ((stderr
, "Merging stack %d into stack %d.\n",
1107 yystack
->yytops
.yystates
[yyk
] = yys
;
1108 yyglrShiftDefer (yystack
, yyk
, yynewLRState
, yyposn
, yys0
, yyrule
);
1114 yysplitStack (yyGLRStack
* yystack
, int yyk
)
1116 if (yystack
->yysplitPoint
== NULL
)
1119 yystack
->yysplitPoint
= yystack
->yytops
.yystates
[yyk
];
1121 if (yystack
->yytops
.yysize
>= yystack
->yytops
.yycapacity
)
1123 yystack
->yytops
.yycapacity
*= 2;
1124 yystack
->yytops
.yystates
=
1125 (yyGLRState
**) realloc (yystack
->yytops
.yystates
,
1126 yystack
->yytops
.yycapacity
1127 * sizeof (yyGLRState
*));
1129 yystack
->yytops
.yystates
[yystack
->yytops
.yysize
]
1130 = yystack
->yytops
.yystates
[yyk
];
1131 yystack
->yytops
.yysize
+= 1;
1132 return yystack
->yytops
.yysize
-1;
1135 /** True iff Y0 and Y1 represent identical options at the top level.
1136 * That is, they represent the same rule applied to RHS symbols
1137 * that produce the same terminal symbols. */
1139 yyidenticalOptions (yySemanticOption
* yyy0
, yySemanticOption
* yyy1
)
1141 if (yyy0
->yyrule
== yyy1
->yyrule
)
1143 yyGLRState
*yys0
, *yys1
;
1145 for (yys0
= yyy0
->yystate
, yys1
= yyy1
->yystate
,
1146 yyn
= yyrhsLength (yyy0
->yyrule
);
1148 yys0
= yys0
->yypred
, yys1
= yys1
->yypred
, yyn
-= 1)
1149 if (yys0
->yyposn
!= yys1
->yyposn
)
1157 /** Assuming identicalOptions (Y0,Y1), (destructively) merge the
1158 * alternative semantic values for the RHS-symbols of Y1 into the
1159 * corresponding semantic value sets of the symbols of Y0. */
1161 yymergeOptionSets (yySemanticOption
* yyy0
, yySemanticOption
* yyy1
)
1163 yyGLRState
*yys0
, *yys1
;
1165 for (yys0
= yyy0
->yystate
, yys1
= yyy1
->yystate
,
1166 yyn
= yyrhsLength (yyy0
->yyrule
);
1168 yys0
= yys0
->yypred
, yys1
= yys1
->yypred
, yyn
-= 1)
1171 else if (! yys0
->yyresolved
&& ! yys1
->yyresolved
)
1173 yySemanticOption
* yyz
;
1174 for (yyz
= yys0
->yysemantics
.yyfirstVal
; yyz
->yynext
!= NULL
;
1177 yyz
->yynext
= yys1
->yysemantics
.yyfirstVal
;
1181 /** Y0 and Y1 represent two possible actions to take in a given
1182 * parsing state; return 0 if no combination is possible,
1183 * 1 if user-mergeable, 2 if Y0 is preferred, 3 if Y1 is preferred. */
1185 yypreference (yySemanticOption
* y0
, yySemanticOption
* y1
)
1187 yyRuleNum r0
= y0
->yyrule
, r1
= y1
->yyrule
;
1188 int p0
= yydprec
[r0
], p1
= yydprec
[r1
];
1192 if (yymerger
[r0
] == 0 || yymerger
[r0
] != yymerger
[r1
])
1197 if (p0
== 0 || p1
== 0)
1206 static YYRESULTTAG
yyresolveValue (yySemanticOption
* yyoptionList
,
1207 yyGLRStack
* yystack
, YYSTYPE
* yyvalp
,
1211 yyresolveStates (yyGLRState
* yys
, int yyn
, yyGLRStack
* yystack
)
1216 assert (yys
->yypred
!= NULL
);
1217 yyflag
= yyresolveStates (yys
->yypred
, yyn
-1, yystack
);
1220 if (! yys
->yyresolved
)
1222 yyflag
= yyresolveValue (yys
->yysemantics
.yyfirstVal
, yystack
,
1223 &yys
->yysemantics
.yysval
, &yys
->yyloc
);
1226 yys
->yyresolved
= yytrue
;
1233 yyresolveAction (yySemanticOption
* yyopt
, yyGLRStack
* yystack
,
1234 YYSTYPE
* yyvalp
, YYLTYPE
* yylocp
)
1236 yyGLRStackItem yyrhsVals
[YYMAXRHS
];
1240 yynrhs
= yyrhsLength (yyopt
->yyrule
);
1241 YYCHK (yyresolveStates (yyopt
->yystate
, yynrhs
, yystack
));
1242 for (yyi
= yynrhs
-1, yys
= yyopt
->yystate
; yyi
>= 0;
1243 yyi
-= 1, yys
= yys
->yypred
)
1245 assert (yys
->yypred
!= NULL
);
1246 yyrhsVals
[yyi
].yystate
.yyresolved
= yytrue
;
1247 yyrhsVals
[yyi
].yystate
.yysemantics
.yysval
= yys
->yysemantics
.yysval
;
1248 yyrhsVals
[yyi
].yystate
.yyloc
= yys
->yyloc
;
1250 return yyuserAction (yyopt
->yyrule
, yynrhs
, yyrhsVals
+ (yynrhs
-1),
1251 yyvalp
, yylocp
, yystack
);
1255 static yyGLRState YYLEFTMOST_STATE
= { 0, NULL
, -1, 0, { NULL
} };
1257 static void yyreportTree (yySemanticOption
* yyx
, int yyindent
)
1259 int yynrhs
= yyrhsLength (yyx
->yyrule
);
1262 yyGLRState
* yystates
[YYMAXRHS
];
1264 for (yyi
= yynrhs
, yys
= yyx
->yystate
; yyi
> 0; yyi
-= 1, yys
= yys
->yypred
)
1265 yystates
[yyi
] = yys
;
1267 yystates
[0] = &YYLEFTMOST_STATE
;
1271 if (yys
->yyposn
+1 > yyx
->yystate
->yyposn
)
1272 YYFPRINTF (stderr
, "%*s%s -> <Rule %d, empty>\n",
1273 yyindent
, "", yytokenName (yylhsNonterm (yyx
->yyrule
)),
1276 YYFPRINTF (stderr
, "%*s%s -> <Rule %d, tokens %d .. %d>\n",
1277 yyindent
, "", yytokenName (yylhsNonterm (yyx
->yyrule
)),
1278 yyx
->yyrule
, yys
->yyposn
+1, yyx
->yystate
->yyposn
);
1279 for (yyi
= 1; yyi
<= yynrhs
; yyi
+= 1)
1281 if (yystates
[yyi
]->yyresolved
)
1283 if (yystates
[yyi
-1]->yyposn
+1 > yystates
[yyi
]->yyposn
)
1284 YYFPRINTF (stderr
, "%*s%s <empty>\n", yyindent
+2, "",
1285 yytokenName (yyrhs
[yyprhs
[yyx
->yyrule
]+yyi
-1]));
1287 YYFPRINTF (stderr
, "%*s%s <tokens %d .. %d>\n", yyindent
+2, "",
1288 yytokenName (yyrhs
[yyprhs
[yyx
->yyrule
]+yyi
-1]),
1289 yystates
[yyi
-1]->yyposn
+1, yystates
[yyi
]->yyposn
);
1292 yyreportTree (yystates
[yyi
]->yysemantics
.yyfirstVal
, yyindent
+2);
1298 yyreportAmbiguity (yySemanticOption
* yyx0
, yySemanticOption
* yyx1
,
1299 yyGLRStack
* yystack
)
1301 /* `Unused' warnings. */
1306 YYFPRINTF (stderr
, "Ambiguity detected.\n");
1307 YYFPRINTF (stderr
, "Option 1,\n");
1308 yyreportTree (yyx0
, 2);
1309 YYFPRINTF (stderr
, "\nOption 2,\n");
1310 yyreportTree (yyx1
, 2);
1311 YYFPRINTF (stderr
, "\n");
1313 yyFail (yystack
, "ambiguity detected");
1317 /** Resolve the ambiguity represented by OPTIONLIST, perform the indicated
1318 * actions, and return the result. */
1320 yyresolveValue (yySemanticOption
* yyoptionList
, yyGLRStack
* yystack
,
1321 YYSTYPE
* yyvalp
, YYLTYPE
* yylocp
)
1323 yySemanticOption
* yybest
;
1324 yySemanticOption
* yyp
;
1327 yybest
= yyoptionList
;
1329 for (yyp
= yyoptionList
->yynext
; yyp
!= NULL
; yyp
= yyp
->yynext
)
1331 if (yyidenticalOptions (yybest
, yyp
))
1332 yymergeOptionSets (yybest
, yyp
);
1334 switch (yypreference (yybest
, yyp
))
1337 yyreportAmbiguity (yybest
, yyp
, yystack
);
1353 int yyprec
= yydprec
[yybest
->yyrule
];
1354 YYCHK (yyresolveAction (yybest
, yystack
, yyvalp
, yylocp
));
1355 for (yyp
= yybest
->yynext
; yyp
!= NULL
; yyp
= yyp
->yynext
)
1357 if (yyprec
== yydprec
[yyp
->yyrule
])
1361 YYCHK (yyresolveAction (yyp
, yystack
, &yyval1
, &yydummy
));
1362 *yyvalp
= yyuserMerge (yymerger
[yyp
->yyrule
], yyvalp
, &yyval1
);
1368 return yyresolveAction (yybest
, yystack
, yyvalp
, yylocp
);
1372 yyresolveStack (yyGLRStack
* yystack
)
1374 if (yystack
->yysplitPoint
!= NULL
)
1379 for (yyn
= 0, yys
= yystack
->yytops
.yystates
[0];
1380 yys
!= yystack
->yysplitPoint
;
1381 yys
= yys
->yypred
, yyn
+= 1)
1383 YYCHK (yyresolveStates (yystack
->yytops
.yystates
[0], yyn
, yystack
));
1389 yycompressStack (yyGLRStack
* yystack
)
1391 yyGLRState
* yyp
, *yyq
, *yyr
;
1393 if (yystack
->yytops
.yysize
!= 1 || yystack
->yysplitPoint
== NULL
)
1396 for (yyp
= yystack
->yytops
.yystates
[0], yyq
= yyp
->yypred
, yyr
= NULL
;
1397 yyp
!= yystack
->yysplitPoint
;
1398 yyr
= yyp
, yyp
= yyq
, yyq
= yyp
->yypred
)
1401 yystack
->yyspaceLeft
+= yystack
->yynextFree
- yystack
->yyitems
;
1402 yystack
->yynextFree
= ((yyGLRStackItem
*) yystack
->yysplitPoint
) + 1;
1403 yystack
->yyspaceLeft
-= yystack
->yynextFree
- yystack
->yyitems
;
1404 yystack
->yysplitPoint
= NULL
;
1405 yystack
->yylastDeleted
= NULL
;
1409 yystack
->yynextFree
->yystate
= *yyr
;
1411 yystack
->yynextFree
->yystate
.yypred
= & yystack
->yynextFree
[-1].yystate
;
1412 yystack
->yytops
.yystates
[0] = &yystack
->yynextFree
->yystate
;
1413 yystack
->yynextFree
+= 1;
1414 yystack
->yyspaceLeft
-= 1;
1419 yyprocessOneStack (yyGLRStack
* yystack
, int yyk
,
1420 size_t yyposn
, YYSTYPE
* yylvalp
, YYLTYPE
* yyllocp
)
1423 const short* yyconflicts
;
1425 yySymbol
* const yytokenp
= yystack
->yytokenp
;
1427 while (yystack
->yytops
.yystates
[yyk
] != NULL
)
1429 yyStateNum yystate
= yystack
->yytops
.yystates
[yyk
]->yylrState
;
1431 assert (yystate
!= YYFINAL
);
1432 if (yyisDefaultedState (yystate
))
1434 yyrule
= yydefaultAction (yystate
);
1437 YYDPRINTF ((stderr
, "Stack %d dies.\n", yyk
));
1438 yymarkStackDeleted (yystack
, yyk
);
1441 YYCHK (yyglrReduce (yystack
, yyk
, yyrule
, yyfalse
));
1445 if (*yytokenp
== YYEMPTY
)
1448 *yytokenp
= YYTRANSLATE(yychar
);
1449 YYDPRINTF ((stderr
, "Read token %s\n", yytokenName (*yytokenp
)));
1451 yygetLRActions (yystate
, *yytokenp
, &yyaction
, &yyconflicts
);
1453 while (*yyconflicts
!= 0)
1455 int yynewStack
= yysplitStack (yystack
, yyk
);
1456 YYDPRINTF ((stderr
, "Splitting off stack %d from %d.\n",
1458 YYCHK (yyglrReduce (yystack
, yynewStack
, *yyconflicts
, yyfalse
));
1459 YYCHK (yyprocessOneStack (yystack
, yynewStack
, yyposn
,
1464 if (yyisShiftAction (yyaction
))
1466 YYDPRINTF ((stderr
, "Shifted token %s on stack %d, ",
1467 yytokenName (*yytokenp
), yyk
));
1468 yyglrShift (yystack
, yyk
, yyaction
, yyposn
+1, *yylvalp
, yyllocp
);
1469 YYDPRINTF ((stderr
, "which is now in state #%d\n",
1470 yystack
->yytops
.yystates
[yyk
]->yylrState
));
1473 else if (yyisErrorAction (yyaction
))
1475 YYDPRINTF ((stderr
, "Stack %d dies.\n", yyk
));
1476 yymarkStackDeleted (yystack
, yyk
);
1480 YYCHK (yyglrReduce (yystack
, yyk
, -yyaction
, yyfalse
));
1487 yyreportParseError (yyGLRStack
* yystack
, YYSTYPE
* yylvalp
, YYLTYPE
* yyllocp
)
1489 /* `Unused' warnings. */
1493 if (yystack
->yyerrState
== 0)
1496 yySymbol
* const yytokenp
= yystack
->yytokenp
;
1497 int yyn
, yyx
, yycount
, yysize
;
1498 const char* yyprefix
;
1501 yyn
= yypact
[yystack
->yytops
.yystates
[0]->yylrState
];
1502 if (YYPACT_NINF
< yyn
&& yyn
< YYLAST
)
1505 /* Start YYX at -YYN if negative to avoid negative indexes in
1507 yysize
= sizeof ("parse error, unexpected ")
1508 + strlen (yytokenName (*yytokenp
));
1509 yyprefix
= ", expecting ";
1510 for (yyx
= yyn
< 0 ? -yyn
: 0; yyx
< yytname_size
&& yycount
<= 5;
1512 if (yycheck
[yyx
+ yyn
] == yyx
)
1513 yysize
+= strlen (yytokenName (yyx
)) + strlen (yyprefix
),
1514 yycount
+= 1, yyprefix
= " or ";
1515 yymsg
= yyp
= (char*) malloc (yysize
);
1516 yyp
+= sprintf (yyp
, "parse error, unexpected %s",
1517 yytokenName (*yytokenp
));
1520 yyprefix
= ", expecting ";
1521 for (yyx
= yyn
< 0 ? -yyn
: 0; yyx
< yytname_size
; yyx
+= 1)
1522 if (yycheck
[yyx
+ yyn
] == yyx
)
1524 yyp
+= sprintf (yyp
, "%s%s", yyprefix
, yytokenName (yyx
));
1533 yyerror ("parse error");
1538 /* Recover from a syntax error on STACK, assuming that TOKENP,
1539 YYLVALP, and YYLLOCP point to the syntactic category, semantic
1540 value, and location of the lookahead.
1541 NOTE: This uses the panic-mode recovery algorithm described in the
1542 Bison documentation, which differs from what is in bison.simple.
1543 Specifically, this routine performs no reductions before shifting
1546 yyrecoverParseError (yyGLRStack
* yystack
, YYSTYPE
* yylvalp
, YYLTYPE
* yyllocp
)
1548 yySymbol
* const yytokenp
= yystack
->yytokenp
;
1552 if (yystack
->yyerrState
== 0)
1553 yystack
->yyerrState
= 3;
1554 else if (yystack
->yyerrState
== 3)
1556 /* We just shifted the error token and (perhaps) took some
1557 reductions. Skip tokens until we can proceed. */
1559 if (*yytokenp
== YYEOF
)
1560 yyFail (yystack
, NULL
);
1561 if (*yytokenp
!= YYEMPTY
)
1562 YYDPRINTF ((stderr
, "Discarding token %s\n",
1563 yytokenName (*yytokenp
)));
1565 *yytokenp
= YYTRANSLATE (yychar
);
1566 YYDPRINTF ((stderr
, "Read token %s\n", yytokenName (*yytokenp
)));
1567 yyj
= yypact
[yystack
->yytops
.yystates
[0]->yylrState
];
1568 if (yyj
== YYPACT_NINF
)
1569 /* Something's not right; we shouldn't be here */
1570 yyFail (yystack
, NULL
);
1572 if (yyj
< 0 || yyj
> YYLAST
|| yycheck
[yyj
] != *yytokenp
)
1574 if (yydefact
[yystack
->yytops
.yystates
[0]->yylrState
] != 0)
1577 else if (yytable
[yyj
] != 0 && yytable
[yyj
] != YYTABLE_NINF
)
1582 /* Reduce to one stack */
1583 for (yyk
= 0; yyk
< yystack
->yytops
.yysize
; yyk
+= 1)
1584 if (yystack
->yytops
.yystates
[yyk
] != NULL
)
1586 if (yyk
>= yystack
->yytops
.yysize
)
1587 yyFail (yystack
, NULL
);
1588 for (yyk
+= 1; yyk
< yystack
->yytops
.yysize
; yyk
+= 1)
1589 yymarkStackDeleted (yystack
, yyk
);
1590 yyremoveDeletes (yystack
);
1591 yycompressStack (yystack
);
1593 /* Now pop stack until we find a state that shifts the error token. */
1594 while (yystack
->yytops
.yystates
[0] != NULL
)
1596 yyj
= yypact
[yystack
->yytops
.yystates
[0]->yylrState
] + YYTERROR
;
1597 if (yyj
!= YYPACT_NINF
+ YYTERROR
&& yyj
>= 0 && yyj
<= YYLAST
&&
1598 yycheck
[yyj
] == YYTERROR
&& yyisShiftAction (yytable
[yyj
]))
1600 yyglrShift (yystack
, 0, yytable
[yyj
],
1601 yystack
->yytops
.yystates
[0]->yyposn
, *yylvalp
, yyllocp
);
1604 yystack
->yytops
.yystates
[0] = yystack
->yytops
.yystates
[0]->yypred
;
1605 yystack
->yynextFree
-= 1;
1606 yystack
->yyspaceLeft
+= 1;
1608 if (yystack
->yytops
.yystates
[0] == NULL
)
1609 yyFail (yystack
, NULL
);
1612 #define YYCHK1(YYE) \
1618 yystack.yyerrflag = 1; \
1621 yystack.yyerrflag = 0; \
1624 goto yyuser_error; \
1629 yyparse (YYPARSE_PARAM_ARG
)
1639 #define yychar (yystack.yyrawchar)
1642 YYSTYPE
* const yylvalp
= &yylval
;
1643 YYLTYPE
* const yyllocp
= &yylloc
;
1645 yyinitGLRStack (&yystack
, YYINITDEPTH
);
1646 yystack
.yytokenp
= &yytoken
;
1648 if (setjmp (yystack
.yyexception_buffer
) != 0)
1651 yyglrShift (&yystack
, 0, 0, 0, yyval_default
, &yyloc_default
);
1657 /* For efficiency, we have two loops, of which the first of which
1658 * is specialized to deterministic operation (single stack, no
1659 * potential ambiguity). */
1666 const short* yyconflicts
;
1668 yyStateNum yystate
= yystack
.yytops
.yystates
[0]->yylrState
;
1669 if (yystate
== YYFINAL
)
1671 if (yyisDefaultedState (yystate
))
1673 yyrule
= yydefaultAction (yystate
);
1676 yyreportParseError (&yystack
, yylvalp
, yyllocp
);
1679 YYCHK1 (yyglrReduce (&yystack
, 0, yyrule
, yytrue
));
1683 if (yytoken
== YYEMPTY
)
1686 yytoken
= YYTRANSLATE (yychar
);
1687 YYDPRINTF ((stderr
, "Read token %s\n",
1688 yytokenName (yytoken
)));
1690 yygetLRActions (yystate
, yytoken
, &yyaction
, &yyconflicts
);
1691 if (*yyconflicts
!= 0)
1693 if (yyisShiftAction (yyaction
))
1695 YYDPRINTF ((stderr
, "Shifted token %s. ",
1696 yytokenName (yytoken
)));
1697 if (yytoken
!= YYEOF
)
1700 yyglrShift (&yystack
, 0, yyaction
, yyposn
, yylval
, yyllocp
);
1701 if (yystack
.yyerrState
> 0)
1702 yystack
.yyerrState
-= 1;
1703 YYDPRINTF ((stderr
, "Now in state #%d\n",
1704 yystack
.yytops
.yystates
[0]->yylrState
));
1706 else if (yyisErrorAction (yyaction
))
1708 yyreportParseError (&yystack
, yylvalp
, yyllocp
);
1712 YYCHK1 (yyglrReduce (&yystack
, 0, -yyaction
, yytrue
));
1719 int yyn
= yystack
.yytops
.yysize
;
1720 for (yys
= 0; yys
< yyn
; yys
+= 1)
1721 YYCHK1 (yyprocessOneStack (&yystack
, yys
, yyposn
,
1725 yyremoveDeletes (&yystack
);
1726 if (yystack
.yytops
.yysize
== 0)
1728 yyundeleteLastStack (&yystack
);
1729 if (yystack
.yytops
.yysize
== 0)
1730 yyFail (&yystack
, "parse error");
1731 YYCHK1 (yyresolveStack (&yystack
));
1732 YYDPRINTF ((stderr
, "Returning to deterministic operation.\n"));
1733 yyreportParseError (&yystack
, yylvalp
, yyllocp
);
1736 else if (yystack
.yytops
.yysize
== 1)
1738 YYCHK1 (yyresolveStack (&yystack
));
1739 YYDPRINTF ((stderr
, "Returning to deterministic operation.\n"));
1740 yycompressStack (&yystack
);
1746 yyrecoverParseError (&yystack
, yylvalp
, yyllocp
);
1747 yyposn
= yystack
.yytops
.yystates
[0]->yyposn
;
1752 yyfreeGLRStack (&yystack
);
1753 return yystack
.yyerrflag
;
1756 /* DEBUGGING ONLY */
1757 static void yypstack (yyGLRStack
* yystack
, int yyk
) ATTRIBUTE_UNUSED
;
1758 static void yypdumpstack (yyGLRStack
* yystack
) ATTRIBUTE_UNUSED
;
1761 yypstates (yyGLRState
* yyst
)
1764 yy_yypstack (yyGLRState
* yys
)
1766 if (yys
->yypred
== NULL
)
1767 fprintf (stderr
, "%d@%d", yys
->yylrState
, yys
->yyposn
);
1770 yy_yypstack (yys
->yypred
);
1771 fprintf (stderr
, " -> %d@%d", yys
->yylrState
, yys
->yyposn
);
1776 fprintf (stderr
, "<null>");
1779 fprintf (stderr
, "\n");
1783 yypstack (yyGLRStack
* yystack
, int yyk
)
1785 yypstates (yystack
->yytops
.yystates
[yyk
]);
1788 #define YYINDEX(YYX) \
1789 ((YYX) == NULL ? -1 : (yyGLRStackItem*) (YYX) - yystack->yyitems)
1793 yypdumpstack (yyGLRStack
* yystack
)
1795 yyGLRStackItem
* yyp
;
1797 for (yyp
= yystack
->yyitems
; yyp
< yystack
->yynextFree
; yyp
+= 1)
1799 fprintf (stderr
, "%3d. ", yyp
- yystack
->yyitems
);
1802 fprintf (stderr
, "Res: %d, LR State: %d, posn: %d, pred: %d",
1803 yyp
->yystate
.yyresolved
, yyp
->yystate
.yylrState
,
1804 yyp
->yystate
.yyposn
,
1805 YYINDEX(yyp
->yystate
.yypred
));
1806 if (! yyp
->yystate
.yyresolved
)
1807 fprintf (stderr
, ", firstVal: %d",
1808 YYINDEX (yyp
->yystate
.yysemantics
.yyfirstVal
));
1812 fprintf (stderr
, "Option. rule: %d, state: %d, next: %d",
1813 yyp
->yyoption
.yyrule
, YYINDEX (yyp
->yyoption
.yystate
),
1814 YYINDEX (yyp
->yyoption
.yynext
));
1816 fprintf (stderr
, "\n");
1818 fprintf (stderr
, "Tops:");
1819 for (yyi
= 0; yyi
< yystack
->yytops
.yysize
; yyi
+= 1)
1820 fprintf (stderr
, "%d: %d; ", yyi
, YYINDEX (yystack
->yytops
.yystates
[yyi
]));
1821 fprintf (stderr
, "\n");
1827 m4_if(b4_defines_flag
, 0, [],
1828 [#output "b4_output_header_name"
1829 b4_copyright([Skeleton parser
for GLR parsing with Bison
], [2002])
1830 #ifndef b4_header_guard
1831 # define b4_header_guard
1833 b4_token_defines(b4_tokens
)
1836 m4_ifdef([b4_stype
],
1837 [#line b4_stype_line "b4_filename"
1838 typedef union b4_stype yystype
;
1839 /* Line __line__ of __file__. */
1840 #line __oline__ "__ofile__"],
1841 [typedef int yystype
;])
1842 # define YYSTYPE yystype
1846 [extern YYSTYPE b4_prefix
[]lval
;])
1850 typedef struct yyltype
1857 # define YYLTYPE yyltype
1861 [extern YYLTYPE b4_prefix
[]lloc
;])
1863 #endif /* not b4_header_guard */