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