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