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) 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@
])
226 # define YYMALLOC malloc
229 # define YYREALLOC realloc
235 typedef unsigned char yybool
;
244 #ifndef __attribute__
245 /* This feature is available in gcc versions 2.5 and later. */
246 # if !defined (__GNUC__) || __GNUC__ < 2 || \
247 (__GNUC__ == 2 && __GNUC_MINOR__ < 5) || __STRICT_ANSI__
248 # define __attribute__(Spec) /* empty */
253 # define YYASSERT(condition) ((void) ((condition) || (abort (), 0)))
256 #ifndef ATTRIBUTE_UNUSED
257 # define ATTRIBUTE_UNUSED __attribute__ ((__unused__))
260 /* YYFINAL -- State number of the termination state. */
261 #define YYFINAL ]b4_final_state_number[
262 /* YYLAST -- Last index in YYTABLE. */
263 #define YYLAST ]b4_last[
265 /* YYNTOKENS -- Number of terminals. */
266 #define YYNTOKENS ]b4_tokens_number[
267 /* YYNNTS -- Number of nonterminals. */
268 #define YYNNTS ]b4_nterms_number[
269 /* YYNRULES -- Number of rules. */
270 #define YYNRULES ]b4_rules_number[
271 /* YYNRULES -- Number of states. */
272 #define YYNSTATES ]b4_states_number[
273 /* YYMAXRHS -- Maximum number of symbols on right-hand side of rule. */
274 #define YYMAXRHS ]b4_r2_max[
275 /* YYMAXLEFT -- Maximum number of symbols to the left of a handle
276 accessed by $0, $-1, etc., in any rule. */
277 #define YYMAXLEFT ]b4_max_left_semantic_context[
279 /* YYTRANSLATE(X) -- Bison symbol number corresponding to X. */
280 #define YYUNDEFTOK ]b4_undef_token_number[
281 #define YYMAXUTOK ]b4_user_token_number_max[
283 #define YYTRANSLATE(YYX) \
284 ((YYX <= 0) ? YYEOF : \
285 (unsigned int) (YYX) <= YYMAXUTOK ? yytranslate[YYX] : YYUNDEFTOK)
287 /* YYTRANSLATE[YYLEX] -- Bison symbol number corresponding to YYLEX. */
288 static const ]b4_int_type_for([b4_translate
])[ yytranslate
[] =
294 /* YYPRHS[YYN] -- Index of the first RHS symbol of rule number YYN in
296 static const ]b4_int_type_for([b4_prhs
])[ yyprhs
[] =
301 /* YYRHS -- A `-1'-separated list of the rules' RHS. */
302 static const ]b4_int_type_for([b4_rhs
])[ yyrhs
[] =
307 /* YYRLINE[YYN] -- source line where rule number YYN was defined. */
308 static const ]b4_int_type_for([b4_rline
])[ yyrline
[] =
314 #if (YYDEBUG) || YYERROR_VERBOSE
315 /* YYTNME[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM.
316 First, the terminals, then, starting at YYNTOKENS, nonterminals. */
317 static const char *const yytname
[] =
323 /* YYR1[YYN] -- Symbol number of symbol that rule YYN derives. */
324 static const ]b4_int_type_for([b4_r1
])[ yyr1
[] =
329 /* YYR2[YYN] -- Number of symbols composing right hand side of rule YYN. */
330 static const ]b4_int_type_for([b4_r2
])[ yyr2
[] =
335 /* YYDPREC[RULE-NUM] -- Dynamic precedence of rule #RULE-NUM (0 if none). */
336 static const ]b4_int_type_for([b4_dprec
])[ yydprec
[] =
341 /* YYMERGER[RULE-NUM] -- Index of merging function for rule #RULE-NUM. */
342 static const ]b4_int_type_for([b4_merger
])[ yymerger
[] =
347 /* YYDEFACT[S] -- default rule to reduce with in state S when YYTABLE
348 doesn't specify something else to do. Zero means the default is an
350 static const ]b4_int_type_for([b4_defact
])[ yydefact
[] =
355 /* YYPDEFGOTO[NTERM-NUM]. */
356 static const ]b4_int_type_for([b4_defgoto
])[ yydefgoto
[] =
361 /* YYPACT[STATE-NUM] -- Index in YYTABLE of the portion describing
363 #define YYPACT_NINF ]b4_pact_ninf[
364 static const ]b4_int_type_for([b4_pact
])[ yypact
[] =
369 /* YYPGOTO[NTERM-NUM]. */
370 static const ]b4_int_type_for([b4_pgoto
])[ yypgoto
[] =
375 /* YYTABLE[YYPACT[STATE-NUM]]. What to do in state STATE-NUM. If
376 positive, shift that token. If negative, reduce the rule which
377 number is the opposite. If zero, do what YYDEFACT says.
378 If YYTABLE_NINF, syntax error. */
379 #define YYTABLE_NINF ]b4_table_ninf[
380 static const ]b4_int_type_for([b4_table
])[ yytable
[] =
385 /* YYCONFLP[YYPACT[STATE-NUM]] -- Pointer into YYCONFL of start of
386 list of conflicting reductions corresponding to action entry for
387 state STATE-NUM in yytable. 0 means no conflicts. The list in
388 yyconfl is terminated by a rule number of 0. */
389 static const ]b4_int_type_for([b4_conflict_list_heads
])[ yyconflp
[] =
391 ]b4_conflict_list_heads
[
394 /* YYCONFL[I] -- lists of conflicting rule numbers, each terminated by
395 0, pointed into by YYCONFLP. */
396 ]dnl Do
not use b4_int_type_for here
, since there are places where
397 dnl pointers onto yyconfl are taken
, which type is
"short int *".
398 dnl We probably ought to introduce a type
for confl
.
399 [static const short int yyconfl
[] =
401 ]b4_conflicting_rules
[
404 static const ]b4_int_type_for([b4_check
])[ yycheck
[] =
409 /* YYSTOS[STATE-NUM] -- The (internal number of the) accessing
410 symbol of state STATE-NUM. */
411 static const ]b4_int_type_for([b4_stos
])[ yystos
[] =
417 /* Prevent warning if -Wmissing-prototypes. */
418 ]b4_c_ansi_function_decl([yyparse
], [int], b4_parse_param
)[
420 /* Error token number */
423 /* YYLLOC_DEFAULT -- Set CURRENT to span from RHS[1] to RHS[N]. */
426 #define YYRHSLOC(yyRhs,YYK) ((yyRhs)[YYK].yystate.yyloc)
428 #ifndef YYLLOC_DEFAULT
429 # define YYLLOC_DEFAULT(yyCurrent, yyRhs, YYN) \
430 ((yyCurrent).first_line = YYRHSLOC(yyRhs, 1).first_line, \
431 (yyCurrent).first_column = YYRHSLOC(yyRhs, 1).first_column, \
432 (yyCurrent).last_line = YYRHSLOC(yyRhs, YYN).last_line, \
433 (yyCurrent).last_column = YYRHSLOC(yyRhs, YYN).last_column)
435 /* YY_LOCATION_PRINT -- Print the location on the stream.
436 This macro was not mandated originally: define only if we know
437 we won't break user code: when these are the locations we know. */
439 # define YY_LOCATION_PRINT(File, Loc) \
440 fprintf (File, "%d.%d-%d.%d", \
441 (Loc).first_line, (Loc).first_column, \
442 (Loc).last_line, (Loc).last_column)
445 #ifndef YYLLOC_DEFAULT
446 # define YYLLOC_DEFAULT(yyCurrent, yyRhs, YYN) ((void) 0)
450 #ifndef YY_LOCATION_PRINT
451 # define YY_LOCATION_PRINT(File, Loc) ((void) 0)
455 /* YYLEX -- calling `yylex' with the right arguments. */
456 #define YYLEX ]b4_c_function_call([yylex], [int], b4_lex_param)[
461 #define yynerrs (yystack->yyerrcnt)
463 #define yychar (yystack->yyrawchar)],
471 static const int YYEOF
= 0;
472 static const int YYEMPTY
= -2;
474 typedef enum { yyok
, yyaccept
, yyabort
, yyerr
} YYRESULTTAG
;
477 do { YYRESULTTAG yyflag = YYE; if (yyflag != yyok) return yyflag; } \
482 #if ! defined (YYFPRINTF)
483 # define YYFPRINTF fprintf
486 # define YYDPRINTF(Args) \
492 ]b4_yysymprint_generate([b4_c_ansi_function_def
])[
494 # define YY_SYMBOL_PRINT(Title, Type, Value, Location) \
498 YYFPRINTF (stderr, "%s ", Title); \
499 yysymprint (stderr, \
500 Type, Value]b4_location_if([, Location])[); \
501 YYFPRINTF (stderr, "\n"); \
505 /* Nonzero means print parse trace. It is left uninitialized so that
506 multiple parsers can coexist. */
511 # define YYDPRINTF(Args)
512 # define YY_SYMBOL_PRINT(Title, Type, Value, Location)
514 #endif /* !YYDEBUG */
516 /* YYINITDEPTH -- initial size of the parser's stacks. */
518 # define YYINITDEPTH ]b4_stack_depth_init[
521 /* YYMAXDEPTH -- maximum size the stacks can grow to (effective only
522 if the built-in stack extension method is used).
524 Do not make this value too large; the results are undefined if
525 SIZE_MAX < YYMAXDEPTH * sizeof (GLRStackItem)
526 evaluated with infinite-precision integer arithmetic. */
533 # define YYMAXDEPTH ]b4_stack_depth_max[
536 /* Minimum number of free items on the stack allowed after an
537 allocation. This is to allow allocation and initialization
538 to be completed by functions that call expandGLRStack before the
539 stack is expanded, thus insuring that all necessary pointers get
540 properly redirected to new data. */
543 #if (! defined (YYSTACKEXPANDABLE) \
544 && (! defined (__cplusplus) \
545 || (]b4_location_if([[defined (YYLTYPE_IS_TRIVIAL) && YYLTYPE_IS_TRIVIAL \
546 && ]])[defined (YYSTYPE_IS_TRIVIAL) && YYSTYPE_IS_TRIVIAL)))
547 #define YYSTACKEXPANDABLE 1
549 #define YYSTACKEXPANDABLE 0
552 /** State numbers, as in LALR(1) machine */
553 typedef int yyStateNum
;
555 /** Rule numbers, as in LALR(1) machine */
556 typedef int yyRuleNum
;
558 /** Grammar symbol */
559 typedef short int yySymbol
;
561 /** Item references, as in LALR(1) machine */
562 typedef short int yyItemNum
;
564 typedef struct yyGLRState yyGLRState
;
565 typedef struct yySemanticOption yySemanticOption
;
566 typedef union yyGLRStackItem yyGLRStackItem
;
567 typedef struct yyGLRStack yyGLRStack
;
568 typedef struct yyGLRStateSet yyGLRStateSet
;
573 yyStateNum yylrState
;
577 yySemanticOption
* yyfirstVal
;
583 struct yyGLRStateSet
{
584 yyGLRState
** yystates
;
585 size_t yysize
, yycapacity
;
588 struct yySemanticOption
{
592 yySemanticOption
* yynext
;
595 union yyGLRStackItem
{
597 yySemanticOption yyoption
;
609 jmp_buf yyexception_buffer
;
610 yyGLRStackItem
* yyitems
;
611 yyGLRStackItem
* yynextFree
;
613 yyGLRState
* yysplitPoint
;
614 yyGLRState
* yylastDeleted
;
615 yyGLRStateSet yytops
;
618 static void yyinitGLRStack (yyGLRStack
* yystack
, size_t yysize
);
619 static void yyexpandGLRStack (yyGLRStack
* yystack
]b4_pure_formals
[);
620 static void yyfreeGLRStack (yyGLRStack
* yystack
);
623 yyFail (yyGLRStack
* yystack
]b4_pure_formals
[, const char* yyformat
, ...)
625 yystack
->yyerrflag
= 1;
626 if (yyformat
!= NULL
)
630 va_start (yyap
, yyformat
);
631 vsprintf (yymsg
, yyformat
, yyap
);
632 yyerror (]b4_yyerror_args
[yymsg
);
634 longjmp (yystack
->yyexception_buffer
, 1);
637 #if YYDEBUG || YYERROR_VERBOSE
638 /** A printable representation of TOKEN. Valid until next call to
640 static inline const char*
641 yytokenName (yySymbol yytoken
)
643 if (yytoken
== YYEMPTY
)
646 return yytname
[yytoken
];
650 /** Fill in YYVSP[YYLOW1 .. YYLOW0-1] from the chain of states starting
651 * at YYVSP[YYLOW0].yystate.yypred. Leaves YYVSP[YYLOW1].yystate.yypred
652 * containing the pointer to the next state in the chain. Assumes
653 * YYLOW1 < YYLOW0. */
654 static void yyfillin (yyGLRStackItem
*, int, int) ATTRIBUTE_UNUSED
;
656 yyfillin (yyGLRStackItem
*yyvsp
, int yylow0
, int yylow1
)
660 s
= yyvsp
[yylow0
].yystate
.yypred
;
661 for (i
= yylow0
-1; i
>= yylow1
; i
-= 1)
663 YYASSERT (s
->yyresolved
);
664 yyvsp
[i
].yystate
.yyresolved
= yytrue
;
665 yyvsp
[i
].yystate
.yysemantics
.yysval
= s
->yysemantics
.yysval
;
666 yyvsp
[i
].yystate
.yyloc
= s
->yyloc
;
667 s
= yyvsp
[i
].yystate
.yypred
= s
->yypred
;
671 /* Do nothing if YYNORMAL or if *YYLOW <= YYLOW1. Otherwise, fill in
672 YYVSP[YYLOW1 .. *YYLOW-1] as in yyfillin and set *YYLOW = YYLOW1.
673 For convenience, always return YYLOW1. */
674 static inline int yyfill (yyGLRStackItem
*, int *, int, yybool
)
677 yyfill (yyGLRStackItem
*yyvsp
, int *yylow
, int yylow1
, yybool yynormal
)
679 if (!yynormal
&& yylow1
< *yylow
)
681 yyfillin (yyvsp
, *yylow
, yylow1
);
687 /** Perform user action for rule number YYN, with RHS length YYRHSLEN,
688 * and top stack item YYVSP. YYLVALP points to place to put semantic
689 * value ($$), and yylocp points to place for location information
690 * (@@$). Returns yyok for normal return, yyaccept for YYACCEPT,
691 * yyerr for YYERROR, yyabort for YYABORT. */
693 yyuserAction (yyRuleNum yyn
, int yyrhslen
, yyGLRStackItem
* yyvsp
,
694 YYSTYPE
* yyvalp
, YYLTYPE
* yylocp
, yyGLRStack
* yystack
697 yybool yynormal ATTRIBUTE_UNUSED
= (yystack
->yysplitPoint
== NULL
);
701 # define yyerrok (yystack->yyerrState = 0)
703 # define YYACCEPT return yyaccept
705 # define YYABORT return yyabort
707 # define YYERROR return yyerrok, yyerr
709 # define YYRECOVERING (yystack->yyerrState != 0)
711 # define yyclearin (yychar = *(yystack->yytokenp) = YYEMPTY)
713 # define YYFILL(N) yyfill (yyvsp, &yylow, N, yynormal)
715 # define YYBACKUP(Token, Value) \
716 return yyerror (]b4_yyerror_args["syntax error: cannot back up"), \
722 *yyvalp
= yyval_default
;
723 *yylocp
= yyvsp
[0].yystate
.yyloc
;
727 *yyvalp
= yyvsp
[YYFILL (1-yyrhslen
)].yystate
.yysemantics
.yysval
;
728 YYLLOC_DEFAULT (*yylocp
, yyvsp
- yyrhslen
, yyrhslen
);
745 /* Line __line__ of glr.c. */
746 b4_syncline([@oline@
], [@ofile@
])
751 yyuserMerge (int yyn
, YYSTYPE
* yy0
, YYSTYPE
* yy1
)
753 /* `Use' the arguments. */
763 /* Bison grammar-table manipulation. */
765 ]b4_yydestruct_generate([b4_c_ansi_function_def
])[
767 /** Number of symbols composing the right hand side of rule #RULE. */
769 yyrhsLength (yyRuleNum yyrule
)
774 /** Left-hand-side symbol for rule #RULE. */
775 static inline yySymbol
776 yylhsNonterm (yyRuleNum yyrule
)
781 #define yyis_pact_ninf(yystate) \
782 ]m4_if(m4_eval(b4_pact_ninf < b4_pact_min), 1,
784 ((yystate
) == YYPACT_NINF
))[
786 /** True iff LR state STATE has only a default reduction (regardless
789 yyisDefaultedState (yyStateNum yystate
)
791 return yyis_pact_ninf (yypact
[yystate
]);
794 /** The default reduction for STATE, assuming it has one. */
795 static inline yyRuleNum
796 yydefaultAction (yyStateNum yystate
)
798 return yydefact
[yystate
];
801 #define yyis_table_ninf(yytable_value) \
802 ]m4_if(m4_eval(b4_table_ninf < b4_table_min), 1,
804 ((yytable_value
) == YYTABLE_NINF
))[
806 /** Set *YYACTION to the action to take in YYSTATE on seeing YYTOKEN.
808 * R < 0: Reduce on rule -R.
810 * R > 0: Shift to state R.
811 * Set *CONFLICTS to a pointer into yyconfl to 0-terminated list of
812 * conflicting reductions.
815 yygetLRActions (yyStateNum yystate
, int yytoken
,
816 int* yyaction
, const short int** yyconflicts
)
818 int yyindex
= yypact
[yystate
] + yytoken
;
819 if (yyindex
< 0 || YYLAST
< yyindex
|| yycheck
[yyindex
] != yytoken
)
821 *yyaction
= -yydefact
[yystate
];
822 *yyconflicts
= yyconfl
;
824 else if (! yyis_table_ninf (yytable
[yyindex
]))
826 *yyaction
= yytable
[yyindex
];
827 *yyconflicts
= yyconfl
+ yyconflp
[yyindex
];
832 *yyconflicts
= yyconfl
+ yyconflp
[yyindex
];
836 static inline yyStateNum
837 yyLRgotoState (yyStateNum yystate
, yySymbol yylhs
)
840 yyr
= yypgoto
[yylhs
- YYNTOKENS
] + yystate
;
841 if (0 <= yyr
&& yyr
<= YYLAST
&& yycheck
[yyr
] == yystate
)
844 return yydefgoto
[yylhs
- YYNTOKENS
];
848 yyisShiftAction (int yyaction
)
854 yyisErrorAction (int yyaction
)
856 return yyaction
== 0;
862 yyaddDeferredAction (yyGLRStack
* yystack
, yyGLRState
* yystate
,
863 yyGLRState
* rhs
, yyRuleNum yyrule
]b4_pure_formals
[)
865 yySemanticOption
* yynewItem
;
866 yynewItem
= &yystack
->yynextFree
->yyoption
;
867 yystack
->yyspaceLeft
-= 1;
868 yystack
->yynextFree
+= 1;
869 yynewItem
->yyisState
= yyfalse
;
870 yynewItem
->yystate
= rhs
;
871 yynewItem
->yyrule
= yyrule
;
872 yynewItem
->yynext
= yystate
->yysemantics
.yyfirstVal
;
873 yystate
->yysemantics
.yyfirstVal
= yynewItem
;
874 if (yystack
->yyspaceLeft
< YYHEADROOM
)
875 yyexpandGLRStack (yystack
]b4_pure_args
[);
880 /** Initialize SET to a singleton set containing an empty stack. */
882 yyinitStateSet (yyGLRStateSet
* yyset
)
885 yyset
->yycapacity
= 16;
886 yyset
->yystates
= (yyGLRState
**) YYMALLOC (16 * sizeof yyset
->yystates
[0]);
887 yyset
->yystates
[0] = NULL
;
890 static void yyfreeStateSet (yyGLRStateSet
* yyset
)
892 YYFREE (yyset
->yystates
);
895 /** Initialize STACK to a single empty stack, with total maximum
896 * capacity for all stacks of SIZE. */
898 yyinitGLRStack (yyGLRStack
* yystack
, size_t yysize
)
900 yystack
->yyerrflag
= 0;
901 yystack
->yyerrState
= 0;
903 yystack
->yyspaceLeft
= yysize
;
904 yystack
->yynextFree
= yystack
->yyitems
=
905 (yyGLRStackItem
*) YYMALLOC (yysize
* sizeof yystack
->yynextFree
[0]);
906 yystack
->yysplitPoint
= NULL
;
907 yystack
->yylastDeleted
= NULL
;
908 yyinitStateSet (&yystack
->yytops
);
911 #define YYRELOC(YYFROMITEMS,YYTOITEMS,YYX,YYTYPE) \
912 &((YYTOITEMS) - ((YYFROMITEMS) - (yyGLRStackItem*) (YYX)))->YYTYPE
914 /** If STACK is expandable, extend it. WARNING: Pointers into the
915 stack from outside should be considered invalid after this call.
916 We always expand when there are 1 or fewer items left AFTER an
917 allocation, so that we can avoid having external pointers exist
918 across an allocation. */
920 yyexpandGLRStack (yyGLRStack
* yystack
]b4_pure_formals
[)
922 #if YYSTACKEXPANDABLE
923 yyGLRStack yynewStack
;
924 yyGLRStackItem
* yyp0
, *yyp1
;
925 size_t yysize
, yynewSize
;
927 yysize
= yystack
->yynextFree
- yystack
->yyitems
;
928 if (YYMAXDEPTH
<= yysize
)
929 yyFail (yystack
][]b4_pure_args
[, "parser stack overflow");
930 yynewSize
= 2*yysize
;
931 if (YYMAXDEPTH
< yynewSize
)
932 yynewSize
= YYMAXDEPTH
;
933 yyinitGLRStack (&yynewStack
, yynewSize
);
934 for (yyp0
= yystack
->yyitems
, yyp1
= yynewStack
.yyitems
, yyn
= yysize
;
936 yyn
-= 1, yyp0
+= 1, yyp1
+= 1)
939 if (*(yybool
*) yyp0
)
941 yyGLRState
* yys0
= &yyp0
->yystate
;
942 yyGLRState
* yys1
= &yyp1
->yystate
;
943 if (yys0
->yypred
!= NULL
)
945 YYRELOC (yyp0
, yyp1
, yys0
->yypred
, yystate
);
946 if (! yys0
->yyresolved
&& yys0
->yysemantics
.yyfirstVal
!= NULL
)
947 yys1
->yysemantics
.yyfirstVal
=
948 YYRELOC(yyp0
, yyp1
, yys0
->yysemantics
.yyfirstVal
, yyoption
);
952 yySemanticOption
* yyv0
= &yyp0
->yyoption
;
953 yySemanticOption
* yyv1
= &yyp1
->yyoption
;
954 if (yyv0
->yystate
!= NULL
)
955 yyv1
->yystate
= YYRELOC (yyp0
, yyp1
, yyv0
->yystate
, yystate
);
956 if (yyv0
->yynext
!= NULL
)
957 yyv1
->yynext
= YYRELOC (yyp0
, yyp1
, yyv0
->yynext
, yyoption
);
960 if (yystack
->yysplitPoint
!= NULL
)
961 yystack
->yysplitPoint
= YYRELOC (yystack
->yyitems
, yynewStack
.yyitems
,
962 yystack
->yysplitPoint
, yystate
);
964 for (yyn
= 0; yyn
< yystack
->yytops
.yysize
; yyn
+= 1)
965 if (yystack
->yytops
.yystates
[yyn
] != NULL
)
966 yystack
->yytops
.yystates
[yyn
] =
967 YYRELOC (yystack
->yyitems
, yynewStack
.yyitems
,
968 yystack
->yytops
.yystates
[yyn
], yystate
);
969 YYFREE (yystack
->yyitems
);
970 yystack
->yyitems
= yynewStack
.yyitems
;
971 yystack
->yynextFree
= yynewStack
.yynextFree
+ yysize
;
972 yystack
->yyspaceLeft
= yynewStack
.yyspaceLeft
- yysize
;
976 yyFail (yystack
][]b4_pure_args
[, "parser stack overflow");
981 yyfreeGLRStack (yyGLRStack
* yystack
)
983 YYFREE (yystack
->yyitems
);
984 yyfreeStateSet (&yystack
->yytops
);
987 /** Assuming that S is a GLRState somewhere on STACK, update the
988 * splitpoint of STACK, if needed, so that it is at least as deep as
991 yyupdateSplit (yyGLRStack
* yystack
, yyGLRState
* yys
)
993 if (yystack
->yysplitPoint
!= NULL
&& yystack
->yysplitPoint
> yys
)
994 yystack
->yysplitPoint
= yys
;
997 /** Invalidate stack #K in STACK. */
999 yymarkStackDeleted (yyGLRStack
* yystack
, int yyk
)
1001 if (yystack
->yytops
.yystates
[yyk
] != NULL
)
1002 yystack
->yylastDeleted
= yystack
->yytops
.yystates
[yyk
];
1003 yystack
->yytops
.yystates
[yyk
] = NULL
;
1006 /** Undelete the last stack that was marked as deleted. Can only be
1007 done once after a deletion, and only when all other stacks have
1010 yyundeleteLastStack (yyGLRStack
* yystack
)
1012 if (yystack
->yylastDeleted
== NULL
|| yystack
->yytops
.yysize
!= 0)
1014 yystack
->yytops
.yystates
[0] = yystack
->yylastDeleted
;
1015 yystack
->yytops
.yysize
= 1;
1016 YYDPRINTF ((stderr
, "Restoring last deleted stack as stack #0.\n"));
1017 yystack
->yylastDeleted
= NULL
;
1021 yyremoveDeletes (yyGLRStack
* yystack
)
1025 while (yyj
< yystack
->yytops
.yysize
)
1027 if (yystack
->yytops
.yystates
[yyi
] == NULL
)
1031 YYDPRINTF ((stderr
, "Removing dead stacks.\n"));
1033 yystack
->yytops
.yysize
-= 1;
1037 yystack
->yytops
.yystates
[yyj
] = yystack
->yytops
.yystates
[yyi
];
1040 YYDPRINTF ((stderr
, "Rename stack %lu -> %lu.\n",
1041 (unsigned long int) yyi
, (unsigned long int) yyj
));
1049 /** Shift to a new state on stack #K of STACK, corresponding to LR state
1050 * LRSTATE, at input position POSN, with (resolved) semantic value SVAL. */
1052 yyglrShift (yyGLRStack
* yystack
, int yyk
, yyStateNum yylrState
, size_t yyposn
,
1053 YYSTYPE yysval
, YYLTYPE
* yylocp
]b4_user_formals
[)
1055 yyGLRStackItem
* yynewItem
;
1057 yynewItem
= yystack
->yynextFree
;
1058 yystack
->yynextFree
+= 1;
1059 yystack
->yyspaceLeft
-= 1;
1060 yynewItem
->yystate
.yyisState
= yytrue
;
1061 yynewItem
->yystate
.yylrState
= yylrState
;
1062 yynewItem
->yystate
.yyposn
= yyposn
;
1063 yynewItem
->yystate
.yyresolved
= yytrue
;
1064 yynewItem
->yystate
.yypred
= yystack
->yytops
.yystates
[yyk
];
1065 yystack
->yytops
.yystates
[yyk
] = &yynewItem
->yystate
;
1066 yynewItem
->yystate
.yysemantics
.yysval
= yysval
;
1067 yynewItem
->yystate
.yyloc
= *yylocp
;
1068 if (yystack
->yyspaceLeft
< YYHEADROOM
)
1069 yyexpandGLRStack (yystack
]b4_pure_args
[);
1072 /** Shift stack #K of YYSTACK, to a new state corresponding to LR
1073 * state YYLRSTATE, at input position YYPOSN, with the (unresolved)
1074 * semantic value of YYRHS under the action for YYRULE. */
1076 yyglrShiftDefer (yyGLRStack
* yystack
, int yyk
, yyStateNum yylrState
,
1077 size_t yyposn
, yyGLRState
* rhs
, yyRuleNum yyrule
]b4_pure_formals
[)
1079 yyGLRStackItem
* yynewItem
;
1081 yynewItem
= yystack
->yynextFree
;
1082 yynewItem
->yystate
.yyisState
= yytrue
;
1083 yynewItem
->yystate
.yylrState
= yylrState
;
1084 yynewItem
->yystate
.yyposn
= yyposn
;
1085 yynewItem
->yystate
.yyresolved
= yyfalse
;
1086 yynewItem
->yystate
.yypred
= yystack
->yytops
.yystates
[yyk
];
1087 yynewItem
->yystate
.yysemantics
.yyfirstVal
= NULL
;
1088 yystack
->yytops
.yystates
[yyk
] = &yynewItem
->yystate
;
1089 yystack
->yynextFree
+= 1;
1090 yystack
->yyspaceLeft
-= 1;
1091 yyaddDeferredAction (yystack
, &yynewItem
->yystate
, rhs
, yyrule
]b4_pure_args
[);
1094 /** Pop the symbols consumed by reduction #RULE from the top of stack
1095 * #K of STACK, and perform the appropriate semantic action on their
1096 * semantic values. Assumes that all ambiguities in semantic values
1097 * have been previously resolved. Set *VALP to the resulting value,
1098 * and *LOCP to the computed location (if any). Return value is as
1099 * for userAction. */
1100 static inline YYRESULTTAG
1101 yydoAction (yyGLRStack
* yystack
, int yyk
, yyRuleNum yyrule
,
1102 YYSTYPE
* yyvalp
, YYLTYPE
* yylocp
]b4_user_formals
[)
1104 int yynrhs
= yyrhsLength (yyrule
);
1106 if (yystack
->yysplitPoint
== NULL
)
1108 /* Standard special case: single stack. */
1109 yyGLRStackItem
* rhs
= (yyGLRStackItem
*) yystack
->yytops
.yystates
[yyk
];
1110 YYASSERT (yyk
== 0);
1111 yystack
->yynextFree
-= yynrhs
;
1112 yystack
->yyspaceLeft
+= yynrhs
;
1113 yystack
->yytops
.yystates
[0] = & yystack
->yynextFree
[-1].yystate
;
1114 return yyuserAction (yyrule
, yynrhs
, rhs
,
1115 yyvalp
, yylocp
, yystack
]b4_user_args
[);
1121 yyGLRStackItem yyrhsVals
[YYMAXRHS
+ YYMAXLEFT
+ 1];
1122 yys
= yyrhsVals
[YYMAXRHS
+ YYMAXLEFT
].yystate
.yypred
1123 = yystack
->yytops
.yystates
[yyk
];
1124 for (yyi
= 0; yyi
< yynrhs
; yyi
+= 1)
1129 yyupdateSplit (yystack
, yys
);
1130 yystack
->yytops
.yystates
[yyk
] = yys
;
1131 return yyuserAction (yyrule
, yynrhs
, yyrhsVals
+ YYMAXRHS
+ YYMAXLEFT
- 1,
1132 yyvalp
, yylocp
, yystack
]b4_user_args
[);
1137 # define YY_REDUCE_PRINT(K, Rule)
1139 # define YY_REDUCE_PRINT(K, Rule) \
1142 yy_reduce_print (K, Rule); \
1145 /*----------------------------------------------------------.
1146 | Report that the RULE is going to be reduced on stack #K. |
1147 `----------------------------------------------------------*/
1150 yy_reduce_print (size_t yyk
, yyRuleNum yyrule
)
1153 YYFPRINTF (stderr
, "Reducing stack %lu by rule %d (line %lu), ",
1154 (unsigned long int) yyk
, yyrule
- 1,
1155 (unsigned long int) yyrline
[yyrule
]);
1156 /* Print the symbols being reduced, and their result. */
1157 for (yyi
= yyprhs
[yyrule
]; 0 <= yyrhs
[yyi
]; yyi
++)
1158 YYFPRINTF (stderr
, "%s ", yytokenName (yyrhs
[yyi
]));
1159 YYFPRINTF (stderr
, "-> %s\n", yytokenName (yyr1
[yyrule
]));
1163 /** Pop items off stack #K of STACK according to grammar rule RULE,
1164 * and push back on the resulting nonterminal symbol. Perform the
1165 * semantic action associated with RULE and store its value with the
1166 * newly pushed state, if FORCEEVAL or if STACK is currently
1167 * unambiguous. Otherwise, store the deferred semantic action with
1168 * the new state. If the new state would have an identical input
1169 * position, LR state, and predecessor to an existing state on the stack,
1170 * it is identified with that existing state, eliminating stack #K from
1171 * the STACK. In this case, the (necessarily deferred) semantic value is
1172 * added to the options for the existing state's semantic value.
1174 static inline YYRESULTTAG
1175 yyglrReduce (yyGLRStack
* yystack
, size_t yyk
, yyRuleNum yyrule
,
1176 yybool yyforceEval
]b4_pure_formals
[)
1178 size_t yyposn
= yystack
->yytops
.yystates
[yyk
]->yyposn
;
1180 if (yyforceEval
|| yystack
->yysplitPoint
== NULL
)
1185 YY_REDUCE_PRINT (yyk
, yyrule
);
1186 YYCHK (yydoAction (yystack
, yyk
, yyrule
, &yysval
, &yyloc
]b4_user_args
[));
1187 yyglrShift (yystack
, yyk
,
1188 yyLRgotoState (yystack
->yytops
.yystates
[yyk
]->yylrState
,
1189 yylhsNonterm (yyrule
)),
1190 yyposn
, yysval
, &yyloc
]b4_user_args
[);
1196 yyGLRState
* yys
, *yys0
= yystack
->yytops
.yystates
[yyk
];
1197 yyStateNum yynewLRState
;
1199 for (yys
= yystack
->yytops
.yystates
[yyk
], yyn
= yyrhsLength (yyrule
);
1205 yyupdateSplit (yystack
, yys
);
1206 yynewLRState
= yyLRgotoState (yys
->yylrState
, yylhsNonterm (yyrule
));
1208 "Reduced stack %lu by rule #%d; action deferred. Now in state %d.\n",
1209 (unsigned long int) yyk
, yyrule
- 1, yynewLRState
));
1210 for (yyi
= 0; yyi
< yystack
->yytops
.yysize
; yyi
+= 1)
1211 if (yyi
!= yyk
&& yystack
->yytops
.yystates
[yyi
] != NULL
)
1213 yyGLRState
* yyp
, *yysplit
= yystack
->yysplitPoint
;
1214 yyp
= yystack
->yytops
.yystates
[yyi
];
1215 while (yyp
!= yys
&& yyp
!= yysplit
&& yyp
->yyposn
>= yyposn
)
1217 if (yyp
->yylrState
== yynewLRState
&& yyp
->yypred
== yys
)
1219 yyaddDeferredAction (yystack
, yyp
, yys0
, yyrule
]b4_pure_args
[);
1220 yymarkStackDeleted (yystack
, yyk
);
1221 YYDPRINTF ((stderr
, "Merging stack %lu into stack %lu.\n",
1222 (unsigned long int) yyk
,
1223 (unsigned long int) yyi
));
1229 yystack
->yytops
.yystates
[yyk
] = yys
;
1230 yyglrShiftDefer (yystack
, yyk
, yynewLRState
, yyposn
, yys0
, yyrule
]b4_pure_args
[);
1236 yysplitStack (yyGLRStack
* yystack
, int yyk
)
1238 if (yystack
->yysplitPoint
== NULL
)
1240 YYASSERT (yyk
== 0);
1241 yystack
->yysplitPoint
= yystack
->yytops
.yystates
[yyk
];
1243 if (yystack
->yytops
.yysize
>= yystack
->yytops
.yycapacity
)
1245 yystack
->yytops
.yycapacity
*= 2;
1246 yystack
->yytops
.yystates
=
1247 (yyGLRState
**) YYREALLOC (yystack
->yytops
.yystates
,
1248 (yystack
->yytops
.yycapacity
1249 * sizeof yystack
->yytops
.yystates
[0]));
1251 yystack
->yytops
.yystates
[yystack
->yytops
.yysize
]
1252 = yystack
->yytops
.yystates
[yyk
];
1253 yystack
->yytops
.yysize
+= 1;
1254 return yystack
->yytops
.yysize
-1;
1257 /** True iff Y0 and Y1 represent identical options at the top level.
1258 * That is, they represent the same rule applied to RHS symbols
1259 * that produce the same terminal symbols. */
1261 yyidenticalOptions (yySemanticOption
* yyy0
, yySemanticOption
* yyy1
)
1263 if (yyy0
->yyrule
== yyy1
->yyrule
)
1265 yyGLRState
*yys0
, *yys1
;
1267 for (yys0
= yyy0
->yystate
, yys1
= yyy1
->yystate
,
1268 yyn
= yyrhsLength (yyy0
->yyrule
);
1270 yys0
= yys0
->yypred
, yys1
= yys1
->yypred
, yyn
-= 1)
1271 if (yys0
->yyposn
!= yys1
->yyposn
)
1279 /** Assuming identicalOptions (Y0,Y1), (destructively) merge the
1280 * alternative semantic values for the RHS-symbols of Y1 into the
1281 * corresponding semantic value sets of the symbols of Y0. */
1283 yymergeOptionSets (yySemanticOption
* yyy0
, yySemanticOption
* yyy1
)
1285 yyGLRState
*yys0
, *yys1
;
1287 for (yys0
= yyy0
->yystate
, yys1
= yyy1
->yystate
,
1288 yyn
= yyrhsLength (yyy0
->yyrule
);
1290 yys0
= yys0
->yypred
, yys1
= yys1
->yypred
, yyn
-= 1)
1293 else if (! yys0
->yyresolved
&& ! yys1
->yyresolved
)
1295 yySemanticOption
* yyz
;
1296 for (yyz
= yys0
->yysemantics
.yyfirstVal
; yyz
->yynext
!= NULL
;
1299 yyz
->yynext
= yys1
->yysemantics
.yyfirstVal
;
1303 /** Y0 and Y1 represent two possible actions to take in a given
1304 * parsing state; return 0 if no combination is possible,
1305 * 1 if user-mergeable, 2 if Y0 is preferred, 3 if Y1 is preferred. */
1307 yypreference (yySemanticOption
* y0
, yySemanticOption
* y1
)
1309 yyRuleNum r0
= y0
->yyrule
, r1
= y1
->yyrule
;
1310 int p0
= yydprec
[r0
], p1
= yydprec
[r1
];
1314 if (yymerger
[r0
] == 0 || yymerger
[r0
] != yymerger
[r1
])
1319 if (p0
== 0 || p1
== 0)
1328 static YYRESULTTAG
yyresolveValue (yySemanticOption
* yyoptionList
,
1329 yyGLRStack
* yystack
, YYSTYPE
* yyvalp
,
1330 YYLTYPE
* yylocp
]b4_user_formals
[);
1333 yyresolveStates (yyGLRState
* yys
, int yyn
, yyGLRStack
* yystack
]b4_user_formals
[)
1338 YYASSERT (yys
->yypred
);
1339 yyflag
= yyresolveStates (yys
->yypred
, yyn
-1, yystack
]b4_user_args
[);
1342 if (! yys
->yyresolved
)
1344 yyflag
= yyresolveValue (yys
->yysemantics
.yyfirstVal
, yystack
,
1345 &yys
->yysemantics
.yysval
, &yys
->yyloc
1349 yys
->yyresolved
= yytrue
;
1356 yyresolveAction (yySemanticOption
* yyopt
, yyGLRStack
* yystack
,
1357 YYSTYPE
* yyvalp
, YYLTYPE
* yylocp
]b4_user_formals
[)
1359 yyGLRStackItem yyrhsVals
[YYMAXRHS
+ YYMAXLEFT
+ 1];
1362 yynrhs
= yyrhsLength (yyopt
->yyrule
);
1363 YYCHK (yyresolveStates (yyopt
->yystate
, yynrhs
, yystack
]b4_user_args
[));
1364 yyrhsVals
[YYMAXRHS
+ YYMAXLEFT
].yystate
.yypred
= yyopt
->yystate
;
1365 return yyuserAction (yyopt
->yyrule
, yynrhs
,
1366 yyrhsVals
+ YYMAXRHS
+ YYMAXLEFT
- 1,
1367 yyvalp
, yylocp
, yystack
]b4_user_args
[);
1372 yyreportTree (yySemanticOption
* yyx
, int yyindent
)
1374 int yynrhs
= yyrhsLength (yyx
->yyrule
);
1377 yyGLRState
* yystates
[YYMAXRHS
];
1378 yyGLRState yyleftmost_state
;
1380 for (yyi
= yynrhs
, yys
= yyx
->yystate
; 0 < yyi
; yyi
-= 1, yys
= yys
->yypred
)
1381 yystates
[yyi
] = yys
;
1384 yyleftmost_state
.yyposn
= 0;
1385 yystates
[0] = &yyleftmost_state
;
1390 if (yyx
->yystate
->yyposn
< yys
->yyposn
+ 1)
1391 YYFPRINTF (stderr
, "%*s%s -> <Rule %d, empty>\n",
1392 yyindent
, "", yytokenName (yylhsNonterm (yyx
->yyrule
)),
1395 YYFPRINTF (stderr
, "%*s%s -> <Rule %d, tokens %lu .. %lu>\n",
1396 yyindent
, "", yytokenName (yylhsNonterm (yyx
->yyrule
)),
1397 yyx
->yyrule
, (unsigned long int) (yys
->yyposn
+ 1),
1398 (unsigned long int) yyx
->yystate
->yyposn
);
1399 for (yyi
= 1; yyi
<= yynrhs
; yyi
+= 1)
1401 if (yystates
[yyi
]->yyresolved
)
1403 if (yystates
[yyi
-1]->yyposn
+1 > yystates
[yyi
]->yyposn
)
1404 YYFPRINTF (stderr
, "%*s%s <empty>\n", yyindent
+2, "",
1405 yytokenName (yyrhs
[yyprhs
[yyx
->yyrule
]+yyi
-1]));
1407 YYFPRINTF (stderr
, "%*s%s <tokens %lu .. %lu>\n", yyindent
+2, "",
1408 yytokenName (yyrhs
[yyprhs
[yyx
->yyrule
]+yyi
-1]),
1409 (unsigned long int) (yystates
[yyi
- 1]->yyposn
+ 1),
1410 (unsigned long int) yystates
[yyi
]->yyposn
);
1413 yyreportTree (yystates
[yyi
]->yysemantics
.yyfirstVal
, yyindent
+2);
1419 yyreportAmbiguity (yySemanticOption
* yyx0
, yySemanticOption
* yyx1
,
1420 yyGLRStack
* yystack
]b4_pure_formals
[)
1422 /* `Unused' warnings. */
1427 YYFPRINTF (stderr
, "Ambiguity detected.\n");
1428 YYFPRINTF (stderr
, "Option 1,\n");
1429 yyreportTree (yyx0
, 2);
1430 YYFPRINTF (stderr
, "\nOption 2,\n");
1431 yyreportTree (yyx1
, 2);
1432 YYFPRINTF (stderr
, "\n");
1434 yyFail (yystack
][]b4_pure_args
[, "ambiguity detected");
1438 /** Resolve the ambiguity represented by OPTIONLIST, perform the indicated
1439 * actions, and return the result. */
1441 yyresolveValue (yySemanticOption
* yyoptionList
, yyGLRStack
* yystack
,
1442 YYSTYPE
* yyvalp
, YYLTYPE
* yylocp
]b4_user_formals
[)
1444 yySemanticOption
* yybest
;
1445 yySemanticOption
* yyp
;
1448 yybest
= yyoptionList
;
1450 for (yyp
= yyoptionList
->yynext
; yyp
!= NULL
; yyp
= yyp
->yynext
)
1452 if (yyidenticalOptions (yybest
, yyp
))
1453 yymergeOptionSets (yybest
, yyp
);
1455 switch (yypreference (yybest
, yyp
))
1458 yyreportAmbiguity (yybest
, yyp
, yystack
]b4_pure_args
[);
1474 int yyprec
= yydprec
[yybest
->yyrule
];
1475 YYCHK (yyresolveAction (yybest
, yystack
, yyvalp
, yylocp
]b4_user_args
[));
1476 for (yyp
= yybest
->yynext
; yyp
!= NULL
; yyp
= yyp
->yynext
)
1478 if (yyprec
== yydprec
[yyp
->yyrule
])
1482 YYCHK (yyresolveAction (yyp
, yystack
, &yyval1
, &yydummy
]b4_user_args
[));
1483 yyuserMerge (yymerger
[yyp
->yyrule
], yyvalp
, &yyval1
);
1489 return yyresolveAction (yybest
, yystack
, yyvalp
, yylocp
]b4_user_args
[);
1493 yyresolveStack (yyGLRStack
* yystack
]b4_user_formals
[)
1495 if (yystack
->yysplitPoint
!= NULL
)
1500 for (yyn
= 0, yys
= yystack
->yytops
.yystates
[0];
1501 yys
!= yystack
->yysplitPoint
;
1502 yys
= yys
->yypred
, yyn
+= 1)
1504 YYCHK (yyresolveStates (yystack
->yytops
.yystates
[0], yyn
, yystack
1511 yycompressStack (yyGLRStack
* yystack
)
1513 yyGLRState
* yyp
, *yyq
, *yyr
;
1515 if (yystack
->yytops
.yysize
!= 1 || yystack
->yysplitPoint
== NULL
)
1518 for (yyp
= yystack
->yytops
.yystates
[0], yyq
= yyp
->yypred
, yyr
= NULL
;
1519 yyp
!= yystack
->yysplitPoint
;
1520 yyr
= yyp
, yyp
= yyq
, yyq
= yyp
->yypred
)
1523 yystack
->yyspaceLeft
+= yystack
->yynextFree
- yystack
->yyitems
;
1524 yystack
->yynextFree
= ((yyGLRStackItem
*) yystack
->yysplitPoint
) + 1;
1525 yystack
->yyspaceLeft
-= yystack
->yynextFree
- yystack
->yyitems
;
1526 yystack
->yysplitPoint
= NULL
;
1527 yystack
->yylastDeleted
= NULL
;
1531 yystack
->yynextFree
->yystate
= *yyr
;
1533 yystack
->yynextFree
->yystate
.yypred
= & yystack
->yynextFree
[-1].yystate
;
1534 yystack
->yytops
.yystates
[0] = &yystack
->yynextFree
->yystate
;
1535 yystack
->yynextFree
+= 1;
1536 yystack
->yyspaceLeft
-= 1;
1541 yyprocessOneStack (yyGLRStack
* yystack
, int yyk
,
1542 size_t yyposn
, YYSTYPE
* yylvalp
, YYLTYPE
* yyllocp
1546 const short int* yyconflicts
;
1548 yySymbol
* const yytokenp
= yystack
->yytokenp
;
1550 while (yystack
->yytops
.yystates
[yyk
] != NULL
)
1552 yyStateNum yystate
= yystack
->yytops
.yystates
[yyk
]->yylrState
;
1553 YYDPRINTF ((stderr
, "Stack %d Entering state %d\n", yyk
, yystate
));
1555 YYASSERT (yystate
!= YYFINAL
);
1557 if (yyisDefaultedState (yystate
))
1559 yyrule
= yydefaultAction (yystate
);
1562 YYDPRINTF ((stderr
, "Stack %d dies.\n", yyk
));
1563 yymarkStackDeleted (yystack
, yyk
);
1566 YYCHK (yyglrReduce (yystack
, yyk
, yyrule
, yyfalse
]b4_lpure_args
[));
1570 if (*yytokenp
== YYEMPTY
)
1572 YYDPRINTF ((stderr
, "Reading a token: "));
1574 *yytokenp
= YYTRANSLATE (yychar
);
1575 YY_SYMBOL_PRINT ("Next token is", *yytokenp
, yylvalp
, yyllocp
);
1577 yygetLRActions (yystate
, *yytokenp
, &yyaction
, &yyconflicts
);
1579 while (*yyconflicts
!= 0)
1581 int yynewStack
= yysplitStack (yystack
, yyk
);
1582 YYDPRINTF ((stderr
, "Splitting off stack %d from %d.\n",
1584 YYCHK (yyglrReduce (yystack
, yynewStack
,
1585 *yyconflicts
, yyfalse
]b4_lpure_args
[));
1586 YYCHK (yyprocessOneStack (yystack
, yynewStack
, yyposn
,
1587 yylvalp
, yyllocp
]b4_user_args
[));
1591 if (yyisShiftAction (yyaction
))
1593 YYDPRINTF ((stderr
, "On stack %d, ", yyk
));
1594 YY_SYMBOL_PRINT ("shifting", *yytokenp
, yylvalp
, yyllocp
);
1595 yyglrShift (yystack
, yyk
, yyaction
, yyposn
+1,
1596 *yylvalp
, yyllocp
]b4_user_args
[);
1597 YYDPRINTF ((stderr
, ", now in state #%d\n",
1598 yystack
->yytops
.yystates
[yyk
]->yylrState
));
1601 else if (yyisErrorAction (yyaction
))
1603 YYDPRINTF ((stderr
, "Stack %d dies.\n", yyk
));
1604 yymarkStackDeleted (yystack
, yyk
);
1608 YYCHK (yyglrReduce (yystack
, yyk
, -yyaction
, yyfalse
]b4_lpure_args
[));
1615 yyreportSyntaxError (yyGLRStack
* yystack
,
1616 YYSTYPE
* yylvalp
, YYLTYPE
* yyllocp
]b4_user_formals
[)
1618 /* `Unused' warnings. */
1622 if (yystack
->yyerrState
== 0)
1625 yySymbol
* const yytokenp
= yystack
->yytokenp
;
1627 yyn
= yypact
[yystack
->yytops
.yystates
[0]->yylrState
];
1628 if (YYPACT_NINF
< yyn
&& yyn
< YYLAST
)
1631 const char* yyprefix
;
1635 /* Start YYX at -YYN if negative to avoid negative indexes in
1637 int yyxbegin
= yyn
< 0 ? -yyn
: 0;
1639 /* Stay within bounds of both yycheck and yytname. */
1640 int yychecklim
= YYLAST
- yyn
;
1641 int yyxend
= yychecklim
< YYNTOKENS
? yychecklim
: YYNTOKENS
;
1644 yyprefix
= ", expecting ";
1645 for (yyx
= yyxbegin
; yyx
< yyxend
; ++yyx
)
1646 if (yycheck
[yyx
+ yyn
] == yyx
&& yyx
!= YYTERROR
)
1648 yysize
+= strlen (yyprefix
) + strlen (yytokenName (yyx
));
1657 yysize
+= (sizeof ("syntax error, unexpected ")
1658 + strlen (yytokenName (*yytokenp
)));
1659 yymsg
= (char*) YYMALLOC (yysize
);
1663 sprintf (yyp
, "syntax error%s%s",
1664 (*yytokenp
== YYEMPTY
? "" : ", unexpected "),
1665 yytokenName (*yytokenp
));
1666 yyp
+= strlen (yyp
);
1669 yyprefix
= ", expecting ";
1670 for (yyx
= yyxbegin
; yyx
< yyxend
; ++yyx
)
1671 if (yycheck
[yyx
+ yyn
] == yyx
&& yyx
!= YYTERROR
)
1673 sprintf (yyp
, "%s%s", yyprefix
, yytokenName (yyx
));
1674 yyp
+= strlen (yyp
);
1678 yyerror (]b4_lyyerror_args
[yymsg
);
1682 yyerror (]b4_lyyerror_args
["syntax error; also virtual memory exhausted");
1685 #endif /* YYERROR_VERBOSE */
1686 yyerror (]b4_lyyerror_args
["syntax error");
1691 /* Recover from a syntax error on YYSTACK, assuming that YYTOKENP,
1692 YYLVALP, and YYLLOCP point to the syntactic category, semantic
1693 value, and location of the look-ahead. */
1695 yyrecoverSyntaxError (yyGLRStack
* yystack
,
1696 YYSTYPE
* yylvalp
, YYLTYPE
* yyllocp
]b4_user_formals
[)
1698 yySymbol
* const yytokenp
= yystack
->yytokenp
;
1702 if (yystack
->yyerrState
== 3)
1703 /* We just shifted the error token and (perhaps) took some
1704 reductions. Skip tokens until we can proceed. */
1707 if (*yytokenp
== YYEOF
)
1709 /* Now pop stack until empty and fail. */
1710 while (yystack
->yytops
.yystates
[0] != NULL
)
1712 yyGLRState
*yys
= yystack
->yytops
.yystates
[0];
1713 yydestruct ("Error: popping",
1714 yystos
[yys
->yylrState
],
1715 &yys
->yysemantics
.yysval
]b4_location_if([, &yys
->yyloc
])[);
1716 yystack
->yytops
.yystates
[0] = yys
->yypred
;
1717 yystack
->yynextFree
-= 1;
1718 yystack
->yyspaceLeft
+= 1;
1720 yyFail (yystack
][]b4_lpure_args
[, NULL
);
1722 if (*yytokenp
!= YYEMPTY
)
1723 yydestruct ("Error: discarding",
1724 *yytokenp
, yylvalp
]b4_location_if([, yyllocp
])[);
1725 YYDPRINTF ((stderr
, "Reading a token: "));
1727 *yytokenp
= YYTRANSLATE (yychar
);
1728 YY_SYMBOL_PRINT ("Next token is", *yytokenp
, yylvalp
, yyllocp
);
1729 yyj
= yypact
[yystack
->yytops
.yystates
[0]->yylrState
];
1730 if (yyis_pact_ninf (yyj
))
1733 if (yyj
< 0 || YYLAST
< yyj
|| yycheck
[yyj
] != *yytokenp
)
1735 if (yydefact
[yystack
->yytops
.yystates
[0]->yylrState
] != 0)
1738 else if (yytable
[yyj
] != 0 && ! yyis_table_ninf (yytable
[yyj
]))
1742 /* Reduce to one stack. */
1743 for (yyk
= 0; yyk
< yystack
->yytops
.yysize
; yyk
+= 1)
1744 if (yystack
->yytops
.yystates
[yyk
] != NULL
)
1746 if (yyk
>= yystack
->yytops
.yysize
)
1747 yyFail (yystack
][]b4_lpure_args
[, NULL
);
1748 for (yyk
+= 1; yyk
< yystack
->yytops
.yysize
; yyk
+= 1)
1749 yymarkStackDeleted (yystack
, yyk
);
1750 yyremoveDeletes (yystack
);
1751 yycompressStack (yystack
);
1753 /* Now pop stack until we find a state that shifts the error token. */
1754 yystack
->yyerrState
= 3;
1755 while (yystack
->yytops
.yystates
[0] != NULL
)
1757 yyGLRState
*yys
= yystack
->yytops
.yystates
[0];
1758 yyj
= yypact
[yys
->yylrState
];
1759 if (! yyis_pact_ninf (yyj
))
1762 if (0 <= yyj
&& yyj
<= YYLAST
&& yycheck
[yyj
] == YYTERROR
1763 && yyisShiftAction (yytable
[yyj
]))
1765 YY_SYMBOL_PRINT ("Shifting", yystos
[yytable
[yyj
]],
1767 yyglrShift (yystack
, 0, yytable
[yyj
],
1768 yys
->yyposn
, *yylvalp
, yyllocp
]b4_user_args
[);
1772 yydestruct ("Error: popping",
1773 yystos
[yys
->yylrState
],
1774 &yys
->yysemantics
.yysval
]b4_location_if([, &yys
->yyloc
])[);
1775 yystack
->yytops
.yystates
[0] = yys
->yypred
;
1776 yystack
->yynextFree
-= 1;
1777 yystack
->yyspaceLeft
+= 1;
1779 if (yystack
->yytops
.yystates
[0] == NULL
)
1780 yyFail (yystack
][]b4_lpure_args
[, NULL
);
1783 #define YYCHK1(YYE) \
1789 yystack.yyerrflag = 1; \
1792 yystack.yyerrflag = 0; \
1795 goto yyuser_error; \
1804 ]b4_c_ansi_function_def([yyparse
], [int], b4_parse_param
)[
1814 #define yychar (yystack.yyrawchar)
1817 YYSTYPE
* const yylvalp
= &yylval
;
1818 YYLTYPE
* const yyllocp
= &yylloc
;
1820 yyinitGLRStack (&yystack
, YYINITDEPTH
);
1821 yystack
.yytokenp
= &yytoken
;
1823 YYDPRINTF ((stderr
, "Starting parse\n"));
1825 if (setjmp (yystack
.yyexception_buffer
) != 0)
1828 yylval
= yyval_default
;
1830 #if YYLTYPE_IS_TRIVIAL
1831 yylloc
.first_line
= yylloc
.last_line
= 1;
1832 yylloc
.first_column
= yylloc
.last_column
= 0;
1835 m4_ifdef([b4_initial_action
], [
1836 m4_pushdef([b4_at_dollar
], [yylval
])dnl
1837 m4_pushdef([b4_dollar_dollar
], [yylloc
])dnl
1838 /* User initialization code. */
1840 m4_popdef([b4_dollar_dollar
])dnl
1841 m4_popdef([b4_at_dollar
])dnl
1842 /* Line __line__ of glr.c. */
1843 b4_syncline([@oline@
], [@ofile@
])])dnl
1845 yyglrShift (&yystack
, 0, 0, 0, yylval
, &yylloc
]b4_user_args
[);
1851 /* For efficiency, we have two loops, the first of which is
1852 specialized to deterministic operation (single stack, no
1853 potential ambiguity). */
1859 const short int* yyconflicts
;
1861 yyStateNum yystate
= yystack
.yytops
.yystates
[0]->yylrState
;
1862 YYDPRINTF ((stderr
, "Entering state %d\n", yystate
));
1863 if (yystate
== YYFINAL
)
1865 if (yyisDefaultedState (yystate
))
1867 yyrule
= yydefaultAction (yystate
);
1870 yyreportSyntaxError (&yystack
, yylvalp
, yyllocp
]b4_user_args
[);
1873 YYCHK1 (yyglrReduce (&yystack
, 0, yyrule
, yytrue
]b4_lpure_args
[));
1877 if (yytoken
== YYEMPTY
)
1879 YYDPRINTF ((stderr
, "Reading a token: "));
1881 yytoken
= YYTRANSLATE (yychar
);
1882 YY_SYMBOL_PRINT ("Next token is", yytoken
, yylvalp
, yyllocp
);
1884 yygetLRActions (yystate
, yytoken
, &yyaction
, &yyconflicts
);
1885 if (*yyconflicts
!= 0)
1887 if (yyisShiftAction (yyaction
))
1889 YY_SYMBOL_PRINT ("Shifting", yytoken
, yylvalp
, yyllocp
);
1890 if (yytoken
!= YYEOF
)
1893 yyglrShift (&yystack
, 0, yyaction
, yyposn
,
1894 yylval
, yyllocp
]b4_user_args
[);
1895 if (0 < yystack
.yyerrState
)
1896 yystack
.yyerrState
-= 1;
1898 else if (yyisErrorAction (yyaction
))
1900 yyreportSyntaxError (&yystack
, yylvalp
, yyllocp
]b4_user_args
[);
1904 YYCHK1 (yyglrReduce (&yystack
, 0, -yyaction
, yytrue
]b4_lpure_args
[));
1911 int yyn
= yystack
.yytops
.yysize
;
1912 for (yys
= 0; yys
< yyn
; yys
+= 1)
1913 YYCHK1 (yyprocessOneStack (&yystack
, yys
, yyposn
,
1914 yylvalp
, yyllocp
]b4_user_args
[));
1917 yyremoveDeletes (&yystack
);
1918 if (yystack
.yytops
.yysize
== 0)
1920 yyundeleteLastStack (&yystack
);
1921 if (yystack
.yytops
.yysize
== 0)
1922 yyFail (&yystack
][]b4_lpure_args
[, "syntax error");
1923 YYCHK1 (yyresolveStack (&yystack
]b4_user_args
[));
1924 YYDPRINTF ((stderr
, "Returning to deterministic operation.\n"));
1925 yyreportSyntaxError (&yystack
, yylvalp
, yyllocp
]b4_user_args
[);
1928 else if (yystack
.yytops
.yysize
== 1)
1930 YYCHK1 (yyresolveStack (&yystack
]b4_user_args
[));
1931 YYDPRINTF ((stderr
, "Returning to deterministic operation.\n"));
1932 yycompressStack (&yystack
);
1938 yyrecoverSyntaxError (&yystack
, yylvalp
, yyllocp
]b4_user_args
[);
1939 yyposn
= yystack
.yytops
.yystates
[0]->yyposn
;
1942 /* On YYABORT, free the lookahead. */
1943 if (yystack
.yyerrflag
== 1 && yytoken
!= YYEMPTY
)
1944 yydestruct ("Error: discarding lookahead",
1945 yytoken
, yylvalp
]b4_location_if([, yyllocp
])[);
1947 yyfreeGLRStack (&yystack
);
1948 return yystack
.yyerrflag
;
1951 /* DEBUGGING ONLY */
1953 static void yypstack (yyGLRStack
* yystack
, int yyk
) ATTRIBUTE_UNUSED
;
1954 static void yypdumpstack (yyGLRStack
* yystack
) ATTRIBUTE_UNUSED
;
1957 yy_yypstack (yyGLRState
* yys
)
1961 yy_yypstack (yys
->yypred
);
1962 fprintf (stderr
, " -> ");
1964 fprintf (stderr
, "%d@@%lu", yys
->yylrState
, (unsigned long int) yys
->yyposn
);
1968 yypstates (yyGLRState
* yyst
)
1971 fprintf (stderr
, "<null>");
1974 fprintf (stderr
, "\n");
1978 yypstack (yyGLRStack
* yystack
, int yyk
)
1980 yypstates (yystack
->yytops
.yystates
[yyk
]);
1983 #define YYINDEX(YYX) \
1984 ((YYX) == NULL ? -1 : (yyGLRStackItem*) (YYX) - yystack->yyitems)
1988 yypdumpstack (yyGLRStack
* yystack
)
1990 yyGLRStackItem
* yyp
;
1992 for (yyp
= yystack
->yyitems
; yyp
< yystack
->yynextFree
; yyp
+= 1)
1994 fprintf (stderr
, "%3lu. ", (unsigned long int) (yyp
- yystack
->yyitems
));
1995 if (*(yybool
*) yyp
)
1997 fprintf (stderr
, "Res: %d, LR State: %d, posn: %lu, pred: %ld",
1998 yyp
->yystate
.yyresolved
, yyp
->yystate
.yylrState
,
1999 (unsigned long int) yyp
->yystate
.yyposn
,
2000 (long int) YYINDEX (yyp
->yystate
.yypred
));
2001 if (! yyp
->yystate
.yyresolved
)
2002 fprintf (stderr
, ", firstVal: %ld",
2003 (long int) YYINDEX (yyp
->yystate
.yysemantics
.yyfirstVal
));
2007 fprintf (stderr
, "Option. rule: %d, state: %ld, next: %ld",
2008 yyp
->yyoption
.yyrule
,
2009 (long int) YYINDEX (yyp
->yyoption
.yystate
),
2010 (long int) YYINDEX (yyp
->yyoption
.yynext
));
2012 fprintf (stderr
, "\n");
2014 fprintf (stderr
, "Tops:");
2015 for (yyi
= 0; yyi
< yystack
->yytops
.yysize
; yyi
+= 1)
2016 fprintf (stderr
, "%lu: %ld; ", (unsigned long int) yyi
,
2017 (long int) YYINDEX (yystack
->yytops
.yystates
[yyi
]));
2018 fprintf (stderr
, "\n");
2024 m4_if(b4_defines_flag
, 0, [],
2025 [@output @output_header_name@
2026 b4_copyright([Skeleton parser
for GLR parsing with Bison
], [2002, 2003, 2004])
2028 b4_token_defines(b4_tokens
)
2030 #if ! defined (YYSTYPE) && ! defined (YYSTYPE_IS_DECLARED)
2031 m4_ifdef([b4_stype
],
2032 [b4_syncline([b4_stype_line
], [b4_filename
])
2033 typedef union m4_bregexp(b4_stype
, [^{], [YYSTYPE
])b4_stype YYSTYPE
;
2034 /* Line __line__ of glr.c. */
2035 b4_syncline([@oline@
], [@ofile@
])],
2036 [typedef int YYSTYPE
;])
2037 # define YYSTYPE_IS_DECLARED 1
2038 # define YYSTYPE_IS_TRIVIAL 1
2042 [extern YYSTYPE b4_prefix
[]lval
;])
2044 #if ! defined (YYLTYPE) && ! defined (YYLTYPE_IS_DECLARED)
2045 typedef struct YYLTYPE
2056 # define YYLTYPE_IS_DECLARED 1
2057 # define YYLTYPE_IS_TRIVIAL 1
2060 b4_location_if([m4_if(b4_pure
, [0],
2061 [extern YYLTYPE b4_prefix
[]lloc
;])