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