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