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