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