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