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
])
36 ## ------------------------ ##
37 ## Pure/impure interfaces. ##
38 ## ------------------------ ##
43 # Accumule in b4_lex_param all the yylex arguments.
44 # Yes, this is quite ugly...
45 m4_define([b4_lex_param
],
46 m4_dquote(b4_pure_if([[[[YYSTYPE
*]], [[yylvalp]]][]dnl
47 b4_location_if([, [[YYLTYPE
*], [yyllocp
]]])])dnl
48 m4_ifdef([b4_lex_param
], [, ]b4_lex_param
)))
53 m4_define([b4_user_formals
],
54 [m4_ifset([b4_parse_param
], [, b4_c_ansi_formals(b4_parse_param
)])])
59 # Arguments passed to yyerror: user args plus yylloc.
60 m4_define([b4_yyerror_args
],
61 [b4_pure_if([b4_location_if([yylocp
, ])])dnl
62 m4_ifset([b4_parse_param
], [b4_c_args(b4_parse_param
), ])])
67 # Same as above, but on the lookahead, hence yyllocp instead of yylocp.
68 m4_define([b4_lyyerror_args
],
69 [b4_pure_if([b4_location_if([yyllocp
, ])])dnl
70 m4_ifset([b4_parse_param
], [b4_c_args(b4_parse_param
), ])])
75 # Arguments needed by yyerror: user args plus yylloc.
76 m4_define([b4_pure_args
],
77 [b4_pure_if([b4_location_if([, yylocp
])])[]b4_user_args
])
82 # Arguments passed to yyerror: user formals plus yyllocp.
83 m4_define([b4_pure_formals
],
84 [b4_pure_if([b4_location_if([, YYLTYPE
*yylocp
])])[]b4_user_formals
])
89 # Same as above, but on the lookahead, hence yyllocp instead of yylocp.
90 m4_define([b4_lpure_args
],
91 [b4_pure_if([b4_location_if([, yyllocp
])])[]b4_user_args
])
96 # Same as above, but on the lookahead, hence yyllocp instead of yylocp.
97 m4_define([b4_lpure_formals
],
98 [b4_pure_if([b4_location_if([YYLTYPE
*yyllocp
])])[]b4_user_formals
])
101 ## ----------------- ##
102 ## Semantic Values. ##
103 ## ----------------- ##
106 # b4_lhs_value([TYPE])
107 # --------------------
108 # Expansion of $<TYPE>$.
109 m4_define([b4_lhs_value
],
110 [(*yyvalp
)[]m4_ifval([$
1], [.$
1])])
113 # b4_rhs_value(RULE-LENGTH, NUM, [TYPE])
114 # --------------------------------------
115 # Expansion of $<TYPE>NUM, where the current rule has RULE-LENGTH
117 m4_define([b4_rhs_value
],
118 [yyvsp@
{m4_eval([$
2 - $
1])@
}.yystate
.yysemantics
.yysval
[]m4_ifval([$
3], [.$
3])])
129 m4_define([b4_lhs_location
],
133 # b4_rhs_location(RULE-LENGTH, NUM)
134 # ---------------------------------
135 # Expansion of @NUM, where the current rule has RULE-LENGTH symbols
137 m4_define([b4_rhs_location
],
138 [yyvsp@
{m4_eval([$
2 - $
1])@
}.yystate
.yyloc
])
141 # We do want M4 expansion after # for CPP macros.
144 @output @output_parser_name@
145 b4_copyright([Skeleton parser
for GLR parsing with Bison
], [2002])
147 /* This is the parser code for GLR (Generalized LR) parser. */
157 m4_if(b4_prefix
[], [yy
], [],
158 [/* If NAME_PREFIX is specified substitute the variables and functions
160 #define yyparse b4_prefix[]parse
161 #define yylex b4_prefix[]lex
162 #define yyerror b4_prefix[]error
163 #define yylval b4_prefix[]lval
164 #define yychar b4_prefix[]char
165 #define yydebug b4_prefix[]debug
166 #define yynerrs b4_prefix[]nerrs
167 b4_location_if([#define yylloc b4_prefix[]lloc])])
169 b4_token_defines(b4_tokens
)
171 /* Copy the first part of user declarations. */
174 /* Enabling traces. */
176 # define YYDEBUG ]b4_debug[
179 /* Enabling verbose error messages. */
180 #ifdef YYERROR_VERBOSE
181 # undef YYERROR_VERBOSE
182 # define YYERROR_VERBOSE 1
184 # define YYERROR_VERBOSE ]b4_error_verbose[
188 ]m4_ifdef([b4_stype
],
189 [b4_syncline([b4_stype_line
], [b4_filename
])
190 typedef union b4_stype yystype
;
191 /* Line __line__ of __file__. */
192 b4_syncline([@oline@
], [@ofile@
])],
193 [typedef int yystype
;])[
194 # define YYSTYPE yystype
195 # define YYSTYPE_IS_TRIVIAL 1
199 typedef struct yyltype
206 # define YYLTYPE ]b4_location_type[
207 # define YYLTYPE_IS_TRIVIAL 1
210 /* Default (constant) values used for initialization for null
211 right-hand sides. Unlike the standard bison.simple template,
212 here we set the default values of $$ and $@@ to zeroed-out
213 values. Since the default value of these quantities is undefined,
214 this behavior is technically correct. */
215 static YYSTYPE yyval_default
;
216 static YYLTYPE yyloc_default
;
218 /* Copy the second part of user declarations. */
221 ]/* Line __line__ of __file__. */
222 b4_syncline([@oline@
], [@ofile@
])
224 #if ! defined (__cplusplus)
234 #ifndef __attribute__
235 /* This feature is available in gcc versions 2.5 and later. */
236 # if !defined (__GNUC__) || __GNUC__ < 2 || \
237 (__GNUC__ == 2 && __GNUC_MINOR__ < 5) || __STRICT_ANSI__
238 # define __attribute__(Spec) /* empty */
242 #ifndef ATTRIBUTE_UNUSED
243 # define ATTRIBUTE_UNUSED __attribute__ ((__unused__))
246 #if ! defined (__GNUC__)
250 /* YYFINAL -- State number of the termination state. */
251 #define YYFINAL ]b4_final_state_number[
252 /* YYLAST -- Last index in YYTABLE. */
253 #define YYLAST ]b4_last[
255 /* YYNTOKENS -- Number of terminals. */
256 #define YYNTOKENS ]b4_tokens_number[
257 /* YYNNTS -- Number of nonterminals. */
258 #define YYNNTS ]b4_nterms_number[
259 /* YYNRULES -- Number of rules. */
260 #define YYNRULES ]b4_rules_number[
261 /* YYNRULES -- Number of states. */
262 #define YYNSTATES ]b4_states_number[
263 /* YYMAXRHS -- Maximum number of symbols on right-hand side of rule. */
264 #define YYMAXRHS ]b4_r2_max[
266 /* YYTRANSLATE(X) -- Bison symbol number corresponding to X. */
267 #define YYUNDEFTOK ]b4_undef_token_number[
268 #define YYMAXUTOK ]b4_user_token_number_max[
270 #define YYTRANSLATE(YYX) \
271 ((YYX <= 0) ? YYEOF : \
272 (unsigned)(YYX) <= YYMAXUTOK ? yytranslate[YYX] : YYUNDEFTOK)
274 /* YYTRANSLATE[YYLEX] -- Bison symbol number corresponding to YYLEX. */
275 static const ]b4_int_type_for([b4_translate
])[ yytranslate
[] =
281 /* YYPRHS[YYN] -- Index of the first RHS symbol of rule number YYN in
283 static const ]b4_int_type_for([b4_prhs
])[ yyprhs
[] =
288 /* YYRHS -- A `-1'-separated list of the rules' RHS. */
289 static const ]b4_int_type_for([b4_rhs
])[ yyrhs
[] =
294 /* YYRLINE[YYN] -- source line where rule number YYN was defined. */
295 static const ]b4_int_type_for([b4_rline
])[ yyrline
[] =
301 #if (YYDEBUG) || YYERROR_VERBOSE
302 /* YYTNME[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM.
303 First, the terminals, then, starting at YYNTOKENS, nonterminals. */
304 static const char *const yytname
[] =
309 #define yytname_size ((int) (sizeof (yytname) / sizeof (yytname[0])))
312 /* YYR1[YYN] -- Symbol number of symbol that rule YYN derives. */
313 static const ]b4_int_type_for([b4_r1
])[ yyr1
[] =
318 /* YYR2[YYN] -- Number of symbols composing right hand side of rule YYN. */
319 static const ]b4_int_type_for([b4_r2
])[ yyr2
[] =
324 /* YYDPREC[RULE-NUM] -- Dynamic precedence of rule #RULE-NUM (0 if none). */
325 static const ]b4_int_type_for([b4_dprec
])[ yydprec
[] =
330 /* YYMERGER[RULE-NUM] -- Index of merging function for rule #RULE-NUM. */
331 static const ]b4_int_type_for([b4_merger
])[ yymerger
[] =
336 /* YYDEFACT[S] -- default rule to reduce with in state S when YYTABLE
337 doesn't specify something else to do. Zero means the default is an
339 static const ]b4_int_type_for([b4_defact
])[ yydefact
[] =
344 /* YYPDEFGOTO[NTERM-NUM]. */
345 static const ]b4_int_type_for([b4_defgoto
])[ yydefgoto
[] =
350 /* YYPACT[STATE-NUM] -- Index in YYTABLE of the portion describing
352 #define YYPACT_NINF ]b4_pact_ninf[
353 static const ]b4_int_type_for([b4_pact
])[ yypact
[] =
358 /* YYPGOTO[NTERM-NUM]. */
359 static const ]b4_int_type_for([b4_pgoto
])[ yypgoto
[] =
364 /* YYTABLE[YYPACT[STATE-NUM]]. What to do in state STATE-NUM. If
365 positive, shift that token. If negative, reduce the rule which
366 number is the opposite. If zero, do what YYDEFACT says.
367 If YYTABLE_NINF, parse error. */
368 #define YYTABLE_NINF ]b4_table_ninf[
369 static const ]b4_int_type_for([b4_table
])[ yytable
[] =
374 /* YYCONFLP[YYPACT[STATE-NUM]] -- Pointer into YYCONFL of start of
375 list of conflicting reductions corresponding to action entry for
376 state STATE-NUM in yytable. 0 means no conflicts. The list in
377 yyconfl is terminated by a rule number of 0. */
378 static const ]b4_int_type_for([b4_conflict_list_heads
])[ yyconflp
[] =
380 ]b4_conflict_list_heads
[
383 /* YYCONFL[I] -- lists of conflicting rule numbers, each terminated by
384 0, pointed into by YYCONFLP. */
385 ]dnl Do
not use b4_int_type_for here
, since there are places where
386 dnl pointers onto yyconfl are taken
, which type is
"short *".
387 dnl We probably ought to introduce a type
for confl
.
388 [static const short yyconfl
[] =
390 ]b4_conflicting_rules
[
393 static const ]b4_int_type_for([b4_check
])[ yycheck
[] =
399 /* Prevent warning if -Wmissing-prototypes. */
400 ]b4_c_ansi_function_decl([yyparse
], [int], b4_parse_param
)[
402 /* Error token number */
405 /* YYLLOC_DEFAULT -- Compute the default location (before the actions
408 #define YYRHSLOC(yyRhs,YYK) (yyRhs[YYK].yystate.yyloc)
410 #ifndef YYLLOC_DEFAULT
411 # define YYLLOC_DEFAULT(yyCurrent, yyRhs, YYN) \
412 yyCurrent.first_line = YYRHSLOC(yyRhs,1).first_line; \
413 yyCurrent.first_column = YYRHSLOC(yyRhs,1).first_column; \
414 yyCurrent.last_line = YYRHSLOC(yyRhs,YYN).last_line; \
415 yyCurrent.last_column = YYRHSLOC(yyRhs,YYN).last_column;
418 /* YYLEX -- calling `yylex' with the right arguments. */
419 #define YYLEX ]b4_c_function_call([yylex], [int], b4_lex_param)[
424 #define yynerrs (yystack->yyerrcnt)
426 #define yychar (yystack->yyrawchar)],
434 static const int YYEOF
= 0;
435 static const int YYEMPTY
= -2;
437 typedef enum { yyok
, yyaccept
, yyabort
, yyerr
} YYRESULTTAG
;
440 do { YYRESULTTAG yyflag = YYE; if (yyflag != yyok) return yyflag; } \
445 #if ! defined (YYFPRINTF)
446 # define YYFPRINTF fprintf
449 # define YYDPRINTF(Args) \
454 /* Nonzero means print parse trace. It is left uninitialized so that
455 multiple parsers can coexist. */
458 /* Avoid empty `if' bodies. */
459 # define YYDPRINTF(Args) {}
460 #endif /* !YYDEBUG */
462 /* YYINITDEPTH -- initial size of the parser's stacks. */
464 # define YYINITDEPTH ]b4_stack_depth_init[
467 /* YYMAXDEPTH -- maximum size the stacks can grow to (effective only
468 if the built-in stack extension method is used).
470 Do not make this value too large; the results are undefined if
471 SIZE_MAX < YYMAXDEPTH * sizeof (GLRStackItem)
472 evaluated with infinite-precision integer arithmetic. */
479 # define YYMAXDEPTH ]b4_stack_depth_max[
482 /* Minimum number of free items on the stack allowed after an
483 allocation. This is to allow allocation and initialization
484 to be completed by functions that call expandGLRStack before the
485 stack is expanded, thus insuring that all necessary pointers get
486 properly redirected to new data. */
489 #if ! defined (YYSTACKEXPANDABLE) \
490 && (! defined (__cplusplus) || (YYLTYPE_IS_TRIVIAL && YYSTYPE_IS_TRIVIAL))
491 #define YYSTACKEXPANDABLE 1
493 #define YYSTACKEXPANDABLE 0
496 /** State numbers, as in LALR(1) machine */
497 typedef int yyStateNum
;
499 /** Rule numbers, as in LALR(1) machine */
500 typedef int yyRuleNum
;
502 /** Grammar symbol */
503 typedef short yySymbol
;
505 /** Item references, as in LALR(1) machine */
506 typedef short yyItemNum
;
508 typedef struct yyGLRState yyGLRState
;
509 typedef struct yySemanticOption yySemanticOption
;
510 typedef union yyGLRStackItem yyGLRStackItem
;
511 typedef struct yyGLRStack yyGLRStack
;
512 typedef struct yyGLRStateSet yyGLRStateSet
;
517 yyStateNum yylrState
;
521 yySemanticOption
* yyfirstVal
;
527 struct yyGLRStateSet
{
528 yyGLRState
** yystates
;
529 size_t yysize
, yycapacity
;
532 struct yySemanticOption
{
536 yySemanticOption
* yynext
;
539 union yyGLRStackItem
{
541 yySemanticOption yyoption
;
553 jmp_buf yyexception_buffer
;
554 yyGLRStackItem
* yyitems
;
555 yyGLRStackItem
* yynextFree
;
557 yyGLRState
* yysplitPoint
;
558 yyGLRState
* yylastDeleted
;
559 yyGLRStateSet yytops
;
562 static void yyinitGLRStack (yyGLRStack
* yystack
, size_t yysize
);
563 static void yyexpandGLRStack (yyGLRStack
* yystack
]b4_pure_formals
[);
564 static void yyfreeGLRStack (yyGLRStack
* yystack
);
567 yyFail (yyGLRStack
* yystack
]b4_pure_formals
[, const char* yyformat
, ...)
569 if (yyformat
!= NULL
)
573 va_start (yyap
, yyformat
);
574 yystack
->yyerrflag
= 1;
575 vsprintf (yymsg
, yyformat
, yyap
);
576 yyerror (]b4_yyerror_args
[yymsg
);
578 longjmp (yystack
->yyexception_buffer
, 1);
581 #if YYDEBUG || YYERROR_VERBOSE
582 /** A printable representation of TOKEN. Valid until next call to
584 static inline const char*
585 yytokenName (yySymbol yytoken
)
587 return yytname
[yytoken
];
591 /** Perform user action for rule number YYN, with RHS length YYRHSLEN,
592 * and top stack item YYVSP. YYLVALP points to place to put semantic
593 * value ($$), and yylocp points to place for location information
594 * (@@$). Returns yyok for normal return, yyaccept for YYACCEPT,
595 * yyerr for YYERROR, yyabort for YYABORT. */
597 yyuserAction (yyRuleNum yyn
, int yyrhslen
, yyGLRStackItem
* yyvsp
,
598 YYSTYPE
* yyvalp
, YYLTYPE
* yylocp
, yyGLRStack
* yystack
601 /* Avoid `unused' warnings in there are no $n. */
606 *yyvalp
= yyval_default
;
607 *yylocp
= yyloc_default
;
611 *yyvalp
= yyvsp
[1-yyrhslen
].yystate
.yysemantics
.yysval
;
612 *yylocp
= yyvsp
[1-yyrhslen
].yystate
.yyloc
;
615 # define yyval (*yyvalp)
617 # define yyerrok (yystack->yyerrState = 0)
619 # define YYACCEPT return yyaccept
621 # define YYABORT return yyabort
623 # define YYERROR return yyerr
625 # define YYRECOVERING (yystack->yyerrState != 0)
627 # define yyclearin (yychar = *(yystack->yytokenp) = YYEMPTY)
629 # define YYBACKUP(Token, Value) \
631 yyerror (]b4_yyerror_args["syntax error: cannot back up"); \
650 /* Line __line__ of __file__. */
651 b4_syncline([@oline@
], [@ofile@
])
656 yyuserMerge (int yyn
, YYSTYPE
* yy0
, YYSTYPE
* yy1
)
658 YYSTYPE yyval
= *yy0
;
659 /* `Use' the arguments. */
670 /* Bison grammar-table manipulation. */
672 /** Number of symbols composing the right hand side of rule #RULE. */
674 yyrhsLength (yyRuleNum yyrule
)
679 /** Left-hand-side symbol for rule #RULE. */
680 static inline yySymbol
681 yylhsNonterm (yyRuleNum yyrule
)
686 #define yyis_pact_ninf(yystate) \
687 ]m4_if(m4_eval(b4_pact_ninf < b4_pact_min), 1,
689 ((yystate
) == YYPACT_NINF
))[
691 /** True iff LR state STATE has only a default reduction (regardless
694 yyisDefaultedState (yyStateNum yystate
)
696 return yyis_pact_ninf (yypact
[yystate
]);
699 /** The default reduction for STATE, assuming it has one. */
700 static inline yyRuleNum
701 yydefaultAction (yyStateNum yystate
)
703 return yydefact
[yystate
];
706 #define yyis_table_ninf(yyindex) \
707 ]m4_if(m4_eval(b4_table_ninf < b4_table_min), 1,
709 ((yyindex
) == YYTABLE_NINF
))[
711 /** Set *YYACTION to the action to take in YYSTATE on seeing YYTOKEN.
713 * R < 0: Reduce on rule -R.
715 * R > 0: Shift to state R.
716 * Set *CONFLICTS to a pointer into yyconfl to 0-terminated list of
717 * conflicting reductions.
720 yygetLRActions (yyStateNum yystate
, int yytoken
,
721 int* yyaction
, const short** yyconflicts
)
723 int yyindex
= yypact
[yystate
] + yytoken
;
724 if (yyindex
< 0 || YYLAST
< yyindex
|| yycheck
[yyindex
] != yytoken
)
726 *yyaction
= -yydefact
[yystate
];
727 *yyconflicts
= yyconfl
;
729 else if (! yyis_table_ninf (yyindex
))
731 *yyaction
= yytable
[yyindex
];
732 *yyconflicts
= yyconfl
+ yyconflp
[yyindex
];
737 *yyconflicts
= yyconfl
+ yyconflp
[yyindex
];
741 static inline yyStateNum
742 yyLRgotoState (yyStateNum yystate
, yySymbol yylhs
)
745 yyr
= yypgoto
[yylhs
- YYNTOKENS
] + yystate
;
746 if (0 <= yyr
&& yyr
<= YYLAST
&& yycheck
[yyr
] == yystate
)
749 return yydefgoto
[yylhs
- YYNTOKENS
];
753 yyisShiftAction (int yyaction
)
759 yyisErrorAction (int yyaction
)
761 return yyaction
== 0;
766 /** True iff the semantic value of the edge leading to STATE is
769 yyhasResolvedValue (yyGLRState
* yystate
)
771 return yystate
->yyresolved
;
775 yyaddDeferredAction (yyGLRStack
* yystack
, yyGLRState
* yystate
,
776 yyGLRState
* rhs
, yyRuleNum yyrule
]b4_pure_formals
[)
778 yySemanticOption
* yynewItem
;
779 yynewItem
= &yystack
->yynextFree
->yyoption
;
780 yystack
->yyspaceLeft
-= 1;
781 yystack
->yynextFree
+= 1;
782 yynewItem
->yyisState
= yyfalse
;
783 yynewItem
->yystate
= rhs
;
784 yynewItem
->yyrule
= yyrule
;
785 yynewItem
->yynext
= yystate
->yysemantics
.yyfirstVal
;
786 yystate
->yysemantics
.yyfirstVal
= yynewItem
;
787 if (yystack
->yyspaceLeft
< YYHEADROOM
)
788 yyexpandGLRStack (yystack
]b4_pure_args
[);
793 /** Initialize SET to a singleton set containing an empty stack. */
795 yyinitStateSet (yyGLRStateSet
* yyset
)
798 yyset
->yycapacity
= 16;
799 yyset
->yystates
= (yyGLRState
**) malloc (16 * sizeof (yyset
->yystates
[0]));
800 yyset
->yystates
[0] = NULL
;
803 static void yyfreeStateSet (yyGLRStateSet
* yyset
)
805 free (yyset
->yystates
);
808 /** Initialize STACK to a single empty stack, with total maximum
809 * capacity for all stacks of SIZE. */
811 yyinitGLRStack (yyGLRStack
* yystack
, size_t yysize
)
813 yystack
->yyerrflag
= 0;
814 yystack
->yyerrState
= 0;
816 yystack
->yyspaceLeft
= yysize
;
817 yystack
->yynextFree
= yystack
->yyitems
=
818 (yyGLRStackItem
*) malloc (yysize
* sizeof (yystack
->yynextFree
[0]));
819 yystack
->yysplitPoint
= NULL
;
820 yystack
->yylastDeleted
= NULL
;
821 yyinitStateSet (&yystack
->yytops
);
824 #define YYRELOC(YYFROMITEMS,YYTOITEMS,YYX,YYTYPE) \
825 &((YYTOITEMS) - ((YYFROMITEMS) - (yyGLRStackItem*) (YYX)))->YYTYPE
827 /** If STACK is expandable, extend it. WARNING: Pointers into the
828 stack from outside should be considered invalid after this call.
829 We always expand when there are 1 or fewer items left AFTER an
830 allocation, so that we can avoid having external pointers exist
831 across an allocation. */
833 yyexpandGLRStack (yyGLRStack
* yystack
]b4_pure_formals
[)
835 #if YYSTACKEXPANDABLE
836 yyGLRStack yynewStack
;
837 yyGLRStackItem
* yyp0
, *yyp1
;
838 size_t yysize
, yynewSize
;
840 yysize
= yystack
->yynextFree
- yystack
->yyitems
;
841 if (YYMAXDEPTH
<= yysize
)
842 yyFail (yystack
][]b4_pure_args
[,
843 "parsing stack overflow (%d items)", yysize
);
844 yynewSize
= 2*yysize
;
845 if (YYMAXDEPTH
< yynewSize
)
846 yynewSize
= YYMAXDEPTH
;
847 yyinitGLRStack (&yynewStack
, yynewSize
);
848 for (yyp0
= yystack
->yyitems
, yyp1
= yynewStack
.yyitems
, yyn
= yysize
;
850 yyn
-= 1, yyp0
+= 1, yyp1
+= 1)
855 yyGLRState
* yys0
= &yyp0
->yystate
;
856 yyGLRState
* yys1
= &yyp1
->yystate
;
857 if (yys0
->yypred
!= NULL
)
859 YYRELOC (yyp0
, yyp1
, yys0
->yypred
, yystate
);
860 if (! yys0
->yyresolved
&& yys0
->yysemantics
.yyfirstVal
!= NULL
)
861 yys1
->yysemantics
.yyfirstVal
=
862 YYRELOC(yyp0
, yyp1
, yys0
->yysemantics
.yyfirstVal
, yyoption
);
866 yySemanticOption
* yyv0
= &yyp0
->yyoption
;
867 yySemanticOption
* yyv1
= &yyp1
->yyoption
;
868 if (yyv0
->yystate
!= NULL
)
869 yyv1
->yystate
= YYRELOC (yyp0
, yyp1
, yyv0
->yystate
, yystate
);
870 if (yyv0
->yynext
!= NULL
)
871 yyv1
->yynext
= YYRELOC (yyp0
, yyp1
, yyv0
->yynext
, yyoption
);
874 if (yystack
->yysplitPoint
!= NULL
)
875 yystack
->yysplitPoint
= YYRELOC (yystack
->yyitems
, yynewStack
.yyitems
,
876 yystack
->yysplitPoint
, yystate
);
878 for (yyn
= 0; yyn
< yystack
->yytops
.yysize
; yyn
+= 1)
879 if (yystack
->yytops
.yystates
[yyn
] != NULL
)
880 yystack
->yytops
.yystates
[yyn
] =
881 YYRELOC (yystack
->yyitems
, yynewStack
.yyitems
,
882 yystack
->yytops
.yystates
[yyn
], yystate
);
883 free (yystack
->yyitems
);
884 yystack
->yyitems
= yynewStack
.yyitems
;
885 yystack
->yynextFree
= yynewStack
.yynextFree
+ yysize
;
886 yystack
->yyspaceLeft
= yynewStack
.yyspaceLeft
- yysize
;
890 yyFail (yystack
][]b4_lpure_args
[,
891 "parsing stack overflow (%d items)", yysize
);
896 yyfreeGLRStack (yyGLRStack
* yystack
)
898 free (yystack
->yyitems
);
899 yyfreeStateSet (&yystack
->yytops
);
902 /** Assuming that S is a GLRState somewhere on STACK, update the
903 * splitpoint of STACK, if needed, so that it is at least as deep as
906 yyupdateSplit (yyGLRStack
* yystack
, yyGLRState
* yys
)
908 if (yystack
->yysplitPoint
!= NULL
&& yystack
->yysplitPoint
> yys
)
909 yystack
->yysplitPoint
= yys
;
912 /** Invalidate stack #K in STACK. */
914 yymarkStackDeleted (yyGLRStack
* yystack
, int yyk
)
916 if (yystack
->yytops
.yystates
[yyk
] != NULL
)
917 yystack
->yylastDeleted
= yystack
->yytops
.yystates
[yyk
];
918 yystack
->yytops
.yystates
[yyk
] = NULL
;
921 /** Undelete the last stack that was marked as deleted. Can only be
922 done once after a deletion, and only when all other stacks have
925 yyundeleteLastStack (yyGLRStack
* yystack
)
927 if (yystack
->yylastDeleted
== NULL
|| yystack
->yytops
.yysize
!= 0)
929 yystack
->yytops
.yystates
[0] = yystack
->yylastDeleted
;
930 yystack
->yytops
.yysize
= 1;
931 YYDPRINTF ((stderr
, "Restoring last deleted stack as stack #0.\n"));
932 yystack
->yylastDeleted
= NULL
;
936 yyremoveDeletes (yyGLRStack
* yystack
)
940 while (yyj
< yystack
->yytops
.yysize
)
942 if (yystack
->yytops
.yystates
[yyi
] == NULL
)
945 YYDPRINTF ((stderr
, "Removing dead stacks.\n"));
946 yystack
->yytops
.yysize
-= 1;
950 yystack
->yytops
.yystates
[yyj
] = yystack
->yytops
.yystates
[yyi
];
952 YYDPRINTF ((stderr
, "Rename stack %d -> %d.\n", yyi
, yyj
));
959 /** Shift to a new state on stack #K of STACK, corresponding to LR state
960 * LRSTATE, at input position POSN, with (resolved) semantic value SVAL. */
962 yyglrShift (yyGLRStack
* yystack
, int yyk
, yyStateNum yylrState
, size_t yyposn
,
963 YYSTYPE yysval
, YYLTYPE
* yylocp
]b4_user_formals
[)
965 yyGLRStackItem
* yynewItem
;
967 yynewItem
= yystack
->yynextFree
;
968 yystack
->yynextFree
+= 1;
969 yystack
->yyspaceLeft
-= 1;
970 yynewItem
->yystate
.yyisState
= yytrue
;
971 yynewItem
->yystate
.yylrState
= yylrState
;
972 yynewItem
->yystate
.yyposn
= yyposn
;
973 yynewItem
->yystate
.yyresolved
= yytrue
;
974 yynewItem
->yystate
.yypred
= yystack
->yytops
.yystates
[yyk
];
975 yystack
->yytops
.yystates
[yyk
] = &yynewItem
->yystate
;
976 yynewItem
->yystate
.yysemantics
.yysval
= yysval
;
977 yynewItem
->yystate
.yyloc
= *yylocp
;
978 if (yystack
->yyspaceLeft
< YYHEADROOM
)
979 yyexpandGLRStack (yystack
]b4_pure_args
[);
982 /** Shift to a new state on stack #K of STACK, to a new state
983 * corresponding to LR state LRSTATE, at input position POSN, with
984 * the (unresolved) semantic value of RHS under the action for RULE. */
986 yyglrShiftDefer (yyGLRStack
* yystack
, int yyk
, yyStateNum yylrState
,
987 size_t yyposn
, yyGLRState
* rhs
, yyRuleNum yyrule
]b4_pure_formals
[)
989 yyGLRStackItem
* yynewItem
;
991 yynewItem
= yystack
->yynextFree
;
992 yynewItem
->yystate
.yyisState
= yytrue
;
993 yynewItem
->yystate
.yylrState
= yylrState
;
994 yynewItem
->yystate
.yyposn
= yyposn
;
995 yynewItem
->yystate
.yyresolved
= yyfalse
;
996 yynewItem
->yystate
.yypred
= yystack
->yytops
.yystates
[yyk
];
997 yynewItem
->yystate
.yysemantics
.yyfirstVal
= NULL
;
998 yystack
->yytops
.yystates
[yyk
] = &yynewItem
->yystate
;
999 yystack
->yynextFree
+= 1;
1000 yystack
->yyspaceLeft
-= 1;
1001 yyaddDeferredAction (yystack
, &yynewItem
->yystate
, rhs
, yyrule
]b4_pure_args
[);
1004 /** Pop the symbols consumed by reduction #RULE from the top of stack
1005 * #K of STACK, and perform the appropriate semantic action on their
1006 * semantic values. Assumes that all ambiguities in semantic values
1007 * have been previously resolved. Set *VALP to the resulting value,
1008 * and *LOCP to the computed location (if any). Return value is as
1009 * for userAction. */
1011 yydoAction (yyGLRStack
* yystack
, int yyk
, yyRuleNum yyrule
,
1012 YYSTYPE
* yyvalp
, YYLTYPE
* yylocp
]b4_user_formals
[)
1014 int yynrhs
= yyrhsLength (yyrule
);
1016 if (yystack
->yysplitPoint
== NULL
)
1018 /* Standard special case: single stack. */
1019 yyGLRStackItem
* rhs
= (yyGLRStackItem
*) yystack
->yytops
.yystates
[yyk
];
1021 yystack
->yynextFree
-= yynrhs
;
1022 yystack
->yyspaceLeft
+= yynrhs
;
1023 yystack
->yytops
.yystates
[0] = & yystack
->yynextFree
[-1].yystate
;
1026 *yyvalp
= yyval_default
;
1027 *yylocp
= yyloc_default
;
1031 *yyvalp
= rhs
[1-yynrhs
].yystate
.yysemantics
.yysval
;
1032 *yylocp
= rhs
[1-yynrhs
].yystate
.yyloc
;
1034 return yyuserAction (yyrule
, yynrhs
, rhs
,
1035 yyvalp
, yylocp
, yystack
]b4_user_args
[);
1041 yyGLRStackItem yyrhsVals
[YYMAXRHS
];
1042 for (yyi
= yynrhs
-1, yys
= yystack
->yytops
.yystates
[yyk
]; 0 <= yyi
;
1043 yyi
-= 1, yys
= yys
->yypred
)
1045 assert (yys
->yypred
!= NULL
);
1046 yyrhsVals
[yyi
].yystate
.yyresolved
= yytrue
;
1047 yyrhsVals
[yyi
].yystate
.yysemantics
.yysval
= yys
->yysemantics
.yysval
;
1048 yyrhsVals
[yyi
].yystate
.yyloc
= yys
->yyloc
;
1050 yyupdateSplit (yystack
, yys
);
1051 yystack
->yytops
.yystates
[yyk
] = yys
;
1054 *yyvalp
= yyval_default
;
1055 *yylocp
= yyloc_default
;
1059 *yyvalp
= yyrhsVals
[0].yystate
.yysemantics
.yysval
;
1060 *yylocp
= yyrhsVals
[0].yystate
.yyloc
;
1062 return yyuserAction (yyrule
, yynrhs
, yyrhsVals
+ (yynrhs
-1),
1063 yyvalp
, yylocp
, yystack
]b4_user_args
[);
1068 # define YY_REDUCE_PRINT(K, Rule)
1070 # define YY_REDUCE_PRINT(K, Rule) \
1073 yy_reduce_print (K, Rule); \
1076 /*----------------------------------------------------------.
1077 | Report that the RULE is going to be reduced on stack #K. |
1078 `----------------------------------------------------------*/
1081 yy_reduce_print (size_t yyk
, yyRuleNum yyrule
)
1084 YYDPRINTF ((stderr
, "Reducing stack %d by rule %d (line %d),",
1085 yyk
, yyrule
- 1, yyrline
[yyrule
]));
1086 /* Print the symbols being reduced, and their result. */
1087 for (yyi
= yyprhs
[yyrule
]; 0 <= yyrhs
[yyi
]; yyi
++)
1088 YYFPRINTF (stderr
, "%s ", yytokenName (yyrhs
[yyi
]));
1089 YYFPRINTF (stderr
, " -> %s\n", yytokenName (yyr1
[yyrule
]));
1093 /** Pop items off stack #K of STACK according to grammar rule RULE,
1094 * and push back on the resulting nonterminal symbol. Perform the
1095 * semantic action associated with RULE and store its value with the
1096 * newly pushed state, if FORCEEVAL or if STACK is currently
1097 * unambiguous. Otherwise, store the deferred semantic action with
1098 * the new state. If the new state would have an identical input
1099 * position, LR state, and predecessor to an existing state on the stack,
1100 * it is identified with that existing state, eliminating stack #K from
1101 * the STACK. In this case, the (necessarily deferred) semantic value is
1102 * added to the options for the existing state's semantic value.
1104 static inline YYRESULTTAG
1105 yyglrReduce (yyGLRStack
* yystack
, size_t yyk
, yyRuleNum yyrule
,
1106 bool yyforceEval
]b4_pure_formals
[)
1108 size_t yyposn
= yystack
->yytops
.yystates
[yyk
]->yyposn
;
1110 if (yyforceEval
|| yystack
->yysplitPoint
== NULL
)
1115 YY_REDUCE_PRINT (yyk
, yyrule
);
1116 YYCHK (yydoAction (yystack
, yyk
, yyrule
, &yysval
, &yyloc
]b4_user_args
[));
1117 yyglrShift (yystack
, yyk
,
1118 yyLRgotoState (yystack
->yytops
.yystates
[yyk
]->yylrState
,
1119 yylhsNonterm (yyrule
)),
1120 yyposn
, yysval
, &yyloc
]b4_user_args
[);
1121 YYDPRINTF ((stderr
, "Stack %d entering state %d\n",
1122 yyk
, yystack
->yytops
.yystates
[yyk
]->yylrState
));
1128 yyGLRState
* yys
, *yys0
= yystack
->yytops
.yystates
[yyk
];
1129 yyStateNum yynewLRState
;
1131 for (yys
= yystack
->yytops
.yystates
[yyk
], yyn
= yyrhsLength (yyrule
);
1135 assert (yys
!= NULL
);
1137 yyupdateSplit (yystack
, yys
);
1138 yynewLRState
= yyLRgotoState (yys
->yylrState
, yylhsNonterm (yyrule
));
1140 "Reduced stack %d by rule #%d; action deferred. "
1141 "Now in state %d.\n",
1142 yyk
, yyrule
-1, yynewLRState
));
1143 for (yyi
= 0; yyi
< yystack
->yytops
.yysize
; yyi
+= 1)
1144 if (yyi
!= yyk
&& yystack
->yytops
.yystates
[yyi
] != NULL
)
1146 yyGLRState
* yyp
, *yysplit
= yystack
->yysplitPoint
;
1147 yyp
= yystack
->yytops
.yystates
[yyi
];
1148 while (yyp
!= yys
&& yyp
!= yysplit
&& yyp
->yyposn
>= yyposn
)
1150 if (yyp
->yylrState
== yynewLRState
&& yyp
->yypred
== yys
)
1152 yyaddDeferredAction (yystack
, yyp
, yys0
, yyrule
]b4_pure_args
[);
1153 yymarkStackDeleted (yystack
, yyk
);
1154 YYDPRINTF ((stderr
, "Merging stack %d into stack %d.\n",
1161 yystack
->yytops
.yystates
[yyk
] = yys
;
1162 yyglrShiftDefer (yystack
, yyk
, yynewLRState
, yyposn
, yys0
, yyrule
]b4_pure_args
[);
1168 yysplitStack (yyGLRStack
* yystack
, int yyk
)
1170 if (yystack
->yysplitPoint
== NULL
)
1173 yystack
->yysplitPoint
= yystack
->yytops
.yystates
[yyk
];
1175 if (yystack
->yytops
.yysize
>= yystack
->yytops
.yycapacity
)
1177 yystack
->yytops
.yycapacity
*= 2;
1178 yystack
->yytops
.yystates
=
1179 (yyGLRState
**) realloc (yystack
->yytops
.yystates
,
1180 yystack
->yytops
.yycapacity
1181 * sizeof (yyGLRState
*));
1183 yystack
->yytops
.yystates
[yystack
->yytops
.yysize
]
1184 = yystack
->yytops
.yystates
[yyk
];
1185 yystack
->yytops
.yysize
+= 1;
1186 return yystack
->yytops
.yysize
-1;
1189 /** True iff Y0 and Y1 represent identical options at the top level.
1190 * That is, they represent the same rule applied to RHS symbols
1191 * that produce the same terminal symbols. */
1193 yyidenticalOptions (yySemanticOption
* yyy0
, yySemanticOption
* yyy1
)
1195 if (yyy0
->yyrule
== yyy1
->yyrule
)
1197 yyGLRState
*yys0
, *yys1
;
1199 for (yys0
= yyy0
->yystate
, yys1
= yyy1
->yystate
,
1200 yyn
= yyrhsLength (yyy0
->yyrule
);
1202 yys0
= yys0
->yypred
, yys1
= yys1
->yypred
, yyn
-= 1)
1203 if (yys0
->yyposn
!= yys1
->yyposn
)
1211 /** Assuming identicalOptions (Y0,Y1), (destructively) merge the
1212 * alternative semantic values for the RHS-symbols of Y1 into the
1213 * corresponding semantic value sets of the symbols of Y0. */
1215 yymergeOptionSets (yySemanticOption
* yyy0
, yySemanticOption
* yyy1
)
1217 yyGLRState
*yys0
, *yys1
;
1219 for (yys0
= yyy0
->yystate
, yys1
= yyy1
->yystate
,
1220 yyn
= yyrhsLength (yyy0
->yyrule
);
1222 yys0
= yys0
->yypred
, yys1
= yys1
->yypred
, yyn
-= 1)
1225 else if (! yys0
->yyresolved
&& ! yys1
->yyresolved
)
1227 yySemanticOption
* yyz
;
1228 for (yyz
= yys0
->yysemantics
.yyfirstVal
; yyz
->yynext
!= NULL
;
1231 yyz
->yynext
= yys1
->yysemantics
.yyfirstVal
;
1235 /** Y0 and Y1 represent two possible actions to take in a given
1236 * parsing state; return 0 if no combination is possible,
1237 * 1 if user-mergeable, 2 if Y0 is preferred, 3 if Y1 is preferred. */
1239 yypreference (yySemanticOption
* y0
, yySemanticOption
* y1
)
1241 yyRuleNum r0
= y0
->yyrule
, r1
= y1
->yyrule
;
1242 int p0
= yydprec
[r0
], p1
= yydprec
[r1
];
1246 if (yymerger
[r0
] == 0 || yymerger
[r0
] != yymerger
[r1
])
1251 if (p0
== 0 || p1
== 0)
1260 static YYRESULTTAG
yyresolveValue (yySemanticOption
* yyoptionList
,
1261 yyGLRStack
* yystack
, YYSTYPE
* yyvalp
,
1262 YYLTYPE
* yylocp
]b4_user_formals
[);
1265 yyresolveStates (yyGLRState
* yys
, int yyn
, yyGLRStack
* yystack
]b4_user_formals
[)
1270 assert (yys
->yypred
!= NULL
);
1271 yyflag
= yyresolveStates (yys
->yypred
, yyn
-1, yystack
]b4_user_args
[);
1274 if (! yys
->yyresolved
)
1276 yyflag
= yyresolveValue (yys
->yysemantics
.yyfirstVal
, yystack
,
1277 &yys
->yysemantics
.yysval
, &yys
->yyloc
1281 yys
->yyresolved
= yytrue
;
1288 yyresolveAction (yySemanticOption
* yyopt
, yyGLRStack
* yystack
,
1289 YYSTYPE
* yyvalp
, YYLTYPE
* yylocp
]b4_user_formals
[)
1291 yyGLRStackItem yyrhsVals
[YYMAXRHS
];
1295 yynrhs
= yyrhsLength (yyopt
->yyrule
);
1296 YYCHK (yyresolveStates (yyopt
->yystate
, yynrhs
, yystack
]b4_user_args
[));
1297 for (yyi
= yynrhs
-1, yys
= yyopt
->yystate
; 0 <= yyi
;
1298 yyi
-= 1, yys
= yys
->yypred
)
1300 assert (yys
->yypred
!= NULL
);
1301 yyrhsVals
[yyi
].yystate
.yyresolved
= yytrue
;
1302 yyrhsVals
[yyi
].yystate
.yysemantics
.yysval
= yys
->yysemantics
.yysval
;
1303 yyrhsVals
[yyi
].yystate
.yyloc
= yys
->yyloc
;
1305 return yyuserAction (yyopt
->yyrule
, yynrhs
, yyrhsVals
+ (yynrhs
-1),
1306 yyvalp
, yylocp
, yystack
]b4_user_args
[);
1311 yyreportTree (yySemanticOption
* yyx
, int yyindent
)
1313 int yynrhs
= yyrhsLength (yyx
->yyrule
);
1316 yyGLRState
* yystates
[YYMAXRHS
];
1317 yyGLRState yyleftmost_state
;
1319 for (yyi
= yynrhs
, yys
= yyx
->yystate
; 0 < yyi
; yyi
-= 1, yys
= yys
->yypred
)
1320 yystates
[yyi
] = yys
;
1323 yyleftmost_state
.yyposn
= 0;
1324 yystates
[0] = &yyleftmost_state
;
1329 if (yyx
->yystate
->yyposn
< yys
->yyposn
+ 1)
1330 YYFPRINTF (stderr
, "%*s%s -> <Rule %d, empty>\n",
1331 yyindent
, "", yytokenName (yylhsNonterm (yyx
->yyrule
)),
1334 YYFPRINTF (stderr
, "%*s%s -> <Rule %d, tokens %d .. %d>\n",
1335 yyindent
, "", yytokenName (yylhsNonterm (yyx
->yyrule
)),
1336 yyx
->yyrule
, yys
->yyposn
+1, yyx
->yystate
->yyposn
);
1337 for (yyi
= 1; yyi
<= yynrhs
; yyi
+= 1)
1339 if (yystates
[yyi
]->yyresolved
)
1341 if (yystates
[yyi
-1]->yyposn
+1 > yystates
[yyi
]->yyposn
)
1342 YYFPRINTF (stderr
, "%*s%s <empty>\n", yyindent
+2, "",
1343 yytokenName (yyrhs
[yyprhs
[yyx
->yyrule
]+yyi
-1]));
1345 YYFPRINTF (stderr
, "%*s%s <tokens %d .. %d>\n", yyindent
+2, "",
1346 yytokenName (yyrhs
[yyprhs
[yyx
->yyrule
]+yyi
-1]),
1347 yystates
[yyi
-1]->yyposn
+1, yystates
[yyi
]->yyposn
);
1350 yyreportTree (yystates
[yyi
]->yysemantics
.yyfirstVal
, yyindent
+2);
1356 yyreportAmbiguity (yySemanticOption
* yyx0
, yySemanticOption
* yyx1
,
1357 yyGLRStack
* yystack
]b4_pure_formals
[)
1359 /* `Unused' warnings. */
1364 YYFPRINTF (stderr
, "Ambiguity detected.\n");
1365 YYFPRINTF (stderr
, "Option 1,\n");
1366 yyreportTree (yyx0
, 2);
1367 YYFPRINTF (stderr
, "\nOption 2,\n");
1368 yyreportTree (yyx1
, 2);
1369 YYFPRINTF (stderr
, "\n");
1371 yyFail (yystack
][]b4_pure_args
[, "ambiguity detected");
1375 /** Resolve the ambiguity represented by OPTIONLIST, perform the indicated
1376 * actions, and return the result. */
1378 yyresolveValue (yySemanticOption
* yyoptionList
, yyGLRStack
* yystack
,
1379 YYSTYPE
* yyvalp
, YYLTYPE
* yylocp
]b4_user_formals
[)
1381 yySemanticOption
* yybest
;
1382 yySemanticOption
* yyp
;
1385 yybest
= yyoptionList
;
1387 for (yyp
= yyoptionList
->yynext
; yyp
!= NULL
; yyp
= yyp
->yynext
)
1389 if (yyidenticalOptions (yybest
, yyp
))
1390 yymergeOptionSets (yybest
, yyp
);
1392 switch (yypreference (yybest
, yyp
))
1395 yyreportAmbiguity (yybest
, yyp
, yystack
]b4_pure_args
[);
1411 int yyprec
= yydprec
[yybest
->yyrule
];
1412 YYCHK (yyresolveAction (yybest
, yystack
, yyvalp
, yylocp
]b4_user_args
[));
1413 for (yyp
= yybest
->yynext
; yyp
!= NULL
; yyp
= yyp
->yynext
)
1415 if (yyprec
== yydprec
[yyp
->yyrule
])
1419 YYCHK (yyresolveAction (yyp
, yystack
, &yyval1
, &yydummy
]b4_user_args
[));
1420 *yyvalp
= yyuserMerge (yymerger
[yyp
->yyrule
], yyvalp
, &yyval1
);
1426 return yyresolveAction (yybest
, yystack
, yyvalp
, yylocp
]b4_user_args
[);
1430 yyresolveStack (yyGLRStack
* yystack
]b4_user_formals
[)
1432 if (yystack
->yysplitPoint
!= NULL
)
1437 for (yyn
= 0, yys
= yystack
->yytops
.yystates
[0];
1438 yys
!= yystack
->yysplitPoint
;
1439 yys
= yys
->yypred
, yyn
+= 1)
1441 YYCHK (yyresolveStates (yystack
->yytops
.yystates
[0], yyn
, yystack
1448 yycompressStack (yyGLRStack
* yystack
)
1450 yyGLRState
* yyp
, *yyq
, *yyr
;
1452 if (yystack
->yytops
.yysize
!= 1 || yystack
->yysplitPoint
== NULL
)
1455 for (yyp
= yystack
->yytops
.yystates
[0], yyq
= yyp
->yypred
, yyr
= NULL
;
1456 yyp
!= yystack
->yysplitPoint
;
1457 yyr
= yyp
, yyp
= yyq
, yyq
= yyp
->yypred
)
1460 yystack
->yyspaceLeft
+= yystack
->yynextFree
- yystack
->yyitems
;
1461 yystack
->yynextFree
= ((yyGLRStackItem
*) yystack
->yysplitPoint
) + 1;
1462 yystack
->yyspaceLeft
-= yystack
->yynextFree
- yystack
->yyitems
;
1463 yystack
->yysplitPoint
= NULL
;
1464 yystack
->yylastDeleted
= NULL
;
1468 yystack
->yynextFree
->yystate
= *yyr
;
1470 yystack
->yynextFree
->yystate
.yypred
= & yystack
->yynextFree
[-1].yystate
;
1471 yystack
->yytops
.yystates
[0] = &yystack
->yynextFree
->yystate
;
1472 yystack
->yynextFree
+= 1;
1473 yystack
->yyspaceLeft
-= 1;
1478 yyprocessOneStack (yyGLRStack
* yystack
, int yyk
,
1479 size_t yyposn
, YYSTYPE
* yylvalp
, YYLTYPE
* yyllocp
1483 const short* yyconflicts
;
1485 yySymbol
* const yytokenp
= yystack
->yytokenp
;
1487 while (yystack
->yytops
.yystates
[yyk
] != NULL
)
1489 yyStateNum yystate
= yystack
->yytops
.yystates
[yyk
]->yylrState
;
1491 assert (yystate
!= YYFINAL
);
1492 if (yyisDefaultedState (yystate
))
1494 yyrule
= yydefaultAction (yystate
);
1497 YYDPRINTF ((stderr
, "Stack %d dies.\n", yyk
));
1498 yymarkStackDeleted (yystack
, yyk
);
1501 YYCHK (yyglrReduce (yystack
, yyk
, yyrule
, yyfalse
]b4_lpure_args
[));
1505 if (*yytokenp
== YYEMPTY
)
1507 YYDPRINTF ((stderr
, "Reading a token: "));
1509 *yytokenp
= YYTRANSLATE (yychar
);
1510 YYDPRINTF ((stderr
, "Next token is %s\n",
1511 yytokenName (*yytokenp
)));
1513 yygetLRActions (yystate
, *yytokenp
, &yyaction
, &yyconflicts
);
1515 while (*yyconflicts
!= 0)
1517 int yynewStack
= yysplitStack (yystack
, yyk
);
1518 YYDPRINTF ((stderr
, "Splitting off stack %d from %d.\n",
1520 YYCHK (yyglrReduce (yystack
, yynewStack
,
1521 *yyconflicts
, yyfalse
]b4_lpure_args
[));
1522 YYCHK (yyprocessOneStack (yystack
, yynewStack
, yyposn
,
1523 yylvalp
, yyllocp
]b4_user_args
[));
1527 if (yyisShiftAction (yyaction
))
1529 YYDPRINTF ((stderr
, "Shifting token %s on stack %d, ",
1530 yytokenName (*yytokenp
), yyk
));
1531 yyglrShift (yystack
, yyk
, yyaction
, yyposn
+1,
1532 *yylvalp
, yyllocp
]b4_user_args
[);
1533 YYDPRINTF ((stderr
, "which is now in state #%d\n",
1534 yystack
->yytops
.yystates
[yyk
]->yylrState
));
1537 else if (yyisErrorAction (yyaction
))
1539 YYDPRINTF ((stderr
, "Stack %d dies.\n", yyk
));
1540 yymarkStackDeleted (yystack
, yyk
);
1544 YYCHK (yyglrReduce (yystack
, yyk
, -yyaction
, yyfalse
]b4_lpure_args
[));
1551 yyreportParseError (yyGLRStack
* yystack
,
1552 YYSTYPE
* yylvalp
, YYLTYPE
* yyllocp
]b4_user_formals
[)
1554 /* `Unused' warnings. */
1558 if (yystack
->yyerrState
== 0)
1561 yySymbol
* const yytokenp
= yystack
->yytokenp
;
1562 int yyn
, yyx
, yycount
;
1564 const char* yyprefix
;
1567 yyn
= yypact
[yystack
->yytops
.yystates
[0]->yylrState
];
1568 if (YYPACT_NINF
< yyn
&& yyn
< YYLAST
)
1571 /* Start YYX at -YYN if negative to avoid negative indexes in
1573 yysize
= sizeof ("parse error, unexpected ")
1574 + strlen (yytokenName (*yytokenp
));
1575 yyprefix
= ", expecting ";
1576 for (yyx
= yyn
< 0 ? -yyn
: 0; yyx
< yytname_size
&& yycount
<= 5;
1578 if (yycheck
[yyx
+ yyn
] == yyx
&& yyx
!= YYTERROR
)
1579 yysize
+= strlen (yytokenName (yyx
)) + strlen (yyprefix
),
1580 yycount
+= 1, yyprefix
= " or ";
1581 yymsg
= yyp
= (char*) malloc (yysize
);
1582 sprintf (yyp
, "parse error, unexpected %s", yytokenName (*yytokenp
));
1583 yyp
+= strlen (yyp
);
1586 yyprefix
= ", expecting ";
1587 for (yyx
= yyn
< 0 ? -yyn
: 0; yyx
< yytname_size
; yyx
+= 1)
1588 if (yycheck
[yyx
+ yyn
] == yyx
&& yyx
!= YYTERROR
)
1590 sprintf (yyp
, "%s%s", yyprefix
, yytokenName (yyx
));
1591 yyp
+= strlen (yyp
);
1595 yyerror (]b4_lyyerror_args
[yymsg
);
1600 yyerror (]b4_lyyerror_args
["parse error");
1605 /* Recover from a syntax error on YYSTACK, assuming that YYTOKENP,
1606 YYLVALP, and YYLLOCP point to the syntactic category, semantic
1607 value, and location of the lookahead. */
1609 yyrecoverParseError (yyGLRStack
* yystack
,
1610 YYSTYPE
* yylvalp
, YYLTYPE
* yyllocp
]b4_user_formals
[)
1612 yySymbol
* const yytokenp
= yystack
->yytokenp
;
1616 if (yystack
->yyerrState
== 0)
1617 yystack
->yyerrState
= 3;
1618 else if (yystack
->yyerrState
== 3)
1619 /* We just shifted the error token and (perhaps) took some
1620 reductions. Skip tokens until we can proceed. */
1623 if (*yytokenp
== YYEOF
)
1624 yyFail (yystack
][]b4_lpure_args
[, NULL
);
1625 if (*yytokenp
!= YYEMPTY
)
1626 YYDPRINTF ((stderr
, "Discarding token %s\n",
1627 yytokenName (*yytokenp
)));
1628 YYDPRINTF ((stderr
, "Reading a token: "));
1630 *yytokenp
= YYTRANSLATE (yychar
);
1631 YYDPRINTF ((stderr
, "Next token is %s\n", yytokenName (*yytokenp
)));
1632 yyj
= yypact
[yystack
->yytops
.yystates
[0]->yylrState
];
1633 if (yyis_pact_ninf (yyj
))
1634 /* Something's not right; we shouldn't be here. */
1635 yyFail (yystack
][]b4_lpure_args
[, NULL
);
1637 if (yyj
< 0 || YYLAST
< yyj
|| yycheck
[yyj
] != *yytokenp
)
1639 if (yydefact
[yystack
->yytops
.yystates
[0]->yylrState
] != 0)
1642 else if (yytable
[yyj
] != 0 && ! yyis_table_ninf (yytable
[yyj
]))
1646 /* Reduce to one stack. */
1647 for (yyk
= 0; yyk
< yystack
->yytops
.yysize
; yyk
+= 1)
1648 if (yystack
->yytops
.yystates
[yyk
] != NULL
)
1650 if (yyk
>= yystack
->yytops
.yysize
)
1651 yyFail (yystack
][]b4_lpure_args
[, NULL
);
1652 for (yyk
+= 1; yyk
< yystack
->yytops
.yysize
; yyk
+= 1)
1653 yymarkStackDeleted (yystack
, yyk
);
1654 yyremoveDeletes (yystack
);
1655 yycompressStack (yystack
);
1657 /* Now pop stack until we find a state that shifts the error token. */
1658 while (yystack
->yytops
.yystates
[0] != NULL
)
1660 yyj
= yypact
[yystack
->yytops
.yystates
[0]->yylrState
];
1661 if (! yyis_pact_ninf (yyj
))
1664 if (0 <= yyj
&& yyj
<= YYLAST
&& yycheck
[yyj
] == YYTERROR
1665 && yyisShiftAction (yytable
[yyj
]))
1667 yyglrShift (yystack
, 0, yytable
[yyj
],
1668 yystack
->yytops
.yystates
[0]->yyposn
,
1669 *yylvalp
, yyllocp
]b4_user_args
[);
1673 yystack
->yytops
.yystates
[0] = yystack
->yytops
.yystates
[0]->yypred
;
1674 yystack
->yynextFree
-= 1;
1675 yystack
->yyspaceLeft
+= 1;
1677 if (yystack
->yytops
.yystates
[0] == NULL
)
1678 yyFail (yystack
][]b4_lpure_args
[, NULL
);
1681 #define YYCHK1(YYE) \
1687 yystack.yyerrflag = 1; \
1690 yystack.yyerrflag = 0; \
1693 goto yyuser_error; \
1702 ]b4_c_ansi_function_def([yyparse
], [int], b4_parse_param
)[
1712 #define yychar (yystack.yyrawchar)
1715 YYSTYPE
* const yylvalp
= &yylval
;
1716 YYLTYPE
* const yyllocp
= &yylloc
;
1718 yyinitGLRStack (&yystack
, YYINITDEPTH
);
1719 yystack
.yytokenp
= &yytoken
;
1721 YYDPRINTF ((stderr
, "Starting parse\n"));
1723 if (setjmp (yystack
.yyexception_buffer
) != 0)
1726 yyglrShift (&yystack
, 0, 0, 0, yyval_default
, &yyloc_default
]b4_user_args
[);
1732 /* For efficiency, we have two loops, the first of which is
1733 specialized to deterministic operation (single stack, no
1734 potential ambiguity). */
1741 const short* yyconflicts
;
1743 yyStateNum yystate
= yystack
.yytops
.yystates
[0]->yylrState
;
1744 if (yystate
== YYFINAL
)
1746 if (yyisDefaultedState (yystate
))
1748 yyrule
= yydefaultAction (yystate
);
1751 yyreportParseError (&yystack
, yylvalp
, yyllocp
]b4_user_args
[);
1754 YYCHK1 (yyglrReduce (&yystack
, 0, yyrule
, yytrue
]b4_lpure_args
[));
1758 if (yytoken
== YYEMPTY
)
1760 YYDPRINTF ((stderr
, "Reading a token: "));
1762 yytoken
= YYTRANSLATE (yychar
);
1763 YYDPRINTF ((stderr
, "Next token is %s\n",
1764 yytokenName (yytoken
)));
1766 yygetLRActions (yystate
, yytoken
, &yyaction
, &yyconflicts
);
1767 if (*yyconflicts
!= 0)
1769 if (yyisShiftAction (yyaction
))
1771 YYDPRINTF ((stderr
, "Shifting token %s, ",
1772 yytokenName (yytoken
)));
1773 if (yytoken
!= YYEOF
)
1776 yyglrShift (&yystack
, 0, yyaction
, yyposn
,
1777 yylval
, yyllocp
]b4_user_args
[);
1778 if (0 < yystack
.yyerrState
)
1779 yystack
.yyerrState
-= 1;
1780 YYDPRINTF ((stderr
, "Entering state %d\n",
1781 yystack
.yytops
.yystates
[0]->yylrState
));
1783 else if (yyisErrorAction (yyaction
))
1785 yyreportParseError (&yystack
, yylvalp
, yyllocp
]b4_user_args
[);
1789 YYCHK1 (yyglrReduce (&yystack
, 0, -yyaction
, yytrue
]b4_lpure_args
[));
1796 int yyn
= yystack
.yytops
.yysize
;
1797 for (yys
= 0; yys
< yyn
; yys
+= 1)
1798 YYCHK1 (yyprocessOneStack (&yystack
, yys
, yyposn
,
1799 yylvalp
, yyllocp
]b4_user_args
[));
1802 yyremoveDeletes (&yystack
);
1803 if (yystack
.yytops
.yysize
== 0)
1805 yyundeleteLastStack (&yystack
);
1806 if (yystack
.yytops
.yysize
== 0)
1807 yyFail (&yystack
][]b4_lpure_args
[, "parse error");
1808 YYCHK1 (yyresolveStack (&yystack
]b4_user_args
[));
1809 YYDPRINTF ((stderr
, "Returning to deterministic operation.\n"));
1810 yyreportParseError (&yystack
, yylvalp
, yyllocp
]b4_user_args
[);
1813 else if (yystack
.yytops
.yysize
== 1)
1815 YYCHK1 (yyresolveStack (&yystack
]b4_user_args
[));
1816 YYDPRINTF ((stderr
, "Returning to deterministic operation.\n"));
1817 yycompressStack (&yystack
);
1823 yyrecoverParseError (&yystack
, yylvalp
, yyllocp
]b4_user_args
[);
1824 yyposn
= yystack
.yytops
.yystates
[0]->yyposn
;
1829 yyfreeGLRStack (&yystack
);
1830 return yystack
.yyerrflag
;
1833 /* DEBUGGING ONLY */
1834 static void yypstack (yyGLRStack
* yystack
, int yyk
) ATTRIBUTE_UNUSED
;
1835 static void yypdumpstack (yyGLRStack
* yystack
) ATTRIBUTE_UNUSED
;
1838 yy_yypstack (yyGLRState
* yys
)
1842 yy_yypstack (yys
->yypred
);
1843 fprintf (stderr
, " -> ");
1845 fprintf (stderr
, "%d@@%lu", yys
->yylrState
, (unsigned long) yys
->yyposn
);
1849 yypstates (yyGLRState
* yyst
)
1852 fprintf (stderr
, "<null>");
1855 fprintf (stderr
, "\n");
1859 yypstack (yyGLRStack
* yystack
, int yyk
)
1861 yypstates (yystack
->yytops
.yystates
[yyk
]);
1864 #define YYINDEX(YYX) \
1865 ((YYX) == NULL ? -1 : (yyGLRStackItem*) (YYX) - yystack->yyitems)
1869 yypdumpstack (yyGLRStack
* yystack
)
1871 yyGLRStackItem
* yyp
;
1873 for (yyp
= yystack
->yyitems
; yyp
< yystack
->yynextFree
; yyp
+= 1)
1875 fprintf (stderr
, "%3lu. ", (unsigned long) (yyp
- yystack
->yyitems
));
1878 fprintf (stderr
, "Res: %d, LR State: %d, posn: %lu, pred: %ld",
1879 yyp
->yystate
.yyresolved
, yyp
->yystate
.yylrState
,
1880 (unsigned long) yyp
->yystate
.yyposn
,
1881 (long) YYINDEX (yyp
->yystate
.yypred
));
1882 if (! yyp
->yystate
.yyresolved
)
1883 fprintf (stderr
, ", firstVal: %ld",
1884 (long) YYINDEX (yyp
->yystate
.yysemantics
.yyfirstVal
));
1888 fprintf (stderr
, "Option. rule: %d, state: %ld, next: %ld",
1889 yyp
->yyoption
.yyrule
,
1890 (long) YYINDEX (yyp
->yyoption
.yystate
),
1891 (long) YYINDEX (yyp
->yyoption
.yynext
));
1893 fprintf (stderr
, "\n");
1895 fprintf (stderr
, "Tops:");
1896 for (yyi
= 0; yyi
< yystack
->yytops
.yysize
; yyi
+= 1)
1897 fprintf (stderr
, "%lu: %ld; ", (unsigned long) yyi
,
1898 (long) YYINDEX (yystack
->yytops
.yystates
[yyi
]));
1899 fprintf (stderr
, "\n");
1904 m4_if(b4_defines_flag
, 0, [],
1905 [@output @output_header_name@
1906 b4_copyright([Skeleton parser
for GLR parsing with Bison
], [2002])
1908 b4_token_defines(b4_tokens
)
1911 m4_ifdef([b4_stype
],
1912 [b4_syncline([b4_stype_line
], [b4_filename
])
1913 typedef union b4_stype yystype
;
1914 /* Line __line__ of __file__. */
1915 b4_syncline([@oline@
], [@ofile@
])],
1916 [typedef int yystype
;])
1917 # define YYSTYPE yystype
1918 # define YYSTYPE_IS_TRIVIAL 1
1922 [extern YYSTYPE b4_prefix
[]lval
;])
1926 typedef struct yyltype
1933 # define YYLTYPE yyltype
1937 [extern YYLTYPE b4_prefix
[]lloc
;])