]> git.saurik.com Git - bison.git/blob - data/lalr1.cc
* data/glr.c (yy_reduce_print): Fix the $ number.
[bison.git] / data / lalr1.cc
1 m4_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
22 m4_include(b4_pkgdatadir/[c++.m4])
23 # Backward compatibility.
24 m4_define([b4_location_constructors])
25 m4_include(b4_pkgdatadir/[location.cc])
26
27 # We do want M4 expansion after # for CPP macros.
28 m4_changecom()
29 m4_divert(0)dnl
30 m4_if(b4_defines_flag, 0, [],
31 [@output @output_header_name@
32 b4_copyright([C++ Skeleton parser for LALR(1) parsing with Bison],
33 [2002, 2003, 2004, 2005])
34 dnl FIXME: This is wrong, we want computed header guards.
35 [
36 #ifndef PARSER_HEADER_H
37 # define PARSER_HEADER_H
38
39 #include <string>
40 #include <iostream>
41 #include "stack.hh"
42
43 namespace yy
44 {
45 class position;
46 class location;
47 }
48
49 /* First part of user declarations. */
50 ]b4_pre_prologue[
51
52 ]/* Line __line__ of lalr1.cc. */
53 b4_syncline([@oline@], [@ofile@])[
54
55 ]dnl Include location.hh here: it might depend on headers included above.
56 [#include "location.hh"
57
58 /* Enabling traces. */
59 #ifndef YYDEBUG
60 # define YYDEBUG ]b4_debug[
61 #endif
62
63 /* Enabling verbose error messages. */
64 #ifdef YYERROR_VERBOSE
65 # undef YYERROR_VERBOSE
66 # define YYERROR_VERBOSE 1
67 #else
68 # define YYERROR_VERBOSE ]b4_error_verbose[
69 #endif
70
71 /* Enabling the token table. */
72 #ifndef YYTOKEN_TABLE
73 # define YYTOKEN_TABLE ]b4_token_table[
74 #endif
75
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). */
79
80 #ifndef YYLLOC_DEFAULT
81 # define YYLLOC_DEFAULT(Current, Rhs, N) \
82 do { \
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 } \
92 } while (false)
93 #endif
94
95 namespace yy
96 {
97
98 /// A Bison parser.
99 class ]b4_parser_class_name[
100 {
101 public:
102 /// Symbol semantic values.
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. */
108 b4_syncline([@oline@], [@ofile@])],
109 [ typedef int semantic_type;])[
110 #else
111 typedef YYSTYPE semantic_type;
112 #endif
113 /// Symbol locations.
114 typedef ]b4_location_type[ location_type;
115 /// Tokens.
116 struct token
117 {
118 ]b4_token_enums(b4_tokens)[
119 };
120
121 /// Build a parser object.
122 ]b4_parser_class_name[ (]b4_parse_param_decl[);
123 virtual ~]b4_parser_class_name[ ();
124
125 /// Parse.
126 /// \returns 0 iff parsing succeeded.
127 virtual int parse ();
128
129 /// The current debugging stream.
130 std::ostream& debug_stream () const;
131 /// Set the current debugging stream.
132 void set_debug_stream (std::ostream &);
133
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
141 private:
142 /// Report a syntax error.
143 /// \param loc where the syntax error is found.
144 /// \param msg a description of the syntax error.
145 virtual void error (const location_type& loc, const std::string& msg);
146
147 /// Generate an error message.
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
151 b4_error_verbose_if([, int tok])[);
152
153 #if YYDEBUG
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,
159 const semantic_type* yyvaluep,
160 const location_type* yylocationp);
161 #endif /* ! YYDEBUG */
162
163
164 /// State numbers.
165 typedef int state_type;
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
173 /// The state stack.
174 state_stack_type yystate_stack_;
175 /// The semantic value stack.
176 semantic_stack_type yysemantic_stack_;
177 /// The location stack.
178 location_stack_type yylocation_stack_;
179
180 /// Internal symbol numbers.
181 typedef ]b4_int_type_for([b4_translate])[ token_number_type;
182 /* Tables. */
183 /// For a state, the index in \a yytable_ of its portion.
184 static const ]b4_int_type_for([b4_pact])[ yypact_[];
185 static const ]b4_int_type(b4_pact_ninf, b4_pact_ninf)[ yypact_ninf_;
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.
190 static const ]b4_int_type_for([b4_defact])[ yydefact_[];
191
192 static const ]b4_int_type_for([b4_pgoto])[ yypgoto_[];
193 static const ]b4_int_type_for([b4_defgoto])[ yydefgoto_[];
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.
200 static const ]b4_int_type_for([b4_table])[ yytable_[];
201 static const ]b4_int_type(b4_table_ninf, b4_table_ninf)[ yytable_ninf_;
202
203 static const ]b4_int_type_for([b4_check])[ yycheck_[];
204
205 /// For a state, its accessing symbol.
206 static const ]b4_int_type_for([b4_stos])[ yystos_[];
207
208 /// For a rule, its LHS.
209 static const ]b4_int_type_for([b4_r1])[ yyr1_[];
210 /// For a rule, its RHS length.
211 static const ]b4_int_type_for([b4_r2])[ yyr2_[];
212
213 #if YYDEBUG || YYERROR_VERBOSE || YYTOKEN_TABLE
214 /// For a symbol, its name in clear.
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);
221 #endif
222
223 #if YYDEBUG
224 /// A type to store symbol numbers and -1.
225 typedef ]b4_int_type_for([b4_rhs])[ rhs_number_type;
226 /// A `-1'-separated list of the rules' RHS.
227 static const rhs_number_type yyrhs_[];
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_[];
234 /// Report on the debug stream that the rule \a r is going to be reduced.
235 virtual void yyreduce_print_ (int r);
236 /// Print the state stack on the debug stream.
237 virtual void yystack_print_ ();
238 #endif
239
240 /// Convert a scanner token number to a symbol number.
241 inline token_number_type yytranslate_ (int token);
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,
250 semantic_type* yyvaluep,
251 location_type* yylocationp);
252
253 /// Pop \a n symbols the three stacks.
254 inline void yypop_ (unsigned int n = 1);
255
256 /* Constants. */
257 static const int yyeof_;
258 /* LAST_ -- Last index in TABLE_. */
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_;
267 static const token_number_type yyundef_token_;
268
269 /* Debugging. */
270 int yydebug_;
271 std::ostream* yycdebug_;
272
273 ]b4_parse_param_vars[
274 };
275 }
276
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 ])[
285 #endif /* ! defined PARSER_HEADER_H */]
286 ])dnl
287 @output @output_parser_name@
288 b4_copyright([C++ Skeleton parser for LALR(1) parsing with Bison],
289 [2002, 2003, 2004, 2005])
290 m4_if(b4_prefix[], [yy], [],
291 [
292 // Take the name prefix into account.
293 #define yylex b4_prefix[]lex])
294 m4_if(b4_defines_flag, 0, [],
295 [
296 #include @output_header_name@])[
297
298 /* User implementation prologue. */
299 ]b4_post_prologue[
300
301 ]/* Line __line__ of lalr1.cc. */
302 b4_syncline([@oline@], [@ofile@])[
303
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
314 #endif
315
316 /* Suppress unused-variable warnings by "using" E. */
317 #define YYUSE(e) do {;} while (false && (e))
318
319 /* A pseudo ostream that takes yydebug_ into account. */
320 # define YYCDEBUG \
321 for (bool yydebugcond_ = yydebug_; yydebugcond_; yydebugcond_ = false) \
322 (*yycdebug_)
323
324 /* Enable debugging if requested. */
325 #if YYDEBUG
326
327 # define YY_SYMBOL_PRINT(Title, Type, Value, Location) \
328 do { \
329 if (yydebug_) \
330 { \
331 *yycdebug_ << (Title) << ' '; \
332 yysymprint_ ((Type), (Value), (Location)); \
333 *yycdebug_ << std::endl; \
334 } \
335 } while (false)
336
337 # define YY_REDUCE_PRINT(Rule) \
338 do { \
339 if (yydebug_) \
340 yyreduce_print_ (Rule); \
341 } while (false)
342
343 # define YY_STACK_PRINT() \
344 do { \
345 if (yydebug_) \
346 yystack_print_ (); \
347 } while (false)
348
349 #else /* !YYDEBUG */
350
351 # define YY_SYMBOL_PRINT(Title, Type, Value, Location)
352 # define YY_REDUCE_PRINT(Rule)
353 # define YY_STACK_PRINT()
354
355 #endif /* !YYDEBUG */
356
357 #define YYACCEPT goto yyacceptlab
358 #define YYABORT goto yyabortlab
359 #define YYERROR goto yyerrorlab
360
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. */
368 std::string
369 yy::]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
402 namespace yy
403 {
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 }
410
411 ]b4_parser_class_name::~b4_parser_class_name[ ()
412 {
413 }
414
415 #if YYDEBUG
416 /*--------------------------------.
417 | Print this symbol on YYOUTPUT. |
418 `--------------------------------*/
419
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 */
443
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 }
461
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 }
469
470 std::ostream&
471 ]b4_parser_class_name[::debug_stream () const
472 {
473 return *yycdebug_;
474 }
475
476 void
477 ]b4_parser_class_name[::set_debug_stream (std::ostream& o)
478 {
479 yycdebug_ = &o;
480 }
481
482
483 ]b4_parser_class_name[::debug_level_type
484 ]b4_parser_class_name[::debug_level () const
485 {
486 return yydebug_;
487 }
488
489 void
490 ]b4_parser_class_name[::set_debug_level (debug_level_type l)
491 {
492 yydebug_ = l;
493 }
494
495
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;
502
503 /* State. */
504 int yyn;
505 int yylen;
506 int yystate = 0;
507
508 /* Error handling. */
509 int yynerrs_ = 0;
510 int yyerrstatus_ = 0;
511
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];
518
519 /// $$.
520 semantic_type yyval;
521 /// @@$.
522 location_type yyloc;
523
524 int yyresult;
525
526 YYCDEBUG << "Starting parse" << std::endl;
527
528 ]m4_ifdef([b4_initial_action], [
529 m4_pushdef([b4_at_dollar], [yylloc])dnl
530 m4_pushdef([b4_dollar_dollar], [yylval])dnl
531 /* User initialization code. */
532 b4_initial_action
533 m4_popdef([b4_dollar_dollar])dnl
534 m4_popdef([b4_at_dollar])dnl
535 /* Line __line__ of yacc.c. */
536 b4_syncline([@oline@], [@ofile@])])dnl
537
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
568 b4_location_if([, [[location*], [&yylloc]]])dnl
569 m4_ifdef([b4_lex_param], [, ]b4_lex_param))[;
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];
647
648 {
649 slice<location_type, location_stack_type> slice (yylocation_stack_, yylen);
650 YYLLOC_DEFAULT (yyloc, slice, yylen);
651 }
652 YY_REDUCE_PRINT (yyn);
653 switch (yyn)
654 {
655 ]b4_actions[
656 default: break;
657 }
658
659 ]/* Line __line__ of lalr1.cc. */
660 b4_syncline([@oline@], [@ofile@])[
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
688 b4_error_verbose_if([, yytoken])[));
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 }
806
807 // Generate an error message.
808 std::string
809 ]b4_parser_class_name[::yysyntax_error_ (int yystate]dnl
810 b4_error_verbose_if([, int tok])[)
811 {
812 std::string res;
813 #if YYERROR_VERBOSE
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
851 #endif
852 res = YY_("syntax error");
853 return res;
854 }
855
856
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 };
865
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 };
874
875 /* YYPGOTO[NTERM-NUM]. */
876 const ]b4_int_type_for([b4_pgoto])[
877 ]b4_parser_class_name[::yypgoto_[] =
878 {
879 ]b4_pgoto[
880 };
881
882 /* YYDEFGOTO[NTERM-NUM]. */
883 const ]b4_int_type_for([b4_defgoto])[
884 ]b4_parser_class_name[::yydefgoto_[] =
885 {
886 ]b4_defgoto[
887 };
888
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 };
913
914 #if YYDEBUG
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 };
922 #endif
923
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 };
930
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 };
937
938 #if YYDEBUG || YYERROR_VERBOSE || YYTOKEN_TABLE
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 };
946 #endif
947
948 #if YYDEBUG
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 };
955
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 };
963
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 };
970
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 }
981
982 // Report on the debug stream that the rule \a yyrule is going to be reduced.
983 void
984 ]b4_parser_class_name[::yyreduce_print_ (int yyrule)
985 {
986 unsigned int yylno = yyrline_[yyrule];
987 /* Print the symbols being reduced, and their result. */
988 *yycdebug_ << "Reducing stack by rule " << yyrule - 1
989 << " (line " << yylno << "), ";
990 for (]b4_int_type_for([b4_prhs])[ i = yyprhs_[yyrule];
991 0 <= yyrhs_[i]; ++i)
992 *yycdebug_ << yytname_[yyrhs_[i]] << ' ';
993 *yycdebug_ << "-> " << yytname_[yyr1_[yyrule]] << std::endl;
994 }
995 #endif // YYDEBUG
996
997 /* YYTRANSLATE(YYLEX) -- Bison symbol number corresponding to YYLEX. */
998 ]b4_parser_class_name[::token_number_type
999 ]b4_parser_class_name[::yytranslate_ (int token)
1000 {
1001 static
1002 const token_number_type
1003 translate_table[] =
1004 {
1005 ]b4_translate[
1006 };
1007 if ((unsigned int) token <= yyuser_token_number_max_)
1008 return translate_table[token];
1009 else
1010 return yyundef_token_;
1011 }
1012
1013 const int ]b4_parser_class_name[::yyeof_ = 0;
1014 const int ]b4_parser_class_name[::yylast_ = ]b4_last[;
1015 const int ]b4_parser_class_name[::yynnts_ = ]b4_nterms_number[;
1016 const int ]b4_parser_class_name[::yyempty_ = -2;
1017 const int ]b4_parser_class_name[::yyfinal_ = ]b4_final_state_number[;
1018 const int ]b4_parser_class_name[::yyterror_ = 1;
1019 const int ]b4_parser_class_name[::yyerrcode_ = 256;
1020 const int ]b4_parser_class_name[::yyntokens_ = ]b4_tokens_number[;
1021
1022 const unsigned int ]b4_parser_class_name[::yyuser_token_number_max_ = ]b4_user_token_number_max[;
1023 const ]b4_parser_class_name[::token_number_type ]b4_parser_class_name[::yyundef_token_ = ]b4_undef_token_number[;
1024
1025 } // namespace yy
1026
1027 ]b4_epilogue
1028 dnl
1029 @output b4_dir_prefix[]stack.hh
1030 b4_copyright([stack handling for Bison C++ parsers], [2002, 2003, 2004, 2005])[
1031
1032 #ifndef BISON_STACK_HH
1033 # define BISON_STACK_HH
1034
1035 #include <deque>
1036
1037 namespace yy
1038 {
1039 template <class T, class S = std::deque<T> >
1040 class stack
1041 {
1042 public:
1043
1044 // Hide our reversed order.
1045 typedef typename S::reverse_iterator iterator;
1046 typedef typename S::const_reverse_iterator const_iterator;
1047
1048 stack () : seq_ ()
1049 {
1050 }
1051
1052 stack (unsigned int n) : seq_ (n)
1053 {
1054 }
1055
1056 inline
1057 T&
1058 operator [] (unsigned int i)
1059 {
1060 return seq_[i];
1061 }
1062
1063 inline
1064 const T&
1065 operator [] (unsigned int i) const
1066 {
1067 return seq_[i];
1068 }
1069
1070 inline
1071 void
1072 push (const T& t)
1073 {
1074 seq_.push_front (t);
1075 }
1076
1077 inline
1078 void
1079 pop (unsigned int n = 1)
1080 {
1081 for (; n; --n)
1082 seq_.pop_front ();
1083 }
1084
1085 inline
1086 unsigned int
1087 height () const
1088 {
1089 return seq_.size ();
1090 }
1091
1092 inline const_iterator begin () const { return seq_.rbegin (); }
1093 inline const_iterator end () const { return seq_.rend (); }
1094
1095 private:
1096
1097 S seq_;
1098 };
1099
1100 /// Present a slice of the top of a stack.
1101 template <class T, class S = stack<T> >
1102 class slice
1103 {
1104 public:
1105
1106 slice (const S& stack,
1107 unsigned int range) : stack_ (stack),
1108 range_ (range)
1109 {
1110 }
1111
1112 inline
1113 const T&
1114 operator [] (unsigned int i) const
1115 {
1116 return stack_[range_ - i];
1117 }
1118
1119 private:
1120
1121 const S& stack_;
1122 unsigned int range_;
1123 };
1124 }
1125
1126 #endif // not BISON_STACK_HH]
1127 m4_divert(-1)