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