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