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 /* Copy the first part of user declarations. */
142 b4_token_defines(b4_tokens
)[
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
175 int yylast_column
;])[
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 YYFLAG ]b4_flag[
224 #define YYLAST ]b4_last[
226 /* YYNTOKENS -- Number of terminals. */
227 #define YYNTOKENS ]b4_tokens_number[
228 /* YYNNTS -- Number of nonterminals. */
229 #define YYNNTS ]b4_nterms_number[
230 /* YYNRULES -- Number of rules. */
231 #define YYNRULES ]b4_rules_number[
232 /* YYNRULES -- Number of states. */
233 #define YYNSTATES ]b4_states_number[
234 /* YYMAXRHS -- Maximum number of symbols on right-hand side of rule. */
235 #define YYMAXRHS ]b4_r2_max[
237 /* YYTRANSLATE(X) -- Bison symbol number corresponding to X. */
238 #define YYUNDEFTOK ]b4_undef_token_number[
239 #define YYMAXUTOK ]b4_user_token_number_max[
241 #define YYTRANSLATE(YYX) \
242 ((unsigned)(YYX) <= YYMAXUTOK ? yytranslate[YYX] : YYUNDEFTOK)
244 /* YYTRANSLATE[YYLEX] -- Bison symbol number corresponding to YYLEX. */
245 static const ]b4_int_type_for([b4_translate
])[ yytranslate
[] =
251 /* YYPRHS[YYN] -- Index of the first RHS symbol of rule number YYN in
253 static const ]b4_int_type_for([b4_prhs
])[ yyprhs
[] =
258 /* YYRHS -- A `-1'-separated list of the rules' RHS. */
259 static const ]b4_int_type_for([b4_rhs
])[ yyrhs
[] =
264 /* YYRLINE[YYN] -- source line where rule number YYN was defined. */
265 static const ]b4_int_type_for([b4_rline
])[ yyrline
[] =
271 #if (YYDEBUG) || YYERROR_VERBOSE
272 /* YYTNME[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM.
273 First, the terminals, then, starting at YYNTOKENS, nonterminals. */
274 static const char *const yytname
[] =
279 #define yytname_size ((int) (sizeof (yytname) / sizeof (yytname[0])))
282 /* YYR1[YYN] -- Symbol number of symbol that rule YYN derives. */
283 static const ]b4_int_type_for([b4_r1
])[ yyr1
[] =
288 /* YYR2[YYN] -- Number of symbols composing right hand side of rule YYN. */
289 static const ]b4_int_type_for([b4_r2
])[ yyr2
[] =
294 /* YYDPREC[RULE-NUM] -- Dynamic precedence of rule #RULE-NUM (0 if none). */
295 static const ]b4_int_type_for([b4_dprec
])[ yydprec
[] =
300 /* YYMERGER[RULE-NUM] -- Index of merging function for rule #RULE-NUM. */
301 static const ]b4_int_type_for([b4_merger
])[ yymerger
[] =
306 /* YYDEFACT[S] -- default rule to reduce with in state S when YYTABLE
307 doesn't specify something else to do. Zero means the default is an
309 static const ]b4_int_type_for([b4_defact
])[ yydefact
[] =
314 /* YYPDEFGOTO[NTERM-NUM]. */
315 static const ]b4_int_type_for([b4_defgoto
])[ yydefgoto
[] =
320 /* YYPACT[STATE-NUM] -- Index in YYTABLE of the portion describing
322 #define YYPACT_NINF ]b4_pact_ninf[
323 static const ]b4_int_type_for([b4_pact
])[ yypact
[] =
328 /* YYPGOTO[NTERM-NUM]. */
329 static const ]b4_int_type_for([b4_pgoto
])[ yypgoto
[] =
334 /* YYTABLE[YYPACT[STATE-NUM]]. What to do in state STATE-NUM. If
335 positive, shift that token. If negative, reduce the rule which
336 number is the opposite. If zero, do what YYDEFACT says. */
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 list
344 of conflicting reductions corresponding to action entry for state
345 STATE-NUM in yytable. 0 means no conflicts. The list in yyconfl
346 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
353 by 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.yyfirst_line = YYRHSLOC(yyRhs,1).yyfirst_line; \
400 yyCurrent.yyfirst_column = YYRHSLOC(yyRhs,1).yyfirst_column; \
401 yyCurrent.yylast_line = YYRHSLOC(yyRhs,YYN).yylast_line; \
402 yyCurrent.yylast_column = YYRHSLOC(yyRhs,YYN).yylast_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 *ACTION to the action to take in STATE on seeing TOKEN.
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 || yyindex
> YYLAST
|| yycheck
[yyindex
] != yytoken
)
710 *yyaction
= -yydefact
[yystate
];
711 *yyconflicts
= yyconfl
;
715 *yyaction
= yytable
[yyindex
];
716 *yyconflicts
= yyconfl
+ yyconflp
[yyindex
];
720 static inline yyStateNum
721 yyLRgotoState (yyStateNum yystate
, yySymbol yylhs
)
724 yyr
= yypgoto
[yylhs
- YYNTOKENS
] + yystate
;
725 if (yyr
>= 0 && yyr
<= YYLAST
&& yycheck
[yyr
] == yystate
)
728 return yydefgoto
[yylhs
- YYNTOKENS
];
732 yyisShiftAction (int yyaction
)
738 yyisErrorAction (int yyaction
)
740 return yyaction
== 0 || yyaction
== YYPACT_NINF
;
745 /** True iff the semantic value of the edge leading to STATE is
748 yyhasResolvedValue (yyGLRState
* yystate
)
750 return yystate
->yyresolved
;
754 yyaddDeferredAction (yyGLRStack
* yystack
, yyGLRState
* yystate
,
755 yyGLRState
* yyrhs
, yyRuleNum yyrule
)
757 yySemanticOption
* yynewItem
;
758 yynewItem
= &yystack
->yynextFree
->yyoption
;
759 yystack
->yyspaceLeft
-= 1;
760 yystack
->yynextFree
+= 1;
761 yynewItem
->yyisState
= yyfalse
;
762 yynewItem
->yystate
= yyrhs
;
763 yynewItem
->yyrule
= yyrule
;
764 yynewItem
->yynext
= yystate
->yysemantics
.yyfirstVal
;
765 yystate
->yysemantics
.yyfirstVal
= yynewItem
;
766 if (yystack
->yyspaceLeft
< YYHEADROOM
)
767 yyexpandGLRStack (yystack
);
772 /** Initialize SET to a singleton set containing an empty stack. */
774 yyinitStateSet (yyGLRStateSet
* yyset
)
777 yyset
->yycapacity
= 16;
778 yyset
->yystates
= (yyGLRState
**) malloc (16 * sizeof (yyset
->yystates
[0]));
779 yyset
->yystates
[0] = NULL
;
782 static void yyfreeStateSet (yyGLRStateSet
* yyset
)
784 free (yyset
->yystates
);
787 /** Initialize STACK to a single empty stack, with total maximum
788 * capacity for all stacks of SIZE. */
790 yyinitGLRStack (yyGLRStack
* yystack
, size_t yysize
)
792 yystack
->yyerrflag
= 0;
793 yystack
->yyerrState
= 0;
795 yystack
->yyspaceLeft
= yysize
;
796 yystack
->yynextFree
= yystack
->yyitems
=
797 (yyGLRStackItem
*) malloc (yysize
* sizeof (yystack
->yynextFree
[0]));
798 yystack
->yysplitPoint
= NULL
;
799 yystack
->yylastDeleted
= NULL
;
800 yyinitStateSet (&yystack
->yytops
);
803 #define YYRELOC(YYFROMITEMS,YYTOITEMS,YYX,YYTYPE) \
804 &((YYTOITEMS) - ((YYFROMITEMS) - (yyGLRStackItem*) (YYX)))->YYTYPE
806 /** If STACK is expandable, extend it. WARNING: Pointers into the
807 stack from outside should be considered invalid after this call.
808 We always expand when there are 1 or fewer items left AFTER an
809 allocation, so that we can avoid having external pointers exist
810 across an allocation. */
812 yyexpandGLRStack (yyGLRStack
* yystack
)
814 #if YYSTACKEXPANDABLE
815 yyGLRStack yynewStack
;
816 yyGLRStackItem
* yyp0
, *yyp1
;
817 size_t yysize
, yynewSize
;
819 yysize
= yystack
->yynextFree
- yystack
->yyitems
;
820 if (yysize
>= YYMAXDEPTH
)
821 yyFail (yystack
, "parsing stack overflow (%d items)", yysize
);
822 yynewSize
= 2*yysize
;
823 if (yynewSize
> YYMAXDEPTH
)
824 yynewSize
= YYMAXDEPTH
;
825 yyinitGLRStack (&yynewStack
, yynewSize
);
826 for (yyp0
= yystack
->yyitems
, yyp1
= yynewStack
.yyitems
, yyn
= yysize
;
828 yyn
-= 1, yyp0
+= 1, yyp1
+= 1)
833 yyGLRState
* yys0
= &yyp0
->yystate
;
834 yyGLRState
* yys1
= &yyp1
->yystate
;
835 if (yys0
->yypred
!= NULL
)
837 YYRELOC (yyp0
, yyp1
, yys0
->yypred
, yystate
);
838 if (! yys0
->yyresolved
&& yys0
->yysemantics
.yyfirstVal
!= NULL
)
839 yys1
->yysemantics
.yyfirstVal
=
840 YYRELOC(yyp0
, yyp1
, yys0
->yysemantics
.yyfirstVal
, yyoption
);
844 yySemanticOption
* yyv0
= &yyp0
->yyoption
;
845 yySemanticOption
* yyv1
= &yyp1
->yyoption
;
846 if (yyv0
->yystate
!= NULL
)
847 yyv1
->yystate
= YYRELOC (yyp0
, yyp1
, yyv0
->yystate
, yystate
);
848 if (yyv0
->yynext
!= NULL
)
849 yyv1
->yynext
= YYRELOC (yyp0
, yyp1
, yyv0
->yynext
, yyoption
);
852 if (yystack
->yysplitPoint
!= NULL
)
853 yystack
->yysplitPoint
= YYRELOC (yystack
->yyitems
, yynewStack
.yyitems
,
854 yystack
->yysplitPoint
, yystate
);
856 for (yyn
= 0; yyn
< yystack
->yytops
.yysize
; yyn
+= 1)
857 if (yystack
->yytops
.yystates
[yyn
] != NULL
)
858 yystack
->yytops
.yystates
[yyn
] =
859 YYRELOC (yystack
->yyitems
, yynewStack
.yyitems
,
860 yystack
->yytops
.yystates
[yyn
], yystate
);
861 free (yystack
->yyitems
);
862 yystack
->yyitems
= yynewStack
.yyitems
;
863 yystack
->yynextFree
= yynewStack
.yynextFree
+ yysize
;
864 yystack
->yyspaceLeft
= yynewStack
.yyspaceLeft
- yysize
;
868 yyFail (yystack
, "parsing stack overflow (%d items)", yysize
);
874 yyfreeGLRStack (yyGLRStack
* yystack
)
876 free (yystack
->yyitems
);
877 yyfreeStateSet (&yystack
->yytops
);
880 /** Assuming that S is a GLRState somewhere on STACK, update the
881 * splitpoint of STACK, if needed, so that it is at least as deep as
884 yyupdateSplit (yyGLRStack
* yystack
, yyGLRState
* yys
)
886 if (yystack
->yysplitPoint
!= NULL
&& yystack
->yysplitPoint
> yys
)
887 yystack
->yysplitPoint
= yys
;
890 /** Invalidate stack #K in STACK. */
892 yymarkStackDeleted (yyGLRStack
* yystack
, int yyk
)
894 if (yystack
->yytops
.yystates
[yyk
] != NULL
)
895 yystack
->yylastDeleted
= yystack
->yytops
.yystates
[yyk
];
896 yystack
->yytops
.yystates
[yyk
] = NULL
;
899 /** Undelete the last stack that was marked as deleted. Can only be
900 done once after a deletion, and only when all other stacks have
903 yyundeleteLastStack (yyGLRStack
* yystack
)
905 if (yystack
->yylastDeleted
== NULL
|| yystack
->yytops
.yysize
!= 0)
907 yystack
->yytops
.yystates
[0] = yystack
->yylastDeleted
;
908 yystack
->yytops
.yysize
= 1;
909 YYDPRINTF ((stderr
, "Restoring last deleted stack as stack #0.\n"));
910 yystack
->yylastDeleted
= NULL
;
914 yyremoveDeletes (yyGLRStack
* yystack
)
918 while (yyj
< yystack
->yytops
.yysize
)
920 if (yystack
->yytops
.yystates
[yyi
] == NULL
)
923 YYDPRINTF ((stderr
, "Removing dead stacks.\n"));
924 yystack
->yytops
.yysize
-= 1;
928 yystack
->yytops
.yystates
[yyj
] = yystack
->yytops
.yystates
[yyi
];
930 YYDPRINTF ((stderr
, "Rename stack %d -> %d.\n", yyi
, yyj
));
937 /** Shift to a new state on stack #K of STACK, corresponding to LR state
938 * LRSTATE, at input position POSN, with (resolved) semantic value SVAL. */
940 yyglrShift (yyGLRStack
* yystack
, int yyk
, yyStateNum yylrState
, size_t yyposn
,
941 YYSTYPE yysval
, YYLTYPE
* yylocp
)
943 yyGLRStackItem
* yynewItem
;
945 yynewItem
= yystack
->yynextFree
;
946 yystack
->yynextFree
+= 1;
947 yystack
->yyspaceLeft
-= 1;
948 yynewItem
->yystate
.yyisState
= yytrue
;
949 yynewItem
->yystate
.yylrState
= yylrState
;
950 yynewItem
->yystate
.yyposn
= yyposn
;
951 yynewItem
->yystate
.yyresolved
= yytrue
;
952 yynewItem
->yystate
.yypred
= yystack
->yytops
.yystates
[yyk
];
953 yystack
->yytops
.yystates
[yyk
] = &yynewItem
->yystate
;
954 yynewItem
->yystate
.yysemantics
.yysval
= yysval
;
955 yynewItem
->yystate
.yyloc
= *yylocp
;
956 if (yystack
->yyspaceLeft
< YYHEADROOM
)
957 yyexpandGLRStack (yystack
);
960 /** Shift to a new state on stack #K of STACK, to a new state
961 * corresponding to LR state LRSTATE, at input position POSN, with
962 * the (unresolved) semantic value of RHS under the action for RULE. */
964 yyglrShiftDefer (yyGLRStack
* yystack
, int yyk
, yyStateNum yylrState
,
965 size_t yyposn
, yyGLRState
* yyrhs
, yyRuleNum yyrule
)
967 yyGLRStackItem
* yynewItem
;
969 yynewItem
= yystack
->yynextFree
;
970 yynewItem
->yystate
.yyisState
= yytrue
;
971 yynewItem
->yystate
.yylrState
= yylrState
;
972 yynewItem
->yystate
.yyposn
= yyposn
;
973 yynewItem
->yystate
.yyresolved
= yyfalse
;
974 yynewItem
->yystate
.yypred
= yystack
->yytops
.yystates
[yyk
];
975 yynewItem
->yystate
.yysemantics
.yyfirstVal
= NULL
;
976 yystack
->yytops
.yystates
[yyk
] = &yynewItem
->yystate
;
977 yystack
->yynextFree
+= 1;
978 yystack
->yyspaceLeft
-= 1;
979 yyaddDeferredAction (yystack
, &yynewItem
->yystate
, yyrhs
, yyrule
);
982 /** Pop the symbols consumed by reduction #RULE from the top of stack
983 * #K of STACK, and perform the appropriate semantic action on their
984 * semantic values. Assumes that all ambiguities in semantic values
985 * have been previously resolved. Set *VALP to the resulting value,
986 * and *LOCP to the computed location (if any). Return value is as
989 yydoAction (yyGLRStack
* yystack
, int yyk
, yyRuleNum yyrule
,
990 YYSTYPE
* yyvalp
, YYLTYPE
* yylocp
)
992 int yynrhs
= yyrhsLength (yyrule
);
994 if (yystack
->yysplitPoint
== NULL
)
996 /* Standard special case: single stack. */
997 yyGLRStackItem
* yyrhs
= (yyGLRStackItem
*) yystack
->yytops
.yystates
[yyk
];
999 yystack
->yynextFree
-= yynrhs
;
1000 yystack
->yyspaceLeft
+= yynrhs
;
1001 yystack
->yytops
.yystates
[0] = & yystack
->yynextFree
[-1].yystate
;
1004 *yyvalp
= yyval_default
;
1005 *yylocp
= yyloc_default
;
1009 *yyvalp
= yyrhs
[1-yynrhs
].yystate
.yysemantics
.yysval
;
1010 *yylocp
= yyrhs
[1-yynrhs
].yystate
.yyloc
;
1012 return yyuserAction (yyrule
, yynrhs
, yyrhs
, yyvalp
, yylocp
, yystack
);
1018 yyGLRStackItem yyrhsVals
[YYMAXRHS
];
1019 for (yyi
= yynrhs
-1, yys
= yystack
->yytops
.yystates
[yyk
]; yyi
>= 0;
1020 yyi
-= 1, yys
= yys
->yypred
)
1022 assert (yys
->yypred
!= NULL
);
1023 yyrhsVals
[yyi
].yystate
.yyresolved
= yytrue
;
1024 yyrhsVals
[yyi
].yystate
.yysemantics
.yysval
= yys
->yysemantics
.yysval
;
1025 yyrhsVals
[yyi
].yystate
.yyloc
= yys
->yyloc
;
1027 yyupdateSplit (yystack
, yys
);
1028 yystack
->yytops
.yystates
[yyk
] = yys
;
1031 *yyvalp
= yyval_default
;
1032 *yylocp
= yyloc_default
;
1036 *yyvalp
= yyrhsVals
[0].yystate
.yysemantics
.yysval
;
1037 *yylocp
= yyrhsVals
[0].yystate
.yyloc
;
1039 return yyuserAction (yyrule
, yynrhs
, yyrhsVals
+ (yynrhs
-1),
1040 yyvalp
, yylocp
, yystack
);
1044 /** Pop items off stack #K of STACK according to grammar rule RULE,
1045 * and push back on the resulting nonterminal symbol. Perform the
1046 * semantic action associated with RULE and store its value with the
1047 * newly pushed state, if FORCEEVAL or if STACK is currently
1048 * unambiguous. Otherwise, store the deferred semantic action with
1049 * the new state. If the new state would have an identical input
1050 * position, LR state, and predecessor to an existing state on the stack,
1051 * it is identified with that existing state, eliminating stack #K from
1052 * the STACK. In this case, the (necessarily deferred) semantic value is
1053 * added to the options for the existing state's semantic value.
1055 static inline YYRESULTTAG
1056 yyglrReduce (yyGLRStack
* yystack
, size_t yyk
, yyRuleNum yyrule
,
1059 size_t yyposn
= yystack
->yytops
.yystates
[yyk
]->yyposn
;
1061 if (yyforceEval
|| yystack
->yysplitPoint
== NULL
)
1066 YYCHK (yydoAction (yystack
, yyk
, yyrule
, &yysval
, &yyloc
));
1067 yyglrShift (yystack
, yyk
,
1068 yyLRgotoState (yystack
->yytops
.yystates
[yyk
]->yylrState
,
1069 yylhsNonterm (yyrule
)),
1070 yyposn
, yysval
, &yyloc
);
1071 YYDPRINTF ((stderr
, "Reduced stack %d by rule #%d. Now in state %d.\n",
1072 yyk
, yyrule
-1, yystack
->yytops
.yystates
[yyk
]->yylrState
));
1078 yyGLRState
* yys
, *yys0
= yystack
->yytops
.yystates
[yyk
];
1079 yyStateNum yynewLRState
;
1081 for (yys
= yystack
->yytops
.yystates
[yyk
], yyn
= yyrhsLength (yyrule
);
1085 assert (yys
!= NULL
);
1087 yyupdateSplit (yystack
, yys
);
1088 yynewLRState
= yyLRgotoState (yys
->yylrState
, yylhsNonterm (yyrule
));
1090 "Reduced stack %d by rule #%d; action deferred. "
1091 "Now in state %d.\n",
1092 yyk
, yyrule
-1, yynewLRState
));
1093 for (yyi
= 0; yyi
< yystack
->yytops
.yysize
; yyi
+= 1)
1094 if (yyi
!= yyk
&& yystack
->yytops
.yystates
[yyi
] != NULL
)
1096 yyGLRState
* yyp
, *yysplit
= yystack
->yysplitPoint
;
1097 yyp
= yystack
->yytops
.yystates
[yyi
];
1098 while (yyp
!= yys
&& yyp
!= yysplit
&& yyp
->yyposn
>= yyposn
)
1100 if (yyp
->yylrState
== yynewLRState
&& yyp
->yypred
== yys
)
1102 yyaddDeferredAction (yystack
, yyp
, yys0
, yyrule
);
1103 yymarkStackDeleted (yystack
, yyk
);
1104 YYDPRINTF ((stderr
, "Merging stack %d into stack %d.\n",
1111 yystack
->yytops
.yystates
[yyk
] = yys
;
1112 yyglrShiftDefer (yystack
, yyk
, yynewLRState
, yyposn
, yys0
, yyrule
);
1118 yysplitStack (yyGLRStack
* yystack
, int yyk
)
1120 if (yystack
->yysplitPoint
== NULL
)
1123 yystack
->yysplitPoint
= yystack
->yytops
.yystates
[yyk
];
1125 if (yystack
->yytops
.yysize
>= yystack
->yytops
.yycapacity
)
1127 yystack
->yytops
.yycapacity
*= 2;
1128 yystack
->yytops
.yystates
=
1129 (yyGLRState
**) realloc (yystack
->yytops
.yystates
,
1130 yystack
->yytops
.yycapacity
1131 * sizeof (yyGLRState
*));
1133 yystack
->yytops
.yystates
[yystack
->yytops
.yysize
]
1134 = yystack
->yytops
.yystates
[yyk
];
1135 yystack
->yytops
.yysize
+= 1;
1136 return yystack
->yytops
.yysize
-1;
1139 /** True iff Y0 and Y1 represent identical options at the top level.
1140 * That is, they represent the same rule applied to RHS symbols
1141 * that produce the same terminal symbols. */
1143 yyidenticalOptions (yySemanticOption
* yyy0
, yySemanticOption
* yyy1
)
1145 if (yyy0
->yyrule
== yyy1
->yyrule
)
1147 yyGLRState
*yys0
, *yys1
;
1149 for (yys0
= yyy0
->yystate
, yys1
= yyy1
->yystate
,
1150 yyn
= yyrhsLength (yyy0
->yyrule
);
1152 yys0
= yys0
->yypred
, yys1
= yys1
->yypred
, yyn
-= 1)
1153 if (yys0
->yyposn
!= yys1
->yyposn
)
1161 /** Assuming identicalOptions (Y0,Y1), (destructively) merge the
1162 * alternative semantic values for the RHS-symbols of Y1 into the
1163 * corresponding semantic value sets of the symbols of Y0. */
1165 yymergeOptionSets (yySemanticOption
* yyy0
, yySemanticOption
* yyy1
)
1167 yyGLRState
*yys0
, *yys1
;
1169 for (yys0
= yyy0
->yystate
, yys1
= yyy1
->yystate
,
1170 yyn
= yyrhsLength (yyy0
->yyrule
);
1172 yys0
= yys0
->yypred
, yys1
= yys1
->yypred
, yyn
-= 1)
1175 else if (! yys0
->yyresolved
&& ! yys1
->yyresolved
)
1177 yySemanticOption
* yyz
;
1178 for (yyz
= yys0
->yysemantics
.yyfirstVal
; yyz
->yynext
!= NULL
;
1181 yyz
->yynext
= yys1
->yysemantics
.yyfirstVal
;
1185 /** Y0 and Y1 represent two possible actions to take in a given
1186 * parsing state; return 0 if no combination is possible,
1187 * 1 if user-mergeable, 2 if Y0 is preferred, 3 if Y1 is preferred. */
1189 yypreference (yySemanticOption
* y0
, yySemanticOption
* y1
)
1191 yyRuleNum r0
= y0
->yyrule
, r1
= y1
->yyrule
;
1192 int p0
= yydprec
[r0
], p1
= yydprec
[r1
];
1196 if (yymerger
[r0
] == 0 || yymerger
[r0
] != yymerger
[r1
])
1201 if (p0
== 0 || p1
== 0)
1210 static YYRESULTTAG
yyresolveValue (yySemanticOption
* yyoptionList
,
1211 yyGLRStack
* yystack
, YYSTYPE
* yyvalp
,
1215 yyresolveStates (yyGLRState
* yys
, int yyn
, yyGLRStack
* yystack
)
1220 assert (yys
->yypred
!= NULL
);
1221 yyflag
= yyresolveStates (yys
->yypred
, yyn
-1, yystack
);
1224 if (! yys
->yyresolved
)
1226 yyflag
= yyresolveValue (yys
->yysemantics
.yyfirstVal
, yystack
,
1227 &yys
->yysemantics
.yysval
, &yys
->yyloc
);
1230 yys
->yyresolved
= yytrue
;
1237 yyresolveAction (yySemanticOption
* yyopt
, yyGLRStack
* yystack
,
1238 YYSTYPE
* yyvalp
, YYLTYPE
* yylocp
)
1240 yyGLRStackItem yyrhsVals
[YYMAXRHS
];
1244 yynrhs
= yyrhsLength (yyopt
->yyrule
);
1245 YYCHK (yyresolveStates (yyopt
->yystate
, yynrhs
, yystack
));
1246 for (yyi
= yynrhs
-1, yys
= yyopt
->yystate
; yyi
>= 0;
1247 yyi
-= 1, yys
= yys
->yypred
)
1249 assert (yys
->yypred
!= NULL
);
1250 yyrhsVals
[yyi
].yystate
.yyresolved
= yytrue
;
1251 yyrhsVals
[yyi
].yystate
.yysemantics
.yysval
= yys
->yysemantics
.yysval
;
1252 yyrhsVals
[yyi
].yystate
.yyloc
= yys
->yyloc
;
1254 return yyuserAction (yyopt
->yyrule
, yynrhs
, yyrhsVals
+ (yynrhs
-1),
1255 yyvalp
, yylocp
, yystack
);
1259 static yyGLRState YYLEFTMOST_STATE
= { 0, NULL
, -1, 0, { NULL
} };
1261 static void yyreportTree (yySemanticOption
* yyx
, int yyindent
)
1263 int yynrhs
= yyrhsLength (yyx
->yyrule
);
1266 yyGLRState
* yystates
[YYMAXRHS
];
1268 for (yyi
= yynrhs
, yys
= yyx
->yystate
; yyi
> 0; yyi
-= 1, yys
= yys
->yypred
)
1269 yystates
[yyi
] = yys
;
1271 yystates
[0] = &YYLEFTMOST_STATE
;
1275 if (yys
->yyposn
+1 > yyx
->yystate
->yyposn
)
1276 YYFPRINTF (stderr
, "%*s%s -> <Rule %d, empty>\n",
1277 yyindent
, "", yytokenName (yylhsNonterm (yyx
->yyrule
)),
1280 YYFPRINTF (stderr
, "%*s%s -> <Rule %d, tokens %d .. %d>\n",
1281 yyindent
, "", yytokenName (yylhsNonterm (yyx
->yyrule
)),
1282 yyx
->yyrule
, yys
->yyposn
+1, yyx
->yystate
->yyposn
);
1283 for (yyi
= 1; yyi
<= yynrhs
; yyi
+= 1)
1285 if (yystates
[yyi
]->yyresolved
)
1287 if (yystates
[yyi
-1]->yyposn
+1 > yystates
[yyi
]->yyposn
)
1288 YYFPRINTF (stderr
, "%*s%s <empty>\n", yyindent
+2, "",
1289 yytokenName (yyrhs
[yyprhs
[yyx
->yyrule
]+yyi
-1]));
1291 YYFPRINTF (stderr
, "%*s%s <tokens %d .. %d>\n", yyindent
+2, "",
1292 yytokenName (yyrhs
[yyprhs
[yyx
->yyrule
]+yyi
-1]),
1293 yystates
[yyi
-1]->yyposn
+1, yystates
[yyi
]->yyposn
);
1296 yyreportTree (yystates
[yyi
]->yysemantics
.yyfirstVal
, yyindent
+2);
1302 yyreportAmbiguity (yySemanticOption
* yyx0
, yySemanticOption
* yyx1
,
1303 yyGLRStack
* yystack
)
1305 /* `Unused' warnings. */
1310 YYFPRINTF (stderr
, "Ambiguity detected.\n");
1311 YYFPRINTF (stderr
, "Option 1,\n");
1312 yyreportTree (yyx0
, 2);
1313 YYFPRINTF (stderr
, "\nOption 2,\n");
1314 yyreportTree (yyx1
, 2);
1315 YYFPRINTF (stderr
, "\n");
1317 yyFail (yystack
, "ambiguity detected");
1321 /** Resolve the ambiguity represented by OPTIONLIST, perform the indicated
1322 * actions, and return the result. */
1324 yyresolveValue (yySemanticOption
* yyoptionList
, yyGLRStack
* yystack
,
1325 YYSTYPE
* yyvalp
, YYLTYPE
* yylocp
)
1327 yySemanticOption
* yybest
;
1328 yySemanticOption
* yyp
;
1331 yybest
= yyoptionList
;
1333 for (yyp
= yyoptionList
->yynext
; yyp
!= NULL
; yyp
= yyp
->yynext
)
1335 if (yyidenticalOptions (yybest
, yyp
))
1336 yymergeOptionSets (yybest
, yyp
);
1338 switch (yypreference (yybest
, yyp
))
1341 yyreportAmbiguity (yybest
, yyp
, yystack
);
1357 int yyprec
= yydprec
[yybest
->yyrule
];
1358 YYCHK (yyresolveAction (yybest
, yystack
, yyvalp
, yylocp
));
1359 for (yyp
= yybest
->yynext
; yyp
!= NULL
; yyp
= yyp
->yynext
)
1361 if (yyprec
== yydprec
[yyp
->yyrule
])
1365 YYCHK (yyresolveAction (yyp
, yystack
, &yyval1
, &yydummy
));
1366 *yyvalp
= yyuserMerge (yymerger
[yyp
->yyrule
], yyvalp
, &yyval1
);
1372 return yyresolveAction (yybest
, yystack
, yyvalp
, yylocp
);
1376 yyresolveStack (yyGLRStack
* yystack
)
1378 if (yystack
->yysplitPoint
!= NULL
)
1383 for (yyn
= 0, yys
= yystack
->yytops
.yystates
[0];
1384 yys
!= yystack
->yysplitPoint
;
1385 yys
= yys
->yypred
, yyn
+= 1)
1387 YYCHK (yyresolveStates (yystack
->yytops
.yystates
[0], yyn
, yystack
));
1393 yycompressStack (yyGLRStack
* yystack
)
1395 yyGLRState
* yyp
, *yyq
, *yyr
;
1397 if (yystack
->yytops
.yysize
!= 1 || yystack
->yysplitPoint
== NULL
)
1400 for (yyp
= yystack
->yytops
.yystates
[0], yyq
= yyp
->yypred
, yyr
= NULL
;
1401 yyp
!= yystack
->yysplitPoint
;
1402 yyr
= yyp
, yyp
= yyq
, yyq
= yyp
->yypred
)
1405 yystack
->yyspaceLeft
+= yystack
->yynextFree
- yystack
->yyitems
;
1406 yystack
->yynextFree
= ((yyGLRStackItem
*) yystack
->yysplitPoint
) + 1;
1407 yystack
->yyspaceLeft
-= yystack
->yynextFree
- yystack
->yyitems
;
1408 yystack
->yysplitPoint
= NULL
;
1409 yystack
->yylastDeleted
= NULL
;
1413 yystack
->yynextFree
->yystate
= *yyr
;
1415 yystack
->yynextFree
->yystate
.yypred
= & yystack
->yynextFree
[-1].yystate
;
1416 yystack
->yytops
.yystates
[0] = &yystack
->yynextFree
->yystate
;
1417 yystack
->yynextFree
+= 1;
1418 yystack
->yyspaceLeft
-= 1;
1423 yyprocessOneStack (yyGLRStack
* yystack
, int yyk
,
1424 size_t yyposn
, YYSTYPE
* yylvalp
, YYLTYPE
* yyllocp
)
1427 const short* yyconflicts
;
1429 yySymbol
* const yytokenp
= yystack
->yytokenp
;
1431 while (yystack
->yytops
.yystates
[yyk
] != NULL
)
1433 yyStateNum yystate
= yystack
->yytops
.yystates
[yyk
]->yylrState
;
1435 assert (yystate
!= YYFINAL
);
1436 if (yyisDefaultedState (yystate
))
1438 yyrule
= yydefaultAction (yystate
);
1441 YYDPRINTF ((stderr
, "Stack %d dies.\n", yyk
));
1442 yymarkStackDeleted (yystack
, yyk
);
1445 YYCHK (yyglrReduce (yystack
, yyk
, yyrule
, yyfalse
));
1449 if (*yytokenp
== YYEMPTY
)
1452 *yytokenp
= YYTRANSLATE(yychar
);
1453 YYDPRINTF ((stderr
, "Read token %s\n", yytokenName (*yytokenp
)));
1455 yygetLRActions (yystate
, *yytokenp
, &yyaction
, &yyconflicts
);
1457 while (*yyconflicts
!= 0)
1459 int yynewStack
= yysplitStack (yystack
, yyk
);
1460 YYDPRINTF ((stderr
, "Splitting off stack %d from %d.\n",
1462 YYCHK (yyglrReduce (yystack
, yynewStack
, *yyconflicts
, yyfalse
));
1463 YYCHK (yyprocessOneStack (yystack
, yynewStack
, yyposn
,
1468 if (yyisShiftAction (yyaction
))
1470 YYDPRINTF ((stderr
, "Shifted token %s on stack %d, ",
1471 yytokenName (*yytokenp
), yyk
));
1472 yyglrShift (yystack
, yyk
, yyaction
, yyposn
+1, *yylvalp
, yyllocp
);
1473 YYDPRINTF ((stderr
, "which is now in state #%d\n",
1474 yystack
->yytops
.yystates
[yyk
]->yylrState
));
1477 else if (yyisErrorAction (yyaction
))
1479 YYDPRINTF ((stderr
, "Stack %d dies.\n", yyk
));
1480 yymarkStackDeleted (yystack
, yyk
);
1484 YYCHK (yyglrReduce (yystack
, yyk
, -yyaction
, yyfalse
));
1491 yyreportParseError (yyGLRStack
* yystack
, YYSTYPE
* yylvalp
, YYLTYPE
* yyllocp
)
1493 /* `Unused' warnings. */
1497 if (yystack
->yyerrState
== 0)
1500 yySymbol
* const yytokenp
= yystack
->yytokenp
;
1501 int yyn
, yyx
, yycount
;
1503 const char* yyprefix
;
1506 yyn
= yypact
[yystack
->yytops
.yystates
[0]->yylrState
];
1507 if (YYPACT_NINF
< yyn
&& yyn
< YYLAST
)
1510 /* Start YYX at -YYN if negative to avoid negative indexes in
1512 yysize
= sizeof ("parse error, unexpected ")
1513 + strlen (yytokenName (*yytokenp
));
1514 yyprefix
= ", expecting ";
1515 for (yyx
= yyn
< 0 ? -yyn
: 0; yyx
< yytname_size
&& yycount
<= 5;
1517 if (yycheck
[yyx
+ yyn
] == yyx
&& yyx
!= YYTERROR
)
1518 yysize
+= strlen (yytokenName (yyx
)) + strlen (yyprefix
),
1519 yycount
+= 1, yyprefix
= " or ";
1520 yymsg
= yyp
= (char*) malloc (yysize
);
1521 yyp
+= sprintf (yyp
, "parse error, unexpected %s",
1522 yytokenName (*yytokenp
));
1525 yyprefix
= ", expecting ";
1526 for (yyx
= yyn
< 0 ? -yyn
: 0; yyx
< yytname_size
; yyx
+= 1)
1527 if (yycheck
[yyx
+ yyn
] == yyx
)
1529 yyp
+= sprintf (yyp
, "%s%s", yyprefix
, yytokenName (yyx
));
1538 yyerror ("parse error");
1543 /* Recover from a syntax error on STACK, assuming that TOKENP,
1544 YYLVALP, and YYLLOCP point to the syntactic category, semantic
1545 value, and location of the lookahead.
1546 NOTE: This uses the panic-mode recovery algorithm described in the
1547 Bison documentation, which differs from what is in bison.simple.
1548 Specifically, this routine performs no reductions before shifting
1551 yyrecoverParseError (yyGLRStack
* yystack
, YYSTYPE
* yylvalp
, YYLTYPE
* yyllocp
)
1553 yySymbol
* const yytokenp
= yystack
->yytokenp
;
1557 if (yystack
->yyerrState
== 0)
1558 yystack
->yyerrState
= 3;
1559 else if (yystack
->yyerrState
== 3)
1561 /* We just shifted the error token and (perhaps) took some
1562 reductions. Skip tokens until we can proceed. */
1564 if (*yytokenp
== YYEOF
)
1565 yyFail (yystack
, NULL
);
1566 if (*yytokenp
!= YYEMPTY
)
1567 YYDPRINTF ((stderr
, "Discarding token %s\n",
1568 yytokenName (*yytokenp
)));
1570 *yytokenp
= YYTRANSLATE (yychar
);
1571 YYDPRINTF ((stderr
, "Read token %s\n", yytokenName (*yytokenp
)));
1572 yyj
= yypact
[yystack
->yytops
.yystates
[0]->yylrState
];
1573 if (yyj
== YYPACT_NINF
)
1574 /* Something's not right; we shouldn't be here */
1575 yyFail (yystack
, NULL
);
1577 if (yyj
< 0 || yyj
> YYLAST
|| yycheck
[yyj
] != *yytokenp
)
1579 if (yydefact
[yystack
->yytops
.yystates
[0]->yylrState
] != 0)
1582 else if (yytable
[yyj
] != 0 && yytable
[yyj
] != YYTABLE_NINF
)
1587 /* Reduce to one stack */
1588 for (yyk
= 0; yyk
< yystack
->yytops
.yysize
; yyk
+= 1)
1589 if (yystack
->yytops
.yystates
[yyk
] != NULL
)
1591 if (yyk
>= yystack
->yytops
.yysize
)
1592 yyFail (yystack
, NULL
);
1593 for (yyk
+= 1; yyk
< yystack
->yytops
.yysize
; yyk
+= 1)
1594 yymarkStackDeleted (yystack
, yyk
);
1595 yyremoveDeletes (yystack
);
1596 yycompressStack (yystack
);
1598 /* Now pop stack until we find a state that shifts the error token. */
1599 while (yystack
->yytops
.yystates
[0] != NULL
)
1601 yyj
= yypact
[yystack
->yytops
.yystates
[0]->yylrState
] + YYTERROR
;
1602 if (yyj
!= YYPACT_NINF
+ YYTERROR
&& yyj
>= 0 && yyj
<= YYLAST
&&
1603 yycheck
[yyj
] == YYTERROR
&& yyisShiftAction (yytable
[yyj
]))
1605 yyglrShift (yystack
, 0, yytable
[yyj
],
1606 yystack
->yytops
.yystates
[0]->yyposn
, *yylvalp
, yyllocp
);
1609 yystack
->yytops
.yystates
[0] = yystack
->yytops
.yystates
[0]->yypred
;
1610 yystack
->yynextFree
-= 1;
1611 yystack
->yyspaceLeft
+= 1;
1613 if (yystack
->yytops
.yystates
[0] == NULL
)
1614 yyFail (yystack
, NULL
);
1617 #define YYCHK1(YYE) \
1623 yystack.yyerrflag = 1; \
1626 yystack.yyerrflag = 0; \
1629 goto yyuser_error; \
1634 yyparse (YYPARSE_PARAM_ARG
)
1644 #define yychar (yystack.yyrawchar)
1647 YYSTYPE
* const yylvalp
= &yylval
;
1648 YYLTYPE
* const yyllocp
= &yylloc
;
1650 yyinitGLRStack (&yystack
, YYINITDEPTH
);
1651 yystack
.yytokenp
= &yytoken
;
1653 if (setjmp (yystack
.yyexception_buffer
) != 0)
1656 yyglrShift (&yystack
, 0, 0, 0, yyval_default
, &yyloc_default
);
1662 /* For efficiency, we have two loops, of which the first of which
1663 * is specialized to deterministic operation (single stack, no
1664 * potential ambiguity). */
1671 const short* yyconflicts
;
1673 yyStateNum yystate
= yystack
.yytops
.yystates
[0]->yylrState
;
1674 if (yystate
== YYFINAL
)
1676 if (yyisDefaultedState (yystate
))
1678 yyrule
= yydefaultAction (yystate
);
1681 yyreportParseError (&yystack
, yylvalp
, yyllocp
);
1684 YYCHK1 (yyglrReduce (&yystack
, 0, yyrule
, yytrue
));
1688 if (yytoken
== YYEMPTY
)
1691 yytoken
= YYTRANSLATE (yychar
);
1692 YYDPRINTF ((stderr
, "Read token %s\n",
1693 yytokenName (yytoken
)));
1695 yygetLRActions (yystate
, yytoken
, &yyaction
, &yyconflicts
);
1696 if (*yyconflicts
!= 0)
1698 if (yyisShiftAction (yyaction
))
1700 YYDPRINTF ((stderr
, "Shifted token %s. ",
1701 yytokenName (yytoken
)));
1702 if (yytoken
!= YYEOF
)
1705 yyglrShift (&yystack
, 0, yyaction
, yyposn
, yylval
, yyllocp
);
1706 if (yystack
.yyerrState
> 0)
1707 yystack
.yyerrState
-= 1;
1708 YYDPRINTF ((stderr
, "Now in state #%d\n",
1709 yystack
.yytops
.yystates
[0]->yylrState
));
1711 else if (yyisErrorAction (yyaction
))
1713 yyreportParseError (&yystack
, yylvalp
, yyllocp
);
1717 YYCHK1 (yyglrReduce (&yystack
, 0, -yyaction
, yytrue
));
1724 int yyn
= yystack
.yytops
.yysize
;
1725 for (yys
= 0; yys
< yyn
; yys
+= 1)
1726 YYCHK1 (yyprocessOneStack (&yystack
, yys
, yyposn
,
1730 yyremoveDeletes (&yystack
);
1731 if (yystack
.yytops
.yysize
== 0)
1733 yyundeleteLastStack (&yystack
);
1734 if (yystack
.yytops
.yysize
== 0)
1735 yyFail (&yystack
, "parse error");
1736 YYCHK1 (yyresolveStack (&yystack
));
1737 YYDPRINTF ((stderr
, "Returning to deterministic operation.\n"));
1738 yyreportParseError (&yystack
, yylvalp
, yyllocp
);
1741 else if (yystack
.yytops
.yysize
== 1)
1743 YYCHK1 (yyresolveStack (&yystack
));
1744 YYDPRINTF ((stderr
, "Returning to deterministic operation.\n"));
1745 yycompressStack (&yystack
);
1751 yyrecoverParseError (&yystack
, yylvalp
, yyllocp
);
1752 yyposn
= yystack
.yytops
.yystates
[0]->yyposn
;
1757 yyfreeGLRStack (&yystack
);
1758 return yystack
.yyerrflag
;
1761 /* DEBUGGING ONLY */
1762 static void yypstack (yyGLRStack
* yystack
, int yyk
) ATTRIBUTE_UNUSED
;
1763 static void yypdumpstack (yyGLRStack
* yystack
) ATTRIBUTE_UNUSED
;
1766 yy_yypstack (yyGLRState
* yys
)
1770 yy_yypstack (yys
->yypred
);
1771 fprintf (stderr
, " -> ");
1773 fprintf (stderr
, "%d@%lu", yys
->yylrState
, (unsigned long) yys
->yyposn
);
1777 yypstates (yyGLRState
* yyst
)
1780 fprintf (stderr
, "<null>");
1783 fprintf (stderr
, "\n");
1787 yypstack (yyGLRStack
* yystack
, int yyk
)
1789 yypstates (yystack
->yytops
.yystates
[yyk
]);
1792 #define YYINDEX(YYX) \
1793 ((YYX) == NULL ? -1 : (yyGLRStackItem*) (YYX) - yystack->yyitems)
1797 yypdumpstack (yyGLRStack
* yystack
)
1799 yyGLRStackItem
* yyp
;
1801 for (yyp
= yystack
->yyitems
; yyp
< yystack
->yynextFree
; yyp
+= 1)
1803 fprintf (stderr
, "%3lu. ", (unsigned long) (yyp
- yystack
->yyitems
));
1806 fprintf (stderr
, "Res: %d, LR State: %d, posn: %lu, pred: %ld",
1807 yyp
->yystate
.yyresolved
, yyp
->yystate
.yylrState
,
1808 (unsigned long) yyp
->yystate
.yyposn
,
1809 (long) YYINDEX (yyp
->yystate
.yypred
));
1810 if (! yyp
->yystate
.yyresolved
)
1811 fprintf (stderr
, ", firstVal: %ld",
1812 (long) YYINDEX (yyp
->yystate
.yysemantics
.yyfirstVal
));
1816 fprintf (stderr
, "Option. rule: %d, state: %ld, next: %ld",
1817 yyp
->yyoption
.yyrule
,
1818 (long) YYINDEX (yyp
->yyoption
.yystate
),
1819 (long) YYINDEX (yyp
->yyoption
.yynext
));
1821 fprintf (stderr
, "\n");
1823 fprintf (stderr
, "Tops:");
1824 for (yyi
= 0; yyi
< yystack
->yytops
.yysize
; yyi
+= 1)
1825 fprintf (stderr
, "%lu: %ld; ", (unsigned long) yyi
,
1826 (long) YYINDEX (yystack
->yytops
.yystates
[yyi
]));
1827 fprintf (stderr
, "\n");
1833 m4_if(b4_defines_flag
, 0, [],
1834 [#output "b4_output_header_name"
1835 b4_copyright([Skeleton parser
for GLR parsing with Bison
], [2002])
1836 #ifndef b4_header_guard
1837 # define b4_header_guard
1839 b4_token_defines(b4_tokens
)
1842 m4_ifdef([b4_stype
],
1843 [#line b4_stype_line "b4_filename"
1844 typedef union b4_stype yystype
;
1845 /* Line __line__ of __file__. */
1846 #line __oline__ "__ofile__"],
1847 [typedef int yystype
;])
1848 # define YYSTYPE yystype
1852 [extern YYSTYPE b4_prefix
[]lval
;])
1856 typedef struct yyltype
1863 # define YYLTYPE yyltype
1867 [extern YYLTYPE b4_prefix
[]lloc
;])
1869 #endif /* not b4_header_guard */