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