1 m4_divert(-1) -*- C
-*-
3 # GLR skeleton for Bison
4 # Copyright (C) 2002, 2003, 2004 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 look-ahead, 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 look-ahead, 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 look-ahead, 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 [((yyGLRStackItem
const *)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 [((yyGLRStackItem
const *)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, 2004])
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 #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) value used for initialization for null
209 right-hand sides. Unlike the standard yacc.c template,
210 here we set the default value of $$ to a zeroed-out value.
211 Since the default value is undefined, this behavior is
212 technically correct. */
213 static YYSTYPE yyval_default
;
215 /* Copy the second part of user declarations. */
218 ]/* Line __line__ of glr.c. */
219 b4_syncline([@oline@
], [@ofile@
])
225 # define YYMALLOC malloc
228 # define YYREALLOC realloc
234 typedef unsigned char yybool
;
243 #ifndef __attribute__
244 /* This feature is available in gcc versions 2.5 and later. */
245 # if !defined (__GNUC__) || __GNUC__ < 2 || \
246 (__GNUC__ == 2 && __GNUC_MINOR__ < 5) || __STRICT_ANSI__
247 # define __attribute__(Spec) /* empty */
252 # define YYASSERT(condition) ((void) ((condition) || (abort (), 0)))
255 #ifndef ATTRIBUTE_UNUSED
256 # define ATTRIBUTE_UNUSED __attribute__ ((__unused__))
259 /* YYFINAL -- State number of the termination state. */
260 #define YYFINAL ]b4_final_state_number[
261 /* YYLAST -- Last index in YYTABLE. */
262 #define YYLAST ]b4_last[
264 /* YYNTOKENS -- Number of terminals. */
265 #define YYNTOKENS ]b4_tokens_number[
266 /* YYNNTS -- Number of nonterminals. */
267 #define YYNNTS ]b4_nterms_number[
268 /* YYNRULES -- Number of rules. */
269 #define YYNRULES ]b4_rules_number[
270 /* YYNRULES -- Number of states. */
271 #define YYNSTATES ]b4_states_number[
272 /* YYMAXRHS -- Maximum number of symbols on right-hand side of rule. */
273 #define YYMAXRHS ]b4_r2_max[
274 /* YYMAXLEFT -- Maximum number of symbols to the left of a handle
275 accessed by $0, $-1, etc., in any rule. */
276 #define YYMAXLEFT ]b4_max_left_semantic_context[
278 /* YYTRANSLATE(X) -- Bison symbol number corresponding to X. */
279 #define YYUNDEFTOK ]b4_undef_token_number[
280 #define YYMAXUTOK ]b4_user_token_number_max[
282 #define YYTRANSLATE(YYX) \
283 ((YYX <= 0) ? YYEOF : \
284 (unsigned int) (YYX) <= YYMAXUTOK ? yytranslate[YYX] : YYUNDEFTOK)
286 /* YYTRANSLATE[YYLEX] -- Bison symbol number corresponding to YYLEX. */
287 static const ]b4_int_type_for([b4_translate
])[ yytranslate
[] =
293 /* YYPRHS[YYN] -- Index of the first RHS symbol of rule number YYN in
295 static const ]b4_int_type_for([b4_prhs
])[ yyprhs
[] =
300 /* YYRHS -- A `-1'-separated list of the rules' RHS. */
301 static const ]b4_int_type_for([b4_rhs
])[ yyrhs
[] =
306 /* YYRLINE[YYN] -- source line where rule number YYN was defined. */
307 static const ]b4_int_type_for([b4_rline
])[ yyrline
[] =
313 #if (YYDEBUG) || YYERROR_VERBOSE
314 /* YYTNME[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM.
315 First, the terminals, then, starting at YYNTOKENS, nonterminals. */
316 static const char *const yytname
[] =
322 /* YYR1[YYN] -- Symbol number of symbol that rule YYN derives. */
323 static const ]b4_int_type_for([b4_r1
])[ yyr1
[] =
328 /* YYR2[YYN] -- Number of symbols composing right hand side of rule YYN. */
329 static const ]b4_int_type_for([b4_r2
])[ yyr2
[] =
334 /* YYDPREC[RULE-NUM] -- Dynamic precedence of rule #RULE-NUM (0 if none). */
335 static const ]b4_int_type_for([b4_dprec
])[ yydprec
[] =
340 /* YYMERGER[RULE-NUM] -- Index of merging function for rule #RULE-NUM. */
341 static const ]b4_int_type_for([b4_merger
])[ yymerger
[] =
346 /* YYDEFACT[S] -- default rule to reduce with in state S when YYTABLE
347 doesn't specify something else to do. Zero means the default is an
349 static const ]b4_int_type_for([b4_defact
])[ yydefact
[] =
354 /* YYPDEFGOTO[NTERM-NUM]. */
355 static const ]b4_int_type_for([b4_defgoto
])[ yydefgoto
[] =
360 /* YYPACT[STATE-NUM] -- Index in YYTABLE of the portion describing
362 #define YYPACT_NINF ]b4_pact_ninf[
363 static const ]b4_int_type_for([b4_pact
])[ yypact
[] =
368 /* YYPGOTO[NTERM-NUM]. */
369 static const ]b4_int_type_for([b4_pgoto
])[ yypgoto
[] =
374 /* YYTABLE[YYPACT[STATE-NUM]]. What to do in state STATE-NUM. If
375 positive, shift that token. If negative, reduce the rule which
376 number is the opposite. If zero, do what YYDEFACT says.
377 If YYTABLE_NINF, syntax error. */
378 #define YYTABLE_NINF ]b4_table_ninf[
379 static const ]b4_int_type_for([b4_table
])[ yytable
[] =
384 /* YYCONFLP[YYPACT[STATE-NUM]] -- Pointer into YYCONFL of start of
385 list of conflicting reductions corresponding to action entry for
386 state STATE-NUM in yytable. 0 means no conflicts. The list in
387 yyconfl is terminated by a rule number of 0. */
388 static const ]b4_int_type_for([b4_conflict_list_heads
])[ yyconflp
[] =
390 ]b4_conflict_list_heads
[
393 /* YYCONFL[I] -- lists of conflicting rule numbers, each terminated by
394 0, pointed into by YYCONFLP. */
395 ]dnl Do
not use b4_int_type_for here
, since there are places where
396 dnl pointers onto yyconfl are taken
, which type is
"short int *".
397 dnl We probably ought to introduce a type
for confl
.
398 [static const short int yyconfl
[] =
400 ]b4_conflicting_rules
[
403 static const ]b4_int_type_for([b4_check
])[ yycheck
[] =
408 /* YYSTOS[STATE-NUM] -- The (internal number of the) accessing
409 symbol of state STATE-NUM. */
410 static const ]b4_int_type_for([b4_stos
])[ yystos
[] =
416 /* Prevent warning if -Wmissing-prototypes. */
417 ]b4_c_ansi_function_decl([yyparse
], [int], b4_parse_param
)[
419 /* Error token number */
422 /* YYLLOC_DEFAULT -- Set CURRENT to span from RHS[1] to RHS[N].
423 If N is 0, then set CURRENT to the empty location which ends
424 the previous symbol: RHS[0] (always defined). */
427 #ifndef YYLLOC_DEFAULT
428 # define YYLLOC_DEFAULT(yyCurrent, yyRhs, YYN) \
432 (yyCurrent).first_line = YYRHSLOC(yyRhs, 1).first_line; \
433 (yyCurrent).first_column = YYRHSLOC(yyRhs, 1).first_column; \
434 (yyCurrent).last_line = YYRHSLOC(yyRhs, YYN).last_line; \
435 (yyCurrent).last_column = YYRHSLOC(yyRhs, YYN).last_column; \
439 (yyCurrent).first_line = YYRHSLOC(yyRhs, 0).last_line; \
440 (yyCurrent).first_column = YYRHSLOC(yyRhs, 0).last_column; \
441 (yyCurrent).last_line = YYRHSLOC(yyRhs, 0).last_line; \
442 (yyCurrent).last_column = YYRHSLOC(yyRhs, 0).last_column; \
446 /* YY_LOCATION_PRINT -- Print the location on the stream.
447 This macro was not mandated originally: define only if we know
448 we won't break user code: when these are the locations we know. */
450 # define YY_LOCATION_PRINT(File, Loc) \
451 fprintf (File, "%d.%d-%d.%d", \
452 (Loc).first_line, (Loc).first_column, \
453 (Loc).last_line, (Loc).last_column)
456 #ifndef YYLLOC_DEFAULT
457 # define YYLLOC_DEFAULT(yyCurrent, yyRhs, YYN) ((void) 0)
461 #ifndef YY_LOCATION_PRINT
462 # define YY_LOCATION_PRINT(File, Loc) ((void) 0)
466 /* YYLEX -- calling `yylex' with the right arguments. */
467 #define YYLEX ]b4_c_function_call([yylex], [int], b4_lex_param)[
472 #define yynerrs (yystack->yyerrcnt)
474 #define yychar (yystack->yyrawchar)],
482 static const int YYEOF
= 0;
483 static const int YYEMPTY
= -2;
485 typedef enum { yyok
, yyaccept
, yyabort
, yyerr
} YYRESULTTAG
;
488 do { YYRESULTTAG yyflag = YYE; if (yyflag != yyok) return yyflag; } \
493 #if ! defined (YYFPRINTF)
494 # define YYFPRINTF fprintf
497 # define YYDPRINTF(Args) \
503 ]b4_yysymprint_generate([b4_c_ansi_function_def
])[
505 # define YY_SYMBOL_PRINT(Title, Type, Value, Location) \
509 YYFPRINTF (stderr, "%s ", Title); \
510 yysymprint (stderr, \
511 Type, Value]b4_location_if([, Location])[); \
512 YYFPRINTF (stderr, "\n"); \
516 /* Nonzero means print parse trace. It is left uninitialized so that
517 multiple parsers can coexist. */
522 # define YYDPRINTF(Args)
523 # define YY_SYMBOL_PRINT(Title, Type, Value, Location)
525 #endif /* !YYDEBUG */
527 /* YYINITDEPTH -- initial size of the parser's stacks. */
529 # define YYINITDEPTH ]b4_stack_depth_init[
532 /* YYMAXDEPTH -- maximum size the stacks can grow to (effective only
533 if the built-in stack extension method is used).
535 Do not make this value too large; the results are undefined if
536 SIZE_MAX < YYMAXDEPTH * sizeof (GLRStackItem)
537 evaluated with infinite-precision integer arithmetic. */
544 # define YYMAXDEPTH ]b4_stack_depth_max[
547 /* Minimum number of free items on the stack allowed after an
548 allocation. This is to allow allocation and initialization
549 to be completed by functions that call expandGLRStack before the
550 stack is expanded, thus insuring that all necessary pointers get
551 properly redirected to new data. */
554 #if (! defined (YYSTACKEXPANDABLE) \
555 && (! defined (__cplusplus) \
556 || (]b4_location_if([[defined (YYLTYPE_IS_TRIVIAL) && YYLTYPE_IS_TRIVIAL \
557 && ]])[defined (YYSTYPE_IS_TRIVIAL) && YYSTYPE_IS_TRIVIAL)))
558 #define YYSTACKEXPANDABLE 1
560 #define YYSTACKEXPANDABLE 0
563 /** State numbers, as in LALR(1) machine */
564 typedef int yyStateNum
;
566 /** Rule numbers, as in LALR(1) machine */
567 typedef int yyRuleNum
;
569 /** Grammar symbol */
570 typedef short int yySymbol
;
572 /** Item references, as in LALR(1) machine */
573 typedef short int yyItemNum
;
575 typedef struct yyGLRState yyGLRState
;
576 typedef struct yySemanticOption yySemanticOption
;
577 typedef union yyGLRStackItem yyGLRStackItem
;
578 typedef struct yyGLRStack yyGLRStack
;
579 typedef struct yyGLRStateSet yyGLRStateSet
;
584 yyStateNum yylrState
;
588 yySemanticOption
* yyfirstVal
;
594 struct yyGLRStateSet
{
595 yyGLRState
** yystates
;
596 size_t yysize
, yycapacity
;
599 struct yySemanticOption
{
603 yySemanticOption
* yynext
;
606 union yyGLRStackItem
{
608 yySemanticOption yyoption
;
614 ]b4_location_if([[ /* To compute the location of the error token, */
615 YYLTYPE yyerror_range
[2];]])[
622 jmp_buf yyexception_buffer
;
623 yyGLRStackItem
* yyitems
;
624 yyGLRStackItem
* yynextFree
;
626 yyGLRState
* yysplitPoint
;
627 yyGLRState
* yylastDeleted
;
628 yyGLRStateSet yytops
;
631 static void yyinitGLRStack (yyGLRStack
* yystack
, size_t yysize
);
632 static void yyexpandGLRStack (yyGLRStack
* yystack
]b4_pure_formals
[);
633 static void yyfreeGLRStack (yyGLRStack
* yystack
);
636 yyFail (yyGLRStack
* yystack
]b4_pure_formals
[, const char* yyformat
, ...)
638 yystack
->yyerrflag
= 1;
639 if (yyformat
!= NULL
)
643 va_start (yyap
, yyformat
);
644 vsprintf (yymsg
, yyformat
, yyap
);
645 yyerror (]b4_yyerror_args
[yymsg
);
647 longjmp (yystack
->yyexception_buffer
, 1);
650 #if YYDEBUG || YYERROR_VERBOSE
651 /** A printable representation of TOKEN. Valid until next call to
653 static inline const char*
654 yytokenName (yySymbol yytoken
)
656 if (yytoken
== YYEMPTY
)
659 return yytname
[yytoken
];
663 /** Fill in YYVSP[YYLOW1 .. YYLOW0-1] from the chain of states starting
664 * at YYVSP[YYLOW0].yystate.yypred. Leaves YYVSP[YYLOW1].yystate.yypred
665 * containing the pointer to the next state in the chain. Assumes
666 * YYLOW1 < YYLOW0. */
667 static void yyfillin (yyGLRStackItem
*, int, int) ATTRIBUTE_UNUSED
;
669 yyfillin (yyGLRStackItem
*yyvsp
, int yylow0
, int yylow1
)
673 s
= yyvsp
[yylow0
].yystate
.yypred
;
674 for (i
= yylow0
-1; i
>= yylow1
; i
-= 1)
676 YYASSERT (s
->yyresolved
);
677 yyvsp
[i
].yystate
.yyresolved
= yytrue
;
678 yyvsp
[i
].yystate
.yysemantics
.yysval
= s
->yysemantics
.yysval
;
679 yyvsp
[i
].yystate
.yyloc
= s
->yyloc
;
680 s
= yyvsp
[i
].yystate
.yypred
= s
->yypred
;
684 /* Do nothing if YYNORMAL or if *YYLOW <= YYLOW1. Otherwise, fill in
685 YYVSP[YYLOW1 .. *YYLOW-1] as in yyfillin and set *YYLOW = YYLOW1.
686 For convenience, always return YYLOW1. */
687 static inline int yyfill (yyGLRStackItem
*, int *, int, yybool
)
690 yyfill (yyGLRStackItem
*yyvsp
, int *yylow
, int yylow1
, yybool yynormal
)
692 if (!yynormal
&& yylow1
< *yylow
)
694 yyfillin (yyvsp
, *yylow
, yylow1
);
700 /** Perform user action for rule number YYN, with RHS length YYRHSLEN,
701 * and top stack item YYVSP. YYLVALP points to place to put semantic
702 * value ($$), and yylocp points to place for location information
703 * (@@$). Returns yyok for normal return, yyaccept for YYACCEPT,
704 * yyerr for YYERROR, yyabort for YYABORT. */
706 yyuserAction (yyRuleNum yyn
, int yyrhslen
, yyGLRStackItem
* yyvsp
,
708 YYLTYPE
* yylocp
]b4_location_if(, [ ATTRIBUTE_UNUSED
])[,
712 yybool yynormal ATTRIBUTE_UNUSED
= (yystack
->yysplitPoint
== NULL
);
716 # define yyerrok (yystack->yyerrState = 0)
718 # define YYACCEPT return yyaccept
720 # define YYABORT return yyabort
722 # define YYERROR return yyerrok, yyerr
724 # define YYRECOVERING (yystack->yyerrState != 0)
726 # define yyclearin (yychar = *(yystack->yytokenp) = YYEMPTY)
728 # define YYFILL(N) yyfill (yyvsp, &yylow, N, yynormal)
730 # define YYBACKUP(Token, Value) \
731 return yyerror (]b4_yyerror_args["syntax error: cannot back up"), \
736 *yyvalp
= yyval_default
;
738 *yyvalp
= yyvsp
[YYFILL (1-yyrhslen
)].yystate
.yysemantics
.yysval
;
739 # define YYRHSLOC(yyRhs,YYK) ((yyRhs)[YYK].yystate.yyloc)
740 YYLLOC_DEFAULT (*yylocp
, yyvsp
- yyrhslen
, yyrhslen
);
756 /* Line __line__ of glr.c. */
757 b4_syncline([@oline@
], [@ofile@
])
762 yyuserMerge (int yyn
, YYSTYPE
* yy0
, YYSTYPE
* yy1
)
764 /* `Use' the arguments. */
774 /* Bison grammar-table manipulation. */
776 ]b4_yydestruct_generate([b4_c_ansi_function_def
])[
778 /** Number of symbols composing the right hand side of rule #RULE. */
780 yyrhsLength (yyRuleNum yyrule
)
785 /** Left-hand-side symbol for rule #RULE. */
786 static inline yySymbol
787 yylhsNonterm (yyRuleNum yyrule
)
792 #define yyis_pact_ninf(yystate) \
793 ]m4_if(m4_eval(b4_pact_ninf < b4_pact_min), 1,
795 ((yystate
) == YYPACT_NINF
))[
797 /** True iff LR state STATE has only a default reduction (regardless
800 yyisDefaultedState (yyStateNum yystate
)
802 return yyis_pact_ninf (yypact
[yystate
]);
805 /** The default reduction for STATE, assuming it has one. */
806 static inline yyRuleNum
807 yydefaultAction (yyStateNum yystate
)
809 return yydefact
[yystate
];
812 #define yyis_table_ninf(yytable_value) \
813 ]m4_if(m4_eval(b4_table_ninf < b4_table_min), 1,
815 ((yytable_value
) == YYTABLE_NINF
))[
817 /** Set *YYACTION to the action to take in YYSTATE on seeing YYTOKEN.
819 * R < 0: Reduce on rule -R.
821 * R > 0: Shift to state R.
822 * Set *CONFLICTS to a pointer into yyconfl to 0-terminated list of
823 * conflicting reductions.
826 yygetLRActions (yyStateNum yystate
, int yytoken
,
827 int* yyaction
, const short int** yyconflicts
)
829 int yyindex
= yypact
[yystate
] + yytoken
;
830 if (yyindex
< 0 || YYLAST
< yyindex
|| yycheck
[yyindex
] != yytoken
)
832 *yyaction
= -yydefact
[yystate
];
833 *yyconflicts
= yyconfl
;
835 else if (! yyis_table_ninf (yytable
[yyindex
]))
837 *yyaction
= yytable
[yyindex
];
838 *yyconflicts
= yyconfl
+ yyconflp
[yyindex
];
843 *yyconflicts
= yyconfl
+ yyconflp
[yyindex
];
847 static inline yyStateNum
848 yyLRgotoState (yyStateNum yystate
, yySymbol yylhs
)
851 yyr
= yypgoto
[yylhs
- YYNTOKENS
] + yystate
;
852 if (0 <= yyr
&& yyr
<= YYLAST
&& yycheck
[yyr
] == yystate
)
855 return yydefgoto
[yylhs
- YYNTOKENS
];
859 yyisShiftAction (int yyaction
)
865 yyisErrorAction (int yyaction
)
867 return yyaction
== 0;
873 yyaddDeferredAction (yyGLRStack
* yystack
, yyGLRState
* yystate
,
874 yyGLRState
* rhs
, yyRuleNum yyrule
]b4_pure_formals
[)
876 yySemanticOption
* yynewItem
;
877 yynewItem
= &yystack
->yynextFree
->yyoption
;
878 yystack
->yyspaceLeft
-= 1;
879 yystack
->yynextFree
+= 1;
880 yynewItem
->yyisState
= yyfalse
;
881 yynewItem
->yystate
= rhs
;
882 yynewItem
->yyrule
= yyrule
;
883 yynewItem
->yynext
= yystate
->yysemantics
.yyfirstVal
;
884 yystate
->yysemantics
.yyfirstVal
= yynewItem
;
885 if (yystack
->yyspaceLeft
< YYHEADROOM
)
886 yyexpandGLRStack (yystack
]b4_pure_args
[);
891 /** Initialize SET to a singleton set containing an empty stack. */
893 yyinitStateSet (yyGLRStateSet
* yyset
)
896 yyset
->yycapacity
= 16;
897 yyset
->yystates
= (yyGLRState
**) YYMALLOC (16 * sizeof yyset
->yystates
[0]);
898 yyset
->yystates
[0] = NULL
;
901 static void yyfreeStateSet (yyGLRStateSet
* yyset
)
903 YYFREE (yyset
->yystates
);
906 /** Initialize STACK to a single empty stack, with total maximum
907 * capacity for all stacks of SIZE. */
909 yyinitGLRStack (yyGLRStack
* yystack
, size_t yysize
)
911 yystack
->yyerrflag
= 0;
912 yystack
->yyerrState
= 0;
914 yystack
->yyspaceLeft
= yysize
;
915 yystack
->yynextFree
= yystack
->yyitems
=
916 (yyGLRStackItem
*) YYMALLOC (yysize
* sizeof yystack
->yynextFree
[0]);
917 yystack
->yysplitPoint
= NULL
;
918 yystack
->yylastDeleted
= NULL
;
919 yyinitStateSet (&yystack
->yytops
);
922 #define YYRELOC(YYFROMITEMS,YYTOITEMS,YYX,YYTYPE) \
923 &((YYTOITEMS) - ((YYFROMITEMS) - (yyGLRStackItem*) (YYX)))->YYTYPE
925 /** If STACK is expandable, extend it. WARNING: Pointers into the
926 stack from outside should be considered invalid after this call.
927 We always expand when there are 1 or fewer items left AFTER an
928 allocation, so that we can avoid having external pointers exist
929 across an allocation. */
931 yyexpandGLRStack (yyGLRStack
* yystack
]b4_pure_formals
[)
933 #if YYSTACKEXPANDABLE
934 yyGLRStack yynewStack
;
935 yyGLRStackItem
* yyp0
, *yyp1
;
936 size_t yysize
, yynewSize
;
938 yysize
= yystack
->yynextFree
- yystack
->yyitems
;
939 if (YYMAXDEPTH
<= yysize
)
940 yyFail (yystack
][]b4_pure_args
[, "parser stack overflow");
941 yynewSize
= 2*yysize
;
942 if (YYMAXDEPTH
< yynewSize
)
943 yynewSize
= YYMAXDEPTH
;
944 yyinitGLRStack (&yynewStack
, yynewSize
);
945 for (yyp0
= yystack
->yyitems
, yyp1
= yynewStack
.yyitems
, yyn
= yysize
;
947 yyn
-= 1, yyp0
+= 1, yyp1
+= 1)
950 if (*(yybool
*) yyp0
)
952 yyGLRState
* yys0
= &yyp0
->yystate
;
953 yyGLRState
* yys1
= &yyp1
->yystate
;
954 if (yys0
->yypred
!= NULL
)
956 YYRELOC (yyp0
, yyp1
, yys0
->yypred
, yystate
);
957 if (! yys0
->yyresolved
&& yys0
->yysemantics
.yyfirstVal
!= NULL
)
958 yys1
->yysemantics
.yyfirstVal
=
959 YYRELOC(yyp0
, yyp1
, yys0
->yysemantics
.yyfirstVal
, yyoption
);
963 yySemanticOption
* yyv0
= &yyp0
->yyoption
;
964 yySemanticOption
* yyv1
= &yyp1
->yyoption
;
965 if (yyv0
->yystate
!= NULL
)
966 yyv1
->yystate
= YYRELOC (yyp0
, yyp1
, yyv0
->yystate
, yystate
);
967 if (yyv0
->yynext
!= NULL
)
968 yyv1
->yynext
= YYRELOC (yyp0
, yyp1
, yyv0
->yynext
, yyoption
);
971 if (yystack
->yysplitPoint
!= NULL
)
972 yystack
->yysplitPoint
= YYRELOC (yystack
->yyitems
, yynewStack
.yyitems
,
973 yystack
->yysplitPoint
, yystate
);
975 for (yyn
= 0; yyn
< yystack
->yytops
.yysize
; yyn
+= 1)
976 if (yystack
->yytops
.yystates
[yyn
] != NULL
)
977 yystack
->yytops
.yystates
[yyn
] =
978 YYRELOC (yystack
->yyitems
, yynewStack
.yyitems
,
979 yystack
->yytops
.yystates
[yyn
], yystate
);
980 YYFREE (yystack
->yyitems
);
981 yystack
->yyitems
= yynewStack
.yyitems
;
982 yystack
->yynextFree
= yynewStack
.yynextFree
+ yysize
;
983 yystack
->yyspaceLeft
= yynewStack
.yyspaceLeft
- yysize
;
987 yyFail (yystack
][]b4_pure_args
[, "parser stack overflow");
992 yyfreeGLRStack (yyGLRStack
* yystack
)
994 YYFREE (yystack
->yyitems
);
995 yyfreeStateSet (&yystack
->yytops
);
998 /** Assuming that S is a GLRState somewhere on STACK, update the
999 * splitpoint of STACK, if needed, so that it is at least as deep as
1002 yyupdateSplit (yyGLRStack
* yystack
, yyGLRState
* yys
)
1004 if (yystack
->yysplitPoint
!= NULL
&& yystack
->yysplitPoint
> yys
)
1005 yystack
->yysplitPoint
= yys
;
1008 /** Invalidate stack #K in STACK. */
1010 yymarkStackDeleted (yyGLRStack
* yystack
, int yyk
)
1012 if (yystack
->yytops
.yystates
[yyk
] != NULL
)
1013 yystack
->yylastDeleted
= yystack
->yytops
.yystates
[yyk
];
1014 yystack
->yytops
.yystates
[yyk
] = NULL
;
1017 /** Undelete the last stack that was marked as deleted. Can only be
1018 done once after a deletion, and only when all other stacks have
1021 yyundeleteLastStack (yyGLRStack
* yystack
)
1023 if (yystack
->yylastDeleted
== NULL
|| yystack
->yytops
.yysize
!= 0)
1025 yystack
->yytops
.yystates
[0] = yystack
->yylastDeleted
;
1026 yystack
->yytops
.yysize
= 1;
1027 YYDPRINTF ((stderr
, "Restoring last deleted stack as stack #0.\n"));
1028 yystack
->yylastDeleted
= NULL
;
1032 yyremoveDeletes (yyGLRStack
* yystack
)
1036 while (yyj
< yystack
->yytops
.yysize
)
1038 if (yystack
->yytops
.yystates
[yyi
] == NULL
)
1042 YYDPRINTF ((stderr
, "Removing dead stacks.\n"));
1044 yystack
->yytops
.yysize
-= 1;
1048 yystack
->yytops
.yystates
[yyj
] = yystack
->yytops
.yystates
[yyi
];
1051 YYDPRINTF ((stderr
, "Rename stack %lu -> %lu.\n",
1052 (unsigned long int) yyi
, (unsigned long int) yyj
));
1060 /** Shift to a new state on stack #K of STACK, corresponding to LR state
1061 * LRSTATE, at input position POSN, with (resolved) semantic value SVAL. */
1063 yyglrShift (yyGLRStack
* yystack
, int yyk
, yyStateNum yylrState
, size_t yyposn
,
1064 YYSTYPE yysval
, YYLTYPE
* yylocp
]b4_user_formals
[)
1066 yyGLRStackItem
* yynewItem
;
1068 yynewItem
= yystack
->yynextFree
;
1069 yystack
->yynextFree
+= 1;
1070 yystack
->yyspaceLeft
-= 1;
1071 yynewItem
->yystate
.yyisState
= yytrue
;
1072 yynewItem
->yystate
.yylrState
= yylrState
;
1073 yynewItem
->yystate
.yyposn
= yyposn
;
1074 yynewItem
->yystate
.yyresolved
= yytrue
;
1075 yynewItem
->yystate
.yypred
= yystack
->yytops
.yystates
[yyk
];
1076 yystack
->yytops
.yystates
[yyk
] = &yynewItem
->yystate
;
1077 yynewItem
->yystate
.yysemantics
.yysval
= yysval
;
1078 yynewItem
->yystate
.yyloc
= *yylocp
;
1079 if (yystack
->yyspaceLeft
< YYHEADROOM
)
1080 yyexpandGLRStack (yystack
]b4_pure_args
[);
1083 /** Shift stack #K of YYSTACK, to a new state corresponding to LR
1084 * state YYLRSTATE, at input position YYPOSN, with the (unresolved)
1085 * semantic value of YYRHS under the action for YYRULE. */
1087 yyglrShiftDefer (yyGLRStack
* yystack
, int yyk
, yyStateNum yylrState
,
1088 size_t yyposn
, yyGLRState
* rhs
, yyRuleNum yyrule
]b4_pure_formals
[)
1090 yyGLRStackItem
* yynewItem
;
1092 yynewItem
= yystack
->yynextFree
;
1093 yynewItem
->yystate
.yyisState
= yytrue
;
1094 yynewItem
->yystate
.yylrState
= yylrState
;
1095 yynewItem
->yystate
.yyposn
= yyposn
;
1096 yynewItem
->yystate
.yyresolved
= yyfalse
;
1097 yynewItem
->yystate
.yypred
= yystack
->yytops
.yystates
[yyk
];
1098 yynewItem
->yystate
.yysemantics
.yyfirstVal
= NULL
;
1099 yystack
->yytops
.yystates
[yyk
] = &yynewItem
->yystate
;
1100 yystack
->yynextFree
+= 1;
1101 yystack
->yyspaceLeft
-= 1;
1102 yyaddDeferredAction (yystack
, &yynewItem
->yystate
, rhs
, yyrule
]b4_pure_args
[);
1105 /** Pop the symbols consumed by reduction #RULE from the top of stack
1106 * #K of STACK, and perform the appropriate semantic action on their
1107 * semantic values. Assumes that all ambiguities in semantic values
1108 * have been previously resolved. Set *VALP to the resulting value,
1109 * and *LOCP to the computed location (if any). Return value is as
1110 * for userAction. */
1111 static inline YYRESULTTAG
1112 yydoAction (yyGLRStack
* yystack
, int yyk
, yyRuleNum yyrule
,
1113 YYSTYPE
* yyvalp
, YYLTYPE
* yylocp
]b4_user_formals
[)
1115 int yynrhs
= yyrhsLength (yyrule
);
1117 if (yystack
->yysplitPoint
== NULL
)
1119 /* Standard special case: single stack. */
1120 yyGLRStackItem
* rhs
= (yyGLRStackItem
*) yystack
->yytops
.yystates
[yyk
];
1121 YYASSERT (yyk
== 0);
1122 yystack
->yynextFree
-= yynrhs
;
1123 yystack
->yyspaceLeft
+= yynrhs
;
1124 yystack
->yytops
.yystates
[0] = & yystack
->yynextFree
[-1].yystate
;
1125 return yyuserAction (yyrule
, yynrhs
, rhs
,
1126 yyvalp
, yylocp
, yystack
]b4_user_args
[);
1132 yyGLRStackItem yyrhsVals
[YYMAXRHS
+ YYMAXLEFT
+ 1];
1133 yys
= yyrhsVals
[YYMAXRHS
+ YYMAXLEFT
].yystate
.yypred
1134 = yystack
->yytops
.yystates
[yyk
];
1135 for (yyi
= 0; yyi
< yynrhs
; yyi
+= 1)
1140 yyupdateSplit (yystack
, yys
);
1141 yystack
->yytops
.yystates
[yyk
] = yys
;
1142 return yyuserAction (yyrule
, yynrhs
, yyrhsVals
+ YYMAXRHS
+ YYMAXLEFT
- 1,
1143 yyvalp
, yylocp
, yystack
]b4_user_args
[);
1148 # define YY_REDUCE_PRINT(K, Rule)
1150 # define YY_REDUCE_PRINT(K, Rule) \
1153 yy_reduce_print (K, Rule); \
1156 /*----------------------------------------------------------.
1157 | Report that the RULE is going to be reduced on stack #K. |
1158 `----------------------------------------------------------*/
1161 yy_reduce_print (size_t yyk
, yyRuleNum yyrule
)
1164 YYFPRINTF (stderr
, "Reducing stack %lu by rule %d (line %lu), ",
1165 (unsigned long int) yyk
, yyrule
- 1,
1166 (unsigned long int) yyrline
[yyrule
]);
1167 /* Print the symbols being reduced, and their result. */
1168 for (yyi
= yyprhs
[yyrule
]; 0 <= yyrhs
[yyi
]; yyi
++)
1169 YYFPRINTF (stderr
, "%s ", yytokenName (yyrhs
[yyi
]));
1170 YYFPRINTF (stderr
, "-> %s\n", yytokenName (yyr1
[yyrule
]));
1174 /** Pop items off stack #K of STACK according to grammar rule RULE,
1175 * and push back on the resulting nonterminal symbol. Perform the
1176 * semantic action associated with RULE and store its value with the
1177 * newly pushed state, if FORCEEVAL or if STACK is currently
1178 * unambiguous. Otherwise, store the deferred semantic action with
1179 * the new state. If the new state would have an identical input
1180 * position, LR state, and predecessor to an existing state on the stack,
1181 * it is identified with that existing state, eliminating stack #K from
1182 * the STACK. In this case, the (necessarily deferred) semantic value is
1183 * added to the options for the existing state's semantic value.
1185 static inline YYRESULTTAG
1186 yyglrReduce (yyGLRStack
* yystack
, size_t yyk
, yyRuleNum yyrule
,
1187 yybool yyforceEval
]b4_pure_formals
[)
1189 size_t yyposn
= yystack
->yytops
.yystates
[yyk
]->yyposn
;
1191 if (yyforceEval
|| yystack
->yysplitPoint
== NULL
)
1196 YY_REDUCE_PRINT (yyk
, yyrule
);
1197 YYCHK (yydoAction (yystack
, yyk
, yyrule
, &yysval
, &yyloc
]b4_user_args
[));
1198 yyglrShift (yystack
, yyk
,
1199 yyLRgotoState (yystack
->yytops
.yystates
[yyk
]->yylrState
,
1200 yylhsNonterm (yyrule
)),
1201 yyposn
, yysval
, &yyloc
]b4_user_args
[);
1207 yyGLRState
* yys
, *yys0
= yystack
->yytops
.yystates
[yyk
];
1208 yyStateNum yynewLRState
;
1210 for (yys
= yystack
->yytops
.yystates
[yyk
], yyn
= yyrhsLength (yyrule
);
1216 yyupdateSplit (yystack
, yys
);
1217 yynewLRState
= yyLRgotoState (yys
->yylrState
, yylhsNonterm (yyrule
));
1219 "Reduced stack %lu by rule #%d; action deferred. Now in state %d.\n",
1220 (unsigned long int) yyk
, yyrule
- 1, yynewLRState
));
1221 for (yyi
= 0; yyi
< yystack
->yytops
.yysize
; yyi
+= 1)
1222 if (yyi
!= yyk
&& yystack
->yytops
.yystates
[yyi
] != NULL
)
1224 yyGLRState
* yyp
, *yysplit
= yystack
->yysplitPoint
;
1225 yyp
= yystack
->yytops
.yystates
[yyi
];
1226 while (yyp
!= yys
&& yyp
!= yysplit
&& yyp
->yyposn
>= yyposn
)
1228 if (yyp
->yylrState
== yynewLRState
&& yyp
->yypred
== yys
)
1230 yyaddDeferredAction (yystack
, yyp
, yys0
, yyrule
]b4_pure_args
[);
1231 yymarkStackDeleted (yystack
, yyk
);
1232 YYDPRINTF ((stderr
, "Merging stack %lu into stack %lu.\n",
1233 (unsigned long int) yyk
,
1234 (unsigned long int) yyi
));
1240 yystack
->yytops
.yystates
[yyk
] = yys
;
1241 yyglrShiftDefer (yystack
, yyk
, yynewLRState
, yyposn
, yys0
, yyrule
]b4_pure_args
[);
1247 yysplitStack (yyGLRStack
* yystack
, int yyk
)
1249 if (yystack
->yysplitPoint
== NULL
)
1251 YYASSERT (yyk
== 0);
1252 yystack
->yysplitPoint
= yystack
->yytops
.yystates
[yyk
];
1254 if (yystack
->yytops
.yysize
>= yystack
->yytops
.yycapacity
)
1256 yystack
->yytops
.yycapacity
*= 2;
1257 yystack
->yytops
.yystates
=
1258 (yyGLRState
**) YYREALLOC (yystack
->yytops
.yystates
,
1259 (yystack
->yytops
.yycapacity
1260 * sizeof yystack
->yytops
.yystates
[0]));
1262 yystack
->yytops
.yystates
[yystack
->yytops
.yysize
]
1263 = yystack
->yytops
.yystates
[yyk
];
1264 yystack
->yytops
.yysize
+= 1;
1265 return yystack
->yytops
.yysize
-1;
1268 /** True iff Y0 and Y1 represent identical options at the top level.
1269 * That is, they represent the same rule applied to RHS symbols
1270 * that produce the same terminal symbols. */
1272 yyidenticalOptions (yySemanticOption
* yyy0
, yySemanticOption
* yyy1
)
1274 if (yyy0
->yyrule
== yyy1
->yyrule
)
1276 yyGLRState
*yys0
, *yys1
;
1278 for (yys0
= yyy0
->yystate
, yys1
= yyy1
->yystate
,
1279 yyn
= yyrhsLength (yyy0
->yyrule
);
1281 yys0
= yys0
->yypred
, yys1
= yys1
->yypred
, yyn
-= 1)
1282 if (yys0
->yyposn
!= yys1
->yyposn
)
1290 /** Assuming identicalOptions (Y0,Y1), (destructively) merge the
1291 * alternative semantic values for the RHS-symbols of Y1 into the
1292 * corresponding semantic value sets of the symbols of Y0. */
1294 yymergeOptionSets (yySemanticOption
* yyy0
, yySemanticOption
* yyy1
)
1296 yyGLRState
*yys0
, *yys1
;
1298 for (yys0
= yyy0
->yystate
, yys1
= yyy1
->yystate
,
1299 yyn
= yyrhsLength (yyy0
->yyrule
);
1301 yys0
= yys0
->yypred
, yys1
= yys1
->yypred
, yyn
-= 1)
1304 else if (! yys0
->yyresolved
&& ! yys1
->yyresolved
)
1306 yySemanticOption
* yyz
;
1307 for (yyz
= yys0
->yysemantics
.yyfirstVal
; yyz
->yynext
!= NULL
;
1310 yyz
->yynext
= yys1
->yysemantics
.yyfirstVal
;
1314 /** Y0 and Y1 represent two possible actions to take in a given
1315 * parsing state; return 0 if no combination is possible,
1316 * 1 if user-mergeable, 2 if Y0 is preferred, 3 if Y1 is preferred. */
1318 yypreference (yySemanticOption
* y0
, yySemanticOption
* y1
)
1320 yyRuleNum r0
= y0
->yyrule
, r1
= y1
->yyrule
;
1321 int p0
= yydprec
[r0
], p1
= yydprec
[r1
];
1325 if (yymerger
[r0
] == 0 || yymerger
[r0
] != yymerger
[r1
])
1330 if (p0
== 0 || p1
== 0)
1339 static YYRESULTTAG
yyresolveValue (yySemanticOption
* yyoptionList
,
1340 yyGLRStack
* yystack
, YYSTYPE
* yyvalp
,
1341 YYLTYPE
* yylocp
]b4_user_formals
[);
1344 yyresolveStates (yyGLRState
* yys
, int yyn
, yyGLRStack
* yystack
]b4_user_formals
[)
1349 YYASSERT (yys
->yypred
);
1350 yyflag
= yyresolveStates (yys
->yypred
, yyn
-1, yystack
]b4_user_args
[);
1353 if (! yys
->yyresolved
)
1355 yyflag
= yyresolveValue (yys
->yysemantics
.yyfirstVal
, yystack
,
1356 &yys
->yysemantics
.yysval
, &yys
->yyloc
1360 yys
->yyresolved
= yytrue
;
1367 yyresolveAction (yySemanticOption
* yyopt
, yyGLRStack
* yystack
,
1368 YYSTYPE
* yyvalp
, YYLTYPE
* yylocp
]b4_user_formals
[)
1370 yyGLRStackItem yyrhsVals
[YYMAXRHS
+ YYMAXLEFT
+ 1];
1373 yynrhs
= yyrhsLength (yyopt
->yyrule
);
1374 YYCHK (yyresolveStates (yyopt
->yystate
, yynrhs
, yystack
]b4_user_args
[));
1375 yyrhsVals
[YYMAXRHS
+ YYMAXLEFT
].yystate
.yypred
= yyopt
->yystate
;
1376 return yyuserAction (yyopt
->yyrule
, yynrhs
,
1377 yyrhsVals
+ YYMAXRHS
+ YYMAXLEFT
- 1,
1378 yyvalp
, yylocp
, yystack
]b4_user_args
[);
1383 yyreportTree (yySemanticOption
* yyx
, int yyindent
)
1385 int yynrhs
= yyrhsLength (yyx
->yyrule
);
1388 yyGLRState
* yystates
[YYMAXRHS
];
1389 yyGLRState yyleftmost_state
;
1391 for (yyi
= yynrhs
, yys
= yyx
->yystate
; 0 < yyi
; yyi
-= 1, yys
= yys
->yypred
)
1392 yystates
[yyi
] = yys
;
1395 yyleftmost_state
.yyposn
= 0;
1396 yystates
[0] = &yyleftmost_state
;
1401 if (yyx
->yystate
->yyposn
< yys
->yyposn
+ 1)
1402 YYFPRINTF (stderr
, "%*s%s -> <Rule %d, empty>\n",
1403 yyindent
, "", yytokenName (yylhsNonterm (yyx
->yyrule
)),
1406 YYFPRINTF (stderr
, "%*s%s -> <Rule %d, tokens %lu .. %lu>\n",
1407 yyindent
, "", yytokenName (yylhsNonterm (yyx
->yyrule
)),
1408 yyx
->yyrule
, (unsigned long int) (yys
->yyposn
+ 1),
1409 (unsigned long int) yyx
->yystate
->yyposn
);
1410 for (yyi
= 1; yyi
<= yynrhs
; yyi
+= 1)
1412 if (yystates
[yyi
]->yyresolved
)
1414 if (yystates
[yyi
-1]->yyposn
+1 > yystates
[yyi
]->yyposn
)
1415 YYFPRINTF (stderr
, "%*s%s <empty>\n", yyindent
+2, "",
1416 yytokenName (yyrhs
[yyprhs
[yyx
->yyrule
]+yyi
-1]));
1418 YYFPRINTF (stderr
, "%*s%s <tokens %lu .. %lu>\n", yyindent
+2, "",
1419 yytokenName (yyrhs
[yyprhs
[yyx
->yyrule
]+yyi
-1]),
1420 (unsigned long int) (yystates
[yyi
- 1]->yyposn
+ 1),
1421 (unsigned long int) yystates
[yyi
]->yyposn
);
1424 yyreportTree (yystates
[yyi
]->yysemantics
.yyfirstVal
, yyindent
+2);
1430 yyreportAmbiguity (yySemanticOption
* yyx0
, yySemanticOption
* yyx1
,
1431 yyGLRStack
* yystack
]b4_pure_formals
[)
1433 /* `Unused' warnings. */
1438 YYFPRINTF (stderr
, "Ambiguity detected.\n");
1439 YYFPRINTF (stderr
, "Option 1,\n");
1440 yyreportTree (yyx0
, 2);
1441 YYFPRINTF (stderr
, "\nOption 2,\n");
1442 yyreportTree (yyx1
, 2);
1443 YYFPRINTF (stderr
, "\n");
1445 yyFail (yystack
][]b4_pure_args
[, "ambiguity detected");
1449 /** Resolve the ambiguity represented by OPTIONLIST, perform the indicated
1450 * actions, and return the result. */
1452 yyresolveValue (yySemanticOption
* yyoptionList
, yyGLRStack
* yystack
,
1453 YYSTYPE
* yyvalp
, YYLTYPE
* yylocp
]b4_user_formals
[)
1455 yySemanticOption
* yybest
;
1456 yySemanticOption
* yyp
;
1459 yybest
= yyoptionList
;
1461 for (yyp
= yyoptionList
->yynext
; yyp
!= NULL
; yyp
= yyp
->yynext
)
1463 if (yyidenticalOptions (yybest
, yyp
))
1464 yymergeOptionSets (yybest
, yyp
);
1466 switch (yypreference (yybest
, yyp
))
1469 yyreportAmbiguity (yybest
, yyp
, yystack
]b4_pure_args
[);
1485 int yyprec
= yydprec
[yybest
->yyrule
];
1486 YYCHK (yyresolveAction (yybest
, yystack
, yyvalp
, yylocp
]b4_user_args
[));
1487 for (yyp
= yybest
->yynext
; yyp
!= NULL
; yyp
= yyp
->yynext
)
1489 if (yyprec
== yydprec
[yyp
->yyrule
])
1493 YYCHK (yyresolveAction (yyp
, yystack
, &yyval1
, &yydummy
]b4_user_args
[));
1494 yyuserMerge (yymerger
[yyp
->yyrule
], yyvalp
, &yyval1
);
1500 return yyresolveAction (yybest
, yystack
, yyvalp
, yylocp
]b4_user_args
[);
1504 yyresolveStack (yyGLRStack
* yystack
]b4_user_formals
[)
1506 if (yystack
->yysplitPoint
!= NULL
)
1511 for (yyn
= 0, yys
= yystack
->yytops
.yystates
[0];
1512 yys
!= yystack
->yysplitPoint
;
1513 yys
= yys
->yypred
, yyn
+= 1)
1515 YYCHK (yyresolveStates (yystack
->yytops
.yystates
[0], yyn
, yystack
1522 yycompressStack (yyGLRStack
* yystack
)
1524 yyGLRState
* yyp
, *yyq
, *yyr
;
1526 if (yystack
->yytops
.yysize
!= 1 || yystack
->yysplitPoint
== NULL
)
1529 for (yyp
= yystack
->yytops
.yystates
[0], yyq
= yyp
->yypred
, yyr
= NULL
;
1530 yyp
!= yystack
->yysplitPoint
;
1531 yyr
= yyp
, yyp
= yyq
, yyq
= yyp
->yypred
)
1534 yystack
->yyspaceLeft
+= yystack
->yynextFree
- yystack
->yyitems
;
1535 yystack
->yynextFree
= ((yyGLRStackItem
*) yystack
->yysplitPoint
) + 1;
1536 yystack
->yyspaceLeft
-= yystack
->yynextFree
- yystack
->yyitems
;
1537 yystack
->yysplitPoint
= NULL
;
1538 yystack
->yylastDeleted
= NULL
;
1542 yystack
->yynextFree
->yystate
= *yyr
;
1544 yystack
->yynextFree
->yystate
.yypred
= & yystack
->yynextFree
[-1].yystate
;
1545 yystack
->yytops
.yystates
[0] = &yystack
->yynextFree
->yystate
;
1546 yystack
->yynextFree
+= 1;
1547 yystack
->yyspaceLeft
-= 1;
1552 yyprocessOneStack (yyGLRStack
* yystack
, int yyk
,
1553 size_t yyposn
, YYSTYPE
* yylvalp
, YYLTYPE
* yyllocp
1557 const short int* yyconflicts
;
1559 yySymbol
* const yytokenp
= yystack
->yytokenp
;
1561 while (yystack
->yytops
.yystates
[yyk
] != NULL
)
1563 yyStateNum yystate
= yystack
->yytops
.yystates
[yyk
]->yylrState
;
1564 YYDPRINTF ((stderr
, "Stack %d Entering state %d\n", yyk
, yystate
));
1566 YYASSERT (yystate
!= YYFINAL
);
1568 if (yyisDefaultedState (yystate
))
1570 yyrule
= yydefaultAction (yystate
);
1573 YYDPRINTF ((stderr
, "Stack %d dies.\n", yyk
));
1574 yymarkStackDeleted (yystack
, yyk
);
1577 YYCHK (yyglrReduce (yystack
, yyk
, yyrule
, yyfalse
]b4_lpure_args
[));
1581 if (*yytokenp
== YYEMPTY
)
1583 YYDPRINTF ((stderr
, "Reading a token: "));
1585 *yytokenp
= YYTRANSLATE (yychar
);
1586 YY_SYMBOL_PRINT ("Next token is", *yytokenp
, yylvalp
, yyllocp
);
1588 yygetLRActions (yystate
, *yytokenp
, &yyaction
, &yyconflicts
);
1590 while (*yyconflicts
!= 0)
1592 int yynewStack
= yysplitStack (yystack
, yyk
);
1593 YYDPRINTF ((stderr
, "Splitting off stack %d from %d.\n",
1595 YYCHK (yyglrReduce (yystack
, yynewStack
,
1596 *yyconflicts
, yyfalse
]b4_lpure_args
[));
1597 YYCHK (yyprocessOneStack (yystack
, yynewStack
, yyposn
,
1598 yylvalp
, yyllocp
]b4_user_args
[));
1602 if (yyisShiftAction (yyaction
))
1604 YYDPRINTF ((stderr
, "On stack %d, ", yyk
));
1605 YY_SYMBOL_PRINT ("shifting", *yytokenp
, yylvalp
, yyllocp
);
1606 yyglrShift (yystack
, yyk
, yyaction
, yyposn
+1,
1607 *yylvalp
, yyllocp
]b4_user_args
[);
1608 YYDPRINTF ((stderr
, ", now in state #%d\n",
1609 yystack
->yytops
.yystates
[yyk
]->yylrState
));
1612 else if (yyisErrorAction (yyaction
))
1614 YYDPRINTF ((stderr
, "Stack %d dies.\n", yyk
));
1615 yymarkStackDeleted (yystack
, yyk
);
1619 YYCHK (yyglrReduce (yystack
, yyk
, -yyaction
, yyfalse
]b4_lpure_args
[));
1626 yyreportSyntaxError (yyGLRStack
* yystack
,
1627 YYSTYPE
* yylvalp
, YYLTYPE
* yyllocp
]b4_user_formals
[)
1629 /* `Unused' warnings. */
1633 if (yystack
->yyerrState
== 0)
1636 yySymbol
* const yytokenp
= yystack
->yytokenp
;
1638 yyn
= yypact
[yystack
->yytops
.yystates
[0]->yylrState
];
1639 if (YYPACT_NINF
< yyn
&& yyn
< YYLAST
)
1642 const char* yyprefix
;
1646 /* Start YYX at -YYN if negative to avoid negative indexes in
1648 int yyxbegin
= yyn
< 0 ? -yyn
: 0;
1650 /* Stay within bounds of both yycheck and yytname. */
1651 int yychecklim
= YYLAST
- yyn
;
1652 int yyxend
= yychecklim
< YYNTOKENS
? yychecklim
: YYNTOKENS
;
1655 yyprefix
= ", expecting ";
1656 for (yyx
= yyxbegin
; yyx
< yyxend
; ++yyx
)
1657 if (yycheck
[yyx
+ yyn
] == yyx
&& yyx
!= YYTERROR
)
1659 yysize
+= strlen (yyprefix
) + strlen (yytokenName (yyx
));
1668 yysize
+= (sizeof ("syntax error, unexpected ")
1669 + strlen (yytokenName (*yytokenp
)));
1670 yymsg
= (char*) YYMALLOC (yysize
);
1674 sprintf (yyp
, "syntax error%s%s",
1675 (*yytokenp
== YYEMPTY
? "" : ", unexpected "),
1676 yytokenName (*yytokenp
));
1677 yyp
+= strlen (yyp
);
1680 yyprefix
= ", expecting ";
1681 for (yyx
= yyxbegin
; yyx
< yyxend
; ++yyx
)
1682 if (yycheck
[yyx
+ yyn
] == yyx
&& yyx
!= YYTERROR
)
1684 sprintf (yyp
, "%s%s", yyprefix
, yytokenName (yyx
));
1685 yyp
+= strlen (yyp
);
1689 yyerror (]b4_lyyerror_args
[yymsg
);
1693 yyerror (]b4_lyyerror_args
["syntax error; also virtual memory exhausted");
1696 #endif /* YYERROR_VERBOSE */
1697 yyerror (]b4_lyyerror_args
["syntax error");
1702 /* Recover from a syntax error on YYSTACK, assuming that YYTOKENP,
1703 YYLVALP, and YYLLOCP point to the syntactic category, semantic
1704 value, and location of the look-ahead. */
1706 yyrecoverSyntaxError (yyGLRStack
* yystack
,
1708 YYLTYPE
* yyllocp
]b4_location_if(, [ ATTRIBUTE_UNUSED
])[
1711 yySymbol
* const yytokenp
= yystack
->yytokenp
;
1715 if (yystack
->yyerrState
== 3)
1716 /* We just shifted the error token and (perhaps) took some
1717 reductions. Skip tokens until we can proceed. */
1720 if (*yytokenp
== YYEOF
)
1722 /* Now pop stack until empty and fail. */
1723 while (yystack
->yytops
.yystates
[0] != NULL
)
1725 yyGLRState
*yys
= yystack
->yytops
.yystates
[0];
1726 ]b4_location_if([[ yystack
->yyerror_range
[0] = yys
->yyloc
;]])[
1727 yydestruct ("Error: popping",
1728 yystos
[yys
->yylrState
],
1729 &yys
->yysemantics
.yysval
]b4_location_if([, &yys
->yyloc
])[);
1730 yystack
->yytops
.yystates
[0] = yys
->yypred
;
1731 yystack
->yynextFree
-= 1;
1732 yystack
->yyspaceLeft
+= 1;
1734 yyFail (yystack
][]b4_lpure_args
[, NULL
);
1736 if (*yytokenp
!= YYEMPTY
)
1738 /* We throw away the lookahead, but the error range
1739 of the shifted error token must take it into account. */
1740 yyGLRState
*yys
= yystack
->yytops
.yystates
[0];
1741 yys
->yyloc
.last_line
= yyllocp
->last_line
;
1742 yys
->yyloc
.last_column
= yyllocp
->last_column
;]])[
1743 yydestruct ("Error: discarding",
1744 *yytokenp
, yylvalp
]b4_location_if([, yyllocp
])[);
1746 YYDPRINTF ((stderr
, "Reading a token: "));
1748 *yytokenp
= YYTRANSLATE (yychar
);
1749 YY_SYMBOL_PRINT ("Next token is", *yytokenp
, yylvalp
, yyllocp
);
1750 yyj
= yypact
[yystack
->yytops
.yystates
[0]->yylrState
];
1751 if (yyis_pact_ninf (yyj
))
1754 if (yyj
< 0 || YYLAST
< yyj
|| yycheck
[yyj
] != *yytokenp
)
1756 if (yydefact
[yystack
->yytops
.yystates
[0]->yylrState
] != 0)
1759 else if (yytable
[yyj
] != 0 && ! yyis_table_ninf (yytable
[yyj
]))
1763 /* Reduce to one stack. */
1764 for (yyk
= 0; yyk
< yystack
->yytops
.yysize
; yyk
+= 1)
1765 if (yystack
->yytops
.yystates
[yyk
] != NULL
)
1767 if (yyk
>= yystack
->yytops
.yysize
)
1768 yyFail (yystack
][]b4_lpure_args
[, NULL
);
1769 for (yyk
+= 1; yyk
< yystack
->yytops
.yysize
; yyk
+= 1)
1770 yymarkStackDeleted (yystack
, yyk
);
1771 yyremoveDeletes (yystack
);
1772 yycompressStack (yystack
);
1774 /* Now pop stack until we find a state that shifts the error token. */
1775 yystack
->yyerrState
= 3;
1776 while (yystack
->yytops
.yystates
[0] != NULL
)
1778 yyGLRState
*yys
= yystack
->yytops
.yystates
[0];
1779 yyj
= yypact
[yys
->yylrState
];
1780 if (! yyis_pact_ninf (yyj
))
1783 if (0 <= yyj
&& yyj
<= YYLAST
&& yycheck
[yyj
] == YYTERROR
1784 && yyisShiftAction (yytable
[yyj
]))
1786 /* Shift the error token having adjusted its location. */
1787 YYLTYPE yyerrloc
;]b4_location_if([[
1788 yystack
->yyerror_range
[1] = *yyllocp
;
1789 # define YYRHSLOC(yyRhs,YYK) ((yyRhs)[YYK])
1790 YYLLOC_DEFAULT (yyerrloc
, yystack
->yyerror_range
- 1, 2);
1791 # undef YYRHSLOC]])[
1792 YY_SYMBOL_PRINT ("Shifting", yystos
[yytable
[yyj
]],
1793 yylvalp
, &yyerrloc
);
1794 yyglrShift (yystack
, 0, yytable
[yyj
],
1795 yys
->yyposn
, *yylvalp
, &yyerrloc
]b4_user_args
[);
1796 yys
= yystack
->yytops
.yystates
[0];
1800 ]b4_location_if([[ yystack
->yyerror_range
[0] = yys
->yyloc
;]])[
1801 yydestruct ("Error: popping",
1802 yystos
[yys
->yylrState
],
1803 &yys
->yysemantics
.yysval
]b4_location_if([, &yys
->yyloc
])[);
1804 yystack
->yytops
.yystates
[0] = yys
->yypred
;
1805 yystack
->yynextFree
-= 1;
1806 yystack
->yyspaceLeft
+= 1;
1808 if (yystack
->yytops
.yystates
[0] == NULL
)
1809 yyFail (yystack
][]b4_lpure_args
[, NULL
);
1812 #define YYCHK1(YYE) \
1818 yystack.yyerrflag = 1; \
1821 yystack.yyerrflag = 0; \
1824 goto yyuser_error; \
1833 ]b4_c_ansi_function_def([yyparse
], [int], b4_parse_param
)[
1843 #define yychar (yystack.yyrawchar)
1846 YYSTYPE
* const yylvalp
= &yylval
;
1847 YYLTYPE
* const yyllocp
= &yylloc
;
1849 yyinitGLRStack (&yystack
, YYINITDEPTH
);
1850 yystack
.yytokenp
= &yytoken
;
1852 YYDPRINTF ((stderr
, "Starting parse\n"));
1854 if (setjmp (yystack
.yyexception_buffer
) != 0)
1857 yylval
= yyval_default
;
1859 #if YYLTYPE_IS_TRIVIAL
1860 yylloc
.first_line
= yylloc
.last_line
= 1;
1861 yylloc
.first_column
= yylloc
.last_column
= 0;
1864 m4_ifdef([b4_initial_action
], [
1865 m4_pushdef([b4_at_dollar
], [yylval
])dnl
1866 m4_pushdef([b4_dollar_dollar
], [yylloc
])dnl
1867 /* User initialization code. */
1869 m4_popdef([b4_dollar_dollar
])dnl
1870 m4_popdef([b4_at_dollar
])dnl
1871 /* Line __line__ of glr.c. */
1872 b4_syncline([@oline@
], [@ofile@
])])dnl
1874 yyglrShift (&yystack
, 0, 0, 0, yylval
, &yylloc
]b4_user_args
[);
1880 /* For efficiency, we have two loops, the first of which is
1881 specialized to deterministic operation (single stack, no
1882 potential ambiguity). */
1888 const short int* yyconflicts
;
1890 yyStateNum yystate
= yystack
.yytops
.yystates
[0]->yylrState
;
1891 YYDPRINTF ((stderr
, "Entering state %d\n", yystate
));
1892 if (yystate
== YYFINAL
)
1894 if (yyisDefaultedState (yystate
))
1896 yyrule
= yydefaultAction (yystate
);
1899 ]b4_location_if([[ yystack
.yyerror_range
[0] = *yyllocp
;]])[
1900 yyreportSyntaxError (&yystack
, yylvalp
, yyllocp
]b4_user_args
[);
1903 YYCHK1 (yyglrReduce (&yystack
, 0, yyrule
, yytrue
]b4_lpure_args
[));
1907 if (yytoken
== YYEMPTY
)
1909 YYDPRINTF ((stderr
, "Reading a token: "));
1911 yytoken
= YYTRANSLATE (yychar
);
1912 YY_SYMBOL_PRINT ("Next token is", yytoken
, yylvalp
, yyllocp
);
1914 yygetLRActions (yystate
, yytoken
, &yyaction
, &yyconflicts
);
1915 if (*yyconflicts
!= 0)
1917 if (yyisShiftAction (yyaction
))
1919 YY_SYMBOL_PRINT ("Shifting", yytoken
, yylvalp
, yyllocp
);
1920 if (yytoken
!= YYEOF
)
1923 yyglrShift (&yystack
, 0, yyaction
, yyposn
,
1924 yylval
, yyllocp
]b4_user_args
[);
1925 if (0 < yystack
.yyerrState
)
1926 yystack
.yyerrState
-= 1;
1928 else if (yyisErrorAction (yyaction
))
1930 ]b4_location_if([[ yystack
.yyerror_range
[0] = *yyllocp
;]])[
1931 yyreportSyntaxError (&yystack
, yylvalp
, yyllocp
]b4_user_args
[);
1935 YYCHK1 (yyglrReduce (&yystack
, 0, -yyaction
, yytrue
]b4_lpure_args
[));
1942 int yyn
= yystack
.yytops
.yysize
;
1943 for (yys
= 0; yys
< yyn
; yys
+= 1)
1944 YYCHK1 (yyprocessOneStack (&yystack
, yys
, yyposn
,
1945 yylvalp
, yyllocp
]b4_user_args
[));
1948 yyremoveDeletes (&yystack
);
1949 if (yystack
.yytops
.yysize
== 0)
1951 yyundeleteLastStack (&yystack
);
1952 if (yystack
.yytops
.yysize
== 0)
1953 yyFail (&yystack
][]b4_lpure_args
[, "syntax error");
1954 YYCHK1 (yyresolveStack (&yystack
]b4_user_args
[));
1955 YYDPRINTF ((stderr
, "Returning to deterministic operation.\n"));
1956 ]b4_location_if([[ yystack
.yyerror_range
[0] = *yyllocp
;]])[
1957 yyreportSyntaxError (&yystack
, yylvalp
, yyllocp
]b4_user_args
[);
1960 else if (yystack
.yytops
.yysize
== 1)
1962 YYCHK1 (yyresolveStack (&yystack
]b4_user_args
[));
1963 YYDPRINTF ((stderr
, "Returning to deterministic operation.\n"));
1964 yycompressStack (&yystack
);
1970 yyrecoverSyntaxError (&yystack
, yylvalp
, yyllocp
]b4_user_args
[);
1971 yyposn
= yystack
.yytops
.yystates
[0]->yyposn
;
1974 /* On YYABORT, free the lookahead. */
1975 if (yystack
.yyerrflag
== 1 && yytoken
!= YYEMPTY
)
1976 yydestruct ("Error: discarding lookahead",
1977 yytoken
, yylvalp
]b4_location_if([, yyllocp
])[);
1979 yyfreeGLRStack (&yystack
);
1980 return yystack
.yyerrflag
;
1983 /* DEBUGGING ONLY */
1985 static void yypstack (yyGLRStack
* yystack
, int yyk
) ATTRIBUTE_UNUSED
;
1986 static void yypdumpstack (yyGLRStack
* yystack
) ATTRIBUTE_UNUSED
;
1989 yy_yypstack (yyGLRState
* yys
)
1993 yy_yypstack (yys
->yypred
);
1994 fprintf (stderr
, " -> ");
1996 fprintf (stderr
, "%d@@%lu", yys
->yylrState
, (unsigned long int) yys
->yyposn
);
2000 yypstates (yyGLRState
* yyst
)
2003 fprintf (stderr
, "<null>");
2006 fprintf (stderr
, "\n");
2010 yypstack (yyGLRStack
* yystack
, int yyk
)
2012 yypstates (yystack
->yytops
.yystates
[yyk
]);
2015 #define YYINDEX(YYX) \
2016 ((YYX) == NULL ? -1 : (yyGLRStackItem*) (YYX) - yystack->yyitems)
2020 yypdumpstack (yyGLRStack
* yystack
)
2022 yyGLRStackItem
* yyp
;
2024 for (yyp
= yystack
->yyitems
; yyp
< yystack
->yynextFree
; yyp
+= 1)
2026 fprintf (stderr
, "%3lu. ", (unsigned long int) (yyp
- yystack
->yyitems
));
2027 if (*(yybool
*) yyp
)
2029 fprintf (stderr
, "Res: %d, LR State: %d, posn: %lu, pred: %ld",
2030 yyp
->yystate
.yyresolved
, yyp
->yystate
.yylrState
,
2031 (unsigned long int) yyp
->yystate
.yyposn
,
2032 (long int) YYINDEX (yyp
->yystate
.yypred
));
2033 if (! yyp
->yystate
.yyresolved
)
2034 fprintf (stderr
, ", firstVal: %ld",
2035 (long int) YYINDEX (yyp
->yystate
.yysemantics
.yyfirstVal
));
2039 fprintf (stderr
, "Option. rule: %d, state: %ld, next: %ld",
2040 yyp
->yyoption
.yyrule
,
2041 (long int) YYINDEX (yyp
->yyoption
.yystate
),
2042 (long int) YYINDEX (yyp
->yyoption
.yynext
));
2044 fprintf (stderr
, "\n");
2046 fprintf (stderr
, "Tops:");
2047 for (yyi
= 0; yyi
< yystack
->yytops
.yysize
; yyi
+= 1)
2048 fprintf (stderr
, "%lu: %ld; ", (unsigned long int) yyi
,
2049 (long int) YYINDEX (yystack
->yytops
.yystates
[yyi
]));
2050 fprintf (stderr
, "\n");
2056 m4_if(b4_defines_flag
, 0, [],
2057 [@output @output_header_name@
2058 b4_copyright([Skeleton parser
for GLR parsing with Bison
], [2002, 2003, 2004])
2060 b4_token_defines(b4_tokens
)
2062 #if ! defined (YYSTYPE) && ! defined (YYSTYPE_IS_DECLARED)
2063 m4_ifdef([b4_stype
],
2064 [b4_syncline([b4_stype_line
], [b4_filename
])
2065 typedef union m4_bregexp(b4_stype
, [^{], [YYSTYPE
])b4_stype YYSTYPE
;
2066 /* Line __line__ of glr.c. */
2067 b4_syncline([@oline@
], [@ofile@
])],
2068 [typedef int YYSTYPE
;])
2069 # define YYSTYPE_IS_DECLARED 1
2070 # define YYSTYPE_IS_TRIVIAL 1
2074 [extern YYSTYPE b4_prefix
[]lval
;])
2076 #if ! defined (YYLTYPE) && ! defined (YYLTYPE_IS_DECLARED)
2077 typedef struct YYLTYPE
2088 # define YYLTYPE_IS_DECLARED 1
2089 # define YYLTYPE_IS_TRIVIAL 1
2092 b4_location_if([b4_pure_if([],
2093 [extern YYLTYPE b4_prefix
[]lloc
;])