]> git.saurik.com Git - bison.git/blob - data/glr.c
(YYOPTIONAL_LOC): Define even if it's not a recent
[bison.git] / data / glr.c
1 m4_divert(-1) -*- C -*-
2
3 # GLR skeleton for Bison
4 # Copyright (C) 2002, 2003, 2004, 2005 Free Software Foundation, Inc.
5
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.
10
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.
15
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., 51 Franklin Street, Fifth Floor, Boston, MA
19 # 02110-1301 USA
20
21
22 ## ---------------- ##
23 ## Default values. ##
24 ## ---------------- ##
25
26 # Stack parameters.
27 m4_define_default([b4_stack_depth_max], [10000])
28 m4_define_default([b4_stack_depth_init], [200])
29
30
31
32 ## ------------------------ ##
33 ## Pure/impure interfaces. ##
34 ## ------------------------ ##
35
36
37 # b4_lex_param
38 # ------------
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)))
45
46
47 # b4_user_formals
48 # ---------------
49 m4_define([b4_user_formals],
50 [m4_ifset([b4_parse_param], [, b4_c_ansi_formals(b4_parse_param)])])
51
52
53 # b4_yyerror_args
54 # ---------------
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), ])])
59
60
61 # b4_lyyerror_args
62 # ----------------
63 # Same as above, but on the look-ahead, 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), ])])
67
68
69 # b4_pure_args
70 # ------------
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])
74
75
76 # b4_pure_formals
77 # ---------------
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])
81
82
83 # b4_lpure_args
84 # -------------
85 # Same as above, but on the look-ahead, hence yyllocp instead of yylocp.
86 m4_define([b4_lpure_args],
87 [b4_pure_if([b4_location_if([, yyllocp])])[]b4_user_args])
88
89
90 # b4_lpure_formals
91 # ----------------
92 # Same as above, but on the look-ahead, hence yyllocp instead of yylocp.
93 m4_define([b4_lpure_formals],
94 [b4_pure_if([b4_location_if([YYLTYPE *yyllocp])])[]b4_user_formals])
95
96
97 ## ----------------- ##
98 ## Semantic Values. ##
99 ## ----------------- ##
100
101
102 # b4_lhs_value([TYPE])
103 # --------------------
104 # Expansion of $<TYPE>$.
105 m4_define([b4_lhs_value],
106 [((*yyvalp)[]m4_ifval([$1], [.$1]))])
107
108
109 # b4_rhs_value(RULE-LENGTH, NUM, [TYPE])
110 # --------------------------------------
111 # Expansion of $<TYPE>NUM, where the current rule has RULE-LENGTH
112 # symbols on RHS.
113 m4_define([b4_rhs_value],
114 [(((yyGLRStackItem const *)yyvsp)@{YYFILL (m4_eval([$2 - $1]))@}.yystate.yysemantics.yysval[]m4_ifval([$3], [.$3]))])
115
116
117
118 ## ----------- ##
119 ## Locations. ##
120 ## ----------- ##
121
122 # b4_lhs_location()
123 # -----------------
124 # Expansion of @$.
125 m4_define([b4_lhs_location],
126 [(*yylocp)])
127
128
129 # b4_rhs_location(RULE-LENGTH, NUM)
130 # ---------------------------------
131 # Expansion of @NUM, where the current rule has RULE-LENGTH symbols
132 # on RHS.
133 m4_define([b4_rhs_location],
134 [(((yyGLRStackItem const *)yyvsp)@{YYFILL (m4_eval([$2 - $1]))@}.yystate.yyloc)])
135
136 # We do want M4 expansion after # for CPP macros.
137 m4_changecom()
138 m4_divert(0)dnl
139 @output @output_parser_name@
140 b4_copyright([Skeleton parser for GLR parsing with Bison],
141 [2002, 2003, 2004, 2005])
142 [
143 /* This is the parser code for GLR (Generalized LR) parser. */
144
145 ]b4_identification
146 m4_if(b4_prefix[], [yy], [],
147 [/* Substitute the variable and function names. */
148 #define yyparse b4_prefix[]parse
149 #define yylex b4_prefix[]lex
150 #define yyerror b4_prefix[]error
151 #define yylval b4_prefix[]lval
152 #define yychar b4_prefix[]char
153 #define yydebug b4_prefix[]debug
154 #define yynerrs b4_prefix[]nerrs
155 #define yylloc b4_prefix[]lloc])
156
157 b4_token_defines(b4_tokens)
158
159 /* Copy the first part of user declarations. */
160 b4_pre_prologue[
161
162 /* Enabling traces. */
163 #ifndef YYDEBUG
164 # define YYDEBUG ]b4_debug[
165 #endif
166
167 /* Enabling verbose error messages. */
168 #ifdef YYERROR_VERBOSE
169 # undef YYERROR_VERBOSE
170 # define YYERROR_VERBOSE 1
171 #else
172 # define YYERROR_VERBOSE ]b4_error_verbose[
173 #endif
174
175 /* Enabling the token table. */
176 #ifndef YYTOKEN_TABLE
177 # define YYTOKEN_TABLE ]b4_token_table[
178 #endif
179
180 #if ! defined (YYSTYPE) && ! defined (YYSTYPE_IS_DECLARED)
181 ]m4_ifdef([b4_stype],
182 [b4_syncline([b4_stype_line], [b4_filename])
183 typedef union m4_bregexp(b4_stype, [^{], [YYSTYPE ])b4_stype YYSTYPE;
184 /* Line __line__ of glr.c. */
185 b4_syncline([@oline@], [@ofile@])],
186 [typedef int YYSTYPE;])[
187 # define YYSTYPE_IS_DECLARED 1
188 # define YYSTYPE_IS_TRIVIAL 1
189 #endif
190
191 #if ! defined (YYLTYPE) && ! defined (YYLTYPE_IS_DECLARED)
192 typedef struct YYLTYPE
193 {
194 ]b4_location_if([
195 int first_line;
196 int first_column;
197 int last_line;
198 int last_column;
199 ],[
200 char yydummy;
201 ])[
202 } YYLTYPE;
203 # define YYLTYPE_IS_DECLARED 1
204 # define YYLTYPE_IS_TRIVIAL 1
205 #endif
206
207 /* Default (constant) value used for initialization for null
208 right-hand sides. Unlike the standard yacc.c template,
209 here we set the default value of $$ to a zeroed-out value.
210 Since the default value is undefined, this behavior is
211 technically correct. */
212 static YYSTYPE yyval_default;
213
214 /* Copy the second part of user declarations. */
215 ]b4_post_prologue[
216
217 ]/* Line __line__ of glr.c. */
218 b4_syncline([@oline@], [@ofile@])
219 [
220 #include <stdio.h>
221 #include <stdlib.h>
222 #include <string.h>
223 #include <stdarg.h>
224 #include <setjmp.h>
225
226 #ifndef YY_
227 # if YYENABLE_NLS
228 # if ENABLE_NLS
229 # include <libintl.h> /* INFRINGES ON USER NAME SPACE */
230 # define YY_(msgid) dgettext ("bison-runtime", msgid)
231 # endif
232 # endif
233 # ifndef YY_
234 # define YY_(msgid) msgid
235 # endif
236 #endif
237
238 #ifndef YYFREE
239 # define YYFREE free
240 #endif
241 #ifndef YYMALLOC
242 # define YYMALLOC malloc
243 #endif
244 #ifndef YYREALLOC
245 # define YYREALLOC realloc
246 #endif
247
248 #define YYSIZEMAX ((size_t) -1)
249
250 #ifdef __cplusplus
251 typedef bool yybool;
252 #else
253 typedef unsigned char yybool;
254 #endif
255 #define yytrue 1
256 #define yyfalse 0
257
258 /*-----------------.
259 | GCC extensions. |
260 `-----------------*/
261
262 #ifndef __attribute__
263 /* This feature is available in gcc versions 2.5 and later. */
264 # if (!defined (__GNUC__) || __GNUC__ < 2 \
265 || (__GNUC__ == 2 && __GNUC_MINOR__ < 5) || __STRICT_ANSI__)
266 # define __attribute__(Spec) /* empty */
267 # endif
268 #endif
269
270 ]b4_location_if([#define YYOPTIONAL_LOC(Name) Name],[
271 #ifdef __cplusplus
272 # define YYOPTIONAL_LOC(Name) /* empty */
273 #else
274 # define YYOPTIONAL_LOC(Name) Name __attribute__ ((__unused__))
275 #endif])[
276
277 #ifndef YYASSERT
278 # define YYASSERT(condition) ((void) ((condition) || (abort (), 0)))
279 #endif
280
281 /* YYFINAL -- State number of the termination state. */
282 #define YYFINAL ]b4_final_state_number[
283 /* YYLAST -- Last index in YYTABLE. */
284 #define YYLAST ]b4_last[
285
286 /* YYNTOKENS -- Number of terminals. */
287 #define YYNTOKENS ]b4_tokens_number[
288 /* YYNNTS -- Number of nonterminals. */
289 #define YYNNTS ]b4_nterms_number[
290 /* YYNRULES -- Number of rules. */
291 #define YYNRULES ]b4_rules_number[
292 /* YYNRULES -- Number of states. */
293 #define YYNSTATES ]b4_states_number[
294 /* YYMAXRHS -- Maximum number of symbols on right-hand side of rule. */
295 #define YYMAXRHS ]b4_r2_max[
296 /* YYMAXLEFT -- Maximum number of symbols to the left of a handle
297 accessed by $0, $-1, etc., in any rule. */
298 #define YYMAXLEFT ]b4_max_left_semantic_context[
299
300 /* YYTRANSLATE(X) -- Bison symbol number corresponding to X. */
301 #define YYUNDEFTOK ]b4_undef_token_number[
302 #define YYMAXUTOK ]b4_user_token_number_max[
303
304 #define YYTRANSLATE(YYX) \
305 ((YYX <= 0) ? YYEOF : \
306 (unsigned int) (YYX) <= YYMAXUTOK ? yytranslate[YYX] : YYUNDEFTOK)
307
308 /* YYTRANSLATE[YYLEX] -- Bison symbol number corresponding to YYLEX. */
309 static const ]b4_int_type_for([b4_translate])[ yytranslate[] =
310 {
311 ]b4_translate[
312 };
313
314 #if YYDEBUG
315 /* YYPRHS[YYN] -- Index of the first RHS symbol of rule number YYN in
316 YYRHS. */
317 static const ]b4_int_type_for([b4_prhs])[ yyprhs[] =
318 {
319 ]b4_prhs[
320 };
321
322 /* YYRHS -- A `-1'-separated list of the rules' RHS. */
323 static const ]b4_int_type_for([b4_rhs])[ yyrhs[] =
324 {
325 ]b4_rhs[
326 };
327
328 /* YYRLINE[YYN] -- source line where rule number YYN was defined. */
329 static const ]b4_int_type_for([b4_rline])[ yyrline[] =
330 {
331 ]b4_rline[
332 };
333 #endif
334
335 #if YYDEBUG || YYERROR_VERBOSE || YYTOKEN_TABLE
336 /* YYTNAME[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM.
337 First, the terminals, then, starting at YYNTOKENS, nonterminals. */
338 static const char *const yytname[] =
339 {
340 ]b4_tname[
341 };
342 #endif
343
344 /* YYR1[YYN] -- Symbol number of symbol that rule YYN derives. */
345 static const ]b4_int_type_for([b4_r1])[ yyr1[] =
346 {
347 ]b4_r1[
348 };
349
350 /* YYR2[YYN] -- Number of symbols composing right hand side of rule YYN. */
351 static const ]b4_int_type_for([b4_r2])[ yyr2[] =
352 {
353 ]b4_r2[
354 };
355
356 /* YYDPREC[RULE-NUM] -- Dynamic precedence of rule #RULE-NUM (0 if none). */
357 static const ]b4_int_type_for([b4_dprec])[ yydprec[] =
358 {
359 ]b4_dprec[
360 };
361
362 /* YYMERGER[RULE-NUM] -- Index of merging function for rule #RULE-NUM. */
363 static const ]b4_int_type_for([b4_merger])[ yymerger[] =
364 {
365 ]b4_merger[
366 };
367
368 /* YYDEFACT[S] -- default rule to reduce with in state S when YYTABLE
369 doesn't specify something else to do. Zero means the default is an
370 error. */
371 static const ]b4_int_type_for([b4_defact])[ yydefact[] =
372 {
373 ]b4_defact[
374 };
375
376 /* YYPDEFGOTO[NTERM-NUM]. */
377 static const ]b4_int_type_for([b4_defgoto])[ yydefgoto[] =
378 {
379 ]b4_defgoto[
380 };
381
382 /* YYPACT[STATE-NUM] -- Index in YYTABLE of the portion describing
383 STATE-NUM. */
384 #define YYPACT_NINF ]b4_pact_ninf[
385 static const ]b4_int_type_for([b4_pact])[ yypact[] =
386 {
387 ]b4_pact[
388 };
389
390 /* YYPGOTO[NTERM-NUM]. */
391 static const ]b4_int_type_for([b4_pgoto])[ yypgoto[] =
392 {
393 ]b4_pgoto[
394 };
395
396 /* YYTABLE[YYPACT[STATE-NUM]]. What to do in state STATE-NUM. If
397 positive, shift that token. If negative, reduce the rule which
398 number is the opposite. If zero, do what YYDEFACT says.
399 If YYTABLE_NINF, syntax error. */
400 #define YYTABLE_NINF ]b4_table_ninf[
401 static const ]b4_int_type_for([b4_table])[ yytable[] =
402 {
403 ]b4_table[
404 };
405
406 /* YYCONFLP[YYPACT[STATE-NUM]] -- Pointer into YYCONFL of start of
407 list of conflicting reductions corresponding to action entry for
408 state STATE-NUM in yytable. 0 means no conflicts. The list in
409 yyconfl is terminated by a rule number of 0. */
410 static const ]b4_int_type_for([b4_conflict_list_heads])[ yyconflp[] =
411 {
412 ]b4_conflict_list_heads[
413 };
414
415 /* YYCONFL[I] -- lists of conflicting rule numbers, each terminated by
416 0, pointed into by YYCONFLP. */
417 ]dnl Do not use b4_int_type_for here, since there are places where
418 dnl pointers onto yyconfl are taken, which type is "short int *".
419 dnl We probably ought to introduce a type for confl.
420 [static const short int yyconfl[] =
421 {
422 ]b4_conflicting_rules[
423 };
424
425 static const ]b4_int_type_for([b4_check])[ yycheck[] =
426 {
427 ]b4_check[
428 };
429
430 /* YYSTOS[STATE-NUM] -- The (internal number of the) accessing
431 symbol of state STATE-NUM. */
432 static const ]b4_int_type_for([b4_stos])[ yystos[] =
433 {
434 ]b4_stos[
435 };
436
437 \f
438 /* Prevent warning if -Wmissing-prototypes. */
439 ]b4_c_ansi_function_decl([yyparse], [int], b4_parse_param)[
440
441 /* Error token number */
442 #define YYTERROR 1
443
444 /* YYLLOC_DEFAULT -- Set CURRENT to span from RHS[1] to RHS[N].
445 If N is 0, then set CURRENT to the empty location which ends
446 the previous symbol: RHS[0] (always defined). */
447
448 ]b4_location_if([[
449 #define YYRHSLOC(Rhs, K) ((Rhs)[K].yystate.yyloc)
450 #ifndef YYLLOC_DEFAULT
451 # define YYLLOC_DEFAULT(Current, Rhs, N) \
452 do \
453 if (N) \
454 { \
455 (Current).first_line = YYRHSLOC (Rhs, 1).first_line; \
456 (Current).first_column = YYRHSLOC (Rhs, 1).first_column; \
457 (Current).last_line = YYRHSLOC (Rhs, N).last_line; \
458 (Current).last_column = YYRHSLOC (Rhs, N).last_column; \
459 } \
460 else \
461 { \
462 (Current).first_line = (Current).last_line = \
463 YYRHSLOC (Rhs, 0).last_line; \
464 (Current).first_column = (Current).last_column = \
465 YYRHSLOC (Rhs, 0).last_column; \
466 } \
467 while (0)
468
469 /* YY_LOCATION_PRINT -- Print the location on the stream.
470 This macro was not mandated originally: define only if we know
471 we won't break user code: when these are the locations we know. */
472
473 # define YY_LOCATION_PRINT(File, Loc) \
474 fprintf (File, "%d.%d-%d.%d", \
475 (Loc).first_line, (Loc).first_column, \
476 (Loc).last_line, (Loc).last_column)
477 #endif
478 ]],[
479 #ifndef YYLLOC_DEFAULT
480 # define YYLLOC_DEFAULT(Current, Rhs, N) ((void) 0)
481 #endif
482 ])[
483
484 #ifndef YY_LOCATION_PRINT
485 # define YY_LOCATION_PRINT(File, Loc) ((void) 0)
486 #endif
487
488
489 /* YYLEX -- calling `yylex' with the right arguments. */
490 #define YYLEX ]b4_c_function_call([yylex], [int], b4_lex_param)[
491
492 ]b4_pure_if(
493 [
494 #undef yynerrs
495 #define yynerrs (yystack->yyerrcnt)
496 #undef yychar
497 #define yychar (yystack->yyrawchar)],
498 [YYSTYPE yylval;
499
500 YYLTYPE yylloc;
501
502 int yynerrs;
503 int yychar;])[
504
505 static const int YYEOF = 0;
506 static const int YYEMPTY = -2;
507
508 typedef enum { yyok, yyaccept, yyabort, yyerr } YYRESULTTAG;
509
510 #define YYCHK(YYE) \
511 do { YYRESULTTAG yyflag = YYE; if (yyflag != yyok) return yyflag; } \
512 while (0)
513
514 #if YYDEBUG
515
516 #if ! defined (YYFPRINTF)
517 # define YYFPRINTF fprintf
518 #endif
519
520 # define YYDPRINTF(Args) \
521 do { \
522 if (yydebug) \
523 YYFPRINTF Args; \
524 } while (0)
525
526 ]b4_yysymprint_generate([b4_c_ansi_function_def])[
527
528 # define YY_SYMBOL_PRINT(Title, Type, Value, Location) \
529 do { \
530 if (yydebug) \
531 { \
532 YYFPRINTF (stderr, "%s ", Title); \
533 yysymprint (stderr, \
534 Type, Value]b4_location_if([, Location])[); \
535 } \
536 } while (0)
537
538 /* Nonzero means print parse trace. It is left uninitialized so that
539 multiple parsers can coexist. */
540 int yydebug;
541
542 #else /* !YYDEBUG */
543
544 # define YYDPRINTF(Args)
545 # define YY_SYMBOL_PRINT(Title, Type, Value, Location)
546
547 #endif /* !YYDEBUG */
548
549 /* YYINITDEPTH -- initial size of the parser's stacks. */
550 #ifndef YYINITDEPTH
551 # define YYINITDEPTH ]b4_stack_depth_init[
552 #endif
553
554 /* YYMAXDEPTH -- maximum size the stacks can grow to (effective only
555 if the built-in stack extension method is used).
556
557 Do not make this value too large; the results are undefined if
558 SIZE_MAX < YYMAXDEPTH * sizeof (GLRStackItem)
559 evaluated with infinite-precision integer arithmetic. */
560
561 #ifndef YYMAXDEPTH
562 # define YYMAXDEPTH ]b4_stack_depth_max[
563 #endif
564
565 /* Minimum number of free items on the stack allowed after an
566 allocation. This is to allow allocation and initialization
567 to be completed by functions that call yyexpandGLRStack before the
568 stack is expanded, thus insuring that all necessary pointers get
569 properly redirected to new data. */
570 #define YYHEADROOM 2
571
572 #ifndef YYSTACKEXPANDABLE
573 # if (! defined (__cplusplus) \
574 || (]b4_location_if([[defined (YYLTYPE_IS_TRIVIAL) && YYLTYPE_IS_TRIVIAL \
575 && ]])[defined (YYSTYPE_IS_TRIVIAL) && YYSTYPE_IS_TRIVIAL))
576 # define YYSTACKEXPANDABLE 1
577 # else
578 # define YYSTACKEXPANDABLE 0
579 # endif
580 #endif
581
582 #if YYERROR_VERBOSE
583
584 # ifndef yystpcpy
585 # if defined (__GLIBC__) && defined (_STRING_H) && defined (_GNU_SOURCE)
586 # define yystpcpy stpcpy
587 # else
588 /* Copy YYSRC to YYDEST, returning the address of the terminating '\0' in
589 YYDEST. */
590 static char *
591 yystpcpy (char *yydest, const char *yysrc)
592 {
593 char *yyd = yydest;
594 const char *yys = yysrc;
595
596 while ((*yyd++ = *yys++) != '\0')
597 continue;
598
599 return yyd - 1;
600 }
601 # endif
602 # endif
603
604 # ifndef yytnamerr
605 /* Copy to YYRES the contents of YYSTR after stripping away unnecessary
606 quotes and backslashes, so that it's suitable for yyerror. The
607 heuristic is that double-quoting is unnecessary unless the string
608 contains an apostrophe, a comma, or backslash (other than
609 backslash-backslash). YYSTR is taken from yytname. If YYRES is
610 null, do not copy; instead, return the length of what the result
611 would have been. */
612 static size_t
613 yytnamerr (char *yyres, const char *yystr)
614 {
615 if (*yystr == '"')
616 {
617 size_t yyn = 0;
618 char const *yyp = yystr;
619
620 for (;;)
621 switch (*++yyp)
622 {
623 case '\'':
624 case ',':
625 goto do_not_strip_quotes;
626
627 case '\\':
628 if (*++yyp != '\\')
629 goto do_not_strip_quotes;
630 /* Fall through. */
631 default:
632 if (yyres)
633 yyres[yyn] = *yyp;
634 yyn++;
635 break;
636
637 case '"':
638 if (yyres)
639 yyres[yyn] = '\0';
640 return yyn;
641 }
642 do_not_strip_quotes: ;
643 }
644
645 if (! yyres)
646 return strlen (yystr);
647
648 return yystpcpy (yyres, yystr) - yyres;
649 }
650 # endif
651
652 #endif /* !YYERROR_VERBOSE */
653
654 /** State numbers, as in LALR(1) machine */
655 typedef int yyStateNum;
656
657 /** Rule numbers, as in LALR(1) machine */
658 typedef int yyRuleNum;
659
660 /** Grammar symbol */
661 typedef short int yySymbol;
662
663 /** Item references, as in LALR(1) machine */
664 typedef short int yyItemNum;
665
666 typedef struct yyGLRState yyGLRState;
667 typedef struct yySemanticOption yySemanticOption;
668 typedef union yyGLRStackItem yyGLRStackItem;
669 typedef struct yyGLRStack yyGLRStack;
670 typedef struct yyGLRStateSet yyGLRStateSet;
671
672 struct yyGLRState {
673 /** Type tag: always true. */
674 yybool yyisState;
675 /** Type tag for yysemantics. If true, yysval applies, otherwise
676 * yyfirstVal applies. */
677 yybool yyresolved;
678 /** Number of corresponding LALR(1) machine state. */
679 yyStateNum yylrState;
680 /** Preceding state in this stack */
681 yyGLRState* yypred;
682 /** Source position of the first token produced by my symbol */
683 size_t yyposn;
684 union {
685 /** First in a chain of alternative reductions producing the
686 * non-terminal corresponding to this state, threaded through
687 * yynext. */
688 yySemanticOption* yyfirstVal;
689 /** Semantic value for this state. */
690 YYSTYPE yysval;
691 } yysemantics;
692 /** Source location for this state. */
693 YYLTYPE yyloc;
694 };
695
696 struct yyGLRStateSet {
697 yyGLRState** yystates;
698 size_t yysize, yycapacity;
699 };
700
701 struct yySemanticOption {
702 /** Type tag: always false. */
703 yybool yyisState;
704 /** Rule number for this reduction */
705 yyRuleNum yyrule;
706 /** The last RHS state in the list of states to be reduced. */
707 yyGLRState* yystate;
708 /** Next sibling in chain of options. To facilitate merging,
709 * options are chained in decreasing order by address. */
710 yySemanticOption* yynext;
711 };
712
713 /** Type of the items in the GLR stack. The yyisState field
714 * indicates which item of the union is valid. */
715 union yyGLRStackItem {
716 yyGLRState yystate;
717 yySemanticOption yyoption;
718 };
719
720 struct yyGLRStack {
721 int yyerrState;
722 ]b4_location_if([[ /* To compute the location of the error token. */
723 yyGLRStackItem yyerror_range[3];]])[
724 ]b4_pure_if(
725 [
726 int yyerrcnt;
727 int yyrawchar;
728 ])[
729 yySymbol* yytokenp;
730 jmp_buf yyexception_buffer;
731 yyGLRStackItem* yyitems;
732 yyGLRStackItem* yynextFree;
733 size_t yyspaceLeft;
734 yyGLRState* yysplitPoint;
735 yyGLRState* yylastDeleted;
736 yyGLRStateSet yytops;
737 };
738
739 static void yyexpandGLRStack (yyGLRStack* yystack);
740
741 static void yyFail (yyGLRStack* yystack]b4_pure_formals[, const char* yymsg)
742 __attribute__ ((__noreturn__));
743 static void
744 yyFail (yyGLRStack* yystack]b4_pure_formals[, const char* yymsg)
745 {
746 if (yymsg != NULL)
747 yyerror (]b4_yyerror_args[yymsg);
748 longjmp (yystack->yyexception_buffer, 1);
749 }
750
751 static void yyMemoryExhausted (yyGLRStack* yystack)
752 __attribute__ ((__noreturn__));
753 static void
754 yyMemoryExhausted (yyGLRStack* yystack)
755 {
756 longjmp (yystack->yyexception_buffer, 2);
757 }
758
759 #if YYDEBUG || YYERROR_VERBOSE
760 /** A printable representation of TOKEN. */
761 static inline const char*
762 yytokenName (yySymbol yytoken)
763 {
764 if (yytoken == YYEMPTY)
765 return "";
766
767 return yytname[yytoken];
768 }
769 #endif
770
771 /** Fill in YYVSP[YYLOW1 .. YYLOW0-1] from the chain of states starting
772 * at YYVSP[YYLOW0].yystate.yypred. Leaves YYVSP[YYLOW1].yystate.yypred
773 * containing the pointer to the next state in the chain. Assumes
774 * YYLOW1 < YYLOW0. */
775 static void yyfillin (yyGLRStackItem *, int, int) __attribute__ ((__unused__));
776 static void
777 yyfillin (yyGLRStackItem *yyvsp, int yylow0, int yylow1)
778 {
779 yyGLRState* s;
780 int i;
781 s = yyvsp[yylow0].yystate.yypred;
782 for (i = yylow0-1; i >= yylow1; i -= 1)
783 {
784 YYASSERT (s->yyresolved);
785 yyvsp[i].yystate.yyresolved = yytrue;
786 yyvsp[i].yystate.yysemantics.yysval = s->yysemantics.yysval;
787 yyvsp[i].yystate.yyloc = s->yyloc;
788 s = yyvsp[i].yystate.yypred = s->yypred;
789 }
790 }
791
792 /* Do nothing if YYNORMAL or if *YYLOW <= YYLOW1. Otherwise, fill in
793 YYVSP[YYLOW1 .. *YYLOW-1] as in yyfillin and set *YYLOW = YYLOW1.
794 For convenience, always return YYLOW1. */
795 static inline int yyfill (yyGLRStackItem *, int *, int, yybool)
796 __attribute__ ((__unused__));
797 static inline int
798 yyfill (yyGLRStackItem *yyvsp, int *yylow, int yylow1, yybool yynormal)
799 {
800 if (!yynormal && yylow1 < *yylow)
801 {
802 yyfillin (yyvsp, *yylow, yylow1);
803 *yylow = yylow1;
804 }
805 return yylow1;
806 }
807
808 /** Perform user action for rule number YYN, with RHS length YYRHSLEN,
809 * and top stack item YYVSP. YYLVALP points to place to put semantic
810 * value ($$), and yylocp points to place for location information
811 * (@@$). Returns yyok for normal return, yyaccept for YYACCEPT,
812 * yyerr for YYERROR, yyabort for YYABORT. */
813 static YYRESULTTAG
814 yyuserAction (yyRuleNum yyn, int yyrhslen, yyGLRStackItem* yyvsp,
815 YYSTYPE* yyvalp,
816 YYLTYPE* YYOPTIONAL_LOC (yylocp),
817 yyGLRStack* yystack
818 ]b4_user_formals[)
819 {
820 yybool yynormal __attribute__ ((__unused__)) =
821 (yystack->yysplitPoint == NULL);
822 int yylow;
823
824 # undef yyerrok
825 # define yyerrok (yystack->yyerrState = 0)
826 # undef YYACCEPT
827 # define YYACCEPT return yyaccept
828 # undef YYABORT
829 # define YYABORT return yyabort
830 # undef YYERROR
831 # define YYERROR return yyerrok, yyerr
832 # undef YYRECOVERING
833 # define YYRECOVERING (yystack->yyerrState != 0)
834 # undef yyclearin
835 # define yyclearin (yychar = *(yystack->yytokenp) = YYEMPTY)
836 # undef YYFILL
837 # define YYFILL(N) yyfill (yyvsp, &yylow, N, yynormal)
838 # undef YYBACKUP
839 # define YYBACKUP(Token, Value) \
840 return yyerror (]b4_yyerror_args[YY_("syntax error: cannot back up")), \
841 yyerrok, yyerr
842
843 yylow = 1;
844 if (yyrhslen == 0)
845 *yyvalp = yyval_default;
846 else
847 *yyvalp = yyvsp[YYFILL (1-yyrhslen)].yystate.yysemantics.yysval;
848 YYLLOC_DEFAULT (*yylocp, yyvsp - yyrhslen, yyrhslen);
849 ]b4_location_if([[ yystack->yyerror_range[1].yystate.yyloc = *yylocp;
850 ]])
851 switch (yyn)
852 {
853 b4_actions
854 default: break;
855 }
856
857 return yyok;
858 # undef yyerrok
859 # undef YYABORT
860 # undef YYACCEPT
861 # undef YYERROR
862 # undef YYBACKUP
863 # undef yyclearin
864 # undef YYRECOVERING
865 /* Line __line__ of glr.c. */
866 b4_syncline([@oline@], [@ofile@])
867 }
868 \f
869
870 static void
871 yyuserMerge (int yyn, YYSTYPE* yy0, YYSTYPE* yy1)
872 {
873 /* `Use' the arguments. */
874 (void) yy0;
875 (void) yy1;
876
877 switch (yyn)
878 {
879 b4_mergers
880 default: break;
881 }
882 }
883 [
884 /* Bison grammar-table manipulation. */
885
886 ]b4_yydestruct_generate([b4_c_ansi_function_def])[
887
888 /** Number of symbols composing the right hand side of rule #RULE. */
889 static inline int
890 yyrhsLength (yyRuleNum yyrule)
891 {
892 return yyr2[yyrule];
893 }
894
895 /** Left-hand-side symbol for rule #RULE. */
896 static inline yySymbol
897 yylhsNonterm (yyRuleNum yyrule)
898 {
899 return yyr1[yyrule];
900 }
901
902 #define yyis_pact_ninf(yystate) \
903 ]m4_if(m4_eval(b4_pact_ninf < b4_pact_min), 1,
904 0,
905 ((yystate) == YYPACT_NINF))[
906
907 /** True iff LR state STATE has only a default reduction (regardless
908 * of token). */
909 static inline yybool
910 yyisDefaultedState (yyStateNum yystate)
911 {
912 return yyis_pact_ninf (yypact[yystate]);
913 }
914
915 /** The default reduction for STATE, assuming it has one. */
916 static inline yyRuleNum
917 yydefaultAction (yyStateNum yystate)
918 {
919 return yydefact[yystate];
920 }
921
922 #define yyis_table_ninf(yytable_value) \
923 ]m4_if(m4_eval(b4_table_ninf < b4_table_min), 1,
924 0,
925 ((yytable_value) == YYTABLE_NINF))[
926
927 /** Set *YYACTION to the action to take in YYSTATE on seeing YYTOKEN.
928 * Result R means
929 * R < 0: Reduce on rule -R.
930 * R = 0: Error.
931 * R > 0: Shift to state R.
932 * Set *CONFLICTS to a pointer into yyconfl to 0-terminated list of
933 * conflicting reductions.
934 */
935 static inline void
936 yygetLRActions (yyStateNum yystate, int yytoken,
937 int* yyaction, const short int** yyconflicts)
938 {
939 int yyindex = yypact[yystate] + yytoken;
940 if (yyindex < 0 || YYLAST < yyindex || yycheck[yyindex] != yytoken)
941 {
942 *yyaction = -yydefact[yystate];
943 *yyconflicts = yyconfl;
944 }
945 else if (! yyis_table_ninf (yytable[yyindex]))
946 {
947 *yyaction = yytable[yyindex];
948 *yyconflicts = yyconfl + yyconflp[yyindex];
949 }
950 else
951 {
952 *yyaction = 0;
953 *yyconflicts = yyconfl + yyconflp[yyindex];
954 }
955 }
956
957 static inline yyStateNum
958 yyLRgotoState (yyStateNum yystate, yySymbol yylhs)
959 {
960 int yyr;
961 yyr = yypgoto[yylhs - YYNTOKENS] + yystate;
962 if (0 <= yyr && yyr <= YYLAST && yycheck[yyr] == yystate)
963 return yytable[yyr];
964 else
965 return yydefgoto[yylhs - YYNTOKENS];
966 }
967
968 static inline yybool
969 yyisShiftAction (int yyaction)
970 {
971 return 0 < yyaction;
972 }
973
974 static inline yybool
975 yyisErrorAction (int yyaction)
976 {
977 return yyaction == 0;
978 }
979
980 /* GLRStates */
981
982 static void
983 yyaddDeferredAction (yyGLRStack* yystack, yyGLRState* yystate,
984 yyGLRState* rhs, yyRuleNum yyrule)
985 {
986 yySemanticOption* yynewItem;
987 yynewItem = &yystack->yynextFree->yyoption;
988 yystack->yyspaceLeft -= 1;
989 yystack->yynextFree += 1;
990 yynewItem->yyisState = yyfalse;
991 yynewItem->yystate = rhs;
992 yynewItem->yyrule = yyrule;
993 yynewItem->yynext = yystate->yysemantics.yyfirstVal;
994 yystate->yysemantics.yyfirstVal = yynewItem;
995 if (yystack->yyspaceLeft < YYHEADROOM)
996 yyexpandGLRStack (yystack);
997 }
998
999 /* GLRStacks */
1000
1001 /** Initialize SET to a singleton set containing an empty stack. */
1002 static yybool
1003 yyinitStateSet (yyGLRStateSet* yyset)
1004 {
1005 yyset->yysize = 1;
1006 yyset->yycapacity = 16;
1007 yyset->yystates = (yyGLRState**) YYMALLOC (16 * sizeof yyset->yystates[0]);
1008 if (! yyset->yystates)
1009 return yyfalse;
1010 yyset->yystates[0] = NULL;
1011 return yytrue;
1012 }
1013
1014 static void yyfreeStateSet (yyGLRStateSet* yyset)
1015 {
1016 YYFREE (yyset->yystates);
1017 }
1018
1019 /** Initialize STACK to a single empty stack, with total maximum
1020 * capacity for all stacks of SIZE. */
1021 static yybool
1022 yyinitGLRStack (yyGLRStack* yystack, size_t yysize)
1023 {
1024 yystack->yyerrState = 0;
1025 yynerrs = 0;
1026 yystack->yyspaceLeft = yysize;
1027 yystack->yyitems =
1028 (yyGLRStackItem*) YYMALLOC (yysize * sizeof yystack->yynextFree[0]);
1029 if (!yystack->yyitems)
1030 return yyfalse;
1031 yystack->yynextFree = yystack->yyitems;
1032 yystack->yysplitPoint = NULL;
1033 yystack->yylastDeleted = NULL;
1034 return yyinitStateSet (&yystack->yytops);
1035 }
1036
1037 #define YYRELOC(YYFROMITEMS,YYTOITEMS,YYX,YYTYPE) \
1038 &((YYTOITEMS) - ((YYFROMITEMS) - (yyGLRStackItem*) (YYX)))->YYTYPE
1039
1040 /** If STACK is expandable, extend it. WARNING: Pointers into the
1041 stack from outside should be considered invalid after this call.
1042 We always expand when there are 1 or fewer items left AFTER an
1043 allocation, so that we can avoid having external pointers exist
1044 across an allocation. */
1045 static void
1046 yyexpandGLRStack (yyGLRStack* yystack)
1047 {
1048 #if YYSTACKEXPANDABLE
1049 yyGLRStackItem* yynewItems;
1050 yyGLRStackItem* yyp0, *yyp1;
1051 size_t yysize, yynewSize;
1052 size_t yyn;
1053 yysize = yystack->yynextFree - yystack->yyitems;
1054 if (YYMAXDEPTH <= yysize)
1055 yyMemoryExhausted (yystack);
1056 yynewSize = 2*yysize;
1057 if (YYMAXDEPTH < yynewSize)
1058 yynewSize = YYMAXDEPTH;
1059 yynewItems = (yyGLRStackItem*) YYMALLOC (yynewSize * sizeof yynewItems[0]);
1060 if (! yynewItems)
1061 yyMemoryExhausted (yystack);
1062 for (yyp0 = yystack->yyitems, yyp1 = yynewItems, yyn = yysize;
1063 0 < yyn;
1064 yyn -= 1, yyp0 += 1, yyp1 += 1)
1065 {
1066 *yyp1 = *yyp0;
1067 if (*(yybool *) yyp0)
1068 {
1069 yyGLRState* yys0 = &yyp0->yystate;
1070 yyGLRState* yys1 = &yyp1->yystate;
1071 if (yys0->yypred != NULL)
1072 yys1->yypred =
1073 YYRELOC (yyp0, yyp1, yys0->yypred, yystate);
1074 if (! yys0->yyresolved && yys0->yysemantics.yyfirstVal != NULL)
1075 yys1->yysemantics.yyfirstVal =
1076 YYRELOC(yyp0, yyp1, yys0->yysemantics.yyfirstVal, yyoption);
1077 }
1078 else
1079 {
1080 yySemanticOption* yyv0 = &yyp0->yyoption;
1081 yySemanticOption* yyv1 = &yyp1->yyoption;
1082 if (yyv0->yystate != NULL)
1083 yyv1->yystate = YYRELOC (yyp0, yyp1, yyv0->yystate, yystate);
1084 if (yyv0->yynext != NULL)
1085 yyv1->yynext = YYRELOC (yyp0, yyp1, yyv0->yynext, yyoption);
1086 }
1087 }
1088 if (yystack->yysplitPoint != NULL)
1089 yystack->yysplitPoint = YYRELOC (yystack->yyitems, yynewItems,
1090 yystack->yysplitPoint, yystate);
1091
1092 for (yyn = 0; yyn < yystack->yytops.yysize; yyn += 1)
1093 if (yystack->yytops.yystates[yyn] != NULL)
1094 yystack->yytops.yystates[yyn] =
1095 YYRELOC (yystack->yyitems, yynewItems,
1096 yystack->yytops.yystates[yyn], yystate);
1097 YYFREE (yystack->yyitems);
1098 yystack->yyitems = yynewItems;
1099 yystack->yynextFree = yynewItems + yysize;
1100 yystack->yyspaceLeft = yynewSize - yysize;
1101
1102 #else
1103 yyMemoryExhausted (yystack);
1104 #endif
1105 }
1106
1107 static void
1108 yyfreeGLRStack (yyGLRStack* yystack)
1109 {
1110 YYFREE (yystack->yyitems);
1111 yyfreeStateSet (&yystack->yytops);
1112 }
1113
1114 /** Assuming that S is a GLRState somewhere on STACK, update the
1115 * splitpoint of STACK, if needed, so that it is at least as deep as
1116 * S. */
1117 static inline void
1118 yyupdateSplit (yyGLRStack* yystack, yyGLRState* yys)
1119 {
1120 if (yystack->yysplitPoint != NULL && yystack->yysplitPoint > yys)
1121 yystack->yysplitPoint = yys;
1122 }
1123
1124 /** Invalidate stack #K in STACK. */
1125 static inline void
1126 yymarkStackDeleted (yyGLRStack* yystack, size_t yyk)
1127 {
1128 if (yystack->yytops.yystates[yyk] != NULL)
1129 yystack->yylastDeleted = yystack->yytops.yystates[yyk];
1130 yystack->yytops.yystates[yyk] = NULL;
1131 }
1132
1133 /** Undelete the last stack that was marked as deleted. Can only be
1134 done once after a deletion, and only when all other stacks have
1135 been deleted. */
1136 static void
1137 yyundeleteLastStack (yyGLRStack* yystack)
1138 {
1139 if (yystack->yylastDeleted == NULL || yystack->yytops.yysize != 0)
1140 return;
1141 yystack->yytops.yystates[0] = yystack->yylastDeleted;
1142 yystack->yytops.yysize = 1;
1143 YYDPRINTF ((stderr, "Restoring last deleted stack as stack #0.\n"));
1144 yystack->yylastDeleted = NULL;
1145 }
1146
1147 static inline void
1148 yyremoveDeletes (yyGLRStack* yystack)
1149 {
1150 size_t yyi, yyj;
1151 yyi = yyj = 0;
1152 while (yyj < yystack->yytops.yysize)
1153 {
1154 if (yystack->yytops.yystates[yyi] == NULL)
1155 {
1156 if (yyi == yyj)
1157 {
1158 YYDPRINTF ((stderr, "Removing dead stacks.\n"));
1159 }
1160 yystack->yytops.yysize -= 1;
1161 }
1162 else
1163 {
1164 yystack->yytops.yystates[yyj] = yystack->yytops.yystates[yyi];
1165 if (yyj != yyi)
1166 {
1167 YYDPRINTF ((stderr, "Rename stack %lu -> %lu.\n",
1168 (unsigned long int) yyi, (unsigned long int) yyj));
1169 }
1170 yyj += 1;
1171 }
1172 yyi += 1;
1173 }
1174 }
1175
1176 /** Shift to a new state on stack #K of STACK, corresponding to LR state
1177 * LRSTATE, at input position POSN, with (resolved) semantic value SVAL. */
1178 static inline void
1179 yyglrShift (yyGLRStack* yystack, size_t yyk, yyStateNum yylrState,
1180 size_t yyposn,
1181 YYSTYPE yysval, YYLTYPE* yylocp)
1182 {
1183 yyGLRStackItem* yynewItem;
1184
1185 yynewItem = yystack->yynextFree;
1186 yystack->yynextFree += 1;
1187 yystack->yyspaceLeft -= 1;
1188 yynewItem->yystate.yyisState = yytrue;
1189 yynewItem->yystate.yylrState = yylrState;
1190 yynewItem->yystate.yyposn = yyposn;
1191 yynewItem->yystate.yyresolved = yytrue;
1192 yynewItem->yystate.yypred = yystack->yytops.yystates[yyk];
1193 yystack->yytops.yystates[yyk] = &yynewItem->yystate;
1194 yynewItem->yystate.yysemantics.yysval = yysval;
1195 yynewItem->yystate.yyloc = *yylocp;
1196 if (yystack->yyspaceLeft < YYHEADROOM)
1197 yyexpandGLRStack (yystack);
1198 }
1199
1200 /** Shift stack #K of YYSTACK, to a new state corresponding to LR
1201 * state YYLRSTATE, at input position YYPOSN, with the (unresolved)
1202 * semantic value of YYRHS under the action for YYRULE. */
1203 static inline void
1204 yyglrShiftDefer (yyGLRStack* yystack, size_t yyk, yyStateNum yylrState,
1205 size_t yyposn, yyGLRState* rhs, yyRuleNum yyrule)
1206 {
1207 yyGLRStackItem* yynewItem;
1208
1209 yynewItem = yystack->yynextFree;
1210 yynewItem->yystate.yyisState = yytrue;
1211 yynewItem->yystate.yylrState = yylrState;
1212 yynewItem->yystate.yyposn = yyposn;
1213 yynewItem->yystate.yyresolved = yyfalse;
1214 yynewItem->yystate.yypred = yystack->yytops.yystates[yyk];
1215 yynewItem->yystate.yysemantics.yyfirstVal = NULL;
1216 yystack->yytops.yystates[yyk] = &yynewItem->yystate;
1217 yystack->yynextFree += 1;
1218 yystack->yyspaceLeft -= 1;
1219 yyaddDeferredAction (yystack, &yynewItem->yystate, rhs, yyrule);
1220 }
1221
1222 /** Pop the symbols consumed by reduction #RULE from the top of stack
1223 * #K of STACK, and perform the appropriate semantic action on their
1224 * semantic values. Assumes that all ambiguities in semantic values
1225 * have been previously resolved. Set *VALP to the resulting value,
1226 * and *LOCP to the computed location (if any). Return value is as
1227 * for userAction. */
1228 static inline YYRESULTTAG
1229 yydoAction (yyGLRStack* yystack, size_t yyk, yyRuleNum yyrule,
1230 YYSTYPE* yyvalp, YYLTYPE* yylocp]b4_user_formals[)
1231 {
1232 int yynrhs = yyrhsLength (yyrule);
1233
1234 if (yystack->yysplitPoint == NULL)
1235 {
1236 /* Standard special case: single stack. */
1237 yyGLRStackItem* rhs = (yyGLRStackItem*) yystack->yytops.yystates[yyk];
1238 YYASSERT (yyk == 0);
1239 yystack->yynextFree -= yynrhs;
1240 yystack->yyspaceLeft += yynrhs;
1241 yystack->yytops.yystates[0] = & yystack->yynextFree[-1].yystate;
1242 return yyuserAction (yyrule, yynrhs, rhs,
1243 yyvalp, yylocp, yystack]b4_user_args[);
1244 }
1245 else
1246 {
1247 int yyi;
1248 yyGLRState* yys;
1249 yyGLRStackItem yyrhsVals[YYMAXRHS + YYMAXLEFT + 1];
1250 yys = yyrhsVals[YYMAXRHS + YYMAXLEFT].yystate.yypred
1251 = yystack->yytops.yystates[yyk];
1252 for (yyi = 0; yyi < yynrhs; yyi += 1)
1253 {
1254 yys = yys->yypred;
1255 YYASSERT (yys);
1256 }
1257 yyupdateSplit (yystack, yys);
1258 yystack->yytops.yystates[yyk] = yys;
1259 return yyuserAction (yyrule, yynrhs, yyrhsVals + YYMAXRHS + YYMAXLEFT - 1,
1260 yyvalp, yylocp, yystack]b4_user_args[);
1261 }
1262 }
1263
1264 #if !YYDEBUG
1265 # define YY_REDUCE_PRINT(K, Rule)
1266 #else
1267 # define YY_REDUCE_PRINT(K, Rule) \
1268 do { \
1269 if (yydebug) \
1270 yy_reduce_print (K, Rule); \
1271 } while (0)
1272
1273 /*----------------------------------------------------------.
1274 | Report that the RULE is going to be reduced on stack #K. |
1275 `----------------------------------------------------------*/
1276
1277 static inline void
1278 yy_reduce_print (size_t yyk, yyRuleNum yyrule)
1279 {
1280 int yyi;
1281 YYFPRINTF (stderr, "Reducing stack %lu by rule %d (line %lu), ",
1282 (unsigned long int) yyk, yyrule - 1,
1283 (unsigned long int) yyrline[yyrule]);
1284 /* Print the symbols being reduced, and their result. */
1285 for (yyi = yyprhs[yyrule]; 0 <= yyrhs[yyi]; yyi++)
1286 YYFPRINTF (stderr, "%s ", yytokenName (yyrhs[yyi]));
1287 YYFPRINTF (stderr, "-> %s\n", yytokenName (yyr1[yyrule]));
1288 }
1289 #endif
1290
1291 /** Pop items off stack #K of STACK according to grammar rule RULE,
1292 * and push back on the resulting nonterminal symbol. Perform the
1293 * semantic action associated with RULE and store its value with the
1294 * newly pushed state, if FORCEEVAL or if STACK is currently
1295 * unambiguous. Otherwise, store the deferred semantic action with
1296 * the new state. If the new state would have an identical input
1297 * position, LR state, and predecessor to an existing state on the stack,
1298 * it is identified with that existing state, eliminating stack #K from
1299 * the STACK. In this case, the (necessarily deferred) semantic value is
1300 * added to the options for the existing state's semantic value.
1301 */
1302 static inline YYRESULTTAG
1303 yyglrReduce (yyGLRStack* yystack, size_t yyk, yyRuleNum yyrule,
1304 yybool yyforceEval]b4_user_formals[)
1305 {
1306 size_t yyposn = yystack->yytops.yystates[yyk]->yyposn;
1307
1308 if (yyforceEval || yystack->yysplitPoint == NULL)
1309 {
1310 YYSTYPE yysval;
1311 YYLTYPE yyloc;
1312
1313 YY_REDUCE_PRINT (yyk, yyrule);
1314 YYCHK (yydoAction (yystack, yyk, yyrule, &yysval, &yyloc]b4_user_args[));
1315 yyglrShift (yystack, yyk,
1316 yyLRgotoState (yystack->yytops.yystates[yyk]->yylrState,
1317 yylhsNonterm (yyrule)),
1318 yyposn, yysval, &yyloc);
1319 }
1320 else
1321 {
1322 size_t yyi;
1323 int yyn;
1324 yyGLRState* yys, *yys0 = yystack->yytops.yystates[yyk];
1325 yyStateNum yynewLRState;
1326
1327 for (yys = yystack->yytops.yystates[yyk], yyn = yyrhsLength (yyrule);
1328 0 < yyn; yyn -= 1)
1329 {
1330 yys = yys->yypred;
1331 YYASSERT (yys);
1332 }
1333 yyupdateSplit (yystack, yys);
1334 yynewLRState = yyLRgotoState (yys->yylrState, yylhsNonterm (yyrule));
1335 YYDPRINTF ((stderr,
1336 "Reduced stack %lu by rule #%d; action deferred. Now in state %d.\n",
1337 (unsigned long int) yyk, yyrule - 1, yynewLRState));
1338 for (yyi = 0; yyi < yystack->yytops.yysize; yyi += 1)
1339 if (yyi != yyk && yystack->yytops.yystates[yyi] != NULL)
1340 {
1341 yyGLRState* yyp, *yysplit = yystack->yysplitPoint;
1342 yyp = yystack->yytops.yystates[yyi];
1343 while (yyp != yys && yyp != yysplit && yyp->yyposn >= yyposn)
1344 {
1345 if (yyp->yylrState == yynewLRState && yyp->yypred == yys)
1346 {
1347 yyaddDeferredAction (yystack, yyp, yys0, yyrule);
1348 yymarkStackDeleted (yystack, yyk);
1349 YYDPRINTF ((stderr, "Merging stack %lu into stack %lu.\n",
1350 (unsigned long int) yyk,
1351 (unsigned long int) yyi));
1352 return yyok;
1353 }
1354 yyp = yyp->yypred;
1355 }
1356 }
1357 yystack->yytops.yystates[yyk] = yys;
1358 yyglrShiftDefer (yystack, yyk, yynewLRState, yyposn, yys0, yyrule);
1359 }
1360 return yyok;
1361 }
1362
1363 static size_t
1364 yysplitStack (yyGLRStack* yystack, size_t yyk)
1365 {
1366 if (yystack->yysplitPoint == NULL)
1367 {
1368 YYASSERT (yyk == 0);
1369 yystack->yysplitPoint = yystack->yytops.yystates[yyk];
1370 }
1371 if (yystack->yytops.yysize >= yystack->yytops.yycapacity)
1372 {
1373 yyGLRState** yynewStates;
1374 if (! ((yystack->yytops.yycapacity
1375 <= (YYSIZEMAX / (2 * sizeof yynewStates[0])))
1376 && (yynewStates =
1377 (yyGLRState**) YYREALLOC (yystack->yytops.yystates,
1378 ((yystack->yytops.yycapacity *= 2)
1379 * sizeof yynewStates[0])))))
1380 yyMemoryExhausted (yystack);
1381 yystack->yytops.yystates = yynewStates;
1382 }
1383 yystack->yytops.yystates[yystack->yytops.yysize]
1384 = yystack->yytops.yystates[yyk];
1385 yystack->yytops.yysize += 1;
1386 return yystack->yytops.yysize-1;
1387 }
1388
1389 /** True iff Y0 and Y1 represent identical options at the top level.
1390 * That is, they represent the same rule applied to RHS symbols
1391 * that produce the same terminal symbols. */
1392 static yybool
1393 yyidenticalOptions (yySemanticOption* yyy0, yySemanticOption* yyy1)
1394 {
1395 if (yyy0->yyrule == yyy1->yyrule)
1396 {
1397 yyGLRState *yys0, *yys1;
1398 int yyn;
1399 for (yys0 = yyy0->yystate, yys1 = yyy1->yystate,
1400 yyn = yyrhsLength (yyy0->yyrule);
1401 yyn > 0;
1402 yys0 = yys0->yypred, yys1 = yys1->yypred, yyn -= 1)
1403 if (yys0->yyposn != yys1->yyposn)
1404 return yyfalse;
1405 return yytrue;
1406 }
1407 else
1408 return yyfalse;
1409 }
1410
1411 /** Assuming identicalOptions (Y0,Y1), destructively merge the
1412 * alternative semantic values for the RHS-symbols of Y1 and Y0. */
1413 static void
1414 yymergeOptionSets (yySemanticOption* yyy0, yySemanticOption* yyy1)
1415 {
1416 yyGLRState *yys0, *yys1;
1417 int yyn;
1418 for (yys0 = yyy0->yystate, yys1 = yyy1->yystate,
1419 yyn = yyrhsLength (yyy0->yyrule);
1420 yyn > 0;
1421 yys0 = yys0->yypred, yys1 = yys1->yypred, yyn -= 1)
1422 {
1423 if (yys0 == yys1)
1424 break;
1425 else if (yys0->yyresolved)
1426 {
1427 yys1->yyresolved = yytrue;
1428 yys1->yysemantics.yysval = yys0->yysemantics.yysval;
1429 }
1430 else if (yys1->yyresolved)
1431 {
1432 yys0->yyresolved = yytrue;
1433 yys0->yysemantics.yysval = yys1->yysemantics.yysval;
1434 }
1435 else
1436 {
1437 yySemanticOption** yyz0p;
1438 yySemanticOption* yyz1;
1439 yyz0p = &yys0->yysemantics.yyfirstVal;
1440 yyz1 = yys1->yysemantics.yyfirstVal;
1441 while (yytrue)
1442 {
1443 if (yyz1 == *yyz0p || yyz1 == NULL)
1444 break;
1445 else if (*yyz0p == NULL)
1446 {
1447 *yyz0p = yyz1;
1448 break;
1449 }
1450 else if (*yyz0p < yyz1)
1451 {
1452 yySemanticOption* yyz = *yyz0p;
1453 *yyz0p = yyz1;
1454 yyz1 = yyz1->yynext;
1455 (*yyz0p)->yynext = yyz;
1456 }
1457 yyz0p = &(*yyz0p)->yynext;
1458 }
1459 yys1->yysemantics.yyfirstVal = yys0->yysemantics.yyfirstVal;
1460 }
1461 }
1462 }
1463
1464 /** Y0 and Y1 represent two possible actions to take in a given
1465 * parsing state; return 0 if no combination is possible,
1466 * 1 if user-mergeable, 2 if Y0 is preferred, 3 if Y1 is preferred. */
1467 static int
1468 yypreference (yySemanticOption* y0, yySemanticOption* y1)
1469 {
1470 yyRuleNum r0 = y0->yyrule, r1 = y1->yyrule;
1471 int p0 = yydprec[r0], p1 = yydprec[r1];
1472
1473 if (p0 == p1)
1474 {
1475 if (yymerger[r0] == 0 || yymerger[r0] != yymerger[r1])
1476 return 0;
1477 else
1478 return 1;
1479 }
1480 if (p0 == 0 || p1 == 0)
1481 return 0;
1482 if (p0 < p1)
1483 return 3;
1484 if (p1 < p0)
1485 return 2;
1486 return 0;
1487 }
1488
1489 static YYRESULTTAG yyresolveValue (yySemanticOption* yyoptionList,
1490 yyGLRStack* yystack, YYSTYPE* yyvalp,
1491 YYLTYPE* yylocp]b4_user_formals[);
1492
1493 static YYRESULTTAG
1494 yyresolveStates (yyGLRState* yys, int yyn, yyGLRStack* yystack]b4_user_formals[)
1495 {
1496 YYRESULTTAG yyflag;
1497 if (0 < yyn)
1498 {
1499 YYASSERT (yys->yypred);
1500 yyflag = yyresolveStates (yys->yypred, yyn-1, yystack]b4_user_args[);
1501 if (yyflag != yyok)
1502 return yyflag;
1503 if (! yys->yyresolved)
1504 {
1505 yyflag = yyresolveValue (yys->yysemantics.yyfirstVal, yystack,
1506 &yys->yysemantics.yysval, &yys->yyloc
1507 ]b4_user_args[);
1508 if (yyflag != yyok)
1509 return yyflag;
1510 yys->yyresolved = yytrue;
1511 }
1512 }
1513 return yyok;
1514 }
1515
1516 static YYRESULTTAG
1517 yyresolveAction (yySemanticOption* yyopt, yyGLRStack* yystack,
1518 YYSTYPE* yyvalp, YYLTYPE* yylocp]b4_user_formals[)
1519 {
1520 yyGLRStackItem yyrhsVals[YYMAXRHS + YYMAXLEFT + 1];
1521 int yynrhs;
1522
1523 yynrhs = yyrhsLength (yyopt->yyrule);
1524 YYCHK (yyresolveStates (yyopt->yystate, yynrhs, yystack]b4_user_args[));
1525 yyrhsVals[YYMAXRHS + YYMAXLEFT].yystate.yypred = yyopt->yystate;
1526 return yyuserAction (yyopt->yyrule, yynrhs,
1527 yyrhsVals + YYMAXRHS + YYMAXLEFT - 1,
1528 yyvalp, yylocp, yystack]b4_user_args[);
1529 }
1530
1531 #if YYDEBUG
1532 static void
1533 yyreportTree (yySemanticOption* yyx, int yyindent)
1534 {
1535 int yynrhs = yyrhsLength (yyx->yyrule);
1536 int yyi;
1537 yyGLRState* yys;
1538 yyGLRState* yystates[YYMAXRHS];
1539 yyGLRState yyleftmost_state;
1540
1541 for (yyi = yynrhs, yys = yyx->yystate; 0 < yyi; yyi -= 1, yys = yys->yypred)
1542 yystates[yyi] = yys;
1543 if (yys == NULL)
1544 {
1545 yyleftmost_state.yyposn = 0;
1546 yystates[0] = &yyleftmost_state;
1547 }
1548 else
1549 yystates[0] = yys;
1550
1551 if (yyx->yystate->yyposn < yys->yyposn + 1)
1552 YYFPRINTF (stderr, "%*s%s -> <Rule %d, empty>\n",
1553 yyindent, "", yytokenName (yylhsNonterm (yyx->yyrule)),
1554 yyx->yyrule);
1555 else
1556 YYFPRINTF (stderr, "%*s%s -> <Rule %d, tokens %lu .. %lu>\n",
1557 yyindent, "", yytokenName (yylhsNonterm (yyx->yyrule)),
1558 yyx->yyrule, (unsigned long int) (yys->yyposn + 1),
1559 (unsigned long int) yyx->yystate->yyposn);
1560 for (yyi = 1; yyi <= yynrhs; yyi += 1)
1561 {
1562 if (yystates[yyi]->yyresolved)
1563 {
1564 if (yystates[yyi-1]->yyposn+1 > yystates[yyi]->yyposn)
1565 YYFPRINTF (stderr, "%*s%s <empty>\n", yyindent+2, "",
1566 yytokenName (yyrhs[yyprhs[yyx->yyrule]+yyi-1]));
1567 else
1568 YYFPRINTF (stderr, "%*s%s <tokens %lu .. %lu>\n", yyindent+2, "",
1569 yytokenName (yyrhs[yyprhs[yyx->yyrule]+yyi-1]),
1570 (unsigned long int) (yystates[yyi - 1]->yyposn + 1),
1571 (unsigned long int) yystates[yyi]->yyposn);
1572 }
1573 else
1574 yyreportTree (yystates[yyi]->yysemantics.yyfirstVal, yyindent+2);
1575 }
1576 }
1577 #endif
1578
1579 static void yyreportAmbiguity (yySemanticOption* yyx0, yySemanticOption* yyx1,
1580 yyGLRStack* yystack]b4_pure_formals[)
1581 __attribute__ ((__noreturn__));
1582 static void
1583 yyreportAmbiguity (yySemanticOption* yyx0, yySemanticOption* yyx1,
1584 yyGLRStack* yystack]b4_pure_formals[)
1585 {
1586 /* `Unused' warnings. */
1587 (void) yyx0;
1588 (void) yyx1;
1589
1590 #if YYDEBUG
1591 YYFPRINTF (stderr, "Ambiguity detected.\n");
1592 YYFPRINTF (stderr, "Option 1,\n");
1593 yyreportTree (yyx0, 2);
1594 YYFPRINTF (stderr, "\nOption 2,\n");
1595 yyreportTree (yyx1, 2);
1596 YYFPRINTF (stderr, "\n");
1597 #endif
1598 yyFail (yystack][]b4_pure_args[, YY_("syntax is ambiguous"));
1599 }
1600
1601
1602 /** Resolve the ambiguity represented by OPTIONLIST, perform the indicated
1603 * actions, and return the result. */
1604 static YYRESULTTAG
1605 yyresolveValue (yySemanticOption* yyoptionList, yyGLRStack* yystack,
1606 YYSTYPE* yyvalp, YYLTYPE* yylocp]b4_user_formals[)
1607 {
1608 yySemanticOption* yybest;
1609 yySemanticOption* yyp;
1610 yybool yymerge;
1611
1612 yybest = yyoptionList;
1613 yymerge = yyfalse;
1614 for (yyp = yyoptionList->yynext; yyp != NULL; yyp = yyp->yynext)
1615 {
1616 if (yyidenticalOptions (yybest, yyp))
1617 yymergeOptionSets (yybest, yyp);
1618 else
1619 switch (yypreference (yybest, yyp))
1620 {
1621 case 0:
1622 yyreportAmbiguity (yybest, yyp, yystack]b4_pure_args[);
1623 break;
1624 case 1:
1625 yymerge = yytrue;
1626 break;
1627 case 2:
1628 break;
1629 case 3:
1630 yybest = yyp;
1631 yymerge = yyfalse;
1632 break;
1633 }
1634 }
1635
1636 if (yymerge)
1637 {
1638 int yyprec = yydprec[yybest->yyrule];
1639 YYCHK (yyresolveAction (yybest, yystack, yyvalp, yylocp]b4_user_args[));
1640 for (yyp = yybest->yynext; yyp != NULL; yyp = yyp->yynext)
1641 {
1642 if (yyprec == yydprec[yyp->yyrule])
1643 {
1644 YYSTYPE yyval1;
1645 YYLTYPE yydummy;
1646 YYCHK (yyresolveAction (yyp, yystack, &yyval1, &yydummy]b4_user_args[));
1647 yyuserMerge (yymerger[yyp->yyrule], yyvalp, &yyval1);
1648 }
1649 }
1650 return yyok;
1651 }
1652 else
1653 return yyresolveAction (yybest, yystack, yyvalp, yylocp]b4_user_args[);
1654 }
1655
1656 static YYRESULTTAG
1657 yyresolveStack (yyGLRStack* yystack]b4_user_formals[)
1658 {
1659 if (yystack->yysplitPoint != NULL)
1660 {
1661 yyGLRState* yys;
1662 int yyn;
1663
1664 for (yyn = 0, yys = yystack->yytops.yystates[0];
1665 yys != yystack->yysplitPoint;
1666 yys = yys->yypred, yyn += 1)
1667 continue;
1668 YYCHK (yyresolveStates (yystack->yytops.yystates[0], yyn, yystack
1669 ]b4_user_args[));
1670 }
1671 return yyok;
1672 }
1673
1674 static void
1675 yycompressStack (yyGLRStack* yystack)
1676 {
1677 yyGLRState* yyp, *yyq, *yyr;
1678
1679 if (yystack->yytops.yysize != 1 || yystack->yysplitPoint == NULL)
1680 return;
1681
1682 for (yyp = yystack->yytops.yystates[0], yyq = yyp->yypred, yyr = NULL;
1683 yyp != yystack->yysplitPoint;
1684 yyr = yyp, yyp = yyq, yyq = yyp->yypred)
1685 yyp->yypred = yyr;
1686
1687 yystack->yyspaceLeft += yystack->yynextFree - yystack->yyitems;
1688 yystack->yynextFree = ((yyGLRStackItem*) yystack->yysplitPoint) + 1;
1689 yystack->yyspaceLeft -= yystack->yynextFree - yystack->yyitems;
1690 yystack->yysplitPoint = NULL;
1691 yystack->yylastDeleted = NULL;
1692
1693 while (yyr != NULL)
1694 {
1695 yystack->yynextFree->yystate = *yyr;
1696 yyr = yyr->yypred;
1697 yystack->yynextFree->yystate.yypred = & yystack->yynextFree[-1].yystate;
1698 yystack->yytops.yystates[0] = &yystack->yynextFree->yystate;
1699 yystack->yynextFree += 1;
1700 yystack->yyspaceLeft -= 1;
1701 }
1702 }
1703
1704 static YYRESULTTAG
1705 yyprocessOneStack (yyGLRStack* yystack, size_t yyk,
1706 size_t yyposn, YYSTYPE* yylvalp, YYLTYPE* yyllocp
1707 ]b4_pure_formals[)
1708 {
1709 int yyaction;
1710 const short int* yyconflicts;
1711 yyRuleNum yyrule;
1712 yySymbol* const yytokenp = yystack->yytokenp;
1713
1714 while (yystack->yytops.yystates[yyk] != NULL)
1715 {
1716 yyStateNum yystate = yystack->yytops.yystates[yyk]->yylrState;
1717 YYDPRINTF ((stderr, "Stack %lu Entering state %d\n",
1718 (unsigned long int) yyk, yystate));
1719
1720 YYASSERT (yystate != YYFINAL);
1721
1722 if (yyisDefaultedState (yystate))
1723 {
1724 yyrule = yydefaultAction (yystate);
1725 if (yyrule == 0)
1726 {
1727 YYDPRINTF ((stderr, "Stack %lu dies.\n",
1728 (unsigned long int) yyk));
1729 yymarkStackDeleted (yystack, yyk);
1730 return yyok;
1731 }
1732 YYCHK (yyglrReduce (yystack, yyk, yyrule, yyfalse]b4_user_args[));
1733 }
1734 else
1735 {
1736 if (*yytokenp == YYEMPTY)
1737 {
1738 YYDPRINTF ((stderr, "Reading a token: "));
1739 yychar = YYLEX;
1740 *yytokenp = YYTRANSLATE (yychar);
1741 YY_SYMBOL_PRINT ("Next token is", *yytokenp, yylvalp, yyllocp);
1742 YYDPRINTF ((stderr, "\n"));
1743 }
1744 yygetLRActions (yystate, *yytokenp, &yyaction, &yyconflicts);
1745
1746 while (*yyconflicts != 0)
1747 {
1748 size_t yynewStack = yysplitStack (yystack, yyk);
1749 YYDPRINTF ((stderr, "Splitting off stack %lu from %lu.\n",
1750 (unsigned long int) yynewStack,
1751 (unsigned long int) yyk));
1752 YYCHK (yyglrReduce (yystack, yynewStack,
1753 *yyconflicts, yyfalse]b4_user_args[));
1754 YYCHK (yyprocessOneStack (yystack, yynewStack, yyposn,
1755 yylvalp, yyllocp]b4_pure_args[));
1756 yyconflicts += 1;
1757 }
1758
1759 if (yyisShiftAction (yyaction))
1760 {
1761 YYDPRINTF ((stderr, "On stack %lu, ", (unsigned long int) yyk));
1762 YY_SYMBOL_PRINT ("shifting", *yytokenp, yylvalp, yyllocp);
1763 yyglrShift (yystack, yyk, yyaction, yyposn+1,
1764 *yylvalp, yyllocp);
1765 YYDPRINTF ((stderr, ", now in state #%d\n",
1766 yystack->yytops.yystates[yyk]->yylrState));
1767 break;
1768 }
1769 else if (yyisErrorAction (yyaction))
1770 {
1771 YYDPRINTF ((stderr, "Stack %lu dies.\n",
1772 (unsigned long int) yyk));
1773 yymarkStackDeleted (yystack, yyk);
1774 break;
1775 }
1776 else
1777 YYCHK (yyglrReduce (yystack, yyk, -yyaction, yyfalse]b4_user_args[));
1778 }
1779 }
1780 return yyok;
1781 }
1782
1783 static void
1784 yyreportSyntaxError (yyGLRStack* yystack,
1785 YYSTYPE* yylvalp, YYLTYPE* yyllocp]b4_user_formals[)
1786 {
1787 /* `Unused' warnings. */
1788 (void) yylvalp;
1789 (void) yyllocp;
1790
1791 if (yystack->yyerrState == 0)
1792 {
1793 #if YYERROR_VERBOSE
1794 yySymbol* const yytokenp = yystack->yytokenp;
1795 int yyn;
1796 yyn = yypact[yystack->yytops.yystates[0]->yylrState];
1797 if (YYPACT_NINF < yyn && yyn < YYLAST)
1798 {
1799 size_t yysize0 = yytnamerr (NULL, yytokenName (*yytokenp));
1800 size_t yysize = yysize0;
1801 size_t yysize1;
1802 yybool yysize_overflow = yyfalse;
1803 char* yymsg = NULL;
1804 enum { YYERROR_VERBOSE_ARGS_MAXIMUM = 5 };
1805 char const *yyarg[YYERROR_VERBOSE_ARGS_MAXIMUM];
1806 int yyx;
1807 char *yyfmt;
1808 char const *yyf;
1809 static char const yyunexpected[] = "syntax error, unexpected %s";
1810 static char const yyexpecting[] = ", expecting %s";
1811 static char const yyor[] = " or %s";
1812 char yyformat[sizeof yyunexpected
1813 + sizeof yyexpecting - 1
1814 + ((YYERROR_VERBOSE_ARGS_MAXIMUM - 2)
1815 * (sizeof yyor - 1))];
1816 char const *yyprefix = yyexpecting;
1817
1818 /* Start YYX at -YYN if negative to avoid negative indexes in
1819 YYCHECK. */
1820 int yyxbegin = yyn < 0 ? -yyn : 0;
1821
1822 /* Stay within bounds of both yycheck and yytname. */
1823 int yychecklim = YYLAST - yyn;
1824 int yyxend = yychecklim < YYNTOKENS ? yychecklim : YYNTOKENS;
1825 int yycount = 1;
1826
1827 yyarg[0] = yytokenName (*yytokenp);
1828 yyfmt = yystpcpy (yyformat, yyunexpected);
1829
1830 for (yyx = yyxbegin; yyx < yyxend; ++yyx)
1831 if (yycheck[yyx + yyn] == yyx && yyx != YYTERROR)
1832 {
1833 if (yycount == YYERROR_VERBOSE_ARGS_MAXIMUM)
1834 {
1835 yycount = 1;
1836 yysize = yysize0;
1837 yyformat[sizeof yyunexpected - 1] = '\0';
1838 break;
1839 }
1840 yyarg[yycount++] = yytokenName (yyx);
1841 yysize1 = yysize + yytnamerr (NULL, yytokenName (yyx));
1842 yysize_overflow |= yysize1 < yysize;
1843 yysize = yysize1;
1844 yyfmt = yystpcpy (yyfmt, yyprefix);
1845 yyprefix = yyor;
1846 }
1847
1848 yyf = YY_(yyformat);
1849 yysize1 = yysize + strlen (yyf);
1850 yysize_overflow |= yysize1 < yysize;
1851 yysize = yysize1;
1852
1853 if (!yysize_overflow)
1854 yymsg = (char *) YYMALLOC (yysize);
1855
1856 if (yymsg)
1857 {
1858 char *yyp = yymsg;
1859 int yyi = 0;
1860 while ((*yyp = *yyf))
1861 {
1862 if (*yyp == '%' && yyf[1] == 's' && yyi < yycount)
1863 {
1864 yyp += yytnamerr (yyp, yyarg[yyi++]);
1865 yyf += 2;
1866 }
1867 else
1868 {
1869 yyp++;
1870 yyf++;
1871 }
1872 }
1873 yyerror (]b4_lyyerror_args[yymsg);
1874 YYFREE (yymsg);
1875 }
1876 else
1877 {
1878 yyerror (]b4_lyyerror_args[YY_("syntax error"));
1879 yyMemoryExhausted (yystack);
1880 }
1881 }
1882 else
1883 #endif /* YYERROR_VERBOSE */
1884 yyerror (]b4_lyyerror_args[YY_("syntax error"));
1885 yynerrs += 1;
1886 }
1887 }
1888
1889 /* Recover from a syntax error on YYSTACK, assuming that YYTOKENP,
1890 YYLVALP, and YYLLOCP point to the syntactic category, semantic
1891 value, and location of the look-ahead. */
1892 static void
1893 yyrecoverSyntaxError (yyGLRStack* yystack,
1894 YYSTYPE* yylvalp,
1895 YYLTYPE* YYOPTIONAL_LOC (yyllocp)
1896 ]b4_user_formals[)
1897 {
1898 yySymbol* const yytokenp = yystack->yytokenp;
1899 size_t yyk;
1900 int yyj;
1901
1902 if (yystack->yyerrState == 3)
1903 /* We just shifted the error token and (perhaps) took some
1904 reductions. Skip tokens until we can proceed. */
1905 while (yytrue)
1906 {
1907 if (*yytokenp == YYEOF)
1908 yyFail (yystack][]b4_lpure_args[, NULL);
1909 if (*yytokenp != YYEMPTY)
1910 {]b4_location_if([[
1911 /* We throw away the lookahead, but the error range
1912 of the shifted error token must take it into account. */
1913 yyGLRState *yys = yystack->yytops.yystates[0];
1914 yyGLRStackItem yyerror_range[3];
1915 yyerror_range[1].yystate.yyloc = yys->yyloc;
1916 yyerror_range[2].yystate.yyloc = *yyllocp;
1917 YYLLOC_DEFAULT (yys->yyloc, yyerror_range, 2);]])[
1918 yydestruct ("Error: discarding",
1919 *yytokenp, yylvalp]b4_location_if([, yyllocp])[);
1920 }
1921 YYDPRINTF ((stderr, "Reading a token: "));
1922 yychar = YYLEX;
1923 *yytokenp = YYTRANSLATE (yychar);
1924 YY_SYMBOL_PRINT ("Next token is", *yytokenp, yylvalp, yyllocp);
1925 YYDPRINTF ((stderr, "\n"));
1926 yyj = yypact[yystack->yytops.yystates[0]->yylrState];
1927 if (yyis_pact_ninf (yyj))
1928 return;
1929 yyj += *yytokenp;
1930 if (yyj < 0 || YYLAST < yyj || yycheck[yyj] != *yytokenp)
1931 {
1932 if (yydefact[yystack->yytops.yystates[0]->yylrState] != 0)
1933 return;
1934 }
1935 else if (yytable[yyj] != 0 && ! yyis_table_ninf (yytable[yyj]))
1936 return;
1937 }
1938
1939 /* Reduce to one stack. */
1940 for (yyk = 0; yyk < yystack->yytops.yysize; yyk += 1)
1941 if (yystack->yytops.yystates[yyk] != NULL)
1942 break;
1943 if (yyk >= yystack->yytops.yysize)
1944 yyFail (yystack][]b4_lpure_args[, NULL);
1945 for (yyk += 1; yyk < yystack->yytops.yysize; yyk += 1)
1946 yymarkStackDeleted (yystack, yyk);
1947 yyremoveDeletes (yystack);
1948 yycompressStack (yystack);
1949
1950 /* Now pop stack until we find a state that shifts the error token. */
1951 yystack->yyerrState = 3;
1952 while (yystack->yytops.yystates[0] != NULL)
1953 {
1954 yyGLRState *yys = yystack->yytops.yystates[0];
1955 yyj = yypact[yys->yylrState];
1956 if (! yyis_pact_ninf (yyj))
1957 {
1958 yyj += YYTERROR;
1959 if (0 <= yyj && yyj <= YYLAST && yycheck[yyj] == YYTERROR
1960 && yyisShiftAction (yytable[yyj]))
1961 {
1962 /* Shift the error token having adjusted its location. */
1963 YYLTYPE yyerrloc;]b4_location_if([[
1964 yystack->yyerror_range[2].yystate.yyloc = *yyllocp;
1965 YYLLOC_DEFAULT (yyerrloc, yystack->yyerror_range, 2);]])[
1966 YY_SYMBOL_PRINT ("Shifting", yystos[yytable[yyj]],
1967 yylvalp, &yyerrloc);
1968 YYDPRINTF ((stderr, "\n"));
1969 yyglrShift (yystack, 0, yytable[yyj],
1970 yys->yyposn, *yylvalp, &yyerrloc);
1971 yys = yystack->yytops.yystates[0];
1972 break;
1973 }
1974 }
1975 ]b4_location_if([[ yystack->yyerror_range[1].yystate.yyloc = yys->yyloc;]])[
1976 yydestruct ("Error: popping",
1977 yystos[yys->yylrState],
1978 &yys->yysemantics.yysval]b4_location_if([, &yys->yyloc])[);
1979 yystack->yytops.yystates[0] = yys->yypred;
1980 yystack->yynextFree -= 1;
1981 yystack->yyspaceLeft += 1;
1982 }
1983 if (yystack->yytops.yystates[0] == NULL)
1984 yyFail (yystack][]b4_lpure_args[, NULL);
1985 }
1986
1987 #define YYCHK1(YYE) \
1988 do { \
1989 switch (YYE) { \
1990 default: \
1991 break; \
1992 case yyabort: \
1993 goto yyabortlab; \
1994 case yyaccept: \
1995 goto yyacceptlab; \
1996 case yyerr: \
1997 goto yyuser_error; \
1998 } \
1999 } while (0)
2000
2001
2002 /*----------.
2003 | yyparse. |
2004 `----------*/
2005
2006 ]b4_c_ansi_function_def([yyparse], [int], b4_parse_param)[
2007 {
2008 int yyresult;
2009 yySymbol yytoken;
2010 yyGLRStack yystack;
2011 size_t yyposn;
2012 ]b4_pure_if(
2013 [
2014 YYSTYPE yylval;
2015 YYLTYPE yylloc;
2016 #undef yychar
2017 #define yychar (yystack.yyrawchar)
2018 ])[
2019
2020 YYSTYPE* const yylvalp = &yylval;
2021 YYLTYPE* const yyllocp = &yylloc;
2022
2023 YYDPRINTF ((stderr, "Starting parse\n"));
2024
2025 yytoken = YYEMPTY;
2026 yylval = yyval_default;
2027 ]b4_location_if([
2028 #if YYLTYPE_IS_TRIVIAL
2029 yylloc.first_line = yylloc.last_line = 1;
2030 yylloc.first_column = yylloc.last_column = 0;
2031 #endif
2032 ])
2033 m4_ifdef([b4_initial_action], [
2034 m4_pushdef([b4_at_dollar], [yylloc])dnl
2035 m4_pushdef([b4_dollar_dollar], [yylval])dnl
2036 /* User initialization code. */
2037 b4_initial_action
2038 m4_popdef([b4_dollar_dollar])dnl
2039 m4_popdef([b4_at_dollar])dnl
2040 /* Line __line__ of glr.c. */
2041 b4_syncline([@oline@], [@ofile@])])dnl
2042 [
2043 if (! yyinitGLRStack (&yystack, YYINITDEPTH))
2044 goto yyexhaustedlab;
2045 switch (setjmp (yystack.yyexception_buffer))
2046 {
2047 case 1: goto yyabortlab;
2048 case 2: goto yyexhaustedlab;
2049 }
2050 yystack.yytokenp = &yytoken;
2051 yyglrShift (&yystack, 0, 0, 0, yylval, &yylloc);
2052 yyposn = 0;
2053
2054 while (yytrue)
2055 {
2056 /* For efficiency, we have two loops, the first of which is
2057 specialized to deterministic operation (single stack, no
2058 potential ambiguity). */
2059 /* Standard mode */
2060 while (yytrue)
2061 {
2062 yyRuleNum yyrule;
2063 int yyaction;
2064 const short int* yyconflicts;
2065
2066 yyStateNum yystate = yystack.yytops.yystates[0]->yylrState;
2067 YYDPRINTF ((stderr, "Entering state %d\n", yystate));
2068 if (yystate == YYFINAL)
2069 goto yyacceptlab;
2070 if (yyisDefaultedState (yystate))
2071 {
2072 yyrule = yydefaultAction (yystate);
2073 if (yyrule == 0)
2074 {
2075 ]b4_location_if([[ yystack.yyerror_range[1].yystate.yyloc = *yyllocp;]])[
2076 yyreportSyntaxError (&yystack, yylvalp, yyllocp]b4_user_args[);
2077 goto yyuser_error;
2078 }
2079 YYCHK1 (yyglrReduce (&yystack, 0, yyrule, yytrue]b4_user_args[));
2080 }
2081 else
2082 {
2083 if (yytoken == YYEMPTY)
2084 {
2085 YYDPRINTF ((stderr, "Reading a token: "));
2086 yychar = YYLEX;
2087 yytoken = YYTRANSLATE (yychar);
2088 YY_SYMBOL_PRINT ("Next token is", yytoken, yylvalp, yyllocp);
2089 YYDPRINTF ((stderr, "\n"));
2090 }
2091 yygetLRActions (yystate, yytoken, &yyaction, &yyconflicts);
2092 if (*yyconflicts != 0)
2093 break;
2094 if (yyisShiftAction (yyaction))
2095 {
2096 YY_SYMBOL_PRINT ("Shifting", yytoken, yylvalp, yyllocp);
2097 YYDPRINTF ((stderr, "\n"));
2098 if (yytoken != YYEOF)
2099 yytoken = YYEMPTY;
2100 yyposn += 1;
2101 yyglrShift (&yystack, 0, yyaction, yyposn, yylval, yyllocp);
2102 if (0 < yystack.yyerrState)
2103 yystack.yyerrState -= 1;
2104 }
2105 else if (yyisErrorAction (yyaction))
2106 {
2107 ]b4_location_if([[ yystack.yyerror_range[1].yystate.yyloc = *yyllocp;]])[
2108 yyreportSyntaxError (&yystack, yylvalp, yyllocp]b4_user_args[);
2109 goto yyuser_error;
2110 }
2111 else
2112 YYCHK1 (yyglrReduce (&yystack, 0, -yyaction, yytrue]b4_user_args[));
2113 }
2114 }
2115
2116 while (yytrue)
2117 {
2118 size_t yys;
2119 size_t yyn = yystack.yytops.yysize;
2120 for (yys = 0; yys < yyn; yys += 1)
2121 YYCHK1 (yyprocessOneStack (&yystack, yys, yyposn,
2122 yylvalp, yyllocp]b4_lpure_args[));
2123 yytoken = YYEMPTY;
2124 yyposn += 1;
2125 yyremoveDeletes (&yystack);
2126 if (yystack.yytops.yysize == 0)
2127 {
2128 yyundeleteLastStack (&yystack);
2129 if (yystack.yytops.yysize == 0)
2130 yyFail (&yystack][]b4_lpure_args[, YY_("syntax error"));
2131 YYCHK1 (yyresolveStack (&yystack]b4_user_args[));
2132 YYDPRINTF ((stderr, "Returning to deterministic operation.\n"));
2133 ]b4_location_if([[ yystack.yyerror_range[1].yystate.yyloc = *yyllocp;]])[
2134 yyreportSyntaxError (&yystack, yylvalp, yyllocp]b4_user_args[);
2135 goto yyuser_error;
2136 }
2137 else if (yystack.yytops.yysize == 1)
2138 {
2139 YYCHK1 (yyresolveStack (&yystack]b4_user_args[));
2140 YYDPRINTF ((stderr, "Returning to deterministic operation.\n"));
2141 yycompressStack (&yystack);
2142 break;
2143 }
2144 }
2145 continue;
2146 yyuser_error:
2147 yyrecoverSyntaxError (&yystack, yylvalp, yyllocp]b4_user_args[);
2148 yyposn = yystack.yytops.yystates[0]->yyposn;
2149 }
2150
2151 yyacceptlab:
2152 yyresult = 0;
2153 goto yyreturn;
2154
2155 yyabortlab:
2156 yyresult = 1;
2157 goto yyreturn;
2158
2159 yyexhaustedlab:
2160 yyerror (]b4_lyyerror_args[YY_("memory exhausted"));
2161 yyresult = 2;
2162 /* Fall through. */
2163
2164 yyreturn:
2165 if (yytoken != YYEOF && yytoken != YYEMPTY)
2166 yydestruct ("Error: discarding lookahead",
2167 yytoken, yylvalp]b4_location_if([, yyllocp])[);
2168
2169 /* If the stack is well-formed, pop the stack until it is empty,
2170 destroying its entries as we go. But free the stack regardless
2171 of whether it is well-formed. */
2172 if (yystack.yyitems)
2173 {
2174 yyGLRState** yystates = yystack.yytops.yystates;
2175 if (yystates)
2176 while (yystates[0])
2177 {
2178 yyGLRState *yys = yystates[0];
2179 ]b4_location_if([[ yystack.yyerror_range[1].yystate.yyloc = yys->yyloc;]]
2180 )[ yydestruct ("Error: popping",
2181 yystos[yys->yylrState],
2182 &yys->yysemantics.yysval]b4_location_if([, &yys->yyloc])[);
2183 yystates[0] = yys->yypred;
2184 yystack.yynextFree -= 1;
2185 yystack.yyspaceLeft += 1;
2186 }
2187 yyfreeGLRStack (&yystack);
2188 }
2189
2190 return yyresult;
2191 }
2192
2193 /* DEBUGGING ONLY */
2194 #ifdef YYDEBUG
2195 static void yypstack (yyGLRStack* yystack, size_t yyk)
2196 __attribute__ ((__unused__));
2197 static void yypdumpstack (yyGLRStack* yystack) __attribute__ ((__unused__));
2198
2199 static void
2200 yy_yypstack (yyGLRState* yys)
2201 {
2202 if (yys->yypred)
2203 {
2204 yy_yypstack (yys->yypred);
2205 fprintf (stderr, " -> ");
2206 }
2207 fprintf (stderr, "%d@@%lu", yys->yylrState, (unsigned long int) yys->yyposn);
2208 }
2209
2210 static void
2211 yypstates (yyGLRState* yyst)
2212 {
2213 if (yyst == NULL)
2214 fprintf (stderr, "<null>");
2215 else
2216 yy_yypstack (yyst);
2217 fprintf (stderr, "\n");
2218 }
2219
2220 static void
2221 yypstack (yyGLRStack* yystack, size_t yyk)
2222 {
2223 yypstates (yystack->yytops.yystates[yyk]);
2224 }
2225
2226 #define YYINDEX(YYX) \
2227 ((YYX) == NULL ? -1 : (yyGLRStackItem*) (YYX) - yystack->yyitems)
2228
2229
2230 static void
2231 yypdumpstack (yyGLRStack* yystack)
2232 {
2233 yyGLRStackItem* yyp;
2234 size_t yyi;
2235 for (yyp = yystack->yyitems; yyp < yystack->yynextFree; yyp += 1)
2236 {
2237 fprintf (stderr, "%3lu. ", (unsigned long int) (yyp - yystack->yyitems));
2238 if (*(yybool *) yyp)
2239 {
2240 fprintf (stderr, "Res: %d, LR State: %d, posn: %lu, pred: %ld",
2241 yyp->yystate.yyresolved, yyp->yystate.yylrState,
2242 (unsigned long int) yyp->yystate.yyposn,
2243 (long int) YYINDEX (yyp->yystate.yypred));
2244 if (! yyp->yystate.yyresolved)
2245 fprintf (stderr, ", firstVal: %ld",
2246 (long int) YYINDEX (yyp->yystate.yysemantics.yyfirstVal));
2247 }
2248 else
2249 {
2250 fprintf (stderr, "Option. rule: %d, state: %ld, next: %ld",
2251 yyp->yyoption.yyrule,
2252 (long int) YYINDEX (yyp->yyoption.yystate),
2253 (long int) YYINDEX (yyp->yyoption.yynext));
2254 }
2255 fprintf (stderr, "\n");
2256 }
2257 fprintf (stderr, "Tops:");
2258 for (yyi = 0; yyi < yystack->yytops.yysize; yyi += 1)
2259 fprintf (stderr, "%lu: %ld; ", (unsigned long int) yyi,
2260 (long int) YYINDEX (yystack->yytops.yystates[yyi]));
2261 fprintf (stderr, "\n");
2262 }
2263 #endif
2264 ]
2265
2266 b4_epilogue
2267 m4_if(b4_defines_flag, 0, [],
2268 [@output @output_header_name@
2269 b4_copyright([Skeleton parser for GLR parsing with Bison],
2270 [2002, 2003, 2004, 2005])
2271
2272 b4_token_defines(b4_tokens)
2273
2274 #if ! defined (YYSTYPE) && ! defined (YYSTYPE_IS_DECLARED)
2275 m4_ifdef([b4_stype],
2276 [b4_syncline([b4_stype_line], [b4_filename])
2277 typedef union m4_bregexp(b4_stype, [^{], [YYSTYPE ])b4_stype YYSTYPE;
2278 /* Line __line__ of glr.c. */
2279 b4_syncline([@oline@], [@ofile@])],
2280 [typedef int YYSTYPE;])
2281 # define YYSTYPE_IS_DECLARED 1
2282 # define YYSTYPE_IS_TRIVIAL 1
2283 #endif
2284
2285 b4_pure_if([],
2286 [extern YYSTYPE b4_prefix[]lval;])
2287
2288 #if ! defined (YYLTYPE) && ! defined (YYLTYPE_IS_DECLARED)
2289 typedef struct YYLTYPE
2290 {
2291 b4_location_if([
2292 int first_line;
2293 int first_column;
2294 int last_line;
2295 int last_column;
2296 ],[
2297 char yydummy;
2298 ])
2299 } YYLTYPE;
2300 # define YYLTYPE_IS_DECLARED 1
2301 # define YYLTYPE_IS_TRIVIAL 1
2302 #endif
2303
2304 b4_location_if([b4_pure_if([],
2305 [extern YYLTYPE b4_prefix[]lloc;])
2306 ])
2307 ])