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 [semantic_stack_@
{m4_eval([$
1 - $
2])@
}m4_ifval([$
3], [.$
3])])
48 m4_define_default([b4_location_type
], [Location
])
53 m4_define([b4_lhs_location
],
57 # b4_rhs_location(RULE-LENGTH, NUM)
58 # ---------------------------------
59 # Expansion of @NUM, where the current rule has RULE-LENGTH symbols
61 m4_define([b4_rhs_location
],
62 [location_stack_@
{m4_eval([$
1 - $
2])@
}])
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
])])])
75 m4_define([b4_parse_param_decl_1
],
82 # Extra initialisations of the constructor.
83 m4_define([b4_parse_param_cons
],
84 [m4_ifset([b4_parse_param
],
86 b4_cc_constructor_calls(b4_parse_param
)])])
87 m4_define([b4_cc_constructor_calls
],
88 [m4_map_sep([b4_cc_constructor_call
], [,
90 m4_define([b4_cc_constructor_call
],
95 # Extra instance variables.
96 m4_define([b4_parse_param_vars
],
97 [m4_ifset([b4_parse_param
],
100 b4_cc_var_decls(b4_parse_param
)])])
101 m4_define([b4_cc_var_decls
],
102 [m4_map_sep([b4_cc_var_decl
], [
104 m4_define([b4_cc_var_decl
],
109 # We do want M4 expansion after # for CPP macros.
112 m4_if(b4_defines_flag
, 0, [],
113 [@output @output_header_name@
114 b4_copyright([C
++ Skeleton parser
for LALR(1) parsing with Bison
],
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
122 #include "location.hh"
127 /* Using locations. */
128 #define YYLSP_NEEDED ]b4_locations_flag[
130 ]b4_token_defines(b4_tokens
)[
132 /* Copy the first part of user declarations. */
135 ]/* Line __line__ of lalr1.cc. */
136 b4_syncline([@oline@
], [@ofile@
])[
138 /* Enabling traces. */
140 # define YYDEBUG ]b4_debug[
143 /* Enabling verbose error message. */
144 #ifndef YYERROR_VERBOSE
145 # define YYERROR_VERBOSE ]b4_error_verbose[
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
160 /* Copy the second part of user declarations. */
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). */
169 #ifndef YYLLOC_DEFAULT
170 # define YYLLOC_DEFAULT(Current, Rhs, N) \
174 (Current).begin = (Rhs)[1].begin; \
175 (Current).end = (Rhs)[N].end; \
179 (Current).begin = (Current).end = (Rhs)[0].end; \
186 class ]b4_parser_class_name
[;
188 template <typename P
>
194 struct Traits
<]b4_parser_class_name
[>
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
;
206 class ]b4_parser_class_name
[
210 typedef Traits
<]b4_parser_class_name
[>::TokenNumberType TokenNumberType
;
211 typedef Traits
<]b4_parser_class_name
[>::RhsNumberType RhsNumberType
;
212 typedef Traits
<]b4_parser_class_name
[>::StateType StateType
;
213 typedef Traits
<]b4_parser_class_name
[>::SemanticType SemanticType
;
214 typedef Traits
<]b4_parser_class_name
[>::LocationType LocationType
;
216 typedef Stack
<StateType
> StateStack
;
217 typedef Stack
<SemanticType
> SemanticStack
;
218 typedef Stack
<LocationType
> LocationStack
;
220 ]b4_parser_class_name
[ (]b4_parse_param_decl
[) :
222 yycdebug_ (&std::cerr
)]b4_parse_param_cons
[
226 virtual ~]b4_parser_class_name
[ ()
231 /// \returns 0 iff parsing succeeded.
232 virtual int parse ();
234 /// The current debugging stream.
235 std::ostream
& debug_stream () const;
236 /// Set the current debugging stream.
237 void set_debug_stream (std::ostream
&);
239 /// Type for debugging levels.
240 typedef int debug_level_type
;
241 /// The current debugging level.
242 debug_level_type
debug_level () const;
243 /// Set the current debugging level.
244 void set_debug_level (debug_level_type l
);
248 /// Call the scanner.
249 virtual void yylex_ ();
250 virtual void error_ ();
251 /// Generate an error message, and invoke error. */
252 virtual void yyreport_syntax_error_ ();
254 /// \brief Report a symbol on the debug stream.
255 /// \param yytype The token type.
256 /// \param yyvaluep Its semantic value.
257 /// \param yylocationp Its location.
258 virtual void yysymprint_ (int yytype
,
259 const SemanticType
* yyvaluep
,
260 const LocationType
* yylocationp
);
261 #endif /* ! YYDEBUG */
265 StateStack state_stack_
;
266 /// The semantic value stack.
267 SemanticStack semantic_stack_
;
268 /// The location stack.
269 LocationStack location_stack_
;
272 static const ]b4_int_type_for([b4_pact
])[ pact_
[];
273 static const ]b4_int_type(b4_pact_ninf
, b4_pact_ninf
)[ pact_ninf_
;
274 static const ]b4_int_type_for([b4_defact
])[ defact_
[];
275 static const ]b4_int_type_for([b4_pgoto
])[ pgoto_
[];
276 static const ]b4_int_type_for([b4_defgoto
])[ defgoto_
[];
277 static const ]b4_int_type_for([b4_table
])[ table_
[];
278 static const ]b4_int_type(b4_table_ninf
, b4_table_ninf
)[ table_ninf_
;
279 static const ]b4_int_type_for([b4_check
])[ check_
[];
280 static const ]b4_int_type_for([b4_stos
])[ stos_
[];
281 static const ]b4_int_type_for([b4_r1
])[ r1_
[];
282 static const ]b4_int_type_for([b4_r2
])[ r2_
[];
284 #if YYDEBUG || YYERROR_VERBOSE
285 static const char* const name_
[];
288 /* More tables, for debugging. */
290 static const RhsNumberType rhs_
[];
291 static const ]b4_int_type_for([b4_prhs
])[ prhs_
[];
292 static const ]b4_int_type_for([b4_rline
])[ rline_
[];
293 static const ]b4_int_type_for([b4_toknum
])[ token_number_
[];
294 virtual void yyreduce_print_ (int yyrule
);
295 virtual void yystack_print_ ();
298 /// Convert a scanner token number to a symbol number.
299 inline TokenNumberType
yytranslate_ (int token
);
301 /// \brief Reclaim the memory associated to a symbol.
302 /// \param yymsg Why this token is reclaimed.
303 /// \param yytype The symbol type.
304 /// \param yyvaluep Its semantic value.
305 /// \param yylocationp Its location.
306 inline void yydestruct_ (const char* yymsg
,
308 SemanticType
* yyvaluep
,
309 LocationType
* yylocationp
);
311 /// Pop \a n symbols the three stacks.
312 inline void yypop_ (unsigned int n
= 1);
315 static const int eof_
;
316 /* LAST_ -- Last index in TABLE_. */
317 static const int last_
;
318 static const int nnts_
;
319 static const int empty_
;
320 static const int final_
;
321 static const int terror_
;
322 static const int errcode_
;
323 static const int ntokens_
;
324 static const unsigned int user_token_number_max_
;
325 static const TokenNumberType undef_token_
;
332 /* Error handling. */
338 std::ostream
* yycdebug_
;
340 /* Look-ahead and look-ahead in internal form. */
347 /// Semantic value of the look-ahead.
349 /// Location of the look-ahead.
350 LocationType location
;
351 /// The locations where the error started and ended.
352 Location error_range_
[2];
358 ]b4_parse_param_vars
[
362 #endif /* ! defined PARSER_HEADER_H */]
364 @output @output_parser_name@
365 b4_copyright([C
++ Skeleton parser
for LALR(1) parsing with Bison
],
368 m4_if(b4_defines_flag
, 0, [], [#include @output_header_name@])[
370 /* A pseudo ostream that takes yydebug_ into account. */
372 for (bool yydebugcond_ = yydebug_; yydebugcond_; yydebugcond_ = false) \
375 /* Enable debugging if requested. */
378 # define YY_SYMBOL_PRINT(Title, Type, Value, Location) \
382 *yycdebug_ << (Title) << ' '; \
383 yysymprint_ ((Type), (Value), (Location)); \
384 *yycdebug_ << std::endl; \
388 # define YY_REDUCE_PRINT(Rule) \
391 yyreduce_print_ (Rule); \
394 # define YY_STACK_PRINT() \
402 # define YY_SYMBOL_PRINT(Title, Type, Value, Location)
403 # define YY_REDUCE_PRINT(Rule)
404 # define YY_STACK_PRINT()
406 #endif /* !YYDEBUG */
408 #define YYACCEPT goto yyacceptlab
409 #define YYABORT goto yyabortlab
410 #define YYERROR goto yyerrorlab
413 /*--------------------------------.
414 | Print this symbol on YYOUTPUT. |
415 `--------------------------------*/
418 yy::]b4_parser_class_name
[::yysymprint_ (int yytype
,
419 const SemanticType
* yyvaluep
, const LocationType
* yylocationp
)
421 /* Pacify ``unused variable'' warnings. */
424 /* Backward compatibility, but should be removed eventually. */
425 std::ostream
& cdebug_
= *yycdebug_
;
428 *yycdebug_
<< (yytype
< ntokens_
? "token" : "nterm")
429 << ' ' << name_
[yytype
] << " ("
430 << *yylocationp
<< ": ";
433 ]m4_map([b4_symbol_actions
], m4_defn([b4_symbol_printers
]))dnl
439 #endif /* ! YYDEBUG */
442 yy::]b4_parser_class_name
[::yydestruct_ (const char* yymsg
,
443 int yytype
, SemanticType
* yyvaluep
, LocationType
* yylocationp
)
445 /* Pacify ``unused variable'' warnings. */
449 YY_SYMBOL_PRINT (yymsg
, yytype
, yyvaluep
, yylocationp
);
453 ]m4_map([b4_symbol_actions
], m4_defn([b4_symbol_destructors
]))[
460 yy::]b4_parser_class_name
[::yypop_ (unsigned int n
)
462 state_stack_
.pop (n
);
463 semantic_stack_
.pop (n
);
464 location_stack_
.pop (n
);
468 yy::]b4_parser_class_name
[::debug_stream () const
474 yy::]b4_parser_class_name
[::set_debug_stream (std::ostream
& o
)
480 yy::]b4_parser_class_name
[::debug_level_type
481 yy::]b4_parser_class_name
[::debug_level () const
487 yy::]b4_parser_class_name
[::set_debug_level (debug_level_type l
)
494 yy::]b4_parser_class_name
[::parse ()
496 YYCDEBUG
<< "Starting parse" << std::endl
;
505 ]m4_ifdef([b4_initial_action
], [
506 m4_pushdef([b4_at_dollar
], [location
])dnl
507 m4_pushdef([b4_dollar_dollar
], [value
])dnl
508 /* User initialization code. */
510 m4_popdef([b4_dollar_dollar
])dnl
511 m4_popdef([b4_at_dollar
])dnl
512 /* Line __line__ of yacc.c. */
513 b4_syncline([@oline@
], [@ofile@
])])dnl
515 [ /* Initialize the stacks. The initial state will be pushed in
516 yynewstate, since the latter expects the semantical and the
517 location values to have been already stored, initialize these
518 stacks with a primary value. */
519 state_stack_
= StateStack (0);
520 semantic_stack_
= SemanticStack (0);
521 location_stack_
= LocationStack (0);
522 semantic_stack_
.push (value
);
523 location_stack_
.push (location
);
527 state_stack_
.push (state_
);
528 YYCDEBUG
<< "Entering state " << state_
<< std::endl
;
534 /* Try to take a decision without look-ahead. */
536 if (n_
== pact_ninf_
)
539 /* Read a look-ahead token. */
540 if (looka_
== empty_
)
543 /* Convert token to internal form. */
546 looka_
= ilooka_
= eof_
;
547 YYCDEBUG
<< "Now at end of input." << std::endl
;
551 ilooka_
= yytranslate_ (looka_
);
552 YY_SYMBOL_PRINT ("Next token is", ilooka_
, &value
, &location
);
555 /* If the proper action on seeing token ILOOKA_ is to reduce or to
556 detect an error, take that action. */
558 if (n_
< 0 || last_
< n_
|| check_
[n_
] != ilooka_
)
561 /* Reduce or error. */
565 if (n_
== table_ninf_
)
580 /* Shift the look-ahead token. */
581 YY_SYMBOL_PRINT ("Shifting", ilooka_
, &value
, &location
);
583 /* Discard the token being shifted unless it is eof. */
587 semantic_stack_
.push (value
);
588 location_stack_
.push (location
);
590 /* Count tokens shifted since error; after three, turn off error
598 /*-----------------------------------------------------------.
599 | yydefault -- do the default action for the current state. |
600 `-----------------------------------------------------------*/
602 n_
= defact_
[state_
];
607 /*-----------------------------.
608 | yyreduce -- Do a reduction. |
609 `-----------------------------*/
612 /* If LEN_ is nonzero, implement the default value of the action:
613 `$$ = $1'. Otherwise, use the top of the stack.
615 Otherwise, the following line sets YYVAL to garbage.
616 This behavior is undocumented and Bison
617 users should not rely upon it. */
619 yyval
= semantic_stack_
[len_
- 1];
621 yyval
= semantic_stack_
[0];
624 Slice
<LocationType
, LocationStack
> slice (location_stack_
, len_
);
625 YYLLOC_DEFAULT (yyloc
, slice
, len_
);
627 YY_REDUCE_PRINT (n_
);
633 ]/* Line __line__ of lalr1.cc. */
634 b4_syncline([@oline@
], [@ofile@
])[
640 semantic_stack_
.push (yyval
);
641 location_stack_
.push (yyloc
);
643 /* Shift the result of the reduction. */
645 state_
= pgoto_
[n_
- ntokens_
] + state_stack_
[0];
646 if (0 <= state_
&& state_
<= last_
&& check_
[state_
] == state_stack_
[0])
647 state_
= table_
[state_
];
649 state_
= defgoto_
[n_
- ntokens_
];
652 /*------------------------------------.
653 | yyerrlab -- here on detecting error |
654 `------------------------------------*/
656 /* If not already recovering from an error, report this error. */
657 yyreport_syntax_error_ ();
659 error_range_
[0] = location
;
662 /* If just tried and failed to reuse look-ahead token after an
663 error, discard it. */
665 /* Return failure if at end of input. */
668 /* If at end of input, pop the error token,
669 then the rest of the stack, then return failure. */
673 error_range_
[0] = location_stack_
[0];
675 if (state_stack_
.height () == 1)
677 yydestruct_ ("Error: popping",
678 stos_
[state_stack_
[0]],
680 &location_stack_
[0]);
685 yydestruct_ ("Error: discarding", ilooka_
, &value
, &location
);
690 /* Else will try to reuse look-ahead token after shifting the error
695 /*---------------------------------------------------.
696 | yyerrorlab -- error raised explicitly by YYERROR. |
697 `---------------------------------------------------*/
701 /* Pacify GCC when the user code never invokes YYERROR and the label
702 yyerrorlab therefore never appears in user code. */
707 error_range_
[0] = location_stack_
[len_
- 1];
709 state_
= state_stack_
[0];
712 /*-------------------------------------------------------------.
713 | yyerrlab1 -- common code for both syntax error and YYERROR. |
714 `-------------------------------------------------------------*/
716 errstatus_
= 3; /* Each real token shifted decrements this. */
721 if (n_
!= pact_ninf_
)
724 if (0 <= n_
&& n_
<= last_
&& check_
[n_
] == terror_
)
732 /* Pop the current state because it cannot handle the error token. */
733 if (state_stack_
.height () == 1)
736 error_range_
[0] = location_stack_
[0];
737 yydestruct_ ("Error: popping",
738 stos_
[state_
], &semantic_stack_
[0], &location_stack_
[0]);
740 state_
= state_stack_
[0];
747 error_range_
[1] = location
;
748 // Using LOCATION is tempting, but would change the location of
749 // the look-ahead. YYLOC is available though.
750 YYLLOC_DEFAULT (yyloc
, error_range_
- 1, 2);
751 semantic_stack_
.push (value
);
752 location_stack_
.push (yyloc
);
754 /* Shift the error token. */
755 YY_SYMBOL_PRINT ("Shifting", stos_
[n_
],
756 &semantic_stack_
[0], &location_stack_
[0]);
767 /* Free the lookahead. */
768 yydestruct_ ("Error: discarding lookahead", ilooka_
, &value
, &location
);
774 yy::]b4_parser_class_name
[::yylex_ ()
776 YYCDEBUG
<< "Reading a token: ";
778 looka_
= ]m4_default(b4_prefix
, [yy
])[lex (&value
, &location
);
780 looka_
= ]m4_default(b4_prefix
, [yy
])[lex (&value
);
784 // Generate an error message, and invoke error.
786 yy::]b4_parser_class_name
[::yyreport_syntax_error_ ()
788 /* If not already recovering from an error, report this error. */
795 if (pact_ninf_
< n_
&& n_
< last_
)
797 message
= "syntax error, unexpected ";
798 message
+= name_
[ilooka_
];
801 for (int x
= (n_
< 0 ? -n_
: 0); x
< ntokens_
+ nnts_
; ++x
)
802 if (check_
[x
+ n_
] == x
&& x
!= terror_
)
807 for (int x
= (n_
< 0 ? -n_
: 0); x
< ntokens_
+ nnts_
; ++x
)
808 if (check_
[x
+ n_
] == x
&& x
!= terror_
)
810 message
+= (!count
++) ? ", expecting " : " or ";
818 message
= "syntax error";
824 /* YYPACT[STATE-NUM] -- Index in YYTABLE of the portion describing
826 const ]b4_int_type(b4_pact_ninf
, b4_pact_ninf
) yy::b4_parser_class_name::pact_ninf_
= b4_pact_ninf
[;
827 const ]b4_int_type_for([b4_pact
])[
828 yy::]b4_parser_class_name
[::pact_
[] =
833 /* YYDEFACT[S] -- default rule to reduce with in state S when YYTABLE
834 doesn't specify something else to do. Zero means the default is an
836 const ]b4_int_type_for([b4_defact
])[
837 yy::]b4_parser_class_name
[::defact_
[] =
842 /* YYPGOTO[NTERM-NUM]. */
843 const ]b4_int_type_for([b4_pgoto
])[
844 yy::]b4_parser_class_name
[::pgoto_
[] =
849 /* YYDEFGOTO[NTERM-NUM]. */
850 const ]b4_int_type_for([b4_defgoto
])[
851 yy::]b4_parser_class_name
[::defgoto_
[] =
856 /* YYTABLE[YYPACT[STATE-NUM]]. What to do in state STATE-NUM. If
857 positive, shift that token. If negative, reduce the rule which
858 number is the opposite. If zero, do what YYDEFACT says. */
859 const ]b4_int_type(b4_table_ninf
, b4_table_ninf
) yy::b4_parser_class_name::table_ninf_
= b4_table_ninf
[;
860 const ]b4_int_type_for([b4_table
])[
861 yy::]b4_parser_class_name
[::table_
[] =
867 const ]b4_int_type_for([b4_check
])[
868 yy::]b4_parser_class_name
[::check_
[] =
873 /* STOS_[STATE-NUM] -- The (internal number of the) accessing
874 symbol of state STATE-NUM. */
875 const ]b4_int_type_for([b4_stos
])[
876 yy::]b4_parser_class_name
[::stos_
[] =
882 /* TOKEN_NUMBER_[YYLEX-NUM] -- Internal token number corresponding
884 const ]b4_int_type_for([b4_toknum
])[
885 yy::]b4_parser_class_name
[::token_number_
[] =
891 /* YYR1[YYN] -- Symbol number of symbol that rule YYN derives. */
892 const ]b4_int_type_for([b4_r1
])[
893 yy::]b4_parser_class_name
[::r1_
[] =
898 /* YYR2[YYN] -- Number of symbols composing right hand side of rule YYN. */
899 const ]b4_int_type_for([b4_r2
])[
900 yy::]b4_parser_class_name
[::r2_
[] =
905 #if YYDEBUG || YYERROR_VERBOSE
906 /* YYTNAME[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM.
907 First, the terminals, then, starting at NTOKENS_, nonterminals. */
909 const yy::]b4_parser_class_name
[::name_
[] =
916 /* YYRHS -- A `-1'-separated list of the rules' RHS. */
917 const yy::]b4_parser_class_name
[::RhsNumberType
918 yy::]b4_parser_class_name
[::rhs_
[] =
923 /* YYPRHS[YYN] -- Index of the first RHS symbol of rule number YYN in
925 const ]b4_int_type_for([b4_prhs
])[
926 yy::]b4_parser_class_name
[::prhs_
[] =
931 /* YYRLINE[YYN] -- source line where rule number YYN was defined. */
932 const ]b4_int_type_for([b4_rline
])[
933 yy::]b4_parser_class_name
[::rline_
[] =
938 /// Print the state stack on the debug stream.
940 yy::]b4_parser_class_name
[::yystack_print_ ()
942 *yycdebug_
<< "Stack now";
943 for (StateStack::const_iterator i
= state_stack_
.begin ();
944 i
!= state_stack_
.end (); ++i
)
945 *yycdebug_
<< ' ' << *i
;
946 *yycdebug_
<< std::endl
;
949 /// Report on the debug stream that the rule \a yyrule is going to be reduced.
951 yy::]b4_parser_class_name
[::yyreduce_print_ (int yyrule
)
953 unsigned int yylno
= rline_
[yyrule
];
954 /* Print the symbols being reduced, and their result. */
955 *yycdebug_
<< "Reducing stack by rule " << n_
- 1
956 << " (line " << yylno
<< "), ";
957 for (]b4_int_type_for([b4_prhs
])[ i
= prhs_
[n_
];
959 *yycdebug_
<< name_
[rhs_
[i
]] << ' ';
960 *yycdebug_
<< "-> " << name_
[r1_
[n_
]] << std::endl
;
964 /* YYTRANSLATE(YYLEX) -- Bison symbol number corresponding to YYLEX. */
965 yy::]b4_parser_class_name
[::TokenNumberType
966 yy::]b4_parser_class_name
[::yytranslate_ (int token
)
969 const TokenNumberType
974 if ((unsigned int) token
<= user_token_number_max_
)
975 return translate_table
[token
];
980 const int yy::]b4_parser_class_name
[::eof_
= 0;
981 const int yy::]b4_parser_class_name
[::last_
= ]b4_last
[;
982 const int yy::]b4_parser_class_name
[::nnts_
= ]b4_nterms_number
[;
983 const int yy::]b4_parser_class_name
[::empty_
= -2;
984 const int yy::]b4_parser_class_name
[::final_
= ]b4_final_state_number
[;
985 const int yy::]b4_parser_class_name
[::terror_
= 1;
986 const int yy::]b4_parser_class_name
[::errcode_
= 256;
987 const int yy::]b4_parser_class_name
[::ntokens_
= ]b4_tokens_number
[;
989 const unsigned int yy::]b4_parser_class_name
[::user_token_number_max_
= ]b4_user_token_number_max
[;
990 const yy::]b4_parser_class_name
[::TokenNumberType
yy::]b4_parser_class_name
[::undef_token_
= ]b4_undef_token_number
[;
995 b4_copyright([Stack handling
for Bison C
++ parsers
], [2002, 2003, 2004])[
997 #ifndef BISON_STACK_HH
998 # define BISON_STACK_HH
1004 template <class T
, class S
= std::deque
<T
> >
1009 // Hide our reversed order.
1010 typedef typename
S::reverse_iterator iterator
;
1011 typedef typename
S::const_reverse_iterator const_iterator
;
1017 Stack (unsigned int n
) : seq_ (n
)
1023 operator [] (unsigned int i
)
1030 operator [] (unsigned int i
) const
1039 seq_
.push_front (t
);
1044 pop (unsigned int n
= 1)
1054 return seq_
.size ();
1057 inline const_iterator
begin () const { return seq_
.rbegin (); }
1058 inline const_iterator
end () const { return seq_
.rend (); }
1065 template <class T
, class S
= Stack
<T
> >
1070 Slice (const S
& stack
,
1071 unsigned int range
) : stack_ (stack
),
1078 operator [] (unsigned int i
) const
1080 return stack_
[range_
- i
];
1086 unsigned int range_
;
1090 #endif // not BISON_STACK_HH]
1093 b4_copyright([Position
class for Bison C
++ parsers
], [2002, 2003, 2004])[
1096 ** \file position.hh
1097 ** Define the Location class.
1100 #ifndef BISON_POSITION_HH
1101 # define BISON_POSITION_HH
1103 # include <iostream>
1108 /// Abstract a Position.
1112 /// Initial column number.
1113 static const unsigned int initial_column
= 0;
1114 /// Initial line number.
1115 static const unsigned int initial_line
= 1;
1117 /** \name Ctor & dtor.
1120 /// Construct a Position.
1123 line (initial_line
),
1124 column (initial_column
)
1130 /** \name Line and Column related manipulators
1133 /// (line related) Advance to the COUNT next lines.
1134 inline void lines (int count
= 1)
1136 column
= initial_column
;
1140 /// (column related) Advance to the COUNT next columns.
1141 inline void columns (int count
= 1)
1143 int leftmost
= initial_column
;
1144 int current
= column
;
1145 if (leftmost
<= current
+ count
)
1148 column
= initial_column
;
1153 /// File name to which this position refers.
1154 std::string filename
;
1155 /// Current line number.
1157 /// Current column number.
1158 unsigned int column
;
1161 /// Add and assign a Position.
1162 inline const Position
&
1163 operator+= (Position
& res
, const int width
)
1165 res
.columns (width
);
1169 /// Add two Position objects.
1170 inline const Position
1171 operator+ (const Position
& begin
, const int width
)
1173 Position res
= begin
;
1174 return res
+= width
;
1177 /// Add and assign a Position.
1178 inline const Position
&
1179 operator-= (Position
& res
, const int width
)
1181 return res
+= -width
;
1184 /// Add two Position objects.
1185 inline const Position
1186 operator- (const Position
& begin
, const int width
)
1188 return begin
+ -width
;
1191 /** \brief Intercept output stream redirection.
1192 ** \param ostr the destination output stream
1193 ** \param pos a reference to the Position to redirect
1195 inline std::ostream
&
1196 operator<< (std::ostream
& ostr
, const Position
& pos
)
1198 if (!pos
.filename
.empty ())
1199 ostr
<< pos
.filename
<< ':';
1200 return ostr
<< pos
.line
<< '.' << pos
.column
;
1204 #endif // not BISON_POSITION_HH]
1206 b4_copyright([Location
class for Bison C
++ parsers
], [2002, 2003, 2004])[
1209 ** \file location.hh
1210 ** Define the Location class.
1213 #ifndef BISON_LOCATION_HH
1214 # define BISON_LOCATION_HH
1216 # include <iostream>
1218 # include "position.hh"
1223 /// Abstract a Location.
1226 /** \name Ctor & dtor.
1229 /// Construct a Location.
1238 /** \name Line and Column related manipulators
1241 /// Reset initial location to final location.
1242 inline void step (void)
1247 /// Extend the current location to the COUNT next columns.
1248 inline void columns (unsigned int count
= 1)
1253 /// Extend the current location to the COUNT next lines.
1254 inline void lines (unsigned int count
= 1)
1262 /// Beginning of the located region.
1264 /// End of the located region.
1268 /// Join two Location objects to create a Location.
1269 inline const Location
operator+ (const Location
& begin
, const Location
& end
)
1271 Location res
= begin
;
1276 /// Add two Location objects.
1277 inline const Location
operator+ (const Location
& begin
, unsigned int width
)
1279 Location res
= begin
;
1280 res
.columns (width
);
1284 /// Add and assign a Location.
1285 inline Location
& operator+= (Location
& res
, unsigned int width
)
1287 res
.columns (width
);
1291 /** \brief Intercept output stream redirection.
1292 ** \param ostr the destination output stream
1293 ** \param loc a reference to the Location to redirect
1295 ** Avoid duplicate information.
1297 inline std::ostream
& operator<< (std::ostream
& ostr
, const Location
& loc
)
1299 Position last
= loc
.end
- 1;
1301 if (loc
.begin
.filename
!= last
.filename
)
1302 ostr
<< '-' << last
;
1303 else if (loc
.begin
.line
!= last
.line
)
1304 ostr
<< '-' << last
.line
<< '.' << last
.column
;
1305 else if (loc
.begin
.column
!= last
.column
)
1306 ostr
<< '-' << last
.column
;
1312 #endif // not BISON_LOCATION_HH]