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_pure_args
],
61 [b4_pure_if([b4_location_if([, yylocp
])])[]b4_user_args
])
66 # Arguments passed to yyerror: user formals plus yyllocp.
67 m4_define([b4_pure_formals
],
68 [b4_pure_if([b4_location_if([, YYLTYPE
*yylocp
])])[]b4_user_formals
])
73 # Same as above, but on the lookahead, hence yyllocp instead of yylocp.
74 m4_define([b4_lpure_args
],
75 [b4_pure_if([b4_location_if([, yyllocp
])])[]b4_user_args
])
80 # Same as above, but on the lookahead, hence yyllocp instead of yylocp.
81 m4_define([b4_lpure_formals
],
82 [b4_pure_if([b4_location_if([YYLTYPE
*yyllocp
])])[]b4_user_formals
])
85 ## ----------------- ##
86 ## Semantic Values. ##
87 ## ----------------- ##
90 # b4_lhs_value([TYPE])
91 # --------------------
92 # Expansion of $<TYPE>$.
93 m4_define([b4_lhs_value
],
94 [(*yyvalp
)[]m4_ifval([$
1], [.$
1])])
97 # b4_rhs_value(RULE-LENGTH, NUM, [TYPE])
98 # --------------------------------------
99 # Expansion of $<TYPE>NUM, where the current rule has RULE-LENGTH
101 m4_define([b4_rhs_value
],
102 [yyvsp@
<:@
m4_eval([$
2 - $
1])@
:>@
.yystate
.yysemantics
.yysval
[]m4_ifval([$
3], [.$
3])])
113 m4_define([b4_lhs_location
],
117 # b4_rhs_location(RULE-LENGTH, NUM)
118 # ---------------------------------
119 # Expansion of @NUM, where the current rule has RULE-LENGTH symbols
121 m4_define([b4_rhs_location
],
122 [yyvsp@
<:@
m4_eval([$
2 - $
1])@
:>@
.yystate
.yyloc
])
126 ## ------------------- ##
127 ## Output file names. ##
128 ## ------------------- ##
130 m4_define_default([b4_input_suffix
], [.y
])
132 m4_define_default([b4_output_parser_suffix
],
133 [m4_translit(b4_input_suffix
, [yY
], [cC
])])
135 m4_define_default([b4_output_parser_name
],
136 [b4_output_prefix
[]b4_output_infix
[]b4_output_parser_suffix
[]])
139 m4_define_default([b4_output_header_suffix
],
140 [m4_translit(b4_input_suffix
, [yY
], [hH
])])
142 m4_define_default([b4_output_header_name
],
143 [b4_output_prefix
[]b4_output_infix
[]b4_output_header_suffix
[]])
145 m4_define_default([b4_header_guard
],
146 [m4_bpatsubst(m4_toupper([BISON_
]b4_output_header_name
),
147 [[^ABCDEFGHIJKLMNOPQRSTUVWXYZ
]], [_
])])
150 # We do want M4 expansion after # for CPP macros.
153 #output "b4_output_parser_name"
154 b4_copyright([Skeleton parser
for GLR parsing with Bison
], [2002])
156 /* This is the parser code for GLR (Generalized LR) parser. */
166 m4_if(b4_prefix
[], [yy
], [],
167 [/* If NAME_PREFIX is specified substitute the variables and functions
169 #define yyparse b4_prefix[]parse
170 #define yylex b4_prefix[]lex
171 #define yyerror b4_prefix[]error
172 #define yylval b4_prefix[]lval
173 #define yychar b4_prefix[]char
174 #define yydebug b4_prefix[]debug
175 #define yynerrs b4_prefix[]nerrs
176 b4_location_if([#define yylloc b4_prefix[]lloc])])
178 b4_token_defines(b4_tokens
)
180 /* Copy the first part of user declarations. */
183 /* Enabling traces. */
185 # define YYDEBUG ]b4_debug[
188 /* Enabling verbose error messages. */
189 #ifdef YYERROR_VERBOSE
190 # undef YYERROR_VERBOSE
191 # define YYERROR_VERBOSE 1
193 # define YYERROR_VERBOSE ]b4_error_verbose[
197 ]m4_ifdef([b4_stype
],
198 [b4_syncline([b4_stype_line
], [b4_filename
])
199 typedef union b4_stype yystype
;
200 /* Line __line__ of __file__. */
201 b4_syncline([__oline__
], [__ofile__
])],
202 [typedef int yystype
;])[
203 # define YYSTYPE yystype
204 # define YYSTYPE_IS_TRIVIAL 1
208 typedef struct yyltype
215 # define YYLTYPE ]b4_location_type[
216 # define YYLTYPE_IS_TRIVIAL 1
219 /* Default (constant) values used for initialization for null
220 right-hand sides. Unlike the standard bison.simple template,
221 here we set the default values of the $$ and $@ to zeroed-out
222 values. Since the default value of these quantities is undefined,
223 this behavior is technically correct. */
224 static YYSTYPE yyval_default
;
225 static YYLTYPE yyloc_default
;
227 /* Copy the second part of user declarations. */
230 ]/* Line __line__ of __file__. */
231 b4_syncline([__oline__
], [__ofile__
])
233 #if ! defined (__cplusplus)
243 #ifndef __attribute__
244 /* This feature is available in gcc versions 2.5 and later. */
245 # if !defined (__GNUC__) || __GNUC__ < 2 || \
246 (__GNUC__ == 2 && __GNUC_MINOR__ < 5) || __STRICT_ANSI__
247 # define __attribute__(Spec) /* empty */
251 #ifndef ATTRIBUTE_UNUSED
252 # define ATTRIBUTE_UNUSED __attribute__ ((__unused__))
255 #if ! defined (__GNUC__)
259 /* YYFINAL -- State number of the termination state. */
260 #define YYFINAL ]b4_final_state_number[
261 /* YYLAST -- Last index in YYTABLE. */
262 #define YYLAST ]b4_last[
264 /* YYNTOKENS -- Number of terminals. */
265 #define YYNTOKENS ]b4_tokens_number[
266 /* YYNNTS -- Number of nonterminals. */
267 #define YYNNTS ]b4_nterms_number[
268 /* YYNRULES -- Number of rules. */
269 #define YYNRULES ]b4_rules_number[
270 /* YYNRULES -- Number of states. */
271 #define YYNSTATES ]b4_states_number[
272 /* YYMAXRHS -- Maximum number of symbols on right-hand side of rule. */
273 #define YYMAXRHS ]b4_r2_max[
275 /* YYTRANSLATE(X) -- Bison symbol number corresponding to X. */
276 #define YYUNDEFTOK ]b4_undef_token_number[
277 #define YYMAXUTOK ]b4_user_token_number_max[
279 #define YYTRANSLATE(YYX) \
280 ((unsigned)(YYX) <= YYMAXUTOK ? yytranslate[YYX] : YYUNDEFTOK)
282 /* YYTRANSLATE[YYLEX] -- Bison symbol number corresponding to YYLEX. */
283 static const ]b4_int_type_for([b4_translate
])[ yytranslate
[] =
289 /* YYPRHS[YYN] -- Index of the first RHS symbol of rule number YYN in
291 static const ]b4_int_type_for([b4_prhs
])[ yyprhs
[] =
296 /* YYRHS -- A `-1'-separated list of the rules' RHS. */
297 static const ]b4_int_type_for([b4_rhs
])[ yyrhs
[] =
302 /* YYRLINE[YYN] -- source line where rule number YYN was defined. */
303 static const ]b4_int_type_for([b4_rline
])[ yyrline
[] =
309 #if (YYDEBUG) || YYERROR_VERBOSE
310 /* YYTNME[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM.
311 First, the terminals, then, starting at YYNTOKENS, nonterminals. */
312 static const char *const yytname
[] =
317 #define yytname_size ((int) (sizeof (yytname) / sizeof (yytname[0])))
320 /* YYR1[YYN] -- Symbol number of symbol that rule YYN derives. */
321 static const ]b4_int_type_for([b4_r1
])[ yyr1
[] =
326 /* YYR2[YYN] -- Number of symbols composing right hand side of rule YYN. */
327 static const ]b4_int_type_for([b4_r2
])[ yyr2
[] =
332 /* YYDPREC[RULE-NUM] -- Dynamic precedence of rule #RULE-NUM (0 if none). */
333 static const ]b4_int_type_for([b4_dprec
])[ yydprec
[] =
338 /* YYMERGER[RULE-NUM] -- Index of merging function for rule #RULE-NUM. */
339 static const ]b4_int_type_for([b4_merger
])[ yymerger
[] =
344 /* YYDEFACT[S] -- default rule to reduce with in state S when YYTABLE
345 doesn't specify something else to do. Zero means the default is an
347 static const ]b4_int_type_for([b4_defact
])[ yydefact
[] =
352 /* YYPDEFGOTO[NTERM-NUM]. */
353 static const ]b4_int_type_for([b4_defgoto
])[ yydefgoto
[] =
358 /* YYPACT[STATE-NUM] -- Index in YYTABLE of the portion describing
360 #define YYPACT_NINF ]b4_pact_ninf[
361 static const ]b4_int_type_for([b4_pact
])[ yypact
[] =
366 /* YYPGOTO[NTERM-NUM]. */
367 static const ]b4_int_type_for([b4_pgoto
])[ yypgoto
[] =
372 /* YYTABLE[YYPACT[STATE-NUM]]. What to do in state STATE-NUM. If
373 positive, shift that token. If negative, reduce the rule which
374 number is the opposite. If zero, do what YYDEFACT says.
375 If YYTABLE_NINF, parse error. */
376 #define YYTABLE_NINF ]b4_table_ninf[
377 static const ]b4_int_type_for([b4_table
])[ yytable
[] =
382 /* YYCONFLP[YYPACT[STATE-NUM]] -- Pointer into YYCONFL of start of
383 list of conflicting reductions corresponding to action entry for
384 state STATE-NUM in yytable. 0 means no conflicts. The list in
385 yyconfl is terminated by a rule number of 0. */
386 static const ]b4_int_type_for([b4_conflict_list_heads
])[ yyconflp
[] =
388 ]b4_conflict_list_heads
[
391 /* YYCONFL[I] -- lists of conflicting rule numbers, each terminated by
392 0, pointed into by YYCONFLP. */
393 ]dnl Do
not use b4_int_type_for here
, since there are places where
394 dnl pointers onto yyconfl are taken
, which type is
"short *".
395 dnl We probably ought to introduce a type
for confl
.
396 [static const short yyconfl
[] =
398 ]b4_conflicting_rules
[
401 static const ]b4_int_type_for([b4_check
])[ yycheck
[] =
407 /* Prevent warning if -Wmissing-prototypes. */
408 ]b4_c_ansi_function_decl([yyparse
], [int], b4_parse_param
)[
410 /* Error token number */
413 /* YYLLOC_DEFAULT -- Compute the default location (before the actions
416 #define YYRHSLOC(yyRhs,YYK) (yyRhs[YYK].yystate.yyloc)
418 #ifndef YYLLOC_DEFAULT
419 # define YYLLOC_DEFAULT(yyCurrent, yyRhs, YYN) \
420 yyCurrent.first_line = YYRHSLOC(yyRhs,1).first_line; \
421 yyCurrent.first_column = YYRHSLOC(yyRhs,1).first_column; \
422 yyCurrent.last_line = YYRHSLOC(yyRhs,YYN).last_line; \
423 yyCurrent.last_column = YYRHSLOC(yyRhs,YYN).last_column;
426 /* YYLEX -- calling `yylex' with the right arguments. */
427 #define YYLEX ]b4_c_function_call([yylex], [int], b4_lex_param)[
432 #define yynerrs (yystack->yyerrcnt)
434 #define yychar (yystack->yyrawchar)],
442 static const int YYEOF
= 0;
443 static const int YYEMPTY
= -2;
445 typedef enum { yyok
, yyaccept
, yyabort
, yyerr
} YYRESULTTAG
;
448 do { YYRESULTTAG yyflag = YYE; if (yyflag != yyok) return yyflag; } \
453 #if ! defined (YYFPRINTF)
454 # define YYFPRINTF fprintf
457 # define YYDPRINTF(Args) \
462 /* Nonzero means print parse trace. It is left uninitialized so that
463 multiple parsers can coexist. */
466 /* Avoid empty `if' bodies. */
467 # define YYDPRINTF(Args) {}
468 #endif /* !YYDEBUG */
470 /* YYINITDEPTH -- initial size of the parser's stacks. */
472 # define YYINITDEPTH ]b4_stack_depth_init[
475 /* YYMAXDEPTH -- maximum size the stacks can grow to (effective only
476 if the built-in stack extension method is used).
478 Do not make this value too large; the results are undefined if
479 SIZE_MAX < YYMAXDEPTH * sizeof (GLRStackItem)
480 evaluated with infinite-precision integer arithmetic. */
487 # define YYMAXDEPTH ]b4_stack_depth_max[
490 /* Minimum number of free items on the stack allowed after an
491 allocation. This is to allow allocation and initialization
492 to be completed by functions that call expandGLRStack before the
493 stack is expanded, thus insuring that all necessary pointers get
494 properly redirected to new data. */
497 #if ! defined (YYSTACKEXPANDABLE) \
498 && (! defined (__cplusplus) || (YYLTYPE_IS_TRIVIAL && YYSTYPE_IS_TRIVIAL))
499 #define YYSTACKEXPANDABLE 1
501 #define YYSTACKEXPANDABLE 0
504 /** State numbers, as in LALR(1) machine */
505 typedef int yyStateNum
;
507 /** Rule numbers, as in LALR(1) machine */
508 typedef int yyRuleNum
;
510 /** Grammar symbol */
511 typedef short yySymbol
;
513 /** Item references, as in LALR(1) machine */
514 typedef short yyItemNum
;
516 typedef struct yyGLRState yyGLRState
;
517 typedef struct yySemanticOption yySemanticOption
;
518 typedef union yyGLRStackItem yyGLRStackItem
;
519 typedef struct yyGLRStack yyGLRStack
;
520 typedef struct yyGLRStateSet yyGLRStateSet
;
525 yyStateNum yylrState
;
529 yySemanticOption
* yyfirstVal
;
535 struct yyGLRStateSet
{
536 yyGLRState
** yystates
;
537 size_t yysize
, yycapacity
;
540 struct yySemanticOption
{
544 yySemanticOption
* yynext
;
547 union yyGLRStackItem
{
549 yySemanticOption yyoption
;
561 jmp_buf yyexception_buffer
;
562 yyGLRStackItem
* yyitems
;
563 yyGLRStackItem
* yynextFree
;
565 yyGLRState
* yysplitPoint
;
566 yyGLRState
* yylastDeleted
;
567 yyGLRStateSet yytops
;
570 static void yyinitGLRStack (yyGLRStack
* yystack
, size_t yysize
);
571 static void yyexpandGLRStack (yyGLRStack
* yystack
]b4_pure_formals
[);
572 static void yyfreeGLRStack (yyGLRStack
* yystack
);
575 yyFail (yyGLRStack
* yystack
]b4_pure_formals
[, const char* yyformat
, ...)
577 if (yyformat
!= NULL
)
581 va_start (yyap
, yyformat
);
582 yystack
->yyerrflag
= 1;
583 vsprintf (yymsg
, yyformat
, yyap
);
584 yyerror (yymsg
]b4_pure_args
[);
586 longjmp (yystack
->yyexception_buffer
, 1);
589 #if YYDEBUG || YYERROR_VERBOSE
590 /** A printable representation of TOKEN. Valid until next call to
592 static inline const char*
593 yytokenName (yySymbol yytoken
)
595 return yytname
[yytoken
];
599 /** Perform user action for rule number YYN, with RHS length YYRHSLEN,
600 * and top stack item YYVSP. YYLVALP points to place to put semantic
601 * value ($$), and yylocp points to place for location information
602 * (@$). Returns yyok for normal return, yyaccept for YYACCEPT,
603 * yyerr for YYERROR, yyabort for YYABORT. */
605 yyuserAction (yyRuleNum yyn
, int yyrhslen
, yyGLRStackItem
* yyvsp
,
606 YYSTYPE
* yyvalp
, YYLTYPE
* yylocp
, yyGLRStack
* yystack
609 /* Avoid `unused' warnings in there are no $n. */
614 *yyvalp
= yyval_default
;
615 *yylocp
= yyloc_default
;
619 *yyvalp
= yyvsp
[1-yyrhslen
].yystate
.yysemantics
.yysval
;
620 *yylocp
= yyvsp
[1-yyrhslen
].yystate
.yyloc
;
623 # define yyval (*yyvalp)
625 # define yyerrok (yystack->yyerrState = 0)
627 # define YYACCEPT return yyaccept
629 # define YYABORT return yyabort
631 # define YYERROR return yyerr
633 # define YYRECOVERING (yystack->yyerrState != 0)
635 # define yyclearin (yychar = *(yystack->yytokenp) = YYEMPTY)
637 # define YYBACKUP(Token, Value) \
639 yyerror ("syntax error: cannot back up"]b4_pure_args[); \
658 /* Line __line__ of __file__. */
659 b4_syncline([__oline__
], [__ofile__
])
664 yyuserMerge (int yyn
, YYSTYPE
* yy0
, YYSTYPE
* yy1
)
666 YYSTYPE yyval
= *yy0
;
667 /* `Use' the arguments. */
678 /* Bison grammar-table manipulation. */
680 /** Number of symbols composing the right hand side of rule #RULE. */
682 yyrhsLength (yyRuleNum yyrule
)
687 /** Left-hand-side symbol for rule #RULE. */
688 static inline yySymbol
689 yylhsNonterm (yyRuleNum yyrule
)
694 /** True iff LR state STATE has only a default reduction (regardless
697 yyisDefaultedState (yyStateNum yystate
)
699 return yypact
[yystate
] == YYPACT_NINF
;
702 /** The default reduction for STATE, assuming it has one. */
703 static inline yyRuleNum
704 yydefaultAction (yyStateNum yystate
)
706 return yydefact
[yystate
];
709 /** Set *YYACTION to the action to take in YYSTATE on seeing YYTOKEN.
711 * R < 0: Reduce on rule -R.
713 * R > 0: Shift to state R.
714 * Set *CONFLICTS to a pointer into yyconfl to 0-terminated list of
715 * conflicting reductions.
718 yygetLRActions (yyStateNum yystate
, int yytoken
,
719 int* yyaction
, const short** yyconflicts
)
721 int yyindex
= yypact
[yystate
] + yytoken
;
722 if (yyindex
< 0 || YYLAST
< yyindex
|| yycheck
[yyindex
] != yytoken
)
724 *yyaction
= -yydefact
[yystate
];
725 *yyconflicts
= yyconfl
;
727 else if (yytable
[yyindex
] != YYTABLE_NINF
)
729 *yyaction
= yytable
[yyindex
];
730 *yyconflicts
= yyconfl
+ yyconflp
[yyindex
];
735 *yyconflicts
= yyconfl
+ yyconflp
[yyindex
];
739 static inline yyStateNum
740 yyLRgotoState (yyStateNum yystate
, yySymbol yylhs
)
743 yyr
= yypgoto
[yylhs
- YYNTOKENS
] + yystate
;
744 if (0 <= yyr
&& yyr
<= YYLAST
&& yycheck
[yyr
] == yystate
)
747 return yydefgoto
[yylhs
- YYNTOKENS
];
751 yyisShiftAction (int yyaction
)
757 yyisErrorAction (int yyaction
)
759 return yyaction
== 0;
764 /** True iff the semantic value of the edge leading to STATE is
767 yyhasResolvedValue (yyGLRState
* yystate
)
769 return yystate
->yyresolved
;
773 yyaddDeferredAction (yyGLRStack
* yystack
, yyGLRState
* yystate
,
774 yyGLRState
* rhs
, yyRuleNum yyrule
]b4_pure_formals
[)
776 yySemanticOption
* yynewItem
;
777 yynewItem
= &yystack
->yynextFree
->yyoption
;
778 yystack
->yyspaceLeft
-= 1;
779 yystack
->yynextFree
+= 1;
780 yynewItem
->yyisState
= yyfalse
;
781 yynewItem
->yystate
= rhs
;
782 yynewItem
->yyrule
= yyrule
;
783 yynewItem
->yynext
= yystate
->yysemantics
.yyfirstVal
;
784 yystate
->yysemantics
.yyfirstVal
= yynewItem
;
785 if (yystack
->yyspaceLeft
< YYHEADROOM
)
786 yyexpandGLRStack (yystack
]b4_pure_args
[);
791 /** Initialize SET to a singleton set containing an empty stack. */
793 yyinitStateSet (yyGLRStateSet
* yyset
)
796 yyset
->yycapacity
= 16;
797 yyset
->yystates
= (yyGLRState
**) malloc (16 * sizeof (yyset
->yystates
[0]));
798 yyset
->yystates
[0] = NULL
;
801 static void yyfreeStateSet (yyGLRStateSet
* yyset
)
803 free (yyset
->yystates
);
806 /** Initialize STACK to a single empty stack, with total maximum
807 * capacity for all stacks of SIZE. */
809 yyinitGLRStack (yyGLRStack
* yystack
, size_t yysize
)
811 yystack
->yyerrflag
= 0;
812 yystack
->yyerrState
= 0;
814 yystack
->yyspaceLeft
= yysize
;
815 yystack
->yynextFree
= yystack
->yyitems
=
816 (yyGLRStackItem
*) malloc (yysize
* sizeof (yystack
->yynextFree
[0]));
817 yystack
->yysplitPoint
= NULL
;
818 yystack
->yylastDeleted
= NULL
;
819 yyinitStateSet (&yystack
->yytops
);
822 #define YYRELOC(YYFROMITEMS,YYTOITEMS,YYX,YYTYPE) \
823 &((YYTOITEMS) - ((YYFROMITEMS) - (yyGLRStackItem*) (YYX)))->YYTYPE
825 /** If STACK is expandable, extend it. WARNING: Pointers into the
826 stack from outside should be considered invalid after this call.
827 We always expand when there are 1 or fewer items left AFTER an
828 allocation, so that we can avoid having external pointers exist
829 across an allocation. */
831 yyexpandGLRStack (yyGLRStack
* yystack
]b4_pure_formals
[)
833 #if YYSTACKEXPANDABLE
834 yyGLRStack yynewStack
;
835 yyGLRStackItem
* yyp0
, *yyp1
;
836 size_t yysize
, yynewSize
;
838 yysize
= yystack
->yynextFree
- yystack
->yyitems
;
839 if (YYMAXDEPTH
<= yysize
)
840 yyFail (yystack
][]b4_pure_args
[,
841 "parsing stack overflow (%d items)", yysize
);
842 yynewSize
= 2*yysize
;
843 if (YYMAXDEPTH
< yynewSize
)
844 yynewSize
= YYMAXDEPTH
;
845 yyinitGLRStack (&yynewStack
, yynewSize
);
846 for (yyp0
= yystack
->yyitems
, yyp1
= yynewStack
.yyitems
, yyn
= yysize
;
848 yyn
-= 1, yyp0
+= 1, yyp1
+= 1)
853 yyGLRState
* yys0
= &yyp0
->yystate
;
854 yyGLRState
* yys1
= &yyp1
->yystate
;
855 if (yys0
->yypred
!= NULL
)
857 YYRELOC (yyp0
, yyp1
, yys0
->yypred
, yystate
);
858 if (! yys0
->yyresolved
&& yys0
->yysemantics
.yyfirstVal
!= NULL
)
859 yys1
->yysemantics
.yyfirstVal
=
860 YYRELOC(yyp0
, yyp1
, yys0
->yysemantics
.yyfirstVal
, yyoption
);
864 yySemanticOption
* yyv0
= &yyp0
->yyoption
;
865 yySemanticOption
* yyv1
= &yyp1
->yyoption
;
866 if (yyv0
->yystate
!= NULL
)
867 yyv1
->yystate
= YYRELOC (yyp0
, yyp1
, yyv0
->yystate
, yystate
);
868 if (yyv0
->yynext
!= NULL
)
869 yyv1
->yynext
= YYRELOC (yyp0
, yyp1
, yyv0
->yynext
, yyoption
);
872 if (yystack
->yysplitPoint
!= NULL
)
873 yystack
->yysplitPoint
= YYRELOC (yystack
->yyitems
, yynewStack
.yyitems
,
874 yystack
->yysplitPoint
, yystate
);
876 for (yyn
= 0; yyn
< yystack
->yytops
.yysize
; yyn
+= 1)
877 if (yystack
->yytops
.yystates
[yyn
] != NULL
)
878 yystack
->yytops
.yystates
[yyn
] =
879 YYRELOC (yystack
->yyitems
, yynewStack
.yyitems
,
880 yystack
->yytops
.yystates
[yyn
], yystate
);
881 free (yystack
->yyitems
);
882 yystack
->yyitems
= yynewStack
.yyitems
;
883 yystack
->yynextFree
= yynewStack
.yynextFree
+ yysize
;
884 yystack
->yyspaceLeft
= yynewStack
.yyspaceLeft
- yysize
;
888 yyFail (yystack
][]b4_lpure_args
[,
889 "parsing stack overflow (%d items)", yysize
);
894 yyfreeGLRStack (yyGLRStack
* yystack
)
896 free (yystack
->yyitems
);
897 yyfreeStateSet (&yystack
->yytops
);
900 /** Assuming that S is a GLRState somewhere on STACK, update the
901 * splitpoint of STACK, if needed, so that it is at least as deep as
904 yyupdateSplit (yyGLRStack
* yystack
, yyGLRState
* yys
)
906 if (yystack
->yysplitPoint
!= NULL
&& yystack
->yysplitPoint
> yys
)
907 yystack
->yysplitPoint
= yys
;
910 /** Invalidate stack #K in STACK. */
912 yymarkStackDeleted (yyGLRStack
* yystack
, int yyk
)
914 if (yystack
->yytops
.yystates
[yyk
] != NULL
)
915 yystack
->yylastDeleted
= yystack
->yytops
.yystates
[yyk
];
916 yystack
->yytops
.yystates
[yyk
] = NULL
;
919 /** Undelete the last stack that was marked as deleted. Can only be
920 done once after a deletion, and only when all other stacks have
923 yyundeleteLastStack (yyGLRStack
* yystack
)
925 if (yystack
->yylastDeleted
== NULL
|| yystack
->yytops
.yysize
!= 0)
927 yystack
->yytops
.yystates
[0] = yystack
->yylastDeleted
;
928 yystack
->yytops
.yysize
= 1;
929 YYDPRINTF ((stderr
, "Restoring last deleted stack as stack #0.\n"));
930 yystack
->yylastDeleted
= NULL
;
934 yyremoveDeletes (yyGLRStack
* yystack
)
938 while (yyj
< yystack
->yytops
.yysize
)
940 if (yystack
->yytops
.yystates
[yyi
] == NULL
)
943 YYDPRINTF ((stderr
, "Removing dead stacks.\n"));
944 yystack
->yytops
.yysize
-= 1;
948 yystack
->yytops
.yystates
[yyj
] = yystack
->yytops
.yystates
[yyi
];
950 YYDPRINTF ((stderr
, "Rename stack %d -> %d.\n", yyi
, yyj
));
957 /** Shift to a new state on stack #K of STACK, corresponding to LR state
958 * LRSTATE, at input position POSN, with (resolved) semantic value SVAL. */
960 yyglrShift (yyGLRStack
* yystack
, int yyk
, yyStateNum yylrState
, size_t yyposn
,
961 YYSTYPE yysval
, YYLTYPE
* yylocp
]b4_user_formals
[)
963 yyGLRStackItem
* yynewItem
;
965 yynewItem
= yystack
->yynextFree
;
966 yystack
->yynextFree
+= 1;
967 yystack
->yyspaceLeft
-= 1;
968 yynewItem
->yystate
.yyisState
= yytrue
;
969 yynewItem
->yystate
.yylrState
= yylrState
;
970 yynewItem
->yystate
.yyposn
= yyposn
;
971 yynewItem
->yystate
.yyresolved
= yytrue
;
972 yynewItem
->yystate
.yypred
= yystack
->yytops
.yystates
[yyk
];
973 yystack
->yytops
.yystates
[yyk
] = &yynewItem
->yystate
;
974 yynewItem
->yystate
.yysemantics
.yysval
= yysval
;
975 yynewItem
->yystate
.yyloc
= *yylocp
;
976 if (yystack
->yyspaceLeft
< YYHEADROOM
)
977 yyexpandGLRStack (yystack
]b4_pure_args
[);
980 /** Shift to a new state on stack #K of STACK, to a new state
981 * corresponding to LR state LRSTATE, at input position POSN, with
982 * the (unresolved) semantic value of RHS under the action for RULE. */
984 yyglrShiftDefer (yyGLRStack
* yystack
, int yyk
, yyStateNum yylrState
,
985 size_t yyposn
, yyGLRState
* rhs
, yyRuleNum yyrule
]b4_pure_formals
[)
987 yyGLRStackItem
* yynewItem
;
989 yynewItem
= yystack
->yynextFree
;
990 yynewItem
->yystate
.yyisState
= yytrue
;
991 yynewItem
->yystate
.yylrState
= yylrState
;
992 yynewItem
->yystate
.yyposn
= yyposn
;
993 yynewItem
->yystate
.yyresolved
= yyfalse
;
994 yynewItem
->yystate
.yypred
= yystack
->yytops
.yystates
[yyk
];
995 yynewItem
->yystate
.yysemantics
.yyfirstVal
= NULL
;
996 yystack
->yytops
.yystates
[yyk
] = &yynewItem
->yystate
;
997 yystack
->yynextFree
+= 1;
998 yystack
->yyspaceLeft
-= 1;
999 yyaddDeferredAction (yystack
, &yynewItem
->yystate
, rhs
, yyrule
]b4_pure_args
[);
1002 /** Pop the symbols consumed by reduction #RULE from the top of stack
1003 * #K of STACK, and perform the appropriate semantic action on their
1004 * semantic values. Assumes that all ambiguities in semantic values
1005 * have been previously resolved. Set *VALP to the resulting value,
1006 * and *LOCP to the computed location (if any). Return value is as
1007 * for userAction. */
1009 yydoAction (yyGLRStack
* yystack
, int yyk
, yyRuleNum yyrule
,
1010 YYSTYPE
* yyvalp
, YYLTYPE
* yylocp
]b4_user_formals
[)
1012 int yynrhs
= yyrhsLength (yyrule
);
1014 if (yystack
->yysplitPoint
== NULL
)
1016 /* Standard special case: single stack. */
1017 yyGLRStackItem
* rhs
= (yyGLRStackItem
*) yystack
->yytops
.yystates
[yyk
];
1019 yystack
->yynextFree
-= yynrhs
;
1020 yystack
->yyspaceLeft
+= yynrhs
;
1021 yystack
->yytops
.yystates
[0] = & yystack
->yynextFree
[-1].yystate
;
1024 *yyvalp
= yyval_default
;
1025 *yylocp
= yyloc_default
;
1029 *yyvalp
= rhs
[1-yynrhs
].yystate
.yysemantics
.yysval
;
1030 *yylocp
= rhs
[1-yynrhs
].yystate
.yyloc
;
1032 return yyuserAction (yyrule
, yynrhs
, rhs
,
1033 yyvalp
, yylocp
, yystack
]b4_user_args
[);
1039 yyGLRStackItem yyrhsVals
[YYMAXRHS
];
1040 for (yyi
= yynrhs
-1, yys
= yystack
->yytops
.yystates
[yyk
]; 0 <= yyi
;
1041 yyi
-= 1, yys
= yys
->yypred
)
1043 assert (yys
->yypred
!= NULL
);
1044 yyrhsVals
[yyi
].yystate
.yyresolved
= yytrue
;
1045 yyrhsVals
[yyi
].yystate
.yysemantics
.yysval
= yys
->yysemantics
.yysval
;
1046 yyrhsVals
[yyi
].yystate
.yyloc
= yys
->yyloc
;
1048 yyupdateSplit (yystack
, yys
);
1049 yystack
->yytops
.yystates
[yyk
] = yys
;
1052 *yyvalp
= yyval_default
;
1053 *yylocp
= yyloc_default
;
1057 *yyvalp
= yyrhsVals
[0].yystate
.yysemantics
.yysval
;
1058 *yylocp
= yyrhsVals
[0].yystate
.yyloc
;
1060 return yyuserAction (yyrule
, yynrhs
, yyrhsVals
+ (yynrhs
-1),
1061 yyvalp
, yylocp
, yystack
]b4_user_args
[);
1066 # define YY_REDUCE_PRINT(K, Rule)
1068 # define YY_REDUCE_PRINT(K, Rule) \
1071 yy_reduce_print (K, Rule); \
1074 /*----------------------------------------------------------.
1075 | Report that the RULE is going to be reduced on stack #K. |
1076 `----------------------------------------------------------*/
1079 yy_reduce_print (size_t yyk
, yyRuleNum yyrule
)
1082 YYDPRINTF ((stderr
, "Reducing stack %d by rule %d (line %d),",
1083 yyk
, yyrule
- 1, yyrline
[yyrule
]));
1084 /* Print the symbols being reduced, and their result. */
1085 for (yyi
= yyprhs
[yyrule
]; 0 <= yyrhs
[yyi
]; yyi
++)
1086 YYFPRINTF (stderr
, "%s ", yytokenName (yyrhs
[yyi
]));
1087 YYFPRINTF (stderr
, " -> %s\n", yytokenName (yyr1
[yyrule
]));
1091 /** Pop items off stack #K of STACK according to grammar rule RULE,
1092 * and push back on the resulting nonterminal symbol. Perform the
1093 * semantic action associated with RULE and store its value with the
1094 * newly pushed state, if FORCEEVAL or if STACK is currently
1095 * unambiguous. Otherwise, store the deferred semantic action with
1096 * the new state. If the new state would have an identical input
1097 * position, LR state, and predecessor to an existing state on the stack,
1098 * it is identified with that existing state, eliminating stack #K from
1099 * the STACK. In this case, the (necessarily deferred) semantic value is
1100 * added to the options for the existing state's semantic value.
1102 static inline YYRESULTTAG
1103 yyglrReduce (yyGLRStack
* yystack
, size_t yyk
, yyRuleNum yyrule
,
1104 bool yyforceEval
]b4_pure_formals
[)
1106 size_t yyposn
= yystack
->yytops
.yystates
[yyk
]->yyposn
;
1108 if (yyforceEval
|| yystack
->yysplitPoint
== NULL
)
1113 YY_REDUCE_PRINT (yyk
, yyrule
);
1114 YYCHK (yydoAction (yystack
, yyk
, yyrule
, &yysval
, &yyloc
]b4_user_args
[));
1115 yyglrShift (yystack
, yyk
,
1116 yyLRgotoState (yystack
->yytops
.yystates
[yyk
]->yylrState
,
1117 yylhsNonterm (yyrule
)),
1118 yyposn
, yysval
, &yyloc
]b4_user_args
[);
1119 YYDPRINTF ((stderr
, "Stack %d entering state %d\n",
1120 yyk
, yystack
->yytops
.yystates
[yyk
]->yylrState
));
1126 yyGLRState
* yys
, *yys0
= yystack
->yytops
.yystates
[yyk
];
1127 yyStateNum yynewLRState
;
1129 for (yys
= yystack
->yytops
.yystates
[yyk
], yyn
= yyrhsLength (yyrule
);
1133 assert (yys
!= NULL
);
1135 yyupdateSplit (yystack
, yys
);
1136 yynewLRState
= yyLRgotoState (yys
->yylrState
, yylhsNonterm (yyrule
));
1138 "Reduced stack %d by rule #%d; action deferred. "
1139 "Now in state %d.\n",
1140 yyk
, yyrule
-1, yynewLRState
));
1141 for (yyi
= 0; yyi
< yystack
->yytops
.yysize
; yyi
+= 1)
1142 if (yyi
!= yyk
&& yystack
->yytops
.yystates
[yyi
] != NULL
)
1144 yyGLRState
* yyp
, *yysplit
= yystack
->yysplitPoint
;
1145 yyp
= yystack
->yytops
.yystates
[yyi
];
1146 while (yyp
!= yys
&& yyp
!= yysplit
&& yyp
->yyposn
>= yyposn
)
1148 if (yyp
->yylrState
== yynewLRState
&& yyp
->yypred
== yys
)
1150 yyaddDeferredAction (yystack
, yyp
, yys0
, yyrule
]b4_pure_args
[);
1151 yymarkStackDeleted (yystack
, yyk
);
1152 YYDPRINTF ((stderr
, "Merging stack %d into stack %d.\n",
1159 yystack
->yytops
.yystates
[yyk
] = yys
;
1160 yyglrShiftDefer (yystack
, yyk
, yynewLRState
, yyposn
, yys0
, yyrule
]b4_pure_args
[);
1166 yysplitStack (yyGLRStack
* yystack
, int yyk
)
1168 if (yystack
->yysplitPoint
== NULL
)
1171 yystack
->yysplitPoint
= yystack
->yytops
.yystates
[yyk
];
1173 if (yystack
->yytops
.yysize
>= yystack
->yytops
.yycapacity
)
1175 yystack
->yytops
.yycapacity
*= 2;
1176 yystack
->yytops
.yystates
=
1177 (yyGLRState
**) realloc (yystack
->yytops
.yystates
,
1178 yystack
->yytops
.yycapacity
1179 * sizeof (yyGLRState
*));
1181 yystack
->yytops
.yystates
[yystack
->yytops
.yysize
]
1182 = yystack
->yytops
.yystates
[yyk
];
1183 yystack
->yytops
.yysize
+= 1;
1184 return yystack
->yytops
.yysize
-1;
1187 /** True iff Y0 and Y1 represent identical options at the top level.
1188 * That is, they represent the same rule applied to RHS symbols
1189 * that produce the same terminal symbols. */
1191 yyidenticalOptions (yySemanticOption
* yyy0
, yySemanticOption
* yyy1
)
1193 if (yyy0
->yyrule
== yyy1
->yyrule
)
1195 yyGLRState
*yys0
, *yys1
;
1197 for (yys0
= yyy0
->yystate
, yys1
= yyy1
->yystate
,
1198 yyn
= yyrhsLength (yyy0
->yyrule
);
1200 yys0
= yys0
->yypred
, yys1
= yys1
->yypred
, yyn
-= 1)
1201 if (yys0
->yyposn
!= yys1
->yyposn
)
1209 /** Assuming identicalOptions (Y0,Y1), (destructively) merge the
1210 * alternative semantic values for the RHS-symbols of Y1 into the
1211 * corresponding semantic value sets of the symbols of Y0. */
1213 yymergeOptionSets (yySemanticOption
* yyy0
, yySemanticOption
* yyy1
)
1215 yyGLRState
*yys0
, *yys1
;
1217 for (yys0
= yyy0
->yystate
, yys1
= yyy1
->yystate
,
1218 yyn
= yyrhsLength (yyy0
->yyrule
);
1220 yys0
= yys0
->yypred
, yys1
= yys1
->yypred
, yyn
-= 1)
1223 else if (! yys0
->yyresolved
&& ! yys1
->yyresolved
)
1225 yySemanticOption
* yyz
;
1226 for (yyz
= yys0
->yysemantics
.yyfirstVal
; yyz
->yynext
!= NULL
;
1229 yyz
->yynext
= yys1
->yysemantics
.yyfirstVal
;
1233 /** Y0 and Y1 represent two possible actions to take in a given
1234 * parsing state; return 0 if no combination is possible,
1235 * 1 if user-mergeable, 2 if Y0 is preferred, 3 if Y1 is preferred. */
1237 yypreference (yySemanticOption
* y0
, yySemanticOption
* y1
)
1239 yyRuleNum r0
= y0
->yyrule
, r1
= y1
->yyrule
;
1240 int p0
= yydprec
[r0
], p1
= yydprec
[r1
];
1244 if (yymerger
[r0
] == 0 || yymerger
[r0
] != yymerger
[r1
])
1249 if (p0
== 0 || p1
== 0)
1258 static YYRESULTTAG
yyresolveValue (yySemanticOption
* yyoptionList
,
1259 yyGLRStack
* yystack
, YYSTYPE
* yyvalp
,
1260 YYLTYPE
* yylocp
]b4_user_formals
[);
1263 yyresolveStates (yyGLRState
* yys
, int yyn
, yyGLRStack
* yystack
]b4_user_formals
[)
1268 assert (yys
->yypred
!= NULL
);
1269 yyflag
= yyresolveStates (yys
->yypred
, yyn
-1, yystack
]b4_user_args
[);
1272 if (! yys
->yyresolved
)
1274 yyflag
= yyresolveValue (yys
->yysemantics
.yyfirstVal
, yystack
,
1275 &yys
->yysemantics
.yysval
, &yys
->yyloc
1279 yys
->yyresolved
= yytrue
;
1286 yyresolveAction (yySemanticOption
* yyopt
, yyGLRStack
* yystack
,
1287 YYSTYPE
* yyvalp
, YYLTYPE
* yylocp
]b4_user_formals
[)
1289 yyGLRStackItem yyrhsVals
[YYMAXRHS
];
1293 yynrhs
= yyrhsLength (yyopt
->yyrule
);
1294 YYCHK (yyresolveStates (yyopt
->yystate
, yynrhs
, yystack
]b4_user_args
[));
1295 for (yyi
= yynrhs
-1, yys
= yyopt
->yystate
; 0 <= yyi
;
1296 yyi
-= 1, yys
= yys
->yypred
)
1298 assert (yys
->yypred
!= NULL
);
1299 yyrhsVals
[yyi
].yystate
.yyresolved
= yytrue
;
1300 yyrhsVals
[yyi
].yystate
.yysemantics
.yysval
= yys
->yysemantics
.yysval
;
1301 yyrhsVals
[yyi
].yystate
.yyloc
= yys
->yyloc
;
1303 return yyuserAction (yyopt
->yyrule
, yynrhs
, yyrhsVals
+ (yynrhs
-1),
1304 yyvalp
, yylocp
, yystack
]b4_user_args
[);
1309 yyreportTree (yySemanticOption
* yyx
, int yyindent
)
1311 int yynrhs
= yyrhsLength (yyx
->yyrule
);
1314 yyGLRState
* yystates
[YYMAXRHS
];
1315 yyGLRState yyleftmost_state
;
1317 for (yyi
= yynrhs
, yys
= yyx
->yystate
; 0 < yyi
; yyi
-= 1, yys
= yys
->yypred
)
1318 yystates
[yyi
] = yys
;
1321 yyleftmost_state
.yyposn
= 0;
1322 yystates
[0] = &yyleftmost_state
;
1327 if (yyx
->yystate
->yyposn
< yys
->yyposn
+ 1)
1328 YYFPRINTF (stderr
, "%*s%s -> <Rule %d, empty>\n",
1329 yyindent
, "", yytokenName (yylhsNonterm (yyx
->yyrule
)),
1332 YYFPRINTF (stderr
, "%*s%s -> <Rule %d, tokens %d .. %d>\n",
1333 yyindent
, "", yytokenName (yylhsNonterm (yyx
->yyrule
)),
1334 yyx
->yyrule
, yys
->yyposn
+1, yyx
->yystate
->yyposn
);
1335 for (yyi
= 1; yyi
<= yynrhs
; yyi
+= 1)
1337 if (yystates
[yyi
]->yyresolved
)
1339 if (yystates
[yyi
-1]->yyposn
+1 > yystates
[yyi
]->yyposn
)
1340 YYFPRINTF (stderr
, "%*s%s <empty>\n", yyindent
+2, "",
1341 yytokenName (yyrhs
[yyprhs
[yyx
->yyrule
]+yyi
-1]));
1343 YYFPRINTF (stderr
, "%*s%s <tokens %d .. %d>\n", yyindent
+2, "",
1344 yytokenName (yyrhs
[yyprhs
[yyx
->yyrule
]+yyi
-1]),
1345 yystates
[yyi
-1]->yyposn
+1, yystates
[yyi
]->yyposn
);
1348 yyreportTree (yystates
[yyi
]->yysemantics
.yyfirstVal
, yyindent
+2);
1354 yyreportAmbiguity (yySemanticOption
* yyx0
, yySemanticOption
* yyx1
,
1355 yyGLRStack
* yystack
]b4_pure_formals
[)
1357 /* `Unused' warnings. */
1362 YYFPRINTF (stderr
, "Ambiguity detected.\n");
1363 YYFPRINTF (stderr
, "Option 1,\n");
1364 yyreportTree (yyx0
, 2);
1365 YYFPRINTF (stderr
, "\nOption 2,\n");
1366 yyreportTree (yyx1
, 2);
1367 YYFPRINTF (stderr
, "\n");
1369 yyFail (yystack
][]b4_pure_args
[, "ambiguity detected");
1373 /** Resolve the ambiguity represented by OPTIONLIST, perform the indicated
1374 * actions, and return the result. */
1376 yyresolveValue (yySemanticOption
* yyoptionList
, yyGLRStack
* yystack
,
1377 YYSTYPE
* yyvalp
, YYLTYPE
* yylocp
]b4_user_formals
[)
1379 yySemanticOption
* yybest
;
1380 yySemanticOption
* yyp
;
1383 yybest
= yyoptionList
;
1385 for (yyp
= yyoptionList
->yynext
; yyp
!= NULL
; yyp
= yyp
->yynext
)
1387 if (yyidenticalOptions (yybest
, yyp
))
1388 yymergeOptionSets (yybest
, yyp
);
1390 switch (yypreference (yybest
, yyp
))
1393 yyreportAmbiguity (yybest
, yyp
, yystack
]b4_pure_args
[);
1409 int yyprec
= yydprec
[yybest
->yyrule
];
1410 YYCHK (yyresolveAction (yybest
, yystack
, yyvalp
, yylocp
]b4_user_args
[));
1411 for (yyp
= yybest
->yynext
; yyp
!= NULL
; yyp
= yyp
->yynext
)
1413 if (yyprec
== yydprec
[yyp
->yyrule
])
1417 YYCHK (yyresolveAction (yyp
, yystack
, &yyval1
, &yydummy
]b4_user_args
[));
1418 *yyvalp
= yyuserMerge (yymerger
[yyp
->yyrule
], yyvalp
, &yyval1
);
1424 return yyresolveAction (yybest
, yystack
, yyvalp
, yylocp
]b4_user_args
[);
1428 yyresolveStack (yyGLRStack
* yystack
]b4_user_formals
[)
1430 if (yystack
->yysplitPoint
!= NULL
)
1435 for (yyn
= 0, yys
= yystack
->yytops
.yystates
[0];
1436 yys
!= yystack
->yysplitPoint
;
1437 yys
= yys
->yypred
, yyn
+= 1)
1439 YYCHK (yyresolveStates (yystack
->yytops
.yystates
[0], yyn
, yystack
1446 yycompressStack (yyGLRStack
* yystack
)
1448 yyGLRState
* yyp
, *yyq
, *yyr
;
1450 if (yystack
->yytops
.yysize
!= 1 || yystack
->yysplitPoint
== NULL
)
1453 for (yyp
= yystack
->yytops
.yystates
[0], yyq
= yyp
->yypred
, yyr
= NULL
;
1454 yyp
!= yystack
->yysplitPoint
;
1455 yyr
= yyp
, yyp
= yyq
, yyq
= yyp
->yypred
)
1458 yystack
->yyspaceLeft
+= yystack
->yynextFree
- yystack
->yyitems
;
1459 yystack
->yynextFree
= ((yyGLRStackItem
*) yystack
->yysplitPoint
) + 1;
1460 yystack
->yyspaceLeft
-= yystack
->yynextFree
- yystack
->yyitems
;
1461 yystack
->yysplitPoint
= NULL
;
1462 yystack
->yylastDeleted
= NULL
;
1466 yystack
->yynextFree
->yystate
= *yyr
;
1468 yystack
->yynextFree
->yystate
.yypred
= & yystack
->yynextFree
[-1].yystate
;
1469 yystack
->yytops
.yystates
[0] = &yystack
->yynextFree
->yystate
;
1470 yystack
->yynextFree
+= 1;
1471 yystack
->yyspaceLeft
-= 1;
1476 yyprocessOneStack (yyGLRStack
* yystack
, int yyk
,
1477 size_t yyposn
, YYSTYPE
* yylvalp
, YYLTYPE
* yyllocp
1481 const short* yyconflicts
;
1483 yySymbol
* const yytokenp
= yystack
->yytokenp
;
1485 while (yystack
->yytops
.yystates
[yyk
] != NULL
)
1487 yyStateNum yystate
= yystack
->yytops
.yystates
[yyk
]->yylrState
;
1489 assert (yystate
!= YYFINAL
);
1490 if (yyisDefaultedState (yystate
))
1492 yyrule
= yydefaultAction (yystate
);
1495 YYDPRINTF ((stderr
, "Stack %d dies.\n", yyk
));
1496 yymarkStackDeleted (yystack
, yyk
);
1499 YYCHK (yyglrReduce (yystack
, yyk
, yyrule
, yyfalse
]b4_lpure_args
[));
1503 if (*yytokenp
== YYEMPTY
)
1505 YYDPRINTF ((stderr
, "Reading a token: "));
1507 *yytokenp
= YYTRANSLATE(yychar
);
1508 YYDPRINTF ((stderr
, "Next token is %s\n",
1509 yytokenName (*yytokenp
)));
1511 yygetLRActions (yystate
, *yytokenp
, &yyaction
, &yyconflicts
);
1513 while (*yyconflicts
!= 0)
1515 int yynewStack
= yysplitStack (yystack
, yyk
);
1516 YYDPRINTF ((stderr
, "Splitting off stack %d from %d.\n",
1518 YYCHK (yyglrReduce (yystack
, yynewStack
,
1519 *yyconflicts
, yyfalse
]b4_lpure_args
[));
1520 YYCHK (yyprocessOneStack (yystack
, yynewStack
, yyposn
,
1521 yylvalp
, yyllocp
]b4_user_args
[));
1525 if (yyisShiftAction (yyaction
))
1527 YYDPRINTF ((stderr
, "Shifting token %s on stack %d, ",
1528 yytokenName (*yytokenp
), yyk
));
1529 yyglrShift (yystack
, yyk
, yyaction
, yyposn
+1,
1530 *yylvalp
, yyllocp
]b4_user_args
[);
1531 YYDPRINTF ((stderr
, "which is now in state #%d\n",
1532 yystack
->yytops
.yystates
[yyk
]->yylrState
));
1535 else if (yyisErrorAction (yyaction
))
1537 YYDPRINTF ((stderr
, "Stack %d dies.\n", yyk
));
1538 yymarkStackDeleted (yystack
, yyk
);
1542 YYCHK (yyglrReduce (yystack
, yyk
, -yyaction
, yyfalse
]b4_lpure_args
[));
1549 yyreportParseError (yyGLRStack
* yystack
,
1550 YYSTYPE
* yylvalp
, YYLTYPE
* yyllocp
]b4_user_formals
[)
1552 /* `Unused' warnings. */
1556 if (yystack
->yyerrState
== 0)
1559 yySymbol
* const yytokenp
= yystack
->yytokenp
;
1560 int yyn
, yyx
, yycount
;
1562 const char* yyprefix
;
1565 yyn
= yypact
[yystack
->yytops
.yystates
[0]->yylrState
];
1566 if (YYPACT_NINF
< yyn
&& yyn
< YYLAST
)
1569 /* Start YYX at -YYN if negative to avoid negative indexes in
1571 yysize
= sizeof ("parse error, unexpected ")
1572 + strlen (yytokenName (*yytokenp
));
1573 yyprefix
= ", expecting ";
1574 for (yyx
= yyn
< 0 ? -yyn
: 0; yyx
< yytname_size
&& yycount
<= 5;
1576 if (yycheck
[yyx
+ yyn
] == yyx
&& yyx
!= YYTERROR
)
1577 yysize
+= strlen (yytokenName (yyx
)) + strlen (yyprefix
),
1578 yycount
+= 1, yyprefix
= " or ";
1579 yymsg
= yyp
= (char*) malloc (yysize
);
1580 sprintf (yyp
, "parse error, unexpected %s",
1581 yytokenName (*yytokenp
));
1582 yyp
+= strlen (yyp
);
1585 yyprefix
= ", expecting ";
1586 for (yyx
= yyn
< 0 ? -yyn
: 0; yyx
< yytname_size
; yyx
+= 1)
1587 if (yycheck
[yyx
+ yyn
] == yyx
&& yyx
!= YYTERROR
)
1589 sprintf (yyp
, "%s%s", yyprefix
, yytokenName (yyx
));
1590 yyp
+= strlen (yyp
);
1594 yyerror (yymsg
]b4_lpure_args
[);
1599 yyerror ("parse error"]b4_lpure_args
[);
1604 /* Recover from a syntax error on YYSTACK, assuming that YYTOKENP,
1605 YYLVALP, and YYLLOCP point to the syntactic category, semantic
1606 value, and location of the lookahead. */
1608 yyrecoverParseError (yyGLRStack
* yystack
,
1609 YYSTYPE
* yylvalp
, YYLTYPE
* yyllocp
]b4_user_formals
[)
1611 yySymbol
* const yytokenp
= yystack
->yytokenp
;
1615 if (yystack
->yyerrState
== 0)
1616 yystack
->yyerrState
= 3;
1617 else if (yystack
->yyerrState
== 3)
1618 /* We just shifted the error token and (perhaps) took some
1619 reductions. Skip tokens until we can proceed. */
1622 if (*yytokenp
== YYEOF
)
1623 yyFail (yystack
][]b4_lpure_args
[, NULL
);
1624 if (*yytokenp
!= YYEMPTY
)
1625 YYDPRINTF ((stderr
, "Discarding token %s\n",
1626 yytokenName (*yytokenp
)));
1627 YYDPRINTF ((stderr
, "Reading a token: "));
1629 *yytokenp
= YYTRANSLATE (yychar
);
1630 YYDPRINTF ((stderr
, "Next token is %s\n", yytokenName (*yytokenp
)));
1631 yyj
= yypact
[yystack
->yytops
.yystates
[0]->yylrState
];
1632 if (yyj
== YYPACT_NINF
)
1633 /* Something's not right; we shouldn't be here. */
1634 yyFail (yystack
][]b4_lpure_args
[, NULL
);
1636 if (yyj
< 0 || YYLAST
< yyj
|| yycheck
[yyj
] != *yytokenp
)
1638 if (yydefact
[yystack
->yytops
.yystates
[0]->yylrState
] != 0)
1641 else if (yytable
[yyj
] != 0 && yytable
[yyj
] != YYTABLE_NINF
)
1645 /* Reduce to one stack. */
1646 for (yyk
= 0; yyk
< yystack
->yytops
.yysize
; yyk
+= 1)
1647 if (yystack
->yytops
.yystates
[yyk
] != NULL
)
1649 if (yyk
>= yystack
->yytops
.yysize
)
1650 yyFail (yystack
][]b4_lpure_args
[, NULL
);
1651 for (yyk
+= 1; yyk
< yystack
->yytops
.yysize
; yyk
+= 1)
1652 yymarkStackDeleted (yystack
, yyk
);
1653 yyremoveDeletes (yystack
);
1654 yycompressStack (yystack
);
1656 /* Now pop stack until we find a state that shifts the error token. */
1657 while (yystack
->yytops
.yystates
[0] != NULL
)
1659 yyj
= yypact
[yystack
->yytops
.yystates
[0]->yylrState
] + YYTERROR
;
1660 if (yyj
!= YYPACT_NINF
+ YYTERROR
&& yyj
>= 0 && yyj
<= YYLAST
&&
1661 yycheck
[yyj
] == YYTERROR
&& yyisShiftAction (yytable
[yyj
]))
1663 yyglrShift (yystack
, 0, yytable
[yyj
],
1664 yystack
->yytops
.yystates
[0]->yyposn
,
1665 *yylvalp
, yyllocp
]b4_user_args
[);
1668 yystack
->yytops
.yystates
[0] = yystack
->yytops
.yystates
[0]->yypred
;
1669 yystack
->yynextFree
-= 1;
1670 yystack
->yyspaceLeft
+= 1;
1672 if (yystack
->yytops
.yystates
[0] == NULL
)
1673 yyFail (yystack
][]b4_lpure_args
[, NULL
);
1676 #define YYCHK1(YYE) \
1682 yystack.yyerrflag = 1; \
1685 yystack.yyerrflag = 0; \
1688 goto yyuser_error; \
1697 ]b4_c_ansi_function_def([yyparse
], [int], b4_parse_param
)[
1707 #define yychar (yystack.yyrawchar)
1710 YYSTYPE
* const yylvalp
= &yylval
;
1711 YYLTYPE
* const yyllocp
= &yylloc
;
1713 yyinitGLRStack (&yystack
, YYINITDEPTH
);
1714 yystack
.yytokenp
= &yytoken
;
1716 YYDPRINTF ((stderr
, "Starting parse\n"));
1718 if (setjmp (yystack
.yyexception_buffer
) != 0)
1721 yyglrShift (&yystack
, 0, 0, 0, yyval_default
, &yyloc_default
]b4_user_args
[);
1727 /* For efficiency, we have two loops, the first of which is
1728 specialized to deterministic operation (single stack, no
1729 potential ambiguity). */
1736 const short* yyconflicts
;
1738 yyStateNum yystate
= yystack
.yytops
.yystates
[0]->yylrState
;
1739 if (yystate
== YYFINAL
)
1741 if (yyisDefaultedState (yystate
))
1743 yyrule
= yydefaultAction (yystate
);
1746 yyreportParseError (&yystack
, yylvalp
, yyllocp
]b4_user_args
[);
1749 YYCHK1 (yyglrReduce (&yystack
, 0, yyrule
, yytrue
]b4_lpure_args
[));
1753 if (yytoken
== YYEMPTY
)
1755 YYDPRINTF ((stderr
, "Reading a token: "));
1757 yytoken
= YYTRANSLATE (yychar
);
1758 YYDPRINTF ((stderr
, "Next token is %s\n",
1759 yytokenName (yytoken
)));
1761 yygetLRActions (yystate
, yytoken
, &yyaction
, &yyconflicts
);
1762 if (*yyconflicts
!= 0)
1764 if (yyisShiftAction (yyaction
))
1766 YYDPRINTF ((stderr
, "Shifting token %s, ",
1767 yytokenName (yytoken
)));
1768 if (yytoken
!= YYEOF
)
1771 yyglrShift (&yystack
, 0, yyaction
, yyposn
,
1772 yylval
, yyllocp
]b4_user_args
[);
1773 if (0 < yystack
.yyerrState
)
1774 yystack
.yyerrState
-= 1;
1775 YYDPRINTF ((stderr
, "Entering state %d\n",
1776 yystack
.yytops
.yystates
[0]->yylrState
));
1778 else if (yyisErrorAction (yyaction
))
1780 yyreportParseError (&yystack
, yylvalp
, yyllocp
]b4_user_args
[);
1784 YYCHK1 (yyglrReduce (&yystack
, 0, -yyaction
, yytrue
]b4_lpure_args
[));
1791 int yyn
= yystack
.yytops
.yysize
;
1792 for (yys
= 0; yys
< yyn
; yys
+= 1)
1793 YYCHK1 (yyprocessOneStack (&yystack
, yys
, yyposn
,
1794 yylvalp
, yyllocp
]b4_user_args
[));
1797 yyremoveDeletes (&yystack
);
1798 if (yystack
.yytops
.yysize
== 0)
1800 yyundeleteLastStack (&yystack
);
1801 if (yystack
.yytops
.yysize
== 0)
1802 yyFail (&yystack
][]b4_lpure_args
[, "parse error");
1803 YYCHK1 (yyresolveStack (&yystack
]b4_user_args
[));
1804 YYDPRINTF ((stderr
, "Returning to deterministic operation.\n"));
1805 yyreportParseError (&yystack
, yylvalp
, yyllocp
]b4_user_args
[);
1808 else if (yystack
.yytops
.yysize
== 1)
1810 YYCHK1 (yyresolveStack (&yystack
]b4_user_args
[));
1811 YYDPRINTF ((stderr
, "Returning to deterministic operation.\n"));
1812 yycompressStack (&yystack
);
1818 yyrecoverParseError (&yystack
, yylvalp
, yyllocp
]b4_user_args
[);
1819 yyposn
= yystack
.yytops
.yystates
[0]->yyposn
;
1824 yyfreeGLRStack (&yystack
);
1825 return yystack
.yyerrflag
;
1828 /* DEBUGGING ONLY */
1829 static void yypstack (yyGLRStack
* yystack
, int yyk
) ATTRIBUTE_UNUSED
;
1830 static void yypdumpstack (yyGLRStack
* yystack
) ATTRIBUTE_UNUSED
;
1833 yy_yypstack (yyGLRState
* yys
)
1837 yy_yypstack (yys
->yypred
);
1838 fprintf (stderr
, " -> ");
1840 fprintf (stderr
, "%d@%lu", yys
->yylrState
, (unsigned long) yys
->yyposn
);
1844 yypstates (yyGLRState
* yyst
)
1847 fprintf (stderr
, "<null>");
1850 fprintf (stderr
, "\n");
1854 yypstack (yyGLRStack
* yystack
, int yyk
)
1856 yypstates (yystack
->yytops
.yystates
[yyk
]);
1859 #define YYINDEX(YYX) \
1860 ((YYX) == NULL ? -1 : (yyGLRStackItem*) (YYX) - yystack->yyitems)
1864 yypdumpstack (yyGLRStack
* yystack
)
1866 yyGLRStackItem
* yyp
;
1868 for (yyp
= yystack
->yyitems
; yyp
< yystack
->yynextFree
; yyp
+= 1)
1870 fprintf (stderr
, "%3lu. ", (unsigned long) (yyp
- yystack
->yyitems
));
1873 fprintf (stderr
, "Res: %d, LR State: %d, posn: %lu, pred: %ld",
1874 yyp
->yystate
.yyresolved
, yyp
->yystate
.yylrState
,
1875 (unsigned long) yyp
->yystate
.yyposn
,
1876 (long) YYINDEX (yyp
->yystate
.yypred
));
1877 if (! yyp
->yystate
.yyresolved
)
1878 fprintf (stderr
, ", firstVal: %ld",
1879 (long) YYINDEX (yyp
->yystate
.yysemantics
.yyfirstVal
));
1883 fprintf (stderr
, "Option. rule: %d, state: %ld, next: %ld",
1884 yyp
->yyoption
.yyrule
,
1885 (long) YYINDEX (yyp
->yyoption
.yystate
),
1886 (long) YYINDEX (yyp
->yyoption
.yynext
));
1888 fprintf (stderr
, "\n");
1890 fprintf (stderr
, "Tops:");
1891 for (yyi
= 0; yyi
< yystack
->yytops
.yysize
; yyi
+= 1)
1892 fprintf (stderr
, "%lu: %ld; ", (unsigned long) yyi
,
1893 (long) YYINDEX (yystack
->yytops
.yystates
[yyi
]));
1894 fprintf (stderr
, "\n");
1899 m4_if(b4_defines_flag
, 0, [],
1900 [#output "b4_output_header_name"
1901 b4_copyright([Skeleton parser
for GLR parsing with Bison
], [2002])
1902 #ifndef b4_header_guard
1903 # define b4_header_guard
1905 b4_token_defines(b4_tokens
)
1908 m4_ifdef([b4_stype
],
1909 [b4_syncline([b4_stype_line
], [b4_filename
])
1910 typedef union b4_stype yystype
;
1911 /* Line __line__ of __file__. */
1912 b4_syncline([__oline__
], [__ofile__
])],
1913 [typedef int yystype
;])
1914 # define YYSTYPE yystype
1918 [extern YYSTYPE b4_prefix
[]lval
;])
1922 typedef struct yyltype
1929 # define YYLTYPE yyltype
1933 [extern YYLTYPE b4_prefix
[]lloc
;])
1935 #endif /* not b4_header_guard */