1 m4_divert(-1) -*- C
-*-
4 # GLR skeleton for Bison
5 # Copyright (C) 2002 Free Software Foundation, Inc.
7 # This program is free software; you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; either version 2 of the License, or
10 # (at your option) any later version.
12 # This program is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
17 # You should have received a copy of the GNU General Public License
18 # along with this program; if not, write to the Free Software
19 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
22 # b4_lhs_value([TYPE])
23 # --------------------
24 # Expansion of $<TYPE>$.
25 m4_define([b4_lhs_value
],
26 [(*yyvalp
)[]m4_ifval([$
1], [.$
1])])
29 # b4_rhs_value(RULE-LENGTH, NUM, [TYPE])
30 # --------------------------------------
31 # Expansion of $<TYPE>NUM, where the current rule has RULE-LENGTH
33 m4_define([b4_rhs_value
],
34 [yyvsp@
<:@
m4_eval([$
2 - $
1])@
:>@
.yystate
.yysemantics
.yysval
[]m4_ifval([$
3], [.$
3])])
42 # b4_location_if(IF-TRUE, IF-FALSE)
43 # ---------------------------------
44 # Expand IF-TRUE, if locations are used, IF-FALSE otherwise.
45 m4_define([b4_location_if
],
46 [m4_if(b4_locations_flag
, [1],
54 m4_define([b4_lhs_location
],
58 # b4_rhs_location(RULE-LENGTH, NUM)
59 # ---------------------------------
60 # Expansion of @NUM, where the current rule has RULE-LENGTH symbols
62 m4_define([b4_rhs_location
],
63 [yyvsp@
<:@
m4_eval([$
2 - $
1])@
:>@
.yystate
.yyloc
])
71 # b4_pure_if(IF-TRUE, IF-FALSE)
72 # -----------------------------
73 # Expand IF-TRUE, if %pure-parser, IF-FALSE otherwise.
74 m4_define([b4_pure_if
],
80 ## ------------------- ##
81 ## Output file names. ##
82 ## ------------------- ##
84 m4_define_default([b4_input_suffix
], [.y
])
86 m4_define_default([b4_output_parser_suffix
],
87 [m4_translit(b4_input_suffix
, [yY
], [cC
])])
89 m4_define_default([b4_output_parser_name
],
90 [b4_output_prefix
[]b4_output_infix
[]b4_output_parser_suffix
[]])
93 m4_define_default([b4_output_header_suffix
],
94 [m4_translit(b4_input_suffix
, [yY
], [hH
])])
96 m4_define_default([b4_output_header_name
],
97 [b4_output_prefix
[]b4_output_infix
[]b4_output_header_suffix
[]])
99 m4_define_default([b4_header_guard
],
100 [m4_bpatsubst(m4_toupper([BISON_
]b4_output_header_name
),
101 [[^ABCDEFGHIJKLMNOPQRSTUVWXYZ
]], [_
])])
105 #output "b4_output_parser_name"
106 b4_copyright([Skeleton parser
for GLR parsing with Bison
], [2002])
108 /* This is the parser code for GLR (Generalized LR) parser. */
110 /* FIXME: minimize these */
118 /* Identify Bison output. */
122 #define YYPURE ]b4_pure[
124 /* Using locations. */
125 #define YYLSP_NEEDED ]b4_locations_flag[
127 ]m4_if(b4_prefix
[], [yy
], [],
128 [/* If NAME_PREFIX is specified substitute the variables and functions
130 #define yyparse b4_prefix[]parse
131 #define yylex b4_prefix[]lex
132 #define yyerror b4_prefix[]error
133 #define yylval b4_prefix[]lval
134 #define yychar b4_prefix[]char
135 #define yydebug b4_prefix[]debug
136 #define yynerrs b4_prefix[]nerrs
137 b4_location_if([#define yylloc b4_prefix[]lloc])])
139 b4_token_defines(b4_tokens
)
141 /* Copy the first part of user declarations. */
144 /* Enabling traces. */
146 # define YYDEBUG ]b4_debug[
149 /* Enabling verbose error messages. */
150 #ifdef YYERROR_VERBOSE
151 # undef YYERROR_VERBOSE
152 # define YYERROR_VERBOSE 1
154 # define YYERROR_VERBOSE ]b4_error_verbose[
158 ]m4_ifdef([b4_stype
],
159 [#line b4_stype_line "b4_filename"
160 typedef union b4_stype yystype
;
161 /* Line __line__ of __file__. */
162 #line __oline__ "__ofile__"],
163 [typedef int yystype
;])[
164 # define YYSTYPE yystype
165 # define YYSTYPE_IS_TRIVIAL 1
169 typedef struct yyltype
177 # define YYLTYPE ]b4_ltype[
178 # define YYLTYPE_IS_TRIVIAL 1
181 /* Default (constant) values used for initialization for null
182 right-hand sides. Unlike the standard bison.simple template,
183 here we set the default values of the $$ and $@ to zeroed-out
184 values. Since the default value of these quantities is undefined,
185 this behavior is technically correct. */
186 static YYSTYPE yyval_default
;
187 static YYLTYPE yyloc_default
;
189 /* Copy the second part of user declarations. */
192 ]/* Line __line__ of __file__. */
193 #line __oline__ "__ofile__"
195 #if ! defined (__cplusplus)
205 #ifndef __attribute__
206 /* This feature is available in gcc versions 2.5 and later. */
207 # if !defined (__GNUC__) || __GNUC__ < 2 || \
208 (__GNUC__ == 2 && __GNUC_MINOR__ < 5) || __STRICT_ANSI__
209 # define __attribute__(Spec) /* empty */
213 #ifndef ATTRIBUTE_UNUSED
214 # define ATTRIBUTE_UNUSED __attribute__ ((__unused__))
217 #if ! defined (__GNUC__)
221 /* YYFINAL -- State number of the termination state. */
222 #define YYFINAL ]b4_final_state_number[
223 #define 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 If YYTABLE_NINF, parse error. */
338 #define YYTABLE_NINF ]b4_table_ninf[
339 static const ]b4_int_type_for([b4_table
])[ yytable
[] =
344 /* YYCONFLP[YYPACT[STATE-NUM]] -- pointer into yyconfl of start of list
345 of conflicting reductions corresponding to action entry for state
346 STATE-NUM in yytable. 0 means no conflicts. The list in yyconfl
347 is terminated by a rule number of 0. */
348 static const ]b4_int_type_for([b4_conflict_list_heads
])[ yyconflp
[] =
350 ]b4_conflict_list_heads
[
353 /* YYCONFL[I] -- lists of conflicting rule numbers, each terminated
354 by 0, pointed into by YYCONFLP. */
355 ]dnl Do
not use b4_int_type_for here
, since there are places where
356 dnl pointers onto yyconfl are taken
, which type is
"short *".
357 dnl We probably ought to introduce a type
for confl
.
358 [static const short yyconfl
[] =
360 ]b4_conflicting_rules
[
363 static const ]b4_int_type_for([b4_check
])[ yycheck
[] =
369 /* The user can define YYPARSE_PARAM as the name of an argument to be passed
370 into yyparse. The argument should have type void *.
371 It should actually point to an object.
372 Grammar actions can access the variable by casting it
373 to the proper pointer type. */
376 # define YYPARSE_PARAM_ARG void *YYPARSE_PARAM
377 #else /* !YYPARSE_PARAM */
378 # define YYPARSE_PARAM_ARG void
379 #endif /* !YYPARSE_PARAM */
381 /* Prevent warning if -Wstrict-prototypes. */
383 # ifdef YYPARSE_PARAM
384 int yyparse (void *);
390 /* Error token number */
393 /* YYLLOC_DEFAULT -- Compute the default location (before the actions
396 #define YYRHSLOC(yyRhs,YYK) (yyRhs[YYK].yystate.yyloc)
398 #ifndef YYLLOC_DEFAULT
399 # define YYLLOC_DEFAULT(yyCurrent, yyRhs, YYN) \
400 yyCurrent.first_line = YYRHSLOC(yyRhs,1).first_line; \
401 yyCurrent.first_column = YYRHSLOC(yyRhs,1).first_column; \
402 yyCurrent.last_line = YYRHSLOC(yyRhs,YYN).last_line; \
403 yyCurrent.last_column = YYRHSLOC(yyRhs,YYN).last_column;
406 /* YYLEX -- calling `yylex' with the right arguments. */
411 # define YYLEX yylex (yylvalp, b4_location_if([yyllocp, ])YYLEX_PARAM)
413 # define YYLEX yylex (yylvalp[]b4_location_if([, yyllocp]))
415 [#define YYLEX yylex ()])
420 #define yynerrs (yystack->yyerrcnt)
422 #define yychar (yystack->yyrawchar)],
430 static const int YYEOF
= 0;
431 static const int YYEMPTY
= -2;
433 typedef enum { yyok
, yyaccept
, yyabort
, yyerr
} YYRESULTTAG
;
436 do { YYRESULTTAG yyflag = YYE; if (yyflag != yyok) return yyflag; } \
441 #if ! defined (YYFPRINTF)
442 # define YYFPRINTF fprintf
445 # define YYDPRINTF(Args) \
450 /* Nonzero means print parse trace. It is left uninitialized so that
451 multiple parsers can coexist. */
454 /* Avoid empty `if' bodies. */
455 # define YYDPRINTF(Args) {}
456 #endif /* !YYDEBUG */
458 /* YYINITDEPTH -- initial size of the parser's stacks. */
460 # define YYINITDEPTH ]b4_initdepth[
463 /* YYMAXDEPTH -- maximum size the stacks can grow to (effective only
464 if the built-in stack extension method is used).
466 Do not make this value too large; the results are undefined if
467 SIZE_MAX < YYMAXDEPTH * sizeof (GLRStackItem)
468 evaluated with infinite-precision integer arithmetic. */
475 # define YYMAXDEPTH ]b4_maxdepth[
478 /* Minimum number of free items on the stack allowed after an
479 allocation. This is to allow allocation and initialization
480 to be completed by functions that call expandGLRStack before the
481 stack is expanded, thus insuring that all necessary pointers get
482 properly redirected to new data. */
485 #if ! defined (YYSTACKEXPANDABLE) \
486 && (! defined (__cplusplus) || (YYLTYPE_IS_TRIVIAL && YYSTYPE_IS_TRIVIAL))
487 #define YYSTACKEXPANDABLE 1
489 #define YYSTACKEXPANDABLE 0
492 /** State numbers, as in LALR(1) machine */
493 typedef int yyStateNum
;
495 /** Rule numbers, as in LALR(1) machine */
496 typedef int yyRuleNum
;
498 /** Grammar symbol */
499 typedef short yySymbol
;
501 /** Item references, as in LALR(1) machine */
502 typedef short yyItemNum
;
504 typedef struct yyGLRState yyGLRState
;
505 typedef struct yySemanticOption yySemanticOption
;
506 typedef union yyGLRStackItem yyGLRStackItem
;
507 typedef struct yyGLRStack yyGLRStack
;
508 typedef struct yyGLRStateSet yyGLRStateSet
;
513 yyStateNum yylrState
;
517 yySemanticOption
* yyfirstVal
;
523 struct yyGLRStateSet
{
524 yyGLRState
** yystates
;
525 size_t yysize
, yycapacity
;
528 struct yySemanticOption
{
532 yySemanticOption
* yynext
;
535 union yyGLRStackItem
{
537 yySemanticOption yyoption
;
549 jmp_buf yyexception_buffer
;
550 yyGLRStackItem
* yyitems
;
551 yyGLRStackItem
* yynextFree
;
553 yyGLRState
* yysplitPoint
;
554 yyGLRState
* yylastDeleted
;
555 yyGLRStateSet yytops
;
558 static void yyinitGLRStack (yyGLRStack
* yystack
, size_t yysize
);
559 static void yyexpandGLRStack (yyGLRStack
* yystack
);
560 static void yyfreeGLRStack (yyGLRStack
* yystack
);
563 yyFail (yyGLRStack
* yystack
, const char* yyformat
, ...)
565 if (yyformat
!= NULL
)
569 va_start (yyap
, yyformat
);
570 yystack
->yyerrflag
= 1;
571 vsprintf (yymsg
, yyformat
, yyap
);
574 longjmp (yystack
->yyexception_buffer
, 1);
577 #if YYDEBUG || YYERROR_VERBOSE
578 /** A printable representation of TOKEN. Valid until next call to
580 static inline const char*
581 yytokenName (yySymbol yytoken
)
583 return yytname
[yytoken
];
587 /** Perform user action for rule number YYN, with RHS length YYRHSLEN,
588 * and top stack item YYVSP. YYLVALP points to place to put semantic
589 * value ($$), and yylocp points to place for location information
590 * (@$). Returns yyok for normal return, yyaccept for YYACCEPT,
591 * yyerr for YYERROR, yyabort for YYABORT. */
593 yyuserAction (yyRuleNum yyn
, int yyrhslen
, yyGLRStackItem
* yyvsp
,
594 YYSTYPE
* yyvalp
, YYLTYPE
* yylocp
, yyGLRStack
* yystack
)
596 /* Avoid `unused' warnings in there are no $n. */
601 *yyvalp
= yyval_default
;
602 *yylocp
= yyloc_default
;
606 *yyvalp
= yyvsp
[1-yyrhslen
].yystate
.yysemantics
.yysval
;
607 *yylocp
= yyvsp
[1-yyrhslen
].yystate
.yyloc
;
610 # define yyval (*yyvalp)
612 # define yyerrok (yystack->yyerrState = 0)
614 # define YYACCEPT return yyaccept
616 # define YYABORT return yyabort
618 # define YYERROR return yyerr
620 # define YYRECOVERING (yystack->yyerrState != 0)
622 # define yyclearin (yychar = *(yystack->yytokenp) = YYEMPTY)
624 # define YYBACKUP(Token, Value) \
626 yyerror ("syntax error: cannot back up"); \
645 /* Line __line__ of __file__. */
646 #line __oline__ "__ofile__"
651 yyuserMerge (int yyn
, YYSTYPE
* yy0
, YYSTYPE
* yy1
)
653 YYSTYPE yyval
= *yy0
;
654 /* `Use' the arguments. */
665 /* Bison grammar-table manipulation */
667 /** Number of symbols composing the right hand side of rule #RULE. */
669 yyrhsLength (yyRuleNum yyrule
)
674 /** Left-hand-side symbol for rule #RULE. */
675 static inline yySymbol
676 yylhsNonterm (yyRuleNum yyrule
)
681 /** True iff LR state STATE has only a default reduction (regardless
684 yyisDefaultedState (yyStateNum yystate
)
686 return yypact
[yystate
] == YYPACT_NINF
;
689 /** The default reduction for STATE, assuming it has one. */
690 static inline yyRuleNum
691 yydefaultAction (yyStateNum yystate
)
693 return yydefact
[yystate
];
696 /** Set *YYACTION to the action to take in YYSTATE on seeing YYTOKEN.
698 * R < 0: Reduce on rule -R.
700 * R > 0: Shift to state R.
701 * Set *CONFLICTS to a pointer into yyconfl to 0-terminated list of
702 * conflicting reductions.
705 yygetLRActions (yyStateNum yystate
, int yytoken
,
706 int* yyaction
, const short** yyconflicts
)
708 int yyindex
= yypact
[yystate
] + yytoken
;
709 if (yyindex
< 0 || YYLAST
< yyindex
|| yycheck
[yyindex
] != yytoken
)
711 *yyaction
= -yydefact
[yystate
];
712 *yyconflicts
= yyconfl
;
714 else if (yytable
[yyindex
] != YYTABLE_NINF
)
716 *yyaction
= yytable
[yyindex
];
717 *yyconflicts
= yyconfl
+ yyconflp
[yyindex
];
722 *yyconflicts
= yyconfl
+ yyconflp
[yyindex
];
726 static inline yyStateNum
727 yyLRgotoState (yyStateNum yystate
, yySymbol yylhs
)
730 yyr
= yypgoto
[yylhs
- YYNTOKENS
] + yystate
;
731 if (0 <= yyr
&& yyr
<= YYLAST
&& yycheck
[yyr
] == yystate
)
734 return yydefgoto
[yylhs
- YYNTOKENS
];
738 yyisShiftAction (int yyaction
)
744 yyisErrorAction (int yyaction
)
746 return yyaction
== 0;
751 /** True iff the semantic value of the edge leading to STATE is
754 yyhasResolvedValue (yyGLRState
* yystate
)
756 return yystate
->yyresolved
;
760 yyaddDeferredAction (yyGLRStack
* yystack
, yyGLRState
* yystate
,
761 yyGLRState
* yyrhs
, yyRuleNum yyrule
)
763 yySemanticOption
* yynewItem
;
764 yynewItem
= &yystack
->yynextFree
->yyoption
;
765 yystack
->yyspaceLeft
-= 1;
766 yystack
->yynextFree
+= 1;
767 yynewItem
->yyisState
= yyfalse
;
768 yynewItem
->yystate
= yyrhs
;
769 yynewItem
->yyrule
= yyrule
;
770 yynewItem
->yynext
= yystate
->yysemantics
.yyfirstVal
;
771 yystate
->yysemantics
.yyfirstVal
= yynewItem
;
772 if (yystack
->yyspaceLeft
< YYHEADROOM
)
773 yyexpandGLRStack (yystack
);
778 /** Initialize SET to a singleton set containing an empty stack. */
780 yyinitStateSet (yyGLRStateSet
* yyset
)
783 yyset
->yycapacity
= 16;
784 yyset
->yystates
= (yyGLRState
**) malloc (16 * sizeof (yyset
->yystates
[0]));
785 yyset
->yystates
[0] = NULL
;
788 static void yyfreeStateSet (yyGLRStateSet
* yyset
)
790 free (yyset
->yystates
);
793 /** Initialize STACK to a single empty stack, with total maximum
794 * capacity for all stacks of SIZE. */
796 yyinitGLRStack (yyGLRStack
* yystack
, size_t yysize
)
798 yystack
->yyerrflag
= 0;
799 yystack
->yyerrState
= 0;
801 yystack
->yyspaceLeft
= yysize
;
802 yystack
->yynextFree
= yystack
->yyitems
=
803 (yyGLRStackItem
*) malloc (yysize
* sizeof (yystack
->yynextFree
[0]));
804 yystack
->yysplitPoint
= NULL
;
805 yystack
->yylastDeleted
= NULL
;
806 yyinitStateSet (&yystack
->yytops
);
809 #define YYRELOC(YYFROMITEMS,YYTOITEMS,YYX,YYTYPE) \
810 &((YYTOITEMS) - ((YYFROMITEMS) - (yyGLRStackItem*) (YYX)))->YYTYPE
812 /** If STACK is expandable, extend it. WARNING: Pointers into the
813 stack from outside should be considered invalid after this call.
814 We always expand when there are 1 or fewer items left AFTER an
815 allocation, so that we can avoid having external pointers exist
816 across an allocation. */
818 yyexpandGLRStack (yyGLRStack
* yystack
)
820 #if YYSTACKEXPANDABLE
821 yyGLRStack yynewStack
;
822 yyGLRStackItem
* yyp0
, *yyp1
;
823 size_t yysize
, yynewSize
;
825 yysize
= yystack
->yynextFree
- yystack
->yyitems
;
826 if (yysize
>= YYMAXDEPTH
)
827 yyFail (yystack
, "parsing stack overflow (%d items)", yysize
);
828 yynewSize
= 2*yysize
;
829 if (yynewSize
> YYMAXDEPTH
)
830 yynewSize
= YYMAXDEPTH
;
831 yyinitGLRStack (&yynewStack
, yynewSize
);
832 for (yyp0
= yystack
->yyitems
, yyp1
= yynewStack
.yyitems
, yyn
= yysize
;
834 yyn
-= 1, yyp0
+= 1, yyp1
+= 1)
839 yyGLRState
* yys0
= &yyp0
->yystate
;
840 yyGLRState
* yys1
= &yyp1
->yystate
;
841 if (yys0
->yypred
!= NULL
)
843 YYRELOC (yyp0
, yyp1
, yys0
->yypred
, yystate
);
844 if (! yys0
->yyresolved
&& yys0
->yysemantics
.yyfirstVal
!= NULL
)
845 yys1
->yysemantics
.yyfirstVal
=
846 YYRELOC(yyp0
, yyp1
, yys0
->yysemantics
.yyfirstVal
, yyoption
);
850 yySemanticOption
* yyv0
= &yyp0
->yyoption
;
851 yySemanticOption
* yyv1
= &yyp1
->yyoption
;
852 if (yyv0
->yystate
!= NULL
)
853 yyv1
->yystate
= YYRELOC (yyp0
, yyp1
, yyv0
->yystate
, yystate
);
854 if (yyv0
->yynext
!= NULL
)
855 yyv1
->yynext
= YYRELOC (yyp0
, yyp1
, yyv0
->yynext
, yyoption
);
858 if (yystack
->yysplitPoint
!= NULL
)
859 yystack
->yysplitPoint
= YYRELOC (yystack
->yyitems
, yynewStack
.yyitems
,
860 yystack
->yysplitPoint
, yystate
);
862 for (yyn
= 0; yyn
< yystack
->yytops
.yysize
; yyn
+= 1)
863 if (yystack
->yytops
.yystates
[yyn
] != NULL
)
864 yystack
->yytops
.yystates
[yyn
] =
865 YYRELOC (yystack
->yyitems
, yynewStack
.yyitems
,
866 yystack
->yytops
.yystates
[yyn
], yystate
);
867 free (yystack
->yyitems
);
868 yystack
->yyitems
= yynewStack
.yyitems
;
869 yystack
->yynextFree
= yynewStack
.yynextFree
+ yysize
;
870 yystack
->yyspaceLeft
= yynewStack
.yyspaceLeft
- yysize
;
874 yyFail (yystack
, "parsing stack overflow (%d items)", yysize
);
880 yyfreeGLRStack (yyGLRStack
* yystack
)
882 free (yystack
->yyitems
);
883 yyfreeStateSet (&yystack
->yytops
);
886 /** Assuming that S is a GLRState somewhere on STACK, update the
887 * splitpoint of STACK, if needed, so that it is at least as deep as
890 yyupdateSplit (yyGLRStack
* yystack
, yyGLRState
* yys
)
892 if (yystack
->yysplitPoint
!= NULL
&& yystack
->yysplitPoint
> yys
)
893 yystack
->yysplitPoint
= yys
;
896 /** Invalidate stack #K in STACK. */
898 yymarkStackDeleted (yyGLRStack
* yystack
, int yyk
)
900 if (yystack
->yytops
.yystates
[yyk
] != NULL
)
901 yystack
->yylastDeleted
= yystack
->yytops
.yystates
[yyk
];
902 yystack
->yytops
.yystates
[yyk
] = NULL
;
905 /** Undelete the last stack that was marked as deleted. Can only be
906 done once after a deletion, and only when all other stacks have
909 yyundeleteLastStack (yyGLRStack
* yystack
)
911 if (yystack
->yylastDeleted
== NULL
|| yystack
->yytops
.yysize
!= 0)
913 yystack
->yytops
.yystates
[0] = yystack
->yylastDeleted
;
914 yystack
->yytops
.yysize
= 1;
915 YYDPRINTF ((stderr
, "Restoring last deleted stack as stack #0.\n"));
916 yystack
->yylastDeleted
= NULL
;
920 yyremoveDeletes (yyGLRStack
* yystack
)
924 while (yyj
< yystack
->yytops
.yysize
)
926 if (yystack
->yytops
.yystates
[yyi
] == NULL
)
929 YYDPRINTF ((stderr
, "Removing dead stacks.\n"));
930 yystack
->yytops
.yysize
-= 1;
934 yystack
->yytops
.yystates
[yyj
] = yystack
->yytops
.yystates
[yyi
];
936 YYDPRINTF ((stderr
, "Rename stack %d -> %d.\n", yyi
, yyj
));
943 /** Shift to a new state on stack #K of STACK, corresponding to LR state
944 * LRSTATE, at input position POSN, with (resolved) semantic value SVAL. */
946 yyglrShift (yyGLRStack
* yystack
, int yyk
, yyStateNum yylrState
, size_t yyposn
,
947 YYSTYPE yysval
, YYLTYPE
* yylocp
)
949 yyGLRStackItem
* yynewItem
;
951 yynewItem
= yystack
->yynextFree
;
952 yystack
->yynextFree
+= 1;
953 yystack
->yyspaceLeft
-= 1;
954 yynewItem
->yystate
.yyisState
= yytrue
;
955 yynewItem
->yystate
.yylrState
= yylrState
;
956 yynewItem
->yystate
.yyposn
= yyposn
;
957 yynewItem
->yystate
.yyresolved
= yytrue
;
958 yynewItem
->yystate
.yypred
= yystack
->yytops
.yystates
[yyk
];
959 yystack
->yytops
.yystates
[yyk
] = &yynewItem
->yystate
;
960 yynewItem
->yystate
.yysemantics
.yysval
= yysval
;
961 yynewItem
->yystate
.yyloc
= *yylocp
;
962 if (yystack
->yyspaceLeft
< YYHEADROOM
)
963 yyexpandGLRStack (yystack
);
966 /** Shift to a new state on stack #K of STACK, to a new state
967 * corresponding to LR state LRSTATE, at input position POSN, with
968 * the (unresolved) semantic value of RHS under the action for RULE. */
970 yyglrShiftDefer (yyGLRStack
* yystack
, int yyk
, yyStateNum yylrState
,
971 size_t yyposn
, yyGLRState
* yyrhs
, yyRuleNum yyrule
)
973 yyGLRStackItem
* yynewItem
;
975 yynewItem
= yystack
->yynextFree
;
976 yynewItem
->yystate
.yyisState
= yytrue
;
977 yynewItem
->yystate
.yylrState
= yylrState
;
978 yynewItem
->yystate
.yyposn
= yyposn
;
979 yynewItem
->yystate
.yyresolved
= yyfalse
;
980 yynewItem
->yystate
.yypred
= yystack
->yytops
.yystates
[yyk
];
981 yynewItem
->yystate
.yysemantics
.yyfirstVal
= NULL
;
982 yystack
->yytops
.yystates
[yyk
] = &yynewItem
->yystate
;
983 yystack
->yynextFree
+= 1;
984 yystack
->yyspaceLeft
-= 1;
985 yyaddDeferredAction (yystack
, &yynewItem
->yystate
, yyrhs
, yyrule
);
988 /** Pop the symbols consumed by reduction #RULE from the top of stack
989 * #K of STACK, and perform the appropriate semantic action on their
990 * semantic values. Assumes that all ambiguities in semantic values
991 * have been previously resolved. Set *VALP to the resulting value,
992 * and *LOCP to the computed location (if any). Return value is as
995 yydoAction (yyGLRStack
* yystack
, int yyk
, yyRuleNum yyrule
,
996 YYSTYPE
* yyvalp
, YYLTYPE
* yylocp
)
998 int yynrhs
= yyrhsLength (yyrule
);
1000 if (yystack
->yysplitPoint
== NULL
)
1002 /* Standard special case: single stack. */
1003 yyGLRStackItem
* yyrhs
= (yyGLRStackItem
*) yystack
->yytops
.yystates
[yyk
];
1005 yystack
->yynextFree
-= yynrhs
;
1006 yystack
->yyspaceLeft
+= yynrhs
;
1007 yystack
->yytops
.yystates
[0] = & yystack
->yynextFree
[-1].yystate
;
1010 *yyvalp
= yyval_default
;
1011 *yylocp
= yyloc_default
;
1015 *yyvalp
= yyrhs
[1-yynrhs
].yystate
.yysemantics
.yysval
;
1016 *yylocp
= yyrhs
[1-yynrhs
].yystate
.yyloc
;
1018 return yyuserAction (yyrule
, yynrhs
, yyrhs
, yyvalp
, yylocp
, yystack
);
1024 yyGLRStackItem yyrhsVals
[YYMAXRHS
];
1025 for (yyi
= yynrhs
-1, yys
= yystack
->yytops
.yystates
[yyk
]; yyi
>= 0;
1026 yyi
-= 1, yys
= yys
->yypred
)
1028 assert (yys
->yypred
!= NULL
);
1029 yyrhsVals
[yyi
].yystate
.yyresolved
= yytrue
;
1030 yyrhsVals
[yyi
].yystate
.yysemantics
.yysval
= yys
->yysemantics
.yysval
;
1031 yyrhsVals
[yyi
].yystate
.yyloc
= yys
->yyloc
;
1033 yyupdateSplit (yystack
, yys
);
1034 yystack
->yytops
.yystates
[yyk
] = yys
;
1037 *yyvalp
= yyval_default
;
1038 *yylocp
= yyloc_default
;
1042 *yyvalp
= yyrhsVals
[0].yystate
.yysemantics
.yysval
;
1043 *yylocp
= yyrhsVals
[0].yystate
.yyloc
;
1045 return yyuserAction (yyrule
, yynrhs
, yyrhsVals
+ (yynrhs
-1),
1046 yyvalp
, yylocp
, yystack
);
1050 /** Pop items off stack #K of STACK according to grammar rule RULE,
1051 * and push back on the resulting nonterminal symbol. Perform the
1052 * semantic action associated with RULE and store its value with the
1053 * newly pushed state, if FORCEEVAL or if STACK is currently
1054 * unambiguous. Otherwise, store the deferred semantic action with
1055 * the new state. If the new state would have an identical input
1056 * position, LR state, and predecessor to an existing state on the stack,
1057 * it is identified with that existing state, eliminating stack #K from
1058 * the STACK. In this case, the (necessarily deferred) semantic value is
1059 * added to the options for the existing state's semantic value.
1061 static inline YYRESULTTAG
1062 yyglrReduce (yyGLRStack
* yystack
, size_t yyk
, yyRuleNum yyrule
,
1065 size_t yyposn
= yystack
->yytops
.yystates
[yyk
]->yyposn
;
1067 if (yyforceEval
|| yystack
->yysplitPoint
== NULL
)
1076 YYDPRINTF ((stderr
, "Reducing stack %d by rule %d (line %d),",
1077 yyk
, yyrule
- 1, yyrline
[yyrule
]));
1078 /* Print the symbols being reduced, and their result. */
1079 for (yyi
= yyprhs
[yyrule
]; yyrhs
[yyi
] >= 0; yyi
++)
1080 YYFPRINTF (stderr
, "%s ", yytokenName (yyrhs
[yyi
]));
1081 YYFPRINTF (stderr
, " -> %s\n", yytokenName (yyr1
[yyrule
]));
1084 YYCHK (yydoAction (yystack
, yyk
, yyrule
, &yysval
, &yyloc
));
1085 yyglrShift (yystack
, yyk
,
1086 yyLRgotoState (yystack
->yytops
.yystates
[yyk
]->yylrState
,
1087 yylhsNonterm (yyrule
)),
1088 yyposn
, yysval
, &yyloc
);
1089 YYDPRINTF ((stderr
, "Stack %d entering state %d\n",
1090 yyk
, yystack
->yytops
.yystates
[yyk
]->yylrState
));
1096 yyGLRState
* yys
, *yys0
= yystack
->yytops
.yystates
[yyk
];
1097 yyStateNum yynewLRState
;
1099 for (yys
= yystack
->yytops
.yystates
[yyk
], yyn
= yyrhsLength (yyrule
);
1103 assert (yys
!= NULL
);
1105 yyupdateSplit (yystack
, yys
);
1106 yynewLRState
= yyLRgotoState (yys
->yylrState
, yylhsNonterm (yyrule
));
1108 "Reduced stack %d by rule #%d; action deferred. "
1109 "Now in state %d.\n",
1110 yyk
, yyrule
-1, yynewLRState
));
1111 for (yyi
= 0; yyi
< yystack
->yytops
.yysize
; yyi
+= 1)
1112 if (yyi
!= yyk
&& yystack
->yytops
.yystates
[yyi
] != NULL
)
1114 yyGLRState
* yyp
, *yysplit
= yystack
->yysplitPoint
;
1115 yyp
= yystack
->yytops
.yystates
[yyi
];
1116 while (yyp
!= yys
&& yyp
!= yysplit
&& yyp
->yyposn
>= yyposn
)
1118 if (yyp
->yylrState
== yynewLRState
&& yyp
->yypred
== yys
)
1120 yyaddDeferredAction (yystack
, yyp
, yys0
, yyrule
);
1121 yymarkStackDeleted (yystack
, yyk
);
1122 YYDPRINTF ((stderr
, "Merging stack %d into stack %d.\n",
1129 yystack
->yytops
.yystates
[yyk
] = yys
;
1130 yyglrShiftDefer (yystack
, yyk
, yynewLRState
, yyposn
, yys0
, yyrule
);
1136 yysplitStack (yyGLRStack
* yystack
, int yyk
)
1138 if (yystack
->yysplitPoint
== NULL
)
1141 yystack
->yysplitPoint
= yystack
->yytops
.yystates
[yyk
];
1143 if (yystack
->yytops
.yysize
>= yystack
->yytops
.yycapacity
)
1145 yystack
->yytops
.yycapacity
*= 2;
1146 yystack
->yytops
.yystates
=
1147 (yyGLRState
**) realloc (yystack
->yytops
.yystates
,
1148 yystack
->yytops
.yycapacity
1149 * sizeof (yyGLRState
*));
1151 yystack
->yytops
.yystates
[yystack
->yytops
.yysize
]
1152 = yystack
->yytops
.yystates
[yyk
];
1153 yystack
->yytops
.yysize
+= 1;
1154 return yystack
->yytops
.yysize
-1;
1157 /** True iff Y0 and Y1 represent identical options at the top level.
1158 * That is, they represent the same rule applied to RHS symbols
1159 * that produce the same terminal symbols. */
1161 yyidenticalOptions (yySemanticOption
* yyy0
, yySemanticOption
* yyy1
)
1163 if (yyy0
->yyrule
== yyy1
->yyrule
)
1165 yyGLRState
*yys0
, *yys1
;
1167 for (yys0
= yyy0
->yystate
, yys1
= yyy1
->yystate
,
1168 yyn
= yyrhsLength (yyy0
->yyrule
);
1170 yys0
= yys0
->yypred
, yys1
= yys1
->yypred
, yyn
-= 1)
1171 if (yys0
->yyposn
!= yys1
->yyposn
)
1179 /** Assuming identicalOptions (Y0,Y1), (destructively) merge the
1180 * alternative semantic values for the RHS-symbols of Y1 into the
1181 * corresponding semantic value sets of the symbols of Y0. */
1183 yymergeOptionSets (yySemanticOption
* yyy0
, yySemanticOption
* yyy1
)
1185 yyGLRState
*yys0
, *yys1
;
1187 for (yys0
= yyy0
->yystate
, yys1
= yyy1
->yystate
,
1188 yyn
= yyrhsLength (yyy0
->yyrule
);
1190 yys0
= yys0
->yypred
, yys1
= yys1
->yypred
, yyn
-= 1)
1193 else if (! yys0
->yyresolved
&& ! yys1
->yyresolved
)
1195 yySemanticOption
* yyz
;
1196 for (yyz
= yys0
->yysemantics
.yyfirstVal
; yyz
->yynext
!= NULL
;
1199 yyz
->yynext
= yys1
->yysemantics
.yyfirstVal
;
1203 /** Y0 and Y1 represent two possible actions to take in a given
1204 * parsing state; return 0 if no combination is possible,
1205 * 1 if user-mergeable, 2 if Y0 is preferred, 3 if Y1 is preferred. */
1207 yypreference (yySemanticOption
* y0
, yySemanticOption
* y1
)
1209 yyRuleNum r0
= y0
->yyrule
, r1
= y1
->yyrule
;
1210 int p0
= yydprec
[r0
], p1
= yydprec
[r1
];
1214 if (yymerger
[r0
] == 0 || yymerger
[r0
] != yymerger
[r1
])
1219 if (p0
== 0 || p1
== 0)
1228 static YYRESULTTAG
yyresolveValue (yySemanticOption
* yyoptionList
,
1229 yyGLRStack
* yystack
, YYSTYPE
* yyvalp
,
1233 yyresolveStates (yyGLRState
* yys
, int yyn
, yyGLRStack
* yystack
)
1238 assert (yys
->yypred
!= NULL
);
1239 yyflag
= yyresolveStates (yys
->yypred
, yyn
-1, yystack
);
1242 if (! yys
->yyresolved
)
1244 yyflag
= yyresolveValue (yys
->yysemantics
.yyfirstVal
, yystack
,
1245 &yys
->yysemantics
.yysval
, &yys
->yyloc
);
1248 yys
->yyresolved
= yytrue
;
1255 yyresolveAction (yySemanticOption
* yyopt
, yyGLRStack
* yystack
,
1256 YYSTYPE
* yyvalp
, YYLTYPE
* yylocp
)
1258 yyGLRStackItem yyrhsVals
[YYMAXRHS
];
1262 yynrhs
= yyrhsLength (yyopt
->yyrule
);
1263 YYCHK (yyresolveStates (yyopt
->yystate
, yynrhs
, yystack
));
1264 for (yyi
= yynrhs
-1, yys
= yyopt
->yystate
; yyi
>= 0;
1265 yyi
-= 1, yys
= yys
->yypred
)
1267 assert (yys
->yypred
!= NULL
);
1268 yyrhsVals
[yyi
].yystate
.yyresolved
= yytrue
;
1269 yyrhsVals
[yyi
].yystate
.yysemantics
.yysval
= yys
->yysemantics
.yysval
;
1270 yyrhsVals
[yyi
].yystate
.yyloc
= yys
->yyloc
;
1272 return yyuserAction (yyopt
->yyrule
, yynrhs
, yyrhsVals
+ (yynrhs
-1),
1273 yyvalp
, yylocp
, yystack
);
1277 static yyGLRState YYLEFTMOST_STATE
= { 0, 0, -1, NULL
, 0, { NULL
} };
1279 static void yyreportTree (yySemanticOption
* yyx
, int yyindent
)
1281 int yynrhs
= yyrhsLength (yyx
->yyrule
);
1284 yyGLRState
* yystates
[YYMAXRHS
];
1286 for (yyi
= yynrhs
, yys
= yyx
->yystate
; yyi
> 0; yyi
-= 1, yys
= yys
->yypred
)
1287 yystates
[yyi
] = yys
;
1289 yystates
[0] = &YYLEFTMOST_STATE
;
1293 if (yys
->yyposn
+1 > yyx
->yystate
->yyposn
)
1294 YYFPRINTF (stderr
, "%*s%s -> <Rule %d, empty>\n",
1295 yyindent
, "", yytokenName (yylhsNonterm (yyx
->yyrule
)),
1298 YYFPRINTF (stderr
, "%*s%s -> <Rule %d, tokens %d .. %d>\n",
1299 yyindent
, "", yytokenName (yylhsNonterm (yyx
->yyrule
)),
1300 yyx
->yyrule
, yys
->yyposn
+1, yyx
->yystate
->yyposn
);
1301 for (yyi
= 1; yyi
<= yynrhs
; yyi
+= 1)
1303 if (yystates
[yyi
]->yyresolved
)
1305 if (yystates
[yyi
-1]->yyposn
+1 > yystates
[yyi
]->yyposn
)
1306 YYFPRINTF (stderr
, "%*s%s <empty>\n", yyindent
+2, "",
1307 yytokenName (yyrhs
[yyprhs
[yyx
->yyrule
]+yyi
-1]));
1309 YYFPRINTF (stderr
, "%*s%s <tokens %d .. %d>\n", yyindent
+2, "",
1310 yytokenName (yyrhs
[yyprhs
[yyx
->yyrule
]+yyi
-1]),
1311 yystates
[yyi
-1]->yyposn
+1, yystates
[yyi
]->yyposn
);
1314 yyreportTree (yystates
[yyi
]->yysemantics
.yyfirstVal
, yyindent
+2);
1320 yyreportAmbiguity (yySemanticOption
* yyx0
, yySemanticOption
* yyx1
,
1321 yyGLRStack
* yystack
)
1323 /* `Unused' warnings. */
1328 YYFPRINTF (stderr
, "Ambiguity detected.\n");
1329 YYFPRINTF (stderr
, "Option 1,\n");
1330 yyreportTree (yyx0
, 2);
1331 YYFPRINTF (stderr
, "\nOption 2,\n");
1332 yyreportTree (yyx1
, 2);
1333 YYFPRINTF (stderr
, "\n");
1335 yyFail (yystack
, "ambiguity detected");
1339 /** Resolve the ambiguity represented by OPTIONLIST, perform the indicated
1340 * actions, and return the result. */
1342 yyresolveValue (yySemanticOption
* yyoptionList
, yyGLRStack
* yystack
,
1343 YYSTYPE
* yyvalp
, YYLTYPE
* yylocp
)
1345 yySemanticOption
* yybest
;
1346 yySemanticOption
* yyp
;
1349 yybest
= yyoptionList
;
1351 for (yyp
= yyoptionList
->yynext
; yyp
!= NULL
; yyp
= yyp
->yynext
)
1353 if (yyidenticalOptions (yybest
, yyp
))
1354 yymergeOptionSets (yybest
, yyp
);
1356 switch (yypreference (yybest
, yyp
))
1359 yyreportAmbiguity (yybest
, yyp
, yystack
);
1375 int yyprec
= yydprec
[yybest
->yyrule
];
1376 YYCHK (yyresolveAction (yybest
, yystack
, yyvalp
, yylocp
));
1377 for (yyp
= yybest
->yynext
; yyp
!= NULL
; yyp
= yyp
->yynext
)
1379 if (yyprec
== yydprec
[yyp
->yyrule
])
1383 YYCHK (yyresolveAction (yyp
, yystack
, &yyval1
, &yydummy
));
1384 *yyvalp
= yyuserMerge (yymerger
[yyp
->yyrule
], yyvalp
, &yyval1
);
1390 return yyresolveAction (yybest
, yystack
, yyvalp
, yylocp
);
1394 yyresolveStack (yyGLRStack
* yystack
)
1396 if (yystack
->yysplitPoint
!= NULL
)
1401 for (yyn
= 0, yys
= yystack
->yytops
.yystates
[0];
1402 yys
!= yystack
->yysplitPoint
;
1403 yys
= yys
->yypred
, yyn
+= 1)
1405 YYCHK (yyresolveStates (yystack
->yytops
.yystates
[0], yyn
, yystack
));
1411 yycompressStack (yyGLRStack
* yystack
)
1413 yyGLRState
* yyp
, *yyq
, *yyr
;
1415 if (yystack
->yytops
.yysize
!= 1 || yystack
->yysplitPoint
== NULL
)
1418 for (yyp
= yystack
->yytops
.yystates
[0], yyq
= yyp
->yypred
, yyr
= NULL
;
1419 yyp
!= yystack
->yysplitPoint
;
1420 yyr
= yyp
, yyp
= yyq
, yyq
= yyp
->yypred
)
1423 yystack
->yyspaceLeft
+= yystack
->yynextFree
- yystack
->yyitems
;
1424 yystack
->yynextFree
= ((yyGLRStackItem
*) yystack
->yysplitPoint
) + 1;
1425 yystack
->yyspaceLeft
-= yystack
->yynextFree
- yystack
->yyitems
;
1426 yystack
->yysplitPoint
= NULL
;
1427 yystack
->yylastDeleted
= NULL
;
1431 yystack
->yynextFree
->yystate
= *yyr
;
1433 yystack
->yynextFree
->yystate
.yypred
= & yystack
->yynextFree
[-1].yystate
;
1434 yystack
->yytops
.yystates
[0] = &yystack
->yynextFree
->yystate
;
1435 yystack
->yynextFree
+= 1;
1436 yystack
->yyspaceLeft
-= 1;
1441 yyprocessOneStack (yyGLRStack
* yystack
, int yyk
,
1442 size_t yyposn
, YYSTYPE
* yylvalp
, YYLTYPE
* yyllocp
)
1445 const short* yyconflicts
;
1447 yySymbol
* const yytokenp
= yystack
->yytokenp
;
1449 while (yystack
->yytops
.yystates
[yyk
] != NULL
)
1451 yyStateNum yystate
= yystack
->yytops
.yystates
[yyk
]->yylrState
;
1453 assert (yystate
!= YYFINAL
);
1454 if (yyisDefaultedState (yystate
))
1456 yyrule
= yydefaultAction (yystate
);
1459 YYDPRINTF ((stderr
, "Stack %d dies.\n", yyk
));
1460 yymarkStackDeleted (yystack
, yyk
);
1463 YYCHK (yyglrReduce (yystack
, yyk
, yyrule
, yyfalse
));
1467 if (*yytokenp
== YYEMPTY
)
1469 YYDPRINTF ((stderr
, "Reading a token: "));
1471 *yytokenp
= YYTRANSLATE(yychar
);
1472 YYDPRINTF ((stderr
, "Next token is %s\n",
1473 yytokenName (*yytokenp
)));
1475 yygetLRActions (yystate
, *yytokenp
, &yyaction
, &yyconflicts
);
1477 while (*yyconflicts
!= 0)
1479 int yynewStack
= yysplitStack (yystack
, yyk
);
1480 YYDPRINTF ((stderr
, "Splitting off stack %d from %d.\n",
1482 YYCHK (yyglrReduce (yystack
, yynewStack
, *yyconflicts
, yyfalse
));
1483 YYCHK (yyprocessOneStack (yystack
, yynewStack
, yyposn
,
1488 if (yyisShiftAction (yyaction
))
1490 YYDPRINTF ((stderr
, "Shifting token %s on stack %d, ",
1491 yytokenName (*yytokenp
), yyk
));
1492 yyglrShift (yystack
, yyk
, yyaction
, yyposn
+1, *yylvalp
, yyllocp
);
1493 YYDPRINTF ((stderr
, "which is now in state #%d\n",
1494 yystack
->yytops
.yystates
[yyk
]->yylrState
));
1497 else if (yyisErrorAction (yyaction
))
1499 YYDPRINTF ((stderr
, "Stack %d dies.\n", yyk
));
1500 yymarkStackDeleted (yystack
, yyk
);
1504 YYCHK (yyglrReduce (yystack
, yyk
, -yyaction
, yyfalse
));
1511 yyreportParseError (yyGLRStack
* yystack
, YYSTYPE
* yylvalp
, YYLTYPE
* yyllocp
)
1513 /* `Unused' warnings. */
1517 if (yystack
->yyerrState
== 0)
1520 yySymbol
* const yytokenp
= yystack
->yytokenp
;
1521 int yyn
, yyx
, yycount
;
1523 const char* yyprefix
;
1526 yyn
= yypact
[yystack
->yytops
.yystates
[0]->yylrState
];
1527 if (YYPACT_NINF
< yyn
&& yyn
< YYLAST
)
1530 /* Start YYX at -YYN if negative to avoid negative indexes in
1532 yysize
= sizeof ("parse error, unexpected ")
1533 + strlen (yytokenName (*yytokenp
));
1534 yyprefix
= ", expecting ";
1535 for (yyx
= yyn
< 0 ? -yyn
: 0; yyx
< yytname_size
&& yycount
<= 5;
1537 if (yycheck
[yyx
+ yyn
] == yyx
&& yyx
!= YYTERROR
)
1538 yysize
+= strlen (yytokenName (yyx
)) + strlen (yyprefix
),
1539 yycount
+= 1, yyprefix
= " or ";
1540 yymsg
= yyp
= (char*) malloc (yysize
);
1541 yyp
+= sprintf (yyp
, "parse error, unexpected %s",
1542 yytokenName (*yytokenp
));
1545 yyprefix
= ", expecting ";
1546 for (yyx
= yyn
< 0 ? -yyn
: 0; yyx
< yytname_size
; yyx
+= 1)
1547 if (yycheck
[yyx
+ yyn
] == yyx
&& yyx
!= YYTERROR
)
1549 yyp
+= sprintf (yyp
, "%s%s", yyprefix
, yytokenName (yyx
));
1558 yyerror ("parse error");
1563 /* Recover from a syntax error on YYSTACK, assuming that YYTOKENP,
1564 YYLVALP, and YYLLOCP point to the syntactic category, semantic
1565 value, and location of the lookahead. */
1567 yyrecoverParseError (yyGLRStack
* yystack
, YYSTYPE
* yylvalp
, YYLTYPE
* yyllocp
)
1569 yySymbol
* const yytokenp
= yystack
->yytokenp
;
1573 if (yystack
->yyerrState
== 0)
1574 yystack
->yyerrState
= 3;
1575 else if (yystack
->yyerrState
== 3)
1576 /* We just shifted the error token and (perhaps) took some
1577 reductions. Skip tokens until we can proceed. */
1580 if (*yytokenp
== YYEOF
)
1581 yyFail (yystack
, NULL
);
1582 if (*yytokenp
!= YYEMPTY
)
1583 YYDPRINTF ((stderr
, "Discarding token %s\n",
1584 yytokenName (*yytokenp
)));
1585 YYDPRINTF ((stderr
, "Reading a token: "));
1587 *yytokenp
= YYTRANSLATE (yychar
);
1588 YYDPRINTF ((stderr
, "Next token is %s\n", yytokenName (*yytokenp
)));
1589 yyj
= yypact
[yystack
->yytops
.yystates
[0]->yylrState
];
1590 if (yyj
== YYPACT_NINF
)
1591 /* Something's not right; we shouldn't be here. */
1592 yyFail (yystack
, NULL
);
1594 if (yyj
< 0 || yyj
> YYLAST
|| yycheck
[yyj
] != *yytokenp
)
1596 if (yydefact
[yystack
->yytops
.yystates
[0]->yylrState
] != 0)
1599 else if (yytable
[yyj
] != 0 && yytable
[yyj
] != YYTABLE_NINF
)
1603 /* Reduce to one stack. */
1604 for (yyk
= 0; yyk
< yystack
->yytops
.yysize
; yyk
+= 1)
1605 if (yystack
->yytops
.yystates
[yyk
] != NULL
)
1607 if (yyk
>= yystack
->yytops
.yysize
)
1608 yyFail (yystack
, NULL
);
1609 for (yyk
+= 1; yyk
< yystack
->yytops
.yysize
; yyk
+= 1)
1610 yymarkStackDeleted (yystack
, yyk
);
1611 yyremoveDeletes (yystack
);
1612 yycompressStack (yystack
);
1614 /* Now pop stack until we find a state that shifts the error token. */
1615 while (yystack
->yytops
.yystates
[0] != NULL
)
1617 yyj
= yypact
[yystack
->yytops
.yystates
[0]->yylrState
] + YYTERROR
;
1618 if (yyj
!= YYPACT_NINF
+ YYTERROR
&& yyj
>= 0 && yyj
<= YYLAST
&&
1619 yycheck
[yyj
] == YYTERROR
&& yyisShiftAction (yytable
[yyj
]))
1621 yyglrShift (yystack
, 0, yytable
[yyj
],
1622 yystack
->yytops
.yystates
[0]->yyposn
, *yylvalp
, yyllocp
);
1625 yystack
->yytops
.yystates
[0] = yystack
->yytops
.yystates
[0]->yypred
;
1626 yystack
->yynextFree
-= 1;
1627 yystack
->yyspaceLeft
+= 1;
1629 if (yystack
->yytops
.yystates
[0] == NULL
)
1630 yyFail (yystack
, NULL
);
1633 #define YYCHK1(YYE) \
1639 yystack.yyerrflag = 1; \
1642 yystack.yyerrflag = 0; \
1645 goto yyuser_error; \
1650 yyparse (YYPARSE_PARAM_ARG
)
1660 #define yychar (yystack.yyrawchar)
1663 YYSTYPE
* const yylvalp
= &yylval
;
1664 YYLTYPE
* const yyllocp
= &yylloc
;
1666 yyinitGLRStack (&yystack
, YYINITDEPTH
);
1667 yystack
.yytokenp
= &yytoken
;
1669 YYDPRINTF ((stderr
, "Starting parse\n"));
1671 if (setjmp (yystack
.yyexception_buffer
) != 0)
1674 yyglrShift (&yystack
, 0, 0, 0, yyval_default
, &yyloc_default
);
1680 /* For efficiency, we have two loops, of which the first of which
1681 * is specialized to deterministic operation (single stack, no
1682 * potential ambiguity). */
1689 const short* yyconflicts
;
1691 yyStateNum yystate
= yystack
.yytops
.yystates
[0]->yylrState
;
1692 if (yystate
== YYFINAL
)
1694 if (yyisDefaultedState (yystate
))
1696 yyrule
= yydefaultAction (yystate
);
1699 yyreportParseError (&yystack
, yylvalp
, yyllocp
);
1702 YYCHK1 (yyglrReduce (&yystack
, 0, yyrule
, yytrue
));
1706 if (yytoken
== YYEMPTY
)
1708 YYDPRINTF ((stderr
, "Reading a token: "));
1710 yytoken
= YYTRANSLATE (yychar
);
1711 YYDPRINTF ((stderr
, "Next token is %s\n",
1712 yytokenName (yytoken
)));
1714 yygetLRActions (yystate
, yytoken
, &yyaction
, &yyconflicts
);
1715 if (*yyconflicts
!= 0)
1717 if (yyisShiftAction (yyaction
))
1719 YYDPRINTF ((stderr
, "Shifting token %s, ",
1720 yytokenName (yytoken
)));
1721 if (yytoken
!= YYEOF
)
1724 yyglrShift (&yystack
, 0, yyaction
, yyposn
, yylval
, yyllocp
);
1725 if (yystack
.yyerrState
> 0)
1726 yystack
.yyerrState
-= 1;
1727 YYDPRINTF ((stderr
, "Entering state %d\n",
1728 yystack
.yytops
.yystates
[0]->yylrState
));
1730 else if (yyisErrorAction (yyaction
))
1732 yyreportParseError (&yystack
, yylvalp
, yyllocp
);
1736 YYCHK1 (yyglrReduce (&yystack
, 0, -yyaction
, yytrue
));
1743 int yyn
= yystack
.yytops
.yysize
;
1744 for (yys
= 0; yys
< yyn
; yys
+= 1)
1745 YYCHK1 (yyprocessOneStack (&yystack
, yys
, yyposn
,
1749 yyremoveDeletes (&yystack
);
1750 if (yystack
.yytops
.yysize
== 0)
1752 yyundeleteLastStack (&yystack
);
1753 if (yystack
.yytops
.yysize
== 0)
1754 yyFail (&yystack
, "parse error");
1755 YYCHK1 (yyresolveStack (&yystack
));
1756 YYDPRINTF ((stderr
, "Returning to deterministic operation.\n"));
1757 yyreportParseError (&yystack
, yylvalp
, yyllocp
);
1760 else if (yystack
.yytops
.yysize
== 1)
1762 YYCHK1 (yyresolveStack (&yystack
));
1763 YYDPRINTF ((stderr
, "Returning to deterministic operation.\n"));
1764 yycompressStack (&yystack
);
1770 yyrecoverParseError (&yystack
, yylvalp
, yyllocp
);
1771 yyposn
= yystack
.yytops
.yystates
[0]->yyposn
;
1776 yyfreeGLRStack (&yystack
);
1777 return yystack
.yyerrflag
;
1780 /* DEBUGGING ONLY */
1781 static void yypstack (yyGLRStack
* yystack
, int yyk
) ATTRIBUTE_UNUSED
;
1782 static void yypdumpstack (yyGLRStack
* yystack
) ATTRIBUTE_UNUSED
;
1785 yy_yypstack (yyGLRState
* yys
)
1789 yy_yypstack (yys
->yypred
);
1790 fprintf (stderr
, " -> ");
1792 fprintf (stderr
, "%d@%lu", yys
->yylrState
, (unsigned long) yys
->yyposn
);
1796 yypstates (yyGLRState
* yyst
)
1799 fprintf (stderr
, "<null>");
1802 fprintf (stderr
, "\n");
1806 yypstack (yyGLRStack
* yystack
, int yyk
)
1808 yypstates (yystack
->yytops
.yystates
[yyk
]);
1811 #define YYINDEX(YYX) \
1812 ((YYX) == NULL ? -1 : (yyGLRStackItem*) (YYX) - yystack->yyitems)
1816 yypdumpstack (yyGLRStack
* yystack
)
1818 yyGLRStackItem
* yyp
;
1820 for (yyp
= yystack
->yyitems
; yyp
< yystack
->yynextFree
; yyp
+= 1)
1822 fprintf (stderr
, "%3lu. ", (unsigned long) (yyp
- yystack
->yyitems
));
1825 fprintf (stderr
, "Res: %d, LR State: %d, posn: %lu, pred: %ld",
1826 yyp
->yystate
.yyresolved
, yyp
->yystate
.yylrState
,
1827 (unsigned long) yyp
->yystate
.yyposn
,
1828 (long) YYINDEX (yyp
->yystate
.yypred
));
1829 if (! yyp
->yystate
.yyresolved
)
1830 fprintf (stderr
, ", firstVal: %ld",
1831 (long) YYINDEX (yyp
->yystate
.yysemantics
.yyfirstVal
));
1835 fprintf (stderr
, "Option. rule: %d, state: %ld, next: %ld",
1836 yyp
->yyoption
.yyrule
,
1837 (long) YYINDEX (yyp
->yyoption
.yystate
),
1838 (long) YYINDEX (yyp
->yyoption
.yynext
));
1840 fprintf (stderr
, "\n");
1842 fprintf (stderr
, "Tops:");
1843 for (yyi
= 0; yyi
< yystack
->yytops
.yysize
; yyi
+= 1)
1844 fprintf (stderr
, "%lu: %ld; ", (unsigned long) yyi
,
1845 (long) YYINDEX (yystack
->yytops
.yystates
[yyi
]));
1846 fprintf (stderr
, "\n");
1852 m4_if(b4_defines_flag
, 0, [],
1853 [#output "b4_output_header_name"
1854 b4_copyright([Skeleton parser
for GLR parsing with Bison
], [2002])
1855 #ifndef b4_header_guard
1856 # define b4_header_guard
1858 b4_token_defines(b4_tokens
)
1861 m4_ifdef([b4_stype
],
1862 [#line b4_stype_line "b4_filename"
1863 typedef union b4_stype yystype
;
1864 /* Line __line__ of __file__. */
1865 #line __oline__ "__ofile__"],
1866 [typedef int yystype
;])
1867 # define YYSTYPE yystype
1871 [extern YYSTYPE b4_prefix
[]lval
;])
1875 typedef struct yyltype
1882 # define YYLTYPE yyltype
1886 [extern YYLTYPE b4_prefix
[]lloc
;])
1888 #endif /* not b4_header_guard */