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