]> git.saurik.com Git - bison.git/blame_incremental - data/lalr1.cc
* tests/glr-regression.at
[bison.git] / data / lalr1.cc
... / ...
CommitLineData
1m4_divert(-1)
2
3# C++ skeleton for Bison
4
5# Copyright (C) 2002, 2003, 2004, 2005 Free Software Foundation, Inc.
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
19# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
20# 02110-1301 USA
21
22m4_include(b4_pkgdatadir/[c++.m4])
23# Backward compatibility.
24m4_define([b4_location_constructors])
25m4_include(b4_pkgdatadir/[location.cc])
26
27# We do want M4 expansion after # for CPP macros.
28m4_changecom()
29m4_divert(0)dnl
30m4_if(b4_defines_flag, 0, [],
31[@output @output_header_name@
32b4_copyright([C++ Skeleton parser for LALR(1) parsing with Bison],
33 [2002, 2003, 2004, 2005])
34dnl FIXME: This is wrong, we want computed header guards.
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
43#ifndef PARSER_HEADER_H
44# define PARSER_HEADER_H
45
46#include <string>
47#include <iostream>
48#include "stack.hh"
49
50namespace yy
51{
52 class position;
53 class location;
54}
55
56/* First part of user declarations. */
57]b4_pre_prologue[
58
59]/* Line __line__ of lalr1.cc. */
60b4_syncline([@oline@], [@ofile@])[
61
62]dnl Include location.hh here: it might depend on headers included above.
63[#include "location.hh"
64
65/* Enabling traces. */
66#ifndef YYDEBUG
67# define YYDEBUG ]b4_debug[
68#endif
69
70/* Enabling verbose error messages. */
71#ifdef YYERROR_VERBOSE
72# undef YYERROR_VERBOSE
73# define YYERROR_VERBOSE 1
74#else
75# define YYERROR_VERBOSE ]b4_error_verbose[
76#endif
77
78/* Enabling the token table. */
79#ifndef YYTOKEN_TABLE
80# define YYTOKEN_TABLE ]b4_token_table[
81#endif
82
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). */
86
87#ifndef YYLLOC_DEFAULT
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 } \
99} while (false)
100#endif
101
102namespace yy
103{
104
105 /// A Bison parser.
106 class ]b4_parser_class_name[
107 {
108 public:
109 /// Symbol semantic values.
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
118 typedef YYSTYPE semantic_type;
119#endif
120 /// Symbol locations.
121 typedef ]b4_location_type[ location_type;
122 /// Tokens.
123 struct token
124 {
125 ]b4_token_enums(b4_tokens)[
126 };
127
128 /// Build a parser object.
129 ]b4_parser_class_name[ (]b4_parse_param_decl[);
130 virtual ~]b4_parser_class_name[ ();
131
132 /// Parse.
133 /// \returns 0 iff parsing succeeded.
134 virtual int parse ();
135
136 /// The current debugging stream.
137 std::ostream& debug_stream () const;
138 /// Set the current debugging stream.
139 void set_debug_stream (std::ostream &);
140
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
148 private:
149 /// Report a syntax error.
150 /// \param loc where the syntax error is found.
151 /// \param msg a description of the syntax error.
152 virtual void error (const location_type& loc, const std::string& msg);
153
154 /// Generate an error message.
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])[);
159
160#if YYDEBUG
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,
166 const semantic_type* yyvaluep,
167 const location_type* yylocationp);
168#endif /* ! YYDEBUG */
169
170
171 /// State numbers.
172 typedef int state_type;
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
180 /// The state stack.
181 state_stack_type yystate_stack_;
182 /// The semantic value stack.
183 semantic_stack_type yysemantic_stack_;
184 /// The location stack.
185 location_stack_type yylocation_stack_;
186
187 /// Internal symbol numbers.
188 typedef ]b4_int_type_for([b4_translate])[ token_number_type;
189 /* Tables. */
190 /// For a state, the index in \a yytable_ of its portion.
191 static const ]b4_int_type_for([b4_pact])[ yypact_[];
192 static const ]b4_int_type(b4_pact_ninf, b4_pact_ninf)[ yypact_ninf_;
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.
197 static const ]b4_int_type_for([b4_defact])[ yydefact_[];
198
199 static const ]b4_int_type_for([b4_pgoto])[ yypgoto_[];
200 static const ]b4_int_type_for([b4_defgoto])[ yydefgoto_[];
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.
207 static const ]b4_int_type_for([b4_table])[ yytable_[];
208 static const ]b4_int_type(b4_table_ninf, b4_table_ninf)[ yytable_ninf_;
209
210 static const ]b4_int_type_for([b4_check])[ yycheck_[];
211
212 /// For a state, its accessing symbol.
213 static const ]b4_int_type_for([b4_stos])[ yystos_[];
214
215 /// For a rule, its LHS.
216 static const ]b4_int_type_for([b4_r1])[ yyr1_[];
217 /// For a rule, its RHS length.
218 static const ]b4_int_type_for([b4_r2])[ yyr2_[];
219
220#if YYDEBUG || YYERROR_VERBOSE || YYTOKEN_TABLE
221 /// For a symbol, its name in clear.
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);
228#endif
229
230#if YYDEBUG
231 /// A type to store symbol numbers and -1.
232 typedef ]b4_int_type_for([b4_rhs])[ rhs_number_type;
233 /// A `-1'-separated list of the rules' RHS.
234 static const rhs_number_type yyrhs_[];
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_[];
241 /// Report on the debug stream that the rule \a r is going to be reduced.
242 virtual void yy_reduce_print_ (int r);
243 /// Print the state stack on the debug stream.
244 virtual void yystack_print_ ();
245#endif
246
247 /// Convert a scanner token number to a symbol number.
248 inline token_number_type yytranslate_ (int token);
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,
257 semantic_type* yyvaluep,
258 location_type* yylocationp);
259
260 /// Pop \a n symbols the three stacks.
261 inline void yypop_ (unsigned int n = 1);
262
263 /* Constants. */
264 static const int yyeof_;
265 /* LAST_ -- Last index in TABLE_. */
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_;
274 static const token_number_type yyundef_token_;
275
276 /* Debugging. */
277 int yydebug_;
278 std::ostream* yycdebug_;
279
280]b4_parse_param_vars[
281 };
282}
283
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])[
292#endif /* ! defined PARSER_HEADER_H */]
293])dnl
294@output @output_parser_name@
295b4_copyright([C++ Skeleton parser for LALR(1) parsing with Bison],
296 [2002, 2003, 2004, 2005])
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@])[
304
305/* User implementation prologue. */
306]b4_post_prologue[
307
308]/* Line __line__ of lalr1.cc. */
309b4_syncline([@oline@], [@ofile@])[
310
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
321#endif
322
323/* Suppress unused-variable warnings by "using" E. */
324#define YYUSE(e) do {;} while (false && (e))
325
326/* A pseudo ostream that takes yydebug_ into account. */
327# define YYCDEBUG \
328 for (bool yydebugcond_ = yydebug_; yydebugcond_; yydebugcond_ = false) \
329 (*yycdebug_)
330
331/* Enable debugging if requested. */
332#if YYDEBUG
333
334# define YY_SYMBOL_PRINT(Title, Type, Value, Location) \
335do { \
336 if (yydebug_) \
337 { \
338 *yycdebug_ << Title << ' '; \
339 yysymprint_ ((Type), (Value), (Location)); \
340 *yycdebug_ << std::endl; \
341 } \
342} while (false)
343
344# define YY_REDUCE_PRINT(Rule) \
345do { \
346 if (yydebug_) \
347 yy_reduce_print_ (Rule); \
348} while (false)
349
350# define YY_STACK_PRINT() \
351do { \
352 if (yydebug_) \
353 yystack_print_ (); \
354} while (false)
355
356#else /* !YYDEBUG */
357
358# define YY_SYMBOL_PRINT(Title, Type, Value, Location)
359# define YY_REDUCE_PRINT(Rule)
360# define YY_STACK_PRINT()
361
362#endif /* !YYDEBUG */
363
364#define YYACCEPT goto yyacceptlab
365#define YYABORT goto yyabortlab
366#define YYERROR goto yyerrorlab
367
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
409namespace yy
410{
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 }
417
418 ]b4_parser_class_name::~b4_parser_class_name[ ()
419 {
420 }
421
422#if YYDEBUG
423 /*--------------------------------.
424 | Print this symbol on YYOUTPUT. |
425 `--------------------------------*/
426
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 */
450
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 }
468
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 }
476
477 std::ostream&
478 ]b4_parser_class_name[::debug_stream () const
479 {
480 return *yycdebug_;
481 }
482
483 void
484 ]b4_parser_class_name[::set_debug_stream (std::ostream& o)
485 {
486 yycdebug_ = &o;
487 }
488
489
490 ]b4_parser_class_name[::debug_level_type
491 ]b4_parser_class_name[::debug_level () const
492 {
493 return yydebug_;
494 }
495
496 void
497 ]b4_parser_class_name[::set_debug_level (debug_level_type l)
498 {
499 yydebug_ = l;
500 }
501
502
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;
509
510 /* State. */
511 int yyn;
512 int yylen;
513 int yystate = 0;
514
515 /* Error handling. */
516 int yynerrs_ = 0;
517 int yyerrstatus_ = 0;
518
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];
525
526 /// $$.
527 semantic_type yyval;
528 /// @@$.
529 location_type yyloc;
530
531 int yyresult;
532
533 YYCDEBUG << "Starting parse" << std::endl;
534
535]m4_ifdef([b4_initial_action], [
536m4_pushdef([b4_at_dollar], [yylloc])dnl
537m4_pushdef([b4_dollar_dollar], [yylval])dnl
538 /* User initialization code. */
539 b4_initial_action
540m4_popdef([b4_dollar_dollar])dnl
541m4_popdef([b4_at_dollar])dnl
542 /* Line __line__ of yacc.c. */
543b4_syncline([@oline@], [@ofile@])])dnl
544
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
575b4_location_if([, [[location*], [&yylloc]]])dnl
576m4_ifdef([b4_lex_param], [, ]b4_lex_param))[;
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];
644 /* If LEN_ is nonzero, implement the default value of the action:
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];
654
655 {
656 slice<location_type, location_stack_type> slice (yylocation_stack_, yylen);
657 YYLLOC_DEFAULT (yyloc, slice, yylen);
658 }
659 YY_REDUCE_PRINT (yyn);
660 switch (yyn)
661 {
662 ]b4_actions[
663 default: break;
664 }
665 YY_SYMBOL_PRINT ("-> $$ =", yyr1_[yyn], &yyval, &yyloc);
666 /* Line __line__ of lalr1.cc. */
667]b4_syncline([@oline@], [@ofile@])[
668
669 yypop_ (yylen);
670
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
695b4_error_verbose_if([, yytoken])[));
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];
734 yypop_ (yylen);
735 yystate = yystate_stack_[0];
736 goto yyerrlab1;
737
738 /*-------------------------------------------------------------.
739 | yyerrlab1 -- common code for both syntax error and YYERROR. |
740 `-------------------------------------------------------------*/
741 yyerrlab1:
742 yyerrstatus_ = 3; /* Each real token shifted decrements this. */
743
744 for (;;)
745 {
746 yyn = yypact_[yystate];
747 if (yyn != yypact_ninf_)
748 {
749 yyn += yyterror_;
750 if (0 <= yyn && yyn <= yylast_ && yycheck_[yyn] == yyterror_)
751 {
752 yyn = yytable_[yyn];
753 if (0 < yyn)
754 break;
755 }
756 }
757
758 /* Pop the current state because it cannot handle the error token. */
759 if (yystate_stack_.height () == 1)
760 YYABORT;
761
762 yyerror_range[0] = yylocation_stack_[0];
763 yydestruct_ ("Error: popping",
764 yystos_[yystate],
765 &yysemantic_stack_[0], &yylocation_stack_[0]);
766 yypop_ ();
767 yystate = yystate_stack_[0];
768 YY_STACK_PRINT ();
769 }
770
771 if (yyn == yyfinal_)
772 goto yyacceptlab;
773
774 yyerror_range[1] = yylloc;
775 // Using YYLLOC is tempting, but would change the location of
776 // the look-ahead. YYLOC is available though.
777 YYLLOC_DEFAULT (yyloc, yyerror_range - 1, 2);
778 yysemantic_stack_.push (yylval);
779 yylocation_stack_.push (yyloc);
780
781 /* Shift the error token. */
782 YY_SYMBOL_PRINT ("Shifting", yystos_[yyn],
783 &yysemantic_stack_[0], &yylocation_stack_[0]);
784
785 yystate = yyn;
786 goto yynewstate;
787
788 /* Accept. */
789 yyacceptlab:
790 yyresult = 0;
791 goto yyreturn;
792
793 /* Abort. */
794 yyabortlab:
795 yyresult = 1;
796 goto yyreturn;
797
798 yyreturn:
799 if (yychar != yyeof_ && yychar != yyempty_)
800 yydestruct_ ("Cleanup: discarding lookahead", yytoken, &yylval, &yylloc);
801
802 while (yystate_stack_.height () != 1)
803 {
804 yydestruct_ ("Cleanup: popping",
805 yystos_[yystate_stack_[0]],
806 &yysemantic_stack_[0],
807 &yylocation_stack_[0]);
808 yypop_ ();
809 }
810
811 return yyresult;
812 }
813
814 // Generate an error message.
815 std::string
816 ]b4_parser_class_name[::yysyntax_error_ (int yystate]dnl
817b4_error_verbose_if([, int tok])[)
818 {
819 std::string res;
820#if YYERROR_VERBOSE
821 int yyn = yypact_[yystate];
822 if (yypact_ninf_ < yyn && yyn < yylast_)
823 {
824 /* Start YYX at -YYN if negative to avoid negative indexes in
825 YYCHECK. */
826 int yyxbegin = yyn < 0 ? -yyn : 0;
827
828 /* Stay within bounds of both yycheck and yytname. */
829 int yychecklim = yylast_ - yyn;
830 int yyxend = yychecklim < yyntokens_ ? yychecklim : yyntokens_;
831 int count = 0;
832 for (int x = yyxbegin; x < yyxend; ++x)
833 if (yycheck_[x + yyn] == x && x != yyterror_)
834 ++count;
835
836 // FIXME: This method of building the message is not compatible
837 // with internationalization. It should work like yacc.c does it.
838 // That is, first build a string that looks like this:
839 // "syntax error, unexpected %s or %s or %s"
840 // Then, invoke YY_ on this string.
841 // Finally, use the string as a format to output
842 // yytname_[tok], etc.
843 // Until this gets fixed, this message appears in English only.
844 res = "syntax error, unexpected ";
845 res += yytnamerr_ (yytname_[tok]);
846 if (count < 5)
847 {
848 count = 0;
849 for (int x = yyxbegin; x < yyxend; ++x)
850 if (yycheck_[x + yyn] == x && x != yyterror_)
851 {
852 res += (!count++) ? ", expecting " : " or ";
853 res += yytnamerr_ (yytname_[x]);
854 }
855 }
856 }
857 else
858#endif
859 res = YY_("syntax error");
860 return res;
861 }
862
863
864 /* YYPACT[STATE-NUM] -- Index in YYTABLE of the portion describing
865 STATE-NUM. */
866 const ]b4_int_type(b4_pact_ninf, b4_pact_ninf) b4_parser_class_name::yypact_ninf_ = b4_pact_ninf[;
867 const ]b4_int_type_for([b4_pact])[
868 ]b4_parser_class_name[::yypact_[] =
869 {
870 ]b4_pact[
871 };
872
873 /* YYDEFACT[S] -- default rule to reduce with in state S when YYTABLE
874 doesn't specify something else to do. Zero means the default is an
875 error. */
876 const ]b4_int_type_for([b4_defact])[
877 ]b4_parser_class_name[::yydefact_[] =
878 {
879 ]b4_defact[
880 };
881
882 /* YYPGOTO[NTERM-NUM]. */
883 const ]b4_int_type_for([b4_pgoto])[
884 ]b4_parser_class_name[::yypgoto_[] =
885 {
886 ]b4_pgoto[
887 };
888
889 /* YYDEFGOTO[NTERM-NUM]. */
890 const ]b4_int_type_for([b4_defgoto])[
891 ]b4_parser_class_name[::yydefgoto_[] =
892 {
893 ]b4_defgoto[
894 };
895
896 /* YYTABLE[YYPACT[STATE-NUM]]. What to do in state STATE-NUM. If
897 positive, shift that token. If negative, reduce the rule which
898 number is the opposite. If zero, do what YYDEFACT says. */
899 const ]b4_int_type(b4_table_ninf, b4_table_ninf) b4_parser_class_name::yytable_ninf_ = b4_table_ninf[;
900 const ]b4_int_type_for([b4_table])[
901 ]b4_parser_class_name[::yytable_[] =
902 {
903 ]b4_table[
904 };
905
906 /* YYCHECK. */
907 const ]b4_int_type_for([b4_check])[
908 ]b4_parser_class_name[::yycheck_[] =
909 {
910 ]b4_check[
911 };
912
913 /* STOS_[STATE-NUM] -- The (internal number of the) accessing
914 symbol of state STATE-NUM. */
915 const ]b4_int_type_for([b4_stos])[
916 ]b4_parser_class_name[::yystos_[] =
917 {
918 ]b4_stos[
919 };
920
921#if YYDEBUG
922 /* TOKEN_NUMBER_[YYLEX-NUM] -- Internal symbol number corresponding
923 to YYLEX-NUM. */
924 const ]b4_int_type_for([b4_toknum])[
925 ]b4_parser_class_name[::yytoken_number_[] =
926 {
927 ]b4_toknum[
928 };
929#endif
930
931 /* YYR1[YYN] -- Symbol number of symbol that rule YYN derives. */
932 const ]b4_int_type_for([b4_r1])[
933 ]b4_parser_class_name[::yyr1_[] =
934 {
935 ]b4_r1[
936 };
937
938 /* YYR2[YYN] -- Number of symbols composing right hand side of rule YYN. */
939 const ]b4_int_type_for([b4_r2])[
940 ]b4_parser_class_name[::yyr2_[] =
941 {
942 ]b4_r2[
943 };
944
945#if YYDEBUG || YYERROR_VERBOSE || YYTOKEN_TABLE
946 /* YYTNAME[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM.
947 First, the terminals, then, starting at \a yyntokens_, nonterminals. */
948 const char*
949 const ]b4_parser_class_name[::yytname_[] =
950 {
951 ]b4_tname[
952 };
953#endif
954
955#if YYDEBUG
956 /* YYRHS -- A `-1'-separated list of the rules' RHS. */
957 const ]b4_parser_class_name[::rhs_number_type
958 ]b4_parser_class_name[::yyrhs_[] =
959 {
960 ]b4_rhs[
961 };
962
963 /* YYPRHS[YYN] -- Index of the first RHS symbol of rule number YYN in
964 YYRHS. */
965 const ]b4_int_type_for([b4_prhs])[
966 ]b4_parser_class_name[::yyprhs_[] =
967 {
968 ]b4_prhs[
969 };
970
971 /* YYRLINE[YYN] -- Source line where rule number YYN was defined. */
972 const ]b4_int_type_for([b4_rline])[
973 ]b4_parser_class_name[::yyrline_[] =
974 {
975 ]b4_rline[
976 };
977
978 // Print the state stack on the debug stream.
979 void
980 ]b4_parser_class_name[::yystack_print_ ()
981 {
982 *yycdebug_ << "Stack now";
983 for (state_stack_type::const_iterator i = yystate_stack_.begin ();
984 i != yystate_stack_.end (); ++i)
985 *yycdebug_ << ' ' << *i;
986 *yycdebug_ << std::endl;
987 }
988
989 // Report on the debug stream that the rule \a yyrule is going to be reduced.
990 void
991 ]b4_parser_class_name[::yy_reduce_print_ (int yyrule)
992 {
993 unsigned int yylno = yyrline_[yyrule];
994 int yynrhs = yyr2_[yyrule];
995 /* Print the symbols being reduced, and their result. */
996 *yycdebug_ << "Reducing stack by rule " << yyrule - 1
997 << " (line " << yylno << "), ";
998 /* The symbols being reduced. */
999 for (int yyi = 0; yyi < yynrhs; yyi++)
1000 YY_SYMBOL_PRINT (" $" << yyi + 1 << " =",
1001 yyrhs_[yyprhs_[yyrule] + yyi],
1002 &]b4_rhs_value(yynrhs, yyi + 1)[,
1003 &]b4_rhs_location(yynrhs, yyi + 1)[);
1004 }
1005#endif // YYDEBUG
1006
1007 /* YYTRANSLATE(YYLEX) -- Bison symbol number corresponding to YYLEX. */
1008 ]b4_parser_class_name[::token_number_type
1009 ]b4_parser_class_name[::yytranslate_ (int token)
1010 {
1011 static
1012 const token_number_type
1013 translate_table[] =
1014 {
1015 ]b4_translate[
1016 };
1017 if ((unsigned int) token <= yyuser_token_number_max_)
1018 return translate_table[token];
1019 else
1020 return yyundef_token_;
1021 }
1022
1023 const int ]b4_parser_class_name[::yyeof_ = 0;
1024 const int ]b4_parser_class_name[::yylast_ = ]b4_last[;
1025 const int ]b4_parser_class_name[::yynnts_ = ]b4_nterms_number[;
1026 const int ]b4_parser_class_name[::yyempty_ = -2;
1027 const int ]b4_parser_class_name[::yyfinal_ = ]b4_final_state_number[;
1028 const int ]b4_parser_class_name[::yyterror_ = 1;
1029 const int ]b4_parser_class_name[::yyerrcode_ = 256;
1030 const int ]b4_parser_class_name[::yyntokens_ = ]b4_tokens_number[;
1031
1032 const unsigned int ]b4_parser_class_name[::yyuser_token_number_max_ = ]b4_user_token_number_max[;
1033 const ]b4_parser_class_name[::token_number_type ]b4_parser_class_name[::yyundef_token_ = ]b4_undef_token_number[;
1034
1035} // namespace yy
1036
1037]b4_epilogue
1038dnl
1039@output b4_dir_prefix[]stack.hh
1040b4_copyright([stack handling for Bison C++ parsers], [2002, 2003, 2004, 2005])[
1041
1042#ifndef BISON_STACK_HH
1043# define BISON_STACK_HH
1044
1045#include <deque>
1046
1047namespace yy
1048{
1049 template <class T, class S = std::deque<T> >
1050 class stack
1051 {
1052 public:
1053
1054 // Hide our reversed order.
1055 typedef typename S::reverse_iterator iterator;
1056 typedef typename S::const_reverse_iterator const_iterator;
1057
1058 stack () : seq_ ()
1059 {
1060 }
1061
1062 stack (unsigned int n) : seq_ (n)
1063 {
1064 }
1065
1066 inline
1067 T&
1068 operator [] (unsigned int i)
1069 {
1070 return seq_[i];
1071 }
1072
1073 inline
1074 const T&
1075 operator [] (unsigned int i) const
1076 {
1077 return seq_[i];
1078 }
1079
1080 inline
1081 void
1082 push (const T& t)
1083 {
1084 seq_.push_front (t);
1085 }
1086
1087 inline
1088 void
1089 pop (unsigned int n = 1)
1090 {
1091 for (; n; --n)
1092 seq_.pop_front ();
1093 }
1094
1095 inline
1096 unsigned int
1097 height () const
1098 {
1099 return seq_.size ();
1100 }
1101
1102 inline const_iterator begin () const { return seq_.rbegin (); }
1103 inline const_iterator end () const { return seq_.rend (); }
1104
1105 private:
1106
1107 S seq_;
1108 };
1109
1110 /// Present a slice of the top of a stack.
1111 template <class T, class S = stack<T> >
1112 class slice
1113 {
1114 public:
1115
1116 slice (const S& stack,
1117 unsigned int range) : stack_ (stack),
1118 range_ (range)
1119 {
1120 }
1121
1122 inline
1123 const T&
1124 operator [] (unsigned int i) const
1125 {
1126 return stack_[range_ - i];
1127 }
1128
1129 private:
1130
1131 const S& stack_;
1132 unsigned int range_;
1133 };
1134}
1135
1136#endif // not BISON_STACK_HH]
1137m4_divert(-1)