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
])
34 # Accumule in b4_lex_param all the yylex arguments.
35 # Yes, this is quite ugly...
36 m4_define([b4_lex_param
],
37 m4_dquote(b4_pure_if([[[[YYSTYPE
*]], [[yylvalp]]][]dnl
38 b4_location_if([, [[YYLTYPE
*], [yyllocp
]]])])dnl
39 m4_ifdef([b4_lex_param
], [, ]b4_lex_param
)))
41 m4_define_default([b4_parse_param
])
44 ## ----------------- ##
45 ## Semantic Values. ##
46 ## ----------------- ##
49 # b4_lhs_value([TYPE])
50 # --------------------
51 # Expansion of $<TYPE>$.
52 m4_define([b4_lhs_value
],
53 [(*yyvalp
)[]m4_ifval([$
1], [.$
1])])
56 # b4_rhs_value(RULE-LENGTH, NUM, [TYPE])
57 # --------------------------------------
58 # Expansion of $<TYPE>NUM, where the current rule has RULE-LENGTH
60 m4_define([b4_rhs_value
],
61 [yyvsp@
<:@
m4_eval([$
2 - $
1])@
:>@
.yystate
.yysemantics
.yysval
[]m4_ifval([$
3], [.$
3])])
72 m4_define([b4_lhs_location
],
76 # b4_rhs_location(RULE-LENGTH, NUM)
77 # ---------------------------------
78 # Expansion of @NUM, where the current rule has RULE-LENGTH symbols
80 m4_define([b4_rhs_location
],
81 [yyvsp@
<:@
m4_eval([$
2 - $
1])@
:>@
.yystate
.yyloc
])
85 ## ------------------- ##
86 ## Output file names. ##
87 ## ------------------- ##
89 m4_define_default([b4_input_suffix
], [.y
])
91 m4_define_default([b4_output_parser_suffix
],
92 [m4_translit(b4_input_suffix
, [yY
], [cC
])])
94 m4_define_default([b4_output_parser_name
],
95 [b4_output_prefix
[]b4_output_infix
[]b4_output_parser_suffix
[]])
98 m4_define_default([b4_output_header_suffix
],
99 [m4_translit(b4_input_suffix
, [yY
], [hH
])])
101 m4_define_default([b4_output_header_name
],
102 [b4_output_prefix
[]b4_output_infix
[]b4_output_header_suffix
[]])
104 m4_define_default([b4_header_guard
],
105 [m4_bpatsubst(m4_toupper([BISON_
]b4_output_header_name
),
106 [[^ABCDEFGHIJKLMNOPQRSTUVWXYZ
]], [_
])])
110 #output "b4_output_parser_name"
111 b4_copyright([Skeleton parser
for GLR parsing with Bison
], [2002])
113 /* This is the parser code for GLR (Generalized LR) parser. */
115 /* FIXME: minimize these */
123 /* Identify Bison output. */
127 #define YYPURE ]b4_pure[
129 /* Using locations. */
130 #define YYLSP_NEEDED ]b4_locations_flag[
132 ]m4_if(b4_prefix
[], [yy
], [],
133 [/* If NAME_PREFIX is specified substitute the variables and functions
135 #define yyparse b4_prefix[]parse
136 #define yylex b4_prefix[]lex
137 #define yyerror b4_prefix[]error
138 #define yylval b4_prefix[]lval
139 #define yychar b4_prefix[]char
140 #define yydebug b4_prefix[]debug
141 #define yynerrs b4_prefix[]nerrs
142 b4_location_if([#define yylloc b4_prefix[]lloc])])
144 b4_token_defines(b4_tokens
)
146 /* Copy the first part of user declarations. */
149 /* Enabling traces. */
151 # define YYDEBUG ]b4_debug[
154 /* Enabling verbose error messages. */
155 #ifdef YYERROR_VERBOSE
156 # undef YYERROR_VERBOSE
157 # define YYERROR_VERBOSE 1
159 # define YYERROR_VERBOSE ]b4_error_verbose[
163 ]m4_ifdef([b4_stype
],
164 [#line b4_stype_line "b4_filename"
165 typedef union b4_stype yystype
;
166 /* Line __line__ of __file__. */
167 #line __oline__ "__ofile__"],
168 [typedef int yystype
;])[
169 # define YYSTYPE yystype
170 # define YYSTYPE_IS_TRIVIAL 1
174 typedef struct yyltype
182 # define YYLTYPE ]b4_location_type[
183 # define YYLTYPE_IS_TRIVIAL 1
186 /* Default (constant) values used for initialization for null
187 right-hand sides. Unlike the standard bison.simple template,
188 here we set the default values of the $$ and $@ to zeroed-out
189 values. Since the default value of these quantities is undefined,
190 this behavior is technically correct. */
191 static YYSTYPE yyval_default
;
192 static YYLTYPE yyloc_default
;
194 /* Copy the second part of user declarations. */
197 ]/* Line __line__ of __file__. */
198 #line __oline__ "__ofile__"
200 #if ! defined (__cplusplus)
206 #if defined (__STDC__) || defined (__cplusplus)
207 typedef signed char yysigned_char
;
209 typedef short yysigned_char
;
216 #ifndef __attribute__
217 /* This feature is available in gcc versions 2.5 and later. */
218 # if !defined (__GNUC__) || __GNUC__ < 2 || \
219 (__GNUC__ == 2 && __GNUC_MINOR__ < 5) || __STRICT_ANSI__
220 # define __attribute__(Spec) /* empty */
224 #ifndef ATTRIBUTE_UNUSED
225 # define ATTRIBUTE_UNUSED __attribute__ ((__unused__))
228 #if ! defined (__GNUC__)
232 /* YYFINAL -- State number of the termination state. */
233 #define YYFINAL ]b4_final_state_number[
234 #define YYLAST ]b4_last[
236 /* YYNTOKENS -- Number of terminals. */
237 #define YYNTOKENS ]b4_tokens_number[
238 /* YYNNTS -- Number of nonterminals. */
239 #define YYNNTS ]b4_nterms_number[
240 /* YYNRULES -- Number of rules. */
241 #define YYNRULES ]b4_rules_number[
242 /* YYNRULES -- Number of states. */
243 #define YYNSTATES ]b4_states_number[
244 /* YYMAXRHS -- Maximum number of symbols on right-hand side of rule. */
245 #define YYMAXRHS ]b4_r2_max[
247 /* YYTRANSLATE(X) -- Bison symbol number corresponding to X. */
248 #define YYUNDEFTOK ]b4_undef_token_number[
249 #define YYMAXUTOK ]b4_user_token_number_max[
251 #define YYTRANSLATE(YYX) \
252 ((unsigned)(YYX) <= YYMAXUTOK ? yytranslate[YYX] : YYUNDEFTOK)
254 /* YYTRANSLATE[YYLEX] -- Bison symbol number corresponding to YYLEX. */
255 static const ]b4_int_type_for([b4_translate
])[ yytranslate
[] =
261 /* YYPRHS[YYN] -- Index of the first RHS symbol of rule number YYN in
263 static const ]b4_int_type_for([b4_prhs
])[ yyprhs
[] =
268 /* YYRHS -- A `-1'-separated list of the rules' RHS. */
269 static const ]b4_int_type_for([b4_rhs
])[ yyrhs
[] =
274 /* YYRLINE[YYN] -- source line where rule number YYN was defined. */
275 static const ]b4_int_type_for([b4_rline
])[ yyrline
[] =
281 #if (YYDEBUG) || YYERROR_VERBOSE
282 /* YYTNME[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM.
283 First, the terminals, then, starting at YYNTOKENS, nonterminals. */
284 static const char *const yytname
[] =
289 #define yytname_size ((int) (sizeof (yytname) / sizeof (yytname[0])))
292 /* YYR1[YYN] -- Symbol number of symbol that rule YYN derives. */
293 static const ]b4_int_type_for([b4_r1
])[ yyr1
[] =
298 /* YYR2[YYN] -- Number of symbols composing right hand side of rule YYN. */
299 static const ]b4_int_type_for([b4_r2
])[ yyr2
[] =
304 /* YYDPREC[RULE-NUM] -- Dynamic precedence of rule #RULE-NUM (0 if none). */
305 static const ]b4_int_type_for([b4_dprec
])[ yydprec
[] =
310 /* YYMERGER[RULE-NUM] -- Index of merging function for rule #RULE-NUM. */
311 static const ]b4_int_type_for([b4_merger
])[ yymerger
[] =
316 /* YYDEFACT[S] -- default rule to reduce with in state S when YYTABLE
317 doesn't specify something else to do. Zero means the default is an
319 static const ]b4_int_type_for([b4_defact
])[ yydefact
[] =
324 /* YYPDEFGOTO[NTERM-NUM]. */
325 static const ]b4_int_type_for([b4_defgoto
])[ yydefgoto
[] =
330 /* YYPACT[STATE-NUM] -- Index in YYTABLE of the portion describing
332 #define YYPACT_NINF ]b4_pact_ninf[
333 static const ]b4_int_type_for([b4_pact
])[ yypact
[] =
338 /* YYPGOTO[NTERM-NUM]. */
339 static const ]b4_int_type_for([b4_pgoto
])[ yypgoto
[] =
344 /* YYTABLE[YYPACT[STATE-NUM]]. What to do in state STATE-NUM. If
345 positive, shift that token. If negative, reduce the rule which
346 number is the opposite. If zero, do what YYDEFACT says.
347 If YYTABLE_NINF, parse error. */
348 #define YYTABLE_NINF ]b4_table_ninf[
349 static const ]b4_int_type_for([b4_table
])[ yytable
[] =
354 /* YYCONFLP[YYPACT[STATE-NUM]] -- Pointer into YYCONFL of start of
355 list of conflicting reductions corresponding to action entry for
356 state STATE-NUM in yytable. 0 means no conflicts. The list in
357 yyconfl is terminated by a rule number of 0. */
358 static const ]b4_int_type_for([b4_conflict_list_heads
])[ yyconflp
[] =
360 ]b4_conflict_list_heads
[
363 /* YYCONFL[I] -- lists of conflicting rule numbers, each terminated by
364 0, pointed into by YYCONFLP. */
365 ]dnl Do
not use b4_int_type_for here
, since there are places where
366 dnl pointers onto yyconfl are taken
, which type is
"short *".
367 dnl We probably ought to introduce a type
for confl
.
368 [static const short yyconfl
[] =
370 ]b4_conflicting_rules
[
373 static const ]b4_int_type_for([b4_check
])[ yycheck
[] =
379 /* The user can define YYPARSE_PARAM as the name of an argument to be passed
380 into yyparse. The argument should have type void *.
381 It should actually point to an object.
382 Grammar actions can access the variable by casting it
383 to the proper pointer type. */
386 # define YYPARSE_PARAM_ARG void *YYPARSE_PARAM
387 #else /* !YYPARSE_PARAM */
388 # define YYPARSE_PARAM_ARG void
389 #endif /* !YYPARSE_PARAM */
391 /* Prevent warning if -Wstrict-prototypes. */
393 # ifdef YYPARSE_PARAM
394 int yyparse (void *);
400 /* Error token number */
403 /* YYLLOC_DEFAULT -- Compute the default location (before the actions
406 #define YYRHSLOC(yyRhs,YYK) (yyRhs[YYK].yystate.yyloc)
408 #ifndef YYLLOC_DEFAULT
409 # define YYLLOC_DEFAULT(yyCurrent, yyRhs, YYN) \
410 yyCurrent.first_line = YYRHSLOC(yyRhs,1).first_line; \
411 yyCurrent.first_column = YYRHSLOC(yyRhs,1).first_column; \
412 yyCurrent.last_line = YYRHSLOC(yyRhs,YYN).last_line; \
413 yyCurrent.last_column = YYRHSLOC(yyRhs,YYN).last_column;
416 /* YYLEX -- calling `yylex' with the right arguments. */
417 #define YYLEX ]b4_c_function_call([yylex], [int], b4_lex_param)[
422 #define yynerrs (yystack->yyerrcnt)
424 #define yychar (yystack->yyrawchar)],
432 static const int YYEOF
= 0;
433 static const int YYEMPTY
= -2;
435 typedef enum { yyok
, yyaccept
, yyabort
, yyerr
} YYRESULTTAG
;
438 do { YYRESULTTAG yyflag = YYE; if (yyflag != yyok) return yyflag; } \
443 #if ! defined (YYFPRINTF)
444 # define YYFPRINTF fprintf
447 # define YYDPRINTF(Args) \
452 /* Nonzero means print parse trace. It is left uninitialized so that
453 multiple parsers can coexist. */
456 /* Avoid empty `if' bodies. */
457 # define YYDPRINTF(Args) {}
458 #endif /* !YYDEBUG */
460 /* YYINITDEPTH -- initial size of the parser's stacks. */
462 # define YYINITDEPTH ]b4_stack_depth_init[
465 /* YYMAXDEPTH -- maximum size the stacks can grow to (effective only
466 if the built-in stack extension method is used).
468 Do not make this value too large; the results are undefined if
469 SIZE_MAX < YYMAXDEPTH * sizeof (GLRStackItem)
470 evaluated with infinite-precision integer arithmetic. */
477 # define YYMAXDEPTH ]b4_stack_depth_max[
480 /* Minimum number of free items on the stack allowed after an
481 allocation. This is to allow allocation and initialization
482 to be completed by functions that call expandGLRStack before the
483 stack is expanded, thus insuring that all necessary pointers get
484 properly redirected to new data. */
487 #if ! defined (YYSTACKEXPANDABLE) \
488 && (! defined (__cplusplus) || (YYLTYPE_IS_TRIVIAL && YYSTYPE_IS_TRIVIAL))
489 #define YYSTACKEXPANDABLE 1
491 #define YYSTACKEXPANDABLE 0
494 /** State numbers, as in LALR(1) machine */
495 typedef int yyStateNum
;
497 /** Rule numbers, as in LALR(1) machine */
498 typedef int yyRuleNum
;
500 /** Grammar symbol */
501 typedef short yySymbol
;
503 /** Item references, as in LALR(1) machine */
504 typedef short yyItemNum
;
506 typedef struct yyGLRState yyGLRState
;
507 typedef struct yySemanticOption yySemanticOption
;
508 typedef union yyGLRStackItem yyGLRStackItem
;
509 typedef struct yyGLRStack yyGLRStack
;
510 typedef struct yyGLRStateSet yyGLRStateSet
;
515 yyStateNum yylrState
;
519 yySemanticOption
* yyfirstVal
;
525 struct yyGLRStateSet
{
526 yyGLRState
** yystates
;
527 size_t yysize
, yycapacity
;
530 struct yySemanticOption
{
534 yySemanticOption
* yynext
;
537 union yyGLRStackItem
{
539 yySemanticOption yyoption
;
551 jmp_buf yyexception_buffer
;
552 yyGLRStackItem
* yyitems
;
553 yyGLRStackItem
* yynextFree
;
555 yyGLRState
* yysplitPoint
;
556 yyGLRState
* yylastDeleted
;
557 yyGLRStateSet yytops
;
560 static void yyinitGLRStack (yyGLRStack
* yystack
, size_t yysize
);
561 static void yyexpandGLRStack (yyGLRStack
* yystack
);
562 static void yyfreeGLRStack (yyGLRStack
* yystack
);
565 yyFail (yyGLRStack
* yystack
, const char* yyformat
, ...)
567 if (yyformat
!= NULL
)
571 va_start (yyap
, yyformat
);
572 yystack
->yyerrflag
= 1;
573 vsprintf (yymsg
, yyformat
, yyap
);
576 longjmp (yystack
->yyexception_buffer
, 1);
579 #if YYDEBUG || YYERROR_VERBOSE
580 /** A printable representation of TOKEN. Valid until next call to
582 static inline const char*
583 yytokenName (yySymbol yytoken
)
585 return yytname
[yytoken
];
589 /** Perform user action for rule number YYN, with RHS length YYRHSLEN,
590 * and top stack item YYVSP. YYLVALP points to place to put semantic
591 * value ($$), and yylocp points to place for location information
592 * (@$). Returns yyok for normal return, yyaccept for YYACCEPT,
593 * yyerr for YYERROR, yyabort for YYABORT. */
595 yyuserAction (yyRuleNum yyn
, int yyrhslen
, yyGLRStackItem
* yyvsp
,
596 YYSTYPE
* yyvalp
, YYLTYPE
* yylocp
, yyGLRStack
* yystack
)
598 /* Avoid `unused' warnings in there are no $n. */
603 *yyvalp
= yyval_default
;
604 *yylocp
= yyloc_default
;
608 *yyvalp
= yyvsp
[1-yyrhslen
].yystate
.yysemantics
.yysval
;
609 *yylocp
= yyvsp
[1-yyrhslen
].yystate
.yyloc
;
612 # define yyval (*yyvalp)
614 # define yyerrok (yystack->yyerrState = 0)
616 # define YYACCEPT return yyaccept
618 # define YYABORT return yyabort
620 # define YYERROR return yyerr
622 # define YYRECOVERING (yystack->yyerrState != 0)
624 # define yyclearin (yychar = *(yystack->yytokenp) = YYEMPTY)
626 # define YYBACKUP(Token, Value) \
628 yyerror ("syntax error: cannot back up"); \
647 /* Line __line__ of __file__. */
648 #line __oline__ "__ofile__"
653 yyuserMerge (int yyn
, YYSTYPE
* yy0
, YYSTYPE
* yy1
)
655 YYSTYPE yyval
= *yy0
;
656 /* `Use' the arguments. */
667 /* Bison grammar-table manipulation */
669 /** Number of symbols composing the right hand side of rule #RULE. */
671 yyrhsLength (yyRuleNum yyrule
)
676 /** Left-hand-side symbol for rule #RULE. */
677 static inline yySymbol
678 yylhsNonterm (yyRuleNum yyrule
)
683 /** True iff LR state STATE has only a default reduction (regardless
686 yyisDefaultedState (yyStateNum yystate
)
688 return yypact
[yystate
] == YYPACT_NINF
;
691 /** The default reduction for STATE, assuming it has one. */
692 static inline yyRuleNum
693 yydefaultAction (yyStateNum yystate
)
695 return yydefact
[yystate
];
698 /** Set *YYACTION to the action to take in YYSTATE on seeing YYTOKEN.
700 * R < 0: Reduce on rule -R.
702 * R > 0: Shift to state R.
703 * Set *CONFLICTS to a pointer into yyconfl to 0-terminated list of
704 * conflicting reductions.
707 yygetLRActions (yyStateNum yystate
, int yytoken
,
708 int* yyaction
, const short** yyconflicts
)
710 int yyindex
= yypact
[yystate
] + yytoken
;
711 if (yyindex
< 0 || YYLAST
< yyindex
|| yycheck
[yyindex
] != yytoken
)
713 *yyaction
= -yydefact
[yystate
];
714 *yyconflicts
= yyconfl
;
716 else if (yytable
[yyindex
] != YYTABLE_NINF
)
718 *yyaction
= yytable
[yyindex
];
719 *yyconflicts
= yyconfl
+ yyconflp
[yyindex
];
724 *yyconflicts
= yyconfl
+ yyconflp
[yyindex
];
728 static inline yyStateNum
729 yyLRgotoState (yyStateNum yystate
, yySymbol yylhs
)
732 yyr
= yypgoto
[yylhs
- YYNTOKENS
] + yystate
;
733 if (0 <= yyr
&& yyr
<= YYLAST
&& yycheck
[yyr
] == yystate
)
736 return yydefgoto
[yylhs
- YYNTOKENS
];
740 yyisShiftAction (int yyaction
)
746 yyisErrorAction (int yyaction
)
748 return yyaction
== 0;
753 /** True iff the semantic value of the edge leading to STATE is
756 yyhasResolvedValue (yyGLRState
* yystate
)
758 return yystate
->yyresolved
;
762 yyaddDeferredAction (yyGLRStack
* yystack
, yyGLRState
* yystate
,
763 yyGLRState
* rhs
, yyRuleNum yyrule
)
765 yySemanticOption
* yynewItem
;
766 yynewItem
= &yystack
->yynextFree
->yyoption
;
767 yystack
->yyspaceLeft
-= 1;
768 yystack
->yynextFree
+= 1;
769 yynewItem
->yyisState
= yyfalse
;
770 yynewItem
->yystate
= rhs
;
771 yynewItem
->yyrule
= yyrule
;
772 yynewItem
->yynext
= yystate
->yysemantics
.yyfirstVal
;
773 yystate
->yysemantics
.yyfirstVal
= yynewItem
;
774 if (yystack
->yyspaceLeft
< YYHEADROOM
)
775 yyexpandGLRStack (yystack
);
780 /** Initialize SET to a singleton set containing an empty stack. */
782 yyinitStateSet (yyGLRStateSet
* yyset
)
785 yyset
->yycapacity
= 16;
786 yyset
->yystates
= (yyGLRState
**) malloc (16 * sizeof (yyset
->yystates
[0]));
787 yyset
->yystates
[0] = NULL
;
790 static void yyfreeStateSet (yyGLRStateSet
* yyset
)
792 free (yyset
->yystates
);
795 /** Initialize STACK to a single empty stack, with total maximum
796 * capacity for all stacks of SIZE. */
798 yyinitGLRStack (yyGLRStack
* yystack
, size_t yysize
)
800 yystack
->yyerrflag
= 0;
801 yystack
->yyerrState
= 0;
803 yystack
->yyspaceLeft
= yysize
;
804 yystack
->yynextFree
= yystack
->yyitems
=
805 (yyGLRStackItem
*) malloc (yysize
* sizeof (yystack
->yynextFree
[0]));
806 yystack
->yysplitPoint
= NULL
;
807 yystack
->yylastDeleted
= NULL
;
808 yyinitStateSet (&yystack
->yytops
);
811 #define YYRELOC(YYFROMITEMS,YYTOITEMS,YYX,YYTYPE) \
812 &((YYTOITEMS) - ((YYFROMITEMS) - (yyGLRStackItem*) (YYX)))->YYTYPE
814 /** If STACK is expandable, extend it. WARNING: Pointers into the
815 stack from outside should be considered invalid after this call.
816 We always expand when there are 1 or fewer items left AFTER an
817 allocation, so that we can avoid having external pointers exist
818 across an allocation. */
820 yyexpandGLRStack (yyGLRStack
* yystack
)
822 #if YYSTACKEXPANDABLE
823 yyGLRStack yynewStack
;
824 yyGLRStackItem
* yyp0
, *yyp1
;
825 size_t yysize
, yynewSize
;
827 yysize
= yystack
->yynextFree
- yystack
->yyitems
;
828 if (yysize
>= YYMAXDEPTH
)
829 yyFail (yystack
, "parsing stack overflow (%d items)", yysize
);
830 yynewSize
= 2*yysize
;
831 if (yynewSize
> YYMAXDEPTH
)
832 yynewSize
= YYMAXDEPTH
;
833 yyinitGLRStack (&yynewStack
, yynewSize
);
834 for (yyp0
= yystack
->yyitems
, yyp1
= yynewStack
.yyitems
, yyn
= yysize
;
836 yyn
-= 1, yyp0
+= 1, yyp1
+= 1)
841 yyGLRState
* yys0
= &yyp0
->yystate
;
842 yyGLRState
* yys1
= &yyp1
->yystate
;
843 if (yys0
->yypred
!= NULL
)
845 YYRELOC (yyp0
, yyp1
, yys0
->yypred
, yystate
);
846 if (! yys0
->yyresolved
&& yys0
->yysemantics
.yyfirstVal
!= NULL
)
847 yys1
->yysemantics
.yyfirstVal
=
848 YYRELOC(yyp0
, yyp1
, yys0
->yysemantics
.yyfirstVal
, yyoption
);
852 yySemanticOption
* yyv0
= &yyp0
->yyoption
;
853 yySemanticOption
* yyv1
= &yyp1
->yyoption
;
854 if (yyv0
->yystate
!= NULL
)
855 yyv1
->yystate
= YYRELOC (yyp0
, yyp1
, yyv0
->yystate
, yystate
);
856 if (yyv0
->yynext
!= NULL
)
857 yyv1
->yynext
= YYRELOC (yyp0
, yyp1
, yyv0
->yynext
, yyoption
);
860 if (yystack
->yysplitPoint
!= NULL
)
861 yystack
->yysplitPoint
= YYRELOC (yystack
->yyitems
, yynewStack
.yyitems
,
862 yystack
->yysplitPoint
, yystate
);
864 for (yyn
= 0; yyn
< yystack
->yytops
.yysize
; yyn
+= 1)
865 if (yystack
->yytops
.yystates
[yyn
] != NULL
)
866 yystack
->yytops
.yystates
[yyn
] =
867 YYRELOC (yystack
->yyitems
, yynewStack
.yyitems
,
868 yystack
->yytops
.yystates
[yyn
], yystate
);
869 free (yystack
->yyitems
);
870 yystack
->yyitems
= yynewStack
.yyitems
;
871 yystack
->yynextFree
= yynewStack
.yynextFree
+ yysize
;
872 yystack
->yyspaceLeft
= yynewStack
.yyspaceLeft
- yysize
;
876 yyFail (yystack
, "parsing stack overflow (%d items)", yysize
);
882 yyfreeGLRStack (yyGLRStack
* yystack
)
884 free (yystack
->yyitems
);
885 yyfreeStateSet (&yystack
->yytops
);
888 /** Assuming that S is a GLRState somewhere on STACK, update the
889 * splitpoint of STACK, if needed, so that it is at least as deep as
892 yyupdateSplit (yyGLRStack
* yystack
, yyGLRState
* yys
)
894 if (yystack
->yysplitPoint
!= NULL
&& yystack
->yysplitPoint
> yys
)
895 yystack
->yysplitPoint
= yys
;
898 /** Invalidate stack #K in STACK. */
900 yymarkStackDeleted (yyGLRStack
* yystack
, int yyk
)
902 if (yystack
->yytops
.yystates
[yyk
] != NULL
)
903 yystack
->yylastDeleted
= yystack
->yytops
.yystates
[yyk
];
904 yystack
->yytops
.yystates
[yyk
] = NULL
;
907 /** Undelete the last stack that was marked as deleted. Can only be
908 done once after a deletion, and only when all other stacks have
911 yyundeleteLastStack (yyGLRStack
* yystack
)
913 if (yystack
->yylastDeleted
== NULL
|| yystack
->yytops
.yysize
!= 0)
915 yystack
->yytops
.yystates
[0] = yystack
->yylastDeleted
;
916 yystack
->yytops
.yysize
= 1;
917 YYDPRINTF ((stderr
, "Restoring last deleted stack as stack #0.\n"));
918 yystack
->yylastDeleted
= NULL
;
922 yyremoveDeletes (yyGLRStack
* yystack
)
926 while (yyj
< yystack
->yytops
.yysize
)
928 if (yystack
->yytops
.yystates
[yyi
] == NULL
)
931 YYDPRINTF ((stderr
, "Removing dead stacks.\n"));
932 yystack
->yytops
.yysize
-= 1;
936 yystack
->yytops
.yystates
[yyj
] = yystack
->yytops
.yystates
[yyi
];
938 YYDPRINTF ((stderr
, "Rename stack %d -> %d.\n", yyi
, yyj
));
945 /** Shift to a new state on stack #K of STACK, corresponding to LR state
946 * LRSTATE, at input position POSN, with (resolved) semantic value SVAL. */
948 yyglrShift (yyGLRStack
* yystack
, int yyk
, yyStateNum yylrState
, size_t yyposn
,
949 YYSTYPE yysval
, YYLTYPE
* yylocp
)
951 yyGLRStackItem
* yynewItem
;
953 yynewItem
= yystack
->yynextFree
;
954 yystack
->yynextFree
+= 1;
955 yystack
->yyspaceLeft
-= 1;
956 yynewItem
->yystate
.yyisState
= yytrue
;
957 yynewItem
->yystate
.yylrState
= yylrState
;
958 yynewItem
->yystate
.yyposn
= yyposn
;
959 yynewItem
->yystate
.yyresolved
= yytrue
;
960 yynewItem
->yystate
.yypred
= yystack
->yytops
.yystates
[yyk
];
961 yystack
->yytops
.yystates
[yyk
] = &yynewItem
->yystate
;
962 yynewItem
->yystate
.yysemantics
.yysval
= yysval
;
963 yynewItem
->yystate
.yyloc
= *yylocp
;
964 if (yystack
->yyspaceLeft
< YYHEADROOM
)
965 yyexpandGLRStack (yystack
);
968 /** Shift to a new state on stack #K of STACK, to a new state
969 * corresponding to LR state LRSTATE, at input position POSN, with
970 * the (unresolved) semantic value of RHS under the action for RULE. */
972 yyglrShiftDefer (yyGLRStack
* yystack
, int yyk
, yyStateNum yylrState
,
973 size_t yyposn
, yyGLRState
* rhs
, yyRuleNum yyrule
)
975 yyGLRStackItem
* yynewItem
;
977 yynewItem
= yystack
->yynextFree
;
978 yynewItem
->yystate
.yyisState
= yytrue
;
979 yynewItem
->yystate
.yylrState
= yylrState
;
980 yynewItem
->yystate
.yyposn
= yyposn
;
981 yynewItem
->yystate
.yyresolved
= yyfalse
;
982 yynewItem
->yystate
.yypred
= yystack
->yytops
.yystates
[yyk
];
983 yynewItem
->yystate
.yysemantics
.yyfirstVal
= NULL
;
984 yystack
->yytops
.yystates
[yyk
] = &yynewItem
->yystate
;
985 yystack
->yynextFree
+= 1;
986 yystack
->yyspaceLeft
-= 1;
987 yyaddDeferredAction (yystack
, &yynewItem
->yystate
, rhs
, yyrule
);
990 /** Pop the symbols consumed by reduction #RULE from the top of stack
991 * #K of STACK, and perform the appropriate semantic action on their
992 * semantic values. Assumes that all ambiguities in semantic values
993 * have been previously resolved. Set *VALP to the resulting value,
994 * and *LOCP to the computed location (if any). Return value is as
997 yydoAction (yyGLRStack
* yystack
, int yyk
, yyRuleNum yyrule
,
998 YYSTYPE
* yyvalp
, YYLTYPE
* yylocp
)
1000 int yynrhs
= yyrhsLength (yyrule
);
1002 if (yystack
->yysplitPoint
== NULL
)
1004 /* Standard special case: single stack. */
1005 yyGLRStackItem
* rhs
= (yyGLRStackItem
*) yystack
->yytops
.yystates
[yyk
];
1007 yystack
->yynextFree
-= yynrhs
;
1008 yystack
->yyspaceLeft
+= yynrhs
;
1009 yystack
->yytops
.yystates
[0] = & yystack
->yynextFree
[-1].yystate
;
1012 *yyvalp
= yyval_default
;
1013 *yylocp
= yyloc_default
;
1017 *yyvalp
= rhs
[1-yynrhs
].yystate
.yysemantics
.yysval
;
1018 *yylocp
= rhs
[1-yynrhs
].yystate
.yyloc
;
1020 return yyuserAction (yyrule
, yynrhs
, rhs
, yyvalp
, yylocp
, yystack
);
1026 yyGLRStackItem yyrhsVals
[YYMAXRHS
];
1027 for (yyi
= yynrhs
-1, yys
= yystack
->yytops
.yystates
[yyk
]; yyi
>= 0;
1028 yyi
-= 1, yys
= yys
->yypred
)
1030 assert (yys
->yypred
!= NULL
);
1031 yyrhsVals
[yyi
].yystate
.yyresolved
= yytrue
;
1032 yyrhsVals
[yyi
].yystate
.yysemantics
.yysval
= yys
->yysemantics
.yysval
;
1033 yyrhsVals
[yyi
].yystate
.yyloc
= yys
->yyloc
;
1035 yyupdateSplit (yystack
, yys
);
1036 yystack
->yytops
.yystates
[yyk
] = yys
;
1039 *yyvalp
= yyval_default
;
1040 *yylocp
= yyloc_default
;
1044 *yyvalp
= yyrhsVals
[0].yystate
.yysemantics
.yysval
;
1045 *yylocp
= yyrhsVals
[0].yystate
.yyloc
;
1047 return yyuserAction (yyrule
, yynrhs
, yyrhsVals
+ (yynrhs
-1),
1048 yyvalp
, yylocp
, yystack
);
1052 /** Pop items off stack #K of STACK according to grammar rule RULE,
1053 * and push back on the resulting nonterminal symbol. Perform the
1054 * semantic action associated with RULE and store its value with the
1055 * newly pushed state, if FORCEEVAL or if STACK is currently
1056 * unambiguous. Otherwise, store the deferred semantic action with
1057 * the new state. If the new state would have an identical input
1058 * position, LR state, and predecessor to an existing state on the stack,
1059 * it is identified with that existing state, eliminating stack #K from
1060 * the STACK. In this case, the (necessarily deferred) semantic value is
1061 * added to the options for the existing state's semantic value.
1063 static inline YYRESULTTAG
1064 yyglrReduce (yyGLRStack
* yystack
, size_t yyk
, yyRuleNum yyrule
,
1067 size_t yyposn
= yystack
->yytops
.yystates
[yyk
]->yyposn
;
1069 if (yyforceEval
|| yystack
->yysplitPoint
== NULL
)
1078 YYDPRINTF ((stderr
, "Reducing stack %d by rule %d (line %d),",
1079 yyk
, yyrule
- 1, yyrline
[yyrule
]));
1080 /* Print the symbols being reduced, and their result. */
1081 for (yyi
= yyprhs
[yyrule
]; yyrhs
[yyi
] >= 0; yyi
++)
1082 YYFPRINTF (stderr
, "%s ", yytokenName (yyrhs
[yyi
]));
1083 YYFPRINTF (stderr
, " -> %s\n", yytokenName (yyr1
[yyrule
]));
1086 YYCHK (yydoAction (yystack
, yyk
, yyrule
, &yysval
, &yyloc
));
1087 yyglrShift (yystack
, yyk
,
1088 yyLRgotoState (yystack
->yytops
.yystates
[yyk
]->yylrState
,
1089 yylhsNonterm (yyrule
)),
1090 yyposn
, yysval
, &yyloc
);
1091 YYDPRINTF ((stderr
, "Stack %d entering state %d\n",
1092 yyk
, yystack
->yytops
.yystates
[yyk
]->yylrState
));
1098 yyGLRState
* yys
, *yys0
= yystack
->yytops
.yystates
[yyk
];
1099 yyStateNum yynewLRState
;
1101 for (yys
= yystack
->yytops
.yystates
[yyk
], yyn
= yyrhsLength (yyrule
);
1105 assert (yys
!= NULL
);
1107 yyupdateSplit (yystack
, yys
);
1108 yynewLRState
= yyLRgotoState (yys
->yylrState
, yylhsNonterm (yyrule
));
1110 "Reduced stack %d by rule #%d; action deferred. "
1111 "Now in state %d.\n",
1112 yyk
, yyrule
-1, yynewLRState
));
1113 for (yyi
= 0; yyi
< yystack
->yytops
.yysize
; yyi
+= 1)
1114 if (yyi
!= yyk
&& yystack
->yytops
.yystates
[yyi
] != NULL
)
1116 yyGLRState
* yyp
, *yysplit
= yystack
->yysplitPoint
;
1117 yyp
= yystack
->yytops
.yystates
[yyi
];
1118 while (yyp
!= yys
&& yyp
!= yysplit
&& yyp
->yyposn
>= yyposn
)
1120 if (yyp
->yylrState
== yynewLRState
&& yyp
->yypred
== yys
)
1122 yyaddDeferredAction (yystack
, yyp
, yys0
, yyrule
);
1123 yymarkStackDeleted (yystack
, yyk
);
1124 YYDPRINTF ((stderr
, "Merging stack %d into stack %d.\n",
1131 yystack
->yytops
.yystates
[yyk
] = yys
;
1132 yyglrShiftDefer (yystack
, yyk
, yynewLRState
, yyposn
, yys0
, yyrule
);
1138 yysplitStack (yyGLRStack
* yystack
, int yyk
)
1140 if (yystack
->yysplitPoint
== NULL
)
1143 yystack
->yysplitPoint
= yystack
->yytops
.yystates
[yyk
];
1145 if (yystack
->yytops
.yysize
>= yystack
->yytops
.yycapacity
)
1147 yystack
->yytops
.yycapacity
*= 2;
1148 yystack
->yytops
.yystates
=
1149 (yyGLRState
**) realloc (yystack
->yytops
.yystates
,
1150 yystack
->yytops
.yycapacity
1151 * sizeof (yyGLRState
*));
1153 yystack
->yytops
.yystates
[yystack
->yytops
.yysize
]
1154 = yystack
->yytops
.yystates
[yyk
];
1155 yystack
->yytops
.yysize
+= 1;
1156 return yystack
->yytops
.yysize
-1;
1159 /** True iff Y0 and Y1 represent identical options at the top level.
1160 * That is, they represent the same rule applied to RHS symbols
1161 * that produce the same terminal symbols. */
1163 yyidenticalOptions (yySemanticOption
* yyy0
, yySemanticOption
* yyy1
)
1165 if (yyy0
->yyrule
== yyy1
->yyrule
)
1167 yyGLRState
*yys0
, *yys1
;
1169 for (yys0
= yyy0
->yystate
, yys1
= yyy1
->yystate
,
1170 yyn
= yyrhsLength (yyy0
->yyrule
);
1172 yys0
= yys0
->yypred
, yys1
= yys1
->yypred
, yyn
-= 1)
1173 if (yys0
->yyposn
!= yys1
->yyposn
)
1181 /** Assuming identicalOptions (Y0,Y1), (destructively) merge the
1182 * alternative semantic values for the RHS-symbols of Y1 into the
1183 * corresponding semantic value sets of the symbols of Y0. */
1185 yymergeOptionSets (yySemanticOption
* yyy0
, yySemanticOption
* yyy1
)
1187 yyGLRState
*yys0
, *yys1
;
1189 for (yys0
= yyy0
->yystate
, yys1
= yyy1
->yystate
,
1190 yyn
= yyrhsLength (yyy0
->yyrule
);
1192 yys0
= yys0
->yypred
, yys1
= yys1
->yypred
, yyn
-= 1)
1195 else if (! yys0
->yyresolved
&& ! yys1
->yyresolved
)
1197 yySemanticOption
* yyz
;
1198 for (yyz
= yys0
->yysemantics
.yyfirstVal
; yyz
->yynext
!= NULL
;
1201 yyz
->yynext
= yys1
->yysemantics
.yyfirstVal
;
1205 /** Y0 and Y1 represent two possible actions to take in a given
1206 * parsing state; return 0 if no combination is possible,
1207 * 1 if user-mergeable, 2 if Y0 is preferred, 3 if Y1 is preferred. */
1209 yypreference (yySemanticOption
* y0
, yySemanticOption
* y1
)
1211 yyRuleNum r0
= y0
->yyrule
, r1
= y1
->yyrule
;
1212 int p0
= yydprec
[r0
], p1
= yydprec
[r1
];
1216 if (yymerger
[r0
] == 0 || yymerger
[r0
] != yymerger
[r1
])
1221 if (p0
== 0 || p1
== 0)
1230 static YYRESULTTAG
yyresolveValue (yySemanticOption
* yyoptionList
,
1231 yyGLRStack
* yystack
, YYSTYPE
* yyvalp
,
1235 yyresolveStates (yyGLRState
* yys
, int yyn
, yyGLRStack
* yystack
)
1240 assert (yys
->yypred
!= NULL
);
1241 yyflag
= yyresolveStates (yys
->yypred
, yyn
-1, yystack
);
1244 if (! yys
->yyresolved
)
1246 yyflag
= yyresolveValue (yys
->yysemantics
.yyfirstVal
, yystack
,
1247 &yys
->yysemantics
.yysval
, &yys
->yyloc
);
1250 yys
->yyresolved
= yytrue
;
1257 yyresolveAction (yySemanticOption
* yyopt
, yyGLRStack
* yystack
,
1258 YYSTYPE
* yyvalp
, YYLTYPE
* yylocp
)
1260 yyGLRStackItem yyrhsVals
[YYMAXRHS
];
1264 yynrhs
= yyrhsLength (yyopt
->yyrule
);
1265 YYCHK (yyresolveStates (yyopt
->yystate
, yynrhs
, yystack
));
1266 for (yyi
= yynrhs
-1, yys
= yyopt
->yystate
; yyi
>= 0;
1267 yyi
-= 1, yys
= yys
->yypred
)
1269 assert (yys
->yypred
!= NULL
);
1270 yyrhsVals
[yyi
].yystate
.yyresolved
= yytrue
;
1271 yyrhsVals
[yyi
].yystate
.yysemantics
.yysval
= yys
->yysemantics
.yysval
;
1272 yyrhsVals
[yyi
].yystate
.yyloc
= yys
->yyloc
;
1274 return yyuserAction (yyopt
->yyrule
, yynrhs
, yyrhsVals
+ (yynrhs
-1),
1275 yyvalp
, yylocp
, yystack
);
1279 static yyGLRState YYLEFTMOST_STATE
=
1281 0, 0, -1, NULL
, 0, { NULL
},
1284 #if YYLTYPE_IS_TRIVIAL
1285 ]b4_location_if([ 0, 0, 0, 0])[
1290 static void yyreportTree (yySemanticOption
* yyx
, int yyindent
)
1292 int yynrhs
= yyrhsLength (yyx
->yyrule
);
1295 yyGLRState
* yystates
[YYMAXRHS
];
1297 for (yyi
= yynrhs
, yys
= yyx
->yystate
; yyi
> 0; yyi
-= 1, yys
= yys
->yypred
)
1298 yystates
[yyi
] = yys
;
1300 yystates
[0] = &YYLEFTMOST_STATE
;
1304 if (yys
->yyposn
+1 > yyx
->yystate
->yyposn
)
1305 YYFPRINTF (stderr
, "%*s%s -> <Rule %d, empty>\n",
1306 yyindent
, "", yytokenName (yylhsNonterm (yyx
->yyrule
)),
1309 YYFPRINTF (stderr
, "%*s%s -> <Rule %d, tokens %d .. %d>\n",
1310 yyindent
, "", yytokenName (yylhsNonterm (yyx
->yyrule
)),
1311 yyx
->yyrule
, yys
->yyposn
+1, yyx
->yystate
->yyposn
);
1312 for (yyi
= 1; yyi
<= yynrhs
; yyi
+= 1)
1314 if (yystates
[yyi
]->yyresolved
)
1316 if (yystates
[yyi
-1]->yyposn
+1 > yystates
[yyi
]->yyposn
)
1317 YYFPRINTF (stderr
, "%*s%s <empty>\n", yyindent
+2, "",
1318 yytokenName (yyrhs
[yyprhs
[yyx
->yyrule
]+yyi
-1]));
1320 YYFPRINTF (stderr
, "%*s%s <tokens %d .. %d>\n", yyindent
+2, "",
1321 yytokenName (yyrhs
[yyprhs
[yyx
->yyrule
]+yyi
-1]),
1322 yystates
[yyi
-1]->yyposn
+1, yystates
[yyi
]->yyposn
);
1325 yyreportTree (yystates
[yyi
]->yysemantics
.yyfirstVal
, yyindent
+2);
1331 yyreportAmbiguity (yySemanticOption
* yyx0
, yySemanticOption
* yyx1
,
1332 yyGLRStack
* yystack
)
1334 /* `Unused' warnings. */
1339 YYFPRINTF (stderr
, "Ambiguity detected.\n");
1340 YYFPRINTF (stderr
, "Option 1,\n");
1341 yyreportTree (yyx0
, 2);
1342 YYFPRINTF (stderr
, "\nOption 2,\n");
1343 yyreportTree (yyx1
, 2);
1344 YYFPRINTF (stderr
, "\n");
1346 yyFail (yystack
, "ambiguity detected");
1350 /** Resolve the ambiguity represented by OPTIONLIST, perform the indicated
1351 * actions, and return the result. */
1353 yyresolveValue (yySemanticOption
* yyoptionList
, yyGLRStack
* yystack
,
1354 YYSTYPE
* yyvalp
, YYLTYPE
* yylocp
)
1356 yySemanticOption
* yybest
;
1357 yySemanticOption
* yyp
;
1360 yybest
= yyoptionList
;
1362 for (yyp
= yyoptionList
->yynext
; yyp
!= NULL
; yyp
= yyp
->yynext
)
1364 if (yyidenticalOptions (yybest
, yyp
))
1365 yymergeOptionSets (yybest
, yyp
);
1367 switch (yypreference (yybest
, yyp
))
1370 yyreportAmbiguity (yybest
, yyp
, yystack
);
1386 int yyprec
= yydprec
[yybest
->yyrule
];
1387 YYCHK (yyresolveAction (yybest
, yystack
, yyvalp
, yylocp
));
1388 for (yyp
= yybest
->yynext
; yyp
!= NULL
; yyp
= yyp
->yynext
)
1390 if (yyprec
== yydprec
[yyp
->yyrule
])
1394 YYCHK (yyresolveAction (yyp
, yystack
, &yyval1
, &yydummy
));
1395 *yyvalp
= yyuserMerge (yymerger
[yyp
->yyrule
], yyvalp
, &yyval1
);
1401 return yyresolveAction (yybest
, yystack
, yyvalp
, yylocp
);
1405 yyresolveStack (yyGLRStack
* yystack
)
1407 if (yystack
->yysplitPoint
!= NULL
)
1412 for (yyn
= 0, yys
= yystack
->yytops
.yystates
[0];
1413 yys
!= yystack
->yysplitPoint
;
1414 yys
= yys
->yypred
, yyn
+= 1)
1416 YYCHK (yyresolveStates (yystack
->yytops
.yystates
[0], yyn
, yystack
));
1422 yycompressStack (yyGLRStack
* yystack
)
1424 yyGLRState
* yyp
, *yyq
, *yyr
;
1426 if (yystack
->yytops
.yysize
!= 1 || yystack
->yysplitPoint
== NULL
)
1429 for (yyp
= yystack
->yytops
.yystates
[0], yyq
= yyp
->yypred
, yyr
= NULL
;
1430 yyp
!= yystack
->yysplitPoint
;
1431 yyr
= yyp
, yyp
= yyq
, yyq
= yyp
->yypred
)
1434 yystack
->yyspaceLeft
+= yystack
->yynextFree
- yystack
->yyitems
;
1435 yystack
->yynextFree
= ((yyGLRStackItem
*) yystack
->yysplitPoint
) + 1;
1436 yystack
->yyspaceLeft
-= yystack
->yynextFree
- yystack
->yyitems
;
1437 yystack
->yysplitPoint
= NULL
;
1438 yystack
->yylastDeleted
= NULL
;
1442 yystack
->yynextFree
->yystate
= *yyr
;
1444 yystack
->yynextFree
->yystate
.yypred
= & yystack
->yynextFree
[-1].yystate
;
1445 yystack
->yytops
.yystates
[0] = &yystack
->yynextFree
->yystate
;
1446 yystack
->yynextFree
+= 1;
1447 yystack
->yyspaceLeft
-= 1;
1452 yyprocessOneStack (yyGLRStack
* yystack
, int yyk
,
1453 size_t yyposn
, YYSTYPE
* yylvalp
, YYLTYPE
* yyllocp
)
1456 const short* yyconflicts
;
1458 yySymbol
* const yytokenp
= yystack
->yytokenp
;
1460 while (yystack
->yytops
.yystates
[yyk
] != NULL
)
1462 yyStateNum yystate
= yystack
->yytops
.yystates
[yyk
]->yylrState
;
1464 assert (yystate
!= YYFINAL
);
1465 if (yyisDefaultedState (yystate
))
1467 yyrule
= yydefaultAction (yystate
);
1470 YYDPRINTF ((stderr
, "Stack %d dies.\n", yyk
));
1471 yymarkStackDeleted (yystack
, yyk
);
1474 YYCHK (yyglrReduce (yystack
, yyk
, yyrule
, yyfalse
));
1478 if (*yytokenp
== YYEMPTY
)
1480 YYDPRINTF ((stderr
, "Reading a token: "));
1482 *yytokenp
= YYTRANSLATE(yychar
);
1483 YYDPRINTF ((stderr
, "Next token is %s\n",
1484 yytokenName (*yytokenp
)));
1486 yygetLRActions (yystate
, *yytokenp
, &yyaction
, &yyconflicts
);
1488 while (*yyconflicts
!= 0)
1490 int yynewStack
= yysplitStack (yystack
, yyk
);
1491 YYDPRINTF ((stderr
, "Splitting off stack %d from %d.\n",
1493 YYCHK (yyglrReduce (yystack
, yynewStack
, *yyconflicts
, yyfalse
));
1494 YYCHK (yyprocessOneStack (yystack
, yynewStack
, yyposn
,
1499 if (yyisShiftAction (yyaction
))
1501 YYDPRINTF ((stderr
, "Shifting token %s on stack %d, ",
1502 yytokenName (*yytokenp
), yyk
));
1503 yyglrShift (yystack
, yyk
, yyaction
, yyposn
+1, *yylvalp
, yyllocp
);
1504 YYDPRINTF ((stderr
, "which is now in state #%d\n",
1505 yystack
->yytops
.yystates
[yyk
]->yylrState
));
1508 else if (yyisErrorAction (yyaction
))
1510 YYDPRINTF ((stderr
, "Stack %d dies.\n", yyk
));
1511 yymarkStackDeleted (yystack
, yyk
);
1515 YYCHK (yyglrReduce (yystack
, yyk
, -yyaction
, yyfalse
));
1522 yyreportParseError (yyGLRStack
* yystack
, YYSTYPE
* yylvalp
, YYLTYPE
* yyllocp
)
1524 /* `Unused' warnings. */
1528 if (yystack
->yyerrState
== 0)
1531 yySymbol
* const yytokenp
= yystack
->yytokenp
;
1532 int yyn
, yyx
, yycount
;
1534 const char* yyprefix
;
1537 yyn
= yypact
[yystack
->yytops
.yystates
[0]->yylrState
];
1538 if (YYPACT_NINF
< yyn
&& yyn
< YYLAST
)
1541 /* Start YYX at -YYN if negative to avoid negative indexes in
1543 yysize
= sizeof ("parse error, unexpected ")
1544 + strlen (yytokenName (*yytokenp
));
1545 yyprefix
= ", expecting ";
1546 for (yyx
= yyn
< 0 ? -yyn
: 0; yyx
< yytname_size
&& yycount
<= 5;
1548 if (yycheck
[yyx
+ yyn
] == yyx
&& yyx
!= YYTERROR
)
1549 yysize
+= strlen (yytokenName (yyx
)) + strlen (yyprefix
),
1550 yycount
+= 1, yyprefix
= " or ";
1551 yymsg
= yyp
= (char*) malloc (yysize
);
1552 sprintf (yyp
, "parse error, unexpected %s",
1553 yytokenName (*yytokenp
));
1554 yyp
+= strlen (yyp
);
1557 yyprefix
= ", expecting ";
1558 for (yyx
= yyn
< 0 ? -yyn
: 0; yyx
< yytname_size
; yyx
+= 1)
1559 if (yycheck
[yyx
+ yyn
] == yyx
&& yyx
!= YYTERROR
)
1561 sprintf (yyp
, "%s%s", yyprefix
, yytokenName (yyx
));
1562 yyp
+= strlen (yyp
);
1571 yyerror ("parse error");
1576 /* Recover from a syntax error on YYSTACK, assuming that YYTOKENP,
1577 YYLVALP, and YYLLOCP point to the syntactic category, semantic
1578 value, and location of the lookahead. */
1580 yyrecoverParseError (yyGLRStack
* yystack
, YYSTYPE
* yylvalp
, YYLTYPE
* yyllocp
)
1582 yySymbol
* const yytokenp
= yystack
->yytokenp
;
1586 if (yystack
->yyerrState
== 0)
1587 yystack
->yyerrState
= 3;
1588 else if (yystack
->yyerrState
== 3)
1589 /* We just shifted the error token and (perhaps) took some
1590 reductions. Skip tokens until we can proceed. */
1593 if (*yytokenp
== YYEOF
)
1594 yyFail (yystack
, NULL
);
1595 if (*yytokenp
!= YYEMPTY
)
1596 YYDPRINTF ((stderr
, "Discarding token %s\n",
1597 yytokenName (*yytokenp
)));
1598 YYDPRINTF ((stderr
, "Reading a token: "));
1600 *yytokenp
= YYTRANSLATE (yychar
);
1601 YYDPRINTF ((stderr
, "Next token is %s\n", yytokenName (*yytokenp
)));
1602 yyj
= yypact
[yystack
->yytops
.yystates
[0]->yylrState
];
1603 if (yyj
== YYPACT_NINF
)
1604 /* Something's not right; we shouldn't be here. */
1605 yyFail (yystack
, NULL
);
1607 if (yyj
< 0 || YYLAST
< yyj
|| yycheck
[yyj
] != *yytokenp
)
1609 if (yydefact
[yystack
->yytops
.yystates
[0]->yylrState
] != 0)
1612 else if (yytable
[yyj
] != 0 && yytable
[yyj
] != YYTABLE_NINF
)
1616 /* Reduce to one stack. */
1617 for (yyk
= 0; yyk
< yystack
->yytops
.yysize
; yyk
+= 1)
1618 if (yystack
->yytops
.yystates
[yyk
] != NULL
)
1620 if (yyk
>= yystack
->yytops
.yysize
)
1621 yyFail (yystack
, NULL
);
1622 for (yyk
+= 1; yyk
< yystack
->yytops
.yysize
; yyk
+= 1)
1623 yymarkStackDeleted (yystack
, yyk
);
1624 yyremoveDeletes (yystack
);
1625 yycompressStack (yystack
);
1627 /* Now pop stack until we find a state that shifts the error token. */
1628 while (yystack
->yytops
.yystates
[0] != NULL
)
1630 yyj
= yypact
[yystack
->yytops
.yystates
[0]->yylrState
] + YYTERROR
;
1631 if (yyj
!= YYPACT_NINF
+ YYTERROR
&& yyj
>= 0 && yyj
<= YYLAST
&&
1632 yycheck
[yyj
] == YYTERROR
&& yyisShiftAction (yytable
[yyj
]))
1634 yyglrShift (yystack
, 0, yytable
[yyj
],
1635 yystack
->yytops
.yystates
[0]->yyposn
, *yylvalp
, yyllocp
);
1638 yystack
->yytops
.yystates
[0] = yystack
->yytops
.yystates
[0]->yypred
;
1639 yystack
->yynextFree
-= 1;
1640 yystack
->yyspaceLeft
+= 1;
1642 if (yystack
->yytops
.yystates
[0] == NULL
)
1643 yyFail (yystack
, NULL
);
1646 #define YYCHK1(YYE) \
1652 yystack.yyerrflag = 1; \
1655 yystack.yyerrflag = 0; \
1658 goto yyuser_error; \
1663 yyparse (YYPARSE_PARAM_ARG
)
1673 #define yychar (yystack.yyrawchar)
1676 YYSTYPE
* const yylvalp
= &yylval
;
1677 YYLTYPE
* const yyllocp
= &yylloc
;
1679 yyinitGLRStack (&yystack
, YYINITDEPTH
);
1680 yystack
.yytokenp
= &yytoken
;
1682 YYDPRINTF ((stderr
, "Starting parse\n"));
1684 if (setjmp (yystack
.yyexception_buffer
) != 0)
1687 yyglrShift (&yystack
, 0, 0, 0, yyval_default
, &yyloc_default
);
1693 /* For efficiency, we have two loops, the first of which is
1694 specialized to deterministic operation (single stack, no
1695 potential ambiguity). */
1702 const short* yyconflicts
;
1704 yyStateNum yystate
= yystack
.yytops
.yystates
[0]->yylrState
;
1705 if (yystate
== YYFINAL
)
1707 if (yyisDefaultedState (yystate
))
1709 yyrule
= yydefaultAction (yystate
);
1712 yyreportParseError (&yystack
, yylvalp
, yyllocp
);
1715 YYCHK1 (yyglrReduce (&yystack
, 0, yyrule
, yytrue
));
1719 if (yytoken
== YYEMPTY
)
1721 YYDPRINTF ((stderr
, "Reading a token: "));
1723 yytoken
= YYTRANSLATE (yychar
);
1724 YYDPRINTF ((stderr
, "Next token is %s\n",
1725 yytokenName (yytoken
)));
1727 yygetLRActions (yystate
, yytoken
, &yyaction
, &yyconflicts
);
1728 if (*yyconflicts
!= 0)
1730 if (yyisShiftAction (yyaction
))
1732 YYDPRINTF ((stderr
, "Shifting token %s, ",
1733 yytokenName (yytoken
)));
1734 if (yytoken
!= YYEOF
)
1737 yyglrShift (&yystack
, 0, yyaction
, yyposn
, yylval
, yyllocp
);
1738 if (yystack
.yyerrState
> 0)
1739 yystack
.yyerrState
-= 1;
1740 YYDPRINTF ((stderr
, "Entering state %d\n",
1741 yystack
.yytops
.yystates
[0]->yylrState
));
1743 else if (yyisErrorAction (yyaction
))
1745 yyreportParseError (&yystack
, yylvalp
, yyllocp
);
1749 YYCHK1 (yyglrReduce (&yystack
, 0, -yyaction
, yytrue
));
1756 int yyn
= yystack
.yytops
.yysize
;
1757 for (yys
= 0; yys
< yyn
; yys
+= 1)
1758 YYCHK1 (yyprocessOneStack (&yystack
, yys
, yyposn
,
1762 yyremoveDeletes (&yystack
);
1763 if (yystack
.yytops
.yysize
== 0)
1765 yyundeleteLastStack (&yystack
);
1766 if (yystack
.yytops
.yysize
== 0)
1767 yyFail (&yystack
, "parse error");
1768 YYCHK1 (yyresolveStack (&yystack
));
1769 YYDPRINTF ((stderr
, "Returning to deterministic operation.\n"));
1770 yyreportParseError (&yystack
, yylvalp
, yyllocp
);
1773 else if (yystack
.yytops
.yysize
== 1)
1775 YYCHK1 (yyresolveStack (&yystack
));
1776 YYDPRINTF ((stderr
, "Returning to deterministic operation.\n"));
1777 yycompressStack (&yystack
);
1783 yyrecoverParseError (&yystack
, yylvalp
, yyllocp
);
1784 yyposn
= yystack
.yytops
.yystates
[0]->yyposn
;
1789 yyfreeGLRStack (&yystack
);
1790 return yystack
.yyerrflag
;
1793 /* DEBUGGING ONLY */
1794 static void yypstack (yyGLRStack
* yystack
, int yyk
) ATTRIBUTE_UNUSED
;
1795 static void yypdumpstack (yyGLRStack
* yystack
) ATTRIBUTE_UNUSED
;
1798 yy_yypstack (yyGLRState
* yys
)
1802 yy_yypstack (yys
->yypred
);
1803 fprintf (stderr
, " -> ");
1805 fprintf (stderr
, "%d@%lu", yys
->yylrState
, (unsigned long) yys
->yyposn
);
1809 yypstates (yyGLRState
* yyst
)
1812 fprintf (stderr
, "<null>");
1815 fprintf (stderr
, "\n");
1819 yypstack (yyGLRStack
* yystack
, int yyk
)
1821 yypstates (yystack
->yytops
.yystates
[yyk
]);
1824 #define YYINDEX(YYX) \
1825 ((YYX) == NULL ? -1 : (yyGLRStackItem*) (YYX) - yystack->yyitems)
1829 yypdumpstack (yyGLRStack
* yystack
)
1831 yyGLRStackItem
* yyp
;
1833 for (yyp
= yystack
->yyitems
; yyp
< yystack
->yynextFree
; yyp
+= 1)
1835 fprintf (stderr
, "%3lu. ", (unsigned long) (yyp
- yystack
->yyitems
));
1838 fprintf (stderr
, "Res: %d, LR State: %d, posn: %lu, pred: %ld",
1839 yyp
->yystate
.yyresolved
, yyp
->yystate
.yylrState
,
1840 (unsigned long) yyp
->yystate
.yyposn
,
1841 (long) YYINDEX (yyp
->yystate
.yypred
));
1842 if (! yyp
->yystate
.yyresolved
)
1843 fprintf (stderr
, ", firstVal: %ld",
1844 (long) YYINDEX (yyp
->yystate
.yysemantics
.yyfirstVal
));
1848 fprintf (stderr
, "Option. rule: %d, state: %ld, next: %ld",
1849 yyp
->yyoption
.yyrule
,
1850 (long) YYINDEX (yyp
->yyoption
.yystate
),
1851 (long) YYINDEX (yyp
->yyoption
.yynext
));
1853 fprintf (stderr
, "\n");
1855 fprintf (stderr
, "Tops:");
1856 for (yyi
= 0; yyi
< yystack
->yytops
.yysize
; yyi
+= 1)
1857 fprintf (stderr
, "%lu: %ld; ", (unsigned long) yyi
,
1858 (long) YYINDEX (yystack
->yytops
.yystates
[yyi
]));
1859 fprintf (stderr
, "\n");
1865 m4_if(b4_defines_flag
, 0, [],
1866 [#output "b4_output_header_name"
1867 b4_copyright([Skeleton parser
for GLR parsing with Bison
], [2002])
1868 #ifndef b4_header_guard
1869 # define b4_header_guard
1871 b4_token_defines(b4_tokens
)
1874 m4_ifdef([b4_stype
],
1875 [#line b4_stype_line "b4_filename"
1876 typedef union b4_stype yystype
;
1877 /* Line __line__ of __file__. */
1878 #line __oline__ "__ofile__"],
1879 [typedef int yystype
;])
1880 # define YYSTYPE yystype
1884 [extern YYSTYPE b4_prefix
[]lval
;])
1888 typedef struct yyltype
1895 # define YYLTYPE yyltype
1899 [extern YYLTYPE b4_prefix
[]lloc
;])
1901 #endif /* not b4_header_guard */