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