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 /* YYLAST -- Last index in YYTABLE. */
235 #define YYLAST ]b4_last[
237 /* YYNTOKENS -- Number of terminals. */
238 #define YYNTOKENS ]b4_tokens_number[
239 /* YYNNTS -- Number of nonterminals. */
240 #define YYNNTS ]b4_nterms_number[
241 /* YYNRULES -- Number of rules. */
242 #define YYNRULES ]b4_rules_number[
243 /* YYNRULES -- Number of states. */
244 #define YYNSTATES ]b4_states_number[
245 /* YYMAXRHS -- Maximum number of symbols on right-hand side of rule. */
246 #define YYMAXRHS ]b4_r2_max[
248 /* YYTRANSLATE(X) -- Bison symbol number corresponding to X. */
249 #define YYUNDEFTOK ]b4_undef_token_number[
250 #define YYMAXUTOK ]b4_user_token_number_max[
252 #define YYTRANSLATE(YYX) \
253 ((unsigned)(YYX) <= YYMAXUTOK ? yytranslate[YYX] : YYUNDEFTOK)
255 /* YYTRANSLATE[YYLEX] -- Bison symbol number corresponding to YYLEX. */
256 static const ]b4_int_type_for([b4_translate
])[ yytranslate
[] =
262 /* YYPRHS[YYN] -- Index of the first RHS symbol of rule number YYN in
264 static const ]b4_int_type_for([b4_prhs
])[ yyprhs
[] =
269 /* YYRHS -- A `-1'-separated list of the rules' RHS. */
270 static const ]b4_int_type_for([b4_rhs
])[ yyrhs
[] =
275 /* YYRLINE[YYN] -- source line where rule number YYN was defined. */
276 static const ]b4_int_type_for([b4_rline
])[ yyrline
[] =
282 #if (YYDEBUG) || YYERROR_VERBOSE
283 /* YYTNME[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM.
284 First, the terminals, then, starting at YYNTOKENS, nonterminals. */
285 static const char *const yytname
[] =
290 #define yytname_size ((int) (sizeof (yytname) / sizeof (yytname[0])))
293 /* YYR1[YYN] -- Symbol number of symbol that rule YYN derives. */
294 static const ]b4_int_type_for([b4_r1
])[ yyr1
[] =
299 /* YYR2[YYN] -- Number of symbols composing right hand side of rule YYN. */
300 static const ]b4_int_type_for([b4_r2
])[ yyr2
[] =
305 /* YYDPREC[RULE-NUM] -- Dynamic precedence of rule #RULE-NUM (0 if none). */
306 static const ]b4_int_type_for([b4_dprec
])[ yydprec
[] =
311 /* YYMERGER[RULE-NUM] -- Index of merging function for rule #RULE-NUM. */
312 static const ]b4_int_type_for([b4_merger
])[ yymerger
[] =
317 /* YYDEFACT[S] -- default rule to reduce with in state S when YYTABLE
318 doesn't specify something else to do. Zero means the default is an
320 static const ]b4_int_type_for([b4_defact
])[ yydefact
[] =
325 /* YYPDEFGOTO[NTERM-NUM]. */
326 static const ]b4_int_type_for([b4_defgoto
])[ yydefgoto
[] =
331 /* YYPACT[STATE-NUM] -- Index in YYTABLE of the portion describing
333 #define YYPACT_NINF ]b4_pact_ninf[
334 static const ]b4_int_type_for([b4_pact
])[ yypact
[] =
339 /* YYPGOTO[NTERM-NUM]. */
340 static const ]b4_int_type_for([b4_pgoto
])[ yypgoto
[] =
345 /* YYTABLE[YYPACT[STATE-NUM]]. What to do in state STATE-NUM. If
346 positive, shift that token. If negative, reduce the rule which
347 number is the opposite. If zero, do what YYDEFACT says.
348 If YYTABLE_NINF, parse error. */
349 #define YYTABLE_NINF ]b4_table_ninf[
350 static const ]b4_int_type_for([b4_table
])[ yytable
[] =
355 /* YYCONFLP[YYPACT[STATE-NUM]] -- Pointer into YYCONFL of start of
356 list of conflicting reductions corresponding to action entry for
357 state STATE-NUM in yytable. 0 means no conflicts. The list in
358 yyconfl is terminated by a rule number of 0. */
359 static const ]b4_int_type_for([b4_conflict_list_heads
])[ yyconflp
[] =
361 ]b4_conflict_list_heads
[
364 /* YYCONFL[I] -- lists of conflicting rule numbers, each terminated by
365 0, pointed into by YYCONFLP. */
366 ]dnl Do
not use b4_int_type_for here
, since there are places where
367 dnl pointers onto yyconfl are taken
, which type is
"short *".
368 dnl We probably ought to introduce a type
for confl
.
369 [static const short yyconfl
[] =
371 ]b4_conflicting_rules
[
374 static const ]b4_int_type_for([b4_check
])[ yycheck
[] =
380 /* The user can define YYPARSE_PARAM as the name of an argument to be passed
381 into yyparse. The argument should have type void *.
382 It should actually point to an object.
383 Grammar actions can access the variable by casting it
384 to the proper pointer type. */
387 # define YYPARSE_PARAM_ARG void *YYPARSE_PARAM
388 #else /* !YYPARSE_PARAM */
389 # define YYPARSE_PARAM_ARG void
390 #endif /* !YYPARSE_PARAM */
392 /* Prevent warning if -Wstrict-prototypes. */
394 # ifdef YYPARSE_PARAM
395 int yyparse (void *);
401 /* Error token number */
404 /* YYLLOC_DEFAULT -- Compute the default location (before the actions
407 #define YYRHSLOC(yyRhs,YYK) (yyRhs[YYK].yystate.yyloc)
409 #ifndef YYLLOC_DEFAULT
410 # define YYLLOC_DEFAULT(yyCurrent, yyRhs, YYN) \
411 yyCurrent.first_line = YYRHSLOC(yyRhs,1).first_line; \
412 yyCurrent.first_column = YYRHSLOC(yyRhs,1).first_column; \
413 yyCurrent.last_line = YYRHSLOC(yyRhs,YYN).last_line; \
414 yyCurrent.last_column = YYRHSLOC(yyRhs,YYN).last_column;
417 /* YYLEX -- calling `yylex' with the right arguments. */
418 #define YYLEX ]b4_c_function_call([yylex], [int], b4_lex_param)[
423 #define yynerrs (yystack->yyerrcnt)
425 #define yychar (yystack->yyrawchar)],
433 static const int YYEOF
= 0;
434 static const int YYEMPTY
= -2;
436 typedef enum { yyok
, yyaccept
, yyabort
, yyerr
} YYRESULTTAG
;
439 do { YYRESULTTAG yyflag = YYE; if (yyflag != yyok) return yyflag; } \
444 #if ! defined (YYFPRINTF)
445 # define YYFPRINTF fprintf
448 # define YYDPRINTF(Args) \
453 /* Nonzero means print parse trace. It is left uninitialized so that
454 multiple parsers can coexist. */
457 /* Avoid empty `if' bodies. */
458 # define YYDPRINTF(Args) {}
459 #endif /* !YYDEBUG */
461 /* YYINITDEPTH -- initial size of the parser's stacks. */
463 # define YYINITDEPTH ]b4_stack_depth_init[
466 /* YYMAXDEPTH -- maximum size the stacks can grow to (effective only
467 if the built-in stack extension method is used).
469 Do not make this value too large; the results are undefined if
470 SIZE_MAX < YYMAXDEPTH * sizeof (GLRStackItem)
471 evaluated with infinite-precision integer arithmetic. */
478 # define YYMAXDEPTH ]b4_stack_depth_max[
481 /* Minimum number of free items on the stack allowed after an
482 allocation. This is to allow allocation and initialization
483 to be completed by functions that call expandGLRStack before the
484 stack is expanded, thus insuring that all necessary pointers get
485 properly redirected to new data. */
488 #if ! defined (YYSTACKEXPANDABLE) \
489 && (! defined (__cplusplus) || (YYLTYPE_IS_TRIVIAL && YYSTYPE_IS_TRIVIAL))
490 #define YYSTACKEXPANDABLE 1
492 #define YYSTACKEXPANDABLE 0
495 /** State numbers, as in LALR(1) machine */
496 typedef int yyStateNum
;
498 /** Rule numbers, as in LALR(1) machine */
499 typedef int yyRuleNum
;
501 /** Grammar symbol */
502 typedef short yySymbol
;
504 /** Item references, as in LALR(1) machine */
505 typedef short yyItemNum
;
507 typedef struct yyGLRState yyGLRState
;
508 typedef struct yySemanticOption yySemanticOption
;
509 typedef union yyGLRStackItem yyGLRStackItem
;
510 typedef struct yyGLRStack yyGLRStack
;
511 typedef struct yyGLRStateSet yyGLRStateSet
;
516 yyStateNum yylrState
;
520 yySemanticOption
* yyfirstVal
;
526 struct yyGLRStateSet
{
527 yyGLRState
** yystates
;
528 size_t yysize
, yycapacity
;
531 struct yySemanticOption
{
535 yySemanticOption
* yynext
;
538 union yyGLRStackItem
{
540 yySemanticOption yyoption
;
552 jmp_buf yyexception_buffer
;
553 yyGLRStackItem
* yyitems
;
554 yyGLRStackItem
* yynextFree
;
556 yyGLRState
* yysplitPoint
;
557 yyGLRState
* yylastDeleted
;
558 yyGLRStateSet yytops
;
561 static void yyinitGLRStack (yyGLRStack
* yystack
, size_t yysize
);
562 static void yyexpandGLRStack (yyGLRStack
* yystack
);
563 static void yyfreeGLRStack (yyGLRStack
* yystack
);
566 yyFail (yyGLRStack
* yystack
, const char* yyformat
, ...)
568 if (yyformat
!= NULL
)
572 va_start (yyap
, yyformat
);
573 yystack
->yyerrflag
= 1;
574 vsprintf (yymsg
, yyformat
, yyap
);
577 longjmp (yystack
->yyexception_buffer
, 1);
580 #if YYDEBUG || YYERROR_VERBOSE
581 /** A printable representation of TOKEN. Valid until next call to
583 static inline const char*
584 yytokenName (yySymbol yytoken
)
586 return yytname
[yytoken
];
590 /** Perform user action for rule number YYN, with RHS length YYRHSLEN,
591 * and top stack item YYVSP. YYLVALP points to place to put semantic
592 * value ($$), and yylocp points to place for location information
593 * (@$). Returns yyok for normal return, yyaccept for YYACCEPT,
594 * yyerr for YYERROR, yyabort for YYABORT. */
596 yyuserAction (yyRuleNum yyn
, int yyrhslen
, yyGLRStackItem
* yyvsp
,
597 YYSTYPE
* yyvalp
, YYLTYPE
* yylocp
, yyGLRStack
* yystack
)
599 /* Avoid `unused' warnings in there are no $n. */
604 *yyvalp
= yyval_default
;
605 *yylocp
= yyloc_default
;
609 *yyvalp
= yyvsp
[1-yyrhslen
].yystate
.yysemantics
.yysval
;
610 *yylocp
= yyvsp
[1-yyrhslen
].yystate
.yyloc
;
613 # define yyval (*yyvalp)
615 # define yyerrok (yystack->yyerrState = 0)
617 # define YYACCEPT return yyaccept
619 # define YYABORT return yyabort
621 # define YYERROR return yyerr
623 # define YYRECOVERING (yystack->yyerrState != 0)
625 # define yyclearin (yychar = *(yystack->yytokenp) = YYEMPTY)
627 # define YYBACKUP(Token, Value) \
629 yyerror ("syntax error: cannot back up"); \
648 /* Line __line__ of __file__. */
649 #line __oline__ "__ofile__"
654 yyuserMerge (int yyn
, YYSTYPE
* yy0
, YYSTYPE
* yy1
)
656 YYSTYPE yyval
= *yy0
;
657 /* `Use' the arguments. */
668 /* Bison grammar-table manipulation */
670 /** Number of symbols composing the right hand side of rule #RULE. */
672 yyrhsLength (yyRuleNum yyrule
)
677 /** Left-hand-side symbol for rule #RULE. */
678 static inline yySymbol
679 yylhsNonterm (yyRuleNum yyrule
)
684 /** True iff LR state STATE has only a default reduction (regardless
687 yyisDefaultedState (yyStateNum yystate
)
689 return yypact
[yystate
] == YYPACT_NINF
;
692 /** The default reduction for STATE, assuming it has one. */
693 static inline yyRuleNum
694 yydefaultAction (yyStateNum yystate
)
696 return yydefact
[yystate
];
699 /** Set *YYACTION to the action to take in YYSTATE on seeing YYTOKEN.
701 * R < 0: Reduce on rule -R.
703 * R > 0: Shift to state R.
704 * Set *CONFLICTS to a pointer into yyconfl to 0-terminated list of
705 * conflicting reductions.
708 yygetLRActions (yyStateNum yystate
, int yytoken
,
709 int* yyaction
, const short** yyconflicts
)
711 int yyindex
= yypact
[yystate
] + yytoken
;
712 if (yyindex
< 0 || YYLAST
< yyindex
|| yycheck
[yyindex
] != yytoken
)
714 *yyaction
= -yydefact
[yystate
];
715 *yyconflicts
= yyconfl
;
717 else if (yytable
[yyindex
] != YYTABLE_NINF
)
719 *yyaction
= yytable
[yyindex
];
720 *yyconflicts
= yyconfl
+ yyconflp
[yyindex
];
725 *yyconflicts
= yyconfl
+ yyconflp
[yyindex
];
729 static inline yyStateNum
730 yyLRgotoState (yyStateNum yystate
, yySymbol yylhs
)
733 yyr
= yypgoto
[yylhs
- YYNTOKENS
] + yystate
;
734 if (0 <= yyr
&& yyr
<= YYLAST
&& yycheck
[yyr
] == yystate
)
737 return yydefgoto
[yylhs
- YYNTOKENS
];
741 yyisShiftAction (int yyaction
)
747 yyisErrorAction (int yyaction
)
749 return yyaction
== 0;
754 /** True iff the semantic value of the edge leading to STATE is
757 yyhasResolvedValue (yyGLRState
* yystate
)
759 return yystate
->yyresolved
;
763 yyaddDeferredAction (yyGLRStack
* yystack
, yyGLRState
* yystate
,
764 yyGLRState
* rhs
, yyRuleNum yyrule
)
766 yySemanticOption
* yynewItem
;
767 yynewItem
= &yystack
->yynextFree
->yyoption
;
768 yystack
->yyspaceLeft
-= 1;
769 yystack
->yynextFree
+= 1;
770 yynewItem
->yyisState
= yyfalse
;
771 yynewItem
->yystate
= rhs
;
772 yynewItem
->yyrule
= yyrule
;
773 yynewItem
->yynext
= yystate
->yysemantics
.yyfirstVal
;
774 yystate
->yysemantics
.yyfirstVal
= yynewItem
;
775 if (yystack
->yyspaceLeft
< YYHEADROOM
)
776 yyexpandGLRStack (yystack
);
781 /** Initialize SET to a singleton set containing an empty stack. */
783 yyinitStateSet (yyGLRStateSet
* yyset
)
786 yyset
->yycapacity
= 16;
787 yyset
->yystates
= (yyGLRState
**) malloc (16 * sizeof (yyset
->yystates
[0]));
788 yyset
->yystates
[0] = NULL
;
791 static void yyfreeStateSet (yyGLRStateSet
* yyset
)
793 free (yyset
->yystates
);
796 /** Initialize STACK to a single empty stack, with total maximum
797 * capacity for all stacks of SIZE. */
799 yyinitGLRStack (yyGLRStack
* yystack
, size_t yysize
)
801 yystack
->yyerrflag
= 0;
802 yystack
->yyerrState
= 0;
804 yystack
->yyspaceLeft
= yysize
;
805 yystack
->yynextFree
= yystack
->yyitems
=
806 (yyGLRStackItem
*) malloc (yysize
* sizeof (yystack
->yynextFree
[0]));
807 yystack
->yysplitPoint
= NULL
;
808 yystack
->yylastDeleted
= NULL
;
809 yyinitStateSet (&yystack
->yytops
);
812 #define YYRELOC(YYFROMITEMS,YYTOITEMS,YYX,YYTYPE) \
813 &((YYTOITEMS) - ((YYFROMITEMS) - (yyGLRStackItem*) (YYX)))->YYTYPE
815 /** If STACK is expandable, extend it. WARNING: Pointers into the
816 stack from outside should be considered invalid after this call.
817 We always expand when there are 1 or fewer items left AFTER an
818 allocation, so that we can avoid having external pointers exist
819 across an allocation. */
821 yyexpandGLRStack (yyGLRStack
* yystack
)
823 #if YYSTACKEXPANDABLE
824 yyGLRStack yynewStack
;
825 yyGLRStackItem
* yyp0
, *yyp1
;
826 size_t yysize
, yynewSize
;
828 yysize
= yystack
->yynextFree
- yystack
->yyitems
;
829 if (YYMAXDEPTH
<= yysize
)
830 yyFail (yystack
, "parsing stack overflow (%d items)", yysize
);
831 yynewSize
= 2*yysize
;
832 if (YYMAXDEPTH
< yynewSize
)
833 yynewSize
= YYMAXDEPTH
;
834 yyinitGLRStack (&yynewStack
, yynewSize
);
835 for (yyp0
= yystack
->yyitems
, yyp1
= yynewStack
.yyitems
, yyn
= yysize
;
837 yyn
-= 1, yyp0
+= 1, yyp1
+= 1)
842 yyGLRState
* yys0
= &yyp0
->yystate
;
843 yyGLRState
* yys1
= &yyp1
->yystate
;
844 if (yys0
->yypred
!= NULL
)
846 YYRELOC (yyp0
, yyp1
, yys0
->yypred
, yystate
);
847 if (! yys0
->yyresolved
&& yys0
->yysemantics
.yyfirstVal
!= NULL
)
848 yys1
->yysemantics
.yyfirstVal
=
849 YYRELOC(yyp0
, yyp1
, yys0
->yysemantics
.yyfirstVal
, yyoption
);
853 yySemanticOption
* yyv0
= &yyp0
->yyoption
;
854 yySemanticOption
* yyv1
= &yyp1
->yyoption
;
855 if (yyv0
->yystate
!= NULL
)
856 yyv1
->yystate
= YYRELOC (yyp0
, yyp1
, yyv0
->yystate
, yystate
);
857 if (yyv0
->yynext
!= NULL
)
858 yyv1
->yynext
= YYRELOC (yyp0
, yyp1
, yyv0
->yynext
, yyoption
);
861 if (yystack
->yysplitPoint
!= NULL
)
862 yystack
->yysplitPoint
= YYRELOC (yystack
->yyitems
, yynewStack
.yyitems
,
863 yystack
->yysplitPoint
, yystate
);
865 for (yyn
= 0; yyn
< yystack
->yytops
.yysize
; yyn
+= 1)
866 if (yystack
->yytops
.yystates
[yyn
] != NULL
)
867 yystack
->yytops
.yystates
[yyn
] =
868 YYRELOC (yystack
->yyitems
, yynewStack
.yyitems
,
869 yystack
->yytops
.yystates
[yyn
], yystate
);
870 free (yystack
->yyitems
);
871 yystack
->yyitems
= yynewStack
.yyitems
;
872 yystack
->yynextFree
= yynewStack
.yynextFree
+ yysize
;
873 yystack
->yyspaceLeft
= yynewStack
.yyspaceLeft
- yysize
;
877 yyFail (yystack
, "parsing stack overflow (%d items)", yysize
);
883 yyfreeGLRStack (yyGLRStack
* yystack
)
885 free (yystack
->yyitems
);
886 yyfreeStateSet (&yystack
->yytops
);
889 /** Assuming that S is a GLRState somewhere on STACK, update the
890 * splitpoint of STACK, if needed, so that it is at least as deep as
893 yyupdateSplit (yyGLRStack
* yystack
, yyGLRState
* yys
)
895 if (yystack
->yysplitPoint
!= NULL
&& yystack
->yysplitPoint
> yys
)
896 yystack
->yysplitPoint
= yys
;
899 /** Invalidate stack #K in STACK. */
901 yymarkStackDeleted (yyGLRStack
* yystack
, int yyk
)
903 if (yystack
->yytops
.yystates
[yyk
] != NULL
)
904 yystack
->yylastDeleted
= yystack
->yytops
.yystates
[yyk
];
905 yystack
->yytops
.yystates
[yyk
] = NULL
;
908 /** Undelete the last stack that was marked as deleted. Can only be
909 done once after a deletion, and only when all other stacks have
912 yyundeleteLastStack (yyGLRStack
* yystack
)
914 if (yystack
->yylastDeleted
== NULL
|| yystack
->yytops
.yysize
!= 0)
916 yystack
->yytops
.yystates
[0] = yystack
->yylastDeleted
;
917 yystack
->yytops
.yysize
= 1;
918 YYDPRINTF ((stderr
, "Restoring last deleted stack as stack #0.\n"));
919 yystack
->yylastDeleted
= NULL
;
923 yyremoveDeletes (yyGLRStack
* yystack
)
927 while (yyj
< yystack
->yytops
.yysize
)
929 if (yystack
->yytops
.yystates
[yyi
] == NULL
)
932 YYDPRINTF ((stderr
, "Removing dead stacks.\n"));
933 yystack
->yytops
.yysize
-= 1;
937 yystack
->yytops
.yystates
[yyj
] = yystack
->yytops
.yystates
[yyi
];
939 YYDPRINTF ((stderr
, "Rename stack %d -> %d.\n", yyi
, yyj
));
946 /** Shift to a new state on stack #K of STACK, corresponding to LR state
947 * LRSTATE, at input position POSN, with (resolved) semantic value SVAL. */
949 yyglrShift (yyGLRStack
* yystack
, int yyk
, yyStateNum yylrState
, size_t yyposn
,
950 YYSTYPE yysval
, YYLTYPE
* yylocp
)
952 yyGLRStackItem
* yynewItem
;
954 yynewItem
= yystack
->yynextFree
;
955 yystack
->yynextFree
+= 1;
956 yystack
->yyspaceLeft
-= 1;
957 yynewItem
->yystate
.yyisState
= yytrue
;
958 yynewItem
->yystate
.yylrState
= yylrState
;
959 yynewItem
->yystate
.yyposn
= yyposn
;
960 yynewItem
->yystate
.yyresolved
= yytrue
;
961 yynewItem
->yystate
.yypred
= yystack
->yytops
.yystates
[yyk
];
962 yystack
->yytops
.yystates
[yyk
] = &yynewItem
->yystate
;
963 yynewItem
->yystate
.yysemantics
.yysval
= yysval
;
964 yynewItem
->yystate
.yyloc
= *yylocp
;
965 if (yystack
->yyspaceLeft
< YYHEADROOM
)
966 yyexpandGLRStack (yystack
);
969 /** Shift to a new state on stack #K of STACK, to a new state
970 * corresponding to LR state LRSTATE, at input position POSN, with
971 * the (unresolved) semantic value of RHS under the action for RULE. */
973 yyglrShiftDefer (yyGLRStack
* yystack
, int yyk
, yyStateNum yylrState
,
974 size_t yyposn
, yyGLRState
* rhs
, yyRuleNum yyrule
)
976 yyGLRStackItem
* yynewItem
;
978 yynewItem
= yystack
->yynextFree
;
979 yynewItem
->yystate
.yyisState
= yytrue
;
980 yynewItem
->yystate
.yylrState
= yylrState
;
981 yynewItem
->yystate
.yyposn
= yyposn
;
982 yynewItem
->yystate
.yyresolved
= yyfalse
;
983 yynewItem
->yystate
.yypred
= yystack
->yytops
.yystates
[yyk
];
984 yynewItem
->yystate
.yysemantics
.yyfirstVal
= NULL
;
985 yystack
->yytops
.yystates
[yyk
] = &yynewItem
->yystate
;
986 yystack
->yynextFree
+= 1;
987 yystack
->yyspaceLeft
-= 1;
988 yyaddDeferredAction (yystack
, &yynewItem
->yystate
, rhs
, yyrule
);
991 /** Pop the symbols consumed by reduction #RULE from the top of stack
992 * #K of STACK, and perform the appropriate semantic action on their
993 * semantic values. Assumes that all ambiguities in semantic values
994 * have been previously resolved. Set *VALP to the resulting value,
995 * and *LOCP to the computed location (if any). Return value is as
998 yydoAction (yyGLRStack
* yystack
, int yyk
, yyRuleNum yyrule
,
999 YYSTYPE
* yyvalp
, YYLTYPE
* yylocp
)
1001 int yynrhs
= yyrhsLength (yyrule
);
1003 if (yystack
->yysplitPoint
== NULL
)
1005 /* Standard special case: single stack. */
1006 yyGLRStackItem
* rhs
= (yyGLRStackItem
*) yystack
->yytops
.yystates
[yyk
];
1008 yystack
->yynextFree
-= yynrhs
;
1009 yystack
->yyspaceLeft
+= yynrhs
;
1010 yystack
->yytops
.yystates
[0] = & yystack
->yynextFree
[-1].yystate
;
1013 *yyvalp
= yyval_default
;
1014 *yylocp
= yyloc_default
;
1018 *yyvalp
= rhs
[1-yynrhs
].yystate
.yysemantics
.yysval
;
1019 *yylocp
= rhs
[1-yynrhs
].yystate
.yyloc
;
1021 return yyuserAction (yyrule
, yynrhs
, rhs
, yyvalp
, yylocp
, yystack
);
1027 yyGLRStackItem yyrhsVals
[YYMAXRHS
];
1028 for (yyi
= yynrhs
-1, yys
= yystack
->yytops
.yystates
[yyk
]; 0 <= yyi
;
1029 yyi
-= 1, yys
= yys
->yypred
)
1031 assert (yys
->yypred
!= NULL
);
1032 yyrhsVals
[yyi
].yystate
.yyresolved
= yytrue
;
1033 yyrhsVals
[yyi
].yystate
.yysemantics
.yysval
= yys
->yysemantics
.yysval
;
1034 yyrhsVals
[yyi
].yystate
.yyloc
= yys
->yyloc
;
1036 yyupdateSplit (yystack
, yys
);
1037 yystack
->yytops
.yystates
[yyk
] = yys
;
1040 *yyvalp
= yyval_default
;
1041 *yylocp
= yyloc_default
;
1045 *yyvalp
= yyrhsVals
[0].yystate
.yysemantics
.yysval
;
1046 *yylocp
= yyrhsVals
[0].yystate
.yyloc
;
1048 return yyuserAction (yyrule
, yynrhs
, yyrhsVals
+ (yynrhs
-1),
1049 yyvalp
, yylocp
, yystack
);
1053 /** Pop items off stack #K of STACK according to grammar rule RULE,
1054 * and push back on the resulting nonterminal symbol. Perform the
1055 * semantic action associated with RULE and store its value with the
1056 * newly pushed state, if FORCEEVAL or if STACK is currently
1057 * unambiguous. Otherwise, store the deferred semantic action with
1058 * the new state. If the new state would have an identical input
1059 * position, LR state, and predecessor to an existing state on the stack,
1060 * it is identified with that existing state, eliminating stack #K from
1061 * the STACK. In this case, the (necessarily deferred) semantic value is
1062 * added to the options for the existing state's semantic value.
1064 static inline YYRESULTTAG
1065 yyglrReduce (yyGLRStack
* yystack
, size_t yyk
, yyRuleNum yyrule
,
1068 size_t yyposn
= yystack
->yytops
.yystates
[yyk
]->yyposn
;
1070 if (yyforceEval
|| yystack
->yysplitPoint
== NULL
)
1079 YYDPRINTF ((stderr
, "Reducing stack %d by rule %d (line %d),",
1080 yyk
, yyrule
- 1, yyrline
[yyrule
]));
1081 /* Print the symbols being reduced, and their result. */
1082 for (yyi
= yyprhs
[yyrule
]; 0 <= yyrhs
[yyi
]; yyi
++)
1083 YYFPRINTF (stderr
, "%s ", yytokenName (yyrhs
[yyi
]));
1084 YYFPRINTF (stderr
, " -> %s\n", yytokenName (yyr1
[yyrule
]));
1087 YYCHK (yydoAction (yystack
, yyk
, yyrule
, &yysval
, &yyloc
));
1088 yyglrShift (yystack
, yyk
,
1089 yyLRgotoState (yystack
->yytops
.yystates
[yyk
]->yylrState
,
1090 yylhsNonterm (yyrule
)),
1091 yyposn
, yysval
, &yyloc
);
1092 YYDPRINTF ((stderr
, "Stack %d entering state %d\n",
1093 yyk
, yystack
->yytops
.yystates
[yyk
]->yylrState
));
1099 yyGLRState
* yys
, *yys0
= yystack
->yytops
.yystates
[yyk
];
1100 yyStateNum yynewLRState
;
1102 for (yys
= yystack
->yytops
.yystates
[yyk
], yyn
= yyrhsLength (yyrule
);
1106 assert (yys
!= NULL
);
1108 yyupdateSplit (yystack
, yys
);
1109 yynewLRState
= yyLRgotoState (yys
->yylrState
, yylhsNonterm (yyrule
));
1111 "Reduced stack %d by rule #%d; action deferred. "
1112 "Now in state %d.\n",
1113 yyk
, yyrule
-1, yynewLRState
));
1114 for (yyi
= 0; yyi
< yystack
->yytops
.yysize
; yyi
+= 1)
1115 if (yyi
!= yyk
&& yystack
->yytops
.yystates
[yyi
] != NULL
)
1117 yyGLRState
* yyp
, *yysplit
= yystack
->yysplitPoint
;
1118 yyp
= yystack
->yytops
.yystates
[yyi
];
1119 while (yyp
!= yys
&& yyp
!= yysplit
&& yyp
->yyposn
>= yyposn
)
1121 if (yyp
->yylrState
== yynewLRState
&& yyp
->yypred
== yys
)
1123 yyaddDeferredAction (yystack
, yyp
, yys0
, yyrule
);
1124 yymarkStackDeleted (yystack
, yyk
);
1125 YYDPRINTF ((stderr
, "Merging stack %d into stack %d.\n",
1132 yystack
->yytops
.yystates
[yyk
] = yys
;
1133 yyglrShiftDefer (yystack
, yyk
, yynewLRState
, yyposn
, yys0
, yyrule
);
1139 yysplitStack (yyGLRStack
* yystack
, int yyk
)
1141 if (yystack
->yysplitPoint
== NULL
)
1144 yystack
->yysplitPoint
= yystack
->yytops
.yystates
[yyk
];
1146 if (yystack
->yytops
.yysize
>= yystack
->yytops
.yycapacity
)
1148 yystack
->yytops
.yycapacity
*= 2;
1149 yystack
->yytops
.yystates
=
1150 (yyGLRState
**) realloc (yystack
->yytops
.yystates
,
1151 yystack
->yytops
.yycapacity
1152 * sizeof (yyGLRState
*));
1154 yystack
->yytops
.yystates
[yystack
->yytops
.yysize
]
1155 = yystack
->yytops
.yystates
[yyk
];
1156 yystack
->yytops
.yysize
+= 1;
1157 return yystack
->yytops
.yysize
-1;
1160 /** True iff Y0 and Y1 represent identical options at the top level.
1161 * That is, they represent the same rule applied to RHS symbols
1162 * that produce the same terminal symbols. */
1164 yyidenticalOptions (yySemanticOption
* yyy0
, yySemanticOption
* yyy1
)
1166 if (yyy0
->yyrule
== yyy1
->yyrule
)
1168 yyGLRState
*yys0
, *yys1
;
1170 for (yys0
= yyy0
->yystate
, yys1
= yyy1
->yystate
,
1171 yyn
= yyrhsLength (yyy0
->yyrule
);
1173 yys0
= yys0
->yypred
, yys1
= yys1
->yypred
, yyn
-= 1)
1174 if (yys0
->yyposn
!= yys1
->yyposn
)
1182 /** Assuming identicalOptions (Y0,Y1), (destructively) merge the
1183 * alternative semantic values for the RHS-symbols of Y1 into the
1184 * corresponding semantic value sets of the symbols of Y0. */
1186 yymergeOptionSets (yySemanticOption
* yyy0
, yySemanticOption
* yyy1
)
1188 yyGLRState
*yys0
, *yys1
;
1190 for (yys0
= yyy0
->yystate
, yys1
= yyy1
->yystate
,
1191 yyn
= yyrhsLength (yyy0
->yyrule
);
1193 yys0
= yys0
->yypred
, yys1
= yys1
->yypred
, yyn
-= 1)
1196 else if (! yys0
->yyresolved
&& ! yys1
->yyresolved
)
1198 yySemanticOption
* yyz
;
1199 for (yyz
= yys0
->yysemantics
.yyfirstVal
; yyz
->yynext
!= NULL
;
1202 yyz
->yynext
= yys1
->yysemantics
.yyfirstVal
;
1206 /** Y0 and Y1 represent two possible actions to take in a given
1207 * parsing state; return 0 if no combination is possible,
1208 * 1 if user-mergeable, 2 if Y0 is preferred, 3 if Y1 is preferred. */
1210 yypreference (yySemanticOption
* y0
, yySemanticOption
* y1
)
1212 yyRuleNum r0
= y0
->yyrule
, r1
= y1
->yyrule
;
1213 int p0
= yydprec
[r0
], p1
= yydprec
[r1
];
1217 if (yymerger
[r0
] == 0 || yymerger
[r0
] != yymerger
[r1
])
1222 if (p0
== 0 || p1
== 0)
1231 static YYRESULTTAG
yyresolveValue (yySemanticOption
* yyoptionList
,
1232 yyGLRStack
* yystack
, YYSTYPE
* yyvalp
,
1236 yyresolveStates (yyGLRState
* yys
, int yyn
, yyGLRStack
* yystack
)
1241 assert (yys
->yypred
!= NULL
);
1242 yyflag
= yyresolveStates (yys
->yypred
, yyn
-1, yystack
);
1245 if (! yys
->yyresolved
)
1247 yyflag
= yyresolveValue (yys
->yysemantics
.yyfirstVal
, yystack
,
1248 &yys
->yysemantics
.yysval
, &yys
->yyloc
);
1251 yys
->yyresolved
= yytrue
;
1258 yyresolveAction (yySemanticOption
* yyopt
, yyGLRStack
* yystack
,
1259 YYSTYPE
* yyvalp
, YYLTYPE
* yylocp
)
1261 yyGLRStackItem yyrhsVals
[YYMAXRHS
];
1265 yynrhs
= yyrhsLength (yyopt
->yyrule
);
1266 YYCHK (yyresolveStates (yyopt
->yystate
, yynrhs
, yystack
));
1267 for (yyi
= yynrhs
-1, yys
= yyopt
->yystate
; 0 <= yyi
;
1268 yyi
-= 1, yys
= yys
->yypred
)
1270 assert (yys
->yypred
!= NULL
);
1271 yyrhsVals
[yyi
].yystate
.yyresolved
= yytrue
;
1272 yyrhsVals
[yyi
].yystate
.yysemantics
.yysval
= yys
->yysemantics
.yysval
;
1273 yyrhsVals
[yyi
].yystate
.yyloc
= yys
->yyloc
;
1275 return yyuserAction (yyopt
->yyrule
, yynrhs
, yyrhsVals
+ (yynrhs
-1),
1276 yyvalp
, yylocp
, yystack
);
1280 static yyGLRState YYLEFTMOST_STATE
=
1282 0, 0, -1, NULL
, 0, { NULL
},
1285 #if YYLTYPE_IS_TRIVIAL
1286 ]b4_location_if([ 0, 0, 0, 0])[
1291 static void yyreportTree (yySemanticOption
* yyx
, int yyindent
)
1293 int yynrhs
= yyrhsLength (yyx
->yyrule
);
1296 yyGLRState
* yystates
[YYMAXRHS
];
1298 for (yyi
= yynrhs
, yys
= yyx
->yystate
; 0 < yyi
; yyi
-= 1, yys
= yys
->yypred
)
1299 yystates
[yyi
] = yys
;
1301 yystates
[0] = &YYLEFTMOST_STATE
;
1305 if (yyx
->yystate
->yyposn
< yys
->yyposn
+ 1)
1306 YYFPRINTF (stderr
, "%*s%s -> <Rule %d, empty>\n",
1307 yyindent
, "", yytokenName (yylhsNonterm (yyx
->yyrule
)),
1310 YYFPRINTF (stderr
, "%*s%s -> <Rule %d, tokens %d .. %d>\n",
1311 yyindent
, "", yytokenName (yylhsNonterm (yyx
->yyrule
)),
1312 yyx
->yyrule
, yys
->yyposn
+1, yyx
->yystate
->yyposn
);
1313 for (yyi
= 1; yyi
<= yynrhs
; yyi
+= 1)
1315 if (yystates
[yyi
]->yyresolved
)
1317 if (yystates
[yyi
-1]->yyposn
+1 > yystates
[yyi
]->yyposn
)
1318 YYFPRINTF (stderr
, "%*s%s <empty>\n", yyindent
+2, "",
1319 yytokenName (yyrhs
[yyprhs
[yyx
->yyrule
]+yyi
-1]));
1321 YYFPRINTF (stderr
, "%*s%s <tokens %d .. %d>\n", yyindent
+2, "",
1322 yytokenName (yyrhs
[yyprhs
[yyx
->yyrule
]+yyi
-1]),
1323 yystates
[yyi
-1]->yyposn
+1, yystates
[yyi
]->yyposn
);
1326 yyreportTree (yystates
[yyi
]->yysemantics
.yyfirstVal
, yyindent
+2);
1332 yyreportAmbiguity (yySemanticOption
* yyx0
, yySemanticOption
* yyx1
,
1333 yyGLRStack
* yystack
)
1335 /* `Unused' warnings. */
1340 YYFPRINTF (stderr
, "Ambiguity detected.\n");
1341 YYFPRINTF (stderr
, "Option 1,\n");
1342 yyreportTree (yyx0
, 2);
1343 YYFPRINTF (stderr
, "\nOption 2,\n");
1344 yyreportTree (yyx1
, 2);
1345 YYFPRINTF (stderr
, "\n");
1347 yyFail (yystack
, "ambiguity detected");
1351 /** Resolve the ambiguity represented by OPTIONLIST, perform the indicated
1352 * actions, and return the result. */
1354 yyresolveValue (yySemanticOption
* yyoptionList
, yyGLRStack
* yystack
,
1355 YYSTYPE
* yyvalp
, YYLTYPE
* yylocp
)
1357 yySemanticOption
* yybest
;
1358 yySemanticOption
* yyp
;
1361 yybest
= yyoptionList
;
1363 for (yyp
= yyoptionList
->yynext
; yyp
!= NULL
; yyp
= yyp
->yynext
)
1365 if (yyidenticalOptions (yybest
, yyp
))
1366 yymergeOptionSets (yybest
, yyp
);
1368 switch (yypreference (yybest
, yyp
))
1371 yyreportAmbiguity (yybest
, yyp
, yystack
);
1387 int yyprec
= yydprec
[yybest
->yyrule
];
1388 YYCHK (yyresolveAction (yybest
, yystack
, yyvalp
, yylocp
));
1389 for (yyp
= yybest
->yynext
; yyp
!= NULL
; yyp
= yyp
->yynext
)
1391 if (yyprec
== yydprec
[yyp
->yyrule
])
1395 YYCHK (yyresolveAction (yyp
, yystack
, &yyval1
, &yydummy
));
1396 *yyvalp
= yyuserMerge (yymerger
[yyp
->yyrule
], yyvalp
, &yyval1
);
1402 return yyresolveAction (yybest
, yystack
, yyvalp
, yylocp
);
1406 yyresolveStack (yyGLRStack
* yystack
)
1408 if (yystack
->yysplitPoint
!= NULL
)
1413 for (yyn
= 0, yys
= yystack
->yytops
.yystates
[0];
1414 yys
!= yystack
->yysplitPoint
;
1415 yys
= yys
->yypred
, yyn
+= 1)
1417 YYCHK (yyresolveStates (yystack
->yytops
.yystates
[0], yyn
, yystack
));
1423 yycompressStack (yyGLRStack
* yystack
)
1425 yyGLRState
* yyp
, *yyq
, *yyr
;
1427 if (yystack
->yytops
.yysize
!= 1 || yystack
->yysplitPoint
== NULL
)
1430 for (yyp
= yystack
->yytops
.yystates
[0], yyq
= yyp
->yypred
, yyr
= NULL
;
1431 yyp
!= yystack
->yysplitPoint
;
1432 yyr
= yyp
, yyp
= yyq
, yyq
= yyp
->yypred
)
1435 yystack
->yyspaceLeft
+= yystack
->yynextFree
- yystack
->yyitems
;
1436 yystack
->yynextFree
= ((yyGLRStackItem
*) yystack
->yysplitPoint
) + 1;
1437 yystack
->yyspaceLeft
-= yystack
->yynextFree
- yystack
->yyitems
;
1438 yystack
->yysplitPoint
= NULL
;
1439 yystack
->yylastDeleted
= NULL
;
1443 yystack
->yynextFree
->yystate
= *yyr
;
1445 yystack
->yynextFree
->yystate
.yypred
= & yystack
->yynextFree
[-1].yystate
;
1446 yystack
->yytops
.yystates
[0] = &yystack
->yynextFree
->yystate
;
1447 yystack
->yynextFree
+= 1;
1448 yystack
->yyspaceLeft
-= 1;
1453 yyprocessOneStack (yyGLRStack
* yystack
, int yyk
,
1454 size_t yyposn
, YYSTYPE
* yylvalp
, YYLTYPE
* yyllocp
)
1457 const short* yyconflicts
;
1459 yySymbol
* const yytokenp
= yystack
->yytokenp
;
1461 while (yystack
->yytops
.yystates
[yyk
] != NULL
)
1463 yyStateNum yystate
= yystack
->yytops
.yystates
[yyk
]->yylrState
;
1465 assert (yystate
!= YYFINAL
);
1466 if (yyisDefaultedState (yystate
))
1468 yyrule
= yydefaultAction (yystate
);
1471 YYDPRINTF ((stderr
, "Stack %d dies.\n", yyk
));
1472 yymarkStackDeleted (yystack
, yyk
);
1475 YYCHK (yyglrReduce (yystack
, yyk
, yyrule
, yyfalse
));
1479 if (*yytokenp
== YYEMPTY
)
1481 YYDPRINTF ((stderr
, "Reading a token: "));
1483 *yytokenp
= YYTRANSLATE(yychar
);
1484 YYDPRINTF ((stderr
, "Next token is %s\n",
1485 yytokenName (*yytokenp
)));
1487 yygetLRActions (yystate
, *yytokenp
, &yyaction
, &yyconflicts
);
1489 while (*yyconflicts
!= 0)
1491 int yynewStack
= yysplitStack (yystack
, yyk
);
1492 YYDPRINTF ((stderr
, "Splitting off stack %d from %d.\n",
1494 YYCHK (yyglrReduce (yystack
, yynewStack
, *yyconflicts
, yyfalse
));
1495 YYCHK (yyprocessOneStack (yystack
, yynewStack
, yyposn
,
1500 if (yyisShiftAction (yyaction
))
1502 YYDPRINTF ((stderr
, "Shifting token %s on stack %d, ",
1503 yytokenName (*yytokenp
), yyk
));
1504 yyglrShift (yystack
, yyk
, yyaction
, yyposn
+1, *yylvalp
, yyllocp
);
1505 YYDPRINTF ((stderr
, "which is now in state #%d\n",
1506 yystack
->yytops
.yystates
[yyk
]->yylrState
));
1509 else if (yyisErrorAction (yyaction
))
1511 YYDPRINTF ((stderr
, "Stack %d dies.\n", yyk
));
1512 yymarkStackDeleted (yystack
, yyk
);
1516 YYCHK (yyglrReduce (yystack
, yyk
, -yyaction
, yyfalse
));
1523 yyreportParseError (yyGLRStack
* yystack
, YYSTYPE
* yylvalp
, YYLTYPE
* yyllocp
)
1525 /* `Unused' warnings. */
1529 if (yystack
->yyerrState
== 0)
1532 yySymbol
* const yytokenp
= yystack
->yytokenp
;
1533 int yyn
, yyx
, yycount
;
1535 const char* yyprefix
;
1538 yyn
= yypact
[yystack
->yytops
.yystates
[0]->yylrState
];
1539 if (YYPACT_NINF
< yyn
&& yyn
< YYLAST
)
1542 /* Start YYX at -YYN if negative to avoid negative indexes in
1544 yysize
= sizeof ("parse error, unexpected ")
1545 + strlen (yytokenName (*yytokenp
));
1546 yyprefix
= ", expecting ";
1547 for (yyx
= yyn
< 0 ? -yyn
: 0; yyx
< yytname_size
&& yycount
<= 5;
1549 if (yycheck
[yyx
+ yyn
] == yyx
&& yyx
!= YYTERROR
)
1550 yysize
+= strlen (yytokenName (yyx
)) + strlen (yyprefix
),
1551 yycount
+= 1, yyprefix
= " or ";
1552 yymsg
= yyp
= (char*) malloc (yysize
);
1553 sprintf (yyp
, "parse error, unexpected %s",
1554 yytokenName (*yytokenp
));
1555 yyp
+= strlen (yyp
);
1558 yyprefix
= ", expecting ";
1559 for (yyx
= yyn
< 0 ? -yyn
: 0; yyx
< yytname_size
; yyx
+= 1)
1560 if (yycheck
[yyx
+ yyn
] == yyx
&& yyx
!= YYTERROR
)
1562 sprintf (yyp
, "%s%s", yyprefix
, yytokenName (yyx
));
1563 yyp
+= strlen (yyp
);
1572 yyerror ("parse error");
1577 /* Recover from a syntax error on YYSTACK, assuming that YYTOKENP,
1578 YYLVALP, and YYLLOCP point to the syntactic category, semantic
1579 value, and location of the lookahead. */
1581 yyrecoverParseError (yyGLRStack
* yystack
, YYSTYPE
* yylvalp
, YYLTYPE
* yyllocp
)
1583 yySymbol
* const yytokenp
= yystack
->yytokenp
;
1587 if (yystack
->yyerrState
== 0)
1588 yystack
->yyerrState
= 3;
1589 else if (yystack
->yyerrState
== 3)
1590 /* We just shifted the error token and (perhaps) took some
1591 reductions. Skip tokens until we can proceed. */
1594 if (*yytokenp
== YYEOF
)
1595 yyFail (yystack
, NULL
);
1596 if (*yytokenp
!= YYEMPTY
)
1597 YYDPRINTF ((stderr
, "Discarding token %s\n",
1598 yytokenName (*yytokenp
)));
1599 YYDPRINTF ((stderr
, "Reading a token: "));
1601 *yytokenp
= YYTRANSLATE (yychar
);
1602 YYDPRINTF ((stderr
, "Next token is %s\n", yytokenName (*yytokenp
)));
1603 yyj
= yypact
[yystack
->yytops
.yystates
[0]->yylrState
];
1604 if (yyj
== YYPACT_NINF
)
1605 /* Something's not right; we shouldn't be here. */
1606 yyFail (yystack
, NULL
);
1608 if (yyj
< 0 || YYLAST
< yyj
|| yycheck
[yyj
] != *yytokenp
)
1610 if (yydefact
[yystack
->yytops
.yystates
[0]->yylrState
] != 0)
1613 else if (yytable
[yyj
] != 0 && yytable
[yyj
] != YYTABLE_NINF
)
1617 /* Reduce to one stack. */
1618 for (yyk
= 0; yyk
< yystack
->yytops
.yysize
; yyk
+= 1)
1619 if (yystack
->yytops
.yystates
[yyk
] != NULL
)
1621 if (yyk
>= yystack
->yytops
.yysize
)
1622 yyFail (yystack
, NULL
);
1623 for (yyk
+= 1; yyk
< yystack
->yytops
.yysize
; yyk
+= 1)
1624 yymarkStackDeleted (yystack
, yyk
);
1625 yyremoveDeletes (yystack
);
1626 yycompressStack (yystack
);
1628 /* Now pop stack until we find a state that shifts the error token. */
1629 while (yystack
->yytops
.yystates
[0] != NULL
)
1631 yyj
= yypact
[yystack
->yytops
.yystates
[0]->yylrState
] + YYTERROR
;
1632 if (yyj
!= YYPACT_NINF
+ YYTERROR
&& yyj
>= 0 && yyj
<= YYLAST
&&
1633 yycheck
[yyj
] == YYTERROR
&& yyisShiftAction (yytable
[yyj
]))
1635 yyglrShift (yystack
, 0, yytable
[yyj
],
1636 yystack
->yytops
.yystates
[0]->yyposn
, *yylvalp
, yyllocp
);
1639 yystack
->yytops
.yystates
[0] = yystack
->yytops
.yystates
[0]->yypred
;
1640 yystack
->yynextFree
-= 1;
1641 yystack
->yyspaceLeft
+= 1;
1643 if (yystack
->yytops
.yystates
[0] == NULL
)
1644 yyFail (yystack
, NULL
);
1647 #define YYCHK1(YYE) \
1653 yystack.yyerrflag = 1; \
1656 yystack.yyerrflag = 0; \
1659 goto yyuser_error; \
1664 yyparse (YYPARSE_PARAM_ARG
)
1674 #define yychar (yystack.yyrawchar)
1677 YYSTYPE
* const yylvalp
= &yylval
;
1678 YYLTYPE
* const yyllocp
= &yylloc
;
1680 yyinitGLRStack (&yystack
, YYINITDEPTH
);
1681 yystack
.yytokenp
= &yytoken
;
1683 YYDPRINTF ((stderr
, "Starting parse\n"));
1685 if (setjmp (yystack
.yyexception_buffer
) != 0)
1688 yyglrShift (&yystack
, 0, 0, 0, yyval_default
, &yyloc_default
);
1694 /* For efficiency, we have two loops, the first of which is
1695 specialized to deterministic operation (single stack, no
1696 potential ambiguity). */
1703 const short* yyconflicts
;
1705 yyStateNum yystate
= yystack
.yytops
.yystates
[0]->yylrState
;
1706 if (yystate
== YYFINAL
)
1708 if (yyisDefaultedState (yystate
))
1710 yyrule
= yydefaultAction (yystate
);
1713 yyreportParseError (&yystack
, yylvalp
, yyllocp
);
1716 YYCHK1 (yyglrReduce (&yystack
, 0, yyrule
, yytrue
));
1720 if (yytoken
== YYEMPTY
)
1722 YYDPRINTF ((stderr
, "Reading a token: "));
1724 yytoken
= YYTRANSLATE (yychar
);
1725 YYDPRINTF ((stderr
, "Next token is %s\n",
1726 yytokenName (yytoken
)));
1728 yygetLRActions (yystate
, yytoken
, &yyaction
, &yyconflicts
);
1729 if (*yyconflicts
!= 0)
1731 if (yyisShiftAction (yyaction
))
1733 YYDPRINTF ((stderr
, "Shifting token %s, ",
1734 yytokenName (yytoken
)));
1735 if (yytoken
!= YYEOF
)
1738 yyglrShift (&yystack
, 0, yyaction
, yyposn
, yylval
, yyllocp
);
1739 if (0 < yystack
.yyerrState
)
1740 yystack
.yyerrState
-= 1;
1741 YYDPRINTF ((stderr
, "Entering state %d\n",
1742 yystack
.yytops
.yystates
[0]->yylrState
));
1744 else if (yyisErrorAction (yyaction
))
1746 yyreportParseError (&yystack
, yylvalp
, yyllocp
);
1750 YYCHK1 (yyglrReduce (&yystack
, 0, -yyaction
, yytrue
));
1757 int yyn
= yystack
.yytops
.yysize
;
1758 for (yys
= 0; yys
< yyn
; yys
+= 1)
1759 YYCHK1 (yyprocessOneStack (&yystack
, yys
, yyposn
,
1763 yyremoveDeletes (&yystack
);
1764 if (yystack
.yytops
.yysize
== 0)
1766 yyundeleteLastStack (&yystack
);
1767 if (yystack
.yytops
.yysize
== 0)
1768 yyFail (&yystack
, "parse error");
1769 YYCHK1 (yyresolveStack (&yystack
));
1770 YYDPRINTF ((stderr
, "Returning to deterministic operation.\n"));
1771 yyreportParseError (&yystack
, yylvalp
, yyllocp
);
1774 else if (yystack
.yytops
.yysize
== 1)
1776 YYCHK1 (yyresolveStack (&yystack
));
1777 YYDPRINTF ((stderr
, "Returning to deterministic operation.\n"));
1778 yycompressStack (&yystack
);
1784 yyrecoverParseError (&yystack
, yylvalp
, yyllocp
);
1785 yyposn
= yystack
.yytops
.yystates
[0]->yyposn
;
1790 yyfreeGLRStack (&yystack
);
1791 return yystack
.yyerrflag
;
1794 /* DEBUGGING ONLY */
1795 static void yypstack (yyGLRStack
* yystack
, int yyk
) ATTRIBUTE_UNUSED
;
1796 static void yypdumpstack (yyGLRStack
* yystack
) ATTRIBUTE_UNUSED
;
1799 yy_yypstack (yyGLRState
* yys
)
1803 yy_yypstack (yys
->yypred
);
1804 fprintf (stderr
, " -> ");
1806 fprintf (stderr
, "%d@%lu", yys
->yylrState
, (unsigned long) yys
->yyposn
);
1810 yypstates (yyGLRState
* yyst
)
1813 fprintf (stderr
, "<null>");
1816 fprintf (stderr
, "\n");
1820 yypstack (yyGLRStack
* yystack
, int yyk
)
1822 yypstates (yystack
->yytops
.yystates
[yyk
]);
1825 #define YYINDEX(YYX) \
1826 ((YYX) == NULL ? -1 : (yyGLRStackItem*) (YYX) - yystack->yyitems)
1830 yypdumpstack (yyGLRStack
* yystack
)
1832 yyGLRStackItem
* yyp
;
1834 for (yyp
= yystack
->yyitems
; yyp
< yystack
->yynextFree
; yyp
+= 1)
1836 fprintf (stderr
, "%3lu. ", (unsigned long) (yyp
- yystack
->yyitems
));
1839 fprintf (stderr
, "Res: %d, LR State: %d, posn: %lu, pred: %ld",
1840 yyp
->yystate
.yyresolved
, yyp
->yystate
.yylrState
,
1841 (unsigned long) yyp
->yystate
.yyposn
,
1842 (long) YYINDEX (yyp
->yystate
.yypred
));
1843 if (! yyp
->yystate
.yyresolved
)
1844 fprintf (stderr
, ", firstVal: %ld",
1845 (long) YYINDEX (yyp
->yystate
.yysemantics
.yyfirstVal
));
1849 fprintf (stderr
, "Option. rule: %d, state: %ld, next: %ld",
1850 yyp
->yyoption
.yyrule
,
1851 (long) YYINDEX (yyp
->yyoption
.yystate
),
1852 (long) YYINDEX (yyp
->yyoption
.yynext
));
1854 fprintf (stderr
, "\n");
1856 fprintf (stderr
, "Tops:");
1857 for (yyi
= 0; yyi
< yystack
->yytops
.yysize
; yyi
+= 1)
1858 fprintf (stderr
, "%lu: %ld; ", (unsigned long) yyi
,
1859 (long) YYINDEX (yystack
->yytops
.yystates
[yyi
]));
1860 fprintf (stderr
, "\n");
1866 m4_if(b4_defines_flag
, 0, [],
1867 [#output "b4_output_header_name"
1868 b4_copyright([Skeleton parser
for GLR parsing with Bison
], [2002])
1869 #ifndef b4_header_guard
1870 # define b4_header_guard
1872 b4_token_defines(b4_tokens
)
1875 m4_ifdef([b4_stype
],
1876 [#line b4_stype_line "b4_filename"
1877 typedef union b4_stype yystype
;
1878 /* Line __line__ of __file__. */
1879 #line __oline__ "__ofile__"],
1880 [typedef int yystype
;])
1881 # define YYSTYPE yystype
1885 [extern YYSTYPE b4_prefix
[]lval
;])
1889 typedef struct yyltype
1896 # define YYLTYPE yyltype
1900 [extern YYLTYPE b4_prefix
[]lloc
;])
1902 #endif /* not b4_header_guard */