]> git.saurik.com Git - bison.git/blob - data/lalr1.cc
Avoid capturing variables too easily.
[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
22 # b4_integral_parser_table_declare(TABLE-NAME, CONTENT, COMMENT)
23 # --------------------------------------------------------------
24 # Declare "parser::yy<TABLE-NAME>_" which contents is CONTENT.
25 m4_define([b4_integral_parser_table_declare],
26 [m4_ifval([$3], [b4_c_comment([$3], [ ])
27 ])dnl
28 static const b4_int_type_for([$2]) yy$1_[[]];dnl
29 ])
30
31 # b4_integral_parser_table_define(TABLE-NAME, CONTENT, COMMENT)
32 # ---------------------------------------------
33 # Define "parser::yy<TABLE-NAME>_" which contents is CONTENT.
34 m4_define([b4_integral_parser_table_define],
35 [ const b4_int_type_for([$2])
36 b4_parser_class_name::yy$1_[[]] =
37 {
38 $2
39 };dnl
40 ])
41
42
43 # b4_symbol_value_template(VAL, [TYPE])
44 # -------------------------------------
45 # Same as b4_symbol_value, but used in a template method.
46 m4_copy([b4_symbol_value], [b4_symbol_value_template])
47
48 # How the semantic value is extracted when using variants.
49 b4_variant_if([
50 # b4_symbol_value(VAL, [TYPE])
51 # ----------------------------
52 m4_define([b4_symbol_value],
53 [m4_ifval([$2],
54 [$1.as< $2 >()],
55 [$1])])
56
57 # b4_symbol_value_template(VAL, [TYPE])
58 # -------------------------------------
59 # Same as b4_symbol_value, but used in a template method.
60 m4_define([b4_symbol_value_template],
61 [m4_ifval([$2],
62 [$1.template as< $2 >()],
63 [$1])])
64 ]) # b4_variant_if
65
66
67 # b4_lex_symbol_if([IF-YYLEX-RETURNS-A-COMPLETE-SYMBOL], [IF-NOT])
68 # ----------------------------------------------------------------
69 m4_define([b4_lex_symbol_if],
70 [b4_percent_define_ifdef([[lex_symbol]], [$1], [$2])])
71
72
73 # b4_assert_if([IF-ASSERTIONS-ARE-USED], [IF-NOT])
74 # ------------------------------------------------
75 m4_define([b4_assert_if],
76 [b4_percent_define_ifdef([[assert]], [$1], [$2])])
77
78
79 # b4_lhs_value([TYPE])
80 # --------------------
81 # Expansion of $<TYPE>$.
82 m4_define([b4_lhs_value],
83 [b4_symbol_value([yylhs.value], [$1])])
84
85
86 # b4_lhs_location()
87 # -----------------
88 # Expansion of @$.
89 m4_define([b4_lhs_location],
90 [yylhs.location])
91
92
93 # b4_rhs_data(RULE-LENGTH, NUM)
94 # -----------------------------
95 # Return the data corresponding to the symbol #NUM, where the current
96 # rule has RULE-LENGTH symbols on RHS.
97 m4_define([b4_rhs_data],
98 [yystack_@{b4_subtract($@)@}])
99
100
101 # b4_rhs_state(RULE-LENGTH, NUM)
102 # -----------------------------
103 # The state corresponding to the symbol #NUM, where the current
104 # rule has RULE-LENGTH symbols on RHS.
105 m4_define([b4_rhs_state],
106 [b4_rhs_data([$1], [$2]).state])
107
108
109 # b4_rhs_value(RULE-LENGTH, NUM, [TYPE])
110 # --------------------------------------
111 # Expansion of $<TYPE>NUM, where the current rule has RULE-LENGTH
112 # symbols on RHS.
113 m4_define([b4_rhs_value],
114 [b4_symbol_value([b4_rhs_data([$1], [$2]).value], [$3])])
115
116
117 # b4_rhs_location(RULE-LENGTH, NUM)
118 # ---------------------------------
119 # Expansion of @NUM, where the current rule has RULE-LENGTH symbols
120 # on RHS.
121 m4_define([b4_rhs_location],
122 [b4_rhs_data([$1], [$2]).location])
123
124
125 # b4_symbol_(NUM, FIELD)
126 # ----------------------
127 # Recover a FIELD about symbol #NUM. Thanks to m4_indir, fails if
128 # undefined.
129 m4_define([b4_symbol_],
130 [m4_indir([b4_symbol($1, $2)])])
131
132
133 # b4_symbol(NUM, FIELD)
134 # ---------------------
135 # Recover a FIELD about symbol #NUM. Thanks to m4_indir, fails if
136 # undefined. If FIELD = id, prepend the prefix.
137 m4_define([b4_symbol],
138 [m4_case([$2],
139 [id], [m4_do([b4_percent_define_get([token.prefix])],
140 [b4_symbol_([$1], [id])])],
141 [b4_symbol_($@)])])
142
143
144 # b4_symbol_if(NUM, FIELD, IF-TRUE, IF-FALSE)
145 # -------------------------------------------
146 # If FIELD about symbol #NUM is 1 expand IF-TRUE, if is 0, expand IF-FALSE.
147 # Otherwise an error.
148 m4_define([b4_symbol_if],
149 [m4_case(b4_symbol([$1], [$2]),
150 [1], [$3],
151 [0], [$4],
152 [m4_fatal([$0: field $2 of $1 is not a Boolean:] b4_symbol([$1], [$2]))])])
153
154
155 # b4_symbol_actions(FILENAME, LINENO,
156 # SYMBOL-TAG, SYMBOL-NUM,
157 # SYMBOL-ACTION, SYMBOL-TYPENAME)
158 # -------------------------------------------------
159 # Same as in C, but using references instead of pointers.
160 m4_define([b4_symbol_actions],
161 [m4_pushdef([b4_dollar_dollar],
162 [b4_symbol_value_template([yysym.value], [$6])])dnl
163 m4_pushdef([b4_at_dollar], [yysym.location])dnl
164 case $4: // $3
165 b4_syncline([$2], [$1])
166 $5;
167 b4_syncline([@oline@], [@ofile@])
168 break;
169 m4_popdef([b4_at_dollar])dnl
170 m4_popdef([b4_dollar_dollar])dnl
171 ])
172
173
174 # b4_symbol_case_(SYMBOL-NUM)
175 # ---------------------------
176 # Issue a "case NUM" for SYMBOL-NUM.
177 m4_define([b4_symbol_case_],
178 [ case b4_symbol([$1], [number]): // b4_symbol([$1], [tag])
179 ])
180
181
182 # b4_type_action_(NUMS)
183 # ---------------------
184 # Run actions for the symbol NUMS that all have the same type-name.
185 # Skip NUMS that have no type-name.
186 m4_define([b4_type_action_],
187 [b4_symbol_if([$1], [has_type],
188 [m4_map([b4_symbol_case_], [$@])[]dnl
189 b4_dollar_dollar([b4_symbol([$1], [number])],
190 [b4_symbol([$1], [tag])],
191 [b4_symbol([$1], [type])]);
192 break;
193
194 ])])
195
196
197 # b4_symbol_constructor_declaration_(SYMBOL-NUMBER)
198 # -------------------------------------------------
199 # Declare the overloaded version of make_symbol for the (common) type of
200 # these SYMBOL-NUMBERS. Use at class-level.
201 m4_define([b4_symbol_constructor_declaration_],
202 [b4_symbol_if([$1], [is_token], [b4_symbol_if([$1], [has_id],
203 [ static inline
204 symbol_type
205 make_[]b4_symbol_([$1], [id]) (dnl
206 b4_args(b4_symbol_if([$1], [has_type],
207 [const b4_symbol([$1], [type])& v]),
208 b4_locations_if([const location_type& l])));
209
210 ])])])
211
212
213 # b4_symbol_constructor_declarations
214 # ----------------------------------
215 # Declare symbol constructors for all the value types.
216 # Use at class-level.
217 m4_define([b4_symbol_constructor_declarations],
218 [b4_variant_if([
219 // Symbol constructors declarations.
220 m4_map([b4_symbol_constructor_declaration_], m4_defn([b4_symbol_numbers]))])])
221
222
223
224 # b4_symbol_constructor_definition_(SYMBOL-NUMBER)
225 # ------------------------------------------------
226 # Define symbol constructor for this SYMBOL-NUMBER.
227 m4_define([b4_symbol_constructor_definition_],
228 [b4_symbol_if([$1], [is_token], [b4_symbol_if([$1], [has_id],
229 [ b4_parser_class_name::symbol_type
230 b4_parser_class_name::make_[]b4_symbol_([$1], [id]) (dnl
231 b4_args(b4_symbol_if([$1], [has_type],
232 [const b4_symbol([$1], [type])& v]),
233 b4_locations_if([const location_type& l])))
234 {
235 return symbol_type (b4_args([yytranslate_ (token::b4_symbol([$1], [id]))],
236 b4_symbol_if([$1], [has_type], [v]),
237 b4_locations_if([l])));
238 }
239
240 ])])])
241
242
243 # b4_symbol_constructor_definitions
244 # ----------------------------------
245 # Define the overloaded versions of make_symbol for all the value types.
246 m4_define([b4_symbol_constructor_definitions],
247 [[ // symbol_base_type.
248 template <typename Exact>
249 ]b4_parser_class_name[::symbol_base_type<Exact>::symbol_base_type ()
250 : value()]b4_locations_if([
251 , location()])[
252 {
253 }]b4_locations_if([[
254
255 template <typename Exact>
256 ]b4_parser_class_name[::symbol_base_type<Exact>::symbol_base_type (const location_type& l)
257 : value()
258 , location(l)
259 {
260 }]])[
261
262 template <typename Exact>
263 ]b4_parser_class_name[::symbol_base_type<Exact>::symbol_base_type (]b4_args(
264 [const semantic_type& v],
265 b4_locations_if([const location_type& l]))[)
266 : value(v)]b4_locations_if([
267 , location(l)])[
268 {
269 }
270
271 template <typename Exact>
272 const Exact&
273 ]b4_parser_class_name[::symbol_base_type<Exact>::self () const
274 {
275 return static_cast<const Exact&>(*this);
276 }
277
278 template <typename Exact>
279 Exact&
280 ]b4_parser_class_name[::symbol_base_type<Exact>::self ()
281 {
282 return static_cast<Exact&>(*this);
283 }
284
285 template <typename Exact>
286 int
287 ]b4_parser_class_name[::symbol_base_type<Exact>::type_get () const
288 {
289 return self ().type_get_ ();
290 }
291
292 // symbol_type.
293 ]b4_parser_class_name[::symbol_type::symbol_type ()
294 : super_type ()
295 , type ()
296 {
297 }
298
299 ]b4_parser_class_name[::symbol_type::symbol_type (]b4_args(
300 [int t],
301 b4_locations_if([const location_type& l]))[)
302 : super_type (]b4_locations_if([l])[)
303 , type (t)
304 {
305 }
306
307 ]b4_parser_class_name[::symbol_type::symbol_type (]b4_args(
308 [int t],
309 [const semantic_type& v],
310 b4_locations_if([const location_type& l]))[)
311 : super_type (v]b4_locations_if([, l])[)
312 , type (t)
313 {
314 }
315
316 int
317 ]b4_parser_class_name[::symbol_type::type_get_ () const
318 {
319 return type;
320 }
321 ]b4_lex_symbol_if([[
322 ]b4_parser_class_name[::token_type
323 ]b4_parser_class_name[::symbol_type::token () const
324 {
325 // YYTOKNUM[NUM] -- (External) token number corresponding to the
326 // (internal) symbol number NUM (which must be that of a token). */
327 static
328 const ]b4_int_type_for([b4_toknum])[
329 yytoken_number_[] =
330 {
331 ]b4_toknum[
332 };
333 return static_cast<token_type> (yytoken_number_[type]);
334 }
335 ]])[
336
337 ]b4_variant_if(
338 [ // Implementation of make_symbol for each symbol type.
339 m4_map([b4_symbol_constructor_definition_], m4_defn([b4_symbol_numbers]))])])
340
341
342 # b4_symbol_variant(YYTYPE, YYVAL, ACTION, [ARGS])
343 # ------------------------------------------------
344 # Run some ACTION ("build", or "destroy") on YYVAL of symbol type
345 # YYTYPE.
346 m4_define([b4_symbol_variant],
347 [m4_pushdef([b4_dollar_dollar],
348 [$2.$3< $][3 >(m4_shift3($@))])dnl
349 switch ($1)
350 {
351 m4_map([b4_type_action_], m4_defn([b4_type_names]))[]dnl
352 default:
353 break;
354 }
355 m4_popdef([b4_dollar_dollar])dnl
356 ])
357
358
359 # _b4_char_sizeof_counter
360 # -----------------------
361 # A counter used by _b4_char_sizeof_dummy to create fresh symbols.
362 m4_define([_b4_char_sizeof_counter],
363 [0])
364
365 # _b4_char_sizeof_dummy
366 # ---------------------
367 # At each call return a new C++ identifier.
368 m4_define([_b4_char_sizeof_dummy],
369 [m4_define([_b4_char_sizeof_counter], m4_incr(_b4_char_sizeof_counter))dnl
370 dummy[]_b4_char_sizeof_counter])
371
372
373 # b4_char_sizeof_(SYMBOL-NUM)
374 # ---------------------------
375 # A comment describing this symbol.
376 m4_define([b4_char_sizeof_],
377 [ // b4_symbol([$1], [tag])
378 ])
379
380 # b4_char_sizeof(SYMBOL-NUMS)
381 # --------------------------
382 # To be mapped on the list of type names to produce:
383 #
384 # char dummy1[sizeof(type_name_1)];
385 # char dummy2[sizeof(type_name_2)];
386 #
387 # for defined type names.
388 m4_define([b4_char_sizeof],
389 [b4_symbol_if([$1], [has_type],
390 [
391 m4_map([b4_char_sizeof_], [$@])dnl
392 char _b4_char_sizeof_dummy@{sizeof([b4_symbol([$1], [type])])@};
393 ])])
394
395
396 # b4_yytranslate_definition
397 # -------------------------
398 # Define yytranslate_. Sometimes we want it in the header file,
399 # sometimes the cc file suffices.
400 m4_define([b4_yytranslate_definition],
401 [[ // Symbol number corresponding to token number t.
402 ]b4_parser_class_name[::token_number_type
403 ]b4_parser_class_name[::yytranslate_ (]b4_lex_symbol_if([token_type],
404 [int])[ t)
405 {
406 static
407 const token_number_type
408 translate_table[] =
409 {
410 ]b4_translate[
411 };
412 const unsigned int user_token_number_max_ = ]b4_user_token_number_max[;
413 const token_number_type undef_token_ = ]b4_undef_token_number[;
414
415 if (static_cast<int>(t) <= yyeof_)
416 return yyeof_;
417 else if (static_cast<unsigned int> (t) <= user_token_number_max_)
418 return translate_table[t];
419 else
420 return undef_token_;
421 }
422 ]])
423
424
425 m4_pushdef([b4_copyright_years],
426 [2002, 2003, 2004, 2005, 2006, 2007, 2008])
427
428 m4_define([b4_parser_class_name],
429 [b4_percent_define_get([[parser_class_name]])])
430
431 # The header is mandatory.
432 b4_defines_if([],
433 [b4_fatal([b4_skeleton[: using %%defines is mandatory]])])
434
435 b4_locations_if(
436 [# Backward compatibility.
437 m4_define([b4_location_constructors])
438 m4_include(b4_pkgdatadir/[location.cc])])
439
440 # We do want M4 expansion after # for CPP macros.
441 m4_changecom()
442 m4_divert_push(0)dnl
443 @output(b4_spec_defines_file@)@
444 b4_copyright([Skeleton interface for Bison LALR(1) parsers in C++])
445 dnl FIXME: This is wrong, we want computed header guards.
446 [
447 /* C++ LALR(1) parser skeleton written by Akim Demaille. */
448
449 #ifndef PARSER_HEADER_H
450 # define PARSER_HEADER_H
451
452 ]b4_percent_code_get([[requires]])[
453
454 ]b4_assert_if([#include <cassert>])[
455 #include <string>
456 #include <iostream>
457 #include "stack.hh"
458
459 ]b4_namespace_open[
460 ]b4_locations_if([ class position;
461 class location;])[
462 ]b4_variant_if(
463 [[
464 /// A char[S] buffer to store and retrieve objects.
465 ///
466 /// Sort of a variant, but does not keep track of the nature
467 /// of the stored data, since that knowledge is available
468 /// via the current state.
469 template <size_t S>
470 struct variant
471 {]b4_assert_if([
472 /// Whether something is contained.
473 bool built;
474 ])[
475 /// Empty construction.
476 inline
477 variant ()]b4_assert_if([
478 : built(false)])[
479 {}
480
481 /// Instantiate a \a T in here.
482 template <typename T>
483 inline T&
484 build()
485 {]b4_assert_if([
486 assert(!built);
487 built = true;])[
488 return *new (buffer) T;
489 }
490
491 /// Instantiate a \a T in here from \a t.
492 template <typename T>
493 inline T&
494 build(const T& t)
495 {]b4_assert_if([
496 assert(!built);
497 built = true;])[
498 return *new (buffer) T(t);
499 }
500
501 /// Construct and fill.
502 template <typename T>
503 inline
504 variant (const T& t)]b4_assert_if([
505 : built(true)])[
506 {
507 new (buffer) T(t);
508 }
509
510 /// Accessor to a built \a T.
511 template <typename T>
512 inline T&
513 as()
514 {]b4_assert_if([
515 assert(built);])[
516 return reinterpret_cast<T&>(buffer);
517 }
518
519 /// Const accessor to a built \a T (for %printer).
520 template <typename T>
521 inline const T&
522 as() const
523 {]b4_assert_if([
524 assert(built);])[
525 return reinterpret_cast<const T&>(buffer);
526 }
527
528 /// Swap the content with \a other.
529 template <typename T>
530 inline void
531 swap(variant<S>& other)
532 {
533 std::swap(as<T>(), other.as<T>());
534 }
535
536 /// Assign the content of \a other to this.
537 /// Destroys \a other.
538 template <typename T>
539 inline void
540 build(variant<S>& other)
541 {
542 build<T>();
543 swap<T>(other);
544 other.destroy<T>();
545 }
546
547 /// Destroy the stored \a T.
548 template <typename T>
549 inline void
550 destroy()
551 {
552 as<T>().~T();]b4_assert_if([
553 built = false;])[
554 }
555
556 /// A buffer large enough to store any of the semantic values.
557 char buffer[S];
558 };
559 ]])[
560 ]b4_namespace_close[
561
562 ]b4_locations_if([#include "location.hh"])[
563
564 /* Enabling traces. */
565 #ifndef YYDEBUG
566 # define YYDEBUG ]b4_debug_flag[
567 #endif
568
569 /* Enabling verbose error messages. */
570 #ifdef YYERROR_VERBOSE
571 # undef YYERROR_VERBOSE
572 # define YYERROR_VERBOSE 1
573 #else
574 # define YYERROR_VERBOSE ]b4_error_verbose_flag[
575 #endif
576
577 /* Enabling the token table. */
578 #ifndef YYTOKEN_TABLE
579 # define YYTOKEN_TABLE ]b4_token_table[
580 #endif
581
582 ]b4_locations_if([dnl
583 [/* YYLLOC_DEFAULT -- Set CURRENT to span from RHS[1] to RHS[N].
584 If N is 0, then set CURRENT to the empty location which ends
585 the previous symbol: RHS[0] (always defined). */
586
587 #ifndef YYLLOC_DEFAULT
588 # define YYLLOC_DEFAULT(Current, Rhs, N) \
589 do { \
590 if (N) \
591 { \
592 (Current).begin = (Rhs)[1].location.begin; \
593 (Current).end = (Rhs)[N].location.end; \
594 } \
595 else \
596 { \
597 (Current).begin = (Current).end = (Rhs)[0].location.end; \
598 } \
599 } while (false)
600 #endif]])[
601
602 ]b4_namespace_open[
603
604 /// A Bison parser.
605 class ]b4_parser_class_name[
606 {
607 public:
608 #ifndef YYSTYPE
609 ]b4_variant_if(
610 [ /// An auxiliary type to compute the largest semantic type.
611 union union_type
612 {]m4_map([b4_char_sizeof], m4_defn([b4_type_names]))[};
613
614 /// Symbol semantic values.
615 typedef variant<sizeof(union_type)> semantic_type;],
616 [ /// Symbol semantic values.
617 m4_ifdef([b4_stype],
618 [ union semantic_type
619 {b4_user_stype
620 };],
621 [m4_if(b4_tag_seen_flag, 0,
622 [[ typedef int semantic_type;]],
623 [[ typedef YYSTYPE semantic_type;]])])])[
624 #else
625 typedef YYSTYPE semantic_type;
626 #endif]b4_locations_if([
627 /// Symbol locations.
628 typedef b4_percent_define_get([[location_type]]) location_type;])[
629 /// Tokens.
630 struct token
631 {
632 ]b4_token_enums(b4_tokens)[
633 };
634 /// Token type.
635 typedef token::yytokentype token_type;
636
637 /// Build a parser object.
638 ]b4_parser_class_name[ (]b4_parse_param_decl[);
639 virtual ~]b4_parser_class_name[ ();
640
641 /// Parse.
642 /// \returns 0 iff parsing succeeded.
643 virtual int parse ();
644
645 #if YYDEBUG
646 /// The current debugging stream.
647 std::ostream& debug_stream () const;
648 /// Set the current debugging stream.
649 void set_debug_stream (std::ostream &);
650
651 /// Type for debugging levels.
652 typedef int debug_level_type;
653 /// The current debugging level.
654 debug_level_type debug_level () const;
655 /// Set the current debugging level.
656 void set_debug_level (debug_level_type l);
657 #endif
658
659 private:
660 /// Report a syntax error.]b4_locations_if([
661 /// \param loc where the syntax error is found.])[
662 /// \param msg a description of the syntax error.
663 virtual void error (]b4_locations_if([const location_type& loc, ])[const std::string& msg);
664
665 /// Generate an error message.
666 /// \param state the state where the error occurred.
667 /// \param tok the lookahead token.
668 virtual std::string yysyntax_error_ (int yystate, int tok);
669
670 /// State numbers.
671 typedef int state_type;
672
673 /// Internal symbol numbers.
674 typedef ]b4_int_type_for([b4_translate])[ token_number_type;
675 static const ]b4_int_type(b4_pact_ninf, b4_pact_ninf)[ yypact_ninf_;
676 static const ]b4_int_type(b4_table_ninf, b4_table_ninf)[ yytable_ninf_;
677
678 /* Tables. */
679 ]b4_parser_tables_declare[
680
681 #if YYDEBUG || YYERROR_VERBOSE || YYTOKEN_TABLE
682 /// For a symbol, its name in clear.
683 static const char* const yytname_[];
684 #endif]b4_error_verbose_if([
685
686 /// Convert the symbol name \a n to a form suitable for a diagnostic.
687 static std::string yytnamerr_ (const char *n);])[
688
689 #if YYDEBUG
690 ]b4_integral_parser_table_declare([rline], [b4_rline],
691 [YYRLINE[YYN] -- Source line where rule number YYN was defined.])[
692 /// Report on the debug stream that the rule \a r is going to be reduced.
693 virtual void yy_reduce_print_ (int r);
694 /// Print the state stack on the debug stream.
695 virtual void yystack_print_ ();
696
697 /* Debugging. */
698 int yydebug_;
699 std::ostream* yycdebug_;
700 #endif
701
702 /// Convert a scanner token number \a t to a symbol number.
703 static inline token_number_type yytranslate_ (]b4_lex_symbol_if([token_type], [int])[ t);
704
705 /// A complete symbol, with its type.
706 template <typename Exact>
707 struct symbol_base_type
708 {
709 /// Default constructor.
710 inline symbol_base_type ();
711
712 /// Constructor.]b4_locations_if([
713 inline symbol_base_type (const location_type& l)])[;
714 inline symbol_base_type (]b4_args(
715 [const semantic_type& v],
716 b4_locations_if([const location_type& l]))[);
717
718 /// Return this with its exact type.
719 const Exact& self () const;
720 Exact& self ();
721
722 /// Return the type of this symbol.
723 int type_get () const;
724
725 /// The semantic value.
726 semantic_type value;]b4_locations_if([
727
728 /// The location.
729 location_type location;])[
730 };
731
732 #if YYDEBUG
733 /// \brief Display a symbol type, value and location.
734 /// \param yyo The output stream.
735 /// \param yysym The symbol.
736 template <typename Exact>
737 void yy_print_ (std::ostream& yyo,
738 const symbol_base_type<Exact>& yysym) const;
739 #endif
740
741 /// \brief Reclaim the memory associated to a symbol.
742 /// \param yymsg Why this token is reclaimed.
743 /// If null, print nothing.
744 /// \param s The symbol.
745 template <typename Exact>
746 inline void yy_destroy_ (const char* yymsg,
747 symbol_base_type<Exact>& yysym) const;
748
749 public:
750 /// Element of the stack: a state and its attributes.
751 struct symbol_type : symbol_base_type<symbol_type>
752 {
753 /// The parent class.
754 typedef symbol_base_type<symbol_type> super_type;
755
756 /// Default constructor.
757 inline symbol_type ();
758
759 /// Constructor.
760 inline symbol_type (]b4_args([int t],
761 [const semantic_type& v],
762 b4_locations_if([const location_type& l]))[);
763
764 inline symbol_type (]b4_args([int t],
765 b4_locations_if([const location_type& l]))[);
766
767 /// The symbol type.
768 int type;
769
770 /// Return the type corresponding to this state.
771 inline int type_get_ () const;
772
773 /// Its token.
774 inline token_type token () const;
775 };
776
777 ]b4_symbol_constructor_declarations[
778
779 private:
780 /// Element of the stack: a state and its attributes.
781 struct stack_symbol_type : symbol_base_type<stack_symbol_type>
782 {
783 /// The parent class.
784 typedef symbol_base_type<stack_symbol_type> super_type;
785
786 /// Default constructor.
787 inline stack_symbol_type ();
788
789 /// Constructor.
790 inline stack_symbol_type (]b4_args([state_type s],
791 [const semantic_type& v],
792 b4_locations_if([const location_type& l]))[);
793
794 /// The state.
795 state_type state;
796
797 /// Return the type corresponding to this state.
798 inline int type_get_ () const;
799 };
800
801 /// Stack type.
802 typedef stack<stack_symbol_type> stack_type;
803
804 /// The stack.
805 stack_type yystack_;
806
807 /// Push a new state on the stack.
808 /// \param m a debug message to display
809 /// if null, no trace is output.
810 /// \param s the symbol
811 /// \warning the contents of \a s.value is stolen.
812 inline void yypush_ (const char* m, stack_symbol_type& s);
813
814 /// Push a new look ahead token on the state on the stack.
815 /// \param m a debug message to display
816 /// if null, no trace is output.
817 /// \param s the state
818 /// \param sym the symbol (for its value and location).
819 /// \warning the contents of \a s.value is stolen.
820 inline void yypush_ (const char* m, state_type s, symbol_type& sym);
821
822 /// Pop \a n symbols the three stacks.
823 inline void yypop_ (unsigned int n = 1);
824
825 /* Constants. */
826 enum
827 {
828 yyeof_ = 0,
829 yylast_ = ]b4_last[, //< Last index in yytable_.
830 yynnts_ = ]b4_nterms_number[, //< Number of nonterminal symbols.
831 yyempty_ = -2,
832 yyfinal_ = ]b4_final_state_number[, //< Termination state number.
833 yyterror_ = 1,
834 yyerrcode_ = 256,
835 yyntokens_ = ]b4_tokens_number[, //< Number of tokens.
836 };
837
838 ]b4_parse_param_vars[
839 };
840
841 ]b4_lex_symbol_if([b4_yytranslate_definition])[
842 ]b4_lex_symbol_if([b4_symbol_constructor_definitions])[
843 ]b4_namespace_close[
844
845 ]b4_percent_define_flag_if([[global_tokens_and_yystype]],
846 [b4_token_defines(b4_tokens)
847
848 #ifndef YYSTYPE
849 /* Redirection for backward compatibility. */
850 # define YYSTYPE b4_namespace_ref::b4_parser_class_name::semantic_type
851 #endif
852 ])
853 b4_percent_code_get([[provides]])[]dnl
854
855 [#endif /* ! defined PARSER_HEADER_H */]
856 @output(b4_parser_file_name@)@
857 b4_copyright([Skeleton implementation for Bison LALR(1) parsers in C++])
858 b4_percent_code_get([[top]])[]dnl
859 m4_if(b4_prefix, [yy], [],
860 [
861 // Take the name prefix into account.
862 #define yylex b4_prefix[]lex])[
863
864 /* First part of user declarations. */
865 ]b4_user_pre_prologue[
866
867 #include "@basename(]b4_spec_defines_file[@)"
868
869 /* User implementation prologue. */
870 ]b4_user_post_prologue
871 b4_percent_code_get[]dnl
872
873 [#ifndef YY_
874 # if YYENABLE_NLS
875 # if ENABLE_NLS
876 # include <libintl.h> /* FIXME: INFRINGES ON USER NAME SPACE */
877 # define YY_(msgid) dgettext ("bison-runtime", msgid)
878 # endif
879 # endif
880 # ifndef YY_
881 # define YY_(msgid) msgid
882 # endif
883 #endif
884
885 /* Suppress unused-variable warnings by "using" E. */
886 #define YYUSE(e) ((void) (e))
887
888 /* Enable debugging if requested. */
889 #if YYDEBUG
890
891 /* A pseudo ostream that takes yydebug_ into account. */
892 # define YYCDEBUG if (yydebug_) (*yycdebug_)
893
894 # define YY_SYMBOL_PRINT(Title, Symbol) \
895 do { \
896 if (yydebug_) \
897 { \
898 *yycdebug_ << Title << ' '; \
899 yy_print_ (*yycdebug_, Symbol); \
900 *yycdebug_ << std::endl; \
901 } \
902 } while (false)
903
904 # define YY_REDUCE_PRINT(Rule) \
905 do { \
906 if (yydebug_) \
907 yy_reduce_print_ (Rule); \
908 } while (false)
909
910 # define YY_STACK_PRINT() \
911 do { \
912 if (yydebug_) \
913 yystack_print_ (); \
914 } while (false)
915
916 #else /* !YYDEBUG */
917
918 # define YYCDEBUG if (false) std::cerr
919 # define YY_SYMBOL_PRINT(Title, Symbol) static_cast<void>(0)
920 # define YY_REDUCE_PRINT(Rule) static_cast<void>(0)
921 # define YY_STACK_PRINT() static_cast<void>(0)
922
923 #endif /* !YYDEBUG */
924
925 #define yyerrok (yyerrstatus_ = 0)
926 #define yyclearin (yyempty = true)
927
928 #define YYACCEPT goto yyacceptlab
929 #define YYABORT goto yyabortlab
930 #define YYERROR goto yyerrorlab
931 #define YYRECOVERING() (!!yyerrstatus_)
932
933 ]b4_namespace_open[]b4_error_verbose_if([[
934
935 /* Return YYSTR after stripping away unnecessary quotes and
936 backslashes, so that it's suitable for yyerror. The heuristic is
937 that double-quoting is unnecessary unless the string contains an
938 apostrophe, a comma, or backslash (other than backslash-backslash).
939 YYSTR is taken from yytname. */
940 std::string
941 ]b4_parser_class_name[::yytnamerr_ (const char *yystr)
942 {
943 if (*yystr == '"')
944 {
945 std::string yyr = "";
946 char const *yyp = yystr;
947
948 for (;;)
949 switch (*++yyp)
950 {
951 case '\'':
952 case ',':
953 goto do_not_strip_quotes;
954
955 case '\\':
956 if (*++yyp != '\\')
957 goto do_not_strip_quotes;
958 /* Fall through. */
959 default:
960 yyr += *yyp;
961 break;
962
963 case '"':
964 return yyr;
965 }
966 do_not_strip_quotes: ;
967 }
968
969 return yystr;
970 }
971 ]])[
972
973 /// Build a parser object.
974 ]b4_parser_class_name::b4_parser_class_name[ (]b4_parse_param_decl[)]m4_ifset([b4_parse_param], [
975 :])[
976 #if YYDEBUG
977 ]m4_ifset([b4_parse_param], [ ], [ :])[yydebug_ (false),
978 yycdebug_ (&std::cerr)]m4_ifset([b4_parse_param], [,])[
979 #endif]b4_parse_param_cons[
980 {
981 }
982
983 ]b4_parser_class_name::~b4_parser_class_name[ ()
984 {
985 }
986
987
988 /*---------------.
989 | Symbol types. |
990 `---------------*/
991
992 ]b4_lex_symbol_if([], [b4_symbol_constructor_definitions])[
993
994 // stack_symbol_type.
995 ]b4_parser_class_name[::stack_symbol_type::stack_symbol_type ()
996 : super_type ()
997 , state ()
998 {
999 }
1000
1001 ]b4_parser_class_name[::stack_symbol_type::stack_symbol_type (]b4_args(
1002 [state_type s],
1003 [const semantic_type& v],
1004 b4_locations_if([const location_type& l]))[)
1005 : super_type (v]b4_locations_if([, l])[)
1006 , state (s)
1007 {
1008 }
1009
1010 int
1011 ]b4_parser_class_name[::stack_symbol_type::type_get_ () const
1012 {
1013 return yystos_[state];
1014 }
1015
1016
1017 template <typename Exact>
1018 void
1019 ]b4_parser_class_name[::yy_destroy_ (const char* yymsg,
1020 symbol_base_type<Exact>& yysym) const
1021 {
1022 int yytype = yysym.type_get ();
1023 YYUSE (yymsg);
1024 if (yymsg)
1025 YY_SYMBOL_PRINT (yymsg, yysym);
1026
1027 // User destructor.
1028 switch (yytype)
1029 {
1030 ]m4_map([b4_symbol_actions], m4_defn([b4_symbol_destructors]))[
1031 default:
1032 break;
1033 }]b4_variant_if([
1034
1035 // Type destructor.
1036 b4_symbol_variant([[yytype]], [[yysym.value]], [[template destroy]])])[
1037 }
1038
1039 #if YYDEBUG
1040 template <typename Exact>
1041 void
1042 ]b4_parser_class_name[::yy_print_ (std::ostream& yyo,
1043 const symbol_base_type<Exact>& yysym) const
1044 {
1045 int yytype = yysym.type_get ();
1046 yyo << (yytype < yyntokens_ ? "token" : "nterm")
1047 << ' ' << yytname_[yytype] << " ("]b4_locations_if([
1048 << yysym.location << ": "])[;
1049 switch (yytype)
1050 {
1051 ]m4_map([b4_symbol_actions], m4_defn([b4_symbol_printers]))[
1052 default:
1053 break;
1054 }
1055 yyo << ')';
1056 }
1057 #endif
1058
1059 void
1060 ]b4_parser_class_name[::yypush_ (const char* m, state_type s,
1061 symbol_type& sym)
1062 {
1063 if (m)
1064 YY_SYMBOL_PRINT (m, sym);
1065 ]b4_variant_if(
1066 [[ yystack_.push (stack_symbol_type (]b4_args(
1067 [s],
1068 [semantic_type()],
1069 b4_locations_if([sym.location]))[));
1070 ]b4_symbol_variant([[yystos_[s]]], [[yystack_[0].value]],
1071 [build], [sym.value])],
1072 [[ yystack_.push (stack_symbol_type (]b4_args(
1073 [s],
1074 [sym.value],
1075 b4_locations_if([sym.location]))[));]])[
1076 }
1077
1078 void
1079 ]b4_parser_class_name[::yypush_ (const char* m, stack_symbol_type& s)
1080 {
1081 if (m)
1082 YY_SYMBOL_PRINT (m, s);
1083 ]b4_variant_if(
1084 [[ yystack_.push (stack_symbol_type (]b4_args(
1085 [s.state],
1086 [semantic_type()],
1087 b4_locations_if([s.location]))[));
1088 ]b4_symbol_variant([[yystos_[s.state]]], [[yystack_[0].value]],
1089 [build], [s.value])],
1090 [ yystack_.push (s);])[
1091 }
1092
1093 void
1094 ]b4_parser_class_name[::yypop_ (unsigned int n)
1095 {
1096 yystack_.pop (n);
1097 }
1098
1099 #if YYDEBUG
1100 std::ostream&
1101 ]b4_parser_class_name[::debug_stream () const
1102 {
1103 return *yycdebug_;
1104 }
1105
1106 void
1107 ]b4_parser_class_name[::set_debug_stream (std::ostream& o)
1108 {
1109 yycdebug_ = &o;
1110 }
1111
1112
1113 ]b4_parser_class_name[::debug_level_type
1114 ]b4_parser_class_name[::debug_level () const
1115 {
1116 return yydebug_;
1117 }
1118
1119 void
1120 ]b4_parser_class_name[::set_debug_level (debug_level_type l)
1121 {
1122 yydebug_ = l;
1123 }
1124 #endif
1125
1126 int
1127 ]b4_parser_class_name[::parse ()
1128 {
1129 /// Whether yyla contains a lookahead.
1130 bool yyempty = true;
1131
1132 /* State. */
1133 int yyn;
1134 int yylen = 0;
1135 int yystate = 0;
1136
1137 /* Error handling. */
1138 int yynerrs_ = 0;
1139 int yyerrstatus_ = 0;
1140
1141 /// The lookahead symbol.
1142 symbol_type yyla;]b4_locations_if([[
1143
1144 /// The locations where the error started and ended.
1145 stack_symbol_type yyerror_range[2];]])[
1146
1147 /// $$ and @@$.
1148 stack_symbol_type yylhs;
1149
1150 /// The return value of parse().
1151 int yyresult;
1152
1153 YYCDEBUG << "Starting parse" << std::endl;
1154
1155 ]m4_ifdef([b4_initial_action], [
1156 m4_pushdef([b4_at_dollar], [yyla.location])dnl
1157 m4_pushdef([b4_dollar_dollar], [yyla.value])dnl
1158 /* User initialization code. */
1159 b4_user_initial_action
1160 m4_popdef([b4_dollar_dollar])dnl
1161 m4_popdef([b4_at_dollar])])dnl
1162
1163 [ /* Initialize the stack. The initial state will be set in
1164 yynewstate, since the latter expects the semantical and the
1165 location values to have been already stored, initialize these
1166 stacks with a primary value. */
1167 yystack_ = stack_type (0);
1168 yypush_ (0, 0, yyla);
1169
1170 // A new state was pushed on the stack.
1171 // Invariant: yystate == yystack_[0].state, i.e.,
1172 // yystate was just pushed onto the state stack.
1173 yynewstate:
1174 YYCDEBUG << "Entering state " << yystate << std::endl;
1175
1176 /* Accept? */
1177 if (yystate == yyfinal_)
1178 goto yyacceptlab;
1179
1180 goto yybackup;
1181
1182 /* Backup. */
1183 yybackup:
1184
1185 /* Try to take a decision without lookahead. */
1186 yyn = yypact_[yystate];
1187 if (yyn == yypact_ninf_)
1188 goto yydefault;
1189
1190 /* Read a lookahead token. */
1191 if (yyempty)
1192 {
1193 YYCDEBUG << "Reading a token: ";
1194 ]b4_lex_symbol_if(
1195 [ yyla = b4_c_function_call([yylex], [symbol_type],
1196 m4_ifdef([b4_lex_param], b4_lex_param));],
1197 [ yyla.type = yytranslate_ (b4_c_function_call([yylex], [int],
1198 [[YYSTYPE*], [&yyla.value]][]dnl
1199 b4_locations_if([, [[location*], [&yyla.location]]])dnl
1200 m4_ifdef([b4_lex_param], [, ]b4_lex_param)));])[
1201 yyempty = false;
1202 }
1203 YY_SYMBOL_PRINT ("Next token is", yyla);
1204
1205 /* If the proper action on seeing token YYLA.TYPE is to reduce or
1206 to detect an error, take that action. */
1207 yyn += yyla.type;
1208 if (yyn < 0 || yylast_ < yyn || yycheck_[yyn] != yyla.type)
1209 goto yydefault;
1210
1211 /* Reduce or error. */
1212 yyn = yytable_[yyn];
1213 if (yyn <= 0)
1214 {
1215 if (yyn == 0 || yyn == yytable_ninf_)
1216 goto yyerrlab;
1217 yyn = -yyn;
1218 goto yyreduce;
1219 }
1220
1221 /* Discard the token being shifted. */
1222 yyempty = true;
1223
1224 /* Count tokens shifted since error; after three, turn off error
1225 status. */
1226 if (yyerrstatus_)
1227 --yyerrstatus_;
1228
1229 /* Shift the lookahead token. */
1230 yystate = yyn;
1231 yypush_ ("Shifting", yystate, yyla);
1232 goto yynewstate;
1233
1234 /*-----------------------------------------------------------.
1235 | yydefault -- do the default action for the current state. |
1236 `-----------------------------------------------------------*/
1237 yydefault:
1238 yyn = yydefact_[yystate];
1239 if (yyn == 0)
1240 goto yyerrlab;
1241 goto yyreduce;
1242
1243 /*-----------------------------.
1244 | yyreduce -- Do a reduction. |
1245 `-----------------------------*/
1246 yyreduce:
1247 yylen = yyr2_[yyn];]b4_variant_if([
1248 /* Variants are always initialized to an empty instance of the
1249 correct type. The default $$=$1 rule is NOT applied when using
1250 variants */
1251 ]b4_symbol_variant([[yyr1_@{yyn@}]], [yylhs.value], [build])[],[
1252 /* If YYLEN is nonzero, implement the default value of the action:
1253 `$$ = $1'. Otherwise, use the top of the stack.
1254
1255 Otherwise, the following line sets YYLHS.VALUE to garbage.
1256 This behavior is undocumented and Bison
1257 users should not rely upon it. */
1258 if (yylen)
1259 yylhs.value = yystack_@{yylen - 1@}.value;
1260 else
1261 yylhs.value = yystack_@{0@}.value;])[
1262 ]b4_locations_if([dnl
1263 [
1264 // Compute the default @@$.
1265 {
1266 slice<stack_symbol_type, stack_type> slice (yystack_, yylen);
1267 YYLLOC_DEFAULT (yylhs.location, slice, yylen);
1268 }]])[
1269
1270 // Perform the reduction.
1271 YY_REDUCE_PRINT (yyn);
1272 switch (yyn)
1273 {
1274 ]b4_user_actions[
1275 default:
1276 break;
1277 }
1278 // Compute post-reduction state.
1279 yyn = yyr1_[yyn];
1280 yystate = yypgoto_[yyn - yyntokens_] + yystack_[yylen].state;
1281 if (0 <= yystate && yystate <= yylast_
1282 && yycheck_[yystate] == yystack_[yylen].state)
1283 yystate = yytable_[yystate];
1284 else
1285 yystate = yydefgoto_[yyn - yyntokens_];
1286 yylhs.state = yystate;
1287 YY_SYMBOL_PRINT ("-> $$ =", yylhs);
1288 ]b4_variant_if([[
1289 // Destroy the lhs symbols.
1290 for (int i = 0; i < yylen; ++i)
1291 // Destroy a variant which value may have be swapped with
1292 // yylhs.value. The value of yylhs.value (hence maybe one of
1293 // these lhs symbols) depends on what does the default
1294 // contruction for this type. In the case of pointers for
1295 // instance, nothing is done, so the value is junk. Therefore
1296 // do not try to report the content in the debug trace, it's
1297 // junk. Hence yymsg = 0. Besides, that keeps exactly the same
1298 // traces as with the other Bison skeletons.
1299 yy_destroy_ (0, yystack_[i]);]])[
1300
1301 yypop_ (yylen);
1302 yylen = 0;
1303 YY_STACK_PRINT ();
1304
1305 /* Shift the result of the reduction. */
1306 yypush_ (0, yylhs);
1307 goto yynewstate;
1308
1309 /*------------------------------------.
1310 | yyerrlab -- here on detecting error |
1311 `------------------------------------*/
1312 yyerrlab:
1313 /* If not already recovering from an error, report this error. */
1314 if (!yyerrstatus_)
1315 {
1316 ++yynerrs_;
1317 error (]b4_args(b4_locations_if([yyla.location]),
1318 [yysyntax_error_ (yystate, yyla.type)])[);
1319 }
1320
1321 ]b4_locations_if([[
1322 yyerror_range[0].location = yyla.location;]])[
1323 if (yyerrstatus_ == 3)
1324 {
1325 /* If just tried and failed to reuse lookahead token after an
1326 error, discard it. */
1327
1328 /* Return failure if at end of input. */
1329 if (yyla.type == yyeof_)
1330 YYABORT;
1331 else
1332 {
1333 yy_destroy_ ("Error: discarding", yyla);
1334 yyempty = true;
1335 }
1336 }
1337
1338 /* Else will try to reuse lookahead token after shifting the error
1339 token. */
1340 goto yyerrlab1;
1341
1342
1343 /*---------------------------------------------------.
1344 | yyerrorlab -- error raised explicitly by YYERROR. |
1345 `---------------------------------------------------*/
1346 yyerrorlab:
1347
1348 /* Pacify compilers like GCC when the user code never invokes
1349 YYERROR and the label yyerrorlab therefore never appears in user
1350 code. */
1351 if (false)
1352 goto yyerrorlab;
1353
1354 ]b4_locations_if([[
1355 yyerror_range[0].location = yystack_[yylen - 1].location;]])[
1356 /* Do not reclaim the symbols of the rule which action triggered
1357 this YYERROR. */
1358 yypop_ (yylen);
1359 yylen = 0;
1360 yystate = yystack_[0].state;
1361 goto yyerrlab1;
1362
1363 /*-------------------------------------------------------------.
1364 | yyerrlab1 -- common code for both syntax error and YYERROR. |
1365 `-------------------------------------------------------------*/
1366 yyerrlab1:
1367 yyerrstatus_ = 3; /* Each real token shifted decrements this. */
1368 {
1369 stack_symbol_type error_token;
1370 for (;;)
1371 {
1372 yyn = yypact_[yystate];
1373 if (yyn != yypact_ninf_)
1374 {
1375 yyn += yyterror_;
1376 if (0 <= yyn && yyn <= yylast_ && yycheck_[yyn] == yyterror_)
1377 {
1378 yyn = yytable_[yyn];
1379 if (0 < yyn)
1380 break;
1381 }
1382 }
1383
1384 // Pop the current state because it cannot handle the error token.
1385 if (yystack_.size () == 1)
1386 YYABORT;
1387 ]b4_locations_if([[
1388 yyerror_range[0].location = yystack_[0].location;]])[
1389 yy_destroy_ ("Error: popping", yystack_[0]);
1390 yypop_ ();
1391 yystate = yystack_[0].state;
1392 YY_STACK_PRINT ();
1393 }
1394 ]b4_locations_if([[
1395 yyerror_range[1].location = yyla.location;
1396 YYLLOC_DEFAULT (error_token.location, (yyerror_range - 1), 2);]])[
1397
1398 /* Shift the error token. */
1399 error_token.state = yystate = yyn;
1400 yypush_ ("Shifting", error_token);
1401 }
1402 goto yynewstate;
1403
1404 /* Accept. */
1405 yyacceptlab:
1406 yyresult = 0;
1407 goto yyreturn;
1408
1409 /* Abort. */
1410 yyabortlab:
1411 yyresult = 1;
1412 goto yyreturn;
1413
1414 yyreturn:
1415 if (!yyempty)
1416 yy_destroy_ ("Cleanup: discarding lookahead", yyla);
1417
1418 /* Do not reclaim the symbols of the rule which action triggered
1419 this YYABORT or YYACCEPT. */
1420 yypop_ (yylen);
1421 while (yystack_.size () != 1)
1422 {
1423 yy_destroy_ ("Cleanup: popping", yystack_[0]);
1424 yypop_ ();
1425 }
1426
1427 return yyresult;
1428 }
1429
1430 // Generate an error message.
1431 std::string
1432 ]b4_parser_class_name[::yysyntax_error_ (]dnl
1433 b4_error_verbose_if([int yystate, int yytoken],
1434 [int, int])[)
1435 {
1436 std::string yyres;]b4_error_verbose_if([[
1437 int yyn = yypact_[yystate];
1438 if (yypact_ninf_ < yyn && yyn <= yylast_)
1439 {
1440 /* Start YYX at -YYN if negative to avoid negative indexes in
1441 YYCHECK. */
1442 int yyxbegin = yyn < 0 ? -yyn : 0;
1443
1444 /* Stay within bounds of both yycheck and yytname. */
1445 int yychecklim = yylast_ - yyn + 1;
1446 int yyxend = yychecklim < yyntokens_ ? yychecklim : yyntokens_;
1447
1448 // Number of "expected" tokens.
1449 size_t yycount = 0;
1450 // Its maximum.
1451 enum { YYERROR_VERBOSE_ARGS_MAXIMUM = 5 };
1452 // Arguments of yyformat.
1453 char const *yyarg[YYERROR_VERBOSE_ARGS_MAXIMUM];
1454 yyarg[yycount++] = yytname_[yytoken];
1455 for (int yyx = yyxbegin; yyx < yyxend; ++yyx)
1456 if (yycheck_[yyx + yyn] == yyx && yyx != yyterror_)
1457 {
1458 if (yycount == YYERROR_VERBOSE_ARGS_MAXIMUM)
1459 {
1460 yycount = 1;
1461 break;
1462 }
1463 else
1464 yyarg[yycount++] = yytname_[yyx];
1465 }
1466
1467 char const* yyformat = 0;
1468 switch (yycount)
1469 {
1470 #define YYCASE_(N, S) \
1471 case N: \
1472 yyformat = S; \
1473 break
1474 YYCASE_(1, YY_("syntax error, unexpected %s"));
1475 YYCASE_(2, YY_("syntax error, unexpected %s, expecting %s"));
1476 YYCASE_(3, YY_("syntax error, unexpected %s, expecting %s or %s"));
1477 YYCASE_(4, YY_("syntax error, unexpected %s, expecting %s or %s or %s"));
1478 YYCASE_(5, YY_("syntax error, unexpected %s, expecting %s or %s or %s or %s"));
1479 #undef YYCASE_
1480 }
1481 // Argument number.
1482 size_t yyi = 0;
1483 for (char const* yyp = yyformat; *yyp; ++yyp)
1484 if (yyp[0] == '%' && yyp[1] == 's' && yyi < yycount)
1485 {
1486 yyres += yytnamerr_ (yyarg[yyi++]);
1487 ++yyp;
1488 }
1489 else
1490 yyres += *yyp;
1491 }
1492 else
1493 ]])dnl
1494 [ yyres = YY_("syntax error");
1495 return yyres;
1496 }
1497
1498
1499 const ]b4_int_type(b4_pact_ninf, b4_pact_ninf) b4_parser_class_name::yypact_ninf_ = b4_pact_ninf[;
1500
1501 const ]b4_int_type(b4_table_ninf, b4_table_ninf) b4_parser_class_name::yytable_ninf_ = b4_table_ninf[;
1502
1503 ]b4_parser_tables_define[
1504
1505 #if YYDEBUG || YYERROR_VERBOSE || YYTOKEN_TABLE
1506 /* YYTNAME[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM.
1507 First, the terminals, then, starting at \a yyntokens_, nonterminals. */
1508 const char*
1509 const ]b4_parser_class_name[::yytname_[] =
1510 {
1511 ]b4_tname[
1512 };
1513 #endif
1514
1515 #if YYDEBUG
1516 ]b4_integral_parser_table_define([rline], [b4_rline])[
1517
1518 // Print the state stack on the debug stream.
1519 void
1520 ]b4_parser_class_name[::yystack_print_ ()
1521 {
1522 *yycdebug_ << "Stack now";
1523 for (stack_type::const_iterator
1524 i = yystack_.begin (),
1525 i_end = yystack_.end ();
1526 i != i_end; ++i)
1527 *yycdebug_ << ' ' << i->state;
1528 *yycdebug_ << std::endl;
1529 }
1530
1531 // Report on the debug stream that the rule \a yyrule is going to be reduced.
1532 void
1533 ]b4_parser_class_name[::yy_reduce_print_ (int yyrule)
1534 {
1535 unsigned int yylno = yyrline_[yyrule];
1536 int yynrhs = yyr2_[yyrule];
1537 /* Print the symbols being reduced, and their result. */
1538 *yycdebug_ << "Reducing stack by rule " << yyrule - 1
1539 << " (line " << yylno << "):" << std::endl;
1540 /* The symbols being reduced. */
1541 for (int yyi = 0; yyi < yynrhs; yyi++)
1542 YY_SYMBOL_PRINT (" $" << yyi + 1 << " =",
1543 ]b4_rhs_data(yynrhs, yyi + 1)[);
1544 }
1545 #endif // YYDEBUG
1546
1547 ]b4_lex_symbol_if([], [b4_yytranslate_definition])[
1548 ]b4_namespace_close[
1549
1550 ]b4_epilogue[]dnl
1551 @output(b4_dir_prefix[]stack.hh@)@
1552 b4_copyright([Stack handling for Bison parsers in C++])[
1553
1554 #ifndef BISON_STACK_HH
1555 # define BISON_STACK_HH
1556
1557 #include <deque>
1558
1559 ]b4_namespace_open[
1560 template <class T, class S = std::deque<T> >
1561 class stack
1562 {
1563 public:
1564
1565 // Hide our reversed order.
1566 typedef typename S::reverse_iterator iterator;
1567 typedef typename S::const_reverse_iterator const_iterator;
1568
1569 stack () : seq_ ()
1570 {
1571 }
1572
1573 stack (unsigned int n) : seq_ (n)
1574 {
1575 }
1576
1577 inline
1578 T&
1579 operator [] (unsigned int i)
1580 {
1581 return seq_[i];
1582 }
1583
1584 inline
1585 const T&
1586 operator [] (unsigned int i) const
1587 {
1588 return seq_[i];
1589 }
1590
1591 inline
1592 void
1593 push (const T& t)
1594 {
1595 seq_.push_front (t);
1596 }
1597
1598 inline
1599 void
1600 pop (unsigned int n = 1)
1601 {
1602 for (; n; --n)
1603 seq_.pop_front ();
1604 }
1605
1606 inline
1607 typename S::size_type
1608 size () const
1609 {
1610 return seq_.size ();
1611 }
1612
1613 inline const_iterator begin () const { return seq_.rbegin (); }
1614 inline const_iterator end () const { return seq_.rend (); }
1615
1616 private:
1617 /// The wrapped container.
1618 S seq_;
1619 };
1620
1621 /// Present a slice of the top of a stack.
1622 template <class T, class S = stack<T> >
1623 class slice
1624 {
1625 public:
1626
1627 slice (const S& stack,
1628 unsigned int range) : stack_ (stack),
1629 range_ (range)
1630 {
1631 }
1632
1633 inline
1634 const T&
1635 operator [] (unsigned int i) const
1636 {
1637 return stack_[range_ - i];
1638 }
1639
1640 private:
1641
1642 const S& stack_;
1643 unsigned int range_;
1644 };
1645 ]b4_namespace_close[
1646
1647 #endif // not BISON_STACK_HH[]dnl
1648 ]
1649 m4_divert_pop(0)
1650 m4_popdef([b4_copyright_years])dnl