]> git.saurik.com Git - bison.git/blob - data/lalr1.cc
* data/yacc.c (malloc, free) [defined __cplusplus]: Wrap inside extern "C" {}.
[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 /* INFRINGES ON USER NAME SPACE */
421 #ifndef _
422 # define _(msgid) msgid
423 #endif
424
425 /* A pseudo ostream that takes yydebug_ into account. */
426 # define YYCDEBUG \
427 for (bool yydebugcond_ = yydebug_; yydebugcond_; yydebugcond_ = false) \
428 (*yycdebug_)
429
430 /* Enable debugging if requested. */
431 #if YYDEBUG
432
433 # define YY_SYMBOL_PRINT(Title, Type, Value, Location) \
434 do { \
435 if (yydebug_) \
436 { \
437 *yycdebug_ << (Title) << ' '; \
438 yysymprint_ ((Type), (Value), (Location)); \
439 *yycdebug_ << std::endl; \
440 } \
441 } while (0)
442
443 # define YY_REDUCE_PRINT(Rule) \
444 do { \
445 if (yydebug_) \
446 yyreduce_print_ (Rule); \
447 } while (0)
448
449 # define YY_STACK_PRINT() \
450 do { \
451 if (yydebug_) \
452 yystack_print_ (); \
453 } while (0)
454
455 #else /* !YYDEBUG */
456
457 # define YY_SYMBOL_PRINT(Title, Type, Value, Location)
458 # define YY_REDUCE_PRINT(Rule)
459 # define YY_STACK_PRINT()
460
461 #endif /* !YYDEBUG */
462
463 #define YYACCEPT goto yyacceptlab
464 #define YYABORT goto yyabortlab
465 #define YYERROR goto yyerrorlab
466
467 #if YYDEBUG
468 /*--------------------------------.
469 | Print this symbol on YYOUTPUT. |
470 `--------------------------------*/
471
472 void
473 yy::]b4_parser_class_name[::yysymprint_ (int yytype,
474 const semantic_type* yyvaluep, const location_type* yylocationp)
475 {
476 /* Pacify ``unused variable'' warnings. */
477 (void) yyvaluep;
478 (void) yylocationp;
479 /* Backward compatibility, but should be removed eventually. */
480 std::ostream& cdebug_ = *yycdebug_;
481 (void) cdebug_;
482
483 *yycdebug_ << (yytype < yyntokens_ ? "token" : "nterm")
484 << ' ' << yyname_[yytype] << " ("
485 << *yylocationp << ": ";
486 switch (yytype)
487 {
488 ]m4_map([b4_symbol_actions], m4_defn([b4_symbol_printers]))dnl
489 [ default:
490 break;
491 }
492 *yycdebug_ << ')';
493 }
494 #endif /* ! YYDEBUG */
495
496 void
497 yy::]b4_parser_class_name[::yydestruct_ (const char* yymsg,
498 int yytype, semantic_type* yyvaluep, location_type* yylocationp)
499 {
500 /* Pacify ``unused variable'' warnings. */
501 (void) yymsg;
502 (void) yyvaluep;
503 (void) yylocationp;
504
505 YY_SYMBOL_PRINT (yymsg, yytype, yyvaluep, yylocationp);
506
507 switch (yytype)
508 {
509 ]m4_map([b4_symbol_actions], m4_defn([b4_symbol_destructors]))[
510 default:
511 break;
512 }
513 }
514
515 void
516 yy::]b4_parser_class_name[::yypop_ (unsigned int n)
517 {
518 yystate_stack_.pop (n);
519 yysemantic_stack_.pop (n);
520 yylocation_stack_.pop (n);
521 }
522
523 std::ostream&
524 yy::]b4_parser_class_name[::debug_stream () const
525 {
526 return *yycdebug_;
527 }
528
529 void
530 yy::]b4_parser_class_name[::set_debug_stream (std::ostream& o)
531 {
532 yycdebug_ = &o;
533 }
534
535
536 yy::]b4_parser_class_name[::debug_level_type
537 yy::]b4_parser_class_name[::debug_level () const
538 {
539 return yydebug_;
540 }
541
542 void
543 yy::]b4_parser_class_name[::set_debug_level (debug_level_type l)
544 {
545 yydebug_ = l;
546 }
547
548
549 int
550 yy::]b4_parser_class_name[::parse ()
551 {
552 int yyresult_;
553
554 YYCDEBUG << _("Starting parse") << std::endl;
555
556 yynerrs_ = 0;
557 yyerrstatus_ = 0;
558
559 /* Start. */
560 yystate_ = 0;
561 yylooka_ = yyempty_;
562
563 ]m4_ifdef([b4_initial_action], [
564 m4_pushdef([b4_at_dollar], [yylloc])dnl
565 m4_pushdef([b4_dollar_dollar], [yylval])dnl
566 /* User initialization code. */
567 b4_initial_action
568 m4_popdef([b4_dollar_dollar])dnl
569 m4_popdef([b4_at_dollar])dnl
570 /* Line __line__ of yacc.c. */
571 b4_syncline([@oline@], [@ofile@])])dnl
572
573 [ /* Initialize the stacks. The initial state will be pushed in
574 yynewstate, since the latter expects the semantical and the
575 location values to have been already stored, initialize these
576 stacks with a primary value. */
577 yystate_stack_ = state_stack_type (0);
578 yysemantic_stack_ = semantic_stack_type (0);
579 yylocation_stack_ = location_stack_type (0);
580 yysemantic_stack_.push (yylval);
581 yylocation_stack_.push (yylloc);
582
583 /* New state. */
584 yynewstate:
585 yystate_stack_.push (yystate_);
586 YYCDEBUG << _("Entering state ") << yystate_ << std::endl;
587 goto yybackup;
588
589 /* Backup. */
590 yybackup:
591
592 /* Try to take a decision without look-ahead. */
593 yyn_ = yypact_[yystate_];
594 if (yyn_ == yypact_ninf_)
595 goto yydefault;
596
597 /* Read a look-ahead token. */
598 if (yylooka_ == yyempty_)
599 yylex_ ();
600
601 /* Convert token to internal form. */
602 if (yylooka_ <= yyeof_)
603 {
604 yylooka_ = yyilooka_ = yyeof_;
605 YYCDEBUG << _("Now at end of input.") << std::endl;
606 }
607 else
608 {
609 yyilooka_ = yytranslate_ (yylooka_);
610 YY_SYMBOL_PRINT (_("Next token is"), yyilooka_, &yylval, &yylloc);
611 }
612
613 /* If the proper action on seeing token ILOOKA_ is to reduce or to
614 detect an error, take that action. */
615 yyn_ += yyilooka_;
616 if (yyn_ < 0 || yylast_ < yyn_ || yycheck_[yyn_] != yyilooka_)
617 goto yydefault;
618
619 /* Reduce or error. */
620 yyn_ = yytable_[yyn_];
621 if (yyn_ < 0)
622 {
623 if (yyn_ == yytable_ninf_)
624 goto yyerrlab;
625 else
626 {
627 yyn_ = -yyn_;
628 goto yyreduce;
629 }
630 }
631 else if (yyn_ == 0)
632 goto yyerrlab;
633
634 /* Accept? */
635 if (yyn_ == yyfinal_)
636 goto yyacceptlab;
637
638 /* Shift the look-ahead token. */
639 YY_SYMBOL_PRINT (_("Shifting"), yyilooka_, &yylval, &yylloc);
640
641 /* Discard the token being shifted unless it is eof. */
642 if (yylooka_ != yyeof_)
643 yylooka_ = yyempty_;
644
645 yysemantic_stack_.push (yylval);
646 yylocation_stack_.push (yylloc);
647
648 /* Count tokens shifted since error; after three, turn off error
649 status. */
650 if (yyerrstatus_)
651 --yyerrstatus_;
652
653 yystate_ = yyn_;
654 goto yynewstate;
655
656 /*-----------------------------------------------------------.
657 | yydefault -- do the default action for the current state. |
658 `-----------------------------------------------------------*/
659 yydefault:
660 yyn_ = yydefact_[yystate_];
661 if (yyn_ == 0)
662 goto yyerrlab;
663 goto yyreduce;
664
665 /*-----------------------------.
666 | yyreduce -- Do a reduction. |
667 `-----------------------------*/
668 yyreduce:
669 yylen_ = yyr2_[yyn_];
670 /* If LEN_ is nonzero, implement the default value of the action:
671 `$$ = $1'. Otherwise, use the top of the stack.
672
673 Otherwise, the following line sets YYVAL to garbage.
674 This behavior is undocumented and Bison
675 users should not rely upon it. */
676 if (yylen_)
677 yyval = yysemantic_stack_[yylen_ - 1];
678 else
679 yyval = yysemantic_stack_[0];
680
681 {
682 slice<location_type, location_stack_type> slice (yylocation_stack_, yylen_);
683 YYLLOC_DEFAULT (yyloc, slice, yylen_);
684 }
685 YY_REDUCE_PRINT (yyn_);
686 switch (yyn_)
687 {
688 ]b4_actions[
689 default: break;
690 }
691
692 ]/* Line __line__ of lalr1.cc. */
693 b4_syncline([@oline@], [@ofile@])[
694
695 yypop_ (yylen_);
696
697 YY_STACK_PRINT ();
698
699 yysemantic_stack_.push (yyval);
700 yylocation_stack_.push (yyloc);
701
702 /* Shift the result of the reduction. */
703 yyn_ = yyr1_[yyn_];
704 yystate_ = yypgoto_[yyn_ - yyntokens_] + yystate_stack_[0];
705 if (0 <= yystate_ && yystate_ <= yylast_
706 && yycheck_[yystate_] == yystate_stack_[0])
707 yystate_ = yytable_[yystate_];
708 else
709 yystate_ = yydefgoto_[yyn_ - yyntokens_];
710 goto yynewstate;
711
712 /*------------------------------------.
713 | yyerrlab -- here on detecting error |
714 `------------------------------------*/
715 yyerrlab:
716 /* If not already recovering from an error, report this error. */
717 yyreport_syntax_error_ ();
718
719 yyerror_range_[0] = yylloc;
720 if (yyerrstatus_ == 3)
721 {
722 /* If just tried and failed to reuse look-ahead token after an
723 error, discard it. */
724
725 /* Return failure if at end of input. */
726 if (yylooka_ <= yyeof_)
727 {
728 /* If at end of input, pop the error token,
729 then the rest of the stack, then return failure. */
730 if (yylooka_ == yyeof_)
731 for (;;)
732 {
733 yyerror_range_[0] = yylocation_stack_[0];
734 yypop_ ();
735 if (yystate_stack_.height () == 1)
736 YYABORT;
737 yydestruct_ (_("Error: popping"),
738 yystos_[yystate_stack_[0]],
739 &yysemantic_stack_[0],
740 &yylocation_stack_[0]);
741 }
742 }
743 else
744 {
745 yydestruct_ (_("Error: discarding"), yyilooka_, &yylval, &yylloc);
746 yylooka_ = yyempty_;
747 }
748 }
749
750 /* Else will try to reuse look-ahead token after shifting the error
751 token. */
752 goto yyerrlab1;
753
754
755 /*---------------------------------------------------.
756 | yyerrorlab -- error raised explicitly by YYERROR. |
757 `---------------------------------------------------*/
758 yyerrorlab:
759
760 /* Pacify compilers like GCC when the user code never invokes
761 YYERROR and the label yyerrorlab therefore never appears in user
762 code. */
763 if (false)
764 goto yyerrorlab;
765
766 yyerror_range_[0] = yylocation_stack_[yylen_ - 1];
767 yypop_ (yylen_);
768 yystate_ = yystate_stack_[0];
769 goto yyerrlab1;
770
771 /*-------------------------------------------------------------.
772 | yyerrlab1 -- common code for both syntax error and YYERROR. |
773 `-------------------------------------------------------------*/
774 yyerrlab1:
775 yyerrstatus_ = 3; /* Each real token shifted decrements this. */
776
777 for (;;)
778 {
779 yyn_ = yypact_[yystate_];
780 if (yyn_ != yypact_ninf_)
781 {
782 yyn_ += yyterror_;
783 if (0 <= yyn_ && yyn_ <= yylast_ && yycheck_[yyn_] == yyterror_)
784 {
785 yyn_ = yytable_[yyn_];
786 if (0 < yyn_)
787 break;
788 }
789 }
790
791 /* Pop the current state because it cannot handle the error token. */
792 if (yystate_stack_.height () == 1)
793 YYABORT;
794
795 yyerror_range_[0] = yylocation_stack_[0];
796 yydestruct_ (_("Error: popping"),
797 yystos_[yystate_],
798 &yysemantic_stack_[0], &yylocation_stack_[0]);
799 yypop_ ();
800 yystate_ = yystate_stack_[0];
801 YY_STACK_PRINT ();
802 }
803
804 if (yyn_ == yyfinal_)
805 goto yyacceptlab;
806
807 yyerror_range_[1] = yylloc;
808 // Using YYLLOC is tempting, but would change the location of
809 // the look-ahead. YYLOC is available though.
810 YYLLOC_DEFAULT (yyloc, yyerror_range_ - 1, 2);
811 yysemantic_stack_.push (yylval);
812 yylocation_stack_.push (yyloc);
813
814 /* Shift the error token. */
815 YY_SYMBOL_PRINT (_("Shifting"), yystos_[yyn_],
816 &yysemantic_stack_[0], &yylocation_stack_[0]);
817
818 yystate_ = yyn_;
819 goto yynewstate;
820
821 /* Accept. */
822 yyacceptlab:
823 yyresult_ = 0;
824 goto yyreturn;
825
826 /* Abort. */
827 yyabortlab:
828 yyresult_ = 1;
829 goto yyreturn;
830
831 yyreturn:
832 if (yylooka_ != yyeof_ && yylooka_ != yyempty_)
833 yydestruct_ (_("Error: discarding lookahead"), yyilooka_, &yylval, &yylloc);
834 return yyresult_;
835 }
836
837 void
838 yy::]b4_parser_class_name[::yylex_ ()
839 {
840 YYCDEBUG << _("Reading a token: ");
841 #if YYLSP_NEEDED
842 yylooka_ = yylex (&yylval, &yylloc);
843 #else
844 yylooka_ = yylex (&yylval);
845 #endif
846 }
847
848 // Generate an error message, and invoke error.
849 void
850 yy::]b4_parser_class_name[::yyreport_syntax_error_ ()
851 {
852 /* If not already recovering from an error, report this error. */
853 if (!yyerrstatus_)
854 {
855 ++yynerrs_;
856 std::string message;
857 #if YYERROR_VERBOSE
858 yyn_ = yypact_[yystate_];
859 if (yypact_ninf_ < yyn_ && yyn_ < yylast_)
860 {
861 /* Start YYX at -YYN if negative to avoid negative indexes in
862 YYCHECK. */
863 int yyxbegin = yyn_ < 0 ? -yyn_ : 0;
864
865 /* Stay within bounds of both yycheck and yytname. */
866 int yychecklim = yylast_ - yyn_;
867 int yyxend = yychecklim < yyntokens_ ? yychecklim : yyntokens_;
868 int count = 0;
869 for (int x = yyxbegin; x < yyxend; ++x)
870 if (yycheck_[x + yyn_] == x && x != yyterror_)
871 ++count;
872
873 message = _("syntax error, unexpected ");
874 message += yyname_[yyilooka_];
875 if (count < 5)
876 {
877 count = 0;
878 for (int x = yyxbegin; x < yyxend; ++x)
879 if (yycheck_[x + yyn_] == x && x != yyterror_)
880 {
881 message += (!count++) ? _(", expecting ") : _(" or ");
882 message += yyname_[x];
883 }
884 }
885 }
886 else
887 #endif
888 message = _("syntax error");
889 error (yylloc, message);
890 }
891 }
892
893
894 /* YYPACT[STATE-NUM] -- Index in YYTABLE of the portion describing
895 STATE-NUM. */
896 const ]b4_int_type(b4_pact_ninf, b4_pact_ninf) yy::b4_parser_class_name::yypact_ninf_ = b4_pact_ninf[;
897 const ]b4_int_type_for([b4_pact])[
898 yy::]b4_parser_class_name[::yypact_[] =
899 {
900 ]b4_pact[
901 };
902
903 /* YYDEFACT[S] -- default rule to reduce with in state S when YYTABLE
904 doesn't specify something else to do. Zero means the default is an
905 error. */
906 const ]b4_int_type_for([b4_defact])[
907 yy::]b4_parser_class_name[::yydefact_[] =
908 {
909 ]b4_defact[
910 };
911
912 /* YYPGOTO[NTERM-NUM]. */
913 const ]b4_int_type_for([b4_pgoto])[
914 yy::]b4_parser_class_name[::yypgoto_[] =
915 {
916 ]b4_pgoto[
917 };
918
919 /* YYDEFGOTO[NTERM-NUM]. */
920 const ]b4_int_type_for([b4_defgoto])[
921 yy::]b4_parser_class_name[::yydefgoto_[] =
922 {
923 ]b4_defgoto[
924 };
925
926 /* YYTABLE[YYPACT[STATE-NUM]]. What to do in state STATE-NUM. If
927 positive, shift that token. If negative, reduce the rule which
928 number is the opposite. If zero, do what YYDEFACT says. */
929 const ]b4_int_type(b4_table_ninf, b4_table_ninf) yy::b4_parser_class_name::yytable_ninf_ = b4_table_ninf[;
930 const ]b4_int_type_for([b4_table])[
931 yy::]b4_parser_class_name[::yytable_[] =
932 {
933 ]b4_table[
934 };
935
936 /* YYCHECK. */
937 const ]b4_int_type_for([b4_check])[
938 yy::]b4_parser_class_name[::yycheck_[] =
939 {
940 ]b4_check[
941 };
942
943 /* STOS_[STATE-NUM] -- The (internal number of the) accessing
944 symbol of state STATE-NUM. */
945 const ]b4_int_type_for([b4_stos])[
946 yy::]b4_parser_class_name[::yystos_[] =
947 {
948 ]b4_stos[
949 };
950
951 #if YYDEBUG
952 /* TOKEN_NUMBER_[YYLEX-NUM] -- Internal symbol number corresponding
953 to YYLEX-NUM. */
954 const ]b4_int_type_for([b4_toknum])[
955 yy::]b4_parser_class_name[::yytoken_number_[] =
956 {
957 ]b4_toknum[
958 };
959 #endif
960
961 /* YYR1[YYN] -- Symbol number of symbol that rule YYN derives. */
962 const ]b4_int_type_for([b4_r1])[
963 yy::]b4_parser_class_name[::yyr1_[] =
964 {
965 ]b4_r1[
966 };
967
968 /* YYR2[YYN] -- Number of symbols composing right hand side of rule YYN. */
969 const ]b4_int_type_for([b4_r2])[
970 yy::]b4_parser_class_name[::yyr2_[] =
971 {
972 ]b4_r2[
973 };
974
975 #if YYDEBUG || YYERROR_VERBOSE
976 /* YYTNAME[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM.
977 First, the terminals, then, starting at \a yyntokens_, nonterminals. */
978 const char*
979 const yy::]b4_parser_class_name[::yyname_[] =
980 {
981 ]b4_tname[
982 };
983 #endif
984
985 #if YYDEBUG
986 /* YYRHS -- A `-1'-separated list of the rules' RHS. */
987 const yy::]b4_parser_class_name[::rhs_number_type
988 yy::]b4_parser_class_name[::yyrhs_[] =
989 {
990 ]b4_rhs[
991 };
992
993 /* YYPRHS[YYN] -- Index of the first RHS symbol of rule number YYN in
994 YYRHS. */
995 const ]b4_int_type_for([b4_prhs])[
996 yy::]b4_parser_class_name[::yyprhs_[] =
997 {
998 ]b4_prhs[
999 };
1000
1001 /* YYRLINE[YYN] -- Source line where rule number YYN was defined. */
1002 const ]b4_int_type_for([b4_rline])[
1003 yy::]b4_parser_class_name[::yyrline_[] =
1004 {
1005 ]b4_rline[
1006 };
1007
1008 // Print the state stack on the debug stream.
1009 void
1010 yy::]b4_parser_class_name[::yystack_print_ ()
1011 {
1012 *yycdebug_ << _("Stack now");
1013 for (state_stack_type::const_iterator i = yystate_stack_.begin ();
1014 i != yystate_stack_.end (); ++i)
1015 *yycdebug_ << ' ' << *i;
1016 *yycdebug_ << std::endl;
1017 }
1018
1019 // Report on the debug stream that the rule \a yyrule is going to be reduced.
1020 void
1021 yy::]b4_parser_class_name[::yyreduce_print_ (int yyrule)
1022 {
1023 unsigned int yylno = yyrline_[yyrule];
1024 /* Print the symbols being reduced, and their result. */
1025 *yycdebug_ << _("Reducing stack by rule ") << yyn_ - 1
1026 << " (" << _("line") << ' ' << yylno << "), ";
1027 for (]b4_int_type_for([b4_prhs])[ i = yyprhs_[yyn_];
1028 0 <= yyrhs_[i]; ++i)
1029 *yycdebug_ << yyname_[yyrhs_[i]] << ' ';
1030 *yycdebug_ << "-> " << yyname_[yyr1_[yyn_]] << std::endl;
1031 }
1032 #endif // YYDEBUG
1033
1034 /* YYTRANSLATE(YYLEX) -- Bison symbol number corresponding to YYLEX. */
1035 yy::]b4_parser_class_name[::token_number_type
1036 yy::]b4_parser_class_name[::yytranslate_ (int token)
1037 {
1038 static
1039 const token_number_type
1040 translate_table[] =
1041 {
1042 ]b4_translate[
1043 };
1044 if ((unsigned int) token <= yyuser_token_number_max_)
1045 return translate_table[token];
1046 else
1047 return yyundef_token_;
1048 }
1049
1050 const int yy::]b4_parser_class_name[::yyeof_ = 0;
1051 const int yy::]b4_parser_class_name[::yylast_ = ]b4_last[;
1052 const int yy::]b4_parser_class_name[::yynnts_ = ]b4_nterms_number[;
1053 const int yy::]b4_parser_class_name[::yyempty_ = -2;
1054 const int yy::]b4_parser_class_name[::yyfinal_ = ]b4_final_state_number[;
1055 const int yy::]b4_parser_class_name[::yyterror_ = 1;
1056 const int yy::]b4_parser_class_name[::yyerrcode_ = 256;
1057 const int yy::]b4_parser_class_name[::yyntokens_ = ]b4_tokens_number[;
1058
1059 const unsigned int yy::]b4_parser_class_name[::yyuser_token_number_max_ = ]b4_user_token_number_max[;
1060 const yy::]b4_parser_class_name[::token_number_type yy::]b4_parser_class_name[::yyundef_token_ = ]b4_undef_token_number[;
1061
1062 ]b4_epilogue
1063 dnl
1064 @output stack.hh
1065 b4_copyright([stack handling for Bison C++ parsers], [2002, 2003, 2004, 2005])[
1066
1067 #ifndef BISON_STACK_HH
1068 # define BISON_STACK_HH
1069
1070 #include <deque>
1071
1072 namespace yy
1073 {
1074 template <class T, class S = std::deque<T> >
1075 class stack
1076 {
1077 public:
1078
1079 // Hide our reversed order.
1080 typedef typename S::reverse_iterator iterator;
1081 typedef typename S::const_reverse_iterator const_iterator;
1082
1083 stack () : seq_ ()
1084 {
1085 }
1086
1087 stack (unsigned int n) : seq_ (n)
1088 {
1089 }
1090
1091 inline
1092 T&
1093 operator [] (unsigned int i)
1094 {
1095 return seq_[i];
1096 }
1097
1098 inline
1099 const T&
1100 operator [] (unsigned int i) const
1101 {
1102 return seq_[i];
1103 }
1104
1105 inline
1106 void
1107 push (const T& t)
1108 {
1109 seq_.push_front (t);
1110 }
1111
1112 inline
1113 void
1114 pop (unsigned int n = 1)
1115 {
1116 for (; n; --n)
1117 seq_.pop_front ();
1118 }
1119
1120 inline
1121 unsigned int
1122 height () const
1123 {
1124 return seq_.size ();
1125 }
1126
1127 inline const_iterator begin () const { return seq_.rbegin (); }
1128 inline const_iterator end () const { return seq_.rend (); }
1129
1130 private:
1131
1132 S seq_;
1133 };
1134
1135 /// Present a slice of the top of a stack.
1136 template <class T, class S = stack<T> >
1137 class slice
1138 {
1139 public:
1140
1141 slice (const S& stack,
1142 unsigned int range) : stack_ (stack),
1143 range_ (range)
1144 {
1145 }
1146
1147 inline
1148 const T&
1149 operator [] (unsigned int i) const
1150 {
1151 return stack_[range_ - i];
1152 }
1153
1154 private:
1155
1156 const S& stack_;
1157 unsigned int range_;
1158 };
1159 }
1160
1161 #endif // not BISON_STACK_HH]
1162 dnl
1163 @output position.hh
1164 b4_copyright([Position class for Bison C++ parsers], [2002, 2003, 2004, 2005])[
1165
1166 /**
1167 ** \file position.hh
1168 ** Define the position class.
1169 */
1170
1171 #ifndef BISON_POSITION_HH
1172 # define BISON_POSITION_HH
1173
1174 # include <iostream>
1175 # include <string>
1176
1177 namespace yy
1178 {
1179 /// Abstract a position.
1180 class position
1181 {
1182 public:
1183 /// Initial column number.
1184 static const unsigned int initial_column = 0;
1185 /// Initial line number.
1186 static const unsigned int initial_line = 1;
1187
1188 /** \name Ctor & dtor.
1189 ** \{ */
1190 public:
1191 /// Construct a position.
1192 position () :
1193 filename (0),
1194 line (initial_line),
1195 column (initial_column)
1196 {
1197 }
1198 /** \} */
1199
1200
1201 /** \name Line and Column related manipulators
1202 ** \{ */
1203 public:
1204 /// (line related) Advance to the COUNT next lines.
1205 inline void lines (int count = 1)
1206 {
1207 column = initial_column;
1208 line += count;
1209 }
1210
1211 /// (column related) Advance to the COUNT next columns.
1212 inline void columns (int count = 1)
1213 {
1214 int leftmost = initial_column;
1215 int current = column;
1216 if (leftmost <= current + count)
1217 column += count;
1218 else
1219 column = initial_column;
1220 }
1221 /** \} */
1222
1223 public:
1224 /// File name to which this position refers.
1225 ]b4_filename_type[* filename;
1226 /// Current line number.
1227 unsigned int line;
1228 /// Current column number.
1229 unsigned int column;
1230 };
1231
1232 /// Add and assign a position.
1233 inline const position&
1234 operator+= (position& res, const int width)
1235 {
1236 res.columns (width);
1237 return res;
1238 }
1239
1240 /// Add two position objects.
1241 inline const position
1242 operator+ (const position& begin, const int width)
1243 {
1244 position res = begin;
1245 return res += width;
1246 }
1247
1248 /// Add and assign a position.
1249 inline const position&
1250 operator-= (position& res, const int width)
1251 {
1252 return res += -width;
1253 }
1254
1255 /// Add two position objects.
1256 inline const position
1257 operator- (const position& begin, const int width)
1258 {
1259 return begin + -width;
1260 }
1261
1262 /** \brief Intercept output stream redirection.
1263 ** \param ostr the destination output stream
1264 ** \param pos a reference to the position to redirect
1265 */
1266 inline std::ostream&
1267 operator<< (std::ostream& ostr, const position& pos)
1268 {
1269 if (pos.filename)
1270 ostr << *pos.filename << ':';
1271 return ostr << pos.line << '.' << pos.column;
1272 }
1273
1274 }
1275 #endif // not BISON_POSITION_HH]
1276 @output location.hh
1277 b4_copyright([Location class for Bison C++ parsers], [2002, 2003, 2004, 2005])[
1278
1279 /**
1280 ** \file location.hh
1281 ** Define the location class.
1282 */
1283
1284 #ifndef BISON_LOCATION_HH
1285 # define BISON_LOCATION_HH
1286
1287 # include <iostream>
1288 # include <string>
1289 # include "position.hh"
1290
1291 namespace yy
1292 {
1293
1294 /// Abstract a location.
1295 class location
1296 {
1297 /** \name Ctor & dtor.
1298 ** \{ */
1299 public:
1300 /// Construct a location.
1301 location () :
1302 begin (),
1303 end ()
1304 {
1305 }
1306 /** \} */
1307
1308
1309 /** \name Line and Column related manipulators
1310 ** \{ */
1311 public:
1312 /// Reset initial location to final location.
1313 inline void step ()
1314 {
1315 begin = end;
1316 }
1317
1318 /// Extend the current location to the COUNT next columns.
1319 inline void columns (unsigned int count = 1)
1320 {
1321 end += count;
1322 }
1323
1324 /// Extend the current location to the COUNT next lines.
1325 inline void lines (unsigned int count = 1)
1326 {
1327 end.lines (count);
1328 }
1329 /** \} */
1330
1331
1332 public:
1333 /// Beginning of the located region.
1334 position begin;
1335 /// End of the located region.
1336 position end;
1337 };
1338
1339 /// Join two location objects to create a location.
1340 inline const location operator+ (const location& begin, const location& end)
1341 {
1342 location res = begin;
1343 res.end = end.end;
1344 return res;
1345 }
1346
1347 /// Add two location objects.
1348 inline const location operator+ (const location& begin, unsigned int width)
1349 {
1350 location res = begin;
1351 res.columns (width);
1352 return res;
1353 }
1354
1355 /// Add and assign a location.
1356 inline location& operator+= (location& res, unsigned int width)
1357 {
1358 res.columns (width);
1359 return res;
1360 }
1361
1362 /** \brief Intercept output stream redirection.
1363 ** \param ostr the destination output stream
1364 ** \param loc a reference to the location to redirect
1365 **
1366 ** Avoid duplicate information.
1367 */
1368 inline std::ostream& operator<< (std::ostream& ostr, const location& loc)
1369 {
1370 position last = loc.end - 1;
1371 ostr << loc.begin;
1372 if (last.filename
1373 && (!loc.begin.filename
1374 || *loc.begin.filename != *last.filename))
1375 ostr << '-' << last;
1376 else if (loc.begin.line != last.line)
1377 ostr << '-' << last.line << '.' << last.column;
1378 else if (loc.begin.column != last.column)
1379 ostr << '-' << last.column;
1380 return ostr;
1381 }
1382
1383 }
1384
1385 #endif // not BISON_LOCATION_HH]