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