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