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