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