]> git.saurik.com Git - bison.git/blame - data/lalr1.cc
* tests/cxx-type.at: Construct a tree, count the parents of shared
[bison.git] / data / lalr1.cc
CommitLineData
a75c057f 1m4_divert(-1)
b4721715 2
60491a94 3# C++ skeleton for Bison
b4721715
PE
4
5# Copyright (C) 2002, 2003, 2004, 2005 Free Software Foundation, Inc.
60491a94
AD
6
7# This program is free software; you can redistribute it and/or modify
8# it under the terms of the GNU General Public License as published by
9# the Free Software Foundation; either version 2 of the License, or
10# (at your option) any later version.
11
12# This program is distributed in the hope that it will be useful,
13# but WITHOUT ANY WARRANTY; without even the implied warranty of
14# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15# GNU General Public License for more details.
16
17# You should have received a copy of the GNU General Public License
18# along with this program; if not, write to the Free Software
0fb669f9
PE
19# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
20# 02110-1301 USA
60491a94 21
cf147260 22m4_include(b4_pkgdatadir/[c++.m4])
4626a15d
AD
23# Backward compatibility.
24m4_define([b4_location_constructors])
fc695704 25m4_include(b4_pkgdatadir/[location.cc])
a5eb1ed2 26
b526ee61
AD
27# We do want M4 expansion after # for CPP macros.
28m4_changecom()
98254360 29m4_divert(0)dnl
b61c6978
PE
30m4_if(b4_defines_flag, 0, [],
31[@output @output_header_name@
fb8135fa 32b4_copyright([C++ Skeleton parser for LALR(1) parsing with Bison],
fb9712a9
AD
33 [2002, 2003, 2004, 2005])
34dnl FIXME: This is wrong, we want computed header guards.
af3412cd
PE
35[/* As a special exception, when this parser skeleton is copied by
36 Bison into a Bison output file, you may use that output file
37 without restriction. This special exception was added by the Free
38 Software Foundation for C++ LALR(1) parsers in version 2.2 of
39 Bison. */
40
41/* C++ LALR(1) parser skeleton written by Akim Demaille. */
42
c5e3e510
AD
43#ifndef PARSER_HEADER_H
44# define PARSER_HEADER_H
2b548aa6 45
8d69a1a3 46#include <string>
717be197 47#include <iostream>
fb9712a9 48#include "stack.hh"
50997c6e 49
fc695704
AD
50namespace yy
51{
52 class position;
53 class location;
54}
4162fa07 55
fb9712a9 56/* First part of user declarations. */
c5e3e510 57]b4_pre_prologue[
4162fa07 58
996b1c7e 59]/* Line __line__ of lalr1.cc. */
c5e3e510 60b4_syncline([@oline@], [@ofile@])[
e96c9728 61
fc695704
AD
62]dnl Include location.hh here: it might depend on headers included above.
63[#include "location.hh"
64
69e2658b
RA
65/* Enabling traces. */
66#ifndef YYDEBUG
c5e3e510 67# define YYDEBUG ]b4_debug[
69e2658b
RA
68#endif
69
141f5793
PE
70/* Enabling verbose error messages. */
71#ifdef YYERROR_VERBOSE
72# undef YYERROR_VERBOSE
73# define YYERROR_VERBOSE 1
74#else
c5e3e510 75# define YYERROR_VERBOSE ]b4_error_verbose[
69e2658b
RA
76#endif
77
141f5793
PE
78/* Enabling the token table. */
79#ifndef YYTOKEN_TABLE
80# define YYTOKEN_TABLE ]b4_token_table[
81#endif
82
b4a20338
AD
83/* YYLLOC_DEFAULT -- Set CURRENT to span from RHS[1] to RHS[N].
84 If N is 0, then set CURRENT to the empty location which ends
85 the previous symbol: RHS[0] (always defined). */
3fc16193 86
374f5a14 87#ifndef YYLLOC_DEFAULT
b4a20338
AD
88# define YYLLOC_DEFAULT(Current, Rhs, N) \
89do { \
90 if (N) \
91 { \
92 (Current).begin = (Rhs)[1].begin; \
93 (Current).end = (Rhs)[N].end; \
94 } \
95 else \
96 { \
97 (Current).begin = (Current).end = (Rhs)[0].end; \
98 } \
2a4647a3 99} while (false)
374f5a14
RA
100#endif
101
2b548aa6
RA
102namespace yy
103{
3f3eed27 104
efeed023 105 /// A Bison parser.
07fed891 106 class ]b4_parser_class_name[
2b548aa6 107 {
fb9712a9 108 public:
617a8f12 109 /// Symbol semantic values.
fb9712a9
AD
110#if ! defined (YYSTYPE)
111]m4_ifdef([b4_stype],
112[b4_syncline([b4_stype_line], [b4_file_name])
113 union semantic_type b4_stype;
114/* Line __line__ of lalr1.cc. */
115b4_syncline([@oline@], [@ofile@])],
116[ typedef int semantic_type;])[
117#else
f479c6c6 118 typedef YYSTYPE semantic_type;
fb9712a9 119#endif
617a8f12 120 /// Symbol locations.
f479c6c6 121 typedef ]b4_location_type[ location_type;
fb9712a9
AD
122 /// Tokens.
123 struct token
124 {
125 ]b4_token_enums(b4_tokens)[
126 };
2b548aa6 127
efeed023 128 /// Build a parser object.
98ae9643
AD
129 ]b4_parser_class_name[ (]b4_parse_param_decl[);
130 virtual ~]b4_parser_class_name[ ();
2b548aa6 131
f69a4142
AD
132 /// Parse.
133 /// \returns 0 iff parsing succeeded.
e019c247 134 virtual int parse ();
2b548aa6 135
f69a4142 136 /// The current debugging stream.
9a1e9989
AD
137 std::ostream& debug_stream () const;
138 /// Set the current debugging stream.
139 void set_debug_stream (std::ostream &);
140
a3cb6248
AD
141 /// Type for debugging levels.
142 typedef int debug_level_type;
143 /// The current debugging level.
144 debug_level_type debug_level () const;
145 /// Set the current debugging level.
146 void set_debug_level (debug_level_type l);
147
2b548aa6 148 private:
efeed023
AD
149 /// Report a syntax error.
150 /// \param loc where the syntax error is found.
151 /// \param msg a description of the syntax error.
99880de5 152 virtual void error (const location_type& loc, const std::string& msg);
efeed023 153
dbcdae2d 154 /// Generate an error message.
d4fb5e3c
AD
155 /// \param state the state where the error occurred.
156 /// \param tok the look-ahead token.
157 virtual std::string yysyntax_error_ (int yystate]dnl
158b4_error_verbose_if([, int tok])[);
efeed023 159
a5eb1ed2 160#if YYDEBUG
f69a4142
AD
161 /// \brief Report a symbol on the debug stream.
162 /// \param yytype The token type.
163 /// \param yyvaluep Its semantic value.
164 /// \param yylocationp Its location.
165 virtual void yysymprint_ (int yytype,
99880de5
AD
166 const semantic_type* yyvaluep,
167 const location_type* yylocationp);
a5eb1ed2
AD
168#endif /* ! YYDEBUG */
169
4bb2bc3f 170
e019c247 171 /// State numbers.
f479c6c6 172 typedef int state_type;
e019c247
AD
173 /// State stack type.
174 typedef stack<state_type> state_stack_type;
175 /// Semantic value stack type.
176 typedef stack<semantic_type> semantic_stack_type;
177 /// location stack type.
178 typedef stack<location_type> location_stack_type;
179
f69a4142 180 /// The state stack.
e019c247 181 state_stack_type yystate_stack_;
f69a4142 182 /// The semantic value stack.
e019c247 183 semantic_stack_type yysemantic_stack_;
f69a4142 184 /// The location stack.
e019c247 185 location_stack_type yylocation_stack_;
2b548aa6 186
e019c247 187 /// Internal symbol numbers.
f479c6c6 188 typedef ]b4_int_type_for([b4_translate])[ token_number_type;
2b548aa6 189 /* Tables. */
efeed023 190 /// For a state, the index in \a yytable_ of its portion.
617a8f12
AD
191 static const ]b4_int_type_for([b4_pact])[ yypact_[];
192 static const ]b4_int_type(b4_pact_ninf, b4_pact_ninf)[ yypact_ninf_;
efeed023
AD
193
194 /// For a state, default rule to reduce.
195 /// Unless\a yytable_ specifies something else to do.
196 /// Zero means the default is an error.
617a8f12 197 static const ]b4_int_type_for([b4_defact])[ yydefact_[];
efeed023 198
617a8f12
AD
199 static const ]b4_int_type_for([b4_pgoto])[ yypgoto_[];
200 static const ]b4_int_type_for([b4_defgoto])[ yydefgoto_[];
efeed023
AD
201
202 /// What to do in a state.
203 /// \a yytable_[yypact_[s]]: what to do in state \a s.
204 /// - if positive, shift that token.
205 /// - if negative, reduce the rule which number is the opposite.
206 /// - if zero, do what YYDEFACT says.
617a8f12
AD
207 static const ]b4_int_type_for([b4_table])[ yytable_[];
208 static const ]b4_int_type(b4_table_ninf, b4_table_ninf)[ yytable_ninf_;
efeed023 209
617a8f12 210 static const ]b4_int_type_for([b4_check])[ yycheck_[];
efeed023
AD
211
212 /// For a state, its accessing symbol.
617a8f12 213 static const ]b4_int_type_for([b4_stos])[ yystos_[];
efeed023
AD
214
215 /// For a rule, its LHS.
617a8f12 216 static const ]b4_int_type_for([b4_r1])[ yyr1_[];
efeed023 217 /// For a rule, its RHS length.
617a8f12 218 static const ]b4_int_type_for([b4_r2])[ yyr2_[];
69e2658b 219
141f5793 220#if YYDEBUG || YYERROR_VERBOSE || YYTOKEN_TABLE
efeed023 221 /// For a symbol, its name in clear.
9e0876fb
PE
222 static const char* const yytname_[];
223#endif
224
225#if YYERROR_VERBOSE
226 /// Convert the symbol name \a n to a form suitable for a diagnostic.
227 virtual std::string yytnamerr_ (const char *n);
69e2658b 228#endif
2b548aa6 229
69e2658b 230#if YYDEBUG
e019c247 231 /// A type to store symbol numbers and -1.
f479c6c6 232 typedef ]b4_int_type_for([b4_rhs])[ rhs_number_type;
617a8f12 233 /// A `-1'-separated list of the rules' RHS.
99880de5 234 static const rhs_number_type yyrhs_[];
617a8f12
AD
235 /// For each rule, the index of the first RHS symbol in \a yyrhs_.
236 static const ]b4_int_type_for([b4_prhs])[ yyprhs_[];
237 /// For each rule, its source line number.
238 static const ]b4_int_type_for([b4_rline])[ yyrline_[];
239 /// For each scanner token number, its symbol number.
240 static const ]b4_int_type_for([b4_toknum])[ yytoken_number_[];
efeed023 241 /// Report on the debug stream that the rule \a r is going to be reduced.
d1ff7a7c 242 virtual void yy_reduce_print_ (int r);
efeed023 243 /// Print the state stack on the debug stream.
f69a4142 244 virtual void yystack_print_ ();
69e2658b 245#endif
2b548aa6 246
f69a4142 247 /// Convert a scanner token number to a symbol number.
99880de5 248 inline token_number_type yytranslate_ (int token);
f69a4142
AD
249
250 /// \brief Reclaim the memory associated to a symbol.
251 /// \param yymsg Why this token is reclaimed.
252 /// \param yytype The symbol type.
253 /// \param yyvaluep Its semantic value.
254 /// \param yylocationp Its location.
255 inline void yydestruct_ (const char* yymsg,
256 int yytype,
99880de5
AD
257 semantic_type* yyvaluep,
258 location_type* yylocationp);
2b548aa6 259
52d5733f 260 /// Pop \a n symbols the three stacks.
f69a4142 261 inline void yypop_ (unsigned int n = 1);
52d5733f 262
762a801e 263 /* Constants. */
617a8f12 264 static const int yyeof_;
39912f52 265 /* LAST_ -- Last index in TABLE_. */
617a8f12
AD
266 static const int yylast_;
267 static const int yynnts_;
268 static const int yyempty_;
269 static const int yyfinal_;
270 static const int yyterror_;
271 static const int yyerrcode_;
272 static const int yyntokens_;
273 static const unsigned int yyuser_token_number_max_;
99880de5 274 static const token_number_type yyundef_token_;
2b548aa6 275
717be197 276 /* Debugging. */
a3cb6248 277 int yydebug_;
9a1e9989 278 std::ostream* yycdebug_;
717be197 279
caf37a36 280]b4_parse_param_vars[
2b548aa6
RA
281 };
282}
283
fb9712a9
AD
284]m4_ifset([b4_global_tokens_and_yystype],
285[b4_token_defines(b4_tokens)
286
287#ifndef YYSTYPE
288 /* Redirection for backward compatibility. */
289# define YYSTYPE yy::b4_parser_class_name::semantic_type
290#endif
291])[
c5e3e510 292#endif /* ! defined PARSER_HEADER_H */]
b61c6978 293])dnl
6ad762a8 294@output @output_parser_name@
fb8135fa 295b4_copyright([C++ Skeleton parser for LALR(1) parsing with Bison],
010f91c3 296 [2002, 2003, 2004, 2005])
c5b95ccf
AD
297m4_if(b4_prefix[], [yy], [],
298[
299// Take the name prefix into account.
300#define yylex b4_prefix[]lex])
301m4_if(b4_defines_flag, 0, [],
302[
303#include @output_header_name@])[
50997c6e 304
fb9712a9
AD
305/* User implementation prologue. */
306]b4_post_prologue[
307
308]/* Line __line__ of lalr1.cc. */
309b4_syncline([@oline@], [@ofile@])[
310
30757c8c
PE
311#ifndef YY_
312# if YYENABLE_NLS
313# if ENABLE_NLS
314# include <libintl.h> /* FIXME: INFRINGES ON USER NAME SPACE */
315# define YY_(msgid) dgettext ("bison-runtime", msgid)
316# endif
317# endif
318# ifndef YY_
319# define YY_(msgid) msgid
320# endif
989b5b8e
AD
321#endif
322
2a4647a3 323/* Suppress unused-variable warnings by "using" E. */
12ce2df6 324#define YYUSE(e) ((void) (e))
2a4647a3 325
a3cb6248 326/* A pseudo ostream that takes yydebug_ into account. */
9a1e9989 327# define YYCDEBUG \
a3cb6248 328 for (bool yydebugcond_ = yydebug_; yydebugcond_; yydebugcond_ = false) \
9a1e9989
AD
329 (*yycdebug_)
330
2b548aa6 331/* Enable debugging if requested. */
50997c6e 332#if YYDEBUG
284acc8b 333
284acc8b
AD
334# define YY_SYMBOL_PRINT(Title, Type, Value, Location) \
335do { \
a3cb6248 336 if (yydebug_) \
284acc8b 337 { \
d1ff7a7c 338 *yycdebug_ << Title << ' '; \
f69a4142 339 yysymprint_ ((Type), (Value), (Location)); \
9a1e9989 340 *yycdebug_ << std::endl; \
284acc8b 341 } \
2a4647a3 342} while (false)
284acc8b 343
5348bfbe
AD
344# define YY_REDUCE_PRINT(Rule) \
345do { \
a3cb6248 346 if (yydebug_) \
d1ff7a7c 347 yy_reduce_print_ (Rule); \
2a4647a3 348} while (false)
284acc8b 349
25f66e1a
AD
350# define YY_STACK_PRINT() \
351do { \
a3cb6248 352 if (yydebug_) \
f69a4142 353 yystack_print_ (); \
2a4647a3 354} while (false)
284acc8b 355
2b548aa6 356#else /* !YYDEBUG */
284acc8b 357
284acc8b 358# define YY_SYMBOL_PRINT(Title, Type, Value, Location)
5348bfbe 359# define YY_REDUCE_PRINT(Rule)
25f66e1a 360# define YY_STACK_PRINT()
284acc8b 361
2b548aa6
RA
362#endif /* !YYDEBUG */
363
60a777aa
AD
364#define YYACCEPT goto yyacceptlab
365#define YYABORT goto yyabortlab
47301314 366#define YYERROR goto yyerrorlab
60a777aa 367
9e0876fb
PE
368#if YYERROR_VERBOSE
369
370/* Return YYSTR after stripping away unnecessary quotes and
371 backslashes, so that it's suitable for yyerror. The heuristic is
372 that double-quoting is unnecessary unless the string contains an
373 apostrophe, a comma, or backslash (other than backslash-backslash).
374 YYSTR is taken from yytname. */
375std::string
376yy::]b4_parser_class_name[::yytnamerr_ (const char *yystr)
377{
378 if (*yystr == '"')
379 {
380 std::string yyr = "";
381 char const *yyp = yystr;
382
383 for (;;)
384 switch (*++yyp)
385 {
386 case '\'':
387 case ',':
388 goto do_not_strip_quotes;
389
390 case '\\':
391 if (*++yyp != '\\')
392 goto do_not_strip_quotes;
393 /* Fall through. */
394 default:
395 yyr += *yyp;
396 break;
397
398 case '"':
399 return yyr;
400 }
401 do_not_strip_quotes: ;
402 }
403
404 return yystr;
405}
406
407#endif
408
98ae9643 409namespace yy
a0e68930 410{
98ae9643
AD
411 /// Build a parser object.
412 ]b4_parser_class_name::b4_parser_class_name[ (]b4_parse_param_decl[)
413 : yydebug_ (false),
414 yycdebug_ (&std::cerr)]b4_parse_param_cons[
415 {
416 }
a0e68930 417
98ae9643
AD
418 ]b4_parser_class_name::~b4_parser_class_name[ ()
419 {
420 }
a0e68930 421
98ae9643
AD
422#if YYDEBUG
423 /*--------------------------------.
424 | Print this symbol on YYOUTPUT. |
425 `--------------------------------*/
a0e68930 426
98ae9643
AD
427 void
428 ]b4_parser_class_name[::yysymprint_ (int yytype,
429 const semantic_type* yyvaluep, const location_type* yylocationp)
430 {
431 /* Backward compatibility, but should be removed eventually. */
432 std::ostream& cdebug_ = *yycdebug_;
433
434 YYUSE (!&cdebug_);
435 YYUSE (yylocationp);
436 YYUSE (yyvaluep);
437
438 *yycdebug_ << (yytype < yyntokens_ ? "token" : "nterm")
439 << ' ' << yytname_[yytype] << " ("
440 << *yylocationp << ": ";
441 switch (yytype)
442 {
443 ]m4_map([b4_symbol_actions], m4_defn([b4_symbol_printers]))dnl
444[ default:
445 break;
446 }
447 *yycdebug_ << ')';
448 }
449#endif /* ! YYDEBUG */
a0e68930 450
98ae9643
AD
451 void
452 ]b4_parser_class_name[::yydestruct_ (const char* yymsg,
453 int yytype, semantic_type* yyvaluep, location_type* yylocationp)
454 {
455 YYUSE (yylocationp);
456 YYUSE (yymsg);
457 YYUSE (yyvaluep);
458
459 YY_SYMBOL_PRINT (yymsg, yytype, yyvaluep, yylocationp);
460
461 switch (yytype)
462 {
463 ]m4_map([b4_symbol_actions], m4_defn([b4_symbol_destructors]))[
464 default:
465 break;
466 }
467 }
60a777aa 468
98ae9643
AD
469 void
470 ]b4_parser_class_name[::yypop_ (unsigned int n)
471 {
472 yystate_stack_.pop (n);
473 yysemantic_stack_.pop (n);
474 yylocation_stack_.pop (n);
475 }
52d5733f 476
98ae9643
AD
477 std::ostream&
478 ]b4_parser_class_name[::debug_stream () const
479 {
480 return *yycdebug_;
481 }
9a1e9989 482
98ae9643
AD
483 void
484 ]b4_parser_class_name[::set_debug_stream (std::ostream& o)
485 {
486 yycdebug_ = &o;
487 }
9a1e9989
AD
488
489
98ae9643
AD
490 ]b4_parser_class_name[::debug_level_type
491 ]b4_parser_class_name[::debug_level () const
492 {
493 return yydebug_;
494 }
a3cb6248 495
98ae9643
AD
496 void
497 ]b4_parser_class_name[::set_debug_level (debug_level_type l)
498 {
499 yydebug_ = l;
500 }
a3cb6248
AD
501
502
98ae9643
AD
503 int
504 ]b4_parser_class_name[::parse ()
505 {
506 /// Look-ahead and look-ahead in internal form.
507 int yychar = yyempty_;
508 int yytoken = 0;
d4fb5e3c 509
98ae9643
AD
510 /* State. */
511 int yyn;
a85284cf 512 int yylen = 0;
98ae9643 513 int yystate = 0;
d4fb5e3c 514
98ae9643
AD
515 /* Error handling. */
516 int yynerrs_ = 0;
517 int yyerrstatus_ = 0;
dbcdae2d 518
98ae9643
AD
519 /// Semantic value of the look-ahead.
520 semantic_type yylval;
521 /// Location of the look-ahead.
522 location_type yylloc;
523 /// The locations where the error started and ended.
524 location yyerror_range[2];
dbcdae2d 525
98ae9643
AD
526 /// $$.
527 semantic_type yyval;
528 /// @@$.
529 location_type yyloc;
dbcdae2d 530
98ae9643 531 int yyresult;
ad745863 532
98ae9643 533 YYCDEBUG << "Starting parse" << std::endl;
451364ed 534
451364ed 535]m4_ifdef([b4_initial_action], [
99880de5
AD
536m4_pushdef([b4_at_dollar], [yylloc])dnl
537m4_pushdef([b4_dollar_dollar], [yylval])dnl
98ae9643
AD
538 /* User initialization code. */
539 b4_initial_action
451364ed
AD
540m4_popdef([b4_dollar_dollar])dnl
541m4_popdef([b4_at_dollar])dnl
98ae9643 542 /* Line __line__ of yacc.c. */
451364ed
AD
543b4_syncline([@oline@], [@ofile@])])dnl
544
98ae9643
AD
545 [ /* Initialize the stacks. The initial state will be pushed in
546 yynewstate, since the latter expects the semantical and the
547 location values to have been already stored, initialize these
548 stacks with a primary value. */
549 yystate_stack_ = state_stack_type (0);
550 yysemantic_stack_ = semantic_stack_type (0);
551 yylocation_stack_ = location_stack_type (0);
552 yysemantic_stack_.push (yylval);
553 yylocation_stack_.push (yylloc);
554
555 /* New state. */
556 yynewstate:
557 yystate_stack_.push (yystate);
558 YYCDEBUG << "Entering state " << yystate << std::endl;
559 goto yybackup;
560
561 /* Backup. */
562 yybackup:
563
564 /* Try to take a decision without look-ahead. */
565 yyn = yypact_[yystate];
566 if (yyn == yypact_ninf_)
567 goto yydefault;
568
569 /* Read a look-ahead token. */
570 if (yychar == yyempty_)
571 {
572 YYCDEBUG << "Reading a token: ";
573 yychar = ]b4_c_function_call([yylex], [int],
574 [[YYSTYPE*], [&yylval]][]dnl
dbcdae2d
AD
575b4_location_if([, [[location*], [&yylloc]]])dnl
576m4_ifdef([b4_lex_param], [, ]b4_lex_param))[;
98ae9643
AD
577 }
578
579
580 /* Convert token to internal form. */
581 if (yychar <= yyeof_)
582 {
583 yychar = yytoken = yyeof_;
584 YYCDEBUG << "Now at end of input." << std::endl;
585 }
586 else
587 {
588 yytoken = yytranslate_ (yychar);
589 YY_SYMBOL_PRINT ("Next token is", yytoken, &yylval, &yylloc);
590 }
591
592 /* If the proper action on seeing token YYTOKEN is to reduce or to
593 detect an error, take that action. */
594 yyn += yytoken;
595 if (yyn < 0 || yylast_ < yyn || yycheck_[yyn] != yytoken)
596 goto yydefault;
597
598 /* Reduce or error. */
599 yyn = yytable_[yyn];
600 if (yyn <= 0)
601 {
602 if (yyn == 0 || yyn == yytable_ninf_)
603 goto yyerrlab;
604 yyn = -yyn;
605 goto yyreduce;
606 }
607
608 /* Accept? */
609 if (yyn == yyfinal_)
610 goto yyacceptlab;
611
612 /* Shift the look-ahead token. */
613 YY_SYMBOL_PRINT ("Shifting", yytoken, &yylval, &yylloc);
614
615 /* Discard the token being shifted unless it is eof. */
616 if (yychar != yyeof_)
617 yychar = yyempty_;
618
619 yysemantic_stack_.push (yylval);
620 yylocation_stack_.push (yylloc);
621
622 /* Count tokens shifted since error; after three, turn off error
623 status. */
624 if (yyerrstatus_)
625 --yyerrstatus_;
626
627 yystate = yyn;
628 goto yynewstate;
629
630 /*-----------------------------------------------------------.
631 | yydefault -- do the default action for the current state. |
632 `-----------------------------------------------------------*/
633 yydefault:
634 yyn = yydefact_[yystate];
635 if (yyn == 0)
636 goto yyerrlab;
637 goto yyreduce;
638
639 /*-----------------------------.
640 | yyreduce -- Do a reduction. |
641 `-----------------------------*/
642 yyreduce:
643 yylen = yyr2_[yyn];
a85284cf 644 /* If YYLEN is nonzero, implement the default value of the action:
98ae9643
AD
645 `$$ = $1'. Otherwise, use the top of the stack.
646
647 Otherwise, the following line sets YYVAL to garbage.
648 This behavior is undocumented and Bison
649 users should not rely upon it. */
650 if (yylen)
651 yyval = yysemantic_stack_[yylen - 1];
652 else
653 yyval = yysemantic_stack_[0];
2b548aa6 654
2b548aa6 655 {
98ae9643
AD
656 slice<location_type, location_stack_type> slice (yylocation_stack_, yylen);
657 YYLLOC_DEFAULT (yyloc, slice, yylen);
2b548aa6 658 }
98ae9643
AD
659 YY_REDUCE_PRINT (yyn);
660 switch (yyn)
661 {
a85284cf
AD
662 ]b4_actions
663 /* Line __line__ of lalr1.cc. */
664b4_syncline([@oline@], [@ofile@])[
98ae9643
AD
665 default: break;
666 }
d1ff7a7c 667 YY_SYMBOL_PRINT ("-> $$ =", yyr1_[yyn], &yyval, &yyloc);
98ae9643
AD
668
669 yypop_ (yylen);
a85284cf 670 yylen = 0;
98ae9643
AD
671 YY_STACK_PRINT ();
672
673 yysemantic_stack_.push (yyval);
674 yylocation_stack_.push (yyloc);
675
676 /* Shift the result of the reduction. */
677 yyn = yyr1_[yyn];
678 yystate = yypgoto_[yyn - yyntokens_] + yystate_stack_[0];
679 if (0 <= yystate && yystate <= yylast_
680 && yycheck_[yystate] == yystate_stack_[0])
681 yystate = yytable_[yystate];
682 else
683 yystate = yydefgoto_[yyn - yyntokens_];
684 goto yynewstate;
685
686 /*------------------------------------.
687 | yyerrlab -- here on detecting error |
688 `------------------------------------*/
689 yyerrlab:
690 /* If not already recovering from an error, report this error. */
691 if (!yyerrstatus_)
692 {
693 ++yynerrs_;
694 error (yylloc, yysyntax_error_ (yystate]dnl
d4fb5e3c 695b4_error_verbose_if([, yytoken])[));
98ae9643
AD
696 }
697
698 yyerror_range[0] = yylloc;
699 if (yyerrstatus_ == 3)
700 {
701 /* If just tried and failed to reuse look-ahead token after an
702 error, discard it. */
703
704 if (yychar <= yyeof_)
705 {
706 /* Return failure if at end of input. */
707 if (yychar == yyeof_)
708 YYABORT;
709 }
710 else
711 {
712 yydestruct_ ("Error: discarding", yytoken, &yylval, &yylloc);
713 yychar = yyempty_;
714 }
715 }
716
717 /* Else will try to reuse look-ahead token after shifting the error
718 token. */
719 goto yyerrlab1;
720
721
722 /*---------------------------------------------------.
723 | yyerrorlab -- error raised explicitly by YYERROR. |
724 `---------------------------------------------------*/
725 yyerrorlab:
726
727 /* Pacify compilers like GCC when the user code never invokes
728 YYERROR and the label yyerrorlab therefore never appears in user
729 code. */
730 if (false)
731 goto yyerrorlab;
732
733 yyerror_range[0] = yylocation_stack_[yylen - 1];
a85284cf
AD
734 /* Do not reclaim the symbols of the rule which action triggered
735 this YYERROR. */
98ae9643 736 yypop_ (yylen);
a85284cf 737 yylen = 0;
98ae9643
AD
738 yystate = yystate_stack_[0];
739 goto yyerrlab1;
740
741 /*-------------------------------------------------------------.
742 | yyerrlab1 -- common code for both syntax error and YYERROR. |
743 `-------------------------------------------------------------*/
744 yyerrlab1:
745 yyerrstatus_ = 3; /* Each real token shifted decrements this. */
746
747 for (;;)
748 {
749 yyn = yypact_[yystate];
750 if (yyn != yypact_ninf_)
751 {
752 yyn += yyterror_;
753 if (0 <= yyn && yyn <= yylast_ && yycheck_[yyn] == yyterror_)
754 {
755 yyn = yytable_[yyn];
756 if (0 < yyn)
757 break;
758 }
759 }
760
761 /* Pop the current state because it cannot handle the error token. */
762 if (yystate_stack_.height () == 1)
763 YYABORT;
764
765 yyerror_range[0] = yylocation_stack_[0];
766 yydestruct_ ("Error: popping",
767 yystos_[yystate],
768 &yysemantic_stack_[0], &yylocation_stack_[0]);
769 yypop_ ();
770 yystate = yystate_stack_[0];
771 YY_STACK_PRINT ();
772 }
773
774 if (yyn == yyfinal_)
775 goto yyacceptlab;
776
777 yyerror_range[1] = yylloc;
778 // Using YYLLOC is tempting, but would change the location of
779 // the look-ahead. YYLOC is available though.
780 YYLLOC_DEFAULT (yyloc, yyerror_range - 1, 2);
781 yysemantic_stack_.push (yylval);
782 yylocation_stack_.push (yyloc);
783
784 /* Shift the error token. */
785 YY_SYMBOL_PRINT ("Shifting", yystos_[yyn],
786 &yysemantic_stack_[0], &yylocation_stack_[0]);
787
788 yystate = yyn;
789 goto yynewstate;
790
791 /* Accept. */
792 yyacceptlab:
793 yyresult = 0;
794 goto yyreturn;
795
796 /* Abort. */
797 yyabortlab:
798 yyresult = 1;
799 goto yyreturn;
800
801 yyreturn:
802 if (yychar != yyeof_ && yychar != yyempty_)
803 yydestruct_ ("Cleanup: discarding lookahead", yytoken, &yylval, &yylloc);
804
a85284cf
AD
805 /* Do not reclaim the symbols of the rule which action triggered
806 this YYABORT or YYACCEPT. */
807 yypop_ (yylen);
98ae9643
AD
808 while (yystate_stack_.height () != 1)
809 {
810 yydestruct_ ("Cleanup: popping",
811 yystos_[yystate_stack_[0]],
812 &yysemantic_stack_[0],
813 &yylocation_stack_[0]);
814 yypop_ ();
815 }
816
817 return yyresult;
818 }
2b548aa6 819
98ae9643
AD
820 // Generate an error message.
821 std::string
822 ]b4_parser_class_name[::yysyntax_error_ (int yystate]dnl
fb9712a9 823b4_error_verbose_if([, int tok])[)
98ae9643
AD
824 {
825 std::string res;
a08460b0 826#if YYERROR_VERBOSE
98ae9643
AD
827 int yyn = yypact_[yystate];
828 if (yypact_ninf_ < yyn && yyn < yylast_)
829 {
830 /* Start YYX at -YYN if negative to avoid negative indexes in
831 YYCHECK. */
832 int yyxbegin = yyn < 0 ? -yyn : 0;
833
834 /* Stay within bounds of both yycheck and yytname. */
835 int yychecklim = yylast_ - yyn;
836 int yyxend = yychecklim < yyntokens_ ? yychecklim : yyntokens_;
837 int count = 0;
838 for (int x = yyxbegin; x < yyxend; ++x)
839 if (yycheck_[x + yyn] == x && x != yyterror_)
840 ++count;
841
842 // FIXME: This method of building the message is not compatible
843 // with internationalization. It should work like yacc.c does it.
844 // That is, first build a string that looks like this:
845 // "syntax error, unexpected %s or %s or %s"
846 // Then, invoke YY_ on this string.
847 // Finally, use the string as a format to output
848 // yytname_[tok], etc.
849 // Until this gets fixed, this message appears in English only.
850 res = "syntax error, unexpected ";
851 res += yytnamerr_ (yytname_[tok]);
852 if (count < 5)
853 {
854 count = 0;
855 for (int x = yyxbegin; x < yyxend; ++x)
856 if (yycheck_[x + yyn] == x && x != yyterror_)
857 {
858 res += (!count++) ? ", expecting " : " or ";
859 res += yytnamerr_ (yytname_[x]);
860 }
861 }
862 }
863 else
dbcdae2d 864#endif
98ae9643
AD
865 res = YY_("syntax error");
866 return res;
867 }
a08460b0 868
5348bfbe 869
98ae9643
AD
870 /* YYPACT[STATE-NUM] -- Index in YYTABLE of the portion describing
871 STATE-NUM. */
872 const ]b4_int_type(b4_pact_ninf, b4_pact_ninf) b4_parser_class_name::yypact_ninf_ = b4_pact_ninf[;
873 const ]b4_int_type_for([b4_pact])[
874 ]b4_parser_class_name[::yypact_[] =
875 {
876 ]b4_pact[
877 };
2b548aa6 878
98ae9643
AD
879 /* YYDEFACT[S] -- default rule to reduce with in state S when YYTABLE
880 doesn't specify something else to do. Zero means the default is an
881 error. */
882 const ]b4_int_type_for([b4_defact])[
883 ]b4_parser_class_name[::yydefact_[] =
884 {
885 ]b4_defact[
886 };
2b548aa6 887
98ae9643
AD
888 /* YYPGOTO[NTERM-NUM]. */
889 const ]b4_int_type_for([b4_pgoto])[
890 ]b4_parser_class_name[::yypgoto_[] =
891 {
892 ]b4_pgoto[
893 };
2b548aa6 894
98ae9643
AD
895 /* YYDEFGOTO[NTERM-NUM]. */
896 const ]b4_int_type_for([b4_defgoto])[
897 ]b4_parser_class_name[::yydefgoto_[] =
898 {
899 ]b4_defgoto[
900 };
2b548aa6 901
98ae9643
AD
902 /* YYTABLE[YYPACT[STATE-NUM]]. What to do in state STATE-NUM. If
903 positive, shift that token. If negative, reduce the rule which
904 number is the opposite. If zero, do what YYDEFACT says. */
905 const ]b4_int_type(b4_table_ninf, b4_table_ninf) b4_parser_class_name::yytable_ninf_ = b4_table_ninf[;
906 const ]b4_int_type_for([b4_table])[
907 ]b4_parser_class_name[::yytable_[] =
908 {
909 ]b4_table[
910 };
911
912 /* YYCHECK. */
913 const ]b4_int_type_for([b4_check])[
914 ]b4_parser_class_name[::yycheck_[] =
915 {
916 ]b4_check[
917 };
918
919 /* STOS_[STATE-NUM] -- The (internal number of the) accessing
920 symbol of state STATE-NUM. */
921 const ]b4_int_type_for([b4_stos])[
922 ]b4_parser_class_name[::yystos_[] =
923 {
924 ]b4_stos[
925 };
769b430f 926
45d5982f 927#if YYDEBUG
98ae9643
AD
928 /* TOKEN_NUMBER_[YYLEX-NUM] -- Internal symbol number corresponding
929 to YYLEX-NUM. */
930 const ]b4_int_type_for([b4_toknum])[
931 ]b4_parser_class_name[::yytoken_number_[] =
932 {
933 ]b4_toknum[
934 };
769b430f
AD
935#endif
936
98ae9643
AD
937 /* YYR1[YYN] -- Symbol number of symbol that rule YYN derives. */
938 const ]b4_int_type_for([b4_r1])[
939 ]b4_parser_class_name[::yyr1_[] =
940 {
941 ]b4_r1[
942 };
2b548aa6 943
98ae9643
AD
944 /* YYR2[YYN] -- Number of symbols composing right hand side of rule YYN. */
945 const ]b4_int_type_for([b4_r2])[
946 ]b4_parser_class_name[::yyr2_[] =
947 {
948 ]b4_r2[
949 };
2b548aa6 950
141f5793 951#if YYDEBUG || YYERROR_VERBOSE || YYTOKEN_TABLE
98ae9643
AD
952 /* YYTNAME[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM.
953 First, the terminals, then, starting at \a yyntokens_, nonterminals. */
954 const char*
955 const ]b4_parser_class_name[::yytname_[] =
956 {
957 ]b4_tname[
958 };
69e2658b 959#endif
2b548aa6 960
69e2658b 961#if YYDEBUG
98ae9643
AD
962 /* YYRHS -- A `-1'-separated list of the rules' RHS. */
963 const ]b4_parser_class_name[::rhs_number_type
964 ]b4_parser_class_name[::yyrhs_[] =
965 {
966 ]b4_rhs[
967 };
2b548aa6 968
98ae9643
AD
969 /* YYPRHS[YYN] -- Index of the first RHS symbol of rule number YYN in
970 YYRHS. */
971 const ]b4_int_type_for([b4_prhs])[
972 ]b4_parser_class_name[::yyprhs_[] =
973 {
974 ]b4_prhs[
975 };
2b548aa6 976
98ae9643
AD
977 /* YYRLINE[YYN] -- Source line where rule number YYN was defined. */
978 const ]b4_int_type_for([b4_rline])[
979 ]b4_parser_class_name[::yyrline_[] =
980 {
981 ]b4_rline[
982 };
5348bfbe 983
98ae9643
AD
984 // Print the state stack on the debug stream.
985 void
986 ]b4_parser_class_name[::yystack_print_ ()
987 {
988 *yycdebug_ << "Stack now";
989 for (state_stack_type::const_iterator i = yystate_stack_.begin ();
990 i != yystate_stack_.end (); ++i)
991 *yycdebug_ << ' ' << *i;
992 *yycdebug_ << std::endl;
993 }
25f66e1a 994
98ae9643
AD
995 // Report on the debug stream that the rule \a yyrule is going to be reduced.
996 void
d1ff7a7c 997 ]b4_parser_class_name[::yy_reduce_print_ (int yyrule)
98ae9643
AD
998 {
999 unsigned int yylno = yyrline_[yyrule];
d1ff7a7c 1000 int yynrhs = yyr2_[yyrule];
98ae9643
AD
1001 /* Print the symbols being reduced, and their result. */
1002 *yycdebug_ << "Reducing stack by rule " << yyrule - 1
1003 << " (line " << yylno << "), ";
d1ff7a7c
AD
1004 /* The symbols being reduced. */
1005 for (int yyi = 0; yyi < yynrhs; yyi++)
1006 YY_SYMBOL_PRINT (" $" << yyi + 1 << " =",
1007 yyrhs_[yyprhs_[yyrule] + yyi],
1008 &]b4_rhs_value(yynrhs, yyi + 1)[,
1009 &]b4_rhs_location(yynrhs, yyi + 1)[);
98ae9643 1010 }
5348bfbe 1011#endif // YYDEBUG
69e2658b 1012
98ae9643
AD
1013 /* YYTRANSLATE(YYLEX) -- Bison symbol number corresponding to YYLEX. */
1014 ]b4_parser_class_name[::token_number_type
1015 ]b4_parser_class_name[::yytranslate_ (int token)
2b548aa6 1016 {
98ae9643
AD
1017 static
1018 const token_number_type
1019 translate_table[] =
1020 {
1021 ]b4_translate[
1022 };
1023 if ((unsigned int) token <= yyuser_token_number_max_)
1024 return translate_table[token];
1025 else
1026 return yyundef_token_;
1027 }
1028
1029 const int ]b4_parser_class_name[::yyeof_ = 0;
1030 const int ]b4_parser_class_name[::yylast_ = ]b4_last[;
1031 const int ]b4_parser_class_name[::yynnts_ = ]b4_nterms_number[;
1032 const int ]b4_parser_class_name[::yyempty_ = -2;
1033 const int ]b4_parser_class_name[::yyfinal_ = ]b4_final_state_number[;
1034 const int ]b4_parser_class_name[::yyterror_ = 1;
1035 const int ]b4_parser_class_name[::yyerrcode_ = 256;
1036 const int ]b4_parser_class_name[::yyntokens_ = ]b4_tokens_number[;
1037
1038 const unsigned int ]b4_parser_class_name[::yyuser_token_number_max_ = ]b4_user_token_number_max[;
1039 const ]b4_parser_class_name[::token_number_type ]b4_parser_class_name[::yyundef_token_ = ]b4_undef_token_number[;
2b548aa6 1040
98ae9643 1041} // namespace yy
2b548aa6 1042
c5e3e510 1043]b4_epilogue
21846f69 1044dnl
2b81e969 1045@output b4_dir_prefix[]stack.hh
010f91c3 1046b4_copyright([stack handling for Bison C++ parsers], [2002, 2003, 2004, 2005])[
98254360 1047
2b548aa6
RA
1048#ifndef BISON_STACK_HH
1049# define BISON_STACK_HH
1050
45119f04 1051#include <deque>
2b548aa6
RA
1052
1053namespace yy
1054{
f85a5e6f 1055 template <class T, class S = std::deque<T> >
99880de5 1056 class stack
2b548aa6
RA
1057 {
1058 public:
1059
ecfe33e7
AD
1060 // Hide our reversed order.
1061 typedef typename S::reverse_iterator iterator;
1062 typedef typename S::const_reverse_iterator const_iterator;
2b548aa6 1063
99880de5 1064 stack () : seq_ ()
2b548aa6
RA
1065 {
1066 }
1067
99880de5 1068 stack (unsigned int n) : seq_ (n)
2b548aa6
RA
1069 {
1070 }
1071
1072 inline
1073 T&
779e7ceb 1074 operator [] (unsigned int i)
2b548aa6 1075 {
1d4055aa 1076 return seq_[i];
2b548aa6
RA
1077 }
1078
1079 inline
1080 const T&
779e7ceb 1081 operator [] (unsigned int i) const
2b548aa6 1082 {
1d4055aa 1083 return seq_[i];
2b548aa6
RA
1084 }
1085
1086 inline
1087 void
1088 push (const T& t)
1089 {
45119f04 1090 seq_.push_front (t);
2b548aa6
RA
1091 }
1092
1093 inline
1094 void
779e7ceb 1095 pop (unsigned int n = 1)
2b548aa6
RA
1096 {
1097 for (; n; --n)
45119f04 1098 seq_.pop_front ();
2b548aa6
RA
1099 }
1100
762a801e 1101 inline
779e7ceb 1102 unsigned int
762a801e
RA
1103 height () const
1104 {
1105 return seq_.size ();
1106 }
1107
ecfe33e7
AD
1108 inline const_iterator begin () const { return seq_.rbegin (); }
1109 inline const_iterator end () const { return seq_.rend (); }
2b548aa6
RA
1110
1111 private:
1112
1113 S seq_;
1114 };
374f5a14 1115
e019c247 1116 /// Present a slice of the top of a stack.
99880de5
AD
1117 template <class T, class S = stack<T> >
1118 class slice
374f5a14
RA
1119 {
1120 public:
1121
99880de5 1122 slice (const S& stack,
779e7ceb
PE
1123 unsigned int range) : stack_ (stack),
1124 range_ (range)
374f5a14
RA
1125 {
1126 }
1127
1128 inline
1129 const T&
779e7ceb 1130 operator [] (unsigned int i) const
374f5a14 1131 {
1d4055aa 1132 return stack_[range_ - i];
374f5a14
RA
1133 }
1134
1135 private:
1136
1137 const S& stack_;
779e7ceb 1138 unsigned int range_;
374f5a14 1139 };
2b548aa6
RA
1140}
1141
c5e3e510 1142#endif // not BISON_STACK_HH]
fc695704 1143m4_divert(-1)