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