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