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