]> git.saurik.com Git - bison.git/blame - data/lalr1.cc
Extract stack.hh from lalr1.cc.
[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)
51bacae6 102# ------------------------------
33c195cc
AD
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
fb7c5b1f 135 b4_symbol_case_([$1])
2bde9113
AD
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])])
51bacae6 387m4_include(b4_pkgdatadir/[stack.hh])
a5eb1ed2 388
b526ee61
AD
389# We do want M4 expansion after # for CPP macros.
390m4_changecom()
08af01c2 391m4_divert_push(0)dnl
c944f7f2 392@output(b4_spec_defines_file@)@
a9ce3f54 393b4_copyright([Skeleton interface for Bison LALR(1) parsers in C++])
fb9712a9 394dnl FIXME: This is wrong, we want computed header guards.
8bb4c753 395[
af3412cd
PE
396/* C++ LALR(1) parser skeleton written by Akim Demaille. */
397
c5e3e510
AD
398#ifndef PARSER_HEADER_H
399# define PARSER_HEADER_H
2b548aa6 400
a4e25e1d 401]b4_percent_code_get([[requires]])[
aef3da86 402
8901f32e 403]b4_assert_if([#include <cassert>])[
8d69a1a3 404#include <string>
717be197 405#include <iostream>
fb9712a9 406#include "stack.hh"
50997c6e 407
793fbca5 408]b4_namespace_open[
2ea7730c
AD
409]b4_locations_if([ class position;
410 class location;])[
8901f32e
AD
411]b4_variant_if(
412[[
5ab8c47b
AD
413 /// A char[S] buffer to store and retrieve objects.
414 ///
415 /// Sort of a variant, but does not keep track of the nature
416 /// of the stored data, since that knowledge is available
417 /// via the current state.
418 template <size_t S>
419 struct variant
8901f32e
AD
420 {]b4_assert_if([
421 /// Whether something is contained.
422 bool built;
2873fdf8
AD
423])[
424 /// Empty construction.
425 inline
426 variant ()]b4_assert_if([
427 : built(false)])[
428 {}
8901f32e 429
5ab8c47b
AD
430 /// Instantiate a \a T in here.
431 template <typename T>
8901f32e 432 inline T&
5ab8c47b 433 build()
8901f32e
AD
434 {]b4_assert_if([
435 assert(!built);
436 built = true;])[
253192e6 437 return *new (buffer.raw) T;
5ab8c47b
AD
438 }
439
e5eb92e7
AD
440 /// Instantiate a \a T in here from \a t.
441 template <typename T>
442 inline T&
443 build(const T& t)
444 {]b4_assert_if([
445 assert(!built);
446 built = true;])[
253192e6 447 return *new (buffer.raw) T(t);
e5eb92e7
AD
448 }
449
2873fdf8
AD
450 /// Construct and fill.
451 template <typename T>
452 inline
453 variant (const T& t)]b4_assert_if([
454 : built(true)])[
455 {
253192e6 456 new (buffer.raw) T(t);
2873fdf8
AD
457 }
458
5ab8c47b
AD
459 /// Accessor to a built \a T.
460 template <typename T>
461 inline T&
462 as()
8901f32e
AD
463 {]b4_assert_if([
464 assert(built);])[
253192e6 465 return reinterpret_cast<T&>(buffer.raw);
5ab8c47b
AD
466 }
467
468 /// Const accessor to a built \a T (for %printer).
469 template <typename T>
470 inline const T&
471 as() const
8901f32e
AD
472 {]b4_assert_if([
473 assert(built);])[
253192e6 474 return reinterpret_cast<const T&>(buffer.raw);
5ab8c47b
AD
475 }
476
8901f32e
AD
477 /// Swap the content with \a other.
478 template <typename T>
479 inline void
480 swap(variant<S>& other)
481 {
482 std::swap(as<T>(), other.as<T>());
483 }
484
485 /// Assign the content of \a other to this.
486 /// Destroys \a other.
487 template <typename T>
488 inline void
489 build(variant<S>& other)
490 {
491 build<T>();
492 swap<T>(other);
493 other.destroy<T>();
494 }
495
496 /// Destroy the stored \a T.
497 template <typename T>
498 inline void
499 destroy()
500 {
501 as<T>().~T();]b4_assert_if([
502 built = false;])[
503 }
504
5ab8c47b 505 /// A buffer large enough to store any of the semantic values.
253192e6
ST
506 /// Long double is chosen as it has the strongest alignment
507 /// constraints.
508 union {
509 long double align_me;
510 char raw[S];
511 } buffer;
5ab8c47b
AD
512 };
513]])[
793fbca5 514]b4_namespace_close[
4162fa07 515
2ea7730c 516]b4_locations_if([#include "location.hh"])[
fc695704 517
69e2658b
RA
518/* Enabling traces. */
519#ifndef YYDEBUG
327afc7c 520# define YYDEBUG ]b4_debug_flag[
69e2658b
RA
521#endif
522
141f5793
PE
523/* Enabling verbose error messages. */
524#ifdef YYERROR_VERBOSE
525# undef YYERROR_VERBOSE
526# define YYERROR_VERBOSE 1
527#else
327afc7c 528# define YYERROR_VERBOSE ]b4_error_verbose_flag[
69e2658b
RA
529#endif
530
141f5793
PE
531/* Enabling the token table. */
532#ifndef YYTOKEN_TABLE
533# define YYTOKEN_TABLE ]b4_token_table[
534#endif
535
2ea7730c
AD
536]b4_locations_if([dnl
537[/* YYLLOC_DEFAULT -- Set CURRENT to span from RHS[1] to RHS[N].
b4a20338
AD
538 If N is 0, then set CURRENT to the empty location which ends
539 the previous symbol: RHS[0] (always defined). */
3fc16193 540
374f5a14 541#ifndef YYLLOC_DEFAULT
8901f32e
AD
542# define YYLLOC_DEFAULT(Current, Rhs, N) \
543do { \
544 if (N) \
545 { \
546 (Current).begin = (Rhs)[1].location.begin; \
547 (Current).end = (Rhs)[N].location.end; \
548 } \
549 else \
550 { \
551 (Current).begin = (Current).end = (Rhs)[0].location.end; \
552 } \
2a4647a3 553} while (false)
2ea7730c 554#endif]])[
374f5a14 555
793fbca5 556]b4_namespace_open[
3f3eed27 557
efeed023 558 /// A Bison parser.
07fed891 559 class ]b4_parser_class_name[
2b548aa6 560 {
fb9712a9 561 public:
02650b7f 562#ifndef YYSTYPE
5ab8c47b
AD
563]b4_variant_if(
564[ /// An auxiliary type to compute the largest semantic type.
565 union union_type
e3c52a63 566 {]b4_type_foreach([b4_char_sizeof])[};
5ab8c47b
AD
567
568 /// Symbol semantic values.
569 typedef variant<sizeof(union_type)> semantic_type;],
570[ /// Symbol semantic values.
571m4_ifdef([b4_stype],
1221b78a 572[ union semantic_type
5ab8c47b 573 {b4_user_stype
7ecec4dd 574 };],
ddc8ede1
PE
575[m4_if(b4_tag_seen_flag, 0,
576[[ typedef int semantic_type;]],
5ab8c47b 577[[ typedef YYSTYPE semantic_type;]])])])[
fb9712a9 578#else
f479c6c6 579 typedef YYSTYPE semantic_type;
2ea7730c 580#endif]b4_locations_if([
617a8f12 581 /// Symbol locations.
2ea7730c 582 typedef b4_percent_define_get([[location_type]]) location_type;])[
fb9712a9
AD
583 /// Tokens.
584 struct token
585 {
586 ]b4_token_enums(b4_tokens)[
587 };
c095d689
AD
588 /// Token type.
589 typedef token::yytokentype token_type;
2b548aa6 590
efeed023 591 /// Build a parser object.
98ae9643
AD
592 ]b4_parser_class_name[ (]b4_parse_param_decl[);
593 virtual ~]b4_parser_class_name[ ();
2b548aa6 594
f69a4142
AD
595 /// Parse.
596 /// \returns 0 iff parsing succeeded.
e019c247 597 virtual int parse ();
2b548aa6 598
52cbbe84 599#if YYDEBUG
f69a4142 600 /// The current debugging stream.
9a1e9989
AD
601 std::ostream& debug_stream () const;
602 /// Set the current debugging stream.
603 void set_debug_stream (std::ostream &);
604
a3cb6248
AD
605 /// Type for debugging levels.
606 typedef int debug_level_type;
607 /// The current debugging level.
608 debug_level_type debug_level () const;
609 /// Set the current debugging level.
610 void set_debug_level (debug_level_type l);
52cbbe84 611#endif
a3cb6248 612
2b548aa6 613 private:
2ea7730c
AD
614 /// Report a syntax error.]b4_locations_if([
615 /// \param loc where the syntax error is found.])[
efeed023 616 /// \param msg a description of the syntax error.
2ea7730c 617 virtual void error (]b4_locations_if([const location_type& loc, ])[const std::string& msg);
efeed023 618
dbcdae2d 619 /// Generate an error message.
d4fb5e3c 620 /// \param state the state where the error occurred.
742e4900 621 /// \param tok the lookahead token.
8901f32e 622 virtual std::string yysyntax_error_ (int yystate, int tok);
efeed023 623
e019c247 624 /// State numbers.
f479c6c6 625 typedef int state_type;
2b548aa6 626
e019c247 627 /// Internal symbol numbers.
f479c6c6 628 typedef ]b4_int_type_for([b4_translate])[ token_number_type;
617a8f12 629 static const ]b4_int_type(b4_pact_ninf, b4_pact_ninf)[ yypact_ninf_;
617a8f12 630 static const ]b4_int_type(b4_table_ninf, b4_table_ninf)[ yytable_ninf_;
efeed023 631
0fddb3d5 632 /* Tables. */
ba206cf4 633]b4_parser_tables_declare[
69e2658b 634
141f5793 635#if YYDEBUG || YYERROR_VERBOSE || YYTOKEN_TABLE
efeed023 636 /// For a symbol, its name in clear.
9e0876fb 637 static const char* const yytname_[];
422c18f4 638#endif]b4_error_verbose_if([
9e0876fb 639
9e0876fb 640 /// Convert the symbol name \a n to a form suitable for a diagnostic.
422c18f4 641 static std::string yytnamerr_ (const char *n);])[
2b548aa6 642
69e2658b 643#if YYDEBUG
ba206cf4
AD
644]b4_integral_parser_table_declare([rline], [b4_rline],
645 [YYRLINE[YYN] -- Source line where rule number YYN was defined.])[
efeed023 646 /// Report on the debug stream that the rule \a r is going to be reduced.
d1ff7a7c 647 virtual void yy_reduce_print_ (int r);
efeed023 648 /// Print the state stack on the debug stream.
f69a4142 649 virtual void yystack_print_ ();
fa7b79c0
PE
650
651 /* Debugging. */
652 int yydebug_;
653 std::ostream* yycdebug_;
69e2658b 654#endif
2b548aa6 655
32c96bd7 656 /// Convert a scanner token number \a t to a symbol number.
1c4af381 657 static inline token_number_type yytranslate_ (]b4_lex_symbol_if([token_type], [int])[ t);
f69a4142 658
1f7d007b 659 /// A complete symbol, with its type.
5de9c593 660 template <typename Exact>
1f7d007b 661 struct symbol_base_type
8901f32e
AD
662 {
663 /// Default constructor.
d3be4f6d 664 inline symbol_base_type ();
8901f32e 665
2ea7730c
AD
666 /// Constructor.]b4_locations_if([
667 inline symbol_base_type (const location_type& l)])[;
668 inline symbol_base_type (]b4_args(
669 [const semantic_type& v],
670 b4_locations_if([const location_type& l]))[);
8901f32e 671
5de9c593
AD
672 /// Return this with its exact type.
673 const Exact& self () const;
674 Exact& self ();
675
1f7d007b 676 /// Return the type of this symbol.
5de9c593 677 int type_get () const;
8901f32e
AD
678
679 /// The semantic value.
2ea7730c 680 semantic_type value;]b4_locations_if([
8901f32e
AD
681
682 /// The location.
2ea7730c 683 location_type location;])[
8901f32e
AD
684 };
685
57295d14 686#if YYDEBUG
1f7d007b
AD
687 /// \brief Display a symbol type, value and location.
688 /// \param yyo The output stream.
689 /// \param yysym The symbol.
5de9c593
AD
690 template <typename Exact>
691 void yy_print_ (std::ostream& yyo,
692 const symbol_base_type<Exact>& yysym) const;
57295d14
AD
693#endif
694
1f7d007b
AD
695 /// \brief Reclaim the memory associated to a symbol.
696 /// \param yymsg Why this token is reclaimed.
697 /// If null, print nothing.
698 /// \param s The symbol.
5de9c593
AD
699 template <typename Exact>
700 inline void yy_destroy_ (const char* yymsg,
701 symbol_base_type<Exact>& yysym) const;
1f7d007b 702
2873fdf8 703 public:
1f7d007b 704 /// Element of the stack: a state and its attributes.
5de9c593 705 struct symbol_type : symbol_base_type<symbol_type>
1f7d007b 706 {
5de9c593
AD
707 /// The parent class.
708 typedef symbol_base_type<symbol_type> super_type;
709
1f7d007b 710 /// Default constructor.
d3be4f6d 711 inline symbol_type ();
1f7d007b
AD
712
713 /// Constructor.
2ea7730c
AD
714 inline symbol_type (]b4_args([int t],
715 [const semantic_type& v],
716 b4_locations_if([const location_type& l]))[);
1f7d007b 717
2ea7730c
AD
718 inline symbol_type (]b4_args([int t],
719 b4_locations_if([const location_type& l]))[);
2873fdf8 720
1f7d007b
AD
721 /// The symbol type.
722 int type;
723
724 /// Return the type corresponding to this state.
5de9c593 725 inline int type_get_ () const;
202598d3
AD
726
727 /// Its token.
728 inline token_type token () const;
1f7d007b
AD
729 };
730
2873fdf8
AD
731]b4_symbol_constructor_declarations[
732
733 private:
1f7d007b 734 /// Element of the stack: a state and its attributes.
5de9c593 735 struct stack_symbol_type : symbol_base_type<stack_symbol_type>
1f7d007b 736 {
5de9c593
AD
737 /// The parent class.
738 typedef symbol_base_type<stack_symbol_type> super_type;
739
1f7d007b 740 /// Default constructor.
d3be4f6d 741 inline stack_symbol_type ();
1f7d007b
AD
742
743 /// Constructor.
2ea7730c
AD
744 inline stack_symbol_type (]b4_args([state_type s],
745 [const semantic_type& v],
746 b4_locations_if([const location_type& l]))[);
1f7d007b
AD
747
748 /// The state.
749 state_type state;
57295d14 750
1f7d007b 751 /// Return the type corresponding to this state.
5de9c593 752 inline int type_get_ () const;
1f7d007b 753 };
57295d14 754
8901f32e 755 /// Stack type.
bc0b0477 756 typedef stack<stack_symbol_type> stack_type;
8901f32e
AD
757
758 /// The stack.
759 stack_type yystack_;
760
7dedf26e 761 /// Push a new state on the stack.
9380cfd0
AD
762 /// \param m a debug message to display
763 /// if null, no trace is output.
e9b0834e
AD
764 /// \param s the symbol
765 /// \warning the contents of \a s.value is stolen.
bc0b0477 766 inline void yypush_ (const char* m, stack_symbol_type& s);
7dedf26e 767
1f7d007b
AD
768 /// Push a new look ahead token on the state on the stack.
769 /// \param m a debug message to display
770 /// if null, no trace is output.
771 /// \param s the state
772 /// \param sym the symbol (for its value and location).
773 /// \warning the contents of \a s.value is stolen.
774 inline void yypush_ (const char* m, state_type s, symbol_type& sym);
775
52d5733f 776 /// Pop \a n symbols the three stacks.
f69a4142 777 inline void yypop_ (unsigned int n = 1);
52d5733f 778
762a801e 779 /* Constants. */
914202bd
AD
780 enum
781 {
782 yyeof_ = 0,
783 yylast_ = ]b4_last[, //< Last index in yytable_.
784 yynnts_ = ]b4_nterms_number[, //< Number of nonterminal symbols.
785 yyempty_ = -2,
786 yyfinal_ = ]b4_final_state_number[, //< Termination state number.
787 yyterror_ = 1,
788 yyerrcode_ = 256,
789 yyntokens_ = ]b4_tokens_number[, //< Number of tokens.
790 };
791
caf37a36 792]b4_parse_param_vars[
2b548aa6 793 };
1c4af381
AD
794
795]b4_lex_symbol_if([b4_yytranslate_definition])[
2c086d29 796]b4_lex_symbol_if([b4_symbol_constructor_definitions])[
793fbca5 797]b4_namespace_close[
2b548aa6 798
592d0b1e 799]b4_percent_define_flag_if([[global_tokens_and_yystype]],
fb9712a9
AD
800[b4_token_defines(b4_tokens)
801
802#ifndef YYSTYPE
9d9b8b70 803 /* Redirection for backward compatibility. */
793fbca5 804# define YYSTYPE b4_namespace_ref::b4_parser_class_name::semantic_type
fb9712a9 805#endif
9bc0dd67 806])
a4e25e1d 807b4_percent_code_get([[provides]])[]dnl
9bc0dd67
JD
808
809[#endif /* ! defined PARSER_HEADER_H */]
a0d4650a 810@output(b4_parser_file_name@)@
a9ce3f54 811b4_copyright([Skeleton implementation for Bison LALR(1) parsers in C++])
a4e25e1d 812b4_percent_code_get([[top]])[]dnl
aa08666d 813m4_if(b4_prefix, [yy], [],
c5b95ccf
AD
814[
815// Take the name prefix into account.
9bc0dd67
JD
816#define yylex b4_prefix[]lex])[
817
818/* First part of user declarations. */
c944f7f2 819]b4_user_pre_prologue[
9bc0dd67 820
c944f7f2 821#include "@basename(]b4_spec_defines_file[@)"
50997c6e 822
fb9712a9 823/* User implementation prologue. */
8e0a5e9e 824]b4_user_post_prologue
a4e25e1d 825b4_percent_code_get[]dnl
fb9712a9 826
8e0a5e9e 827[#ifndef YY_
30757c8c
PE
828# if YYENABLE_NLS
829# if ENABLE_NLS
830# include <libintl.h> /* FIXME: INFRINGES ON USER NAME SPACE */
831# define YY_(msgid) dgettext ("bison-runtime", msgid)
832# endif
833# endif
834# ifndef YY_
835# define YY_(msgid) msgid
836# endif
989b5b8e
AD
837#endif
838
2a4647a3 839/* Suppress unused-variable warnings by "using" E. */
12ce2df6 840#define YYUSE(e) ((void) (e))
2a4647a3 841
2b548aa6 842/* Enable debugging if requested. */
50997c6e 843#if YYDEBUG
284acc8b 844
fa7b79c0
PE
845/* A pseudo ostream that takes yydebug_ into account. */
846# define YYCDEBUG if (yydebug_) (*yycdebug_)
847
1f7d007b 848# define YY_SYMBOL_PRINT(Title, Symbol) \
57295d14
AD
849 do { \
850 if (yydebug_) \
851 { \
852 *yycdebug_ << Title << ' '; \
1f7d007b 853 yy_print_ (*yycdebug_, Symbol); \
57295d14
AD
854 *yycdebug_ << std::endl; \
855 } \
8901f32e 856 } while (false)
284acc8b 857
5348bfbe 858# define YY_REDUCE_PRINT(Rule) \
8901f32e
AD
859 do { \
860 if (yydebug_) \
861 yy_reduce_print_ (Rule); \
862 } while (false)
284acc8b 863
25f66e1a 864# define YY_STACK_PRINT() \
8901f32e
AD
865 do { \
866 if (yydebug_) \
867 yystack_print_ (); \
868 } while (false)
284acc8b 869
2b548aa6 870#else /* !YYDEBUG */
284acc8b 871
a36b333c 872# define YYCDEBUG if (false) std::cerr
1f7d007b
AD
873# define YY_SYMBOL_PRINT(Title, Symbol) static_cast<void>(0)
874# define YY_REDUCE_PRINT(Rule) static_cast<void>(0)
875# define YY_STACK_PRINT() static_cast<void>(0)
284acc8b 876
2b548aa6
RA
877#endif /* !YYDEBUG */
878
39be9022
AD
879#define yyerrok (yyerrstatus_ = 0)
880#define yyclearin (yyempty = true)
98e26a92 881
39be9022
AD
882#define YYACCEPT goto yyacceptlab
883#define YYABORT goto yyabortlab
884#define YYERROR goto yyerrorlab
98e26a92 885#define YYRECOVERING() (!!yyerrstatus_)
60a777aa 886
422c18f4 887]b4_namespace_open[]b4_error_verbose_if([[
9e0876fb 888
aa08666d
AD
889 /* Return YYSTR after stripping away unnecessary quotes and
890 backslashes, so that it's suitable for yyerror. The heuristic is
891 that double-quoting is unnecessary unless the string contains an
892 apostrophe, a comma, or backslash (other than backslash-backslash).
893 YYSTR is taken from yytname. */
894 std::string
895 ]b4_parser_class_name[::yytnamerr_ (const char *yystr)
896 {
897 if (*yystr == '"')
898 {
899 std::string yyr = "";
900 char const *yyp = yystr;
193d7c70 901
aa08666d
AD
902 for (;;)
903 switch (*++yyp)
904 {
905 case '\'':
906 case ',':
907 goto do_not_strip_quotes;
193d7c70 908
aa08666d
AD
909 case '\\':
910 if (*++yyp != '\\')
911 goto do_not_strip_quotes;
912 /* Fall through. */
913 default:
914 yyr += *yyp;
915 break;
193d7c70 916
aa08666d
AD
917 case '"':
918 return yyr;
919 }
920 do_not_strip_quotes: ;
921 }
193d7c70 922
aa08666d
AD
923 return yystr;
924 }
422c18f4 925]])[
9e0876fb 926
98ae9643 927 /// Build a parser object.
fa7b79c0
PE
928 ]b4_parser_class_name::b4_parser_class_name[ (]b4_parse_param_decl[)]m4_ifset([b4_parse_param], [
929 :])[
930#if YYDEBUG
931 ]m4_ifset([b4_parse_param], [ ], [ :])[yydebug_ (false),
932 yycdebug_ (&std::cerr)]m4_ifset([b4_parse_param], [,])[
933#endif]b4_parse_param_cons[
98ae9643
AD
934 {
935 }
a0e68930 936
98ae9643
AD
937 ]b4_parser_class_name::~b4_parser_class_name[ ()
938 {
939 }
a0e68930 940
a0e68930 941
1f7d007b
AD
942 /*---------------.
943 | Symbol types. |
944 `---------------*/
945
2c086d29 946]b4_lex_symbol_if([], [b4_symbol_constructor_definitions])[
2873fdf8 947
1f7d007b
AD
948 // stack_symbol_type.
949 ]b4_parser_class_name[::stack_symbol_type::stack_symbol_type ()
5de9c593
AD
950 : super_type ()
951 , state ()
1f7d007b
AD
952 {
953 }
954
2ea7730c
AD
955 ]b4_parser_class_name[::stack_symbol_type::stack_symbol_type (]b4_args(
956 [state_type s],
957 [const semantic_type& v],
958 b4_locations_if([const location_type& l]))[)
959 : super_type (v]b4_locations_if([, l])[)
5de9c593 960 , state (s)
1f7d007b
AD
961 {
962 }
963
964 int
5de9c593 965 ]b4_parser_class_name[::stack_symbol_type::type_get_ () const
1f7d007b
AD
966 {
967 return yystos_[state];
968 }
969
970
5de9c593 971 template <typename Exact>
98ae9643 972 void
5de9c593
AD
973 ]b4_parser_class_name[::yy_destroy_ (const char* yymsg,
974 symbol_base_type<Exact>& yysym) const
98ae9643 975 {
1f7d007b 976 int yytype = yysym.type_get ();
98ae9643 977 YYUSE (yymsg);
8901f32e 978 if (yymsg)
1f7d007b 979 YY_SYMBOL_PRINT (yymsg, yysym);
98ae9643 980
8901f32e 981 // User destructor.
98ae9643
AD
982 switch (yytype)
983 {
e3c52a63 984]b4_symbol_foreach([b4_symbol_destructor])dnl
2bde9113
AD
985[ default:
986 break;
8901f32e
AD
987 }]b4_variant_if([
988
989 // Type destructor.
4c3cc7da 990 b4_symbol_variant([[yytype]], [[yysym.value]], [[template destroy]])])[
8901f32e
AD
991 }
992
1f7d007b 993#if YYDEBUG
5de9c593 994 template <typename Exact>
1f7d007b 995 void
5de9c593
AD
996 ]b4_parser_class_name[::yy_print_ (std::ostream& yyo,
997 const symbol_base_type<Exact>& yysym) const
8901f32e 998 {
1f7d007b
AD
999 int yytype = yysym.type_get ();
1000 yyo << (yytype < yyntokens_ ? "token" : "nterm")
2ea7730c
AD
1001 << ' ' << yytname_[yytype] << " ("]b4_locations_if([
1002 << yysym.location << ": "])[;
1f7d007b
AD
1003 switch (yytype)
1004 {
e3c52a63 1005]b4_symbol_foreach([b4_symbol_printer])dnl
2bde9113 1006[ default:
1f7d007b
AD
1007 break;
1008 }
1009 yyo << ')';
8901f32e 1010 }
1f7d007b 1011#endif
8901f32e 1012
1f7d007b
AD
1013 void
1014 ]b4_parser_class_name[::yypush_ (const char* m, state_type s,
1015 symbol_type& sym)
8901f32e 1016 {
1f7d007b
AD
1017 if (m)
1018 YY_SYMBOL_PRINT (m, sym);
1019]b4_variant_if(
2ea7730c
AD
1020[[ yystack_.push (stack_symbol_type (]b4_args(
1021 [s],
1022 [semantic_type()],
1023 b4_locations_if([sym.location]))[));
1f7d007b
AD
1024 ]b4_symbol_variant([[yystos_[s]]], [[yystack_[0].value]],
1025 [build], [sym.value])],
2ea7730c
AD
1026[[ yystack_.push (stack_symbol_type (]b4_args(
1027 [s],
1028 [sym.value],
1029 b4_locations_if([sym.location]))[));]])[
98ae9643 1030 }
60a777aa 1031
7dedf26e 1032 void
bc0b0477 1033 ]b4_parser_class_name[::yypush_ (const char* m, stack_symbol_type& s)
7dedf26e 1034 {
9380cfd0 1035 if (m)
1f7d007b 1036 YY_SYMBOL_PRINT (m, s);
8901f32e 1037]b4_variant_if(
2ea7730c
AD
1038[[ yystack_.push (stack_symbol_type (]b4_args(
1039 [s.state],
1040 [semantic_type()],
1041 b4_locations_if([s.location]))[));
1f7d007b 1042 ]b4_symbol_variant([[yystos_[s.state]]], [[yystack_[0].value]],
e9b0834e
AD
1043 [build], [s.value])],
1044[ yystack_.push (s);])[
7dedf26e
AD
1045 }
1046
98ae9643
AD
1047 void
1048 ]b4_parser_class_name[::yypop_ (unsigned int n)
1049 {
8901f32e 1050 yystack_.pop (n);
98ae9643 1051 }
52d5733f 1052
fa7b79c0 1053#if YYDEBUG
98ae9643
AD
1054 std::ostream&
1055 ]b4_parser_class_name[::debug_stream () const
1056 {
1057 return *yycdebug_;
1058 }
9a1e9989 1059
98ae9643
AD
1060 void
1061 ]b4_parser_class_name[::set_debug_stream (std::ostream& o)
1062 {
1063 yycdebug_ = &o;
1064 }
9a1e9989
AD
1065
1066
98ae9643
AD
1067 ]b4_parser_class_name[::debug_level_type
1068 ]b4_parser_class_name[::debug_level () const
1069 {
1070 return yydebug_;
1071 }
a3cb6248 1072
98ae9643
AD
1073 void
1074 ]b4_parser_class_name[::set_debug_level (debug_level_type l)
1075 {
1076 yydebug_ = l;
1077 }
fa7b79c0 1078#endif
a3cb6248 1079
98ae9643
AD
1080 int
1081 ]b4_parser_class_name[::parse ()
1082 {
39be9022
AD
1083 /// Whether yyla contains a lookahead.
1084 bool yyempty = true;
d4fb5e3c 1085
98ae9643
AD
1086 /* State. */
1087 int yyn;
a85284cf 1088 int yylen = 0;
98ae9643 1089 int yystate = 0;
d4fb5e3c 1090
9d9b8b70 1091 /* Error handling. */
98ae9643
AD
1092 int yynerrs_ = 0;
1093 int yyerrstatus_ = 0;
dbcdae2d 1094
6082531a 1095 /// The lookahead symbol.
2ea7730c 1096 symbol_type yyla;]b4_locations_if([[
6082531a 1097
98ae9643 1098 /// The locations where the error started and ended.
2ea7730c 1099 stack_symbol_type yyerror_range[2];]])[
dbcdae2d 1100
e1f93869 1101 /// $$ and @@$.
bc0b0477 1102 stack_symbol_type yylhs;
dbcdae2d 1103
e1f93869 1104 /// The return value of parse().
98ae9643 1105 int yyresult;
ad745863 1106
98ae9643 1107 YYCDEBUG << "Starting parse" << std::endl;
451364ed 1108
451364ed 1109]m4_ifdef([b4_initial_action], [
6082531a
AD
1110m4_pushdef([b4_at_dollar], [yyla.location])dnl
1111m4_pushdef([b4_dollar_dollar], [yyla.value])dnl
9d9b8b70 1112 /* User initialization code. */
8ec0a172 1113 b4_user_initial_action
451364ed 1114m4_popdef([b4_dollar_dollar])dnl
8ec0a172 1115m4_popdef([b4_at_dollar])])dnl
451364ed 1116
8901f32e 1117 [ /* Initialize the stack. The initial state will be set in
98ae9643
AD
1118 yynewstate, since the latter expects the semantical and the
1119 location values to have been already stored, initialize these
1120 stacks with a primary value. */
8901f32e 1121 yystack_ = stack_type (0);
1f7d007b 1122 yypush_ (0, 0, yyla);
98ae9643 1123
7dedf26e
AD
1124 // A new state was pushed on the stack.
1125 // Invariant: yystate == yystack_[0].state, i.e.,
1126 // yystate was just pushed onto the state stack.
98ae9643 1127 yynewstate:
98ae9643 1128 YYCDEBUG << "Entering state " << yystate << std::endl;
868d2d96
JD
1129
1130 /* Accept? */
1131 if (yystate == yyfinal_)
1132 goto yyacceptlab;
1133
98ae9643
AD
1134 goto yybackup;
1135
1136 /* Backup. */
1137 yybackup:
1138
742e4900 1139 /* Try to take a decision without lookahead. */
98ae9643
AD
1140 yyn = yypact_[yystate];
1141 if (yyn == yypact_ninf_)
1142 goto yydefault;
1143
742e4900 1144 /* Read a lookahead token. */
39be9022 1145 if (yyempty)
98ae9643 1146 {
09277875
AD
1147 YYCDEBUG << "Reading a token: ";
1148]b4_lex_symbol_if(
dd735e4e
AD
1149[ yyla = b4_c_function_call([yylex], [symbol_type],
1150 m4_ifdef([b4_lex_param], b4_lex_param));],
09277875 1151[ yyla.type = yytranslate_ (b4_c_function_call([yylex], [int],
6082531a
AD
1152 [[YYSTYPE*], [&yyla.value]][]dnl
1153b4_locations_if([, [[location*], [&yyla.location]]])dnl
09277875 1154m4_ifdef([b4_lex_param], [, ]b4_lex_param)));])[
39be9022 1155 yyempty = false;
98ae9643 1156 }
aba12ad1 1157 YY_SYMBOL_PRINT ("Next token is", yyla);
98ae9643 1158
1f7d007b
AD
1159 /* If the proper action on seeing token YYLA.TYPE is to reduce or
1160 to detect an error, take that action. */
1161 yyn += yyla.type;
1162 if (yyn < 0 || yylast_ < yyn || yycheck_[yyn] != yyla.type)
98ae9643
AD
1163 goto yydefault;
1164
1165 /* Reduce or error. */
1166 yyn = yytable_[yyn];
1167 if (yyn <= 0)
1168 {
02650b7f 1169 if (yyn == 0 || yyn == yytable_ninf_)
6082531a 1170 goto yyerrlab;
02650b7f
PE
1171 yyn = -yyn;
1172 goto yyreduce;
98ae9643
AD
1173 }
1174
868d2d96 1175 /* Discard the token being shifted. */
39be9022 1176 yyempty = true;
98ae9643
AD
1177
1178 /* Count tokens shifted since error; after three, turn off error
1179 status. */
1180 if (yyerrstatus_)
1181 --yyerrstatus_;
1182
9380cfd0 1183 /* Shift the lookahead token. */
1f7d007b
AD
1184 yystate = yyn;
1185 yypush_ ("Shifting", yystate, yyla);
98ae9643
AD
1186 goto yynewstate;
1187
1188 /*-----------------------------------------------------------.
1189 | yydefault -- do the default action for the current state. |
1190 `-----------------------------------------------------------*/
1191 yydefault:
1192 yyn = yydefact_[yystate];
1193 if (yyn == 0)
1194 goto yyerrlab;
1195 goto yyreduce;
1196
1197 /*-----------------------------.
1198 | yyreduce -- Do a reduction. |
1199 `-----------------------------*/
1200 yyreduce:
5ab8c47b
AD
1201 yylen = yyr2_[yyn];]b4_variant_if([
1202 /* Variants are always initialized to an empty instance of the
1203 correct type. The default $$=$1 rule is NOT applied when using
1204 variants */
e1f93869 1205 ]b4_symbol_variant([[yyr1_@{yyn@}]], [yylhs.value], [build])[],[
a85284cf 1206 /* If YYLEN is nonzero, implement the default value of the action:
98ae9643
AD
1207 `$$ = $1'. Otherwise, use the top of the stack.
1208
e1f93869 1209 Otherwise, the following line sets YYLHS.VALUE to garbage.
98ae9643
AD
1210 This behavior is undocumented and Bison
1211 users should not rely upon it. */
1212 if (yylen)
e1f93869 1213 yylhs.value = yystack_@{yylen - 1@}.value;
98ae9643 1214 else
e1f93869 1215 yylhs.value = yystack_@{0@}.value;])[
2ea7730c
AD
1216]b4_locations_if([dnl
1217[
8901f32e 1218 // Compute the default @@$.
2b548aa6 1219 {
bc0b0477 1220 slice<stack_symbol_type, stack_type> slice (yystack_, yylen);
e1f93869 1221 YYLLOC_DEFAULT (yylhs.location, slice, yylen);
2ea7730c 1222 }]])[
8901f32e
AD
1223
1224 // Perform the reduction.
98ae9643
AD
1225 YY_REDUCE_PRINT (yyn);
1226 switch (yyn)
1227 {
30bb2edc 1228]b4_user_actions[
cf98343c
AD
1229 default:
1230 break;
98ae9643 1231 }
e1f93869
AD
1232 // Compute post-reduction state.
1233 yyn = yyr1_[yyn];
1234 yystate = yypgoto_[yyn - yyntokens_] + yystack_[yylen].state;
1235 if (0 <= yystate && yystate <= yylast_
1236 && yycheck_[yystate] == yystack_[yylen].state)
1237 yystate = yytable_[yystate];
1238 else
1239 yystate = yydefgoto_[yyn - yyntokens_];
1240 yylhs.state = yystate;
1f7d007b 1241 YY_SYMBOL_PRINT ("-> $$ =", yylhs);
8901f32e
AD
1242]b4_variant_if([[
1243 // Destroy the lhs symbols.
1244 for (int i = 0; i < yylen; ++i)
e1f93869
AD
1245 // Destroy a variant which value may have be swapped with
1246 // yylhs.value. The value of yylhs.value (hence maybe one of
1247 // these lhs symbols) depends on what does the default
1248 // contruction for this type. In the case of pointers for
1249 // instance, nothing is done, so the value is junk. Therefore
1250 // do not try to report the content in the debug trace, it's
1251 // junk. Hence yymsg = 0. Besides, that keeps exactly the same
1252 // traces as with the other Bison skeletons.
1f7d007b 1253 yy_destroy_ (0, yystack_[i]);]])[
98ae9643
AD
1254
1255 yypop_ (yylen);
a85284cf 1256 yylen = 0;
98ae9643 1257 YY_STACK_PRINT ();
98ae9643
AD
1258
1259 /* Shift the result of the reduction. */
e9b0834e 1260 yypush_ (0, yylhs);
98ae9643
AD
1261 goto yynewstate;
1262
1263 /*------------------------------------.
1264 | yyerrlab -- here on detecting error |
1265 `------------------------------------*/
1266 yyerrlab:
1267 /* If not already recovering from an error, report this error. */
1268 if (!yyerrstatus_)
1269 {
02650b7f 1270 ++yynerrs_;
2ea7730c
AD
1271 error (]b4_args(b4_locations_if([yyla.location]),
1272 [yysyntax_error_ (yystate, yyla.type)])[);
98ae9643
AD
1273 }
1274
2ea7730c
AD
1275]b4_locations_if([[
1276 yyerror_range[0].location = yyla.location;]])[
98ae9643
AD
1277 if (yyerrstatus_ == 3)
1278 {
742e4900 1279 /* If just tried and failed to reuse lookahead token after an
27cb5b59
AD
1280 error, discard it. */
1281
1282 /* Return failure if at end of input. */
aba12ad1 1283 if (yyla.type == yyeof_)
27cb5b59
AD
1284 YYABORT;
1285 else
39be9022 1286 {
27cb5b59 1287 yy_destroy_ ("Error: discarding", yyla);
39be9022 1288 yyempty = true;
02650b7f 1289 }
98ae9643
AD
1290 }
1291
742e4900 1292 /* Else will try to reuse lookahead token after shifting the error
98ae9643
AD
1293 token. */
1294 goto yyerrlab1;
1295
1296
1297 /*---------------------------------------------------.
1298 | yyerrorlab -- error raised explicitly by YYERROR. |
1299 `---------------------------------------------------*/
1300 yyerrorlab:
1301
1302 /* Pacify compilers like GCC when the user code never invokes
1303 YYERROR and the label yyerrorlab therefore never appears in user
1304 code. */
1305 if (false)
1306 goto yyerrorlab;
1307
2ea7730c
AD
1308]b4_locations_if([[
1309 yyerror_range[0].location = yystack_[yylen - 1].location;]])[
a85284cf 1310 /* Do not reclaim the symbols of the rule which action triggered
9d9b8b70 1311 this YYERROR. */
98ae9643 1312 yypop_ (yylen);
a85284cf 1313 yylen = 0;
8901f32e 1314 yystate = yystack_[0].state;
98ae9643
AD
1315 goto yyerrlab1;
1316
1317 /*-------------------------------------------------------------.
1318 | yyerrlab1 -- common code for both syntax error and YYERROR. |
1319 `-------------------------------------------------------------*/
1320 yyerrlab1:
1321 yyerrstatus_ = 3; /* Each real token shifted decrements this. */
e1f93869 1322 {
bc0b0477 1323 stack_symbol_type error_token;
e1f93869
AD
1324 for (;;)
1325 {
1326 yyn = yypact_[yystate];
1327 if (yyn != yypact_ninf_)
1328 {
1329 yyn += yyterror_;
1330 if (0 <= yyn && yyn <= yylast_ && yycheck_[yyn] == yyterror_)
1331 {
1332 yyn = yytable_[yyn];
1333 if (0 < yyn)
1334 break;
1335 }
1336 }
98ae9643 1337
e1f93869
AD
1338 // Pop the current state because it cannot handle the error token.
1339 if (yystack_.size () == 1)
1340 YYABORT;
2ea7730c
AD
1341]b4_locations_if([[
1342 yyerror_range[0].location = yystack_[0].location;]])[
1f7d007b 1343 yy_destroy_ ("Error: popping", yystack_[0]);
e1f93869
AD
1344 yypop_ ();
1345 yystate = yystack_[0].state;
1346 YY_STACK_PRINT ();
1347 }
2ea7730c 1348]b4_locations_if([[
6082531a 1349 yyerror_range[1].location = yyla.location;
2ea7730c 1350 YYLLOC_DEFAULT (error_token.location, (yyerror_range - 1), 2);]])[
e1f93869
AD
1351
1352 /* Shift the error token. */
e9b0834e
AD
1353 error_token.state = yystate = yyn;
1354 yypush_ ("Shifting", error_token);
e1f93869 1355 }
98ae9643
AD
1356 goto yynewstate;
1357
1358 /* Accept. */
1359 yyacceptlab:
1360 yyresult = 0;
1361 goto yyreturn;
1362
1363 /* Abort. */
1364 yyabortlab:
1365 yyresult = 1;
1366 goto yyreturn;
1367
1368 yyreturn:
39be9022 1369 if (!yyempty)
1f7d007b 1370 yy_destroy_ ("Cleanup: discarding lookahead", yyla);
98ae9643 1371
a85284cf 1372 /* Do not reclaim the symbols of the rule which action triggered
9d9b8b70 1373 this YYABORT or YYACCEPT. */
a85284cf 1374 yypop_ (yylen);
8901f32e 1375 while (yystack_.size () != 1)
98ae9643 1376 {
1f7d007b 1377 yy_destroy_ ("Cleanup: popping", yystack_[0]);
02650b7f 1378 yypop_ ();
98ae9643
AD
1379 }
1380
1381 return yyresult;
1382 }
2b548aa6 1383
98ae9643
AD
1384 // Generate an error message.
1385 std::string
422c18f4
AD
1386 ]b4_parser_class_name[::yysyntax_error_ (]dnl
1387b4_error_verbose_if([int yystate, int yytoken],
1388 [int, int])[)
98ae9643 1389 {
422c18f4 1390 std::string yyres;]b4_error_verbose_if([[
98ae9643 1391 int yyn = yypact_[yystate];
d6645148 1392 if (yypact_ninf_ < yyn && yyn <= yylast_)
98ae9643 1393 {
02650b7f
PE
1394 /* Start YYX at -YYN if negative to avoid negative indexes in
1395 YYCHECK. */
1396 int yyxbegin = yyn < 0 ? -yyn : 0;
1397
1398 /* Stay within bounds of both yycheck and yytname. */
d6645148 1399 int yychecklim = yylast_ - yyn + 1;
02650b7f 1400 int yyxend = yychecklim < yyntokens_ ? yychecklim : yyntokens_;
a0ffc175 1401
eeb29422
AD
1402 // Number of reported tokens (one for the "unexpected", one per
1403 // "expected").
a0ffc175
AD
1404 size_t yycount = 0;
1405 // Its maximum.
1406 enum { YYERROR_VERBOSE_ARGS_MAXIMUM = 5 };
1407 // Arguments of yyformat.
1408 char const *yyarg[YYERROR_VERBOSE_ARGS_MAXIMUM];
1409 yyarg[yycount++] = yytname_[yytoken];
1410 for (int yyx = yyxbegin; yyx < yyxend; ++yyx)
1411 if (yycheck_[yyx + yyn] == yyx && yyx != yyterror_)
1412 {
1413 if (yycount == YYERROR_VERBOSE_ARGS_MAXIMUM)
1414 {
1415 yycount = 1;
1416 break;
1417 }
1418 else
1419 yyarg[yycount++] = yytname_[yyx];
1420 }
1421
1422 char const* yyformat = 0;
1423 switch (yycount)
1424 {
1425#define YYCASE_(N, S) \
1426 case N: \
1427 yyformat = S; \
1428 break
1429 YYCASE_(1, YY_("syntax error, unexpected %s"));
1430 YYCASE_(2, YY_("syntax error, unexpected %s, expecting %s"));
1431 YYCASE_(3, YY_("syntax error, unexpected %s, expecting %s or %s"));
1432 YYCASE_(4, YY_("syntax error, unexpected %s, expecting %s or %s or %s"));
1433 YYCASE_(5, YY_("syntax error, unexpected %s, expecting %s or %s or %s or %s"));
1434#undef YYCASE_
1435 }
1436 // Argument number.
1437 size_t yyi = 0;
1438 for (char const* yyp = yyformat; *yyp; ++yyp)
1439 if (yyp[0] == '%' && yyp[1] == 's' && yyi < yycount)
1440 {
1441 yyres += yytnamerr_ (yyarg[yyi++]);
1442 ++yyp;
1443 }
1444 else
1445 yyres += *yyp;
98ae9643
AD
1446 }
1447 else
422c18f4
AD
1448 ]])dnl
1449[ yyres = YY_("syntax error");
a0ffc175 1450 return yyres;
98ae9643 1451 }
a08460b0 1452
5348bfbe 1453
98ae9643 1454 const ]b4_int_type(b4_pact_ninf, b4_pact_ninf) b4_parser_class_name::yypact_ninf_ = b4_pact_ninf[;
2b548aa6 1455
0fddb3d5
AD
1456 const ]b4_int_type(b4_table_ninf, b4_table_ninf) b4_parser_class_name::yytable_ninf_ = b4_table_ninf[;
1457
ba206cf4 1458]b4_parser_tables_define[
2b548aa6 1459
141f5793 1460#if YYDEBUG || YYERROR_VERBOSE || YYTOKEN_TABLE
98ae9643 1461 /* YYTNAME[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM.
9d9b8b70 1462 First, the terminals, then, starting at \a yyntokens_, nonterminals. */
98ae9643
AD
1463 const char*
1464 const ]b4_parser_class_name[::yytname_[] =
1465 {
8901f32e 1466 ]b4_tname[
98ae9643 1467 };
69e2658b 1468#endif
2b548aa6 1469
69e2658b 1470#if YYDEBUG
ba206cf4 1471]b4_integral_parser_table_define([rline], [b4_rline])[
5348bfbe 1472
98ae9643
AD
1473 // Print the state stack on the debug stream.
1474 void
1475 ]b4_parser_class_name[::yystack_print_ ()
1476 {
1477 *yycdebug_ << "Stack now";
8901f32e
AD
1478 for (stack_type::const_iterator
1479 i = yystack_.begin (),
1480 i_end = yystack_.end ();
1481 i != i_end; ++i)
1482 *yycdebug_ << ' ' << i->state;
98ae9643
AD
1483 *yycdebug_ << std::endl;
1484 }
25f66e1a 1485
98ae9643
AD
1486 // Report on the debug stream that the rule \a yyrule is going to be reduced.
1487 void
d1ff7a7c 1488 ]b4_parser_class_name[::yy_reduce_print_ (int yyrule)
98ae9643
AD
1489 {
1490 unsigned int yylno = yyrline_[yyrule];
d1ff7a7c 1491 int yynrhs = yyr2_[yyrule];
98ae9643
AD
1492 /* Print the symbols being reduced, and their result. */
1493 *yycdebug_ << "Reducing stack by rule " << yyrule - 1
7cff04b5 1494 << " (line " << yylno << "):" << std::endl;
d1ff7a7c
AD
1495 /* The symbols being reduced. */
1496 for (int yyi = 0; yyi < yynrhs; yyi++)
1497 YY_SYMBOL_PRINT (" $" << yyi + 1 << " =",
1f7d007b 1498 ]b4_rhs_data(yynrhs, yyi + 1)[);
98ae9643 1499 }
5348bfbe 1500#endif // YYDEBUG
69e2658b 1501
1c4af381 1502]b4_lex_symbol_if([], [b4_yytranslate_definition])[
793fbca5 1503]b4_namespace_close[
8901f32e 1504]b4_epilogue[]dnl
08af01c2 1505m4_divert_pop(0)
a9ce3f54 1506m4_popdef([b4_copyright_years])dnl