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
23 ## ---------------- ##
25 ## ---------------- ##
28 m4_define_default([b4_stack_depth_max
], [10000])
29 m4_define_default([b4_stack_depth_init
], [200])
32 m4_define_default([b4_location_type
], [yyltype
])
34 # Accumule in b4_lex_param all the yylex arguments.
35 # Yes, this is quite ugly...
36 m4_define([b4_lex_param
],
37 m4_dquote(b4_pure_if([[[[YYSTYPE
*]], [[yylvalp]]][]dnl
38 b4_location_if([, [[YYLTYPE
*], [yyllocp
]]])])dnl
39 m4_ifdef([b4_lex_param
], [, ]b4_lex_param
)))
41 # Yes, this is quite ugly...
42 m4_define_default([b4_parse_param
])
43 m4_ifdef([b4_parse_param
],
44 [m4_define([b4_parse_param
],
49 ## ----------------- ##
50 ## Semantic Values. ##
51 ## ----------------- ##
54 # b4_lhs_value([TYPE])
55 # --------------------
56 # Expansion of $<TYPE>$.
57 m4_define([b4_lhs_value
],
58 [(*yyvalp
)[]m4_ifval([$
1], [.$
1])])
61 # b4_rhs_value(RULE-LENGTH, NUM, [TYPE])
62 # --------------------------------------
63 # Expansion of $<TYPE>NUM, where the current rule has RULE-LENGTH
65 m4_define([b4_rhs_value
],
66 [yyvsp@
<:@
m4_eval([$
2 - $
1])@
:>@
.yystate
.yysemantics
.yysval
[]m4_ifval([$
3], [.$
3])])
77 m4_define([b4_lhs_location
],
81 # b4_rhs_location(RULE-LENGTH, NUM)
82 # ---------------------------------
83 # Expansion of @NUM, where the current rule has RULE-LENGTH symbols
85 m4_define([b4_rhs_location
],
86 [yyvsp@
<:@
m4_eval([$
2 - $
1])@
:>@
.yystate
.yyloc
])
90 ## ------------------- ##
91 ## Output file names. ##
92 ## ------------------- ##
94 m4_define_default([b4_input_suffix
], [.y
])
96 m4_define_default([b4_output_parser_suffix
],
97 [m4_translit(b4_input_suffix
, [yY
], [cC
])])
99 m4_define_default([b4_output_parser_name
],
100 [b4_output_prefix
[]b4_output_infix
[]b4_output_parser_suffix
[]])
103 m4_define_default([b4_output_header_suffix
],
104 [m4_translit(b4_input_suffix
, [yY
], [hH
])])
106 m4_define_default([b4_output_header_name
],
107 [b4_output_prefix
[]b4_output_infix
[]b4_output_header_suffix
[]])
109 m4_define_default([b4_header_guard
],
110 [m4_bpatsubst(m4_toupper([BISON_
]b4_output_header_name
),
111 [[^ABCDEFGHIJKLMNOPQRSTUVWXYZ
]], [_
])])
115 #output "b4_output_parser_name"
116 b4_copyright([Skeleton parser
for GLR parsing with Bison
], [2002])
118 /* This is the parser code for GLR (Generalized LR) parser. */
120 /* FIXME: minimize these */
128 /* Identify Bison output. */
132 #define YYPURE ]b4_pure[
134 /* Using locations. */
135 #define YYLSP_NEEDED ]b4_locations_flag[
137 ]m4_if(b4_prefix
[], [yy
], [],
138 [/* If NAME_PREFIX is specified substitute the variables and functions
140 #define yyparse b4_prefix[]parse
141 #define yylex b4_prefix[]lex
142 #define yyerror b4_prefix[]error
143 #define yylval b4_prefix[]lval
144 #define yychar b4_prefix[]char
145 #define yydebug b4_prefix[]debug
146 #define yynerrs b4_prefix[]nerrs
147 b4_location_if([#define yylloc b4_prefix[]lloc])])
149 b4_token_defines(b4_tokens
)
151 /* Copy the first part of user declarations. */
154 /* Enabling traces. */
156 # define YYDEBUG ]b4_debug[
159 /* Enabling verbose error messages. */
160 #ifdef YYERROR_VERBOSE
161 # undef YYERROR_VERBOSE
162 # define YYERROR_VERBOSE 1
164 # define YYERROR_VERBOSE ]b4_error_verbose[
168 ]m4_ifdef([b4_stype
],
169 [#line b4_stype_line "b4_filename"
170 typedef union b4_stype yystype
;
171 /* Line __line__ of __file__. */
172 #line __oline__ "__ofile__"],
173 [typedef int yystype
;])[
174 # define YYSTYPE yystype
175 # define YYSTYPE_IS_TRIVIAL 1
179 typedef struct yyltype
186 # define YYLTYPE ]b4_location_type[
187 # define YYLTYPE_IS_TRIVIAL 1
190 /* Default (constant) values used for initialization for null
191 right-hand sides. Unlike the standard bison.simple template,
192 here we set the default values of the $$ and $@ to zeroed-out
193 values. Since the default value of these quantities is undefined,
194 this behavior is technically correct. */
195 static YYSTYPE yyval_default
;
196 static YYLTYPE yyloc_default
;
198 /* Copy the second part of user declarations. */
201 ]/* Line __line__ of __file__. */
202 #line __oline__ "__ofile__"
204 #if ! defined (__cplusplus)
214 #ifndef __attribute__
215 /* This feature is available in gcc versions 2.5 and later. */
216 # if !defined (__GNUC__) || __GNUC__ < 2 || \
217 (__GNUC__ == 2 && __GNUC_MINOR__ < 5) || __STRICT_ANSI__
218 # define __attribute__(Spec) /* empty */
222 #ifndef ATTRIBUTE_UNUSED
223 # define ATTRIBUTE_UNUSED __attribute__ ((__unused__))
226 #if ! defined (__GNUC__)
230 /* YYFINAL -- State number of the termination state. */
231 #define YYFINAL ]b4_final_state_number[
232 /* YYLAST -- Last index in YYTABLE. */
233 #define YYLAST ]b4_last[
235 /* YYNTOKENS -- Number of terminals. */
236 #define YYNTOKENS ]b4_tokens_number[
237 /* YYNNTS -- Number of nonterminals. */
238 #define YYNNTS ]b4_nterms_number[
239 /* YYNRULES -- Number of rules. */
240 #define YYNRULES ]b4_rules_number[
241 /* YYNRULES -- Number of states. */
242 #define YYNSTATES ]b4_states_number[
243 /* YYMAXRHS -- Maximum number of symbols on right-hand side of rule. */
244 #define YYMAXRHS ]b4_r2_max[
246 /* YYTRANSLATE(X) -- Bison symbol number corresponding to X. */
247 #define YYUNDEFTOK ]b4_undef_token_number[
248 #define YYMAXUTOK ]b4_user_token_number_max[
250 #define YYTRANSLATE(YYX) \
251 ((unsigned)(YYX) <= YYMAXUTOK ? yytranslate[YYX] : YYUNDEFTOK)
253 /* YYTRANSLATE[YYLEX] -- Bison symbol number corresponding to YYLEX. */
254 static const ]b4_int_type_for([b4_translate
])[ yytranslate
[] =
260 /* YYPRHS[YYN] -- Index of the first RHS symbol of rule number YYN in
262 static const ]b4_int_type_for([b4_prhs
])[ yyprhs
[] =
267 /* YYRHS -- A `-1'-separated list of the rules' RHS. */
268 static const ]b4_int_type_for([b4_rhs
])[ yyrhs
[] =
273 /* YYRLINE[YYN] -- source line where rule number YYN was defined. */
274 static const ]b4_int_type_for([b4_rline
])[ yyrline
[] =
280 #if (YYDEBUG) || YYERROR_VERBOSE
281 /* YYTNME[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM.
282 First, the terminals, then, starting at YYNTOKENS, nonterminals. */
283 static const char *const yytname
[] =
288 #define yytname_size ((int) (sizeof (yytname) / sizeof (yytname[0])))
291 /* YYR1[YYN] -- Symbol number of symbol that rule YYN derives. */
292 static const ]b4_int_type_for([b4_r1
])[ yyr1
[] =
297 /* YYR2[YYN] -- Number of symbols composing right hand side of rule YYN. */
298 static const ]b4_int_type_for([b4_r2
])[ yyr2
[] =
303 /* YYDPREC[RULE-NUM] -- Dynamic precedence of rule #RULE-NUM (0 if none). */
304 static const ]b4_int_type_for([b4_dprec
])[ yydprec
[] =
309 /* YYMERGER[RULE-NUM] -- Index of merging function for rule #RULE-NUM. */
310 static const ]b4_int_type_for([b4_merger
])[ yymerger
[] =
315 /* YYDEFACT[S] -- default rule to reduce with in state S when YYTABLE
316 doesn't specify something else to do. Zero means the default is an
318 static const ]b4_int_type_for([b4_defact
])[ yydefact
[] =
323 /* YYPDEFGOTO[NTERM-NUM]. */
324 static const ]b4_int_type_for([b4_defgoto
])[ yydefgoto
[] =
329 /* YYPACT[STATE-NUM] -- Index in YYTABLE of the portion describing
331 #define YYPACT_NINF ]b4_pact_ninf[
332 static const ]b4_int_type_for([b4_pact
])[ yypact
[] =
337 /* YYPGOTO[NTERM-NUM]. */
338 static const ]b4_int_type_for([b4_pgoto
])[ yypgoto
[] =
343 /* YYTABLE[YYPACT[STATE-NUM]]. What to do in state STATE-NUM. If
344 positive, shift that token. If negative, reduce the rule which
345 number is the opposite. If zero, do what YYDEFACT says.
346 If YYTABLE_NINF, parse error. */
347 #define YYTABLE_NINF ]b4_table_ninf[
348 static const ]b4_int_type_for([b4_table
])[ yytable
[] =
353 /* YYCONFLP[YYPACT[STATE-NUM]] -- Pointer into YYCONFL of start of
354 list of conflicting reductions corresponding to action entry for
355 state STATE-NUM in yytable. 0 means no conflicts. The list in
356 yyconfl is terminated by a rule number of 0. */
357 static const ]b4_int_type_for([b4_conflict_list_heads
])[ yyconflp
[] =
359 ]b4_conflict_list_heads
[
362 /* YYCONFL[I] -- lists of conflicting rule numbers, each terminated by
363 0, pointed into by YYCONFLP. */
364 ]dnl Do
not use b4_int_type_for here
, since there are places where
365 dnl pointers onto yyconfl are taken
, which type is
"short *".
366 dnl We probably ought to introduce a type
for confl
.
367 [static const short yyconfl
[] =
369 ]b4_conflicting_rules
[
372 static const ]b4_int_type_for([b4_check
])[ yycheck
[] =
378 /* Prevent warning if -Wmissing-prototypes. */
379 ]b4_c_ansi_function_decl([yyparse
], [int], b4_parse_param
)
381 m4_ifset([b4_parse_param
],
382 [#define YY_USER_FORMALS , b4_c_ansi_formals(b4_parse_param)
383 #define YY_USER_ARGS , b4_c_args(b4_parse_param)],
384 [#define YY_USER_FORMALS
385 #define YY_USER_ARGS])
388 [/* Error token number */
391 /* YYLLOC_DEFAULT -- Compute the default location (before the actions
394 #define YYRHSLOC(yyRhs,YYK) (yyRhs[YYK].yystate.yyloc)
396 #ifndef YYLLOC_DEFAULT
397 # define YYLLOC_DEFAULT(yyCurrent, yyRhs, YYN) \
398 yyCurrent.first_line = YYRHSLOC(yyRhs,1).first_line; \
399 yyCurrent.first_column = YYRHSLOC(yyRhs,1).first_column; \
400 yyCurrent.last_line = YYRHSLOC(yyRhs,YYN).last_line; \
401 yyCurrent.last_column = YYRHSLOC(yyRhs,YYN).last_column;
404 /* YYLEX -- calling `yylex' with the right arguments. */
405 #define YYLEX ]b4_c_function_call([yylex], [int], b4_lex_param)[
410 #define yynerrs (yystack->yyerrcnt)
412 #define yychar (yystack->yyrawchar)],
420 static const int YYEOF
= 0;
421 static const int YYEMPTY
= -2;
423 typedef enum { yyok
, yyaccept
, yyabort
, yyerr
} YYRESULTTAG
;
426 do { YYRESULTTAG yyflag = YYE; if (yyflag != yyok) return yyflag; } \
431 #if ! defined (YYFPRINTF)
432 # define YYFPRINTF fprintf
435 # define YYDPRINTF(Args) \
440 /* Nonzero means print parse trace. It is left uninitialized so that
441 multiple parsers can coexist. */
444 /* Avoid empty `if' bodies. */
445 # define YYDPRINTF(Args) {}
446 #endif /* !YYDEBUG */
448 /* YYINITDEPTH -- initial size of the parser's stacks. */
450 # define YYINITDEPTH ]b4_stack_depth_init[
453 /* YYMAXDEPTH -- maximum size the stacks can grow to (effective only
454 if the built-in stack extension method is used).
456 Do not make this value too large; the results are undefined if
457 SIZE_MAX < YYMAXDEPTH * sizeof (GLRStackItem)
458 evaluated with infinite-precision integer arithmetic. */
465 # define YYMAXDEPTH ]b4_stack_depth_max[
468 /* Minimum number of free items on the stack allowed after an
469 allocation. This is to allow allocation and initialization
470 to be completed by functions that call expandGLRStack before the
471 stack is expanded, thus insuring that all necessary pointers get
472 properly redirected to new data. */
475 #if ! defined (YYSTACKEXPANDABLE) \
476 && (! defined (__cplusplus) || (YYLTYPE_IS_TRIVIAL && YYSTYPE_IS_TRIVIAL))
477 #define YYSTACKEXPANDABLE 1
479 #define YYSTACKEXPANDABLE 0
482 /** State numbers, as in LALR(1) machine */
483 typedef int yyStateNum
;
485 /** Rule numbers, as in LALR(1) machine */
486 typedef int yyRuleNum
;
488 /** Grammar symbol */
489 typedef short yySymbol
;
491 /** Item references, as in LALR(1) machine */
492 typedef short yyItemNum
;
494 typedef struct yyGLRState yyGLRState
;
495 typedef struct yySemanticOption yySemanticOption
;
496 typedef union yyGLRStackItem yyGLRStackItem
;
497 typedef struct yyGLRStack yyGLRStack
;
498 typedef struct yyGLRStateSet yyGLRStateSet
;
503 yyStateNum yylrState
;
507 yySemanticOption
* yyfirstVal
;
513 struct yyGLRStateSet
{
514 yyGLRState
** yystates
;
515 size_t yysize
, yycapacity
;
518 struct yySemanticOption
{
522 yySemanticOption
* yynext
;
525 union yyGLRStackItem
{
527 yySemanticOption yyoption
;
539 jmp_buf yyexception_buffer
;
540 yyGLRStackItem
* yyitems
;
541 yyGLRStackItem
* yynextFree
;
543 yyGLRState
* yysplitPoint
;
544 yyGLRState
* yylastDeleted
;
545 yyGLRStateSet yytops
;
548 static void yyinitGLRStack (yyGLRStack
* yystack
, size_t yysize
);
549 static void yyexpandGLRStack (yyGLRStack
* yystack
);
550 static void yyfreeGLRStack (yyGLRStack
* yystack
);
553 yyFail (yyGLRStack
* yystack
, const char* yyformat
, ...)
555 if (yyformat
!= NULL
)
559 va_start (yyap
, yyformat
);
560 yystack
->yyerrflag
= 1;
561 vsprintf (yymsg
, yyformat
, yyap
);
564 longjmp (yystack
->yyexception_buffer
, 1);
567 #if YYDEBUG || YYERROR_VERBOSE
568 /** A printable representation of TOKEN. Valid until next call to
570 static inline const char*
571 yytokenName (yySymbol yytoken
)
573 return yytname
[yytoken
];
577 /** Perform user action for rule number YYN, with RHS length YYRHSLEN,
578 * and top stack item YYVSP. YYLVALP points to place to put semantic
579 * value ($$), and yylocp points to place for location information
580 * (@$). Returns yyok for normal return, yyaccept for YYACCEPT,
581 * yyerr for YYERROR, yyabort for YYABORT. */
583 yyuserAction (yyRuleNum yyn
, int yyrhslen
, yyGLRStackItem
* yyvsp
,
584 YYSTYPE
* yyvalp
, YYLTYPE
* yylocp
, yyGLRStack
* yystack
587 /* Avoid `unused' warnings in there are no $n. */
592 *yyvalp
= yyval_default
;
593 *yylocp
= yyloc_default
;
597 *yyvalp
= yyvsp
[1-yyrhslen
].yystate
.yysemantics
.yysval
;
598 *yylocp
= yyvsp
[1-yyrhslen
].yystate
.yyloc
;
601 # define yyval (*yyvalp)
603 # define yyerrok (yystack->yyerrState = 0)
605 # define YYACCEPT return yyaccept
607 # define YYABORT return yyabort
609 # define YYERROR return yyerr
611 # define YYRECOVERING (yystack->yyerrState != 0)
613 # define yyclearin (yychar = *(yystack->yytokenp) = YYEMPTY)
615 # define YYBACKUP(Token, Value) \
617 yyerror ("syntax error: cannot back up"); \
636 /* Line __line__ of __file__. */
637 #line __oline__ "__ofile__"
642 yyuserMerge (int yyn
, YYSTYPE
* yy0
, YYSTYPE
* yy1
)
644 YYSTYPE yyval
= *yy0
;
645 /* `Use' the arguments. */
656 /* Bison grammar-table manipulation */
658 /** Number of symbols composing the right hand side of rule #RULE. */
660 yyrhsLength (yyRuleNum yyrule
)
665 /** Left-hand-side symbol for rule #RULE. */
666 static inline yySymbol
667 yylhsNonterm (yyRuleNum yyrule
)
672 /** True iff LR state STATE has only a default reduction (regardless
675 yyisDefaultedState (yyStateNum yystate
)
677 return yypact
[yystate
] == YYPACT_NINF
;
680 /** The default reduction for STATE, assuming it has one. */
681 static inline yyRuleNum
682 yydefaultAction (yyStateNum yystate
)
684 return yydefact
[yystate
];
687 /** Set *YYACTION to the action to take in YYSTATE on seeing YYTOKEN.
689 * R < 0: Reduce on rule -R.
691 * R > 0: Shift to state R.
692 * Set *CONFLICTS to a pointer into yyconfl to 0-terminated list of
693 * conflicting reductions.
696 yygetLRActions (yyStateNum yystate
, int yytoken
,
697 int* yyaction
, const short** yyconflicts
)
699 int yyindex
= yypact
[yystate
] + yytoken
;
700 if (yyindex
< 0 || YYLAST
< yyindex
|| yycheck
[yyindex
] != yytoken
)
702 *yyaction
= -yydefact
[yystate
];
703 *yyconflicts
= yyconfl
;
705 else if (yytable
[yyindex
] != YYTABLE_NINF
)
707 *yyaction
= yytable
[yyindex
];
708 *yyconflicts
= yyconfl
+ yyconflp
[yyindex
];
713 *yyconflicts
= yyconfl
+ yyconflp
[yyindex
];
717 static inline yyStateNum
718 yyLRgotoState (yyStateNum yystate
, yySymbol yylhs
)
721 yyr
= yypgoto
[yylhs
- YYNTOKENS
] + yystate
;
722 if (0 <= yyr
&& yyr
<= YYLAST
&& yycheck
[yyr
] == yystate
)
725 return yydefgoto
[yylhs
- YYNTOKENS
];
729 yyisShiftAction (int yyaction
)
735 yyisErrorAction (int yyaction
)
737 return yyaction
== 0;
742 /** True iff the semantic value of the edge leading to STATE is
745 yyhasResolvedValue (yyGLRState
* yystate
)
747 return yystate
->yyresolved
;
751 yyaddDeferredAction (yyGLRStack
* yystack
, yyGLRState
* yystate
,
752 yyGLRState
* rhs
, yyRuleNum yyrule
)
754 yySemanticOption
* yynewItem
;
755 yynewItem
= &yystack
->yynextFree
->yyoption
;
756 yystack
->yyspaceLeft
-= 1;
757 yystack
->yynextFree
+= 1;
758 yynewItem
->yyisState
= yyfalse
;
759 yynewItem
->yystate
= rhs
;
760 yynewItem
->yyrule
= yyrule
;
761 yynewItem
->yynext
= yystate
->yysemantics
.yyfirstVal
;
762 yystate
->yysemantics
.yyfirstVal
= yynewItem
;
763 if (yystack
->yyspaceLeft
< YYHEADROOM
)
764 yyexpandGLRStack (yystack
);
769 /** Initialize SET to a singleton set containing an empty stack. */
771 yyinitStateSet (yyGLRStateSet
* yyset
)
774 yyset
->yycapacity
= 16;
775 yyset
->yystates
= (yyGLRState
**) malloc (16 * sizeof (yyset
->yystates
[0]));
776 yyset
->yystates
[0] = NULL
;
779 static void yyfreeStateSet (yyGLRStateSet
* yyset
)
781 free (yyset
->yystates
);
784 /** Initialize STACK to a single empty stack, with total maximum
785 * capacity for all stacks of SIZE. */
787 yyinitGLRStack (yyGLRStack
* yystack
, size_t yysize
)
789 yystack
->yyerrflag
= 0;
790 yystack
->yyerrState
= 0;
792 yystack
->yyspaceLeft
= yysize
;
793 yystack
->yynextFree
= yystack
->yyitems
=
794 (yyGLRStackItem
*) malloc (yysize
* sizeof (yystack
->yynextFree
[0]));
795 yystack
->yysplitPoint
= NULL
;
796 yystack
->yylastDeleted
= NULL
;
797 yyinitStateSet (&yystack
->yytops
);
800 #define YYRELOC(YYFROMITEMS,YYTOITEMS,YYX,YYTYPE) \
801 &((YYTOITEMS) - ((YYFROMITEMS) - (yyGLRStackItem*) (YYX)))->YYTYPE
803 /** If STACK is expandable, extend it. WARNING: Pointers into the
804 stack from outside should be considered invalid after this call.
805 We always expand when there are 1 or fewer items left AFTER an
806 allocation, so that we can avoid having external pointers exist
807 across an allocation. */
809 yyexpandGLRStack (yyGLRStack
* yystack
)
811 #if YYSTACKEXPANDABLE
812 yyGLRStack yynewStack
;
813 yyGLRStackItem
* yyp0
, *yyp1
;
814 size_t yysize
, yynewSize
;
816 yysize
= yystack
->yynextFree
- yystack
->yyitems
;
817 if (YYMAXDEPTH
<= yysize
)
818 yyFail (yystack
, "parsing stack overflow (%d items)", yysize
);
819 yynewSize
= 2*yysize
;
820 if (YYMAXDEPTH
< yynewSize
)
821 yynewSize
= YYMAXDEPTH
;
822 yyinitGLRStack (&yynewStack
, yynewSize
);
823 for (yyp0
= yystack
->yyitems
, yyp1
= yynewStack
.yyitems
, yyn
= yysize
;
825 yyn
-= 1, yyp0
+= 1, yyp1
+= 1)
830 yyGLRState
* yys0
= &yyp0
->yystate
;
831 yyGLRState
* yys1
= &yyp1
->yystate
;
832 if (yys0
->yypred
!= NULL
)
834 YYRELOC (yyp0
, yyp1
, yys0
->yypred
, yystate
);
835 if (! yys0
->yyresolved
&& yys0
->yysemantics
.yyfirstVal
!= NULL
)
836 yys1
->yysemantics
.yyfirstVal
=
837 YYRELOC(yyp0
, yyp1
, yys0
->yysemantics
.yyfirstVal
, yyoption
);
841 yySemanticOption
* yyv0
= &yyp0
->yyoption
;
842 yySemanticOption
* yyv1
= &yyp1
->yyoption
;
843 if (yyv0
->yystate
!= NULL
)
844 yyv1
->yystate
= YYRELOC (yyp0
, yyp1
, yyv0
->yystate
, yystate
);
845 if (yyv0
->yynext
!= NULL
)
846 yyv1
->yynext
= YYRELOC (yyp0
, yyp1
, yyv0
->yynext
, yyoption
);
849 if (yystack
->yysplitPoint
!= NULL
)
850 yystack
->yysplitPoint
= YYRELOC (yystack
->yyitems
, yynewStack
.yyitems
,
851 yystack
->yysplitPoint
, yystate
);
853 for (yyn
= 0; yyn
< yystack
->yytops
.yysize
; yyn
+= 1)
854 if (yystack
->yytops
.yystates
[yyn
] != NULL
)
855 yystack
->yytops
.yystates
[yyn
] =
856 YYRELOC (yystack
->yyitems
, yynewStack
.yyitems
,
857 yystack
->yytops
.yystates
[yyn
], yystate
);
858 free (yystack
->yyitems
);
859 yystack
->yyitems
= yynewStack
.yyitems
;
860 yystack
->yynextFree
= yynewStack
.yynextFree
+ yysize
;
861 yystack
->yyspaceLeft
= yynewStack
.yyspaceLeft
- yysize
;
865 yyFail (yystack
, "parsing stack overflow (%d items)", yysize
);
871 yyfreeGLRStack (yyGLRStack
* yystack
)
873 free (yystack
->yyitems
);
874 yyfreeStateSet (&yystack
->yytops
);
877 /** Assuming that S is a GLRState somewhere on STACK, update the
878 * splitpoint of STACK, if needed, so that it is at least as deep as
881 yyupdateSplit (yyGLRStack
* yystack
, yyGLRState
* yys
)
883 if (yystack
->yysplitPoint
!= NULL
&& yystack
->yysplitPoint
> yys
)
884 yystack
->yysplitPoint
= yys
;
887 /** Invalidate stack #K in STACK. */
889 yymarkStackDeleted (yyGLRStack
* yystack
, int yyk
)
891 if (yystack
->yytops
.yystates
[yyk
] != NULL
)
892 yystack
->yylastDeleted
= yystack
->yytops
.yystates
[yyk
];
893 yystack
->yytops
.yystates
[yyk
] = NULL
;
896 /** Undelete the last stack that was marked as deleted. Can only be
897 done once after a deletion, and only when all other stacks have
900 yyundeleteLastStack (yyGLRStack
* yystack
)
902 if (yystack
->yylastDeleted
== NULL
|| yystack
->yytops
.yysize
!= 0)
904 yystack
->yytops
.yystates
[0] = yystack
->yylastDeleted
;
905 yystack
->yytops
.yysize
= 1;
906 YYDPRINTF ((stderr
, "Restoring last deleted stack as stack #0.\n"));
907 yystack
->yylastDeleted
= NULL
;
911 yyremoveDeletes (yyGLRStack
* yystack
)
915 while (yyj
< yystack
->yytops
.yysize
)
917 if (yystack
->yytops
.yystates
[yyi
] == NULL
)
920 YYDPRINTF ((stderr
, "Removing dead stacks.\n"));
921 yystack
->yytops
.yysize
-= 1;
925 yystack
->yytops
.yystates
[yyj
] = yystack
->yytops
.yystates
[yyi
];
927 YYDPRINTF ((stderr
, "Rename stack %d -> %d.\n", yyi
, yyj
));
934 /** Shift to a new state on stack #K of STACK, corresponding to LR state
935 * LRSTATE, at input position POSN, with (resolved) semantic value SVAL. */
937 yyglrShift (yyGLRStack
* yystack
, int yyk
, yyStateNum yylrState
, size_t yyposn
,
938 YYSTYPE yysval
, YYLTYPE
* yylocp
)
940 yyGLRStackItem
* yynewItem
;
942 yynewItem
= yystack
->yynextFree
;
943 yystack
->yynextFree
+= 1;
944 yystack
->yyspaceLeft
-= 1;
945 yynewItem
->yystate
.yyisState
= yytrue
;
946 yynewItem
->yystate
.yylrState
= yylrState
;
947 yynewItem
->yystate
.yyposn
= yyposn
;
948 yynewItem
->yystate
.yyresolved
= yytrue
;
949 yynewItem
->yystate
.yypred
= yystack
->yytops
.yystates
[yyk
];
950 yystack
->yytops
.yystates
[yyk
] = &yynewItem
->yystate
;
951 yynewItem
->yystate
.yysemantics
.yysval
= yysval
;
952 yynewItem
->yystate
.yyloc
= *yylocp
;
953 if (yystack
->yyspaceLeft
< YYHEADROOM
)
954 yyexpandGLRStack (yystack
);
957 /** Shift to a new state on stack #K of STACK, to a new state
958 * corresponding to LR state LRSTATE, at input position POSN, with
959 * the (unresolved) semantic value of RHS under the action for RULE. */
961 yyglrShiftDefer (yyGLRStack
* yystack
, int yyk
, yyStateNum yylrState
,
962 size_t yyposn
, yyGLRState
* rhs
, yyRuleNum yyrule
)
964 yyGLRStackItem
* yynewItem
;
966 yynewItem
= yystack
->yynextFree
;
967 yynewItem
->yystate
.yyisState
= yytrue
;
968 yynewItem
->yystate
.yylrState
= yylrState
;
969 yynewItem
->yystate
.yyposn
= yyposn
;
970 yynewItem
->yystate
.yyresolved
= yyfalse
;
971 yynewItem
->yystate
.yypred
= yystack
->yytops
.yystates
[yyk
];
972 yynewItem
->yystate
.yysemantics
.yyfirstVal
= NULL
;
973 yystack
->yytops
.yystates
[yyk
] = &yynewItem
->yystate
;
974 yystack
->yynextFree
+= 1;
975 yystack
->yyspaceLeft
-= 1;
976 yyaddDeferredAction (yystack
, &yynewItem
->yystate
, rhs
, yyrule
);
979 /** Pop the symbols consumed by reduction #RULE from the top of stack
980 * #K of STACK, and perform the appropriate semantic action on their
981 * semantic values. Assumes that all ambiguities in semantic values
982 * have been previously resolved. Set *VALP to the resulting value,
983 * and *LOCP to the computed location (if any). Return value is as
986 yydoAction (yyGLRStack
* yystack
, int yyk
, yyRuleNum yyrule
,
987 YYSTYPE
* yyvalp
, YYLTYPE
* yylocp YY_USER_FORMALS
)
989 int yynrhs
= yyrhsLength (yyrule
);
991 if (yystack
->yysplitPoint
== NULL
)
993 /* Standard special case: single stack. */
994 yyGLRStackItem
* rhs
= (yyGLRStackItem
*) yystack
->yytops
.yystates
[yyk
];
996 yystack
->yynextFree
-= yynrhs
;
997 yystack
->yyspaceLeft
+= yynrhs
;
998 yystack
->yytops
.yystates
[0] = & yystack
->yynextFree
[-1].yystate
;
1001 *yyvalp
= yyval_default
;
1002 *yylocp
= yyloc_default
;
1006 *yyvalp
= rhs
[1-yynrhs
].yystate
.yysemantics
.yysval
;
1007 *yylocp
= rhs
[1-yynrhs
].yystate
.yyloc
;
1009 return yyuserAction (yyrule
, yynrhs
, rhs
,
1010 yyvalp
, yylocp
, yystack YY_USER_ARGS
);
1016 yyGLRStackItem yyrhsVals
[YYMAXRHS
];
1017 for (yyi
= yynrhs
-1, yys
= yystack
->yytops
.yystates
[yyk
]; 0 <= yyi
;
1018 yyi
-= 1, yys
= yys
->yypred
)
1020 assert (yys
->yypred
!= NULL
);
1021 yyrhsVals
[yyi
].yystate
.yyresolved
= yytrue
;
1022 yyrhsVals
[yyi
].yystate
.yysemantics
.yysval
= yys
->yysemantics
.yysval
;
1023 yyrhsVals
[yyi
].yystate
.yyloc
= yys
->yyloc
;
1025 yyupdateSplit (yystack
, yys
);
1026 yystack
->yytops
.yystates
[yyk
] = yys
;
1029 *yyvalp
= yyval_default
;
1030 *yylocp
= yyloc_default
;
1034 *yyvalp
= yyrhsVals
[0].yystate
.yysemantics
.yysval
;
1035 *yylocp
= yyrhsVals
[0].yystate
.yyloc
;
1037 return yyuserAction (yyrule
, yynrhs
, yyrhsVals
+ (yynrhs
-1),
1038 yyvalp
, yylocp
, yystack YY_USER_ARGS
);
1043 # define YY_REDUCE_PRINT(K, Rule)
1045 # define YY_REDUCE_PRINT(K, Rule) \
1048 yy_reduce_print (K, Rule); \
1051 /*----------------------------------------------------------.
1052 | Report that the RULE is going to be reduced on stack #K. |
1053 `----------------------------------------------------------*/
1056 yy_reduce_print (size_t yyk
, yyRuleNum yyrule
)
1059 YYDPRINTF ((stderr
, "Reducing stack %d by rule %d (line %d),",
1060 yyk
, yyrule
- 1, yyrline
[yyrule
]));
1061 /* Print the symbols being reduced, and their result. */
1062 for (yyi
= yyprhs
[yyrule
]; 0 <= yyrhs
[yyi
]; yyi
++)
1063 YYFPRINTF (stderr
, "%s ", yytokenName (yyrhs
[yyi
]));
1064 YYFPRINTF (stderr
, " -> %s\n", yytokenName (yyr1
[yyrule
]));
1068 /** Pop items off stack #K of STACK according to grammar rule RULE,
1069 * and push back on the resulting nonterminal symbol. Perform the
1070 * semantic action associated with RULE and store its value with the
1071 * newly pushed state, if FORCEEVAL or if STACK is currently
1072 * unambiguous. Otherwise, store the deferred semantic action with
1073 * the new state. If the new state would have an identical input
1074 * position, LR state, and predecessor to an existing state on the stack,
1075 * it is identified with that existing state, eliminating stack #K from
1076 * the STACK. In this case, the (necessarily deferred) semantic value is
1077 * added to the options for the existing state's semantic value.
1079 static inline YYRESULTTAG
1080 yyglrReduce (yyGLRStack
* yystack
, size_t yyk
, yyRuleNum yyrule
,
1081 bool yyforceEval YY_USER_FORMALS
)
1083 size_t yyposn
= yystack
->yytops
.yystates
[yyk
]->yyposn
;
1085 if (yyforceEval
|| yystack
->yysplitPoint
== NULL
)
1090 YY_REDUCE_PRINT (yyk
, yyrule
);
1091 YYCHK (yydoAction (yystack
, yyk
, yyrule
, &yysval
, &yyloc YY_USER_ARGS
));
1092 yyglrShift (yystack
, yyk
,
1093 yyLRgotoState (yystack
->yytops
.yystates
[yyk
]->yylrState
,
1094 yylhsNonterm (yyrule
)),
1095 yyposn
, yysval
, &yyloc
);
1096 YYDPRINTF ((stderr
, "Stack %d entering state %d\n",
1097 yyk
, yystack
->yytops
.yystates
[yyk
]->yylrState
));
1103 yyGLRState
* yys
, *yys0
= yystack
->yytops
.yystates
[yyk
];
1104 yyStateNum yynewLRState
;
1106 for (yys
= yystack
->yytops
.yystates
[yyk
], yyn
= yyrhsLength (yyrule
);
1110 assert (yys
!= NULL
);
1112 yyupdateSplit (yystack
, yys
);
1113 yynewLRState
= yyLRgotoState (yys
->yylrState
, yylhsNonterm (yyrule
));
1115 "Reduced stack %d by rule #%d; action deferred. "
1116 "Now in state %d.\n",
1117 yyk
, yyrule
-1, yynewLRState
));
1118 for (yyi
= 0; yyi
< yystack
->yytops
.yysize
; yyi
+= 1)
1119 if (yyi
!= yyk
&& yystack
->yytops
.yystates
[yyi
] != NULL
)
1121 yyGLRState
* yyp
, *yysplit
= yystack
->yysplitPoint
;
1122 yyp
= yystack
->yytops
.yystates
[yyi
];
1123 while (yyp
!= yys
&& yyp
!= yysplit
&& yyp
->yyposn
>= yyposn
)
1125 if (yyp
->yylrState
== yynewLRState
&& yyp
->yypred
== yys
)
1127 yyaddDeferredAction (yystack
, yyp
, yys0
, yyrule
);
1128 yymarkStackDeleted (yystack
, yyk
);
1129 YYDPRINTF ((stderr
, "Merging stack %d into stack %d.\n",
1136 yystack
->yytops
.yystates
[yyk
] = yys
;
1137 yyglrShiftDefer (yystack
, yyk
, yynewLRState
, yyposn
, yys0
, yyrule
);
1143 yysplitStack (yyGLRStack
* yystack
, int yyk
)
1145 if (yystack
->yysplitPoint
== NULL
)
1148 yystack
->yysplitPoint
= yystack
->yytops
.yystates
[yyk
];
1150 if (yystack
->yytops
.yysize
>= yystack
->yytops
.yycapacity
)
1152 yystack
->yytops
.yycapacity
*= 2;
1153 yystack
->yytops
.yystates
=
1154 (yyGLRState
**) realloc (yystack
->yytops
.yystates
,
1155 yystack
->yytops
.yycapacity
1156 * sizeof (yyGLRState
*));
1158 yystack
->yytops
.yystates
[yystack
->yytops
.yysize
]
1159 = yystack
->yytops
.yystates
[yyk
];
1160 yystack
->yytops
.yysize
+= 1;
1161 return yystack
->yytops
.yysize
-1;
1164 /** True iff Y0 and Y1 represent identical options at the top level.
1165 * That is, they represent the same rule applied to RHS symbols
1166 * that produce the same terminal symbols. */
1168 yyidenticalOptions (yySemanticOption
* yyy0
, yySemanticOption
* yyy1
)
1170 if (yyy0
->yyrule
== yyy1
->yyrule
)
1172 yyGLRState
*yys0
, *yys1
;
1174 for (yys0
= yyy0
->yystate
, yys1
= yyy1
->yystate
,
1175 yyn
= yyrhsLength (yyy0
->yyrule
);
1177 yys0
= yys0
->yypred
, yys1
= yys1
->yypred
, yyn
-= 1)
1178 if (yys0
->yyposn
!= yys1
->yyposn
)
1186 /** Assuming identicalOptions (Y0,Y1), (destructively) merge the
1187 * alternative semantic values for the RHS-symbols of Y1 into the
1188 * corresponding semantic value sets of the symbols of Y0. */
1190 yymergeOptionSets (yySemanticOption
* yyy0
, yySemanticOption
* yyy1
)
1192 yyGLRState
*yys0
, *yys1
;
1194 for (yys0
= yyy0
->yystate
, yys1
= yyy1
->yystate
,
1195 yyn
= yyrhsLength (yyy0
->yyrule
);
1197 yys0
= yys0
->yypred
, yys1
= yys1
->yypred
, yyn
-= 1)
1200 else if (! yys0
->yyresolved
&& ! yys1
->yyresolved
)
1202 yySemanticOption
* yyz
;
1203 for (yyz
= yys0
->yysemantics
.yyfirstVal
; yyz
->yynext
!= NULL
;
1206 yyz
->yynext
= yys1
->yysemantics
.yyfirstVal
;
1210 /** Y0 and Y1 represent two possible actions to take in a given
1211 * parsing state; return 0 if no combination is possible,
1212 * 1 if user-mergeable, 2 if Y0 is preferred, 3 if Y1 is preferred. */
1214 yypreference (yySemanticOption
* y0
, yySemanticOption
* y1
)
1216 yyRuleNum r0
= y0
->yyrule
, r1
= y1
->yyrule
;
1217 int p0
= yydprec
[r0
], p1
= yydprec
[r1
];
1221 if (yymerger
[r0
] == 0 || yymerger
[r0
] != yymerger
[r1
])
1226 if (p0
== 0 || p1
== 0)
1235 static YYRESULTTAG
yyresolveValue (yySemanticOption
* yyoptionList
,
1236 yyGLRStack
* yystack
, YYSTYPE
* yyvalp
,
1237 YYLTYPE
* yylocp YY_USER_FORMALS
);
1240 yyresolveStates (yyGLRState
* yys
, int yyn
, yyGLRStack
* yystack YY_USER_FORMALS
)
1245 assert (yys
->yypred
!= NULL
);
1246 yyflag
= yyresolveStates (yys
->yypred
, yyn
-1, yystack YY_USER_ARGS
);
1249 if (! yys
->yyresolved
)
1251 yyflag
= yyresolveValue (yys
->yysemantics
.yyfirstVal
, yystack
,
1252 &yys
->yysemantics
.yysval
, &yys
->yyloc
1256 yys
->yyresolved
= yytrue
;
1263 yyresolveAction (yySemanticOption
* yyopt
, yyGLRStack
* yystack
,
1264 YYSTYPE
* yyvalp
, YYLTYPE
* yylocp YY_USER_FORMALS
)
1266 yyGLRStackItem yyrhsVals
[YYMAXRHS
];
1270 yynrhs
= yyrhsLength (yyopt
->yyrule
);
1271 YYCHK (yyresolveStates (yyopt
->yystate
, yynrhs
, yystack YY_USER_ARGS
));
1272 for (yyi
= yynrhs
-1, yys
= yyopt
->yystate
; 0 <= yyi
;
1273 yyi
-= 1, yys
= yys
->yypred
)
1275 assert (yys
->yypred
!= NULL
);
1276 yyrhsVals
[yyi
].yystate
.yyresolved
= yytrue
;
1277 yyrhsVals
[yyi
].yystate
.yysemantics
.yysval
= yys
->yysemantics
.yysval
;
1278 yyrhsVals
[yyi
].yystate
.yyloc
= yys
->yyloc
;
1280 return yyuserAction (yyopt
->yyrule
, yynrhs
, yyrhsVals
+ (yynrhs
-1),
1281 yyvalp
, yylocp
, yystack YY_USER_ARGS
);
1285 static yyGLRState YYLEFTMOST_STATE
=
1287 0, 0, -1, NULL
, 0, { NULL
},
1290 #if YYLTYPE_IS_TRIVIAL
1291 ]b4_location_if([ 0, 0, 0, 0])[
1297 yyreportTree (yySemanticOption
* yyx
, int yyindent
)
1299 int yynrhs
= yyrhsLength (yyx
->yyrule
);
1302 yyGLRState
* yystates
[YYMAXRHS
];
1304 for (yyi
= yynrhs
, yys
= yyx
->yystate
; 0 < yyi
; yyi
-= 1, yys
= yys
->yypred
)
1305 yystates
[yyi
] = yys
;
1307 yystates
[0] = &YYLEFTMOST_STATE
;
1311 if (yyx
->yystate
->yyposn
< yys
->yyposn
+ 1)
1312 YYFPRINTF (stderr
, "%*s%s -> <Rule %d, empty>\n",
1313 yyindent
, "", yytokenName (yylhsNonterm (yyx
->yyrule
)),
1316 YYFPRINTF (stderr
, "%*s%s -> <Rule %d, tokens %d .. %d>\n",
1317 yyindent
, "", yytokenName (yylhsNonterm (yyx
->yyrule
)),
1318 yyx
->yyrule
, yys
->yyposn
+1, yyx
->yystate
->yyposn
);
1319 for (yyi
= 1; yyi
<= yynrhs
; yyi
+= 1)
1321 if (yystates
[yyi
]->yyresolved
)
1323 if (yystates
[yyi
-1]->yyposn
+1 > yystates
[yyi
]->yyposn
)
1324 YYFPRINTF (stderr
, "%*s%s <empty>\n", yyindent
+2, "",
1325 yytokenName (yyrhs
[yyprhs
[yyx
->yyrule
]+yyi
-1]));
1327 YYFPRINTF (stderr
, "%*s%s <tokens %d .. %d>\n", yyindent
+2, "",
1328 yytokenName (yyrhs
[yyprhs
[yyx
->yyrule
]+yyi
-1]),
1329 yystates
[yyi
-1]->yyposn
+1, yystates
[yyi
]->yyposn
);
1332 yyreportTree (yystates
[yyi
]->yysemantics
.yyfirstVal
, yyindent
+2);
1338 yyreportAmbiguity (yySemanticOption
* yyx0
, yySemanticOption
* yyx1
,
1339 yyGLRStack
* yystack
)
1341 /* `Unused' warnings. */
1346 YYFPRINTF (stderr
, "Ambiguity detected.\n");
1347 YYFPRINTF (stderr
, "Option 1,\n");
1348 yyreportTree (yyx0
, 2);
1349 YYFPRINTF (stderr
, "\nOption 2,\n");
1350 yyreportTree (yyx1
, 2);
1351 YYFPRINTF (stderr
, "\n");
1353 yyFail (yystack
, "ambiguity detected");
1357 /** Resolve the ambiguity represented by OPTIONLIST, perform the indicated
1358 * actions, and return the result. */
1360 yyresolveValue (yySemanticOption
* yyoptionList
, yyGLRStack
* yystack
,
1361 YYSTYPE
* yyvalp
, YYLTYPE
* yylocp YY_USER_FORMALS
)
1363 yySemanticOption
* yybest
;
1364 yySemanticOption
* yyp
;
1367 yybest
= yyoptionList
;
1369 for (yyp
= yyoptionList
->yynext
; yyp
!= NULL
; yyp
= yyp
->yynext
)
1371 if (yyidenticalOptions (yybest
, yyp
))
1372 yymergeOptionSets (yybest
, yyp
);
1374 switch (yypreference (yybest
, yyp
))
1377 yyreportAmbiguity (yybest
, yyp
, yystack
);
1393 int yyprec
= yydprec
[yybest
->yyrule
];
1394 YYCHK (yyresolveAction (yybest
, yystack
, yyvalp
, yylocp YY_USER_ARGS
));
1395 for (yyp
= yybest
->yynext
; yyp
!= NULL
; yyp
= yyp
->yynext
)
1397 if (yyprec
== yydprec
[yyp
->yyrule
])
1401 YYCHK (yyresolveAction (yyp
, yystack
, &yyval1
, &yydummy YY_USER_ARGS
));
1402 *yyvalp
= yyuserMerge (yymerger
[yyp
->yyrule
], yyvalp
, &yyval1
);
1408 return yyresolveAction (yybest
, yystack
, yyvalp
, yylocp YY_USER_ARGS
);
1412 yyresolveStack (yyGLRStack
* yystack YY_USER_FORMALS
)
1414 if (yystack
->yysplitPoint
!= NULL
)
1419 for (yyn
= 0, yys
= yystack
->yytops
.yystates
[0];
1420 yys
!= yystack
->yysplitPoint
;
1421 yys
= yys
->yypred
, yyn
+= 1)
1423 YYCHK (yyresolveStates (yystack
->yytops
.yystates
[0], yyn
, yystack
1430 yycompressStack (yyGLRStack
* yystack
)
1432 yyGLRState
* yyp
, *yyq
, *yyr
;
1434 if (yystack
->yytops
.yysize
!= 1 || yystack
->yysplitPoint
== NULL
)
1437 for (yyp
= yystack
->yytops
.yystates
[0], yyq
= yyp
->yypred
, yyr
= NULL
;
1438 yyp
!= yystack
->yysplitPoint
;
1439 yyr
= yyp
, yyp
= yyq
, yyq
= yyp
->yypred
)
1442 yystack
->yyspaceLeft
+= yystack
->yynextFree
- yystack
->yyitems
;
1443 yystack
->yynextFree
= ((yyGLRStackItem
*) yystack
->yysplitPoint
) + 1;
1444 yystack
->yyspaceLeft
-= yystack
->yynextFree
- yystack
->yyitems
;
1445 yystack
->yysplitPoint
= NULL
;
1446 yystack
->yylastDeleted
= NULL
;
1450 yystack
->yynextFree
->yystate
= *yyr
;
1452 yystack
->yynextFree
->yystate
.yypred
= & yystack
->yynextFree
[-1].yystate
;
1453 yystack
->yytops
.yystates
[0] = &yystack
->yynextFree
->yystate
;
1454 yystack
->yynextFree
+= 1;
1455 yystack
->yyspaceLeft
-= 1;
1460 yyprocessOneStack (yyGLRStack
* yystack
, int yyk
,
1461 size_t yyposn
, YYSTYPE
* yylvalp
, YYLTYPE
* yyllocp
1465 const short* yyconflicts
;
1467 yySymbol
* const yytokenp
= yystack
->yytokenp
;
1469 while (yystack
->yytops
.yystates
[yyk
] != NULL
)
1471 yyStateNum yystate
= yystack
->yytops
.yystates
[yyk
]->yylrState
;
1473 assert (yystate
!= YYFINAL
);
1474 if (yyisDefaultedState (yystate
))
1476 yyrule
= yydefaultAction (yystate
);
1479 YYDPRINTF ((stderr
, "Stack %d dies.\n", yyk
));
1480 yymarkStackDeleted (yystack
, yyk
);
1483 YYCHK (yyglrReduce (yystack
, yyk
, yyrule
, yyfalse YY_USER_ARGS
));
1487 if (*yytokenp
== YYEMPTY
)
1489 YYDPRINTF ((stderr
, "Reading a token: "));
1491 *yytokenp
= YYTRANSLATE(yychar
);
1492 YYDPRINTF ((stderr
, "Next token is %s\n",
1493 yytokenName (*yytokenp
)));
1495 yygetLRActions (yystate
, *yytokenp
, &yyaction
, &yyconflicts
);
1497 while (*yyconflicts
!= 0)
1499 int yynewStack
= yysplitStack (yystack
, yyk
);
1500 YYDPRINTF ((stderr
, "Splitting off stack %d from %d.\n",
1502 YYCHK (yyglrReduce (yystack
, yynewStack
,
1503 *yyconflicts
, yyfalse YY_USER_ARGS
));
1504 YYCHK (yyprocessOneStack (yystack
, yynewStack
, yyposn
,
1505 yylvalp
, yyllocp YY_USER_ARGS
));
1509 if (yyisShiftAction (yyaction
))
1511 YYDPRINTF ((stderr
, "Shifting token %s on stack %d, ",
1512 yytokenName (*yytokenp
), yyk
));
1513 yyglrShift (yystack
, yyk
, yyaction
, yyposn
+1, *yylvalp
, yyllocp
);
1514 YYDPRINTF ((stderr
, "which is now in state #%d\n",
1515 yystack
->yytops
.yystates
[yyk
]->yylrState
));
1518 else if (yyisErrorAction (yyaction
))
1520 YYDPRINTF ((stderr
, "Stack %d dies.\n", yyk
));
1521 yymarkStackDeleted (yystack
, yyk
);
1525 YYCHK (yyglrReduce (yystack
, yyk
, -yyaction
, yyfalse YY_USER_ARGS
));
1532 yyreportParseError (yyGLRStack
* yystack
, YYSTYPE
* yylvalp
, YYLTYPE
* yyllocp
)
1534 /* `Unused' warnings. */
1538 if (yystack
->yyerrState
== 0)
1541 yySymbol
* const yytokenp
= yystack
->yytokenp
;
1542 int yyn
, yyx
, yycount
;
1544 const char* yyprefix
;
1547 yyn
= yypact
[yystack
->yytops
.yystates
[0]->yylrState
];
1548 if (YYPACT_NINF
< yyn
&& yyn
< YYLAST
)
1551 /* Start YYX at -YYN if negative to avoid negative indexes in
1553 yysize
= sizeof ("parse error, unexpected ")
1554 + strlen (yytokenName (*yytokenp
));
1555 yyprefix
= ", expecting ";
1556 for (yyx
= yyn
< 0 ? -yyn
: 0; yyx
< yytname_size
&& yycount
<= 5;
1558 if (yycheck
[yyx
+ yyn
] == yyx
&& yyx
!= YYTERROR
)
1559 yysize
+= strlen (yytokenName (yyx
)) + strlen (yyprefix
),
1560 yycount
+= 1, yyprefix
= " or ";
1561 yymsg
= yyp
= (char*) malloc (yysize
);
1562 sprintf (yyp
, "parse error, unexpected %s",
1563 yytokenName (*yytokenp
));
1564 yyp
+= strlen (yyp
);
1567 yyprefix
= ", expecting ";
1568 for (yyx
= yyn
< 0 ? -yyn
: 0; yyx
< yytname_size
; yyx
+= 1)
1569 if (yycheck
[yyx
+ yyn
] == yyx
&& yyx
!= YYTERROR
)
1571 sprintf (yyp
, "%s%s", yyprefix
, yytokenName (yyx
));
1572 yyp
+= strlen (yyp
);
1581 yyerror ("parse error");
1586 /* Recover from a syntax error on YYSTACK, assuming that YYTOKENP,
1587 YYLVALP, and YYLLOCP point to the syntactic category, semantic
1588 value, and location of the lookahead. */
1590 yyrecoverParseError (yyGLRStack
* yystack
, YYSTYPE
* yylvalp
, YYLTYPE
* yyllocp
)
1592 yySymbol
* const yytokenp
= yystack
->yytokenp
;
1596 if (yystack
->yyerrState
== 0)
1597 yystack
->yyerrState
= 3;
1598 else if (yystack
->yyerrState
== 3)
1599 /* We just shifted the error token and (perhaps) took some
1600 reductions. Skip tokens until we can proceed. */
1603 if (*yytokenp
== YYEOF
)
1604 yyFail (yystack
, NULL
);
1605 if (*yytokenp
!= YYEMPTY
)
1606 YYDPRINTF ((stderr
, "Discarding token %s\n",
1607 yytokenName (*yytokenp
)));
1608 YYDPRINTF ((stderr
, "Reading a token: "));
1610 *yytokenp
= YYTRANSLATE (yychar
);
1611 YYDPRINTF ((stderr
, "Next token is %s\n", yytokenName (*yytokenp
)));
1612 yyj
= yypact
[yystack
->yytops
.yystates
[0]->yylrState
];
1613 if (yyj
== YYPACT_NINF
)
1614 /* Something's not right; we shouldn't be here. */
1615 yyFail (yystack
, NULL
);
1617 if (yyj
< 0 || YYLAST
< yyj
|| yycheck
[yyj
] != *yytokenp
)
1619 if (yydefact
[yystack
->yytops
.yystates
[0]->yylrState
] != 0)
1622 else if (yytable
[yyj
] != 0 && yytable
[yyj
] != YYTABLE_NINF
)
1626 /* Reduce to one stack. */
1627 for (yyk
= 0; yyk
< yystack
->yytops
.yysize
; yyk
+= 1)
1628 if (yystack
->yytops
.yystates
[yyk
] != NULL
)
1630 if (yyk
>= yystack
->yytops
.yysize
)
1631 yyFail (yystack
, NULL
);
1632 for (yyk
+= 1; yyk
< yystack
->yytops
.yysize
; yyk
+= 1)
1633 yymarkStackDeleted (yystack
, yyk
);
1634 yyremoveDeletes (yystack
);
1635 yycompressStack (yystack
);
1637 /* Now pop stack until we find a state that shifts the error token. */
1638 while (yystack
->yytops
.yystates
[0] != NULL
)
1640 yyj
= yypact
[yystack
->yytops
.yystates
[0]->yylrState
] + YYTERROR
;
1641 if (yyj
!= YYPACT_NINF
+ YYTERROR
&& yyj
>= 0 && yyj
<= YYLAST
&&
1642 yycheck
[yyj
] == YYTERROR
&& yyisShiftAction (yytable
[yyj
]))
1644 yyglrShift (yystack
, 0, yytable
[yyj
],
1645 yystack
->yytops
.yystates
[0]->yyposn
, *yylvalp
, yyllocp
);
1648 yystack
->yytops
.yystates
[0] = yystack
->yytops
.yystates
[0]->yypred
;
1649 yystack
->yynextFree
-= 1;
1650 yystack
->yyspaceLeft
+= 1;
1652 if (yystack
->yytops
.yystates
[0] == NULL
)
1653 yyFail (yystack
, NULL
);
1656 #define YYCHK1(YYE) \
1662 yystack.yyerrflag = 1; \
1665 yystack.yyerrflag = 0; \
1668 goto yyuser_error; \
1677 ]b4_c_ansi_function_def([yyparse
], [int], b4_parse_param
)[
1687 #define yychar (yystack.yyrawchar)
1690 YYSTYPE
* const yylvalp
= &yylval
;
1691 YYLTYPE
* const yyllocp
= &yylloc
;
1693 yyinitGLRStack (&yystack
, YYINITDEPTH
);
1694 yystack
.yytokenp
= &yytoken
;
1696 YYDPRINTF ((stderr
, "Starting parse\n"));
1698 if (setjmp (yystack
.yyexception_buffer
) != 0)
1701 yyglrShift (&yystack
, 0, 0, 0, yyval_default
, &yyloc_default
);
1707 /* For efficiency, we have two loops, the first of which is
1708 specialized to deterministic operation (single stack, no
1709 potential ambiguity). */
1716 const short* yyconflicts
;
1718 yyStateNum yystate
= yystack
.yytops
.yystates
[0]->yylrState
;
1719 if (yystate
== YYFINAL
)
1721 if (yyisDefaultedState (yystate
))
1723 yyrule
= yydefaultAction (yystate
);
1726 yyreportParseError (&yystack
, yylvalp
, yyllocp
);
1729 YYCHK1 (yyglrReduce (&yystack
, 0, yyrule
, yytrue YY_USER_ARGS
));
1733 if (yytoken
== YYEMPTY
)
1735 YYDPRINTF ((stderr
, "Reading a token: "));
1737 yytoken
= YYTRANSLATE (yychar
);
1738 YYDPRINTF ((stderr
, "Next token is %s\n",
1739 yytokenName (yytoken
)));
1741 yygetLRActions (yystate
, yytoken
, &yyaction
, &yyconflicts
);
1742 if (*yyconflicts
!= 0)
1744 if (yyisShiftAction (yyaction
))
1746 YYDPRINTF ((stderr
, "Shifting token %s, ",
1747 yytokenName (yytoken
)));
1748 if (yytoken
!= YYEOF
)
1751 yyglrShift (&yystack
, 0, yyaction
, yyposn
, yylval
, yyllocp
);
1752 if (0 < yystack
.yyerrState
)
1753 yystack
.yyerrState
-= 1;
1754 YYDPRINTF ((stderr
, "Entering state %d\n",
1755 yystack
.yytops
.yystates
[0]->yylrState
));
1757 else if (yyisErrorAction (yyaction
))
1759 yyreportParseError (&yystack
, yylvalp
, yyllocp
);
1763 YYCHK1 (yyglrReduce (&yystack
, 0, -yyaction
, yytrue YY_USER_ARGS
));
1770 int yyn
= yystack
.yytops
.yysize
;
1771 for (yys
= 0; yys
< yyn
; yys
+= 1)
1772 YYCHK1 (yyprocessOneStack (&yystack
, yys
, yyposn
,
1773 yylvalp
, yyllocp YY_USER_ARGS
));
1776 yyremoveDeletes (&yystack
);
1777 if (yystack
.yytops
.yysize
== 0)
1779 yyundeleteLastStack (&yystack
);
1780 if (yystack
.yytops
.yysize
== 0)
1781 yyFail (&yystack
, "parse error");
1782 YYCHK1 (yyresolveStack (&yystack YY_USER_ARGS
));
1783 YYDPRINTF ((stderr
, "Returning to deterministic operation.\n"));
1784 yyreportParseError (&yystack
, yylvalp
, yyllocp
);
1787 else if (yystack
.yytops
.yysize
== 1)
1789 YYCHK1 (yyresolveStack (&yystack YY_USER_ARGS
));
1790 YYDPRINTF ((stderr
, "Returning to deterministic operation.\n"));
1791 yycompressStack (&yystack
);
1797 yyrecoverParseError (&yystack
, yylvalp
, yyllocp
);
1798 yyposn
= yystack
.yytops
.yystates
[0]->yyposn
;
1803 yyfreeGLRStack (&yystack
);
1804 return yystack
.yyerrflag
;
1807 /* DEBUGGING ONLY */
1808 static void yypstack (yyGLRStack
* yystack
, int yyk
) ATTRIBUTE_UNUSED
;
1809 static void yypdumpstack (yyGLRStack
* yystack
) ATTRIBUTE_UNUSED
;
1812 yy_yypstack (yyGLRState
* yys
)
1816 yy_yypstack (yys
->yypred
);
1817 fprintf (stderr
, " -> ");
1819 fprintf (stderr
, "%d@%lu", yys
->yylrState
, (unsigned long) yys
->yyposn
);
1823 yypstates (yyGLRState
* yyst
)
1826 fprintf (stderr
, "<null>");
1829 fprintf (stderr
, "\n");
1833 yypstack (yyGLRStack
* yystack
, int yyk
)
1835 yypstates (yystack
->yytops
.yystates
[yyk
]);
1838 #define YYINDEX(YYX) \
1839 ((YYX) == NULL ? -1 : (yyGLRStackItem*) (YYX) - yystack->yyitems)
1843 yypdumpstack (yyGLRStack
* yystack
)
1845 yyGLRStackItem
* yyp
;
1847 for (yyp
= yystack
->yyitems
; yyp
< yystack
->yynextFree
; yyp
+= 1)
1849 fprintf (stderr
, "%3lu. ", (unsigned long) (yyp
- yystack
->yyitems
));
1852 fprintf (stderr
, "Res: %d, LR State: %d, posn: %lu, pred: %ld",
1853 yyp
->yystate
.yyresolved
, yyp
->yystate
.yylrState
,
1854 (unsigned long) yyp
->yystate
.yyposn
,
1855 (long) YYINDEX (yyp
->yystate
.yypred
));
1856 if (! yyp
->yystate
.yyresolved
)
1857 fprintf (stderr
, ", firstVal: %ld",
1858 (long) YYINDEX (yyp
->yystate
.yysemantics
.yyfirstVal
));
1862 fprintf (stderr
, "Option. rule: %d, state: %ld, next: %ld",
1863 yyp
->yyoption
.yyrule
,
1864 (long) YYINDEX (yyp
->yyoption
.yystate
),
1865 (long) YYINDEX (yyp
->yyoption
.yynext
));
1867 fprintf (stderr
, "\n");
1869 fprintf (stderr
, "Tops:");
1870 for (yyi
= 0; yyi
< yystack
->yytops
.yysize
; yyi
+= 1)
1871 fprintf (stderr
, "%lu: %ld; ", (unsigned long) yyi
,
1872 (long) YYINDEX (yystack
->yytops
.yystates
[yyi
]));
1873 fprintf (stderr
, "\n");
1878 m4_if(b4_defines_flag
, 0, [],
1879 [#output "b4_output_header_name"
1880 b4_copyright([Skeleton parser
for GLR parsing with Bison
], [2002])
1881 #ifndef b4_header_guard
1882 # define b4_header_guard
1884 b4_token_defines(b4_tokens
)
1887 m4_ifdef([b4_stype
],
1888 [#line b4_stype_line "b4_filename"
1889 typedef union b4_stype yystype
;
1890 /* Line __line__ of __file__. */
1891 #line __oline__ "__ofile__"],
1892 [typedef int yystype
;])
1893 # define YYSTYPE yystype
1897 [extern YYSTYPE b4_prefix
[]lval
;])
1901 typedef struct yyltype
1908 # define YYLTYPE yyltype
1912 [extern YYLTYPE b4_prefix
[]lloc
;])
1914 #endif /* not b4_header_guard */