]> git.saurik.com Git - bison.git/blame - data/lalr1.cc
Remove spurious empty line before syncline.
[bison.git] / data / lalr1.cc
CommitLineData
60491a94 1# C++ skeleton for Bison
b4721715 2
cf98343c
AD
3# Copyright (C) 2002, 2003, 2004, 2005, 2006, 2007, 2008
4# Free Software Foundation, Inc.
60491a94 5
f16b0819 6# This program is free software: you can redistribute it and/or modify
60491a94 7# it under the terms of the GNU General Public License as published by
f16b0819 8# the Free Software Foundation, either version 3 of the License, or
60491a94 9# (at your option) any later version.
f16b0819 10#
60491a94
AD
11# This program is distributed in the hope that it will be useful,
12# but WITHOUT ANY WARRANTY; without even the implied warranty of
13# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14# GNU General Public License for more details.
f16b0819 15#
60491a94 16# You should have received a copy of the GNU General Public License
f16b0819 17# along with this program. If not, see <http://www.gnu.org/licenses/>.
60491a94 18
cf147260 19m4_include(b4_pkgdatadir/[c++.m4])
7eb8a0bc 20
2ea7730c 21
ba206cf4
AD
22# b4_integral_parser_table_declare(TABLE-NAME, CONTENT, COMMENT)
23# --------------------------------------------------------------
0fddb3d5 24# Declare "parser::yy<TABLE-NAME>_" which contents is CONTENT.
ba206cf4 25m4_define([b4_integral_parser_table_declare],
6ab1adbe
AD
26[m4_ifval([$3], [b4_c_comment([$3], [ ])
27])dnl
28 static const b4_int_type_for([$2]) yy$1_[[]];dnl
0fddb3d5
AD
29])
30
ba206cf4 31# b4_integral_parser_table_define(TABLE-NAME, CONTENT, COMMENT)
0fddb3d5 32# ---------------------------------------------
8901f32e 33# Define "parser::yy<TABLE-NAME>_" which contents is CONTENT.
ba206cf4 34m4_define([b4_integral_parser_table_define],
6ab1adbe 35[ const b4_int_type_for([$2])
8901f32e
AD
36 b4_parser_class_name::yy$1_[[]] =
37 {
38 $2
6ab1adbe
AD
39 };dnl
40])
41
a9ce3f54 42
5de9c593
AD
43# b4_symbol_value_template(VAL, [TYPE])
44# -------------------------------------
45# Same as b4_symbol_value, but used in a template method.
46m4_copy([b4_symbol_value], [b4_symbol_value_template])
47
5ab8c47b
AD
48# How the semantic value is extracted when using variants.
49b4_variant_if([
50 # b4_symbol_value(VAL, [TYPE])
51 # ----------------------------
52 m4_define([b4_symbol_value],
53 [m4_ifval([$2],
cb823b6f 54 [$1.as< $2 >()],
5ab8c47b 55 [$1])])
5de9c593
AD
56
57 # b4_symbol_value_template(VAL, [TYPE])
58 # -------------------------------------
59 # Same as b4_symbol_value, but used in a template method.
60 m4_define([b4_symbol_value_template],
61 [m4_ifval([$2],
cb823b6f 62 [$1.template as< $2 >()],
5de9c593 63 [$1])])
5ab8c47b
AD
64]) # b4_variant_if
65
66
09277875
AD
67# b4_lex_symbol_if([IF-YYLEX-RETURNS-A-COMPLETE-SYMBOL], [IF-NOT])
68# ----------------------------------------------------------------
69m4_define([b4_lex_symbol_if],
70[b4_percent_define_ifdef([[lex_symbol]], [$1], [$2])])
71
72
8901f32e 73# b4_assert_if([IF-ASSERTIONS-ARE-USED], [IF-NOT])
5de9c593 74# ------------------------------------------------
8901f32e
AD
75m4_define([b4_assert_if],
76[b4_percent_define_ifdef([[assert]], [$1], [$2])])
77
78
e1f93869
AD
79# b4_lhs_value([TYPE])
80# --------------------
81# Expansion of $<TYPE>$.
82m4_define([b4_lhs_value],
83[b4_symbol_value([yylhs.value], [$1])])
84
85
86# b4_lhs_location()
87# -----------------
88# Expansion of @$.
89m4_define([b4_lhs_location],
90[yylhs.location])
91
92
33c195cc
AD
93# b4_rhs_data(RULE-LENGTH, NUM)
94# -----------------------------
95# Return the data corresponding to the symbol #NUM, where the current
96# rule has RULE-LENGTH symbols on RHS.
97m4_define([b4_rhs_data],
3204049e 98 [yystack_@{b4_subtract($@)@}])
33c195cc
AD
99
100
101# b4_rhs_state(RULE-LENGTH, NUM)
102# -----------------------------
103# The state corresponding to the symbol #NUM, where the current
104# rule has RULE-LENGTH symbols on RHS.
105m4_define([b4_rhs_state],
106 [b4_rhs_data([$1], [$2]).state])
107
108
8901f32e
AD
109# b4_rhs_value(RULE-LENGTH, NUM, [TYPE])
110# --------------------------------------
111# Expansion of $<TYPE>NUM, where the current rule has RULE-LENGTH
112# symbols on RHS.
113m4_define([b4_rhs_value],
33c195cc
AD
114 [b4_symbol_value([b4_rhs_data([$1], [$2]).value], [$3])])
115
8901f32e
AD
116
117# b4_rhs_location(RULE-LENGTH, NUM)
118# ---------------------------------
119# Expansion of @NUM, where the current rule has RULE-LENGTH symbols
120# on RHS.
121m4_define([b4_rhs_location],
33c195cc 122 [b4_rhs_data([$1], [$2]).location])
8901f32e
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. */
ba206cf4 679]b4_parser_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
ba206cf4
AD
690]b4_integral_parser_table_declare([rline], [b4_rline],
691 [YYRLINE[YYN] -- Source line where rule number YYN was defined.])[
efeed023 692 /// Report on the debug stream that the rule \a r is going to be reduced.
d1ff7a7c 693 virtual void yy_reduce_print_ (int r);
efeed023 694 /// Print the state stack on the debug stream.
f69a4142 695 virtual void yystack_print_ ();
fa7b79c0
PE
696
697 /* Debugging. */
698 int yydebug_;
699 std::ostream* yycdebug_;
69e2658b 700#endif
2b548aa6 701
32c96bd7 702 /// Convert a scanner token number \a t to a symbol number.
1c4af381 703 static inline token_number_type yytranslate_ (]b4_lex_symbol_if([token_type], [int])[ t);
f69a4142 704
1f7d007b 705 /// A complete symbol, with its type.
5de9c593 706 template <typename Exact>
1f7d007b 707 struct symbol_base_type
8901f32e
AD
708 {
709 /// Default constructor.
d3be4f6d 710 inline symbol_base_type ();
8901f32e 711
2ea7730c
AD
712 /// Constructor.]b4_locations_if([
713 inline symbol_base_type (const location_type& l)])[;
714 inline symbol_base_type (]b4_args(
715 [const semantic_type& v],
716 b4_locations_if([const location_type& l]))[);
8901f32e 717
5de9c593
AD
718 /// Return this with its exact type.
719 const Exact& self () const;
720 Exact& self ();
721
1f7d007b 722 /// Return the type of this symbol.
5de9c593 723 int type_get () const;
8901f32e
AD
724
725 /// The semantic value.
2ea7730c 726 semantic_type value;]b4_locations_if([
8901f32e
AD
727
728 /// The location.
2ea7730c 729 location_type location;])[
8901f32e
AD
730 };
731
57295d14 732#if YYDEBUG
1f7d007b
AD
733 /// \brief Display a symbol type, value and location.
734 /// \param yyo The output stream.
735 /// \param yysym The symbol.
5de9c593
AD
736 template <typename Exact>
737 void yy_print_ (std::ostream& yyo,
738 const symbol_base_type<Exact>& yysym) const;
57295d14
AD
739#endif
740
1f7d007b
AD
741 /// \brief Reclaim the memory associated to a symbol.
742 /// \param yymsg Why this token is reclaimed.
743 /// If null, print nothing.
744 /// \param s The symbol.
5de9c593
AD
745 template <typename Exact>
746 inline void yy_destroy_ (const char* yymsg,
747 symbol_base_type<Exact>& yysym) const;
1f7d007b 748
2873fdf8 749 public:
1f7d007b 750 /// Element of the stack: a state and its attributes.
5de9c593 751 struct symbol_type : symbol_base_type<symbol_type>
1f7d007b 752 {
5de9c593
AD
753 /// The parent class.
754 typedef symbol_base_type<symbol_type> super_type;
755
1f7d007b 756 /// Default constructor.
d3be4f6d 757 inline symbol_type ();
1f7d007b
AD
758
759 /// Constructor.
2ea7730c
AD
760 inline symbol_type (]b4_args([int t],
761 [const semantic_type& v],
762 b4_locations_if([const location_type& l]))[);
1f7d007b 763
2ea7730c
AD
764 inline symbol_type (]b4_args([int t],
765 b4_locations_if([const location_type& l]))[);
2873fdf8 766
1f7d007b
AD
767 /// The symbol type.
768 int type;
769
770 /// Return the type corresponding to this state.
5de9c593 771 inline int type_get_ () const;
202598d3
AD
772
773 /// Its token.
774 inline token_type token () const;
1f7d007b
AD
775 };
776
2873fdf8
AD
777]b4_symbol_constructor_declarations[
778
779 private:
1f7d007b 780 /// Element of the stack: a state and its attributes.
5de9c593 781 struct stack_symbol_type : symbol_base_type<stack_symbol_type>
1f7d007b 782 {
5de9c593
AD
783 /// The parent class.
784 typedef symbol_base_type<stack_symbol_type> super_type;
785
1f7d007b 786 /// Default constructor.
d3be4f6d 787 inline stack_symbol_type ();
1f7d007b
AD
788
789 /// Constructor.
2ea7730c
AD
790 inline stack_symbol_type (]b4_args([state_type s],
791 [const semantic_type& v],
792 b4_locations_if([const location_type& l]))[);
1f7d007b
AD
793
794 /// The state.
795 state_type state;
57295d14 796
1f7d007b 797 /// Return the type corresponding to this state.
5de9c593 798 inline int type_get_ () const;
1f7d007b 799 };
57295d14 800
8901f32e 801 /// Stack type.
bc0b0477 802 typedef stack<stack_symbol_type> stack_type;
8901f32e
AD
803
804 /// The stack.
805 stack_type yystack_;
806
7dedf26e 807 /// Push a new state on the stack.
9380cfd0
AD
808 /// \param m a debug message to display
809 /// if null, no trace is output.
e9b0834e
AD
810 /// \param s the symbol
811 /// \warning the contents of \a s.value is stolen.
bc0b0477 812 inline void yypush_ (const char* m, stack_symbol_type& s);
7dedf26e 813
1f7d007b
AD
814 /// Push a new look ahead token on the state on the stack.
815 /// \param m a debug message to display
816 /// if null, no trace is output.
817 /// \param s the state
818 /// \param sym the symbol (for its value and location).
819 /// \warning the contents of \a s.value is stolen.
820 inline void yypush_ (const char* m, state_type s, symbol_type& sym);
821
52d5733f 822 /// Pop \a n symbols the three stacks.
f69a4142 823 inline void yypop_ (unsigned int n = 1);
52d5733f 824
762a801e 825 /* Constants. */
914202bd
AD
826 enum
827 {
828 yyeof_ = 0,
829 yylast_ = ]b4_last[, //< Last index in yytable_.
830 yynnts_ = ]b4_nterms_number[, //< Number of nonterminal symbols.
831 yyempty_ = -2,
832 yyfinal_ = ]b4_final_state_number[, //< Termination state number.
833 yyterror_ = 1,
834 yyerrcode_ = 256,
835 yyntokens_ = ]b4_tokens_number[, //< Number of tokens.
836 };
837
caf37a36 838]b4_parse_param_vars[
2b548aa6 839 };
1c4af381
AD
840
841]b4_lex_symbol_if([b4_yytranslate_definition])[
2c086d29 842]b4_lex_symbol_if([b4_symbol_constructor_definitions])[
793fbca5 843]b4_namespace_close[
2b548aa6 844
592d0b1e 845]b4_percent_define_flag_if([[global_tokens_and_yystype]],
fb9712a9
AD
846[b4_token_defines(b4_tokens)
847
848#ifndef YYSTYPE
9d9b8b70 849 /* Redirection for backward compatibility. */
793fbca5 850# define YYSTYPE b4_namespace_ref::b4_parser_class_name::semantic_type
fb9712a9 851#endif
9bc0dd67 852])
a4e25e1d 853b4_percent_code_get([[provides]])[]dnl
9bc0dd67
JD
854
855[#endif /* ! defined PARSER_HEADER_H */]
a0d4650a 856@output(b4_parser_file_name@)@
a9ce3f54 857b4_copyright([Skeleton implementation for Bison LALR(1) parsers in C++])
a4e25e1d 858b4_percent_code_get([[top]])[]dnl
aa08666d 859m4_if(b4_prefix, [yy], [],
c5b95ccf
AD
860[
861// Take the name prefix into account.
9bc0dd67
JD
862#define yylex b4_prefix[]lex])[
863
864/* First part of user declarations. */
c944f7f2 865]b4_user_pre_prologue[
9bc0dd67 866
c944f7f2 867#include "@basename(]b4_spec_defines_file[@)"
50997c6e 868
fb9712a9 869/* User implementation prologue. */
8e0a5e9e 870]b4_user_post_prologue
a4e25e1d 871b4_percent_code_get[]dnl
fb9712a9 872
8e0a5e9e 873[#ifndef YY_
30757c8c
PE
874# if YYENABLE_NLS
875# if ENABLE_NLS
876# include <libintl.h> /* FIXME: INFRINGES ON USER NAME SPACE */
877# define YY_(msgid) dgettext ("bison-runtime", msgid)
878# endif
879# endif
880# ifndef YY_
881# define YY_(msgid) msgid
882# endif
989b5b8e
AD
883#endif
884
2a4647a3 885/* Suppress unused-variable warnings by "using" E. */
12ce2df6 886#define YYUSE(e) ((void) (e))
2a4647a3 887
2b548aa6 888/* Enable debugging if requested. */
50997c6e 889#if YYDEBUG
284acc8b 890
fa7b79c0
PE
891/* A pseudo ostream that takes yydebug_ into account. */
892# define YYCDEBUG if (yydebug_) (*yycdebug_)
893
1f7d007b 894# define YY_SYMBOL_PRINT(Title, Symbol) \
57295d14
AD
895 do { \
896 if (yydebug_) \
897 { \
898 *yycdebug_ << Title << ' '; \
1f7d007b 899 yy_print_ (*yycdebug_, Symbol); \
57295d14
AD
900 *yycdebug_ << std::endl; \
901 } \
8901f32e 902 } while (false)
284acc8b 903
5348bfbe 904# define YY_REDUCE_PRINT(Rule) \
8901f32e
AD
905 do { \
906 if (yydebug_) \
907 yy_reduce_print_ (Rule); \
908 } while (false)
284acc8b 909
25f66e1a 910# define YY_STACK_PRINT() \
8901f32e
AD
911 do { \
912 if (yydebug_) \
913 yystack_print_ (); \
914 } while (false)
284acc8b 915
2b548aa6 916#else /* !YYDEBUG */
284acc8b 917
a36b333c 918# define YYCDEBUG if (false) std::cerr
1f7d007b
AD
919# define YY_SYMBOL_PRINT(Title, Symbol) static_cast<void>(0)
920# define YY_REDUCE_PRINT(Rule) static_cast<void>(0)
921# define YY_STACK_PRINT() static_cast<void>(0)
284acc8b 922
2b548aa6
RA
923#endif /* !YYDEBUG */
924
39be9022
AD
925#define yyerrok (yyerrstatus_ = 0)
926#define yyclearin (yyempty = true)
98e26a92 927
39be9022
AD
928#define YYACCEPT goto yyacceptlab
929#define YYABORT goto yyabortlab
930#define YYERROR goto yyerrorlab
98e26a92 931#define YYRECOVERING() (!!yyerrstatus_)
60a777aa 932
422c18f4 933]b4_namespace_open[]b4_error_verbose_if([[
9e0876fb 934
aa08666d
AD
935 /* Return YYSTR after stripping away unnecessary quotes and
936 backslashes, so that it's suitable for yyerror. The heuristic is
937 that double-quoting is unnecessary unless the string contains an
938 apostrophe, a comma, or backslash (other than backslash-backslash).
939 YYSTR is taken from yytname. */
940 std::string
941 ]b4_parser_class_name[::yytnamerr_ (const char *yystr)
942 {
943 if (*yystr == '"')
944 {
945 std::string yyr = "";
946 char const *yyp = yystr;
193d7c70 947
aa08666d
AD
948 for (;;)
949 switch (*++yyp)
950 {
951 case '\'':
952 case ',':
953 goto do_not_strip_quotes;
193d7c70 954
aa08666d
AD
955 case '\\':
956 if (*++yyp != '\\')
957 goto do_not_strip_quotes;
958 /* Fall through. */
959 default:
960 yyr += *yyp;
961 break;
193d7c70 962
aa08666d
AD
963 case '"':
964 return yyr;
965 }
966 do_not_strip_quotes: ;
967 }
193d7c70 968
aa08666d
AD
969 return yystr;
970 }
422c18f4 971]])[
9e0876fb 972
98ae9643 973 /// Build a parser object.
fa7b79c0
PE
974 ]b4_parser_class_name::b4_parser_class_name[ (]b4_parse_param_decl[)]m4_ifset([b4_parse_param], [
975 :])[
976#if YYDEBUG
977 ]m4_ifset([b4_parse_param], [ ], [ :])[yydebug_ (false),
978 yycdebug_ (&std::cerr)]m4_ifset([b4_parse_param], [,])[
979#endif]b4_parse_param_cons[
98ae9643
AD
980 {
981 }
a0e68930 982
98ae9643
AD
983 ]b4_parser_class_name::~b4_parser_class_name[ ()
984 {
985 }
a0e68930 986
a0e68930 987
1f7d007b
AD
988 /*---------------.
989 | Symbol types. |
990 `---------------*/
991
2c086d29 992]b4_lex_symbol_if([], [b4_symbol_constructor_definitions])[
2873fdf8 993
1f7d007b
AD
994 // stack_symbol_type.
995 ]b4_parser_class_name[::stack_symbol_type::stack_symbol_type ()
5de9c593
AD
996 : super_type ()
997 , state ()
1f7d007b
AD
998 {
999 }
1000
2ea7730c
AD
1001 ]b4_parser_class_name[::stack_symbol_type::stack_symbol_type (]b4_args(
1002 [state_type s],
1003 [const semantic_type& v],
1004 b4_locations_if([const location_type& l]))[)
1005 : super_type (v]b4_locations_if([, l])[)
5de9c593 1006 , state (s)
1f7d007b
AD
1007 {
1008 }
1009
1010 int
5de9c593 1011 ]b4_parser_class_name[::stack_symbol_type::type_get_ () const
1f7d007b
AD
1012 {
1013 return yystos_[state];
1014 }
1015
1016
5de9c593 1017 template <typename Exact>
98ae9643 1018 void
5de9c593
AD
1019 ]b4_parser_class_name[::yy_destroy_ (const char* yymsg,
1020 symbol_base_type<Exact>& yysym) const
98ae9643 1021 {
1f7d007b 1022 int yytype = yysym.type_get ();
98ae9643 1023 YYUSE (yymsg);
8901f32e 1024 if (yymsg)
1f7d007b 1025 YY_SYMBOL_PRINT (yymsg, yysym);
98ae9643 1026
8901f32e 1027 // User destructor.
98ae9643
AD
1028 switch (yytype)
1029 {
d69c9694 1030]m4_map([b4_symbol_actions], m4_defn([b4_symbol_destructors]))[
02650b7f
PE
1031 default:
1032 break;
8901f32e
AD
1033 }]b4_variant_if([
1034
1035 // Type destructor.
4c3cc7da 1036 b4_symbol_variant([[yytype]], [[yysym.value]], [[template destroy]])])[
8901f32e
AD
1037 }
1038
1f7d007b 1039#if YYDEBUG
5de9c593 1040 template <typename Exact>
1f7d007b 1041 void
5de9c593
AD
1042 ]b4_parser_class_name[::yy_print_ (std::ostream& yyo,
1043 const symbol_base_type<Exact>& yysym) const
8901f32e 1044 {
1f7d007b
AD
1045 int yytype = yysym.type_get ();
1046 yyo << (yytype < yyntokens_ ? "token" : "nterm")
2ea7730c
AD
1047 << ' ' << yytname_[yytype] << " ("]b4_locations_if([
1048 << yysym.location << ": "])[;
1f7d007b
AD
1049 switch (yytype)
1050 {
30bb2edc
AD
1051]m4_map([b4_symbol_actions], m4_defn([b4_symbol_printers]))[
1052 default:
1f7d007b
AD
1053 break;
1054 }
1055 yyo << ')';
8901f32e 1056 }
1f7d007b 1057#endif
8901f32e 1058
1f7d007b
AD
1059 void
1060 ]b4_parser_class_name[::yypush_ (const char* m, state_type s,
1061 symbol_type& sym)
8901f32e 1062 {
1f7d007b
AD
1063 if (m)
1064 YY_SYMBOL_PRINT (m, sym);
1065]b4_variant_if(
2ea7730c
AD
1066[[ yystack_.push (stack_symbol_type (]b4_args(
1067 [s],
1068 [semantic_type()],
1069 b4_locations_if([sym.location]))[));
1f7d007b
AD
1070 ]b4_symbol_variant([[yystos_[s]]], [[yystack_[0].value]],
1071 [build], [sym.value])],
2ea7730c
AD
1072[[ yystack_.push (stack_symbol_type (]b4_args(
1073 [s],
1074 [sym.value],
1075 b4_locations_if([sym.location]))[));]])[
98ae9643 1076 }
60a777aa 1077
7dedf26e 1078 void
bc0b0477 1079 ]b4_parser_class_name[::yypush_ (const char* m, stack_symbol_type& s)
7dedf26e 1080 {
9380cfd0 1081 if (m)
1f7d007b 1082 YY_SYMBOL_PRINT (m, s);
8901f32e 1083]b4_variant_if(
2ea7730c
AD
1084[[ yystack_.push (stack_symbol_type (]b4_args(
1085 [s.state],
1086 [semantic_type()],
1087 b4_locations_if([s.location]))[));
1f7d007b 1088 ]b4_symbol_variant([[yystos_[s.state]]], [[yystack_[0].value]],
e9b0834e
AD
1089 [build], [s.value])],
1090[ yystack_.push (s);])[
7dedf26e
AD
1091 }
1092
98ae9643
AD
1093 void
1094 ]b4_parser_class_name[::yypop_ (unsigned int n)
1095 {
8901f32e 1096 yystack_.pop (n);
98ae9643 1097 }
52d5733f 1098
fa7b79c0 1099#if YYDEBUG
98ae9643
AD
1100 std::ostream&
1101 ]b4_parser_class_name[::debug_stream () const
1102 {
1103 return *yycdebug_;
1104 }
9a1e9989 1105
98ae9643
AD
1106 void
1107 ]b4_parser_class_name[::set_debug_stream (std::ostream& o)
1108 {
1109 yycdebug_ = &o;
1110 }
9a1e9989
AD
1111
1112
98ae9643
AD
1113 ]b4_parser_class_name[::debug_level_type
1114 ]b4_parser_class_name[::debug_level () const
1115 {
1116 return yydebug_;
1117 }
a3cb6248 1118
98ae9643
AD
1119 void
1120 ]b4_parser_class_name[::set_debug_level (debug_level_type l)
1121 {
1122 yydebug_ = l;
1123 }
fa7b79c0 1124#endif
a3cb6248 1125
98ae9643
AD
1126 int
1127 ]b4_parser_class_name[::parse ()
1128 {
39be9022
AD
1129 /// Whether yyla contains a lookahead.
1130 bool yyempty = true;
d4fb5e3c 1131
98ae9643
AD
1132 /* State. */
1133 int yyn;
a85284cf 1134 int yylen = 0;
98ae9643 1135 int yystate = 0;
d4fb5e3c 1136
9d9b8b70 1137 /* Error handling. */
98ae9643
AD
1138 int yynerrs_ = 0;
1139 int yyerrstatus_ = 0;
dbcdae2d 1140
6082531a 1141 /// The lookahead symbol.
2ea7730c 1142 symbol_type yyla;]b4_locations_if([[
6082531a 1143
98ae9643 1144 /// The locations where the error started and ended.
2ea7730c 1145 stack_symbol_type yyerror_range[2];]])[
dbcdae2d 1146
e1f93869 1147 /// $$ and @@$.
bc0b0477 1148 stack_symbol_type yylhs;
dbcdae2d 1149
e1f93869 1150 /// The return value of parse().
98ae9643 1151 int yyresult;
ad745863 1152
98ae9643 1153 YYCDEBUG << "Starting parse" << std::endl;
451364ed 1154
451364ed 1155]m4_ifdef([b4_initial_action], [
6082531a
AD
1156m4_pushdef([b4_at_dollar], [yyla.location])dnl
1157m4_pushdef([b4_dollar_dollar], [yyla.value])dnl
9d9b8b70 1158 /* User initialization code. */
8ec0a172 1159 b4_user_initial_action
451364ed 1160m4_popdef([b4_dollar_dollar])dnl
8ec0a172 1161m4_popdef([b4_at_dollar])])dnl
451364ed 1162
8901f32e 1163 [ /* Initialize the stack. The initial state will be set in
98ae9643
AD
1164 yynewstate, since the latter expects the semantical and the
1165 location values to have been already stored, initialize these
1166 stacks with a primary value. */
8901f32e 1167 yystack_ = stack_type (0);
1f7d007b 1168 yypush_ (0, 0, yyla);
98ae9643 1169
7dedf26e
AD
1170 // A new state was pushed on the stack.
1171 // Invariant: yystate == yystack_[0].state, i.e.,
1172 // yystate was just pushed onto the state stack.
98ae9643 1173 yynewstate:
98ae9643 1174 YYCDEBUG << "Entering state " << yystate << std::endl;
868d2d96
JD
1175
1176 /* Accept? */
1177 if (yystate == yyfinal_)
1178 goto yyacceptlab;
1179
98ae9643
AD
1180 goto yybackup;
1181
1182 /* Backup. */
1183 yybackup:
1184
742e4900 1185 /* Try to take a decision without lookahead. */
98ae9643
AD
1186 yyn = yypact_[yystate];
1187 if (yyn == yypact_ninf_)
1188 goto yydefault;
1189
742e4900 1190 /* Read a lookahead token. */
39be9022 1191 if (yyempty)
98ae9643 1192 {
09277875
AD
1193 YYCDEBUG << "Reading a token: ";
1194]b4_lex_symbol_if(
dd735e4e
AD
1195[ yyla = b4_c_function_call([yylex], [symbol_type],
1196 m4_ifdef([b4_lex_param], b4_lex_param));],
09277875 1197[ yyla.type = yytranslate_ (b4_c_function_call([yylex], [int],
6082531a
AD
1198 [[YYSTYPE*], [&yyla.value]][]dnl
1199b4_locations_if([, [[location*], [&yyla.location]]])dnl
09277875 1200m4_ifdef([b4_lex_param], [, ]b4_lex_param)));])[
39be9022 1201 yyempty = false;
98ae9643 1202 }
aba12ad1 1203 YY_SYMBOL_PRINT ("Next token is", yyla);
98ae9643 1204
1f7d007b
AD
1205 /* If the proper action on seeing token YYLA.TYPE is to reduce or
1206 to detect an error, take that action. */
1207 yyn += yyla.type;
1208 if (yyn < 0 || yylast_ < yyn || yycheck_[yyn] != yyla.type)
98ae9643
AD
1209 goto yydefault;
1210
1211 /* Reduce or error. */
1212 yyn = yytable_[yyn];
1213 if (yyn <= 0)
1214 {
02650b7f 1215 if (yyn == 0 || yyn == yytable_ninf_)
6082531a 1216 goto yyerrlab;
02650b7f
PE
1217 yyn = -yyn;
1218 goto yyreduce;
98ae9643
AD
1219 }
1220
868d2d96 1221 /* Discard the token being shifted. */
39be9022 1222 yyempty = true;
98ae9643
AD
1223
1224 /* Count tokens shifted since error; after three, turn off error
1225 status. */
1226 if (yyerrstatus_)
1227 --yyerrstatus_;
1228
9380cfd0 1229 /* Shift the lookahead token. */
1f7d007b
AD
1230 yystate = yyn;
1231 yypush_ ("Shifting", yystate, yyla);
98ae9643
AD
1232 goto yynewstate;
1233
1234 /*-----------------------------------------------------------.
1235 | yydefault -- do the default action for the current state. |
1236 `-----------------------------------------------------------*/
1237 yydefault:
1238 yyn = yydefact_[yystate];
1239 if (yyn == 0)
1240 goto yyerrlab;
1241 goto yyreduce;
1242
1243 /*-----------------------------.
1244 | yyreduce -- Do a reduction. |
1245 `-----------------------------*/
1246 yyreduce:
5ab8c47b
AD
1247 yylen = yyr2_[yyn];]b4_variant_if([
1248 /* Variants are always initialized to an empty instance of the
1249 correct type. The default $$=$1 rule is NOT applied when using
1250 variants */
e1f93869 1251 ]b4_symbol_variant([[yyr1_@{yyn@}]], [yylhs.value], [build])[],[
a85284cf 1252 /* If YYLEN is nonzero, implement the default value of the action:
98ae9643
AD
1253 `$$ = $1'. Otherwise, use the top of the stack.
1254
e1f93869 1255 Otherwise, the following line sets YYLHS.VALUE to garbage.
98ae9643
AD
1256 This behavior is undocumented and Bison
1257 users should not rely upon it. */
1258 if (yylen)
e1f93869 1259 yylhs.value = yystack_@{yylen - 1@}.value;
98ae9643 1260 else
e1f93869 1261 yylhs.value = yystack_@{0@}.value;])[
2ea7730c
AD
1262]b4_locations_if([dnl
1263[
8901f32e 1264 // Compute the default @@$.
2b548aa6 1265 {
bc0b0477 1266 slice<stack_symbol_type, stack_type> slice (yystack_, yylen);
e1f93869 1267 YYLLOC_DEFAULT (yylhs.location, slice, yylen);
2ea7730c 1268 }]])[
8901f32e
AD
1269
1270 // Perform the reduction.
98ae9643
AD
1271 YY_REDUCE_PRINT (yyn);
1272 switch (yyn)
1273 {
30bb2edc 1274]b4_user_actions[
cf98343c
AD
1275 default:
1276 break;
98ae9643 1277 }
e1f93869
AD
1278 // Compute post-reduction state.
1279 yyn = yyr1_[yyn];
1280 yystate = yypgoto_[yyn - yyntokens_] + yystack_[yylen].state;
1281 if (0 <= yystate && yystate <= yylast_
1282 && yycheck_[yystate] == yystack_[yylen].state)
1283 yystate = yytable_[yystate];
1284 else
1285 yystate = yydefgoto_[yyn - yyntokens_];
1286 yylhs.state = yystate;
1f7d007b 1287 YY_SYMBOL_PRINT ("-> $$ =", yylhs);
8901f32e
AD
1288]b4_variant_if([[
1289 // Destroy the lhs symbols.
1290 for (int i = 0; i < yylen; ++i)
e1f93869
AD
1291 // Destroy a variant which value may have be swapped with
1292 // yylhs.value. The value of yylhs.value (hence maybe one of
1293 // these lhs symbols) depends on what does the default
1294 // contruction for this type. In the case of pointers for
1295 // instance, nothing is done, so the value is junk. Therefore
1296 // do not try to report the content in the debug trace, it's
1297 // junk. Hence yymsg = 0. Besides, that keeps exactly the same
1298 // traces as with the other Bison skeletons.
1f7d007b 1299 yy_destroy_ (0, yystack_[i]);]])[
98ae9643
AD
1300
1301 yypop_ (yylen);
a85284cf 1302 yylen = 0;
98ae9643 1303 YY_STACK_PRINT ();
98ae9643
AD
1304
1305 /* Shift the result of the reduction. */
e9b0834e 1306 yypush_ (0, yylhs);
98ae9643
AD
1307 goto yynewstate;
1308
1309 /*------------------------------------.
1310 | yyerrlab -- here on detecting error |
1311 `------------------------------------*/
1312 yyerrlab:
1313 /* If not already recovering from an error, report this error. */
1314 if (!yyerrstatus_)
1315 {
02650b7f 1316 ++yynerrs_;
2ea7730c
AD
1317 error (]b4_args(b4_locations_if([yyla.location]),
1318 [yysyntax_error_ (yystate, yyla.type)])[);
98ae9643
AD
1319 }
1320
2ea7730c
AD
1321]b4_locations_if([[
1322 yyerror_range[0].location = yyla.location;]])[
98ae9643
AD
1323 if (yyerrstatus_ == 3)
1324 {
742e4900 1325 /* If just tried and failed to reuse lookahead token after an
27cb5b59
AD
1326 error, discard it. */
1327
1328 /* Return failure if at end of input. */
aba12ad1 1329 if (yyla.type == yyeof_)
27cb5b59
AD
1330 YYABORT;
1331 else
39be9022 1332 {
27cb5b59 1333 yy_destroy_ ("Error: discarding", yyla);
39be9022 1334 yyempty = true;
02650b7f 1335 }
98ae9643
AD
1336 }
1337
742e4900 1338 /* Else will try to reuse lookahead token after shifting the error
98ae9643
AD
1339 token. */
1340 goto yyerrlab1;
1341
1342
1343 /*---------------------------------------------------.
1344 | yyerrorlab -- error raised explicitly by YYERROR. |
1345 `---------------------------------------------------*/
1346 yyerrorlab:
1347
1348 /* Pacify compilers like GCC when the user code never invokes
1349 YYERROR and the label yyerrorlab therefore never appears in user
1350 code. */
1351 if (false)
1352 goto yyerrorlab;
1353
2ea7730c
AD
1354]b4_locations_if([[
1355 yyerror_range[0].location = yystack_[yylen - 1].location;]])[
a85284cf 1356 /* Do not reclaim the symbols of the rule which action triggered
9d9b8b70 1357 this YYERROR. */
98ae9643 1358 yypop_ (yylen);
a85284cf 1359 yylen = 0;
8901f32e 1360 yystate = yystack_[0].state;
98ae9643
AD
1361 goto yyerrlab1;
1362
1363 /*-------------------------------------------------------------.
1364 | yyerrlab1 -- common code for both syntax error and YYERROR. |
1365 `-------------------------------------------------------------*/
1366 yyerrlab1:
1367 yyerrstatus_ = 3; /* Each real token shifted decrements this. */
e1f93869 1368 {
bc0b0477 1369 stack_symbol_type error_token;
e1f93869
AD
1370 for (;;)
1371 {
1372 yyn = yypact_[yystate];
1373 if (yyn != yypact_ninf_)
1374 {
1375 yyn += yyterror_;
1376 if (0 <= yyn && yyn <= yylast_ && yycheck_[yyn] == yyterror_)
1377 {
1378 yyn = yytable_[yyn];
1379 if (0 < yyn)
1380 break;
1381 }
1382 }
98ae9643 1383
e1f93869
AD
1384 // Pop the current state because it cannot handle the error token.
1385 if (yystack_.size () == 1)
1386 YYABORT;
2ea7730c
AD
1387]b4_locations_if([[
1388 yyerror_range[0].location = yystack_[0].location;]])[
1f7d007b 1389 yy_destroy_ ("Error: popping", yystack_[0]);
e1f93869
AD
1390 yypop_ ();
1391 yystate = yystack_[0].state;
1392 YY_STACK_PRINT ();
1393 }
2ea7730c 1394]b4_locations_if([[
6082531a 1395 yyerror_range[1].location = yyla.location;
2ea7730c 1396 YYLLOC_DEFAULT (error_token.location, (yyerror_range - 1), 2);]])[
e1f93869
AD
1397
1398 /* Shift the error token. */
e9b0834e
AD
1399 error_token.state = yystate = yyn;
1400 yypush_ ("Shifting", error_token);
e1f93869 1401 }
98ae9643
AD
1402 goto yynewstate;
1403
1404 /* Accept. */
1405 yyacceptlab:
1406 yyresult = 0;
1407 goto yyreturn;
1408
1409 /* Abort. */
1410 yyabortlab:
1411 yyresult = 1;
1412 goto yyreturn;
1413
1414 yyreturn:
39be9022 1415 if (!yyempty)
1f7d007b 1416 yy_destroy_ ("Cleanup: discarding lookahead", yyla);
98ae9643 1417
a85284cf 1418 /* Do not reclaim the symbols of the rule which action triggered
9d9b8b70 1419 this YYABORT or YYACCEPT. */
a85284cf 1420 yypop_ (yylen);
8901f32e 1421 while (yystack_.size () != 1)
98ae9643 1422 {
1f7d007b 1423 yy_destroy_ ("Cleanup: popping", yystack_[0]);
02650b7f 1424 yypop_ ();
98ae9643
AD
1425 }
1426
1427 return yyresult;
1428 }
2b548aa6 1429
98ae9643
AD
1430 // Generate an error message.
1431 std::string
422c18f4
AD
1432 ]b4_parser_class_name[::yysyntax_error_ (]dnl
1433b4_error_verbose_if([int yystate, int yytoken],
1434 [int, int])[)
98ae9643 1435 {
422c18f4 1436 std::string yyres;]b4_error_verbose_if([[
98ae9643 1437 int yyn = yypact_[yystate];
d6645148 1438 if (yypact_ninf_ < yyn && yyn <= yylast_)
98ae9643 1439 {
02650b7f
PE
1440 /* Start YYX at -YYN if negative to avoid negative indexes in
1441 YYCHECK. */
1442 int yyxbegin = yyn < 0 ? -yyn : 0;
1443
1444 /* Stay within bounds of both yycheck and yytname. */
d6645148 1445 int yychecklim = yylast_ - yyn + 1;
02650b7f 1446 int yyxend = yychecklim < yyntokens_ ? yychecklim : yyntokens_;
a0ffc175
AD
1447
1448 // Number of "expected" tokens.
1449 size_t yycount = 0;
1450 // Its maximum.
1451 enum { YYERROR_VERBOSE_ARGS_MAXIMUM = 5 };
1452 // Arguments of yyformat.
1453 char const *yyarg[YYERROR_VERBOSE_ARGS_MAXIMUM];
1454 yyarg[yycount++] = yytname_[yytoken];
1455 for (int yyx = yyxbegin; yyx < yyxend; ++yyx)
1456 if (yycheck_[yyx + yyn] == yyx && yyx != yyterror_)
1457 {
1458 if (yycount == YYERROR_VERBOSE_ARGS_MAXIMUM)
1459 {
1460 yycount = 1;
1461 break;
1462 }
1463 else
1464 yyarg[yycount++] = yytname_[yyx];
1465 }
1466
1467 char const* yyformat = 0;
1468 switch (yycount)
1469 {
1470#define YYCASE_(N, S) \
1471 case N: \
1472 yyformat = S; \
1473 break
1474 YYCASE_(1, YY_("syntax error, unexpected %s"));
1475 YYCASE_(2, YY_("syntax error, unexpected %s, expecting %s"));
1476 YYCASE_(3, YY_("syntax error, unexpected %s, expecting %s or %s"));
1477 YYCASE_(4, YY_("syntax error, unexpected %s, expecting %s or %s or %s"));
1478 YYCASE_(5, YY_("syntax error, unexpected %s, expecting %s or %s or %s or %s"));
1479#undef YYCASE_
1480 }
1481 // Argument number.
1482 size_t yyi = 0;
1483 for (char const* yyp = yyformat; *yyp; ++yyp)
1484 if (yyp[0] == '%' && yyp[1] == 's' && yyi < yycount)
1485 {
1486 yyres += yytnamerr_ (yyarg[yyi++]);
1487 ++yyp;
1488 }
1489 else
1490 yyres += *yyp;
98ae9643
AD
1491 }
1492 else
422c18f4
AD
1493 ]])dnl
1494[ yyres = YY_("syntax error");
a0ffc175 1495 return yyres;
98ae9643 1496 }
a08460b0 1497
5348bfbe 1498
98ae9643 1499 const ]b4_int_type(b4_pact_ninf, b4_pact_ninf) b4_parser_class_name::yypact_ninf_ = b4_pact_ninf[;
2b548aa6 1500
0fddb3d5
AD
1501 const ]b4_int_type(b4_table_ninf, b4_table_ninf) b4_parser_class_name::yytable_ninf_ = b4_table_ninf[;
1502
ba206cf4 1503]b4_parser_tables_define[
2b548aa6 1504
141f5793 1505#if YYDEBUG || YYERROR_VERBOSE || YYTOKEN_TABLE
98ae9643 1506 /* YYTNAME[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM.
9d9b8b70 1507 First, the terminals, then, starting at \a yyntokens_, nonterminals. */
98ae9643
AD
1508 const char*
1509 const ]b4_parser_class_name[::yytname_[] =
1510 {
8901f32e 1511 ]b4_tname[
98ae9643 1512 };
69e2658b 1513#endif
2b548aa6 1514
69e2658b 1515#if YYDEBUG
ba206cf4 1516]b4_integral_parser_table_define([rline], [b4_rline])[
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