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