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