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 lookahead, hence yyllocp instead of yylocp.
64 m4_define([b4_lyyerror_args
],
65 [b4_pure_if([b4_location_if([yyllocp
, ])])dnl
66 m4_ifset([b4_parse_param
], [b4_c_args(b4_parse_param
), ])])
71 # Arguments needed by yyerror: user args plus yylloc.
72 m4_define([b4_pure_args
],
73 [b4_pure_if([b4_location_if([, yylocp
])])[]b4_user_args
])
78 # Arguments passed to yyerror: user formals plus yyllocp.
79 m4_define([b4_pure_formals
],
80 [b4_pure_if([b4_location_if([, YYLTYPE
*yylocp
])])[]b4_user_formals
])
85 # Same as above, but on the lookahead, hence yyllocp instead of yylocp.
86 m4_define([b4_lpure_args
],
87 [b4_pure_if([b4_location_if([, yyllocp
])])[]b4_user_args
])
92 # Same as above, but on the lookahead, hence yyllocp instead of yylocp.
93 m4_define([b4_lpure_formals
],
94 [b4_pure_if([b4_location_if([YYLTYPE
*yyllocp
])])[]b4_user_formals
])
97 ## ----------------- ##
98 ## Semantic Values. ##
99 ## ----------------- ##
102 # b4_lhs_value([TYPE])
103 # --------------------
104 # Expansion of $<TYPE>$.
105 m4_define([b4_lhs_value
],
106 [(*yyvalp
)[]m4_ifval([$
1], [.$
1])])
109 # b4_rhs_value(RULE-LENGTH, NUM, [TYPE])
110 # --------------------------------------
111 # Expansion of $<TYPE>NUM, where the current rule has RULE-LENGTH
113 m4_define([b4_rhs_value
],
114 [((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])
142 /* This is the parser code for GLR (Generalized LR) parser. */
151 m4_if(b4_prefix
[], [yy
], [],
152 [/* If NAME_PREFIX is specified substitute the variables and functions
154 #define yyparse b4_prefix[]parse
155 #define yylex b4_prefix[]lex
156 #define yyerror b4_prefix[]error
157 #define yylval b4_prefix[]lval
158 #define yychar b4_prefix[]char
159 #define yydebug b4_prefix[]debug
160 #define yynerrs b4_prefix[]nerrs
161 b4_location_if([#define yylloc b4_prefix[]lloc])])
163 b4_token_defines(b4_tokens
)
165 /* Copy the first part of user declarations. */
168 /* Enabling traces. */
170 # define YYDEBUG ]b4_debug[
173 /* Enabling verbose error messages. */
174 #ifdef YYERROR_VERBOSE
175 # undef YYERROR_VERBOSE
176 # define YYERROR_VERBOSE 1
178 # define YYERROR_VERBOSE ]b4_error_verbose[
181 #if ! defined (YYSTYPE) && ! defined (YYSTYPE_IS_DECLARED)
182 ]m4_ifdef([b4_stype
],
183 [b4_syncline([b4_stype_line
], [b4_filename
])
184 typedef union m4_bregexp(b4_stype
, [^{], [YYSTYPE
])b4_stype YYSTYPE
;
185 /* Line __line__ of glr.c. */
186 b4_syncline([@oline@
], [@ofile@
])],
187 [typedef int YYSTYPE
;])[
188 # define YYSTYPE_IS_DECLARED 1
189 # define YYSTYPE_IS_TRIVIAL 1
192 #if ! defined (YYLTYPE) && ! defined (YYLTYPE_IS_DECLARED)
193 typedef struct YYLTYPE
204 # define YYLTYPE_IS_DECLARED 1
205 # define YYLTYPE_IS_TRIVIAL 1
208 /* Default (constant) values used for initialization for null
209 right-hand sides. Unlike the standard yacc.c template,
210 here we set the default values of $$ and $@@ to zeroed-out
211 values. Since the default value of these quantities is undefined,
212 this behavior is technically correct. */
213 static YYSTYPE yyval_default
;
214 static YYLTYPE yyloc_default
;
216 /* Copy the second part of user declarations. */
219 ]/* Line __line__ of glr.c. */
220 b4_syncline([@oline@
], [@ofile@
])
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)(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 *".
398 dnl We probably ought to introduce a type
for confl
.
399 [static const short 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 -- Compute the default location (before the actions
427 #define YYRHSLOC(yyRhs,YYK) ((yyRhs)[YYK].yystate.yyloc)
429 #ifndef YYLLOC_DEFAULT
430 # define YYLLOC_DEFAULT(yyCurrent, yyRhs, YYN) \
431 ((yyCurrent).first_line = YYRHSLOC(yyRhs, 1).first_line, \
432 (yyCurrent).first_column = YYRHSLOC(yyRhs, 1).first_column, \
433 (yyCurrent).last_line = YYRHSLOC(yyRhs, YYN).last_line, \
434 (yyCurrent).last_column = YYRHSLOC(yyRhs, YYN).last_column)
437 #ifndef YYLLOC_DEFAULT
438 # define YYLLOC_DEFAULT(yyCurrent, yyRhs, YYN) ((void) 0)
443 /* YYLEX -- calling `yylex' with the right arguments. */
444 #define YYLEX ]b4_c_function_call([yylex], [int], b4_lex_param)[
449 #define yynerrs (yystack->yyerrcnt)
451 #define yychar (yystack->yyrawchar)],
459 static const int YYEOF
= 0;
460 static const int YYEMPTY
= -2;
462 typedef enum { yyok
, yyaccept
, yyabort
, yyerr
} YYRESULTTAG
;
465 do { YYRESULTTAG yyflag = YYE; if (yyflag != yyok) return yyflag; } \
470 #if ! defined (YYFPRINTF)
471 # define YYFPRINTF fprintf
474 # define YYDPRINTF(Args) \
480 ]b4_yysymprint_generate([b4_c_ansi_function_def
])[
482 # define YYDSYMPRINT(Args) \
488 # define YYDSYMPRINTF(Title, Token, Value, Location) \
492 YYFPRINTF (stderr, "%s ", Title); \
493 yysymprint (stderr, \
494 Token, Value]b4_location_if([, Location])[); \
495 YYFPRINTF (stderr, "\n"); \
499 /* Nonzero means print parse trace. It is left uninitialized so that
500 multiple parsers can coexist. */
505 /* Avoid empty `if' bodies. */
506 # define YYDPRINTF(Args)
507 # define YYDSYMPRINT(Args)
508 # define YYDSYMPRINTF(Title, Token, Value, Location)
510 #endif /* !YYDEBUG */
512 /* YYINITDEPTH -- initial size of the parser's stacks. */
514 # define YYINITDEPTH ]b4_stack_depth_init[
517 /* YYMAXDEPTH -- maximum size the stacks can grow to (effective only
518 if the built-in stack extension method is used).
520 Do not make this value too large; the results are undefined if
521 SIZE_MAX < YYMAXDEPTH * sizeof (GLRStackItem)
522 evaluated with infinite-precision integer arithmetic. */
529 # define YYMAXDEPTH ]b4_stack_depth_max[
532 /* Minimum number of free items on the stack allowed after an
533 allocation. This is to allow allocation and initialization
534 to be completed by functions that call expandGLRStack before the
535 stack is expanded, thus insuring that all necessary pointers get
536 properly redirected to new data. */
539 #if (! defined (YYSTACKEXPANDABLE) \
540 && (! defined (__cplusplus) \
541 || (]b4_location_if([[defined (YYLTYPE_IS_TRIVIAL) && YYLTYPE_IS_TRIVIAL \
542 && ]])[defined (YYSTYPE_IS_TRIVIAL) && YYSTYPE_IS_TRIVIAL)))
543 #define YYSTACKEXPANDABLE 1
545 #define YYSTACKEXPANDABLE 0
548 /** State numbers, as in LALR(1) machine */
549 typedef int yyStateNum
;
551 /** Rule numbers, as in LALR(1) machine */
552 typedef int yyRuleNum
;
554 /** Grammar symbol */
555 typedef short yySymbol
;
557 /** Item references, as in LALR(1) machine */
558 typedef short yyItemNum
;
560 typedef struct yyGLRState yyGLRState
;
561 typedef struct yySemanticOption yySemanticOption
;
562 typedef union yyGLRStackItem yyGLRStackItem
;
563 typedef struct yyGLRStack yyGLRStack
;
564 typedef struct yyGLRStateSet yyGLRStateSet
;
569 yyStateNum yylrState
;
573 yySemanticOption
* yyfirstVal
;
579 struct yyGLRStateSet
{
580 yyGLRState
** yystates
;
581 size_t yysize
, yycapacity
;
584 struct yySemanticOption
{
588 yySemanticOption
* yynext
;
591 union yyGLRStackItem
{
593 yySemanticOption yyoption
;
605 jmp_buf yyexception_buffer
;
606 yyGLRStackItem
* yyitems
;
607 yyGLRStackItem
* yynextFree
;
609 yyGLRState
* yysplitPoint
;
610 yyGLRState
* yylastDeleted
;
611 yyGLRStateSet yytops
;
614 static void yyinitGLRStack (yyGLRStack
* yystack
, size_t yysize
);
615 static void yyexpandGLRStack (yyGLRStack
* yystack
]b4_pure_formals
[);
616 static void yyfreeGLRStack (yyGLRStack
* yystack
);
619 yyFail (yyGLRStack
* yystack
]b4_pure_formals
[, const char* yyformat
, ...)
621 yystack
->yyerrflag
= 1;
622 if (yyformat
!= NULL
)
626 va_start (yyap
, yyformat
);
627 vsprintf (yymsg
, yyformat
, yyap
);
628 yyerror (]b4_yyerror_args
[yymsg
);
630 longjmp (yystack
->yyexception_buffer
, 1);
633 #if YYDEBUG || YYERROR_VERBOSE
634 /** A printable representation of TOKEN. Valid until next call to
636 static inline const char*
637 yytokenName (yySymbol yytoken
)
639 if (yytoken
== YYEMPTY
)
642 return yytname
[yytoken
];
646 /** Fill in YYVSP[YYLOW1 .. YYLOW0-1] from the chain of states starting
647 * at YYVSP[YYLOW0].yystate.yypred. Leaves YYVSP[YYLOW1].yystate.yypred
648 * containing the pointer to the next state in the chain. Assumes
649 * YYLOW1 < YYLOW0. */
650 static void yyfillin (yyGLRStackItem
*, int, int) ATTRIBUTE_UNUSED
;
652 yyfillin (yyGLRStackItem
*yyvsp
, int yylow0
, int yylow1
)
656 s
= yyvsp
[yylow0
].yystate
.yypred
;
657 for (i
= yylow0
-1; i
>= yylow1
; i
-= 1)
659 YYASSERT (s
->yyresolved
);
660 yyvsp
[i
].yystate
.yyresolved
= yytrue
;
661 yyvsp
[i
].yystate
.yysemantics
.yysval
= s
->yysemantics
.yysval
;
662 yyvsp
[i
].yystate
.yyloc
= s
->yyloc
;
663 s
= yyvsp
[i
].yystate
.yypred
= s
->yypred
;
667 /* Do nothing if YYNORMAL or if *YYLOW <= YYLOW1. Otherwise, fill in
668 YYVSP[YYLOW1 .. *YYLOW-1] as in yyfillin and set *YYLOW = YYLOW1.
669 For convenience, always return YYLOW1. */
670 static inline int yyfill (yyGLRStackItem
*, int *, int, yybool
)
673 yyfill (yyGLRStackItem
*yyvsp
, int *yylow
, int yylow1
, yybool yynormal
)
675 if (!yynormal
&& yylow1
< *yylow
)
677 yyfillin (yyvsp
, *yylow
, yylow1
);
683 /** Perform user action for rule number YYN, with RHS length YYRHSLEN,
684 * and top stack item YYVSP. YYLVALP points to place to put semantic
685 * value ($$), and yylocp points to place for location information
686 * (@@$). Returns yyok for normal return, yyaccept for YYACCEPT,
687 * yyerr for YYERROR, yyabort for YYABORT. */
689 yyuserAction (yyRuleNum yyn
, int yyrhslen
, yyGLRStackItem
* yyvsp
,
690 YYSTYPE
* yyvalp
, YYLTYPE
* yylocp
, yyGLRStack
* yystack
693 yybool yynormal ATTRIBUTE_UNUSED
= (yystack
->yysplitPoint
== NULL
);
697 # define yyerrok (yystack->yyerrState = 0)
699 # define YYACCEPT return yyaccept
701 # define YYABORT return yyabort
703 # define YYERROR return yyerrok, yyerr
705 # define YYRECOVERING (yystack->yyerrState != 0)
707 # define yyclearin (yychar = *(yystack->yytokenp) = YYEMPTY)
709 # define YYFILL(N) yyfill (yyvsp, &yylow, N, yynormal)
711 # define YYBACKUP(Token, Value) \
712 return yyerror (]b4_yyerror_args["syntax error: cannot back up"), \
718 *yyvalp
= yyval_default
;
719 *yylocp
= yyloc_default
;
723 *yyvalp
= yyvsp
[YYFILL (1-yyrhslen
)].yystate
.yysemantics
.yysval
;
724 YYLLOC_DEFAULT (*yylocp
, yyvsp
- yyrhslen
, yyrhslen
);
741 /* Line __line__ of glr.c. */
742 b4_syncline([@oline@
], [@ofile@
])
747 yyuserMerge (int yyn
, YYSTYPE
* yy0
, YYSTYPE
* yy1
)
749 /* `Use' the arguments. */
759 /* Bison grammar-table manipulation. */
761 ]b4_yydestruct_generate([b4_c_ansi_function_def
])[
763 /** Number of symbols composing the right hand side of rule #RULE. */
765 yyrhsLength (yyRuleNum yyrule
)
770 /** Left-hand-side symbol for rule #RULE. */
771 static inline yySymbol
772 yylhsNonterm (yyRuleNum yyrule
)
777 #define yyis_pact_ninf(yystate) \
778 ]m4_if(m4_eval(b4_pact_ninf < b4_pact_min), 1,
780 ((yystate
) == YYPACT_NINF
))[
782 /** True iff LR state STATE has only a default reduction (regardless
785 yyisDefaultedState (yyStateNum yystate
)
787 return yyis_pact_ninf (yypact
[yystate
]);
790 /** The default reduction for STATE, assuming it has one. */
791 static inline yyRuleNum
792 yydefaultAction (yyStateNum yystate
)
794 return yydefact
[yystate
];
797 #define yyis_table_ninf(yytable_value) \
798 ]m4_if(m4_eval(b4_table_ninf < b4_table_min), 1,
800 ((yytable_value
) == YYTABLE_NINF
))[
802 /** Set *YYACTION to the action to take in YYSTATE on seeing YYTOKEN.
804 * R < 0: Reduce on rule -R.
806 * R > 0: Shift to state R.
807 * Set *CONFLICTS to a pointer into yyconfl to 0-terminated list of
808 * conflicting reductions.
811 yygetLRActions (yyStateNum yystate
, int yytoken
,
812 int* yyaction
, const short** yyconflicts
)
814 int yyindex
= yypact
[yystate
] + yytoken
;
815 if (yyindex
< 0 || YYLAST
< yyindex
|| yycheck
[yyindex
] != yytoken
)
817 *yyaction
= -yydefact
[yystate
];
818 *yyconflicts
= yyconfl
;
820 else if (! yyis_table_ninf (yytable
[yyindex
]))
822 *yyaction
= yytable
[yyindex
];
823 *yyconflicts
= yyconfl
+ yyconflp
[yyindex
];
828 *yyconflicts
= yyconfl
+ yyconflp
[yyindex
];
832 static inline yyStateNum
833 yyLRgotoState (yyStateNum yystate
, yySymbol yylhs
)
836 yyr
= yypgoto
[yylhs
- YYNTOKENS
] + yystate
;
837 if (0 <= yyr
&& yyr
<= YYLAST
&& yycheck
[yyr
] == yystate
)
840 return yydefgoto
[yylhs
- YYNTOKENS
];
844 yyisShiftAction (int yyaction
)
850 yyisErrorAction (int yyaction
)
852 return yyaction
== 0;
858 yyaddDeferredAction (yyGLRStack
* yystack
, yyGLRState
* yystate
,
859 yyGLRState
* rhs
, yyRuleNum yyrule
]b4_pure_formals
[)
861 yySemanticOption
* yynewItem
;
862 yynewItem
= &yystack
->yynextFree
->yyoption
;
863 yystack
->yyspaceLeft
-= 1;
864 yystack
->yynextFree
+= 1;
865 yynewItem
->yyisState
= yyfalse
;
866 yynewItem
->yystate
= rhs
;
867 yynewItem
->yyrule
= yyrule
;
868 yynewItem
->yynext
= yystate
->yysemantics
.yyfirstVal
;
869 yystate
->yysemantics
.yyfirstVal
= yynewItem
;
870 if (yystack
->yyspaceLeft
< YYHEADROOM
)
871 yyexpandGLRStack (yystack
]b4_pure_args
[);
876 /** Initialize SET to a singleton set containing an empty stack. */
878 yyinitStateSet (yyGLRStateSet
* yyset
)
881 yyset
->yycapacity
= 16;
882 yyset
->yystates
= (yyGLRState
**) YYMALLOC (16 * sizeof yyset
->yystates
[0]);
883 yyset
->yystates
[0] = NULL
;
886 static void yyfreeStateSet (yyGLRStateSet
* yyset
)
888 YYFREE (yyset
->yystates
);
891 /** Initialize STACK to a single empty stack, with total maximum
892 * capacity for all stacks of SIZE. */
894 yyinitGLRStack (yyGLRStack
* yystack
, size_t yysize
)
896 yystack
->yyerrflag
= 0;
897 yystack
->yyerrState
= 0;
899 yystack
->yyspaceLeft
= yysize
;
900 yystack
->yynextFree
= yystack
->yyitems
=
901 (yyGLRStackItem
*) YYMALLOC (yysize
* sizeof yystack
->yynextFree
[0]);
902 yystack
->yysplitPoint
= NULL
;
903 yystack
->yylastDeleted
= NULL
;
904 yyinitStateSet (&yystack
->yytops
);
907 #define YYRELOC(YYFROMITEMS,YYTOITEMS,YYX,YYTYPE) \
908 &((YYTOITEMS) - ((YYFROMITEMS) - (yyGLRStackItem*) (YYX)))->YYTYPE
910 /** If STACK is expandable, extend it. WARNING: Pointers into the
911 stack from outside should be considered invalid after this call.
912 We always expand when there are 1 or fewer items left AFTER an
913 allocation, so that we can avoid having external pointers exist
914 across an allocation. */
916 yyexpandGLRStack (yyGLRStack
* yystack
]b4_pure_formals
[)
918 #if YYSTACKEXPANDABLE
919 yyGLRStack yynewStack
;
920 yyGLRStackItem
* yyp0
, *yyp1
;
921 size_t yysize
, yynewSize
;
923 yysize
= yystack
->yynextFree
- yystack
->yyitems
;
924 if (YYMAXDEPTH
<= yysize
)
925 yyFail (yystack
][]b4_pure_args
[, "parser stack overflow");
926 yynewSize
= 2*yysize
;
927 if (YYMAXDEPTH
< yynewSize
)
928 yynewSize
= YYMAXDEPTH
;
929 yyinitGLRStack (&yynewStack
, yynewSize
);
930 for (yyp0
= yystack
->yyitems
, yyp1
= yynewStack
.yyitems
, yyn
= yysize
;
932 yyn
-= 1, yyp0
+= 1, yyp1
+= 1)
935 if (*(yybool
*) yyp0
)
937 yyGLRState
* yys0
= &yyp0
->yystate
;
938 yyGLRState
* yys1
= &yyp1
->yystate
;
939 if (yys0
->yypred
!= NULL
)
941 YYRELOC (yyp0
, yyp1
, yys0
->yypred
, yystate
);
942 if (! yys0
->yyresolved
&& yys0
->yysemantics
.yyfirstVal
!= NULL
)
943 yys1
->yysemantics
.yyfirstVal
=
944 YYRELOC(yyp0
, yyp1
, yys0
->yysemantics
.yyfirstVal
, yyoption
);
948 yySemanticOption
* yyv0
= &yyp0
->yyoption
;
949 yySemanticOption
* yyv1
= &yyp1
->yyoption
;
950 if (yyv0
->yystate
!= NULL
)
951 yyv1
->yystate
= YYRELOC (yyp0
, yyp1
, yyv0
->yystate
, yystate
);
952 if (yyv0
->yynext
!= NULL
)
953 yyv1
->yynext
= YYRELOC (yyp0
, yyp1
, yyv0
->yynext
, yyoption
);
956 if (yystack
->yysplitPoint
!= NULL
)
957 yystack
->yysplitPoint
= YYRELOC (yystack
->yyitems
, yynewStack
.yyitems
,
958 yystack
->yysplitPoint
, yystate
);
960 for (yyn
= 0; yyn
< yystack
->yytops
.yysize
; yyn
+= 1)
961 if (yystack
->yytops
.yystates
[yyn
] != NULL
)
962 yystack
->yytops
.yystates
[yyn
] =
963 YYRELOC (yystack
->yyitems
, yynewStack
.yyitems
,
964 yystack
->yytops
.yystates
[yyn
], yystate
);
965 YYFREE (yystack
->yyitems
);
966 yystack
->yyitems
= yynewStack
.yyitems
;
967 yystack
->yynextFree
= yynewStack
.yynextFree
+ yysize
;
968 yystack
->yyspaceLeft
= yynewStack
.yyspaceLeft
- yysize
;
972 yyFail (yystack
][]b4_pure_args
[, "parser stack overflow");
977 yyfreeGLRStack (yyGLRStack
* yystack
)
979 YYFREE (yystack
->yyitems
);
980 yyfreeStateSet (&yystack
->yytops
);
983 /** Assuming that S is a GLRState somewhere on STACK, update the
984 * splitpoint of STACK, if needed, so that it is at least as deep as
987 yyupdateSplit (yyGLRStack
* yystack
, yyGLRState
* yys
)
989 if (yystack
->yysplitPoint
!= NULL
&& yystack
->yysplitPoint
> yys
)
990 yystack
->yysplitPoint
= yys
;
993 /** Invalidate stack #K in STACK. */
995 yymarkStackDeleted (yyGLRStack
* yystack
, int yyk
)
997 if (yystack
->yytops
.yystates
[yyk
] != NULL
)
998 yystack
->yylastDeleted
= yystack
->yytops
.yystates
[yyk
];
999 yystack
->yytops
.yystates
[yyk
] = NULL
;
1002 /** Undelete the last stack that was marked as deleted. Can only be
1003 done once after a deletion, and only when all other stacks have
1006 yyundeleteLastStack (yyGLRStack
* yystack
)
1008 if (yystack
->yylastDeleted
== NULL
|| yystack
->yytops
.yysize
!= 0)
1010 yystack
->yytops
.yystates
[0] = yystack
->yylastDeleted
;
1011 yystack
->yytops
.yysize
= 1;
1012 YYDPRINTF ((stderr
, "Restoring last deleted stack as stack #0.\n"));
1013 yystack
->yylastDeleted
= NULL
;
1017 yyremoveDeletes (yyGLRStack
* yystack
)
1021 while (yyj
< yystack
->yytops
.yysize
)
1023 if (yystack
->yytops
.yystates
[yyi
] == NULL
)
1027 YYDPRINTF ((stderr
, "Removing dead stacks.\n"));
1029 yystack
->yytops
.yysize
-= 1;
1033 yystack
->yytops
.yystates
[yyj
] = yystack
->yytops
.yystates
[yyi
];
1036 YYDPRINTF ((stderr
, "Rename stack %lu -> %lu.\n",
1037 (unsigned long int) yyi
, (unsigned long int) yyj
));
1045 /** Shift to a new state on stack #K of STACK, corresponding to LR state
1046 * LRSTATE, at input position POSN, with (resolved) semantic value SVAL. */
1048 yyglrShift (yyGLRStack
* yystack
, int yyk
, yyStateNum yylrState
, size_t yyposn
,
1049 YYSTYPE yysval
, YYLTYPE
* yylocp
]b4_user_formals
[)
1051 yyGLRStackItem
* yynewItem
;
1053 yynewItem
= yystack
->yynextFree
;
1054 yystack
->yynextFree
+= 1;
1055 yystack
->yyspaceLeft
-= 1;
1056 yynewItem
->yystate
.yyisState
= yytrue
;
1057 yynewItem
->yystate
.yylrState
= yylrState
;
1058 yynewItem
->yystate
.yyposn
= yyposn
;
1059 yynewItem
->yystate
.yyresolved
= yytrue
;
1060 yynewItem
->yystate
.yypred
= yystack
->yytops
.yystates
[yyk
];
1061 yystack
->yytops
.yystates
[yyk
] = &yynewItem
->yystate
;
1062 yynewItem
->yystate
.yysemantics
.yysval
= yysval
;
1063 yynewItem
->yystate
.yyloc
= *yylocp
;
1064 if (yystack
->yyspaceLeft
< YYHEADROOM
)
1065 yyexpandGLRStack (yystack
]b4_pure_args
[);
1068 /** Shift stack #K of YYSTACK, to a new state corresponding to LR
1069 * state YYLRSTATE, at input position YYPOSN, with the (unresolved)
1070 * semantic value of YYRHS under the action for YYRULE. */
1072 yyglrShiftDefer (yyGLRStack
* yystack
, int yyk
, yyStateNum yylrState
,
1073 size_t yyposn
, yyGLRState
* rhs
, yyRuleNum yyrule
]b4_pure_formals
[)
1075 yyGLRStackItem
* yynewItem
;
1077 yynewItem
= yystack
->yynextFree
;
1078 yynewItem
->yystate
.yyisState
= yytrue
;
1079 yynewItem
->yystate
.yylrState
= yylrState
;
1080 yynewItem
->yystate
.yyposn
= yyposn
;
1081 yynewItem
->yystate
.yyresolved
= yyfalse
;
1082 yynewItem
->yystate
.yypred
= yystack
->yytops
.yystates
[yyk
];
1083 yynewItem
->yystate
.yysemantics
.yyfirstVal
= NULL
;
1084 yystack
->yytops
.yystates
[yyk
] = &yynewItem
->yystate
;
1085 yystack
->yynextFree
+= 1;
1086 yystack
->yyspaceLeft
-= 1;
1087 yyaddDeferredAction (yystack
, &yynewItem
->yystate
, rhs
, yyrule
]b4_pure_args
[);
1090 /** Pop the symbols consumed by reduction #RULE from the top of stack
1091 * #K of STACK, and perform the appropriate semantic action on their
1092 * semantic values. Assumes that all ambiguities in semantic values
1093 * have been previously resolved. Set *VALP to the resulting value,
1094 * and *LOCP to the computed location (if any). Return value is as
1095 * for userAction. */
1096 static inline YYRESULTTAG
1097 yydoAction (yyGLRStack
* yystack
, int yyk
, yyRuleNum yyrule
,
1098 YYSTYPE
* yyvalp
, YYLTYPE
* yylocp
]b4_user_formals
[)
1100 int yynrhs
= yyrhsLength (yyrule
);
1102 if (yystack
->yysplitPoint
== NULL
)
1104 /* Standard special case: single stack. */
1105 yyGLRStackItem
* rhs
= (yyGLRStackItem
*) yystack
->yytops
.yystates
[yyk
];
1106 YYASSERT (yyk
== 0);
1107 yystack
->yynextFree
-= yynrhs
;
1108 yystack
->yyspaceLeft
+= yynrhs
;
1109 yystack
->yytops
.yystates
[0] = & yystack
->yynextFree
[-1].yystate
;
1110 return yyuserAction (yyrule
, yynrhs
, rhs
,
1111 yyvalp
, yylocp
, yystack
]b4_user_args
[);
1117 yyGLRStackItem yyrhsVals
[YYMAXRHS
+ YYMAXLEFT
+ 1];
1118 yys
= yyrhsVals
[YYMAXRHS
+ YYMAXLEFT
].yystate
.yypred
1119 = yystack
->yytops
.yystates
[yyk
];
1120 for (yyi
= 0; yyi
< yynrhs
; yyi
+= 1)
1125 yyupdateSplit (yystack
, yys
);
1126 yystack
->yytops
.yystates
[yyk
] = yys
;
1127 return yyuserAction (yyrule
, yynrhs
, yyrhsVals
+ YYMAXRHS
+ YYMAXLEFT
- 1,
1128 yyvalp
, yylocp
, yystack
]b4_user_args
[);
1133 # define YY_REDUCE_PRINT(K, Rule)
1135 # define YY_REDUCE_PRINT(K, Rule) \
1138 yy_reduce_print (K, Rule); \
1141 /*----------------------------------------------------------.
1142 | Report that the RULE is going to be reduced on stack #K. |
1143 `----------------------------------------------------------*/
1146 yy_reduce_print (size_t yyk
, yyRuleNum yyrule
)
1149 YYFPRINTF (stderr
, "Reducing stack %lu by rule %d (line %lu), ",
1150 (unsigned long int) yyk
, yyrule
- 1,
1151 (unsigned long int) yyrline
[yyrule
]);
1152 /* Print the symbols being reduced, and their result. */
1153 for (yyi
= yyprhs
[yyrule
]; 0 <= yyrhs
[yyi
]; yyi
++)
1154 YYFPRINTF (stderr
, "%s ", yytokenName (yyrhs
[yyi
]));
1155 YYFPRINTF (stderr
, "-> %s\n", yytokenName (yyr1
[yyrule
]));
1159 /** Pop items off stack #K of STACK according to grammar rule RULE,
1160 * and push back on the resulting nonterminal symbol. Perform the
1161 * semantic action associated with RULE and store its value with the
1162 * newly pushed state, if FORCEEVAL or if STACK is currently
1163 * unambiguous. Otherwise, store the deferred semantic action with
1164 * the new state. If the new state would have an identical input
1165 * position, LR state, and predecessor to an existing state on the stack,
1166 * it is identified with that existing state, eliminating stack #K from
1167 * the STACK. In this case, the (necessarily deferred) semantic value is
1168 * added to the options for the existing state's semantic value.
1170 static inline YYRESULTTAG
1171 yyglrReduce (yyGLRStack
* yystack
, size_t yyk
, yyRuleNum yyrule
,
1172 yybool yyforceEval
]b4_pure_formals
[)
1174 size_t yyposn
= yystack
->yytops
.yystates
[yyk
]->yyposn
;
1176 if (yyforceEval
|| yystack
->yysplitPoint
== NULL
)
1181 YY_REDUCE_PRINT (yyk
, yyrule
);
1182 YYCHK (yydoAction (yystack
, yyk
, yyrule
, &yysval
, &yyloc
]b4_user_args
[));
1183 yyglrShift (yystack
, yyk
,
1184 yyLRgotoState (yystack
->yytops
.yystates
[yyk
]->yylrState
,
1185 yylhsNonterm (yyrule
)),
1186 yyposn
, yysval
, &yyloc
]b4_user_args
[);
1192 yyGLRState
* yys
, *yys0
= yystack
->yytops
.yystates
[yyk
];
1193 yyStateNum yynewLRState
;
1195 for (yys
= yystack
->yytops
.yystates
[yyk
], yyn
= yyrhsLength (yyrule
);
1201 yyupdateSplit (yystack
, yys
);
1202 yynewLRState
= yyLRgotoState (yys
->yylrState
, yylhsNonterm (yyrule
));
1204 "Reduced stack %lu by rule #%d; action deferred. Now in state %d.\n",
1205 (unsigned long int) yyk
, yyrule
- 1, yynewLRState
));
1206 for (yyi
= 0; yyi
< yystack
->yytops
.yysize
; yyi
+= 1)
1207 if (yyi
!= yyk
&& yystack
->yytops
.yystates
[yyi
] != NULL
)
1209 yyGLRState
* yyp
, *yysplit
= yystack
->yysplitPoint
;
1210 yyp
= yystack
->yytops
.yystates
[yyi
];
1211 while (yyp
!= yys
&& yyp
!= yysplit
&& yyp
->yyposn
>= yyposn
)
1213 if (yyp
->yylrState
== yynewLRState
&& yyp
->yypred
== yys
)
1215 yyaddDeferredAction (yystack
, yyp
, yys0
, yyrule
]b4_pure_args
[);
1216 yymarkStackDeleted (yystack
, yyk
);
1217 YYDPRINTF ((stderr
, "Merging stack %lu into stack %lu.\n",
1218 (unsigned long int) yyk
,
1219 (unsigned long int) yyi
));
1225 yystack
->yytops
.yystates
[yyk
] = yys
;
1226 yyglrShiftDefer (yystack
, yyk
, yynewLRState
, yyposn
, yys0
, yyrule
]b4_pure_args
[);
1232 yysplitStack (yyGLRStack
* yystack
, int yyk
)
1234 if (yystack
->yysplitPoint
== NULL
)
1236 YYASSERT (yyk
== 0);
1237 yystack
->yysplitPoint
= yystack
->yytops
.yystates
[yyk
];
1239 if (yystack
->yytops
.yysize
>= yystack
->yytops
.yycapacity
)
1241 yystack
->yytops
.yycapacity
*= 2;
1242 yystack
->yytops
.yystates
=
1243 (yyGLRState
**) YYREALLOC (yystack
->yytops
.yystates
,
1244 (yystack
->yytops
.yycapacity
1245 * sizeof yystack
->yytops
.yystates
[0]));
1247 yystack
->yytops
.yystates
[yystack
->yytops
.yysize
]
1248 = yystack
->yytops
.yystates
[yyk
];
1249 yystack
->yytops
.yysize
+= 1;
1250 return yystack
->yytops
.yysize
-1;
1253 /** True iff Y0 and Y1 represent identical options at the top level.
1254 * That is, they represent the same rule applied to RHS symbols
1255 * that produce the same terminal symbols. */
1257 yyidenticalOptions (yySemanticOption
* yyy0
, yySemanticOption
* yyy1
)
1259 if (yyy0
->yyrule
== yyy1
->yyrule
)
1261 yyGLRState
*yys0
, *yys1
;
1263 for (yys0
= yyy0
->yystate
, yys1
= yyy1
->yystate
,
1264 yyn
= yyrhsLength (yyy0
->yyrule
);
1266 yys0
= yys0
->yypred
, yys1
= yys1
->yypred
, yyn
-= 1)
1267 if (yys0
->yyposn
!= yys1
->yyposn
)
1275 /** Assuming identicalOptions (Y0,Y1), (destructively) merge the
1276 * alternative semantic values for the RHS-symbols of Y1 into the
1277 * corresponding semantic value sets of the symbols of Y0. */
1279 yymergeOptionSets (yySemanticOption
* yyy0
, yySemanticOption
* yyy1
)
1281 yyGLRState
*yys0
, *yys1
;
1283 for (yys0
= yyy0
->yystate
, yys1
= yyy1
->yystate
,
1284 yyn
= yyrhsLength (yyy0
->yyrule
);
1286 yys0
= yys0
->yypred
, yys1
= yys1
->yypred
, yyn
-= 1)
1289 else if (! yys0
->yyresolved
&& ! yys1
->yyresolved
)
1291 yySemanticOption
* yyz
;
1292 for (yyz
= yys0
->yysemantics
.yyfirstVal
; yyz
->yynext
!= NULL
;
1295 yyz
->yynext
= yys1
->yysemantics
.yyfirstVal
;
1299 /** Y0 and Y1 represent two possible actions to take in a given
1300 * parsing state; return 0 if no combination is possible,
1301 * 1 if user-mergeable, 2 if Y0 is preferred, 3 if Y1 is preferred. */
1303 yypreference (yySemanticOption
* y0
, yySemanticOption
* y1
)
1305 yyRuleNum r0
= y0
->yyrule
, r1
= y1
->yyrule
;
1306 int p0
= yydprec
[r0
], p1
= yydprec
[r1
];
1310 if (yymerger
[r0
] == 0 || yymerger
[r0
] != yymerger
[r1
])
1315 if (p0
== 0 || p1
== 0)
1324 static YYRESULTTAG
yyresolveValue (yySemanticOption
* yyoptionList
,
1325 yyGLRStack
* yystack
, YYSTYPE
* yyvalp
,
1326 YYLTYPE
* yylocp
]b4_user_formals
[);
1329 yyresolveStates (yyGLRState
* yys
, int yyn
, yyGLRStack
* yystack
]b4_user_formals
[)
1334 YYASSERT (yys
->yypred
);
1335 yyflag
= yyresolveStates (yys
->yypred
, yyn
-1, yystack
]b4_user_args
[);
1338 if (! yys
->yyresolved
)
1340 yyflag
= yyresolveValue (yys
->yysemantics
.yyfirstVal
, yystack
,
1341 &yys
->yysemantics
.yysval
, &yys
->yyloc
1345 yys
->yyresolved
= yytrue
;
1352 yyresolveAction (yySemanticOption
* yyopt
, yyGLRStack
* yystack
,
1353 YYSTYPE
* yyvalp
, YYLTYPE
* yylocp
]b4_user_formals
[)
1355 yyGLRStackItem yyrhsVals
[YYMAXRHS
+ YYMAXLEFT
+ 1];
1358 yynrhs
= yyrhsLength (yyopt
->yyrule
);
1359 YYCHK (yyresolveStates (yyopt
->yystate
, yynrhs
, yystack
]b4_user_args
[));
1360 yyrhsVals
[YYMAXRHS
+ YYMAXLEFT
].yystate
.yypred
= yyopt
->yystate
;
1361 return yyuserAction (yyopt
->yyrule
, yynrhs
,
1362 yyrhsVals
+ YYMAXRHS
+ YYMAXLEFT
- 1,
1363 yyvalp
, yylocp
, yystack
]b4_user_args
[);
1368 yyreportTree (yySemanticOption
* yyx
, int yyindent
)
1370 int yynrhs
= yyrhsLength (yyx
->yyrule
);
1373 yyGLRState
* yystates
[YYMAXRHS
];
1374 yyGLRState yyleftmost_state
;
1376 for (yyi
= yynrhs
, yys
= yyx
->yystate
; 0 < yyi
; yyi
-= 1, yys
= yys
->yypred
)
1377 yystates
[yyi
] = yys
;
1380 yyleftmost_state
.yyposn
= 0;
1381 yystates
[0] = &yyleftmost_state
;
1386 if (yyx
->yystate
->yyposn
< yys
->yyposn
+ 1)
1387 YYFPRINTF (stderr
, "%*s%s -> <Rule %d, empty>\n",
1388 yyindent
, "", yytokenName (yylhsNonterm (yyx
->yyrule
)),
1391 YYFPRINTF (stderr
, "%*s%s -> <Rule %d, tokens %lu .. %lu>\n",
1392 yyindent
, "", yytokenName (yylhsNonterm (yyx
->yyrule
)),
1393 yyx
->yyrule
, (unsigned long int) (yys
->yyposn
+ 1),
1394 (unsigned long int) yyx
->yystate
->yyposn
);
1395 for (yyi
= 1; yyi
<= yynrhs
; yyi
+= 1)
1397 if (yystates
[yyi
]->yyresolved
)
1399 if (yystates
[yyi
-1]->yyposn
+1 > yystates
[yyi
]->yyposn
)
1400 YYFPRINTF (stderr
, "%*s%s <empty>\n", yyindent
+2, "",
1401 yytokenName (yyrhs
[yyprhs
[yyx
->yyrule
]+yyi
-1]));
1403 YYFPRINTF (stderr
, "%*s%s <tokens %lu .. %lu>\n", yyindent
+2, "",
1404 yytokenName (yyrhs
[yyprhs
[yyx
->yyrule
]+yyi
-1]),
1405 (unsigned long int) (yystates
[yyi
- 1]->yyposn
+ 1),
1406 (unsigned long int) yystates
[yyi
]->yyposn
);
1409 yyreportTree (yystates
[yyi
]->yysemantics
.yyfirstVal
, yyindent
+2);
1415 yyreportAmbiguity (yySemanticOption
* yyx0
, yySemanticOption
* yyx1
,
1416 yyGLRStack
* yystack
]b4_pure_formals
[)
1418 /* `Unused' warnings. */
1423 YYFPRINTF (stderr
, "Ambiguity detected.\n");
1424 YYFPRINTF (stderr
, "Option 1,\n");
1425 yyreportTree (yyx0
, 2);
1426 YYFPRINTF (stderr
, "\nOption 2,\n");
1427 yyreportTree (yyx1
, 2);
1428 YYFPRINTF (stderr
, "\n");
1430 yyFail (yystack
][]b4_pure_args
[, "ambiguity detected");
1434 /** Resolve the ambiguity represented by OPTIONLIST, perform the indicated
1435 * actions, and return the result. */
1437 yyresolveValue (yySemanticOption
* yyoptionList
, yyGLRStack
* yystack
,
1438 YYSTYPE
* yyvalp
, YYLTYPE
* yylocp
]b4_user_formals
[)
1440 yySemanticOption
* yybest
;
1441 yySemanticOption
* yyp
;
1444 yybest
= yyoptionList
;
1446 for (yyp
= yyoptionList
->yynext
; yyp
!= NULL
; yyp
= yyp
->yynext
)
1448 if (yyidenticalOptions (yybest
, yyp
))
1449 yymergeOptionSets (yybest
, yyp
);
1451 switch (yypreference (yybest
, yyp
))
1454 yyreportAmbiguity (yybest
, yyp
, yystack
]b4_pure_args
[);
1470 int yyprec
= yydprec
[yybest
->yyrule
];
1471 YYCHK (yyresolveAction (yybest
, yystack
, yyvalp
, yylocp
]b4_user_args
[));
1472 for (yyp
= yybest
->yynext
; yyp
!= NULL
; yyp
= yyp
->yynext
)
1474 if (yyprec
== yydprec
[yyp
->yyrule
])
1478 YYCHK (yyresolveAction (yyp
, yystack
, &yyval1
, &yydummy
]b4_user_args
[));
1479 yyuserMerge (yymerger
[yyp
->yyrule
], yyvalp
, &yyval1
);
1485 return yyresolveAction (yybest
, yystack
, yyvalp
, yylocp
]b4_user_args
[);
1489 yyresolveStack (yyGLRStack
* yystack
]b4_user_formals
[)
1491 if (yystack
->yysplitPoint
!= NULL
)
1496 for (yyn
= 0, yys
= yystack
->yytops
.yystates
[0];
1497 yys
!= yystack
->yysplitPoint
;
1498 yys
= yys
->yypred
, yyn
+= 1)
1500 YYCHK (yyresolveStates (yystack
->yytops
.yystates
[0], yyn
, yystack
1507 yycompressStack (yyGLRStack
* yystack
)
1509 yyGLRState
* yyp
, *yyq
, *yyr
;
1511 if (yystack
->yytops
.yysize
!= 1 || yystack
->yysplitPoint
== NULL
)
1514 for (yyp
= yystack
->yytops
.yystates
[0], yyq
= yyp
->yypred
, yyr
= NULL
;
1515 yyp
!= yystack
->yysplitPoint
;
1516 yyr
= yyp
, yyp
= yyq
, yyq
= yyp
->yypred
)
1519 yystack
->yyspaceLeft
+= yystack
->yynextFree
- yystack
->yyitems
;
1520 yystack
->yynextFree
= ((yyGLRStackItem
*) yystack
->yysplitPoint
) + 1;
1521 yystack
->yyspaceLeft
-= yystack
->yynextFree
- yystack
->yyitems
;
1522 yystack
->yysplitPoint
= NULL
;
1523 yystack
->yylastDeleted
= NULL
;
1527 yystack
->yynextFree
->yystate
= *yyr
;
1529 yystack
->yynextFree
->yystate
.yypred
= & yystack
->yynextFree
[-1].yystate
;
1530 yystack
->yytops
.yystates
[0] = &yystack
->yynextFree
->yystate
;
1531 yystack
->yynextFree
+= 1;
1532 yystack
->yyspaceLeft
-= 1;
1537 yyprocessOneStack (yyGLRStack
* yystack
, int yyk
,
1538 size_t yyposn
, YYSTYPE
* yylvalp
, YYLTYPE
* yyllocp
1542 const short* yyconflicts
;
1544 yySymbol
* const yytokenp
= yystack
->yytokenp
;
1546 while (yystack
->yytops
.yystates
[yyk
] != NULL
)
1548 yyStateNum yystate
= yystack
->yytops
.yystates
[yyk
]->yylrState
;
1549 YYDPRINTF ((stderr
, "Stack %d Entering state %d\n", yyk
, yystate
));
1551 YYASSERT (yystate
!= YYFINAL
);
1553 if (yyisDefaultedState (yystate
))
1555 yyrule
= yydefaultAction (yystate
);
1558 YYDPRINTF ((stderr
, "Stack %d dies.\n", yyk
));
1559 yymarkStackDeleted (yystack
, yyk
);
1562 YYCHK (yyglrReduce (yystack
, yyk
, yyrule
, yyfalse
]b4_lpure_args
[));
1566 if (*yytokenp
== YYEMPTY
)
1568 YYDPRINTF ((stderr
, "Reading a token: "));
1570 *yytokenp
= YYTRANSLATE (yychar
);
1571 YYDSYMPRINTF ("Next token is", *yytokenp
, yylvalp
, yyllocp
);
1573 yygetLRActions (yystate
, *yytokenp
, &yyaction
, &yyconflicts
);
1575 while (*yyconflicts
!= 0)
1577 int yynewStack
= yysplitStack (yystack
, yyk
);
1578 YYDPRINTF ((stderr
, "Splitting off stack %d from %d.\n",
1580 YYCHK (yyglrReduce (yystack
, yynewStack
,
1581 *yyconflicts
, yyfalse
]b4_lpure_args
[));
1582 YYCHK (yyprocessOneStack (yystack
, yynewStack
, yyposn
,
1583 yylvalp
, yyllocp
]b4_user_args
[));
1587 if (yyisShiftAction (yyaction
))
1589 YYDPRINTF ((stderr
, "Shifting token %s on stack %d, ",
1590 yytokenName (*yytokenp
), yyk
));
1591 yyglrShift (yystack
, yyk
, yyaction
, yyposn
+1,
1592 *yylvalp
, yyllocp
]b4_user_args
[);
1593 YYDPRINTF ((stderr
, "which is now in state #%d\n",
1594 yystack
->yytops
.yystates
[yyk
]->yylrState
));
1597 else if (yyisErrorAction (yyaction
))
1599 YYDPRINTF ((stderr
, "Stack %d dies.\n", yyk
));
1600 yymarkStackDeleted (yystack
, yyk
);
1604 YYCHK (yyglrReduce (yystack
, yyk
, -yyaction
, yyfalse
]b4_lpure_args
[));
1611 yyreportSyntaxError (yyGLRStack
* yystack
,
1612 YYSTYPE
* yylvalp
, YYLTYPE
* yyllocp
]b4_user_formals
[)
1614 /* `Unused' warnings. */
1618 if (yystack
->yyerrState
== 0)
1621 yySymbol
* const yytokenp
= yystack
->yytokenp
;
1623 yyn
= yypact
[yystack
->yytops
.yystates
[0]->yylrState
];
1624 if (YYPACT_NINF
< yyn
&& yyn
< YYLAST
)
1627 const char* yyprefix
;
1631 /* Start YYX at -YYN if negative to avoid negative indexes in
1633 int yyxbegin
= yyn
< 0 ? -yyn
: 0;
1635 /* Stay within bounds of both yycheck and yytname. */
1636 int yychecklim
= YYLAST
- yyn
;
1637 int yyxend
= yychecklim
< YYNTOKENS
? yychecklim
: YYNTOKENS
;
1640 yyprefix
= ", expecting ";
1641 for (yyx
= yyxbegin
; yyx
< yyxend
; ++yyx
)
1642 if (yycheck
[yyx
+ yyn
] == yyx
&& yyx
!= YYTERROR
)
1644 yysize
+= strlen (yyprefix
) + strlen (yytokenName (yyx
));
1653 yysize
+= (sizeof ("syntax error, unexpected ")
1654 + strlen (yytokenName (*yytokenp
)));
1655 yymsg
= (char*) YYMALLOC (yysize
);
1659 sprintf (yyp
, "syntax error%s%s",
1660 (*yytokenp
== YYEMPTY
? "" : ", unexpected "),
1661 yytokenName (*yytokenp
));
1662 yyp
+= strlen (yyp
);
1665 yyprefix
= ", expecting ";
1666 for (yyx
= yyxbegin
; yyx
< yyxend
; ++yyx
)
1667 if (yycheck
[yyx
+ yyn
] == yyx
&& yyx
!= YYTERROR
)
1669 sprintf (yyp
, "%s%s", yyprefix
, yytokenName (yyx
));
1670 yyp
+= strlen (yyp
);
1674 yyerror (]b4_lyyerror_args
[yymsg
);
1678 yyerror (]b4_lyyerror_args
["syntax error; also virtual memory exhausted");
1681 #endif /* YYERROR_VERBOSE */
1682 yyerror (]b4_lyyerror_args
["syntax error");
1687 /* Recover from a syntax error on YYSTACK, assuming that YYTOKENP,
1688 YYLVALP, and YYLLOCP point to the syntactic category, semantic
1689 value, and location of the lookahead. */
1691 yyrecoverSyntaxError (yyGLRStack
* yystack
,
1692 YYSTYPE
* yylvalp
, YYLTYPE
* yyllocp
]b4_user_formals
[)
1694 yySymbol
* const yytokenp
= yystack
->yytokenp
;
1698 if (yystack
->yyerrState
== 3)
1699 /* We just shifted the error token and (perhaps) took some
1700 reductions. Skip tokens until we can proceed. */
1703 if (*yytokenp
== YYEOF
)
1705 /* Now pop stack until empty and fail. */
1706 while (yystack
->yytops
.yystates
[0] != NULL
)
1708 yyGLRState
*yys
= yystack
->yytops
.yystates
[0];
1709 YYDSYMPRINTF ("Error: popping",
1710 yystos
[yys
->yylrState
],
1711 &yys
->yysemantics
.yysval
, &yys
->yyloc
);
1712 yydestruct (yystos
[yys
->yylrState
],
1713 &yys
->yysemantics
.yysval
]b4_location_if([, &yys
->yyloc
])[);
1714 yystack
->yytops
.yystates
[0] = yys
->yypred
;
1715 yystack
->yynextFree
-= 1;
1716 yystack
->yyspaceLeft
+= 1;
1718 yyFail (yystack
][]b4_lpure_args
[, NULL
);
1720 if (*yytokenp
!= YYEMPTY
)
1722 YYDSYMPRINTF ("Error: discarding", *yytokenp
, yylvalp
, yyllocp
);
1723 yydestruct (*yytokenp
, yylvalp
]b4_location_if([, yyllocp
])[);
1725 YYDPRINTF ((stderr
, "Reading a token: "));
1727 *yytokenp
= YYTRANSLATE (yychar
);
1728 YYDSYMPRINTF ("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 YYDPRINTF ((stderr
, "Shifting error token, "));
1766 yyglrShift (yystack
, 0, yytable
[yyj
],
1767 yys
->yyposn
, *yylvalp
, yyllocp
]b4_user_args
[);
1771 YYDSYMPRINTF ("Error: popping",
1772 yystos
[yys
->yylrState
],
1773 &yys
->yysemantics
.yysval
, &yys
->yyloc
);
1774 yydestruct (yystos
[yys
->yylrState
],
1775 &yys
->yysemantics
.yysval
]b4_location_if([, &yys
->yyloc
])[);
1776 yystack
->yytops
.yystates
[0] = yys
->yypred
;
1777 yystack
->yynextFree
-= 1;
1778 yystack
->yyspaceLeft
+= 1;
1780 if (yystack
->yytops
.yystates
[0] == NULL
)
1781 yyFail (yystack
][]b4_lpure_args
[, NULL
);
1784 #define YYCHK1(YYE) \
1790 yystack.yyerrflag = 1; \
1793 yystack.yyerrflag = 0; \
1796 goto yyuser_error; \
1805 ]b4_c_ansi_function_def([yyparse
], [int], b4_parse_param
)[
1815 #define yychar (yystack.yyrawchar)
1818 YYSTYPE
* const yylvalp
= &yylval
;
1819 YYLTYPE
* const yyllocp
= &yylloc
;
1821 yyinitGLRStack (&yystack
, YYINITDEPTH
);
1822 yystack
.yytokenp
= &yytoken
;
1824 YYDPRINTF ((stderr
, "Starting parse\n"));
1826 if (setjmp (yystack
.yyexception_buffer
) != 0)
1829 yyglrShift (&yystack
, 0, 0, 0, yyval_default
, &yyloc_default
]b4_user_args
[);
1835 /* For efficiency, we have two loops, the first of which is
1836 specialized to deterministic operation (single stack, no
1837 potential ambiguity). */
1843 const short* yyconflicts
;
1845 yyStateNum yystate
= yystack
.yytops
.yystates
[0]->yylrState
;
1846 YYDPRINTF ((stderr
, "Entering state %d\n", yystate
));
1847 if (yystate
== YYFINAL
)
1849 if (yyisDefaultedState (yystate
))
1851 yyrule
= yydefaultAction (yystate
);
1854 yyreportSyntaxError (&yystack
, yylvalp
, yyllocp
]b4_user_args
[);
1857 YYCHK1 (yyglrReduce (&yystack
, 0, yyrule
, yytrue
]b4_lpure_args
[));
1861 if (yytoken
== YYEMPTY
)
1863 YYDPRINTF ((stderr
, "Reading a token: "));
1865 yytoken
= YYTRANSLATE (yychar
);
1866 YYDSYMPRINTF ("Next token is", yytoken
, yylvalp
, yyllocp
);
1868 yygetLRActions (yystate
, yytoken
, &yyaction
, &yyconflicts
);
1869 if (*yyconflicts
!= 0)
1871 if (yyisShiftAction (yyaction
))
1873 YYDPRINTF ((stderr
, "Shifting token %s, ",
1874 yytokenName (yytoken
)));
1875 if (yytoken
!= YYEOF
)
1878 yyglrShift (&yystack
, 0, yyaction
, yyposn
,
1879 yylval
, yyllocp
]b4_user_args
[);
1880 if (0 < yystack
.yyerrState
)
1881 yystack
.yyerrState
-= 1;
1883 else if (yyisErrorAction (yyaction
))
1885 yyreportSyntaxError (&yystack
, yylvalp
, yyllocp
]b4_user_args
[);
1889 YYCHK1 (yyglrReduce (&yystack
, 0, -yyaction
, yytrue
]b4_lpure_args
[));
1896 int yyn
= yystack
.yytops
.yysize
;
1897 for (yys
= 0; yys
< yyn
; yys
+= 1)
1898 YYCHK1 (yyprocessOneStack (&yystack
, yys
, yyposn
,
1899 yylvalp
, yyllocp
]b4_user_args
[));
1902 yyremoveDeletes (&yystack
);
1903 if (yystack
.yytops
.yysize
== 0)
1905 yyundeleteLastStack (&yystack
);
1906 if (yystack
.yytops
.yysize
== 0)
1907 yyFail (&yystack
][]b4_lpure_args
[, "syntax error");
1908 YYCHK1 (yyresolveStack (&yystack
]b4_user_args
[));
1909 YYDPRINTF ((stderr
, "Returning to deterministic operation.\n"));
1910 yyreportSyntaxError (&yystack
, yylvalp
, yyllocp
]b4_user_args
[);
1913 else if (yystack
.yytops
.yysize
== 1)
1915 YYCHK1 (yyresolveStack (&yystack
]b4_user_args
[));
1916 YYDPRINTF ((stderr
, "Returning to deterministic operation.\n"));
1917 yycompressStack (&yystack
);
1923 yyrecoverSyntaxError (&yystack
, yylvalp
, yyllocp
]b4_user_args
[);
1924 yyposn
= yystack
.yytops
.yystates
[0]->yyposn
;
1929 yyfreeGLRStack (&yystack
);
1930 return yystack
.yyerrflag
;
1933 /* DEBUGGING ONLY */
1934 static void yypstack (yyGLRStack
* yystack
, int yyk
) ATTRIBUTE_UNUSED
;
1935 static void yypdumpstack (yyGLRStack
* yystack
) ATTRIBUTE_UNUSED
;
1938 yy_yypstack (yyGLRState
* yys
)
1942 yy_yypstack (yys
->yypred
);
1943 fprintf (stderr
, " -> ");
1945 fprintf (stderr
, "%d@@%lu", yys
->yylrState
, (unsigned long) yys
->yyposn
);
1949 yypstates (yyGLRState
* yyst
)
1952 fprintf (stderr
, "<null>");
1955 fprintf (stderr
, "\n");
1959 yypstack (yyGLRStack
* yystack
, int yyk
)
1961 yypstates (yystack
->yytops
.yystates
[yyk
]);
1964 #define YYINDEX(YYX) \
1965 ((YYX) == NULL ? -1 : (yyGLRStackItem*) (YYX) - yystack->yyitems)
1969 yypdumpstack (yyGLRStack
* yystack
)
1971 yyGLRStackItem
* yyp
;
1973 for (yyp
= yystack
->yyitems
; yyp
< yystack
->yynextFree
; yyp
+= 1)
1975 fprintf (stderr
, "%3lu. ", (unsigned long) (yyp
- yystack
->yyitems
));
1976 if (*(yybool
*) yyp
)
1978 fprintf (stderr
, "Res: %d, LR State: %d, posn: %lu, pred: %ld",
1979 yyp
->yystate
.yyresolved
, yyp
->yystate
.yylrState
,
1980 (unsigned long) yyp
->yystate
.yyposn
,
1981 (long) YYINDEX (yyp
->yystate
.yypred
));
1982 if (! yyp
->yystate
.yyresolved
)
1983 fprintf (stderr
, ", firstVal: %ld",
1984 (long) YYINDEX (yyp
->yystate
.yysemantics
.yyfirstVal
));
1988 fprintf (stderr
, "Option. rule: %d, state: %ld, next: %ld",
1989 yyp
->yyoption
.yyrule
,
1990 (long) YYINDEX (yyp
->yyoption
.yystate
),
1991 (long) YYINDEX (yyp
->yyoption
.yynext
));
1993 fprintf (stderr
, "\n");
1995 fprintf (stderr
, "Tops:");
1996 for (yyi
= 0; yyi
< yystack
->yytops
.yysize
; yyi
+= 1)
1997 fprintf (stderr
, "%lu: %ld; ", (unsigned long) yyi
,
1998 (long) YYINDEX (yystack
->yytops
.yystates
[yyi
]));
1999 fprintf (stderr
, "\n");
2004 m4_if(b4_defines_flag
, 0, [],
2005 [@output @output_header_name@
2006 b4_copyright([Skeleton parser
for GLR parsing with Bison
], [2002, 2003])
2008 b4_token_defines(b4_tokens
)
2010 #if ! defined (YYSTYPE) && ! defined (YYSTYPE_IS_DECLARED)
2011 m4_ifdef([b4_stype
],
2012 [b4_syncline([b4_stype_line
], [b4_filename
])
2013 typedef union m4_bregexp(b4_stype
, [^{], [YYSTYPE
])b4_stype YYSTYPE
;
2014 /* Line __line__ of glr.c. */
2015 b4_syncline([@oline@
], [@ofile@
])],
2016 [typedef int YYSTYPE
;])
2017 # define YYSTYPE_IS_DECLARED 1
2018 # define YYSTYPE_IS_TRIVIAL 1
2022 [extern YYSTYPE b4_prefix
[]lval
;])
2024 #if ! defined (YYLTYPE) && ! defined (YYLTYPE_IS_DECLARED)
2025 typedef struct YYLTYPE
2036 # define YYLTYPE_IS_DECLARED 1
2037 # define YYLTYPE_IS_TRIVIAL 1
2040 b4_location_if([m4_if(b4_pure
, [0],
2041 [extern YYLTYPE b4_prefix
[]lloc
;])