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 m4_ifset([b4_parse_param
],
389 [#define YY_USER_FORMALS , b4_c_ansi_formals(b4_parse_param)
390 #define YY_USER_ARGS , b4_c_args(b4_parse_param)],
391 [#define YY_USER_FORMALS
392 #define YY_USER_ARGS])
395 [/* Error token number */
398 /* YYLLOC_DEFAULT -- Compute the default location (before the actions
401 #define YYRHSLOC(yyRhs,YYK) (yyRhs[YYK].yystate.yyloc)
403 #ifndef YYLLOC_DEFAULT
404 # define YYLLOC_DEFAULT(yyCurrent, yyRhs, YYN) \
405 yyCurrent.first_line = YYRHSLOC(yyRhs,1).first_line; \
406 yyCurrent.first_column = YYRHSLOC(yyRhs,1).first_column; \
407 yyCurrent.last_line = YYRHSLOC(yyRhs,YYN).last_line; \
408 yyCurrent.last_column = YYRHSLOC(yyRhs,YYN).last_column;
411 /* YYLEX -- calling `yylex' with the right arguments. */
412 #define YYLEX ]b4_c_function_call([yylex], [int], b4_lex_param)[
417 #define yynerrs (yystack->yyerrcnt)
419 #define yychar (yystack->yyrawchar)],
427 static const int YYEOF
= 0;
428 static const int YYEMPTY
= -2;
430 typedef enum { yyok
, yyaccept
, yyabort
, yyerr
} YYRESULTTAG
;
433 do { YYRESULTTAG yyflag = YYE; if (yyflag != yyok) return yyflag; } \
438 #if ! defined (YYFPRINTF)
439 # define YYFPRINTF fprintf
442 # define YYDPRINTF(Args) \
447 /* Nonzero means print parse trace. It is left uninitialized so that
448 multiple parsers can coexist. */
451 /* Avoid empty `if' bodies. */
452 # define YYDPRINTF(Args) {}
453 #endif /* !YYDEBUG */
455 /* YYINITDEPTH -- initial size of the parser's stacks. */
457 # define YYINITDEPTH ]b4_stack_depth_init[
460 /* YYMAXDEPTH -- maximum size the stacks can grow to (effective only
461 if the built-in stack extension method is used).
463 Do not make this value too large; the results are undefined if
464 SIZE_MAX < YYMAXDEPTH * sizeof (GLRStackItem)
465 evaluated with infinite-precision integer arithmetic. */
472 # define YYMAXDEPTH ]b4_stack_depth_max[
475 /* Minimum number of free items on the stack allowed after an
476 allocation. This is to allow allocation and initialization
477 to be completed by functions that call expandGLRStack before the
478 stack is expanded, thus insuring that all necessary pointers get
479 properly redirected to new data. */
482 #if ! defined (YYSTACKEXPANDABLE) \
483 && (! defined (__cplusplus) || (YYLTYPE_IS_TRIVIAL && YYSTYPE_IS_TRIVIAL))
484 #define YYSTACKEXPANDABLE 1
486 #define YYSTACKEXPANDABLE 0
489 /** State numbers, as in LALR(1) machine */
490 typedef int yyStateNum
;
492 /** Rule numbers, as in LALR(1) machine */
493 typedef int yyRuleNum
;
495 /** Grammar symbol */
496 typedef short yySymbol
;
498 /** Item references, as in LALR(1) machine */
499 typedef short yyItemNum
;
501 typedef struct yyGLRState yyGLRState
;
502 typedef struct yySemanticOption yySemanticOption
;
503 typedef union yyGLRStackItem yyGLRStackItem
;
504 typedef struct yyGLRStack yyGLRStack
;
505 typedef struct yyGLRStateSet yyGLRStateSet
;
510 yyStateNum yylrState
;
514 yySemanticOption
* yyfirstVal
;
520 struct yyGLRStateSet
{
521 yyGLRState
** yystates
;
522 size_t yysize
, yycapacity
;
525 struct yySemanticOption
{
529 yySemanticOption
* yynext
;
532 union yyGLRStackItem
{
534 yySemanticOption yyoption
;
546 jmp_buf yyexception_buffer
;
547 yyGLRStackItem
* yyitems
;
548 yyGLRStackItem
* yynextFree
;
550 yyGLRState
* yysplitPoint
;
551 yyGLRState
* yylastDeleted
;
552 yyGLRStateSet yytops
;
555 static void yyinitGLRStack (yyGLRStack
* yystack
, size_t yysize
);
556 static void yyexpandGLRStack (yyGLRStack
* yystack
);
557 static void yyfreeGLRStack (yyGLRStack
* yystack
);
560 yyFail (yyGLRStack
* yystack
, const char* yyformat
, ...)
562 if (yyformat
!= NULL
)
566 va_start (yyap
, yyformat
);
567 yystack
->yyerrflag
= 1;
568 vsprintf (yymsg
, yyformat
, yyap
);
571 longjmp (yystack
->yyexception_buffer
, 1);
574 #if YYDEBUG || YYERROR_VERBOSE
575 /** A printable representation of TOKEN. Valid until next call to
577 static inline const char*
578 yytokenName (yySymbol yytoken
)
580 return yytname
[yytoken
];
584 /** Perform user action for rule number YYN, with RHS length YYRHSLEN,
585 * and top stack item YYVSP. YYLVALP points to place to put semantic
586 * value ($$), and yylocp points to place for location information
587 * (@$). Returns yyok for normal return, yyaccept for YYACCEPT,
588 * yyerr for YYERROR, yyabort for YYABORT. */
590 yyuserAction (yyRuleNum yyn
, int yyrhslen
, yyGLRStackItem
* yyvsp
,
591 YYSTYPE
* yyvalp
, YYLTYPE
* yylocp
, yyGLRStack
* yystack
594 /* Avoid `unused' warnings in there are no $n. */
599 *yyvalp
= yyval_default
;
600 *yylocp
= yyloc_default
;
604 *yyvalp
= yyvsp
[1-yyrhslen
].yystate
.yysemantics
.yysval
;
605 *yylocp
= yyvsp
[1-yyrhslen
].yystate
.yyloc
;
608 # define yyval (*yyvalp)
610 # define yyerrok (yystack->yyerrState = 0)
612 # define YYACCEPT return yyaccept
614 # define YYABORT return yyabort
616 # define YYERROR return yyerr
618 # define YYRECOVERING (yystack->yyerrState != 0)
620 # define yyclearin (yychar = *(yystack->yytokenp) = YYEMPTY)
622 # define YYBACKUP(Token, Value) \
624 yyerror ("syntax error: cannot back up"); \
643 /* Line __line__ of __file__. */
644 #line __oline__ "__ofile__"
649 yyuserMerge (int yyn
, YYSTYPE
* yy0
, YYSTYPE
* yy1
)
651 YYSTYPE yyval
= *yy0
;
652 /* `Use' the arguments. */
663 /* Bison grammar-table manipulation */
665 /** Number of symbols composing the right hand side of rule #RULE. */
667 yyrhsLength (yyRuleNum yyrule
)
672 /** Left-hand-side symbol for rule #RULE. */
673 static inline yySymbol
674 yylhsNonterm (yyRuleNum yyrule
)
679 /** True iff LR state STATE has only a default reduction (regardless
682 yyisDefaultedState (yyStateNum yystate
)
684 return yypact
[yystate
] == YYPACT_NINF
;
687 /** The default reduction for STATE, assuming it has one. */
688 static inline yyRuleNum
689 yydefaultAction (yyStateNum yystate
)
691 return yydefact
[yystate
];
694 /** Set *YYACTION to the action to take in YYSTATE on seeing YYTOKEN.
696 * R < 0: Reduce on rule -R.
698 * R > 0: Shift to state R.
699 * Set *CONFLICTS to a pointer into yyconfl to 0-terminated list of
700 * conflicting reductions.
703 yygetLRActions (yyStateNum yystate
, int yytoken
,
704 int* yyaction
, const short** yyconflicts
)
706 int yyindex
= yypact
[yystate
] + yytoken
;
707 if (yyindex
< 0 || YYLAST
< yyindex
|| yycheck
[yyindex
] != yytoken
)
709 *yyaction
= -yydefact
[yystate
];
710 *yyconflicts
= yyconfl
;
712 else if (yytable
[yyindex
] != YYTABLE_NINF
)
714 *yyaction
= yytable
[yyindex
];
715 *yyconflicts
= yyconfl
+ yyconflp
[yyindex
];
720 *yyconflicts
= yyconfl
+ yyconflp
[yyindex
];
724 static inline yyStateNum
725 yyLRgotoState (yyStateNum yystate
, yySymbol yylhs
)
728 yyr
= yypgoto
[yylhs
- YYNTOKENS
] + yystate
;
729 if (0 <= yyr
&& yyr
<= YYLAST
&& yycheck
[yyr
] == yystate
)
732 return yydefgoto
[yylhs
- YYNTOKENS
];
736 yyisShiftAction (int yyaction
)
742 yyisErrorAction (int yyaction
)
744 return yyaction
== 0;
749 /** True iff the semantic value of the edge leading to STATE is
752 yyhasResolvedValue (yyGLRState
* yystate
)
754 return yystate
->yyresolved
;
758 yyaddDeferredAction (yyGLRStack
* yystack
, yyGLRState
* yystate
,
759 yyGLRState
* rhs
, yyRuleNum yyrule
)
761 yySemanticOption
* yynewItem
;
762 yynewItem
= &yystack
->yynextFree
->yyoption
;
763 yystack
->yyspaceLeft
-= 1;
764 yystack
->yynextFree
+= 1;
765 yynewItem
->yyisState
= yyfalse
;
766 yynewItem
->yystate
= rhs
;
767 yynewItem
->yyrule
= yyrule
;
768 yynewItem
->yynext
= yystate
->yysemantics
.yyfirstVal
;
769 yystate
->yysemantics
.yyfirstVal
= yynewItem
;
770 if (yystack
->yyspaceLeft
< YYHEADROOM
)
771 yyexpandGLRStack (yystack
);
776 /** Initialize SET to a singleton set containing an empty stack. */
778 yyinitStateSet (yyGLRStateSet
* yyset
)
781 yyset
->yycapacity
= 16;
782 yyset
->yystates
= (yyGLRState
**) malloc (16 * sizeof (yyset
->yystates
[0]));
783 yyset
->yystates
[0] = NULL
;
786 static void yyfreeStateSet (yyGLRStateSet
* yyset
)
788 free (yyset
->yystates
);
791 /** Initialize STACK to a single empty stack, with total maximum
792 * capacity for all stacks of SIZE. */
794 yyinitGLRStack (yyGLRStack
* yystack
, size_t yysize
)
796 yystack
->yyerrflag
= 0;
797 yystack
->yyerrState
= 0;
799 yystack
->yyspaceLeft
= yysize
;
800 yystack
->yynextFree
= yystack
->yyitems
=
801 (yyGLRStackItem
*) malloc (yysize
* sizeof (yystack
->yynextFree
[0]));
802 yystack
->yysplitPoint
= NULL
;
803 yystack
->yylastDeleted
= NULL
;
804 yyinitStateSet (&yystack
->yytops
);
807 #define YYRELOC(YYFROMITEMS,YYTOITEMS,YYX,YYTYPE) \
808 &((YYTOITEMS) - ((YYFROMITEMS) - (yyGLRStackItem*) (YYX)))->YYTYPE
810 /** If STACK is expandable, extend it. WARNING: Pointers into the
811 stack from outside should be considered invalid after this call.
812 We always expand when there are 1 or fewer items left AFTER an
813 allocation, so that we can avoid having external pointers exist
814 across an allocation. */
816 yyexpandGLRStack (yyGLRStack
* yystack
)
818 #if YYSTACKEXPANDABLE
819 yyGLRStack yynewStack
;
820 yyGLRStackItem
* yyp0
, *yyp1
;
821 size_t yysize
, yynewSize
;
823 yysize
= yystack
->yynextFree
- yystack
->yyitems
;
824 if (YYMAXDEPTH
<= yysize
)
825 yyFail (yystack
, "parsing stack overflow (%d items)", yysize
);
826 yynewSize
= 2*yysize
;
827 if (YYMAXDEPTH
< yynewSize
)
828 yynewSize
= YYMAXDEPTH
;
829 yyinitGLRStack (&yynewStack
, yynewSize
);
830 for (yyp0
= yystack
->yyitems
, yyp1
= yynewStack
.yyitems
, yyn
= yysize
;
832 yyn
-= 1, yyp0
+= 1, yyp1
+= 1)
837 yyGLRState
* yys0
= &yyp0
->yystate
;
838 yyGLRState
* yys1
= &yyp1
->yystate
;
839 if (yys0
->yypred
!= NULL
)
841 YYRELOC (yyp0
, yyp1
, yys0
->yypred
, yystate
);
842 if (! yys0
->yyresolved
&& yys0
->yysemantics
.yyfirstVal
!= NULL
)
843 yys1
->yysemantics
.yyfirstVal
=
844 YYRELOC(yyp0
, yyp1
, yys0
->yysemantics
.yyfirstVal
, yyoption
);
848 yySemanticOption
* yyv0
= &yyp0
->yyoption
;
849 yySemanticOption
* yyv1
= &yyp1
->yyoption
;
850 if (yyv0
->yystate
!= NULL
)
851 yyv1
->yystate
= YYRELOC (yyp0
, yyp1
, yyv0
->yystate
, yystate
);
852 if (yyv0
->yynext
!= NULL
)
853 yyv1
->yynext
= YYRELOC (yyp0
, yyp1
, yyv0
->yynext
, yyoption
);
856 if (yystack
->yysplitPoint
!= NULL
)
857 yystack
->yysplitPoint
= YYRELOC (yystack
->yyitems
, yynewStack
.yyitems
,
858 yystack
->yysplitPoint
, yystate
);
860 for (yyn
= 0; yyn
< yystack
->yytops
.yysize
; yyn
+= 1)
861 if (yystack
->yytops
.yystates
[yyn
] != NULL
)
862 yystack
->yytops
.yystates
[yyn
] =
863 YYRELOC (yystack
->yyitems
, yynewStack
.yyitems
,
864 yystack
->yytops
.yystates
[yyn
], yystate
);
865 free (yystack
->yyitems
);
866 yystack
->yyitems
= yynewStack
.yyitems
;
867 yystack
->yynextFree
= yynewStack
.yynextFree
+ yysize
;
868 yystack
->yyspaceLeft
= yynewStack
.yyspaceLeft
- yysize
;
872 yyFail (yystack
, "parsing stack overflow (%d items)", yysize
);
878 yyfreeGLRStack (yyGLRStack
* yystack
)
880 free (yystack
->yyitems
);
881 yyfreeStateSet (&yystack
->yytops
);
884 /** Assuming that S is a GLRState somewhere on STACK, update the
885 * splitpoint of STACK, if needed, so that it is at least as deep as
888 yyupdateSplit (yyGLRStack
* yystack
, yyGLRState
* yys
)
890 if (yystack
->yysplitPoint
!= NULL
&& yystack
->yysplitPoint
> yys
)
891 yystack
->yysplitPoint
= yys
;
894 /** Invalidate stack #K in STACK. */
896 yymarkStackDeleted (yyGLRStack
* yystack
, int yyk
)
898 if (yystack
->yytops
.yystates
[yyk
] != NULL
)
899 yystack
->yylastDeleted
= yystack
->yytops
.yystates
[yyk
];
900 yystack
->yytops
.yystates
[yyk
] = NULL
;
903 /** Undelete the last stack that was marked as deleted. Can only be
904 done once after a deletion, and only when all other stacks have
907 yyundeleteLastStack (yyGLRStack
* yystack
)
909 if (yystack
->yylastDeleted
== NULL
|| yystack
->yytops
.yysize
!= 0)
911 yystack
->yytops
.yystates
[0] = yystack
->yylastDeleted
;
912 yystack
->yytops
.yysize
= 1;
913 YYDPRINTF ((stderr
, "Restoring last deleted stack as stack #0.\n"));
914 yystack
->yylastDeleted
= NULL
;
918 yyremoveDeletes (yyGLRStack
* yystack
)
922 while (yyj
< yystack
->yytops
.yysize
)
924 if (yystack
->yytops
.yystates
[yyi
] == NULL
)
927 YYDPRINTF ((stderr
, "Removing dead stacks.\n"));
928 yystack
->yytops
.yysize
-= 1;
932 yystack
->yytops
.yystates
[yyj
] = yystack
->yytops
.yystates
[yyi
];
934 YYDPRINTF ((stderr
, "Rename stack %d -> %d.\n", yyi
, yyj
));
941 /** Shift to a new state on stack #K of STACK, corresponding to LR state
942 * LRSTATE, at input position POSN, with (resolved) semantic value SVAL. */
944 yyglrShift (yyGLRStack
* yystack
, int yyk
, yyStateNum yylrState
, size_t yyposn
,
945 YYSTYPE yysval
, YYLTYPE
* yylocp
)
947 yyGLRStackItem
* yynewItem
;
949 yynewItem
= yystack
->yynextFree
;
950 yystack
->yynextFree
+= 1;
951 yystack
->yyspaceLeft
-= 1;
952 yynewItem
->yystate
.yyisState
= yytrue
;
953 yynewItem
->yystate
.yylrState
= yylrState
;
954 yynewItem
->yystate
.yyposn
= yyposn
;
955 yynewItem
->yystate
.yyresolved
= yytrue
;
956 yynewItem
->yystate
.yypred
= yystack
->yytops
.yystates
[yyk
];
957 yystack
->yytops
.yystates
[yyk
] = &yynewItem
->yystate
;
958 yynewItem
->yystate
.yysemantics
.yysval
= yysval
;
959 yynewItem
->yystate
.yyloc
= *yylocp
;
960 if (yystack
->yyspaceLeft
< YYHEADROOM
)
961 yyexpandGLRStack (yystack
);
964 /** Shift to a new state on stack #K of STACK, to a new state
965 * corresponding to LR state LRSTATE, at input position POSN, with
966 * the (unresolved) semantic value of RHS under the action for RULE. */
968 yyglrShiftDefer (yyGLRStack
* yystack
, int yyk
, yyStateNum yylrState
,
969 size_t yyposn
, yyGLRState
* rhs
, yyRuleNum yyrule
)
971 yyGLRStackItem
* yynewItem
;
973 yynewItem
= yystack
->yynextFree
;
974 yynewItem
->yystate
.yyisState
= yytrue
;
975 yynewItem
->yystate
.yylrState
= yylrState
;
976 yynewItem
->yystate
.yyposn
= yyposn
;
977 yynewItem
->yystate
.yyresolved
= yyfalse
;
978 yynewItem
->yystate
.yypred
= yystack
->yytops
.yystates
[yyk
];
979 yynewItem
->yystate
.yysemantics
.yyfirstVal
= NULL
;
980 yystack
->yytops
.yystates
[yyk
] = &yynewItem
->yystate
;
981 yystack
->yynextFree
+= 1;
982 yystack
->yyspaceLeft
-= 1;
983 yyaddDeferredAction (yystack
, &yynewItem
->yystate
, rhs
, yyrule
);
986 /** Pop the symbols consumed by reduction #RULE from the top of stack
987 * #K of STACK, and perform the appropriate semantic action on their
988 * semantic values. Assumes that all ambiguities in semantic values
989 * have been previously resolved. Set *VALP to the resulting value,
990 * and *LOCP to the computed location (if any). Return value is as
993 yydoAction (yyGLRStack
* yystack
, int yyk
, yyRuleNum yyrule
,
994 YYSTYPE
* yyvalp
, YYLTYPE
* yylocp YY_USER_FORMALS
)
996 int yynrhs
= yyrhsLength (yyrule
);
998 if (yystack
->yysplitPoint
== NULL
)
1000 /* Standard special case: single stack. */
1001 yyGLRStackItem
* rhs
= (yyGLRStackItem
*) yystack
->yytops
.yystates
[yyk
];
1003 yystack
->yynextFree
-= yynrhs
;
1004 yystack
->yyspaceLeft
+= yynrhs
;
1005 yystack
->yytops
.yystates
[0] = & yystack
->yynextFree
[-1].yystate
;
1008 *yyvalp
= yyval_default
;
1009 *yylocp
= yyloc_default
;
1013 *yyvalp
= rhs
[1-yynrhs
].yystate
.yysemantics
.yysval
;
1014 *yylocp
= rhs
[1-yynrhs
].yystate
.yyloc
;
1016 return yyuserAction (yyrule
, yynrhs
, rhs
,
1017 yyvalp
, yylocp
, yystack YY_USER_ARGS
);
1023 yyGLRStackItem yyrhsVals
[YYMAXRHS
];
1024 for (yyi
= yynrhs
-1, yys
= yystack
->yytops
.yystates
[yyk
]; 0 <= yyi
;
1025 yyi
-= 1, yys
= yys
->yypred
)
1027 assert (yys
->yypred
!= NULL
);
1028 yyrhsVals
[yyi
].yystate
.yyresolved
= yytrue
;
1029 yyrhsVals
[yyi
].yystate
.yysemantics
.yysval
= yys
->yysemantics
.yysval
;
1030 yyrhsVals
[yyi
].yystate
.yyloc
= yys
->yyloc
;
1032 yyupdateSplit (yystack
, yys
);
1033 yystack
->yytops
.yystates
[yyk
] = yys
;
1036 *yyvalp
= yyval_default
;
1037 *yylocp
= yyloc_default
;
1041 *yyvalp
= yyrhsVals
[0].yystate
.yysemantics
.yysval
;
1042 *yylocp
= yyrhsVals
[0].yystate
.yyloc
;
1044 return yyuserAction (yyrule
, yynrhs
, yyrhsVals
+ (yynrhs
-1),
1045 yyvalp
, yylocp
, yystack YY_USER_ARGS
);
1050 # define YY_REDUCE_PRINT(K, Rule)
1052 # define YY_REDUCE_PRINT(K, Rule) \
1055 yy_reduce_print (K, Rule); \
1058 /*----------------------------------------------------------.
1059 | Report that the RULE is going to be reduced on stack #K. |
1060 `----------------------------------------------------------*/
1063 yy_reduce_print (size_t yyk
, yyRuleNum yyrule
)
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
]));
1075 /** Pop items off stack #K of STACK according to grammar rule RULE,
1076 * and push back on the resulting nonterminal symbol. Perform the
1077 * semantic action associated with RULE and store its value with the
1078 * newly pushed state, if FORCEEVAL or if STACK is currently
1079 * unambiguous. Otherwise, store the deferred semantic action with
1080 * the new state. If the new state would have an identical input
1081 * position, LR state, and predecessor to an existing state on the stack,
1082 * it is identified with that existing state, eliminating stack #K from
1083 * the STACK. In this case, the (necessarily deferred) semantic value is
1084 * added to the options for the existing state's semantic value.
1086 static inline YYRESULTTAG
1087 yyglrReduce (yyGLRStack
* yystack
, size_t yyk
, yyRuleNum yyrule
,
1088 bool yyforceEval YY_USER_FORMALS
)
1090 size_t yyposn
= yystack
->yytops
.yystates
[yyk
]->yyposn
;
1092 if (yyforceEval
|| yystack
->yysplitPoint
== NULL
)
1097 YY_REDUCE_PRINT (yyk
, yyrule
);
1098 YYCHK (yydoAction (yystack
, yyk
, yyrule
, &yysval
, &yyloc YY_USER_ARGS
));
1099 yyglrShift (yystack
, yyk
,
1100 yyLRgotoState (yystack
->yytops
.yystates
[yyk
]->yylrState
,
1101 yylhsNonterm (yyrule
)),
1102 yyposn
, yysval
, &yyloc
);
1103 YYDPRINTF ((stderr
, "Stack %d entering state %d\n",
1104 yyk
, yystack
->yytops
.yystates
[yyk
]->yylrState
));
1110 yyGLRState
* yys
, *yys0
= yystack
->yytops
.yystates
[yyk
];
1111 yyStateNum yynewLRState
;
1113 for (yys
= yystack
->yytops
.yystates
[yyk
], yyn
= yyrhsLength (yyrule
);
1117 assert (yys
!= NULL
);
1119 yyupdateSplit (yystack
, yys
);
1120 yynewLRState
= yyLRgotoState (yys
->yylrState
, yylhsNonterm (yyrule
));
1122 "Reduced stack %d by rule #%d; action deferred. "
1123 "Now in state %d.\n",
1124 yyk
, yyrule
-1, yynewLRState
));
1125 for (yyi
= 0; yyi
< yystack
->yytops
.yysize
; yyi
+= 1)
1126 if (yyi
!= yyk
&& yystack
->yytops
.yystates
[yyi
] != NULL
)
1128 yyGLRState
* yyp
, *yysplit
= yystack
->yysplitPoint
;
1129 yyp
= yystack
->yytops
.yystates
[yyi
];
1130 while (yyp
!= yys
&& yyp
!= yysplit
&& yyp
->yyposn
>= yyposn
)
1132 if (yyp
->yylrState
== yynewLRState
&& yyp
->yypred
== yys
)
1134 yyaddDeferredAction (yystack
, yyp
, yys0
, yyrule
);
1135 yymarkStackDeleted (yystack
, yyk
);
1136 YYDPRINTF ((stderr
, "Merging stack %d into stack %d.\n",
1143 yystack
->yytops
.yystates
[yyk
] = yys
;
1144 yyglrShiftDefer (yystack
, yyk
, yynewLRState
, yyposn
, yys0
, yyrule
);
1150 yysplitStack (yyGLRStack
* yystack
, int yyk
)
1152 if (yystack
->yysplitPoint
== NULL
)
1155 yystack
->yysplitPoint
= yystack
->yytops
.yystates
[yyk
];
1157 if (yystack
->yytops
.yysize
>= yystack
->yytops
.yycapacity
)
1159 yystack
->yytops
.yycapacity
*= 2;
1160 yystack
->yytops
.yystates
=
1161 (yyGLRState
**) realloc (yystack
->yytops
.yystates
,
1162 yystack
->yytops
.yycapacity
1163 * sizeof (yyGLRState
*));
1165 yystack
->yytops
.yystates
[yystack
->yytops
.yysize
]
1166 = yystack
->yytops
.yystates
[yyk
];
1167 yystack
->yytops
.yysize
+= 1;
1168 return yystack
->yytops
.yysize
-1;
1171 /** True iff Y0 and Y1 represent identical options at the top level.
1172 * That is, they represent the same rule applied to RHS symbols
1173 * that produce the same terminal symbols. */
1175 yyidenticalOptions (yySemanticOption
* yyy0
, yySemanticOption
* yyy1
)
1177 if (yyy0
->yyrule
== yyy1
->yyrule
)
1179 yyGLRState
*yys0
, *yys1
;
1181 for (yys0
= yyy0
->yystate
, yys1
= yyy1
->yystate
,
1182 yyn
= yyrhsLength (yyy0
->yyrule
);
1184 yys0
= yys0
->yypred
, yys1
= yys1
->yypred
, yyn
-= 1)
1185 if (yys0
->yyposn
!= yys1
->yyposn
)
1193 /** Assuming identicalOptions (Y0,Y1), (destructively) merge the
1194 * alternative semantic values for the RHS-symbols of Y1 into the
1195 * corresponding semantic value sets of the symbols of Y0. */
1197 yymergeOptionSets (yySemanticOption
* yyy0
, yySemanticOption
* yyy1
)
1199 yyGLRState
*yys0
, *yys1
;
1201 for (yys0
= yyy0
->yystate
, yys1
= yyy1
->yystate
,
1202 yyn
= yyrhsLength (yyy0
->yyrule
);
1204 yys0
= yys0
->yypred
, yys1
= yys1
->yypred
, yyn
-= 1)
1207 else if (! yys0
->yyresolved
&& ! yys1
->yyresolved
)
1209 yySemanticOption
* yyz
;
1210 for (yyz
= yys0
->yysemantics
.yyfirstVal
; yyz
->yynext
!= NULL
;
1213 yyz
->yynext
= yys1
->yysemantics
.yyfirstVal
;
1217 /** Y0 and Y1 represent two possible actions to take in a given
1218 * parsing state; return 0 if no combination is possible,
1219 * 1 if user-mergeable, 2 if Y0 is preferred, 3 if Y1 is preferred. */
1221 yypreference (yySemanticOption
* y0
, yySemanticOption
* y1
)
1223 yyRuleNum r0
= y0
->yyrule
, r1
= y1
->yyrule
;
1224 int p0
= yydprec
[r0
], p1
= yydprec
[r1
];
1228 if (yymerger
[r0
] == 0 || yymerger
[r0
] != yymerger
[r1
])
1233 if (p0
== 0 || p1
== 0)
1242 static YYRESULTTAG
yyresolveValue (yySemanticOption
* yyoptionList
,
1243 yyGLRStack
* yystack
, YYSTYPE
* yyvalp
,
1244 YYLTYPE
* yylocp YY_USER_FORMALS
);
1247 yyresolveStates (yyGLRState
* yys
, int yyn
, yyGLRStack
* yystack YY_USER_FORMALS
)
1252 assert (yys
->yypred
!= NULL
);
1253 yyflag
= yyresolveStates (yys
->yypred
, yyn
-1, yystack YY_USER_ARGS
);
1256 if (! yys
->yyresolved
)
1258 yyflag
= yyresolveValue (yys
->yysemantics
.yyfirstVal
, yystack
,
1259 &yys
->yysemantics
.yysval
, &yys
->yyloc
1263 yys
->yyresolved
= yytrue
;
1270 yyresolveAction (yySemanticOption
* yyopt
, yyGLRStack
* yystack
,
1271 YYSTYPE
* yyvalp
, YYLTYPE
* yylocp YY_USER_FORMALS
)
1273 yyGLRStackItem yyrhsVals
[YYMAXRHS
];
1277 yynrhs
= yyrhsLength (yyopt
->yyrule
);
1278 YYCHK (yyresolveStates (yyopt
->yystate
, yynrhs
, yystack YY_USER_ARGS
));
1279 for (yyi
= yynrhs
-1, yys
= yyopt
->yystate
; 0 <= yyi
;
1280 yyi
-= 1, yys
= yys
->yypred
)
1282 assert (yys
->yypred
!= NULL
);
1283 yyrhsVals
[yyi
].yystate
.yyresolved
= yytrue
;
1284 yyrhsVals
[yyi
].yystate
.yysemantics
.yysval
= yys
->yysemantics
.yysval
;
1285 yyrhsVals
[yyi
].yystate
.yyloc
= yys
->yyloc
;
1287 return yyuserAction (yyopt
->yyrule
, yynrhs
, yyrhsVals
+ (yynrhs
-1),
1288 yyvalp
, yylocp
, yystack YY_USER_ARGS
);
1292 static yyGLRState YYLEFTMOST_STATE
=
1294 0, 0, -1, NULL
, 0, { NULL
},
1297 #if YYLTYPE_IS_TRIVIAL
1298 ]b4_location_if([ 0, 0, 0, 0])[
1304 yyreportTree (yySemanticOption
* yyx
, int yyindent
)
1306 int yynrhs
= yyrhsLength (yyx
->yyrule
);
1309 yyGLRState
* yystates
[YYMAXRHS
];
1311 for (yyi
= yynrhs
, yys
= yyx
->yystate
; 0 < yyi
; yyi
-= 1, yys
= yys
->yypred
)
1312 yystates
[yyi
] = yys
;
1314 yystates
[0] = &YYLEFTMOST_STATE
;
1318 if (yyx
->yystate
->yyposn
< yys
->yyposn
+ 1)
1319 YYFPRINTF (stderr
, "%*s%s -> <Rule %d, empty>\n",
1320 yyindent
, "", yytokenName (yylhsNonterm (yyx
->yyrule
)),
1323 YYFPRINTF (stderr
, "%*s%s -> <Rule %d, tokens %d .. %d>\n",
1324 yyindent
, "", yytokenName (yylhsNonterm (yyx
->yyrule
)),
1325 yyx
->yyrule
, yys
->yyposn
+1, yyx
->yystate
->yyposn
);
1326 for (yyi
= 1; yyi
<= yynrhs
; yyi
+= 1)
1328 if (yystates
[yyi
]->yyresolved
)
1330 if (yystates
[yyi
-1]->yyposn
+1 > yystates
[yyi
]->yyposn
)
1331 YYFPRINTF (stderr
, "%*s%s <empty>\n", yyindent
+2, "",
1332 yytokenName (yyrhs
[yyprhs
[yyx
->yyrule
]+yyi
-1]));
1334 YYFPRINTF (stderr
, "%*s%s <tokens %d .. %d>\n", yyindent
+2, "",
1335 yytokenName (yyrhs
[yyprhs
[yyx
->yyrule
]+yyi
-1]),
1336 yystates
[yyi
-1]->yyposn
+1, yystates
[yyi
]->yyposn
);
1339 yyreportTree (yystates
[yyi
]->yysemantics
.yyfirstVal
, yyindent
+2);
1345 yyreportAmbiguity (yySemanticOption
* yyx0
, yySemanticOption
* yyx1
,
1346 yyGLRStack
* yystack
)
1348 /* `Unused' warnings. */
1353 YYFPRINTF (stderr
, "Ambiguity detected.\n");
1354 YYFPRINTF (stderr
, "Option 1,\n");
1355 yyreportTree (yyx0
, 2);
1356 YYFPRINTF (stderr
, "\nOption 2,\n");
1357 yyreportTree (yyx1
, 2);
1358 YYFPRINTF (stderr
, "\n");
1360 yyFail (yystack
, "ambiguity detected");
1364 /** Resolve the ambiguity represented by OPTIONLIST, perform the indicated
1365 * actions, and return the result. */
1367 yyresolveValue (yySemanticOption
* yyoptionList
, yyGLRStack
* yystack
,
1368 YYSTYPE
* yyvalp
, YYLTYPE
* yylocp YY_USER_FORMALS
)
1370 yySemanticOption
* yybest
;
1371 yySemanticOption
* yyp
;
1374 yybest
= yyoptionList
;
1376 for (yyp
= yyoptionList
->yynext
; yyp
!= NULL
; yyp
= yyp
->yynext
)
1378 if (yyidenticalOptions (yybest
, yyp
))
1379 yymergeOptionSets (yybest
, yyp
);
1381 switch (yypreference (yybest
, yyp
))
1384 yyreportAmbiguity (yybest
, yyp
, yystack
);
1400 int yyprec
= yydprec
[yybest
->yyrule
];
1401 YYCHK (yyresolveAction (yybest
, yystack
, yyvalp
, yylocp YY_USER_ARGS
));
1402 for (yyp
= yybest
->yynext
; yyp
!= NULL
; yyp
= yyp
->yynext
)
1404 if (yyprec
== yydprec
[yyp
->yyrule
])
1408 YYCHK (yyresolveAction (yyp
, yystack
, &yyval1
, &yydummy YY_USER_ARGS
));
1409 *yyvalp
= yyuserMerge (yymerger
[yyp
->yyrule
], yyvalp
, &yyval1
);
1415 return yyresolveAction (yybest
, yystack
, yyvalp
, yylocp YY_USER_ARGS
);
1419 yyresolveStack (yyGLRStack
* yystack YY_USER_FORMALS
)
1421 if (yystack
->yysplitPoint
!= NULL
)
1426 for (yyn
= 0, yys
= yystack
->yytops
.yystates
[0];
1427 yys
!= yystack
->yysplitPoint
;
1428 yys
= yys
->yypred
, yyn
+= 1)
1430 YYCHK (yyresolveStates (yystack
->yytops
.yystates
[0], yyn
, yystack
1437 yycompressStack (yyGLRStack
* yystack
)
1439 yyGLRState
* yyp
, *yyq
, *yyr
;
1441 if (yystack
->yytops
.yysize
!= 1 || yystack
->yysplitPoint
== NULL
)
1444 for (yyp
= yystack
->yytops
.yystates
[0], yyq
= yyp
->yypred
, yyr
= NULL
;
1445 yyp
!= yystack
->yysplitPoint
;
1446 yyr
= yyp
, yyp
= yyq
, yyq
= yyp
->yypred
)
1449 yystack
->yyspaceLeft
+= yystack
->yynextFree
- yystack
->yyitems
;
1450 yystack
->yynextFree
= ((yyGLRStackItem
*) yystack
->yysplitPoint
) + 1;
1451 yystack
->yyspaceLeft
-= yystack
->yynextFree
- yystack
->yyitems
;
1452 yystack
->yysplitPoint
= NULL
;
1453 yystack
->yylastDeleted
= NULL
;
1457 yystack
->yynextFree
->yystate
= *yyr
;
1459 yystack
->yynextFree
->yystate
.yypred
= & yystack
->yynextFree
[-1].yystate
;
1460 yystack
->yytops
.yystates
[0] = &yystack
->yynextFree
->yystate
;
1461 yystack
->yynextFree
+= 1;
1462 yystack
->yyspaceLeft
-= 1;
1467 yyprocessOneStack (yyGLRStack
* yystack
, int yyk
,
1468 size_t yyposn
, YYSTYPE
* yylvalp
, YYLTYPE
* yyllocp
1472 const short* yyconflicts
;
1474 yySymbol
* const yytokenp
= yystack
->yytokenp
;
1476 while (yystack
->yytops
.yystates
[yyk
] != NULL
)
1478 yyStateNum yystate
= yystack
->yytops
.yystates
[yyk
]->yylrState
;
1480 assert (yystate
!= YYFINAL
);
1481 if (yyisDefaultedState (yystate
))
1483 yyrule
= yydefaultAction (yystate
);
1486 YYDPRINTF ((stderr
, "Stack %d dies.\n", yyk
));
1487 yymarkStackDeleted (yystack
, yyk
);
1490 YYCHK (yyglrReduce (yystack
, yyk
, yyrule
, yyfalse YY_USER_ARGS
));
1494 if (*yytokenp
== YYEMPTY
)
1496 YYDPRINTF ((stderr
, "Reading a token: "));
1498 *yytokenp
= YYTRANSLATE(yychar
);
1499 YYDPRINTF ((stderr
, "Next token is %s\n",
1500 yytokenName (*yytokenp
)));
1502 yygetLRActions (yystate
, *yytokenp
, &yyaction
, &yyconflicts
);
1504 while (*yyconflicts
!= 0)
1506 int yynewStack
= yysplitStack (yystack
, yyk
);
1507 YYDPRINTF ((stderr
, "Splitting off stack %d from %d.\n",
1509 YYCHK (yyglrReduce (yystack
, yynewStack
,
1510 *yyconflicts
, yyfalse YY_USER_ARGS
));
1511 YYCHK (yyprocessOneStack (yystack
, yynewStack
, yyposn
,
1512 yylvalp
, yyllocp YY_USER_ARGS
));
1516 if (yyisShiftAction (yyaction
))
1518 YYDPRINTF ((stderr
, "Shifting token %s on stack %d, ",
1519 yytokenName (*yytokenp
), yyk
));
1520 yyglrShift (yystack
, yyk
, yyaction
, yyposn
+1, *yylvalp
, yyllocp
);
1521 YYDPRINTF ((stderr
, "which is now in state #%d\n",
1522 yystack
->yytops
.yystates
[yyk
]->yylrState
));
1525 else if (yyisErrorAction (yyaction
))
1527 YYDPRINTF ((stderr
, "Stack %d dies.\n", yyk
));
1528 yymarkStackDeleted (yystack
, yyk
);
1532 YYCHK (yyglrReduce (yystack
, yyk
, -yyaction
, yyfalse YY_USER_ARGS
));
1539 yyreportParseError (yyGLRStack
* yystack
, YYSTYPE
* yylvalp
, YYLTYPE
* yyllocp
)
1541 /* `Unused' warnings. */
1545 if (yystack
->yyerrState
== 0)
1548 yySymbol
* const yytokenp
= yystack
->yytokenp
;
1549 int yyn
, yyx
, yycount
;
1551 const char* yyprefix
;
1554 yyn
= yypact
[yystack
->yytops
.yystates
[0]->yylrState
];
1555 if (YYPACT_NINF
< yyn
&& yyn
< YYLAST
)
1558 /* Start YYX at -YYN if negative to avoid negative indexes in
1560 yysize
= sizeof ("parse error, unexpected ")
1561 + strlen (yytokenName (*yytokenp
));
1562 yyprefix
= ", expecting ";
1563 for (yyx
= yyn
< 0 ? -yyn
: 0; yyx
< yytname_size
&& yycount
<= 5;
1565 if (yycheck
[yyx
+ yyn
] == yyx
&& yyx
!= YYTERROR
)
1566 yysize
+= strlen (yytokenName (yyx
)) + strlen (yyprefix
),
1567 yycount
+= 1, yyprefix
= " or ";
1568 yymsg
= yyp
= (char*) malloc (yysize
);
1569 sprintf (yyp
, "parse error, unexpected %s",
1570 yytokenName (*yytokenp
));
1571 yyp
+= strlen (yyp
);
1574 yyprefix
= ", expecting ";
1575 for (yyx
= yyn
< 0 ? -yyn
: 0; yyx
< yytname_size
; yyx
+= 1)
1576 if (yycheck
[yyx
+ yyn
] == yyx
&& yyx
!= YYTERROR
)
1578 sprintf (yyp
, "%s%s", yyprefix
, yytokenName (yyx
));
1579 yyp
+= strlen (yyp
);
1588 yyerror ("parse error");
1593 /* Recover from a syntax error on YYSTACK, assuming that YYTOKENP,
1594 YYLVALP, and YYLLOCP point to the syntactic category, semantic
1595 value, and location of the lookahead. */
1597 yyrecoverParseError (yyGLRStack
* yystack
, YYSTYPE
* yylvalp
, YYLTYPE
* yyllocp
)
1599 yySymbol
* const yytokenp
= yystack
->yytokenp
;
1603 if (yystack
->yyerrState
== 0)
1604 yystack
->yyerrState
= 3;
1605 else if (yystack
->yyerrState
== 3)
1606 /* We just shifted the error token and (perhaps) took some
1607 reductions. Skip tokens until we can proceed. */
1610 if (*yytokenp
== YYEOF
)
1611 yyFail (yystack
, NULL
);
1612 if (*yytokenp
!= YYEMPTY
)
1613 YYDPRINTF ((stderr
, "Discarding token %s\n",
1614 yytokenName (*yytokenp
)));
1615 YYDPRINTF ((stderr
, "Reading a token: "));
1617 *yytokenp
= YYTRANSLATE (yychar
);
1618 YYDPRINTF ((stderr
, "Next token is %s\n", yytokenName (*yytokenp
)));
1619 yyj
= yypact
[yystack
->yytops
.yystates
[0]->yylrState
];
1620 if (yyj
== YYPACT_NINF
)
1621 /* Something's not right; we shouldn't be here. */
1622 yyFail (yystack
, NULL
);
1624 if (yyj
< 0 || YYLAST
< yyj
|| yycheck
[yyj
] != *yytokenp
)
1626 if (yydefact
[yystack
->yytops
.yystates
[0]->yylrState
] != 0)
1629 else if (yytable
[yyj
] != 0 && yytable
[yyj
] != YYTABLE_NINF
)
1633 /* Reduce to one stack. */
1634 for (yyk
= 0; yyk
< yystack
->yytops
.yysize
; yyk
+= 1)
1635 if (yystack
->yytops
.yystates
[yyk
] != NULL
)
1637 if (yyk
>= yystack
->yytops
.yysize
)
1638 yyFail (yystack
, NULL
);
1639 for (yyk
+= 1; yyk
< yystack
->yytops
.yysize
; yyk
+= 1)
1640 yymarkStackDeleted (yystack
, yyk
);
1641 yyremoveDeletes (yystack
);
1642 yycompressStack (yystack
);
1644 /* Now pop stack until we find a state that shifts the error token. */
1645 while (yystack
->yytops
.yystates
[0] != NULL
)
1647 yyj
= yypact
[yystack
->yytops
.yystates
[0]->yylrState
] + YYTERROR
;
1648 if (yyj
!= YYPACT_NINF
+ YYTERROR
&& yyj
>= 0 && yyj
<= YYLAST
&&
1649 yycheck
[yyj
] == YYTERROR
&& yyisShiftAction (yytable
[yyj
]))
1651 yyglrShift (yystack
, 0, yytable
[yyj
],
1652 yystack
->yytops
.yystates
[0]->yyposn
, *yylvalp
, yyllocp
);
1655 yystack
->yytops
.yystates
[0] = yystack
->yytops
.yystates
[0]->yypred
;
1656 yystack
->yynextFree
-= 1;
1657 yystack
->yyspaceLeft
+= 1;
1659 if (yystack
->yytops
.yystates
[0] == NULL
)
1660 yyFail (yystack
, NULL
);
1663 #define YYCHK1(YYE) \
1669 yystack.yyerrflag = 1; \
1672 yystack.yyerrflag = 0; \
1675 goto yyuser_error; \
1684 ]b4_c_ansi_function_def([yyparse
], [int], b4_parse_param
)[
1694 #define yychar (yystack.yyrawchar)
1697 YYSTYPE
* const yylvalp
= &yylval
;
1698 YYLTYPE
* const yyllocp
= &yylloc
;
1700 yyinitGLRStack (&yystack
, YYINITDEPTH
);
1701 yystack
.yytokenp
= &yytoken
;
1703 YYDPRINTF ((stderr
, "Starting parse\n"));
1705 if (setjmp (yystack
.yyexception_buffer
) != 0)
1708 yyglrShift (&yystack
, 0, 0, 0, yyval_default
, &yyloc_default
);
1714 /* For efficiency, we have two loops, the first of which is
1715 specialized to deterministic operation (single stack, no
1716 potential ambiguity). */
1723 const short* yyconflicts
;
1725 yyStateNum yystate
= yystack
.yytops
.yystates
[0]->yylrState
;
1726 if (yystate
== YYFINAL
)
1728 if (yyisDefaultedState (yystate
))
1730 yyrule
= yydefaultAction (yystate
);
1733 yyreportParseError (&yystack
, yylvalp
, yyllocp
);
1736 YYCHK1 (yyglrReduce (&yystack
, 0, yyrule
, yytrue YY_USER_ARGS
));
1740 if (yytoken
== YYEMPTY
)
1742 YYDPRINTF ((stderr
, "Reading a token: "));
1744 yytoken
= YYTRANSLATE (yychar
);
1745 YYDPRINTF ((stderr
, "Next token is %s\n",
1746 yytokenName (yytoken
)));
1748 yygetLRActions (yystate
, yytoken
, &yyaction
, &yyconflicts
);
1749 if (*yyconflicts
!= 0)
1751 if (yyisShiftAction (yyaction
))
1753 YYDPRINTF ((stderr
, "Shifting token %s, ",
1754 yytokenName (yytoken
)));
1755 if (yytoken
!= YYEOF
)
1758 yyglrShift (&yystack
, 0, yyaction
, yyposn
, yylval
, yyllocp
);
1759 if (0 < yystack
.yyerrState
)
1760 yystack
.yyerrState
-= 1;
1761 YYDPRINTF ((stderr
, "Entering state %d\n",
1762 yystack
.yytops
.yystates
[0]->yylrState
));
1764 else if (yyisErrorAction (yyaction
))
1766 yyreportParseError (&yystack
, yylvalp
, yyllocp
);
1770 YYCHK1 (yyglrReduce (&yystack
, 0, -yyaction
, yytrue YY_USER_ARGS
));
1777 int yyn
= yystack
.yytops
.yysize
;
1778 for (yys
= 0; yys
< yyn
; yys
+= 1)
1779 YYCHK1 (yyprocessOneStack (&yystack
, yys
, yyposn
,
1780 yylvalp
, yyllocp YY_USER_ARGS
));
1783 yyremoveDeletes (&yystack
);
1784 if (yystack
.yytops
.yysize
== 0)
1786 yyundeleteLastStack (&yystack
);
1787 if (yystack
.yytops
.yysize
== 0)
1788 yyFail (&yystack
, "parse error");
1789 YYCHK1 (yyresolveStack (&yystack YY_USER_ARGS
));
1790 YYDPRINTF ((stderr
, "Returning to deterministic operation.\n"));
1791 yyreportParseError (&yystack
, yylvalp
, yyllocp
);
1794 else if (yystack
.yytops
.yysize
== 1)
1796 YYCHK1 (yyresolveStack (&yystack YY_USER_ARGS
));
1797 YYDPRINTF ((stderr
, "Returning to deterministic operation.\n"));
1798 yycompressStack (&yystack
);
1804 yyrecoverParseError (&yystack
, yylvalp
, yyllocp
);
1805 yyposn
= yystack
.yytops
.yystates
[0]->yyposn
;
1810 yyfreeGLRStack (&yystack
);
1811 return yystack
.yyerrflag
;
1814 /* DEBUGGING ONLY */
1815 static void yypstack (yyGLRStack
* yystack
, int yyk
) ATTRIBUTE_UNUSED
;
1816 static void yypdumpstack (yyGLRStack
* yystack
) ATTRIBUTE_UNUSED
;
1819 yy_yypstack (yyGLRState
* yys
)
1823 yy_yypstack (yys
->yypred
);
1824 fprintf (stderr
, " -> ");
1826 fprintf (stderr
, "%d@%lu", yys
->yylrState
, (unsigned long) yys
->yyposn
);
1830 yypstates (yyGLRState
* yyst
)
1833 fprintf (stderr
, "<null>");
1836 fprintf (stderr
, "\n");
1840 yypstack (yyGLRStack
* yystack
, int yyk
)
1842 yypstates (yystack
->yytops
.yystates
[yyk
]);
1845 #define YYINDEX(YYX) \
1846 ((YYX) == NULL ? -1 : (yyGLRStackItem*) (YYX) - yystack->yyitems)
1850 yypdumpstack (yyGLRStack
* yystack
)
1852 yyGLRStackItem
* yyp
;
1854 for (yyp
= yystack
->yyitems
; yyp
< yystack
->yynextFree
; yyp
+= 1)
1856 fprintf (stderr
, "%3lu. ", (unsigned long) (yyp
- yystack
->yyitems
));
1859 fprintf (stderr
, "Res: %d, LR State: %d, posn: %lu, pred: %ld",
1860 yyp
->yystate
.yyresolved
, yyp
->yystate
.yylrState
,
1861 (unsigned long) yyp
->yystate
.yyposn
,
1862 (long) YYINDEX (yyp
->yystate
.yypred
));
1863 if (! yyp
->yystate
.yyresolved
)
1864 fprintf (stderr
, ", firstVal: %ld",
1865 (long) YYINDEX (yyp
->yystate
.yysemantics
.yyfirstVal
));
1869 fprintf (stderr
, "Option. rule: %d, state: %ld, next: %ld",
1870 yyp
->yyoption
.yyrule
,
1871 (long) YYINDEX (yyp
->yyoption
.yystate
),
1872 (long) YYINDEX (yyp
->yyoption
.yynext
));
1874 fprintf (stderr
, "\n");
1876 fprintf (stderr
, "Tops:");
1877 for (yyi
= 0; yyi
< yystack
->yytops
.yysize
; yyi
+= 1)
1878 fprintf (stderr
, "%lu: %ld; ", (unsigned long) yyi
,
1879 (long) YYINDEX (yystack
->yytops
.yystates
[yyi
]));
1880 fprintf (stderr
, "\n");
1885 m4_if(b4_defines_flag
, 0, [],
1886 [#output "b4_output_header_name"
1887 b4_copyright([Skeleton parser
for GLR parsing with Bison
], [2002])
1888 #ifndef b4_header_guard
1889 # define b4_header_guard
1891 b4_token_defines(b4_tokens
)
1894 m4_ifdef([b4_stype
],
1895 [#line b4_stype_line "b4_filename"
1896 typedef union b4_stype yystype
;
1897 /* Line __line__ of __file__. */
1898 #line __oline__ "__ofile__"],
1899 [typedef int yystype
;])
1900 # define YYSTYPE yystype
1904 [extern YYSTYPE b4_prefix
[]lval
;])
1908 typedef struct yyltype
1915 # define YYLTYPE yyltype
1919 [extern YYLTYPE b4_prefix
[]lloc
;])
1921 #endif /* not b4_header_guard */