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
187 # define YYLTYPE ]b4_location_type[
188 # define YYLTYPE_IS_TRIVIAL 1
191 /* Default (constant) values used for initialization for null
192 right-hand sides. Unlike the standard bison.simple template,
193 here we set the default values of the $$ and $@ to zeroed-out
194 values. Since the default value of these quantities is undefined,
195 this behavior is technically correct. */
196 static YYSTYPE yyval_default
;
197 static YYLTYPE yyloc_default
;
199 /* Copy the second part of user declarations. */
202 ]/* Line __line__ of __file__. */
203 #line __oline__ "__ofile__"
205 #if ! defined (__cplusplus)
211 #if defined (__STDC__) || defined (__cplusplus)
212 typedef signed char yysigned_char
;
214 typedef short yysigned_char
;
221 #ifndef __attribute__
222 /* This feature is available in gcc versions 2.5 and later. */
223 # if !defined (__GNUC__) || __GNUC__ < 2 || \
224 (__GNUC__ == 2 && __GNUC_MINOR__ < 5) || __STRICT_ANSI__
225 # define __attribute__(Spec) /* empty */
229 #ifndef ATTRIBUTE_UNUSED
230 # define ATTRIBUTE_UNUSED __attribute__ ((__unused__))
233 #if ! defined (__GNUC__)
237 /* YYFINAL -- State number of the termination state. */
238 #define YYFINAL ]b4_final_state_number[
239 /* YYLAST -- Last index in YYTABLE. */
240 #define YYLAST ]b4_last[
242 /* YYNTOKENS -- Number of terminals. */
243 #define YYNTOKENS ]b4_tokens_number[
244 /* YYNNTS -- Number of nonterminals. */
245 #define YYNNTS ]b4_nterms_number[
246 /* YYNRULES -- Number of rules. */
247 #define YYNRULES ]b4_rules_number[
248 /* YYNRULES -- Number of states. */
249 #define YYNSTATES ]b4_states_number[
250 /* YYMAXRHS -- Maximum number of symbols on right-hand side of rule. */
251 #define YYMAXRHS ]b4_r2_max[
253 /* YYTRANSLATE(X) -- Bison symbol number corresponding to X. */
254 #define YYUNDEFTOK ]b4_undef_token_number[
255 #define YYMAXUTOK ]b4_user_token_number_max[
257 #define YYTRANSLATE(YYX) \
258 ((unsigned)(YYX) <= YYMAXUTOK ? yytranslate[YYX] : YYUNDEFTOK)
260 /* YYTRANSLATE[YYLEX] -- Bison symbol number corresponding to YYLEX. */
261 static const ]b4_int_type_for([b4_translate
])[ yytranslate
[] =
267 /* YYPRHS[YYN] -- Index of the first RHS symbol of rule number YYN in
269 static const ]b4_int_type_for([b4_prhs
])[ yyprhs
[] =
274 /* YYRHS -- A `-1'-separated list of the rules' RHS. */
275 static const ]b4_int_type_for([b4_rhs
])[ yyrhs
[] =
280 /* YYRLINE[YYN] -- source line where rule number YYN was defined. */
281 static const ]b4_int_type_for([b4_rline
])[ yyrline
[] =
287 #if (YYDEBUG) || YYERROR_VERBOSE
288 /* YYTNME[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM.
289 First, the terminals, then, starting at YYNTOKENS, nonterminals. */
290 static const char *const yytname
[] =
295 #define yytname_size ((int) (sizeof (yytname) / sizeof (yytname[0])))
298 /* YYR1[YYN] -- Symbol number of symbol that rule YYN derives. */
299 static const ]b4_int_type_for([b4_r1
])[ yyr1
[] =
304 /* YYR2[YYN] -- Number of symbols composing right hand side of rule YYN. */
305 static const ]b4_int_type_for([b4_r2
])[ yyr2
[] =
310 /* YYDPREC[RULE-NUM] -- Dynamic precedence of rule #RULE-NUM (0 if none). */
311 static const ]b4_int_type_for([b4_dprec
])[ yydprec
[] =
316 /* YYMERGER[RULE-NUM] -- Index of merging function for rule #RULE-NUM. */
317 static const ]b4_int_type_for([b4_merger
])[ yymerger
[] =
322 /* YYDEFACT[S] -- default rule to reduce with in state S when YYTABLE
323 doesn't specify something else to do. Zero means the default is an
325 static const ]b4_int_type_for([b4_defact
])[ yydefact
[] =
330 /* YYPDEFGOTO[NTERM-NUM]. */
331 static const ]b4_int_type_for([b4_defgoto
])[ yydefgoto
[] =
336 /* YYPACT[STATE-NUM] -- Index in YYTABLE of the portion describing
338 #define YYPACT_NINF ]b4_pact_ninf[
339 static const ]b4_int_type_for([b4_pact
])[ yypact
[] =
344 /* YYPGOTO[NTERM-NUM]. */
345 static const ]b4_int_type_for([b4_pgoto
])[ yypgoto
[] =
350 /* YYTABLE[YYPACT[STATE-NUM]]. What to do in state STATE-NUM. If
351 positive, shift that token. If negative, reduce the rule which
352 number is the opposite. If zero, do what YYDEFACT says.
353 If YYTABLE_NINF, parse error. */
354 #define YYTABLE_NINF ]b4_table_ninf[
355 static const ]b4_int_type_for([b4_table
])[ yytable
[] =
360 /* YYCONFLP[YYPACT[STATE-NUM]] -- Pointer into YYCONFL of start of
361 list of conflicting reductions corresponding to action entry for
362 state STATE-NUM in yytable. 0 means no conflicts. The list in
363 yyconfl is terminated by a rule number of 0. */
364 static const ]b4_int_type_for([b4_conflict_list_heads
])[ yyconflp
[] =
366 ]b4_conflict_list_heads
[
369 /* YYCONFL[I] -- lists of conflicting rule numbers, each terminated by
370 0, pointed into by YYCONFLP. */
371 ]dnl Do
not use b4_int_type_for here
, since there are places where
372 dnl pointers onto yyconfl are taken
, which type is
"short *".
373 dnl We probably ought to introduce a type
for confl
.
374 [static const short yyconfl
[] =
376 ]b4_conflicting_rules
[
379 static const ]b4_int_type_for([b4_check
])[ yycheck
[] =
385 /* Prevent warning if -Wmissing-prototypes. */
386 ]b4_c_ansi_function_decl([yyparse
], [int], b4_parse_param
)[
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
)
586 /* Avoid `unused' warnings in there are no $n. */
591 *yyvalp
= yyval_default
;
592 *yylocp
= yyloc_default
;
596 *yyvalp
= yyvsp
[1-yyrhslen
].yystate
.yysemantics
.yysval
;
597 *yylocp
= yyvsp
[1-yyrhslen
].yystate
.yyloc
;
600 # define yyval (*yyvalp)
602 # define yyerrok (yystack->yyerrState = 0)
604 # define YYACCEPT return yyaccept
606 # define YYABORT return yyabort
608 # define YYERROR return yyerr
610 # define YYRECOVERING (yystack->yyerrState != 0)
612 # define yyclearin (yychar = *(yystack->yytokenp) = YYEMPTY)
614 # define YYBACKUP(Token, Value) \
616 yyerror ("syntax error: cannot back up"); \
635 /* Line __line__ of __file__. */
636 #line __oline__ "__ofile__"
641 yyuserMerge (int yyn
, YYSTYPE
* yy0
, YYSTYPE
* yy1
)
643 YYSTYPE yyval
= *yy0
;
644 /* `Use' the arguments. */
655 /* Bison grammar-table manipulation */
657 /** Number of symbols composing the right hand side of rule #RULE. */
659 yyrhsLength (yyRuleNum yyrule
)
664 /** Left-hand-side symbol for rule #RULE. */
665 static inline yySymbol
666 yylhsNonterm (yyRuleNum yyrule
)
671 /** True iff LR state STATE has only a default reduction (regardless
674 yyisDefaultedState (yyStateNum yystate
)
676 return yypact
[yystate
] == YYPACT_NINF
;
679 /** The default reduction for STATE, assuming it has one. */
680 static inline yyRuleNum
681 yydefaultAction (yyStateNum yystate
)
683 return yydefact
[yystate
];
686 /** Set *YYACTION to the action to take in YYSTATE on seeing YYTOKEN.
688 * R < 0: Reduce on rule -R.
690 * R > 0: Shift to state R.
691 * Set *CONFLICTS to a pointer into yyconfl to 0-terminated list of
692 * conflicting reductions.
695 yygetLRActions (yyStateNum yystate
, int yytoken
,
696 int* yyaction
, const short** yyconflicts
)
698 int yyindex
= yypact
[yystate
] + yytoken
;
699 if (yyindex
< 0 || YYLAST
< yyindex
|| yycheck
[yyindex
] != yytoken
)
701 *yyaction
= -yydefact
[yystate
];
702 *yyconflicts
= yyconfl
;
704 else if (yytable
[yyindex
] != YYTABLE_NINF
)
706 *yyaction
= yytable
[yyindex
];
707 *yyconflicts
= yyconfl
+ yyconflp
[yyindex
];
712 *yyconflicts
= yyconfl
+ yyconflp
[yyindex
];
716 static inline yyStateNum
717 yyLRgotoState (yyStateNum yystate
, yySymbol yylhs
)
720 yyr
= yypgoto
[yylhs
- YYNTOKENS
] + yystate
;
721 if (0 <= yyr
&& yyr
<= YYLAST
&& yycheck
[yyr
] == yystate
)
724 return yydefgoto
[yylhs
- YYNTOKENS
];
728 yyisShiftAction (int yyaction
)
734 yyisErrorAction (int yyaction
)
736 return yyaction
== 0;
741 /** True iff the semantic value of the edge leading to STATE is
744 yyhasResolvedValue (yyGLRState
* yystate
)
746 return yystate
->yyresolved
;
750 yyaddDeferredAction (yyGLRStack
* yystack
, yyGLRState
* yystate
,
751 yyGLRState
* rhs
, yyRuleNum yyrule
)
753 yySemanticOption
* yynewItem
;
754 yynewItem
= &yystack
->yynextFree
->yyoption
;
755 yystack
->yyspaceLeft
-= 1;
756 yystack
->yynextFree
+= 1;
757 yynewItem
->yyisState
= yyfalse
;
758 yynewItem
->yystate
= rhs
;
759 yynewItem
->yyrule
= yyrule
;
760 yynewItem
->yynext
= yystate
->yysemantics
.yyfirstVal
;
761 yystate
->yysemantics
.yyfirstVal
= yynewItem
;
762 if (yystack
->yyspaceLeft
< YYHEADROOM
)
763 yyexpandGLRStack (yystack
);
768 /** Initialize SET to a singleton set containing an empty stack. */
770 yyinitStateSet (yyGLRStateSet
* yyset
)
773 yyset
->yycapacity
= 16;
774 yyset
->yystates
= (yyGLRState
**) malloc (16 * sizeof (yyset
->yystates
[0]));
775 yyset
->yystates
[0] = NULL
;
778 static void yyfreeStateSet (yyGLRStateSet
* yyset
)
780 free (yyset
->yystates
);
783 /** Initialize STACK to a single empty stack, with total maximum
784 * capacity for all stacks of SIZE. */
786 yyinitGLRStack (yyGLRStack
* yystack
, size_t yysize
)
788 yystack
->yyerrflag
= 0;
789 yystack
->yyerrState
= 0;
791 yystack
->yyspaceLeft
= yysize
;
792 yystack
->yynextFree
= yystack
->yyitems
=
793 (yyGLRStackItem
*) malloc (yysize
* sizeof (yystack
->yynextFree
[0]));
794 yystack
->yysplitPoint
= NULL
;
795 yystack
->yylastDeleted
= NULL
;
796 yyinitStateSet (&yystack
->yytops
);
799 #define YYRELOC(YYFROMITEMS,YYTOITEMS,YYX,YYTYPE) \
800 &((YYTOITEMS) - ((YYFROMITEMS) - (yyGLRStackItem*) (YYX)))->YYTYPE
802 /** If STACK is expandable, extend it. WARNING: Pointers into the
803 stack from outside should be considered invalid after this call.
804 We always expand when there are 1 or fewer items left AFTER an
805 allocation, so that we can avoid having external pointers exist
806 across an allocation. */
808 yyexpandGLRStack (yyGLRStack
* yystack
)
810 #if YYSTACKEXPANDABLE
811 yyGLRStack yynewStack
;
812 yyGLRStackItem
* yyp0
, *yyp1
;
813 size_t yysize
, yynewSize
;
815 yysize
= yystack
->yynextFree
- yystack
->yyitems
;
816 if (YYMAXDEPTH
<= yysize
)
817 yyFail (yystack
, "parsing stack overflow (%d items)", yysize
);
818 yynewSize
= 2*yysize
;
819 if (YYMAXDEPTH
< yynewSize
)
820 yynewSize
= YYMAXDEPTH
;
821 yyinitGLRStack (&yynewStack
, yynewSize
);
822 for (yyp0
= yystack
->yyitems
, yyp1
= yynewStack
.yyitems
, yyn
= yysize
;
824 yyn
-= 1, yyp0
+= 1, yyp1
+= 1)
829 yyGLRState
* yys0
= &yyp0
->yystate
;
830 yyGLRState
* yys1
= &yyp1
->yystate
;
831 if (yys0
->yypred
!= NULL
)
833 YYRELOC (yyp0
, yyp1
, yys0
->yypred
, yystate
);
834 if (! yys0
->yyresolved
&& yys0
->yysemantics
.yyfirstVal
!= NULL
)
835 yys1
->yysemantics
.yyfirstVal
=
836 YYRELOC(yyp0
, yyp1
, yys0
->yysemantics
.yyfirstVal
, yyoption
);
840 yySemanticOption
* yyv0
= &yyp0
->yyoption
;
841 yySemanticOption
* yyv1
= &yyp1
->yyoption
;
842 if (yyv0
->yystate
!= NULL
)
843 yyv1
->yystate
= YYRELOC (yyp0
, yyp1
, yyv0
->yystate
, yystate
);
844 if (yyv0
->yynext
!= NULL
)
845 yyv1
->yynext
= YYRELOC (yyp0
, yyp1
, yyv0
->yynext
, yyoption
);
848 if (yystack
->yysplitPoint
!= NULL
)
849 yystack
->yysplitPoint
= YYRELOC (yystack
->yyitems
, yynewStack
.yyitems
,
850 yystack
->yysplitPoint
, yystate
);
852 for (yyn
= 0; yyn
< yystack
->yytops
.yysize
; yyn
+= 1)
853 if (yystack
->yytops
.yystates
[yyn
] != NULL
)
854 yystack
->yytops
.yystates
[yyn
] =
855 YYRELOC (yystack
->yyitems
, yynewStack
.yyitems
,
856 yystack
->yytops
.yystates
[yyn
], yystate
);
857 free (yystack
->yyitems
);
858 yystack
->yyitems
= yynewStack
.yyitems
;
859 yystack
->yynextFree
= yynewStack
.yynextFree
+ yysize
;
860 yystack
->yyspaceLeft
= yynewStack
.yyspaceLeft
- yysize
;
864 yyFail (yystack
, "parsing stack overflow (%d items)", yysize
);
870 yyfreeGLRStack (yyGLRStack
* yystack
)
872 free (yystack
->yyitems
);
873 yyfreeStateSet (&yystack
->yytops
);
876 /** Assuming that S is a GLRState somewhere on STACK, update the
877 * splitpoint of STACK, if needed, so that it is at least as deep as
880 yyupdateSplit (yyGLRStack
* yystack
, yyGLRState
* yys
)
882 if (yystack
->yysplitPoint
!= NULL
&& yystack
->yysplitPoint
> yys
)
883 yystack
->yysplitPoint
= yys
;
886 /** Invalidate stack #K in STACK. */
888 yymarkStackDeleted (yyGLRStack
* yystack
, int yyk
)
890 if (yystack
->yytops
.yystates
[yyk
] != NULL
)
891 yystack
->yylastDeleted
= yystack
->yytops
.yystates
[yyk
];
892 yystack
->yytops
.yystates
[yyk
] = NULL
;
895 /** Undelete the last stack that was marked as deleted. Can only be
896 done once after a deletion, and only when all other stacks have
899 yyundeleteLastStack (yyGLRStack
* yystack
)
901 if (yystack
->yylastDeleted
== NULL
|| yystack
->yytops
.yysize
!= 0)
903 yystack
->yytops
.yystates
[0] = yystack
->yylastDeleted
;
904 yystack
->yytops
.yysize
= 1;
905 YYDPRINTF ((stderr
, "Restoring last deleted stack as stack #0.\n"));
906 yystack
->yylastDeleted
= NULL
;
910 yyremoveDeletes (yyGLRStack
* yystack
)
914 while (yyj
< yystack
->yytops
.yysize
)
916 if (yystack
->yytops
.yystates
[yyi
] == NULL
)
919 YYDPRINTF ((stderr
, "Removing dead stacks.\n"));
920 yystack
->yytops
.yysize
-= 1;
924 yystack
->yytops
.yystates
[yyj
] = yystack
->yytops
.yystates
[yyi
];
926 YYDPRINTF ((stderr
, "Rename stack %d -> %d.\n", yyi
, yyj
));
933 /** Shift to a new state on stack #K of STACK, corresponding to LR state
934 * LRSTATE, at input position POSN, with (resolved) semantic value SVAL. */
936 yyglrShift (yyGLRStack
* yystack
, int yyk
, yyStateNum yylrState
, size_t yyposn
,
937 YYSTYPE yysval
, YYLTYPE
* yylocp
)
939 yyGLRStackItem
* yynewItem
;
941 yynewItem
= yystack
->yynextFree
;
942 yystack
->yynextFree
+= 1;
943 yystack
->yyspaceLeft
-= 1;
944 yynewItem
->yystate
.yyisState
= yytrue
;
945 yynewItem
->yystate
.yylrState
= yylrState
;
946 yynewItem
->yystate
.yyposn
= yyposn
;
947 yynewItem
->yystate
.yyresolved
= yytrue
;
948 yynewItem
->yystate
.yypred
= yystack
->yytops
.yystates
[yyk
];
949 yystack
->yytops
.yystates
[yyk
] = &yynewItem
->yystate
;
950 yynewItem
->yystate
.yysemantics
.yysval
= yysval
;
951 yynewItem
->yystate
.yyloc
= *yylocp
;
952 if (yystack
->yyspaceLeft
< YYHEADROOM
)
953 yyexpandGLRStack (yystack
);
956 /** Shift to a new state on stack #K of STACK, to a new state
957 * corresponding to LR state LRSTATE, at input position POSN, with
958 * the (unresolved) semantic value of RHS under the action for RULE. */
960 yyglrShiftDefer (yyGLRStack
* yystack
, int yyk
, yyStateNum yylrState
,
961 size_t yyposn
, yyGLRState
* rhs
, yyRuleNum yyrule
)
963 yyGLRStackItem
* yynewItem
;
965 yynewItem
= yystack
->yynextFree
;
966 yynewItem
->yystate
.yyisState
= yytrue
;
967 yynewItem
->yystate
.yylrState
= yylrState
;
968 yynewItem
->yystate
.yyposn
= yyposn
;
969 yynewItem
->yystate
.yyresolved
= yyfalse
;
970 yynewItem
->yystate
.yypred
= yystack
->yytops
.yystates
[yyk
];
971 yynewItem
->yystate
.yysemantics
.yyfirstVal
= NULL
;
972 yystack
->yytops
.yystates
[yyk
] = &yynewItem
->yystate
;
973 yystack
->yynextFree
+= 1;
974 yystack
->yyspaceLeft
-= 1;
975 yyaddDeferredAction (yystack
, &yynewItem
->yystate
, rhs
, yyrule
);
978 /** Pop the symbols consumed by reduction #RULE from the top of stack
979 * #K of STACK, and perform the appropriate semantic action on their
980 * semantic values. Assumes that all ambiguities in semantic values
981 * have been previously resolved. Set *VALP to the resulting value,
982 * and *LOCP to the computed location (if any). Return value is as
985 yydoAction (yyGLRStack
* yystack
, int yyk
, yyRuleNum yyrule
,
986 YYSTYPE
* yyvalp
, YYLTYPE
* yylocp
)
988 int yynrhs
= yyrhsLength (yyrule
);
990 if (yystack
->yysplitPoint
== NULL
)
992 /* Standard special case: single stack. */
993 yyGLRStackItem
* rhs
= (yyGLRStackItem
*) yystack
->yytops
.yystates
[yyk
];
995 yystack
->yynextFree
-= yynrhs
;
996 yystack
->yyspaceLeft
+= yynrhs
;
997 yystack
->yytops
.yystates
[0] = & yystack
->yynextFree
[-1].yystate
;
1000 *yyvalp
= yyval_default
;
1001 *yylocp
= yyloc_default
;
1005 *yyvalp
= rhs
[1-yynrhs
].yystate
.yysemantics
.yysval
;
1006 *yylocp
= rhs
[1-yynrhs
].yystate
.yyloc
;
1008 return yyuserAction (yyrule
, yynrhs
, rhs
, yyvalp
, yylocp
, yystack
);
1014 yyGLRStackItem yyrhsVals
[YYMAXRHS
];
1015 for (yyi
= yynrhs
-1, yys
= yystack
->yytops
.yystates
[yyk
]; 0 <= yyi
;
1016 yyi
-= 1, yys
= yys
->yypred
)
1018 assert (yys
->yypred
!= NULL
);
1019 yyrhsVals
[yyi
].yystate
.yyresolved
= yytrue
;
1020 yyrhsVals
[yyi
].yystate
.yysemantics
.yysval
= yys
->yysemantics
.yysval
;
1021 yyrhsVals
[yyi
].yystate
.yyloc
= yys
->yyloc
;
1023 yyupdateSplit (yystack
, yys
);
1024 yystack
->yytops
.yystates
[yyk
] = yys
;
1027 *yyvalp
= yyval_default
;
1028 *yylocp
= yyloc_default
;
1032 *yyvalp
= yyrhsVals
[0].yystate
.yysemantics
.yysval
;
1033 *yylocp
= yyrhsVals
[0].yystate
.yyloc
;
1035 return yyuserAction (yyrule
, yynrhs
, yyrhsVals
+ (yynrhs
-1),
1036 yyvalp
, yylocp
, yystack
);
1040 /** Pop items off stack #K of STACK according to grammar rule RULE,
1041 * and push back on the resulting nonterminal symbol. Perform the
1042 * semantic action associated with RULE and store its value with the
1043 * newly pushed state, if FORCEEVAL or if STACK is currently
1044 * unambiguous. Otherwise, store the deferred semantic action with
1045 * the new state. If the new state would have an identical input
1046 * position, LR state, and predecessor to an existing state on the stack,
1047 * it is identified with that existing state, eliminating stack #K from
1048 * the STACK. In this case, the (necessarily deferred) semantic value is
1049 * added to the options for the existing state's semantic value.
1051 static inline YYRESULTTAG
1052 yyglrReduce (yyGLRStack
* yystack
, size_t yyk
, yyRuleNum yyrule
,
1055 size_t yyposn
= yystack
->yytops
.yystates
[yyk
]->yyposn
;
1057 if (yyforceEval
|| yystack
->yysplitPoint
== NULL
)
1066 YYDPRINTF ((stderr
, "Reducing stack %d by rule %d (line %d),",
1067 yyk
, yyrule
- 1, yyrline
[yyrule
]));
1068 /* Print the symbols being reduced, and their result. */
1069 for (yyi
= yyprhs
[yyrule
]; 0 <= yyrhs
[yyi
]; yyi
++)
1070 YYFPRINTF (stderr
, "%s ", yytokenName (yyrhs
[yyi
]));
1071 YYFPRINTF (stderr
, " -> %s\n", yytokenName (yyr1
[yyrule
]));
1074 YYCHK (yydoAction (yystack
, yyk
, yyrule
, &yysval
, &yyloc
));
1075 yyglrShift (yystack
, yyk
,
1076 yyLRgotoState (yystack
->yytops
.yystates
[yyk
]->yylrState
,
1077 yylhsNonterm (yyrule
)),
1078 yyposn
, yysval
, &yyloc
);
1079 YYDPRINTF ((stderr
, "Stack %d entering state %d\n",
1080 yyk
, yystack
->yytops
.yystates
[yyk
]->yylrState
));
1086 yyGLRState
* yys
, *yys0
= yystack
->yytops
.yystates
[yyk
];
1087 yyStateNum yynewLRState
;
1089 for (yys
= yystack
->yytops
.yystates
[yyk
], yyn
= yyrhsLength (yyrule
);
1093 assert (yys
!= NULL
);
1095 yyupdateSplit (yystack
, yys
);
1096 yynewLRState
= yyLRgotoState (yys
->yylrState
, yylhsNonterm (yyrule
));
1098 "Reduced stack %d by rule #%d; action deferred. "
1099 "Now in state %d.\n",
1100 yyk
, yyrule
-1, yynewLRState
));
1101 for (yyi
= 0; yyi
< yystack
->yytops
.yysize
; yyi
+= 1)
1102 if (yyi
!= yyk
&& yystack
->yytops
.yystates
[yyi
] != NULL
)
1104 yyGLRState
* yyp
, *yysplit
= yystack
->yysplitPoint
;
1105 yyp
= yystack
->yytops
.yystates
[yyi
];
1106 while (yyp
!= yys
&& yyp
!= yysplit
&& yyp
->yyposn
>= yyposn
)
1108 if (yyp
->yylrState
== yynewLRState
&& yyp
->yypred
== yys
)
1110 yyaddDeferredAction (yystack
, yyp
, yys0
, yyrule
);
1111 yymarkStackDeleted (yystack
, yyk
);
1112 YYDPRINTF ((stderr
, "Merging stack %d into stack %d.\n",
1119 yystack
->yytops
.yystates
[yyk
] = yys
;
1120 yyglrShiftDefer (yystack
, yyk
, yynewLRState
, yyposn
, yys0
, yyrule
);
1126 yysplitStack (yyGLRStack
* yystack
, int yyk
)
1128 if (yystack
->yysplitPoint
== NULL
)
1131 yystack
->yysplitPoint
= yystack
->yytops
.yystates
[yyk
];
1133 if (yystack
->yytops
.yysize
>= yystack
->yytops
.yycapacity
)
1135 yystack
->yytops
.yycapacity
*= 2;
1136 yystack
->yytops
.yystates
=
1137 (yyGLRState
**) realloc (yystack
->yytops
.yystates
,
1138 yystack
->yytops
.yycapacity
1139 * sizeof (yyGLRState
*));
1141 yystack
->yytops
.yystates
[yystack
->yytops
.yysize
]
1142 = yystack
->yytops
.yystates
[yyk
];
1143 yystack
->yytops
.yysize
+= 1;
1144 return yystack
->yytops
.yysize
-1;
1147 /** True iff Y0 and Y1 represent identical options at the top level.
1148 * That is, they represent the same rule applied to RHS symbols
1149 * that produce the same terminal symbols. */
1151 yyidenticalOptions (yySemanticOption
* yyy0
, yySemanticOption
* yyy1
)
1153 if (yyy0
->yyrule
== yyy1
->yyrule
)
1155 yyGLRState
*yys0
, *yys1
;
1157 for (yys0
= yyy0
->yystate
, yys1
= yyy1
->yystate
,
1158 yyn
= yyrhsLength (yyy0
->yyrule
);
1160 yys0
= yys0
->yypred
, yys1
= yys1
->yypred
, yyn
-= 1)
1161 if (yys0
->yyposn
!= yys1
->yyposn
)
1169 /** Assuming identicalOptions (Y0,Y1), (destructively) merge the
1170 * alternative semantic values for the RHS-symbols of Y1 into the
1171 * corresponding semantic value sets of the symbols of Y0. */
1173 yymergeOptionSets (yySemanticOption
* yyy0
, yySemanticOption
* yyy1
)
1175 yyGLRState
*yys0
, *yys1
;
1177 for (yys0
= yyy0
->yystate
, yys1
= yyy1
->yystate
,
1178 yyn
= yyrhsLength (yyy0
->yyrule
);
1180 yys0
= yys0
->yypred
, yys1
= yys1
->yypred
, yyn
-= 1)
1183 else if (! yys0
->yyresolved
&& ! yys1
->yyresolved
)
1185 yySemanticOption
* yyz
;
1186 for (yyz
= yys0
->yysemantics
.yyfirstVal
; yyz
->yynext
!= NULL
;
1189 yyz
->yynext
= yys1
->yysemantics
.yyfirstVal
;
1193 /** Y0 and Y1 represent two possible actions to take in a given
1194 * parsing state; return 0 if no combination is possible,
1195 * 1 if user-mergeable, 2 if Y0 is preferred, 3 if Y1 is preferred. */
1197 yypreference (yySemanticOption
* y0
, yySemanticOption
* y1
)
1199 yyRuleNum r0
= y0
->yyrule
, r1
= y1
->yyrule
;
1200 int p0
= yydprec
[r0
], p1
= yydprec
[r1
];
1204 if (yymerger
[r0
] == 0 || yymerger
[r0
] != yymerger
[r1
])
1209 if (p0
== 0 || p1
== 0)
1218 static YYRESULTTAG
yyresolveValue (yySemanticOption
* yyoptionList
,
1219 yyGLRStack
* yystack
, YYSTYPE
* yyvalp
,
1223 yyresolveStates (yyGLRState
* yys
, int yyn
, yyGLRStack
* yystack
)
1228 assert (yys
->yypred
!= NULL
);
1229 yyflag
= yyresolveStates (yys
->yypred
, yyn
-1, yystack
);
1232 if (! yys
->yyresolved
)
1234 yyflag
= yyresolveValue (yys
->yysemantics
.yyfirstVal
, yystack
,
1235 &yys
->yysemantics
.yysval
, &yys
->yyloc
);
1238 yys
->yyresolved
= yytrue
;
1245 yyresolveAction (yySemanticOption
* yyopt
, yyGLRStack
* yystack
,
1246 YYSTYPE
* yyvalp
, YYLTYPE
* yylocp
)
1248 yyGLRStackItem yyrhsVals
[YYMAXRHS
];
1252 yynrhs
= yyrhsLength (yyopt
->yyrule
);
1253 YYCHK (yyresolveStates (yyopt
->yystate
, yynrhs
, yystack
));
1254 for (yyi
= yynrhs
-1, yys
= yyopt
->yystate
; 0 <= yyi
;
1255 yyi
-= 1, yys
= yys
->yypred
)
1257 assert (yys
->yypred
!= NULL
);
1258 yyrhsVals
[yyi
].yystate
.yyresolved
= yytrue
;
1259 yyrhsVals
[yyi
].yystate
.yysemantics
.yysval
= yys
->yysemantics
.yysval
;
1260 yyrhsVals
[yyi
].yystate
.yyloc
= yys
->yyloc
;
1262 return yyuserAction (yyopt
->yyrule
, yynrhs
, yyrhsVals
+ (yynrhs
-1),
1263 yyvalp
, yylocp
, yystack
);
1267 static yyGLRState YYLEFTMOST_STATE
=
1269 0, 0, -1, NULL
, 0, { NULL
},
1272 #if YYLTYPE_IS_TRIVIAL
1273 ]b4_location_if([ 0, 0, 0, 0])[
1278 static void yyreportTree (yySemanticOption
* yyx
, int yyindent
)
1280 int yynrhs
= yyrhsLength (yyx
->yyrule
);
1283 yyGLRState
* yystates
[YYMAXRHS
];
1285 for (yyi
= yynrhs
, yys
= yyx
->yystate
; 0 < yyi
; yyi
-= 1, yys
= yys
->yypred
)
1286 yystates
[yyi
] = yys
;
1288 yystates
[0] = &YYLEFTMOST_STATE
;
1292 if (yyx
->yystate
->yyposn
< yys
->yyposn
+ 1)
1293 YYFPRINTF (stderr
, "%*s%s -> <Rule %d, empty>\n",
1294 yyindent
, "", yytokenName (yylhsNonterm (yyx
->yyrule
)),
1297 YYFPRINTF (stderr
, "%*s%s -> <Rule %d, tokens %d .. %d>\n",
1298 yyindent
, "", yytokenName (yylhsNonterm (yyx
->yyrule
)),
1299 yyx
->yyrule
, yys
->yyposn
+1, yyx
->yystate
->yyposn
);
1300 for (yyi
= 1; yyi
<= yynrhs
; yyi
+= 1)
1302 if (yystates
[yyi
]->yyresolved
)
1304 if (yystates
[yyi
-1]->yyposn
+1 > yystates
[yyi
]->yyposn
)
1305 YYFPRINTF (stderr
, "%*s%s <empty>\n", yyindent
+2, "",
1306 yytokenName (yyrhs
[yyprhs
[yyx
->yyrule
]+yyi
-1]));
1308 YYFPRINTF (stderr
, "%*s%s <tokens %d .. %d>\n", yyindent
+2, "",
1309 yytokenName (yyrhs
[yyprhs
[yyx
->yyrule
]+yyi
-1]),
1310 yystates
[yyi
-1]->yyposn
+1, yystates
[yyi
]->yyposn
);
1313 yyreportTree (yystates
[yyi
]->yysemantics
.yyfirstVal
, yyindent
+2);
1319 yyreportAmbiguity (yySemanticOption
* yyx0
, yySemanticOption
* yyx1
,
1320 yyGLRStack
* yystack
)
1322 /* `Unused' warnings. */
1327 YYFPRINTF (stderr
, "Ambiguity detected.\n");
1328 YYFPRINTF (stderr
, "Option 1,\n");
1329 yyreportTree (yyx0
, 2);
1330 YYFPRINTF (stderr
, "\nOption 2,\n");
1331 yyreportTree (yyx1
, 2);
1332 YYFPRINTF (stderr
, "\n");
1334 yyFail (yystack
, "ambiguity detected");
1338 /** Resolve the ambiguity represented by OPTIONLIST, perform the indicated
1339 * actions, and return the result. */
1341 yyresolveValue (yySemanticOption
* yyoptionList
, yyGLRStack
* yystack
,
1342 YYSTYPE
* yyvalp
, YYLTYPE
* yylocp
)
1344 yySemanticOption
* yybest
;
1345 yySemanticOption
* yyp
;
1348 yybest
= yyoptionList
;
1350 for (yyp
= yyoptionList
->yynext
; yyp
!= NULL
; yyp
= yyp
->yynext
)
1352 if (yyidenticalOptions (yybest
, yyp
))
1353 yymergeOptionSets (yybest
, yyp
);
1355 switch (yypreference (yybest
, yyp
))
1358 yyreportAmbiguity (yybest
, yyp
, yystack
);
1374 int yyprec
= yydprec
[yybest
->yyrule
];
1375 YYCHK (yyresolveAction (yybest
, yystack
, yyvalp
, yylocp
));
1376 for (yyp
= yybest
->yynext
; yyp
!= NULL
; yyp
= yyp
->yynext
)
1378 if (yyprec
== yydprec
[yyp
->yyrule
])
1382 YYCHK (yyresolveAction (yyp
, yystack
, &yyval1
, &yydummy
));
1383 *yyvalp
= yyuserMerge (yymerger
[yyp
->yyrule
], yyvalp
, &yyval1
);
1389 return yyresolveAction (yybest
, yystack
, yyvalp
, yylocp
);
1393 yyresolveStack (yyGLRStack
* yystack
)
1395 if (yystack
->yysplitPoint
!= NULL
)
1400 for (yyn
= 0, yys
= yystack
->yytops
.yystates
[0];
1401 yys
!= yystack
->yysplitPoint
;
1402 yys
= yys
->yypred
, yyn
+= 1)
1404 YYCHK (yyresolveStates (yystack
->yytops
.yystates
[0], yyn
, yystack
));
1410 yycompressStack (yyGLRStack
* yystack
)
1412 yyGLRState
* yyp
, *yyq
, *yyr
;
1414 if (yystack
->yytops
.yysize
!= 1 || yystack
->yysplitPoint
== NULL
)
1417 for (yyp
= yystack
->yytops
.yystates
[0], yyq
= yyp
->yypred
, yyr
= NULL
;
1418 yyp
!= yystack
->yysplitPoint
;
1419 yyr
= yyp
, yyp
= yyq
, yyq
= yyp
->yypred
)
1422 yystack
->yyspaceLeft
+= yystack
->yynextFree
- yystack
->yyitems
;
1423 yystack
->yynextFree
= ((yyGLRStackItem
*) yystack
->yysplitPoint
) + 1;
1424 yystack
->yyspaceLeft
-= yystack
->yynextFree
- yystack
->yyitems
;
1425 yystack
->yysplitPoint
= NULL
;
1426 yystack
->yylastDeleted
= NULL
;
1430 yystack
->yynextFree
->yystate
= *yyr
;
1432 yystack
->yynextFree
->yystate
.yypred
= & yystack
->yynextFree
[-1].yystate
;
1433 yystack
->yytops
.yystates
[0] = &yystack
->yynextFree
->yystate
;
1434 yystack
->yynextFree
+= 1;
1435 yystack
->yyspaceLeft
-= 1;
1440 yyprocessOneStack (yyGLRStack
* yystack
, int yyk
,
1441 size_t yyposn
, YYSTYPE
* yylvalp
, YYLTYPE
* yyllocp
)
1444 const short* yyconflicts
;
1446 yySymbol
* const yytokenp
= yystack
->yytokenp
;
1448 while (yystack
->yytops
.yystates
[yyk
] != NULL
)
1450 yyStateNum yystate
= yystack
->yytops
.yystates
[yyk
]->yylrState
;
1452 assert (yystate
!= YYFINAL
);
1453 if (yyisDefaultedState (yystate
))
1455 yyrule
= yydefaultAction (yystate
);
1458 YYDPRINTF ((stderr
, "Stack %d dies.\n", yyk
));
1459 yymarkStackDeleted (yystack
, yyk
);
1462 YYCHK (yyglrReduce (yystack
, yyk
, yyrule
, yyfalse
));
1466 if (*yytokenp
== YYEMPTY
)
1468 YYDPRINTF ((stderr
, "Reading a token: "));
1470 *yytokenp
= YYTRANSLATE(yychar
);
1471 YYDPRINTF ((stderr
, "Next token is %s\n",
1472 yytokenName (*yytokenp
)));
1474 yygetLRActions (yystate
, *yytokenp
, &yyaction
, &yyconflicts
);
1476 while (*yyconflicts
!= 0)
1478 int yynewStack
= yysplitStack (yystack
, yyk
);
1479 YYDPRINTF ((stderr
, "Splitting off stack %d from %d.\n",
1481 YYCHK (yyglrReduce (yystack
, yynewStack
, *yyconflicts
, yyfalse
));
1482 YYCHK (yyprocessOneStack (yystack
, yynewStack
, yyposn
,
1487 if (yyisShiftAction (yyaction
))
1489 YYDPRINTF ((stderr
, "Shifting token %s on stack %d, ",
1490 yytokenName (*yytokenp
), yyk
));
1491 yyglrShift (yystack
, yyk
, yyaction
, yyposn
+1, *yylvalp
, yyllocp
);
1492 YYDPRINTF ((stderr
, "which is now in state #%d\n",
1493 yystack
->yytops
.yystates
[yyk
]->yylrState
));
1496 else if (yyisErrorAction (yyaction
))
1498 YYDPRINTF ((stderr
, "Stack %d dies.\n", yyk
));
1499 yymarkStackDeleted (yystack
, yyk
);
1503 YYCHK (yyglrReduce (yystack
, yyk
, -yyaction
, yyfalse
));
1510 yyreportParseError (yyGLRStack
* yystack
, YYSTYPE
* yylvalp
, YYLTYPE
* yyllocp
)
1512 /* `Unused' warnings. */
1516 if (yystack
->yyerrState
== 0)
1519 yySymbol
* const yytokenp
= yystack
->yytokenp
;
1520 int yyn
, yyx
, yycount
;
1522 const char* yyprefix
;
1525 yyn
= yypact
[yystack
->yytops
.yystates
[0]->yylrState
];
1526 if (YYPACT_NINF
< yyn
&& yyn
< YYLAST
)
1529 /* Start YYX at -YYN if negative to avoid negative indexes in
1531 yysize
= sizeof ("parse error, unexpected ")
1532 + strlen (yytokenName (*yytokenp
));
1533 yyprefix
= ", expecting ";
1534 for (yyx
= yyn
< 0 ? -yyn
: 0; yyx
< yytname_size
&& yycount
<= 5;
1536 if (yycheck
[yyx
+ yyn
] == yyx
&& yyx
!= YYTERROR
)
1537 yysize
+= strlen (yytokenName (yyx
)) + strlen (yyprefix
),
1538 yycount
+= 1, yyprefix
= " or ";
1539 yymsg
= yyp
= (char*) malloc (yysize
);
1540 sprintf (yyp
, "parse error, unexpected %s",
1541 yytokenName (*yytokenp
));
1542 yyp
+= strlen (yyp
);
1545 yyprefix
= ", expecting ";
1546 for (yyx
= yyn
< 0 ? -yyn
: 0; yyx
< yytname_size
; yyx
+= 1)
1547 if (yycheck
[yyx
+ yyn
] == yyx
&& yyx
!= YYTERROR
)
1549 sprintf (yyp
, "%s%s", yyprefix
, yytokenName (yyx
));
1550 yyp
+= strlen (yyp
);
1559 yyerror ("parse error");
1564 /* Recover from a syntax error on YYSTACK, assuming that YYTOKENP,
1565 YYLVALP, and YYLLOCP point to the syntactic category, semantic
1566 value, and location of the lookahead. */
1568 yyrecoverParseError (yyGLRStack
* yystack
, YYSTYPE
* yylvalp
, YYLTYPE
* yyllocp
)
1570 yySymbol
* const yytokenp
= yystack
->yytokenp
;
1574 if (yystack
->yyerrState
== 0)
1575 yystack
->yyerrState
= 3;
1576 else if (yystack
->yyerrState
== 3)
1577 /* We just shifted the error token and (perhaps) took some
1578 reductions. Skip tokens until we can proceed. */
1581 if (*yytokenp
== YYEOF
)
1582 yyFail (yystack
, NULL
);
1583 if (*yytokenp
!= YYEMPTY
)
1584 YYDPRINTF ((stderr
, "Discarding token %s\n",
1585 yytokenName (*yytokenp
)));
1586 YYDPRINTF ((stderr
, "Reading a token: "));
1588 *yytokenp
= YYTRANSLATE (yychar
);
1589 YYDPRINTF ((stderr
, "Next token is %s\n", yytokenName (*yytokenp
)));
1590 yyj
= yypact
[yystack
->yytops
.yystates
[0]->yylrState
];
1591 if (yyj
== YYPACT_NINF
)
1592 /* Something's not right; we shouldn't be here. */
1593 yyFail (yystack
, NULL
);
1595 if (yyj
< 0 || YYLAST
< yyj
|| yycheck
[yyj
] != *yytokenp
)
1597 if (yydefact
[yystack
->yytops
.yystates
[0]->yylrState
] != 0)
1600 else if (yytable
[yyj
] != 0 && yytable
[yyj
] != YYTABLE_NINF
)
1604 /* Reduce to one stack. */
1605 for (yyk
= 0; yyk
< yystack
->yytops
.yysize
; yyk
+= 1)
1606 if (yystack
->yytops
.yystates
[yyk
] != NULL
)
1608 if (yyk
>= yystack
->yytops
.yysize
)
1609 yyFail (yystack
, NULL
);
1610 for (yyk
+= 1; yyk
< yystack
->yytops
.yysize
; yyk
+= 1)
1611 yymarkStackDeleted (yystack
, yyk
);
1612 yyremoveDeletes (yystack
);
1613 yycompressStack (yystack
);
1615 /* Now pop stack until we find a state that shifts the error token. */
1616 while (yystack
->yytops
.yystates
[0] != NULL
)
1618 yyj
= yypact
[yystack
->yytops
.yystates
[0]->yylrState
] + YYTERROR
;
1619 if (yyj
!= YYPACT_NINF
+ YYTERROR
&& yyj
>= 0 && yyj
<= YYLAST
&&
1620 yycheck
[yyj
] == YYTERROR
&& yyisShiftAction (yytable
[yyj
]))
1622 yyglrShift (yystack
, 0, yytable
[yyj
],
1623 yystack
->yytops
.yystates
[0]->yyposn
, *yylvalp
, yyllocp
);
1626 yystack
->yytops
.yystates
[0] = yystack
->yytops
.yystates
[0]->yypred
;
1627 yystack
->yynextFree
-= 1;
1628 yystack
->yyspaceLeft
+= 1;
1630 if (yystack
->yytops
.yystates
[0] == NULL
)
1631 yyFail (yystack
, NULL
);
1634 #define YYCHK1(YYE) \
1640 yystack.yyerrflag = 1; \
1643 yystack.yyerrflag = 0; \
1646 goto yyuser_error; \
1655 ]b4_c_ansi_function_def([yyparse
], [int], b4_parse_param
)[
1665 #define yychar (yystack.yyrawchar)
1668 YYSTYPE
* const yylvalp
= &yylval
;
1669 YYLTYPE
* const yyllocp
= &yylloc
;
1671 yyinitGLRStack (&yystack
, YYINITDEPTH
);
1672 yystack
.yytokenp
= &yytoken
;
1674 YYDPRINTF ((stderr
, "Starting parse\n"));
1676 if (setjmp (yystack
.yyexception_buffer
) != 0)
1679 yyglrShift (&yystack
, 0, 0, 0, yyval_default
, &yyloc_default
);
1685 /* For efficiency, we have two loops, the first of which is
1686 specialized to deterministic operation (single stack, no
1687 potential ambiguity). */
1694 const short* yyconflicts
;
1696 yyStateNum yystate
= yystack
.yytops
.yystates
[0]->yylrState
;
1697 if (yystate
== YYFINAL
)
1699 if (yyisDefaultedState (yystate
))
1701 yyrule
= yydefaultAction (yystate
);
1704 yyreportParseError (&yystack
, yylvalp
, yyllocp
);
1707 YYCHK1 (yyglrReduce (&yystack
, 0, yyrule
, yytrue
));
1711 if (yytoken
== YYEMPTY
)
1713 YYDPRINTF ((stderr
, "Reading a token: "));
1715 yytoken
= YYTRANSLATE (yychar
);
1716 YYDPRINTF ((stderr
, "Next token is %s\n",
1717 yytokenName (yytoken
)));
1719 yygetLRActions (yystate
, yytoken
, &yyaction
, &yyconflicts
);
1720 if (*yyconflicts
!= 0)
1722 if (yyisShiftAction (yyaction
))
1724 YYDPRINTF ((stderr
, "Shifting token %s, ",
1725 yytokenName (yytoken
)));
1726 if (yytoken
!= YYEOF
)
1729 yyglrShift (&yystack
, 0, yyaction
, yyposn
, yylval
, yyllocp
);
1730 if (0 < yystack
.yyerrState
)
1731 yystack
.yyerrState
-= 1;
1732 YYDPRINTF ((stderr
, "Entering state %d\n",
1733 yystack
.yytops
.yystates
[0]->yylrState
));
1735 else if (yyisErrorAction (yyaction
))
1737 yyreportParseError (&yystack
, yylvalp
, yyllocp
);
1741 YYCHK1 (yyglrReduce (&yystack
, 0, -yyaction
, yytrue
));
1748 int yyn
= yystack
.yytops
.yysize
;
1749 for (yys
= 0; yys
< yyn
; yys
+= 1)
1750 YYCHK1 (yyprocessOneStack (&yystack
, yys
, yyposn
,
1754 yyremoveDeletes (&yystack
);
1755 if (yystack
.yytops
.yysize
== 0)
1757 yyundeleteLastStack (&yystack
);
1758 if (yystack
.yytops
.yysize
== 0)
1759 yyFail (&yystack
, "parse error");
1760 YYCHK1 (yyresolveStack (&yystack
));
1761 YYDPRINTF ((stderr
, "Returning to deterministic operation.\n"));
1762 yyreportParseError (&yystack
, yylvalp
, yyllocp
);
1765 else if (yystack
.yytops
.yysize
== 1)
1767 YYCHK1 (yyresolveStack (&yystack
));
1768 YYDPRINTF ((stderr
, "Returning to deterministic operation.\n"));
1769 yycompressStack (&yystack
);
1775 yyrecoverParseError (&yystack
, yylvalp
, yyllocp
);
1776 yyposn
= yystack
.yytops
.yystates
[0]->yyposn
;
1781 yyfreeGLRStack (&yystack
);
1782 return yystack
.yyerrflag
;
1785 /* DEBUGGING ONLY */
1786 static void yypstack (yyGLRStack
* yystack
, int yyk
) ATTRIBUTE_UNUSED
;
1787 static void yypdumpstack (yyGLRStack
* yystack
) ATTRIBUTE_UNUSED
;
1790 yy_yypstack (yyGLRState
* yys
)
1794 yy_yypstack (yys
->yypred
);
1795 fprintf (stderr
, " -> ");
1797 fprintf (stderr
, "%d@%lu", yys
->yylrState
, (unsigned long) yys
->yyposn
);
1801 yypstates (yyGLRState
* yyst
)
1804 fprintf (stderr
, "<null>");
1807 fprintf (stderr
, "\n");
1811 yypstack (yyGLRStack
* yystack
, int yyk
)
1813 yypstates (yystack
->yytops
.yystates
[yyk
]);
1816 #define YYINDEX(YYX) \
1817 ((YYX) == NULL ? -1 : (yyGLRStackItem*) (YYX) - yystack->yyitems)
1821 yypdumpstack (yyGLRStack
* yystack
)
1823 yyGLRStackItem
* yyp
;
1825 for (yyp
= yystack
->yyitems
; yyp
< yystack
->yynextFree
; yyp
+= 1)
1827 fprintf (stderr
, "%3lu. ", (unsigned long) (yyp
- yystack
->yyitems
));
1830 fprintf (stderr
, "Res: %d, LR State: %d, posn: %lu, pred: %ld",
1831 yyp
->yystate
.yyresolved
, yyp
->yystate
.yylrState
,
1832 (unsigned long) yyp
->yystate
.yyposn
,
1833 (long) YYINDEX (yyp
->yystate
.yypred
));
1834 if (! yyp
->yystate
.yyresolved
)
1835 fprintf (stderr
, ", firstVal: %ld",
1836 (long) YYINDEX (yyp
->yystate
.yysemantics
.yyfirstVal
));
1840 fprintf (stderr
, "Option. rule: %d, state: %ld, next: %ld",
1841 yyp
->yyoption
.yyrule
,
1842 (long) YYINDEX (yyp
->yyoption
.yystate
),
1843 (long) YYINDEX (yyp
->yyoption
.yynext
));
1845 fprintf (stderr
, "\n");
1847 fprintf (stderr
, "Tops:");
1848 for (yyi
= 0; yyi
< yystack
->yytops
.yysize
; yyi
+= 1)
1849 fprintf (stderr
, "%lu: %ld; ", (unsigned long) yyi
,
1850 (long) YYINDEX (yystack
->yytops
.yystates
[yyi
]));
1851 fprintf (stderr
, "\n");
1857 m4_if(b4_defines_flag
, 0, [],
1858 [#output "b4_output_header_name"
1859 b4_copyright([Skeleton parser
for GLR parsing with Bison
], [2002])
1860 #ifndef b4_header_guard
1861 # define b4_header_guard
1863 b4_token_defines(b4_tokens
)
1866 m4_ifdef([b4_stype
],
1867 [#line b4_stype_line "b4_filename"
1868 typedef union b4_stype yystype
;
1869 /* Line __line__ of __file__. */
1870 #line __oline__ "__ofile__"],
1871 [typedef int yystype
;])
1872 # define YYSTYPE yystype
1876 [extern YYSTYPE b4_prefix
[]lval
;])
1880 typedef struct yyltype
1887 # define YYLTYPE yyltype
1891 [extern YYLTYPE b4_prefix
[]lloc
;])
1893 #endif /* not b4_header_guard */