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