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