1 m4_divert(-1) -*- C
-*-
4 # GLR skeleton for Bison
5 # Copyright (C) 2002 Free Software Foundation, Inc.
7 # This program is free software; you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; either version 2 of the License, or
10 # (at your option) any later version.
12 # This program is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
17 # You should have received a copy of the GNU General Public License
18 # along with this program; if not, write to the Free Software
19 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
23 ## ---------------- ##
25 ## ---------------- ##
28 m4_define_default([b4_stack_depth_max
], [10000])
29 m4_define_default([b4_stack_depth_init
], [200])
32 m4_define_default([b4_location_type
], [yyltype
])
36 ## ----------------- ##
37 ## Semantic Values. ##
38 ## ----------------- ##
41 # b4_lhs_value([TYPE])
42 # --------------------
43 # Expansion of $<TYPE>$.
44 m4_define([b4_lhs_value
],
45 [(*yyvalp
)[]m4_ifval([$
1], [.$
1])])
48 # b4_rhs_value(RULE-LENGTH, NUM, [TYPE])
49 # --------------------------------------
50 # Expansion of $<TYPE>NUM, where the current rule has RULE-LENGTH
52 m4_define([b4_rhs_value
],
53 [yyvsp@
<:@
m4_eval([$
2 - $
1])@
:>@
.yystate
.yysemantics
.yysval
[]m4_ifval([$
3], [.$
3])])
61 # b4_location_if(IF-TRUE, IF-FALSE)
62 # ---------------------------------
63 # Expand IF-TRUE, if locations are used, IF-FALSE otherwise.
64 m4_define([b4_location_if
],
65 [m4_if(b4_locations_flag
, [1],
73 m4_define([b4_lhs_location
],
77 # b4_rhs_location(RULE-LENGTH, NUM)
78 # ---------------------------------
79 # Expansion of @NUM, where the current rule has RULE-LENGTH symbols
81 m4_define([b4_rhs_location
],
82 [yyvsp@
<:@
m4_eval([$
2 - $
1])@
:>@
.yystate
.yyloc
])
90 # b4_pure_if(IF-TRUE, IF-FALSE)
91 # -----------------------------
92 # Expand IF-TRUE, if %pure-parser, IF-FALSE otherwise.
93 m4_define([b4_pure_if
],
99 ## ------------------- ##
100 ## Output file names. ##
101 ## ------------------- ##
103 m4_define_default([b4_input_suffix
], [.y
])
105 m4_define_default([b4_output_parser_suffix
],
106 [m4_translit(b4_input_suffix
, [yY
], [cC
])])
108 m4_define_default([b4_output_parser_name
],
109 [b4_output_prefix
[]b4_output_infix
[]b4_output_parser_suffix
[]])
112 m4_define_default([b4_output_header_suffix
],
113 [m4_translit(b4_input_suffix
, [yY
], [hH
])])
115 m4_define_default([b4_output_header_name
],
116 [b4_output_prefix
[]b4_output_infix
[]b4_output_header_suffix
[]])
118 m4_define_default([b4_header_guard
],
119 [m4_bpatsubst(m4_toupper([BISON_
]b4_output_header_name
),
120 [[^ABCDEFGHIJKLMNOPQRSTUVWXYZ
]], [_
])])
124 #output "b4_output_parser_name"
125 b4_copyright([Skeleton parser
for GLR parsing with Bison
], [2002])
127 /* This is the parser code for GLR (Generalized LR) parser. */
129 /* FIXME: minimize these */
137 /* Identify Bison output. */
141 #define YYPURE ]b4_pure[
143 /* Using locations. */
144 #define YYLSP_NEEDED ]b4_locations_flag[
146 ]m4_if(b4_prefix
[], [yy
], [],
147 [/* If NAME_PREFIX is specified substitute the variables and functions
149 #define yyparse b4_prefix[]parse
150 #define yylex b4_prefix[]lex
151 #define yyerror b4_prefix[]error
152 #define yylval b4_prefix[]lval
153 #define yychar b4_prefix[]char
154 #define yydebug b4_prefix[]debug
155 #define yynerrs b4_prefix[]nerrs
156 b4_location_if([#define yylloc b4_prefix[]lloc])])
158 b4_token_defines(b4_tokens
)
160 /* Copy the first part of user declarations. */
163 /* Enabling traces. */
165 # define YYDEBUG ]b4_debug[
168 /* Enabling verbose error messages. */
169 #ifdef YYERROR_VERBOSE
170 # undef YYERROR_VERBOSE
171 # define YYERROR_VERBOSE 1
173 # define YYERROR_VERBOSE ]b4_error_verbose[
177 ]m4_ifdef([b4_stype
],
178 [#line b4_stype_line "b4_filename"
179 typedef union b4_stype yystype
;
180 /* Line __line__ of __file__. */
181 #line __oline__ "__ofile__"],
182 [typedef int yystype
;])[
183 # define YYSTYPE yystype
184 # define YYSTYPE_IS_TRIVIAL 1
188 typedef struct yyltype
196 # define YYLTYPE ]b4_location_type[
197 # define YYLTYPE_IS_TRIVIAL 1
200 /* Default (constant) values used for initialization for null
201 right-hand sides. Unlike the standard bison.simple template,
202 here we set the default values of the $$ and $@ to zeroed-out
203 values. Since the default value of these quantities is undefined,
204 this behavior is technically correct. */
205 static YYSTYPE yyval_default
;
206 static YYLTYPE yyloc_default
;
208 /* Copy the second part of user declarations. */
211 ]/* Line __line__ of __file__. */
212 #line __oline__ "__ofile__"
214 #if ! defined (__cplusplus)
220 #if defined (__STDC__) || defined (__cplusplus)
221 typedef signed char yysigned_char
;
223 typedef short yysigned_char
;
230 #ifndef __attribute__
231 /* This feature is available in gcc versions 2.5 and later. */
232 # if !defined (__GNUC__) || __GNUC__ < 2 || \
233 (__GNUC__ == 2 && __GNUC_MINOR__ < 5) || __STRICT_ANSI__
234 # define __attribute__(Spec) /* empty */
238 #ifndef ATTRIBUTE_UNUSED
239 # define ATTRIBUTE_UNUSED __attribute__ ((__unused__))
242 #if ! defined (__GNUC__)
246 /* YYFINAL -- State number of the termination state. */
247 #define YYFINAL ]b4_final_state_number[
248 #define YYLAST ]b4_last[
250 /* YYNTOKENS -- Number of terminals. */
251 #define YYNTOKENS ]b4_tokens_number[
252 /* YYNNTS -- Number of nonterminals. */
253 #define YYNNTS ]b4_nterms_number[
254 /* YYNRULES -- Number of rules. */
255 #define YYNRULES ]b4_rules_number[
256 /* YYNRULES -- Number of states. */
257 #define YYNSTATES ]b4_states_number[
258 /* YYMAXRHS -- Maximum number of symbols on right-hand side of rule. */
259 #define YYMAXRHS ]b4_r2_max[
261 /* YYTRANSLATE(X) -- Bison symbol number corresponding to X. */
262 #define YYUNDEFTOK ]b4_undef_token_number[
263 #define YYMAXUTOK ]b4_user_token_number_max[
265 #define YYTRANSLATE(YYX) \
266 ((unsigned)(YYX) <= YYMAXUTOK ? yytranslate[YYX] : YYUNDEFTOK)
268 /* YYTRANSLATE[YYLEX] -- Bison symbol number corresponding to YYLEX. */
269 static const ]b4_int_type_for([b4_translate
])[ yytranslate
[] =
275 /* YYPRHS[YYN] -- Index of the first RHS symbol of rule number YYN in
277 static const ]b4_int_type_for([b4_prhs
])[ yyprhs
[] =
282 /* YYRHS -- A `-1'-separated list of the rules' RHS. */
283 static const ]b4_int_type_for([b4_rhs
])[ yyrhs
[] =
288 /* YYRLINE[YYN] -- source line where rule number YYN was defined. */
289 static const ]b4_int_type_for([b4_rline
])[ yyrline
[] =
295 #if (YYDEBUG) || YYERROR_VERBOSE
296 /* YYTNME[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM.
297 First, the terminals, then, starting at YYNTOKENS, nonterminals. */
298 static const char *const yytname
[] =
303 #define yytname_size ((int) (sizeof (yytname) / sizeof (yytname[0])))
306 /* YYR1[YYN] -- Symbol number of symbol that rule YYN derives. */
307 static const ]b4_int_type_for([b4_r1
])[ yyr1
[] =
312 /* YYR2[YYN] -- Number of symbols composing right hand side of rule YYN. */
313 static const ]b4_int_type_for([b4_r2
])[ yyr2
[] =
318 /* YYDPREC[RULE-NUM] -- Dynamic precedence of rule #RULE-NUM (0 if none). */
319 static const ]b4_int_type_for([b4_dprec
])[ yydprec
[] =
324 /* YYMERGER[RULE-NUM] -- Index of merging function for rule #RULE-NUM. */
325 static const ]b4_int_type_for([b4_merger
])[ yymerger
[] =
330 /* YYDEFACT[S] -- default rule to reduce with in state S when YYTABLE
331 doesn't specify something else to do. Zero means the default is an
333 static const ]b4_int_type_for([b4_defact
])[ yydefact
[] =
338 /* YYPDEFGOTO[NTERM-NUM]. */
339 static const ]b4_int_type_for([b4_defgoto
])[ yydefgoto
[] =
344 /* YYPACT[STATE-NUM] -- Index in YYTABLE of the portion describing
346 #define YYPACT_NINF ]b4_pact_ninf[
347 static const ]b4_int_type_for([b4_pact
])[ yypact
[] =
352 /* YYPGOTO[NTERM-NUM]. */
353 static const ]b4_int_type_for([b4_pgoto
])[ yypgoto
[] =
358 /* YYTABLE[YYPACT[STATE-NUM]]. What to do in state STATE-NUM. If
359 positive, shift that token. If negative, reduce the rule which
360 number is the opposite. If zero, do what YYDEFACT says.
361 If YYTABLE_NINF, parse error. */
362 #define YYTABLE_NINF ]b4_table_ninf[
363 static const ]b4_int_type_for([b4_table
])[ yytable
[] =
368 /* YYCONFLP[YYPACT[STATE-NUM]] -- Pointer into YYCONFL of start of
369 list of conflicting reductions corresponding to action entry for
370 state STATE-NUM in yytable. 0 means no conflicts. The list in
371 yyconfl is terminated by a rule number of 0. */
372 static const ]b4_int_type_for([b4_conflict_list_heads
])[ yyconflp
[] =
374 ]b4_conflict_list_heads
[
377 /* YYCONFL[I] -- lists of conflicting rule numbers, each terminated by
378 0, pointed into by YYCONFLP. */
379 ]dnl Do
not use b4_int_type_for here
, since there are places where
380 dnl pointers onto yyconfl are taken
, which type is
"short *".
381 dnl We probably ought to introduce a type
for confl
.
382 [static const short yyconfl
[] =
384 ]b4_conflicting_rules
[
387 static const ]b4_int_type_for([b4_check
])[ yycheck
[] =
393 /* The user can define YYPARSE_PARAM as the name of an argument to be passed
394 into yyparse. The argument should have type void *.
395 It should actually point to an object.
396 Grammar actions can access the variable by casting it
397 to the proper pointer type. */
400 # define YYPARSE_PARAM_ARG void *YYPARSE_PARAM
401 #else /* !YYPARSE_PARAM */
402 # define YYPARSE_PARAM_ARG void
403 #endif /* !YYPARSE_PARAM */
405 /* Prevent warning if -Wstrict-prototypes. */
407 # ifdef YYPARSE_PARAM
408 int yyparse (void *);
414 /* Error token number */
417 /* YYLLOC_DEFAULT -- Compute the default location (before the actions
420 #define YYRHSLOC(yyRhs,YYK) (yyRhs[YYK].yystate.yyloc)
422 #ifndef YYLLOC_DEFAULT
423 # define YYLLOC_DEFAULT(yyCurrent, yyRhs, YYN) \
424 yyCurrent.first_line = YYRHSLOC(yyRhs,1).first_line; \
425 yyCurrent.first_column = YYRHSLOC(yyRhs,1).first_column; \
426 yyCurrent.last_line = YYRHSLOC(yyRhs,YYN).last_line; \
427 yyCurrent.last_column = YYRHSLOC(yyRhs,YYN).last_column;
430 /* YYLEX -- calling `yylex' with the right arguments. */
435 # define YYLEX yylex (yylvalp, b4_location_if([yyllocp, ])YYLEX_PARAM)
437 # define YYLEX yylex (yylvalp[]b4_location_if([, yyllocp]))
439 [#define YYLEX yylex ()])
444 #define yynerrs (yystack->yyerrcnt)
446 #define yychar (yystack->yyrawchar)],
454 static const int YYEOF
= 0;
455 static const int YYEMPTY
= -2;
457 typedef enum { yyok
, yyaccept
, yyabort
, yyerr
} YYRESULTTAG
;
460 do { YYRESULTTAG yyflag = YYE; if (yyflag != yyok) return yyflag; } \
465 #if ! defined (YYFPRINTF)
466 # define YYFPRINTF fprintf
469 # define YYDPRINTF(Args) \
474 /* Nonzero means print parse trace. It is left uninitialized so that
475 multiple parsers can coexist. */
478 /* Avoid empty `if' bodies. */
479 # define YYDPRINTF(Args) {}
480 #endif /* !YYDEBUG */
482 /* YYINITDEPTH -- initial size of the parser's stacks. */
484 # define YYINITDEPTH ]b4_stack_depth_init[
487 /* YYMAXDEPTH -- maximum size the stacks can grow to (effective only
488 if the built-in stack extension method is used).
490 Do not make this value too large; the results are undefined if
491 SIZE_MAX < YYMAXDEPTH * sizeof (GLRStackItem)
492 evaluated with infinite-precision integer arithmetic. */
499 # define YYMAXDEPTH ]b4_stack_depth_max[
502 /* Minimum number of free items on the stack allowed after an
503 allocation. This is to allow allocation and initialization
504 to be completed by functions that call expandGLRStack before the
505 stack is expanded, thus insuring that all necessary pointers get
506 properly redirected to new data. */
509 #if ! defined (YYSTACKEXPANDABLE) \
510 && (! defined (__cplusplus) || (YYLTYPE_IS_TRIVIAL && YYSTYPE_IS_TRIVIAL))
511 #define YYSTACKEXPANDABLE 1
513 #define YYSTACKEXPANDABLE 0
516 /** State numbers, as in LALR(1) machine */
517 typedef int yyStateNum
;
519 /** Rule numbers, as in LALR(1) machine */
520 typedef int yyRuleNum
;
522 /** Grammar symbol */
523 typedef short yySymbol
;
525 /** Item references, as in LALR(1) machine */
526 typedef short yyItemNum
;
528 typedef struct yyGLRState yyGLRState
;
529 typedef struct yySemanticOption yySemanticOption
;
530 typedef union yyGLRStackItem yyGLRStackItem
;
531 typedef struct yyGLRStack yyGLRStack
;
532 typedef struct yyGLRStateSet yyGLRStateSet
;
537 yyStateNum yylrState
;
541 yySemanticOption
* yyfirstVal
;
547 struct yyGLRStateSet
{
548 yyGLRState
** yystates
;
549 size_t yysize
, yycapacity
;
552 struct yySemanticOption
{
556 yySemanticOption
* yynext
;
559 union yyGLRStackItem
{
561 yySemanticOption yyoption
;
573 jmp_buf yyexception_buffer
;
574 yyGLRStackItem
* yyitems
;
575 yyGLRStackItem
* yynextFree
;
577 yyGLRState
* yysplitPoint
;
578 yyGLRState
* yylastDeleted
;
579 yyGLRStateSet yytops
;
582 static void yyinitGLRStack (yyGLRStack
* yystack
, size_t yysize
);
583 static void yyexpandGLRStack (yyGLRStack
* yystack
);
584 static void yyfreeGLRStack (yyGLRStack
* yystack
);
587 yyFail (yyGLRStack
* yystack
, const char* yyformat
, ...)
589 if (yyformat
!= NULL
)
593 va_start (yyap
, yyformat
);
594 yystack
->yyerrflag
= 1;
595 vsprintf (yymsg
, yyformat
, yyap
);
598 longjmp (yystack
->yyexception_buffer
, 1);
601 #if YYDEBUG || YYERROR_VERBOSE
602 /** A printable representation of TOKEN. Valid until next call to
604 static inline const char*
605 yytokenName (yySymbol yytoken
)
607 return yytname
[yytoken
];
611 /** Perform user action for rule number YYN, with RHS length YYRHSLEN,
612 * and top stack item YYVSP. YYLVALP points to place to put semantic
613 * value ($$), and yylocp points to place for location information
614 * (@$). Returns yyok for normal return, yyaccept for YYACCEPT,
615 * yyerr for YYERROR, yyabort for YYABORT. */
617 yyuserAction (yyRuleNum yyn
, int yyrhslen
, yyGLRStackItem
* yyvsp
,
618 YYSTYPE
* yyvalp
, YYLTYPE
* yylocp
, yyGLRStack
* yystack
)
620 /* Avoid `unused' warnings in there are no $n. */
625 *yyvalp
= yyval_default
;
626 *yylocp
= yyloc_default
;
630 *yyvalp
= yyvsp
[1-yyrhslen
].yystate
.yysemantics
.yysval
;
631 *yylocp
= yyvsp
[1-yyrhslen
].yystate
.yyloc
;
634 # define yyval (*yyvalp)
636 # define yyerrok (yystack->yyerrState = 0)
638 # define YYACCEPT return yyaccept
640 # define YYABORT return yyabort
642 # define YYERROR return yyerr
644 # define YYRECOVERING (yystack->yyerrState != 0)
646 # define yyclearin (yychar = *(yystack->yytokenp) = YYEMPTY)
648 # define YYBACKUP(Token, Value) \
650 yyerror ("syntax error: cannot back up"); \
669 /* Line __line__ of __file__. */
670 #line __oline__ "__ofile__"
675 yyuserMerge (int yyn
, YYSTYPE
* yy0
, YYSTYPE
* yy1
)
677 YYSTYPE yyval
= *yy0
;
678 /* `Use' the arguments. */
689 /* Bison grammar-table manipulation */
691 /** Number of symbols composing the right hand side of rule #RULE. */
693 yyrhsLength (yyRuleNum yyrule
)
698 /** Left-hand-side symbol for rule #RULE. */
699 static inline yySymbol
700 yylhsNonterm (yyRuleNum yyrule
)
705 /** True iff LR state STATE has only a default reduction (regardless
708 yyisDefaultedState (yyStateNum yystate
)
710 return yypact
[yystate
] == YYPACT_NINF
;
713 /** The default reduction for STATE, assuming it has one. */
714 static inline yyRuleNum
715 yydefaultAction (yyStateNum yystate
)
717 return yydefact
[yystate
];
720 /** Set *YYACTION to the action to take in YYSTATE on seeing YYTOKEN.
722 * R < 0: Reduce on rule -R.
724 * R > 0: Shift to state R.
725 * Set *CONFLICTS to a pointer into yyconfl to 0-terminated list of
726 * conflicting reductions.
729 yygetLRActions (yyStateNum yystate
, int yytoken
,
730 int* yyaction
, const short** yyconflicts
)
732 int yyindex
= yypact
[yystate
] + yytoken
;
733 if (yyindex
< 0 || YYLAST
< yyindex
|| yycheck
[yyindex
] != yytoken
)
735 *yyaction
= -yydefact
[yystate
];
736 *yyconflicts
= yyconfl
;
738 else if (yytable
[yyindex
] != YYTABLE_NINF
)
740 *yyaction
= yytable
[yyindex
];
741 *yyconflicts
= yyconfl
+ yyconflp
[yyindex
];
746 *yyconflicts
= yyconfl
+ yyconflp
[yyindex
];
750 static inline yyStateNum
751 yyLRgotoState (yyStateNum yystate
, yySymbol yylhs
)
754 yyr
= yypgoto
[yylhs
- YYNTOKENS
] + yystate
;
755 if (0 <= yyr
&& yyr
<= YYLAST
&& yycheck
[yyr
] == yystate
)
758 return yydefgoto
[yylhs
- YYNTOKENS
];
762 yyisShiftAction (int yyaction
)
768 yyisErrorAction (int yyaction
)
770 return yyaction
== 0;
775 /** True iff the semantic value of the edge leading to STATE is
778 yyhasResolvedValue (yyGLRState
* yystate
)
780 return yystate
->yyresolved
;
784 yyaddDeferredAction (yyGLRStack
* yystack
, yyGLRState
* yystate
,
785 yyGLRState
* rhs
, yyRuleNum yyrule
)
787 yySemanticOption
* yynewItem
;
788 yynewItem
= &yystack
->yynextFree
->yyoption
;
789 yystack
->yyspaceLeft
-= 1;
790 yystack
->yynextFree
+= 1;
791 yynewItem
->yyisState
= yyfalse
;
792 yynewItem
->yystate
= rhs
;
793 yynewItem
->yyrule
= yyrule
;
794 yynewItem
->yynext
= yystate
->yysemantics
.yyfirstVal
;
795 yystate
->yysemantics
.yyfirstVal
= yynewItem
;
796 if (yystack
->yyspaceLeft
< YYHEADROOM
)
797 yyexpandGLRStack (yystack
);
802 /** Initialize SET to a singleton set containing an empty stack. */
804 yyinitStateSet (yyGLRStateSet
* yyset
)
807 yyset
->yycapacity
= 16;
808 yyset
->yystates
= (yyGLRState
**) malloc (16 * sizeof (yyset
->yystates
[0]));
809 yyset
->yystates
[0] = NULL
;
812 static void yyfreeStateSet (yyGLRStateSet
* yyset
)
814 free (yyset
->yystates
);
817 /** Initialize STACK to a single empty stack, with total maximum
818 * capacity for all stacks of SIZE. */
820 yyinitGLRStack (yyGLRStack
* yystack
, size_t yysize
)
822 yystack
->yyerrflag
= 0;
823 yystack
->yyerrState
= 0;
825 yystack
->yyspaceLeft
= yysize
;
826 yystack
->yynextFree
= yystack
->yyitems
=
827 (yyGLRStackItem
*) malloc (yysize
* sizeof (yystack
->yynextFree
[0]));
828 yystack
->yysplitPoint
= NULL
;
829 yystack
->yylastDeleted
= NULL
;
830 yyinitStateSet (&yystack
->yytops
);
833 #define YYRELOC(YYFROMITEMS,YYTOITEMS,YYX,YYTYPE) \
834 &((YYTOITEMS) - ((YYFROMITEMS) - (yyGLRStackItem*) (YYX)))->YYTYPE
836 /** If STACK is expandable, extend it. WARNING: Pointers into the
837 stack from outside should be considered invalid after this call.
838 We always expand when there are 1 or fewer items left AFTER an
839 allocation, so that we can avoid having external pointers exist
840 across an allocation. */
842 yyexpandGLRStack (yyGLRStack
* yystack
)
844 #if YYSTACKEXPANDABLE
845 yyGLRStack yynewStack
;
846 yyGLRStackItem
* yyp0
, *yyp1
;
847 size_t yysize
, yynewSize
;
849 yysize
= yystack
->yynextFree
- yystack
->yyitems
;
850 if (yysize
>= YYMAXDEPTH
)
851 yyFail (yystack
, "parsing stack overflow (%d items)", yysize
);
852 yynewSize
= 2*yysize
;
853 if (yynewSize
> YYMAXDEPTH
)
854 yynewSize
= YYMAXDEPTH
;
855 yyinitGLRStack (&yynewStack
, yynewSize
);
856 for (yyp0
= yystack
->yyitems
, yyp1
= yynewStack
.yyitems
, yyn
= yysize
;
858 yyn
-= 1, yyp0
+= 1, yyp1
+= 1)
863 yyGLRState
* yys0
= &yyp0
->yystate
;
864 yyGLRState
* yys1
= &yyp1
->yystate
;
865 if (yys0
->yypred
!= NULL
)
867 YYRELOC (yyp0
, yyp1
, yys0
->yypred
, yystate
);
868 if (! yys0
->yyresolved
&& yys0
->yysemantics
.yyfirstVal
!= NULL
)
869 yys1
->yysemantics
.yyfirstVal
=
870 YYRELOC(yyp0
, yyp1
, yys0
->yysemantics
.yyfirstVal
, yyoption
);
874 yySemanticOption
* yyv0
= &yyp0
->yyoption
;
875 yySemanticOption
* yyv1
= &yyp1
->yyoption
;
876 if (yyv0
->yystate
!= NULL
)
877 yyv1
->yystate
= YYRELOC (yyp0
, yyp1
, yyv0
->yystate
, yystate
);
878 if (yyv0
->yynext
!= NULL
)
879 yyv1
->yynext
= YYRELOC (yyp0
, yyp1
, yyv0
->yynext
, yyoption
);
882 if (yystack
->yysplitPoint
!= NULL
)
883 yystack
->yysplitPoint
= YYRELOC (yystack
->yyitems
, yynewStack
.yyitems
,
884 yystack
->yysplitPoint
, yystate
);
886 for (yyn
= 0; yyn
< yystack
->yytops
.yysize
; yyn
+= 1)
887 if (yystack
->yytops
.yystates
[yyn
] != NULL
)
888 yystack
->yytops
.yystates
[yyn
] =
889 YYRELOC (yystack
->yyitems
, yynewStack
.yyitems
,
890 yystack
->yytops
.yystates
[yyn
], yystate
);
891 free (yystack
->yyitems
);
892 yystack
->yyitems
= yynewStack
.yyitems
;
893 yystack
->yynextFree
= yynewStack
.yynextFree
+ yysize
;
894 yystack
->yyspaceLeft
= yynewStack
.yyspaceLeft
- yysize
;
898 yyFail (yystack
, "parsing stack overflow (%d items)", yysize
);
904 yyfreeGLRStack (yyGLRStack
* yystack
)
906 free (yystack
->yyitems
);
907 yyfreeStateSet (&yystack
->yytops
);
910 /** Assuming that S is a GLRState somewhere on STACK, update the
911 * splitpoint of STACK, if needed, so that it is at least as deep as
914 yyupdateSplit (yyGLRStack
* yystack
, yyGLRState
* yys
)
916 if (yystack
->yysplitPoint
!= NULL
&& yystack
->yysplitPoint
> yys
)
917 yystack
->yysplitPoint
= yys
;
920 /** Invalidate stack #K in STACK. */
922 yymarkStackDeleted (yyGLRStack
* yystack
, int yyk
)
924 if (yystack
->yytops
.yystates
[yyk
] != NULL
)
925 yystack
->yylastDeleted
= yystack
->yytops
.yystates
[yyk
];
926 yystack
->yytops
.yystates
[yyk
] = NULL
;
929 /** Undelete the last stack that was marked as deleted. Can only be
930 done once after a deletion, and only when all other stacks have
933 yyundeleteLastStack (yyGLRStack
* yystack
)
935 if (yystack
->yylastDeleted
== NULL
|| yystack
->yytops
.yysize
!= 0)
937 yystack
->yytops
.yystates
[0] = yystack
->yylastDeleted
;
938 yystack
->yytops
.yysize
= 1;
939 YYDPRINTF ((stderr
, "Restoring last deleted stack as stack #0.\n"));
940 yystack
->yylastDeleted
= NULL
;
944 yyremoveDeletes (yyGLRStack
* yystack
)
948 while (yyj
< yystack
->yytops
.yysize
)
950 if (yystack
->yytops
.yystates
[yyi
] == NULL
)
953 YYDPRINTF ((stderr
, "Removing dead stacks.\n"));
954 yystack
->yytops
.yysize
-= 1;
958 yystack
->yytops
.yystates
[yyj
] = yystack
->yytops
.yystates
[yyi
];
960 YYDPRINTF ((stderr
, "Rename stack %d -> %d.\n", yyi
, yyj
));
967 /** Shift to a new state on stack #K of STACK, corresponding to LR state
968 * LRSTATE, at input position POSN, with (resolved) semantic value SVAL. */
970 yyglrShift (yyGLRStack
* yystack
, int yyk
, yyStateNum yylrState
, size_t yyposn
,
971 YYSTYPE yysval
, YYLTYPE
* yylocp
)
973 yyGLRStackItem
* yynewItem
;
975 yynewItem
= yystack
->yynextFree
;
976 yystack
->yynextFree
+= 1;
977 yystack
->yyspaceLeft
-= 1;
978 yynewItem
->yystate
.yyisState
= yytrue
;
979 yynewItem
->yystate
.yylrState
= yylrState
;
980 yynewItem
->yystate
.yyposn
= yyposn
;
981 yynewItem
->yystate
.yyresolved
= yytrue
;
982 yynewItem
->yystate
.yypred
= yystack
->yytops
.yystates
[yyk
];
983 yystack
->yytops
.yystates
[yyk
] = &yynewItem
->yystate
;
984 yynewItem
->yystate
.yysemantics
.yysval
= yysval
;
985 yynewItem
->yystate
.yyloc
= *yylocp
;
986 if (yystack
->yyspaceLeft
< YYHEADROOM
)
987 yyexpandGLRStack (yystack
);
990 /** Shift to a new state on stack #K of STACK, to a new state
991 * corresponding to LR state LRSTATE, at input position POSN, with
992 * the (unresolved) semantic value of RHS under the action for RULE. */
994 yyglrShiftDefer (yyGLRStack
* yystack
, int yyk
, yyStateNum yylrState
,
995 size_t yyposn
, yyGLRState
* rhs
, yyRuleNum yyrule
)
997 yyGLRStackItem
* yynewItem
;
999 yynewItem
= yystack
->yynextFree
;
1000 yynewItem
->yystate
.yyisState
= yytrue
;
1001 yynewItem
->yystate
.yylrState
= yylrState
;
1002 yynewItem
->yystate
.yyposn
= yyposn
;
1003 yynewItem
->yystate
.yyresolved
= yyfalse
;
1004 yynewItem
->yystate
.yypred
= yystack
->yytops
.yystates
[yyk
];
1005 yynewItem
->yystate
.yysemantics
.yyfirstVal
= NULL
;
1006 yystack
->yytops
.yystates
[yyk
] = &yynewItem
->yystate
;
1007 yystack
->yynextFree
+= 1;
1008 yystack
->yyspaceLeft
-= 1;
1009 yyaddDeferredAction (yystack
, &yynewItem
->yystate
, rhs
, yyrule
);
1012 /** Pop the symbols consumed by reduction #RULE from the top of stack
1013 * #K of STACK, and perform the appropriate semantic action on their
1014 * semantic values. Assumes that all ambiguities in semantic values
1015 * have been previously resolved. Set *VALP to the resulting value,
1016 * and *LOCP to the computed location (if any). Return value is as
1017 * for userAction. */
1019 yydoAction (yyGLRStack
* yystack
, int yyk
, yyRuleNum yyrule
,
1020 YYSTYPE
* yyvalp
, YYLTYPE
* yylocp
)
1022 int yynrhs
= yyrhsLength (yyrule
);
1024 if (yystack
->yysplitPoint
== NULL
)
1026 /* Standard special case: single stack. */
1027 yyGLRStackItem
* rhs
= (yyGLRStackItem
*) yystack
->yytops
.yystates
[yyk
];
1029 yystack
->yynextFree
-= yynrhs
;
1030 yystack
->yyspaceLeft
+= yynrhs
;
1031 yystack
->yytops
.yystates
[0] = & yystack
->yynextFree
[-1].yystate
;
1034 *yyvalp
= yyval_default
;
1035 *yylocp
= yyloc_default
;
1039 *yyvalp
= rhs
[1-yynrhs
].yystate
.yysemantics
.yysval
;
1040 *yylocp
= rhs
[1-yynrhs
].yystate
.yyloc
;
1042 return yyuserAction (yyrule
, yynrhs
, rhs
, yyvalp
, yylocp
, yystack
);
1048 yyGLRStackItem yyrhsVals
[YYMAXRHS
];
1049 for (yyi
= yynrhs
-1, yys
= yystack
->yytops
.yystates
[yyk
]; yyi
>= 0;
1050 yyi
-= 1, yys
= yys
->yypred
)
1052 assert (yys
->yypred
!= NULL
);
1053 yyrhsVals
[yyi
].yystate
.yyresolved
= yytrue
;
1054 yyrhsVals
[yyi
].yystate
.yysemantics
.yysval
= yys
->yysemantics
.yysval
;
1055 yyrhsVals
[yyi
].yystate
.yyloc
= yys
->yyloc
;
1057 yyupdateSplit (yystack
, yys
);
1058 yystack
->yytops
.yystates
[yyk
] = yys
;
1061 *yyvalp
= yyval_default
;
1062 *yylocp
= yyloc_default
;
1066 *yyvalp
= yyrhsVals
[0].yystate
.yysemantics
.yysval
;
1067 *yylocp
= yyrhsVals
[0].yystate
.yyloc
;
1069 return yyuserAction (yyrule
, yynrhs
, yyrhsVals
+ (yynrhs
-1),
1070 yyvalp
, yylocp
, yystack
);
1074 /** Pop items off stack #K of STACK according to grammar rule RULE,
1075 * and push back on the resulting nonterminal symbol. Perform the
1076 * semantic action associated with RULE and store its value with the
1077 * newly pushed state, if FORCEEVAL or if STACK is currently
1078 * unambiguous. Otherwise, store the deferred semantic action with
1079 * the new state. If the new state would have an identical input
1080 * position, LR state, and predecessor to an existing state on the stack,
1081 * it is identified with that existing state, eliminating stack #K from
1082 * the STACK. In this case, the (necessarily deferred) semantic value is
1083 * added to the options for the existing state's semantic value.
1085 static inline YYRESULTTAG
1086 yyglrReduce (yyGLRStack
* yystack
, size_t yyk
, yyRuleNum yyrule
,
1089 size_t yyposn
= yystack
->yytops
.yystates
[yyk
]->yyposn
;
1091 if (yyforceEval
|| yystack
->yysplitPoint
== NULL
)
1100 YYDPRINTF ((stderr
, "Reducing stack %d by rule %d (line %d),",
1101 yyk
, yyrule
- 1, yyrline
[yyrule
]));
1102 /* Print the symbols being reduced, and their result. */
1103 for (yyi
= yyprhs
[yyrule
]; yyrhs
[yyi
] >= 0; yyi
++)
1104 YYFPRINTF (stderr
, "%s ", yytokenName (yyrhs
[yyi
]));
1105 YYFPRINTF (stderr
, " -> %s\n", yytokenName (yyr1
[yyrule
]));
1108 YYCHK (yydoAction (yystack
, yyk
, yyrule
, &yysval
, &yyloc
));
1109 yyglrShift (yystack
, yyk
,
1110 yyLRgotoState (yystack
->yytops
.yystates
[yyk
]->yylrState
,
1111 yylhsNonterm (yyrule
)),
1112 yyposn
, yysval
, &yyloc
);
1113 YYDPRINTF ((stderr
, "Stack %d entering state %d\n",
1114 yyk
, yystack
->yytops
.yystates
[yyk
]->yylrState
));
1120 yyGLRState
* yys
, *yys0
= yystack
->yytops
.yystates
[yyk
];
1121 yyStateNum yynewLRState
;
1123 for (yys
= yystack
->yytops
.yystates
[yyk
], yyn
= yyrhsLength (yyrule
);
1127 assert (yys
!= NULL
);
1129 yyupdateSplit (yystack
, yys
);
1130 yynewLRState
= yyLRgotoState (yys
->yylrState
, yylhsNonterm (yyrule
));
1132 "Reduced stack %d by rule #%d; action deferred. "
1133 "Now in state %d.\n",
1134 yyk
, yyrule
-1, yynewLRState
));
1135 for (yyi
= 0; yyi
< yystack
->yytops
.yysize
; yyi
+= 1)
1136 if (yyi
!= yyk
&& yystack
->yytops
.yystates
[yyi
] != NULL
)
1138 yyGLRState
* yyp
, *yysplit
= yystack
->yysplitPoint
;
1139 yyp
= yystack
->yytops
.yystates
[yyi
];
1140 while (yyp
!= yys
&& yyp
!= yysplit
&& yyp
->yyposn
>= yyposn
)
1142 if (yyp
->yylrState
== yynewLRState
&& yyp
->yypred
== yys
)
1144 yyaddDeferredAction (yystack
, yyp
, yys0
, yyrule
);
1145 yymarkStackDeleted (yystack
, yyk
);
1146 YYDPRINTF ((stderr
, "Merging stack %d into stack %d.\n",
1153 yystack
->yytops
.yystates
[yyk
] = yys
;
1154 yyglrShiftDefer (yystack
, yyk
, yynewLRState
, yyposn
, yys0
, yyrule
);
1160 yysplitStack (yyGLRStack
* yystack
, int yyk
)
1162 if (yystack
->yysplitPoint
== NULL
)
1165 yystack
->yysplitPoint
= yystack
->yytops
.yystates
[yyk
];
1167 if (yystack
->yytops
.yysize
>= yystack
->yytops
.yycapacity
)
1169 yystack
->yytops
.yycapacity
*= 2;
1170 yystack
->yytops
.yystates
=
1171 (yyGLRState
**) realloc (yystack
->yytops
.yystates
,
1172 yystack
->yytops
.yycapacity
1173 * sizeof (yyGLRState
*));
1175 yystack
->yytops
.yystates
[yystack
->yytops
.yysize
]
1176 = yystack
->yytops
.yystates
[yyk
];
1177 yystack
->yytops
.yysize
+= 1;
1178 return yystack
->yytops
.yysize
-1;
1181 /** True iff Y0 and Y1 represent identical options at the top level.
1182 * That is, they represent the same rule applied to RHS symbols
1183 * that produce the same terminal symbols. */
1185 yyidenticalOptions (yySemanticOption
* yyy0
, yySemanticOption
* yyy1
)
1187 if (yyy0
->yyrule
== yyy1
->yyrule
)
1189 yyGLRState
*yys0
, *yys1
;
1191 for (yys0
= yyy0
->yystate
, yys1
= yyy1
->yystate
,
1192 yyn
= yyrhsLength (yyy0
->yyrule
);
1194 yys0
= yys0
->yypred
, yys1
= yys1
->yypred
, yyn
-= 1)
1195 if (yys0
->yyposn
!= yys1
->yyposn
)
1203 /** Assuming identicalOptions (Y0,Y1), (destructively) merge the
1204 * alternative semantic values for the RHS-symbols of Y1 into the
1205 * corresponding semantic value sets of the symbols of Y0. */
1207 yymergeOptionSets (yySemanticOption
* yyy0
, yySemanticOption
* yyy1
)
1209 yyGLRState
*yys0
, *yys1
;
1211 for (yys0
= yyy0
->yystate
, yys1
= yyy1
->yystate
,
1212 yyn
= yyrhsLength (yyy0
->yyrule
);
1214 yys0
= yys0
->yypred
, yys1
= yys1
->yypred
, yyn
-= 1)
1217 else if (! yys0
->yyresolved
&& ! yys1
->yyresolved
)
1219 yySemanticOption
* yyz
;
1220 for (yyz
= yys0
->yysemantics
.yyfirstVal
; yyz
->yynext
!= NULL
;
1223 yyz
->yynext
= yys1
->yysemantics
.yyfirstVal
;
1227 /** Y0 and Y1 represent two possible actions to take in a given
1228 * parsing state; return 0 if no combination is possible,
1229 * 1 if user-mergeable, 2 if Y0 is preferred, 3 if Y1 is preferred. */
1231 yypreference (yySemanticOption
* y0
, yySemanticOption
* y1
)
1233 yyRuleNum r0
= y0
->yyrule
, r1
= y1
->yyrule
;
1234 int p0
= yydprec
[r0
], p1
= yydprec
[r1
];
1238 if (yymerger
[r0
] == 0 || yymerger
[r0
] != yymerger
[r1
])
1243 if (p0
== 0 || p1
== 0)
1252 static YYRESULTTAG
yyresolveValue (yySemanticOption
* yyoptionList
,
1253 yyGLRStack
* yystack
, YYSTYPE
* yyvalp
,
1257 yyresolveStates (yyGLRState
* yys
, int yyn
, yyGLRStack
* yystack
)
1262 assert (yys
->yypred
!= NULL
);
1263 yyflag
= yyresolveStates (yys
->yypred
, yyn
-1, yystack
);
1266 if (! yys
->yyresolved
)
1268 yyflag
= yyresolveValue (yys
->yysemantics
.yyfirstVal
, yystack
,
1269 &yys
->yysemantics
.yysval
, &yys
->yyloc
);
1272 yys
->yyresolved
= yytrue
;
1279 yyresolveAction (yySemanticOption
* yyopt
, yyGLRStack
* yystack
,
1280 YYSTYPE
* yyvalp
, YYLTYPE
* yylocp
)
1282 yyGLRStackItem yyrhsVals
[YYMAXRHS
];
1286 yynrhs
= yyrhsLength (yyopt
->yyrule
);
1287 YYCHK (yyresolveStates (yyopt
->yystate
, yynrhs
, yystack
));
1288 for (yyi
= yynrhs
-1, yys
= yyopt
->yystate
; yyi
>= 0;
1289 yyi
-= 1, yys
= yys
->yypred
)
1291 assert (yys
->yypred
!= NULL
);
1292 yyrhsVals
[yyi
].yystate
.yyresolved
= yytrue
;
1293 yyrhsVals
[yyi
].yystate
.yysemantics
.yysval
= yys
->yysemantics
.yysval
;
1294 yyrhsVals
[yyi
].yystate
.yyloc
= yys
->yyloc
;
1296 return yyuserAction (yyopt
->yyrule
, yynrhs
, yyrhsVals
+ (yynrhs
-1),
1297 yyvalp
, yylocp
, yystack
);
1301 static yyGLRState YYLEFTMOST_STATE
=
1303 0, 0, -1, NULL
, 0, { NULL
},
1306 #if YYLTYPE_IS_TRIVIAL
1307 ]b4_location_if([ 0, 0, 0, 0])[
1312 static void yyreportTree (yySemanticOption
* yyx
, int yyindent
)
1314 int yynrhs
= yyrhsLength (yyx
->yyrule
);
1317 yyGLRState
* yystates
[YYMAXRHS
];
1319 for (yyi
= yynrhs
, yys
= yyx
->yystate
; yyi
> 0; yyi
-= 1, yys
= yys
->yypred
)
1320 yystates
[yyi
] = yys
;
1322 yystates
[0] = &YYLEFTMOST_STATE
;
1326 if (yys
->yyposn
+1 > yyx
->yystate
->yyposn
)
1327 YYFPRINTF (stderr
, "%*s%s -> <Rule %d, empty>\n",
1328 yyindent
, "", yytokenName (yylhsNonterm (yyx
->yyrule
)),
1331 YYFPRINTF (stderr
, "%*s%s -> <Rule %d, tokens %d .. %d>\n",
1332 yyindent
, "", yytokenName (yylhsNonterm (yyx
->yyrule
)),
1333 yyx
->yyrule
, yys
->yyposn
+1, yyx
->yystate
->yyposn
);
1334 for (yyi
= 1; yyi
<= yynrhs
; yyi
+= 1)
1336 if (yystates
[yyi
]->yyresolved
)
1338 if (yystates
[yyi
-1]->yyposn
+1 > yystates
[yyi
]->yyposn
)
1339 YYFPRINTF (stderr
, "%*s%s <empty>\n", yyindent
+2, "",
1340 yytokenName (yyrhs
[yyprhs
[yyx
->yyrule
]+yyi
-1]));
1342 YYFPRINTF (stderr
, "%*s%s <tokens %d .. %d>\n", yyindent
+2, "",
1343 yytokenName (yyrhs
[yyprhs
[yyx
->yyrule
]+yyi
-1]),
1344 yystates
[yyi
-1]->yyposn
+1, yystates
[yyi
]->yyposn
);
1347 yyreportTree (yystates
[yyi
]->yysemantics
.yyfirstVal
, yyindent
+2);
1353 yyreportAmbiguity (yySemanticOption
* yyx0
, yySemanticOption
* yyx1
,
1354 yyGLRStack
* yystack
)
1356 /* `Unused' warnings. */
1361 YYFPRINTF (stderr
, "Ambiguity detected.\n");
1362 YYFPRINTF (stderr
, "Option 1,\n");
1363 yyreportTree (yyx0
, 2);
1364 YYFPRINTF (stderr
, "\nOption 2,\n");
1365 yyreportTree (yyx1
, 2);
1366 YYFPRINTF (stderr
, "\n");
1368 yyFail (yystack
, "ambiguity detected");
1372 /** Resolve the ambiguity represented by OPTIONLIST, perform the indicated
1373 * actions, and return the result. */
1375 yyresolveValue (yySemanticOption
* yyoptionList
, yyGLRStack
* yystack
,
1376 YYSTYPE
* yyvalp
, YYLTYPE
* yylocp
)
1378 yySemanticOption
* yybest
;
1379 yySemanticOption
* yyp
;
1382 yybest
= yyoptionList
;
1384 for (yyp
= yyoptionList
->yynext
; yyp
!= NULL
; yyp
= yyp
->yynext
)
1386 if (yyidenticalOptions (yybest
, yyp
))
1387 yymergeOptionSets (yybest
, yyp
);
1389 switch (yypreference (yybest
, yyp
))
1392 yyreportAmbiguity (yybest
, yyp
, yystack
);
1408 int yyprec
= yydprec
[yybest
->yyrule
];
1409 YYCHK (yyresolveAction (yybest
, yystack
, yyvalp
, yylocp
));
1410 for (yyp
= yybest
->yynext
; yyp
!= NULL
; yyp
= yyp
->yynext
)
1412 if (yyprec
== yydprec
[yyp
->yyrule
])
1416 YYCHK (yyresolveAction (yyp
, yystack
, &yyval1
, &yydummy
));
1417 *yyvalp
= yyuserMerge (yymerger
[yyp
->yyrule
], yyvalp
, &yyval1
);
1423 return yyresolveAction (yybest
, yystack
, yyvalp
, yylocp
);
1427 yyresolveStack (yyGLRStack
* yystack
)
1429 if (yystack
->yysplitPoint
!= NULL
)
1434 for (yyn
= 0, yys
= yystack
->yytops
.yystates
[0];
1435 yys
!= yystack
->yysplitPoint
;
1436 yys
= yys
->yypred
, yyn
+= 1)
1438 YYCHK (yyresolveStates (yystack
->yytops
.yystates
[0], yyn
, yystack
));
1444 yycompressStack (yyGLRStack
* yystack
)
1446 yyGLRState
* yyp
, *yyq
, *yyr
;
1448 if (yystack
->yytops
.yysize
!= 1 || yystack
->yysplitPoint
== NULL
)
1451 for (yyp
= yystack
->yytops
.yystates
[0], yyq
= yyp
->yypred
, yyr
= NULL
;
1452 yyp
!= yystack
->yysplitPoint
;
1453 yyr
= yyp
, yyp
= yyq
, yyq
= yyp
->yypred
)
1456 yystack
->yyspaceLeft
+= yystack
->yynextFree
- yystack
->yyitems
;
1457 yystack
->yynextFree
= ((yyGLRStackItem
*) yystack
->yysplitPoint
) + 1;
1458 yystack
->yyspaceLeft
-= yystack
->yynextFree
- yystack
->yyitems
;
1459 yystack
->yysplitPoint
= NULL
;
1460 yystack
->yylastDeleted
= NULL
;
1464 yystack
->yynextFree
->yystate
= *yyr
;
1466 yystack
->yynextFree
->yystate
.yypred
= & yystack
->yynextFree
[-1].yystate
;
1467 yystack
->yytops
.yystates
[0] = &yystack
->yynextFree
->yystate
;
1468 yystack
->yynextFree
+= 1;
1469 yystack
->yyspaceLeft
-= 1;
1474 yyprocessOneStack (yyGLRStack
* yystack
, int yyk
,
1475 size_t yyposn
, YYSTYPE
* yylvalp
, YYLTYPE
* yyllocp
)
1478 const short* yyconflicts
;
1480 yySymbol
* const yytokenp
= yystack
->yytokenp
;
1482 while (yystack
->yytops
.yystates
[yyk
] != NULL
)
1484 yyStateNum yystate
= yystack
->yytops
.yystates
[yyk
]->yylrState
;
1486 assert (yystate
!= YYFINAL
);
1487 if (yyisDefaultedState (yystate
))
1489 yyrule
= yydefaultAction (yystate
);
1492 YYDPRINTF ((stderr
, "Stack %d dies.\n", yyk
));
1493 yymarkStackDeleted (yystack
, yyk
);
1496 YYCHK (yyglrReduce (yystack
, yyk
, yyrule
, yyfalse
));
1500 if (*yytokenp
== YYEMPTY
)
1502 YYDPRINTF ((stderr
, "Reading a token: "));
1504 *yytokenp
= YYTRANSLATE(yychar
);
1505 YYDPRINTF ((stderr
, "Next token is %s\n",
1506 yytokenName (*yytokenp
)));
1508 yygetLRActions (yystate
, *yytokenp
, &yyaction
, &yyconflicts
);
1510 while (*yyconflicts
!= 0)
1512 int yynewStack
= yysplitStack (yystack
, yyk
);
1513 YYDPRINTF ((stderr
, "Splitting off stack %d from %d.\n",
1515 YYCHK (yyglrReduce (yystack
, yynewStack
, *yyconflicts
, yyfalse
));
1516 YYCHK (yyprocessOneStack (yystack
, yynewStack
, yyposn
,
1521 if (yyisShiftAction (yyaction
))
1523 YYDPRINTF ((stderr
, "Shifting token %s on stack %d, ",
1524 yytokenName (*yytokenp
), yyk
));
1525 yyglrShift (yystack
, yyk
, yyaction
, yyposn
+1, *yylvalp
, yyllocp
);
1526 YYDPRINTF ((stderr
, "which is now in state #%d\n",
1527 yystack
->yytops
.yystates
[yyk
]->yylrState
));
1530 else if (yyisErrorAction (yyaction
))
1532 YYDPRINTF ((stderr
, "Stack %d dies.\n", yyk
));
1533 yymarkStackDeleted (yystack
, yyk
);
1537 YYCHK (yyglrReduce (yystack
, yyk
, -yyaction
, yyfalse
));
1544 yyreportParseError (yyGLRStack
* yystack
, YYSTYPE
* yylvalp
, YYLTYPE
* yyllocp
)
1546 /* `Unused' warnings. */
1550 if (yystack
->yyerrState
== 0)
1553 yySymbol
* const yytokenp
= yystack
->yytokenp
;
1554 int yyn
, yyx
, yycount
;
1556 const char* yyprefix
;
1559 yyn
= yypact
[yystack
->yytops
.yystates
[0]->yylrState
];
1560 if (YYPACT_NINF
< yyn
&& yyn
< YYLAST
)
1563 /* Start YYX at -YYN if negative to avoid negative indexes in
1565 yysize
= sizeof ("parse error, unexpected ")
1566 + strlen (yytokenName (*yytokenp
));
1567 yyprefix
= ", expecting ";
1568 for (yyx
= yyn
< 0 ? -yyn
: 0; yyx
< yytname_size
&& yycount
<= 5;
1570 if (yycheck
[yyx
+ yyn
] == yyx
&& yyx
!= YYTERROR
)
1571 yysize
+= strlen (yytokenName (yyx
)) + strlen (yyprefix
),
1572 yycount
+= 1, yyprefix
= " or ";
1573 yymsg
= yyp
= (char*) malloc (yysize
);
1574 sprintf (yyp
, "parse error, unexpected %s",
1575 yytokenName (*yytokenp
));
1576 yyp
+= strlen (yyp
);
1579 yyprefix
= ", expecting ";
1580 for (yyx
= yyn
< 0 ? -yyn
: 0; yyx
< yytname_size
; yyx
+= 1)
1581 if (yycheck
[yyx
+ yyn
] == yyx
&& yyx
!= YYTERROR
)
1583 sprintf (yyp
, "%s%s", yyprefix
, yytokenName (yyx
));
1584 yyp
+= strlen (yyp
);
1593 yyerror ("parse error");
1598 /* Recover from a syntax error on YYSTACK, assuming that YYTOKENP,
1599 YYLVALP, and YYLLOCP point to the syntactic category, semantic
1600 value, and location of the lookahead. */
1602 yyrecoverParseError (yyGLRStack
* yystack
, YYSTYPE
* yylvalp
, YYLTYPE
* yyllocp
)
1604 yySymbol
* const yytokenp
= yystack
->yytokenp
;
1608 if (yystack
->yyerrState
== 0)
1609 yystack
->yyerrState
= 3;
1610 else if (yystack
->yyerrState
== 3)
1611 /* We just shifted the error token and (perhaps) took some
1612 reductions. Skip tokens until we can proceed. */
1615 if (*yytokenp
== YYEOF
)
1616 yyFail (yystack
, NULL
);
1617 if (*yytokenp
!= YYEMPTY
)
1618 YYDPRINTF ((stderr
, "Discarding token %s\n",
1619 yytokenName (*yytokenp
)));
1620 YYDPRINTF ((stderr
, "Reading a token: "));
1622 *yytokenp
= YYTRANSLATE (yychar
);
1623 YYDPRINTF ((stderr
, "Next token is %s\n", yytokenName (*yytokenp
)));
1624 yyj
= yypact
[yystack
->yytops
.yystates
[0]->yylrState
];
1625 if (yyj
== YYPACT_NINF
)
1626 /* Something's not right; we shouldn't be here. */
1627 yyFail (yystack
, NULL
);
1629 if (yyj
< 0 || YYLAST
< yyj
|| yycheck
[yyj
] != *yytokenp
)
1631 if (yydefact
[yystack
->yytops
.yystates
[0]->yylrState
] != 0)
1634 else if (yytable
[yyj
] != 0 && yytable
[yyj
] != YYTABLE_NINF
)
1638 /* Reduce to one stack. */
1639 for (yyk
= 0; yyk
< yystack
->yytops
.yysize
; yyk
+= 1)
1640 if (yystack
->yytops
.yystates
[yyk
] != NULL
)
1642 if (yyk
>= yystack
->yytops
.yysize
)
1643 yyFail (yystack
, NULL
);
1644 for (yyk
+= 1; yyk
< yystack
->yytops
.yysize
; yyk
+= 1)
1645 yymarkStackDeleted (yystack
, yyk
);
1646 yyremoveDeletes (yystack
);
1647 yycompressStack (yystack
);
1649 /* Now pop stack until we find a state that shifts the error token. */
1650 while (yystack
->yytops
.yystates
[0] != NULL
)
1652 yyj
= yypact
[yystack
->yytops
.yystates
[0]->yylrState
] + YYTERROR
;
1653 if (yyj
!= YYPACT_NINF
+ YYTERROR
&& yyj
>= 0 && yyj
<= YYLAST
&&
1654 yycheck
[yyj
] == YYTERROR
&& yyisShiftAction (yytable
[yyj
]))
1656 yyglrShift (yystack
, 0, yytable
[yyj
],
1657 yystack
->yytops
.yystates
[0]->yyposn
, *yylvalp
, yyllocp
);
1660 yystack
->yytops
.yystates
[0] = yystack
->yytops
.yystates
[0]->yypred
;
1661 yystack
->yynextFree
-= 1;
1662 yystack
->yyspaceLeft
+= 1;
1664 if (yystack
->yytops
.yystates
[0] == NULL
)
1665 yyFail (yystack
, NULL
);
1668 #define YYCHK1(YYE) \
1674 yystack.yyerrflag = 1; \
1677 yystack.yyerrflag = 0; \
1680 goto yyuser_error; \
1685 yyparse (YYPARSE_PARAM_ARG
)
1695 #define yychar (yystack.yyrawchar)
1698 YYSTYPE
* const yylvalp
= &yylval
;
1699 YYLTYPE
* const yyllocp
= &yylloc
;
1701 yyinitGLRStack (&yystack
, YYINITDEPTH
);
1702 yystack
.yytokenp
= &yytoken
;
1704 YYDPRINTF ((stderr
, "Starting parse\n"));
1706 if (setjmp (yystack
.yyexception_buffer
) != 0)
1709 yyglrShift (&yystack
, 0, 0, 0, yyval_default
, &yyloc_default
);
1715 /* For efficiency, we have two loops, of which the first of which
1716 * is specialized to deterministic operation (single stack, no
1717 * potential ambiguity). */
1724 const short* yyconflicts
;
1726 yyStateNum yystate
= yystack
.yytops
.yystates
[0]->yylrState
;
1727 if (yystate
== YYFINAL
)
1729 if (yyisDefaultedState (yystate
))
1731 yyrule
= yydefaultAction (yystate
);
1734 yyreportParseError (&yystack
, yylvalp
, yyllocp
);
1737 YYCHK1 (yyglrReduce (&yystack
, 0, yyrule
, yytrue
));
1741 if (yytoken
== YYEMPTY
)
1743 YYDPRINTF ((stderr
, "Reading a token: "));
1745 yytoken
= YYTRANSLATE (yychar
);
1746 YYDPRINTF ((stderr
, "Next token is %s\n",
1747 yytokenName (yytoken
)));
1749 yygetLRActions (yystate
, yytoken
, &yyaction
, &yyconflicts
);
1750 if (*yyconflicts
!= 0)
1752 if (yyisShiftAction (yyaction
))
1754 YYDPRINTF ((stderr
, "Shifting token %s, ",
1755 yytokenName (yytoken
)));
1756 if (yytoken
!= YYEOF
)
1759 yyglrShift (&yystack
, 0, yyaction
, yyposn
, yylval
, yyllocp
);
1760 if (yystack
.yyerrState
> 0)
1761 yystack
.yyerrState
-= 1;
1762 YYDPRINTF ((stderr
, "Entering state %d\n",
1763 yystack
.yytops
.yystates
[0]->yylrState
));
1765 else if (yyisErrorAction (yyaction
))
1767 yyreportParseError (&yystack
, yylvalp
, yyllocp
);
1771 YYCHK1 (yyglrReduce (&yystack
, 0, -yyaction
, yytrue
));
1778 int yyn
= yystack
.yytops
.yysize
;
1779 for (yys
= 0; yys
< yyn
; yys
+= 1)
1780 YYCHK1 (yyprocessOneStack (&yystack
, yys
, yyposn
,
1784 yyremoveDeletes (&yystack
);
1785 if (yystack
.yytops
.yysize
== 0)
1787 yyundeleteLastStack (&yystack
);
1788 if (yystack
.yytops
.yysize
== 0)
1789 yyFail (&yystack
, "parse error");
1790 YYCHK1 (yyresolveStack (&yystack
));
1791 YYDPRINTF ((stderr
, "Returning to deterministic operation.\n"));
1792 yyreportParseError (&yystack
, yylvalp
, yyllocp
);
1795 else if (yystack
.yytops
.yysize
== 1)
1797 YYCHK1 (yyresolveStack (&yystack
));
1798 YYDPRINTF ((stderr
, "Returning to deterministic operation.\n"));
1799 yycompressStack (&yystack
);
1805 yyrecoverParseError (&yystack
, yylvalp
, yyllocp
);
1806 yyposn
= yystack
.yytops
.yystates
[0]->yyposn
;
1811 yyfreeGLRStack (&yystack
);
1812 return yystack
.yyerrflag
;
1815 /* DEBUGGING ONLY */
1816 static void yypstack (yyGLRStack
* yystack
, int yyk
) ATTRIBUTE_UNUSED
;
1817 static void yypdumpstack (yyGLRStack
* yystack
) ATTRIBUTE_UNUSED
;
1820 yy_yypstack (yyGLRState
* yys
)
1824 yy_yypstack (yys
->yypred
);
1825 fprintf (stderr
, " -> ");
1827 fprintf (stderr
, "%d@%lu", yys
->yylrState
, (unsigned long) yys
->yyposn
);
1831 yypstates (yyGLRState
* yyst
)
1834 fprintf (stderr
, "<null>");
1837 fprintf (stderr
, "\n");
1841 yypstack (yyGLRStack
* yystack
, int yyk
)
1843 yypstates (yystack
->yytops
.yystates
[yyk
]);
1846 #define YYINDEX(YYX) \
1847 ((YYX) == NULL ? -1 : (yyGLRStackItem*) (YYX) - yystack->yyitems)
1851 yypdumpstack (yyGLRStack
* yystack
)
1853 yyGLRStackItem
* yyp
;
1855 for (yyp
= yystack
->yyitems
; yyp
< yystack
->yynextFree
; yyp
+= 1)
1857 fprintf (stderr
, "%3lu. ", (unsigned long) (yyp
- yystack
->yyitems
));
1860 fprintf (stderr
, "Res: %d, LR State: %d, posn: %lu, pred: %ld",
1861 yyp
->yystate
.yyresolved
, yyp
->yystate
.yylrState
,
1862 (unsigned long) yyp
->yystate
.yyposn
,
1863 (long) YYINDEX (yyp
->yystate
.yypred
));
1864 if (! yyp
->yystate
.yyresolved
)
1865 fprintf (stderr
, ", firstVal: %ld",
1866 (long) YYINDEX (yyp
->yystate
.yysemantics
.yyfirstVal
));
1870 fprintf (stderr
, "Option. rule: %d, state: %ld, next: %ld",
1871 yyp
->yyoption
.yyrule
,
1872 (long) YYINDEX (yyp
->yyoption
.yystate
),
1873 (long) YYINDEX (yyp
->yyoption
.yynext
));
1875 fprintf (stderr
, "\n");
1877 fprintf (stderr
, "Tops:");
1878 for (yyi
= 0; yyi
< yystack
->yytops
.yysize
; yyi
+= 1)
1879 fprintf (stderr
, "%lu: %ld; ", (unsigned long) yyi
,
1880 (long) YYINDEX (yystack
->yytops
.yystates
[yyi
]));
1881 fprintf (stderr
, "\n");
1887 m4_if(b4_defines_flag
, 0, [],
1888 [#output "b4_output_header_name"
1889 b4_copyright([Skeleton parser
for GLR parsing with Bison
], [2002])
1890 #ifndef b4_header_guard
1891 # define b4_header_guard
1893 b4_token_defines(b4_tokens
)
1896 m4_ifdef([b4_stype
],
1897 [#line b4_stype_line "b4_filename"
1898 typedef union b4_stype yystype
;
1899 /* Line __line__ of __file__. */
1900 #line __oline__ "__ofile__"],
1901 [typedef int yystype
;])
1902 # define YYSTYPE yystype
1906 [extern YYSTYPE b4_prefix
[]lval
;])
1910 typedef struct yyltype
1917 # define YYLTYPE yyltype
1921 [extern YYLTYPE b4_prefix
[]lloc
;])
1923 #endif /* not b4_header_guard */