1 m4_divert(-1) -*- C
-*-
3 # GLR skeleton for Bison
4 # Copyright (C) 2002, 2003 Free Software Foundation, Inc.
6 # This program is free software; you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation; either version 2 of the License, or
9 # (at your option) any later version.
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License
17 # along with this program; if not, write to the Free Software
18 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
22 ## ---------------- ##
24 ## ---------------- ##
27 m4_define_default([b4_stack_depth_max
], [10000])
28 m4_define_default([b4_stack_depth_init
], [200])
32 ## ------------------------ ##
33 ## Pure/impure interfaces. ##
34 ## ------------------------ ##
39 # Accumule in b4_lex_param all the yylex arguments.
40 # Yes, this is quite ugly...
41 m4_define([b4_lex_param
],
42 m4_dquote(b4_pure_if([[[[YYSTYPE
*]], [[yylvalp]]][]dnl
43 b4_location_if([, [[YYLTYPE
*], [yyllocp
]]])])dnl
44 m4_ifdef([b4_lex_param
], [, ]b4_lex_param
)))
49 m4_define([b4_user_formals
],
50 [m4_ifset([b4_parse_param
], [, b4_c_ansi_formals(b4_parse_param
)])])
55 # Arguments passed to yyerror: user args plus yylloc.
56 m4_define([b4_yyerror_args
],
57 [b4_pure_if([b4_location_if([yylocp
, ])])dnl
58 m4_ifset([b4_parse_param
], [b4_c_args(b4_parse_param
), ])])
63 # Same as above, but on the lookahead, hence yyllocp instead of yylocp.
64 m4_define([b4_lyyerror_args
],
65 [b4_pure_if([b4_location_if([yyllocp
, ])])dnl
66 m4_ifset([b4_parse_param
], [b4_c_args(b4_parse_param
), ])])
71 # Arguments needed by yyerror: user args plus yylloc.
72 m4_define([b4_pure_args
],
73 [b4_pure_if([b4_location_if([, yylocp
])])[]b4_user_args
])
78 # Arguments passed to yyerror: user formals plus yyllocp.
79 m4_define([b4_pure_formals
],
80 [b4_pure_if([b4_location_if([, YYLTYPE
*yylocp
])])[]b4_user_formals
])
85 # Same as above, but on the lookahead, hence yyllocp instead of yylocp.
86 m4_define([b4_lpure_args
],
87 [b4_pure_if([b4_location_if([, yyllocp
])])[]b4_user_args
])
92 # Same as above, but on the lookahead, hence yyllocp instead of yylocp.
93 m4_define([b4_lpure_formals
],
94 [b4_pure_if([b4_location_if([YYLTYPE
*yyllocp
])])[]b4_user_formals
])
97 ## ----------------- ##
98 ## Semantic Values. ##
99 ## ----------------- ##
102 # b4_lhs_value([TYPE])
103 # --------------------
104 # Expansion of $<TYPE>$.
105 m4_define([b4_lhs_value
],
106 [(*yyvalp
)[]m4_ifval([$
1], [.$
1])])
109 # b4_rhs_value(RULE-LENGTH, NUM, [TYPE])
110 # --------------------------------------
111 # Expansion of $<TYPE>NUM, where the current rule has RULE-LENGTH
113 m4_define([b4_rhs_value
],
114 [yyvsp@
{m4_eval([$
2 - $
1])@
}.yystate
.yysemantics
.yysval
[]m4_ifval([$
3], [.$
3])])
125 m4_define([b4_lhs_location
],
129 # b4_rhs_location(RULE-LENGTH, NUM)
130 # ---------------------------------
131 # Expansion of @NUM, where the current rule has RULE-LENGTH symbols
133 m4_define([b4_rhs_location
],
134 [yyvsp@
{m4_eval([$
2 - $
1])@
}.yystate
.yyloc
])
137 # We do want M4 expansion after # for CPP macros.
140 @output @output_parser_name@
141 b4_copyright([Skeleton parser
for GLR parsing with Bison
], [2002, 2003])
143 /* This is the parser code for GLR (Generalized LR) parser. */
152 m4_if(b4_prefix
[], [yy
], [],
153 [/* If NAME_PREFIX is specified substitute the variables and functions
155 #define yyparse b4_prefix[]parse
156 #define yylex b4_prefix[]lex
157 #define yyerror b4_prefix[]error
158 #define yylval b4_prefix[]lval
159 #define yychar b4_prefix[]char
160 #define yydebug b4_prefix[]debug
161 #define yynerrs b4_prefix[]nerrs
162 b4_location_if([#define yylloc b4_prefix[]lloc])])
164 b4_token_defines(b4_tokens
)
166 /* Copy the first part of user declarations. */
169 /* Enabling traces. */
171 # define YYDEBUG ]b4_debug[
174 /* Enabling verbose error messages. */
175 #ifdef YYERROR_VERBOSE
176 # undef YYERROR_VERBOSE
177 # define YYERROR_VERBOSE 1
179 # define YYERROR_VERBOSE ]b4_error_verbose[
182 #if ! defined (YYSTYPE) && ! defined (YYSTYPE_IS_DECLARED)
183 ]m4_ifdef([b4_stype
],
184 [b4_syncline([b4_stype_line
], [b4_filename
])
185 typedef union m4_bregexp(b4_stype
, [^{], [YYSTYPE
])b4_stype YYSTYPE
;
186 /* Line __line__ of glr.c. */
187 b4_syncline([@oline@
], [@ofile@
])],
188 [typedef int YYSTYPE
;])[
189 # define YYSTYPE_IS_DECLARED 1
190 # define YYSTYPE_IS_TRIVIAL 1
193 #if ! defined (YYLTYPE) && ! defined (YYLTYPE_IS_DECLARED)
194 typedef struct YYLTYPE
201 # define YYLTYPE_IS_DECLARED 1
202 # define YYLTYPE_IS_TRIVIAL 1
205 /* Default (constant) values used for initialization for null
206 right-hand sides. Unlike the standard yacc.c template,
207 here we set the default values of $$ and $@@ to zeroed-out
208 values. Since the default value of these quantities is undefined,
209 this behavior is technically correct. */
210 static YYSTYPE yyval_default
;
211 static YYLTYPE yyloc_default
;
213 /* Copy the second part of user declarations. */
216 ]/* Line __line__ of glr.c. */
217 b4_syncline([@oline@
], [@ofile@
])
222 typedef unsigned char yybool
;
231 #ifndef __attribute__
232 /* This feature is available in gcc versions 2.5 and later. */
233 # if !defined (__GNUC__) || __GNUC__ < 2 || \
234 (__GNUC__ == 2 && __GNUC_MINOR__ < 5) || __STRICT_ANSI__
235 # define __attribute__(Spec) /* empty */
239 #ifndef ATTRIBUTE_UNUSED
240 # define ATTRIBUTE_UNUSED __attribute__ ((__unused__))
243 /* YYFINAL -- State number of the termination state. */
244 #define YYFINAL ]b4_final_state_number[
245 /* YYLAST -- Last index in YYTABLE. */
246 #define YYLAST ]b4_last[
248 /* YYNTOKENS -- Number of terminals. */
249 #define YYNTOKENS ]b4_tokens_number[
250 /* YYNNTS -- Number of nonterminals. */
251 #define YYNNTS ]b4_nterms_number[
252 /* YYNRULES -- Number of rules. */
253 #define YYNRULES ]b4_rules_number[
254 /* YYNRULES -- Number of states. */
255 #define YYNSTATES ]b4_states_number[
256 /* YYMAXRHS -- Maximum number of symbols on right-hand side of rule. */
257 #define YYMAXRHS ]b4_r2_max[
259 /* YYTRANSLATE(X) -- Bison symbol number corresponding to X. */
260 #define YYUNDEFTOK ]b4_undef_token_number[
261 #define YYMAXUTOK ]b4_user_token_number_max[
263 #define YYTRANSLATE(YYX) \
264 ((YYX <= 0) ? YYEOF : \
265 (unsigned)(YYX) <= YYMAXUTOK ? yytranslate[YYX] : YYUNDEFTOK)
267 /* YYTRANSLATE[YYLEX] -- Bison symbol number corresponding to YYLEX. */
268 static const ]b4_int_type_for([b4_translate
])[ yytranslate
[] =
274 /* YYPRHS[YYN] -- Index of the first RHS symbol of rule number YYN in
276 static const ]b4_int_type_for([b4_prhs
])[ yyprhs
[] =
281 /* YYRHS -- A `-1'-separated list of the rules' RHS. */
282 static const ]b4_int_type_for([b4_rhs
])[ yyrhs
[] =
287 /* YYRLINE[YYN] -- source line where rule number YYN was defined. */
288 static const ]b4_int_type_for([b4_rline
])[ yyrline
[] =
294 #if (YYDEBUG) || YYERROR_VERBOSE
295 /* YYTNME[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM.
296 First, the terminals, then, starting at YYNTOKENS, nonterminals. */
297 static const char *const yytname
[] =
302 #define yytname_size ((int) (sizeof (yytname) / sizeof (yytname[0])))
305 /* YYR1[YYN] -- Symbol number of symbol that rule YYN derives. */
306 static const ]b4_int_type_for([b4_r1
])[ yyr1
[] =
311 /* YYR2[YYN] -- Number of symbols composing right hand side of rule YYN. */
312 static const ]b4_int_type_for([b4_r2
])[ yyr2
[] =
317 /* YYDPREC[RULE-NUM] -- Dynamic precedence of rule #RULE-NUM (0 if none). */
318 static const ]b4_int_type_for([b4_dprec
])[ yydprec
[] =
323 /* YYMERGER[RULE-NUM] -- Index of merging function for rule #RULE-NUM. */
324 static const ]b4_int_type_for([b4_merger
])[ yymerger
[] =
329 /* YYDEFACT[S] -- default rule to reduce with in state S when YYTABLE
330 doesn't specify something else to do. Zero means the default is an
332 static const ]b4_int_type_for([b4_defact
])[ yydefact
[] =
337 /* YYPDEFGOTO[NTERM-NUM]. */
338 static const ]b4_int_type_for([b4_defgoto
])[ yydefgoto
[] =
343 /* YYPACT[STATE-NUM] -- Index in YYTABLE of the portion describing
345 #define YYPACT_NINF ]b4_pact_ninf[
346 static const ]b4_int_type_for([b4_pact
])[ yypact
[] =
351 /* YYPGOTO[NTERM-NUM]. */
352 static const ]b4_int_type_for([b4_pgoto
])[ yypgoto
[] =
357 /* YYTABLE[YYPACT[STATE-NUM]]. What to do in state STATE-NUM. If
358 positive, shift that token. If negative, reduce the rule which
359 number is the opposite. If zero, do what YYDEFACT says.
360 If YYTABLE_NINF, syntax error. */
361 #define YYTABLE_NINF ]b4_table_ninf[
362 static const ]b4_int_type_for([b4_table
])[ yytable
[] =
367 /* YYCONFLP[YYPACT[STATE-NUM]] -- Pointer into YYCONFL of start of
368 list of conflicting reductions corresponding to action entry for
369 state STATE-NUM in yytable. 0 means no conflicts. The list in
370 yyconfl is terminated by a rule number of 0. */
371 static const ]b4_int_type_for([b4_conflict_list_heads
])[ yyconflp
[] =
373 ]b4_conflict_list_heads
[
376 /* YYCONFL[I] -- lists of conflicting rule numbers, each terminated by
377 0, pointed into by YYCONFLP. */
378 ]dnl Do
not use b4_int_type_for here
, since there are places where
379 dnl pointers onto yyconfl are taken
, which type is
"short *".
380 dnl We probably ought to introduce a type
for confl
.
381 [static const short yyconfl
[] =
383 ]b4_conflicting_rules
[
386 static const ]b4_int_type_for([b4_check
])[ yycheck
[] =
391 /* YYSTOS[STATE-NUM] -- The (internal number of the) accessing
392 symbol of state STATE-NUM. */
393 static const ]b4_int_type_for([b4_stos
])[ yystos
[] =
399 /* Prevent warning if -Wmissing-prototypes. */
400 ]b4_c_ansi_function_decl([yyparse
], [int], b4_parse_param
)[
402 /* Error token number */
405 /* YYLLOC_DEFAULT -- Compute the default location (before the actions
408 #define YYRHSLOC(yyRhs,YYK) (yyRhs[YYK].yystate.yyloc)
410 #ifndef YYLLOC_DEFAULT
411 # define YYLLOC_DEFAULT(yyCurrent, yyRhs, YYN) \
412 yyCurrent.first_line = YYRHSLOC(yyRhs,1).first_line; \
413 yyCurrent.first_column = YYRHSLOC(yyRhs,1).first_column; \
414 yyCurrent.last_line = YYRHSLOC(yyRhs,YYN).last_line; \
415 yyCurrent.last_column = YYRHSLOC(yyRhs,YYN).last_column;
418 /* YYLEX -- calling `yylex' with the right arguments. */
419 #define YYLEX ]b4_c_function_call([yylex], [int], b4_lex_param)[
424 #define yynerrs (yystack->yyerrcnt)
426 #define yychar (yystack->yyrawchar)],
434 static const int YYEOF
= 0;
435 static const int YYEMPTY
= -2;
437 typedef enum { yyok
, yyaccept
, yyabort
, yyerr
} YYRESULTTAG
;
440 do { YYRESULTTAG yyflag = YYE; if (yyflag != yyok) return yyflag; } \
445 #if ! defined (YYFPRINTF)
446 # define YYFPRINTF fprintf
449 # define YYDPRINTF(Args) \
455 ]b4_yysymprint_generate([b4_c_ansi_function_def
])[
457 # define YYDSYMPRINT(Args) \
463 # define YYDSYMPRINTF(Title, Token, Value, Location) \
467 YYFPRINTF (stderr, "%s ", Title); \
468 yysymprint (stderr, \
469 Token, Value]b4_location_if([, Location])[); \
470 YYFPRINTF (stderr, "\n"); \
474 /* Nonzero means print parse trace. It is left uninitialized so that
475 multiple parsers can coexist. */
480 /* Avoid empty `if' bodies. */
481 # define YYDPRINTF(Args)
482 # define YYDSYMPRINT(Args)
483 # define YYDSYMPRINTF(Title, Token, Value, Location)
485 #endif /* !YYDEBUG */
487 /* YYINITDEPTH -- initial size of the parser's stacks. */
489 # define YYINITDEPTH ]b4_stack_depth_init[
492 /* YYMAXDEPTH -- maximum size the stacks can grow to (effective only
493 if the built-in stack extension method is used).
495 Do not make this value too large; the results are undefined if
496 SIZE_MAX < YYMAXDEPTH * sizeof (GLRStackItem)
497 evaluated with infinite-precision integer arithmetic. */
504 # define YYMAXDEPTH ]b4_stack_depth_max[
507 /* Minimum number of free items on the stack allowed after an
508 allocation. This is to allow allocation and initialization
509 to be completed by functions that call expandGLRStack before the
510 stack is expanded, thus insuring that all necessary pointers get
511 properly redirected to new data. */
514 #if (! defined (YYSTACKEXPANDABLE) \
515 && (! defined (__cplusplus) \
516 || (]b4_location_if([YYLTYPE_IS_TRIVIAL && ])[YYSTYPE_IS_TRIVIAL)))
517 #define YYSTACKEXPANDABLE 1
519 #define YYSTACKEXPANDABLE 0
522 /** State numbers, as in LALR(1) machine */
523 typedef int yyStateNum
;
525 /** Rule numbers, as in LALR(1) machine */
526 typedef int yyRuleNum
;
528 /** Grammar symbol */
529 typedef short yySymbol
;
531 /** Item references, as in LALR(1) machine */
532 typedef short yyItemNum
;
534 typedef struct yyGLRState yyGLRState
;
535 typedef struct yySemanticOption yySemanticOption
;
536 typedef union yyGLRStackItem yyGLRStackItem
;
537 typedef struct yyGLRStack yyGLRStack
;
538 typedef struct yyGLRStateSet yyGLRStateSet
;
543 yyStateNum yylrState
;
547 yySemanticOption
* yyfirstVal
;
553 struct yyGLRStateSet
{
554 yyGLRState
** yystates
;
555 size_t yysize
, yycapacity
;
558 struct yySemanticOption
{
562 yySemanticOption
* yynext
;
565 union yyGLRStackItem
{
567 yySemanticOption yyoption
;
579 jmp_buf yyexception_buffer
;
580 yyGLRStackItem
* yyitems
;
581 yyGLRStackItem
* yynextFree
;
583 yyGLRState
* yysplitPoint
;
584 yyGLRState
* yylastDeleted
;
585 yyGLRStateSet yytops
;
588 static void yyinitGLRStack (yyGLRStack
* yystack
, size_t yysize
);
589 static void yyexpandGLRStack (yyGLRStack
* yystack
]b4_pure_formals
[);
590 static void yyfreeGLRStack (yyGLRStack
* yystack
);
593 yyFail (yyGLRStack
* yystack
]b4_pure_formals
[, const char* yyformat
, ...)
595 yystack
->yyerrflag
= 1;
596 if (yyformat
!= NULL
)
600 va_start (yyap
, yyformat
);
601 vsprintf (yymsg
, yyformat
, yyap
);
602 yyerror (]b4_yyerror_args
[yymsg
);
604 longjmp (yystack
->yyexception_buffer
, 1);
607 #if YYDEBUG || YYERROR_VERBOSE
608 /** A printable representation of TOKEN. Valid until next call to
610 static inline const char*
611 yytokenName (yySymbol yytoken
)
613 return yytname
[yytoken
];
617 /** Perform user action for rule number YYN, with RHS length YYRHSLEN,
618 * and top stack item YYVSP. YYLVALP points to place to put semantic
619 * value ($$), and yylocp points to place for location information
620 * (@@$). Returns yyok for normal return, yyaccept for YYACCEPT,
621 * yyerr for YYERROR, yyabort for YYABORT. */
623 yyuserAction (yyRuleNum yyn
, int yyrhslen
, yyGLRStackItem
* yyvsp
,
624 YYSTYPE
* yyvalp
, YYLTYPE
* yylocp
, yyGLRStack
* yystack
627 /* Avoid `unused' warnings in there are no $n. */
632 *yyvalp
= yyval_default
;
633 *yylocp
= yyloc_default
;
637 *yyvalp
= yyvsp
[1-yyrhslen
].yystate
.yysemantics
.yysval
;
638 *yylocp
= yyvsp
[1-yyrhslen
].yystate
.yyloc
;
641 # define yyerrok (yystack->yyerrState = 0)
643 # define YYACCEPT return yyaccept
645 # define YYABORT return yyabort
647 # define YYERROR return yyerr
649 # define YYRECOVERING (yystack->yyerrState != 0)
651 # define yyclearin (yychar = *(yystack->yytokenp) = YYEMPTY)
653 # define YYBACKUP(Token, Value) \
655 yyerror (]b4_yyerror_args["syntax error: cannot back up"); \
673 /* Line __line__ of glr.c. */
674 b4_syncline([@oline@
], [@ofile@
])
679 yyuserMerge (int yyn
, YYSTYPE
* yy0
, YYSTYPE
* yy1
)
681 YYSTYPE yyval
= *yy0
;
682 /* `Use' the arguments. */
693 /* Bison grammar-table manipulation. */
695 ]b4_yydestruct_generate([b4_c_ansi_function_def
])[
697 /** Number of symbols composing the right hand side of rule #RULE. */
699 yyrhsLength (yyRuleNum yyrule
)
704 /** Left-hand-side symbol for rule #RULE. */
705 static inline yySymbol
706 yylhsNonterm (yyRuleNum yyrule
)
711 #define yyis_pact_ninf(yystate) \
712 ]m4_if(m4_eval(b4_pact_ninf < b4_pact_min), 1,
714 ((yystate
) == YYPACT_NINF
))[
716 /** True iff LR state STATE has only a default reduction (regardless
719 yyisDefaultedState (yyStateNum yystate
)
721 return yyis_pact_ninf (yypact
[yystate
]);
724 /** The default reduction for STATE, assuming it has one. */
725 static inline yyRuleNum
726 yydefaultAction (yyStateNum yystate
)
728 return yydefact
[yystate
];
731 #define yyis_table_ninf(yytable_value) \
732 ]m4_if(m4_eval(b4_table_ninf < b4_table_min), 1,
734 ((yytable_value
) == YYTABLE_NINF
))[
736 /** Set *YYACTION to the action to take in YYSTATE on seeing YYTOKEN.
738 * R < 0: Reduce on rule -R.
740 * R > 0: Shift to state R.
741 * Set *CONFLICTS to a pointer into yyconfl to 0-terminated list of
742 * conflicting reductions.
745 yygetLRActions (yyStateNum yystate
, int yytoken
,
746 int* yyaction
, const short** yyconflicts
)
748 int yyindex
= yypact
[yystate
] + yytoken
;
749 if (yyindex
< 0 || YYLAST
< yyindex
|| yycheck
[yyindex
] != yytoken
)
751 *yyaction
= -yydefact
[yystate
];
752 *yyconflicts
= yyconfl
;
754 else if (! yyis_table_ninf (yytable
[yyindex
]))
756 *yyaction
= yytable
[yyindex
];
757 *yyconflicts
= yyconfl
+ yyconflp
[yyindex
];
762 *yyconflicts
= yyconfl
+ yyconflp
[yyindex
];
766 static inline yyStateNum
767 yyLRgotoState (yyStateNum yystate
, yySymbol yylhs
)
770 yyr
= yypgoto
[yylhs
- YYNTOKENS
] + yystate
;
771 if (0 <= yyr
&& yyr
<= YYLAST
&& yycheck
[yyr
] == yystate
)
774 return yydefgoto
[yylhs
- YYNTOKENS
];
778 yyisShiftAction (int yyaction
)
784 yyisErrorAction (int yyaction
)
786 return yyaction
== 0;
792 yyaddDeferredAction (yyGLRStack
* yystack
, yyGLRState
* yystate
,
793 yyGLRState
* rhs
, yyRuleNum yyrule
]b4_pure_formals
[)
795 yySemanticOption
* yynewItem
;
796 yynewItem
= &yystack
->yynextFree
->yyoption
;
797 yystack
->yyspaceLeft
-= 1;
798 yystack
->yynextFree
+= 1;
799 yynewItem
->yyisState
= yyfalse
;
800 yynewItem
->yystate
= rhs
;
801 yynewItem
->yyrule
= yyrule
;
802 yynewItem
->yynext
= yystate
->yysemantics
.yyfirstVal
;
803 yystate
->yysemantics
.yyfirstVal
= yynewItem
;
804 if (yystack
->yyspaceLeft
< YYHEADROOM
)
805 yyexpandGLRStack (yystack
]b4_pure_args
[);
810 /** Initialize SET to a singleton set containing an empty stack. */
812 yyinitStateSet (yyGLRStateSet
* yyset
)
815 yyset
->yycapacity
= 16;
816 yyset
->yystates
= (yyGLRState
**) malloc (16 * sizeof (yyset
->yystates
[0]));
817 yyset
->yystates
[0] = NULL
;
820 static void yyfreeStateSet (yyGLRStateSet
* yyset
)
822 free (yyset
->yystates
);
825 /** Initialize STACK to a single empty stack, with total maximum
826 * capacity for all stacks of SIZE. */
828 yyinitGLRStack (yyGLRStack
* yystack
, size_t yysize
)
830 yystack
->yyerrflag
= 0;
831 yystack
->yyerrState
= 0;
833 yystack
->yyspaceLeft
= yysize
;
834 yystack
->yynextFree
= yystack
->yyitems
=
835 (yyGLRStackItem
*) malloc (yysize
* sizeof (yystack
->yynextFree
[0]));
836 yystack
->yysplitPoint
= NULL
;
837 yystack
->yylastDeleted
= NULL
;
838 yyinitStateSet (&yystack
->yytops
);
841 #define YYRELOC(YYFROMITEMS,YYTOITEMS,YYX,YYTYPE) \
842 &((YYTOITEMS) - ((YYFROMITEMS) - (yyGLRStackItem*) (YYX)))->YYTYPE
844 /** If STACK is expandable, extend it. WARNING: Pointers into the
845 stack from outside should be considered invalid after this call.
846 We always expand when there are 1 or fewer items left AFTER an
847 allocation, so that we can avoid having external pointers exist
848 across an allocation. */
850 yyexpandGLRStack (yyGLRStack
* yystack
]b4_pure_formals
[)
852 #if YYSTACKEXPANDABLE
853 yyGLRStack yynewStack
;
854 yyGLRStackItem
* yyp0
, *yyp1
;
855 size_t yysize
, yynewSize
;
857 yysize
= yystack
->yynextFree
- yystack
->yyitems
;
858 if (YYMAXDEPTH
<= yysize
)
859 yyFail (yystack
][]b4_pure_args
[, "parser stack overflow");
860 yynewSize
= 2*yysize
;
861 if (YYMAXDEPTH
< yynewSize
)
862 yynewSize
= YYMAXDEPTH
;
863 yyinitGLRStack (&yynewStack
, yynewSize
);
864 for (yyp0
= yystack
->yyitems
, yyp1
= yynewStack
.yyitems
, yyn
= yysize
;
866 yyn
-= 1, yyp0
+= 1, yyp1
+= 1)
869 if (*(yybool
*) yyp0
)
871 yyGLRState
* yys0
= &yyp0
->yystate
;
872 yyGLRState
* yys1
= &yyp1
->yystate
;
873 if (yys0
->yypred
!= NULL
)
875 YYRELOC (yyp0
, yyp1
, yys0
->yypred
, yystate
);
876 if (! yys0
->yyresolved
&& yys0
->yysemantics
.yyfirstVal
!= NULL
)
877 yys1
->yysemantics
.yyfirstVal
=
878 YYRELOC(yyp0
, yyp1
, yys0
->yysemantics
.yyfirstVal
, yyoption
);
882 yySemanticOption
* yyv0
= &yyp0
->yyoption
;
883 yySemanticOption
* yyv1
= &yyp1
->yyoption
;
884 if (yyv0
->yystate
!= NULL
)
885 yyv1
->yystate
= YYRELOC (yyp0
, yyp1
, yyv0
->yystate
, yystate
);
886 if (yyv0
->yynext
!= NULL
)
887 yyv1
->yynext
= YYRELOC (yyp0
, yyp1
, yyv0
->yynext
, yyoption
);
890 if (yystack
->yysplitPoint
!= NULL
)
891 yystack
->yysplitPoint
= YYRELOC (yystack
->yyitems
, yynewStack
.yyitems
,
892 yystack
->yysplitPoint
, yystate
);
894 for (yyn
= 0; yyn
< yystack
->yytops
.yysize
; yyn
+= 1)
895 if (yystack
->yytops
.yystates
[yyn
] != NULL
)
896 yystack
->yytops
.yystates
[yyn
] =
897 YYRELOC (yystack
->yyitems
, yynewStack
.yyitems
,
898 yystack
->yytops
.yystates
[yyn
], yystate
);
899 free (yystack
->yyitems
);
900 yystack
->yyitems
= yynewStack
.yyitems
;
901 yystack
->yynextFree
= yynewStack
.yynextFree
+ yysize
;
902 yystack
->yyspaceLeft
= yynewStack
.yyspaceLeft
- yysize
;
906 yyFail (yystack
][]b4_lpure_args
[, "parser stack overflow");
911 yyfreeGLRStack (yyGLRStack
* yystack
)
913 free (yystack
->yyitems
);
914 yyfreeStateSet (&yystack
->yytops
);
917 /** Assuming that S is a GLRState somewhere on STACK, update the
918 * splitpoint of STACK, if needed, so that it is at least as deep as
921 yyupdateSplit (yyGLRStack
* yystack
, yyGLRState
* yys
)
923 if (yystack
->yysplitPoint
!= NULL
&& yystack
->yysplitPoint
> yys
)
924 yystack
->yysplitPoint
= yys
;
927 /** Invalidate stack #K in STACK. */
929 yymarkStackDeleted (yyGLRStack
* yystack
, int yyk
)
931 if (yystack
->yytops
.yystates
[yyk
] != NULL
)
932 yystack
->yylastDeleted
= yystack
->yytops
.yystates
[yyk
];
933 yystack
->yytops
.yystates
[yyk
] = NULL
;
936 /** Undelete the last stack that was marked as deleted. Can only be
937 done once after a deletion, and only when all other stacks have
940 yyundeleteLastStack (yyGLRStack
* yystack
)
942 if (yystack
->yylastDeleted
== NULL
|| yystack
->yytops
.yysize
!= 0)
944 yystack
->yytops
.yystates
[0] = yystack
->yylastDeleted
;
945 yystack
->yytops
.yysize
= 1;
946 YYDPRINTF ((stderr
, "Restoring last deleted stack as stack #0.\n"));
947 yystack
->yylastDeleted
= NULL
;
951 yyremoveDeletes (yyGLRStack
* yystack
)
955 while (yyj
< yystack
->yytops
.yysize
)
957 if (yystack
->yytops
.yystates
[yyi
] == NULL
)
961 YYDPRINTF ((stderr
, "Removing dead stacks.\n"));
963 yystack
->yytops
.yysize
-= 1;
967 yystack
->yytops
.yystates
[yyj
] = yystack
->yytops
.yystates
[yyi
];
970 YYDPRINTF ((stderr
, "Rename stack %d -> %d.\n", yyi
, yyj
));
978 /** Shift to a new state on stack #K of STACK, corresponding to LR state
979 * LRSTATE, at input position POSN, with (resolved) semantic value SVAL. */
981 yyglrShift (yyGLRStack
* yystack
, int yyk
, yyStateNum yylrState
, size_t yyposn
,
982 YYSTYPE yysval
, YYLTYPE
* yylocp
]b4_user_formals
[)
984 yyGLRStackItem
* yynewItem
;
986 yynewItem
= yystack
->yynextFree
;
987 yystack
->yynextFree
+= 1;
988 yystack
->yyspaceLeft
-= 1;
989 yynewItem
->yystate
.yyisState
= yytrue
;
990 yynewItem
->yystate
.yylrState
= yylrState
;
991 yynewItem
->yystate
.yyposn
= yyposn
;
992 yynewItem
->yystate
.yyresolved
= yytrue
;
993 yynewItem
->yystate
.yypred
= yystack
->yytops
.yystates
[yyk
];
994 yystack
->yytops
.yystates
[yyk
] = &yynewItem
->yystate
;
995 yynewItem
->yystate
.yysemantics
.yysval
= yysval
;
996 yynewItem
->yystate
.yyloc
= *yylocp
;
997 if (yystack
->yyspaceLeft
< YYHEADROOM
)
998 yyexpandGLRStack (yystack
]b4_pure_args
[);
1001 /** Shift to a new state on stack #K of STACK, to a new state
1002 * corresponding to LR state LRSTATE, at input position POSN, with
1003 * the (unresolved) semantic value of RHS under the action for RULE. */
1005 yyglrShiftDefer (yyGLRStack
* yystack
, int yyk
, yyStateNum yylrState
,
1006 size_t yyposn
, yyGLRState
* rhs
, yyRuleNum yyrule
]b4_pure_formals
[)
1008 yyGLRStackItem
* yynewItem
;
1010 yynewItem
= yystack
->yynextFree
;
1011 yynewItem
->yystate
.yyisState
= yytrue
;
1012 yynewItem
->yystate
.yylrState
= yylrState
;
1013 yynewItem
->yystate
.yyposn
= yyposn
;
1014 yynewItem
->yystate
.yyresolved
= yyfalse
;
1015 yynewItem
->yystate
.yypred
= yystack
->yytops
.yystates
[yyk
];
1016 yynewItem
->yystate
.yysemantics
.yyfirstVal
= NULL
;
1017 yystack
->yytops
.yystates
[yyk
] = &yynewItem
->yystate
;
1018 yystack
->yynextFree
+= 1;
1019 yystack
->yyspaceLeft
-= 1;
1020 yyaddDeferredAction (yystack
, &yynewItem
->yystate
, rhs
, yyrule
]b4_pure_args
[);
1023 /** Pop the symbols consumed by reduction #RULE from the top of stack
1024 * #K of STACK, and perform the appropriate semantic action on their
1025 * semantic values. Assumes that all ambiguities in semantic values
1026 * have been previously resolved. Set *VALP to the resulting value,
1027 * and *LOCP to the computed location (if any). Return value is as
1028 * for userAction. */
1029 static inline YYRESULTTAG
1030 yydoAction (yyGLRStack
* yystack
, int yyk
, yyRuleNum yyrule
,
1031 YYSTYPE
* yyvalp
, YYLTYPE
* yylocp
]b4_user_formals
[)
1033 int yynrhs
= yyrhsLength (yyrule
);
1035 if (yystack
->yysplitPoint
== NULL
)
1037 /* Standard special case: single stack. */
1038 yyGLRStackItem
* rhs
= (yyGLRStackItem
*) yystack
->yytops
.yystates
[yyk
];
1041 yystack
->yynextFree
-= yynrhs
;
1042 yystack
->yyspaceLeft
+= yynrhs
;
1043 yystack
->yytops
.yystates
[0] = & yystack
->yynextFree
[-1].yystate
;
1046 *yyvalp
= yyval_default
;
1047 *yylocp
= yyloc_default
;
1051 *yyvalp
= rhs
[1-yynrhs
].yystate
.yysemantics
.yysval
;
1052 *yylocp
= rhs
[1-yynrhs
].yystate
.yyloc
;
1054 return yyuserAction (yyrule
, yynrhs
, rhs
,
1055 yyvalp
, yylocp
, yystack
]b4_user_args
[);
1061 yyGLRStackItem yyrhsVals
[YYMAXRHS
];
1062 for (yyi
= yynrhs
-1, yys
= yystack
->yytops
.yystates
[yyk
]; 0 <= yyi
;
1063 yyi
-= 1, yys
= yys
->yypred
)
1067 yyrhsVals
[yyi
].yystate
.yyresolved
= yytrue
;
1068 yyrhsVals
[yyi
].yystate
.yysemantics
.yysval
= yys
->yysemantics
.yysval
;
1069 yyrhsVals
[yyi
].yystate
.yyloc
= yys
->yyloc
;
1071 yyupdateSplit (yystack
, yys
);
1072 yystack
->yytops
.yystates
[yyk
] = yys
;
1075 *yyvalp
= yyval_default
;
1076 *yylocp
= yyloc_default
;
1080 *yyvalp
= yyrhsVals
[0].yystate
.yysemantics
.yysval
;
1081 *yylocp
= yyrhsVals
[0].yystate
.yyloc
;
1083 return yyuserAction (yyrule
, yynrhs
, yyrhsVals
+ (yynrhs
-1),
1084 yyvalp
, yylocp
, yystack
]b4_user_args
[);
1089 # define YY_REDUCE_PRINT(K, Rule)
1091 # define YY_REDUCE_PRINT(K, Rule) \
1094 yy_reduce_print (K, Rule); \
1097 /*----------------------------------------------------------.
1098 | Report that the RULE is going to be reduced on stack #K. |
1099 `----------------------------------------------------------*/
1102 yy_reduce_print (size_t yyk
, yyRuleNum yyrule
)
1105 unsigned int yylineno
= yyrline
[yyrule
];
1106 YYFPRINTF (stderr
, "Reducing stack %d by rule %d (line %u), ",
1107 yyk
, yyrule
- 1, yylineno
);
1108 /* Print the symbols being reduced, and their result. */
1109 for (yyi
= yyprhs
[yyrule
]; 0 <= yyrhs
[yyi
]; yyi
++)
1110 YYFPRINTF (stderr
, "%s ", yytokenName (yyrhs
[yyi
]));
1111 YYFPRINTF (stderr
, "-> %s\n", yytokenName (yyr1
[yyrule
]));
1115 /** Pop items off stack #K of STACK according to grammar rule RULE,
1116 * and push back on the resulting nonterminal symbol. Perform the
1117 * semantic action associated with RULE and store its value with the
1118 * newly pushed state, if FORCEEVAL or if STACK is currently
1119 * unambiguous. Otherwise, store the deferred semantic action with
1120 * the new state. If the new state would have an identical input
1121 * position, LR state, and predecessor to an existing state on the stack,
1122 * it is identified with that existing state, eliminating stack #K from
1123 * the STACK. In this case, the (necessarily deferred) semantic value is
1124 * added to the options for the existing state's semantic value.
1126 static inline YYRESULTTAG
1127 yyglrReduce (yyGLRStack
* yystack
, size_t yyk
, yyRuleNum yyrule
,
1128 yybool yyforceEval
]b4_pure_formals
[)
1130 size_t yyposn
= yystack
->yytops
.yystates
[yyk
]->yyposn
;
1132 if (yyforceEval
|| yystack
->yysplitPoint
== NULL
)
1137 YY_REDUCE_PRINT (yyk
, yyrule
);
1138 YYCHK (yydoAction (yystack
, yyk
, yyrule
, &yysval
, &yyloc
]b4_user_args
[));
1139 yyglrShift (yystack
, yyk
,
1140 yyLRgotoState (yystack
->yytops
.yystates
[yyk
]->yylrState
,
1141 yylhsNonterm (yyrule
)),
1142 yyposn
, yysval
, &yyloc
]b4_user_args
[);
1148 yyGLRState
* yys
, *yys0
= yystack
->yytops
.yystates
[yyk
];
1149 yyStateNum yynewLRState
;
1151 for (yys
= yystack
->yytops
.yystates
[yyk
], yyn
= yyrhsLength (yyrule
);
1158 yyupdateSplit (yystack
, yys
);
1159 yynewLRState
= yyLRgotoState (yys
->yylrState
, yylhsNonterm (yyrule
));
1161 "Reduced stack %d by rule #%d; action deferred. "
1162 "Now in state %d.\n",
1163 yyk
, yyrule
-1, yynewLRState
));
1164 for (yyi
= 0; yyi
< yystack
->yytops
.yysize
; yyi
+= 1)
1165 if (yyi
!= yyk
&& yystack
->yytops
.yystates
[yyi
] != NULL
)
1167 yyGLRState
* yyp
, *yysplit
= yystack
->yysplitPoint
;
1168 yyp
= yystack
->yytops
.yystates
[yyi
];
1169 while (yyp
!= yys
&& yyp
!= yysplit
&& yyp
->yyposn
>= yyposn
)
1171 if (yyp
->yylrState
== yynewLRState
&& yyp
->yypred
== yys
)
1173 yyaddDeferredAction (yystack
, yyp
, yys0
, yyrule
]b4_pure_args
[);
1174 yymarkStackDeleted (yystack
, yyk
);
1175 YYDPRINTF ((stderr
, "Merging stack %d into stack %d.\n",
1182 yystack
->yytops
.yystates
[yyk
] = yys
;
1183 yyglrShiftDefer (yystack
, yyk
, yynewLRState
, yyposn
, yys0
, yyrule
]b4_pure_args
[);
1189 yysplitStack (yyGLRStack
* yystack
, int yyk
)
1191 if (yystack
->yysplitPoint
== NULL
)
1195 yystack
->yysplitPoint
= yystack
->yytops
.yystates
[yyk
];
1197 if (yystack
->yytops
.yysize
>= yystack
->yytops
.yycapacity
)
1199 yystack
->yytops
.yycapacity
*= 2;
1200 yystack
->yytops
.yystates
=
1201 (yyGLRState
**) realloc (yystack
->yytops
.yystates
,
1202 yystack
->yytops
.yycapacity
1203 * sizeof (yyGLRState
*));
1205 yystack
->yytops
.yystates
[yystack
->yytops
.yysize
]
1206 = yystack
->yytops
.yystates
[yyk
];
1207 yystack
->yytops
.yysize
+= 1;
1208 return yystack
->yytops
.yysize
-1;
1211 /** True iff Y0 and Y1 represent identical options at the top level.
1212 * That is, they represent the same rule applied to RHS symbols
1213 * that produce the same terminal symbols. */
1215 yyidenticalOptions (yySemanticOption
* yyy0
, yySemanticOption
* yyy1
)
1217 if (yyy0
->yyrule
== yyy1
->yyrule
)
1219 yyGLRState
*yys0
, *yys1
;
1221 for (yys0
= yyy0
->yystate
, yys1
= yyy1
->yystate
,
1222 yyn
= yyrhsLength (yyy0
->yyrule
);
1224 yys0
= yys0
->yypred
, yys1
= yys1
->yypred
, yyn
-= 1)
1225 if (yys0
->yyposn
!= yys1
->yyposn
)
1233 /** Assuming identicalOptions (Y0,Y1), (destructively) merge the
1234 * alternative semantic values for the RHS-symbols of Y1 into the
1235 * corresponding semantic value sets of the symbols of Y0. */
1237 yymergeOptionSets (yySemanticOption
* yyy0
, yySemanticOption
* yyy1
)
1239 yyGLRState
*yys0
, *yys1
;
1241 for (yys0
= yyy0
->yystate
, yys1
= yyy1
->yystate
,
1242 yyn
= yyrhsLength (yyy0
->yyrule
);
1244 yys0
= yys0
->yypred
, yys1
= yys1
->yypred
, yyn
-= 1)
1247 else if (! yys0
->yyresolved
&& ! yys1
->yyresolved
)
1249 yySemanticOption
* yyz
;
1250 for (yyz
= yys0
->yysemantics
.yyfirstVal
; yyz
->yynext
!= NULL
;
1253 yyz
->yynext
= yys1
->yysemantics
.yyfirstVal
;
1257 /** Y0 and Y1 represent two possible actions to take in a given
1258 * parsing state; return 0 if no combination is possible,
1259 * 1 if user-mergeable, 2 if Y0 is preferred, 3 if Y1 is preferred. */
1261 yypreference (yySemanticOption
* y0
, yySemanticOption
* y1
)
1263 yyRuleNum r0
= y0
->yyrule
, r1
= y1
->yyrule
;
1264 int p0
= yydprec
[r0
], p1
= yydprec
[r1
];
1268 if (yymerger
[r0
] == 0 || yymerger
[r0
] != yymerger
[r1
])
1273 if (p0
== 0 || p1
== 0)
1282 static YYRESULTTAG
yyresolveValue (yySemanticOption
* yyoptionList
,
1283 yyGLRStack
* yystack
, YYSTYPE
* yyvalp
,
1284 YYLTYPE
* yylocp
]b4_user_formals
[);
1287 yyresolveStates (yyGLRState
* yys
, int yyn
, yyGLRStack
* yystack
]b4_user_formals
[)
1294 yyflag
= yyresolveStates (yys
->yypred
, yyn
-1, yystack
]b4_user_args
[);
1297 if (! yys
->yyresolved
)
1299 yyflag
= yyresolveValue (yys
->yysemantics
.yyfirstVal
, yystack
,
1300 &yys
->yysemantics
.yysval
, &yys
->yyloc
1304 yys
->yyresolved
= yytrue
;
1311 yyresolveAction (yySemanticOption
* yyopt
, yyGLRStack
* yystack
,
1312 YYSTYPE
* yyvalp
, YYLTYPE
* yylocp
]b4_user_formals
[)
1314 yyGLRStackItem yyrhsVals
[YYMAXRHS
];
1318 yynrhs
= yyrhsLength (yyopt
->yyrule
);
1319 YYCHK (yyresolveStates (yyopt
->yystate
, yynrhs
, yystack
]b4_user_args
[));
1320 for (yyi
= yynrhs
-1, yys
= yyopt
->yystate
; 0 <= yyi
;
1321 yyi
-= 1, yys
= yys
->yypred
)
1325 yyrhsVals
[yyi
].yystate
.yyresolved
= yytrue
;
1326 yyrhsVals
[yyi
].yystate
.yysemantics
.yysval
= yys
->yysemantics
.yysval
;
1327 yyrhsVals
[yyi
].yystate
.yyloc
= yys
->yyloc
;
1329 return yyuserAction (yyopt
->yyrule
, yynrhs
, yyrhsVals
+ (yynrhs
-1),
1330 yyvalp
, yylocp
, yystack
]b4_user_args
[);
1335 yyreportTree (yySemanticOption
* yyx
, int yyindent
)
1337 int yynrhs
= yyrhsLength (yyx
->yyrule
);
1340 yyGLRState
* yystates
[YYMAXRHS
];
1341 yyGLRState yyleftmost_state
;
1343 for (yyi
= yynrhs
, yys
= yyx
->yystate
; 0 < yyi
; yyi
-= 1, yys
= yys
->yypred
)
1344 yystates
[yyi
] = yys
;
1347 yyleftmost_state
.yyposn
= 0;
1348 yystates
[0] = &yyleftmost_state
;
1353 if (yyx
->yystate
->yyposn
< yys
->yyposn
+ 1)
1354 YYFPRINTF (stderr
, "%*s%s -> <Rule %d, empty>\n",
1355 yyindent
, "", yytokenName (yylhsNonterm (yyx
->yyrule
)),
1358 YYFPRINTF (stderr
, "%*s%s -> <Rule %d, tokens %d .. %d>\n",
1359 yyindent
, "", yytokenName (yylhsNonterm (yyx
->yyrule
)),
1360 yyx
->yyrule
, yys
->yyposn
+1, yyx
->yystate
->yyposn
);
1361 for (yyi
= 1; yyi
<= yynrhs
; yyi
+= 1)
1363 if (yystates
[yyi
]->yyresolved
)
1365 if (yystates
[yyi
-1]->yyposn
+1 > yystates
[yyi
]->yyposn
)
1366 YYFPRINTF (stderr
, "%*s%s <empty>\n", yyindent
+2, "",
1367 yytokenName (yyrhs
[yyprhs
[yyx
->yyrule
]+yyi
-1]));
1369 YYFPRINTF (stderr
, "%*s%s <tokens %d .. %d>\n", yyindent
+2, "",
1370 yytokenName (yyrhs
[yyprhs
[yyx
->yyrule
]+yyi
-1]),
1371 yystates
[yyi
-1]->yyposn
+1, yystates
[yyi
]->yyposn
);
1374 yyreportTree (yystates
[yyi
]->yysemantics
.yyfirstVal
, yyindent
+2);
1380 yyreportAmbiguity (yySemanticOption
* yyx0
, yySemanticOption
* yyx1
,
1381 yyGLRStack
* yystack
]b4_pure_formals
[)
1383 /* `Unused' warnings. */
1388 YYFPRINTF (stderr
, "Ambiguity detected.\n");
1389 YYFPRINTF (stderr
, "Option 1,\n");
1390 yyreportTree (yyx0
, 2);
1391 YYFPRINTF (stderr
, "\nOption 2,\n");
1392 yyreportTree (yyx1
, 2);
1393 YYFPRINTF (stderr
, "\n");
1395 yyFail (yystack
][]b4_pure_args
[, "ambiguity detected");
1399 /** Resolve the ambiguity represented by OPTIONLIST, perform the indicated
1400 * actions, and return the result. */
1402 yyresolveValue (yySemanticOption
* yyoptionList
, yyGLRStack
* yystack
,
1403 YYSTYPE
* yyvalp
, YYLTYPE
* yylocp
]b4_user_formals
[)
1405 yySemanticOption
* yybest
;
1406 yySemanticOption
* yyp
;
1409 yybest
= yyoptionList
;
1411 for (yyp
= yyoptionList
->yynext
; yyp
!= NULL
; yyp
= yyp
->yynext
)
1413 if (yyidenticalOptions (yybest
, yyp
))
1414 yymergeOptionSets (yybest
, yyp
);
1416 switch (yypreference (yybest
, yyp
))
1419 yyreportAmbiguity (yybest
, yyp
, yystack
]b4_pure_args
[);
1435 int yyprec
= yydprec
[yybest
->yyrule
];
1436 YYCHK (yyresolveAction (yybest
, yystack
, yyvalp
, yylocp
]b4_user_args
[));
1437 for (yyp
= yybest
->yynext
; yyp
!= NULL
; yyp
= yyp
->yynext
)
1439 if (yyprec
== yydprec
[yyp
->yyrule
])
1443 YYCHK (yyresolveAction (yyp
, yystack
, &yyval1
, &yydummy
]b4_user_args
[));
1444 *yyvalp
= yyuserMerge (yymerger
[yyp
->yyrule
], yyvalp
, &yyval1
);
1450 return yyresolveAction (yybest
, yystack
, yyvalp
, yylocp
]b4_user_args
[);
1454 yyresolveStack (yyGLRStack
* yystack
]b4_user_formals
[)
1456 if (yystack
->yysplitPoint
!= NULL
)
1461 for (yyn
= 0, yys
= yystack
->yytops
.yystates
[0];
1462 yys
!= yystack
->yysplitPoint
;
1463 yys
= yys
->yypred
, yyn
+= 1)
1465 YYCHK (yyresolveStates (yystack
->yytops
.yystates
[0], yyn
, yystack
1472 yycompressStack (yyGLRStack
* yystack
)
1474 yyGLRState
* yyp
, *yyq
, *yyr
;
1476 if (yystack
->yytops
.yysize
!= 1 || yystack
->yysplitPoint
== NULL
)
1479 for (yyp
= yystack
->yytops
.yystates
[0], yyq
= yyp
->yypred
, yyr
= NULL
;
1480 yyp
!= yystack
->yysplitPoint
;
1481 yyr
= yyp
, yyp
= yyq
, yyq
= yyp
->yypred
)
1484 yystack
->yyspaceLeft
+= yystack
->yynextFree
- yystack
->yyitems
;
1485 yystack
->yynextFree
= ((yyGLRStackItem
*) yystack
->yysplitPoint
) + 1;
1486 yystack
->yyspaceLeft
-= yystack
->yynextFree
- yystack
->yyitems
;
1487 yystack
->yysplitPoint
= NULL
;
1488 yystack
->yylastDeleted
= NULL
;
1492 yystack
->yynextFree
->yystate
= *yyr
;
1494 yystack
->yynextFree
->yystate
.yypred
= & yystack
->yynextFree
[-1].yystate
;
1495 yystack
->yytops
.yystates
[0] = &yystack
->yynextFree
->yystate
;
1496 yystack
->yynextFree
+= 1;
1497 yystack
->yyspaceLeft
-= 1;
1502 yyprocessOneStack (yyGLRStack
* yystack
, int yyk
,
1503 size_t yyposn
, YYSTYPE
* yylvalp
, YYLTYPE
* yyllocp
1507 const short* yyconflicts
;
1509 yySymbol
* const yytokenp
= yystack
->yytokenp
;
1511 while (yystack
->yytops
.yystates
[yyk
] != NULL
)
1513 yyStateNum yystate
= yystack
->yytops
.yystates
[yyk
]->yylrState
;
1514 YYDPRINTF ((stderr
, "Stack %d Entering state %d\n", yyk
, yystate
));
1516 if (yystate
== YYFINAL
)
1518 if (yyisDefaultedState (yystate
))
1520 yyrule
= yydefaultAction (yystate
);
1523 YYDPRINTF ((stderr
, "Stack %d dies.\n", yyk
));
1524 yymarkStackDeleted (yystack
, yyk
);
1527 YYCHK (yyglrReduce (yystack
, yyk
, yyrule
, yyfalse
]b4_lpure_args
[));
1531 if (*yytokenp
== YYEMPTY
)
1533 YYDPRINTF ((stderr
, "Reading a token: "));
1535 *yytokenp
= YYTRANSLATE (yychar
);
1536 YYDSYMPRINTF ("Next token is", *yytokenp
, yylvalp
, yyllocp
);
1538 yygetLRActions (yystate
, *yytokenp
, &yyaction
, &yyconflicts
);
1540 while (*yyconflicts
!= 0)
1542 int yynewStack
= yysplitStack (yystack
, yyk
);
1543 YYDPRINTF ((stderr
, "Splitting off stack %d from %d.\n",
1545 YYCHK (yyglrReduce (yystack
, yynewStack
,
1546 *yyconflicts
, yyfalse
]b4_lpure_args
[));
1547 YYCHK (yyprocessOneStack (yystack
, yynewStack
, yyposn
,
1548 yylvalp
, yyllocp
]b4_user_args
[));
1552 if (yyisShiftAction (yyaction
))
1554 YYDPRINTF ((stderr
, "Shifting token %s on stack %d, ",
1555 yytokenName (*yytokenp
), yyk
));
1556 yyglrShift (yystack
, yyk
, yyaction
, yyposn
+1,
1557 *yylvalp
, yyllocp
]b4_user_args
[);
1558 YYDPRINTF ((stderr
, "which is now in state #%d\n",
1559 yystack
->yytops
.yystates
[yyk
]->yylrState
));
1562 else if (yyisErrorAction (yyaction
))
1564 YYDPRINTF ((stderr
, "Stack %d dies.\n", yyk
));
1565 yymarkStackDeleted (yystack
, yyk
);
1569 YYCHK (yyglrReduce (yystack
, yyk
, -yyaction
, yyfalse
]b4_lpure_args
[));
1576 yyreportSyntaxError (yyGLRStack
* yystack
,
1577 YYSTYPE
* yylvalp
, YYLTYPE
* yyllocp
]b4_user_formals
[)
1579 /* `Unused' warnings. */
1583 if (yystack
->yyerrState
== 0)
1586 yySymbol
* const yytokenp
= yystack
->yytokenp
;
1587 int yyn
, yyx
, yycount
;
1589 const char* yyprefix
;
1592 yyn
= yypact
[yystack
->yytops
.yystates
[0]->yylrState
];
1593 if (YYPACT_NINF
< yyn
&& yyn
< YYLAST
)
1596 /* Start YYX at -YYN if negative to avoid negative indexes in
1598 yysize
= sizeof ("syntax error, unexpected ")
1599 + strlen (yytokenName (*yytokenp
));
1600 yyprefix
= ", expecting ";
1601 for (yyx
= yyn
< 0 ? -yyn
: 0; yyx
< yytname_size
&& yycount
<= 5;
1603 if (yycheck
[yyx
+ yyn
] == yyx
&& yyx
!= YYTERROR
)
1604 yysize
+= strlen (yytokenName (yyx
)) + strlen (yyprefix
),
1605 yycount
+= 1, yyprefix
= " or ";
1606 yymsg
= yyp
= (char*) malloc (yysize
);
1607 sprintf (yyp
, "syntax error, unexpected %s",
1608 yytokenName (*yytokenp
));
1609 yyp
+= strlen (yyp
);
1612 yyprefix
= ", expecting ";
1613 for (yyx
= yyn
< 0 ? -yyn
: 0; yyx
< yytname_size
; yyx
+= 1)
1614 if (yycheck
[yyx
+ yyn
] == yyx
&& yyx
!= YYTERROR
)
1616 sprintf (yyp
, "%s%s", yyprefix
, yytokenName (yyx
));
1617 yyp
+= strlen (yyp
);
1621 yyerror (]b4_lyyerror_args
[yymsg
);
1626 yyerror (]b4_lyyerror_args
["syntax error");
1631 /* Recover from a syntax error on YYSTACK, assuming that YYTOKENP,
1632 YYLVALP, and YYLLOCP point to the syntactic category, semantic
1633 value, and location of the lookahead. */
1635 yyrecoverSyntaxError (yyGLRStack
* yystack
,
1636 YYSTYPE
* yylvalp
, YYLTYPE
* yyllocp
]b4_user_formals
[)
1638 yySymbol
* const yytokenp
= yystack
->yytokenp
;
1642 if (yystack
->yyerrState
== 0)
1643 yystack
->yyerrState
= 3;
1644 else if (yystack
->yyerrState
== 3)
1645 /* We just shifted the error token and (perhaps) took some
1646 reductions. Skip tokens until we can proceed. */
1649 if (*yytokenp
== YYEOF
)
1651 /* Now pop stack until we find a state that shifts the
1653 while (yystack
->yytops
.yystates
[0] != NULL
)
1655 yyGLRState
*yys
= yystack
->yytops
.yystates
[0];
1656 YYDSYMPRINTF ("Error: popping",
1657 yystos
[yys
->yylrState
],
1658 &yys
->yysemantics
.yysval
, &yys
->yyloc
);
1659 yydestruct (yystos
[yys
->yylrState
],
1660 &yys
->yysemantics
.yysval
]b4_location_if([, &yys
->yyloc
])[);
1661 yystack
->yytops
.yystates
[0] = yys
->yypred
;
1662 yystack
->yynextFree
-= 1;
1663 yystack
->yyspaceLeft
+= 1;
1665 yyFail (yystack
][]b4_lpure_args
[, NULL
);
1667 if (*yytokenp
!= YYEMPTY
)
1669 YYDSYMPRINTF ("Error: discarding", *yytokenp
, yylvalp
, yyllocp
);
1670 yydestruct (*yytokenp
, yylvalp
]b4_location_if([, yyllocp
])[);
1672 YYDPRINTF ((stderr
, "Reading a token: "));
1674 *yytokenp
= YYTRANSLATE (yychar
);
1675 YYDSYMPRINTF ("Next token is", *yytokenp
, yylvalp
, yyllocp
);
1676 yyj
= yypact
[yystack
->yytops
.yystates
[0]->yylrState
];
1677 if (yyis_pact_ninf (yyj
))
1678 /* Something's not right; we shouldn't be here. */
1679 yyFail (yystack
][]b4_lpure_args
[, NULL
);
1681 if (yyj
< 0 || YYLAST
< yyj
|| yycheck
[yyj
] != *yytokenp
)
1683 if (yydefact
[yystack
->yytops
.yystates
[0]->yylrState
] != 0)
1686 else if (yytable
[yyj
] != 0 && ! yyis_table_ninf (yytable
[yyj
]))
1690 /* Reduce to one stack. */
1691 for (yyk
= 0; yyk
< yystack
->yytops
.yysize
; yyk
+= 1)
1692 if (yystack
->yytops
.yystates
[yyk
] != NULL
)
1694 if (yyk
>= yystack
->yytops
.yysize
)
1695 yyFail (yystack
][]b4_lpure_args
[, NULL
);
1696 for (yyk
+= 1; yyk
< yystack
->yytops
.yysize
; yyk
+= 1)
1697 yymarkStackDeleted (yystack
, yyk
);
1698 yyremoveDeletes (yystack
);
1699 yycompressStack (yystack
);
1701 /* Now pop stack until we find a state that shifts the error token. */
1702 while (yystack
->yytops
.yystates
[0] != NULL
)
1704 yyGLRState
*yys
= yystack
->yytops
.yystates
[0];
1705 yyj
= yypact
[yys
->yylrState
];
1706 if (! yyis_pact_ninf (yyj
))
1709 if (0 <= yyj
&& yyj
<= YYLAST
&& yycheck
[yyj
] == YYTERROR
1710 && yyisShiftAction (yytable
[yyj
]))
1712 YYDPRINTF ((stderr
, "Shifting error token, "));
1713 yyglrShift (yystack
, 0, yytable
[yyj
],
1714 yys
->yyposn
, *yylvalp
, yyllocp
]b4_user_args
[);
1718 YYDSYMPRINTF ("Error: popping",
1719 yystos
[yys
->yylrState
],
1720 &yys
->yysemantics
.yysval
, &yys
->yyloc
);
1721 yydestruct (yystos
[yys
->yylrState
],
1722 &yys
->yysemantics
.yysval
]b4_location_if([, &yys
->yyloc
])[);
1723 yystack
->yytops
.yystates
[0] = yys
->yypred
;
1724 yystack
->yynextFree
-= 1;
1725 yystack
->yyspaceLeft
+= 1;
1727 if (yystack
->yytops
.yystates
[0] == NULL
)
1728 yyFail (yystack
][]b4_lpure_args
[, NULL
);
1731 #define YYCHK1(YYE) \
1737 yystack.yyerrflag = 1; \
1740 yystack.yyerrflag = 0; \
1743 goto yyuser_error; \
1752 ]b4_c_ansi_function_def([yyparse
], [int], b4_parse_param
)[
1762 #define yychar (yystack.yyrawchar)
1765 YYSTYPE
* const yylvalp
= &yylval
;
1766 YYLTYPE
* const yyllocp
= &yylloc
;
1768 yyinitGLRStack (&yystack
, YYINITDEPTH
);
1769 yystack
.yytokenp
= &yytoken
;
1771 YYDPRINTF ((stderr
, "Starting parse\n"));
1773 if (setjmp (yystack
.yyexception_buffer
) != 0)
1776 yyglrShift (&yystack
, 0, 0, 0, yyval_default
, &yyloc_default
]b4_user_args
[);
1782 /* For efficiency, we have two loops, the first of which is
1783 specialized to deterministic operation (single stack, no
1784 potential ambiguity). */
1790 const short* yyconflicts
;
1792 yyStateNum yystate
= yystack
.yytops
.yystates
[0]->yylrState
;
1793 YYDPRINTF ((stderr
, "Entering state %d\n", yystate
));
1794 if (yystate
== YYFINAL
)
1796 if (yyisDefaultedState (yystate
))
1798 yyrule
= yydefaultAction (yystate
);
1801 yyreportSyntaxError (&yystack
, yylvalp
, yyllocp
]b4_user_args
[);
1804 YYCHK1 (yyglrReduce (&yystack
, 0, yyrule
, yytrue
]b4_lpure_args
[));
1808 if (yytoken
== YYEMPTY
)
1810 YYDPRINTF ((stderr
, "Reading a token: "));
1812 yytoken
= YYTRANSLATE (yychar
);
1813 YYDSYMPRINTF ("Next token is", yytoken
, yylvalp
, yyllocp
);
1815 yygetLRActions (yystate
, yytoken
, &yyaction
, &yyconflicts
);
1816 if (*yyconflicts
!= 0)
1818 if (yyisShiftAction (yyaction
))
1820 YYDPRINTF ((stderr
, "Shifting token %s, ",
1821 yytokenName (yytoken
)));
1822 if (yytoken
!= YYEOF
)
1825 yyglrShift (&yystack
, 0, yyaction
, yyposn
,
1826 yylval
, yyllocp
]b4_user_args
[);
1827 if (0 < yystack
.yyerrState
)
1828 yystack
.yyerrState
-= 1;
1830 else if (yyisErrorAction (yyaction
))
1832 yyreportSyntaxError (&yystack
, yylvalp
, yyllocp
]b4_user_args
[);
1836 YYCHK1 (yyglrReduce (&yystack
, 0, -yyaction
, yytrue
]b4_lpure_args
[));
1843 int yyn
= yystack
.yytops
.yysize
;
1844 for (yys
= 0; yys
< yyn
; yys
+= 1)
1845 YYCHK1 (yyprocessOneStack (&yystack
, yys
, yyposn
,
1846 yylvalp
, yyllocp
]b4_user_args
[));
1849 yyremoveDeletes (&yystack
);
1850 if (yystack
.yytops
.yysize
== 0)
1852 yyundeleteLastStack (&yystack
);
1853 if (yystack
.yytops
.yysize
== 0)
1854 yyFail (&yystack
][]b4_lpure_args
[, "syntax error");
1855 YYCHK1 (yyresolveStack (&yystack
]b4_user_args
[));
1856 YYDPRINTF ((stderr
, "Returning to deterministic operation.\n"));
1857 yyreportSyntaxError (&yystack
, yylvalp
, yyllocp
]b4_user_args
[);
1860 else if (yystack
.yytops
.yysize
== 1)
1862 YYCHK1 (yyresolveStack (&yystack
]b4_user_args
[));
1863 YYDPRINTF ((stderr
, "Returning to deterministic operation.\n"));
1864 yycompressStack (&yystack
);
1870 yyrecoverSyntaxError (&yystack
, yylvalp
, yyllocp
]b4_user_args
[);
1871 yyposn
= yystack
.yytops
.yystates
[0]->yyposn
;
1876 yyfreeGLRStack (&yystack
);
1877 return yystack
.yyerrflag
;
1880 /* DEBUGGING ONLY */
1881 static void yypstack (yyGLRStack
* yystack
, int yyk
) ATTRIBUTE_UNUSED
;
1882 static void yypdumpstack (yyGLRStack
* yystack
) ATTRIBUTE_UNUSED
;
1885 yy_yypstack (yyGLRState
* yys
)
1889 yy_yypstack (yys
->yypred
);
1890 fprintf (stderr
, " -> ");
1892 fprintf (stderr
, "%d@@%lu", yys
->yylrState
, (unsigned long) yys
->yyposn
);
1896 yypstates (yyGLRState
* yyst
)
1899 fprintf (stderr
, "<null>");
1902 fprintf (stderr
, "\n");
1906 yypstack (yyGLRStack
* yystack
, int yyk
)
1908 yypstates (yystack
->yytops
.yystates
[yyk
]);
1911 #define YYINDEX(YYX) \
1912 ((YYX) == NULL ? -1 : (yyGLRStackItem*) (YYX) - yystack->yyitems)
1916 yypdumpstack (yyGLRStack
* yystack
)
1918 yyGLRStackItem
* yyp
;
1920 for (yyp
= yystack
->yyitems
; yyp
< yystack
->yynextFree
; yyp
+= 1)
1922 fprintf (stderr
, "%3lu. ", (unsigned long) (yyp
- yystack
->yyitems
));
1923 if (*(yybool
*) yyp
)
1925 fprintf (stderr
, "Res: %d, LR State: %d, posn: %lu, pred: %ld",
1926 yyp
->yystate
.yyresolved
, yyp
->yystate
.yylrState
,
1927 (unsigned long) yyp
->yystate
.yyposn
,
1928 (long) YYINDEX (yyp
->yystate
.yypred
));
1929 if (! yyp
->yystate
.yyresolved
)
1930 fprintf (stderr
, ", firstVal: %ld",
1931 (long) YYINDEX (yyp
->yystate
.yysemantics
.yyfirstVal
));
1935 fprintf (stderr
, "Option. rule: %d, state: %ld, next: %ld",
1936 yyp
->yyoption
.yyrule
,
1937 (long) YYINDEX (yyp
->yyoption
.yystate
),
1938 (long) YYINDEX (yyp
->yyoption
.yynext
));
1940 fprintf (stderr
, "\n");
1942 fprintf (stderr
, "Tops:");
1943 for (yyi
= 0; yyi
< yystack
->yytops
.yysize
; yyi
+= 1)
1944 fprintf (stderr
, "%lu: %ld; ", (unsigned long) yyi
,
1945 (long) YYINDEX (yystack
->yytops
.yystates
[yyi
]));
1946 fprintf (stderr
, "\n");
1951 m4_if(b4_defines_flag
, 0, [],
1952 [@output @output_header_name@
1953 b4_copyright([Skeleton parser
for GLR parsing with Bison
], [2002, 2003])
1955 b4_token_defines(b4_tokens
)
1957 #if ! defined (YYSTYPE) && ! defined (YYSTYPE_IS_DECLARED)
1958 m4_ifdef([b4_stype
],
1959 [b4_syncline([b4_stype_line
], [b4_filename
])
1960 typedef union m4_bregexp(b4_stype
, [^{], [YYSTYPE
])b4_stype YYSTYPE
;
1961 /* Line __line__ of glr.c. */
1962 b4_syncline([@oline@
], [@ofile@
])],
1963 [typedef int YYSTYPE
;])
1964 # define YYSTYPE_IS_DECLARED 1
1965 # define YYSTYPE_IS_TRIVIAL 1
1969 [extern YYSTYPE b4_prefix
[]lval
;])
1972 [#if ! defined (YYLTYPE) && ! defined (YYLTYPE_IS_DECLARED)
1973 typedef struct YYLTYPE
1980 # define YYLTYPE_IS_DECLARED 1
1981 # define YYLTYPE_IS_TRIVIAL 1
1985 [extern YYLTYPE b4_prefix
[]lloc
;])