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@
{YYFILL (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@
{YYFILL (m4_eval([$
2 - $
1]))@
}.yystate
.yyloc
])
136 # We do want M4 expansion after # for CPP macros.
139 @output @output_parser_name@
140 b4_copyright([Skeleton parser
for GLR parsing with Bison
], [2002, 2003])
142 /* This is the parser code for GLR (Generalized LR) parser. */
151 m4_if(b4_prefix
[], [yy
], [],
152 [/* If NAME_PREFIX is specified substitute the variables and functions
154 #define yyparse b4_prefix[]parse
155 #define yylex b4_prefix[]lex
156 #define yyerror b4_prefix[]error
157 #define yylval b4_prefix[]lval
158 #define yychar b4_prefix[]char
159 #define yydebug b4_prefix[]debug
160 #define yynerrs b4_prefix[]nerrs
161 b4_location_if([#define yylloc b4_prefix[]lloc])])
163 b4_token_defines(b4_tokens
)
165 /* Copy the first part of user declarations. */
168 /* Enabling traces. */
170 # define YYDEBUG ]b4_debug[
173 /* Enabling verbose error messages. */
174 #ifdef YYERROR_VERBOSE
175 # undef YYERROR_VERBOSE
176 # define YYERROR_VERBOSE 1
178 # define YYERROR_VERBOSE ]b4_error_verbose[
181 #if ! defined (YYSTYPE) && ! defined (YYSTYPE_IS_DECLARED)
182 ]m4_ifdef([b4_stype
],
183 [b4_syncline([b4_stype_line
], [b4_filename
])
184 typedef union m4_bregexp(b4_stype
, [^{], [YYSTYPE
])b4_stype YYSTYPE
;
185 /* Line __line__ of glr.c. */
186 b4_syncline([@oline@
], [@ofile@
])],
187 [typedef int YYSTYPE
;])[
188 # define YYSTYPE_IS_DECLARED 1
189 # define YYSTYPE_IS_TRIVIAL 1
192 #if ! defined (YYLTYPE) && ! defined (YYLTYPE_IS_DECLARED)
193 typedef struct YYLTYPE
204 # define YYLTYPE_IS_DECLARED 1
205 # define YYLTYPE_IS_TRIVIAL 1
208 /* Default (constant) values used for initialization for null
209 right-hand sides. Unlike the standard yacc.c template,
210 here we set the default values of $$ and $@@ to zeroed-out
211 values. Since the default value of these quantities is undefined,
212 this behavior is technically correct. */
213 static YYSTYPE yyval_default
;
214 static YYLTYPE yyloc_default
;
216 /* Copy the second part of user declarations. */
219 ]/* Line __line__ of glr.c. */
220 b4_syncline([@oline@
], [@ofile@
])
225 typedef unsigned char yybool
;
234 #ifndef __attribute__
235 /* This feature is available in gcc versions 2.5 and later. */
236 # if !defined (__GNUC__) || __GNUC__ < 2 || \
237 (__GNUC__ == 2 && __GNUC_MINOR__ < 5) || __STRICT_ANSI__
238 # define __attribute__(Spec) /* empty */
242 #ifndef ATTRIBUTE_UNUSED
243 # define ATTRIBUTE_UNUSED __attribute__ ((__unused__))
246 /* YYFINAL -- State number of the termination state. */
247 #define YYFINAL ]b4_final_state_number[
248 /* YYLAST -- Last index in YYTABLE. */
249 #define YYLAST ]b4_last[
251 /* YYNTOKENS -- Number of terminals. */
252 #define YYNTOKENS ]b4_tokens_number[
253 /* YYNNTS -- Number of nonterminals. */
254 #define YYNNTS ]b4_nterms_number[
255 /* YYNRULES -- Number of rules. */
256 #define YYNRULES ]b4_rules_number[
257 /* YYNRULES -- Number of states. */
258 #define YYNSTATES ]b4_states_number[
259 /* YYMAXRHS -- Maximum number of symbols on right-hand side of rule. */
260 #define YYMAXRHS ]b4_r2_max[
261 /* YYMAXLEFT -- Maximum number of symbols to the left of a handle
262 accessed by $0, $-1, etc., in any rule. */
263 #define YYMAXLEFT ]b4_max_left_semantic_context[
265 /* YYTRANSLATE(X) -- Bison symbol number corresponding to X. */
266 #define YYUNDEFTOK ]b4_undef_token_number[
267 #define YYMAXUTOK ]b4_user_token_number_max[
269 #define YYTRANSLATE(YYX) \
270 ((YYX <= 0) ? YYEOF : \
271 (unsigned)(YYX) <= YYMAXUTOK ? yytranslate[YYX] : YYUNDEFTOK)
273 /* YYTRANSLATE[YYLEX] -- Bison symbol number corresponding to YYLEX. */
274 static const ]b4_int_type_for([b4_translate
])[ yytranslate
[] =
280 /* YYPRHS[YYN] -- Index of the first RHS symbol of rule number YYN in
282 static const ]b4_int_type_for([b4_prhs
])[ yyprhs
[] =
287 /* YYRHS -- A `-1'-separated list of the rules' RHS. */
288 static const ]b4_int_type_for([b4_rhs
])[ yyrhs
[] =
293 /* YYRLINE[YYN] -- source line where rule number YYN was defined. */
294 static const ]b4_int_type_for([b4_rline
])[ yyrline
[] =
300 #if (YYDEBUG) || YYERROR_VERBOSE
301 /* YYTNME[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM.
302 First, the terminals, then, starting at YYNTOKENS, nonterminals. */
303 static const char *const yytname
[] =
309 /* YYR1[YYN] -- Symbol number of symbol that rule YYN derives. */
310 static const ]b4_int_type_for([b4_r1
])[ yyr1
[] =
315 /* YYR2[YYN] -- Number of symbols composing right hand side of rule YYN. */
316 static const ]b4_int_type_for([b4_r2
])[ yyr2
[] =
321 /* YYDPREC[RULE-NUM] -- Dynamic precedence of rule #RULE-NUM (0 if none). */
322 static const ]b4_int_type_for([b4_dprec
])[ yydprec
[] =
327 /* YYMERGER[RULE-NUM] -- Index of merging function for rule #RULE-NUM. */
328 static const ]b4_int_type_for([b4_merger
])[ yymerger
[] =
333 /* YYDEFACT[S] -- default rule to reduce with in state S when YYTABLE
334 doesn't specify something else to do. Zero means the default is an
336 static const ]b4_int_type_for([b4_defact
])[ yydefact
[] =
341 /* YYPDEFGOTO[NTERM-NUM]. */
342 static const ]b4_int_type_for([b4_defgoto
])[ yydefgoto
[] =
347 /* YYPACT[STATE-NUM] -- Index in YYTABLE of the portion describing
349 #define YYPACT_NINF ]b4_pact_ninf[
350 static const ]b4_int_type_for([b4_pact
])[ yypact
[] =
355 /* YYPGOTO[NTERM-NUM]. */
356 static const ]b4_int_type_for([b4_pgoto
])[ yypgoto
[] =
361 /* YYTABLE[YYPACT[STATE-NUM]]. What to do in state STATE-NUM. If
362 positive, shift that token. If negative, reduce the rule which
363 number is the opposite. If zero, do what YYDEFACT says.
364 If YYTABLE_NINF, syntax error. */
365 #define YYTABLE_NINF ]b4_table_ninf[
366 static const ]b4_int_type_for([b4_table
])[ yytable
[] =
371 /* YYCONFLP[YYPACT[STATE-NUM]] -- Pointer into YYCONFL of start of
372 list of conflicting reductions corresponding to action entry for
373 state STATE-NUM in yytable. 0 means no conflicts. The list in
374 yyconfl is terminated by a rule number of 0. */
375 static const ]b4_int_type_for([b4_conflict_list_heads
])[ yyconflp
[] =
377 ]b4_conflict_list_heads
[
380 /* YYCONFL[I] -- lists of conflicting rule numbers, each terminated by
381 0, pointed into by YYCONFLP. */
382 ]dnl Do
not use b4_int_type_for here
, since there are places where
383 dnl pointers onto yyconfl are taken
, which type is
"short *".
384 dnl We probably ought to introduce a type
for confl
.
385 [static const short yyconfl
[] =
387 ]b4_conflicting_rules
[
390 static const ]b4_int_type_for([b4_check
])[ yycheck
[] =
395 /* YYSTOS[STATE-NUM] -- The (internal number of the) accessing
396 symbol of state STATE-NUM. */
397 static const ]b4_int_type_for([b4_stos
])[ yystos
[] =
403 /* Prevent warning if -Wmissing-prototypes. */
404 ]b4_c_ansi_function_decl([yyparse
], [int], b4_parse_param
)[
406 /* Error token number */
409 /* YYLLOC_DEFAULT -- Compute the default location (before the actions
413 #define YYRHSLOC(yyRhs,YYK) ((yyRhs)[YYK].yystate.yyloc)
415 #ifndef YYLLOC_DEFAULT
416 # define YYLLOC_DEFAULT(yyCurrent, yyRhs, YYN) \
417 ((yyCurrent).first_line = YYRHSLOC(yyRhs, 1).first_line, \
418 (yyCurrent).first_column = YYRHSLOC(yyRhs, 1).first_column, \
419 (yyCurrent).last_line = YYRHSLOC(yyRhs, YYN).last_line, \
420 (yyCurrent).last_column = YYRHSLOC(yyRhs, YYN).last_column)
423 #ifndef YYLLOC_DEFAULT
424 # define YYLLOC_DEFAULT(yyCurrent, yyRhs, YYN) ((void) 0)
429 /* YYLEX -- calling `yylex' with the right arguments. */
430 #define YYLEX ]b4_c_function_call([yylex], [int], b4_lex_param)[
435 #define yynerrs (yystack->yyerrcnt)
437 #define yychar (yystack->yyrawchar)],
445 static const int YYEOF
= 0;
446 static const int YYEMPTY
= -2;
448 typedef enum { yyok
, yyaccept
, yyabort
, yyerr
} YYRESULTTAG
;
451 do { YYRESULTTAG yyflag = YYE; if (yyflag != yyok) return yyflag; } \
456 #if ! defined (YYFPRINTF)
457 # define YYFPRINTF fprintf
460 # define YYDPRINTF(Args) \
466 ]b4_yysymprint_generate([b4_c_ansi_function_def
])[
468 # define YYDSYMPRINT(Args) \
474 # define YYDSYMPRINTF(Title, Token, Value, Location) \
478 YYFPRINTF (stderr, "%s ", Title); \
479 yysymprint (stderr, \
480 Token, Value]b4_location_if([, Location])[); \
481 YYFPRINTF (stderr, "\n"); \
485 /* Nonzero means print parse trace. It is left uninitialized so that
486 multiple parsers can coexist. */
491 /* Avoid empty `if' bodies. */
492 # define YYDPRINTF(Args)
493 # define YYDSYMPRINT(Args)
494 # define YYDSYMPRINTF(Title, Token, Value, Location)
496 #endif /* !YYDEBUG */
498 /* YYINITDEPTH -- initial size of the parser's stacks. */
500 # define YYINITDEPTH ]b4_stack_depth_init[
503 /* YYMAXDEPTH -- maximum size the stacks can grow to (effective only
504 if the built-in stack extension method is used).
506 Do not make this value too large; the results are undefined if
507 SIZE_MAX < YYMAXDEPTH * sizeof (GLRStackItem)
508 evaluated with infinite-precision integer arithmetic. */
515 # define YYMAXDEPTH ]b4_stack_depth_max[
518 /* Minimum number of free items on the stack allowed after an
519 allocation. This is to allow allocation and initialization
520 to be completed by functions that call expandGLRStack before the
521 stack is expanded, thus insuring that all necessary pointers get
522 properly redirected to new data. */
525 #if (! defined (YYSTACKEXPANDABLE) \
526 && (! defined (__cplusplus) \
527 || (]b4_location_if([[defined (YYLTYPE_IS_TRIVIAL) && YYLTYPE_IS_TRIVIAL \
528 && ]])[defined (YYSTYPE_IS_TRIVIAL) && YYSTYPE_IS_TRIVIAL)))
529 #define YYSTACKEXPANDABLE 1
531 #define YYSTACKEXPANDABLE 0
534 /** State numbers, as in LALR(1) machine */
535 typedef int yyStateNum
;
537 /** Rule numbers, as in LALR(1) machine */
538 typedef int yyRuleNum
;
540 /** Grammar symbol */
541 typedef short yySymbol
;
543 /** Item references, as in LALR(1) machine */
544 typedef short yyItemNum
;
546 typedef struct yyGLRState yyGLRState
;
547 typedef struct yySemanticOption yySemanticOption
;
548 typedef union yyGLRStackItem yyGLRStackItem
;
549 typedef struct yyGLRStack yyGLRStack
;
550 typedef struct yyGLRStateSet yyGLRStateSet
;
555 yyStateNum yylrState
;
559 yySemanticOption
* yyfirstVal
;
565 struct yyGLRStateSet
{
566 yyGLRState
** yystates
;
567 size_t yysize
, yycapacity
;
570 struct yySemanticOption
{
574 yySemanticOption
* yynext
;
577 union yyGLRStackItem
{
579 yySemanticOption yyoption
;
591 jmp_buf yyexception_buffer
;
592 yyGLRStackItem
* yyitems
;
593 yyGLRStackItem
* yynextFree
;
595 yyGLRState
* yysplitPoint
;
596 yyGLRState
* yylastDeleted
;
597 yyGLRStateSet yytops
;
600 static void yyinitGLRStack (yyGLRStack
* yystack
, size_t yysize
);
601 static void yyexpandGLRStack (yyGLRStack
* yystack
]b4_pure_formals
[);
602 static void yyfreeGLRStack (yyGLRStack
* yystack
);
605 yyFail (yyGLRStack
* yystack
]b4_pure_formals
[, const char* yyformat
, ...)
607 yystack
->yyerrflag
= 1;
608 if (yyformat
!= NULL
)
612 va_start (yyap
, yyformat
);
613 vsprintf (yymsg
, yyformat
, yyap
);
614 yyerror (]b4_yyerror_args
[yymsg
);
616 longjmp (yystack
->yyexception_buffer
, 1);
619 #if YYDEBUG || YYERROR_VERBOSE
620 /** A printable representation of TOKEN. Valid until next call to
622 static inline const char*
623 yytokenName (yySymbol yytoken
)
625 return yytname
[yytoken
];
629 /** Fill in YYVSP[YYLOW1 .. YYLOW0-1] from the chain of states starting
630 * at YYVSP[YYLOW0].yystate.yypred. Leaves YYVSP[YYLOW1].yystate.yypred
631 * containing the pointer to the next state in the chain. Assumes
632 * YYLOW1 < YYLOW0. */
633 static void yyfillin (yyGLRStackItem
*, int, int) ATTRIBUTE_UNUSED
;
635 yyfillin (yyGLRStackItem
*yyvsp
, int yylow0
, int yylow1
)
639 s
= yyvsp
[yylow0
].yystate
.yypred
;
640 for (i
= yylow0
-1; i
>= yylow1
; i
-= 1)
644 yyvsp
[i
].yystate
.yyresolved
= yytrue
;
645 yyvsp
[i
].yystate
.yysemantics
.yysval
= s
->yysemantics
.yysval
;
646 yyvsp
[i
].yystate
.yyloc
= s
->yyloc
;
647 s
= yyvsp
[i
].yystate
.yypred
= s
->yypred
;
651 /* Do nothing if YYNORMAL or if *YYLOW <= YYLOW1. Otherwise, fill in
652 YYVSP[YYLOW1 .. *YYLOW-1] as in yyfillin and set *YYLOW = YYLOW1.
653 For convenience, always return YYLOW1. */
654 static inline int yyfill (yyGLRStackItem
*, int *, int, yybool
)
657 yyfill (yyGLRStackItem
*yyvsp
, int *yylow
, int yylow1
, yybool yynormal
)
659 if (!yynormal
&& yylow1
< *yylow
)
661 yyfillin (yyvsp
, *yylow
, yylow1
);
667 /** Perform user action for rule number YYN, with RHS length YYRHSLEN,
668 * and top stack item YYVSP. YYLVALP points to place to put semantic
669 * value ($$), and yylocp points to place for location information
670 * (@@$). Returns yyok for normal return, yyaccept for YYACCEPT,
671 * yyerr for YYERROR, yyabort for YYABORT. */
673 yyuserAction (yyRuleNum yyn
, int yyrhslen
, yyGLRStackItem
* yyvsp
,
674 YYSTYPE
* yyvalp
, YYLTYPE
* yylocp
, yyGLRStack
* yystack
677 yybool yynormal ATTRIBUTE_UNUSED
= (yystack
->yysplitPoint
== NULL
);
681 # define yyerrok (yystack->yyerrState = 0)
683 # define YYACCEPT return yyaccept
685 # define YYABORT return yyabort
687 # define YYERROR return yyerrok, yyerr
689 # define YYRECOVERING (yystack->yyerrState != 0)
691 # define yyclearin (yychar = *(yystack->yytokenp) = YYEMPTY)
693 # define YYFILL(N) yyfill (yyvsp, &yylow, N, yynormal)
695 # define YYBACKUP(Token, Value) \
696 return yyerror (]b4_yyerror_args["syntax error: cannot back up"), \
702 *yyvalp
= yyval_default
;
703 *yylocp
= yyloc_default
;
707 *yyvalp
= yyvsp
[YYFILL (1-yyrhslen
)].yystate
.yysemantics
.yysval
;
708 YYLLOC_DEFAULT (*yylocp
, yyvsp
- yyrhslen
, yyrhslen
);
725 /* Line __line__ of glr.c. */
726 b4_syncline([@oline@
], [@ofile@
])
731 yyuserMerge (int yyn
, YYSTYPE
* yy0
, YYSTYPE
* yy1
)
733 YYSTYPE yyval
= *yy0
;
734 /* `Use' the arguments. */
745 /* Bison grammar-table manipulation. */
747 ]b4_yydestruct_generate([b4_c_ansi_function_def
])[
749 /** Number of symbols composing the right hand side of rule #RULE. */
751 yyrhsLength (yyRuleNum yyrule
)
756 /** Left-hand-side symbol for rule #RULE. */
757 static inline yySymbol
758 yylhsNonterm (yyRuleNum yyrule
)
763 #define yyis_pact_ninf(yystate) \
764 ]m4_if(m4_eval(b4_pact_ninf < b4_pact_min), 1,
766 ((yystate
) == YYPACT_NINF
))[
768 /** True iff LR state STATE has only a default reduction (regardless
771 yyisDefaultedState (yyStateNum yystate
)
773 return yyis_pact_ninf (yypact
[yystate
]);
776 /** The default reduction for STATE, assuming it has one. */
777 static inline yyRuleNum
778 yydefaultAction (yyStateNum yystate
)
780 return yydefact
[yystate
];
783 #define yyis_table_ninf(yytable_value) \
784 ]m4_if(m4_eval(b4_table_ninf < b4_table_min), 1,
786 ((yytable_value
) == YYTABLE_NINF
))[
788 /** Set *YYACTION to the action to take in YYSTATE on seeing YYTOKEN.
790 * R < 0: Reduce on rule -R.
792 * R > 0: Shift to state R.
793 * Set *CONFLICTS to a pointer into yyconfl to 0-terminated list of
794 * conflicting reductions.
797 yygetLRActions (yyStateNum yystate
, int yytoken
,
798 int* yyaction
, const short** yyconflicts
)
800 int yyindex
= yypact
[yystate
] + yytoken
;
801 if (yyindex
< 0 || YYLAST
< yyindex
|| yycheck
[yyindex
] != yytoken
)
803 *yyaction
= -yydefact
[yystate
];
804 *yyconflicts
= yyconfl
;
806 else if (! yyis_table_ninf (yytable
[yyindex
]))
808 *yyaction
= yytable
[yyindex
];
809 *yyconflicts
= yyconfl
+ yyconflp
[yyindex
];
814 *yyconflicts
= yyconfl
+ yyconflp
[yyindex
];
818 static inline yyStateNum
819 yyLRgotoState (yyStateNum yystate
, yySymbol yylhs
)
822 yyr
= yypgoto
[yylhs
- YYNTOKENS
] + yystate
;
823 if (0 <= yyr
&& yyr
<= YYLAST
&& yycheck
[yyr
] == yystate
)
826 return yydefgoto
[yylhs
- YYNTOKENS
];
830 yyisShiftAction (int yyaction
)
836 yyisErrorAction (int yyaction
)
838 return yyaction
== 0;
844 yyaddDeferredAction (yyGLRStack
* yystack
, yyGLRState
* yystate
,
845 yyGLRState
* rhs
, yyRuleNum yyrule
]b4_pure_formals
[)
847 yySemanticOption
* yynewItem
;
848 yynewItem
= &yystack
->yynextFree
->yyoption
;
849 yystack
->yyspaceLeft
-= 1;
850 yystack
->yynextFree
+= 1;
851 yynewItem
->yyisState
= yyfalse
;
852 yynewItem
->yystate
= rhs
;
853 yynewItem
->yyrule
= yyrule
;
854 yynewItem
->yynext
= yystate
->yysemantics
.yyfirstVal
;
855 yystate
->yysemantics
.yyfirstVal
= yynewItem
;
856 if (yystack
->yyspaceLeft
< YYHEADROOM
)
857 yyexpandGLRStack (yystack
]b4_pure_args
[);
862 /** Initialize SET to a singleton set containing an empty stack. */
864 yyinitStateSet (yyGLRStateSet
* yyset
)
867 yyset
->yycapacity
= 16;
868 yyset
->yystates
= (yyGLRState
**) malloc (16 * sizeof (yyset
->yystates
[0]));
869 yyset
->yystates
[0] = NULL
;
872 static void yyfreeStateSet (yyGLRStateSet
* yyset
)
874 free (yyset
->yystates
);
877 /** Initialize STACK to a single empty stack, with total maximum
878 * capacity for all stacks of SIZE. */
880 yyinitGLRStack (yyGLRStack
* yystack
, size_t yysize
)
882 yystack
->yyerrflag
= 0;
883 yystack
->yyerrState
= 0;
885 yystack
->yyspaceLeft
= yysize
;
886 yystack
->yynextFree
= yystack
->yyitems
=
887 (yyGLRStackItem
*) malloc (yysize
* sizeof (yystack
->yynextFree
[0]));
888 yystack
->yysplitPoint
= NULL
;
889 yystack
->yylastDeleted
= NULL
;
890 yyinitStateSet (&yystack
->yytops
);
893 #define YYRELOC(YYFROMITEMS,YYTOITEMS,YYX,YYTYPE) \
894 &((YYTOITEMS) - ((YYFROMITEMS) - (yyGLRStackItem*) (YYX)))->YYTYPE
896 /** If STACK is expandable, extend it. WARNING: Pointers into the
897 stack from outside should be considered invalid after this call.
898 We always expand when there are 1 or fewer items left AFTER an
899 allocation, so that we can avoid having external pointers exist
900 across an allocation. */
902 yyexpandGLRStack (yyGLRStack
* yystack
]b4_pure_formals
[)
904 #if YYSTACKEXPANDABLE
905 yyGLRStack yynewStack
;
906 yyGLRStackItem
* yyp0
, *yyp1
;
907 size_t yysize
, yynewSize
;
909 yysize
= yystack
->yynextFree
- yystack
->yyitems
;
910 if (YYMAXDEPTH
<= yysize
)
911 yyFail (yystack
][]b4_pure_args
[, "parser stack overflow");
912 yynewSize
= 2*yysize
;
913 if (YYMAXDEPTH
< yynewSize
)
914 yynewSize
= YYMAXDEPTH
;
915 yyinitGLRStack (&yynewStack
, yynewSize
);
916 for (yyp0
= yystack
->yyitems
, yyp1
= yynewStack
.yyitems
, yyn
= yysize
;
918 yyn
-= 1, yyp0
+= 1, yyp1
+= 1)
921 if (*(yybool
*) yyp0
)
923 yyGLRState
* yys0
= &yyp0
->yystate
;
924 yyGLRState
* yys1
= &yyp1
->yystate
;
925 if (yys0
->yypred
!= NULL
)
927 YYRELOC (yyp0
, yyp1
, yys0
->yypred
, yystate
);
928 if (! yys0
->yyresolved
&& yys0
->yysemantics
.yyfirstVal
!= NULL
)
929 yys1
->yysemantics
.yyfirstVal
=
930 YYRELOC(yyp0
, yyp1
, yys0
->yysemantics
.yyfirstVal
, yyoption
);
934 yySemanticOption
* yyv0
= &yyp0
->yyoption
;
935 yySemanticOption
* yyv1
= &yyp1
->yyoption
;
936 if (yyv0
->yystate
!= NULL
)
937 yyv1
->yystate
= YYRELOC (yyp0
, yyp1
, yyv0
->yystate
, yystate
);
938 if (yyv0
->yynext
!= NULL
)
939 yyv1
->yynext
= YYRELOC (yyp0
, yyp1
, yyv0
->yynext
, yyoption
);
942 if (yystack
->yysplitPoint
!= NULL
)
943 yystack
->yysplitPoint
= YYRELOC (yystack
->yyitems
, yynewStack
.yyitems
,
944 yystack
->yysplitPoint
, yystate
);
946 for (yyn
= 0; yyn
< yystack
->yytops
.yysize
; yyn
+= 1)
947 if (yystack
->yytops
.yystates
[yyn
] != NULL
)
948 yystack
->yytops
.yystates
[yyn
] =
949 YYRELOC (yystack
->yyitems
, yynewStack
.yyitems
,
950 yystack
->yytops
.yystates
[yyn
], yystate
);
951 free (yystack
->yyitems
);
952 yystack
->yyitems
= yynewStack
.yyitems
;
953 yystack
->yynextFree
= yynewStack
.yynextFree
+ yysize
;
954 yystack
->yyspaceLeft
= yynewStack
.yyspaceLeft
- yysize
;
958 yyFail (yystack
][]b4_pure_args
[, "parser stack overflow");
963 yyfreeGLRStack (yyGLRStack
* yystack
)
965 free (yystack
->yyitems
);
966 yyfreeStateSet (&yystack
->yytops
);
969 /** Assuming that S is a GLRState somewhere on STACK, update the
970 * splitpoint of STACK, if needed, so that it is at least as deep as
973 yyupdateSplit (yyGLRStack
* yystack
, yyGLRState
* yys
)
975 if (yystack
->yysplitPoint
!= NULL
&& yystack
->yysplitPoint
> yys
)
976 yystack
->yysplitPoint
= yys
;
979 /** Invalidate stack #K in STACK. */
981 yymarkStackDeleted (yyGLRStack
* yystack
, int yyk
)
983 if (yystack
->yytops
.yystates
[yyk
] != NULL
)
984 yystack
->yylastDeleted
= yystack
->yytops
.yystates
[yyk
];
985 yystack
->yytops
.yystates
[yyk
] = NULL
;
988 /** Undelete the last stack that was marked as deleted. Can only be
989 done once after a deletion, and only when all other stacks have
992 yyundeleteLastStack (yyGLRStack
* yystack
)
994 if (yystack
->yylastDeleted
== NULL
|| yystack
->yytops
.yysize
!= 0)
996 yystack
->yytops
.yystates
[0] = yystack
->yylastDeleted
;
997 yystack
->yytops
.yysize
= 1;
998 YYDPRINTF ((stderr
, "Restoring last deleted stack as stack #0.\n"));
999 yystack
->yylastDeleted
= NULL
;
1003 yyremoveDeletes (yyGLRStack
* yystack
)
1007 while (yyj
< yystack
->yytops
.yysize
)
1009 if (yystack
->yytops
.yystates
[yyi
] == NULL
)
1013 YYDPRINTF ((stderr
, "Removing dead stacks.\n"));
1015 yystack
->yytops
.yysize
-= 1;
1019 yystack
->yytops
.yystates
[yyj
] = yystack
->yytops
.yystates
[yyi
];
1022 YYDPRINTF ((stderr
, "Rename stack %lu -> %lu.\n",
1023 (unsigned long int) yyi
, (unsigned long int) yyj
));
1031 /** Shift to a new state on stack #K of STACK, corresponding to LR state
1032 * LRSTATE, at input position POSN, with (resolved) semantic value SVAL. */
1034 yyglrShift (yyGLRStack
* yystack
, int yyk
, yyStateNum yylrState
, size_t yyposn
,
1035 YYSTYPE yysval
, YYLTYPE
* yylocp
]b4_user_formals
[)
1037 yyGLRStackItem
* yynewItem
;
1039 yynewItem
= yystack
->yynextFree
;
1040 yystack
->yynextFree
+= 1;
1041 yystack
->yyspaceLeft
-= 1;
1042 yynewItem
->yystate
.yyisState
= yytrue
;
1043 yynewItem
->yystate
.yylrState
= yylrState
;
1044 yynewItem
->yystate
.yyposn
= yyposn
;
1045 yynewItem
->yystate
.yyresolved
= yytrue
;
1046 yynewItem
->yystate
.yypred
= yystack
->yytops
.yystates
[yyk
];
1047 yystack
->yytops
.yystates
[yyk
] = &yynewItem
->yystate
;
1048 yynewItem
->yystate
.yysemantics
.yysval
= yysval
;
1049 yynewItem
->yystate
.yyloc
= *yylocp
;
1050 if (yystack
->yyspaceLeft
< YYHEADROOM
)
1051 yyexpandGLRStack (yystack
]b4_pure_args
[);
1054 /** Shift stack #K of YYSTACK, to a new state corresponding to LR
1055 * state YYLRSTATE, at input position YYPOSN, with the (unresolved)
1056 * semantic value of YYRHS under the action for YYRULE. */
1058 yyglrShiftDefer (yyGLRStack
* yystack
, int yyk
, yyStateNum yylrState
,
1059 size_t yyposn
, yyGLRState
* rhs
, yyRuleNum yyrule
]b4_pure_formals
[)
1061 yyGLRStackItem
* yynewItem
;
1063 yynewItem
= yystack
->yynextFree
;
1064 yynewItem
->yystate
.yyisState
= yytrue
;
1065 yynewItem
->yystate
.yylrState
= yylrState
;
1066 yynewItem
->yystate
.yyposn
= yyposn
;
1067 yynewItem
->yystate
.yyresolved
= yyfalse
;
1068 yynewItem
->yystate
.yypred
= yystack
->yytops
.yystates
[yyk
];
1069 yynewItem
->yystate
.yysemantics
.yyfirstVal
= NULL
;
1070 yystack
->yytops
.yystates
[yyk
] = &yynewItem
->yystate
;
1071 yystack
->yynextFree
+= 1;
1072 yystack
->yyspaceLeft
-= 1;
1073 yyaddDeferredAction (yystack
, &yynewItem
->yystate
, rhs
, yyrule
]b4_pure_args
[);
1076 /** Pop the symbols consumed by reduction #RULE from the top of stack
1077 * #K of STACK, and perform the appropriate semantic action on their
1078 * semantic values. Assumes that all ambiguities in semantic values
1079 * have been previously resolved. Set *VALP to the resulting value,
1080 * and *LOCP to the computed location (if any). Return value is as
1081 * for userAction. */
1082 static inline YYRESULTTAG
1083 yydoAction (yyGLRStack
* yystack
, int yyk
, yyRuleNum yyrule
,
1084 YYSTYPE
* yyvalp
, YYLTYPE
* yylocp
]b4_user_formals
[)
1086 int yynrhs
= yyrhsLength (yyrule
);
1088 if (yystack
->yysplitPoint
== NULL
)
1090 /* Standard special case: single stack. */
1091 yyGLRStackItem
* rhs
= (yyGLRStackItem
*) yystack
->yytops
.yystates
[yyk
];
1094 yystack
->yynextFree
-= yynrhs
;
1095 yystack
->yyspaceLeft
+= yynrhs
;
1096 yystack
->yytops
.yystates
[0] = & yystack
->yynextFree
[-1].yystate
;
1097 return yyuserAction (yyrule
, yynrhs
, rhs
,
1098 yyvalp
, yylocp
, yystack
]b4_user_args
[);
1104 yyGLRStackItem yyrhsVals
[YYMAXRHS
+ YYMAXLEFT
+ 1];
1105 yys
= yyrhsVals
[YYMAXRHS
+ YYMAXLEFT
].yystate
.yypred
1106 = yystack
->yytops
.yystates
[yyk
];
1107 for (yyi
= 0; yyi
< yynrhs
; yyi
+= 1)
1113 yyupdateSplit (yystack
, yys
);
1114 yystack
->yytops
.yystates
[yyk
] = yys
;
1115 return yyuserAction (yyrule
, yynrhs
, yyrhsVals
+ YYMAXRHS
+ YYMAXLEFT
- 1,
1116 yyvalp
, yylocp
, yystack
]b4_user_args
[);
1121 # define YY_REDUCE_PRINT(K, Rule)
1123 # define YY_REDUCE_PRINT(K, Rule) \
1126 yy_reduce_print (K, Rule); \
1129 /*----------------------------------------------------------.
1130 | Report that the RULE is going to be reduced on stack #K. |
1131 `----------------------------------------------------------*/
1134 yy_reduce_print (size_t yyk
, yyRuleNum yyrule
)
1137 YYFPRINTF (stderr
, "Reducing stack %lu by rule %d (line %lu), ",
1138 (unsigned long int) yyk
, yyrule
- 1,
1139 (unsigned long int) yyrline
[yyrule
]);
1140 /* Print the symbols being reduced, and their result. */
1141 for (yyi
= yyprhs
[yyrule
]; 0 <= yyrhs
[yyi
]; yyi
++)
1142 YYFPRINTF (stderr
, "%s ", yytokenName (yyrhs
[yyi
]));
1143 YYFPRINTF (stderr
, "-> %s\n", yytokenName (yyr1
[yyrule
]));
1147 /** Pop items off stack #K of STACK according to grammar rule RULE,
1148 * and push back on the resulting nonterminal symbol. Perform the
1149 * semantic action associated with RULE and store its value with the
1150 * newly pushed state, if FORCEEVAL or if STACK is currently
1151 * unambiguous. Otherwise, store the deferred semantic action with
1152 * the new state. If the new state would have an identical input
1153 * position, LR state, and predecessor to an existing state on the stack,
1154 * it is identified with that existing state, eliminating stack #K from
1155 * the STACK. In this case, the (necessarily deferred) semantic value is
1156 * added to the options for the existing state's semantic value.
1158 static inline YYRESULTTAG
1159 yyglrReduce (yyGLRStack
* yystack
, size_t yyk
, yyRuleNum yyrule
,
1160 yybool yyforceEval
]b4_pure_formals
[)
1162 size_t yyposn
= yystack
->yytops
.yystates
[yyk
]->yyposn
;
1164 if (yyforceEval
|| yystack
->yysplitPoint
== NULL
)
1169 YY_REDUCE_PRINT (yyk
, yyrule
);
1170 YYCHK (yydoAction (yystack
, yyk
, yyrule
, &yysval
, &yyloc
]b4_user_args
[));
1171 yyglrShift (yystack
, yyk
,
1172 yyLRgotoState (yystack
->yytops
.yystates
[yyk
]->yylrState
,
1173 yylhsNonterm (yyrule
)),
1174 yyposn
, yysval
, &yyloc
]b4_user_args
[);
1180 yyGLRState
* yys
, *yys0
= yystack
->yytops
.yystates
[yyk
];
1181 yyStateNum yynewLRState
;
1183 for (yys
= yystack
->yytops
.yystates
[yyk
], yyn
= yyrhsLength (yyrule
);
1190 yyupdateSplit (yystack
, yys
);
1191 yynewLRState
= yyLRgotoState (yys
->yylrState
, yylhsNonterm (yyrule
));
1193 "Reduced stack %lu by rule #%d; action deferred. "
1194 "Now in state %d.\n",
1195 (unsigned long int) yyk
, yyrule
- 1, yynewLRState
));
1196 for (yyi
= 0; yyi
< yystack
->yytops
.yysize
; yyi
+= 1)
1197 if (yyi
!= yyk
&& yystack
->yytops
.yystates
[yyi
] != NULL
)
1199 yyGLRState
* yyp
, *yysplit
= yystack
->yysplitPoint
;
1200 yyp
= yystack
->yytops
.yystates
[yyi
];
1201 while (yyp
!= yys
&& yyp
!= yysplit
&& yyp
->yyposn
>= yyposn
)
1203 if (yyp
->yylrState
== yynewLRState
&& yyp
->yypred
== yys
)
1205 yyaddDeferredAction (yystack
, yyp
, yys0
, yyrule
]b4_pure_args
[);
1206 yymarkStackDeleted (yystack
, yyk
);
1207 YYDPRINTF ((stderr
, "Merging stack %lu into stack %lu.\n",
1208 (unsigned long int) yyk
,
1209 (unsigned long int) yyi
));
1215 yystack
->yytops
.yystates
[yyk
] = yys
;
1216 yyglrShiftDefer (yystack
, yyk
, yynewLRState
, yyposn
, yys0
, yyrule
]b4_pure_args
[);
1222 yysplitStack (yyGLRStack
* yystack
, int yyk
)
1224 if (yystack
->yysplitPoint
== NULL
)
1228 yystack
->yysplitPoint
= yystack
->yytops
.yystates
[yyk
];
1230 if (yystack
->yytops
.yysize
>= yystack
->yytops
.yycapacity
)
1232 yystack
->yytops
.yycapacity
*= 2;
1233 yystack
->yytops
.yystates
=
1234 (yyGLRState
**) realloc (yystack
->yytops
.yystates
,
1235 yystack
->yytops
.yycapacity
1236 * sizeof (yyGLRState
*));
1238 yystack
->yytops
.yystates
[yystack
->yytops
.yysize
]
1239 = yystack
->yytops
.yystates
[yyk
];
1240 yystack
->yytops
.yysize
+= 1;
1241 return yystack
->yytops
.yysize
-1;
1244 /** True iff Y0 and Y1 represent identical options at the top level.
1245 * That is, they represent the same rule applied to RHS symbols
1246 * that produce the same terminal symbols. */
1248 yyidenticalOptions (yySemanticOption
* yyy0
, yySemanticOption
* yyy1
)
1250 if (yyy0
->yyrule
== yyy1
->yyrule
)
1252 yyGLRState
*yys0
, *yys1
;
1254 for (yys0
= yyy0
->yystate
, yys1
= yyy1
->yystate
,
1255 yyn
= yyrhsLength (yyy0
->yyrule
);
1257 yys0
= yys0
->yypred
, yys1
= yys1
->yypred
, yyn
-= 1)
1258 if (yys0
->yyposn
!= yys1
->yyposn
)
1266 /** Assuming identicalOptions (Y0,Y1), (destructively) merge the
1267 * alternative semantic values for the RHS-symbols of Y1 into the
1268 * corresponding semantic value sets of the symbols of Y0. */
1270 yymergeOptionSets (yySemanticOption
* yyy0
, yySemanticOption
* yyy1
)
1272 yyGLRState
*yys0
, *yys1
;
1274 for (yys0
= yyy0
->yystate
, yys1
= yyy1
->yystate
,
1275 yyn
= yyrhsLength (yyy0
->yyrule
);
1277 yys0
= yys0
->yypred
, yys1
= yys1
->yypred
, yyn
-= 1)
1280 else if (! yys0
->yyresolved
&& ! yys1
->yyresolved
)
1282 yySemanticOption
* yyz
;
1283 for (yyz
= yys0
->yysemantics
.yyfirstVal
; yyz
->yynext
!= NULL
;
1286 yyz
->yynext
= yys1
->yysemantics
.yyfirstVal
;
1290 /** Y0 and Y1 represent two possible actions to take in a given
1291 * parsing state; return 0 if no combination is possible,
1292 * 1 if user-mergeable, 2 if Y0 is preferred, 3 if Y1 is preferred. */
1294 yypreference (yySemanticOption
* y0
, yySemanticOption
* y1
)
1296 yyRuleNum r0
= y0
->yyrule
, r1
= y1
->yyrule
;
1297 int p0
= yydprec
[r0
], p1
= yydprec
[r1
];
1301 if (yymerger
[r0
] == 0 || yymerger
[r0
] != yymerger
[r1
])
1306 if (p0
== 0 || p1
== 0)
1315 static YYRESULTTAG
yyresolveValue (yySemanticOption
* yyoptionList
,
1316 yyGLRStack
* yystack
, YYSTYPE
* yyvalp
,
1317 YYLTYPE
* yylocp
]b4_user_formals
[);
1320 yyresolveStates (yyGLRState
* yys
, int yyn
, yyGLRStack
* yystack
]b4_user_formals
[)
1325 if (yys
->yypred
== NULL
)
1327 yyflag
= yyresolveStates (yys
->yypred
, yyn
-1, yystack
]b4_user_args
[);
1330 if (! yys
->yyresolved
)
1332 yyflag
= yyresolveValue (yys
->yysemantics
.yyfirstVal
, yystack
,
1333 &yys
->yysemantics
.yysval
, &yys
->yyloc
1337 yys
->yyresolved
= yytrue
;
1344 yyresolveAction (yySemanticOption
* yyopt
, yyGLRStack
* yystack
,
1345 YYSTYPE
* yyvalp
, YYLTYPE
* yylocp
]b4_user_formals
[)
1347 yyGLRStackItem yyrhsVals
[YYMAXRHS
+ YYMAXLEFT
+ 1];
1350 yynrhs
= yyrhsLength (yyopt
->yyrule
);
1351 YYCHK (yyresolveStates (yyopt
->yystate
, yynrhs
, yystack
]b4_user_args
[));
1352 yyrhsVals
[YYMAXRHS
+ YYMAXLEFT
].yystate
.yypred
= yyopt
->yystate
;
1353 return yyuserAction (yyopt
->yyrule
, yynrhs
,
1354 yyrhsVals
+ YYMAXRHS
+ YYMAXLEFT
- 1,
1355 yyvalp
, yylocp
, yystack
]b4_user_args
[);
1360 yyreportTree (yySemanticOption
* yyx
, int yyindent
)
1362 int yynrhs
= yyrhsLength (yyx
->yyrule
);
1365 yyGLRState
* yystates
[YYMAXRHS
];
1366 yyGLRState yyleftmost_state
;
1368 for (yyi
= yynrhs
, yys
= yyx
->yystate
; 0 < yyi
; yyi
-= 1, yys
= yys
->yypred
)
1369 yystates
[yyi
] = yys
;
1372 yyleftmost_state
.yyposn
= 0;
1373 yystates
[0] = &yyleftmost_state
;
1378 if (yyx
->yystate
->yyposn
< yys
->yyposn
+ 1)
1379 YYFPRINTF (stderr
, "%*s%s -> <Rule %d, empty>\n",
1380 yyindent
, "", yytokenName (yylhsNonterm (yyx
->yyrule
)),
1383 YYFPRINTF (stderr
, "%*s%s -> <Rule %d, tokens %lu .. %lu>\n",
1384 yyindent
, "", yytokenName (yylhsNonterm (yyx
->yyrule
)),
1385 yyx
->yyrule
, (unsigned long int) (yys
->yyposn
+ 1),
1386 (unsigned long int) yyx
->yystate
->yyposn
);
1387 for (yyi
= 1; yyi
<= yynrhs
; yyi
+= 1)
1389 if (yystates
[yyi
]->yyresolved
)
1391 if (yystates
[yyi
-1]->yyposn
+1 > yystates
[yyi
]->yyposn
)
1392 YYFPRINTF (stderr
, "%*s%s <empty>\n", yyindent
+2, "",
1393 yytokenName (yyrhs
[yyprhs
[yyx
->yyrule
]+yyi
-1]));
1395 YYFPRINTF (stderr
, "%*s%s <tokens %lu .. %lu>\n", yyindent
+2, "",
1396 yytokenName (yyrhs
[yyprhs
[yyx
->yyrule
]+yyi
-1]),
1397 (unsigned long int) (yystates
[yyi
- 1]->yyposn
+ 1),
1398 (unsigned long int) yystates
[yyi
]->yyposn
);
1401 yyreportTree (yystates
[yyi
]->yysemantics
.yyfirstVal
, yyindent
+2);
1407 yyreportAmbiguity (yySemanticOption
* yyx0
, yySemanticOption
* yyx1
,
1408 yyGLRStack
* yystack
]b4_pure_formals
[)
1410 /* `Unused' warnings. */
1415 YYFPRINTF (stderr
, "Ambiguity detected.\n");
1416 YYFPRINTF (stderr
, "Option 1,\n");
1417 yyreportTree (yyx0
, 2);
1418 YYFPRINTF (stderr
, "\nOption 2,\n");
1419 yyreportTree (yyx1
, 2);
1420 YYFPRINTF (stderr
, "\n");
1422 yyFail (yystack
][]b4_pure_args
[, "ambiguity detected");
1426 /** Resolve the ambiguity represented by OPTIONLIST, perform the indicated
1427 * actions, and return the result. */
1429 yyresolveValue (yySemanticOption
* yyoptionList
, yyGLRStack
* yystack
,
1430 YYSTYPE
* yyvalp
, YYLTYPE
* yylocp
]b4_user_formals
[)
1432 yySemanticOption
* yybest
;
1433 yySemanticOption
* yyp
;
1436 yybest
= yyoptionList
;
1438 for (yyp
= yyoptionList
->yynext
; yyp
!= NULL
; yyp
= yyp
->yynext
)
1440 if (yyidenticalOptions (yybest
, yyp
))
1441 yymergeOptionSets (yybest
, yyp
);
1443 switch (yypreference (yybest
, yyp
))
1446 yyreportAmbiguity (yybest
, yyp
, yystack
]b4_pure_args
[);
1462 int yyprec
= yydprec
[yybest
->yyrule
];
1463 YYCHK (yyresolveAction (yybest
, yystack
, yyvalp
, yylocp
]b4_user_args
[));
1464 for (yyp
= yybest
->yynext
; yyp
!= NULL
; yyp
= yyp
->yynext
)
1466 if (yyprec
== yydprec
[yyp
->yyrule
])
1470 YYCHK (yyresolveAction (yyp
, yystack
, &yyval1
, &yydummy
]b4_user_args
[));
1471 *yyvalp
= yyuserMerge (yymerger
[yyp
->yyrule
], yyvalp
, &yyval1
);
1477 return yyresolveAction (yybest
, yystack
, yyvalp
, yylocp
]b4_user_args
[);
1481 yyresolveStack (yyGLRStack
* yystack
]b4_user_formals
[)
1483 if (yystack
->yysplitPoint
!= NULL
)
1488 for (yyn
= 0, yys
= yystack
->yytops
.yystates
[0];
1489 yys
!= yystack
->yysplitPoint
;
1490 yys
= yys
->yypred
, yyn
+= 1)
1492 YYCHK (yyresolveStates (yystack
->yytops
.yystates
[0], yyn
, yystack
1499 yycompressStack (yyGLRStack
* yystack
)
1501 yyGLRState
* yyp
, *yyq
, *yyr
;
1503 if (yystack
->yytops
.yysize
!= 1 || yystack
->yysplitPoint
== NULL
)
1506 for (yyp
= yystack
->yytops
.yystates
[0], yyq
= yyp
->yypred
, yyr
= NULL
;
1507 yyp
!= yystack
->yysplitPoint
;
1508 yyr
= yyp
, yyp
= yyq
, yyq
= yyp
->yypred
)
1511 yystack
->yyspaceLeft
+= yystack
->yynextFree
- yystack
->yyitems
;
1512 yystack
->yynextFree
= ((yyGLRStackItem
*) yystack
->yysplitPoint
) + 1;
1513 yystack
->yyspaceLeft
-= yystack
->yynextFree
- yystack
->yyitems
;
1514 yystack
->yysplitPoint
= NULL
;
1515 yystack
->yylastDeleted
= NULL
;
1519 yystack
->yynextFree
->yystate
= *yyr
;
1521 yystack
->yynextFree
->yystate
.yypred
= & yystack
->yynextFree
[-1].yystate
;
1522 yystack
->yytops
.yystates
[0] = &yystack
->yynextFree
->yystate
;
1523 yystack
->yynextFree
+= 1;
1524 yystack
->yyspaceLeft
-= 1;
1529 yyprocessOneStack (yyGLRStack
* yystack
, int yyk
,
1530 size_t yyposn
, YYSTYPE
* yylvalp
, YYLTYPE
* yyllocp
1534 const short* yyconflicts
;
1536 yySymbol
* const yytokenp
= yystack
->yytokenp
;
1538 while (yystack
->yytops
.yystates
[yyk
] != NULL
)
1540 yyStateNum yystate
= yystack
->yytops
.yystates
[yyk
]->yylrState
;
1541 YYDPRINTF ((stderr
, "Stack %d Entering state %d\n", yyk
, yystate
));
1543 if (yystate
== YYFINAL
)
1545 if (yyisDefaultedState (yystate
))
1547 yyrule
= yydefaultAction (yystate
);
1550 YYDPRINTF ((stderr
, "Stack %d dies.\n", yyk
));
1551 yymarkStackDeleted (yystack
, yyk
);
1554 YYCHK (yyglrReduce (yystack
, yyk
, yyrule
, yyfalse
]b4_lpure_args
[));
1558 if (*yytokenp
== YYEMPTY
)
1560 YYDPRINTF ((stderr
, "Reading a token: "));
1562 *yytokenp
= YYTRANSLATE (yychar
);
1563 YYDSYMPRINTF ("Next token is", *yytokenp
, yylvalp
, yyllocp
);
1565 yygetLRActions (yystate
, *yytokenp
, &yyaction
, &yyconflicts
);
1567 while (*yyconflicts
!= 0)
1569 int yynewStack
= yysplitStack (yystack
, yyk
);
1570 YYDPRINTF ((stderr
, "Splitting off stack %d from %d.\n",
1572 YYCHK (yyglrReduce (yystack
, yynewStack
,
1573 *yyconflicts
, yyfalse
]b4_lpure_args
[));
1574 YYCHK (yyprocessOneStack (yystack
, yynewStack
, yyposn
,
1575 yylvalp
, yyllocp
]b4_user_args
[));
1579 if (yyisShiftAction (yyaction
))
1581 YYDPRINTF ((stderr
, "Shifting token %s on stack %d, ",
1582 yytokenName (*yytokenp
), yyk
));
1583 yyglrShift (yystack
, yyk
, yyaction
, yyposn
+1,
1584 *yylvalp
, yyllocp
]b4_user_args
[);
1585 YYDPRINTF ((stderr
, "which is now in state #%d\n",
1586 yystack
->yytops
.yystates
[yyk
]->yylrState
));
1589 else if (yyisErrorAction (yyaction
))
1591 YYDPRINTF ((stderr
, "Stack %d dies.\n", yyk
));
1592 yymarkStackDeleted (yystack
, yyk
);
1596 YYCHK (yyglrReduce (yystack
, yyk
, -yyaction
, yyfalse
]b4_lpure_args
[));
1603 yyreportSyntaxError (yyGLRStack
* yystack
,
1604 YYSTYPE
* yylvalp
, YYLTYPE
* yyllocp
]b4_user_formals
[)
1606 /* `Unused' warnings. */
1610 if (yystack
->yyerrState
== 0)
1613 yySymbol
* const yytokenp
= yystack
->yytokenp
;
1615 yyn
= yypact
[yystack
->yytops
.yystates
[0]->yylrState
];
1616 if (YYPACT_NINF
< yyn
&& yyn
< YYLAST
)
1619 const char* yyprefix
;
1623 /* Start YYX at -YYN if negative to avoid negative indexes in
1625 int yyxbegin
= yyn
< 0 ? -yyn
: 0;
1627 /* Stay within bounds of both yycheck and yytname. */
1628 int yychecklim
= YYLAST
- yyn
;
1629 int yyxend
= yychecklim
< YYNTOKENS
? yychecklim
: YYNTOKENS
;
1632 yyprefix
= ", expecting ";
1633 for (yyx
= yyxbegin
; yyx
< yyxend
; ++yyx
)
1634 if (yycheck
[yyx
+ yyn
] == yyx
&& yyx
!= YYTERROR
)
1636 yysize
+= strlen (yyprefix
) + strlen (yytokenName (yyx
));
1645 yysize
+= (sizeof ("syntax error, unexpected ")
1646 + strlen (yytokenName (*yytokenp
)));
1647 yymsg
= (char*) malloc (yysize
);
1651 sprintf (yyp
, "syntax error, unexpected %s",
1652 yytokenName (*yytokenp
));
1653 yyp
+= strlen (yyp
);
1656 yyprefix
= ", expecting ";
1657 for (yyx
= yyxbegin
; yyx
< yyxend
; ++yyx
)
1658 if (yycheck
[yyx
+ yyn
] == yyx
&& yyx
!= YYTERROR
)
1660 sprintf (yyp
, "%s%s", yyprefix
, yytokenName (yyx
));
1661 yyp
+= strlen (yyp
);
1665 yyerror (]b4_lyyerror_args
[yymsg
);
1669 yyerror (]b4_lyyerror_args
["syntax error; also virtual memory exhausted");
1672 #endif /* YYERROR_VERBOSE */
1673 yyerror (]b4_lyyerror_args
["syntax error");
1678 /* Recover from a syntax error on YYSTACK, assuming that YYTOKENP,
1679 YYLVALP, and YYLLOCP point to the syntactic category, semantic
1680 value, and location of the lookahead. */
1682 yyrecoverSyntaxError (yyGLRStack
* yystack
,
1683 YYSTYPE
* yylvalp
, YYLTYPE
* yyllocp
]b4_user_formals
[)
1685 yySymbol
* const yytokenp
= yystack
->yytokenp
;
1689 if (yystack
->yyerrState
== 3)
1690 /* We just shifted the error token and (perhaps) took some
1691 reductions. Skip tokens until we can proceed. */
1694 if (*yytokenp
== YYEOF
)
1696 /* Now pop stack until empty and fail. */
1697 while (yystack
->yytops
.yystates
[0] != NULL
)
1699 yyGLRState
*yys
= yystack
->yytops
.yystates
[0];
1700 YYDSYMPRINTF ("Error: popping",
1701 yystos
[yys
->yylrState
],
1702 &yys
->yysemantics
.yysval
, &yys
->yyloc
);
1703 yydestruct (yystos
[yys
->yylrState
],
1704 &yys
->yysemantics
.yysval
]b4_location_if([, &yys
->yyloc
])[);
1705 yystack
->yytops
.yystates
[0] = yys
->yypred
;
1706 yystack
->yynextFree
-= 1;
1707 yystack
->yyspaceLeft
+= 1;
1709 yyFail (yystack
][]b4_lpure_args
[, NULL
);
1711 if (*yytokenp
!= YYEMPTY
)
1713 YYDSYMPRINTF ("Error: discarding", *yytokenp
, yylvalp
, yyllocp
);
1714 yydestruct (*yytokenp
, yylvalp
]b4_location_if([, yyllocp
])[);
1716 YYDPRINTF ((stderr
, "Reading a token: "));
1718 *yytokenp
= YYTRANSLATE (yychar
);
1719 YYDSYMPRINTF ("Next token is", *yytokenp
, yylvalp
, yyllocp
);
1720 yyj
= yypact
[yystack
->yytops
.yystates
[0]->yylrState
];
1721 if (yyis_pact_ninf (yyj
))
1724 if (yyj
< 0 || YYLAST
< yyj
|| yycheck
[yyj
] != *yytokenp
)
1726 if (yydefact
[yystack
->yytops
.yystates
[0]->yylrState
] != 0)
1729 else if (yytable
[yyj
] != 0 && ! yyis_table_ninf (yytable
[yyj
]))
1733 /* Reduce to one stack. */
1734 for (yyk
= 0; yyk
< yystack
->yytops
.yysize
; yyk
+= 1)
1735 if (yystack
->yytops
.yystates
[yyk
] != NULL
)
1737 if (yyk
>= yystack
->yytops
.yysize
)
1738 yyFail (yystack
][]b4_lpure_args
[, NULL
);
1739 for (yyk
+= 1; yyk
< yystack
->yytops
.yysize
; yyk
+= 1)
1740 yymarkStackDeleted (yystack
, yyk
);
1741 yyremoveDeletes (yystack
);
1742 yycompressStack (yystack
);
1744 /* Now pop stack until we find a state that shifts the error token. */
1745 yystack
->yyerrState
= 3;
1746 while (yystack
->yytops
.yystates
[0] != NULL
)
1748 yyGLRState
*yys
= yystack
->yytops
.yystates
[0];
1749 yyj
= yypact
[yys
->yylrState
];
1750 if (! yyis_pact_ninf (yyj
))
1753 if (0 <= yyj
&& yyj
<= YYLAST
&& yycheck
[yyj
] == YYTERROR
1754 && yyisShiftAction (yytable
[yyj
]))
1756 YYDPRINTF ((stderr
, "Shifting error token, "));
1757 yyglrShift (yystack
, 0, yytable
[yyj
],
1758 yys
->yyposn
, *yylvalp
, yyllocp
]b4_user_args
[);
1762 YYDSYMPRINTF ("Error: popping",
1763 yystos
[yys
->yylrState
],
1764 &yys
->yysemantics
.yysval
, &yys
->yyloc
);
1765 yydestruct (yystos
[yys
->yylrState
],
1766 &yys
->yysemantics
.yysval
]b4_location_if([, &yys
->yyloc
])[);
1767 yystack
->yytops
.yystates
[0] = yys
->yypred
;
1768 yystack
->yynextFree
-= 1;
1769 yystack
->yyspaceLeft
+= 1;
1771 if (yystack
->yytops
.yystates
[0] == NULL
)
1772 yyFail (yystack
][]b4_lpure_args
[, NULL
);
1775 #define YYCHK1(YYE) \
1781 yystack.yyerrflag = 1; \
1784 yystack.yyerrflag = 0; \
1787 goto yyuser_error; \
1796 ]b4_c_ansi_function_def([yyparse
], [int], b4_parse_param
)[
1806 #define yychar (yystack.yyrawchar)
1809 YYSTYPE
* const yylvalp
= &yylval
;
1810 YYLTYPE
* const yyllocp
= &yylloc
;
1812 yyinitGLRStack (&yystack
, YYINITDEPTH
);
1813 yystack
.yytokenp
= &yytoken
;
1815 YYDPRINTF ((stderr
, "Starting parse\n"));
1817 if (setjmp (yystack
.yyexception_buffer
) != 0)
1820 yyglrShift (&yystack
, 0, 0, 0, yyval_default
, &yyloc_default
]b4_user_args
[);
1826 /* For efficiency, we have two loops, the first of which is
1827 specialized to deterministic operation (single stack, no
1828 potential ambiguity). */
1834 const short* yyconflicts
;
1836 yyStateNum yystate
= yystack
.yytops
.yystates
[0]->yylrState
;
1837 YYDPRINTF ((stderr
, "Entering state %d\n", yystate
));
1838 if (yystate
== YYFINAL
)
1840 if (yyisDefaultedState (yystate
))
1842 yyrule
= yydefaultAction (yystate
);
1845 yyreportSyntaxError (&yystack
, yylvalp
, yyllocp
]b4_user_args
[);
1848 YYCHK1 (yyglrReduce (&yystack
, 0, yyrule
, yytrue
]b4_lpure_args
[));
1852 if (yytoken
== YYEMPTY
)
1854 YYDPRINTF ((stderr
, "Reading a token: "));
1856 yytoken
= YYTRANSLATE (yychar
);
1857 YYDSYMPRINTF ("Next token is", yytoken
, yylvalp
, yyllocp
);
1859 yygetLRActions (yystate
, yytoken
, &yyaction
, &yyconflicts
);
1860 if (*yyconflicts
!= 0)
1862 if (yyisShiftAction (yyaction
))
1864 YYDPRINTF ((stderr
, "Shifting token %s, ",
1865 yytokenName (yytoken
)));
1866 if (yytoken
!= YYEOF
)
1869 yyglrShift (&yystack
, 0, yyaction
, yyposn
,
1870 yylval
, yyllocp
]b4_user_args
[);
1871 if (0 < yystack
.yyerrState
)
1872 yystack
.yyerrState
-= 1;
1874 else if (yyisErrorAction (yyaction
))
1876 yyreportSyntaxError (&yystack
, yylvalp
, yyllocp
]b4_user_args
[);
1880 YYCHK1 (yyglrReduce (&yystack
, 0, -yyaction
, yytrue
]b4_lpure_args
[));
1887 int yyn
= yystack
.yytops
.yysize
;
1888 for (yys
= 0; yys
< yyn
; yys
+= 1)
1889 YYCHK1 (yyprocessOneStack (&yystack
, yys
, yyposn
,
1890 yylvalp
, yyllocp
]b4_user_args
[));
1893 yyremoveDeletes (&yystack
);
1894 if (yystack
.yytops
.yysize
== 0)
1896 yyundeleteLastStack (&yystack
);
1897 if (yystack
.yytops
.yysize
== 0)
1898 yyFail (&yystack
][]b4_lpure_args
[, "syntax error");
1899 YYCHK1 (yyresolveStack (&yystack
]b4_user_args
[));
1900 YYDPRINTF ((stderr
, "Returning to deterministic operation.\n"));
1901 yyreportSyntaxError (&yystack
, yylvalp
, yyllocp
]b4_user_args
[);
1904 else if (yystack
.yytops
.yysize
== 1)
1906 YYCHK1 (yyresolveStack (&yystack
]b4_user_args
[));
1907 YYDPRINTF ((stderr
, "Returning to deterministic operation.\n"));
1908 yycompressStack (&yystack
);
1914 yyrecoverSyntaxError (&yystack
, yylvalp
, yyllocp
]b4_user_args
[);
1915 yyposn
= yystack
.yytops
.yystates
[0]->yyposn
;
1920 yyfreeGLRStack (&yystack
);
1921 return yystack
.yyerrflag
;
1924 /* DEBUGGING ONLY */
1925 static void yypstack (yyGLRStack
* yystack
, int yyk
) ATTRIBUTE_UNUSED
;
1926 static void yypdumpstack (yyGLRStack
* yystack
) ATTRIBUTE_UNUSED
;
1929 yy_yypstack (yyGLRState
* yys
)
1933 yy_yypstack (yys
->yypred
);
1934 fprintf (stderr
, " -> ");
1936 fprintf (stderr
, "%d@@%lu", yys
->yylrState
, (unsigned long) yys
->yyposn
);
1940 yypstates (yyGLRState
* yyst
)
1943 fprintf (stderr
, "<null>");
1946 fprintf (stderr
, "\n");
1950 yypstack (yyGLRStack
* yystack
, int yyk
)
1952 yypstates (yystack
->yytops
.yystates
[yyk
]);
1955 #define YYINDEX(YYX) \
1956 ((YYX) == NULL ? -1 : (yyGLRStackItem*) (YYX) - yystack->yyitems)
1960 yypdumpstack (yyGLRStack
* yystack
)
1962 yyGLRStackItem
* yyp
;
1964 for (yyp
= yystack
->yyitems
; yyp
< yystack
->yynextFree
; yyp
+= 1)
1966 fprintf (stderr
, "%3lu. ", (unsigned long) (yyp
- yystack
->yyitems
));
1967 if (*(yybool
*) yyp
)
1969 fprintf (stderr
, "Res: %d, LR State: %d, posn: %lu, pred: %ld",
1970 yyp
->yystate
.yyresolved
, yyp
->yystate
.yylrState
,
1971 (unsigned long) yyp
->yystate
.yyposn
,
1972 (long) YYINDEX (yyp
->yystate
.yypred
));
1973 if (! yyp
->yystate
.yyresolved
)
1974 fprintf (stderr
, ", firstVal: %ld",
1975 (long) YYINDEX (yyp
->yystate
.yysemantics
.yyfirstVal
));
1979 fprintf (stderr
, "Option. rule: %d, state: %ld, next: %ld",
1980 yyp
->yyoption
.yyrule
,
1981 (long) YYINDEX (yyp
->yyoption
.yystate
),
1982 (long) YYINDEX (yyp
->yyoption
.yynext
));
1984 fprintf (stderr
, "\n");
1986 fprintf (stderr
, "Tops:");
1987 for (yyi
= 0; yyi
< yystack
->yytops
.yysize
; yyi
+= 1)
1988 fprintf (stderr
, "%lu: %ld; ", (unsigned long) yyi
,
1989 (long) YYINDEX (yystack
->yytops
.yystates
[yyi
]));
1990 fprintf (stderr
, "\n");
1995 m4_if(b4_defines_flag
, 0, [],
1996 [@output @output_header_name@
1997 b4_copyright([Skeleton parser
for GLR parsing with Bison
], [2002, 2003])
1999 b4_token_defines(b4_tokens
)
2001 #if ! defined (YYSTYPE) && ! defined (YYSTYPE_IS_DECLARED)
2002 m4_ifdef([b4_stype
],
2003 [b4_syncline([b4_stype_line
], [b4_filename
])
2004 typedef union m4_bregexp(b4_stype
, [^{], [YYSTYPE
])b4_stype YYSTYPE
;
2005 /* Line __line__ of glr.c. */
2006 b4_syncline([@oline@
], [@ofile@
])],
2007 [typedef int YYSTYPE
;])
2008 # define YYSTYPE_IS_DECLARED 1
2009 # define YYSTYPE_IS_TRIVIAL 1
2013 [extern YYSTYPE b4_prefix
[]lval
;])
2015 #if ! defined (YYLTYPE) && ! defined (YYLTYPE_IS_DECLARED)
2016 typedef struct YYLTYPE
2027 # define YYLTYPE_IS_DECLARED 1
2028 # define YYLTYPE_IS_TRIVIAL 1
2031 b4_location_if([m4_if(b4_pure
, [0],
2032 [extern YYLTYPE b4_prefix
[]lloc
;])