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])
33 ## ------------------------ ##
34 ## Pure/impure interfaces. ##
35 ## ------------------------ ##
40 # Accumule in b4_lex_param all the yylex arguments.
41 # Yes, this is quite ugly...
42 m4_define([b4_lex_param
],
43 m4_dquote(b4_pure_if([[[[YYSTYPE
*]], [[yylvalp]]][]dnl
44 b4_location_if([, [[YYLTYPE
*], [yyllocp
]]])])dnl
45 m4_ifdef([b4_lex_param
], [, ]b4_lex_param
)))
50 m4_define([b4_user_formals
],
51 [m4_ifset([b4_parse_param
], [, b4_c_ansi_formals(b4_parse_param
)])])
56 # Arguments passed to yyerror: user args plus yylloc.
57 m4_define([b4_yyerror_args
],
58 [b4_pure_if([b4_location_if([yylocp
, ])])dnl
59 m4_ifset([b4_parse_param
], [b4_c_args(b4_parse_param
), ])])
64 # Same as above, but on the lookahead, hence yyllocp instead of yylocp.
65 m4_define([b4_lyyerror_args
],
66 [b4_pure_if([b4_location_if([yyllocp
, ])])dnl
67 m4_ifset([b4_parse_param
], [b4_c_args(b4_parse_param
), ])])
72 # Arguments needed by yyerror: user args plus yylloc.
73 m4_define([b4_pure_args
],
74 [b4_pure_if([b4_location_if([, yylocp
])])[]b4_user_args
])
79 # Arguments passed to yyerror: user formals plus yyllocp.
80 m4_define([b4_pure_formals
],
81 [b4_pure_if([b4_location_if([, YYLTYPE
*yylocp
])])[]b4_user_formals
])
86 # Same as above, but on the lookahead, hence yyllocp instead of yylocp.
87 m4_define([b4_lpure_args
],
88 [b4_pure_if([b4_location_if([, yyllocp
])])[]b4_user_args
])
93 # Same as above, but on the lookahead, hence yyllocp instead of yylocp.
94 m4_define([b4_lpure_formals
],
95 [b4_pure_if([b4_location_if([YYLTYPE
*yyllocp
])])[]b4_user_formals
])
98 ## ----------------- ##
99 ## Semantic Values. ##
100 ## ----------------- ##
103 # b4_lhs_value([TYPE])
104 # --------------------
105 # Expansion of $<TYPE>$.
106 m4_define([b4_lhs_value
],
107 [(*yyvalp
)[]m4_ifval([$
1], [.$
1])])
110 # b4_rhs_value(RULE-LENGTH, NUM, [TYPE])
111 # --------------------------------------
112 # Expansion of $<TYPE>NUM, where the current rule has RULE-LENGTH
114 m4_define([b4_rhs_value
],
115 [yyvsp@
{m4_eval([$
2 - $
1])@
}.yystate
.yysemantics
.yysval
[]m4_ifval([$
3], [.$
3])])
126 m4_define([b4_lhs_location
],
130 # b4_rhs_location(RULE-LENGTH, NUM)
131 # ---------------------------------
132 # Expansion of @NUM, where the current rule has RULE-LENGTH symbols
134 m4_define([b4_rhs_location
],
135 [yyvsp@
{m4_eval([$
2 - $
1])@
}.yystate
.yyloc
])
138 # We do want M4 expansion after # for CPP macros.
141 @output @output_parser_name@
142 b4_copyright([Skeleton parser
for GLR parsing with Bison
], [2002])
144 /* This is the parser code for GLR (Generalized LR) parser. */
153 m4_if(b4_prefix
[], [yy
], [],
154 [/* If NAME_PREFIX is specified substitute the variables and functions
156 #define yyparse b4_prefix[]parse
157 #define yylex b4_prefix[]lex
158 #define yyerror b4_prefix[]error
159 #define yylval b4_prefix[]lval
160 #define yychar b4_prefix[]char
161 #define yydebug b4_prefix[]debug
162 #define yynerrs b4_prefix[]nerrs
163 b4_location_if([#define yylloc b4_prefix[]lloc])])
165 b4_token_defines(b4_tokens
)
167 /* Copy the first part of user declarations. */
170 /* Enabling traces. */
172 # define YYDEBUG ]b4_debug[
175 /* Enabling verbose error messages. */
176 #ifdef YYERROR_VERBOSE
177 # undef YYERROR_VERBOSE
178 # define YYERROR_VERBOSE 1
180 # define YYERROR_VERBOSE ]b4_error_verbose[
183 #if ! defined (YYSTYPE) && ! defined (YYSTYPE_IS_DECLARED)
184 ]m4_ifdef([b4_stype
],
185 [b4_syncline([b4_stype_line
], [b4_filename
])
186 typedef union m4_bregexp(b4_stype
, [^{], [YYSTYPE
])b4_stype YYSTYPE
;
187 /* Line __line__ of glr.c. */
188 b4_syncline([@oline@
], [@ofile@
])],
189 [typedef int YYSTYPE
;])[
190 # define YYSTYPE_IS_DECLARED 1
191 # define YYSTYPE_IS_TRIVIAL 1
194 #if ! defined (YYLTYPE) && ! defined (YYLTYPE_IS_DECLARED)
195 typedef struct YYLTYPE
202 # define YYLTYPE_IS_DECLARED 1
203 # define YYLTYPE_IS_TRIVIAL 1
206 /* Default (constant) values used for initialization for null
207 right-hand sides. Unlike the standard bison.simple template,
208 here we set the default values of $$ and $@@ to zeroed-out
209 values. Since the default value of these quantities is undefined,
210 this behavior is technically correct. */
211 static YYSTYPE yyval_default
;
212 static YYLTYPE yyloc_default
;
214 /* Copy the second part of user declarations. */
217 ]/* Line __line__ of glr.c. */
218 b4_syncline([@oline@
], [@ofile@
])
220 #if ! defined (__cplusplus)
230 #ifndef __attribute__
231 /* This feature is available in gcc versions 2.5 and later. */
232 # if !defined (__GNUC__) || __GNUC__ < 2 || \
233 (__GNUC__ == 2 && __GNUC_MINOR__ < 5) || __STRICT_ANSI__
234 # define __attribute__(Spec) /* empty */
238 #ifndef ATTRIBUTE_UNUSED
239 # define ATTRIBUTE_UNUSED __attribute__ ((__unused__))
242 /* YYFINAL -- State number of the termination state. */
243 #define YYFINAL ]b4_final_state_number[
244 /* YYLAST -- Last index in YYTABLE. */
245 #define YYLAST ]b4_last[
247 /* YYNTOKENS -- Number of terminals. */
248 #define YYNTOKENS ]b4_tokens_number[
249 /* YYNNTS -- Number of nonterminals. */
250 #define YYNNTS ]b4_nterms_number[
251 /* YYNRULES -- Number of rules. */
252 #define YYNRULES ]b4_rules_number[
253 /* YYNRULES -- Number of states. */
254 #define YYNSTATES ]b4_states_number[
255 /* YYMAXRHS -- Maximum number of symbols on right-hand side of rule. */
256 #define YYMAXRHS ]b4_r2_max[
258 /* YYTRANSLATE(X) -- Bison symbol number corresponding to X. */
259 #define YYUNDEFTOK ]b4_undef_token_number[
260 #define YYMAXUTOK ]b4_user_token_number_max[
262 #define YYTRANSLATE(YYX) \
263 ((YYX <= 0) ? YYEOF : \
264 (unsigned)(YYX) <= YYMAXUTOK ? yytranslate[YYX] : YYUNDEFTOK)
266 /* YYTRANSLATE[YYLEX] -- Bison symbol number corresponding to YYLEX. */
267 static const ]b4_int_type_for([b4_translate
])[ yytranslate
[] =
273 /* YYPRHS[YYN] -- Index of the first RHS symbol of rule number YYN in
275 static const ]b4_int_type_for([b4_prhs
])[ yyprhs
[] =
280 /* YYRHS -- A `-1'-separated list of the rules' RHS. */
281 static const ]b4_int_type_for([b4_rhs
])[ yyrhs
[] =
286 /* YYRLINE[YYN] -- source line where rule number YYN was defined. */
287 static const ]b4_int_type_for([b4_rline
])[ yyrline
[] =
293 #if (YYDEBUG) || YYERROR_VERBOSE
294 /* YYTNME[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM.
295 First, the terminals, then, starting at YYNTOKENS, nonterminals. */
296 static const char *const yytname
[] =
301 #define yytname_size ((int) (sizeof (yytname) / sizeof (yytname[0])))
304 /* YYR1[YYN] -- Symbol number of symbol that rule YYN derives. */
305 static const ]b4_int_type_for([b4_r1
])[ yyr1
[] =
310 /* YYR2[YYN] -- Number of symbols composing right hand side of rule YYN. */
311 static const ]b4_int_type_for([b4_r2
])[ yyr2
[] =
316 /* YYDPREC[RULE-NUM] -- Dynamic precedence of rule #RULE-NUM (0 if none). */
317 static const ]b4_int_type_for([b4_dprec
])[ yydprec
[] =
322 /* YYMERGER[RULE-NUM] -- Index of merging function for rule #RULE-NUM. */
323 static const ]b4_int_type_for([b4_merger
])[ yymerger
[] =
328 /* YYDEFACT[S] -- default rule to reduce with in state S when YYTABLE
329 doesn't specify something else to do. Zero means the default is an
331 static const ]b4_int_type_for([b4_defact
])[ yydefact
[] =
336 /* YYPDEFGOTO[NTERM-NUM]. */
337 static const ]b4_int_type_for([b4_defgoto
])[ yydefgoto
[] =
342 /* YYPACT[STATE-NUM] -- Index in YYTABLE of the portion describing
344 #define YYPACT_NINF ]b4_pact_ninf[
345 static const ]b4_int_type_for([b4_pact
])[ yypact
[] =
350 /* YYPGOTO[NTERM-NUM]. */
351 static const ]b4_int_type_for([b4_pgoto
])[ yypgoto
[] =
356 /* YYTABLE[YYPACT[STATE-NUM]]. What to do in state STATE-NUM. If
357 positive, shift that token. If negative, reduce the rule which
358 number is the opposite. If zero, do what YYDEFACT says.
359 If YYTABLE_NINF, syntax error. */
360 #define YYTABLE_NINF ]b4_table_ninf[
361 static const ]b4_int_type_for([b4_table
])[ yytable
[] =
366 /* YYCONFLP[YYPACT[STATE-NUM]] -- Pointer into YYCONFL of start of
367 list of conflicting reductions corresponding to action entry for
368 state STATE-NUM in yytable. 0 means no conflicts. The list in
369 yyconfl is terminated by a rule number of 0. */
370 static const ]b4_int_type_for([b4_conflict_list_heads
])[ yyconflp
[] =
372 ]b4_conflict_list_heads
[
375 /* YYCONFL[I] -- lists of conflicting rule numbers, each terminated by
376 0, pointed into by YYCONFLP. */
377 ]dnl Do
not use b4_int_type_for here
, since there are places where
378 dnl pointers onto yyconfl are taken
, which type is
"short *".
379 dnl We probably ought to introduce a type
for confl
.
380 [static const short yyconfl
[] =
382 ]b4_conflicting_rules
[
385 static const ]b4_int_type_for([b4_check
])[ yycheck
[] =
390 /* YYSTOS[STATE-NUM] -- The (internal number of the) accessing
391 symbol of state STATE-NUM. */
392 static const ]b4_int_type_for([b4_stos
])[ yystos
[] =
398 /* Prevent warning if -Wmissing-prototypes. */
399 ]b4_c_ansi_function_decl([yyparse
], [int], b4_parse_param
)[
401 /* Error token number */
404 /* YYLLOC_DEFAULT -- Compute the default location (before the actions
407 #define YYRHSLOC(yyRhs,YYK) (yyRhs[YYK].yystate.yyloc)
409 #ifndef YYLLOC_DEFAULT
410 # define YYLLOC_DEFAULT(yyCurrent, yyRhs, YYN) \
411 yyCurrent.first_line = YYRHSLOC(yyRhs,1).first_line; \
412 yyCurrent.first_column = YYRHSLOC(yyRhs,1).first_column; \
413 yyCurrent.last_line = YYRHSLOC(yyRhs,YYN).last_line; \
414 yyCurrent.last_column = YYRHSLOC(yyRhs,YYN).last_column;
417 /* YYLEX -- calling `yylex' with the right arguments. */
418 #define YYLEX ]b4_c_function_call([yylex], [int], b4_lex_param)[
423 #define yynerrs (yystack->yyerrcnt)
425 #define yychar (yystack->yyrawchar)],
433 static const int YYEOF
= 0;
434 static const int YYEMPTY
= -2;
436 typedef enum { yyok
, yyaccept
, yyabort
, yyerr
} YYRESULTTAG
;
439 do { YYRESULTTAG yyflag = YYE; if (yyflag != yyok) return yyflag; } \
444 #if ! defined (YYFPRINTF)
445 # define YYFPRINTF fprintf
448 # define YYDPRINTF(Args) \
454 ]b4_yysymprint_generate([b4_c_ansi_function_def
])[
456 # define YYDSYMPRINT(Args) \
462 # define YYDSYMPRINTF(Title, Token, Value, Location) \
466 YYFPRINTF (stderr, "%s ", Title); \
467 yysymprint (stderr, \
468 Token, Value]b4_location_if([, Location])[); \
469 YYFPRINTF (stderr, "\n"); \
473 /* Nonzero means print parse trace. It is left uninitialized so that
474 multiple parsers can coexist. */
479 /* Avoid empty `if' bodies. */
480 # define YYDPRINTF(Args)
481 # define YYDSYMPRINT(Args)
482 # define YYDSYMPRINTF(Title, Token, Value, Location)
484 #endif /* !YYDEBUG */
486 /* YYINITDEPTH -- initial size of the parser's stacks. */
488 # define YYINITDEPTH ]b4_stack_depth_init[
491 /* YYMAXDEPTH -- maximum size the stacks can grow to (effective only
492 if the built-in stack extension method is used).
494 Do not make this value too large; the results are undefined if
495 SIZE_MAX < YYMAXDEPTH * sizeof (GLRStackItem)
496 evaluated with infinite-precision integer arithmetic. */
503 # define YYMAXDEPTH ]b4_stack_depth_max[
506 /* Minimum number of free items on the stack allowed after an
507 allocation. This is to allow allocation and initialization
508 to be completed by functions that call expandGLRStack before the
509 stack is expanded, thus insuring that all necessary pointers get
510 properly redirected to new data. */
513 #if (! defined (YYSTACKEXPANDABLE) \
514 && (! defined (__cplusplus) \
515 || (]b4_location_if([YYLTYPE_IS_TRIVIAL && ])[YYSTYPE_IS_TRIVIAL)))
516 #define YYSTACKEXPANDABLE 1
518 #define YYSTACKEXPANDABLE 0
521 /** State numbers, as in LALR(1) machine */
522 typedef int yyStateNum
;
524 /** Rule numbers, as in LALR(1) machine */
525 typedef int yyRuleNum
;
527 /** Grammar symbol */
528 typedef short yySymbol
;
530 /** Item references, as in LALR(1) machine */
531 typedef short yyItemNum
;
533 typedef struct yyGLRState yyGLRState
;
534 typedef struct yySemanticOption yySemanticOption
;
535 typedef union yyGLRStackItem yyGLRStackItem
;
536 typedef struct yyGLRStack yyGLRStack
;
537 typedef struct yyGLRStateSet yyGLRStateSet
;
542 yyStateNum yylrState
;
546 yySemanticOption
* yyfirstVal
;
552 struct yyGLRStateSet
{
553 yyGLRState
** yystates
;
554 size_t yysize
, yycapacity
;
557 struct yySemanticOption
{
561 yySemanticOption
* yynext
;
564 union yyGLRStackItem
{
566 yySemanticOption yyoption
;
578 jmp_buf yyexception_buffer
;
579 yyGLRStackItem
* yyitems
;
580 yyGLRStackItem
* yynextFree
;
582 yyGLRState
* yysplitPoint
;
583 yyGLRState
* yylastDeleted
;
584 yyGLRStateSet yytops
;
587 static void yyinitGLRStack (yyGLRStack
* yystack
, size_t yysize
);
588 static void yyexpandGLRStack (yyGLRStack
* yystack
]b4_pure_formals
[);
589 static void yyfreeGLRStack (yyGLRStack
* yystack
);
592 yyFail (yyGLRStack
* yystack
]b4_pure_formals
[, const char* yyformat
, ...)
594 yystack
->yyerrflag
= 1;
595 if (yyformat
!= NULL
)
599 va_start (yyap
, yyformat
);
600 vsprintf (yymsg
, yyformat
, yyap
);
601 yyerror (]b4_yyerror_args
[yymsg
);
603 longjmp (yystack
->yyexception_buffer
, 1);
606 #if YYDEBUG || YYERROR_VERBOSE
607 /** A printable representation of TOKEN. Valid until next call to
609 static inline const char*
610 yytokenName (yySymbol yytoken
)
612 return yytname
[yytoken
];
616 /** Perform user action for rule number YYN, with RHS length YYRHSLEN,
617 * and top stack item YYVSP. YYLVALP points to place to put semantic
618 * value ($$), and yylocp points to place for location information
619 * (@@$). Returns yyok for normal return, yyaccept for YYACCEPT,
620 * yyerr for YYERROR, yyabort for YYABORT. */
622 yyuserAction (yyRuleNum yyn
, int yyrhslen
, yyGLRStackItem
* yyvsp
,
623 YYSTYPE
* yyvalp
, YYLTYPE
* yylocp
, yyGLRStack
* yystack
626 /* Avoid `unused' warnings in there are no $n. */
631 *yyvalp
= yyval_default
;
632 *yylocp
= yyloc_default
;
636 *yyvalp
= yyvsp
[1-yyrhslen
].yystate
.yysemantics
.yysval
;
637 *yylocp
= yyvsp
[1-yyrhslen
].yystate
.yyloc
;
640 # define yyerrok (yystack->yyerrState = 0)
642 # define YYACCEPT return yyaccept
644 # define YYABORT return yyabort
646 # define YYERROR return yyerr
648 # define YYRECOVERING (yystack->yyerrState != 0)
650 # define yyclearin (yychar = *(yystack->yytokenp) = YYEMPTY)
652 # define YYBACKUP(Token, Value) \
654 yyerror (]b4_yyerror_args["syntax error: cannot back up"); \
672 /* Line __line__ of glr.c. */
673 b4_syncline([@oline@
], [@ofile@
])
678 yyuserMerge (int yyn
, YYSTYPE
* yy0
, YYSTYPE
* yy1
)
680 YYSTYPE yyval
= *yy0
;
681 /* `Use' the arguments. */
692 /* Bison grammar-table manipulation. */
694 ]b4_yydestruct_generate([b4_c_ansi_function_def
])[
696 /** Number of symbols composing the right hand side of rule #RULE. */
698 yyrhsLength (yyRuleNum yyrule
)
703 /** Left-hand-side symbol for rule #RULE. */
704 static inline yySymbol
705 yylhsNonterm (yyRuleNum yyrule
)
710 #define yyis_pact_ninf(yystate) \
711 ]m4_if(m4_eval(b4_pact_ninf < b4_pact_min), 1,
713 ((yystate
) == YYPACT_NINF
))[
715 /** True iff LR state STATE has only a default reduction (regardless
718 yyisDefaultedState (yyStateNum yystate
)
720 return yyis_pact_ninf (yypact
[yystate
]);
723 /** The default reduction for STATE, assuming it has one. */
724 static inline yyRuleNum
725 yydefaultAction (yyStateNum yystate
)
727 return yydefact
[yystate
];
730 #define yyis_table_ninf(yytable_value) \
731 ]m4_if(m4_eval(b4_table_ninf < b4_table_min), 1,
733 ((yytable_value
) == YYTABLE_NINF
))[
735 /** Set *YYACTION to the action to take in YYSTATE on seeing YYTOKEN.
737 * R < 0: Reduce on rule -R.
739 * R > 0: Shift to state R.
740 * Set *CONFLICTS to a pointer into yyconfl to 0-terminated list of
741 * conflicting reductions.
744 yygetLRActions (yyStateNum yystate
, int yytoken
,
745 int* yyaction
, const short** yyconflicts
)
747 int yyindex
= yypact
[yystate
] + yytoken
;
748 if (yyindex
< 0 || YYLAST
< yyindex
|| yycheck
[yyindex
] != yytoken
)
750 *yyaction
= -yydefact
[yystate
];
751 *yyconflicts
= yyconfl
;
753 else if (! yyis_table_ninf (yytable
[yyindex
]))
755 *yyaction
= yytable
[yyindex
];
756 *yyconflicts
= yyconfl
+ yyconflp
[yyindex
];
761 *yyconflicts
= yyconfl
+ yyconflp
[yyindex
];
765 static inline yyStateNum
766 yyLRgotoState (yyStateNum yystate
, yySymbol yylhs
)
769 yyr
= yypgoto
[yylhs
- YYNTOKENS
] + yystate
;
770 if (0 <= yyr
&& yyr
<= YYLAST
&& yycheck
[yyr
] == yystate
)
773 return yydefgoto
[yylhs
- YYNTOKENS
];
777 yyisShiftAction (int yyaction
)
783 yyisErrorAction (int yyaction
)
785 return yyaction
== 0;
791 yyaddDeferredAction (yyGLRStack
* yystack
, yyGLRState
* yystate
,
792 yyGLRState
* rhs
, yyRuleNum yyrule
]b4_pure_formals
[)
794 yySemanticOption
* yynewItem
;
795 yynewItem
= &yystack
->yynextFree
->yyoption
;
796 yystack
->yyspaceLeft
-= 1;
797 yystack
->yynextFree
+= 1;
798 yynewItem
->yyisState
= yyfalse
;
799 yynewItem
->yystate
= rhs
;
800 yynewItem
->yyrule
= yyrule
;
801 yynewItem
->yynext
= yystate
->yysemantics
.yyfirstVal
;
802 yystate
->yysemantics
.yyfirstVal
= yynewItem
;
803 if (yystack
->yyspaceLeft
< YYHEADROOM
)
804 yyexpandGLRStack (yystack
]b4_pure_args
[);
809 /** Initialize SET to a singleton set containing an empty stack. */
811 yyinitStateSet (yyGLRStateSet
* yyset
)
814 yyset
->yycapacity
= 16;
815 yyset
->yystates
= (yyGLRState
**) malloc (16 * sizeof (yyset
->yystates
[0]));
816 yyset
->yystates
[0] = NULL
;
819 static void yyfreeStateSet (yyGLRStateSet
* yyset
)
821 free (yyset
->yystates
);
824 /** Initialize STACK to a single empty stack, with total maximum
825 * capacity for all stacks of SIZE. */
827 yyinitGLRStack (yyGLRStack
* yystack
, size_t yysize
)
829 yystack
->yyerrflag
= 0;
830 yystack
->yyerrState
= 0;
832 yystack
->yyspaceLeft
= yysize
;
833 yystack
->yynextFree
= yystack
->yyitems
=
834 (yyGLRStackItem
*) malloc (yysize
* sizeof (yystack
->yynextFree
[0]));
835 yystack
->yysplitPoint
= NULL
;
836 yystack
->yylastDeleted
= NULL
;
837 yyinitStateSet (&yystack
->yytops
);
840 #define YYRELOC(YYFROMITEMS,YYTOITEMS,YYX,YYTYPE) \
841 &((YYTOITEMS) - ((YYFROMITEMS) - (yyGLRStackItem*) (YYX)))->YYTYPE
843 /** If STACK is expandable, extend it. WARNING: Pointers into the
844 stack from outside should be considered invalid after this call.
845 We always expand when there are 1 or fewer items left AFTER an
846 allocation, so that we can avoid having external pointers exist
847 across an allocation. */
849 yyexpandGLRStack (yyGLRStack
* yystack
]b4_pure_formals
[)
851 #if YYSTACKEXPANDABLE
852 yyGLRStack yynewStack
;
853 yyGLRStackItem
* yyp0
, *yyp1
;
854 size_t yysize
, yynewSize
;
856 yysize
= yystack
->yynextFree
- yystack
->yyitems
;
857 if (YYMAXDEPTH
<= yysize
)
858 yyFail (yystack
][]b4_pure_args
[, "parser stack overflow");
859 yynewSize
= 2*yysize
;
860 if (YYMAXDEPTH
< yynewSize
)
861 yynewSize
= YYMAXDEPTH
;
862 yyinitGLRStack (&yynewStack
, yynewSize
);
863 for (yyp0
= yystack
->yyitems
, yyp1
= yynewStack
.yyitems
, yyn
= yysize
;
865 yyn
-= 1, yyp0
+= 1, yyp1
+= 1)
870 yyGLRState
* yys0
= &yyp0
->yystate
;
871 yyGLRState
* yys1
= &yyp1
->yystate
;
872 if (yys0
->yypred
!= NULL
)
874 YYRELOC (yyp0
, yyp1
, yys0
->yypred
, yystate
);
875 if (! yys0
->yyresolved
&& yys0
->yysemantics
.yyfirstVal
!= NULL
)
876 yys1
->yysemantics
.yyfirstVal
=
877 YYRELOC(yyp0
, yyp1
, yys0
->yysemantics
.yyfirstVal
, yyoption
);
881 yySemanticOption
* yyv0
= &yyp0
->yyoption
;
882 yySemanticOption
* yyv1
= &yyp1
->yyoption
;
883 if (yyv0
->yystate
!= NULL
)
884 yyv1
->yystate
= YYRELOC (yyp0
, yyp1
, yyv0
->yystate
, yystate
);
885 if (yyv0
->yynext
!= NULL
)
886 yyv1
->yynext
= YYRELOC (yyp0
, yyp1
, yyv0
->yynext
, yyoption
);
889 if (yystack
->yysplitPoint
!= NULL
)
890 yystack
->yysplitPoint
= YYRELOC (yystack
->yyitems
, yynewStack
.yyitems
,
891 yystack
->yysplitPoint
, yystate
);
893 for (yyn
= 0; yyn
< yystack
->yytops
.yysize
; yyn
+= 1)
894 if (yystack
->yytops
.yystates
[yyn
] != NULL
)
895 yystack
->yytops
.yystates
[yyn
] =
896 YYRELOC (yystack
->yyitems
, yynewStack
.yyitems
,
897 yystack
->yytops
.yystates
[yyn
], yystate
);
898 free (yystack
->yyitems
);
899 yystack
->yyitems
= yynewStack
.yyitems
;
900 yystack
->yynextFree
= yynewStack
.yynextFree
+ yysize
;
901 yystack
->yyspaceLeft
= yynewStack
.yyspaceLeft
- yysize
;
905 yyFail (yystack
][]b4_lpure_args
[, "parser stack overflow");
910 yyfreeGLRStack (yyGLRStack
* yystack
)
912 free (yystack
->yyitems
);
913 yyfreeStateSet (&yystack
->yytops
);
916 /** Assuming that S is a GLRState somewhere on STACK, update the
917 * splitpoint of STACK, if needed, so that it is at least as deep as
920 yyupdateSplit (yyGLRStack
* yystack
, yyGLRState
* yys
)
922 if (yystack
->yysplitPoint
!= NULL
&& yystack
->yysplitPoint
> yys
)
923 yystack
->yysplitPoint
= yys
;
926 /** Invalidate stack #K in STACK. */
928 yymarkStackDeleted (yyGLRStack
* yystack
, int yyk
)
930 if (yystack
->yytops
.yystates
[yyk
] != NULL
)
931 yystack
->yylastDeleted
= yystack
->yytops
.yystates
[yyk
];
932 yystack
->yytops
.yystates
[yyk
] = NULL
;
935 /** Undelete the last stack that was marked as deleted. Can only be
936 done once after a deletion, and only when all other stacks have
939 yyundeleteLastStack (yyGLRStack
* yystack
)
941 if (yystack
->yylastDeleted
== NULL
|| yystack
->yytops
.yysize
!= 0)
943 yystack
->yytops
.yystates
[0] = yystack
->yylastDeleted
;
944 yystack
->yytops
.yysize
= 1;
945 YYDPRINTF ((stderr
, "Restoring last deleted stack as stack #0.\n"));
946 yystack
->yylastDeleted
= NULL
;
950 yyremoveDeletes (yyGLRStack
* yystack
)
954 while (yyj
< yystack
->yytops
.yysize
)
956 if (yystack
->yytops
.yystates
[yyi
] == NULL
)
960 YYDPRINTF ((stderr
, "Removing dead stacks.\n"));
962 yystack
->yytops
.yysize
-= 1;
966 yystack
->yytops
.yystates
[yyj
] = yystack
->yytops
.yystates
[yyi
];
969 YYDPRINTF ((stderr
, "Rename stack %d -> %d.\n", yyi
, yyj
));
977 /** Shift to a new state on stack #K of STACK, corresponding to LR state
978 * LRSTATE, at input position POSN, with (resolved) semantic value SVAL. */
980 yyglrShift (yyGLRStack
* yystack
, int yyk
, yyStateNum yylrState
, size_t yyposn
,
981 YYSTYPE yysval
, YYLTYPE
* yylocp
]b4_user_formals
[)
983 yyGLRStackItem
* yynewItem
;
985 yynewItem
= yystack
->yynextFree
;
986 yystack
->yynextFree
+= 1;
987 yystack
->yyspaceLeft
-= 1;
988 yynewItem
->yystate
.yyisState
= yytrue
;
989 yynewItem
->yystate
.yylrState
= yylrState
;
990 yynewItem
->yystate
.yyposn
= yyposn
;
991 yynewItem
->yystate
.yyresolved
= yytrue
;
992 yynewItem
->yystate
.yypred
= yystack
->yytops
.yystates
[yyk
];
993 yystack
->yytops
.yystates
[yyk
] = &yynewItem
->yystate
;
994 yynewItem
->yystate
.yysemantics
.yysval
= yysval
;
995 yynewItem
->yystate
.yyloc
= *yylocp
;
996 if (yystack
->yyspaceLeft
< YYHEADROOM
)
997 yyexpandGLRStack (yystack
]b4_pure_args
[);
1000 /** Shift to a new state on stack #K of STACK, to a new state
1001 * corresponding to LR state LRSTATE, at input position POSN, with
1002 * the (unresolved) semantic value of RHS under the action for RULE. */
1004 yyglrShiftDefer (yyGLRStack
* yystack
, int yyk
, yyStateNum yylrState
,
1005 size_t yyposn
, yyGLRState
* rhs
, yyRuleNum yyrule
]b4_pure_formals
[)
1007 yyGLRStackItem
* yynewItem
;
1009 yynewItem
= yystack
->yynextFree
;
1010 yynewItem
->yystate
.yyisState
= yytrue
;
1011 yynewItem
->yystate
.yylrState
= yylrState
;
1012 yynewItem
->yystate
.yyposn
= yyposn
;
1013 yynewItem
->yystate
.yyresolved
= yyfalse
;
1014 yynewItem
->yystate
.yypred
= yystack
->yytops
.yystates
[yyk
];
1015 yynewItem
->yystate
.yysemantics
.yyfirstVal
= NULL
;
1016 yystack
->yytops
.yystates
[yyk
] = &yynewItem
->yystate
;
1017 yystack
->yynextFree
+= 1;
1018 yystack
->yyspaceLeft
-= 1;
1019 yyaddDeferredAction (yystack
, &yynewItem
->yystate
, rhs
, yyrule
]b4_pure_args
[);
1022 /** Pop the symbols consumed by reduction #RULE from the top of stack
1023 * #K of STACK, and perform the appropriate semantic action on their
1024 * semantic values. Assumes that all ambiguities in semantic values
1025 * have been previously resolved. Set *VALP to the resulting value,
1026 * and *LOCP to the computed location (if any). Return value is as
1027 * for userAction. */
1028 static inline YYRESULTTAG
1029 yydoAction (yyGLRStack
* yystack
, int yyk
, yyRuleNum yyrule
,
1030 YYSTYPE
* yyvalp
, YYLTYPE
* yylocp
]b4_user_formals
[)
1032 int yynrhs
= yyrhsLength (yyrule
);
1034 if (yystack
->yysplitPoint
== NULL
)
1036 /* Standard special case: single stack. */
1037 yyGLRStackItem
* rhs
= (yyGLRStackItem
*) yystack
->yytops
.yystates
[yyk
];
1040 yystack
->yynextFree
-= yynrhs
;
1041 yystack
->yyspaceLeft
+= yynrhs
;
1042 yystack
->yytops
.yystates
[0] = & yystack
->yynextFree
[-1].yystate
;
1045 *yyvalp
= yyval_default
;
1046 *yylocp
= yyloc_default
;
1050 *yyvalp
= rhs
[1-yynrhs
].yystate
.yysemantics
.yysval
;
1051 *yylocp
= rhs
[1-yynrhs
].yystate
.yyloc
;
1053 return yyuserAction (yyrule
, yynrhs
, rhs
,
1054 yyvalp
, yylocp
, yystack
]b4_user_args
[);
1060 yyGLRStackItem yyrhsVals
[YYMAXRHS
];
1061 for (yyi
= yynrhs
-1, yys
= yystack
->yytops
.yystates
[yyk
]; 0 <= yyi
;
1062 yyi
-= 1, yys
= yys
->yypred
)
1066 yyrhsVals
[yyi
].yystate
.yyresolved
= yytrue
;
1067 yyrhsVals
[yyi
].yystate
.yysemantics
.yysval
= yys
->yysemantics
.yysval
;
1068 yyrhsVals
[yyi
].yystate
.yyloc
= yys
->yyloc
;
1070 yyupdateSplit (yystack
, yys
);
1071 yystack
->yytops
.yystates
[yyk
] = yys
;
1074 *yyvalp
= yyval_default
;
1075 *yylocp
= yyloc_default
;
1079 *yyvalp
= yyrhsVals
[0].yystate
.yysemantics
.yysval
;
1080 *yylocp
= yyrhsVals
[0].yystate
.yyloc
;
1082 return yyuserAction (yyrule
, yynrhs
, yyrhsVals
+ (yynrhs
-1),
1083 yyvalp
, yylocp
, yystack
]b4_user_args
[);
1088 # define YY_REDUCE_PRINT(K, Rule)
1090 # define YY_REDUCE_PRINT(K, Rule) \
1093 yy_reduce_print (K, Rule); \
1096 /*----------------------------------------------------------.
1097 | Report that the RULE is going to be reduced on stack #K. |
1098 `----------------------------------------------------------*/
1101 yy_reduce_print (size_t yyk
, yyRuleNum yyrule
)
1104 unsigned int yylineno
= yyrline
[yyrule
];
1105 YYFPRINTF (stderr
, "Reducing stack %d by rule %d (line %u), ",
1106 yyk
, yyrule
- 1, yylineno
);
1107 /* Print the symbols being reduced, and their result. */
1108 for (yyi
= yyprhs
[yyrule
]; 0 <= yyrhs
[yyi
]; yyi
++)
1109 YYFPRINTF (stderr
, "%s ", yytokenName (yyrhs
[yyi
]));
1110 YYFPRINTF (stderr
, "-> %s\n", yytokenName (yyr1
[yyrule
]));
1114 /** Pop items off stack #K of STACK according to grammar rule RULE,
1115 * and push back on the resulting nonterminal symbol. Perform the
1116 * semantic action associated with RULE and store its value with the
1117 * newly pushed state, if FORCEEVAL or if STACK is currently
1118 * unambiguous. Otherwise, store the deferred semantic action with
1119 * the new state. If the new state would have an identical input
1120 * position, LR state, and predecessor to an existing state on the stack,
1121 * it is identified with that existing state, eliminating stack #K from
1122 * the STACK. In this case, the (necessarily deferred) semantic value is
1123 * added to the options for the existing state's semantic value.
1125 static inline YYRESULTTAG
1126 yyglrReduce (yyGLRStack
* yystack
, size_t yyk
, yyRuleNum yyrule
,
1127 bool yyforceEval
]b4_pure_formals
[)
1129 size_t yyposn
= yystack
->yytops
.yystates
[yyk
]->yyposn
;
1131 if (yyforceEval
|| yystack
->yysplitPoint
== NULL
)
1136 YY_REDUCE_PRINT (yyk
, yyrule
);
1137 YYCHK (yydoAction (yystack
, yyk
, yyrule
, &yysval
, &yyloc
]b4_user_args
[));
1138 yyglrShift (yystack
, yyk
,
1139 yyLRgotoState (yystack
->yytops
.yystates
[yyk
]->yylrState
,
1140 yylhsNonterm (yyrule
)),
1141 yyposn
, yysval
, &yyloc
]b4_user_args
[);
1147 yyGLRState
* yys
, *yys0
= yystack
->yytops
.yystates
[yyk
];
1148 yyStateNum yynewLRState
;
1150 for (yys
= yystack
->yytops
.yystates
[yyk
], yyn
= yyrhsLength (yyrule
);
1157 yyupdateSplit (yystack
, yys
);
1158 yynewLRState
= yyLRgotoState (yys
->yylrState
, yylhsNonterm (yyrule
));
1160 "Reduced stack %d by rule #%d; action deferred. "
1161 "Now in state %d.\n",
1162 yyk
, yyrule
-1, yynewLRState
));
1163 for (yyi
= 0; yyi
< yystack
->yytops
.yysize
; yyi
+= 1)
1164 if (yyi
!= yyk
&& yystack
->yytops
.yystates
[yyi
] != NULL
)
1166 yyGLRState
* yyp
, *yysplit
= yystack
->yysplitPoint
;
1167 yyp
= yystack
->yytops
.yystates
[yyi
];
1168 while (yyp
!= yys
&& yyp
!= yysplit
&& yyp
->yyposn
>= yyposn
)
1170 if (yyp
->yylrState
== yynewLRState
&& yyp
->yypred
== yys
)
1172 yyaddDeferredAction (yystack
, yyp
, yys0
, yyrule
]b4_pure_args
[);
1173 yymarkStackDeleted (yystack
, yyk
);
1174 YYDPRINTF ((stderr
, "Merging stack %d into stack %d.\n",
1181 yystack
->yytops
.yystates
[yyk
] = yys
;
1182 yyglrShiftDefer (yystack
, yyk
, yynewLRState
, yyposn
, yys0
, yyrule
]b4_pure_args
[);
1188 yysplitStack (yyGLRStack
* yystack
, int yyk
)
1190 if (yystack
->yysplitPoint
== NULL
)
1194 yystack
->yysplitPoint
= yystack
->yytops
.yystates
[yyk
];
1196 if (yystack
->yytops
.yysize
>= yystack
->yytops
.yycapacity
)
1198 yystack
->yytops
.yycapacity
*= 2;
1199 yystack
->yytops
.yystates
=
1200 (yyGLRState
**) realloc (yystack
->yytops
.yystates
,
1201 yystack
->yytops
.yycapacity
1202 * sizeof (yyGLRState
*));
1204 yystack
->yytops
.yystates
[yystack
->yytops
.yysize
]
1205 = yystack
->yytops
.yystates
[yyk
];
1206 yystack
->yytops
.yysize
+= 1;
1207 return yystack
->yytops
.yysize
-1;
1210 /** True iff Y0 and Y1 represent identical options at the top level.
1211 * That is, they represent the same rule applied to RHS symbols
1212 * that produce the same terminal symbols. */
1214 yyidenticalOptions (yySemanticOption
* yyy0
, yySemanticOption
* yyy1
)
1216 if (yyy0
->yyrule
== yyy1
->yyrule
)
1218 yyGLRState
*yys0
, *yys1
;
1220 for (yys0
= yyy0
->yystate
, yys1
= yyy1
->yystate
,
1221 yyn
= yyrhsLength (yyy0
->yyrule
);
1223 yys0
= yys0
->yypred
, yys1
= yys1
->yypred
, yyn
-= 1)
1224 if (yys0
->yyposn
!= yys1
->yyposn
)
1232 /** Assuming identicalOptions (Y0,Y1), (destructively) merge the
1233 * alternative semantic values for the RHS-symbols of Y1 into the
1234 * corresponding semantic value sets of the symbols of Y0. */
1236 yymergeOptionSets (yySemanticOption
* yyy0
, yySemanticOption
* yyy1
)
1238 yyGLRState
*yys0
, *yys1
;
1240 for (yys0
= yyy0
->yystate
, yys1
= yyy1
->yystate
,
1241 yyn
= yyrhsLength (yyy0
->yyrule
);
1243 yys0
= yys0
->yypred
, yys1
= yys1
->yypred
, yyn
-= 1)
1246 else if (! yys0
->yyresolved
&& ! yys1
->yyresolved
)
1248 yySemanticOption
* yyz
;
1249 for (yyz
= yys0
->yysemantics
.yyfirstVal
; yyz
->yynext
!= NULL
;
1252 yyz
->yynext
= yys1
->yysemantics
.yyfirstVal
;
1256 /** Y0 and Y1 represent two possible actions to take in a given
1257 * parsing state; return 0 if no combination is possible,
1258 * 1 if user-mergeable, 2 if Y0 is preferred, 3 if Y1 is preferred. */
1260 yypreference (yySemanticOption
* y0
, yySemanticOption
* y1
)
1262 yyRuleNum r0
= y0
->yyrule
, r1
= y1
->yyrule
;
1263 int p0
= yydprec
[r0
], p1
= yydprec
[r1
];
1267 if (yymerger
[r0
] == 0 || yymerger
[r0
] != yymerger
[r1
])
1272 if (p0
== 0 || p1
== 0)
1281 static YYRESULTTAG
yyresolveValue (yySemanticOption
* yyoptionList
,
1282 yyGLRStack
* yystack
, YYSTYPE
* yyvalp
,
1283 YYLTYPE
* yylocp
]b4_user_formals
[);
1286 yyresolveStates (yyGLRState
* yys
, int yyn
, yyGLRStack
* yystack
]b4_user_formals
[)
1293 yyflag
= yyresolveStates (yys
->yypred
, yyn
-1, yystack
]b4_user_args
[);
1296 if (! yys
->yyresolved
)
1298 yyflag
= yyresolveValue (yys
->yysemantics
.yyfirstVal
, yystack
,
1299 &yys
->yysemantics
.yysval
, &yys
->yyloc
1303 yys
->yyresolved
= yytrue
;
1310 yyresolveAction (yySemanticOption
* yyopt
, yyGLRStack
* yystack
,
1311 YYSTYPE
* yyvalp
, YYLTYPE
* yylocp
]b4_user_formals
[)
1313 yyGLRStackItem yyrhsVals
[YYMAXRHS
];
1317 yynrhs
= yyrhsLength (yyopt
->yyrule
);
1318 YYCHK (yyresolveStates (yyopt
->yystate
, yynrhs
, yystack
]b4_user_args
[));
1319 for (yyi
= yynrhs
-1, yys
= yyopt
->yystate
; 0 <= yyi
;
1320 yyi
-= 1, yys
= yys
->yypred
)
1324 yyrhsVals
[yyi
].yystate
.yyresolved
= yytrue
;
1325 yyrhsVals
[yyi
].yystate
.yysemantics
.yysval
= yys
->yysemantics
.yysval
;
1326 yyrhsVals
[yyi
].yystate
.yyloc
= yys
->yyloc
;
1328 return yyuserAction (yyopt
->yyrule
, yynrhs
, yyrhsVals
+ (yynrhs
-1),
1329 yyvalp
, yylocp
, yystack
]b4_user_args
[);
1334 yyreportTree (yySemanticOption
* yyx
, int yyindent
)
1336 int yynrhs
= yyrhsLength (yyx
->yyrule
);
1339 yyGLRState
* yystates
[YYMAXRHS
];
1340 yyGLRState yyleftmost_state
;
1342 for (yyi
= yynrhs
, yys
= yyx
->yystate
; 0 < yyi
; yyi
-= 1, yys
= yys
->yypred
)
1343 yystates
[yyi
] = yys
;
1346 yyleftmost_state
.yyposn
= 0;
1347 yystates
[0] = &yyleftmost_state
;
1352 if (yyx
->yystate
->yyposn
< yys
->yyposn
+ 1)
1353 YYFPRINTF (stderr
, "%*s%s -> <Rule %d, empty>\n",
1354 yyindent
, "", yytokenName (yylhsNonterm (yyx
->yyrule
)),
1357 YYFPRINTF (stderr
, "%*s%s -> <Rule %d, tokens %d .. %d>\n",
1358 yyindent
, "", yytokenName (yylhsNonterm (yyx
->yyrule
)),
1359 yyx
->yyrule
, yys
->yyposn
+1, yyx
->yystate
->yyposn
);
1360 for (yyi
= 1; yyi
<= yynrhs
; yyi
+= 1)
1362 if (yystates
[yyi
]->yyresolved
)
1364 if (yystates
[yyi
-1]->yyposn
+1 > yystates
[yyi
]->yyposn
)
1365 YYFPRINTF (stderr
, "%*s%s <empty>\n", yyindent
+2, "",
1366 yytokenName (yyrhs
[yyprhs
[yyx
->yyrule
]+yyi
-1]));
1368 YYFPRINTF (stderr
, "%*s%s <tokens %d .. %d>\n", yyindent
+2, "",
1369 yytokenName (yyrhs
[yyprhs
[yyx
->yyrule
]+yyi
-1]),
1370 yystates
[yyi
-1]->yyposn
+1, yystates
[yyi
]->yyposn
);
1373 yyreportTree (yystates
[yyi
]->yysemantics
.yyfirstVal
, yyindent
+2);
1379 yyreportAmbiguity (yySemanticOption
* yyx0
, yySemanticOption
* yyx1
,
1380 yyGLRStack
* yystack
]b4_pure_formals
[)
1382 /* `Unused' warnings. */
1387 YYFPRINTF (stderr
, "Ambiguity detected.\n");
1388 YYFPRINTF (stderr
, "Option 1,\n");
1389 yyreportTree (yyx0
, 2);
1390 YYFPRINTF (stderr
, "\nOption 2,\n");
1391 yyreportTree (yyx1
, 2);
1392 YYFPRINTF (stderr
, "\n");
1394 yyFail (yystack
][]b4_pure_args
[, "ambiguity detected");
1398 /** Resolve the ambiguity represented by OPTIONLIST, perform the indicated
1399 * actions, and return the result. */
1401 yyresolveValue (yySemanticOption
* yyoptionList
, yyGLRStack
* yystack
,
1402 YYSTYPE
* yyvalp
, YYLTYPE
* yylocp
]b4_user_formals
[)
1404 yySemanticOption
* yybest
;
1405 yySemanticOption
* yyp
;
1408 yybest
= yyoptionList
;
1410 for (yyp
= yyoptionList
->yynext
; yyp
!= NULL
; yyp
= yyp
->yynext
)
1412 if (yyidenticalOptions (yybest
, yyp
))
1413 yymergeOptionSets (yybest
, yyp
);
1415 switch (yypreference (yybest
, yyp
))
1418 yyreportAmbiguity (yybest
, yyp
, yystack
]b4_pure_args
[);
1434 int yyprec
= yydprec
[yybest
->yyrule
];
1435 YYCHK (yyresolveAction (yybest
, yystack
, yyvalp
, yylocp
]b4_user_args
[));
1436 for (yyp
= yybest
->yynext
; yyp
!= NULL
; yyp
= yyp
->yynext
)
1438 if (yyprec
== yydprec
[yyp
->yyrule
])
1442 YYCHK (yyresolveAction (yyp
, yystack
, &yyval1
, &yydummy
]b4_user_args
[));
1443 *yyvalp
= yyuserMerge (yymerger
[yyp
->yyrule
], yyvalp
, &yyval1
);
1449 return yyresolveAction (yybest
, yystack
, yyvalp
, yylocp
]b4_user_args
[);
1453 yyresolveStack (yyGLRStack
* yystack
]b4_user_formals
[)
1455 if (yystack
->yysplitPoint
!= NULL
)
1460 for (yyn
= 0, yys
= yystack
->yytops
.yystates
[0];
1461 yys
!= yystack
->yysplitPoint
;
1462 yys
= yys
->yypred
, yyn
+= 1)
1464 YYCHK (yyresolveStates (yystack
->yytops
.yystates
[0], yyn
, yystack
1471 yycompressStack (yyGLRStack
* yystack
)
1473 yyGLRState
* yyp
, *yyq
, *yyr
;
1475 if (yystack
->yytops
.yysize
!= 1 || yystack
->yysplitPoint
== NULL
)
1478 for (yyp
= yystack
->yytops
.yystates
[0], yyq
= yyp
->yypred
, yyr
= NULL
;
1479 yyp
!= yystack
->yysplitPoint
;
1480 yyr
= yyp
, yyp
= yyq
, yyq
= yyp
->yypred
)
1483 yystack
->yyspaceLeft
+= yystack
->yynextFree
- yystack
->yyitems
;
1484 yystack
->yynextFree
= ((yyGLRStackItem
*) yystack
->yysplitPoint
) + 1;
1485 yystack
->yyspaceLeft
-= yystack
->yynextFree
- yystack
->yyitems
;
1486 yystack
->yysplitPoint
= NULL
;
1487 yystack
->yylastDeleted
= NULL
;
1491 yystack
->yynextFree
->yystate
= *yyr
;
1493 yystack
->yynextFree
->yystate
.yypred
= & yystack
->yynextFree
[-1].yystate
;
1494 yystack
->yytops
.yystates
[0] = &yystack
->yynextFree
->yystate
;
1495 yystack
->yynextFree
+= 1;
1496 yystack
->yyspaceLeft
-= 1;
1501 yyprocessOneStack (yyGLRStack
* yystack
, int yyk
,
1502 size_t yyposn
, YYSTYPE
* yylvalp
, YYLTYPE
* yyllocp
1506 const short* yyconflicts
;
1508 yySymbol
* const yytokenp
= yystack
->yytokenp
;
1510 while (yystack
->yytops
.yystates
[yyk
] != NULL
)
1512 yyStateNum yystate
= yystack
->yytops
.yystates
[yyk
]->yylrState
;
1513 YYDPRINTF ((stderr
, "Stack %d Entering state %d\n", yyk
, yystate
));
1515 if (yystate
== YYFINAL
)
1517 if (yyisDefaultedState (yystate
))
1519 yyrule
= yydefaultAction (yystate
);
1522 YYDPRINTF ((stderr
, "Stack %d dies.\n", yyk
));
1523 yymarkStackDeleted (yystack
, yyk
);
1526 YYCHK (yyglrReduce (yystack
, yyk
, yyrule
, yyfalse
]b4_lpure_args
[));
1530 if (*yytokenp
== YYEMPTY
)
1532 YYDPRINTF ((stderr
, "Reading a token: "));
1534 *yytokenp
= YYTRANSLATE (yychar
);
1535 YYDSYMPRINTF ("Next token is", *yytokenp
, yylvalp
, yyllocp
);
1537 yygetLRActions (yystate
, *yytokenp
, &yyaction
, &yyconflicts
);
1539 while (*yyconflicts
!= 0)
1541 int yynewStack
= yysplitStack (yystack
, yyk
);
1542 YYDPRINTF ((stderr
, "Splitting off stack %d from %d.\n",
1544 YYCHK (yyglrReduce (yystack
, yynewStack
,
1545 *yyconflicts
, yyfalse
]b4_lpure_args
[));
1546 YYCHK (yyprocessOneStack (yystack
, yynewStack
, yyposn
,
1547 yylvalp
, yyllocp
]b4_user_args
[));
1551 if (yyisShiftAction (yyaction
))
1553 YYDPRINTF ((stderr
, "Shifting token %s on stack %d, ",
1554 yytokenName (*yytokenp
), yyk
));
1555 yyglrShift (yystack
, yyk
, yyaction
, yyposn
+1,
1556 *yylvalp
, yyllocp
]b4_user_args
[);
1557 YYDPRINTF ((stderr
, "which is now in state #%d\n",
1558 yystack
->yytops
.yystates
[yyk
]->yylrState
));
1561 else if (yyisErrorAction (yyaction
))
1563 YYDPRINTF ((stderr
, "Stack %d dies.\n", yyk
));
1564 yymarkStackDeleted (yystack
, yyk
);
1568 YYCHK (yyglrReduce (yystack
, yyk
, -yyaction
, yyfalse
]b4_lpure_args
[));
1575 yyreportSyntaxError (yyGLRStack
* yystack
,
1576 YYSTYPE
* yylvalp
, YYLTYPE
* yyllocp
]b4_user_formals
[)
1578 /* `Unused' warnings. */
1582 if (yystack
->yyerrState
== 0)
1585 yySymbol
* const yytokenp
= yystack
->yytokenp
;
1586 int yyn
, yyx
, yycount
;
1588 const char* yyprefix
;
1591 yyn
= yypact
[yystack
->yytops
.yystates
[0]->yylrState
];
1592 if (YYPACT_NINF
< yyn
&& yyn
< YYLAST
)
1595 /* Start YYX at -YYN if negative to avoid negative indexes in
1597 yysize
= sizeof ("syntax error, unexpected ")
1598 + strlen (yytokenName (*yytokenp
));
1599 yyprefix
= ", expecting ";
1600 for (yyx
= yyn
< 0 ? -yyn
: 0; yyx
< yytname_size
&& yycount
<= 5;
1602 if (yycheck
[yyx
+ yyn
] == yyx
&& yyx
!= YYTERROR
)
1603 yysize
+= strlen (yytokenName (yyx
)) + strlen (yyprefix
),
1604 yycount
+= 1, yyprefix
= " or ";
1605 yymsg
= yyp
= (char*) malloc (yysize
);
1606 sprintf (yyp
, "syntax error, unexpected %s",
1607 yytokenName (*yytokenp
));
1608 yyp
+= strlen (yyp
);
1611 yyprefix
= ", expecting ";
1612 for (yyx
= yyn
< 0 ? -yyn
: 0; yyx
< yytname_size
; yyx
+= 1)
1613 if (yycheck
[yyx
+ yyn
] == yyx
&& yyx
!= YYTERROR
)
1615 sprintf (yyp
, "%s%s", yyprefix
, yytokenName (yyx
));
1616 yyp
+= strlen (yyp
);
1620 yyerror (]b4_lyyerror_args
[yymsg
);
1625 yyerror (]b4_lyyerror_args
["syntax error");
1630 /* Recover from a syntax error on YYSTACK, assuming that YYTOKENP,
1631 YYLVALP, and YYLLOCP point to the syntactic category, semantic
1632 value, and location of the lookahead. */
1634 yyrecoverSyntaxError (yyGLRStack
* yystack
,
1635 YYSTYPE
* yylvalp
, YYLTYPE
* yyllocp
]b4_user_formals
[)
1637 yySymbol
* const yytokenp
= yystack
->yytokenp
;
1641 if (yystack
->yyerrState
== 0)
1642 yystack
->yyerrState
= 3;
1643 else if (yystack
->yyerrState
== 3)
1644 /* We just shifted the error token and (perhaps) took some
1645 reductions. Skip tokens until we can proceed. */
1648 if (*yytokenp
== YYEOF
)
1650 /* Now pop stack until we find a state that shifts the
1652 while (yystack
->yytops
.yystates
[0] != NULL
)
1654 yyGLRState
*yys
= yystack
->yytops
.yystates
[0];
1655 YYDSYMPRINTF ("Error: popping",
1656 yystos
[yys
->yylrState
],
1657 &yys
->yysemantics
.yysval
, &yys
->yyloc
);
1658 yydestruct (yystos
[yys
->yylrState
],
1659 &yys
->yysemantics
.yysval
]b4_location_if([, &yys
->yyloc
])[);
1660 yystack
->yytops
.yystates
[0] = yys
->yypred
;
1661 yystack
->yynextFree
-= 1;
1662 yystack
->yyspaceLeft
+= 1;
1664 yyFail (yystack
][]b4_lpure_args
[, NULL
);
1666 if (*yytokenp
!= YYEMPTY
)
1668 YYDSYMPRINTF ("Error: discarding", *yytokenp
, yylvalp
, yyllocp
);
1669 yydestruct (*yytokenp
, yylvalp
]b4_location_if([, yyllocp
])[);
1671 YYDPRINTF ((stderr
, "Reading a token: "));
1673 *yytokenp
= YYTRANSLATE (yychar
);
1674 YYDSYMPRINTF ("Next token is", *yytokenp
, yylvalp
, yyllocp
);
1675 yyj
= yypact
[yystack
->yytops
.yystates
[0]->yylrState
];
1676 if (yyis_pact_ninf (yyj
))
1677 /* Something's not right; we shouldn't be here. */
1678 yyFail (yystack
][]b4_lpure_args
[, NULL
);
1680 if (yyj
< 0 || YYLAST
< yyj
|| yycheck
[yyj
] != *yytokenp
)
1682 if (yydefact
[yystack
->yytops
.yystates
[0]->yylrState
] != 0)
1685 else if (yytable
[yyj
] != 0 && ! yyis_table_ninf (yytable
[yyj
]))
1689 /* Reduce to one stack. */
1690 for (yyk
= 0; yyk
< yystack
->yytops
.yysize
; yyk
+= 1)
1691 if (yystack
->yytops
.yystates
[yyk
] != NULL
)
1693 if (yyk
>= yystack
->yytops
.yysize
)
1694 yyFail (yystack
][]b4_lpure_args
[, NULL
);
1695 for (yyk
+= 1; yyk
< yystack
->yytops
.yysize
; yyk
+= 1)
1696 yymarkStackDeleted (yystack
, yyk
);
1697 yyremoveDeletes (yystack
);
1698 yycompressStack (yystack
);
1700 /* Now pop stack until we find a state that shifts the error token. */
1701 while (yystack
->yytops
.yystates
[0] != NULL
)
1703 yyGLRState
*yys
= yystack
->yytops
.yystates
[0];
1704 yyj
= yypact
[yys
->yylrState
];
1705 if (! yyis_pact_ninf (yyj
))
1708 if (0 <= yyj
&& yyj
<= YYLAST
&& yycheck
[yyj
] == YYTERROR
1709 && yyisShiftAction (yytable
[yyj
]))
1711 YYDPRINTF ((stderr
, "Shifting error token, "));
1712 yyglrShift (yystack
, 0, yytable
[yyj
],
1713 yys
->yyposn
, *yylvalp
, yyllocp
]b4_user_args
[);
1717 YYDSYMPRINTF ("Error: popping",
1718 yystos
[yys
->yylrState
],
1719 &yys
->yysemantics
.yysval
, &yys
->yyloc
);
1720 yydestruct (yystos
[yys
->yylrState
],
1721 &yys
->yysemantics
.yysval
]b4_location_if([, &yys
->yyloc
])[);
1722 yystack
->yytops
.yystates
[0] = yys
->yypred
;
1723 yystack
->yynextFree
-= 1;
1724 yystack
->yyspaceLeft
+= 1;
1726 if (yystack
->yytops
.yystates
[0] == NULL
)
1727 yyFail (yystack
][]b4_lpure_args
[, NULL
);
1730 #define YYCHK1(YYE) \
1736 yystack.yyerrflag = 1; \
1739 yystack.yyerrflag = 0; \
1742 goto yyuser_error; \
1751 ]b4_c_ansi_function_def([yyparse
], [int], b4_parse_param
)[
1761 #define yychar (yystack.yyrawchar)
1764 YYSTYPE
* const yylvalp
= &yylval
;
1765 YYLTYPE
* const yyllocp
= &yylloc
;
1767 yyinitGLRStack (&yystack
, YYINITDEPTH
);
1768 yystack
.yytokenp
= &yytoken
;
1770 YYDPRINTF ((stderr
, "Starting parse\n"));
1772 if (setjmp (yystack
.yyexception_buffer
) != 0)
1775 yyglrShift (&yystack
, 0, 0, 0, yyval_default
, &yyloc_default
]b4_user_args
[);
1781 /* For efficiency, we have two loops, the first of which is
1782 specialized to deterministic operation (single stack, no
1783 potential ambiguity). */
1789 const short* yyconflicts
;
1791 yyStateNum yystate
= yystack
.yytops
.yystates
[0]->yylrState
;
1792 YYDPRINTF ((stderr
, "Entering state %d\n", yystate
));
1793 if (yystate
== YYFINAL
)
1795 if (yyisDefaultedState (yystate
))
1797 yyrule
= yydefaultAction (yystate
);
1800 yyreportSyntaxError (&yystack
, yylvalp
, yyllocp
]b4_user_args
[);
1803 YYCHK1 (yyglrReduce (&yystack
, 0, yyrule
, yytrue
]b4_lpure_args
[));
1807 if (yytoken
== YYEMPTY
)
1809 YYDPRINTF ((stderr
, "Reading a token: "));
1811 yytoken
= YYTRANSLATE (yychar
);
1812 YYDSYMPRINTF ("Next token is", yytoken
, yylvalp
, yyllocp
);
1814 yygetLRActions (yystate
, yytoken
, &yyaction
, &yyconflicts
);
1815 if (*yyconflicts
!= 0)
1817 if (yyisShiftAction (yyaction
))
1819 YYDPRINTF ((stderr
, "Shifting token %s, ",
1820 yytokenName (yytoken
)));
1821 if (yytoken
!= YYEOF
)
1824 yyglrShift (&yystack
, 0, yyaction
, yyposn
,
1825 yylval
, yyllocp
]b4_user_args
[);
1826 if (0 < yystack
.yyerrState
)
1827 yystack
.yyerrState
-= 1;
1829 else if (yyisErrorAction (yyaction
))
1831 yyreportSyntaxError (&yystack
, yylvalp
, yyllocp
]b4_user_args
[);
1835 YYCHK1 (yyglrReduce (&yystack
, 0, -yyaction
, yytrue
]b4_lpure_args
[));
1842 int yyn
= yystack
.yytops
.yysize
;
1843 for (yys
= 0; yys
< yyn
; yys
+= 1)
1844 YYCHK1 (yyprocessOneStack (&yystack
, yys
, yyposn
,
1845 yylvalp
, yyllocp
]b4_user_args
[));
1848 yyremoveDeletes (&yystack
);
1849 if (yystack
.yytops
.yysize
== 0)
1851 yyundeleteLastStack (&yystack
);
1852 if (yystack
.yytops
.yysize
== 0)
1853 yyFail (&yystack
][]b4_lpure_args
[, "syntax error");
1854 YYCHK1 (yyresolveStack (&yystack
]b4_user_args
[));
1855 YYDPRINTF ((stderr
, "Returning to deterministic operation.\n"));
1856 yyreportSyntaxError (&yystack
, yylvalp
, yyllocp
]b4_user_args
[);
1859 else if (yystack
.yytops
.yysize
== 1)
1861 YYCHK1 (yyresolveStack (&yystack
]b4_user_args
[));
1862 YYDPRINTF ((stderr
, "Returning to deterministic operation.\n"));
1863 yycompressStack (&yystack
);
1869 yyrecoverSyntaxError (&yystack
, yylvalp
, yyllocp
]b4_user_args
[);
1870 yyposn
= yystack
.yytops
.yystates
[0]->yyposn
;
1875 yyfreeGLRStack (&yystack
);
1876 return yystack
.yyerrflag
;
1879 /* DEBUGGING ONLY */
1880 static void yypstack (yyGLRStack
* yystack
, int yyk
) ATTRIBUTE_UNUSED
;
1881 static void yypdumpstack (yyGLRStack
* yystack
) ATTRIBUTE_UNUSED
;
1884 yy_yypstack (yyGLRState
* yys
)
1888 yy_yypstack (yys
->yypred
);
1889 fprintf (stderr
, " -> ");
1891 fprintf (stderr
, "%d@@%lu", yys
->yylrState
, (unsigned long) yys
->yyposn
);
1895 yypstates (yyGLRState
* yyst
)
1898 fprintf (stderr
, "<null>");
1901 fprintf (stderr
, "\n");
1905 yypstack (yyGLRStack
* yystack
, int yyk
)
1907 yypstates (yystack
->yytops
.yystates
[yyk
]);
1910 #define YYINDEX(YYX) \
1911 ((YYX) == NULL ? -1 : (yyGLRStackItem*) (YYX) - yystack->yyitems)
1915 yypdumpstack (yyGLRStack
* yystack
)
1917 yyGLRStackItem
* yyp
;
1919 for (yyp
= yystack
->yyitems
; yyp
< yystack
->yynextFree
; yyp
+= 1)
1921 fprintf (stderr
, "%3lu. ", (unsigned long) (yyp
- yystack
->yyitems
));
1924 fprintf (stderr
, "Res: %d, LR State: %d, posn: %lu, pred: %ld",
1925 yyp
->yystate
.yyresolved
, yyp
->yystate
.yylrState
,
1926 (unsigned long) yyp
->yystate
.yyposn
,
1927 (long) YYINDEX (yyp
->yystate
.yypred
));
1928 if (! yyp
->yystate
.yyresolved
)
1929 fprintf (stderr
, ", firstVal: %ld",
1930 (long) YYINDEX (yyp
->yystate
.yysemantics
.yyfirstVal
));
1934 fprintf (stderr
, "Option. rule: %d, state: %ld, next: %ld",
1935 yyp
->yyoption
.yyrule
,
1936 (long) YYINDEX (yyp
->yyoption
.yystate
),
1937 (long) YYINDEX (yyp
->yyoption
.yynext
));
1939 fprintf (stderr
, "\n");
1941 fprintf (stderr
, "Tops:");
1942 for (yyi
= 0; yyi
< yystack
->yytops
.yysize
; yyi
+= 1)
1943 fprintf (stderr
, "%lu: %ld; ", (unsigned long) yyi
,
1944 (long) YYINDEX (yystack
->yytops
.yystates
[yyi
]));
1945 fprintf (stderr
, "\n");
1950 m4_if(b4_defines_flag
, 0, [],
1951 [@output @output_header_name@
1952 b4_copyright([Skeleton parser
for GLR parsing with Bison
], [2002])
1954 b4_token_defines(b4_tokens
)
1956 #if ! defined (YYSTYPE) && ! defined (YYSTYPE_IS_DECLARED)
1957 m4_ifdef([b4_stype
],
1958 [b4_syncline([b4_stype_line
], [b4_filename
])
1959 typedef union m4_bregexp(b4_stype
, [^{], [YYSTYPE
])b4_stype YYSTYPE
;
1960 /* Line __line__ of glr.c. */
1961 b4_syncline([@oline@
], [@ofile@
])],
1962 [typedef int YYSTYPE
;])
1963 # define YYSTYPE_IS_DECLARED 1
1964 # define YYSTYPE_IS_TRIVIAL 1
1968 [extern YYSTYPE b4_prefix
[]lval
;])
1971 [#if ! defined (YYLTYPE) && ! defined (YYLTYPE_IS_DECLARED)
1972 typedef struct YYLTYPE
1979 # define YYLTYPE_IS_DECLARED 1
1980 # define YYLTYPE_IS_TRIVIAL 1
1984 [extern YYLTYPE b4_prefix
[]lloc
;])