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