1 m4_divert(-1) -*- C
-*-
3 # GLR skeleton for Bison
4 # Copyright (C) 2002, 2003 Free Software Foundation, Inc.
6 # This program is free software; you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation; either version 2 of the License, or
9 # (at your option) any later version.
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License
17 # along with this program; if not, write to the Free Software
18 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
22 ## ---------------- ##
24 ## ---------------- ##
27 m4_define_default([b4_stack_depth_max
], [10000])
28 m4_define_default([b4_stack_depth_init
], [200])
32 ## ------------------------ ##
33 ## Pure/impure interfaces. ##
34 ## ------------------------ ##
39 # Accumule in b4_lex_param all the yylex arguments.
40 # Yes, this is quite ugly...
41 m4_define([b4_lex_param
],
42 m4_dquote(b4_pure_if([[[[YYSTYPE
*]], [[yylvalp]]][]dnl
43 b4_location_if([, [[YYLTYPE
*], [yyllocp
]]])])dnl
44 m4_ifdef([b4_lex_param
], [, ]b4_lex_param
)))
49 m4_define([b4_user_formals
],
50 [m4_ifset([b4_parse_param
], [, b4_c_ansi_formals(b4_parse_param
)])])
55 # Arguments passed to yyerror: user args plus yylloc.
56 m4_define([b4_yyerror_args
],
57 [b4_pure_if([b4_location_if([yylocp
, ])])dnl
58 m4_ifset([b4_parse_param
], [b4_c_args(b4_parse_param
), ])])
63 # Same as above, but on the lookahead, hence yyllocp instead of yylocp.
64 m4_define([b4_lyyerror_args
],
65 [b4_pure_if([b4_location_if([yyllocp
, ])])dnl
66 m4_ifset([b4_parse_param
], [b4_c_args(b4_parse_param
), ])])
71 # Arguments needed by yyerror: user args plus yylloc.
72 m4_define([b4_pure_args
],
73 [b4_pure_if([b4_location_if([, yylocp
])])[]b4_user_args
])
78 # Arguments passed to yyerror: user formals plus yyllocp.
79 m4_define([b4_pure_formals
],
80 [b4_pure_if([b4_location_if([, YYLTYPE
*yylocp
])])[]b4_user_formals
])
85 # Same as above, but on the lookahead, hence yyllocp instead of yylocp.
86 m4_define([b4_lpure_args
],
87 [b4_pure_if([b4_location_if([, yyllocp
])])[]b4_user_args
])
92 # Same as above, but on the lookahead, hence yyllocp instead of yylocp.
93 m4_define([b4_lpure_formals
],
94 [b4_pure_if([b4_location_if([YYLTYPE
*yyllocp
])])[]b4_user_formals
])
97 ## ----------------- ##
98 ## Semantic Values. ##
99 ## ----------------- ##
102 # b4_lhs_value([TYPE])
103 # --------------------
104 # Expansion of $<TYPE>$.
105 m4_define([b4_lhs_value
],
106 [(*yyvalp
)[]m4_ifval([$
1], [.$
1])])
109 # b4_rhs_value(RULE-LENGTH, NUM, [TYPE])
110 # --------------------------------------
111 # Expansion of $<TYPE>NUM, where the current rule has RULE-LENGTH
113 m4_define([b4_rhs_value
],
114 [yyvsp@
{YYFILL (m4_eval([$
2 - $
1]))@
}.yystate
.yysemantics
.yysval
[]m4_ifval([$
3], [.$
3])])
125 m4_define([b4_lhs_location
],
129 # b4_rhs_location(RULE-LENGTH, NUM)
130 # ---------------------------------
131 # Expansion of @NUM, where the current rule has RULE-LENGTH symbols
133 m4_define([b4_rhs_location
],
134 [yyvsp@
{YYFILL (m4_eval([$
2 - $
1]))@
}.yystate
.yyloc
])
136 # We do want M4 expansion after # for CPP macros.
139 @output @output_parser_name@
140 b4_copyright([Skeleton parser
for GLR parsing with Bison
], [2002, 2003])
142 /* This is the parser code for GLR (Generalized LR) parser. */
151 m4_if(b4_prefix
[], [yy
], [],
152 [/* If NAME_PREFIX is specified substitute the variables and functions
154 #define yyparse b4_prefix[]parse
155 #define yylex b4_prefix[]lex
156 #define yyerror b4_prefix[]error
157 #define yylval b4_prefix[]lval
158 #define yychar b4_prefix[]char
159 #define yydebug b4_prefix[]debug
160 #define yynerrs b4_prefix[]nerrs
161 b4_location_if([#define yylloc b4_prefix[]lloc])])
163 b4_token_defines(b4_tokens
)
165 /* Copy the first part of user declarations. */
168 /* Enabling traces. */
170 # define YYDEBUG ]b4_debug[
173 /* Enabling verbose error messages. */
174 #ifdef YYERROR_VERBOSE
175 # undef YYERROR_VERBOSE
176 # define YYERROR_VERBOSE 1
178 # define YYERROR_VERBOSE ]b4_error_verbose[
181 #if ! defined (YYSTYPE) && ! defined (YYSTYPE_IS_DECLARED)
182 ]m4_ifdef([b4_stype
],
183 [b4_syncline([b4_stype_line
], [b4_filename
])
184 typedef union m4_bregexp(b4_stype
, [^{], [YYSTYPE
])b4_stype YYSTYPE
;
185 /* Line __line__ of glr.c. */
186 b4_syncline([@oline@
], [@ofile@
])],
187 [typedef int YYSTYPE
;])[
188 # define YYSTYPE_IS_DECLARED 1
189 # define YYSTYPE_IS_TRIVIAL 1
192 #if ! defined (YYLTYPE) && ! defined (YYLTYPE_IS_DECLARED)
193 typedef struct YYLTYPE
200 # define YYLTYPE_IS_DECLARED 1
201 # define YYLTYPE_IS_TRIVIAL 1
204 /* Default (constant) values used for initialization for null
205 right-hand sides. Unlike the standard yacc.c template,
206 here we set the default values of $$ and $@@ to zeroed-out
207 values. Since the default value of these quantities is undefined,
208 this behavior is technically correct. */
209 static YYSTYPE yyval_default
;
210 static YYLTYPE yyloc_default
;
212 /* Copy the second part of user declarations. */
215 ]/* Line __line__ of glr.c. */
216 b4_syncline([@oline@
], [@ofile@
])
221 typedef unsigned char yybool
;
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 /* YYFINAL -- State number of the termination state. */
243 #define YYFINAL ]b4_final_state_number[
244 /* YYLAST -- Last index in YYTABLE. */
245 #define YYLAST ]b4_last[
247 /* YYNTOKENS -- Number of terminals. */
248 #define YYNTOKENS ]b4_tokens_number[
249 /* YYNNTS -- Number of nonterminals. */
250 #define YYNNTS ]b4_nterms_number[
251 /* YYNRULES -- Number of rules. */
252 #define YYNRULES ]b4_rules_number[
253 /* YYNRULES -- Number of states. */
254 #define YYNSTATES ]b4_states_number[
255 /* YYMAXRHS -- Maximum number of symbols on right-hand side of rule. */
256 #define YYMAXRHS ]b4_r2_max[
258 /* YYTRANSLATE(X) -- Bison symbol number corresponding to X. */
259 #define YYUNDEFTOK ]b4_undef_token_number[
260 #define YYMAXUTOK ]b4_user_token_number_max[
262 #define YYTRANSLATE(YYX) \
263 ((YYX <= 0) ? YYEOF : \
264 (unsigned)(YYX) <= YYMAXUTOK ? yytranslate[YYX] : YYUNDEFTOK)
266 /* YYTRANSLATE[YYLEX] -- Bison symbol number corresponding to YYLEX. */
267 static const ]b4_int_type_for([b4_translate
])[ yytranslate
[] =
273 /* YYPRHS[YYN] -- Index of the first RHS symbol of rule number YYN in
275 static const ]b4_int_type_for([b4_prhs
])[ yyprhs
[] =
280 /* YYRHS -- A `-1'-separated list of the rules' RHS. */
281 static const ]b4_int_type_for([b4_rhs
])[ yyrhs
[] =
286 /* YYRLINE[YYN] -- source line where rule number YYN was defined. */
287 static const ]b4_int_type_for([b4_rline
])[ yyrline
[] =
293 #if (YYDEBUG) || YYERROR_VERBOSE
294 /* YYTNME[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM.
295 First, the terminals, then, starting at YYNTOKENS, nonterminals. */
296 static const char *const yytname
[] =
301 #define yytname_size ((int) (sizeof (yytname) / sizeof (yytname[0])))
304 /* YYR1[YYN] -- Symbol number of symbol that rule YYN derives. */
305 static const ]b4_int_type_for([b4_r1
])[ yyr1
[] =
310 /* YYR2[YYN] -- Number of symbols composing right hand side of rule YYN. */
311 static const ]b4_int_type_for([b4_r2
])[ yyr2
[] =
316 /* YYDPREC[RULE-NUM] -- Dynamic precedence of rule #RULE-NUM (0 if none). */
317 static const ]b4_int_type_for([b4_dprec
])[ yydprec
[] =
322 /* YYMERGER[RULE-NUM] -- Index of merging function for rule #RULE-NUM. */
323 static const ]b4_int_type_for([b4_merger
])[ yymerger
[] =
328 /* YYDEFACT[S] -- default rule to reduce with in state S when YYTABLE
329 doesn't specify something else to do. Zero means the default is an
331 static const ]b4_int_type_for([b4_defact
])[ yydefact
[] =
336 /* YYPDEFGOTO[NTERM-NUM]. */
337 static const ]b4_int_type_for([b4_defgoto
])[ yydefgoto
[] =
342 /* YYPACT[STATE-NUM] -- Index in YYTABLE of the portion describing
344 #define YYPACT_NINF ]b4_pact_ninf[
345 static const ]b4_int_type_for([b4_pact
])[ yypact
[] =
350 /* YYPGOTO[NTERM-NUM]. */
351 static const ]b4_int_type_for([b4_pgoto
])[ yypgoto
[] =
356 /* YYTABLE[YYPACT[STATE-NUM]]. What to do in state STATE-NUM. If
357 positive, shift that token. If negative, reduce the rule which
358 number is the opposite. If zero, do what YYDEFACT says.
359 If YYTABLE_NINF, syntax error. */
360 #define YYTABLE_NINF ]b4_table_ninf[
361 static const ]b4_int_type_for([b4_table
])[ yytable
[] =
366 /* YYCONFLP[YYPACT[STATE-NUM]] -- Pointer into YYCONFL of start of
367 list of conflicting reductions corresponding to action entry for
368 state STATE-NUM in yytable. 0 means no conflicts. The list in
369 yyconfl is terminated by a rule number of 0. */
370 static const ]b4_int_type_for([b4_conflict_list_heads
])[ yyconflp
[] =
372 ]b4_conflict_list_heads
[
375 /* YYCONFL[I] -- lists of conflicting rule numbers, each terminated by
376 0, pointed into by YYCONFLP. */
377 ]dnl Do
not use b4_int_type_for here
, since there are places where
378 dnl pointers onto yyconfl are taken
, which type is
"short *".
379 dnl We probably ought to introduce a type
for confl
.
380 [static const short yyconfl
[] =
382 ]b4_conflicting_rules
[
385 static const ]b4_int_type_for([b4_check
])[ yycheck
[] =
390 /* YYSTOS[STATE-NUM] -- The (internal number of the) accessing
391 symbol of state STATE-NUM. */
392 static const ]b4_int_type_for([b4_stos
])[ yystos
[] =
398 /* Prevent warning if -Wmissing-prototypes. */
399 ]b4_c_ansi_function_decl([yyparse
], [int], b4_parse_param
)[
401 /* Error token number */
404 /* YYLLOC_DEFAULT -- Compute the default location (before the actions
407 #define YYRHSLOC(yyRhs,YYK) (yyRhs[YYK].yystate.yyloc)
409 #ifndef YYLLOC_DEFAULT
410 # define YYLLOC_DEFAULT(yyCurrent, yyRhs, YYN) \
411 yyCurrent.first_line = YYRHSLOC(yyRhs,1).first_line; \
412 yyCurrent.first_column = YYRHSLOC(yyRhs,1).first_column; \
413 yyCurrent.last_line = YYRHSLOC(yyRhs,YYN).last_line; \
414 yyCurrent.last_column = YYRHSLOC(yyRhs,YYN).last_column;
417 /* YYLEX -- calling `yylex' with the right arguments. */
418 #define YYLEX ]b4_c_function_call([yylex], [int], b4_lex_param)[
423 #define yynerrs (yystack->yyerrcnt)
425 #define yychar (yystack->yyrawchar)],
433 static const int YYEOF
= 0;
434 static const int YYEMPTY
= -2;
436 typedef enum { yyok
, yyaccept
, yyabort
, yyerr
} YYRESULTTAG
;
439 do { YYRESULTTAG yyflag = YYE; if (yyflag != yyok) return yyflag; } \
444 #if ! defined (YYFPRINTF)
445 # define YYFPRINTF fprintf
448 # define YYDPRINTF(Args) \
454 ]b4_yysymprint_generate([b4_c_ansi_function_def
])[
456 # define YYDSYMPRINT(Args) \
462 # define YYDSYMPRINTF(Title, Token, Value, Location) \
466 YYFPRINTF (stderr, "%s ", Title); \
467 yysymprint (stderr, \
468 Token, Value]b4_location_if([, Location])[); \
469 YYFPRINTF (stderr, "\n"); \
473 /* Nonzero means print parse trace. It is left uninitialized so that
474 multiple parsers can coexist. */
479 /* Avoid empty `if' bodies. */
480 # define YYDPRINTF(Args)
481 # define YYDSYMPRINT(Args)
482 # define YYDSYMPRINTF(Title, Token, Value, Location)
484 #endif /* !YYDEBUG */
486 /* YYINITDEPTH -- initial size of the parser's stacks. */
488 # define YYINITDEPTH ]b4_stack_depth_init[
491 /* YYMAXDEPTH -- maximum size the stacks can grow to (effective only
492 if the built-in stack extension method is used).
494 Do not make this value too large; the results are undefined if
495 SIZE_MAX < YYMAXDEPTH * sizeof (GLRStackItem)
496 evaluated with infinite-precision integer arithmetic. */
503 # define YYMAXDEPTH ]b4_stack_depth_max[
506 /* Minimum number of free items on the stack allowed after an
507 allocation. This is to allow allocation and initialization
508 to be completed by functions that call expandGLRStack before the
509 stack is expanded, thus insuring that all necessary pointers get
510 properly redirected to new data. */
513 #if (! defined (YYSTACKEXPANDABLE) \
514 && (! defined (__cplusplus) \
515 || (]b4_location_if([YYLTYPE_IS_TRIVIAL && ])[YYSTYPE_IS_TRIVIAL)))
516 #define YYSTACKEXPANDABLE 1
518 #define YYSTACKEXPANDABLE 0
521 /** State numbers, as in LALR(1) machine */
522 typedef int yyStateNum
;
524 /** Rule numbers, as in LALR(1) machine */
525 typedef int yyRuleNum
;
527 /** Grammar symbol */
528 typedef short yySymbol
;
530 /** Item references, as in LALR(1) machine */
531 typedef short yyItemNum
;
533 typedef struct yyGLRState yyGLRState
;
534 typedef struct yySemanticOption yySemanticOption
;
535 typedef union yyGLRStackItem yyGLRStackItem
;
536 typedef struct yyGLRStack yyGLRStack
;
537 typedef struct yyGLRStateSet yyGLRStateSet
;
542 yyStateNum yylrState
;
546 yySemanticOption
* yyfirstVal
;
552 struct yyGLRStateSet
{
553 yyGLRState
** yystates
;
554 size_t yysize
, yycapacity
;
557 struct yySemanticOption
{
561 yySemanticOption
* yynext
;
564 union yyGLRStackItem
{
566 yySemanticOption yyoption
;
578 jmp_buf yyexception_buffer
;
579 yyGLRStackItem
* yyitems
;
580 yyGLRStackItem
* yynextFree
;
582 yyGLRState
* yysplitPoint
;
583 yyGLRState
* yylastDeleted
;
584 yyGLRStateSet yytops
;
587 static void yyinitGLRStack (yyGLRStack
* yystack
, size_t yysize
);
588 static void yyexpandGLRStack (yyGLRStack
* yystack
]b4_pure_formals
[);
589 static void yyfreeGLRStack (yyGLRStack
* yystack
);
592 yyFail (yyGLRStack
* yystack
]b4_pure_formals
[, const char* yyformat
, ...)
594 yystack
->yyerrflag
= 1;
595 if (yyformat
!= NULL
)
599 va_start (yyap
, yyformat
);
600 vsprintf (yymsg
, yyformat
, yyap
);
601 yyerror (]b4_yyerror_args
[yymsg
);
603 longjmp (yystack
->yyexception_buffer
, 1);
606 #if YYDEBUG || YYERROR_VERBOSE
607 /** A printable representation of TOKEN. Valid until next call to
609 static inline const char*
610 yytokenName (yySymbol yytoken
)
612 return yytname
[yytoken
];
616 /** Fill in YYVSP[YYLOW1 .. YYLOW0-1] from the chain of states starting
617 * at YYVSP[YYLOW0].yystate.yypred. Leaves YYVSP[YYLOW1].yystate.yypred
618 * containing the pointer to the next state in the chain. Assumes
619 * YYLOW1 < YYLOW0. For convenience, returns YYLOW1. */
621 yyfill (yyGLRStackItem
* yyvsp
, int yylow0
, int yylow1
)
625 s
= yyvsp
[yylow0
].yystate
.yypred
;
626 for (i
= yylow0
-1; i
>= yylow1
; i
-= 1)
630 yyvsp
[i
].yystate
.yyresolved
= yytrue
;
631 yyvsp
[i
].yystate
.yysemantics
.yysval
= s
->yysemantics
.yysval
;
632 yyvsp
[i
].yystate
.yyloc
= s
->yyloc
;
633 s
= yyvsp
[i
].yystate
.yypred
= s
->yypred
;
638 /** Perform user action for rule number YYN, with RHS length YYRHSLEN,
639 * and top stack item YYVSP. YYLVALP points to place to put semantic
640 * value ($$), and yylocp points to place for location information
641 * (@@$). Returns yyok for normal return, yyaccept for YYACCEPT,
642 * yyerr for YYERROR, yyabort for YYABORT. */
644 yyuserAction (yyRuleNum yyn
, int yyrhslen
, yyGLRStackItem
* yyvsp
,
645 YYSTYPE
* yyvalp
, YYLTYPE
* yylocp
, yyGLRStack
* yystack
648 int yynormal
= (yystack
->yysplitPoint
== NULL
);
653 *yyvalp
= yyval_default
;
654 *yylocp
= yyloc_default
;
658 *yyvalp
= yyvsp
[1-yyrhslen
].yystate
.yysemantics
.yysval
;
659 *yylocp
= yyvsp
[1-yyrhslen
].yystate
.yyloc
;
662 # define yyerrok (yystack->yyerrState = 0)
664 # define YYACCEPT return yyaccept
666 # define YYABORT return yyabort
668 # define YYERROR return yyerr
670 # define YYRECOVERING (yystack->yyerrState != 0)
672 # define yyclearin (yychar = *(yystack->yytokenp) = YYEMPTY)
675 ((yynormal || yylow <= (N)) ? (N) : (yylow = yyfill (yyvsp, yylow, N)))
677 # define YYBACKUP(Token, Value) \
679 yyerror (]b4_yyerror_args["syntax error: cannot back up"); \
698 /* Line __line__ of glr.c. */
699 b4_syncline([@oline@
], [@ofile@
])
704 yyuserMerge (int yyn
, YYSTYPE
* yy0
, YYSTYPE
* yy1
)
706 YYSTYPE yyval
= *yy0
;
707 /* `Use' the arguments. */
718 /* Bison grammar-table manipulation. */
720 ]b4_yydestruct_generate([b4_c_ansi_function_def
])[
722 /** Number of symbols composing the right hand side of rule #RULE. */
724 yyrhsLength (yyRuleNum yyrule
)
729 /** Left-hand-side symbol for rule #RULE. */
730 static inline yySymbol
731 yylhsNonterm (yyRuleNum yyrule
)
736 #define yyis_pact_ninf(yystate) \
737 ]m4_if(m4_eval(b4_pact_ninf < b4_pact_min), 1,
739 ((yystate
) == YYPACT_NINF
))[
741 /** True iff LR state STATE has only a default reduction (regardless
744 yyisDefaultedState (yyStateNum yystate
)
746 return yyis_pact_ninf (yypact
[yystate
]);
749 /** The default reduction for STATE, assuming it has one. */
750 static inline yyRuleNum
751 yydefaultAction (yyStateNum yystate
)
753 return yydefact
[yystate
];
756 #define yyis_table_ninf(yytable_value) \
757 ]m4_if(m4_eval(b4_table_ninf < b4_table_min), 1,
759 ((yytable_value
) == YYTABLE_NINF
))[
761 /** Set *YYACTION to the action to take in YYSTATE on seeing YYTOKEN.
763 * R < 0: Reduce on rule -R.
765 * R > 0: Shift to state R.
766 * Set *CONFLICTS to a pointer into yyconfl to 0-terminated list of
767 * conflicting reductions.
770 yygetLRActions (yyStateNum yystate
, int yytoken
,
771 int* yyaction
, const short** yyconflicts
)
773 int yyindex
= yypact
[yystate
] + yytoken
;
774 if (yyindex
< 0 || YYLAST
< yyindex
|| yycheck
[yyindex
] != yytoken
)
776 *yyaction
= -yydefact
[yystate
];
777 *yyconflicts
= yyconfl
;
779 else if (! yyis_table_ninf (yytable
[yyindex
]))
781 *yyaction
= yytable
[yyindex
];
782 *yyconflicts
= yyconfl
+ yyconflp
[yyindex
];
787 *yyconflicts
= yyconfl
+ yyconflp
[yyindex
];
791 static inline yyStateNum
792 yyLRgotoState (yyStateNum yystate
, yySymbol yylhs
)
795 yyr
= yypgoto
[yylhs
- YYNTOKENS
] + yystate
;
796 if (0 <= yyr
&& yyr
<= YYLAST
&& yycheck
[yyr
] == yystate
)
799 return yydefgoto
[yylhs
- YYNTOKENS
];
803 yyisShiftAction (int yyaction
)
809 yyisErrorAction (int yyaction
)
811 return yyaction
== 0;
817 yyaddDeferredAction (yyGLRStack
* yystack
, yyGLRState
* yystate
,
818 yyGLRState
* rhs
, yyRuleNum yyrule
]b4_pure_formals
[)
820 yySemanticOption
* yynewItem
;
821 yynewItem
= &yystack
->yynextFree
->yyoption
;
822 yystack
->yyspaceLeft
-= 1;
823 yystack
->yynextFree
+= 1;
824 yynewItem
->yyisState
= yyfalse
;
825 yynewItem
->yystate
= rhs
;
826 yynewItem
->yyrule
= yyrule
;
827 yynewItem
->yynext
= yystate
->yysemantics
.yyfirstVal
;
828 yystate
->yysemantics
.yyfirstVal
= yynewItem
;
829 if (yystack
->yyspaceLeft
< YYHEADROOM
)
830 yyexpandGLRStack (yystack
]b4_pure_args
[);
835 /** Initialize SET to a singleton set containing an empty stack. */
837 yyinitStateSet (yyGLRStateSet
* yyset
)
840 yyset
->yycapacity
= 16;
841 yyset
->yystates
= (yyGLRState
**) malloc (16 * sizeof (yyset
->yystates
[0]));
842 yyset
->yystates
[0] = NULL
;
845 static void yyfreeStateSet (yyGLRStateSet
* yyset
)
847 free (yyset
->yystates
);
850 /** Initialize STACK to a single empty stack, with total maximum
851 * capacity for all stacks of SIZE. */
853 yyinitGLRStack (yyGLRStack
* yystack
, size_t yysize
)
855 yystack
->yyerrflag
= 0;
856 yystack
->yyerrState
= 0;
858 yystack
->yyspaceLeft
= yysize
;
859 yystack
->yynextFree
= yystack
->yyitems
=
860 (yyGLRStackItem
*) malloc (yysize
* sizeof (yystack
->yynextFree
[0]));
861 yystack
->yysplitPoint
= NULL
;
862 yystack
->yylastDeleted
= NULL
;
863 yyinitStateSet (&yystack
->yytops
);
866 #define YYRELOC(YYFROMITEMS,YYTOITEMS,YYX,YYTYPE) \
867 &((YYTOITEMS) - ((YYFROMITEMS) - (yyGLRStackItem*) (YYX)))->YYTYPE
869 /** If STACK is expandable, extend it. WARNING: Pointers into the
870 stack from outside should be considered invalid after this call.
871 We always expand when there are 1 or fewer items left AFTER an
872 allocation, so that we can avoid having external pointers exist
873 across an allocation. */
875 yyexpandGLRStack (yyGLRStack
* yystack
]b4_pure_formals
[)
877 #if YYSTACKEXPANDABLE
878 yyGLRStack yynewStack
;
879 yyGLRStackItem
* yyp0
, *yyp1
;
880 size_t yysize
, yynewSize
;
882 yysize
= yystack
->yynextFree
- yystack
->yyitems
;
883 if (YYMAXDEPTH
<= yysize
)
884 yyFail (yystack
][]b4_pure_args
[, "parser stack overflow");
885 yynewSize
= 2*yysize
;
886 if (YYMAXDEPTH
< yynewSize
)
887 yynewSize
= YYMAXDEPTH
;
888 yyinitGLRStack (&yynewStack
, yynewSize
);
889 for (yyp0
= yystack
->yyitems
, yyp1
= yynewStack
.yyitems
, yyn
= yysize
;
891 yyn
-= 1, yyp0
+= 1, yyp1
+= 1)
894 if (*(yybool
*) yyp0
)
896 yyGLRState
* yys0
= &yyp0
->yystate
;
897 yyGLRState
* yys1
= &yyp1
->yystate
;
898 if (yys0
->yypred
!= NULL
)
900 YYRELOC (yyp0
, yyp1
, yys0
->yypred
, yystate
);
901 if (! yys0
->yyresolved
&& yys0
->yysemantics
.yyfirstVal
!= NULL
)
902 yys1
->yysemantics
.yyfirstVal
=
903 YYRELOC(yyp0
, yyp1
, yys0
->yysemantics
.yyfirstVal
, yyoption
);
907 yySemanticOption
* yyv0
= &yyp0
->yyoption
;
908 yySemanticOption
* yyv1
= &yyp1
->yyoption
;
909 if (yyv0
->yystate
!= NULL
)
910 yyv1
->yystate
= YYRELOC (yyp0
, yyp1
, yyv0
->yystate
, yystate
);
911 if (yyv0
->yynext
!= NULL
)
912 yyv1
->yynext
= YYRELOC (yyp0
, yyp1
, yyv0
->yynext
, yyoption
);
915 if (yystack
->yysplitPoint
!= NULL
)
916 yystack
->yysplitPoint
= YYRELOC (yystack
->yyitems
, yynewStack
.yyitems
,
917 yystack
->yysplitPoint
, yystate
);
919 for (yyn
= 0; yyn
< yystack
->yytops
.yysize
; yyn
+= 1)
920 if (yystack
->yytops
.yystates
[yyn
] != NULL
)
921 yystack
->yytops
.yystates
[yyn
] =
922 YYRELOC (yystack
->yyitems
, yynewStack
.yyitems
,
923 yystack
->yytops
.yystates
[yyn
], yystate
);
924 free (yystack
->yyitems
);
925 yystack
->yyitems
= yynewStack
.yyitems
;
926 yystack
->yynextFree
= yynewStack
.yynextFree
+ yysize
;
927 yystack
->yyspaceLeft
= yynewStack
.yyspaceLeft
- yysize
;
931 yyFail (yystack
][]b4_lpure_args
[, "parser stack overflow");
936 yyfreeGLRStack (yyGLRStack
* yystack
)
938 free (yystack
->yyitems
);
939 yyfreeStateSet (&yystack
->yytops
);
942 /** Assuming that S is a GLRState somewhere on STACK, update the
943 * splitpoint of STACK, if needed, so that it is at least as deep as
946 yyupdateSplit (yyGLRStack
* yystack
, yyGLRState
* yys
)
948 if (yystack
->yysplitPoint
!= NULL
&& yystack
->yysplitPoint
> yys
)
949 yystack
->yysplitPoint
= yys
;
952 /** Invalidate stack #K in STACK. */
954 yymarkStackDeleted (yyGLRStack
* yystack
, int yyk
)
956 if (yystack
->yytops
.yystates
[yyk
] != NULL
)
957 yystack
->yylastDeleted
= yystack
->yytops
.yystates
[yyk
];
958 yystack
->yytops
.yystates
[yyk
] = NULL
;
961 /** Undelete the last stack that was marked as deleted. Can only be
962 done once after a deletion, and only when all other stacks have
965 yyundeleteLastStack (yyGLRStack
* yystack
)
967 if (yystack
->yylastDeleted
== NULL
|| yystack
->yytops
.yysize
!= 0)
969 yystack
->yytops
.yystates
[0] = yystack
->yylastDeleted
;
970 yystack
->yytops
.yysize
= 1;
971 YYDPRINTF ((stderr
, "Restoring last deleted stack as stack #0.\n"));
972 yystack
->yylastDeleted
= NULL
;
976 yyremoveDeletes (yyGLRStack
* yystack
)
980 while (yyj
< yystack
->yytops
.yysize
)
982 if (yystack
->yytops
.yystates
[yyi
] == NULL
)
986 YYDPRINTF ((stderr
, "Removing dead stacks.\n"));
988 yystack
->yytops
.yysize
-= 1;
992 yystack
->yytops
.yystates
[yyj
] = yystack
->yytops
.yystates
[yyi
];
995 YYDPRINTF ((stderr
, "Rename stack %d -> %d.\n", yyi
, yyj
));
1003 /** Shift to a new state on stack #K of STACK, corresponding to LR state
1004 * LRSTATE, at input position POSN, with (resolved) semantic value SVAL. */
1006 yyglrShift (yyGLRStack
* yystack
, int yyk
, yyStateNum yylrState
, size_t yyposn
,
1007 YYSTYPE yysval
, YYLTYPE
* yylocp
]b4_user_formals
[)
1009 yyGLRStackItem
* yynewItem
;
1011 yynewItem
= yystack
->yynextFree
;
1012 yystack
->yynextFree
+= 1;
1013 yystack
->yyspaceLeft
-= 1;
1014 yynewItem
->yystate
.yyisState
= yytrue
;
1015 yynewItem
->yystate
.yylrState
= yylrState
;
1016 yynewItem
->yystate
.yyposn
= yyposn
;
1017 yynewItem
->yystate
.yyresolved
= yytrue
;
1018 yynewItem
->yystate
.yypred
= yystack
->yytops
.yystates
[yyk
];
1019 yystack
->yytops
.yystates
[yyk
] = &yynewItem
->yystate
;
1020 yynewItem
->yystate
.yysemantics
.yysval
= yysval
;
1021 yynewItem
->yystate
.yyloc
= *yylocp
;
1022 if (yystack
->yyspaceLeft
< YYHEADROOM
)
1023 yyexpandGLRStack (yystack
]b4_pure_args
[);
1026 /** Shift stack #K of YYSTACK, to a new state corresponding to LR
1027 * state YYLRSTATE, at input position YYPOSN, with the (unresolved)
1028 * semantic value of YYRHS under the action for YYRULE. */
1030 yyglrShiftDefer (yyGLRStack
* yystack
, int yyk
, yyStateNum yylrState
,
1031 size_t yyposn
, yyGLRState
* rhs
, yyRuleNum yyrule
]b4_pure_formals
[)
1033 yyGLRStackItem
* yynewItem
;
1035 yynewItem
= yystack
->yynextFree
;
1036 yynewItem
->yystate
.yyisState
= yytrue
;
1037 yynewItem
->yystate
.yylrState
= yylrState
;
1038 yynewItem
->yystate
.yyposn
= yyposn
;
1039 yynewItem
->yystate
.yyresolved
= yyfalse
;
1040 yynewItem
->yystate
.yypred
= yystack
->yytops
.yystates
[yyk
];
1041 yynewItem
->yystate
.yysemantics
.yyfirstVal
= NULL
;
1042 yystack
->yytops
.yystates
[yyk
] = &yynewItem
->yystate
;
1043 yystack
->yynextFree
+= 1;
1044 yystack
->yyspaceLeft
-= 1;
1045 yyaddDeferredAction (yystack
, &yynewItem
->yystate
, rhs
, yyrule
]b4_pure_args
[);
1048 /** Pop the symbols consumed by reduction #RULE from the top of stack
1049 * #K of STACK, and perform the appropriate semantic action on their
1050 * semantic values. Assumes that all ambiguities in semantic values
1051 * have been previously resolved. Set *VALP to the resulting value,
1052 * and *LOCP to the computed location (if any). Return value is as
1053 * for userAction. */
1054 static inline YYRESULTTAG
1055 yydoAction (yyGLRStack
* yystack
, int yyk
, yyRuleNum yyrule
,
1056 YYSTYPE
* yyvalp
, YYLTYPE
* yylocp
]b4_user_formals
[)
1058 int yynrhs
= yyrhsLength (yyrule
);
1060 if (yystack
->yysplitPoint
== NULL
)
1062 /* Standard special case: single stack. */
1063 yyGLRStackItem
* rhs
= (yyGLRStackItem
*) yystack
->yytops
.yystates
[yyk
];
1066 yystack
->yynextFree
-= yynrhs
;
1067 yystack
->yyspaceLeft
+= yynrhs
;
1068 yystack
->yytops
.yystates
[0] = & yystack
->yynextFree
[-1].yystate
;
1071 *yyvalp
= yyval_default
;
1072 *yylocp
= yyloc_default
;
1076 *yyvalp
= rhs
[1-yynrhs
].yystate
.yysemantics
.yysval
;
1077 *yylocp
= rhs
[1-yynrhs
].yystate
.yyloc
;
1079 return yyuserAction (yyrule
, yynrhs
, rhs
,
1080 yyvalp
, yylocp
, yystack
]b4_user_args
[);
1086 yyGLRStackItem yyrhsVals
[YYMAXRHS
+1];
1087 yys
= yyrhsVals
[YYMAXRHS
].yystate
.yypred
= yystack
->yytops
.yystates
[yyk
];
1088 for (yyi
= 0; yyi
< yynrhs
; yyi
+= 1)
1094 yyupdateSplit (yystack
, yys
);
1095 yystack
->yytops
.yystates
[yyk
] = yys
;
1098 *yyvalp
= yyval_default
;
1099 *yylocp
= yyloc_default
;
1103 *yyvalp
= yyrhsVals
[1].yystate
.yysemantics
.yysval
;
1104 *yylocp
= yyrhsVals
[1].yystate
.yyloc
;
1106 return yyuserAction (yyrule
, yynrhs
, yyrhsVals
+ YYMAXRHS
- 1,
1107 yyvalp
, yylocp
, yystack
]b4_user_args
[);
1112 # define YY_REDUCE_PRINT(K, Rule)
1114 # define YY_REDUCE_PRINT(K, Rule) \
1117 yy_reduce_print (K, Rule); \
1120 /*----------------------------------------------------------.
1121 | Report that the RULE is going to be reduced on stack #K. |
1122 `----------------------------------------------------------*/
1125 yy_reduce_print (size_t yyk
, yyRuleNum yyrule
)
1128 unsigned int yylineno
= yyrline
[yyrule
];
1129 YYFPRINTF (stderr
, "Reducing stack %d by rule %d (line %u), ",
1130 yyk
, yyrule
- 1, yylineno
);
1131 /* Print the symbols being reduced, and their result. */
1132 for (yyi
= yyprhs
[yyrule
]; 0 <= yyrhs
[yyi
]; yyi
++)
1133 YYFPRINTF (stderr
, "%s ", yytokenName (yyrhs
[yyi
]));
1134 YYFPRINTF (stderr
, "-> %s\n", yytokenName (yyr1
[yyrule
]));
1138 /** Pop items off stack #K of STACK according to grammar rule RULE,
1139 * and push back on the resulting nonterminal symbol. Perform the
1140 * semantic action associated with RULE and store its value with the
1141 * newly pushed state, if FORCEEVAL or if STACK is currently
1142 * unambiguous. Otherwise, store the deferred semantic action with
1143 * the new state. If the new state would have an identical input
1144 * position, LR state, and predecessor to an existing state on the stack,
1145 * it is identified with that existing state, eliminating stack #K from
1146 * the STACK. In this case, the (necessarily deferred) semantic value is
1147 * added to the options for the existing state's semantic value.
1149 static inline YYRESULTTAG
1150 yyglrReduce (yyGLRStack
* yystack
, size_t yyk
, yyRuleNum yyrule
,
1151 yybool yyforceEval
]b4_pure_formals
[)
1153 size_t yyposn
= yystack
->yytops
.yystates
[yyk
]->yyposn
;
1155 if (yyforceEval
|| yystack
->yysplitPoint
== NULL
)
1160 YY_REDUCE_PRINT (yyk
, yyrule
);
1161 YYCHK (yydoAction (yystack
, yyk
, yyrule
, &yysval
, &yyloc
]b4_user_args
[));
1162 yyglrShift (yystack
, yyk
,
1163 yyLRgotoState (yystack
->yytops
.yystates
[yyk
]->yylrState
,
1164 yylhsNonterm (yyrule
)),
1165 yyposn
, yysval
, &yyloc
]b4_user_args
[);
1171 yyGLRState
* yys
, *yys0
= yystack
->yytops
.yystates
[yyk
];
1172 yyStateNum yynewLRState
;
1174 for (yys
= yystack
->yytops
.yystates
[yyk
], yyn
= yyrhsLength (yyrule
);
1181 yyupdateSplit (yystack
, yys
);
1182 yynewLRState
= yyLRgotoState (yys
->yylrState
, yylhsNonterm (yyrule
));
1184 "Reduced stack %d by rule #%d; action deferred. "
1185 "Now in state %d.\n",
1186 yyk
, yyrule
-1, yynewLRState
));
1187 for (yyi
= 0; yyi
< yystack
->yytops
.yysize
; yyi
+= 1)
1188 if (yyi
!= yyk
&& yystack
->yytops
.yystates
[yyi
] != NULL
)
1190 yyGLRState
* yyp
, *yysplit
= yystack
->yysplitPoint
;
1191 yyp
= yystack
->yytops
.yystates
[yyi
];
1192 while (yyp
!= yys
&& yyp
!= yysplit
&& yyp
->yyposn
>= yyposn
)
1194 if (yyp
->yylrState
== yynewLRState
&& yyp
->yypred
== yys
)
1196 yyaddDeferredAction (yystack
, yyp
, yys0
, yyrule
]b4_pure_args
[);
1197 yymarkStackDeleted (yystack
, yyk
);
1198 YYDPRINTF ((stderr
, "Merging stack %d into stack %d.\n",
1205 yystack
->yytops
.yystates
[yyk
] = yys
;
1206 yyglrShiftDefer (yystack
, yyk
, yynewLRState
, yyposn
, yys0
, yyrule
]b4_pure_args
[);
1212 yysplitStack (yyGLRStack
* yystack
, int yyk
)
1214 if (yystack
->yysplitPoint
== NULL
)
1218 yystack
->yysplitPoint
= yystack
->yytops
.yystates
[yyk
];
1220 if (yystack
->yytops
.yysize
>= yystack
->yytops
.yycapacity
)
1222 yystack
->yytops
.yycapacity
*= 2;
1223 yystack
->yytops
.yystates
=
1224 (yyGLRState
**) realloc (yystack
->yytops
.yystates
,
1225 yystack
->yytops
.yycapacity
1226 * sizeof (yyGLRState
*));
1228 yystack
->yytops
.yystates
[yystack
->yytops
.yysize
]
1229 = yystack
->yytops
.yystates
[yyk
];
1230 yystack
->yytops
.yysize
+= 1;
1231 return yystack
->yytops
.yysize
-1;
1234 /** True iff Y0 and Y1 represent identical options at the top level.
1235 * That is, they represent the same rule applied to RHS symbols
1236 * that produce the same terminal symbols. */
1238 yyidenticalOptions (yySemanticOption
* yyy0
, yySemanticOption
* yyy1
)
1240 if (yyy0
->yyrule
== yyy1
->yyrule
)
1242 yyGLRState
*yys0
, *yys1
;
1244 for (yys0
= yyy0
->yystate
, yys1
= yyy1
->yystate
,
1245 yyn
= yyrhsLength (yyy0
->yyrule
);
1247 yys0
= yys0
->yypred
, yys1
= yys1
->yypred
, yyn
-= 1)
1248 if (yys0
->yyposn
!= yys1
->yyposn
)
1256 /** Assuming identicalOptions (Y0,Y1), (destructively) merge the
1257 * alternative semantic values for the RHS-symbols of Y1 into the
1258 * corresponding semantic value sets of the symbols of Y0. */
1260 yymergeOptionSets (yySemanticOption
* yyy0
, yySemanticOption
* yyy1
)
1262 yyGLRState
*yys0
, *yys1
;
1264 for (yys0
= yyy0
->yystate
, yys1
= yyy1
->yystate
,
1265 yyn
= yyrhsLength (yyy0
->yyrule
);
1267 yys0
= yys0
->yypred
, yys1
= yys1
->yypred
, yyn
-= 1)
1270 else if (! yys0
->yyresolved
&& ! yys1
->yyresolved
)
1272 yySemanticOption
* yyz
;
1273 for (yyz
= yys0
->yysemantics
.yyfirstVal
; yyz
->yynext
!= NULL
;
1276 yyz
->yynext
= yys1
->yysemantics
.yyfirstVal
;
1280 /** Y0 and Y1 represent two possible actions to take in a given
1281 * parsing state; return 0 if no combination is possible,
1282 * 1 if user-mergeable, 2 if Y0 is preferred, 3 if Y1 is preferred. */
1284 yypreference (yySemanticOption
* y0
, yySemanticOption
* y1
)
1286 yyRuleNum r0
= y0
->yyrule
, r1
= y1
->yyrule
;
1287 int p0
= yydprec
[r0
], p1
= yydprec
[r1
];
1291 if (yymerger
[r0
] == 0 || yymerger
[r0
] != yymerger
[r1
])
1296 if (p0
== 0 || p1
== 0)
1305 static YYRESULTTAG
yyresolveValue (yySemanticOption
* yyoptionList
,
1306 yyGLRStack
* yystack
, YYSTYPE
* yyvalp
,
1307 YYLTYPE
* yylocp
]b4_user_formals
[);
1310 yyresolveStates (yyGLRState
* yys
, int yyn
, yyGLRStack
* yystack
]b4_user_formals
[)
1315 if (yys
->yypred
== NULL
)
1317 yyflag
= yyresolveStates (yys
->yypred
, yyn
-1, yystack
]b4_user_args
[);
1320 if (! yys
->yyresolved
)
1322 yyflag
= yyresolveValue (yys
->yysemantics
.yyfirstVal
, yystack
,
1323 &yys
->yysemantics
.yysval
, &yys
->yyloc
1327 yys
->yyresolved
= yytrue
;
1334 yyresolveAction (yySemanticOption
* yyopt
, yyGLRStack
* yystack
,
1335 YYSTYPE
* yyvalp
, YYLTYPE
* yylocp
]b4_user_formals
[)
1337 yyGLRStackItem yyrhsVals
[YYMAXRHS
+1];
1340 yynrhs
= yyrhsLength (yyopt
->yyrule
);
1341 YYCHK (yyresolveStates (yyopt
->yystate
, yynrhs
, yystack
]b4_user_args
[));
1342 yyrhsVals
[YYMAXRHS
].yystate
.yypred
= yyopt
->yystate
;
1343 return yyuserAction (yyopt
->yyrule
, yynrhs
, yyrhsVals
+ YYMAXRHS
- 1,
1344 yyvalp
, yylocp
, yystack
]b4_user_args
[);
1349 yyreportTree (yySemanticOption
* yyx
, int yyindent
)
1351 int yynrhs
= yyrhsLength (yyx
->yyrule
);
1354 yyGLRState
* yystates
[YYMAXRHS
];
1355 yyGLRState yyleftmost_state
;
1357 for (yyi
= yynrhs
, yys
= yyx
->yystate
; 0 < yyi
; yyi
-= 1, yys
= yys
->yypred
)
1358 yystates
[yyi
] = yys
;
1361 yyleftmost_state
.yyposn
= 0;
1362 yystates
[0] = &yyleftmost_state
;
1367 if (yyx
->yystate
->yyposn
< yys
->yyposn
+ 1)
1368 YYFPRINTF (stderr
, "%*s%s -> <Rule %d, empty>\n",
1369 yyindent
, "", yytokenName (yylhsNonterm (yyx
->yyrule
)),
1372 YYFPRINTF (stderr
, "%*s%s -> <Rule %d, tokens %d .. %d>\n",
1373 yyindent
, "", yytokenName (yylhsNonterm (yyx
->yyrule
)),
1374 yyx
->yyrule
, yys
->yyposn
+1, yyx
->yystate
->yyposn
);
1375 for (yyi
= 1; yyi
<= yynrhs
; yyi
+= 1)
1377 if (yystates
[yyi
]->yyresolved
)
1379 if (yystates
[yyi
-1]->yyposn
+1 > yystates
[yyi
]->yyposn
)
1380 YYFPRINTF (stderr
, "%*s%s <empty>\n", yyindent
+2, "",
1381 yytokenName (yyrhs
[yyprhs
[yyx
->yyrule
]+yyi
-1]));
1383 YYFPRINTF (stderr
, "%*s%s <tokens %d .. %d>\n", yyindent
+2, "",
1384 yytokenName (yyrhs
[yyprhs
[yyx
->yyrule
]+yyi
-1]),
1385 yystates
[yyi
-1]->yyposn
+1, yystates
[yyi
]->yyposn
);
1388 yyreportTree (yystates
[yyi
]->yysemantics
.yyfirstVal
, yyindent
+2);
1394 yyreportAmbiguity (yySemanticOption
* yyx0
, yySemanticOption
* yyx1
,
1395 yyGLRStack
* yystack
]b4_pure_formals
[)
1397 /* `Unused' warnings. */
1402 YYFPRINTF (stderr
, "Ambiguity detected.\n");
1403 YYFPRINTF (stderr
, "Option 1,\n");
1404 yyreportTree (yyx0
, 2);
1405 YYFPRINTF (stderr
, "\nOption 2,\n");
1406 yyreportTree (yyx1
, 2);
1407 YYFPRINTF (stderr
, "\n");
1409 yyFail (yystack
][]b4_pure_args
[, "ambiguity detected");
1413 /** Resolve the ambiguity represented by OPTIONLIST, perform the indicated
1414 * actions, and return the result. */
1416 yyresolveValue (yySemanticOption
* yyoptionList
, yyGLRStack
* yystack
,
1417 YYSTYPE
* yyvalp
, YYLTYPE
* yylocp
]b4_user_formals
[)
1419 yySemanticOption
* yybest
;
1420 yySemanticOption
* yyp
;
1423 yybest
= yyoptionList
;
1425 for (yyp
= yyoptionList
->yynext
; yyp
!= NULL
; yyp
= yyp
->yynext
)
1427 if (yyidenticalOptions (yybest
, yyp
))
1428 yymergeOptionSets (yybest
, yyp
);
1430 switch (yypreference (yybest
, yyp
))
1433 yyreportAmbiguity (yybest
, yyp
, yystack
]b4_pure_args
[);
1449 int yyprec
= yydprec
[yybest
->yyrule
];
1450 YYCHK (yyresolveAction (yybest
, yystack
, yyvalp
, yylocp
]b4_user_args
[));
1451 for (yyp
= yybest
->yynext
; yyp
!= NULL
; yyp
= yyp
->yynext
)
1453 if (yyprec
== yydprec
[yyp
->yyrule
])
1457 YYCHK (yyresolveAction (yyp
, yystack
, &yyval1
, &yydummy
]b4_user_args
[));
1458 *yyvalp
= yyuserMerge (yymerger
[yyp
->yyrule
], yyvalp
, &yyval1
);
1464 return yyresolveAction (yybest
, yystack
, yyvalp
, yylocp
]b4_user_args
[);
1468 yyresolveStack (yyGLRStack
* yystack
]b4_user_formals
[)
1470 if (yystack
->yysplitPoint
!= NULL
)
1475 for (yyn
= 0, yys
= yystack
->yytops
.yystates
[0];
1476 yys
!= yystack
->yysplitPoint
;
1477 yys
= yys
->yypred
, yyn
+= 1)
1479 YYCHK (yyresolveStates (yystack
->yytops
.yystates
[0], yyn
, yystack
1486 yycompressStack (yyGLRStack
* yystack
)
1488 yyGLRState
* yyp
, *yyq
, *yyr
;
1490 if (yystack
->yytops
.yysize
!= 1 || yystack
->yysplitPoint
== NULL
)
1493 for (yyp
= yystack
->yytops
.yystates
[0], yyq
= yyp
->yypred
, yyr
= NULL
;
1494 yyp
!= yystack
->yysplitPoint
;
1495 yyr
= yyp
, yyp
= yyq
, yyq
= yyp
->yypred
)
1498 yystack
->yyspaceLeft
+= yystack
->yynextFree
- yystack
->yyitems
;
1499 yystack
->yynextFree
= ((yyGLRStackItem
*) yystack
->yysplitPoint
) + 1;
1500 yystack
->yyspaceLeft
-= yystack
->yynextFree
- yystack
->yyitems
;
1501 yystack
->yysplitPoint
= NULL
;
1502 yystack
->yylastDeleted
= NULL
;
1506 yystack
->yynextFree
->yystate
= *yyr
;
1508 yystack
->yynextFree
->yystate
.yypred
= & yystack
->yynextFree
[-1].yystate
;
1509 yystack
->yytops
.yystates
[0] = &yystack
->yynextFree
->yystate
;
1510 yystack
->yynextFree
+= 1;
1511 yystack
->yyspaceLeft
-= 1;
1516 yyprocessOneStack (yyGLRStack
* yystack
, int yyk
,
1517 size_t yyposn
, YYSTYPE
* yylvalp
, YYLTYPE
* yyllocp
1521 const short* yyconflicts
;
1523 yySymbol
* const yytokenp
= yystack
->yytokenp
;
1525 while (yystack
->yytops
.yystates
[yyk
] != NULL
)
1527 yyStateNum yystate
= yystack
->yytops
.yystates
[yyk
]->yylrState
;
1528 YYDPRINTF ((stderr
, "Stack %d Entering state %d\n", yyk
, yystate
));
1530 if (yystate
== YYFINAL
)
1532 if (yyisDefaultedState (yystate
))
1534 yyrule
= yydefaultAction (yystate
);
1537 YYDPRINTF ((stderr
, "Stack %d dies.\n", yyk
));
1538 yymarkStackDeleted (yystack
, yyk
);
1541 YYCHK (yyglrReduce (yystack
, yyk
, yyrule
, yyfalse
]b4_lpure_args
[));
1545 if (*yytokenp
== YYEMPTY
)
1547 YYDPRINTF ((stderr
, "Reading a token: "));
1549 *yytokenp
= YYTRANSLATE (yychar
);
1550 YYDSYMPRINTF ("Next token is", *yytokenp
, yylvalp
, yyllocp
);
1552 yygetLRActions (yystate
, *yytokenp
, &yyaction
, &yyconflicts
);
1554 while (*yyconflicts
!= 0)
1556 int yynewStack
= yysplitStack (yystack
, yyk
);
1557 YYDPRINTF ((stderr
, "Splitting off stack %d from %d.\n",
1559 YYCHK (yyglrReduce (yystack
, yynewStack
,
1560 *yyconflicts
, yyfalse
]b4_lpure_args
[));
1561 YYCHK (yyprocessOneStack (yystack
, yynewStack
, yyposn
,
1562 yylvalp
, yyllocp
]b4_user_args
[));
1566 if (yyisShiftAction (yyaction
))
1568 YYDPRINTF ((stderr
, "Shifting token %s on stack %d, ",
1569 yytokenName (*yytokenp
), yyk
));
1570 yyglrShift (yystack
, yyk
, yyaction
, yyposn
+1,
1571 *yylvalp
, yyllocp
]b4_user_args
[);
1572 YYDPRINTF ((stderr
, "which is now in state #%d\n",
1573 yystack
->yytops
.yystates
[yyk
]->yylrState
));
1576 else if (yyisErrorAction (yyaction
))
1578 YYDPRINTF ((stderr
, "Stack %d dies.\n", yyk
));
1579 yymarkStackDeleted (yystack
, yyk
);
1583 YYCHK (yyglrReduce (yystack
, yyk
, -yyaction
, yyfalse
]b4_lpure_args
[));
1590 yyreportSyntaxError (yyGLRStack
* yystack
,
1591 YYSTYPE
* yylvalp
, YYLTYPE
* yyllocp
]b4_user_formals
[)
1593 /* `Unused' warnings. */
1597 if (yystack
->yyerrState
== 0)
1600 yySymbol
* const yytokenp
= yystack
->yytokenp
;
1601 int yyn
, yyx
, yycount
;
1603 const char* yyprefix
;
1606 yyn
= yypact
[yystack
->yytops
.yystates
[0]->yylrState
];
1607 if (YYPACT_NINF
< yyn
&& yyn
< YYLAST
)
1610 /* Start YYX at -YYN if negative to avoid negative indexes in
1612 yysize
= sizeof ("syntax error, unexpected ")
1613 + strlen (yytokenName (*yytokenp
));
1614 yyprefix
= ", expecting ";
1615 for (yyx
= yyn
< 0 ? -yyn
: 0; yyx
< yytname_size
&& yycount
<= 5;
1617 if (yycheck
[yyx
+ yyn
] == yyx
&& yyx
!= YYTERROR
)
1618 yysize
+= strlen (yytokenName (yyx
)) + strlen (yyprefix
),
1619 yycount
+= 1, yyprefix
= " or ";
1620 yymsg
= yyp
= (char*) malloc (yysize
);
1621 sprintf (yyp
, "syntax error, unexpected %s",
1622 yytokenName (*yytokenp
));
1623 yyp
+= strlen (yyp
);
1626 yyprefix
= ", expecting ";
1627 for (yyx
= yyn
< 0 ? -yyn
: 0; yyx
< yytname_size
; yyx
+= 1)
1628 if (yycheck
[yyx
+ yyn
] == yyx
&& yyx
!= YYTERROR
)
1630 sprintf (yyp
, "%s%s", yyprefix
, yytokenName (yyx
));
1631 yyp
+= strlen (yyp
);
1635 yyerror (]b4_lyyerror_args
[yymsg
);
1640 yyerror (]b4_lyyerror_args
["syntax error");
1645 /* Recover from a syntax error on YYSTACK, assuming that YYTOKENP,
1646 YYLVALP, and YYLLOCP point to the syntactic category, semantic
1647 value, and location of the lookahead. */
1649 yyrecoverSyntaxError (yyGLRStack
* yystack
,
1650 YYSTYPE
* yylvalp
, YYLTYPE
* yyllocp
]b4_user_formals
[)
1652 yySymbol
* const yytokenp
= yystack
->yytokenp
;
1656 if (yystack
->yyerrState
== 0)
1657 yystack
->yyerrState
= 3;
1658 else if (yystack
->yyerrState
== 3)
1659 /* We just shifted the error token and (perhaps) took some
1660 reductions. Skip tokens until we can proceed. */
1663 if (*yytokenp
== YYEOF
)
1665 /* Now pop stack until we find a state that shifts the
1667 while (yystack
->yytops
.yystates
[0] != NULL
)
1669 yyGLRState
*yys
= yystack
->yytops
.yystates
[0];
1670 YYDSYMPRINTF ("Error: popping",
1671 yystos
[yys
->yylrState
],
1672 &yys
->yysemantics
.yysval
, &yys
->yyloc
);
1673 yydestruct (yystos
[yys
->yylrState
],
1674 &yys
->yysemantics
.yysval
]b4_location_if([, &yys
->yyloc
])[);
1675 yystack
->yytops
.yystates
[0] = yys
->yypred
;
1676 yystack
->yynextFree
-= 1;
1677 yystack
->yyspaceLeft
+= 1;
1679 yyFail (yystack
][]b4_lpure_args
[, NULL
);
1681 if (*yytokenp
!= YYEMPTY
)
1683 YYDSYMPRINTF ("Error: discarding", *yytokenp
, yylvalp
, yyllocp
);
1684 yydestruct (*yytokenp
, yylvalp
]b4_location_if([, yyllocp
])[);
1686 YYDPRINTF ((stderr
, "Reading a token: "));
1688 *yytokenp
= YYTRANSLATE (yychar
);
1689 YYDSYMPRINTF ("Next token is", *yytokenp
, yylvalp
, yyllocp
);
1690 yyj
= yypact
[yystack
->yytops
.yystates
[0]->yylrState
];
1691 if (yyis_pact_ninf (yyj
))
1692 /* Something's not right; we shouldn't be here. */
1693 yyFail (yystack
][]b4_lpure_args
[, NULL
);
1695 if (yyj
< 0 || YYLAST
< yyj
|| yycheck
[yyj
] != *yytokenp
)
1697 if (yydefact
[yystack
->yytops
.yystates
[0]->yylrState
] != 0)
1700 else if (yytable
[yyj
] != 0 && ! yyis_table_ninf (yytable
[yyj
]))
1704 /* Reduce to one stack. */
1705 for (yyk
= 0; yyk
< yystack
->yytops
.yysize
; yyk
+= 1)
1706 if (yystack
->yytops
.yystates
[yyk
] != NULL
)
1708 if (yyk
>= yystack
->yytops
.yysize
)
1709 yyFail (yystack
][]b4_lpure_args
[, NULL
);
1710 for (yyk
+= 1; yyk
< yystack
->yytops
.yysize
; yyk
+= 1)
1711 yymarkStackDeleted (yystack
, yyk
);
1712 yyremoveDeletes (yystack
);
1713 yycompressStack (yystack
);
1715 /* Now pop stack until we find a state that shifts the error token. */
1716 while (yystack
->yytops
.yystates
[0] != NULL
)
1718 yyGLRState
*yys
= yystack
->yytops
.yystates
[0];
1719 yyj
= yypact
[yys
->yylrState
];
1720 if (! yyis_pact_ninf (yyj
))
1723 if (0 <= yyj
&& yyj
<= YYLAST
&& yycheck
[yyj
] == YYTERROR
1724 && yyisShiftAction (yytable
[yyj
]))
1726 YYDPRINTF ((stderr
, "Shifting error token, "));
1727 yyglrShift (yystack
, 0, yytable
[yyj
],
1728 yys
->yyposn
, *yylvalp
, yyllocp
]b4_user_args
[);
1732 YYDSYMPRINTF ("Error: popping",
1733 yystos
[yys
->yylrState
],
1734 &yys
->yysemantics
.yysval
, &yys
->yyloc
);
1735 yydestruct (yystos
[yys
->yylrState
],
1736 &yys
->yysemantics
.yysval
]b4_location_if([, &yys
->yyloc
])[);
1737 yystack
->yytops
.yystates
[0] = yys
->yypred
;
1738 yystack
->yynextFree
-= 1;
1739 yystack
->yyspaceLeft
+= 1;
1741 if (yystack
->yytops
.yystates
[0] == NULL
)
1742 yyFail (yystack
][]b4_lpure_args
[, NULL
);
1745 #define YYCHK1(YYE) \
1751 yystack.yyerrflag = 1; \
1754 yystack.yyerrflag = 0; \
1757 goto yyuser_error; \
1766 ]b4_c_ansi_function_def([yyparse
], [int], b4_parse_param
)[
1776 #define yychar (yystack.yyrawchar)
1779 YYSTYPE
* const yylvalp
= &yylval
;
1780 YYLTYPE
* const yyllocp
= &yylloc
;
1782 yyinitGLRStack (&yystack
, YYINITDEPTH
);
1783 yystack
.yytokenp
= &yytoken
;
1785 YYDPRINTF ((stderr
, "Starting parse\n"));
1787 if (setjmp (yystack
.yyexception_buffer
) != 0)
1790 yyglrShift (&yystack
, 0, 0, 0, yyval_default
, &yyloc_default
]b4_user_args
[);
1796 /* For efficiency, we have two loops, the first of which is
1797 specialized to deterministic operation (single stack, no
1798 potential ambiguity). */
1804 const short* yyconflicts
;
1806 yyStateNum yystate
= yystack
.yytops
.yystates
[0]->yylrState
;
1807 YYDPRINTF ((stderr
, "Entering state %d\n", yystate
));
1808 if (yystate
== YYFINAL
)
1810 if (yyisDefaultedState (yystate
))
1812 yyrule
= yydefaultAction (yystate
);
1815 yyreportSyntaxError (&yystack
, yylvalp
, yyllocp
]b4_user_args
[);
1818 YYCHK1 (yyglrReduce (&yystack
, 0, yyrule
, yytrue
]b4_lpure_args
[));
1822 if (yytoken
== YYEMPTY
)
1824 YYDPRINTF ((stderr
, "Reading a token: "));
1826 yytoken
= YYTRANSLATE (yychar
);
1827 YYDSYMPRINTF ("Next token is", yytoken
, yylvalp
, yyllocp
);
1829 yygetLRActions (yystate
, yytoken
, &yyaction
, &yyconflicts
);
1830 if (*yyconflicts
!= 0)
1832 if (yyisShiftAction (yyaction
))
1834 YYDPRINTF ((stderr
, "Shifting token %s, ",
1835 yytokenName (yytoken
)));
1836 if (yytoken
!= YYEOF
)
1839 yyglrShift (&yystack
, 0, yyaction
, yyposn
,
1840 yylval
, yyllocp
]b4_user_args
[);
1841 if (0 < yystack
.yyerrState
)
1842 yystack
.yyerrState
-= 1;
1844 else if (yyisErrorAction (yyaction
))
1846 yyreportSyntaxError (&yystack
, yylvalp
, yyllocp
]b4_user_args
[);
1850 YYCHK1 (yyglrReduce (&yystack
, 0, -yyaction
, yytrue
]b4_lpure_args
[));
1857 int yyn
= yystack
.yytops
.yysize
;
1858 for (yys
= 0; yys
< yyn
; yys
+= 1)
1859 YYCHK1 (yyprocessOneStack (&yystack
, yys
, yyposn
,
1860 yylvalp
, yyllocp
]b4_user_args
[));
1863 yyremoveDeletes (&yystack
);
1864 if (yystack
.yytops
.yysize
== 0)
1866 yyundeleteLastStack (&yystack
);
1867 if (yystack
.yytops
.yysize
== 0)
1868 yyFail (&yystack
][]b4_lpure_args
[, "syntax error");
1869 YYCHK1 (yyresolveStack (&yystack
]b4_user_args
[));
1870 YYDPRINTF ((stderr
, "Returning to deterministic operation.\n"));
1871 yyreportSyntaxError (&yystack
, yylvalp
, yyllocp
]b4_user_args
[);
1874 else if (yystack
.yytops
.yysize
== 1)
1876 YYCHK1 (yyresolveStack (&yystack
]b4_user_args
[));
1877 YYDPRINTF ((stderr
, "Returning to deterministic operation.\n"));
1878 yycompressStack (&yystack
);
1884 yyrecoverSyntaxError (&yystack
, yylvalp
, yyllocp
]b4_user_args
[);
1885 yyposn
= yystack
.yytops
.yystates
[0]->yyposn
;
1890 yyfreeGLRStack (&yystack
);
1891 return yystack
.yyerrflag
;
1894 /* DEBUGGING ONLY */
1895 static void yypstack (yyGLRStack
* yystack
, int yyk
) ATTRIBUTE_UNUSED
;
1896 static void yypdumpstack (yyGLRStack
* yystack
) ATTRIBUTE_UNUSED
;
1899 yy_yypstack (yyGLRState
* yys
)
1903 yy_yypstack (yys
->yypred
);
1904 fprintf (stderr
, " -> ");
1906 fprintf (stderr
, "%d@@%lu", yys
->yylrState
, (unsigned long) yys
->yyposn
);
1910 yypstates (yyGLRState
* yyst
)
1913 fprintf (stderr
, "<null>");
1916 fprintf (stderr
, "\n");
1920 yypstack (yyGLRStack
* yystack
, int yyk
)
1922 yypstates (yystack
->yytops
.yystates
[yyk
]);
1925 #define YYINDEX(YYX) \
1926 ((YYX) == NULL ? -1 : (yyGLRStackItem*) (YYX) - yystack->yyitems)
1930 yypdumpstack (yyGLRStack
* yystack
)
1932 yyGLRStackItem
* yyp
;
1934 for (yyp
= yystack
->yyitems
; yyp
< yystack
->yynextFree
; yyp
+= 1)
1936 fprintf (stderr
, "%3lu. ", (unsigned long) (yyp
- yystack
->yyitems
));
1937 if (*(yybool
*) yyp
)
1939 fprintf (stderr
, "Res: %d, LR State: %d, posn: %lu, pred: %ld",
1940 yyp
->yystate
.yyresolved
, yyp
->yystate
.yylrState
,
1941 (unsigned long) yyp
->yystate
.yyposn
,
1942 (long) YYINDEX (yyp
->yystate
.yypred
));
1943 if (! yyp
->yystate
.yyresolved
)
1944 fprintf (stderr
, ", firstVal: %ld",
1945 (long) YYINDEX (yyp
->yystate
.yysemantics
.yyfirstVal
));
1949 fprintf (stderr
, "Option. rule: %d, state: %ld, next: %ld",
1950 yyp
->yyoption
.yyrule
,
1951 (long) YYINDEX (yyp
->yyoption
.yystate
),
1952 (long) YYINDEX (yyp
->yyoption
.yynext
));
1954 fprintf (stderr
, "\n");
1956 fprintf (stderr
, "Tops:");
1957 for (yyi
= 0; yyi
< yystack
->yytops
.yysize
; yyi
+= 1)
1958 fprintf (stderr
, "%lu: %ld; ", (unsigned long) yyi
,
1959 (long) YYINDEX (yystack
->yytops
.yystates
[yyi
]));
1960 fprintf (stderr
, "\n");
1965 m4_if(b4_defines_flag
, 0, [],
1966 [@output @output_header_name@
1967 b4_copyright([Skeleton parser
for GLR parsing with Bison
], [2002, 2003])
1969 b4_token_defines(b4_tokens
)
1971 #if ! defined (YYSTYPE) && ! defined (YYSTYPE_IS_DECLARED)
1972 m4_ifdef([b4_stype
],
1973 [b4_syncline([b4_stype_line
], [b4_filename
])
1974 typedef union m4_bregexp(b4_stype
, [^{], [YYSTYPE
])b4_stype YYSTYPE
;
1975 /* Line __line__ of glr.c. */
1976 b4_syncline([@oline@
], [@ofile@
])],
1977 [typedef int YYSTYPE
;])
1978 # define YYSTYPE_IS_DECLARED 1
1979 # define YYSTYPE_IS_TRIVIAL 1
1983 [extern YYSTYPE b4_prefix
[]lval
;])
1986 [#if ! defined (YYLTYPE) && ! defined (YYLTYPE_IS_DECLARED)
1987 typedef struct YYLTYPE
1994 # define YYLTYPE_IS_DECLARED 1
1995 # define YYLTYPE_IS_TRIVIAL 1
1999 [extern YYLTYPE b4_prefix
[]lloc
;])