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