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