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