]> git.saurik.com Git - bison.git/blob - data/yacc.c
* data/glr.c, data/lalr1.cc, data/yacc.c: Do not use __file__,
[bison.git] / data / yacc.c
1 m4_divert(-1) -*- C -*-
2 m4_include([c.m4])
3
4 # Yacc compatible skeleton for Bison
5 # Copyright (C) 1984, 1989, 1990, 2000, 2001, 2002
6 # Free Software Foundation, Inc.
7
8 # This program is free software; you can redistribute it and/or modify
9 # it under the terms of the GNU General Public License as published by
10 # the Free Software Foundation; either version 2 of the License, or
11 # (at your option) any later version.
12
13 # This program is distributed in the hope that it will be useful,
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 # GNU General Public License for more details.
17
18 # You should have received a copy of the GNU General Public License
19 # along with this program; if not, write to the Free Software
20 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
21 # 02111-1307 USA
22
23
24
25 ## ---------------- ##
26 ## Default values. ##
27 ## ---------------- ##
28
29 # Stack parameters.
30 m4_define_default([b4_stack_depth_max], [10000])
31 m4_define_default([b4_stack_depth_init], [200])
32
33 # Location type.
34 m4_define_default([b4_location_type], [yyltype])
35
36
37 ## ------------------------ ##
38 ## Pure/impure interfaces. ##
39 ## ------------------------ ##
40
41
42 # b4_pure_if(IF-TRUE, IF-FALSE)
43 # -----------------------------
44 # Expand IF-TRUE, if %pure-parser and %parse-param, IF-FALSE otherwise.
45 m4_define([b4_Pure_if],
46 [b4_pure_if([m4_ifset([b4_parse_param],
47 [$1], [$2])],
48 [$2])])
49
50
51 # b4_yyerror_args
52 # ---------------
53 # Arguments passed to yyerror: user args plus yylloc.
54 m4_define([b4_yyerror_args],
55 [b4_Pure_if([b4_location_if([&yylloc, ])])dnl
56 m4_ifset([b4_parse_param], [b4_c_args(b4_parse_param), ])])
57
58
59 # b4_lex_param
60 # ------------
61 # Accumule in b4_lex_param all the yylex arguments.
62 # b4_lex_param arrives quoted twice, but we want to keep only one level.
63 m4_define([b4_lex_param],
64 m4_dquote(b4_pure_if([[[[YYSTYPE *]], [[&yylval]]][]dnl
65 b4_location_if([, [[YYLTYPE *], [&yylloc]]])])dnl
66 m4_ifdef([b4_lex_param], [, ]b4_lex_param)))
67
68
69
70 ## ------------ ##
71 ## Data Types. ##
72 ## ------------ ##
73
74 # b4_int_type(MIN, MAX)
75 # ---------------------
76 # Return the smallest int type able to handle numbers ranging from
77 # MIN to MAX (included). We overwrite the version from c.m4 which relies
78 # on "signed char" which is not portable to old K&R compilers.
79 m4_define([b4_int_type],
80 [m4_if(b4_ints_in($@, [0], [255]), [1], [unsigned char],
81 b4_ints_in($@, [-128], [127]), [1], [yysigned_char],
82
83 b4_ints_in($@, [0], [65535]), [1], [unsigned short],
84 b4_ints_in($@, [-32768], [32767]), [1], [short],
85
86 m4_eval([0 <= $1]), [1], [unsigned int],
87
88 [int])])
89
90
91 ## ----------------- ##
92 ## Semantic Values. ##
93 ## ----------------- ##
94
95
96 # b4_lhs_value([TYPE])
97 # --------------------
98 # Expansion of $<TYPE>$.
99 m4_define([b4_lhs_value],
100 [yyval[]m4_ifval([$1], [.$1])])
101
102
103 # b4_rhs_value(RULE-LENGTH, NUM, [TYPE])
104 # --------------------------------------
105 # Expansion of $<TYPE>NUM, where the current rule has RULE-LENGTH
106 # symbols on RHS.
107 m4_define([b4_rhs_value],
108 [yyvsp@{m4_eval([$2 - $1])@}m4_ifval([$3], [.$3])])
109
110
111
112 ## ----------- ##
113 ## Locations. ##
114 ## ----------- ##
115
116 # b4_lhs_location()
117 # -----------------
118 # Expansion of @$.
119 m4_define([b4_lhs_location],
120 [yyloc])
121
122
123 # b4_rhs_location(RULE-LENGTH, NUM)
124 # ---------------------------------
125 # Expansion of @NUM, where the current rule has RULE-LENGTH symbols
126 # on RHS.
127 m4_define([b4_rhs_location],
128 [yylsp@{m4_eval([$2 - $1])@}])
129
130
131
132 ## --------------------------------------------------------- ##
133 ## Defining symbol actions, e.g., printers and destructors. ##
134 ## --------------------------------------------------------- ##
135
136 # We do want M4 expansion after # for CPP macros.
137 m4_changecom()
138 m4_divert(0)dnl
139 @output @output_parser_name@
140 b4_copyright([Skeleton parser for Yacc-like parsing with Bison],
141 [1984, 1989, 1990, 2000, 2001, 2002])[
142
143 /* As a special exception, when this file is copied by Bison into a
144 Bison output file, you may use that output file without restriction.
145 This special exception was added by the Free Software Foundation
146 in version 1.24 of Bison. */
147
148 /* Written by Richard Stallman by simplifying the original so called
149 ``semantic'' parser. */
150
151 /* All symbols defined below should begin with yy or YY, to avoid
152 infringing on user name space. This should be done even for local
153 variables, as they might otherwise be expanded by user macros.
154 There are some unavoidable exceptions within include files to
155 define necessary library symbols; they are noted "INFRINGES ON
156 USER NAME SPACE" below. */
157
158 ]b4_identification
159 m4_if(b4_prefix[], [yy], [],
160 [/* If NAME_PREFIX is specified substitute the variables and functions
161 names. */
162 #define yyparse b4_prefix[]parse
163 #define yylex b4_prefix[]lex
164 #define yyerror b4_prefix[]error
165 #define yylval b4_prefix[]lval
166 #define yychar b4_prefix[]char
167 #define yydebug b4_prefix[]debug
168 #define yynerrs b4_prefix[]nerrs
169 b4_location_if([#define yylloc b4_prefix[]lloc])])[
170
171 ]b4_token_defines(b4_tokens)[
172
173 /* Copy the first part of user declarations. */
174 ]b4_pre_prologue[
175
176 /* Enabling traces. */
177 #ifndef YYDEBUG
178 # define YYDEBUG ]b4_debug[
179 #endif
180
181 /* Enabling verbose error messages. */
182 #ifdef YYERROR_VERBOSE
183 # undef YYERROR_VERBOSE
184 # define YYERROR_VERBOSE 1
185 #else
186 # define YYERROR_VERBOSE ]b4_error_verbose[
187 #endif
188
189 #ifndef YYSTYPE
190 ]m4_ifdef([b4_stype],
191 [b4_syncline([b4_stype_line], [b4_filename])
192 typedef union b4_stype yystype;
193 /* Line __line__ of yacc.c. */
194 b4_syncline([@oline@], [@ofile@])],
195 [typedef int yystype;])[
196 # define YYSTYPE yystype
197 # define YYSTYPE_IS_TRIVIAL 1
198 #endif
199
200 #ifndef YYLTYPE
201 typedef struct yyltype
202 {
203 int first_line;
204 int first_column;
205 int last_line;
206 int last_column;
207 } yyltype;
208 # define YYLTYPE ]b4_location_type[
209 # define YYLTYPE_IS_TRIVIAL 1
210 #endif
211
212 /* Copy the second part of user declarations. */
213 ]b4_post_prologue
214
215 /* Line __line__ of yacc.c. */
216 b4_syncline([@oline@], [@ofile@])[
217
218 #if ! defined (yyoverflow) || YYERROR_VERBOSE
219
220 /* The parser invokes alloca or malloc; define the necessary symbols. */
221
222 # if YYSTACK_USE_ALLOCA
223 # define YYSTACK_ALLOC alloca
224 # else
225 # ifndef YYSTACK_USE_ALLOCA
226 # if defined (alloca) || defined (_ALLOCA_H)
227 # define YYSTACK_ALLOC alloca
228 # else
229 # ifdef __GNUC__
230 # define YYSTACK_ALLOC __builtin_alloca
231 # endif
232 # endif
233 # endif
234 # endif
235
236 # ifdef YYSTACK_ALLOC
237 /* Pacify GCC's `empty if-body' warning. */
238 # define YYSTACK_FREE(Ptr) do { /* empty */; } while (0)
239 # else
240 # if defined (__STDC__) || defined (__cplusplus)
241 # include <stdlib.h> /* INFRINGES ON USER NAME SPACE */
242 # define YYSIZE_T size_t
243 # endif
244 # define YYSTACK_ALLOC malloc
245 # define YYSTACK_FREE free
246 # endif
247 #endif /* ! defined (yyoverflow) || YYERROR_VERBOSE */
248
249
250 #if (! defined (yyoverflow) \
251 && (! defined (__cplusplus) \
252 || (YYLTYPE_IS_TRIVIAL && YYSTYPE_IS_TRIVIAL)))
253
254 /* A type that is properly aligned for any stack member. */
255 union yyalloc
256 {
257 short yyss;
258 YYSTYPE yyvs;
259 ]b4_location_if([ YYLTYPE yyls;
260 ])dnl
261 [};
262
263 /* The size of the maximum gap between one aligned stack and the next. */
264 # define YYSTACK_GAP_MAX (sizeof (union yyalloc) - 1)
265
266 /* The size of an array large to enough to hold all stacks, each with
267 N elements. */
268 ]b4_location_if(
269 [# define YYSTACK_BYTES(N) \
270 ((N) * (sizeof (short) + sizeof (YYSTYPE) + sizeof (YYLTYPE)) \
271 + 2 * YYSTACK_GAP_MAX)],
272 [# define YYSTACK_BYTES(N) \
273 ((N) * (sizeof (short) + sizeof (YYSTYPE)) \
274 + YYSTACK_GAP_MAX)])[
275
276 /* Copy COUNT objects from FROM to TO. The source and destination do
277 not overlap. */
278 # ifndef YYCOPY
279 # if 1 < __GNUC__
280 # define YYCOPY(To, From, Count) \
281 __builtin_memcpy (To, From, (Count) * sizeof (*(From)))
282 # else
283 # define YYCOPY(To, From, Count) \
284 do \
285 { \
286 register YYSIZE_T yyi; \
287 for (yyi = 0; yyi < (Count); yyi++) \
288 (To)[yyi] = (From)[yyi]; \
289 } \
290 while (0)
291 # endif
292 # endif
293
294 /* Relocate STACK from its old location to the new one. The
295 local variables YYSIZE and YYSTACKSIZE give the old and new number of
296 elements in the stack, and YYPTR gives the new location of the
297 stack. Advance YYPTR to a properly aligned location for the next
298 stack. */
299 # define YYSTACK_RELOCATE(Stack) \
300 do \
301 { \
302 YYSIZE_T yynewbytes; \
303 YYCOPY (&yyptr->Stack, Stack, yysize); \
304 Stack = &yyptr->Stack; \
305 yynewbytes = yystacksize * sizeof (*Stack) + YYSTACK_GAP_MAX; \
306 yyptr += yynewbytes / sizeof (*yyptr); \
307 } \
308 while (0)
309
310 #endif
311
312 #if defined (__STDC__) || defined (__cplusplus)
313 typedef signed char yysigned_char;
314 #else
315 typedef short yysigned_char;
316 #endif
317
318 /* YYFINAL -- State number of the termination state. */
319 #define YYFINAL ]b4_final_state_number[
320 /* YYLAST -- Last index in YYTABLE. */
321 #define YYLAST ]b4_last[
322
323 /* YYNTOKENS -- Number of terminals. */
324 #define YYNTOKENS ]b4_tokens_number[
325 /* YYNNTS -- Number of nonterminals. */
326 #define YYNNTS ]b4_nterms_number[
327 /* YYNRULES -- Number of rules. */
328 #define YYNRULES ]b4_rules_number[
329 /* YYNRULES -- Number of states. */
330 #define YYNSTATES ]b4_states_number[
331
332 /* YYTRANSLATE(YYLEX) -- Bison symbol number corresponding to YYLEX. */
333 #define YYUNDEFTOK ]b4_undef_token_number[
334 #define YYMAXUTOK ]b4_user_token_number_max[
335
336 #define YYTRANSLATE(YYX) \
337 ((YYX <= 0) ? YYEOF : \
338 (unsigned)(YYX) <= YYMAXUTOK ? yytranslate[YYX] : YYUNDEFTOK)
339
340 /* YYTRANSLATE[YYLEX] -- Bison symbol number corresponding to YYLEX. */
341 static const ]b4_int_type_for([b4_translate])[ yytranslate[] =
342 {
343 ]b4_translate[
344 };
345
346 #if YYDEBUG
347 /* YYPRHS[YYN] -- Index of the first RHS symbol of rule number YYN in
348 YYRHS. */
349 static const ]b4_int_type_for([b4_prhs])[ yyprhs[] =
350 {
351 ]b4_prhs[
352 };
353
354 /* YYRHS -- A `-1'-separated list of the rules' RHS. */
355 static const ]b4_int_type_for([b4_rhs])[ yyrhs[] =
356 {
357 ]b4_rhs[
358 };
359
360 /* YYRLINE[YYN] -- source line where rule number YYN was defined. */
361 static const ]b4_int_type_for([b4_rline])[ yyrline[] =
362 {
363 ]b4_rline[
364 };
365 #endif
366
367 #if YYDEBUG || YYERROR_VERBOSE
368 /* YYTNME[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM.
369 First, the terminals, then, starting at YYNTOKENS, nonterminals. */
370 static const char *const yytname[] =
371 {
372 ]b4_tname[
373 };
374 #endif
375
376 # ifdef YYPRINT
377 /* YYTOKNUM[YYLEX-NUM] -- Internal token number corresponding to
378 token YYLEX-NUM. */
379 static const ]b4_int_type_for([b4_toknum])[ yytoknum[] =
380 {
381 ]b4_toknum[
382 };
383 # endif
384
385 /* YYR1[YYN] -- Symbol number of symbol that rule YYN derives. */
386 static const ]b4_int_type_for([b4_r1])[ yyr1[] =
387 {
388 ]b4_r1[
389 };
390
391 /* YYR2[YYN] -- Number of symbols composing right hand side of rule YYN. */
392 static const ]b4_int_type_for([b4_r2])[ yyr2[] =
393 {
394 ]b4_r2[
395 };
396
397 /* YYDEFACT[STATE-NAME] -- Default rule to reduce with in state
398 STATE-NUM when YYTABLE doesn't specify something else to do. Zero
399 means the default is an error. */
400 static const ]b4_int_type_for([b4_defact])[ yydefact[] =
401 {
402 ]b4_defact[
403 };
404
405 /* YYDEFGOTO[NTERM-NUM]. */
406 static const ]b4_int_type_for([b4_defgoto])[ yydefgoto[] =
407 {
408 ]b4_defgoto[
409 };
410
411 /* YYPACT[STATE-NUM] -- Index in YYTABLE of the portion describing
412 STATE-NUM. */
413 #define YYPACT_NINF ]b4_pact_ninf[
414 static const ]b4_int_type_for([b4_pact])[ yypact[] =
415 {
416 ]b4_pact[
417 };
418
419 /* YYPGOTO[NTERM-NUM]. */
420 static const ]b4_int_type_for([b4_pgoto])[ yypgoto[] =
421 {
422 ]b4_pgoto[
423 };
424
425 /* YYTABLE[YYPACT[STATE-NUM]]. What to do in state STATE-NUM. If
426 positive, shift that token. If negative, reduce the rule which
427 number is the opposite. If zero, do what YYDEFACT says.
428 If YYTABLE_NINF, syntax error. */
429 #define YYTABLE_NINF ]b4_table_ninf[
430 static const ]b4_int_type_for([b4_table])[ yytable[] =
431 {
432 ]b4_table[
433 };
434
435 static const ]b4_int_type_for([b4_check])[ yycheck[] =
436 {
437 ]b4_check[
438 };
439
440 /* YYSTOS[STATE-NUM] -- The (internal number of the) accessing
441 symbol of state STATE-NUM. */
442 static const ]b4_int_type_for([b4_stos])[ yystos[] =
443 {
444 ]b4_stos[
445 };
446
447 #if ! defined (YYSIZE_T) && defined (__SIZE_TYPE__)
448 # define YYSIZE_T __SIZE_TYPE__
449 #endif
450 #if ! defined (YYSIZE_T) && defined (size_t)
451 # define YYSIZE_T size_t
452 #endif
453 #if ! defined (YYSIZE_T)
454 # if defined (__STDC__) || defined (__cplusplus)
455 # include <stddef.h> /* INFRINGES ON USER NAME SPACE */
456 # define YYSIZE_T size_t
457 # endif
458 #endif
459 #if ! defined (YYSIZE_T)
460 # define YYSIZE_T unsigned int
461 #endif
462
463 #define yyerrok (yyerrstatus = 0)
464 #define yyclearin (yytoken = YYEMPTY)
465 #define YYEMPTY -2
466 #define YYEOF 0
467
468 #define YYACCEPT goto yyacceptlab
469 #define YYABORT goto yyabortlab
470 #define YYERROR goto yyerrlab1
471
472 /* Like YYERROR except do call yyerror. This remains here temporarily
473 to ease the transition to the new meaning of YYERROR, for GCC.
474 Once GCC version 2 has supplanted version 1, this can go. */
475
476 #define YYFAIL goto yyerrlab
477
478 #define YYRECOVERING() (!!yyerrstatus)
479
480 #define YYBACKUP(Token, Value) \
481 do \
482 if (yytoken == YYEMPTY && yylen == 1) \
483 { \
484 yychar = (Token); \
485 yylval = (Value); \
486 yytoken = YYTRANSLATE (yychar); \
487 YYPOPSTACK; \
488 goto yybackup; \
489 } \
490 else \
491 { \
492 yyerror (]b4_yyerror_args["syntax error: cannot back up");\
493 YYERROR; \
494 } \
495 while (0)
496
497 #define YYTERROR 1
498 #define YYERRCODE 256
499
500 /* YYLLOC_DEFAULT -- Compute the default location (before the actions
501 are run). */
502
503 #ifndef YYLLOC_DEFAULT
504 # define YYLLOC_DEFAULT(Current, Rhs, N) \
505 Current.first_line = Rhs[1].first_line; \
506 Current.first_column = Rhs[1].first_column; \
507 Current.last_line = Rhs[N].last_line; \
508 Current.last_column = Rhs[N].last_column;
509 #endif
510
511 /* YYLEX -- calling `yylex' with the right arguments. */
512
513 #ifdef YYLEX_PARAM
514 # define YYLEX yylex (]b4_pure_if([&yylval[]b4_location_if([, &yylloc]), ])[YYLEX_PARAM)
515 #else
516 # define YYLEX ]b4_c_function_call([yylex], [int], b4_lex_param)[
517 #endif
518
519 /* Enable debugging if requested. */
520 #if YYDEBUG
521
522 # ifndef YYFPRINTF
523 # include <stdio.h> /* INFRINGES ON USER NAME SPACE */
524 # define YYFPRINTF fprintf
525 # endif
526
527 # define YYDPRINTF(Args) \
528 do { \
529 if (yydebug) \
530 YYFPRINTF Args; \
531 } while (0)
532
533 # define YYDSYMPRINT(Args) \
534 do { \
535 if (yydebug) \
536 yysymprint Args; \
537 } while (0)
538
539 # define YYDSYMPRINTF(Title, Token, Value, Location) \
540 do { \
541 if (yydebug) \
542 { \
543 YYFPRINTF (stderr, "%s ", Title); \
544 yysymprint (stderr, \
545 Token, Value]b4_location_if([, Location])[); \
546 YYFPRINTF (stderr, "\n"); \
547 } \
548 } while (0)
549
550 /*------------------------------------------------------------------.
551 | yy_stack_print -- Print the state stack from its BOTTOM up to its |
552 | TOP (cinluded). |
553 `------------------------------------------------------------------*/
554
555 ]b4_c_function_def([yy_stack_print], [static void],
556 [[short *bottom], [bottom]],
557 [[short *top], [top]])[
558 {
559 YYFPRINTF (stderr, "Stack now");
560 for (/* Nothing. */; bottom <= top; ++bottom)
561 YYFPRINTF (stderr, " %d", *bottom);
562 YYFPRINTF (stderr, "\n");
563 }
564
565 # define YY_STACK_PRINT(Bottom, Top) \
566 do { \
567 if (yydebug) \
568 yy_stack_print ((Bottom), (Top)); \
569 } while (0)
570
571
572 /*------------------------------------------------.
573 | Report that the YYRULE is going to be reduced. |
574 `------------------------------------------------*/
575
576 ]b4_c_function_def([yy_reduce_print], [static void],
577 [[int yyrule], [yyrule]])[
578 {
579 int yyi;
580 unsigned int yylineno = yyrline[yyrule];
581 YYFPRINTF (stderr, "Reducing stack by rule %d (line %u), ",
582 yyrule - 1, yylineno);
583 /* Print the symbols being reduced, and their result. */
584 for (yyi = yyprhs[yyrule]; 0 <= yyrhs[yyi]; yyi++)
585 YYFPRINTF (stderr, "%s ", yytname [yyrhs[yyi]]);
586 YYFPRINTF (stderr, "-> %s\n", yytname [yyr1[yyrule]]);
587 }
588
589 # define YY_REDUCE_PRINT(Rule) \
590 do { \
591 if (yydebug) \
592 yy_reduce_print (Rule); \
593 } while (0)
594
595 /* Nonzero means print parse trace. It is left uninitialized so that
596 multiple parsers can coexist. */
597 int yydebug;
598 #else /* !YYDEBUG */
599 # define YYDPRINTF(Args)
600 # define YYDSYMPRINT(Args)
601 # define YYDSYMPRINTF(Title, Token, Value, Location)
602 # define YY_STACK_PRINT(Bottom, Top)
603 # define YY_REDUCE_PRINT(Rule)
604 #endif /* !YYDEBUG */
605
606
607 /* YYINITDEPTH -- initial size of the parser's stacks. */
608 #ifndef YYINITDEPTH
609 # define YYINITDEPTH ]b4_stack_depth_init[
610 #endif
611
612 /* YYMAXDEPTH -- maximum size the stacks can grow to (effective only
613 if the built-in stack extension method is used).
614
615 Do not make this value too large; the results are undefined if
616 SIZE_MAX < YYSTACK_BYTES (YYMAXDEPTH)
617 evaluated with infinite-precision integer arithmetic. */
618
619 #if YYMAXDEPTH == 0
620 # undef YYMAXDEPTH
621 #endif
622
623 #ifndef YYMAXDEPTH
624 # define YYMAXDEPTH ]b4_stack_depth_max[
625 #endif
626
627 \f
628
629 #if YYERROR_VERBOSE
630
631 # ifndef yystrlen
632 # if defined (__GLIBC__) && defined (_STRING_H)
633 # define yystrlen strlen
634 # else
635 /* Return the length of YYSTR. */
636 static YYSIZE_T
637 # if defined (__STDC__) || defined (__cplusplus)
638 yystrlen (const char *yystr)
639 # else
640 yystrlen (yystr)
641 const char *yystr;
642 # endif
643 {
644 register const char *yys = yystr;
645
646 while (*yys++ != '\0')
647 continue;
648
649 return yys - yystr - 1;
650 }
651 # endif
652 # endif
653
654 # ifndef yystpcpy
655 # if defined (__GLIBC__) && defined (_STRING_H) && defined (_GNU_SOURCE)
656 # define yystpcpy stpcpy
657 # else
658 /* Copy YYSRC to YYDEST, returning the address of the terminating '\0' in
659 YYDEST. */
660 static char *
661 # if defined (__STDC__) || defined (__cplusplus)
662 yystpcpy (char *yydest, const char *yysrc)
663 # else
664 yystpcpy (yydest, yysrc)
665 char *yydest;
666 const char *yysrc;
667 # endif
668 {
669 register char *yyd = yydest;
670 register const char *yys = yysrc;
671
672 while ((*yyd++ = *yys++) != '\0')
673 continue;
674
675 return yyd - 1;
676 }
677 # endif
678 # endif
679
680 #endif /* !YYERROR_VERBOSE */
681
682 \f
683
684 #if YYDEBUG
685 ]b4_yysymprint_generate([b4_c_function_def])[
686 #endif /* ! YYDEBUG */
687 ]b4_yydestruct_generate([b4_c_function_def])
688 \f
689
690 /* Prevent warnings from -Wmissing-prototypes. */
691
692 #ifdef YYPARSE_PARAM
693 # if defined (__STDC__) || defined (__cplusplus)
694 int yyparse (void *YYPARSE_PARAM);
695 # else
696 int yyparse ();
697 # endif
698 #else /* ! YYPARSE_PARAM */
699 b4_c_function_decl([yyparse], [int], b4_parse_param)
700 #endif /* ! YYPARSE_PARAM */
701
702
703 m4_divert_push([KILL])# ======================== M4 code.
704 # b4_declare_parser_variables
705 # ---------------------------
706 # Declare the variables that are global, or local to YYPARSE if
707 # pure-parser.
708 m4_define([b4_declare_parser_variables],
709 [/* The lookahead symbol. */
710 int yychar;
711
712 /* The semantic value of the lookahead symbol. */
713 YYSTYPE yylval;
714
715 /* Number of syntax errors so far. */
716 int yynerrs;b4_location_if([
717 /* Location data for the lookahead symbol. */
718 YYLTYPE yylloc;])
719 ])
720 m4_divert_pop([KILL])dnl# ====================== End of M4 code.
721
722 b4_pure_if([],
723 [b4_declare_parser_variables])
724
725
726 /*----------.
727 | yyparse. |
728 `----------*/
729
730 #ifdef YYPARSE_PARAM
731 # if defined (__STDC__) || defined (__cplusplus)
732 int yyparse (void *YYPARSE_PARAM)
733 # else
734 int yyparse (YYPARSE_PARAM)
735 void *YYPARSE_PARAM;
736 # endif
737 #else /* ! YYPARSE_PARAM */
738 b4_c_function_def([yyparse], [int], b4_parse_param)
739 #endif
740 {[
741 ]b4_pure_if([b4_declare_parser_variables])[
742 register int yystate;
743 register int yyn;
744 int yyresult;
745 /* Number of tokens to shift before error messages enabled. */
746 int yyerrstatus;
747 /* Lookahead token as an internal (translated) token number. */
748 int yytoken = 0;
749
750 /* Three stacks and their tools:
751 `yyss': related to states,
752 `yyvs': related to semantic values,
753 `yyls': related to locations.
754
755 Refer to the stacks thru separate pointers, to allow yyoverflow
756 to reallocate them elsewhere. */
757
758 /* The state stack. */
759 short yyssa[YYINITDEPTH];
760 short *yyss = yyssa;
761 register short *yyssp;
762
763 /* The semantic value stack. */
764 YYSTYPE yyvsa[YYINITDEPTH];
765 YYSTYPE *yyvs = yyvsa;
766 register YYSTYPE *yyvsp;
767
768 ]b4_location_if(
769 [[ /* The location stack. */
770 YYLTYPE yylsa[YYINITDEPTH];
771 YYLTYPE *yyls = yylsa;
772 YYLTYPE *yylsp;]])[
773
774 #define YYPOPSTACK (yyvsp--, yyssp--]b4_location_if([, yylsp--])[)
775
776 YYSIZE_T yystacksize = YYINITDEPTH;
777
778 /* The variables used to return semantic value and location from the
779 action routines. */
780 YYSTYPE yyval;
781 ]b4_location_if([ YYLTYPE yyloc;])[
782
783 /* When reducing, the number of symbols on the RHS of the reduced
784 rule. */
785 int yylen;
786
787 YYDPRINTF ((stderr, "Starting parse\n"));
788
789 yystate = 0;
790 yyerrstatus = 0;
791 yynerrs = 0;
792 yychar = yytoken = YYEMPTY; /* Cause a token to be read. */
793
794 /* Initialize stack pointers.
795 Waste one element of value and location stack
796 so that they stay on the same level as the state stack.
797 The wasted elements are never initialized. */
798
799 yyssp = yyss;
800 yyvsp = yyvs;
801 ]b4_location_if([ yylsp = yyls;])[
802 goto yysetstate;
803
804 /*------------------------------------------------------------.
805 | yynewstate -- Push a new state, which is found in yystate. |
806 `------------------------------------------------------------*/
807 yynewstate:
808 /* In all cases, when you get here, the value and location stacks
809 have just been pushed. so pushing a state here evens the stacks.
810 */
811 yyssp++;
812
813 yysetstate:
814 *yyssp = yystate;
815
816 if (yyss + yystacksize - 1 <= yyssp)
817 {
818 /* Get the current used size of the three stacks, in elements. */
819 YYSIZE_T yysize = yyssp - yyss + 1;
820
821 #ifdef yyoverflow
822 {
823 /* Give user a chance to reallocate the stack. Use copies of
824 these so that the &'s don't force the real ones into
825 memory. */
826 YYSTYPE *yyvs1 = yyvs;
827 short *yyss1 = yyss;
828 ]b4_location_if([ YYLTYPE *yyls1 = yyls;])[
829
830 /* Each stack pointer address is followed by the size of the
831 data in use in that stack, in bytes. This used to be a
832 conditional around just the two extra args, but that might
833 be undefined if yyoverflow is a macro. */
834 yyoverflow ("parser stack overflow",
835 &yyss1, yysize * sizeof (*yyssp),
836 &yyvs1, yysize * sizeof (*yyvsp),
837 ]b4_location_if([ &yyls1, yysize * sizeof (*yylsp),])[
838 &yystacksize);
839 ]b4_location_if([ yyls = yyls1;])[
840 yyss = yyss1;
841 yyvs = yyvs1;
842 }
843 #else /* no yyoverflow */
844 # ifndef YYSTACK_RELOCATE
845 goto yyoverflowlab;
846 # else
847 /* Extend the stack our own way. */
848 if (YYMAXDEPTH <= yystacksize)
849 goto yyoverflowlab;
850 yystacksize *= 2;
851 if (YYMAXDEPTH < yystacksize)
852 yystacksize = YYMAXDEPTH;
853
854 {
855 short *yyss1 = yyss;
856 union yyalloc *yyptr =
857 (union yyalloc *) YYSTACK_ALLOC (YYSTACK_BYTES (yystacksize));
858 if (! yyptr)
859 goto yyoverflowlab;
860 YYSTACK_RELOCATE (yyss);
861 YYSTACK_RELOCATE (yyvs);
862 ]b4_location_if([ YYSTACK_RELOCATE (yyls);])[
863 # undef YYSTACK_RELOCATE
864 if (yyss1 != yyssa)
865 YYSTACK_FREE (yyss1);
866 }
867 # endif
868 #endif /* no yyoverflow */
869
870 yyssp = yyss + yysize - 1;
871 yyvsp = yyvs + yysize - 1;
872 ]b4_location_if([ yylsp = yyls + yysize - 1;])[
873
874 YYDPRINTF ((stderr, "Stack size increased to %lu\n",
875 (unsigned long int) yystacksize));
876
877 if (yyss + yystacksize - 1 <= yyssp)
878 YYABORT;
879 }
880
881 YYDPRINTF ((stderr, "Entering state %d\n", yystate));
882
883 goto yybackup;
884
885 /*-----------.
886 | yybackup. |
887 `-----------*/
888 yybackup:
889
890 /* Do appropriate processing given the current state. */
891 /* Read a lookahead token if we need one and don't already have one. */
892 /* yyresume: */
893
894 /* First try to decide what to do without reference to lookahead token. */
895
896 yyn = yypact[yystate];
897 if (yyn == YYPACT_NINF)
898 goto yydefault;
899
900 /* Not known => get a lookahead token if don't already have one. */
901
902 /* YYTOKEN is either YYEMPTY or YYEOF or a valid token. */
903 if (yytoken == YYEMPTY)
904 {
905 YYDPRINTF ((stderr, "Reading a token: "));
906 yychar = YYLEX;
907 yytoken = YYTRANSLATE (yychar);
908 }
909
910 if (yytoken == YYEOF)
911 {
912 YYDPRINTF ((stderr, "Now at end of input.\n"));
913 }
914 else
915 {
916 YYDSYMPRINTF ("Next token is", yytoken, &yylval, &yylloc);
917 }
918
919 /* If the proper action on seeing token YYTOKEN is to reduce or to
920 detect an error, take that action. */
921 yyn += yytoken;
922 if (yyn < 0 || YYLAST < yyn || yycheck[yyn] != yytoken)
923 goto yydefault;
924 yyn = yytable[yyn];
925 if (yyn <= 0)
926 {
927 if (yyn == 0 || yyn == YYTABLE_NINF)
928 goto yyerrlab;
929 yyn = -yyn;
930 goto yyreduce;
931 }
932
933 if (yyn == YYFINAL)
934 YYACCEPT;
935
936 /* Shift the lookahead token. */
937 YYDPRINTF ((stderr, "Shifting token %s, ", yytname[yytoken]));
938
939 /* Discard the token being shifted unless it is eof. */
940 if (yytoken != YYEOF)
941 yytoken = YYEMPTY;
942
943 *++yyvsp = yylval;
944 ]b4_location_if([ *++yylsp = yylloc;])[
945
946 /* Count tokens shifted since error; after three, turn off error
947 status. */
948 if (yyerrstatus)
949 yyerrstatus--;
950
951 yystate = yyn;
952 goto yynewstate;
953
954
955 /*-----------------------------------------------------------.
956 | yydefault -- do the default action for the current state. |
957 `-----------------------------------------------------------*/
958 yydefault:
959 yyn = yydefact[yystate];
960 if (yyn == 0)
961 goto yyerrlab;
962 goto yyreduce;
963
964
965 /*-----------------------------.
966 | yyreduce -- Do a reduction. |
967 `-----------------------------*/
968 yyreduce:
969 /* yyn is the number of a rule to reduce with. */
970 yylen = yyr2[yyn];
971
972 /* If YYLEN is nonzero, implement the default value of the action:
973 `$$ = $1'.
974
975 Otherwise, the following line sets YYVAL to garbage.
976 This behavior is undocumented and Bison
977 users should not rely upon it. Assigning to YYVAL
978 unconditionally makes the parser a bit smaller, and it avoids a
979 GCC warning that YYVAL may be used uninitialized. */
980 yyval = yyvsp[1-yylen];
981
982 ]b4_location_if(
983 [ /* Default location. */
984 YYLLOC_DEFAULT (yyloc, (yylsp - yylen), yylen);])[
985 YY_REDUCE_PRINT (yyn);
986 switch (yyn)
987 ]{
988 b4_actions
989 }
990
991 /* Line __line__ of yacc.c. */
992 b4_syncline([@oline@], [@ofile@])
993 \f
994 [ yyvsp -= yylen;
995 yyssp -= yylen;
996 ]b4_location_if([ yylsp -= yylen;])[
997
998 YY_STACK_PRINT (yyss, yyssp);
999
1000 *++yyvsp = yyval;
1001 ]b4_location_if([ *++yylsp = yyloc;])[
1002
1003 /* Now `shift' the result of the reduction. Determine what state
1004 that goes to, based on the state we popped back to and the rule
1005 number reduced by. */
1006
1007 yyn = yyr1[yyn];
1008
1009 yystate = yypgoto[yyn - YYNTOKENS] + *yyssp;
1010 if (0 <= yystate && yystate <= YYLAST && yycheck[yystate] == *yyssp)
1011 yystate = yytable[yystate];
1012 else
1013 yystate = yydefgoto[yyn - YYNTOKENS];
1014
1015 goto yynewstate;
1016
1017
1018 /*------------------------------------.
1019 | yyerrlab -- here on detecting error |
1020 `------------------------------------*/
1021 yyerrlab:
1022 /* If not already recovering from an error, report this error. */
1023 if (!yyerrstatus)
1024 {
1025 ++yynerrs;
1026 #if YYERROR_VERBOSE
1027 yyn = yypact[yystate];
1028
1029 if (YYPACT_NINF < yyn && yyn < YYLAST)
1030 {
1031 YYSIZE_T yysize = 0;
1032 int yytype = YYTRANSLATE (yychar);
1033 char *yymsg;
1034 int yyx, yycount;
1035
1036 yycount = 0;
1037 /* Start YYX at -YYN if negative to avoid negative indexes in
1038 YYCHECK. */
1039 for (yyx = yyn < 0 ? -yyn : 0;
1040 yyx < (int) (sizeof (yytname) / sizeof (char *)); yyx++)
1041 if (yycheck[yyx + yyn] == yyx && yyx != YYTERROR)
1042 yysize += yystrlen (yytname[yyx]) + 15, yycount++;
1043 yysize += yystrlen ("syntax error, unexpected ") + 1;
1044 yysize += yystrlen (yytname[yytype]);
1045 yymsg = (char *) YYSTACK_ALLOC (yysize);
1046 if (yymsg != 0)
1047 {
1048 char *yyp = yystpcpy (yymsg, "syntax error, unexpected ");
1049 yyp = yystpcpy (yyp, yytname[yytype]);
1050
1051 if (yycount < 5)
1052 {
1053 yycount = 0;
1054 for (yyx = yyn < 0 ? -yyn : 0;
1055 yyx < (int) (sizeof (yytname) / sizeof (char *));
1056 yyx++)
1057 if (yycheck[yyx + yyn] == yyx && yyx != YYTERROR)
1058 {
1059 const char *yyq = ! yycount ? ", expecting " : " or ";
1060 yyp = yystpcpy (yyp, yyq);
1061 yyp = yystpcpy (yyp, yytname[yyx]);
1062 yycount++;
1063 }
1064 }
1065 yyerror (]b4_yyerror_args[yymsg);
1066 YYSTACK_FREE (yymsg);
1067 }
1068 else
1069 yyerror (]b4_yyerror_args["syntax error; also virtual memory exhausted");
1070 }
1071 else
1072 #endif /* YYERROR_VERBOSE */
1073 yyerror (]b4_yyerror_args["syntax error");
1074 }
1075
1076 if (yyerrstatus == 3)
1077 {
1078 /* If just tried and failed to reuse lookahead token after an
1079 error, discard it. */
1080
1081 /* Return failure if at end of input. */
1082 if (yytoken == YYEOF)
1083 {
1084 /* Pop the error token. */
1085 YYPOPSTACK;
1086 /* Pop the rest of the stack. */
1087 while (yyss < yyssp)
1088 {
1089 YYDSYMPRINTF ("Error: popping", yystos[*yyssp], yyvsp, yylsp);
1090 yydestruct (yystos[*yyssp], yyvsp]b4_location_if([, yylsp])[);
1091 YYPOPSTACK;
1092 }
1093 YYABORT;
1094 }
1095
1096 YYDSYMPRINTF ("Error: discarding", yytoken, &yylval, &yylloc);
1097 yydestruct (yytoken, &yylval]b4_location_if([, &yylloc])[);
1098 yytoken = YYEMPTY;
1099 }
1100
1101 /* Else will try to reuse lookahead token after shifting the error
1102 token. */
1103 goto yyerrlab1;
1104
1105
1106 /*----------------------------------------------------.
1107 | yyerrlab1 -- error raised explicitly by an action. |
1108 `----------------------------------------------------*/
1109 yyerrlab1:
1110 yyerrstatus = 3; /* Each real token shifted decrements this. */
1111
1112 for (;;)
1113 {
1114 yyn = yypact[yystate];
1115 if (yyn != YYPACT_NINF)
1116 {
1117 yyn += YYTERROR;
1118 if (0 <= yyn && yyn <= YYLAST && yycheck[yyn] == YYTERROR)
1119 {
1120 yyn = yytable[yyn];
1121 if (0 < yyn)
1122 break;
1123 }
1124 }
1125
1126 /* Pop the current state because it cannot handle the error token. */
1127 if (yyssp == yyss)
1128 YYABORT;
1129
1130 YYDSYMPRINTF ("Error: popping", yystos[*yyssp], yyvsp, yylsp);
1131 yydestruct (yystos[yystate], yyvsp]b4_location_if([, yylsp])[);
1132 yyvsp--;
1133 yystate = *--yyssp;
1134 ]b4_location_if([ yylsp--;])[
1135 YY_STACK_PRINT (yyss, yyssp);
1136 }
1137
1138 if (yyn == YYFINAL)
1139 YYACCEPT;
1140
1141 YYDPRINTF ((stderr, "Shifting error token, "));
1142
1143 *++yyvsp = yylval;
1144 ]b4_location_if([ *++yylsp = yylloc;])[
1145
1146 yystate = yyn;
1147 goto yynewstate;
1148
1149
1150 /*-------------------------------------.
1151 | yyacceptlab -- YYACCEPT comes here. |
1152 `-------------------------------------*/
1153 yyacceptlab:
1154 yyresult = 0;
1155 goto yyreturn;
1156
1157 /*-----------------------------------.
1158 | yyabortlab -- YYABORT comes here. |
1159 `-----------------------------------*/
1160 yyabortlab:
1161 yyresult = 1;
1162 goto yyreturn;
1163
1164 #ifndef yyoverflow
1165 /*----------------------------------------------.
1166 | yyoverflowlab -- parser overflow comes here. |
1167 `----------------------------------------------*/
1168 yyoverflowlab:
1169 yyerror (]b4_yyerror_args["parser stack overflow");
1170 yyresult = 2;
1171 /* Fall through. */
1172 #endif
1173
1174 yyreturn:
1175 #ifndef yyoverflow
1176 if (yyss != yyssa)
1177 YYSTACK_FREE (yyss);
1178 #endif
1179 return yyresult;
1180 ]}
1181
1182
1183 b4_epilogue
1184 m4_if(b4_defines_flag, 0, [],
1185 [@output @output_header_name@
1186 b4_copyright([Skeleton parser for Yacc-like parsing with Bison],
1187 [1984, 1989, 1990, 2000, 2001, 2002])
1188
1189 /* As a special exception, when this file is copied by Bison into a
1190 Bison output file, you may use that output file without restriction.
1191 This special exception was added by the Free Software Foundation
1192 in version 1.24 of Bison. */
1193
1194 b4_token_defines(b4_tokens)
1195
1196 #ifndef YYSTYPE
1197 m4_ifdef([b4_stype],
1198 [b4_syncline([b4_stype_line], [b4_filename])
1199 typedef union b4_stype yystype;
1200 /* Line __line__ of yacc.c. */
1201 b4_syncline([@oline@], [@ofile@])],
1202 [typedef int yystype;])
1203 # define YYSTYPE yystype
1204 # define YYSTYPE_IS_TRIVIAL 1
1205 #endif
1206
1207 b4_pure_if([],
1208 [extern YYSTYPE b4_prefix[]lval;])
1209
1210 b4_location_if(
1211 [#ifndef YYLTYPE
1212 typedef struct yyltype
1213 {
1214 int first_line;
1215 int first_column;
1216 int last_line;
1217 int last_column;
1218 } yyltype;
1219 # define YYLTYPE yyltype
1220 #endif
1221
1222 m4_if(b4_pure, [0],
1223 [extern YYLTYPE b4_prefix[]lloc;])
1224 ])
1225 ])