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