]> git.saurik.com Git - bison.git/blob - data/lalr1.cc
Improve genericity of bench.pl.
[bison.git] / data / lalr1.cc
1 # C++ skeleton for Bison
2
3 # Copyright (C) 2002, 2003, 2004, 2005, 2006, 2007, 2008
4 # 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 3 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, see <http://www.gnu.org/licenses/>.
18
19 m4_include(b4_pkgdatadir/[c++.m4])
20
21 # How the semantic value is extracted when using variants.
22 b4_variant_if([
23 # b4_symbol_value(VAL, [TYPE])
24 # ----------------------------
25 m4_define([b4_symbol_value],
26 [m4_ifval([$2],
27 [$1.as<$2>()],
28 [$1])])
29 ]) # b4_variant_if
30
31
32 # b4_symbol_actions(FILENAME, LINENO,
33 # SYMBOL-TAG, SYMBOL-NUM,
34 # SYMBOL-ACTION, SYMBOL-TYPENAME)
35 # -------------------------------------------------
36 # Same as in C, but using references instead of pointers.
37 m4_define([b4_symbol_actions],
38 [m4_pushdef([b4_dollar_dollar],
39 [b4_symbol_value([yyvalue], [$6])])dnl
40 m4_pushdef([b4_at_dollar], [yylocation])dnl
41 case $4: // $3
42 b4_syncline([$2], [$1])
43 $5;
44 b4_syncline([@oline@], [@ofile@])
45 break;
46 m4_popdef([b4_at_dollar])dnl
47 m4_popdef([b4_dollar_dollar])dnl
48 ])
49
50
51 # b4_symbol_action_(SYMBOL-TAG, SYMBOL-NUM, SYMBOL-TYPENAME)
52 # ----------------------------------------------------------
53 # Invoke b4_dollar_dollar(SYMBOL_TYPENAME) for each symbol.
54 m4_define([b4_symbol_action_],
55 [m4_ifval($3,
56 [ case $2: // $1
57 b4_dollar_dollar($@);
58 break;
59 ])])
60
61
62 # b4_symbol_variant(YYTYPE, YYVAL, ACTION)
63 # ----------------------------------------
64 # Run some ACTION ("build", or "destroy") on YYVAL of symbol type
65 # YYTYPE.
66 m4_define([b4_symbol_variant],
67 [m4_pushdef([b4_dollar_dollar],
68 [$2.$3<$][3>()])dnl
69 switch ($1)
70 {
71 m4_map([b4_symbol_action_], m4_defn([b4_type_names]))
72 default:
73 break;
74 }
75 m4_popdef([b4_dollar_dollar])dnl
76 ])
77
78
79 # _b4_char_sizeof_counter
80 # -----------------------
81 # A counter used by _b4_char_sizeof_dummy to create fresh symbols.
82 m4_define([_b4_char_sizeof_counter],
83 [0])
84
85 # _b4_char_sizeof_dummy
86 # ---------------------
87 # At each call return a new C++ identifier.
88 m4_define([_b4_char_sizeof_dummy],
89 [m4_define([_b4_char_sizeof_counter], m4_incr(_b4_char_sizeof_counter))dnl
90 dummy[]_b4_char_sizeof_counter])
91
92
93 # b4_char_sizeof(SYMBOL-TAG, SYMBOL-NUM, SYMBOL-TYPENAME)
94 # -------------------------------------------------------
95 # To be mapped on the list of type names to produce:
96 #
97 # char dummy1[sizeof(type_name_1)];
98 # char dummy2[sizeof(type_name_2)];
99 #
100 # for defined type names.
101 # $3 is doubly-quoted, do not quote it again.
102 m4_define([b4_char_sizeof],
103 [m4_ifval($3,
104 [
105 char _b4_char_sizeof_dummy@{sizeof($3)@}; // $1])dnl
106 ])
107
108
109 m4_define([b4_parser_class_name],
110 [b4_percent_define_get([[parser_class_name]])])
111
112 # The header is mandatory.
113 b4_defines_if([],
114 [b4_fatal([b4_skeleton[: using %%defines is mandatory]])])
115
116 # Backward compatibility.
117 m4_define([b4_location_constructors])
118 m4_include(b4_pkgdatadir/[location.cc])
119
120 # We do want M4 expansion after # for CPP macros.
121 m4_changecom()
122 m4_divert_push(0)dnl
123 b4_defines_if(
124 [@output(b4_spec_defines_file@)
125 b4_copyright([Skeleton interface for Bison LALR(1) parsers in C++],
126 [2002, 2003, 2004, 2005, 2006, 2007, 2008])
127 dnl FIXME: This is wrong, we want computed header guards.
128 [
129 /* C++ LALR(1) parser skeleton written by Akim Demaille. */
130
131 #ifndef PARSER_HEADER_H
132 # define PARSER_HEADER_H
133
134 ]b4_percent_code_get([[requires]])[
135
136 #include <string>
137 #include <iostream>
138 #include "stack.hh"
139
140 ]b4_namespace_open[
141 class position;
142 class location;
143 ]b4_variant_if([[
144 /// A char[S] buffer to store and retrieve objects.
145 ///
146 /// Sort of a variant, but does not keep track of the nature
147 /// of the stored data, since that knowledge is available
148 /// via the current state.
149 template <size_t S>
150 struct variant
151 {
152 /// Instantiate a \a T in here.
153 template <typename T>
154 inline void
155 build()
156 {
157 new (buffer) T;
158 }
159
160 /// Destroy the stored \a T.
161 template <typename T>
162 inline void
163 destroy()
164 {
165 reinterpret_cast<T&>(buffer).~T();
166 }
167
168 /// Accessor to a built \a T.
169 template <typename T>
170 inline T&
171 as()
172 {
173 return reinterpret_cast<T&>(buffer);
174 }
175
176 /// Const accessor to a built \a T (for %printer).
177 template <typename T>
178 inline const T&
179 as() const
180 {
181 return reinterpret_cast<const T&>(buffer);
182 }
183
184 /// A buffer large enough to store any of the semantic values.
185 char buffer[S];
186 };
187 ]])[
188 ]b4_namespace_close[
189
190 #include "location.hh"
191
192 /* Enabling traces. */
193 #ifndef YYDEBUG
194 # define YYDEBUG ]b4_debug_flag[
195 #endif
196
197 /* Enabling verbose error messages. */
198 #ifdef YYERROR_VERBOSE
199 # undef YYERROR_VERBOSE
200 # define YYERROR_VERBOSE 1
201 #else
202 # define YYERROR_VERBOSE ]b4_error_verbose_flag[
203 #endif
204
205 /* Enabling the token table. */
206 #ifndef YYTOKEN_TABLE
207 # define YYTOKEN_TABLE ]b4_token_table[
208 #endif
209
210 /* YYLLOC_DEFAULT -- Set CURRENT to span from RHS[1] to RHS[N].
211 If N is 0, then set CURRENT to the empty location which ends
212 the previous symbol: RHS[0] (always defined). */
213
214 #ifndef YYLLOC_DEFAULT
215 # define YYLLOC_DEFAULT(Current, Rhs, N) \
216 do { \
217 if (N) \
218 { \
219 (Current).begin = (Rhs)[1].begin; \
220 (Current).end = (Rhs)[N].end; \
221 } \
222 else \
223 { \
224 (Current).begin = (Current).end = (Rhs)[0].end; \
225 } \
226 } while (false)
227 #endif
228
229 ]b4_namespace_open[
230
231 /// A Bison parser.
232 class ]b4_parser_class_name[
233 {
234 public:
235 #ifndef YYSTYPE
236 ]b4_variant_if(
237 [ /// An auxiliary type to compute the largest semantic type.
238 union union_type
239 {]m4_map([b4_char_sizeof], m4_defn([b4_type_names]))[
240 };
241
242 /// Symbol semantic values.
243 typedef variant<sizeof(union_type)> semantic_type;],
244 [ /// Symbol semantic values.
245 m4_ifdef([b4_stype],
246 [ union semantic_type
247 {b4_user_stype
248 };],
249 [m4_if(b4_tag_seen_flag, 0,
250 [[ typedef int semantic_type;]],
251 [[ typedef YYSTYPE semantic_type;]])])])[
252 #else
253 typedef YYSTYPE semantic_type;
254 #endif
255 /// Symbol locations.
256 typedef ]b4_percent_define_get([[location_type]])[ location_type;
257 /// Tokens.
258 struct token
259 {
260 ]b4_token_enums(b4_tokens)[
261 };
262 /// Token type.
263 typedef token::yytokentype token_type;
264
265 /// Build a parser object.
266 ]b4_parser_class_name[ (]b4_parse_param_decl[);
267 virtual ~]b4_parser_class_name[ ();
268
269 /// Parse.
270 /// \returns 0 iff parsing succeeded.
271 virtual int parse ();
272
273 #if YYDEBUG
274 /// The current debugging stream.
275 std::ostream& debug_stream () const;
276 /// Set the current debugging stream.
277 void set_debug_stream (std::ostream &);
278
279 /// Type for debugging levels.
280 typedef int debug_level_type;
281 /// The current debugging level.
282 debug_level_type debug_level () const;
283 /// Set the current debugging level.
284 void set_debug_level (debug_level_type l);
285 #endif
286
287 private:
288 /// Report a syntax error.
289 /// \param loc where the syntax error is found.
290 /// \param msg a description of the syntax error.
291 virtual void error (const location_type& loc, const std::string& msg);
292
293 /// Generate an error message.
294 /// \param state the state where the error occurred.
295 /// \param tok the lookahead token.
296 virtual std::string yysyntax_error_ (int yystate]dnl
297 b4_error_verbose_if([, int tok])[);
298
299 #if YYDEBUG
300 /// \brief Report a symbol value on the debug stream.
301 /// \param yytype The token type.
302 /// \param yyvalue Its semantic value.
303 /// \param yylocation Its location.
304 virtual void yy_symbol_value_print_ (int yytype,
305 const semantic_type& yyvalue,
306 const location_type& yylocation);
307 /// \brief Report a symbol on the debug stream.
308 /// \param yytype The token type.
309 /// \param yyvalue Its semantic value.
310 /// \param yylocation Its location.
311 virtual void yy_symbol_print_ (int yytype,
312 const semantic_type& yyvalue,
313 const location_type& yylocation);
314 #endif
315
316
317 /// State numbers.
318 typedef int state_type;
319 /// State stack type.
320 typedef stack<state_type> state_stack_type;
321 /// Semantic value stack type.
322 typedef stack<semantic_type> semantic_stack_type;
323 /// location stack type.
324 typedef stack<location_type> location_stack_type;
325
326 /// The state stack.
327 state_stack_type yystate_stack_;
328 /// The semantic value stack.
329 semantic_stack_type yysemantic_stack_;
330 /// The location stack.
331 location_stack_type yylocation_stack_;
332
333 /// Internal symbol numbers.
334 typedef ]b4_int_type_for([b4_translate])[ token_number_type;
335 /* Tables. */
336 /// For a state, the index in \a yytable_ of its portion.
337 static const ]b4_int_type_for([b4_pact])[ yypact_[];
338 static const ]b4_int_type(b4_pact_ninf, b4_pact_ninf)[ yypact_ninf_;
339
340 /// For a state, default rule to reduce.
341 /// Unless\a yytable_ specifies something else to do.
342 /// Zero means the default is an error.
343 static const ]b4_int_type_for([b4_defact])[ yydefact_[];
344
345 static const ]b4_int_type_for([b4_pgoto])[ yypgoto_[];
346 static const ]b4_int_type_for([b4_defgoto])[ yydefgoto_[];
347
348 /// What to do in a state.
349 /// \a yytable_[yypact_[s]]: what to do in state \a s.
350 /// - if positive, shift that token.
351 /// - if negative, reduce the rule which number is the opposite.
352 /// - if zero, do what YYDEFACT says.
353 static const ]b4_int_type_for([b4_table])[ yytable_[];
354 static const ]b4_int_type(b4_table_ninf, b4_table_ninf)[ yytable_ninf_;
355
356 static const ]b4_int_type_for([b4_check])[ yycheck_[];
357
358 /// For a state, its accessing symbol.
359 static const ]b4_int_type_for([b4_stos])[ yystos_[];
360
361 /// For a rule, its LHS.
362 static const ]b4_int_type_for([b4_r1])[ yyr1_[];
363 /// For a rule, its RHS length.
364 static const ]b4_int_type_for([b4_r2])[ yyr2_[];
365
366 #if YYDEBUG || YYERROR_VERBOSE || YYTOKEN_TABLE
367 /// For a symbol, its name in clear.
368 static const char* const yytname_[];
369 #endif
370
371 #if YYERROR_VERBOSE
372 /// Convert the symbol name \a n to a form suitable for a diagnostic.
373 virtual std::string yytnamerr_ (const char *n);
374 #endif
375
376 #if YYDEBUG
377 /// A type to store symbol numbers and -1.
378 typedef ]b4_int_type_for([b4_rhs])[ rhs_number_type;
379 /// A `-1'-separated list of the rules' RHS.
380 static const rhs_number_type yyrhs_[];
381 /// For each rule, the index of the first RHS symbol in \a yyrhs_.
382 static const ]b4_int_type_for([b4_prhs])[ yyprhs_[];
383 /// For each rule, its source line number.
384 static const ]b4_int_type_for([b4_rline])[ yyrline_[];
385 /// For each scanner token number, its symbol number.
386 static const ]b4_int_type_for([b4_toknum])[ yytoken_number_[];
387 /// Report on the debug stream that the rule \a r is going to be reduced.
388 virtual void yy_reduce_print_ (int r);
389 /// Print the state stack on the debug stream.
390 virtual void yystack_print_ ();
391
392 /* Debugging. */
393 int yydebug_;
394 std::ostream* yycdebug_;
395 #endif
396
397 /// Convert a scanner token number \a t to a symbol number.
398 token_number_type yytranslate_ (int t);
399
400 /// \brief Reclaim the memory associated to a symbol.
401 /// \param yymsg Why this token is reclaimed.
402 /// \param yytype The symbol type.
403 /// \param yyvalue Its semantic value.
404 /// \param yylocation Its location.
405 inline void yydestruct_ (const char* yymsg,
406 int yytype,
407 semantic_type& yyvalue,
408 location_type& yylocation);
409
410 /// Push a new state on the stack.
411 /// \warning the contents of \a v is stolen.
412 inline void yypush_ (state_type s,
413 semantic_type& v, const location_type& l);
414
415 /// Pop \a n symbols the three stacks.
416 inline void yypop_ (unsigned int n = 1);
417
418 /* Constants. */
419 static const int yyeof_;
420 /* LAST_ -- Last index in TABLE_. */
421 static const int yylast_;
422 static const int yynnts_;
423 static const int yyempty_;
424 static const int yyfinal_;
425 static const int yyterror_;
426 static const int yyerrcode_;
427 static const int yyntokens_;
428 static const unsigned int yyuser_token_number_max_;
429 static const token_number_type yyundef_token_;
430 ]b4_parse_param_vars[
431 };
432 ]b4_namespace_close[
433
434 ]b4_percent_define_flag_if([[global_tokens_and_yystype]],
435 [b4_token_defines(b4_tokens)
436
437 #ifndef YYSTYPE
438 /* Redirection for backward compatibility. */
439 # define YYSTYPE b4_namespace_ref::b4_parser_class_name::semantic_type
440 #endif
441 ])
442 b4_percent_code_get([[provides]])[]dnl
443
444 [#endif /* ! defined PARSER_HEADER_H */]
445 ])dnl
446 @output(b4_parser_file_name@)
447 b4_copyright([Skeleton implementation for Bison LALR(1) parsers in C++],
448 [2002, 2003, 2004, 2005, 2006, 2007, 2008])
449 b4_percent_code_get([[top]])[]dnl
450 m4_if(b4_prefix, [yy], [],
451 [
452 // Take the name prefix into account.
453 #define yylex b4_prefix[]lex])[
454
455 /* First part of user declarations. */
456 ]b4_user_pre_prologue
457
458 b4_defines_if([[
459 #include "@basename(]b4_spec_defines_file[@)"]])[
460
461 /* User implementation prologue. */
462 ]b4_user_post_prologue
463 b4_percent_code_get[]dnl
464
465 [#ifndef YY_
466 # if YYENABLE_NLS
467 # if ENABLE_NLS
468 # include <libintl.h> /* FIXME: INFRINGES ON USER NAME SPACE */
469 # define YY_(msgid) dgettext ("bison-runtime", msgid)
470 # endif
471 # endif
472 # ifndef YY_
473 # define YY_(msgid) msgid
474 # endif
475 #endif
476
477 /* Suppress unused-variable warnings by "using" E. */
478 #define YYUSE(e) ((void) (e))
479
480 /* Enable debugging if requested. */
481 #if YYDEBUG
482
483 /* A pseudo ostream that takes yydebug_ into account. */
484 # define YYCDEBUG if (yydebug_) (*yycdebug_)
485
486 # define YY_SYMBOL_PRINT(Title, Type, Value, Location) \
487 do { \
488 if (yydebug_) \
489 { \
490 *yycdebug_ << Title << ' '; \
491 yy_symbol_print_ ((Type), (Value), (Location)); \
492 *yycdebug_ << std::endl; \
493 } \
494 } while (false)
495
496 # define YY_REDUCE_PRINT(Rule) \
497 do { \
498 if (yydebug_) \
499 yy_reduce_print_ (Rule); \
500 } while (false)
501
502 # define YY_STACK_PRINT() \
503 do { \
504 if (yydebug_) \
505 yystack_print_ (); \
506 } while (false)
507
508 #else /* !YYDEBUG */
509
510 # define YYCDEBUG if (false) std::cerr
511 # define YY_SYMBOL_PRINT(Title, Type, Value, Location)
512 # define YY_REDUCE_PRINT(Rule)
513 # define YY_STACK_PRINT()
514
515 #endif /* !YYDEBUG */
516
517 #define yyerrok (yyerrstatus_ = 0)
518 #define yyclearin (yychar = yyempty_)
519
520 #define YYACCEPT goto yyacceptlab
521 #define YYABORT goto yyabortlab
522 #define YYERROR goto yyerrorlab
523 #define YYRECOVERING() (!!yyerrstatus_)
524
525 ]b4_namespace_open[
526 #if YYERROR_VERBOSE
527
528 /* Return YYSTR after stripping away unnecessary quotes and
529 backslashes, so that it's suitable for yyerror. The heuristic is
530 that double-quoting is unnecessary unless the string contains an
531 apostrophe, a comma, or backslash (other than backslash-backslash).
532 YYSTR is taken from yytname. */
533 std::string
534 ]b4_parser_class_name[::yytnamerr_ (const char *yystr)
535 {
536 if (*yystr == '"')
537 {
538 std::string yyr = "";
539 char const *yyp = yystr;
540
541 for (;;)
542 switch (*++yyp)
543 {
544 case '\'':
545 case ',':
546 goto do_not_strip_quotes;
547
548 case '\\':
549 if (*++yyp != '\\')
550 goto do_not_strip_quotes;
551 /* Fall through. */
552 default:
553 yyr += *yyp;
554 break;
555
556 case '"':
557 return yyr;
558 }
559 do_not_strip_quotes: ;
560 }
561
562 return yystr;
563 }
564
565 #endif
566
567 /// Build a parser object.
568 ]b4_parser_class_name::b4_parser_class_name[ (]b4_parse_param_decl[)]m4_ifset([b4_parse_param], [
569 :])[
570 #if YYDEBUG
571 ]m4_ifset([b4_parse_param], [ ], [ :])[yydebug_ (false),
572 yycdebug_ (&std::cerr)]m4_ifset([b4_parse_param], [,])[
573 #endif]b4_parse_param_cons[
574 {
575 }
576
577 ]b4_parser_class_name::~b4_parser_class_name[ ()
578 {
579 }
580
581 #if YYDEBUG
582 /*--------------------------------.
583 | Print this symbol on YYOUTPUT. |
584 `--------------------------------*/
585
586 inline void
587 ]b4_parser_class_name[::yy_symbol_value_print_ (int yytype,
588 const semantic_type& yyvalue, const location_type& yylocation)
589 {
590 YYUSE (yylocation);
591 YYUSE (yyvalue);
592 switch (yytype)
593 {
594 ]m4_map([b4_symbol_actions], m4_defn([b4_symbol_printers]))dnl
595 [ default:
596 break;
597 }
598 }
599
600
601 void
602 ]b4_parser_class_name[::yy_symbol_print_ (int yytype,
603 const semantic_type& yyvalue, const location_type& yylocation)
604 {
605 *yycdebug_ << (yytype < yyntokens_ ? "token" : "nterm")
606 << ' ' << yytname_[yytype] << " ("
607 << yylocation << ": ";
608 yy_symbol_value_print_ (yytype, yyvalue, yylocation);
609 *yycdebug_ << ')';
610 }
611 #endif
612
613 void
614 ]b4_parser_class_name[::yydestruct_ (const char* yymsg,
615 int yytype, semantic_type& yyvalue, location_type& yylocation)
616 {
617 YYUSE (yymsg);
618 YYUSE (yyvalue);
619 YYUSE (yylocation);
620
621 YY_SYMBOL_PRINT (yymsg, yytype, yyvalue, yylocation);
622
623 switch (yytype)
624 {
625 ]m4_map([b4_symbol_actions], m4_defn([b4_symbol_destructors]))[
626 default:
627 break;
628 }
629 }
630
631 void
632 ]b4_parser_class_name[::yypush_ (state_type s,
633 semantic_type& v, const location_type& l)
634 {
635 yystate_stack_.push (s);
636 yysemantic_stack_.push (v);
637 yylocation_stack_.push (l);
638 }
639
640 void
641 ]b4_parser_class_name[::yypop_ (unsigned int n)
642 {
643 yystate_stack_.pop (n);
644 yysemantic_stack_.pop (n);
645 yylocation_stack_.pop (n);
646 }
647
648 #if YYDEBUG
649 std::ostream&
650 ]b4_parser_class_name[::debug_stream () const
651 {
652 return *yycdebug_;
653 }
654
655 void
656 ]b4_parser_class_name[::set_debug_stream (std::ostream& o)
657 {
658 yycdebug_ = &o;
659 }
660
661
662 ]b4_parser_class_name[::debug_level_type
663 ]b4_parser_class_name[::debug_level () const
664 {
665 return yydebug_;
666 }
667
668 void
669 ]b4_parser_class_name[::set_debug_level (debug_level_type l)
670 {
671 yydebug_ = l;
672 }
673 #endif
674
675 int
676 ]b4_parser_class_name[::parse ()
677 {
678 /// Lookahead and lookahead in internal form.
679 int yychar = yyempty_;
680 int yytoken = 0;
681
682 /* State. */
683 int yyn;
684 int yylen = 0;
685 int yystate = 0;
686
687 /* Error handling. */
688 int yynerrs_ = 0;
689 int yyerrstatus_ = 0;
690
691 /// Semantic value of the lookahead.
692 semantic_type yylval;
693 /// Location of the lookahead.
694 location_type yylloc;
695 /// The locations where the error started and ended.
696 location_type yyerror_range[2];
697
698 /// $$.
699 semantic_type yyval;
700 /// @@$.
701 location_type yyloc;
702
703 int yyresult;
704
705 YYCDEBUG << "Starting parse" << std::endl;
706
707 ]m4_ifdef([b4_initial_action], [
708 m4_pushdef([b4_at_dollar], [yylloc])dnl
709 m4_pushdef([b4_dollar_dollar], [yylval])dnl
710 /* User initialization code. */
711 b4_user_initial_action
712 m4_popdef([b4_dollar_dollar])dnl
713 m4_popdef([b4_at_dollar])])dnl
714
715 [ /* Initialize the stacks. The initial state will be pushed in
716 yynewstate, since the latter expects the semantical and the
717 location values to have been already stored, initialize these
718 stacks with a primary value. */
719 yystate_stack_ = state_stack_type (0);
720 yysemantic_stack_ = semantic_stack_type (0);
721 yylocation_stack_ = location_stack_type (0);
722 yypush_ (yystate, yylval, yylloc);
723
724 // A new state was pushed on the stack.
725 // Invariant: yystate == yystack_[0].state, i.e.,
726 // yystate was just pushed onto the state stack.
727 yynewstate:
728 YYCDEBUG << "Entering state " << yystate << std::endl;
729
730 /* Accept? */
731 if (yystate == yyfinal_)
732 goto yyacceptlab;
733
734 goto yybackup;
735
736 /* Backup. */
737 yybackup:
738
739 /* Try to take a decision without lookahead. */
740 yyn = yypact_[yystate];
741 if (yyn == yypact_ninf_)
742 goto yydefault;
743
744 /* Read a lookahead token. */
745 if (yychar == yyempty_)
746 {
747 YYCDEBUG << "Reading a token: ";
748 yychar = ]b4_c_function_call([yylex], [int],
749 [[YYSTYPE*], [&yylval]][]dnl
750 b4_locations_if([, [[location*], [&yylloc]]])dnl
751 m4_ifdef([b4_lex_param], [, ]b4_lex_param))[;
752 }
753
754
755 /* Convert token to internal form. */
756 if (yychar <= yyeof_)
757 {
758 yychar = yytoken = yyeof_;
759 YYCDEBUG << "Now at end of input." << std::endl;
760 }
761 else
762 {
763 yytoken = yytranslate_ (yychar);
764 YY_SYMBOL_PRINT ("Next token is", yytoken, yylval, yylloc);
765 }
766
767 /* If the proper action on seeing token YYTOKEN is to reduce or to
768 detect an error, take that action. */
769 yyn += yytoken;
770 if (yyn < 0 || yylast_ < yyn || yycheck_[yyn] != yytoken)
771 goto yydefault;
772
773 /* Reduce or error. */
774 yyn = yytable_[yyn];
775 if (yyn <= 0)
776 {
777 if (yyn == 0 || yyn == yytable_ninf_)
778 goto yyerrlab;
779 yyn = -yyn;
780 goto yyreduce;
781 }
782
783 /* Shift the lookahead token. */
784 YY_SYMBOL_PRINT ("Shifting", yytoken, yylval, yylloc);
785
786 /* Discard the token being shifted. */
787 yychar = yyempty_;
788
789 /* Count tokens shifted since error; after three, turn off error
790 status. */
791 if (yyerrstatus_)
792 --yyerrstatus_;
793
794 yystate = yyn;
795 yypush_ (yystate, yylval, yylloc);
796 goto yynewstate;
797
798 /*-----------------------------------------------------------.
799 | yydefault -- do the default action for the current state. |
800 `-----------------------------------------------------------*/
801 yydefault:
802 yyn = yydefact_[yystate];
803 if (yyn == 0)
804 goto yyerrlab;
805 goto yyreduce;
806
807 /*-----------------------------.
808 | yyreduce -- Do a reduction. |
809 `-----------------------------*/
810 yyreduce:
811 yylen = yyr2_[yyn];]b4_variant_if([
812 /* Variants are always initialized to an empty instance of the
813 correct type. The default $$=$1 rule is NOT applied when using
814 variants */
815 ]b4_symbol_variant([[yyr1_@{yyn@}]], [yyval], [build])[],[
816 /* If YYLEN is nonzero, implement the default value of the action:
817 `$$ = $1'. Otherwise, use the top of the stack.
818
819 Otherwise, the following line sets YYVAL to garbage.
820 This behavior is undocumented and Bison
821 users should not rely upon it. */
822 if (yylen)
823 yyval = yysemantic_stack_@{yylen - 1@};
824 else
825 yyval = yysemantic_stack_@{0@};])[
826
827 {
828 slice<location_type, location_stack_type> slice (yylocation_stack_, yylen);
829 YYLLOC_DEFAULT (yyloc, slice, yylen);
830 }
831 YY_REDUCE_PRINT (yyn);
832 switch (yyn)
833 {
834 ]b4_user_actions[
835 default:
836 break;
837 }
838 YY_SYMBOL_PRINT ("-> $$ =", yyr1_[yyn], yyval, yyloc);
839
840 yypop_ (yylen);
841 yylen = 0;
842 YY_STACK_PRINT ();
843
844 /* Shift the result of the reduction. */
845 yyn = yyr1_[yyn];
846 yystate = yypgoto_[yyn - yyntokens_] + yystate_stack_[0];
847 if (0 <= yystate && yystate <= yylast_
848 && yycheck_[yystate] == yystate_stack_[0])
849 yystate = yytable_[yystate];
850 else
851 yystate = yydefgoto_[yyn - yyntokens_];
852 yypush_ (yystate, yyval, yyloc);
853 goto yynewstate;
854
855 /*------------------------------------.
856 | yyerrlab -- here on detecting error |
857 `------------------------------------*/
858 yyerrlab:
859 /* If not already recovering from an error, report this error. */
860 if (!yyerrstatus_)
861 {
862 ++yynerrs_;
863 error (yylloc, yysyntax_error_ (yystate]dnl
864 b4_error_verbose_if([, yytoken])[));
865 }
866
867 yyerror_range[0] = yylloc;
868 if (yyerrstatus_ == 3)
869 {
870 /* If just tried and failed to reuse lookahead token after an
871 error, discard it. */
872
873 if (yychar <= yyeof_)
874 {
875 /* Return failure if at end of input. */
876 if (yychar == yyeof_)
877 YYABORT;
878 }
879 else
880 {
881 yydestruct_ ("Error: discarding", yytoken, yylval, yylloc);
882 yychar = yyempty_;
883 }
884 }
885
886 /* Else will try to reuse lookahead token after shifting the error
887 token. */
888 goto yyerrlab1;
889
890
891 /*---------------------------------------------------.
892 | yyerrorlab -- error raised explicitly by YYERROR. |
893 `---------------------------------------------------*/
894 yyerrorlab:
895
896 /* Pacify compilers like GCC when the user code never invokes
897 YYERROR and the label yyerrorlab therefore never appears in user
898 code. */
899 if (false)
900 goto yyerrorlab;
901
902 yyerror_range[0] = yylocation_stack_[yylen - 1];
903 /* Do not reclaim the symbols of the rule which action triggered
904 this YYERROR. */
905 yypop_ (yylen);
906 yylen = 0;
907 yystate = yystate_stack_[0];
908 goto yyerrlab1;
909
910 /*-------------------------------------------------------------.
911 | yyerrlab1 -- common code for both syntax error and YYERROR. |
912 `-------------------------------------------------------------*/
913 yyerrlab1:
914 yyerrstatus_ = 3; /* Each real token shifted decrements this. */
915
916 for (;;)
917 {
918 yyn = yypact_[yystate];
919 if (yyn != yypact_ninf_)
920 {
921 yyn += yyterror_;
922 if (0 <= yyn && yyn <= yylast_ && yycheck_[yyn] == yyterror_)
923 {
924 yyn = yytable_[yyn];
925 if (0 < yyn)
926 break;
927 }
928 }
929
930 /* Pop the current state because it cannot handle the error token. */
931 if (yystate_stack_.size () == 1)
932 YYABORT;
933
934 yyerror_range[0] = yylocation_stack_[0];
935 yydestruct_ ("Error: popping",
936 yystos_[yystate],
937 yysemantic_stack_[0], yylocation_stack_[0]);
938 yypop_ ();
939 yystate = yystate_stack_[0];
940 YY_STACK_PRINT ();
941 }
942
943 yyerror_range[1] = yylloc;
944 // Using YYLLOC is tempting, but would change the location of
945 // the lookahead. YYLOC is available though.
946 YYLLOC_DEFAULT (yyloc, (yyerror_range - 1), 2);
947
948 /* Shift the error token. */
949 YY_SYMBOL_PRINT ("Shifting", yystos_[yyn],
950 yysemantic_stack_[0], yylocation_stack_[0]);
951
952 yystate = yyn;
953 yypush_ (yystate, yylval, yyloc);
954 goto yynewstate;
955
956 /* Accept. */
957 yyacceptlab:
958 yyresult = 0;
959 goto yyreturn;
960
961 /* Abort. */
962 yyabortlab:
963 yyresult = 1;
964 goto yyreturn;
965
966 yyreturn:
967 if (yychar != yyempty_)
968 yydestruct_ ("Cleanup: discarding lookahead", yytoken, yylval, yylloc);
969
970 /* Do not reclaim the symbols of the rule which action triggered
971 this YYABORT or YYACCEPT. */
972 yypop_ (yylen);
973 while (yystate_stack_.size () != 1)
974 {
975 yydestruct_ ("Cleanup: popping",
976 yystos_[yystate_stack_[0]],
977 yysemantic_stack_[0],
978 yylocation_stack_[0]);
979 yypop_ ();
980 }
981
982 return yyresult;
983 }
984
985 // Generate an error message.
986 std::string
987 ]b4_parser_class_name[::yysyntax_error_ (int yystate]dnl
988 b4_error_verbose_if([, int tok])[)
989 {
990 std::string res;
991 YYUSE (yystate);
992 #if YYERROR_VERBOSE
993 int yyn = yypact_[yystate];
994 if (yypact_ninf_ < yyn && yyn <= yylast_)
995 {
996 /* Start YYX at -YYN if negative to avoid negative indexes in
997 YYCHECK. */
998 int yyxbegin = yyn < 0 ? -yyn : 0;
999
1000 /* Stay within bounds of both yycheck and yytname. */
1001 int yychecklim = yylast_ - yyn + 1;
1002 int yyxend = yychecklim < yyntokens_ ? yychecklim : yyntokens_;
1003 int count = 0;
1004 for (int x = yyxbegin; x < yyxend; ++x)
1005 if (yycheck_[x + yyn] == x && x != yyterror_)
1006 ++count;
1007
1008 // FIXME: This method of building the message is not compatible
1009 // with internationalization. It should work like yacc.c does it.
1010 // That is, first build a string that looks like this:
1011 // "syntax error, unexpected %s or %s or %s"
1012 // Then, invoke YY_ on this string.
1013 // Finally, use the string as a format to output
1014 // yytname_[tok], etc.
1015 // Until this gets fixed, this message appears in English only.
1016 res = "syntax error, unexpected ";
1017 res += yytnamerr_ (yytname_[tok]);
1018 if (count < 5)
1019 {
1020 count = 0;
1021 for (int x = yyxbegin; x < yyxend; ++x)
1022 if (yycheck_[x + yyn] == x && x != yyterror_)
1023 {
1024 res += (!count++) ? ", expecting " : " or ";
1025 res += yytnamerr_ (yytname_[x]);
1026 }
1027 }
1028 }
1029 else
1030 #endif
1031 res = YY_("syntax error");
1032 return res;
1033 }
1034
1035
1036 /* YYPACT[STATE-NUM] -- Index in YYTABLE of the portion describing
1037 STATE-NUM. */
1038 const ]b4_int_type(b4_pact_ninf, b4_pact_ninf) b4_parser_class_name::yypact_ninf_ = b4_pact_ninf[;
1039 const ]b4_int_type_for([b4_pact])[
1040 ]b4_parser_class_name[::yypact_[] =
1041 {
1042 ]b4_pact[
1043 };
1044
1045 /* YYDEFACT[S] -- default rule to reduce with in state S when YYTABLE
1046 doesn't specify something else to do. Zero means the default is an
1047 error. */
1048 const ]b4_int_type_for([b4_defact])[
1049 ]b4_parser_class_name[::yydefact_[] =
1050 {
1051 ]b4_defact[
1052 };
1053
1054 /* YYPGOTO[NTERM-NUM]. */
1055 const ]b4_int_type_for([b4_pgoto])[
1056 ]b4_parser_class_name[::yypgoto_[] =
1057 {
1058 ]b4_pgoto[
1059 };
1060
1061 /* YYDEFGOTO[NTERM-NUM]. */
1062 const ]b4_int_type_for([b4_defgoto])[
1063 ]b4_parser_class_name[::yydefgoto_[] =
1064 {
1065 ]b4_defgoto[
1066 };
1067
1068 /* YYTABLE[YYPACT[STATE-NUM]]. What to do in state STATE-NUM. If
1069 positive, shift that token. If negative, reduce the rule which
1070 number is the opposite. If zero, do what YYDEFACT says. */
1071 const ]b4_int_type(b4_table_ninf, b4_table_ninf) b4_parser_class_name::yytable_ninf_ = b4_table_ninf[;
1072 const ]b4_int_type_for([b4_table])[
1073 ]b4_parser_class_name[::yytable_[] =
1074 {
1075 ]b4_table[
1076 };
1077
1078 /* YYCHECK. */
1079 const ]b4_int_type_for([b4_check])[
1080 ]b4_parser_class_name[::yycheck_[] =
1081 {
1082 ]b4_check[
1083 };
1084
1085 /* STOS_[STATE-NUM] -- The (internal number of the) accessing
1086 symbol of state STATE-NUM. */
1087 const ]b4_int_type_for([b4_stos])[
1088 ]b4_parser_class_name[::yystos_[] =
1089 {
1090 ]b4_stos[
1091 };
1092
1093 #if YYDEBUG
1094 /* TOKEN_NUMBER_[YYLEX-NUM] -- Internal symbol number corresponding
1095 to YYLEX-NUM. */
1096 const ]b4_int_type_for([b4_toknum])[
1097 ]b4_parser_class_name[::yytoken_number_[] =
1098 {
1099 ]b4_toknum[
1100 };
1101 #endif
1102
1103 /* YYR1[YYN] -- Symbol number of symbol that rule YYN derives. */
1104 const ]b4_int_type_for([b4_r1])[
1105 ]b4_parser_class_name[::yyr1_[] =
1106 {
1107 ]b4_r1[
1108 };
1109
1110 /* YYR2[YYN] -- Number of symbols composing right hand side of rule YYN. */
1111 const ]b4_int_type_for([b4_r2])[
1112 ]b4_parser_class_name[::yyr2_[] =
1113 {
1114 ]b4_r2[
1115 };
1116
1117 #if YYDEBUG || YYERROR_VERBOSE || YYTOKEN_TABLE
1118 /* YYTNAME[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM.
1119 First, the terminals, then, starting at \a yyntokens_, nonterminals. */
1120 const char*
1121 const ]b4_parser_class_name[::yytname_[] =
1122 {
1123 ]b4_tname[
1124 };
1125 #endif
1126
1127 #if YYDEBUG
1128 /* YYRHS -- A `-1'-separated list of the rules' RHS. */
1129 const ]b4_parser_class_name[::rhs_number_type
1130 ]b4_parser_class_name[::yyrhs_[] =
1131 {
1132 ]b4_rhs[
1133 };
1134
1135 /* YYPRHS[YYN] -- Index of the first RHS symbol of rule number YYN in
1136 YYRHS. */
1137 const ]b4_int_type_for([b4_prhs])[
1138 ]b4_parser_class_name[::yyprhs_[] =
1139 {
1140 ]b4_prhs[
1141 };
1142
1143 /* YYRLINE[YYN] -- Source line where rule number YYN was defined. */
1144 const ]b4_int_type_for([b4_rline])[
1145 ]b4_parser_class_name[::yyrline_[] =
1146 {
1147 ]b4_rline[
1148 };
1149
1150 // Print the state stack on the debug stream.
1151 void
1152 ]b4_parser_class_name[::yystack_print_ ()
1153 {
1154 *yycdebug_ << "Stack now";
1155 for (state_stack_type::const_iterator i = yystate_stack_.begin ();
1156 i != yystate_stack_.end (); ++i)
1157 *yycdebug_ << ' ' << *i;
1158 *yycdebug_ << std::endl;
1159 }
1160
1161 // Report on the debug stream that the rule \a yyrule is going to be reduced.
1162 void
1163 ]b4_parser_class_name[::yy_reduce_print_ (int yyrule)
1164 {
1165 unsigned int yylno = yyrline_[yyrule];
1166 int yynrhs = yyr2_[yyrule];
1167 /* Print the symbols being reduced, and their result. */
1168 *yycdebug_ << "Reducing stack by rule " << yyrule - 1
1169 << " (line " << yylno << "):" << std::endl;
1170 /* The symbols being reduced. */
1171 for (int yyi = 0; yyi < yynrhs; yyi++)
1172 YY_SYMBOL_PRINT (" $" << yyi + 1 << " =",
1173 yyrhs_[yyprhs_[yyrule] + yyi],
1174 ]b4_rhs_value(yynrhs, yyi + 1)[,
1175 ]b4_rhs_location(yynrhs, yyi + 1)[);
1176 }
1177 #endif // YYDEBUG
1178
1179 /* YYTRANSLATE(YYLEX) -- Bison symbol number corresponding to YYLEX. */
1180 ]b4_parser_class_name[::token_number_type
1181 ]b4_parser_class_name[::yytranslate_ (int t)
1182 {
1183 static
1184 const token_number_type
1185 translate_table[] =
1186 {
1187 ]b4_translate[
1188 };
1189 if ((unsigned int) t <= yyuser_token_number_max_)
1190 return translate_table[t];
1191 else
1192 return yyundef_token_;
1193 }
1194
1195 const int ]b4_parser_class_name[::yyeof_ = 0;
1196 const int ]b4_parser_class_name[::yylast_ = ]b4_last[;
1197 const int ]b4_parser_class_name[::yynnts_ = ]b4_nterms_number[;
1198 const int ]b4_parser_class_name[::yyempty_ = -2;
1199 const int ]b4_parser_class_name[::yyfinal_ = ]b4_final_state_number[;
1200 const int ]b4_parser_class_name[::yyterror_ = 1;
1201 const int ]b4_parser_class_name[::yyerrcode_ = 256;
1202 const int ]b4_parser_class_name[::yyntokens_ = ]b4_tokens_number[;
1203
1204 const unsigned int ]b4_parser_class_name[::yyuser_token_number_max_ = ]b4_user_token_number_max[;
1205 const ]b4_parser_class_name[::token_number_type ]b4_parser_class_name[::yyundef_token_ = ]b4_undef_token_number[;
1206
1207 ]b4_namespace_close[
1208
1209 ]b4_epilogue
1210 dnl
1211 @output(b4_dir_prefix[]stack.hh@)
1212 b4_copyright([Stack handling for Bison parsers in C++],
1213 [2002, 2003, 2004, 2005, 2006, 2007, 2008])[
1214
1215 #ifndef BISON_STACK_HH
1216 # define BISON_STACK_HH
1217
1218 #include <deque>
1219
1220 ]b4_namespace_open[
1221 template <class T, class S = std::deque<T> >
1222 class stack
1223 {
1224 public:
1225
1226 // Hide our reversed order.
1227 typedef typename S::reverse_iterator iterator;
1228 typedef typename S::const_reverse_iterator const_iterator;
1229
1230 stack () : seq_ ()
1231 {
1232 }
1233
1234 stack (unsigned int n) : seq_ (n)
1235 {
1236 }
1237
1238 inline
1239 T&
1240 operator [] (unsigned int i)
1241 {
1242 return seq_[i];
1243 }
1244
1245 inline
1246 const T&
1247 operator [] (unsigned int i) const
1248 {
1249 return seq_[i];
1250 }
1251
1252 inline
1253 void
1254 push (const T& t)
1255 {
1256 seq_.push_front (t);
1257 }
1258
1259 inline
1260 void
1261 pop (unsigned int n = 1)
1262 {
1263 for (; n; --n)
1264 seq_.pop_front ();
1265 }
1266
1267 inline
1268 typename S::size_type
1269 size () const
1270 {
1271 return seq_.size ();
1272 }
1273
1274 inline const_iterator begin () const { return seq_.rbegin (); }
1275 inline const_iterator end () const { return seq_.rend (); }
1276
1277 private:
1278 /// The wrapped container.
1279 S seq_;
1280 };
1281
1282 /// Present a slice of the top of a stack.
1283 template <class T, class S = stack<T> >
1284 class slice
1285 {
1286 public:
1287
1288 slice (const S& stack,
1289 unsigned int range) : stack_ (stack),
1290 range_ (range)
1291 {
1292 }
1293
1294 inline
1295 const T&
1296 operator [] (unsigned int i) const
1297 {
1298 return stack_[range_ - i];
1299 }
1300
1301 private:
1302
1303 const S& stack_;
1304 unsigned int range_;
1305 };
1306 ]b4_namespace_close[
1307
1308 #endif // not BISON_STACK_HH[]dnl
1309 ]
1310 m4_divert_pop(0)