2 # C++ skeleton for Bison
3 # Copyright (C) 2002, 2003, 2004 Free Software Foundation, Inc.
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.
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.
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
20 ## ---------------- ##
22 ## ---------------- ##
24 # Default parser class name.
25 m4_define_default([b4_parser_class_name
], [parser
])
29 ## ----------------- ##
30 ## Semantic Values. ##
31 ## ----------------- ##
34 # b4_lhs_value([TYPE])
35 # --------------------
36 # Expansion of $<TYPE>$.
37 m4_define([b4_lhs_value
],
38 [(yyval
[]m4_ifval([$
1], [.$
1]))])
41 # b4_rhs_value(RULE-LENGTH, NUM, [TYPE])
42 # --------------------------------------
43 # Expansion of $<TYPE>NUM, where the current rule has RULE-LENGTH
45 m4_define([b4_rhs_value
],
46 [(yysemantic_stack_@
{m4_eval([$
1 - $
2])@
}m4_ifval([$
3], [.$
3]))])
48 m4_define_default([b4_location_type
], [location
])
49 m4_define_default([b4_filename_type
], [std::string
])
54 m4_define([b4_lhs_location
],
58 # b4_rhs_location(RULE-LENGTH, NUM)
59 # ---------------------------------
60 # Expansion of @NUM, where the current rule has RULE-LENGTH symbols
62 m4_define([b4_rhs_location
],
63 [(yylocation_stack_@
{m4_eval([$
1 - $
2])@
})])
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
])])])
76 m4_define([b4_parse_param_decl_1
],
83 # Extra initialisations of the constructor.
84 m4_define([b4_parse_param_cons
],
85 [m4_ifset([b4_parse_param
],
87 b4_cc_constructor_calls(b4_parse_param
)])])
88 m4_define([b4_cc_constructor_calls
],
89 [m4_map_sep([b4_cc_constructor_call
], [,
91 m4_define([b4_cc_constructor_call
],
96 # Extra instance variables.
97 m4_define([b4_parse_param_vars
],
98 [m4_ifset([b4_parse_param
],
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
], [
105 m4_define([b4_cc_var_decl
],
110 # We do want M4 expansion after # for CPP macros.
113 m4_if(b4_defines_flag
, 0, [],
114 [@output @output_header_name@
115 b4_copyright([C
++ Skeleton parser
for LALR(1) parsing with Bison
],
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
125 /* Using locations. */
126 #define YYLSP_NEEDED ]b4_locations_flag[
134 ]b4_token_defines(b4_tokens
)[
136 /* Copy the first part of user declarations. */
139 ]/* Line __line__ of lalr1.cc. */
140 b4_syncline([@oline@
], [@ofile@
])[
143 #include "location.hh"
145 /* Enabling traces. */
147 # define YYDEBUG ]b4_debug[
150 /* Enabling verbose error message. */
151 #ifndef YYERROR_VERBOSE
152 # define YYERROR_VERBOSE ]b4_error_verbose[
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
167 /* Copy the second part of user declarations. */
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). */
176 #ifndef YYLLOC_DEFAULT
177 # define YYLLOC_DEFAULT(Current, Rhs, N) \
181 (Current).begin = (Rhs)[1].begin; \
182 (Current).end = (Rhs)[N].end; \
186 (Current).begin = (Current).end = (Rhs)[0].end; \
193 class ]b4_parser_class_name
[;
195 template <typename P
>
201 struct traits
<]b4_parser_class_name
[>
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
;
214 class ]b4_parser_class_name
[
216 /// Symbol semantic values.
217 typedef traits
<]b4_parser_class_name
[>::semantic_type semantic_type
;
218 /// Symbol locations.
219 typedef traits
<]b4_parser_class_name
[>::location_type location_type
;
222 /// Build a parser object.
223 ]b4_parser_class_name
[ (]b4_parse_param_decl
[) :
225 yycdebug_ (&std::cerr
)]b4_parse_param_cons
[
229 virtual ~]b4_parser_class_name
[ ()
234 /// \returns 0 iff parsing succeeded.
235 virtual int parse ();
237 /// The current debugging stream.
238 std::ostream
& debug_stream () const;
239 /// Set the current debugging stream.
240 void set_debug_stream (std::ostream
&);
242 /// Type for debugging levels.
243 typedef int debug_level_type
;
244 /// The current debugging level.
245 debug_level_type
debug_level () const;
246 /// Set the current debugging level.
247 void set_debug_level (debug_level_type l
);
251 /// Call the scanner.
252 virtual void yylex_ ();
254 /// Report a syntax error.
255 /// \param loc where the syntax error is found.
256 /// \param msg a description of the syntax error.
257 virtual void error (const location_type
& loc
, const std::string
& msg
);
259 /// Generate an error message, and invoke error.
260 virtual void yyreport_syntax_error_ ();
263 /// \brief Report a symbol on the debug stream.
264 /// \param yytype The token type.
265 /// \param yyvaluep Its semantic value.
266 /// \param yylocationp Its location.
267 virtual void yysymprint_ (int yytype
,
268 const semantic_type
* yyvaluep
,
269 const location_type
* yylocationp
);
270 #endif /* ! YYDEBUG */
274 typedef traits
<]b4_parser_class_name
[>::state_type state_type
;
275 /// State stack type.
276 typedef stack
<state_type
> state_stack_type
;
277 /// Semantic value stack type.
278 typedef stack
<semantic_type
> semantic_stack_type
;
279 /// location stack type.
280 typedef stack
<location_type
> location_stack_type
;
283 state_stack_type yystate_stack_
;
284 /// The semantic value stack.
285 semantic_stack_type yysemantic_stack_
;
286 /// The location stack.
287 location_stack_type yylocation_stack_
;
289 /// Internal symbol numbers.
290 typedef traits
<]b4_parser_class_name
[>::token_number_type token_number_type
;
292 /// For a state, the index in \a yytable_ of its portion.
293 static const ]b4_int_type_for([b4_pact
])[ yypact_
[];
294 static const ]b4_int_type(b4_pact_ninf
, b4_pact_ninf
)[ yypact_ninf_
;
296 /// For a state, default rule to reduce.
297 /// Unless\a yytable_ specifies something else to do.
298 /// Zero means the default is an error.
299 static const ]b4_int_type_for([b4_defact
])[ yydefact_
[];
301 static const ]b4_int_type_for([b4_pgoto
])[ yypgoto_
[];
302 static const ]b4_int_type_for([b4_defgoto
])[ yydefgoto_
[];
304 /// What to do in a state.
305 /// \a yytable_[yypact_[s]]: what to do in state \a s.
306 /// - if positive, shift that token.
307 /// - if negative, reduce the rule which number is the opposite.
308 /// - if zero, do what YYDEFACT says.
309 static const ]b4_int_type_for([b4_table
])[ yytable_
[];
310 static const ]b4_int_type(b4_table_ninf
, b4_table_ninf
)[ yytable_ninf_
;
312 static const ]b4_int_type_for([b4_check
])[ yycheck_
[];
314 /// For a state, its accessing symbol.
315 static const ]b4_int_type_for([b4_stos
])[ yystos_
[];
317 /// For a rule, its LHS.
318 static const ]b4_int_type_for([b4_r1
])[ yyr1_
[];
319 /// For a rule, its RHS length.
320 static const ]b4_int_type_for([b4_r2
])[ yyr2_
[];
322 #if YYDEBUG || YYERROR_VERBOSE
323 /// For a symbol, its name in clear.
324 static const char* const yyname_
[];
328 /// A type to store symbol numbers and -1.
329 typedef traits
<]b4_parser_class_name
[>::rhs_number_type rhs_number_type
;
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_ ();
344 /// Convert a scanner token number to a symbol number.
345 inline token_number_type
yytranslate_ (int token
);
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
,
354 semantic_type
* yyvaluep
,
355 location_type
* yylocationp
);
357 /// Pop \a n symbols the three stacks.
358 inline void yypop_ (unsigned int n
= 1);
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_
;
378 /* Error handling. */
384 std::ostream
* yycdebug_
;
386 /* Look-ahead and look-ahead in internal form. */
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];
401 ]b4_parse_param_vars
[
405 #endif /* ! defined PARSER_HEADER_H */]
407 @output @output_parser_name@
408 b4_copyright([C
++ Skeleton parser
for LALR(1) parsing with Bison
],
410 m4_if(b4_prefix
[], [yy
], [],
412 // Take the name prefix into account.
413 #define yylex b4_prefix[]lex])
414 m4_if(b4_defines_flag
, 0, [],
416 #include @output_header_name@])[
418 /* A pseudo ostream that takes yydebug_ into account. */
420 for (bool yydebugcond_ = yydebug_; yydebugcond_; yydebugcond_ = false) \
423 /* Enable debugging if requested. */
426 # define YY_SYMBOL_PRINT(Title, Type, Value, Location) \
430 *yycdebug_ << (Title) << ' '; \
431 yysymprint_ ((Type), (Value), (Location)); \
432 *yycdebug_ << std::endl; \
436 # define YY_REDUCE_PRINT(Rule) \
439 yyreduce_print_ (Rule); \
442 # define YY_STACK_PRINT() \
450 # define YY_SYMBOL_PRINT(Title, Type, Value, Location)
451 # define YY_REDUCE_PRINT(Rule)
452 # define YY_STACK_PRINT()
454 #endif /* !YYDEBUG */
456 #define YYACCEPT goto yyacceptlab
457 #define YYABORT goto yyabortlab
458 #define YYERROR goto yyerrorlab
461 /*--------------------------------.
462 | Print this symbol on YYOUTPUT. |
463 `--------------------------------*/
466 yy::]b4_parser_class_name
[::yysymprint_ (int yytype
,
467 const semantic_type
* yyvaluep
, const location_type
* yylocationp
)
469 /* Pacify ``unused variable'' warnings. */
472 /* Backward compatibility, but should be removed eventually. */
473 std::ostream
& cdebug_
= *yycdebug_
;
476 *yycdebug_
<< (yytype
< yyntokens_
? "token" : "nterm")
477 << ' ' << yyname_
[yytype
] << " ("
478 << *yylocationp
<< ": ";
481 ]m4_map([b4_symbol_actions
], m4_defn([b4_symbol_printers
]))dnl
487 #endif /* ! YYDEBUG */
490 yy::]b4_parser_class_name
[::yydestruct_ (const char* yymsg
,
491 int yytype
, semantic_type
* yyvaluep
, location_type
* yylocationp
)
493 /* Pacify ``unused variable'' warnings. */
498 YY_SYMBOL_PRINT (yymsg
, yytype
, yyvaluep
, yylocationp
);
502 ]m4_map([b4_symbol_actions
], m4_defn([b4_symbol_destructors
]))[
509 yy::]b4_parser_class_name
[::yypop_ (unsigned int n
)
511 yystate_stack_
.pop (n
);
512 yysemantic_stack_
.pop (n
);
513 yylocation_stack_
.pop (n
);
517 yy::]b4_parser_class_name
[::debug_stream () const
523 yy::]b4_parser_class_name
[::set_debug_stream (std::ostream
& o
)
529 yy::]b4_parser_class_name
[::debug_level_type
530 yy::]b4_parser_class_name
[::debug_level () const
536 yy::]b4_parser_class_name
[::set_debug_level (debug_level_type l
)
543 yy::]b4_parser_class_name
[::parse ()
545 YYCDEBUG
<< "Starting parse" << std::endl
;
554 ]m4_ifdef([b4_initial_action
], [
555 m4_pushdef([b4_at_dollar
], [yylloc
])dnl
556 m4_pushdef([b4_dollar_dollar
], [yylval
])dnl
557 /* User initialization code. */
559 m4_popdef([b4_dollar_dollar
])dnl
560 m4_popdef([b4_at_dollar
])dnl
561 /* Line __line__ of yacc.c. */
562 b4_syncline([@oline@
], [@ofile@
])])dnl
564 [ /* Initialize the stacks. The initial state will be pushed in
565 yynewstate, since the latter expects the semantical and the
566 location values to have been already stored, initialize these
567 stacks with a primary value. */
568 yystate_stack_
= state_stack_type (0);
569 yysemantic_stack_
= semantic_stack_type (0);
570 yylocation_stack_
= location_stack_type (0);
571 yysemantic_stack_
.push (yylval
);
572 yylocation_stack_
.push (yylloc
);
576 yystate_stack_
.push (yystate_
);
577 YYCDEBUG
<< "Entering state " << yystate_
<< std::endl
;
583 /* Try to take a decision without look-ahead. */
584 yyn_
= yypact_
[yystate_
];
585 if (yyn_
== yypact_ninf_
)
588 /* Read a look-ahead token. */
589 if (yylooka_
== yyempty_
)
592 /* Convert token to internal form. */
593 if (yylooka_
<= yyeof_
)
595 yylooka_
= yyilooka_
= yyeof_
;
596 YYCDEBUG
<< "Now at end of input." << std::endl
;
600 yyilooka_
= yytranslate_ (yylooka_
);
601 YY_SYMBOL_PRINT ("Next token is", yyilooka_
, &yylval
, &yylloc
);
604 /* If the proper action on seeing token ILOOKA_ is to reduce or to
605 detect an error, take that action. */
607 if (yyn_
< 0 || yylast_
< yyn_
|| yycheck_
[yyn_
] != yyilooka_
)
610 /* Reduce or error. */
611 yyn_
= yytable_
[yyn_
];
614 if (yyn_
== yytable_ninf_
)
626 if (yyn_
== yyfinal_
)
629 /* Shift the look-ahead token. */
630 YY_SYMBOL_PRINT ("Shifting", yyilooka_
, &yylval
, &yylloc
);
632 /* Discard the token being shifted unless it is eof. */
633 if (yylooka_
!= yyeof_
)
636 yysemantic_stack_
.push (yylval
);
637 yylocation_stack_
.push (yylloc
);
639 /* Count tokens shifted since error; after three, turn off error
647 /*-----------------------------------------------------------.
648 | yydefault -- do the default action for the current state. |
649 `-----------------------------------------------------------*/
651 yyn_
= yydefact_
[yystate_
];
656 /*-----------------------------.
657 | yyreduce -- Do a reduction. |
658 `-----------------------------*/
660 yylen_
= yyr2_
[yyn_
];
661 /* If LEN_ is nonzero, implement the default value of the action:
662 `$$ = $1'. Otherwise, use the top of the stack.
664 Otherwise, the following line sets YYVAL to garbage.
665 This behavior is undocumented and Bison
666 users should not rely upon it. */
668 yyval
= yysemantic_stack_
[yylen_
- 1];
670 yyval
= yysemantic_stack_
[0];
673 slice
<location_type
, location_stack_type
> slice (yylocation_stack_
, yylen_
);
674 YYLLOC_DEFAULT (yyloc
, slice
, yylen_
);
676 YY_REDUCE_PRINT (yyn_
);
682 ]/* Line __line__ of lalr1.cc. */
683 b4_syncline([@oline@
], [@ofile@
])[
689 yysemantic_stack_
.push (yyval
);
690 yylocation_stack_
.push (yyloc
);
692 /* Shift the result of the reduction. */
694 yystate_
= yypgoto_
[yyn_
- yyntokens_
] + yystate_stack_
[0];
695 if (0 <= yystate_
&& yystate_
<= yylast_
696 && yycheck_
[yystate_
] == yystate_stack_
[0])
697 yystate_
= yytable_
[yystate_
];
699 yystate_
= yydefgoto_
[yyn_
- yyntokens_
];
702 /*------------------------------------.
703 | yyerrlab -- here on detecting error |
704 `------------------------------------*/
706 /* If not already recovering from an error, report this error. */
707 yyreport_syntax_error_ ();
709 yyerror_range_
[0] = yylloc
;
710 if (yyerrstatus_
== 3)
712 /* If just tried and failed to reuse look-ahead token after an
713 error, discard it. */
715 /* Return failure if at end of input. */
716 if (yylooka_
<= yyeof_
)
718 /* If at end of input, pop the error token,
719 then the rest of the stack, then return failure. */
720 if (yylooka_
== yyeof_
)
723 yyerror_range_
[0] = yylocation_stack_
[0];
725 if (yystate_stack_
.height () == 1)
727 yydestruct_ ("Error: popping",
728 yystos_
[yystate_stack_
[0]],
729 &yysemantic_stack_
[0],
730 &yylocation_stack_
[0]);
735 yydestruct_ ("Error: discarding", yyilooka_
, &yylval
, &yylloc
);
740 /* Else will try to reuse look-ahead token after shifting the error
745 /*---------------------------------------------------.
746 | yyerrorlab -- error raised explicitly by YYERROR. |
747 `---------------------------------------------------*/
751 /* Pacify GCC when the user code never invokes YYERROR and the label
752 yyerrorlab therefore never appears in user code. */
757 yyerror_range_
[0] = yylocation_stack_
[yylen_
- 1];
759 yystate_
= yystate_stack_
[0];
762 /*-------------------------------------------------------------.
763 | yyerrlab1 -- common code for both syntax error and YYERROR. |
764 `-------------------------------------------------------------*/
766 yyerrstatus_
= 3; /* Each real token shifted decrements this. */
770 yyn_
= yypact_
[yystate_
];
771 if (yyn_
!= yypact_ninf_
)
774 if (0 <= yyn_
&& yyn_
<= yylast_
&& yycheck_
[yyn_
] == yyterror_
)
776 yyn_
= yytable_
[yyn_
];
782 /* Pop the current state because it cannot handle the error token. */
783 if (yystate_stack_
.height () == 1)
786 yyerror_range_
[0] = yylocation_stack_
[0];
787 yydestruct_ ("Error: popping",
789 &yysemantic_stack_
[0], &yylocation_stack_
[0]);
791 yystate_
= yystate_stack_
[0];
795 if (yyn_
== yyfinal_
)
798 yyerror_range_
[1] = yylloc
;
799 // Using YYLLOC is tempting, but would change the location of
800 // the look-ahead. YYLOC is available though.
801 YYLLOC_DEFAULT (yyloc
, yyerror_range_
- 1, 2);
802 yysemantic_stack_
.push (yylval
);
803 yylocation_stack_
.push (yyloc
);
805 /* Shift the error token. */
806 YY_SYMBOL_PRINT ("Shifting", yystos_
[yyn_
],
807 &yysemantic_stack_
[0], &yylocation_stack_
[0]);
818 /* Free the lookahead. */
819 yydestruct_ ("Error: discarding lookahead", yyilooka_
, &yylval
, &yylloc
);
825 yy::]b4_parser_class_name
[::yylex_ ()
827 YYCDEBUG
<< "Reading a token: ";
829 yylooka_
= yylex (&yylval
, &yylloc
);
831 yylooka_
= yylex (&yylval
);
835 // Generate an error message, and invoke error.
837 yy::]b4_parser_class_name
[::yyreport_syntax_error_ ()
839 /* If not already recovering from an error, report this error. */
845 yyn_
= yypact_
[yystate_
];
846 if (yypact_ninf_
< yyn_
&& yyn_
< yylast_
)
848 /* Start YYX at -YYN if negative to avoid negative indexes in
850 int yyxbegin
= yyn_
< 0 ? -yyn_
: 0;
852 /* Stay within bounds of both yycheck and yytname. */
853 int yychecklim
= yylast_
- yyn_
;
854 int yyxend
= yychecklim
< yyntokens_
? yychecklim
: yyntokens_
;
856 for (int x
= yyxbegin
; x
< yyxend
; ++x
)
857 if (yycheck_
[x
+ yyn_
] == x
&& x
!= yyterror_
)
860 message
= "syntax error, unexpected ";
861 message
+= yyname_
[yyilooka_
];
865 for (int x
= yyxbegin
; x
< yyxend
; ++x
)
866 if (yycheck_
[x
+ yyn_
] == x
&& x
!= yyterror_
)
868 message
+= (!count
++) ? ", expecting " : " or ";
869 message
+= yyname_
[x
];
875 message
= "syntax error";
876 error (yylloc
, message
);
881 /* YYPACT[STATE-NUM] -- Index in YYTABLE of the portion describing
883 const ]b4_int_type(b4_pact_ninf
, b4_pact_ninf
) yy::b4_parser_class_name::yypact_ninf_
= b4_pact_ninf
[;
884 const ]b4_int_type_for([b4_pact
])[
885 yy::]b4_parser_class_name
[::yypact_
[] =
890 /* YYDEFACT[S] -- default rule to reduce with in state S when YYTABLE
891 doesn't specify something else to do. Zero means the default is an
893 const ]b4_int_type_for([b4_defact
])[
894 yy::]b4_parser_class_name
[::yydefact_
[] =
899 /* YYPGOTO[NTERM-NUM]. */
900 const ]b4_int_type_for([b4_pgoto
])[
901 yy::]b4_parser_class_name
[::yypgoto_
[] =
906 /* YYDEFGOTO[NTERM-NUM]. */
907 const ]b4_int_type_for([b4_defgoto
])[
908 yy::]b4_parser_class_name
[::yydefgoto_
[] =
913 /* YYTABLE[YYPACT[STATE-NUM]]. What to do in state STATE-NUM. If
914 positive, shift that token. If negative, reduce the rule which
915 number is the opposite. If zero, do what YYDEFACT says. */
916 const ]b4_int_type(b4_table_ninf
, b4_table_ninf
) yy::b4_parser_class_name::yytable_ninf_
= b4_table_ninf
[;
917 const ]b4_int_type_for([b4_table
])[
918 yy::]b4_parser_class_name
[::yytable_
[] =
924 const ]b4_int_type_for([b4_check
])[
925 yy::]b4_parser_class_name
[::yycheck_
[] =
930 /* STOS_[STATE-NUM] -- The (internal number of the) accessing
931 symbol of state STATE-NUM. */
932 const ]b4_int_type_for([b4_stos
])[
933 yy::]b4_parser_class_name
[::yystos_
[] =
939 /* TOKEN_NUMBER_[YYLEX-NUM] -- Internal symbol number corresponding
941 const ]b4_int_type_for([b4_toknum
])[
942 yy::]b4_parser_class_name
[::yytoken_number_
[] =
948 /* YYR1[YYN] -- Symbol number of symbol that rule YYN derives. */
949 const ]b4_int_type_for([b4_r1
])[
950 yy::]b4_parser_class_name
[::yyr1_
[] =
955 /* YYR2[YYN] -- Number of symbols composing right hand side of rule YYN. */
956 const ]b4_int_type_for([b4_r2
])[
957 yy::]b4_parser_class_name
[::yyr2_
[] =
962 #if YYDEBUG || YYERROR_VERBOSE
963 /* YYTNAME[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM.
964 First, the terminals, then, starting at \a yyntokens_, nonterminals. */
966 const yy::]b4_parser_class_name
[::yyname_
[] =
973 /* YYRHS -- A `-1'-separated list of the rules' RHS. */
974 const yy::]b4_parser_class_name
[::rhs_number_type
975 yy::]b4_parser_class_name
[::yyrhs_
[] =
980 /* YYPRHS[YYN] -- Index of the first RHS symbol of rule number YYN in
982 const ]b4_int_type_for([b4_prhs
])[
983 yy::]b4_parser_class_name
[::yyprhs_
[] =
988 /* YYRLINE[YYN] -- Source line where rule number YYN was defined. */
989 const ]b4_int_type_for([b4_rline
])[
990 yy::]b4_parser_class_name
[::yyrline_
[] =
995 // Print the state stack on the debug stream.
997 yy::]b4_parser_class_name
[::yystack_print_ ()
999 *yycdebug_
<< "Stack now";
1000 for (state_stack_type::const_iterator i
= yystate_stack_
.begin ();
1001 i
!= yystate_stack_
.end (); ++i
)
1002 *yycdebug_
<< ' ' << *i
;
1003 *yycdebug_
<< std::endl
;
1006 // Report on the debug stream that the rule \a yyrule is going to be reduced.
1008 yy::]b4_parser_class_name
[::yyreduce_print_ (int yyrule
)
1010 unsigned int yylno
= yyrline_
[yyrule
];
1011 /* Print the symbols being reduced, and their result. */
1012 *yycdebug_
<< "Reducing stack by rule " << yyn_
- 1
1013 << " (line " << yylno
<< "), ";
1014 for (]b4_int_type_for([b4_prhs
])[ i
= yyprhs_
[yyn_
];
1015 0 <= yyrhs_
[i
]; ++i
)
1016 *yycdebug_
<< yyname_
[yyrhs_
[i
]] << ' ';
1017 *yycdebug_
<< "-> " << yyname_
[yyr1_
[yyn_
]] << std::endl
;
1021 /* YYTRANSLATE(YYLEX) -- Bison symbol number corresponding to YYLEX. */
1022 yy::]b4_parser_class_name
[::token_number_type
1023 yy::]b4_parser_class_name
[::yytranslate_ (int token
)
1026 const token_number_type
1031 if ((unsigned int) token
<= yyuser_token_number_max_
)
1032 return translate_table
[token
];
1034 return yyundef_token_
;
1037 const int yy::]b4_parser_class_name
[::yyeof_
= 0;
1038 const int yy::]b4_parser_class_name
[::yylast_
= ]b4_last
[;
1039 const int yy::]b4_parser_class_name
[::yynnts_
= ]b4_nterms_number
[;
1040 const int yy::]b4_parser_class_name
[::yyempty_
= -2;
1041 const int yy::]b4_parser_class_name
[::yyfinal_
= ]b4_final_state_number
[;
1042 const int yy::]b4_parser_class_name
[::yyterror_
= 1;
1043 const int yy::]b4_parser_class_name
[::yyerrcode_
= 256;
1044 const int yy::]b4_parser_class_name
[::yyntokens_
= ]b4_tokens_number
[;
1046 const unsigned int yy::]b4_parser_class_name
[::yyuser_token_number_max_
= ]b4_user_token_number_max
[;
1047 const yy::]b4_parser_class_name
[::token_number_type
yy::]b4_parser_class_name
[::yyundef_token_
= ]b4_undef_token_number
[;
1052 b4_copyright([stack handling
for Bison C
++ parsers
], [2002, 2003, 2004])[
1054 #ifndef BISON_STACK_HH
1055 # define BISON_STACK_HH
1061 template <class T
, class S
= std::deque
<T
> >
1066 // Hide our reversed order.
1067 typedef typename
S::reverse_iterator iterator
;
1068 typedef typename
S::const_reverse_iterator const_iterator
;
1074 stack (unsigned int n
) : seq_ (n
)
1080 operator [] (unsigned int i
)
1087 operator [] (unsigned int i
) const
1096 seq_
.push_front (t
);
1101 pop (unsigned int n
= 1)
1111 return seq_
.size ();
1114 inline const_iterator
begin () const { return seq_
.rbegin (); }
1115 inline const_iterator
end () const { return seq_
.rend (); }
1122 /// Present a slice of the top of a stack.
1123 template <class T
, class S
= stack
<T
> >
1128 slice (const S
& stack
,
1129 unsigned int range
) : stack_ (stack
),
1136 operator [] (unsigned int i
) const
1138 return stack_
[range_
- i
];
1144 unsigned int range_
;
1148 #endif // not BISON_STACK_HH]
1151 b4_copyright([Position
class for Bison C
++ parsers
], [2002, 2003, 2004])[
1154 ** \file position.hh
1155 ** Define the position class.
1158 #ifndef BISON_POSITION_HH
1159 # define BISON_POSITION_HH
1161 # include <iostream>
1166 /// Abstract a position.
1170 /// Initial column number.
1171 static const unsigned int initial_column
= 0;
1172 /// Initial line number.
1173 static const unsigned int initial_line
= 1;
1175 /** \name Ctor & dtor.
1178 /// Construct a position.
1181 line (initial_line
),
1182 column (initial_column
)
1188 /** \name Line and Column related manipulators
1191 /// (line related) Advance to the COUNT next lines.
1192 inline void lines (int count
= 1)
1194 column
= initial_column
;
1198 /// (column related) Advance to the COUNT next columns.
1199 inline void columns (int count
= 1)
1201 int leftmost
= initial_column
;
1202 int current
= column
;
1203 if (leftmost
<= current
+ count
)
1206 column
= initial_column
;
1211 /// File name to which this position refers.
1212 ]b4_filename_type
[* filename
;
1213 /// Current line number.
1215 /// Current column number.
1216 unsigned int column
;
1219 /// Add and assign a position.
1220 inline const position
&
1221 operator+= (position
& res
, const int width
)
1223 res
.columns (width
);
1227 /// Add two position objects.
1228 inline const position
1229 operator+ (const position
& begin
, const int width
)
1231 position res
= begin
;
1232 return res
+= width
;
1235 /// Add and assign a position.
1236 inline const position
&
1237 operator-= (position
& res
, const int width
)
1239 return res
+= -width
;
1242 /// Add two position objects.
1243 inline const position
1244 operator- (const position
& begin
, const int width
)
1246 return begin
+ -width
;
1249 /** \brief Intercept output stream redirection.
1250 ** \param ostr the destination output stream
1251 ** \param pos a reference to the position to redirect
1253 inline std::ostream
&
1254 operator<< (std::ostream
& ostr
, const position
& pos
)
1257 ostr
<< *pos
.filename
<< ':';
1258 return ostr
<< pos
.line
<< '.' << pos
.column
;
1262 #endif // not BISON_POSITION_HH]
1264 b4_copyright([Location
class for Bison C
++ parsers
], [2002, 2003, 2004])[
1267 ** \file location.hh
1268 ** Define the location class.
1271 #ifndef BISON_LOCATION_HH
1272 # define BISON_LOCATION_HH
1274 # include <iostream>
1276 # include "position.hh"
1281 /// Abstract a location.
1284 /** \name Ctor & dtor.
1287 /// Construct a location.
1296 /** \name Line and Column related manipulators
1299 /// Reset initial location to final location.
1305 /// Extend the current location to the COUNT next columns.
1306 inline void columns (unsigned int count
= 1)
1311 /// Extend the current location to the COUNT next lines.
1312 inline void lines (unsigned int count
= 1)
1320 /// Beginning of the located region.
1322 /// End of the located region.
1326 /// Join two location objects to create a location.
1327 inline const location
operator+ (const location
& begin
, const location
& end
)
1329 location res
= begin
;
1334 /// Add two location objects.
1335 inline const location
operator+ (const location
& begin
, unsigned int width
)
1337 location res
= begin
;
1338 res
.columns (width
);
1342 /// Add and assign a location.
1343 inline location
& operator+= (location
& res
, unsigned int width
)
1345 res
.columns (width
);
1349 /** \brief Intercept output stream redirection.
1350 ** \param ostr the destination output stream
1351 ** \param loc a reference to the location to redirect
1353 ** Avoid duplicate information.
1355 inline std::ostream
& operator<< (std::ostream
& ostr
, const location
& loc
)
1357 position last
= loc
.end
- 1;
1360 && (!loc
.begin
.filename
1361 || *loc
.begin
.filename
!= *last
.filename
))
1362 ostr
<< '-' << last
;
1363 else if (loc
.begin
.line
!= last
.line
)
1364 ostr
<< '-' << last
.line
<< '.' << last
.column
;
1365 else if (loc
.begin
.column
!= last
.column
)
1366 ostr
<< '-' << last
.column
;
1372 #endif // not BISON_LOCATION_HH]