1 m4_divert(-1) -*- C
-*-
4 # GLR skeleton for Bison
5 # Copyright (C) 2002 Free Software Foundation, Inc.
7 # This program is free software; you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; either version 2 of the License, or
10 # (at your option) any later version.
12 # This program is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
17 # You should have received a copy of the GNU General Public License
18 # along with this program; if not, write to the Free Software
19 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
23 ## ---------------- ##
25 ## ---------------- ##
28 m4_define_default([b4_stack_depth_max
], [10000])
29 m4_define_default([b4_stack_depth_init
], [200])
32 m4_define_default([b4_location_type
], [yyltype
])
36 ## ------------------------ ##
37 ## Pure/impure interfaces. ##
38 ## ------------------------ ##
43 # Accumule in b4_lex_param all the yylex arguments.
44 # Yes, this is quite ugly...
45 m4_define([b4_lex_param
],
46 m4_dquote(b4_pure_if([[[[YYSTYPE
*]], [[yylvalp]]][]dnl
47 b4_location_if([, [[YYLTYPE
*], [yyllocp
]]])])dnl
48 m4_ifdef([b4_lex_param
], [, ]b4_lex_param
)))
53 m4_define([b4_user_formals
],
54 [m4_ifset([b4_parse_param
], [, b4_c_ansi_formals(b4_parse_param
)])])
59 # Arguments passed to yyerror: user args plus yylloc.
60 m4_define([b4_yyerror_args
],
61 [b4_pure_if([b4_location_if([yylocp
, ])])dnl
62 m4_ifset([b4_parse_param
], [b4_c_args(b4_parse_param
), ])])
67 # Same as above, but on the lookahead, hence yyllocp instead of yylocp.
68 m4_define([b4_lyyerror_args
],
69 [b4_pure_if([b4_location_if([yyllocp
, ])])dnl
70 m4_ifset([b4_parse_param
], [b4_c_args(b4_parse_param
), ])])
75 # Arguments needed by yyerror: user args plus yylloc.
76 m4_define([b4_pure_args
],
77 [b4_pure_if([b4_location_if([, yylocp
])])[]b4_user_args
])
82 # Arguments passed to yyerror: user formals plus yyllocp.
83 m4_define([b4_pure_formals
],
84 [b4_pure_if([b4_location_if([, YYLTYPE
*yylocp
])])[]b4_user_formals
])
89 # Same as above, but on the lookahead, hence yyllocp instead of yylocp.
90 m4_define([b4_lpure_args
],
91 [b4_pure_if([b4_location_if([, yyllocp
])])[]b4_user_args
])
96 # Same as above, but on the lookahead, hence yyllocp instead of yylocp.
97 m4_define([b4_lpure_formals
],
98 [b4_pure_if([b4_location_if([YYLTYPE
*yyllocp
])])[]b4_user_formals
])
101 ## ----------------- ##
102 ## Semantic Values. ##
103 ## ----------------- ##
106 # b4_lhs_value([TYPE])
107 # --------------------
108 # Expansion of $<TYPE>$.
109 m4_define([b4_lhs_value
],
110 [(*yyvalp
)[]m4_ifval([$
1], [.$
1])])
113 # b4_rhs_value(RULE-LENGTH, NUM, [TYPE])
114 # --------------------------------------
115 # Expansion of $<TYPE>NUM, where the current rule has RULE-LENGTH
117 m4_define([b4_rhs_value
],
118 [yyvsp@
{m4_eval([$
2 - $
1])@
}.yystate
.yysemantics
.yysval
[]m4_ifval([$
3], [.$
3])])
129 m4_define([b4_lhs_location
],
133 # b4_rhs_location(RULE-LENGTH, NUM)
134 # ---------------------------------
135 # Expansion of @NUM, where the current rule has RULE-LENGTH symbols
137 m4_define([b4_rhs_location
],
138 [yyvsp@
{m4_eval([$
2 - $
1])@
}.yystate
.yyloc
])
141 # We do want M4 expansion after # for CPP macros.
144 @output @output_parser_name@
145 b4_copyright([Skeleton parser
for GLR parsing with Bison
], [2002])
147 /* This is the parser code for GLR (Generalized LR) parser. */
157 m4_if(b4_prefix
[], [yy
], [],
158 [/* If NAME_PREFIX is specified substitute the variables and functions
160 #define yyparse b4_prefix[]parse
161 #define yylex b4_prefix[]lex
162 #define yyerror b4_prefix[]error
163 #define yylval b4_prefix[]lval
164 #define yychar b4_prefix[]char
165 #define yydebug b4_prefix[]debug
166 #define yynerrs b4_prefix[]nerrs
167 b4_location_if([#define yylloc b4_prefix[]lloc])])
169 b4_token_defines(b4_tokens
)
171 /* Copy the first part of user declarations. */
174 /* Enabling traces. */
176 # define YYDEBUG ]b4_debug[
179 /* Enabling verbose error messages. */
180 #ifdef YYERROR_VERBOSE
181 # undef YYERROR_VERBOSE
182 # define YYERROR_VERBOSE 1
184 # define YYERROR_VERBOSE ]b4_error_verbose[
188 ]m4_ifdef([b4_stype
],
189 [b4_syncline([b4_stype_line
], [b4_filename
])
190 typedef union b4_stype yystype
;
191 /* Line __line__ of __file__. */
192 b4_syncline([@oline@
], [@ofile@
])],
193 [typedef int yystype
;])[
194 # define YYSTYPE yystype
195 # define YYSTYPE_IS_TRIVIAL 1
199 typedef struct yyltype
206 # define YYLTYPE ]b4_location_type[
207 # define YYLTYPE_IS_TRIVIAL 1
210 /* Default (constant) values used for initialization for null
211 right-hand sides. Unlike the standard bison.simple template,
212 here we set the default values of $$ and $@@ to zeroed-out
213 values. Since the default value of these quantities is undefined,
214 this behavior is technically correct. */
215 static YYSTYPE yyval_default
;
216 static YYLTYPE yyloc_default
;
218 /* Copy the second part of user declarations. */
221 ]/* Line __line__ of __file__. */
222 b4_syncline([@oline@
], [@ofile@
])
224 #if ! defined (__cplusplus)
234 #ifndef __attribute__
235 /* This feature is available in gcc versions 2.5 and later. */
236 # if !defined (__GNUC__) || __GNUC__ < 2 || \
237 (__GNUC__ == 2 && __GNUC_MINOR__ < 5) || __STRICT_ANSI__
238 # define __attribute__(Spec) /* empty */
242 #ifndef ATTRIBUTE_UNUSED
243 # define ATTRIBUTE_UNUSED __attribute__ ((__unused__))
246 #if ! defined (__GNUC__)
250 /* YYFINAL -- State number of the termination state. */
251 #define YYFINAL ]b4_final_state_number[
252 /* YYLAST -- Last index in YYTABLE. */
253 #define YYLAST ]b4_last[
255 /* YYNTOKENS -- Number of terminals. */
256 #define YYNTOKENS ]b4_tokens_number[
257 /* YYNNTS -- Number of nonterminals. */
258 #define YYNNTS ]b4_nterms_number[
259 /* YYNRULES -- Number of rules. */
260 #define YYNRULES ]b4_rules_number[
261 /* YYNRULES -- Number of states. */
262 #define YYNSTATES ]b4_states_number[
263 /* YYMAXRHS -- Maximum number of symbols on right-hand side of rule. */
264 #define YYMAXRHS ]b4_r2_max[
266 /* YYTRANSLATE(X) -- Bison symbol number corresponding to X. */
267 #define YYUNDEFTOK ]b4_undef_token_number[
268 #define YYMAXUTOK ]b4_user_token_number_max[
270 #define YYTRANSLATE(YYX) \
271 ((unsigned)(YYX) <= YYMAXUTOK ? yytranslate[YYX] : YYUNDEFTOK)
273 /* YYTRANSLATE[YYLEX] -- Bison symbol number corresponding to YYLEX. */
274 static const ]b4_int_type_for([b4_translate
])[ yytranslate
[] =
280 /* YYPRHS[YYN] -- Index of the first RHS symbol of rule number YYN in
282 static const ]b4_int_type_for([b4_prhs
])[ yyprhs
[] =
287 /* YYRHS -- A `-1'-separated list of the rules' RHS. */
288 static const ]b4_int_type_for([b4_rhs
])[ yyrhs
[] =
293 /* YYRLINE[YYN] -- source line where rule number YYN was defined. */
294 static const ]b4_int_type_for([b4_rline
])[ yyrline
[] =
300 #if (YYDEBUG) || YYERROR_VERBOSE
301 /* YYTNME[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM.
302 First, the terminals, then, starting at YYNTOKENS, nonterminals. */
303 static const char *const yytname
[] =
308 #define yytname_size ((int) (sizeof (yytname) / sizeof (yytname[0])))
311 /* YYR1[YYN] -- Symbol number of symbol that rule YYN derives. */
312 static const ]b4_int_type_for([b4_r1
])[ yyr1
[] =
317 /* YYR2[YYN] -- Number of symbols composing right hand side of rule YYN. */
318 static const ]b4_int_type_for([b4_r2
])[ yyr2
[] =
323 /* YYDPREC[RULE-NUM] -- Dynamic precedence of rule #RULE-NUM (0 if none). */
324 static const ]b4_int_type_for([b4_dprec
])[ yydprec
[] =
329 /* YYMERGER[RULE-NUM] -- Index of merging function for rule #RULE-NUM. */
330 static const ]b4_int_type_for([b4_merger
])[ yymerger
[] =
335 /* YYDEFACT[S] -- default rule to reduce with in state S when YYTABLE
336 doesn't specify something else to do. Zero means the default is an
338 static const ]b4_int_type_for([b4_defact
])[ yydefact
[] =
343 /* YYPDEFGOTO[NTERM-NUM]. */
344 static const ]b4_int_type_for([b4_defgoto
])[ yydefgoto
[] =
349 /* YYPACT[STATE-NUM] -- Index in YYTABLE of the portion describing
351 #define YYPACT_NINF ]b4_pact_ninf[
352 static const ]b4_int_type_for([b4_pact
])[ yypact
[] =
357 /* YYPGOTO[NTERM-NUM]. */
358 static const ]b4_int_type_for([b4_pgoto
])[ yypgoto
[] =
363 /* YYTABLE[YYPACT[STATE-NUM]]. What to do in state STATE-NUM. If
364 positive, shift that token. If negative, reduce the rule which
365 number is the opposite. If zero, do what YYDEFACT says.
366 If YYTABLE_NINF, parse error. */
367 #define YYTABLE_NINF ]b4_table_ninf[
368 static const ]b4_int_type_for([b4_table
])[ yytable
[] =
373 /* YYCONFLP[YYPACT[STATE-NUM]] -- Pointer into YYCONFL of start of
374 list of conflicting reductions corresponding to action entry for
375 state STATE-NUM in yytable. 0 means no conflicts. The list in
376 yyconfl is terminated by a rule number of 0. */
377 static const ]b4_int_type_for([b4_conflict_list_heads
])[ yyconflp
[] =
379 ]b4_conflict_list_heads
[
382 /* YYCONFL[I] -- lists of conflicting rule numbers, each terminated by
383 0, pointed into by YYCONFLP. */
384 ]dnl Do
not use b4_int_type_for here
, since there are places where
385 dnl pointers onto yyconfl are taken
, which type is
"short *".
386 dnl We probably ought to introduce a type
for confl
.
387 [static const short yyconfl
[] =
389 ]b4_conflicting_rules
[
392 static const ]b4_int_type_for([b4_check
])[ yycheck
[] =
398 /* Prevent warning if -Wmissing-prototypes. */
399 ]b4_c_ansi_function_decl([yyparse
], [int], b4_parse_param
)[
401 /* Error token number */
404 /* YYLLOC_DEFAULT -- Compute the default location (before the actions
407 #define YYRHSLOC(yyRhs,YYK) (yyRhs[YYK].yystate.yyloc)
409 #ifndef YYLLOC_DEFAULT
410 # define YYLLOC_DEFAULT(yyCurrent, yyRhs, YYN) \
411 yyCurrent.first_line = YYRHSLOC(yyRhs,1).first_line; \
412 yyCurrent.first_column = YYRHSLOC(yyRhs,1).first_column; \
413 yyCurrent.last_line = YYRHSLOC(yyRhs,YYN).last_line; \
414 yyCurrent.last_column = YYRHSLOC(yyRhs,YYN).last_column;
417 /* YYLEX -- calling `yylex' with the right arguments. */
418 #define YYLEX ]b4_c_function_call([yylex], [int], b4_lex_param)[
423 #define yynerrs (yystack->yyerrcnt)
425 #define yychar (yystack->yyrawchar)],
433 static const int YYEOF
= 0;
434 static const int YYEMPTY
= -2;
436 typedef enum { yyok
, yyaccept
, yyabort
, yyerr
} YYRESULTTAG
;
439 do { YYRESULTTAG yyflag = YYE; if (yyflag != yyok) return yyflag; } \
444 #if ! defined (YYFPRINTF)
445 # define YYFPRINTF fprintf
448 # define YYDPRINTF(Args) \
453 /* Nonzero means print parse trace. It is left uninitialized so that
454 multiple parsers can coexist. */
457 /* Avoid empty `if' bodies. */
458 # define YYDPRINTF(Args) {}
459 #endif /* !YYDEBUG */
461 /* YYINITDEPTH -- initial size of the parser's stacks. */
463 # define YYINITDEPTH ]b4_stack_depth_init[
466 /* YYMAXDEPTH -- maximum size the stacks can grow to (effective only
467 if the built-in stack extension method is used).
469 Do not make this value too large; the results are undefined if
470 SIZE_MAX < YYMAXDEPTH * sizeof (GLRStackItem)
471 evaluated with infinite-precision integer arithmetic. */
478 # define YYMAXDEPTH ]b4_stack_depth_max[
481 /* Minimum number of free items on the stack allowed after an
482 allocation. This is to allow allocation and initialization
483 to be completed by functions that call expandGLRStack before the
484 stack is expanded, thus insuring that all necessary pointers get
485 properly redirected to new data. */
488 #if ! defined (YYSTACKEXPANDABLE) \
489 && (! defined (__cplusplus) || (YYLTYPE_IS_TRIVIAL && YYSTYPE_IS_TRIVIAL))
490 #define YYSTACKEXPANDABLE 1
492 #define YYSTACKEXPANDABLE 0
495 /** State numbers, as in LALR(1) machine */
496 typedef int yyStateNum
;
498 /** Rule numbers, as in LALR(1) machine */
499 typedef int yyRuleNum
;
501 /** Grammar symbol */
502 typedef short yySymbol
;
504 /** Item references, as in LALR(1) machine */
505 typedef short yyItemNum
;
507 typedef struct yyGLRState yyGLRState
;
508 typedef struct yySemanticOption yySemanticOption
;
509 typedef union yyGLRStackItem yyGLRStackItem
;
510 typedef struct yyGLRStack yyGLRStack
;
511 typedef struct yyGLRStateSet yyGLRStateSet
;
516 yyStateNum yylrState
;
520 yySemanticOption
* yyfirstVal
;
526 struct yyGLRStateSet
{
527 yyGLRState
** yystates
;
528 size_t yysize
, yycapacity
;
531 struct yySemanticOption
{
535 yySemanticOption
* yynext
;
538 union yyGLRStackItem
{
540 yySemanticOption yyoption
;
552 jmp_buf yyexception_buffer
;
553 yyGLRStackItem
* yyitems
;
554 yyGLRStackItem
* yynextFree
;
556 yyGLRState
* yysplitPoint
;
557 yyGLRState
* yylastDeleted
;
558 yyGLRStateSet yytops
;
561 static void yyinitGLRStack (yyGLRStack
* yystack
, size_t yysize
);
562 static void yyexpandGLRStack (yyGLRStack
* yystack
]b4_pure_formals
[);
563 static void yyfreeGLRStack (yyGLRStack
* yystack
);
566 yyFail (yyGLRStack
* yystack
]b4_pure_formals
[, const char* yyformat
, ...)
568 if (yyformat
!= NULL
)
572 va_start (yyap
, yyformat
);
573 yystack
->yyerrflag
= 1;
574 vsprintf (yymsg
, yyformat
, yyap
);
575 yyerror (]b4_yyerror_args
[yymsg
);
577 longjmp (yystack
->yyexception_buffer
, 1);
580 #if YYDEBUG || YYERROR_VERBOSE
581 /** A printable representation of TOKEN. Valid until next call to
583 static inline const char*
584 yytokenName (yySymbol yytoken
)
586 return yytname
[yytoken
];
590 /** Perform user action for rule number YYN, with RHS length YYRHSLEN,
591 * and top stack item YYVSP. YYLVALP points to place to put semantic
592 * value ($$), and yylocp points to place for location information
593 * (@@$). Returns yyok for normal return, yyaccept for YYACCEPT,
594 * yyerr for YYERROR, yyabort for YYABORT. */
596 yyuserAction (yyRuleNum yyn
, int yyrhslen
, yyGLRStackItem
* yyvsp
,
597 YYSTYPE
* yyvalp
, YYLTYPE
* yylocp
, yyGLRStack
* yystack
600 /* Avoid `unused' warnings in there are no $n. */
605 *yyvalp
= yyval_default
;
606 *yylocp
= yyloc_default
;
610 *yyvalp
= yyvsp
[1-yyrhslen
].yystate
.yysemantics
.yysval
;
611 *yylocp
= yyvsp
[1-yyrhslen
].yystate
.yyloc
;
614 # define yyval (*yyvalp)
616 # define yyerrok (yystack->yyerrState = 0)
618 # define YYACCEPT return yyaccept
620 # define YYABORT return yyabort
622 # define YYERROR return yyerr
624 # define YYRECOVERING (yystack->yyerrState != 0)
626 # define yyclearin (yychar = *(yystack->yytokenp) = YYEMPTY)
628 # define YYBACKUP(Token, Value) \
630 yyerror (]b4_yyerror_args["syntax error: cannot back up"); \
649 /* Line __line__ of __file__. */
650 b4_syncline([@oline@
], [@ofile@
])
655 yyuserMerge (int yyn
, YYSTYPE
* yy0
, YYSTYPE
* yy1
)
657 YYSTYPE yyval
= *yy0
;
658 /* `Use' the arguments. */
669 /* Bison grammar-table manipulation. */
671 /** Number of symbols composing the right hand side of rule #RULE. */
673 yyrhsLength (yyRuleNum yyrule
)
678 /** Left-hand-side symbol for rule #RULE. */
679 static inline yySymbol
680 yylhsNonterm (yyRuleNum yyrule
)
685 #define yyis_pact_ninf(yystate) \
686 ]m4_if(m4_eval(b4_pact_ninf < b4_pact_min), 1,
688 ((yystate
) == YYPACT_NINF
))[
690 /** True iff LR state STATE has only a default reduction (regardless
693 yyisDefaultedState (yyStateNum yystate
)
695 return yyis_pact_ninf (yypact
[yystate
]);
698 /** The default reduction for STATE, assuming it has one. */
699 static inline yyRuleNum
700 yydefaultAction (yyStateNum yystate
)
702 return yydefact
[yystate
];
705 #define yyis_table_ninf(yyindex) \
706 ]m4_if(m4_eval(b4_table_ninf < b4_table_min), 1,
708 ((yyindex
) == YYTABLE_NINF
))[
710 /** Set *YYACTION to the action to take in YYSTATE on seeing YYTOKEN.
712 * R < 0: Reduce on rule -R.
714 * R > 0: Shift to state R.
715 * Set *CONFLICTS to a pointer into yyconfl to 0-terminated list of
716 * conflicting reductions.
719 yygetLRActions (yyStateNum yystate
, int yytoken
,
720 int* yyaction
, const short** yyconflicts
)
722 int yyindex
= yypact
[yystate
] + yytoken
;
723 if (yyindex
< 0 || YYLAST
< yyindex
|| yycheck
[yyindex
] != yytoken
)
725 *yyaction
= -yydefact
[yystate
];
726 *yyconflicts
= yyconfl
;
728 else if (! yyis_table_ninf (yyindex
))
730 *yyaction
= yytable
[yyindex
];
731 *yyconflicts
= yyconfl
+ yyconflp
[yyindex
];
736 *yyconflicts
= yyconfl
+ yyconflp
[yyindex
];
740 static inline yyStateNum
741 yyLRgotoState (yyStateNum yystate
, yySymbol yylhs
)
744 yyr
= yypgoto
[yylhs
- YYNTOKENS
] + yystate
;
745 if (0 <= yyr
&& yyr
<= YYLAST
&& yycheck
[yyr
] == yystate
)
748 return yydefgoto
[yylhs
- YYNTOKENS
];
752 yyisShiftAction (int yyaction
)
758 yyisErrorAction (int yyaction
)
760 return yyaction
== 0;
765 /** True iff the semantic value of the edge leading to STATE is
768 yyhasResolvedValue (yyGLRState
* yystate
)
770 return yystate
->yyresolved
;
774 yyaddDeferredAction (yyGLRStack
* yystack
, yyGLRState
* yystate
,
775 yyGLRState
* rhs
, yyRuleNum yyrule
]b4_pure_formals
[)
777 yySemanticOption
* yynewItem
;
778 yynewItem
= &yystack
->yynextFree
->yyoption
;
779 yystack
->yyspaceLeft
-= 1;
780 yystack
->yynextFree
+= 1;
781 yynewItem
->yyisState
= yyfalse
;
782 yynewItem
->yystate
= rhs
;
783 yynewItem
->yyrule
= yyrule
;
784 yynewItem
->yynext
= yystate
->yysemantics
.yyfirstVal
;
785 yystate
->yysemantics
.yyfirstVal
= yynewItem
;
786 if (yystack
->yyspaceLeft
< YYHEADROOM
)
787 yyexpandGLRStack (yystack
]b4_pure_args
[);
792 /** Initialize SET to a singleton set containing an empty stack. */
794 yyinitStateSet (yyGLRStateSet
* yyset
)
797 yyset
->yycapacity
= 16;
798 yyset
->yystates
= (yyGLRState
**) malloc (16 * sizeof (yyset
->yystates
[0]));
799 yyset
->yystates
[0] = NULL
;
802 static void yyfreeStateSet (yyGLRStateSet
* yyset
)
804 free (yyset
->yystates
);
807 /** Initialize STACK to a single empty stack, with total maximum
808 * capacity for all stacks of SIZE. */
810 yyinitGLRStack (yyGLRStack
* yystack
, size_t yysize
)
812 yystack
->yyerrflag
= 0;
813 yystack
->yyerrState
= 0;
815 yystack
->yyspaceLeft
= yysize
;
816 yystack
->yynextFree
= yystack
->yyitems
=
817 (yyGLRStackItem
*) malloc (yysize
* sizeof (yystack
->yynextFree
[0]));
818 yystack
->yysplitPoint
= NULL
;
819 yystack
->yylastDeleted
= NULL
;
820 yyinitStateSet (&yystack
->yytops
);
823 #define YYRELOC(YYFROMITEMS,YYTOITEMS,YYX,YYTYPE) \
824 &((YYTOITEMS) - ((YYFROMITEMS) - (yyGLRStackItem*) (YYX)))->YYTYPE
826 /** If STACK is expandable, extend it. WARNING: Pointers into the
827 stack from outside should be considered invalid after this call.
828 We always expand when there are 1 or fewer items left AFTER an
829 allocation, so that we can avoid having external pointers exist
830 across an allocation. */
832 yyexpandGLRStack (yyGLRStack
* yystack
]b4_pure_formals
[)
834 #if YYSTACKEXPANDABLE
835 yyGLRStack yynewStack
;
836 yyGLRStackItem
* yyp0
, *yyp1
;
837 size_t yysize
, yynewSize
;
839 yysize
= yystack
->yynextFree
- yystack
->yyitems
;
840 if (YYMAXDEPTH
<= yysize
)
841 yyFail (yystack
][]b4_pure_args
[,
842 "parsing stack overflow (%d items)", yysize
);
843 yynewSize
= 2*yysize
;
844 if (YYMAXDEPTH
< yynewSize
)
845 yynewSize
= YYMAXDEPTH
;
846 yyinitGLRStack (&yynewStack
, yynewSize
);
847 for (yyp0
= yystack
->yyitems
, yyp1
= yynewStack
.yyitems
, yyn
= yysize
;
849 yyn
-= 1, yyp0
+= 1, yyp1
+= 1)
854 yyGLRState
* yys0
= &yyp0
->yystate
;
855 yyGLRState
* yys1
= &yyp1
->yystate
;
856 if (yys0
->yypred
!= NULL
)
858 YYRELOC (yyp0
, yyp1
, yys0
->yypred
, yystate
);
859 if (! yys0
->yyresolved
&& yys0
->yysemantics
.yyfirstVal
!= NULL
)
860 yys1
->yysemantics
.yyfirstVal
=
861 YYRELOC(yyp0
, yyp1
, yys0
->yysemantics
.yyfirstVal
, yyoption
);
865 yySemanticOption
* yyv0
= &yyp0
->yyoption
;
866 yySemanticOption
* yyv1
= &yyp1
->yyoption
;
867 if (yyv0
->yystate
!= NULL
)
868 yyv1
->yystate
= YYRELOC (yyp0
, yyp1
, yyv0
->yystate
, yystate
);
869 if (yyv0
->yynext
!= NULL
)
870 yyv1
->yynext
= YYRELOC (yyp0
, yyp1
, yyv0
->yynext
, yyoption
);
873 if (yystack
->yysplitPoint
!= NULL
)
874 yystack
->yysplitPoint
= YYRELOC (yystack
->yyitems
, yynewStack
.yyitems
,
875 yystack
->yysplitPoint
, yystate
);
877 for (yyn
= 0; yyn
< yystack
->yytops
.yysize
; yyn
+= 1)
878 if (yystack
->yytops
.yystates
[yyn
] != NULL
)
879 yystack
->yytops
.yystates
[yyn
] =
880 YYRELOC (yystack
->yyitems
, yynewStack
.yyitems
,
881 yystack
->yytops
.yystates
[yyn
], yystate
);
882 free (yystack
->yyitems
);
883 yystack
->yyitems
= yynewStack
.yyitems
;
884 yystack
->yynextFree
= yynewStack
.yynextFree
+ yysize
;
885 yystack
->yyspaceLeft
= yynewStack
.yyspaceLeft
- yysize
;
889 yyFail (yystack
][]b4_lpure_args
[,
890 "parsing stack overflow (%d items)", yysize
);
895 yyfreeGLRStack (yyGLRStack
* yystack
)
897 free (yystack
->yyitems
);
898 yyfreeStateSet (&yystack
->yytops
);
901 /** Assuming that S is a GLRState somewhere on STACK, update the
902 * splitpoint of STACK, if needed, so that it is at least as deep as
905 yyupdateSplit (yyGLRStack
* yystack
, yyGLRState
* yys
)
907 if (yystack
->yysplitPoint
!= NULL
&& yystack
->yysplitPoint
> yys
)
908 yystack
->yysplitPoint
= yys
;
911 /** Invalidate stack #K in STACK. */
913 yymarkStackDeleted (yyGLRStack
* yystack
, int yyk
)
915 if (yystack
->yytops
.yystates
[yyk
] != NULL
)
916 yystack
->yylastDeleted
= yystack
->yytops
.yystates
[yyk
];
917 yystack
->yytops
.yystates
[yyk
] = NULL
;
920 /** Undelete the last stack that was marked as deleted. Can only be
921 done once after a deletion, and only when all other stacks have
924 yyundeleteLastStack (yyGLRStack
* yystack
)
926 if (yystack
->yylastDeleted
== NULL
|| yystack
->yytops
.yysize
!= 0)
928 yystack
->yytops
.yystates
[0] = yystack
->yylastDeleted
;
929 yystack
->yytops
.yysize
= 1;
930 YYDPRINTF ((stderr
, "Restoring last deleted stack as stack #0.\n"));
931 yystack
->yylastDeleted
= NULL
;
935 yyremoveDeletes (yyGLRStack
* yystack
)
939 while (yyj
< yystack
->yytops
.yysize
)
941 if (yystack
->yytops
.yystates
[yyi
] == NULL
)
944 YYDPRINTF ((stderr
, "Removing dead stacks.\n"));
945 yystack
->yytops
.yysize
-= 1;
949 yystack
->yytops
.yystates
[yyj
] = yystack
->yytops
.yystates
[yyi
];
951 YYDPRINTF ((stderr
, "Rename stack %d -> %d.\n", yyi
, yyj
));
958 /** Shift to a new state on stack #K of STACK, corresponding to LR state
959 * LRSTATE, at input position POSN, with (resolved) semantic value SVAL. */
961 yyglrShift (yyGLRStack
* yystack
, int yyk
, yyStateNum yylrState
, size_t yyposn
,
962 YYSTYPE yysval
, YYLTYPE
* yylocp
]b4_user_formals
[)
964 yyGLRStackItem
* yynewItem
;
966 yynewItem
= yystack
->yynextFree
;
967 yystack
->yynextFree
+= 1;
968 yystack
->yyspaceLeft
-= 1;
969 yynewItem
->yystate
.yyisState
= yytrue
;
970 yynewItem
->yystate
.yylrState
= yylrState
;
971 yynewItem
->yystate
.yyposn
= yyposn
;
972 yynewItem
->yystate
.yyresolved
= yytrue
;
973 yynewItem
->yystate
.yypred
= yystack
->yytops
.yystates
[yyk
];
974 yystack
->yytops
.yystates
[yyk
] = &yynewItem
->yystate
;
975 yynewItem
->yystate
.yysemantics
.yysval
= yysval
;
976 yynewItem
->yystate
.yyloc
= *yylocp
;
977 if (yystack
->yyspaceLeft
< YYHEADROOM
)
978 yyexpandGLRStack (yystack
]b4_pure_args
[);
981 /** Shift to a new state on stack #K of STACK, to a new state
982 * corresponding to LR state LRSTATE, at input position POSN, with
983 * the (unresolved) semantic value of RHS under the action for RULE. */
985 yyglrShiftDefer (yyGLRStack
* yystack
, int yyk
, yyStateNum yylrState
,
986 size_t yyposn
, yyGLRState
* rhs
, yyRuleNum yyrule
]b4_pure_formals
[)
988 yyGLRStackItem
* yynewItem
;
990 yynewItem
= yystack
->yynextFree
;
991 yynewItem
->yystate
.yyisState
= yytrue
;
992 yynewItem
->yystate
.yylrState
= yylrState
;
993 yynewItem
->yystate
.yyposn
= yyposn
;
994 yynewItem
->yystate
.yyresolved
= yyfalse
;
995 yynewItem
->yystate
.yypred
= yystack
->yytops
.yystates
[yyk
];
996 yynewItem
->yystate
.yysemantics
.yyfirstVal
= NULL
;
997 yystack
->yytops
.yystates
[yyk
] = &yynewItem
->yystate
;
998 yystack
->yynextFree
+= 1;
999 yystack
->yyspaceLeft
-= 1;
1000 yyaddDeferredAction (yystack
, &yynewItem
->yystate
, rhs
, yyrule
]b4_pure_args
[);
1003 /** Pop the symbols consumed by reduction #RULE from the top of stack
1004 * #K of STACK, and perform the appropriate semantic action on their
1005 * semantic values. Assumes that all ambiguities in semantic values
1006 * have been previously resolved. Set *VALP to the resulting value,
1007 * and *LOCP to the computed location (if any). Return value is as
1008 * for userAction. */
1010 yydoAction (yyGLRStack
* yystack
, int yyk
, yyRuleNum yyrule
,
1011 YYSTYPE
* yyvalp
, YYLTYPE
* yylocp
]b4_user_formals
[)
1013 int yynrhs
= yyrhsLength (yyrule
);
1015 if (yystack
->yysplitPoint
== NULL
)
1017 /* Standard special case: single stack. */
1018 yyGLRStackItem
* rhs
= (yyGLRStackItem
*) yystack
->yytops
.yystates
[yyk
];
1020 yystack
->yynextFree
-= yynrhs
;
1021 yystack
->yyspaceLeft
+= yynrhs
;
1022 yystack
->yytops
.yystates
[0] = & yystack
->yynextFree
[-1].yystate
;
1025 *yyvalp
= yyval_default
;
1026 *yylocp
= yyloc_default
;
1030 *yyvalp
= rhs
[1-yynrhs
].yystate
.yysemantics
.yysval
;
1031 *yylocp
= rhs
[1-yynrhs
].yystate
.yyloc
;
1033 return yyuserAction (yyrule
, yynrhs
, rhs
,
1034 yyvalp
, yylocp
, yystack
]b4_user_args
[);
1040 yyGLRStackItem yyrhsVals
[YYMAXRHS
];
1041 for (yyi
= yynrhs
-1, yys
= yystack
->yytops
.yystates
[yyk
]; 0 <= yyi
;
1042 yyi
-= 1, yys
= yys
->yypred
)
1044 assert (yys
->yypred
!= NULL
);
1045 yyrhsVals
[yyi
].yystate
.yyresolved
= yytrue
;
1046 yyrhsVals
[yyi
].yystate
.yysemantics
.yysval
= yys
->yysemantics
.yysval
;
1047 yyrhsVals
[yyi
].yystate
.yyloc
= yys
->yyloc
;
1049 yyupdateSplit (yystack
, yys
);
1050 yystack
->yytops
.yystates
[yyk
] = yys
;
1053 *yyvalp
= yyval_default
;
1054 *yylocp
= yyloc_default
;
1058 *yyvalp
= yyrhsVals
[0].yystate
.yysemantics
.yysval
;
1059 *yylocp
= yyrhsVals
[0].yystate
.yyloc
;
1061 return yyuserAction (yyrule
, yynrhs
, yyrhsVals
+ (yynrhs
-1),
1062 yyvalp
, yylocp
, yystack
]b4_user_args
[);
1067 # define YY_REDUCE_PRINT(K, Rule)
1069 # define YY_REDUCE_PRINT(K, Rule) \
1072 yy_reduce_print (K, Rule); \
1075 /*----------------------------------------------------------.
1076 | Report that the RULE is going to be reduced on stack #K. |
1077 `----------------------------------------------------------*/
1080 yy_reduce_print (size_t yyk
, yyRuleNum yyrule
)
1083 YYDPRINTF ((stderr
, "Reducing stack %d by rule %d (line %d),",
1084 yyk
, yyrule
- 1, yyrline
[yyrule
]));
1085 /* Print the symbols being reduced, and their result. */
1086 for (yyi
= yyprhs
[yyrule
]; 0 <= yyrhs
[yyi
]; yyi
++)
1087 YYFPRINTF (stderr
, "%s ", yytokenName (yyrhs
[yyi
]));
1088 YYFPRINTF (stderr
, " -> %s\n", yytokenName (yyr1
[yyrule
]));
1092 /** Pop items off stack #K of STACK according to grammar rule RULE,
1093 * and push back on the resulting nonterminal symbol. Perform the
1094 * semantic action associated with RULE and store its value with the
1095 * newly pushed state, if FORCEEVAL or if STACK is currently
1096 * unambiguous. Otherwise, store the deferred semantic action with
1097 * the new state. If the new state would have an identical input
1098 * position, LR state, and predecessor to an existing state on the stack,
1099 * it is identified with that existing state, eliminating stack #K from
1100 * the STACK. In this case, the (necessarily deferred) semantic value is
1101 * added to the options for the existing state's semantic value.
1103 static inline YYRESULTTAG
1104 yyglrReduce (yyGLRStack
* yystack
, size_t yyk
, yyRuleNum yyrule
,
1105 bool yyforceEval
]b4_pure_formals
[)
1107 size_t yyposn
= yystack
->yytops
.yystates
[yyk
]->yyposn
;
1109 if (yyforceEval
|| yystack
->yysplitPoint
== NULL
)
1114 YY_REDUCE_PRINT (yyk
, yyrule
);
1115 YYCHK (yydoAction (yystack
, yyk
, yyrule
, &yysval
, &yyloc
]b4_user_args
[));
1116 yyglrShift (yystack
, yyk
,
1117 yyLRgotoState (yystack
->yytops
.yystates
[yyk
]->yylrState
,
1118 yylhsNonterm (yyrule
)),
1119 yyposn
, yysval
, &yyloc
]b4_user_args
[);
1120 YYDPRINTF ((stderr
, "Stack %d entering state %d\n",
1121 yyk
, yystack
->yytops
.yystates
[yyk
]->yylrState
));
1127 yyGLRState
* yys
, *yys0
= yystack
->yytops
.yystates
[yyk
];
1128 yyStateNum yynewLRState
;
1130 for (yys
= yystack
->yytops
.yystates
[yyk
], yyn
= yyrhsLength (yyrule
);
1134 assert (yys
!= NULL
);
1136 yyupdateSplit (yystack
, yys
);
1137 yynewLRState
= yyLRgotoState (yys
->yylrState
, yylhsNonterm (yyrule
));
1139 "Reduced stack %d by rule #%d; action deferred. "
1140 "Now in state %d.\n",
1141 yyk
, yyrule
-1, yynewLRState
));
1142 for (yyi
= 0; yyi
< yystack
->yytops
.yysize
; yyi
+= 1)
1143 if (yyi
!= yyk
&& yystack
->yytops
.yystates
[yyi
] != NULL
)
1145 yyGLRState
* yyp
, *yysplit
= yystack
->yysplitPoint
;
1146 yyp
= yystack
->yytops
.yystates
[yyi
];
1147 while (yyp
!= yys
&& yyp
!= yysplit
&& yyp
->yyposn
>= yyposn
)
1149 if (yyp
->yylrState
== yynewLRState
&& yyp
->yypred
== yys
)
1151 yyaddDeferredAction (yystack
, yyp
, yys0
, yyrule
]b4_pure_args
[);
1152 yymarkStackDeleted (yystack
, yyk
);
1153 YYDPRINTF ((stderr
, "Merging stack %d into stack %d.\n",
1160 yystack
->yytops
.yystates
[yyk
] = yys
;
1161 yyglrShiftDefer (yystack
, yyk
, yynewLRState
, yyposn
, yys0
, yyrule
]b4_pure_args
[);
1167 yysplitStack (yyGLRStack
* yystack
, int yyk
)
1169 if (yystack
->yysplitPoint
== NULL
)
1172 yystack
->yysplitPoint
= yystack
->yytops
.yystates
[yyk
];
1174 if (yystack
->yytops
.yysize
>= yystack
->yytops
.yycapacity
)
1176 yystack
->yytops
.yycapacity
*= 2;
1177 yystack
->yytops
.yystates
=
1178 (yyGLRState
**) realloc (yystack
->yytops
.yystates
,
1179 yystack
->yytops
.yycapacity
1180 * sizeof (yyGLRState
*));
1182 yystack
->yytops
.yystates
[yystack
->yytops
.yysize
]
1183 = yystack
->yytops
.yystates
[yyk
];
1184 yystack
->yytops
.yysize
+= 1;
1185 return yystack
->yytops
.yysize
-1;
1188 /** True iff Y0 and Y1 represent identical options at the top level.
1189 * That is, they represent the same rule applied to RHS symbols
1190 * that produce the same terminal symbols. */
1192 yyidenticalOptions (yySemanticOption
* yyy0
, yySemanticOption
* yyy1
)
1194 if (yyy0
->yyrule
== yyy1
->yyrule
)
1196 yyGLRState
*yys0
, *yys1
;
1198 for (yys0
= yyy0
->yystate
, yys1
= yyy1
->yystate
,
1199 yyn
= yyrhsLength (yyy0
->yyrule
);
1201 yys0
= yys0
->yypred
, yys1
= yys1
->yypred
, yyn
-= 1)
1202 if (yys0
->yyposn
!= yys1
->yyposn
)
1210 /** Assuming identicalOptions (Y0,Y1), (destructively) merge the
1211 * alternative semantic values for the RHS-symbols of Y1 into the
1212 * corresponding semantic value sets of the symbols of Y0. */
1214 yymergeOptionSets (yySemanticOption
* yyy0
, yySemanticOption
* yyy1
)
1216 yyGLRState
*yys0
, *yys1
;
1218 for (yys0
= yyy0
->yystate
, yys1
= yyy1
->yystate
,
1219 yyn
= yyrhsLength (yyy0
->yyrule
);
1221 yys0
= yys0
->yypred
, yys1
= yys1
->yypred
, yyn
-= 1)
1224 else if (! yys0
->yyresolved
&& ! yys1
->yyresolved
)
1226 yySemanticOption
* yyz
;
1227 for (yyz
= yys0
->yysemantics
.yyfirstVal
; yyz
->yynext
!= NULL
;
1230 yyz
->yynext
= yys1
->yysemantics
.yyfirstVal
;
1234 /** Y0 and Y1 represent two possible actions to take in a given
1235 * parsing state; return 0 if no combination is possible,
1236 * 1 if user-mergeable, 2 if Y0 is preferred, 3 if Y1 is preferred. */
1238 yypreference (yySemanticOption
* y0
, yySemanticOption
* y1
)
1240 yyRuleNum r0
= y0
->yyrule
, r1
= y1
->yyrule
;
1241 int p0
= yydprec
[r0
], p1
= yydprec
[r1
];
1245 if (yymerger
[r0
] == 0 || yymerger
[r0
] != yymerger
[r1
])
1250 if (p0
== 0 || p1
== 0)
1259 static YYRESULTTAG
yyresolveValue (yySemanticOption
* yyoptionList
,
1260 yyGLRStack
* yystack
, YYSTYPE
* yyvalp
,
1261 YYLTYPE
* yylocp
]b4_user_formals
[);
1264 yyresolveStates (yyGLRState
* yys
, int yyn
, yyGLRStack
* yystack
]b4_user_formals
[)
1269 assert (yys
->yypred
!= NULL
);
1270 yyflag
= yyresolveStates (yys
->yypred
, yyn
-1, yystack
]b4_user_args
[);
1273 if (! yys
->yyresolved
)
1275 yyflag
= yyresolveValue (yys
->yysemantics
.yyfirstVal
, yystack
,
1276 &yys
->yysemantics
.yysval
, &yys
->yyloc
1280 yys
->yyresolved
= yytrue
;
1287 yyresolveAction (yySemanticOption
* yyopt
, yyGLRStack
* yystack
,
1288 YYSTYPE
* yyvalp
, YYLTYPE
* yylocp
]b4_user_formals
[)
1290 yyGLRStackItem yyrhsVals
[YYMAXRHS
];
1294 yynrhs
= yyrhsLength (yyopt
->yyrule
);
1295 YYCHK (yyresolveStates (yyopt
->yystate
, yynrhs
, yystack
]b4_user_args
[));
1296 for (yyi
= yynrhs
-1, yys
= yyopt
->yystate
; 0 <= yyi
;
1297 yyi
-= 1, yys
= yys
->yypred
)
1299 assert (yys
->yypred
!= NULL
);
1300 yyrhsVals
[yyi
].yystate
.yyresolved
= yytrue
;
1301 yyrhsVals
[yyi
].yystate
.yysemantics
.yysval
= yys
->yysemantics
.yysval
;
1302 yyrhsVals
[yyi
].yystate
.yyloc
= yys
->yyloc
;
1304 return yyuserAction (yyopt
->yyrule
, yynrhs
, yyrhsVals
+ (yynrhs
-1),
1305 yyvalp
, yylocp
, yystack
]b4_user_args
[);
1310 yyreportTree (yySemanticOption
* yyx
, int yyindent
)
1312 int yynrhs
= yyrhsLength (yyx
->yyrule
);
1315 yyGLRState
* yystates
[YYMAXRHS
];
1316 yyGLRState yyleftmost_state
;
1318 for (yyi
= yynrhs
, yys
= yyx
->yystate
; 0 < yyi
; yyi
-= 1, yys
= yys
->yypred
)
1319 yystates
[yyi
] = yys
;
1322 yyleftmost_state
.yyposn
= 0;
1323 yystates
[0] = &yyleftmost_state
;
1328 if (yyx
->yystate
->yyposn
< yys
->yyposn
+ 1)
1329 YYFPRINTF (stderr
, "%*s%s -> <Rule %d, empty>\n",
1330 yyindent
, "", yytokenName (yylhsNonterm (yyx
->yyrule
)),
1333 YYFPRINTF (stderr
, "%*s%s -> <Rule %d, tokens %d .. %d>\n",
1334 yyindent
, "", yytokenName (yylhsNonterm (yyx
->yyrule
)),
1335 yyx
->yyrule
, yys
->yyposn
+1, yyx
->yystate
->yyposn
);
1336 for (yyi
= 1; yyi
<= yynrhs
; yyi
+= 1)
1338 if (yystates
[yyi
]->yyresolved
)
1340 if (yystates
[yyi
-1]->yyposn
+1 > yystates
[yyi
]->yyposn
)
1341 YYFPRINTF (stderr
, "%*s%s <empty>\n", yyindent
+2, "",
1342 yytokenName (yyrhs
[yyprhs
[yyx
->yyrule
]+yyi
-1]));
1344 YYFPRINTF (stderr
, "%*s%s <tokens %d .. %d>\n", yyindent
+2, "",
1345 yytokenName (yyrhs
[yyprhs
[yyx
->yyrule
]+yyi
-1]),
1346 yystates
[yyi
-1]->yyposn
+1, yystates
[yyi
]->yyposn
);
1349 yyreportTree (yystates
[yyi
]->yysemantics
.yyfirstVal
, yyindent
+2);
1355 yyreportAmbiguity (yySemanticOption
* yyx0
, yySemanticOption
* yyx1
,
1356 yyGLRStack
* yystack
]b4_pure_formals
[)
1358 /* `Unused' warnings. */
1363 YYFPRINTF (stderr
, "Ambiguity detected.\n");
1364 YYFPRINTF (stderr
, "Option 1,\n");
1365 yyreportTree (yyx0
, 2);
1366 YYFPRINTF (stderr
, "\nOption 2,\n");
1367 yyreportTree (yyx1
, 2);
1368 YYFPRINTF (stderr
, "\n");
1370 yyFail (yystack
][]b4_pure_args
[, "ambiguity detected");
1374 /** Resolve the ambiguity represented by OPTIONLIST, perform the indicated
1375 * actions, and return the result. */
1377 yyresolveValue (yySemanticOption
* yyoptionList
, yyGLRStack
* yystack
,
1378 YYSTYPE
* yyvalp
, YYLTYPE
* yylocp
]b4_user_formals
[)
1380 yySemanticOption
* yybest
;
1381 yySemanticOption
* yyp
;
1384 yybest
= yyoptionList
;
1386 for (yyp
= yyoptionList
->yynext
; yyp
!= NULL
; yyp
= yyp
->yynext
)
1388 if (yyidenticalOptions (yybest
, yyp
))
1389 yymergeOptionSets (yybest
, yyp
);
1391 switch (yypreference (yybest
, yyp
))
1394 yyreportAmbiguity (yybest
, yyp
, yystack
]b4_pure_args
[);
1410 int yyprec
= yydprec
[yybest
->yyrule
];
1411 YYCHK (yyresolveAction (yybest
, yystack
, yyvalp
, yylocp
]b4_user_args
[));
1412 for (yyp
= yybest
->yynext
; yyp
!= NULL
; yyp
= yyp
->yynext
)
1414 if (yyprec
== yydprec
[yyp
->yyrule
])
1418 YYCHK (yyresolveAction (yyp
, yystack
, &yyval1
, &yydummy
]b4_user_args
[));
1419 *yyvalp
= yyuserMerge (yymerger
[yyp
->yyrule
], yyvalp
, &yyval1
);
1425 return yyresolveAction (yybest
, yystack
, yyvalp
, yylocp
]b4_user_args
[);
1429 yyresolveStack (yyGLRStack
* yystack
]b4_user_formals
[)
1431 if (yystack
->yysplitPoint
!= NULL
)
1436 for (yyn
= 0, yys
= yystack
->yytops
.yystates
[0];
1437 yys
!= yystack
->yysplitPoint
;
1438 yys
= yys
->yypred
, yyn
+= 1)
1440 YYCHK (yyresolveStates (yystack
->yytops
.yystates
[0], yyn
, yystack
1447 yycompressStack (yyGLRStack
* yystack
)
1449 yyGLRState
* yyp
, *yyq
, *yyr
;
1451 if (yystack
->yytops
.yysize
!= 1 || yystack
->yysplitPoint
== NULL
)
1454 for (yyp
= yystack
->yytops
.yystates
[0], yyq
= yyp
->yypred
, yyr
= NULL
;
1455 yyp
!= yystack
->yysplitPoint
;
1456 yyr
= yyp
, yyp
= yyq
, yyq
= yyp
->yypred
)
1459 yystack
->yyspaceLeft
+= yystack
->yynextFree
- yystack
->yyitems
;
1460 yystack
->yynextFree
= ((yyGLRStackItem
*) yystack
->yysplitPoint
) + 1;
1461 yystack
->yyspaceLeft
-= yystack
->yynextFree
- yystack
->yyitems
;
1462 yystack
->yysplitPoint
= NULL
;
1463 yystack
->yylastDeleted
= NULL
;
1467 yystack
->yynextFree
->yystate
= *yyr
;
1469 yystack
->yynextFree
->yystate
.yypred
= & yystack
->yynextFree
[-1].yystate
;
1470 yystack
->yytops
.yystates
[0] = &yystack
->yynextFree
->yystate
;
1471 yystack
->yynextFree
+= 1;
1472 yystack
->yyspaceLeft
-= 1;
1477 yyprocessOneStack (yyGLRStack
* yystack
, int yyk
,
1478 size_t yyposn
, YYSTYPE
* yylvalp
, YYLTYPE
* yyllocp
1482 const short* yyconflicts
;
1484 yySymbol
* const yytokenp
= yystack
->yytokenp
;
1486 while (yystack
->yytops
.yystates
[yyk
] != NULL
)
1488 yyStateNum yystate
= yystack
->yytops
.yystates
[yyk
]->yylrState
;
1490 assert (yystate
!= YYFINAL
);
1491 if (yyisDefaultedState (yystate
))
1493 yyrule
= yydefaultAction (yystate
);
1496 YYDPRINTF ((stderr
, "Stack %d dies.\n", yyk
));
1497 yymarkStackDeleted (yystack
, yyk
);
1500 YYCHK (yyglrReduce (yystack
, yyk
, yyrule
, yyfalse
]b4_lpure_args
[));
1504 if (*yytokenp
== YYEMPTY
)
1506 YYDPRINTF ((stderr
, "Reading a token: "));
1508 *yytokenp
= YYTRANSLATE(yychar
);
1509 YYDPRINTF ((stderr
, "Next token is %s\n",
1510 yytokenName (*yytokenp
)));
1512 yygetLRActions (yystate
, *yytokenp
, &yyaction
, &yyconflicts
);
1514 while (*yyconflicts
!= 0)
1516 int yynewStack
= yysplitStack (yystack
, yyk
);
1517 YYDPRINTF ((stderr
, "Splitting off stack %d from %d.\n",
1519 YYCHK (yyglrReduce (yystack
, yynewStack
,
1520 *yyconflicts
, yyfalse
]b4_lpure_args
[));
1521 YYCHK (yyprocessOneStack (yystack
, yynewStack
, yyposn
,
1522 yylvalp
, yyllocp
]b4_user_args
[));
1526 if (yyisShiftAction (yyaction
))
1528 YYDPRINTF ((stderr
, "Shifting token %s on stack %d, ",
1529 yytokenName (*yytokenp
), yyk
));
1530 yyglrShift (yystack
, yyk
, yyaction
, yyposn
+1,
1531 *yylvalp
, yyllocp
]b4_user_args
[);
1532 YYDPRINTF ((stderr
, "which is now in state #%d\n",
1533 yystack
->yytops
.yystates
[yyk
]->yylrState
));
1536 else if (yyisErrorAction (yyaction
))
1538 YYDPRINTF ((stderr
, "Stack %d dies.\n", yyk
));
1539 yymarkStackDeleted (yystack
, yyk
);
1543 YYCHK (yyglrReduce (yystack
, yyk
, -yyaction
, yyfalse
]b4_lpure_args
[));
1550 yyreportParseError (yyGLRStack
* yystack
,
1551 YYSTYPE
* yylvalp
, YYLTYPE
* yyllocp
]b4_user_formals
[)
1553 /* `Unused' warnings. */
1557 if (yystack
->yyerrState
== 0)
1560 yySymbol
* const yytokenp
= yystack
->yytokenp
;
1561 int yyn
, yyx
, yycount
;
1563 const char* yyprefix
;
1566 yyn
= yypact
[yystack
->yytops
.yystates
[0]->yylrState
];
1567 if (YYPACT_NINF
< yyn
&& yyn
< YYLAST
)
1570 /* Start YYX at -YYN if negative to avoid negative indexes in
1572 yysize
= sizeof ("parse error, unexpected ")
1573 + strlen (yytokenName (*yytokenp
));
1574 yyprefix
= ", expecting ";
1575 for (yyx
= yyn
< 0 ? -yyn
: 0; yyx
< yytname_size
&& yycount
<= 5;
1577 if (yycheck
[yyx
+ yyn
] == yyx
&& yyx
!= YYTERROR
)
1578 yysize
+= strlen (yytokenName (yyx
)) + strlen (yyprefix
),
1579 yycount
+= 1, yyprefix
= " or ";
1580 yymsg
= yyp
= (char*) malloc (yysize
);
1581 sprintf (yyp
, "parse error, unexpected %s",
1582 yytokenName (*yytokenp
));
1583 yyp
+= strlen (yyp
);
1586 yyprefix
= ", expecting ";
1587 for (yyx
= yyn
< 0 ? -yyn
: 0; yyx
< yytname_size
; yyx
+= 1)
1588 if (yycheck
[yyx
+ yyn
] == yyx
&& yyx
!= YYTERROR
)
1590 sprintf (yyp
, "%s%s", yyprefix
, yytokenName (yyx
));
1591 yyp
+= strlen (yyp
);
1595 yyerror (]b4_lyyerror_args
[yymsg
);
1600 yyerror (]b4_lyyerror_args
["parse error");
1605 /* Recover from a syntax error on YYSTACK, assuming that YYTOKENP,
1606 YYLVALP, and YYLLOCP point to the syntactic category, semantic
1607 value, and location of the lookahead. */
1609 yyrecoverParseError (yyGLRStack
* yystack
,
1610 YYSTYPE
* yylvalp
, YYLTYPE
* yyllocp
]b4_user_formals
[)
1612 yySymbol
* const yytokenp
= yystack
->yytokenp
;
1616 if (yystack
->yyerrState
== 0)
1617 yystack
->yyerrState
= 3;
1618 else if (yystack
->yyerrState
== 3)
1619 /* We just shifted the error token and (perhaps) took some
1620 reductions. Skip tokens until we can proceed. */
1623 if (*yytokenp
== YYEOF
)
1624 yyFail (yystack
][]b4_lpure_args
[, NULL
);
1625 if (*yytokenp
!= YYEMPTY
)
1626 YYDPRINTF ((stderr
, "Discarding token %s\n",
1627 yytokenName (*yytokenp
)));
1628 YYDPRINTF ((stderr
, "Reading a token: "));
1630 *yytokenp
= YYTRANSLATE (yychar
);
1631 YYDPRINTF ((stderr
, "Next token is %s\n", yytokenName (*yytokenp
)));
1632 yyj
= yypact
[yystack
->yytops
.yystates
[0]->yylrState
];
1633 if (yyis_pact_ninf (yyj
))
1634 /* Something's not right; we shouldn't be here. */
1635 yyFail (yystack
][]b4_lpure_args
[, NULL
);
1637 if (yyj
< 0 || YYLAST
< yyj
|| yycheck
[yyj
] != *yytokenp
)
1639 if (yydefact
[yystack
->yytops
.yystates
[0]->yylrState
] != 0)
1642 else if (yytable
[yyj
] != 0 && ! yyis_table_ninf (yytable
[yyj
]))
1646 /* Reduce to one stack. */
1647 for (yyk
= 0; yyk
< yystack
->yytops
.yysize
; yyk
+= 1)
1648 if (yystack
->yytops
.yystates
[yyk
] != NULL
)
1650 if (yyk
>= yystack
->yytops
.yysize
)
1651 yyFail (yystack
][]b4_lpure_args
[, NULL
);
1652 for (yyk
+= 1; yyk
< yystack
->yytops
.yysize
; yyk
+= 1)
1653 yymarkStackDeleted (yystack
, yyk
);
1654 yyremoveDeletes (yystack
);
1655 yycompressStack (yystack
);
1657 /* Now pop stack until we find a state that shifts the error token. */
1658 while (yystack
->yytops
.yystates
[0] != NULL
)
1660 yyj
= yypact
[yystack
->yytops
.yystates
[0]->yylrState
];
1661 if (! yyis_pact_ninf (yyj
))
1664 if (0 <= yyj
&& yyj
<= YYLAST
&& yycheck
[yyj
] == YYTERROR
1665 && yyisShiftAction (yytable
[yyj
]))
1667 yyglrShift (yystack
, 0, yytable
[yyj
],
1668 yystack
->yytops
.yystates
[0]->yyposn
,
1669 *yylvalp
, yyllocp
]b4_user_args
[);
1673 yystack
->yytops
.yystates
[0] = yystack
->yytops
.yystates
[0]->yypred
;
1674 yystack
->yynextFree
-= 1;
1675 yystack
->yyspaceLeft
+= 1;
1677 if (yystack
->yytops
.yystates
[0] == NULL
)
1678 yyFail (yystack
][]b4_lpure_args
[, NULL
);
1681 #define YYCHK1(YYE) \
1687 yystack.yyerrflag = 1; \
1690 yystack.yyerrflag = 0; \
1693 goto yyuser_error; \
1702 ]b4_c_ansi_function_def([yyparse
], [int], b4_parse_param
)[
1712 #define yychar (yystack.yyrawchar)
1715 YYSTYPE
* const yylvalp
= &yylval
;
1716 YYLTYPE
* const yyllocp
= &yylloc
;
1718 yyinitGLRStack (&yystack
, YYINITDEPTH
);
1719 yystack
.yytokenp
= &yytoken
;
1721 YYDPRINTF ((stderr
, "Starting parse\n"));
1723 if (setjmp (yystack
.yyexception_buffer
) != 0)
1726 yyglrShift (&yystack
, 0, 0, 0, yyval_default
, &yyloc_default
]b4_user_args
[);
1732 /* For efficiency, we have two loops, the first of which is
1733 specialized to deterministic operation (single stack, no
1734 potential ambiguity). */
1741 const short* yyconflicts
;
1743 yyStateNum yystate
= yystack
.yytops
.yystates
[0]->yylrState
;
1744 if (yystate
== YYFINAL
)
1746 if (yyisDefaultedState (yystate
))
1748 yyrule
= yydefaultAction (yystate
);
1751 yyreportParseError (&yystack
, yylvalp
, yyllocp
]b4_user_args
[);
1754 YYCHK1 (yyglrReduce (&yystack
, 0, yyrule
, yytrue
]b4_lpure_args
[));
1758 if (yytoken
== YYEMPTY
)
1760 YYDPRINTF ((stderr
, "Reading a token: "));
1762 yytoken
= YYTRANSLATE (yychar
);
1763 YYDPRINTF ((stderr
, "Next token is %s\n",
1764 yytokenName (yytoken
)));
1766 yygetLRActions (yystate
, yytoken
, &yyaction
, &yyconflicts
);
1767 if (*yyconflicts
!= 0)
1769 if (yyisShiftAction (yyaction
))
1771 YYDPRINTF ((stderr
, "Shifting token %s, ",
1772 yytokenName (yytoken
)));
1773 if (yytoken
!= YYEOF
)
1776 yyglrShift (&yystack
, 0, yyaction
, yyposn
,
1777 yylval
, yyllocp
]b4_user_args
[);
1778 if (0 < yystack
.yyerrState
)
1779 yystack
.yyerrState
-= 1;
1780 YYDPRINTF ((stderr
, "Entering state %d\n",
1781 yystack
.yytops
.yystates
[0]->yylrState
));
1783 else if (yyisErrorAction (yyaction
))
1785 yyreportParseError (&yystack
, yylvalp
, yyllocp
]b4_user_args
[);
1789 YYCHK1 (yyglrReduce (&yystack
, 0, -yyaction
, yytrue
]b4_lpure_args
[));
1796 int yyn
= yystack
.yytops
.yysize
;
1797 for (yys
= 0; yys
< yyn
; yys
+= 1)
1798 YYCHK1 (yyprocessOneStack (&yystack
, yys
, yyposn
,
1799 yylvalp
, yyllocp
]b4_user_args
[));
1802 yyremoveDeletes (&yystack
);
1803 if (yystack
.yytops
.yysize
== 0)
1805 yyundeleteLastStack (&yystack
);
1806 if (yystack
.yytops
.yysize
== 0)
1807 yyFail (&yystack
][]b4_lpure_args
[, "parse error");
1808 YYCHK1 (yyresolveStack (&yystack
]b4_user_args
[));
1809 YYDPRINTF ((stderr
, "Returning to deterministic operation.\n"));
1810 yyreportParseError (&yystack
, yylvalp
, yyllocp
]b4_user_args
[);
1813 else if (yystack
.yytops
.yysize
== 1)
1815 YYCHK1 (yyresolveStack (&yystack
]b4_user_args
[));
1816 YYDPRINTF ((stderr
, "Returning to deterministic operation.\n"));
1817 yycompressStack (&yystack
);
1823 yyrecoverParseError (&yystack
, yylvalp
, yyllocp
]b4_user_args
[);
1824 yyposn
= yystack
.yytops
.yystates
[0]->yyposn
;
1829 yyfreeGLRStack (&yystack
);
1830 return yystack
.yyerrflag
;
1833 /* DEBUGGING ONLY */
1834 static void yypstack (yyGLRStack
* yystack
, int yyk
) ATTRIBUTE_UNUSED
;
1835 static void yypdumpstack (yyGLRStack
* yystack
) ATTRIBUTE_UNUSED
;
1838 yy_yypstack (yyGLRState
* yys
)
1842 yy_yypstack (yys
->yypred
);
1843 fprintf (stderr
, " -> ");
1845 fprintf (stderr
, "%d@@%lu", yys
->yylrState
, (unsigned long) yys
->yyposn
);
1849 yypstates (yyGLRState
* yyst
)
1852 fprintf (stderr
, "<null>");
1855 fprintf (stderr
, "\n");
1859 yypstack (yyGLRStack
* yystack
, int yyk
)
1861 yypstates (yystack
->yytops
.yystates
[yyk
]);
1864 #define YYINDEX(YYX) \
1865 ((YYX) == NULL ? -1 : (yyGLRStackItem*) (YYX) - yystack->yyitems)
1869 yypdumpstack (yyGLRStack
* yystack
)
1871 yyGLRStackItem
* yyp
;
1873 for (yyp
= yystack
->yyitems
; yyp
< yystack
->yynextFree
; yyp
+= 1)
1875 fprintf (stderr
, "%3lu. ", (unsigned long) (yyp
- yystack
->yyitems
));
1878 fprintf (stderr
, "Res: %d, LR State: %d, posn: %lu, pred: %ld",
1879 yyp
->yystate
.yyresolved
, yyp
->yystate
.yylrState
,
1880 (unsigned long) yyp
->yystate
.yyposn
,
1881 (long) YYINDEX (yyp
->yystate
.yypred
));
1882 if (! yyp
->yystate
.yyresolved
)
1883 fprintf (stderr
, ", firstVal: %ld",
1884 (long) YYINDEX (yyp
->yystate
.yysemantics
.yyfirstVal
));
1888 fprintf (stderr
, "Option. rule: %d, state: %ld, next: %ld",
1889 yyp
->yyoption
.yyrule
,
1890 (long) YYINDEX (yyp
->yyoption
.yystate
),
1891 (long) YYINDEX (yyp
->yyoption
.yynext
));
1893 fprintf (stderr
, "\n");
1895 fprintf (stderr
, "Tops:");
1896 for (yyi
= 0; yyi
< yystack
->yytops
.yysize
; yyi
+= 1)
1897 fprintf (stderr
, "%lu: %ld; ", (unsigned long) yyi
,
1898 (long) YYINDEX (yystack
->yytops
.yystates
[yyi
]));
1899 fprintf (stderr
, "\n");
1904 m4_if(b4_defines_flag
, 0, [],
1905 [@output @output_header_name@
1906 b4_copyright([Skeleton parser
for GLR parsing with Bison
], [2002])
1908 b4_token_defines(b4_tokens
)
1911 m4_ifdef([b4_stype
],
1912 [b4_syncline([b4_stype_line
], [b4_filename
])
1913 typedef union b4_stype yystype
;
1914 /* Line __line__ of __file__. */
1915 b4_syncline([@oline@
], [@ofile@
])],
1916 [typedef int yystype
;])
1917 # define YYSTYPE yystype
1918 # define YYSTYPE_IS_TRIVIAL 1
1922 [extern YYSTYPE b4_prefix
[]lval
;])
1926 typedef struct yyltype
1933 # define YYLTYPE yyltype
1937 [extern YYLTYPE b4_prefix
[]lloc
;])