]> git.saurik.com Git - bison.git/blame - data/lalr1.cc
Remove parser::rhs_number_type.
[bison.git] / data / lalr1.cc
CommitLineData
60491a94 1# C++ skeleton for Bison
b4721715 2
cf98343c
AD
3# Copyright (C) 2002, 2003, 2004, 2005, 2006, 2007, 2008
4# Free Software Foundation, Inc.
60491a94 5
f16b0819 6# This program is free software: you can redistribute it and/or modify
60491a94 7# it under the terms of the GNU General Public License as published by
f16b0819 8# the Free Software Foundation, either version 3 of the License, or
60491a94 9# (at your option) any later version.
f16b0819 10#
60491a94
AD
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.
f16b0819 15#
60491a94 16# You should have received a copy of the GNU General Public License
f16b0819 17# along with this program. If not, see <http://www.gnu.org/licenses/>.
60491a94 18
cf147260 19m4_include(b4_pkgdatadir/[c++.m4])
7eb8a0bc 20
5ab8c47b
AD
21# How the semantic value is extracted when using variants.
22b4_variant_if([
23 # b4_symbol_value(VAL, [TYPE])
24 # ----------------------------
25 m4_define([b4_symbol_value],
26 [m4_ifval([$2],
27 [$1.as<$2>()],
28 [$1])])
29]) # b4_variant_if
30
31
c4585f1e
AD
32# b4_symbol_actions(FILENAME, LINENO,
33# SYMBOL-TAG, SYMBOL-NUM,
34# SYMBOL-ACTION, SYMBOL-TYPENAME)
35# -------------------------------------------------
36# Same as in C, but using references instead of pointers.
37m4_define([b4_symbol_actions],
38[m4_pushdef([b4_dollar_dollar],
39 [b4_symbol_value([yyvalue], [$6])])dnl
40m4_pushdef([b4_at_dollar], [yylocation])dnl
41 case $4: // $3
42b4_syncline([$2], [$1])
43 $5;
44b4_syncline([@oline@], [@ofile@])
45 break;
46m4_popdef([b4_at_dollar])dnl
47m4_popdef([b4_dollar_dollar])dnl
48])
49
50
5ab8c47b
AD
51# b4_symbol_action_(SYMBOL-TAG, SYMBOL-NUM, SYMBOL-TYPENAME)
52# ----------------------------------------------------------
53# Invoke b4_dollar_dollar(SYMBOL_TYPENAME) for each symbol.
54m4_define([b4_symbol_action_],
55[m4_ifval($3,
56[ case $2: // $1
57 b4_dollar_dollar($@);
58 break;
59])])
60
61
62# b4_symbol_variant(YYTYPE, YYVAL, ACTION)
63# ----------------------------------------
64# Run some ACTION ("build", or "destroy") on YYVAL of symbol type
65# YYTYPE.
66m4_define([b4_symbol_variant],
67[m4_pushdef([b4_dollar_dollar],
68 [$2.$3<$][3>()])dnl
69 switch ($1)
70 {
71m4_map([b4_symbol_action_], m4_defn([b4_type_names]))
72 default:
73 break;
74 }
75m4_popdef([b4_dollar_dollar])dnl
76])
77
78
79# _b4_char_sizeof_counter
80# -----------------------
81# A counter used by _b4_char_sizeof_dummy to create fresh symbols.
82m4_define([_b4_char_sizeof_counter],
83[0])
84
85# _b4_char_sizeof_dummy
86# ---------------------
87# At each call return a new C++ identifier.
88m4_define([_b4_char_sizeof_dummy],
89[m4_define([_b4_char_sizeof_counter], m4_incr(_b4_char_sizeof_counter))dnl
90dummy[]_b4_char_sizeof_counter])
91
92
93# b4_char_sizeof(SYMBOL-TAG, SYMBOL-NUM, SYMBOL-TYPENAME)
94# -------------------------------------------------------
95# To be mapped on the list of type names to produce:
96#
97# char dummy1[sizeof(type_name_1)];
98# char dummy2[sizeof(type_name_2)];
99#
100# for defined type names.
101# $3 is doubly-quoted, do not quote it again.
102m4_define([b4_char_sizeof],
103[m4_ifval($3,
104[
105 char _b4_char_sizeof_dummy@{sizeof($3)@}; // $1])dnl
106])
107
108
6afc30cc 109m4_define([b4_parser_class_name],
a4e25e1d 110 [b4_percent_define_get([[parser_class_name]])])
34376418
AD
111
112# The header is mandatory.
113b4_defines_if([],
5f340b48 114 [b4_fatal([b4_skeleton[: using %%defines is mandatory]])])
34376418 115
4626a15d
AD
116# Backward compatibility.
117m4_define([b4_location_constructors])
fc695704 118m4_include(b4_pkgdatadir/[location.cc])
a5eb1ed2 119
b526ee61
AD
120# We do want M4 expansion after # for CPP macros.
121m4_changecom()
08af01c2 122m4_divert_push(0)dnl
327afc7c 123b4_defines_if(
08af01c2 124[@output(b4_spec_defines_file@)
193d7c70 125b4_copyright([Skeleton interface for Bison LALR(1) parsers in C++],
cf98343c 126 [2002, 2003, 2004, 2005, 2006, 2007, 2008])
fb9712a9 127dnl FIXME: This is wrong, we want computed header guards.
8bb4c753 128[
af3412cd
PE
129/* C++ LALR(1) parser skeleton written by Akim Demaille. */
130
c5e3e510
AD
131#ifndef PARSER_HEADER_H
132# define PARSER_HEADER_H
2b548aa6 133
a4e25e1d 134]b4_percent_code_get([[requires]])[
aef3da86 135
8d69a1a3 136#include <string>
717be197 137#include <iostream>
fb9712a9 138#include "stack.hh"
50997c6e 139
793fbca5 140]b4_namespace_open[
fc695704
AD
141 class position;
142 class location;
5ab8c47b
AD
143]b4_variant_if([[
144 /// A char[S] buffer to store and retrieve objects.
145 ///
146 /// Sort of a variant, but does not keep track of the nature
147 /// of the stored data, since that knowledge is available
148 /// via the current state.
149 template <size_t S>
150 struct variant
151 {
152 /// Instantiate a \a T in here.
153 template <typename T>
154 inline void
155 build()
156 {
157 new (buffer) T;
158 }
159
160 /// Destroy the stored \a T.
161 template <typename T>
162 inline void
163 destroy()
164 {
165 reinterpret_cast<T&>(buffer).~T();
166 }
167
168 /// Accessor to a built \a T.
169 template <typename T>
170 inline T&
171 as()
172 {
173 return reinterpret_cast<T&>(buffer);
174 }
175
176 /// Const accessor to a built \a T (for %printer).
177 template <typename T>
178 inline const T&
179 as() const
180 {
181 return reinterpret_cast<const T&>(buffer);
182 }
183
184 /// A buffer large enough to store any of the semantic values.
185 char buffer[S];
186 };
187]])[
793fbca5 188]b4_namespace_close[
4162fa07 189
aef3da86 190#include "location.hh"
fc695704 191
69e2658b
RA
192/* Enabling traces. */
193#ifndef YYDEBUG
327afc7c 194# define YYDEBUG ]b4_debug_flag[
69e2658b
RA
195#endif
196
141f5793
PE
197/* Enabling verbose error messages. */
198#ifdef YYERROR_VERBOSE
199# undef YYERROR_VERBOSE
200# define YYERROR_VERBOSE 1
201#else
327afc7c 202# define YYERROR_VERBOSE ]b4_error_verbose_flag[
69e2658b
RA
203#endif
204
141f5793
PE
205/* Enabling the token table. */
206#ifndef YYTOKEN_TABLE
207# define YYTOKEN_TABLE ]b4_token_table[
208#endif
209
b4a20338
AD
210/* YYLLOC_DEFAULT -- Set CURRENT to span from RHS[1] to RHS[N].
211 If N is 0, then set CURRENT to the empty location which ends
212 the previous symbol: RHS[0] (always defined). */
3fc16193 213
374f5a14 214#ifndef YYLLOC_DEFAULT
b4a20338
AD
215# define YYLLOC_DEFAULT(Current, Rhs, N) \
216do { \
217 if (N) \
218 { \
219 (Current).begin = (Rhs)[1].begin; \
220 (Current).end = (Rhs)[N].end; \
221 } \
222 else \
223 { \
224 (Current).begin = (Current).end = (Rhs)[0].end; \
225 } \
2a4647a3 226} while (false)
374f5a14
RA
227#endif
228
793fbca5 229]b4_namespace_open[
3f3eed27 230
efeed023 231 /// A Bison parser.
07fed891 232 class ]b4_parser_class_name[
2b548aa6 233 {
fb9712a9 234 public:
02650b7f 235#ifndef YYSTYPE
5ab8c47b
AD
236]b4_variant_if(
237[ /// An auxiliary type to compute the largest semantic type.
238 union union_type
239 {]m4_map([b4_char_sizeof], m4_defn([b4_type_names]))[
240 };
241
242 /// Symbol semantic values.
243 typedef variant<sizeof(union_type)> semantic_type;],
244[ /// Symbol semantic values.
245m4_ifdef([b4_stype],
1221b78a 246[ union semantic_type
5ab8c47b 247 {b4_user_stype
7ecec4dd 248 };],
ddc8ede1
PE
249[m4_if(b4_tag_seen_flag, 0,
250[[ typedef int semantic_type;]],
5ab8c47b 251[[ typedef YYSTYPE semantic_type;]])])])[
fb9712a9 252#else
f479c6c6 253 typedef YYSTYPE semantic_type;
fb9712a9 254#endif
617a8f12 255 /// Symbol locations.
a4e25e1d 256 typedef ]b4_percent_define_get([[location_type]])[ location_type;
fb9712a9
AD
257 /// Tokens.
258 struct token
259 {
260 ]b4_token_enums(b4_tokens)[
261 };
c095d689
AD
262 /// Token type.
263 typedef token::yytokentype token_type;
2b548aa6 264
efeed023 265 /// Build a parser object.
98ae9643
AD
266 ]b4_parser_class_name[ (]b4_parse_param_decl[);
267 virtual ~]b4_parser_class_name[ ();
2b548aa6 268
f69a4142
AD
269 /// Parse.
270 /// \returns 0 iff parsing succeeded.
e019c247 271 virtual int parse ();
2b548aa6 272
52cbbe84 273#if YYDEBUG
f69a4142 274 /// The current debugging stream.
9a1e9989
AD
275 std::ostream& debug_stream () const;
276 /// Set the current debugging stream.
277 void set_debug_stream (std::ostream &);
278
a3cb6248
AD
279 /// Type for debugging levels.
280 typedef int debug_level_type;
281 /// The current debugging level.
282 debug_level_type debug_level () const;
283 /// Set the current debugging level.
284 void set_debug_level (debug_level_type l);
52cbbe84 285#endif
a3cb6248 286
2b548aa6 287 private:
efeed023
AD
288 /// Report a syntax error.
289 /// \param loc where the syntax error is found.
290 /// \param msg a description of the syntax error.
99880de5 291 virtual void error (const location_type& loc, const std::string& msg);
efeed023 292
dbcdae2d 293 /// Generate an error message.
d4fb5e3c 294 /// \param state the state where the error occurred.
742e4900 295 /// \param tok the lookahead token.
d4fb5e3c
AD
296 virtual std::string yysyntax_error_ (int yystate]dnl
297b4_error_verbose_if([, int tok])[);
efeed023 298
a5eb1ed2 299#if YYDEBUG
a0af42fc
AD
300 /// \brief Report a symbol value on the debug stream.
301 /// \param yytype The token type.
c4585f1e
AD
302 /// \param yyvalue Its semantic value.
303 /// \param yylocation Its location.
a0af42fc 304 virtual void yy_symbol_value_print_ (int yytype,
c4585f1e
AD
305 const semantic_type& yyvalue,
306 const location_type& yylocation);
f69a4142
AD
307 /// \brief Report a symbol on the debug stream.
308 /// \param yytype The token type.
c4585f1e
AD
309 /// \param yyvalue Its semantic value.
310 /// \param yylocation Its location.
a0af42fc 311 virtual void yy_symbol_print_ (int yytype,
c4585f1e
AD
312 const semantic_type& yyvalue,
313 const location_type& yylocation);
fa7b79c0 314#endif
a5eb1ed2 315
4bb2bc3f 316
e019c247 317 /// State numbers.
f479c6c6 318 typedef int state_type;
e019c247
AD
319 /// State stack type.
320 typedef stack<state_type> state_stack_type;
321 /// Semantic value stack type.
322 typedef stack<semantic_type> semantic_stack_type;
323 /// location stack type.
324 typedef stack<location_type> location_stack_type;
325
f69a4142 326 /// The state stack.
e019c247 327 state_stack_type yystate_stack_;
f69a4142 328 /// The semantic value stack.
e019c247 329 semantic_stack_type yysemantic_stack_;
f69a4142 330 /// The location stack.
e019c247 331 location_stack_type yylocation_stack_;
2b548aa6 332
e019c247 333 /// Internal symbol numbers.
f479c6c6 334 typedef ]b4_int_type_for([b4_translate])[ token_number_type;
2b548aa6 335 /* Tables. */
efeed023 336 /// For a state, the index in \a yytable_ of its portion.
617a8f12
AD
337 static const ]b4_int_type_for([b4_pact])[ yypact_[];
338 static const ]b4_int_type(b4_pact_ninf, b4_pact_ninf)[ yypact_ninf_;
efeed023
AD
339
340 /// For a state, default rule to reduce.
341 /// Unless\a yytable_ specifies something else to do.
342 /// Zero means the default is an error.
617a8f12 343 static const ]b4_int_type_for([b4_defact])[ yydefact_[];
efeed023 344
617a8f12
AD
345 static const ]b4_int_type_for([b4_pgoto])[ yypgoto_[];
346 static const ]b4_int_type_for([b4_defgoto])[ yydefgoto_[];
efeed023
AD
347
348 /// What to do in a state.
349 /// \a yytable_[yypact_[s]]: what to do in state \a s.
350 /// - if positive, shift that token.
351 /// - if negative, reduce the rule which number is the opposite.
352 /// - if zero, do what YYDEFACT says.
617a8f12
AD
353 static const ]b4_int_type_for([b4_table])[ yytable_[];
354 static const ]b4_int_type(b4_table_ninf, b4_table_ninf)[ yytable_ninf_;
efeed023 355
617a8f12 356 static const ]b4_int_type_for([b4_check])[ yycheck_[];
efeed023
AD
357
358 /// For a state, its accessing symbol.
617a8f12 359 static const ]b4_int_type_for([b4_stos])[ yystos_[];
efeed023
AD
360
361 /// For a rule, its LHS.
617a8f12 362 static const ]b4_int_type_for([b4_r1])[ yyr1_[];
efeed023 363 /// For a rule, its RHS length.
617a8f12 364 static const ]b4_int_type_for([b4_r2])[ yyr2_[];
69e2658b 365
141f5793 366#if YYDEBUG || YYERROR_VERBOSE || YYTOKEN_TABLE
efeed023 367 /// For a symbol, its name in clear.
9e0876fb
PE
368 static const char* const yytname_[];
369#endif
370
371#if YYERROR_VERBOSE
372 /// Convert the symbol name \a n to a form suitable for a diagnostic.
373 virtual std::string yytnamerr_ (const char *n);
69e2658b 374#endif
2b548aa6 375
69e2658b 376#if YYDEBUG
e019c247 377 /// A type to store symbol numbers and -1.
f479c6c6 378 typedef ]b4_int_type_for([b4_rhs])[ rhs_number_type;
617a8f12 379 /// A `-1'-separated list of the rules' RHS.
99880de5 380 static const rhs_number_type yyrhs_[];
617a8f12
AD
381 /// For each rule, the index of the first RHS symbol in \a yyrhs_.
382 static const ]b4_int_type_for([b4_prhs])[ yyprhs_[];
383 /// For each rule, its source line number.
384 static const ]b4_int_type_for([b4_rline])[ yyrline_[];
385 /// For each scanner token number, its symbol number.
386 static const ]b4_int_type_for([b4_toknum])[ yytoken_number_[];
efeed023 387 /// Report on the debug stream that the rule \a r is going to be reduced.
d1ff7a7c 388 virtual void yy_reduce_print_ (int r);
efeed023 389 /// Print the state stack on the debug stream.
f69a4142 390 virtual void yystack_print_ ();
fa7b79c0
PE
391
392 /* Debugging. */
393 int yydebug_;
394 std::ostream* yycdebug_;
69e2658b 395#endif
2b548aa6 396
32c96bd7
AD
397 /// Convert a scanner token number \a t to a symbol number.
398 token_number_type yytranslate_ (int t);
f69a4142
AD
399
400 /// \brief Reclaim the memory associated to a symbol.
401 /// \param yymsg Why this token is reclaimed.
402 /// \param yytype The symbol type.
c4585f1e
AD
403 /// \param yyvalue Its semantic value.
404 /// \param yylocation Its location.
f69a4142 405 inline void yydestruct_ (const char* yymsg,
02650b7f 406 int yytype,
c4585f1e
AD
407 semantic_type& yyvalue,
408 location_type& yylocation);
2b548aa6 409
7dedf26e
AD
410 /// Push a new state on the stack.
411 /// \warning the contents of \a v is stolen.
412 inline void yypush_ (state_type s,
413 semantic_type& v, const location_type& l);
414
52d5733f 415 /// Pop \a n symbols the three stacks.
f69a4142 416 inline void yypop_ (unsigned int n = 1);
52d5733f 417
762a801e 418 /* Constants. */
617a8f12 419 static const int yyeof_;
39912f52 420 /* LAST_ -- Last index in TABLE_. */
617a8f12
AD
421 static const int yylast_;
422 static const int yynnts_;
423 static const int yyempty_;
424 static const int yyfinal_;
425 static const int yyterror_;
426 static const int yyerrcode_;
427 static const int yyntokens_;
428 static const unsigned int yyuser_token_number_max_;
99880de5 429 static const token_number_type yyundef_token_;
caf37a36 430]b4_parse_param_vars[
2b548aa6 431 };
793fbca5 432]b4_namespace_close[
2b548aa6 433
592d0b1e 434]b4_percent_define_flag_if([[global_tokens_and_yystype]],
fb9712a9
AD
435[b4_token_defines(b4_tokens)
436
437#ifndef YYSTYPE
9d9b8b70 438 /* Redirection for backward compatibility. */
793fbca5 439# define YYSTYPE b4_namespace_ref::b4_parser_class_name::semantic_type
fb9712a9 440#endif
9bc0dd67 441])
a4e25e1d 442b4_percent_code_get([[provides]])[]dnl
9bc0dd67
JD
443
444[#endif /* ! defined PARSER_HEADER_H */]
b61c6978 445])dnl
08af01c2 446@output(b4_parser_file_name@)
193d7c70 447b4_copyright([Skeleton implementation for Bison LALR(1) parsers in C++],
cf98343c 448 [2002, 2003, 2004, 2005, 2006, 2007, 2008])
a4e25e1d 449b4_percent_code_get([[top]])[]dnl
aa08666d 450m4_if(b4_prefix, [yy], [],
c5b95ccf
AD
451[
452// Take the name prefix into account.
9bc0dd67
JD
453#define yylex b4_prefix[]lex])[
454
455/* First part of user declarations. */
136a0f76 456]b4_user_pre_prologue
9bc0dd67 457
bd9d212b
JD
458b4_defines_if([[
459#include "@basename(]b4_spec_defines_file[@)"]])[
50997c6e 460
fb9712a9 461/* User implementation prologue. */
8e0a5e9e 462]b4_user_post_prologue
a4e25e1d 463b4_percent_code_get[]dnl
fb9712a9 464
8e0a5e9e 465[#ifndef YY_
30757c8c
PE
466# if YYENABLE_NLS
467# if ENABLE_NLS
468# include <libintl.h> /* FIXME: INFRINGES ON USER NAME SPACE */
469# define YY_(msgid) dgettext ("bison-runtime", msgid)
470# endif
471# endif
472# ifndef YY_
473# define YY_(msgid) msgid
474# endif
989b5b8e
AD
475#endif
476
2a4647a3 477/* Suppress unused-variable warnings by "using" E. */
12ce2df6 478#define YYUSE(e) ((void) (e))
2a4647a3 479
2b548aa6 480/* Enable debugging if requested. */
50997c6e 481#if YYDEBUG
284acc8b 482
fa7b79c0
PE
483/* A pseudo ostream that takes yydebug_ into account. */
484# define YYCDEBUG if (yydebug_) (*yycdebug_)
485
284acc8b
AD
486# define YY_SYMBOL_PRINT(Title, Type, Value, Location) \
487do { \
a3cb6248 488 if (yydebug_) \
284acc8b 489 { \
d1ff7a7c 490 *yycdebug_ << Title << ' '; \
a0af42fc 491 yy_symbol_print_ ((Type), (Value), (Location)); \
9a1e9989 492 *yycdebug_ << std::endl; \
284acc8b 493 } \
2a4647a3 494} while (false)
284acc8b 495
5348bfbe
AD
496# define YY_REDUCE_PRINT(Rule) \
497do { \
a3cb6248 498 if (yydebug_) \
d1ff7a7c 499 yy_reduce_print_ (Rule); \
2a4647a3 500} while (false)
284acc8b 501
25f66e1a
AD
502# define YY_STACK_PRINT() \
503do { \
a3cb6248 504 if (yydebug_) \
f69a4142 505 yystack_print_ (); \
2a4647a3 506} while (false)
284acc8b 507
2b548aa6 508#else /* !YYDEBUG */
284acc8b 509
a36b333c 510# define YYCDEBUG if (false) std::cerr
284acc8b 511# define YY_SYMBOL_PRINT(Title, Type, Value, Location)
5348bfbe 512# define YY_REDUCE_PRINT(Rule)
25f66e1a 513# define YY_STACK_PRINT()
284acc8b 514
2b548aa6
RA
515#endif /* !YYDEBUG */
516
98e26a92
AD
517#define yyerrok (yyerrstatus_ = 0)
518#define yyclearin (yychar = yyempty_)
519
60a777aa
AD
520#define YYACCEPT goto yyacceptlab
521#define YYABORT goto yyabortlab
47301314 522#define YYERROR goto yyerrorlab
98e26a92 523#define YYRECOVERING() (!!yyerrstatus_)
60a777aa 524
793fbca5 525]b4_namespace_open[
aa08666d 526#if YYERROR_VERBOSE
9e0876fb 527
aa08666d
AD
528 /* Return YYSTR after stripping away unnecessary quotes and
529 backslashes, so that it's suitable for yyerror. The heuristic is
530 that double-quoting is unnecessary unless the string contains an
531 apostrophe, a comma, or backslash (other than backslash-backslash).
532 YYSTR is taken from yytname. */
533 std::string
534 ]b4_parser_class_name[::yytnamerr_ (const char *yystr)
535 {
536 if (*yystr == '"')
537 {
538 std::string yyr = "";
539 char const *yyp = yystr;
193d7c70 540
aa08666d
AD
541 for (;;)
542 switch (*++yyp)
543 {
544 case '\'':
545 case ',':
546 goto do_not_strip_quotes;
193d7c70 547
aa08666d
AD
548 case '\\':
549 if (*++yyp != '\\')
550 goto do_not_strip_quotes;
551 /* Fall through. */
552 default:
553 yyr += *yyp;
554 break;
193d7c70 555
aa08666d
AD
556 case '"':
557 return yyr;
558 }
559 do_not_strip_quotes: ;
560 }
193d7c70 561
aa08666d
AD
562 return yystr;
563 }
9e0876fb
PE
564
565#endif
566
98ae9643 567 /// Build a parser object.
fa7b79c0
PE
568 ]b4_parser_class_name::b4_parser_class_name[ (]b4_parse_param_decl[)]m4_ifset([b4_parse_param], [
569 :])[
570#if YYDEBUG
571 ]m4_ifset([b4_parse_param], [ ], [ :])[yydebug_ (false),
572 yycdebug_ (&std::cerr)]m4_ifset([b4_parse_param], [,])[
573#endif]b4_parse_param_cons[
98ae9643
AD
574 {
575 }
a0e68930 576
98ae9643
AD
577 ]b4_parser_class_name::~b4_parser_class_name[ ()
578 {
579 }
a0e68930 580
98ae9643
AD
581#if YYDEBUG
582 /*--------------------------------.
583 | Print this symbol on YYOUTPUT. |
584 `--------------------------------*/
a0e68930 585
a0af42fc
AD
586 inline void
587 ]b4_parser_class_name[::yy_symbol_value_print_ (int yytype,
c4585f1e 588 const semantic_type& yyvalue, const location_type& yylocation)
98ae9643 589 {
c4585f1e
AD
590 YYUSE (yylocation);
591 YYUSE (yyvalue);
98ae9643
AD
592 switch (yytype)
593 {
594 ]m4_map([b4_symbol_actions], m4_defn([b4_symbol_printers]))dnl
595[ default:
02650b7f 596 break;
98ae9643 597 }
a0af42fc
AD
598 }
599
600
601 void
602 ]b4_parser_class_name[::yy_symbol_print_ (int yytype,
c4585f1e 603 const semantic_type& yyvalue, const location_type& yylocation)
a0af42fc
AD
604 {
605 *yycdebug_ << (yytype < yyntokens_ ? "token" : "nterm")
02650b7f 606 << ' ' << yytname_[yytype] << " ("
c4585f1e
AD
607 << yylocation << ": ";
608 yy_symbol_value_print_ (yytype, yyvalue, yylocation);
98ae9643
AD
609 *yycdebug_ << ')';
610 }
fa7b79c0 611#endif
a0e68930 612
98ae9643
AD
613 void
614 ]b4_parser_class_name[::yydestruct_ (const char* yymsg,
c4585f1e 615 int yytype, semantic_type& yyvalue, location_type& yylocation)
98ae9643 616 {
98ae9643 617 YYUSE (yymsg);
c4585f1e
AD
618 YYUSE (yyvalue);
619 YYUSE (yylocation);
98ae9643 620
c4585f1e 621 YY_SYMBOL_PRINT (yymsg, yytype, yyvalue, yylocation);
98ae9643
AD
622
623 switch (yytype)
624 {
625 ]m4_map([b4_symbol_actions], m4_defn([b4_symbol_destructors]))[
02650b7f
PE
626 default:
627 break;
98ae9643
AD
628 }
629 }
60a777aa 630
7dedf26e
AD
631 void
632 ]b4_parser_class_name[::yypush_ (state_type s,
633 semantic_type& v, const location_type& l)
634 {
635 yystate_stack_.push (s);
636 yysemantic_stack_.push (v);
637 yylocation_stack_.push (l);
638 }
639
98ae9643
AD
640 void
641 ]b4_parser_class_name[::yypop_ (unsigned int n)
642 {
643 yystate_stack_.pop (n);
644 yysemantic_stack_.pop (n);
645 yylocation_stack_.pop (n);
646 }
52d5733f 647
fa7b79c0 648#if YYDEBUG
98ae9643
AD
649 std::ostream&
650 ]b4_parser_class_name[::debug_stream () const
651 {
652 return *yycdebug_;
653 }
9a1e9989 654
98ae9643
AD
655 void
656 ]b4_parser_class_name[::set_debug_stream (std::ostream& o)
657 {
658 yycdebug_ = &o;
659 }
9a1e9989
AD
660
661
98ae9643
AD
662 ]b4_parser_class_name[::debug_level_type
663 ]b4_parser_class_name[::debug_level () const
664 {
665 return yydebug_;
666 }
a3cb6248 667
98ae9643
AD
668 void
669 ]b4_parser_class_name[::set_debug_level (debug_level_type l)
670 {
671 yydebug_ = l;
672 }
fa7b79c0 673#endif
a3cb6248 674
98ae9643
AD
675 int
676 ]b4_parser_class_name[::parse ()
677 {
742e4900 678 /// Lookahead and lookahead in internal form.
98ae9643
AD
679 int yychar = yyempty_;
680 int yytoken = 0;
d4fb5e3c 681
98ae9643
AD
682 /* State. */
683 int yyn;
a85284cf 684 int yylen = 0;
98ae9643 685 int yystate = 0;
d4fb5e3c 686
9d9b8b70 687 /* Error handling. */
98ae9643
AD
688 int yynerrs_ = 0;
689 int yyerrstatus_ = 0;
dbcdae2d 690
742e4900 691 /// Semantic value of the lookahead.
98ae9643 692 semantic_type yylval;
742e4900 693 /// Location of the lookahead.
98ae9643
AD
694 location_type yylloc;
695 /// The locations where the error started and ended.
0f0e1ace 696 location_type yyerror_range[2];
dbcdae2d 697
98ae9643
AD
698 /// $$.
699 semantic_type yyval;
700 /// @@$.
701 location_type yyloc;
dbcdae2d 702
98ae9643 703 int yyresult;
ad745863 704
98ae9643 705 YYCDEBUG << "Starting parse" << std::endl;
451364ed 706
451364ed 707]m4_ifdef([b4_initial_action], [
99880de5
AD
708m4_pushdef([b4_at_dollar], [yylloc])dnl
709m4_pushdef([b4_dollar_dollar], [yylval])dnl
9d9b8b70 710 /* User initialization code. */
8ec0a172 711 b4_user_initial_action
451364ed 712m4_popdef([b4_dollar_dollar])dnl
8ec0a172 713m4_popdef([b4_at_dollar])])dnl
451364ed 714
98ae9643
AD
715 [ /* Initialize the stacks. The initial state will be pushed in
716 yynewstate, since the latter expects the semantical and the
717 location values to have been already stored, initialize these
718 stacks with a primary value. */
719 yystate_stack_ = state_stack_type (0);
720 yysemantic_stack_ = semantic_stack_type (0);
721 yylocation_stack_ = location_stack_type (0);
7dedf26e 722 yypush_ (yystate, yylval, yylloc);
98ae9643 723
7dedf26e
AD
724 // A new state was pushed on the stack.
725 // Invariant: yystate == yystack_[0].state, i.e.,
726 // yystate was just pushed onto the state stack.
98ae9643 727 yynewstate:
98ae9643 728 YYCDEBUG << "Entering state " << yystate << std::endl;
868d2d96
JD
729
730 /* Accept? */
731 if (yystate == yyfinal_)
732 goto yyacceptlab;
733
98ae9643
AD
734 goto yybackup;
735
736 /* Backup. */
737 yybackup:
738
742e4900 739 /* Try to take a decision without lookahead. */
98ae9643
AD
740 yyn = yypact_[yystate];
741 if (yyn == yypact_ninf_)
742 goto yydefault;
743
742e4900 744 /* Read a lookahead token. */
98ae9643
AD
745 if (yychar == yyempty_)
746 {
02650b7f
PE
747 YYCDEBUG << "Reading a token: ";
748 yychar = ]b4_c_function_call([yylex], [int],
749 [[YYSTYPE*], [&yylval]][]dnl
327afc7c 750b4_locations_if([, [[location*], [&yylloc]]])dnl
dbcdae2d 751m4_ifdef([b4_lex_param], [, ]b4_lex_param))[;
98ae9643
AD
752 }
753
754
755 /* Convert token to internal form. */
756 if (yychar <= yyeof_)
757 {
02650b7f
PE
758 yychar = yytoken = yyeof_;
759 YYCDEBUG << "Now at end of input." << std::endl;
98ae9643
AD
760 }
761 else
762 {
02650b7f 763 yytoken = yytranslate_ (yychar);
c4585f1e 764 YY_SYMBOL_PRINT ("Next token is", yytoken, yylval, yylloc);
98ae9643
AD
765 }
766
767 /* If the proper action on seeing token YYTOKEN is to reduce or to
768 detect an error, take that action. */
769 yyn += yytoken;
34ec3579 770 if (yyn < 0 || yylast_ < yyn || yycheck_[yyn] != yytoken)
98ae9643
AD
771 goto yydefault;
772
773 /* Reduce or error. */
774 yyn = yytable_[yyn];
775 if (yyn <= 0)
776 {
02650b7f
PE
777 if (yyn == 0 || yyn == yytable_ninf_)
778 goto yyerrlab;
779 yyn = -yyn;
780 goto yyreduce;
98ae9643
AD
781 }
782
742e4900 783 /* Shift the lookahead token. */
c4585f1e 784 YY_SYMBOL_PRINT ("Shifting", yytoken, yylval, yylloc);
98ae9643 785
868d2d96
JD
786 /* Discard the token being shifted. */
787 yychar = yyempty_;
98ae9643
AD
788
789 /* Count tokens shifted since error; after three, turn off error
790 status. */
791 if (yyerrstatus_)
792 --yyerrstatus_;
793
794 yystate = yyn;
7dedf26e 795 yypush_ (yystate, yylval, yylloc);
98ae9643
AD
796 goto yynewstate;
797
798 /*-----------------------------------------------------------.
799 | yydefault -- do the default action for the current state. |
800 `-----------------------------------------------------------*/
801 yydefault:
802 yyn = yydefact_[yystate];
803 if (yyn == 0)
804 goto yyerrlab;
805 goto yyreduce;
806
807 /*-----------------------------.
808 | yyreduce -- Do a reduction. |
809 `-----------------------------*/
810 yyreduce:
5ab8c47b
AD
811 yylen = yyr2_[yyn];]b4_variant_if([
812 /* Variants are always initialized to an empty instance of the
813 correct type. The default $$=$1 rule is NOT applied when using
814 variants */
815 ]b4_symbol_variant([[yyr1_@{yyn@}]], [yyval], [build])[],[
a85284cf 816 /* If YYLEN is nonzero, implement the default value of the action:
98ae9643
AD
817 `$$ = $1'. Otherwise, use the top of the stack.
818
819 Otherwise, the following line sets YYVAL to garbage.
820 This behavior is undocumented and Bison
821 users should not rely upon it. */
822 if (yylen)
91ba8a55 823 yyval = yysemantic_stack_@{yylen - 1@};
98ae9643 824 else
5ab8c47b 825 yyval = yysemantic_stack_@{0@};])[
2b548aa6 826
2b548aa6 827 {
98ae9643
AD
828 slice<location_type, location_stack_type> slice (yylocation_stack_, yylen);
829 YYLLOC_DEFAULT (yyloc, slice, yylen);
2b548aa6 830 }
98ae9643
AD
831 YY_REDUCE_PRINT (yyn);
832 switch (yyn)
833 {
8ec0a172 834 ]b4_user_actions[
cf98343c
AD
835 default:
836 break;
98ae9643 837 }
c4585f1e 838 YY_SYMBOL_PRINT ("-> $$ =", yyr1_[yyn], yyval, yyloc);
98ae9643
AD
839
840 yypop_ (yylen);
a85284cf 841 yylen = 0;
98ae9643 842 YY_STACK_PRINT ();
98ae9643
AD
843
844 /* Shift the result of the reduction. */
845 yyn = yyr1_[yyn];
846 yystate = yypgoto_[yyn - yyntokens_] + yystate_stack_[0];
847 if (0 <= yystate && yystate <= yylast_
34ec3579 848 && yycheck_[yystate] == yystate_stack_[0])
98ae9643
AD
849 yystate = yytable_[yystate];
850 else
851 yystate = yydefgoto_[yyn - yyntokens_];
7dedf26e 852 yypush_ (yystate, yyval, yyloc);
98ae9643
AD
853 goto yynewstate;
854
855 /*------------------------------------.
856 | yyerrlab -- here on detecting error |
857 `------------------------------------*/
858 yyerrlab:
859 /* If not already recovering from an error, report this error. */
860 if (!yyerrstatus_)
861 {
02650b7f
PE
862 ++yynerrs_;
863 error (yylloc, yysyntax_error_ (yystate]dnl
d4fb5e3c 864b4_error_verbose_if([, yytoken])[));
98ae9643
AD
865 }
866
867 yyerror_range[0] = yylloc;
868 if (yyerrstatus_ == 3)
869 {
742e4900 870 /* If just tried and failed to reuse lookahead token after an
02650b7f
PE
871 error, discard it. */
872
873 if (yychar <= yyeof_)
874 {
875 /* Return failure if at end of input. */
876 if (yychar == yyeof_)
877 YYABORT;
878 }
879 else
880 {
c4585f1e 881 yydestruct_ ("Error: discarding", yytoken, yylval, yylloc);
02650b7f
PE
882 yychar = yyempty_;
883 }
98ae9643
AD
884 }
885
742e4900 886 /* Else will try to reuse lookahead token after shifting the error
98ae9643
AD
887 token. */
888 goto yyerrlab1;
889
890
891 /*---------------------------------------------------.
892 | yyerrorlab -- error raised explicitly by YYERROR. |
893 `---------------------------------------------------*/
894 yyerrorlab:
895
896 /* Pacify compilers like GCC when the user code never invokes
897 YYERROR and the label yyerrorlab therefore never appears in user
898 code. */
899 if (false)
900 goto yyerrorlab;
901
902 yyerror_range[0] = yylocation_stack_[yylen - 1];
a85284cf 903 /* Do not reclaim the symbols of the rule which action triggered
9d9b8b70 904 this YYERROR. */
98ae9643 905 yypop_ (yylen);
a85284cf 906 yylen = 0;
98ae9643
AD
907 yystate = yystate_stack_[0];
908 goto yyerrlab1;
909
910 /*-------------------------------------------------------------.
911 | yyerrlab1 -- common code for both syntax error and YYERROR. |
912 `-------------------------------------------------------------*/
913 yyerrlab1:
914 yyerrstatus_ = 3; /* Each real token shifted decrements this. */
915
916 for (;;)
917 {
02650b7f
PE
918 yyn = yypact_[yystate];
919 if (yyn != yypact_ninf_)
920 {
921 yyn += yyterror_;
34ec3579 922 if (0 <= yyn && yyn <= yylast_ && yycheck_[yyn] == yyterror_)
02650b7f
PE
923 {
924 yyn = yytable_[yyn];
925 if (0 < yyn)
926 break;
927 }
928 }
929
930 /* Pop the current state because it cannot handle the error token. */
56017c17 931 if (yystate_stack_.size () == 1)
02650b7f
PE
932 YYABORT;
933
934 yyerror_range[0] = yylocation_stack_[0];
935 yydestruct_ ("Error: popping",
936 yystos_[yystate],
c4585f1e 937 yysemantic_stack_[0], yylocation_stack_[0]);
02650b7f
PE
938 yypop_ ();
939 yystate = yystate_stack_[0];
940 YY_STACK_PRINT ();
98ae9643
AD
941 }
942
98ae9643
AD
943 yyerror_range[1] = yylloc;
944 // Using YYLLOC is tempting, but would change the location of
742e4900 945 // the lookahead. YYLOC is available though.
401aace6 946 YYLLOC_DEFAULT (yyloc, (yyerror_range - 1), 2);
98ae9643 947
9d9b8b70 948 /* Shift the error token. */
98ae9643 949 YY_SYMBOL_PRINT ("Shifting", yystos_[yyn],
c4585f1e 950 yysemantic_stack_[0], yylocation_stack_[0]);
98ae9643
AD
951
952 yystate = yyn;
7dedf26e 953 yypush_ (yystate, yylval, yyloc);
98ae9643
AD
954 goto yynewstate;
955
956 /* Accept. */
957 yyacceptlab:
958 yyresult = 0;
959 goto yyreturn;
960
961 /* Abort. */
962 yyabortlab:
963 yyresult = 1;
964 goto yyreturn;
965
966 yyreturn:
868d2d96 967 if (yychar != yyempty_)
c4585f1e 968 yydestruct_ ("Cleanup: discarding lookahead", yytoken, yylval, yylloc);
98ae9643 969
a85284cf 970 /* Do not reclaim the symbols of the rule which action triggered
9d9b8b70 971 this YYABORT or YYACCEPT. */
a85284cf 972 yypop_ (yylen);
56017c17 973 while (yystate_stack_.size () != 1)
98ae9643 974 {
02650b7f 975 yydestruct_ ("Cleanup: popping",
c4585f1e
AD
976 yystos_[yystate_stack_[0]],
977 yysemantic_stack_[0],
978 yylocation_stack_[0]);
02650b7f 979 yypop_ ();
98ae9643
AD
980 }
981
982 return yyresult;
983 }
2b548aa6 984
98ae9643
AD
985 // Generate an error message.
986 std::string
987 ]b4_parser_class_name[::yysyntax_error_ (int yystate]dnl
fb9712a9 988b4_error_verbose_if([, int tok])[)
98ae9643
AD
989 {
990 std::string res;
c66dfadd 991 YYUSE (yystate);
a08460b0 992#if YYERROR_VERBOSE
98ae9643 993 int yyn = yypact_[yystate];
d6645148 994 if (yypact_ninf_ < yyn && yyn <= yylast_)
98ae9643 995 {
02650b7f
PE
996 /* Start YYX at -YYN if negative to avoid negative indexes in
997 YYCHECK. */
998 int yyxbegin = yyn < 0 ? -yyn : 0;
999
1000 /* Stay within bounds of both yycheck and yytname. */
d6645148 1001 int yychecklim = yylast_ - yyn + 1;
02650b7f
PE
1002 int yyxend = yychecklim < yyntokens_ ? yychecklim : yyntokens_;
1003 int count = 0;
1004 for (int x = yyxbegin; x < yyxend; ++x)
34ec3579 1005 if (yycheck_[x + yyn] == x && x != yyterror_)
02650b7f
PE
1006 ++count;
1007
1008 // FIXME: This method of building the message is not compatible
1009 // with internationalization. It should work like yacc.c does it.
1010 // That is, first build a string that looks like this:
1011 // "syntax error, unexpected %s or %s or %s"
1012 // Then, invoke YY_ on this string.
1013 // Finally, use the string as a format to output
1014 // yytname_[tok], etc.
1015 // Until this gets fixed, this message appears in English only.
1016 res = "syntax error, unexpected ";
1017 res += yytnamerr_ (yytname_[tok]);
1018 if (count < 5)
1019 {
1020 count = 0;
1021 for (int x = yyxbegin; x < yyxend; ++x)
34ec3579 1022 if (yycheck_[x + yyn] == x && x != yyterror_)
02650b7f
PE
1023 {
1024 res += (!count++) ? ", expecting " : " or ";
1025 res += yytnamerr_ (yytname_[x]);
1026 }
1027 }
98ae9643
AD
1028 }
1029 else
dbcdae2d 1030#endif
98ae9643
AD
1031 res = YY_("syntax error");
1032 return res;
1033 }
a08460b0 1034
5348bfbe 1035
98ae9643
AD
1036 /* YYPACT[STATE-NUM] -- Index in YYTABLE of the portion describing
1037 STATE-NUM. */
1038 const ]b4_int_type(b4_pact_ninf, b4_pact_ninf) b4_parser_class_name::yypact_ninf_ = b4_pact_ninf[;
1039 const ]b4_int_type_for([b4_pact])[
1040 ]b4_parser_class_name[::yypact_[] =
1041 {
1042 ]b4_pact[
1043 };
2b548aa6 1044
98ae9643
AD
1045 /* YYDEFACT[S] -- default rule to reduce with in state S when YYTABLE
1046 doesn't specify something else to do. Zero means the default is an
1047 error. */
1048 const ]b4_int_type_for([b4_defact])[
1049 ]b4_parser_class_name[::yydefact_[] =
1050 {
1051 ]b4_defact[
1052 };
2b548aa6 1053
98ae9643
AD
1054 /* YYPGOTO[NTERM-NUM]. */
1055 const ]b4_int_type_for([b4_pgoto])[
1056 ]b4_parser_class_name[::yypgoto_[] =
1057 {
1058 ]b4_pgoto[
1059 };
2b548aa6 1060
98ae9643
AD
1061 /* YYDEFGOTO[NTERM-NUM]. */
1062 const ]b4_int_type_for([b4_defgoto])[
1063 ]b4_parser_class_name[::yydefgoto_[] =
1064 {
1065 ]b4_defgoto[
1066 };
2b548aa6 1067
98ae9643
AD
1068 /* YYTABLE[YYPACT[STATE-NUM]]. What to do in state STATE-NUM. If
1069 positive, shift that token. If negative, reduce the rule which
1070 number is the opposite. If zero, do what YYDEFACT says. */
1071 const ]b4_int_type(b4_table_ninf, b4_table_ninf) b4_parser_class_name::yytable_ninf_ = b4_table_ninf[;
1072 const ]b4_int_type_for([b4_table])[
1073 ]b4_parser_class_name[::yytable_[] =
1074 {
1075 ]b4_table[
1076 };
1077
1078 /* YYCHECK. */
1079 const ]b4_int_type_for([b4_check])[
1080 ]b4_parser_class_name[::yycheck_[] =
1081 {
1082 ]b4_check[
1083 };
1084
1085 /* STOS_[STATE-NUM] -- The (internal number of the) accessing
1086 symbol of state STATE-NUM. */
1087 const ]b4_int_type_for([b4_stos])[
1088 ]b4_parser_class_name[::yystos_[] =
1089 {
1090 ]b4_stos[
1091 };
769b430f 1092
45d5982f 1093#if YYDEBUG
98ae9643
AD
1094 /* TOKEN_NUMBER_[YYLEX-NUM] -- Internal symbol number corresponding
1095 to YYLEX-NUM. */
1096 const ]b4_int_type_for([b4_toknum])[
1097 ]b4_parser_class_name[::yytoken_number_[] =
1098 {
1099 ]b4_toknum[
1100 };
769b430f
AD
1101#endif
1102
98ae9643
AD
1103 /* YYR1[YYN] -- Symbol number of symbol that rule YYN derives. */
1104 const ]b4_int_type_for([b4_r1])[
1105 ]b4_parser_class_name[::yyr1_[] =
1106 {
1107 ]b4_r1[
1108 };
2b548aa6 1109
98ae9643
AD
1110 /* YYR2[YYN] -- Number of symbols composing right hand side of rule YYN. */
1111 const ]b4_int_type_for([b4_r2])[
1112 ]b4_parser_class_name[::yyr2_[] =
1113 {
1114 ]b4_r2[
1115 };
2b548aa6 1116
141f5793 1117#if YYDEBUG || YYERROR_VERBOSE || YYTOKEN_TABLE
98ae9643 1118 /* YYTNAME[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM.
9d9b8b70 1119 First, the terminals, then, starting at \a yyntokens_, nonterminals. */
98ae9643
AD
1120 const char*
1121 const ]b4_parser_class_name[::yytname_[] =
1122 {
1123 ]b4_tname[
1124 };
69e2658b 1125#endif
2b548aa6 1126
69e2658b 1127#if YYDEBUG
9d9b8b70 1128 /* YYRHS -- A `-1'-separated list of the rules' RHS. */
98ae9643
AD
1129 const ]b4_parser_class_name[::rhs_number_type
1130 ]b4_parser_class_name[::yyrhs_[] =
1131 {
1132 ]b4_rhs[
1133 };
2b548aa6 1134
98ae9643
AD
1135 /* YYPRHS[YYN] -- Index of the first RHS symbol of rule number YYN in
1136 YYRHS. */
1137 const ]b4_int_type_for([b4_prhs])[
1138 ]b4_parser_class_name[::yyprhs_[] =
1139 {
1140 ]b4_prhs[
1141 };
2b548aa6 1142
98ae9643
AD
1143 /* YYRLINE[YYN] -- Source line where rule number YYN was defined. */
1144 const ]b4_int_type_for([b4_rline])[
1145 ]b4_parser_class_name[::yyrline_[] =
1146 {
1147 ]b4_rline[
1148 };
5348bfbe 1149
98ae9643
AD
1150 // Print the state stack on the debug stream.
1151 void
1152 ]b4_parser_class_name[::yystack_print_ ()
1153 {
1154 *yycdebug_ << "Stack now";
1155 for (state_stack_type::const_iterator i = yystate_stack_.begin ();
02650b7f 1156 i != yystate_stack_.end (); ++i)
98ae9643
AD
1157 *yycdebug_ << ' ' << *i;
1158 *yycdebug_ << std::endl;
1159 }
25f66e1a 1160
98ae9643
AD
1161 // Report on the debug stream that the rule \a yyrule is going to be reduced.
1162 void
d1ff7a7c 1163 ]b4_parser_class_name[::yy_reduce_print_ (int yyrule)
98ae9643
AD
1164 {
1165 unsigned int yylno = yyrline_[yyrule];
d1ff7a7c 1166 int yynrhs = yyr2_[yyrule];
98ae9643
AD
1167 /* Print the symbols being reduced, and their result. */
1168 *yycdebug_ << "Reducing stack by rule " << yyrule - 1
7cff04b5 1169 << " (line " << yylno << "):" << std::endl;
d1ff7a7c
AD
1170 /* The symbols being reduced. */
1171 for (int yyi = 0; yyi < yynrhs; yyi++)
1172 YY_SYMBOL_PRINT (" $" << yyi + 1 << " =",
02650b7f 1173 yyrhs_[yyprhs_[yyrule] + yyi],
c4585f1e
AD
1174 ]b4_rhs_value(yynrhs, yyi + 1)[,
1175 ]b4_rhs_location(yynrhs, yyi + 1)[);
98ae9643 1176 }
5348bfbe 1177#endif // YYDEBUG
69e2658b 1178
98ae9643
AD
1179 /* YYTRANSLATE(YYLEX) -- Bison symbol number corresponding to YYLEX. */
1180 ]b4_parser_class_name[::token_number_type
32c96bd7 1181 ]b4_parser_class_name[::yytranslate_ (int t)
2b548aa6 1182 {
98ae9643
AD
1183 static
1184 const token_number_type
1185 translate_table[] =
1186 {
1187 ]b4_translate[
1188 };
32c96bd7
AD
1189 if ((unsigned int) t <= yyuser_token_number_max_)
1190 return translate_table[t];
98ae9643
AD
1191 else
1192 return yyundef_token_;
1193 }
1194
1195 const int ]b4_parser_class_name[::yyeof_ = 0;
1196 const int ]b4_parser_class_name[::yylast_ = ]b4_last[;
1197 const int ]b4_parser_class_name[::yynnts_ = ]b4_nterms_number[;
1198 const int ]b4_parser_class_name[::yyempty_ = -2;
1199 const int ]b4_parser_class_name[::yyfinal_ = ]b4_final_state_number[;
1200 const int ]b4_parser_class_name[::yyterror_ = 1;
1201 const int ]b4_parser_class_name[::yyerrcode_ = 256;
1202 const int ]b4_parser_class_name[::yyntokens_ = ]b4_tokens_number[;
1203
1204 const unsigned int ]b4_parser_class_name[::yyuser_token_number_max_ = ]b4_user_token_number_max[;
1205 const ]b4_parser_class_name[::token_number_type ]b4_parser_class_name[::yyundef_token_ = ]b4_undef_token_number[;
2b548aa6 1206
793fbca5 1207]b4_namespace_close[
2b548aa6 1208
c5e3e510 1209]b4_epilogue
21846f69 1210dnl
08af01c2 1211@output(b4_dir_prefix[]stack.hh@)
193d7c70 1212b4_copyright([Stack handling for Bison parsers in C++],
cf98343c 1213 [2002, 2003, 2004, 2005, 2006, 2007, 2008])[
98254360 1214
2b548aa6
RA
1215#ifndef BISON_STACK_HH
1216# define BISON_STACK_HH
1217
45119f04 1218#include <deque>
2b548aa6 1219
793fbca5 1220]b4_namespace_open[
f85a5e6f 1221 template <class T, class S = std::deque<T> >
99880de5 1222 class stack
2b548aa6
RA
1223 {
1224 public:
1225
ecfe33e7
AD
1226 // Hide our reversed order.
1227 typedef typename S::reverse_iterator iterator;
1228 typedef typename S::const_reverse_iterator const_iterator;
2b548aa6 1229
99880de5 1230 stack () : seq_ ()
2b548aa6
RA
1231 {
1232 }
1233
99880de5 1234 stack (unsigned int n) : seq_ (n)
2b548aa6
RA
1235 {
1236 }
1237
1238 inline
1239 T&
779e7ceb 1240 operator [] (unsigned int i)
2b548aa6 1241 {
1d4055aa 1242 return seq_[i];
2b548aa6
RA
1243 }
1244
1245 inline
1246 const T&
779e7ceb 1247 operator [] (unsigned int i) const
2b548aa6 1248 {
1d4055aa 1249 return seq_[i];
2b548aa6
RA
1250 }
1251
1252 inline
1253 void
1254 push (const T& t)
1255 {
45119f04 1256 seq_.push_front (t);
2b548aa6
RA
1257 }
1258
1259 inline
1260 void
779e7ceb 1261 pop (unsigned int n = 1)
2b548aa6
RA
1262 {
1263 for (; n; --n)
45119f04 1264 seq_.pop_front ();
2b548aa6
RA
1265 }
1266
762a801e 1267 inline
56017c17
AD
1268 typename S::size_type
1269 size () const
762a801e
RA
1270 {
1271 return seq_.size ();
1272 }
1273
ecfe33e7 1274 inline const_iterator begin () const { return seq_.rbegin (); }
56017c17 1275 inline const_iterator end () const { return seq_.rend (); }
2b548aa6
RA
1276
1277 private:
56017c17 1278 /// The wrapped container.
2b548aa6
RA
1279 S seq_;
1280 };
374f5a14 1281
e019c247 1282 /// Present a slice of the top of a stack.
99880de5
AD
1283 template <class T, class S = stack<T> >
1284 class slice
374f5a14
RA
1285 {
1286 public:
1287
99880de5 1288 slice (const S& stack,
779e7ceb
PE
1289 unsigned int range) : stack_ (stack),
1290 range_ (range)
374f5a14
RA
1291 {
1292 }
1293
1294 inline
1295 const T&
779e7ceb 1296 operator [] (unsigned int i) const
374f5a14 1297 {
1d4055aa 1298 return stack_[range_ - i];
374f5a14
RA
1299 }
1300
1301 private:
1302
1303 const S& stack_;
779e7ceb 1304 unsigned int range_;
374f5a14 1305 };
793fbca5 1306]b4_namespace_close[
2b548aa6 1307
cf98343c
AD
1308#endif // not BISON_STACK_HH[]dnl
1309]
08af01c2 1310m4_divert_pop(0)