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. */
156 m4_if(b4_prefix
[], [yy
], [],
157 [/* If NAME_PREFIX is specified substitute the variables and functions
159 #define yyparse b4_prefix[]parse
160 #define yylex b4_prefix[]lex
161 #define yyerror b4_prefix[]error
162 #define yylval b4_prefix[]lval
163 #define yychar b4_prefix[]char
164 #define yydebug b4_prefix[]debug
165 #define yynerrs b4_prefix[]nerrs
166 b4_location_if([#define yylloc b4_prefix[]lloc])])
168 b4_token_defines(b4_tokens
)
170 /* Copy the first part of user declarations. */
173 /* Enabling traces. */
175 # define YYDEBUG ]b4_debug[
178 /* Enabling verbose error messages. */
179 #ifdef YYERROR_VERBOSE
180 # undef YYERROR_VERBOSE
181 # define YYERROR_VERBOSE 1
183 # define YYERROR_VERBOSE ]b4_error_verbose[
187 ]m4_ifdef([b4_stype
],
188 [b4_syncline([b4_stype_line
], [b4_filename
])
189 typedef union b4_stype yystype
;
190 /* Line __line__ of glr.c. */
191 b4_syncline([@oline@
], [@ofile@
])],
192 [typedef int yystype
;])[
193 # define YYSTYPE yystype
194 # define YYSTYPE_IS_TRIVIAL 1
198 typedef struct yyltype
205 # define YYLTYPE ]b4_location_type[
206 # define YYLTYPE_IS_TRIVIAL 1
209 /* Default (constant) values used for initialization for null
210 right-hand sides. Unlike the standard bison.simple template,
211 here we set the default values of $$ and $@@ to zeroed-out
212 values. Since the default value of these quantities is undefined,
213 this behavior is technically correct. */
214 static YYSTYPE yyval_default
;
215 static YYLTYPE yyloc_default
;
217 /* Copy the second part of user declarations. */
220 ]/* Line __line__ of glr.c. */
221 b4_syncline([@oline@
], [@ofile@
])
223 #if ! defined (__cplusplus)
233 #ifndef __attribute__
234 /* This feature is available in gcc versions 2.5 and later. */
235 # if !defined (__GNUC__) || __GNUC__ < 2 || \
236 (__GNUC__ == 2 && __GNUC_MINOR__ < 5) || __STRICT_ANSI__
237 # define __attribute__(Spec) /* empty */
241 #ifndef ATTRIBUTE_UNUSED
242 # define ATTRIBUTE_UNUSED __attribute__ ((__unused__))
245 /* YYFINAL -- State number of the termination state. */
246 #define YYFINAL ]b4_final_state_number[
247 /* YYLAST -- Last index in YYTABLE. */
248 #define YYLAST ]b4_last[
250 /* YYNTOKENS -- Number of terminals. */
251 #define YYNTOKENS ]b4_tokens_number[
252 /* YYNNTS -- Number of nonterminals. */
253 #define YYNNTS ]b4_nterms_number[
254 /* YYNRULES -- Number of rules. */
255 #define YYNRULES ]b4_rules_number[
256 /* YYNRULES -- Number of states. */
257 #define YYNSTATES ]b4_states_number[
258 /* YYMAXRHS -- Maximum number of symbols on right-hand side of rule. */
259 #define YYMAXRHS ]b4_r2_max[
261 /* YYTRANSLATE(X) -- Bison symbol number corresponding to X. */
262 #define YYUNDEFTOK ]b4_undef_token_number[
263 #define YYMAXUTOK ]b4_user_token_number_max[
265 #define YYTRANSLATE(YYX) \
266 ((YYX <= 0) ? YYEOF : \
267 (unsigned)(YYX) <= YYMAXUTOK ? yytranslate[YYX] : YYUNDEFTOK)
269 /* YYTRANSLATE[YYLEX] -- Bison symbol number corresponding to YYLEX. */
270 static const ]b4_int_type_for([b4_translate
])[ yytranslate
[] =
276 /* YYPRHS[YYN] -- Index of the first RHS symbol of rule number YYN in
278 static const ]b4_int_type_for([b4_prhs
])[ yyprhs
[] =
283 /* YYRHS -- A `-1'-separated list of the rules' RHS. */
284 static const ]b4_int_type_for([b4_rhs
])[ yyrhs
[] =
289 /* YYRLINE[YYN] -- source line where rule number YYN was defined. */
290 static const ]b4_int_type_for([b4_rline
])[ yyrline
[] =
296 #if (YYDEBUG) || YYERROR_VERBOSE
297 /* YYTNME[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM.
298 First, the terminals, then, starting at YYNTOKENS, nonterminals. */
299 static const char *const yytname
[] =
304 #define yytname_size ((int) (sizeof (yytname) / sizeof (yytname[0])))
307 /* YYR1[YYN] -- Symbol number of symbol that rule YYN derives. */
308 static const ]b4_int_type_for([b4_r1
])[ yyr1
[] =
313 /* YYR2[YYN] -- Number of symbols composing right hand side of rule YYN. */
314 static const ]b4_int_type_for([b4_r2
])[ yyr2
[] =
319 /* YYDPREC[RULE-NUM] -- Dynamic precedence of rule #RULE-NUM (0 if none). */
320 static const ]b4_int_type_for([b4_dprec
])[ yydprec
[] =
325 /* YYMERGER[RULE-NUM] -- Index of merging function for rule #RULE-NUM. */
326 static const ]b4_int_type_for([b4_merger
])[ yymerger
[] =
331 /* YYDEFACT[S] -- default rule to reduce with in state S when YYTABLE
332 doesn't specify something else to do. Zero means the default is an
334 static const ]b4_int_type_for([b4_defact
])[ yydefact
[] =
339 /* YYPDEFGOTO[NTERM-NUM]. */
340 static const ]b4_int_type_for([b4_defgoto
])[ yydefgoto
[] =
345 /* YYPACT[STATE-NUM] -- Index in YYTABLE of the portion describing
347 #define YYPACT_NINF ]b4_pact_ninf[
348 static const ]b4_int_type_for([b4_pact
])[ yypact
[] =
353 /* YYPGOTO[NTERM-NUM]. */
354 static const ]b4_int_type_for([b4_pgoto
])[ yypgoto
[] =
359 /* YYTABLE[YYPACT[STATE-NUM]]. What to do in state STATE-NUM. If
360 positive, shift that token. If negative, reduce the rule which
361 number is the opposite. If zero, do what YYDEFACT says.
362 If YYTABLE_NINF, syntax error. */
363 #define YYTABLE_NINF ]b4_table_ninf[
364 static const ]b4_int_type_for([b4_table
])[ yytable
[] =
369 /* YYCONFLP[YYPACT[STATE-NUM]] -- Pointer into YYCONFL of start of
370 list of conflicting reductions corresponding to action entry for
371 state STATE-NUM in yytable. 0 means no conflicts. The list in
372 yyconfl is terminated by a rule number of 0. */
373 static const ]b4_int_type_for([b4_conflict_list_heads
])[ yyconflp
[] =
375 ]b4_conflict_list_heads
[
378 /* YYCONFL[I] -- lists of conflicting rule numbers, each terminated by
379 0, pointed into by YYCONFLP. */
380 ]dnl Do
not use b4_int_type_for here
, since there are places where
381 dnl pointers onto yyconfl are taken
, which type is
"short *".
382 dnl We probably ought to introduce a type
for confl
.
383 [static const short yyconfl
[] =
385 ]b4_conflicting_rules
[
388 static const ]b4_int_type_for([b4_check
])[ yycheck
[] =
393 /* YYSTOS[STATE-NUM] -- The (internal number of the) accessing
394 symbol of state STATE-NUM. */
395 static const ]b4_int_type_for([b4_stos
])[ yystos
[] =
401 /* Prevent warning if -Wmissing-prototypes. */
402 ]b4_c_ansi_function_decl([yyparse
], [int], b4_parse_param
)[
404 /* Error token number */
407 /* YYLLOC_DEFAULT -- Compute the default location (before the actions
410 #define YYRHSLOC(yyRhs,YYK) (yyRhs[YYK].yystate.yyloc)
412 #ifndef YYLLOC_DEFAULT
413 # define YYLLOC_DEFAULT(yyCurrent, yyRhs, YYN) \
414 yyCurrent.first_line = YYRHSLOC(yyRhs,1).first_line; \
415 yyCurrent.first_column = YYRHSLOC(yyRhs,1).first_column; \
416 yyCurrent.last_line = YYRHSLOC(yyRhs,YYN).last_line; \
417 yyCurrent.last_column = YYRHSLOC(yyRhs,YYN).last_column;
420 /* YYLEX -- calling `yylex' with the right arguments. */
421 #define YYLEX ]b4_c_function_call([yylex], [int], b4_lex_param)[
426 #define yynerrs (yystack->yyerrcnt)
428 #define yychar (yystack->yyrawchar)],
436 static const int YYEOF
= 0;
437 static const int YYEMPTY
= -2;
439 typedef enum { yyok
, yyaccept
, yyabort
, yyerr
} YYRESULTTAG
;
442 do { YYRESULTTAG yyflag = YYE; if (yyflag != yyok) return yyflag; } \
447 #if ! defined (YYFPRINTF)
448 # define YYFPRINTF fprintf
451 # define YYDPRINTF(Args) \
457 ]b4_yysymprint_generate([b4_c_ansi_function_def
])[
459 # define YYDSYMPRINT(Args) \
465 # define YYDSYMPRINTF(Title, Token, Value, Location) \
469 YYFPRINTF (stderr, "%s ", Title); \
470 yysymprint (stderr, \
471 Token, Value]b4_location_if([, Location])[); \
472 YYFPRINTF (stderr, "\n"); \
476 /* Nonzero means print parse trace. It is left uninitialized so that
477 multiple parsers can coexist. */
482 /* Avoid empty `if' bodies. */
483 # define YYDPRINTF(Args)
484 # define YYDSYMPRINT(Args)
485 # define YYDSYMPRINTF(Title, Token, Value, Location)
487 #endif /* !YYDEBUG */
489 /* YYINITDEPTH -- initial size of the parser's stacks. */
491 # define YYINITDEPTH ]b4_stack_depth_init[
494 /* YYMAXDEPTH -- maximum size the stacks can grow to (effective only
495 if the built-in stack extension method is used).
497 Do not make this value too large; the results are undefined if
498 SIZE_MAX < YYMAXDEPTH * sizeof (GLRStackItem)
499 evaluated with infinite-precision integer arithmetic. */
506 # define YYMAXDEPTH ]b4_stack_depth_max[
509 /* Minimum number of free items on the stack allowed after an
510 allocation. This is to allow allocation and initialization
511 to be completed by functions that call expandGLRStack before the
512 stack is expanded, thus insuring that all necessary pointers get
513 properly redirected to new data. */
516 #if ! defined (YYSTACKEXPANDABLE) \
517 && (! defined (__cplusplus) || (YYLTYPE_IS_TRIVIAL && YYSTYPE_IS_TRIVIAL))
518 #define YYSTACKEXPANDABLE 1
520 #define YYSTACKEXPANDABLE 0
523 /** State numbers, as in LALR(1) machine */
524 typedef int yyStateNum
;
526 /** Rule numbers, as in LALR(1) machine */
527 typedef int yyRuleNum
;
529 /** Grammar symbol */
530 typedef short yySymbol
;
532 /** Item references, as in LALR(1) machine */
533 typedef short yyItemNum
;
535 typedef struct yyGLRState yyGLRState
;
536 typedef struct yySemanticOption yySemanticOption
;
537 typedef union yyGLRStackItem yyGLRStackItem
;
538 typedef struct yyGLRStack yyGLRStack
;
539 typedef struct yyGLRStateSet yyGLRStateSet
;
544 yyStateNum yylrState
;
548 yySemanticOption
* yyfirstVal
;
554 struct yyGLRStateSet
{
555 yyGLRState
** yystates
;
556 size_t yysize
, yycapacity
;
559 struct yySemanticOption
{
563 yySemanticOption
* yynext
;
566 union yyGLRStackItem
{
568 yySemanticOption yyoption
;
580 jmp_buf yyexception_buffer
;
581 yyGLRStackItem
* yyitems
;
582 yyGLRStackItem
* yynextFree
;
584 yyGLRState
* yysplitPoint
;
585 yyGLRState
* yylastDeleted
;
586 yyGLRStateSet yytops
;
589 static void yyinitGLRStack (yyGLRStack
* yystack
, size_t yysize
);
590 static void yyexpandGLRStack (yyGLRStack
* yystack
]b4_pure_formals
[);
591 static void yyfreeGLRStack (yyGLRStack
* yystack
);
594 yyFail (yyGLRStack
* yystack
]b4_pure_formals
[, const char* yyformat
, ...)
596 yystack
->yyerrflag
= 1;
597 if (yyformat
!= NULL
)
601 va_start (yyap
, yyformat
);
602 vsprintf (yymsg
, yyformat
, yyap
);
603 yyerror (]b4_yyerror_args
[yymsg
);
605 longjmp (yystack
->yyexception_buffer
, 1);
608 #if YYDEBUG || YYERROR_VERBOSE
609 /** A printable representation of TOKEN. Valid until next call to
611 static inline const char*
612 yytokenName (yySymbol yytoken
)
614 return yytname
[yytoken
];
618 /** Perform user action for rule number YYN, with RHS length YYRHSLEN,
619 * and top stack item YYVSP. YYLVALP points to place to put semantic
620 * value ($$), and yylocp points to place for location information
621 * (@@$). Returns yyok for normal return, yyaccept for YYACCEPT,
622 * yyerr for YYERROR, yyabort for YYABORT. */
624 yyuserAction (yyRuleNum yyn
, int yyrhslen
, yyGLRStackItem
* yyvsp
,
625 YYSTYPE
* yyvalp
, YYLTYPE
* yylocp
, yyGLRStack
* yystack
628 /* Avoid `unused' warnings in there are no $n. */
633 *yyvalp
= yyval_default
;
634 *yylocp
= yyloc_default
;
638 *yyvalp
= yyvsp
[1-yyrhslen
].yystate
.yysemantics
.yysval
;
639 *yylocp
= yyvsp
[1-yyrhslen
].yystate
.yyloc
;
642 # define yyerrok (yystack->yyerrState = 0)
644 # define YYACCEPT return yyaccept
646 # define YYABORT return yyabort
648 # define YYERROR return yyerr
650 # define YYRECOVERING (yystack->yyerrState != 0)
652 # define yyclearin (yychar = *(yystack->yytokenp) = YYEMPTY)
654 # define YYBACKUP(Token, Value) \
656 yyerror (]b4_yyerror_args["syntax error: cannot back up"); \
674 /* Line __line__ of glr.c. */
675 b4_syncline([@oline@
], [@ofile@
])
680 yyuserMerge (int yyn
, YYSTYPE
* yy0
, YYSTYPE
* yy1
)
682 YYSTYPE yyval
= *yy0
;
683 /* `Use' the arguments. */
694 /* Bison grammar-table manipulation. */
696 ]b4_yydestruct_generate([b4_c_ansi_function_def
])[
698 /** Number of symbols composing the right hand side of rule #RULE. */
700 yyrhsLength (yyRuleNum yyrule
)
705 /** Left-hand-side symbol for rule #RULE. */
706 static inline yySymbol
707 yylhsNonterm (yyRuleNum yyrule
)
712 #define yyis_pact_ninf(yystate) \
713 ]m4_if(m4_eval(b4_pact_ninf < b4_pact_min), 1,
715 ((yystate
) == YYPACT_NINF
))[
717 /** True iff LR state STATE has only a default reduction (regardless
720 yyisDefaultedState (yyStateNum yystate
)
722 return yyis_pact_ninf (yypact
[yystate
]);
725 /** The default reduction for STATE, assuming it has one. */
726 static inline yyRuleNum
727 yydefaultAction (yyStateNum yystate
)
729 return yydefact
[yystate
];
732 #define yyis_table_ninf(yytable_value) \
733 ]m4_if(m4_eval(b4_table_ninf < b4_table_min), 1,
735 ((yytable_value
) == YYTABLE_NINF
))[
737 /** Set *YYACTION to the action to take in YYSTATE on seeing YYTOKEN.
739 * R < 0: Reduce on rule -R.
741 * R > 0: Shift to state R.
742 * Set *CONFLICTS to a pointer into yyconfl to 0-terminated list of
743 * conflicting reductions.
746 yygetLRActions (yyStateNum yystate
, int yytoken
,
747 int* yyaction
, const short** yyconflicts
)
749 int yyindex
= yypact
[yystate
] + yytoken
;
750 if (yyindex
< 0 || YYLAST
< yyindex
|| yycheck
[yyindex
] != yytoken
)
752 *yyaction
= -yydefact
[yystate
];
753 *yyconflicts
= yyconfl
;
755 else if (! yyis_table_ninf (yytable
[yyindex
]))
757 *yyaction
= yytable
[yyindex
];
758 *yyconflicts
= yyconfl
+ yyconflp
[yyindex
];
763 *yyconflicts
= yyconfl
+ yyconflp
[yyindex
];
767 static inline yyStateNum
768 yyLRgotoState (yyStateNum yystate
, yySymbol yylhs
)
771 yyr
= yypgoto
[yylhs
- YYNTOKENS
] + yystate
;
772 if (0 <= yyr
&& yyr
<= YYLAST
&& yycheck
[yyr
] == yystate
)
775 return yydefgoto
[yylhs
- YYNTOKENS
];
779 yyisShiftAction (int yyaction
)
785 yyisErrorAction (int yyaction
)
787 return yyaction
== 0;
793 yyaddDeferredAction (yyGLRStack
* yystack
, yyGLRState
* yystate
,
794 yyGLRState
* rhs
, yyRuleNum yyrule
]b4_pure_formals
[)
796 yySemanticOption
* yynewItem
;
797 yynewItem
= &yystack
->yynextFree
->yyoption
;
798 yystack
->yyspaceLeft
-= 1;
799 yystack
->yynextFree
+= 1;
800 yynewItem
->yyisState
= yyfalse
;
801 yynewItem
->yystate
= rhs
;
802 yynewItem
->yyrule
= yyrule
;
803 yynewItem
->yynext
= yystate
->yysemantics
.yyfirstVal
;
804 yystate
->yysemantics
.yyfirstVal
= yynewItem
;
805 if (yystack
->yyspaceLeft
< YYHEADROOM
)
806 yyexpandGLRStack (yystack
]b4_pure_args
[);
811 /** Initialize SET to a singleton set containing an empty stack. */
813 yyinitStateSet (yyGLRStateSet
* yyset
)
816 yyset
->yycapacity
= 16;
817 yyset
->yystates
= (yyGLRState
**) malloc (16 * sizeof (yyset
->yystates
[0]));
818 yyset
->yystates
[0] = NULL
;
821 static void yyfreeStateSet (yyGLRStateSet
* yyset
)
823 free (yyset
->yystates
);
826 /** Initialize STACK to a single empty stack, with total maximum
827 * capacity for all stacks of SIZE. */
829 yyinitGLRStack (yyGLRStack
* yystack
, size_t yysize
)
831 yystack
->yyerrflag
= 0;
832 yystack
->yyerrState
= 0;
834 yystack
->yyspaceLeft
= yysize
;
835 yystack
->yynextFree
= yystack
->yyitems
=
836 (yyGLRStackItem
*) malloc (yysize
* sizeof (yystack
->yynextFree
[0]));
837 yystack
->yysplitPoint
= NULL
;
838 yystack
->yylastDeleted
= NULL
;
839 yyinitStateSet (&yystack
->yytops
);
842 #define YYRELOC(YYFROMITEMS,YYTOITEMS,YYX,YYTYPE) \
843 &((YYTOITEMS) - ((YYFROMITEMS) - (yyGLRStackItem*) (YYX)))->YYTYPE
845 /** If STACK is expandable, extend it. WARNING: Pointers into the
846 stack from outside should be considered invalid after this call.
847 We always expand when there are 1 or fewer items left AFTER an
848 allocation, so that we can avoid having external pointers exist
849 across an allocation. */
851 yyexpandGLRStack (yyGLRStack
* yystack
]b4_pure_formals
[)
853 #if YYSTACKEXPANDABLE
854 yyGLRStack yynewStack
;
855 yyGLRStackItem
* yyp0
, *yyp1
;
856 size_t yysize
, yynewSize
;
858 yysize
= yystack
->yynextFree
- yystack
->yyitems
;
859 if (YYMAXDEPTH
<= yysize
)
860 yyFail (yystack
][]b4_pure_args
[, "parser stack overflow");
861 yynewSize
= 2*yysize
;
862 if (YYMAXDEPTH
< yynewSize
)
863 yynewSize
= YYMAXDEPTH
;
864 yyinitGLRStack (&yynewStack
, yynewSize
);
865 for (yyp0
= yystack
->yyitems
, yyp1
= yynewStack
.yyitems
, yyn
= yysize
;
867 yyn
-= 1, yyp0
+= 1, yyp1
+= 1)
872 yyGLRState
* yys0
= &yyp0
->yystate
;
873 yyGLRState
* yys1
= &yyp1
->yystate
;
874 if (yys0
->yypred
!= NULL
)
876 YYRELOC (yyp0
, yyp1
, yys0
->yypred
, yystate
);
877 if (! yys0
->yyresolved
&& yys0
->yysemantics
.yyfirstVal
!= NULL
)
878 yys1
->yysemantics
.yyfirstVal
=
879 YYRELOC(yyp0
, yyp1
, yys0
->yysemantics
.yyfirstVal
, yyoption
);
883 yySemanticOption
* yyv0
= &yyp0
->yyoption
;
884 yySemanticOption
* yyv1
= &yyp1
->yyoption
;
885 if (yyv0
->yystate
!= NULL
)
886 yyv1
->yystate
= YYRELOC (yyp0
, yyp1
, yyv0
->yystate
, yystate
);
887 if (yyv0
->yynext
!= NULL
)
888 yyv1
->yynext
= YYRELOC (yyp0
, yyp1
, yyv0
->yynext
, yyoption
);
891 if (yystack
->yysplitPoint
!= NULL
)
892 yystack
->yysplitPoint
= YYRELOC (yystack
->yyitems
, yynewStack
.yyitems
,
893 yystack
->yysplitPoint
, yystate
);
895 for (yyn
= 0; yyn
< yystack
->yytops
.yysize
; yyn
+= 1)
896 if (yystack
->yytops
.yystates
[yyn
] != NULL
)
897 yystack
->yytops
.yystates
[yyn
] =
898 YYRELOC (yystack
->yyitems
, yynewStack
.yyitems
,
899 yystack
->yytops
.yystates
[yyn
], yystate
);
900 free (yystack
->yyitems
);
901 yystack
->yyitems
= yynewStack
.yyitems
;
902 yystack
->yynextFree
= yynewStack
.yynextFree
+ yysize
;
903 yystack
->yyspaceLeft
= yynewStack
.yyspaceLeft
- yysize
;
907 yyFail (yystack
][]b4_lpure_args
[, "parser stack overflow");
912 yyfreeGLRStack (yyGLRStack
* yystack
)
914 free (yystack
->yyitems
);
915 yyfreeStateSet (&yystack
->yytops
);
918 /** Assuming that S is a GLRState somewhere on STACK, update the
919 * splitpoint of STACK, if needed, so that it is at least as deep as
922 yyupdateSplit (yyGLRStack
* yystack
, yyGLRState
* yys
)
924 if (yystack
->yysplitPoint
!= NULL
&& yystack
->yysplitPoint
> yys
)
925 yystack
->yysplitPoint
= yys
;
928 /** Invalidate stack #K in STACK. */
930 yymarkStackDeleted (yyGLRStack
* yystack
, int yyk
)
932 if (yystack
->yytops
.yystates
[yyk
] != NULL
)
933 yystack
->yylastDeleted
= yystack
->yytops
.yystates
[yyk
];
934 yystack
->yytops
.yystates
[yyk
] = NULL
;
937 /** Undelete the last stack that was marked as deleted. Can only be
938 done once after a deletion, and only when all other stacks have
941 yyundeleteLastStack (yyGLRStack
* yystack
)
943 if (yystack
->yylastDeleted
== NULL
|| yystack
->yytops
.yysize
!= 0)
945 yystack
->yytops
.yystates
[0] = yystack
->yylastDeleted
;
946 yystack
->yytops
.yysize
= 1;
947 YYDPRINTF ((stderr
, "Restoring last deleted stack as stack #0.\n"));
948 yystack
->yylastDeleted
= NULL
;
952 yyremoveDeletes (yyGLRStack
* yystack
)
956 while (yyj
< yystack
->yytops
.yysize
)
958 if (yystack
->yytops
.yystates
[yyi
] == NULL
)
962 YYDPRINTF ((stderr
, "Removing dead stacks.\n"));
964 yystack
->yytops
.yysize
-= 1;
968 yystack
->yytops
.yystates
[yyj
] = yystack
->yytops
.yystates
[yyi
];
971 YYDPRINTF ((stderr
, "Rename stack %d -> %d.\n", yyi
, yyj
));
979 /** Shift to a new state on stack #K of STACK, corresponding to LR state
980 * LRSTATE, at input position POSN, with (resolved) semantic value SVAL. */
982 yyglrShift (yyGLRStack
* yystack
, int yyk
, yyStateNum yylrState
, size_t yyposn
,
983 YYSTYPE yysval
, YYLTYPE
* yylocp
]b4_user_formals
[)
985 yyGLRStackItem
* yynewItem
;
987 yynewItem
= yystack
->yynextFree
;
988 yystack
->yynextFree
+= 1;
989 yystack
->yyspaceLeft
-= 1;
990 yynewItem
->yystate
.yyisState
= yytrue
;
991 yynewItem
->yystate
.yylrState
= yylrState
;
992 yynewItem
->yystate
.yyposn
= yyposn
;
993 yynewItem
->yystate
.yyresolved
= yytrue
;
994 yynewItem
->yystate
.yypred
= yystack
->yytops
.yystates
[yyk
];
995 yystack
->yytops
.yystates
[yyk
] = &yynewItem
->yystate
;
996 yynewItem
->yystate
.yysemantics
.yysval
= yysval
;
997 yynewItem
->yystate
.yyloc
= *yylocp
;
998 if (yystack
->yyspaceLeft
< YYHEADROOM
)
999 yyexpandGLRStack (yystack
]b4_pure_args
[);
1002 /** Shift to a new state on stack #K of STACK, to a new state
1003 * corresponding to LR state LRSTATE, at input position POSN, with
1004 * the (unresolved) semantic value of RHS under the action for RULE. */
1006 yyglrShiftDefer (yyGLRStack
* yystack
, int yyk
, yyStateNum yylrState
,
1007 size_t yyposn
, yyGLRState
* rhs
, yyRuleNum yyrule
]b4_pure_formals
[)
1009 yyGLRStackItem
* yynewItem
;
1011 yynewItem
= yystack
->yynextFree
;
1012 yynewItem
->yystate
.yyisState
= yytrue
;
1013 yynewItem
->yystate
.yylrState
= yylrState
;
1014 yynewItem
->yystate
.yyposn
= yyposn
;
1015 yynewItem
->yystate
.yyresolved
= yyfalse
;
1016 yynewItem
->yystate
.yypred
= yystack
->yytops
.yystates
[yyk
];
1017 yynewItem
->yystate
.yysemantics
.yyfirstVal
= NULL
;
1018 yystack
->yytops
.yystates
[yyk
] = &yynewItem
->yystate
;
1019 yystack
->yynextFree
+= 1;
1020 yystack
->yyspaceLeft
-= 1;
1021 yyaddDeferredAction (yystack
, &yynewItem
->yystate
, rhs
, yyrule
]b4_pure_args
[);
1024 /** Pop the symbols consumed by reduction #RULE from the top of stack
1025 * #K of STACK, and perform the appropriate semantic action on their
1026 * semantic values. Assumes that all ambiguities in semantic values
1027 * have been previously resolved. Set *VALP to the resulting value,
1028 * and *LOCP to the computed location (if any). Return value is as
1029 * for userAction. */
1030 static inline YYRESULTTAG
1031 yydoAction (yyGLRStack
* yystack
, int yyk
, yyRuleNum yyrule
,
1032 YYSTYPE
* yyvalp
, YYLTYPE
* yylocp
]b4_user_formals
[)
1034 int yynrhs
= yyrhsLength (yyrule
);
1036 if (yystack
->yysplitPoint
== NULL
)
1038 /* Standard special case: single stack. */
1039 yyGLRStackItem
* rhs
= (yyGLRStackItem
*) yystack
->yytops
.yystates
[yyk
];
1042 yystack
->yynextFree
-= yynrhs
;
1043 yystack
->yyspaceLeft
+= yynrhs
;
1044 yystack
->yytops
.yystates
[0] = & yystack
->yynextFree
[-1].yystate
;
1047 *yyvalp
= yyval_default
;
1048 *yylocp
= yyloc_default
;
1052 *yyvalp
= rhs
[1-yynrhs
].yystate
.yysemantics
.yysval
;
1053 *yylocp
= rhs
[1-yynrhs
].yystate
.yyloc
;
1055 return yyuserAction (yyrule
, yynrhs
, rhs
,
1056 yyvalp
, yylocp
, yystack
]b4_user_args
[);
1062 yyGLRStackItem yyrhsVals
[YYMAXRHS
];
1063 for (yyi
= yynrhs
-1, yys
= yystack
->yytops
.yystates
[yyk
]; 0 <= yyi
;
1064 yyi
-= 1, yys
= yys
->yypred
)
1068 yyrhsVals
[yyi
].yystate
.yyresolved
= yytrue
;
1069 yyrhsVals
[yyi
].yystate
.yysemantics
.yysval
= yys
->yysemantics
.yysval
;
1070 yyrhsVals
[yyi
].yystate
.yyloc
= yys
->yyloc
;
1072 yyupdateSplit (yystack
, yys
);
1073 yystack
->yytops
.yystates
[yyk
] = yys
;
1076 *yyvalp
= yyval_default
;
1077 *yylocp
= yyloc_default
;
1081 *yyvalp
= yyrhsVals
[0].yystate
.yysemantics
.yysval
;
1082 *yylocp
= yyrhsVals
[0].yystate
.yyloc
;
1084 return yyuserAction (yyrule
, yynrhs
, yyrhsVals
+ (yynrhs
-1),
1085 yyvalp
, yylocp
, yystack
]b4_user_args
[);
1090 # define YY_REDUCE_PRINT(K, Rule)
1092 # define YY_REDUCE_PRINT(K, Rule) \
1095 yy_reduce_print (K, Rule); \
1098 /*----------------------------------------------------------.
1099 | Report that the RULE is going to be reduced on stack #K. |
1100 `----------------------------------------------------------*/
1103 yy_reduce_print (size_t yyk
, yyRuleNum yyrule
)
1106 unsigned int yylineno
= yyrline
[yyrule
];
1107 YYFPRINTF (stderr
, "Reducing stack %d by rule %d (line %u), ",
1108 yyk
, yyrule
- 1, yylineno
);
1109 /* Print the symbols being reduced, and their result. */
1110 for (yyi
= yyprhs
[yyrule
]; 0 <= yyrhs
[yyi
]; yyi
++)
1111 YYFPRINTF (stderr
, "%s ", yytokenName (yyrhs
[yyi
]));
1112 YYFPRINTF (stderr
, "-> %s\n", yytokenName (yyr1
[yyrule
]));
1116 /** Pop items off stack #K of STACK according to grammar rule RULE,
1117 * and push back on the resulting nonterminal symbol. Perform the
1118 * semantic action associated with RULE and store its value with the
1119 * newly pushed state, if FORCEEVAL or if STACK is currently
1120 * unambiguous. Otherwise, store the deferred semantic action with
1121 * the new state. If the new state would have an identical input
1122 * position, LR state, and predecessor to an existing state on the stack,
1123 * it is identified with that existing state, eliminating stack #K from
1124 * the STACK. In this case, the (necessarily deferred) semantic value is
1125 * added to the options for the existing state's semantic value.
1127 static inline YYRESULTTAG
1128 yyglrReduce (yyGLRStack
* yystack
, size_t yyk
, yyRuleNum yyrule
,
1129 bool yyforceEval
]b4_pure_formals
[)
1131 size_t yyposn
= yystack
->yytops
.yystates
[yyk
]->yyposn
;
1133 if (yyforceEval
|| yystack
->yysplitPoint
== NULL
)
1138 YY_REDUCE_PRINT (yyk
, yyrule
);
1139 YYCHK (yydoAction (yystack
, yyk
, yyrule
, &yysval
, &yyloc
]b4_user_args
[));
1140 yyglrShift (yystack
, yyk
,
1141 yyLRgotoState (yystack
->yytops
.yystates
[yyk
]->yylrState
,
1142 yylhsNonterm (yyrule
)),
1143 yyposn
, yysval
, &yyloc
]b4_user_args
[);
1149 yyGLRState
* yys
, *yys0
= yystack
->yytops
.yystates
[yyk
];
1150 yyStateNum yynewLRState
;
1152 for (yys
= yystack
->yytops
.yystates
[yyk
], yyn
= yyrhsLength (yyrule
);
1159 yyupdateSplit (yystack
, yys
);
1160 yynewLRState
= yyLRgotoState (yys
->yylrState
, yylhsNonterm (yyrule
));
1162 "Reduced stack %d by rule #%d; action deferred. "
1163 "Now in state %d.\n",
1164 yyk
, yyrule
-1, yynewLRState
));
1165 for (yyi
= 0; yyi
< yystack
->yytops
.yysize
; yyi
+= 1)
1166 if (yyi
!= yyk
&& yystack
->yytops
.yystates
[yyi
] != NULL
)
1168 yyGLRState
* yyp
, *yysplit
= yystack
->yysplitPoint
;
1169 yyp
= yystack
->yytops
.yystates
[yyi
];
1170 while (yyp
!= yys
&& yyp
!= yysplit
&& yyp
->yyposn
>= yyposn
)
1172 if (yyp
->yylrState
== yynewLRState
&& yyp
->yypred
== yys
)
1174 yyaddDeferredAction (yystack
, yyp
, yys0
, yyrule
]b4_pure_args
[);
1175 yymarkStackDeleted (yystack
, yyk
);
1176 YYDPRINTF ((stderr
, "Merging stack %d into stack %d.\n",
1183 yystack
->yytops
.yystates
[yyk
] = yys
;
1184 yyglrShiftDefer (yystack
, yyk
, yynewLRState
, yyposn
, yys0
, yyrule
]b4_pure_args
[);
1190 yysplitStack (yyGLRStack
* yystack
, int yyk
)
1192 if (yystack
->yysplitPoint
== NULL
)
1196 yystack
->yysplitPoint
= yystack
->yytops
.yystates
[yyk
];
1198 if (yystack
->yytops
.yysize
>= yystack
->yytops
.yycapacity
)
1200 yystack
->yytops
.yycapacity
*= 2;
1201 yystack
->yytops
.yystates
=
1202 (yyGLRState
**) realloc (yystack
->yytops
.yystates
,
1203 yystack
->yytops
.yycapacity
1204 * sizeof (yyGLRState
*));
1206 yystack
->yytops
.yystates
[yystack
->yytops
.yysize
]
1207 = yystack
->yytops
.yystates
[yyk
];
1208 yystack
->yytops
.yysize
+= 1;
1209 return yystack
->yytops
.yysize
-1;
1212 /** True iff Y0 and Y1 represent identical options at the top level.
1213 * That is, they represent the same rule applied to RHS symbols
1214 * that produce the same terminal symbols. */
1216 yyidenticalOptions (yySemanticOption
* yyy0
, yySemanticOption
* yyy1
)
1218 if (yyy0
->yyrule
== yyy1
->yyrule
)
1220 yyGLRState
*yys0
, *yys1
;
1222 for (yys0
= yyy0
->yystate
, yys1
= yyy1
->yystate
,
1223 yyn
= yyrhsLength (yyy0
->yyrule
);
1225 yys0
= yys0
->yypred
, yys1
= yys1
->yypred
, yyn
-= 1)
1226 if (yys0
->yyposn
!= yys1
->yyposn
)
1234 /** Assuming identicalOptions (Y0,Y1), (destructively) merge the
1235 * alternative semantic values for the RHS-symbols of Y1 into the
1236 * corresponding semantic value sets of the symbols of Y0. */
1238 yymergeOptionSets (yySemanticOption
* yyy0
, yySemanticOption
* yyy1
)
1240 yyGLRState
*yys0
, *yys1
;
1242 for (yys0
= yyy0
->yystate
, yys1
= yyy1
->yystate
,
1243 yyn
= yyrhsLength (yyy0
->yyrule
);
1245 yys0
= yys0
->yypred
, yys1
= yys1
->yypred
, yyn
-= 1)
1248 else if (! yys0
->yyresolved
&& ! yys1
->yyresolved
)
1250 yySemanticOption
* yyz
;
1251 for (yyz
= yys0
->yysemantics
.yyfirstVal
; yyz
->yynext
!= NULL
;
1254 yyz
->yynext
= yys1
->yysemantics
.yyfirstVal
;
1258 /** Y0 and Y1 represent two possible actions to take in a given
1259 * parsing state; return 0 if no combination is possible,
1260 * 1 if user-mergeable, 2 if Y0 is preferred, 3 if Y1 is preferred. */
1262 yypreference (yySemanticOption
* y0
, yySemanticOption
* y1
)
1264 yyRuleNum r0
= y0
->yyrule
, r1
= y1
->yyrule
;
1265 int p0
= yydprec
[r0
], p1
= yydprec
[r1
];
1269 if (yymerger
[r0
] == 0 || yymerger
[r0
] != yymerger
[r1
])
1274 if (p0
== 0 || p1
== 0)
1283 static YYRESULTTAG
yyresolveValue (yySemanticOption
* yyoptionList
,
1284 yyGLRStack
* yystack
, YYSTYPE
* yyvalp
,
1285 YYLTYPE
* yylocp
]b4_user_formals
[);
1288 yyresolveStates (yyGLRState
* yys
, int yyn
, yyGLRStack
* yystack
]b4_user_formals
[)
1295 yyflag
= yyresolveStates (yys
->yypred
, yyn
-1, yystack
]b4_user_args
[);
1298 if (! yys
->yyresolved
)
1300 yyflag
= yyresolveValue (yys
->yysemantics
.yyfirstVal
, yystack
,
1301 &yys
->yysemantics
.yysval
, &yys
->yyloc
1305 yys
->yyresolved
= yytrue
;
1312 yyresolveAction (yySemanticOption
* yyopt
, yyGLRStack
* yystack
,
1313 YYSTYPE
* yyvalp
, YYLTYPE
* yylocp
]b4_user_formals
[)
1315 yyGLRStackItem yyrhsVals
[YYMAXRHS
];
1319 yynrhs
= yyrhsLength (yyopt
->yyrule
);
1320 YYCHK (yyresolveStates (yyopt
->yystate
, yynrhs
, yystack
]b4_user_args
[));
1321 for (yyi
= yynrhs
-1, yys
= yyopt
->yystate
; 0 <= yyi
;
1322 yyi
-= 1, yys
= yys
->yypred
)
1326 yyrhsVals
[yyi
].yystate
.yyresolved
= yytrue
;
1327 yyrhsVals
[yyi
].yystate
.yysemantics
.yysval
= yys
->yysemantics
.yysval
;
1328 yyrhsVals
[yyi
].yystate
.yyloc
= yys
->yyloc
;
1330 return yyuserAction (yyopt
->yyrule
, yynrhs
, yyrhsVals
+ (yynrhs
-1),
1331 yyvalp
, yylocp
, yystack
]b4_user_args
[);
1336 yyreportTree (yySemanticOption
* yyx
, int yyindent
)
1338 int yynrhs
= yyrhsLength (yyx
->yyrule
);
1341 yyGLRState
* yystates
[YYMAXRHS
];
1342 yyGLRState yyleftmost_state
;
1344 for (yyi
= yynrhs
, yys
= yyx
->yystate
; 0 < yyi
; yyi
-= 1, yys
= yys
->yypred
)
1345 yystates
[yyi
] = yys
;
1348 yyleftmost_state
.yyposn
= 0;
1349 yystates
[0] = &yyleftmost_state
;
1354 if (yyx
->yystate
->yyposn
< yys
->yyposn
+ 1)
1355 YYFPRINTF (stderr
, "%*s%s -> <Rule %d, empty>\n",
1356 yyindent
, "", yytokenName (yylhsNonterm (yyx
->yyrule
)),
1359 YYFPRINTF (stderr
, "%*s%s -> <Rule %d, tokens %d .. %d>\n",
1360 yyindent
, "", yytokenName (yylhsNonterm (yyx
->yyrule
)),
1361 yyx
->yyrule
, yys
->yyposn
+1, yyx
->yystate
->yyposn
);
1362 for (yyi
= 1; yyi
<= yynrhs
; yyi
+= 1)
1364 if (yystates
[yyi
]->yyresolved
)
1366 if (yystates
[yyi
-1]->yyposn
+1 > yystates
[yyi
]->yyposn
)
1367 YYFPRINTF (stderr
, "%*s%s <empty>\n", yyindent
+2, "",
1368 yytokenName (yyrhs
[yyprhs
[yyx
->yyrule
]+yyi
-1]));
1370 YYFPRINTF (stderr
, "%*s%s <tokens %d .. %d>\n", yyindent
+2, "",
1371 yytokenName (yyrhs
[yyprhs
[yyx
->yyrule
]+yyi
-1]),
1372 yystates
[yyi
-1]->yyposn
+1, yystates
[yyi
]->yyposn
);
1375 yyreportTree (yystates
[yyi
]->yysemantics
.yyfirstVal
, yyindent
+2);
1381 yyreportAmbiguity (yySemanticOption
* yyx0
, yySemanticOption
* yyx1
,
1382 yyGLRStack
* yystack
]b4_pure_formals
[)
1384 /* `Unused' warnings. */
1389 YYFPRINTF (stderr
, "Ambiguity detected.\n");
1390 YYFPRINTF (stderr
, "Option 1,\n");
1391 yyreportTree (yyx0
, 2);
1392 YYFPRINTF (stderr
, "\nOption 2,\n");
1393 yyreportTree (yyx1
, 2);
1394 YYFPRINTF (stderr
, "\n");
1396 yyFail (yystack
][]b4_pure_args
[, "ambiguity detected");
1400 /** Resolve the ambiguity represented by OPTIONLIST, perform the indicated
1401 * actions, and return the result. */
1403 yyresolveValue (yySemanticOption
* yyoptionList
, yyGLRStack
* yystack
,
1404 YYSTYPE
* yyvalp
, YYLTYPE
* yylocp
]b4_user_formals
[)
1406 yySemanticOption
* yybest
;
1407 yySemanticOption
* yyp
;
1410 yybest
= yyoptionList
;
1412 for (yyp
= yyoptionList
->yynext
; yyp
!= NULL
; yyp
= yyp
->yynext
)
1414 if (yyidenticalOptions (yybest
, yyp
))
1415 yymergeOptionSets (yybest
, yyp
);
1417 switch (yypreference (yybest
, yyp
))
1420 yyreportAmbiguity (yybest
, yyp
, yystack
]b4_pure_args
[);
1436 int yyprec
= yydprec
[yybest
->yyrule
];
1437 YYCHK (yyresolveAction (yybest
, yystack
, yyvalp
, yylocp
]b4_user_args
[));
1438 for (yyp
= yybest
->yynext
; yyp
!= NULL
; yyp
= yyp
->yynext
)
1440 if (yyprec
== yydprec
[yyp
->yyrule
])
1444 YYCHK (yyresolveAction (yyp
, yystack
, &yyval1
, &yydummy
]b4_user_args
[));
1445 *yyvalp
= yyuserMerge (yymerger
[yyp
->yyrule
], yyvalp
, &yyval1
);
1451 return yyresolveAction (yybest
, yystack
, yyvalp
, yylocp
]b4_user_args
[);
1455 yyresolveStack (yyGLRStack
* yystack
]b4_user_formals
[)
1457 if (yystack
->yysplitPoint
!= NULL
)
1462 for (yyn
= 0, yys
= yystack
->yytops
.yystates
[0];
1463 yys
!= yystack
->yysplitPoint
;
1464 yys
= yys
->yypred
, yyn
+= 1)
1466 YYCHK (yyresolveStates (yystack
->yytops
.yystates
[0], yyn
, yystack
1473 yycompressStack (yyGLRStack
* yystack
)
1475 yyGLRState
* yyp
, *yyq
, *yyr
;
1477 if (yystack
->yytops
.yysize
!= 1 || yystack
->yysplitPoint
== NULL
)
1480 for (yyp
= yystack
->yytops
.yystates
[0], yyq
= yyp
->yypred
, yyr
= NULL
;
1481 yyp
!= yystack
->yysplitPoint
;
1482 yyr
= yyp
, yyp
= yyq
, yyq
= yyp
->yypred
)
1485 yystack
->yyspaceLeft
+= yystack
->yynextFree
- yystack
->yyitems
;
1486 yystack
->yynextFree
= ((yyGLRStackItem
*) yystack
->yysplitPoint
) + 1;
1487 yystack
->yyspaceLeft
-= yystack
->yynextFree
- yystack
->yyitems
;
1488 yystack
->yysplitPoint
= NULL
;
1489 yystack
->yylastDeleted
= NULL
;
1493 yystack
->yynextFree
->yystate
= *yyr
;
1495 yystack
->yynextFree
->yystate
.yypred
= & yystack
->yynextFree
[-1].yystate
;
1496 yystack
->yytops
.yystates
[0] = &yystack
->yynextFree
->yystate
;
1497 yystack
->yynextFree
+= 1;
1498 yystack
->yyspaceLeft
-= 1;
1503 yyprocessOneStack (yyGLRStack
* yystack
, int yyk
,
1504 size_t yyposn
, YYSTYPE
* yylvalp
, YYLTYPE
* yyllocp
1508 const short* yyconflicts
;
1510 yySymbol
* const yytokenp
= yystack
->yytokenp
;
1512 while (yystack
->yytops
.yystates
[yyk
] != NULL
)
1514 yyStateNum yystate
= yystack
->yytops
.yystates
[yyk
]->yylrState
;
1515 YYDPRINTF ((stderr
, "Stack %d Entering state %d\n", yyk
, yystate
));
1517 if (yystate
== YYFINAL
)
1519 if (yyisDefaultedState (yystate
))
1521 yyrule
= yydefaultAction (yystate
);
1524 YYDPRINTF ((stderr
, "Stack %d dies.\n", yyk
));
1525 yymarkStackDeleted (yystack
, yyk
);
1528 YYCHK (yyglrReduce (yystack
, yyk
, yyrule
, yyfalse
]b4_lpure_args
[));
1532 if (*yytokenp
== YYEMPTY
)
1534 YYDPRINTF ((stderr
, "Reading a token: "));
1536 *yytokenp
= YYTRANSLATE (yychar
);
1537 YYDSYMPRINTF ("Next token is", *yytokenp
, yylvalp
, yyllocp
);
1539 yygetLRActions (yystate
, *yytokenp
, &yyaction
, &yyconflicts
);
1541 while (*yyconflicts
!= 0)
1543 int yynewStack
= yysplitStack (yystack
, yyk
);
1544 YYDPRINTF ((stderr
, "Splitting off stack %d from %d.\n",
1546 YYCHK (yyglrReduce (yystack
, yynewStack
,
1547 *yyconflicts
, yyfalse
]b4_lpure_args
[));
1548 YYCHK (yyprocessOneStack (yystack
, yynewStack
, yyposn
,
1549 yylvalp
, yyllocp
]b4_user_args
[));
1553 if (yyisShiftAction (yyaction
))
1555 YYDPRINTF ((stderr
, "Shifting token %s on stack %d, ",
1556 yytokenName (*yytokenp
), yyk
));
1557 yyglrShift (yystack
, yyk
, yyaction
, yyposn
+1,
1558 *yylvalp
, yyllocp
]b4_user_args
[);
1559 YYDPRINTF ((stderr
, "which is now in state #%d\n",
1560 yystack
->yytops
.yystates
[yyk
]->yylrState
));
1563 else if (yyisErrorAction (yyaction
))
1565 YYDPRINTF ((stderr
, "Stack %d dies.\n", yyk
));
1566 yymarkStackDeleted (yystack
, yyk
);
1570 YYCHK (yyglrReduce (yystack
, yyk
, -yyaction
, yyfalse
]b4_lpure_args
[));
1577 yyreportSyntaxError (yyGLRStack
* yystack
,
1578 YYSTYPE
* yylvalp
, YYLTYPE
* yyllocp
]b4_user_formals
[)
1580 /* `Unused' warnings. */
1584 if (yystack
->yyerrState
== 0)
1587 yySymbol
* const yytokenp
= yystack
->yytokenp
;
1588 int yyn
, yyx
, yycount
;
1590 const char* yyprefix
;
1593 yyn
= yypact
[yystack
->yytops
.yystates
[0]->yylrState
];
1594 if (YYPACT_NINF
< yyn
&& yyn
< YYLAST
)
1597 /* Start YYX at -YYN if negative to avoid negative indexes in
1599 yysize
= sizeof ("syntax error, unexpected ")
1600 + strlen (yytokenName (*yytokenp
));
1601 yyprefix
= ", expecting ";
1602 for (yyx
= yyn
< 0 ? -yyn
: 0; yyx
< yytname_size
&& yycount
<= 5;
1604 if (yycheck
[yyx
+ yyn
] == yyx
&& yyx
!= YYTERROR
)
1605 yysize
+= strlen (yytokenName (yyx
)) + strlen (yyprefix
),
1606 yycount
+= 1, yyprefix
= " or ";
1607 yymsg
= yyp
= (char*) malloc (yysize
);
1608 sprintf (yyp
, "syntax error, unexpected %s",
1609 yytokenName (*yytokenp
));
1610 yyp
+= strlen (yyp
);
1613 yyprefix
= ", expecting ";
1614 for (yyx
= yyn
< 0 ? -yyn
: 0; yyx
< yytname_size
; yyx
+= 1)
1615 if (yycheck
[yyx
+ yyn
] == yyx
&& yyx
!= YYTERROR
)
1617 sprintf (yyp
, "%s%s", yyprefix
, yytokenName (yyx
));
1618 yyp
+= strlen (yyp
);
1622 yyerror (]b4_lyyerror_args
[yymsg
);
1627 yyerror (]b4_lyyerror_args
["syntax error");
1632 /* Recover from a syntax error on YYSTACK, assuming that YYTOKENP,
1633 YYLVALP, and YYLLOCP point to the syntactic category, semantic
1634 value, and location of the lookahead. */
1636 yyrecoverSyntaxError (yyGLRStack
* yystack
,
1637 YYSTYPE
* yylvalp
, YYLTYPE
* yyllocp
]b4_user_formals
[)
1639 yySymbol
* const yytokenp
= yystack
->yytokenp
;
1643 if (yystack
->yyerrState
== 0)
1644 yystack
->yyerrState
= 3;
1645 else if (yystack
->yyerrState
== 3)
1646 /* We just shifted the error token and (perhaps) took some
1647 reductions. Skip tokens until we can proceed. */
1650 if (*yytokenp
== YYEOF
)
1652 /* Now pop stack until we find a state that shifts the
1654 while (yystack
->yytops
.yystates
[0] != NULL
)
1656 yyGLRState
*yys
= yystack
->yytops
.yystates
[0];
1657 YYDSYMPRINTF ("Error: popping",
1658 yystos
[yys
->yylrState
],
1659 &yys
->yysemantics
.yysval
, &yys
->yyloc
);
1660 yydestruct (yystos
[yys
->yylrState
],
1661 &yys
->yysemantics
.yysval
]b4_location_if([, &yys
->yyloc
])[);
1662 yystack
->yytops
.yystates
[0] = yys
->yypred
;
1663 yystack
->yynextFree
-= 1;
1664 yystack
->yyspaceLeft
+= 1;
1666 yyFail (yystack
][]b4_lpure_args
[, NULL
);
1668 if (*yytokenp
!= YYEMPTY
)
1670 YYDSYMPRINTF ("Error: discarding", *yytokenp
, yylvalp
, yyllocp
);
1671 yydestruct (*yytokenp
, yylvalp
]b4_location_if([, yyllocp
])[);
1673 YYDPRINTF ((stderr
, "Reading a token: "));
1675 *yytokenp
= YYTRANSLATE (yychar
);
1676 YYDSYMPRINTF ("Next token is", *yytokenp
, yylvalp
, yyllocp
);
1677 yyj
= yypact
[yystack
->yytops
.yystates
[0]->yylrState
];
1678 if (yyis_pact_ninf (yyj
))
1679 /* Something's not right; we shouldn't be here. */
1680 yyFail (yystack
][]b4_lpure_args
[, NULL
);
1682 if (yyj
< 0 || YYLAST
< yyj
|| yycheck
[yyj
] != *yytokenp
)
1684 if (yydefact
[yystack
->yytops
.yystates
[0]->yylrState
] != 0)
1687 else if (yytable
[yyj
] != 0 && ! yyis_table_ninf (yytable
[yyj
]))
1691 /* Reduce to one stack. */
1692 for (yyk
= 0; yyk
< yystack
->yytops
.yysize
; yyk
+= 1)
1693 if (yystack
->yytops
.yystates
[yyk
] != NULL
)
1695 if (yyk
>= yystack
->yytops
.yysize
)
1696 yyFail (yystack
][]b4_lpure_args
[, NULL
);
1697 for (yyk
+= 1; yyk
< yystack
->yytops
.yysize
; yyk
+= 1)
1698 yymarkStackDeleted (yystack
, yyk
);
1699 yyremoveDeletes (yystack
);
1700 yycompressStack (yystack
);
1702 /* Now pop stack until we find a state that shifts the error token. */
1703 while (yystack
->yytops
.yystates
[0] != NULL
)
1705 yyGLRState
*yys
= yystack
->yytops
.yystates
[0];
1706 yyj
= yypact
[yys
->yylrState
];
1707 if (! yyis_pact_ninf (yyj
))
1710 if (0 <= yyj
&& yyj
<= YYLAST
&& yycheck
[yyj
] == YYTERROR
1711 && yyisShiftAction (yytable
[yyj
]))
1713 YYDPRINTF ((stderr
, "Shifting error token, "));
1714 yyglrShift (yystack
, 0, yytable
[yyj
],
1715 yys
->yyposn
, *yylvalp
, yyllocp
]b4_user_args
[);
1719 YYDSYMPRINTF ("Error: popping",
1720 yystos
[yys
->yylrState
],
1721 &yys
->yysemantics
.yysval
, &yys
->yyloc
);
1722 yydestruct (yystos
[yys
->yylrState
],
1723 &yys
->yysemantics
.yysval
]b4_location_if([, &yys
->yyloc
])[);
1724 yystack
->yytops
.yystates
[0] = yys
->yypred
;
1725 yystack
->yynextFree
-= 1;
1726 yystack
->yyspaceLeft
+= 1;
1728 if (yystack
->yytops
.yystates
[0] == NULL
)
1729 yyFail (yystack
][]b4_lpure_args
[, NULL
);
1732 #define YYCHK1(YYE) \
1738 yystack.yyerrflag = 1; \
1741 yystack.yyerrflag = 0; \
1744 goto yyuser_error; \
1753 ]b4_c_ansi_function_def([yyparse
], [int], b4_parse_param
)[
1763 #define yychar (yystack.yyrawchar)
1766 YYSTYPE
* const yylvalp
= &yylval
;
1767 YYLTYPE
* const yyllocp
= &yylloc
;
1769 yyinitGLRStack (&yystack
, YYINITDEPTH
);
1770 yystack
.yytokenp
= &yytoken
;
1772 YYDPRINTF ((stderr
, "Starting parse\n"));
1774 if (setjmp (yystack
.yyexception_buffer
) != 0)
1777 yyglrShift (&yystack
, 0, 0, 0, yyval_default
, &yyloc_default
]b4_user_args
[);
1783 /* For efficiency, we have two loops, the first of which is
1784 specialized to deterministic operation (single stack, no
1785 potential ambiguity). */
1791 const short* yyconflicts
;
1793 yyStateNum yystate
= yystack
.yytops
.yystates
[0]->yylrState
;
1794 YYDPRINTF ((stderr
, "Entering state %d\n", yystate
));
1795 if (yystate
== YYFINAL
)
1797 if (yyisDefaultedState (yystate
))
1799 yyrule
= yydefaultAction (yystate
);
1802 yyreportSyntaxError (&yystack
, yylvalp
, yyllocp
]b4_user_args
[);
1805 YYCHK1 (yyglrReduce (&yystack
, 0, yyrule
, yytrue
]b4_lpure_args
[));
1809 if (yytoken
== YYEMPTY
)
1811 YYDPRINTF ((stderr
, "Reading a token: "));
1813 yytoken
= YYTRANSLATE (yychar
);
1814 YYDSYMPRINTF ("Next token is", yytoken
, yylvalp
, yyllocp
);
1816 yygetLRActions (yystate
, yytoken
, &yyaction
, &yyconflicts
);
1817 if (*yyconflicts
!= 0)
1819 if (yyisShiftAction (yyaction
))
1821 YYDPRINTF ((stderr
, "Shifting token %s, ",
1822 yytokenName (yytoken
)));
1823 if (yytoken
!= YYEOF
)
1826 yyglrShift (&yystack
, 0, yyaction
, yyposn
,
1827 yylval
, yyllocp
]b4_user_args
[);
1828 if (0 < yystack
.yyerrState
)
1829 yystack
.yyerrState
-= 1;
1831 else if (yyisErrorAction (yyaction
))
1833 yyreportSyntaxError (&yystack
, yylvalp
, yyllocp
]b4_user_args
[);
1837 YYCHK1 (yyglrReduce (&yystack
, 0, -yyaction
, yytrue
]b4_lpure_args
[));
1844 int yyn
= yystack
.yytops
.yysize
;
1845 for (yys
= 0; yys
< yyn
; yys
+= 1)
1846 YYCHK1 (yyprocessOneStack (&yystack
, yys
, yyposn
,
1847 yylvalp
, yyllocp
]b4_user_args
[));
1850 yyremoveDeletes (&yystack
);
1851 if (yystack
.yytops
.yysize
== 0)
1853 yyundeleteLastStack (&yystack
);
1854 if (yystack
.yytops
.yysize
== 0)
1855 yyFail (&yystack
][]b4_lpure_args
[, "syntax error");
1856 YYCHK1 (yyresolveStack (&yystack
]b4_user_args
[));
1857 YYDPRINTF ((stderr
, "Returning to deterministic operation.\n"));
1858 yyreportSyntaxError (&yystack
, yylvalp
, yyllocp
]b4_user_args
[);
1861 else if (yystack
.yytops
.yysize
== 1)
1863 YYCHK1 (yyresolveStack (&yystack
]b4_user_args
[));
1864 YYDPRINTF ((stderr
, "Returning to deterministic operation.\n"));
1865 yycompressStack (&yystack
);
1871 yyrecoverSyntaxError (&yystack
, yylvalp
, yyllocp
]b4_user_args
[);
1872 yyposn
= yystack
.yytops
.yystates
[0]->yyposn
;
1877 yyfreeGLRStack (&yystack
);
1878 return yystack
.yyerrflag
;
1881 /* DEBUGGING ONLY */
1882 static void yypstack (yyGLRStack
* yystack
, int yyk
) ATTRIBUTE_UNUSED
;
1883 static void yypdumpstack (yyGLRStack
* yystack
) ATTRIBUTE_UNUSED
;
1886 yy_yypstack (yyGLRState
* yys
)
1890 yy_yypstack (yys
->yypred
);
1891 fprintf (stderr
, " -> ");
1893 fprintf (stderr
, "%d@@%lu", yys
->yylrState
, (unsigned long) yys
->yyposn
);
1897 yypstates (yyGLRState
* yyst
)
1900 fprintf (stderr
, "<null>");
1903 fprintf (stderr
, "\n");
1907 yypstack (yyGLRStack
* yystack
, int yyk
)
1909 yypstates (yystack
->yytops
.yystates
[yyk
]);
1912 #define YYINDEX(YYX) \
1913 ((YYX) == NULL ? -1 : (yyGLRStackItem*) (YYX) - yystack->yyitems)
1917 yypdumpstack (yyGLRStack
* yystack
)
1919 yyGLRStackItem
* yyp
;
1921 for (yyp
= yystack
->yyitems
; yyp
< yystack
->yynextFree
; yyp
+= 1)
1923 fprintf (stderr
, "%3lu. ", (unsigned long) (yyp
- yystack
->yyitems
));
1926 fprintf (stderr
, "Res: %d, LR State: %d, posn: %lu, pred: %ld",
1927 yyp
->yystate
.yyresolved
, yyp
->yystate
.yylrState
,
1928 (unsigned long) yyp
->yystate
.yyposn
,
1929 (long) YYINDEX (yyp
->yystate
.yypred
));
1930 if (! yyp
->yystate
.yyresolved
)
1931 fprintf (stderr
, ", firstVal: %ld",
1932 (long) YYINDEX (yyp
->yystate
.yysemantics
.yyfirstVal
));
1936 fprintf (stderr
, "Option. rule: %d, state: %ld, next: %ld",
1937 yyp
->yyoption
.yyrule
,
1938 (long) YYINDEX (yyp
->yyoption
.yystate
),
1939 (long) YYINDEX (yyp
->yyoption
.yynext
));
1941 fprintf (stderr
, "\n");
1943 fprintf (stderr
, "Tops:");
1944 for (yyi
= 0; yyi
< yystack
->yytops
.yysize
; yyi
+= 1)
1945 fprintf (stderr
, "%lu: %ld; ", (unsigned long) yyi
,
1946 (long) YYINDEX (yystack
->yytops
.yystates
[yyi
]));
1947 fprintf (stderr
, "\n");
1952 m4_if(b4_defines_flag
, 0, [],
1953 [@output @output_header_name@
1954 b4_copyright([Skeleton parser
for GLR parsing with Bison
], [2002])
1956 b4_token_defines(b4_tokens
)
1959 m4_ifdef([b4_stype
],
1960 [b4_syncline([b4_stype_line
], [b4_filename
])
1961 typedef union b4_stype yystype
;
1962 /* Line __line__ of glr.c. */
1963 b4_syncline([@oline@
], [@ofile@
])],
1964 [typedef int yystype
;])
1965 # define YYSTYPE yystype
1966 # define YYSTYPE_IS_TRIVIAL 1
1970 [extern YYSTYPE b4_prefix
[]lval
;])
1974 typedef struct yyltype
1981 # define YYLTYPE yyltype
1985 [extern YYLTYPE b4_prefix
[]lloc
;])