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