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