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)
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 %d -> %d.\n", yyi
, yyj
));
1030 /** Shift to a new state on stack #K of STACK, corresponding to LR state
1031 * LRSTATE, at input position POSN, with (resolved) semantic value SVAL. */
1033 yyglrShift (yyGLRStack
* yystack
, int yyk
, yyStateNum yylrState
, size_t yyposn
,
1034 YYSTYPE yysval
, YYLTYPE
* yylocp
]b4_user_formals
[)
1036 yyGLRStackItem
* yynewItem
;
1038 yynewItem
= yystack
->yynextFree
;
1039 yystack
->yynextFree
+= 1;
1040 yystack
->yyspaceLeft
-= 1;
1041 yynewItem
->yystate
.yyisState
= yytrue
;
1042 yynewItem
->yystate
.yylrState
= yylrState
;
1043 yynewItem
->yystate
.yyposn
= yyposn
;
1044 yynewItem
->yystate
.yyresolved
= yytrue
;
1045 yynewItem
->yystate
.yypred
= yystack
->yytops
.yystates
[yyk
];
1046 yystack
->yytops
.yystates
[yyk
] = &yynewItem
->yystate
;
1047 yynewItem
->yystate
.yysemantics
.yysval
= yysval
;
1048 yynewItem
->yystate
.yyloc
= *yylocp
;
1049 if (yystack
->yyspaceLeft
< YYHEADROOM
)
1050 yyexpandGLRStack (yystack
]b4_pure_args
[);
1053 /** Shift stack #K of YYSTACK, to a new state corresponding to LR
1054 * state YYLRSTATE, at input position YYPOSN, with the (unresolved)
1055 * semantic value of YYRHS under the action for YYRULE. */
1057 yyglrShiftDefer (yyGLRStack
* yystack
, int yyk
, yyStateNum yylrState
,
1058 size_t yyposn
, yyGLRState
* rhs
, yyRuleNum yyrule
]b4_pure_formals
[)
1060 yyGLRStackItem
* yynewItem
;
1062 yynewItem
= yystack
->yynextFree
;
1063 yynewItem
->yystate
.yyisState
= yytrue
;
1064 yynewItem
->yystate
.yylrState
= yylrState
;
1065 yynewItem
->yystate
.yyposn
= yyposn
;
1066 yynewItem
->yystate
.yyresolved
= yyfalse
;
1067 yynewItem
->yystate
.yypred
= yystack
->yytops
.yystates
[yyk
];
1068 yynewItem
->yystate
.yysemantics
.yyfirstVal
= NULL
;
1069 yystack
->yytops
.yystates
[yyk
] = &yynewItem
->yystate
;
1070 yystack
->yynextFree
+= 1;
1071 yystack
->yyspaceLeft
-= 1;
1072 yyaddDeferredAction (yystack
, &yynewItem
->yystate
, rhs
, yyrule
]b4_pure_args
[);
1075 /** Pop the symbols consumed by reduction #RULE from the top of stack
1076 * #K of STACK, and perform the appropriate semantic action on their
1077 * semantic values. Assumes that all ambiguities in semantic values
1078 * have been previously resolved. Set *VALP to the resulting value,
1079 * and *LOCP to the computed location (if any). Return value is as
1080 * for userAction. */
1081 static inline YYRESULTTAG
1082 yydoAction (yyGLRStack
* yystack
, int yyk
, yyRuleNum yyrule
,
1083 YYSTYPE
* yyvalp
, YYLTYPE
* yylocp
]b4_user_formals
[)
1085 int yynrhs
= yyrhsLength (yyrule
);
1087 if (yystack
->yysplitPoint
== NULL
)
1089 /* Standard special case: single stack. */
1090 yyGLRStackItem
* rhs
= (yyGLRStackItem
*) yystack
->yytops
.yystates
[yyk
];
1093 yystack
->yynextFree
-= yynrhs
;
1094 yystack
->yyspaceLeft
+= yynrhs
;
1095 yystack
->yytops
.yystates
[0] = & yystack
->yynextFree
[-1].yystate
;
1096 return yyuserAction (yyrule
, yynrhs
, rhs
,
1097 yyvalp
, yylocp
, yystack
]b4_user_args
[);
1103 yyGLRStackItem yyrhsVals
[YYMAXRHS
+ YYMAXLEFT
+ 1];
1104 yys
= yyrhsVals
[YYMAXRHS
+ YYMAXLEFT
].yystate
.yypred
1105 = yystack
->yytops
.yystates
[yyk
];
1106 for (yyi
= 0; yyi
< yynrhs
; yyi
+= 1)
1112 yyupdateSplit (yystack
, yys
);
1113 yystack
->yytops
.yystates
[yyk
] = yys
;
1114 return yyuserAction (yyrule
, yynrhs
, yyrhsVals
+ YYMAXRHS
+ YYMAXLEFT
- 1,
1115 yyvalp
, yylocp
, yystack
]b4_user_args
[);
1120 # define YY_REDUCE_PRINT(K, Rule)
1122 # define YY_REDUCE_PRINT(K, Rule) \
1125 yy_reduce_print (K, Rule); \
1128 /*----------------------------------------------------------.
1129 | Report that the RULE is going to be reduced on stack #K. |
1130 `----------------------------------------------------------*/
1133 yy_reduce_print (size_t yyk
, yyRuleNum yyrule
)
1136 unsigned int yylno
= yyrline
[yyrule
];
1137 YYFPRINTF (stderr
, "Reducing stack %d by rule %d (line %u), ",
1138 yyk
, yyrule
- 1, yylno
);
1139 /* Print the symbols being reduced, and their result. */
1140 for (yyi
= yyprhs
[yyrule
]; 0 <= yyrhs
[yyi
]; yyi
++)
1141 YYFPRINTF (stderr
, "%s ", yytokenName (yyrhs
[yyi
]));
1142 YYFPRINTF (stderr
, "-> %s\n", yytokenName (yyr1
[yyrule
]));
1146 /** Pop items off stack #K of STACK according to grammar rule RULE,
1147 * and push back on the resulting nonterminal symbol. Perform the
1148 * semantic action associated with RULE and store its value with the
1149 * newly pushed state, if FORCEEVAL or if STACK is currently
1150 * unambiguous. Otherwise, store the deferred semantic action with
1151 * the new state. If the new state would have an identical input
1152 * position, LR state, and predecessor to an existing state on the stack,
1153 * it is identified with that existing state, eliminating stack #K from
1154 * the STACK. In this case, the (necessarily deferred) semantic value is
1155 * added to the options for the existing state's semantic value.
1157 static inline YYRESULTTAG
1158 yyglrReduce (yyGLRStack
* yystack
, size_t yyk
, yyRuleNum yyrule
,
1159 yybool yyforceEval
]b4_pure_formals
[)
1161 size_t yyposn
= yystack
->yytops
.yystates
[yyk
]->yyposn
;
1163 if (yyforceEval
|| yystack
->yysplitPoint
== NULL
)
1168 YY_REDUCE_PRINT (yyk
, yyrule
);
1169 YYCHK (yydoAction (yystack
, yyk
, yyrule
, &yysval
, &yyloc
]b4_user_args
[));
1170 yyglrShift (yystack
, yyk
,
1171 yyLRgotoState (yystack
->yytops
.yystates
[yyk
]->yylrState
,
1172 yylhsNonterm (yyrule
)),
1173 yyposn
, yysval
, &yyloc
]b4_user_args
[);
1179 yyGLRState
* yys
, *yys0
= yystack
->yytops
.yystates
[yyk
];
1180 yyStateNum yynewLRState
;
1182 for (yys
= yystack
->yytops
.yystates
[yyk
], yyn
= yyrhsLength (yyrule
);
1189 yyupdateSplit (yystack
, yys
);
1190 yynewLRState
= yyLRgotoState (yys
->yylrState
, yylhsNonterm (yyrule
));
1192 "Reduced stack %d by rule #%d; action deferred. "
1193 "Now in state %d.\n",
1194 yyk
, yyrule
-1, yynewLRState
));
1195 for (yyi
= 0; yyi
< yystack
->yytops
.yysize
; yyi
+= 1)
1196 if (yyi
!= yyk
&& yystack
->yytops
.yystates
[yyi
] != NULL
)
1198 yyGLRState
* yyp
, *yysplit
= yystack
->yysplitPoint
;
1199 yyp
= yystack
->yytops
.yystates
[yyi
];
1200 while (yyp
!= yys
&& yyp
!= yysplit
&& yyp
->yyposn
>= yyposn
)
1202 if (yyp
->yylrState
== yynewLRState
&& yyp
->yypred
== yys
)
1204 yyaddDeferredAction (yystack
, yyp
, yys0
, yyrule
]b4_pure_args
[);
1205 yymarkStackDeleted (yystack
, yyk
);
1206 YYDPRINTF ((stderr
, "Merging stack %d into stack %d.\n",
1213 yystack
->yytops
.yystates
[yyk
] = yys
;
1214 yyglrShiftDefer (yystack
, yyk
, yynewLRState
, yyposn
, yys0
, yyrule
]b4_pure_args
[);
1220 yysplitStack (yyGLRStack
* yystack
, int yyk
)
1222 if (yystack
->yysplitPoint
== NULL
)
1226 yystack
->yysplitPoint
= yystack
->yytops
.yystates
[yyk
];
1228 if (yystack
->yytops
.yysize
>= yystack
->yytops
.yycapacity
)
1230 yystack
->yytops
.yycapacity
*= 2;
1231 yystack
->yytops
.yystates
=
1232 (yyGLRState
**) realloc (yystack
->yytops
.yystates
,
1233 yystack
->yytops
.yycapacity
1234 * sizeof (yyGLRState
*));
1236 yystack
->yytops
.yystates
[yystack
->yytops
.yysize
]
1237 = yystack
->yytops
.yystates
[yyk
];
1238 yystack
->yytops
.yysize
+= 1;
1239 return yystack
->yytops
.yysize
-1;
1242 /** True iff Y0 and Y1 represent identical options at the top level.
1243 * That is, they represent the same rule applied to RHS symbols
1244 * that produce the same terminal symbols. */
1246 yyidenticalOptions (yySemanticOption
* yyy0
, yySemanticOption
* yyy1
)
1248 if (yyy0
->yyrule
== yyy1
->yyrule
)
1250 yyGLRState
*yys0
, *yys1
;
1252 for (yys0
= yyy0
->yystate
, yys1
= yyy1
->yystate
,
1253 yyn
= yyrhsLength (yyy0
->yyrule
);
1255 yys0
= yys0
->yypred
, yys1
= yys1
->yypred
, yyn
-= 1)
1256 if (yys0
->yyposn
!= yys1
->yyposn
)
1264 /** Assuming identicalOptions (Y0,Y1), (destructively) merge the
1265 * alternative semantic values for the RHS-symbols of Y1 into the
1266 * corresponding semantic value sets of the symbols of Y0. */
1268 yymergeOptionSets (yySemanticOption
* yyy0
, yySemanticOption
* yyy1
)
1270 yyGLRState
*yys0
, *yys1
;
1272 for (yys0
= yyy0
->yystate
, yys1
= yyy1
->yystate
,
1273 yyn
= yyrhsLength (yyy0
->yyrule
);
1275 yys0
= yys0
->yypred
, yys1
= yys1
->yypred
, yyn
-= 1)
1278 else if (! yys0
->yyresolved
&& ! yys1
->yyresolved
)
1280 yySemanticOption
* yyz
;
1281 for (yyz
= yys0
->yysemantics
.yyfirstVal
; yyz
->yynext
!= NULL
;
1284 yyz
->yynext
= yys1
->yysemantics
.yyfirstVal
;
1288 /** Y0 and Y1 represent two possible actions to take in a given
1289 * parsing state; return 0 if no combination is possible,
1290 * 1 if user-mergeable, 2 if Y0 is preferred, 3 if Y1 is preferred. */
1292 yypreference (yySemanticOption
* y0
, yySemanticOption
* y1
)
1294 yyRuleNum r0
= y0
->yyrule
, r1
= y1
->yyrule
;
1295 int p0
= yydprec
[r0
], p1
= yydprec
[r1
];
1299 if (yymerger
[r0
] == 0 || yymerger
[r0
] != yymerger
[r1
])
1304 if (p0
== 0 || p1
== 0)
1313 static YYRESULTTAG
yyresolveValue (yySemanticOption
* yyoptionList
,
1314 yyGLRStack
* yystack
, YYSTYPE
* yyvalp
,
1315 YYLTYPE
* yylocp
]b4_user_formals
[);
1318 yyresolveStates (yyGLRState
* yys
, int yyn
, yyGLRStack
* yystack
]b4_user_formals
[)
1323 if (yys
->yypred
== NULL
)
1325 yyflag
= yyresolveStates (yys
->yypred
, yyn
-1, yystack
]b4_user_args
[);
1328 if (! yys
->yyresolved
)
1330 yyflag
= yyresolveValue (yys
->yysemantics
.yyfirstVal
, yystack
,
1331 &yys
->yysemantics
.yysval
, &yys
->yyloc
1335 yys
->yyresolved
= yytrue
;
1342 yyresolveAction (yySemanticOption
* yyopt
, yyGLRStack
* yystack
,
1343 YYSTYPE
* yyvalp
, YYLTYPE
* yylocp
]b4_user_formals
[)
1345 yyGLRStackItem yyrhsVals
[YYMAXRHS
+ YYMAXLEFT
+ 1];
1348 yynrhs
= yyrhsLength (yyopt
->yyrule
);
1349 YYCHK (yyresolveStates (yyopt
->yystate
, yynrhs
, yystack
]b4_user_args
[));
1350 yyrhsVals
[YYMAXRHS
+ YYMAXLEFT
].yystate
.yypred
= yyopt
->yystate
;
1351 return yyuserAction (yyopt
->yyrule
, yynrhs
,
1352 yyrhsVals
+ YYMAXRHS
+ YYMAXLEFT
- 1,
1353 yyvalp
, yylocp
, yystack
]b4_user_args
[);
1358 yyreportTree (yySemanticOption
* yyx
, int yyindent
)
1360 int yynrhs
= yyrhsLength (yyx
->yyrule
);
1363 yyGLRState
* yystates
[YYMAXRHS
];
1364 yyGLRState yyleftmost_state
;
1366 for (yyi
= yynrhs
, yys
= yyx
->yystate
; 0 < yyi
; yyi
-= 1, yys
= yys
->yypred
)
1367 yystates
[yyi
] = yys
;
1370 yyleftmost_state
.yyposn
= 0;
1371 yystates
[0] = &yyleftmost_state
;
1376 if (yyx
->yystate
->yyposn
< yys
->yyposn
+ 1)
1377 YYFPRINTF (stderr
, "%*s%s -> <Rule %d, empty>\n",
1378 yyindent
, "", yytokenName (yylhsNonterm (yyx
->yyrule
)),
1381 YYFPRINTF (stderr
, "%*s%s -> <Rule %d, tokens %d .. %d>\n",
1382 yyindent
, "", yytokenName (yylhsNonterm (yyx
->yyrule
)),
1383 yyx
->yyrule
, yys
->yyposn
+1, yyx
->yystate
->yyposn
);
1384 for (yyi
= 1; yyi
<= yynrhs
; yyi
+= 1)
1386 if (yystates
[yyi
]->yyresolved
)
1388 if (yystates
[yyi
-1]->yyposn
+1 > yystates
[yyi
]->yyposn
)
1389 YYFPRINTF (stderr
, "%*s%s <empty>\n", yyindent
+2, "",
1390 yytokenName (yyrhs
[yyprhs
[yyx
->yyrule
]+yyi
-1]));
1392 YYFPRINTF (stderr
, "%*s%s <tokens %d .. %d>\n", yyindent
+2, "",
1393 yytokenName (yyrhs
[yyprhs
[yyx
->yyrule
]+yyi
-1]),
1394 yystates
[yyi
-1]->yyposn
+1, yystates
[yyi
]->yyposn
);
1397 yyreportTree (yystates
[yyi
]->yysemantics
.yyfirstVal
, yyindent
+2);
1403 yyreportAmbiguity (yySemanticOption
* yyx0
, yySemanticOption
* yyx1
,
1404 yyGLRStack
* yystack
]b4_pure_formals
[)
1406 /* `Unused' warnings. */
1411 YYFPRINTF (stderr
, "Ambiguity detected.\n");
1412 YYFPRINTF (stderr
, "Option 1,\n");
1413 yyreportTree (yyx0
, 2);
1414 YYFPRINTF (stderr
, "\nOption 2,\n");
1415 yyreportTree (yyx1
, 2);
1416 YYFPRINTF (stderr
, "\n");
1418 yyFail (yystack
][]b4_pure_args
[, "ambiguity detected");
1422 /** Resolve the ambiguity represented by OPTIONLIST, perform the indicated
1423 * actions, and return the result. */
1425 yyresolveValue (yySemanticOption
* yyoptionList
, yyGLRStack
* yystack
,
1426 YYSTYPE
* yyvalp
, YYLTYPE
* yylocp
]b4_user_formals
[)
1428 yySemanticOption
* yybest
;
1429 yySemanticOption
* yyp
;
1432 yybest
= yyoptionList
;
1434 for (yyp
= yyoptionList
->yynext
; yyp
!= NULL
; yyp
= yyp
->yynext
)
1436 if (yyidenticalOptions (yybest
, yyp
))
1437 yymergeOptionSets (yybest
, yyp
);
1439 switch (yypreference (yybest
, yyp
))
1442 yyreportAmbiguity (yybest
, yyp
, yystack
]b4_pure_args
[);
1458 int yyprec
= yydprec
[yybest
->yyrule
];
1459 YYCHK (yyresolveAction (yybest
, yystack
, yyvalp
, yylocp
]b4_user_args
[));
1460 for (yyp
= yybest
->yynext
; yyp
!= NULL
; yyp
= yyp
->yynext
)
1462 if (yyprec
== yydprec
[yyp
->yyrule
])
1466 YYCHK (yyresolveAction (yyp
, yystack
, &yyval1
, &yydummy
]b4_user_args
[));
1467 *yyvalp
= yyuserMerge (yymerger
[yyp
->yyrule
], yyvalp
, &yyval1
);
1473 return yyresolveAction (yybest
, yystack
, yyvalp
, yylocp
]b4_user_args
[);
1477 yyresolveStack (yyGLRStack
* yystack
]b4_user_formals
[)
1479 if (yystack
->yysplitPoint
!= NULL
)
1484 for (yyn
= 0, yys
= yystack
->yytops
.yystates
[0];
1485 yys
!= yystack
->yysplitPoint
;
1486 yys
= yys
->yypred
, yyn
+= 1)
1488 YYCHK (yyresolveStates (yystack
->yytops
.yystates
[0], yyn
, yystack
1495 yycompressStack (yyGLRStack
* yystack
)
1497 yyGLRState
* yyp
, *yyq
, *yyr
;
1499 if (yystack
->yytops
.yysize
!= 1 || yystack
->yysplitPoint
== NULL
)
1502 for (yyp
= yystack
->yytops
.yystates
[0], yyq
= yyp
->yypred
, yyr
= NULL
;
1503 yyp
!= yystack
->yysplitPoint
;
1504 yyr
= yyp
, yyp
= yyq
, yyq
= yyp
->yypred
)
1507 yystack
->yyspaceLeft
+= yystack
->yynextFree
- yystack
->yyitems
;
1508 yystack
->yynextFree
= ((yyGLRStackItem
*) yystack
->yysplitPoint
) + 1;
1509 yystack
->yyspaceLeft
-= yystack
->yynextFree
- yystack
->yyitems
;
1510 yystack
->yysplitPoint
= NULL
;
1511 yystack
->yylastDeleted
= NULL
;
1515 yystack
->yynextFree
->yystate
= *yyr
;
1517 yystack
->yynextFree
->yystate
.yypred
= & yystack
->yynextFree
[-1].yystate
;
1518 yystack
->yytops
.yystates
[0] = &yystack
->yynextFree
->yystate
;
1519 yystack
->yynextFree
+= 1;
1520 yystack
->yyspaceLeft
-= 1;
1525 yyprocessOneStack (yyGLRStack
* yystack
, int yyk
,
1526 size_t yyposn
, YYSTYPE
* yylvalp
, YYLTYPE
* yyllocp
1530 const short* yyconflicts
;
1532 yySymbol
* const yytokenp
= yystack
->yytokenp
;
1534 while (yystack
->yytops
.yystates
[yyk
] != NULL
)
1536 yyStateNum yystate
= yystack
->yytops
.yystates
[yyk
]->yylrState
;
1537 YYDPRINTF ((stderr
, "Stack %d Entering state %d\n", yyk
, yystate
));
1539 if (yystate
== YYFINAL
)
1541 if (yyisDefaultedState (yystate
))
1543 yyrule
= yydefaultAction (yystate
);
1546 YYDPRINTF ((stderr
, "Stack %d dies.\n", yyk
));
1547 yymarkStackDeleted (yystack
, yyk
);
1550 YYCHK (yyglrReduce (yystack
, yyk
, yyrule
, yyfalse
]b4_lpure_args
[));
1554 if (*yytokenp
== YYEMPTY
)
1556 YYDPRINTF ((stderr
, "Reading a token: "));
1558 *yytokenp
= YYTRANSLATE (yychar
);
1559 YYDSYMPRINTF ("Next token is", *yytokenp
, yylvalp
, yyllocp
);
1561 yygetLRActions (yystate
, *yytokenp
, &yyaction
, &yyconflicts
);
1563 while (*yyconflicts
!= 0)
1565 int yynewStack
= yysplitStack (yystack
, yyk
);
1566 YYDPRINTF ((stderr
, "Splitting off stack %d from %d.\n",
1568 YYCHK (yyglrReduce (yystack
, yynewStack
,
1569 *yyconflicts
, yyfalse
]b4_lpure_args
[));
1570 YYCHK (yyprocessOneStack (yystack
, yynewStack
, yyposn
,
1571 yylvalp
, yyllocp
]b4_user_args
[));
1575 if (yyisShiftAction (yyaction
))
1577 YYDPRINTF ((stderr
, "Shifting token %s on stack %d, ",
1578 yytokenName (*yytokenp
), yyk
));
1579 yyglrShift (yystack
, yyk
, yyaction
, yyposn
+1,
1580 *yylvalp
, yyllocp
]b4_user_args
[);
1581 YYDPRINTF ((stderr
, "which is now in state #%d\n",
1582 yystack
->yytops
.yystates
[yyk
]->yylrState
));
1585 else if (yyisErrorAction (yyaction
))
1587 YYDPRINTF ((stderr
, "Stack %d dies.\n", yyk
));
1588 yymarkStackDeleted (yystack
, yyk
);
1592 YYCHK (yyglrReduce (yystack
, yyk
, -yyaction
, yyfalse
]b4_lpure_args
[));
1599 yyreportSyntaxError (yyGLRStack
* yystack
,
1600 YYSTYPE
* yylvalp
, YYLTYPE
* yyllocp
]b4_user_formals
[)
1602 /* `Unused' warnings. */
1606 if (yystack
->yyerrState
== 0)
1609 yySymbol
* const yytokenp
= yystack
->yytokenp
;
1611 yyn
= yypact
[yystack
->yytops
.yystates
[0]->yylrState
];
1612 if (YYPACT_NINF
< yyn
&& yyn
< YYLAST
)
1615 const char* yyprefix
;
1619 /* Start YYX at -YYN if negative to avoid negative indexes in
1621 int yyxbegin
= yyn
< 0 ? -yyn
: 0;
1623 /* Stay within bounds of both yycheck and yytname. */
1624 int yychecklim
= YYLAST
- yyn
;
1625 int yyxend
= yychecklim
< YYNTOKENS
? yychecklim
: YYNTOKENS
;
1628 yyprefix
= ", expecting ";
1629 for (yyx
= yyxbegin
; yyx
< yyxend
; ++yyx
)
1630 if (yycheck
[yyx
+ yyn
] == yyx
&& yyx
!= YYTERROR
)
1632 yysize
+= strlen (yyprefix
) + strlen (yytokenName (yyx
));
1641 yysize
+= (sizeof ("syntax error, unexpected ")
1642 + strlen (yytokenName (*yytokenp
)));
1643 yymsg
= (char*) malloc (yysize
);
1647 sprintf (yyp
, "syntax error, unexpected %s",
1648 yytokenName (*yytokenp
));
1649 yyp
+= strlen (yyp
);
1652 yyprefix
= ", expecting ";
1653 for (yyx
= yyxbegin
; yyx
< yyxend
; ++yyx
)
1654 if (yycheck
[yyx
+ yyn
] == yyx
&& yyx
!= YYTERROR
)
1656 sprintf (yyp
, "%s%s", yyprefix
, yytokenName (yyx
));
1657 yyp
+= strlen (yyp
);
1661 yyerror (]b4_lyyerror_args
[yymsg
);
1665 yyerror (]b4_lyyerror_args
["syntax error; also virtual memory exhausted");
1668 #endif /* YYERROR_VERBOSE */
1669 yyerror (]b4_lyyerror_args
["syntax error");
1674 /* Recover from a syntax error on YYSTACK, assuming that YYTOKENP,
1675 YYLVALP, and YYLLOCP point to the syntactic category, semantic
1676 value, and location of the lookahead. */
1678 yyrecoverSyntaxError (yyGLRStack
* yystack
,
1679 YYSTYPE
* yylvalp
, YYLTYPE
* yyllocp
]b4_user_formals
[)
1681 yySymbol
* const yytokenp
= yystack
->yytokenp
;
1685 if (yystack
->yyerrState
== 3)
1686 /* We just shifted the error token and (perhaps) took some
1687 reductions. Skip tokens until we can proceed. */
1690 if (*yytokenp
== YYEOF
)
1692 /* Now pop stack until empty and fail. */
1693 while (yystack
->yytops
.yystates
[0] != NULL
)
1695 yyGLRState
*yys
= yystack
->yytops
.yystates
[0];
1696 YYDSYMPRINTF ("Error: popping",
1697 yystos
[yys
->yylrState
],
1698 &yys
->yysemantics
.yysval
, &yys
->yyloc
);
1699 yydestruct (yystos
[yys
->yylrState
],
1700 &yys
->yysemantics
.yysval
]b4_location_if([, &yys
->yyloc
])[);
1701 yystack
->yytops
.yystates
[0] = yys
->yypred
;
1702 yystack
->yynextFree
-= 1;
1703 yystack
->yyspaceLeft
+= 1;
1705 yyFail (yystack
][]b4_lpure_args
[, NULL
);
1707 if (*yytokenp
!= YYEMPTY
)
1709 YYDSYMPRINTF ("Error: discarding", *yytokenp
, yylvalp
, yyllocp
);
1710 yydestruct (*yytokenp
, yylvalp
]b4_location_if([, yyllocp
])[);
1712 YYDPRINTF ((stderr
, "Reading a token: "));
1714 *yytokenp
= YYTRANSLATE (yychar
);
1715 YYDSYMPRINTF ("Next token is", *yytokenp
, yylvalp
, yyllocp
);
1716 yyj
= yypact
[yystack
->yytops
.yystates
[0]->yylrState
];
1717 if (yyis_pact_ninf (yyj
))
1720 if (yyj
< 0 || YYLAST
< yyj
|| yycheck
[yyj
] != *yytokenp
)
1722 if (yydefact
[yystack
->yytops
.yystates
[0]->yylrState
] != 0)
1725 else if (yytable
[yyj
] != 0 && ! yyis_table_ninf (yytable
[yyj
]))
1729 /* Reduce to one stack. */
1730 for (yyk
= 0; yyk
< yystack
->yytops
.yysize
; yyk
+= 1)
1731 if (yystack
->yytops
.yystates
[yyk
] != NULL
)
1733 if (yyk
>= yystack
->yytops
.yysize
)
1734 yyFail (yystack
][]b4_lpure_args
[, NULL
);
1735 for (yyk
+= 1; yyk
< yystack
->yytops
.yysize
; yyk
+= 1)
1736 yymarkStackDeleted (yystack
, yyk
);
1737 yyremoveDeletes (yystack
);
1738 yycompressStack (yystack
);
1740 /* Now pop stack until we find a state that shifts the error token. */
1741 yystack
->yyerrState
= 3;
1742 while (yystack
->yytops
.yystates
[0] != NULL
)
1744 yyGLRState
*yys
= yystack
->yytops
.yystates
[0];
1745 yyj
= yypact
[yys
->yylrState
];
1746 if (! yyis_pact_ninf (yyj
))
1749 if (0 <= yyj
&& yyj
<= YYLAST
&& yycheck
[yyj
] == YYTERROR
1750 && yyisShiftAction (yytable
[yyj
]))
1752 YYDPRINTF ((stderr
, "Shifting error token, "));
1753 yyglrShift (yystack
, 0, yytable
[yyj
],
1754 yys
->yyposn
, *yylvalp
, yyllocp
]b4_user_args
[);
1758 YYDSYMPRINTF ("Error: popping",
1759 yystos
[yys
->yylrState
],
1760 &yys
->yysemantics
.yysval
, &yys
->yyloc
);
1761 yydestruct (yystos
[yys
->yylrState
],
1762 &yys
->yysemantics
.yysval
]b4_location_if([, &yys
->yyloc
])[);
1763 yystack
->yytops
.yystates
[0] = yys
->yypred
;
1764 yystack
->yynextFree
-= 1;
1765 yystack
->yyspaceLeft
+= 1;
1767 if (yystack
->yytops
.yystates
[0] == NULL
)
1768 yyFail (yystack
][]b4_lpure_args
[, NULL
);
1771 #define YYCHK1(YYE) \
1777 yystack.yyerrflag = 1; \
1780 yystack.yyerrflag = 0; \
1783 goto yyuser_error; \
1792 ]b4_c_ansi_function_def([yyparse
], [int], b4_parse_param
)[
1802 #define yychar (yystack.yyrawchar)
1805 YYSTYPE
* const yylvalp
= &yylval
;
1806 YYLTYPE
* const yyllocp
= &yylloc
;
1808 yyinitGLRStack (&yystack
, YYINITDEPTH
);
1809 yystack
.yytokenp
= &yytoken
;
1811 YYDPRINTF ((stderr
, "Starting parse\n"));
1813 if (setjmp (yystack
.yyexception_buffer
) != 0)
1816 yyglrShift (&yystack
, 0, 0, 0, yyval_default
, &yyloc_default
]b4_user_args
[);
1822 /* For efficiency, we have two loops, the first of which is
1823 specialized to deterministic operation (single stack, no
1824 potential ambiguity). */
1830 const short* yyconflicts
;
1832 yyStateNum yystate
= yystack
.yytops
.yystates
[0]->yylrState
;
1833 YYDPRINTF ((stderr
, "Entering state %d\n", yystate
));
1834 if (yystate
== YYFINAL
)
1836 if (yyisDefaultedState (yystate
))
1838 yyrule
= yydefaultAction (yystate
);
1841 yyreportSyntaxError (&yystack
, yylvalp
, yyllocp
]b4_user_args
[);
1844 YYCHK1 (yyglrReduce (&yystack
, 0, yyrule
, yytrue
]b4_lpure_args
[));
1848 if (yytoken
== YYEMPTY
)
1850 YYDPRINTF ((stderr
, "Reading a token: "));
1852 yytoken
= YYTRANSLATE (yychar
);
1853 YYDSYMPRINTF ("Next token is", yytoken
, yylvalp
, yyllocp
);
1855 yygetLRActions (yystate
, yytoken
, &yyaction
, &yyconflicts
);
1856 if (*yyconflicts
!= 0)
1858 if (yyisShiftAction (yyaction
))
1860 YYDPRINTF ((stderr
, "Shifting token %s, ",
1861 yytokenName (yytoken
)));
1862 if (yytoken
!= YYEOF
)
1865 yyglrShift (&yystack
, 0, yyaction
, yyposn
,
1866 yylval
, yyllocp
]b4_user_args
[);
1867 if (0 < yystack
.yyerrState
)
1868 yystack
.yyerrState
-= 1;
1870 else if (yyisErrorAction (yyaction
))
1872 yyreportSyntaxError (&yystack
, yylvalp
, yyllocp
]b4_user_args
[);
1876 YYCHK1 (yyglrReduce (&yystack
, 0, -yyaction
, yytrue
]b4_lpure_args
[));
1883 int yyn
= yystack
.yytops
.yysize
;
1884 for (yys
= 0; yys
< yyn
; yys
+= 1)
1885 YYCHK1 (yyprocessOneStack (&yystack
, yys
, yyposn
,
1886 yylvalp
, yyllocp
]b4_user_args
[));
1889 yyremoveDeletes (&yystack
);
1890 if (yystack
.yytops
.yysize
== 0)
1892 yyundeleteLastStack (&yystack
);
1893 if (yystack
.yytops
.yysize
== 0)
1894 yyFail (&yystack
][]b4_lpure_args
[, "syntax error");
1895 YYCHK1 (yyresolveStack (&yystack
]b4_user_args
[));
1896 YYDPRINTF ((stderr
, "Returning to deterministic operation.\n"));
1897 yyreportSyntaxError (&yystack
, yylvalp
, yyllocp
]b4_user_args
[);
1900 else if (yystack
.yytops
.yysize
== 1)
1902 YYCHK1 (yyresolveStack (&yystack
]b4_user_args
[));
1903 YYDPRINTF ((stderr
, "Returning to deterministic operation.\n"));
1904 yycompressStack (&yystack
);
1910 yyrecoverSyntaxError (&yystack
, yylvalp
, yyllocp
]b4_user_args
[);
1911 yyposn
= yystack
.yytops
.yystates
[0]->yyposn
;
1916 yyfreeGLRStack (&yystack
);
1917 return yystack
.yyerrflag
;
1920 /* DEBUGGING ONLY */
1921 static void yypstack (yyGLRStack
* yystack
, int yyk
) ATTRIBUTE_UNUSED
;
1922 static void yypdumpstack (yyGLRStack
* yystack
) ATTRIBUTE_UNUSED
;
1925 yy_yypstack (yyGLRState
* yys
)
1929 yy_yypstack (yys
->yypred
);
1930 fprintf (stderr
, " -> ");
1932 fprintf (stderr
, "%d@@%lu", yys
->yylrState
, (unsigned long) yys
->yyposn
);
1936 yypstates (yyGLRState
* yyst
)
1939 fprintf (stderr
, "<null>");
1942 fprintf (stderr
, "\n");
1946 yypstack (yyGLRStack
* yystack
, int yyk
)
1948 yypstates (yystack
->yytops
.yystates
[yyk
]);
1951 #define YYINDEX(YYX) \
1952 ((YYX) == NULL ? -1 : (yyGLRStackItem*) (YYX) - yystack->yyitems)
1956 yypdumpstack (yyGLRStack
* yystack
)
1958 yyGLRStackItem
* yyp
;
1960 for (yyp
= yystack
->yyitems
; yyp
< yystack
->yynextFree
; yyp
+= 1)
1962 fprintf (stderr
, "%3lu. ", (unsigned long) (yyp
- yystack
->yyitems
));
1963 if (*(yybool
*) yyp
)
1965 fprintf (stderr
, "Res: %d, LR State: %d, posn: %lu, pred: %ld",
1966 yyp
->yystate
.yyresolved
, yyp
->yystate
.yylrState
,
1967 (unsigned long) yyp
->yystate
.yyposn
,
1968 (long) YYINDEX (yyp
->yystate
.yypred
));
1969 if (! yyp
->yystate
.yyresolved
)
1970 fprintf (stderr
, ", firstVal: %ld",
1971 (long) YYINDEX (yyp
->yystate
.yysemantics
.yyfirstVal
));
1975 fprintf (stderr
, "Option. rule: %d, state: %ld, next: %ld",
1976 yyp
->yyoption
.yyrule
,
1977 (long) YYINDEX (yyp
->yyoption
.yystate
),
1978 (long) YYINDEX (yyp
->yyoption
.yynext
));
1980 fprintf (stderr
, "\n");
1982 fprintf (stderr
, "Tops:");
1983 for (yyi
= 0; yyi
< yystack
->yytops
.yysize
; yyi
+= 1)
1984 fprintf (stderr
, "%lu: %ld; ", (unsigned long) yyi
,
1985 (long) YYINDEX (yystack
->yytops
.yystates
[yyi
]));
1986 fprintf (stderr
, "\n");
1991 m4_if(b4_defines_flag
, 0, [],
1992 [@output @output_header_name@
1993 b4_copyright([Skeleton parser
for GLR parsing with Bison
], [2002, 2003])
1995 b4_token_defines(b4_tokens
)
1997 #if ! defined (YYSTYPE) && ! defined (YYSTYPE_IS_DECLARED)
1998 m4_ifdef([b4_stype
],
1999 [b4_syncline([b4_stype_line
], [b4_filename
])
2000 typedef union m4_bregexp(b4_stype
, [^{], [YYSTYPE
])b4_stype YYSTYPE
;
2001 /* Line __line__ of glr.c. */
2002 b4_syncline([@oline@
], [@ofile@
])],
2003 [typedef int YYSTYPE
;])
2004 # define YYSTYPE_IS_DECLARED 1
2005 # define YYSTYPE_IS_TRIVIAL 1
2009 [extern YYSTYPE b4_prefix
[]lval
;])
2011 #if ! defined (YYLTYPE) && ! defined (YYLTYPE_IS_DECLARED)
2012 typedef struct YYLTYPE
2023 # define YYLTYPE_IS_DECLARED 1
2024 # define YYLTYPE_IS_TRIVIAL 1
2027 b4_location_if([m4_if(b4_pure
, [0],
2028 [extern YYLTYPE b4_prefix
[]lloc
;])