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