3 # C++ skeleton for Bison
5 # Copyright (C) 2002, 2003, 2004, 2005 Free Software Foundation, Inc.
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.
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.
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
22 m4_include(b4_pkgdatadir
/[c
++.m4
])
24 # We do want M4 expansion after # for CPP macros.
27 m4_if(b4_defines_flag
, 0, [],
28 [@output @output_header_name@
29 b4_copyright([C
++ Skeleton parser
for LALR(1) parsing with Bison
],
30 [2002, 2003, 2004, 2005])[
31 /* FIXME: This is wrong, we want computed header guards.
32 I don't know why the macros are missing now. :( */
33 #ifndef PARSER_HEADER_H
34 # define PARSER_HEADER_H
39 /* Using locations. */
40 #define YYLSP_NEEDED ]b4_locations_flag[
48 ]b4_token_enums(b4_tokens
)[
50 /* Copy the first part of user declarations. */
53 ]/* Line __line__ of lalr1.cc. */
54 b4_syncline([@oline@
], [@ofile@
])[
57 #include "location.hh"
59 /* Enabling traces. */
61 # define YYDEBUG ]b4_debug[
64 /* Enabling verbose error messages. */
65 #ifdef YYERROR_VERBOSE
66 # undef YYERROR_VERBOSE
67 # define YYERROR_VERBOSE 1
69 # define YYERROR_VERBOSE ]b4_error_verbose[
72 /* Enabling the token table. */
74 # define YYTOKEN_TABLE ]b4_token_table[
77 #if ! defined (YYSTYPE) && ! defined (YYSTYPE_IS_DECLARED)
79 [b4_syncline([b4_stype_line
], [b4_file_name
])
80 union YYSTYPE b4_stype
;
81 /* Line __line__ of lalr1.cc. */
82 b4_syncline([@oline@
], [@ofile@
])],
83 [typedef int YYSTYPE
;])[
84 # define yystype YYSTYPE /* obsolescent; will be withdrawn */
85 # define YYSTYPE_IS_DECLARED 1
86 # define YYSTYPE_IS_TRIVIAL 1
89 /* Copy the second part of user declarations. */
92 ]/* Line __line__ of lalr1.cc. */
93 b4_syncline([@oline@
], [@ofile@
])[
94 /* YYLLOC_DEFAULT -- Set CURRENT to span from RHS[1] to RHS[N].
95 If N is 0, then set CURRENT to the empty location which ends
96 the previous symbol: RHS[0] (always defined). */
98 #ifndef YYLLOC_DEFAULT
99 # define YYLLOC_DEFAULT(Current, Rhs, N) \
103 (Current).begin = (Rhs)[1].begin; \
104 (Current).end = (Rhs)[N].end; \
108 (Current).begin = (Current).end = (Rhs)[0].end; \
115 class ]b4_parser_class_name
[;
117 template <typename P
>
123 struct traits
<]b4_parser_class_name
[>
125 typedef ]b4_int_type_for([b4_translate
])[ token_number_type
;
126 typedef ]b4_int_type_for([b4_rhs
])[ rhs_number_type
;
127 typedef int state_type
;
128 typedef YYSTYPE semantic_type
;
129 typedef ]b4_location_type
[ location_type
;
136 class ]b4_parser_class_name
[
138 /// Symbol semantic values.
139 typedef traits
<]b4_parser_class_name
[>::semantic_type semantic_type
;
140 /// Symbol locations.
141 typedef traits
<]b4_parser_class_name
[>::location_type location_type
;
144 /// Build a parser object.
145 ]b4_parser_class_name
[ (]b4_parse_param_decl
[) :
147 yycdebug_ (&std::cerr
)]b4_parse_param_cons
[
151 virtual ~]b4_parser_class_name
[ ()
156 /// \returns 0 iff parsing succeeded.
157 virtual int parse ();
159 /// The current debugging stream.
160 std::ostream
& debug_stream () const;
161 /// Set the current debugging stream.
162 void set_debug_stream (std::ostream
&);
164 /// Type for debugging levels.
165 typedef int debug_level_type
;
166 /// The current debugging level.
167 debug_level_type
debug_level () const;
168 /// Set the current debugging level.
169 void set_debug_level (debug_level_type l
);
172 /// Report a syntax error.
173 /// \param loc where the syntax error is found.
174 /// \param msg a description of the syntax error.
175 virtual void error (const location_type
& loc
, const std::string
& msg
);
177 /// Generate an error message.
178 /// \param tok the look-ahead token.
179 virtual std::string
yysyntax_error_ (int tok
);
182 /// \brief Report a symbol on the debug stream.
183 /// \param yytype The token type.
184 /// \param yyvaluep Its semantic value.
185 /// \param yylocationp Its location.
186 virtual void yysymprint_ (int yytype
,
187 const semantic_type
* yyvaluep
,
188 const location_type
* yylocationp
);
189 #endif /* ! YYDEBUG */
193 typedef traits
<]b4_parser_class_name
[>::state_type state_type
;
194 /// State stack type.
195 typedef stack
<state_type
> state_stack_type
;
196 /// Semantic value stack type.
197 typedef stack
<semantic_type
> semantic_stack_type
;
198 /// location stack type.
199 typedef stack
<location_type
> location_stack_type
;
202 state_stack_type yystate_stack_
;
203 /// The semantic value stack.
204 semantic_stack_type yysemantic_stack_
;
205 /// The location stack.
206 location_stack_type yylocation_stack_
;
208 /// Internal symbol numbers.
209 typedef traits
<]b4_parser_class_name
[>::token_number_type token_number_type
;
211 /// For a state, the index in \a yytable_ of its portion.
212 static const ]b4_int_type_for([b4_pact
])[ yypact_
[];
213 static const ]b4_int_type(b4_pact_ninf
, b4_pact_ninf
)[ yypact_ninf_
;
215 /// For a state, default rule to reduce.
216 /// Unless\a yytable_ specifies something else to do.
217 /// Zero means the default is an error.
218 static const ]b4_int_type_for([b4_defact
])[ yydefact_
[];
220 static const ]b4_int_type_for([b4_pgoto
])[ yypgoto_
[];
221 static const ]b4_int_type_for([b4_defgoto
])[ yydefgoto_
[];
223 /// What to do in a state.
224 /// \a yytable_[yypact_[s]]: what to do in state \a s.
225 /// - if positive, shift that token.
226 /// - if negative, reduce the rule which number is the opposite.
227 /// - if zero, do what YYDEFACT says.
228 static const ]b4_int_type_for([b4_table
])[ yytable_
[];
229 static const ]b4_int_type(b4_table_ninf
, b4_table_ninf
)[ yytable_ninf_
;
231 static const ]b4_int_type_for([b4_check
])[ yycheck_
[];
233 /// For a state, its accessing symbol.
234 static const ]b4_int_type_for([b4_stos
])[ yystos_
[];
236 /// For a rule, its LHS.
237 static const ]b4_int_type_for([b4_r1
])[ yyr1_
[];
238 /// For a rule, its RHS length.
239 static const ]b4_int_type_for([b4_r2
])[ yyr2_
[];
241 #if YYDEBUG || YYERROR_VERBOSE || YYTOKEN_TABLE
242 /// For a symbol, its name in clear.
243 static const char* const yytname_
[];
247 /// Convert the symbol name \a n to a form suitable for a diagnostic.
248 virtual std::string
yytnamerr_ (const char *n
);
252 /// A type to store symbol numbers and -1.
253 typedef traits
<]b4_parser_class_name
[>::rhs_number_type rhs_number_type
;
254 /// A `-1'-separated list of the rules' RHS.
255 static const rhs_number_type yyrhs_
[];
256 /// For each rule, the index of the first RHS symbol in \a yyrhs_.
257 static const ]b4_int_type_for([b4_prhs
])[ yyprhs_
[];
258 /// For each rule, its source line number.
259 static const ]b4_int_type_for([b4_rline
])[ yyrline_
[];
260 /// For each scanner token number, its symbol number.
261 static const ]b4_int_type_for([b4_toknum
])[ yytoken_number_
[];
262 /// Report on the debug stream that the rule \a r is going to be reduced.
263 virtual void yyreduce_print_ (int r
);
264 /// Print the state stack on the debug stream.
265 virtual void yystack_print_ ();
268 /// Convert a scanner token number to a symbol number.
269 inline token_number_type
yytranslate_ (int token
);
271 /// \brief Reclaim the memory associated to a symbol.
272 /// \param yymsg Why this token is reclaimed.
273 /// \param yytype The symbol type.
274 /// \param yyvaluep Its semantic value.
275 /// \param yylocationp Its location.
276 inline void yydestruct_ (const char* yymsg
,
278 semantic_type
* yyvaluep
,
279 location_type
* yylocationp
);
281 /// Pop \a n symbols the three stacks.
282 inline void yypop_ (unsigned int n
= 1);
285 static const int yyeof_
;
286 /* LAST_ -- Last index in TABLE_. */
287 static const int yylast_
;
288 static const int yynnts_
;
289 static const int yyempty_
;
290 static const int yyfinal_
;
291 static const int yyterror_
;
292 static const int yyerrcode_
;
293 static const int yyntokens_
;
294 static const unsigned int yyuser_token_number_max_
;
295 static const token_number_type yyundef_token_
;
302 /* Error handling. */
308 std::ostream
* yycdebug_
;
310 ]b4_parse_param_vars
[
314 #endif /* ! defined PARSER_HEADER_H */]
316 @output @output_parser_name@
317 b4_copyright([C
++ Skeleton parser
for LALR(1) parsing with Bison
],
318 [2002, 2003, 2004, 2005])
319 m4_if(b4_prefix
[], [yy
], [],
321 // Take the name prefix into account.
322 #define yylex b4_prefix[]lex])
323 m4_if(b4_defines_flag
, 0, [],
325 #include @output_header_name@])[
330 # include <libintl.h> /* FIXME: INFRINGES ON USER NAME SPACE */
331 # define YY_(msgid) dgettext ("bison-runtime", msgid)
335 # define YY_(msgid) msgid
339 /* A pseudo ostream that takes yydebug_ into account. */
341 for (bool yydebugcond_ = yydebug_; yydebugcond_; yydebugcond_ = false) \
344 /* Enable debugging if requested. */
347 # define YY_SYMBOL_PRINT(Title, Type, Value, Location) \
351 *yycdebug_ << (Title) << ' '; \
352 yysymprint_ ((Type), (Value), (Location)); \
353 *yycdebug_ << std::endl; \
357 # define YY_REDUCE_PRINT(Rule) \
360 yyreduce_print_ (Rule); \
363 # define YY_STACK_PRINT() \
371 # define YY_SYMBOL_PRINT(Title, Type, Value, Location)
372 # define YY_REDUCE_PRINT(Rule)
373 # define YY_STACK_PRINT()
375 #endif /* !YYDEBUG */
377 #define YYACCEPT goto yyacceptlab
378 #define YYABORT goto yyabortlab
379 #define YYERROR goto yyerrorlab
383 /* Return YYSTR after stripping away unnecessary quotes and
384 backslashes, so that it's suitable for yyerror. The heuristic is
385 that double-quoting is unnecessary unless the string contains an
386 apostrophe, a comma, or backslash (other than backslash-backslash).
387 YYSTR is taken from yytname. */
389 yy::]b4_parser_class_name
[::yytnamerr_ (const char *yystr
)
393 std::string yyr
= "";
394 char const *yyp
= yystr
;
401 goto do_not_strip_quotes
;
405 goto do_not_strip_quotes
;
414 do_not_strip_quotes
: ;
423 /*--------------------------------.
424 | Print this symbol on YYOUTPUT. |
425 `--------------------------------*/
428 yy::]b4_parser_class_name
[::yysymprint_ (int yytype
,
429 const semantic_type
* yyvaluep
, const location_type
* yylocationp
)
431 /* Pacify ``unused variable'' warnings. */
434 /* Backward compatibility, but should be removed eventually. */
435 std::ostream
& cdebug_
= *yycdebug_
;
438 *yycdebug_
<< (yytype
< yyntokens_
? "token" : "nterm")
439 << ' ' << yytname_
[yytype
] << " ("
440 << *yylocationp
<< ": ";
443 ]m4_map([b4_symbol_actions
], m4_defn([b4_symbol_printers
]))dnl
449 #endif /* ! YYDEBUG */
452 yy::]b4_parser_class_name
[::yydestruct_ (const char* yymsg
,
453 int yytype
, semantic_type
* yyvaluep
, location_type
* yylocationp
)
455 /* Pacify ``unused variable'' warnings. */
460 YY_SYMBOL_PRINT (yymsg
, yytype
, yyvaluep
, yylocationp
);
464 ]m4_map([b4_symbol_actions
], m4_defn([b4_symbol_destructors
]))[
471 yy::]b4_parser_class_name
[::yypop_ (unsigned int n
)
473 yystate_stack_
.pop (n
);
474 yysemantic_stack_
.pop (n
);
475 yylocation_stack_
.pop (n
);
479 yy::]b4_parser_class_name
[::debug_stream () const
485 yy::]b4_parser_class_name
[::set_debug_stream (std::ostream
& o
)
491 yy::]b4_parser_class_name
[::debug_level_type
492 yy::]b4_parser_class_name
[::debug_level () const
498 yy::]b4_parser_class_name
[::set_debug_level (debug_level_type l
)
505 yy::]b4_parser_class_name
[::parse ()
507 /* Look-ahead and look-ahead in internal form. */
511 /// Semantic value of the look-ahead.
512 semantic_type yylval
;
513 /// Location of the look-ahead.
514 location_type yylloc
;
515 /// The locations where the error started and ended.
516 location yyerror_range
[2];
525 YYCDEBUG
<< "Starting parse" << std::endl
;
534 ]m4_ifdef([b4_initial_action
], [
535 m4_pushdef([b4_at_dollar
], [yylloc
])dnl
536 m4_pushdef([b4_dollar_dollar
], [yylval
])dnl
537 /* User initialization code. */
539 m4_popdef([b4_dollar_dollar
])dnl
540 m4_popdef([b4_at_dollar
])dnl
541 /* Line __line__ of yacc.c. */
542 b4_syncline([@oline@
], [@ofile@
])])dnl
544 [ /* Initialize the stacks. The initial state will be pushed in
545 yynewstate, since the latter expects the semantical and the
546 location values to have been already stored, initialize these
547 stacks with a primary value. */
548 yystate_stack_
= state_stack_type (0);
549 yysemantic_stack_
= semantic_stack_type (0);
550 yylocation_stack_
= location_stack_type (0);
551 yysemantic_stack_
.push (yylval
);
552 yylocation_stack_
.push (yylloc
);
556 yystate_stack_
.push (yystate_
);
557 YYCDEBUG
<< "Entering state " << yystate_
<< std::endl
;
563 /* Try to take a decision without look-ahead. */
564 yyn_
= yypact_
[yystate_
];
565 if (yyn_
== yypact_ninf_
)
568 /* Read a look-ahead token. */
569 if (yylooka
== yyempty_
)
571 YYCDEBUG
<< "Reading a token: ";
572 yylooka
= ]b4_c_function_call([yylex
], [int],
573 [[YYSTYPE
*], [&yylval
]][]dnl
574 b4_location_if([, [[location
*], [&yylloc
]]])dnl
575 m4_ifdef([b4_lex_param
], [, ]b4_lex_param
))[;
579 /* Convert token to internal form. */
580 if (yylooka
<= yyeof_
)
582 yylooka
= yyilooka
= yyeof_
;
583 YYCDEBUG
<< "Now at end of input." << std::endl
;
587 yyilooka
= yytranslate_ (yylooka
);
588 YY_SYMBOL_PRINT ("Next token is", yyilooka
, &yylval
, &yylloc
);
591 /* If the proper action on seeing token ILOOKA_ is to reduce or to
592 detect an error, take that action. */
594 if (yyn_
< 0 || yylast_
< yyn_
|| yycheck_
[yyn_
] != yyilooka
)
597 /* Reduce or error. */
598 yyn_
= yytable_
[yyn_
];
601 if (yyn_
== yytable_ninf_
)
613 if (yyn_
== yyfinal_
)
616 /* Shift the look-ahead token. */
617 YY_SYMBOL_PRINT ("Shifting", yyilooka
, &yylval
, &yylloc
);
619 /* Discard the token being shifted unless it is eof. */
620 if (yylooka
!= yyeof_
)
623 yysemantic_stack_
.push (yylval
);
624 yylocation_stack_
.push (yylloc
);
626 /* Count tokens shifted since error; after three, turn off error
634 /*-----------------------------------------------------------.
635 | yydefault -- do the default action for the current state. |
636 `-----------------------------------------------------------*/
638 yyn_
= yydefact_
[yystate_
];
643 /*-----------------------------.
644 | yyreduce -- Do a reduction. |
645 `-----------------------------*/
647 yylen_
= yyr2_
[yyn_
];
648 /* If LEN_ is nonzero, implement the default value of the action:
649 `$$ = $1'. Otherwise, use the top of the stack.
651 Otherwise, the following line sets YYVAL to garbage.
652 This behavior is undocumented and Bison
653 users should not rely upon it. */
655 yyval
= yysemantic_stack_
[yylen_
- 1];
657 yyval
= yysemantic_stack_
[0];
660 slice
<location_type
, location_stack_type
> slice (yylocation_stack_
, yylen_
);
661 YYLLOC_DEFAULT (yyloc
, slice
, yylen_
);
663 YY_REDUCE_PRINT (yyn_
);
670 ]/* Line __line__ of lalr1.cc. */
671 b4_syncline([@oline@
], [@ofile@
])[
677 yysemantic_stack_
.push (yyval
);
678 yylocation_stack_
.push (yyloc
);
680 /* Shift the result of the reduction. */
682 yystate_
= yypgoto_
[yyn_
- yyntokens_
] + yystate_stack_
[0];
683 if (0 <= yystate_
&& yystate_
<= yylast_
684 && yycheck_
[yystate_
] == yystate_stack_
[0])
685 yystate_
= yytable_
[yystate_
];
687 yystate_
= yydefgoto_
[yyn_
- yyntokens_
];
690 /*------------------------------------.
691 | yyerrlab -- here on detecting error |
692 `------------------------------------*/
694 /* If not already recovering from an error, report this error. */
698 error (yylloc
, yysyntax_error_ (yyilooka
));
701 yyerror_range
[0] = yylloc
;
702 if (yyerrstatus_
== 3)
704 /* If just tried and failed to reuse look-ahead token after an
705 error, discard it. */
707 if (yylooka
<= yyeof_
)
709 /* Return failure if at end of input. */
710 if (yylooka
== yyeof_
)
715 yydestruct_ ("Error: discarding", yyilooka
, &yylval
, &yylloc
);
720 /* Else will try to reuse look-ahead token after shifting the error
725 /*---------------------------------------------------.
726 | yyerrorlab -- error raised explicitly by YYERROR. |
727 `---------------------------------------------------*/
730 /* Pacify compilers like GCC when the user code never invokes
731 YYERROR and the label yyerrorlab therefore never appears in user
736 yyerror_range
[0] = yylocation_stack_
[yylen_
- 1];
738 yystate_
= yystate_stack_
[0];
741 /*-------------------------------------------------------------.
742 | yyerrlab1 -- common code for both syntax error and YYERROR. |
743 `-------------------------------------------------------------*/
745 yyerrstatus_
= 3; /* Each real token shifted decrements this. */
749 yyn_
= yypact_
[yystate_
];
750 if (yyn_
!= yypact_ninf_
)
753 if (0 <= yyn_
&& yyn_
<= yylast_
&& yycheck_
[yyn_
] == yyterror_
)
755 yyn_
= yytable_
[yyn_
];
761 /* Pop the current state because it cannot handle the error token. */
762 if (yystate_stack_
.height () == 1)
765 yyerror_range
[0] = yylocation_stack_
[0];
766 yydestruct_ ("Error: popping",
768 &yysemantic_stack_
[0], &yylocation_stack_
[0]);
770 yystate_
= yystate_stack_
[0];
774 if (yyn_
== yyfinal_
)
777 yyerror_range
[1] = yylloc
;
778 // Using YYLLOC is tempting, but would change the location of
779 // the look-ahead. YYLOC is available though.
780 YYLLOC_DEFAULT (yyloc
, yyerror_range
- 1, 2);
781 yysemantic_stack_
.push (yylval
);
782 yylocation_stack_
.push (yyloc
);
784 /* Shift the error token. */
785 YY_SYMBOL_PRINT ("Shifting", yystos_
[yyn_
],
786 &yysemantic_stack_
[0], &yylocation_stack_
[0]);
802 if (yylooka
!= yyeof_
&& yylooka
!= yyempty_
)
803 yydestruct_ ("Cleanup: discarding lookahead", yyilooka
, &yylval
, &yylloc
);
805 while (yystate_stack_
.height () != 1)
807 yydestruct_ ("Cleanup: popping",
808 yystos_
[yystate_stack_
[0]],
809 &yysemantic_stack_
[0],
810 &yylocation_stack_
[0]);
817 // Generate an error message.
819 yy::]b4_parser_class_name
[::yysyntax_error_ (int tok
)
823 yyn_
= yypact_
[yystate_
];
824 if (yypact_ninf_
< yyn_
&& yyn_
< yylast_
)
826 /* Start YYX at -YYN if negative to avoid negative indexes in
828 int yyxbegin
= yyn_
< 0 ? -yyn_
: 0;
830 /* Stay within bounds of both yycheck and yytname. */
831 int yychecklim
= yylast_
- yyn_
;
832 int yyxend
= yychecklim
< yyntokens_
? yychecklim
: yyntokens_
;
834 for (int x
= yyxbegin
; x
< yyxend
; ++x
)
835 if (yycheck_
[x
+ yyn_
] == x
&& x
!= yyterror_
)
838 // FIXME: This method of building the message is not compatible
839 // with internationalization. It should work like yacc.c does it.
840 // That is, first build a string that looks like this:
841 // "syntax error, unexpected %s or %s or %s"
842 // Then, invoke YY_ on this string.
843 // Finally, use the string as a format to output
844 // yytname_[tok], etc.
845 // Until this gets fixed, this message appears in English only.
846 res
= "syntax error, unexpected ";
847 res
+= yytnamerr_ (yytname_
[tok
]);
851 for (int x
= yyxbegin
; x
< yyxend
; ++x
)
852 if (yycheck_
[x
+ yyn_
] == x
&& x
!= yyterror_
)
854 res
+= (!count
++) ? ", expecting " : " or ";
855 res
+= yytnamerr_ (yytname_
[x
]);
861 res
= YY_("syntax error");
866 /* YYPACT[STATE-NUM] -- Index in YYTABLE of the portion describing
868 const ]b4_int_type(b4_pact_ninf
, b4_pact_ninf
) yy::b4_parser_class_name::yypact_ninf_
= b4_pact_ninf
[;
869 const ]b4_int_type_for([b4_pact
])[
870 yy::]b4_parser_class_name
[::yypact_
[] =
875 /* YYDEFACT[S] -- default rule to reduce with in state S when YYTABLE
876 doesn't specify something else to do. Zero means the default is an
878 const ]b4_int_type_for([b4_defact
])[
879 yy::]b4_parser_class_name
[::yydefact_
[] =
884 /* YYPGOTO[NTERM-NUM]. */
885 const ]b4_int_type_for([b4_pgoto
])[
886 yy::]b4_parser_class_name
[::yypgoto_
[] =
891 /* YYDEFGOTO[NTERM-NUM]. */
892 const ]b4_int_type_for([b4_defgoto
])[
893 yy::]b4_parser_class_name
[::yydefgoto_
[] =
898 /* YYTABLE[YYPACT[STATE-NUM]]. What to do in state STATE-NUM. If
899 positive, shift that token. If negative, reduce the rule which
900 number is the opposite. If zero, do what YYDEFACT says. */
901 const ]b4_int_type(b4_table_ninf
, b4_table_ninf
) yy::b4_parser_class_name::yytable_ninf_
= b4_table_ninf
[;
902 const ]b4_int_type_for([b4_table
])[
903 yy::]b4_parser_class_name
[::yytable_
[] =
909 const ]b4_int_type_for([b4_check
])[
910 yy::]b4_parser_class_name
[::yycheck_
[] =
915 /* STOS_[STATE-NUM] -- The (internal number of the) accessing
916 symbol of state STATE-NUM. */
917 const ]b4_int_type_for([b4_stos
])[
918 yy::]b4_parser_class_name
[::yystos_
[] =
924 /* TOKEN_NUMBER_[YYLEX-NUM] -- Internal symbol number corresponding
926 const ]b4_int_type_for([b4_toknum
])[
927 yy::]b4_parser_class_name
[::yytoken_number_
[] =
933 /* YYR1[YYN] -- Symbol number of symbol that rule YYN derives. */
934 const ]b4_int_type_for([b4_r1
])[
935 yy::]b4_parser_class_name
[::yyr1_
[] =
940 /* YYR2[YYN] -- Number of symbols composing right hand side of rule YYN. */
941 const ]b4_int_type_for([b4_r2
])[
942 yy::]b4_parser_class_name
[::yyr2_
[] =
947 #if YYDEBUG || YYERROR_VERBOSE || YYTOKEN_TABLE
948 /* YYTNAME[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM.
949 First, the terminals, then, starting at \a yyntokens_, nonterminals. */
951 const yy::]b4_parser_class_name
[::yytname_
[] =
958 /* YYRHS -- A `-1'-separated list of the rules' RHS. */
959 const yy::]b4_parser_class_name
[::rhs_number_type
960 yy::]b4_parser_class_name
[::yyrhs_
[] =
965 /* YYPRHS[YYN] -- Index of the first RHS symbol of rule number YYN in
967 const ]b4_int_type_for([b4_prhs
])[
968 yy::]b4_parser_class_name
[::yyprhs_
[] =
973 /* YYRLINE[YYN] -- Source line where rule number YYN was defined. */
974 const ]b4_int_type_for([b4_rline
])[
975 yy::]b4_parser_class_name
[::yyrline_
[] =
980 // Print the state stack on the debug stream.
982 yy::]b4_parser_class_name
[::yystack_print_ ()
984 *yycdebug_
<< "Stack now";
985 for (state_stack_type::const_iterator i
= yystate_stack_
.begin ();
986 i
!= yystate_stack_
.end (); ++i
)
987 *yycdebug_
<< ' ' << *i
;
988 *yycdebug_
<< std::endl
;
991 // Report on the debug stream that the rule \a yyrule is going to be reduced.
993 yy::]b4_parser_class_name
[::yyreduce_print_ (int yyrule
)
995 unsigned int yylno
= yyrline_
[yyrule
];
996 /* Print the symbols being reduced, and their result. */
997 *yycdebug_
<< "Reducing stack by rule " << yyn_
- 1
998 << " (line " << yylno
<< "), ";
999 for (]b4_int_type_for([b4_prhs
])[ i
= yyprhs_
[yyn_
];
1000 0 <= yyrhs_
[i
]; ++i
)
1001 *yycdebug_
<< yytname_
[yyrhs_
[i
]] << ' ';
1002 *yycdebug_
<< "-> " << yytname_
[yyr1_
[yyn_
]] << std::endl
;
1006 /* YYTRANSLATE(YYLEX) -- Bison symbol number corresponding to YYLEX. */
1007 yy::]b4_parser_class_name
[::token_number_type
1008 yy::]b4_parser_class_name
[::yytranslate_ (int token
)
1011 const token_number_type
1016 if ((unsigned int) token
<= yyuser_token_number_max_
)
1017 return translate_table
[token
];
1019 return yyundef_token_
;
1022 const int yy::]b4_parser_class_name
[::yyeof_
= 0;
1023 const int yy::]b4_parser_class_name
[::yylast_
= ]b4_last
[;
1024 const int yy::]b4_parser_class_name
[::yynnts_
= ]b4_nterms_number
[;
1025 const int yy::]b4_parser_class_name
[::yyempty_
= -2;
1026 const int yy::]b4_parser_class_name
[::yyfinal_
= ]b4_final_state_number
[;
1027 const int yy::]b4_parser_class_name
[::yyterror_
= 1;
1028 const int yy::]b4_parser_class_name
[::yyerrcode_
= 256;
1029 const int yy::]b4_parser_class_name
[::yyntokens_
= ]b4_tokens_number
[;
1031 const unsigned int yy::]b4_parser_class_name
[::yyuser_token_number_max_
= ]b4_user_token_number_max
[;
1032 const yy::]b4_parser_class_name
[::token_number_type
yy::]b4_parser_class_name
[::yyundef_token_
= ]b4_undef_token_number
[;
1037 b4_copyright([stack handling
for Bison C
++ parsers
], [2002, 2003, 2004, 2005])[
1039 #ifndef BISON_STACK_HH
1040 # define BISON_STACK_HH
1046 template <class T
, class S
= std::deque
<T
> >
1051 // Hide our reversed order.
1052 typedef typename
S::reverse_iterator iterator
;
1053 typedef typename
S::const_reverse_iterator const_iterator
;
1059 stack (unsigned int n
) : seq_ (n
)
1065 operator [] (unsigned int i
)
1072 operator [] (unsigned int i
) const
1081 seq_
.push_front (t
);
1086 pop (unsigned int n
= 1)
1096 return seq_
.size ();
1099 inline const_iterator
begin () const { return seq_
.rbegin (); }
1100 inline const_iterator
end () const { return seq_
.rend (); }
1107 /// Present a slice of the top of a stack.
1108 template <class T
, class S
= stack
<T
> >
1113 slice (const S
& stack
,
1114 unsigned int range
) : stack_ (stack
),
1121 operator [] (unsigned int i
) const
1123 return stack_
[range_
- i
];
1129 unsigned int range_
;
1133 #endif // not BISON_STACK_HH]
1136 b4_copyright([Position
class for Bison C
++ parsers
], [2002, 2003, 2004, 2005])[
1139 ** \file position.hh
1140 ** Define the position class.
1143 #ifndef BISON_POSITION_HH
1144 # define BISON_POSITION_HH
1146 # include <iostream>
1151 /// Abstract a position.
1155 /// Initial column number.
1156 static const unsigned int initial_column
= 0;
1157 /// Initial line number.
1158 static const unsigned int initial_line
= 1;
1160 /** \name Ctor & dtor.
1163 /// Construct a position.
1166 line (initial_line
),
1167 column (initial_column
)
1173 /** \name Line and Column related manipulators
1176 /// (line related) Advance to the COUNT next lines.
1177 inline void lines (int count
= 1)
1179 column
= initial_column
;
1183 /// (column related) Advance to the COUNT next columns.
1184 inline void columns (int count
= 1)
1186 int leftmost
= initial_column
;
1187 int current
= column
;
1188 if (leftmost
<= current
+ count
)
1191 column
= initial_column
;
1196 /// File name to which this position refers.
1197 ]b4_filename_type
[* filename
;
1198 /// Current line number.
1200 /// Current column number.
1201 unsigned int column
;
1204 /// Add and assign a position.
1205 inline const position
&
1206 operator+= (position
& res
, const int width
)
1208 res
.columns (width
);
1212 /// Add two position objects.
1213 inline const position
1214 operator+ (const position
& begin
, const int width
)
1216 position res
= begin
;
1217 return res
+= width
;
1220 /// Add and assign a position.
1221 inline const position
&
1222 operator-= (position
& res
, const int width
)
1224 return res
+= -width
;
1227 /// Add two position objects.
1228 inline const position
1229 operator- (const position
& begin
, const int width
)
1231 return begin
+ -width
;
1234 /** \brief Intercept output stream redirection.
1235 ** \param ostr the destination output stream
1236 ** \param pos a reference to the position to redirect
1238 inline std::ostream
&
1239 operator<< (std::ostream
& ostr
, const position
& pos
)
1242 ostr
<< *pos
.filename
<< ':';
1243 return ostr
<< pos
.line
<< '.' << pos
.column
;
1247 #endif // not BISON_POSITION_HH]
1249 b4_copyright([Location
class for Bison C
++ parsers
], [2002, 2003, 2004, 2005])[
1252 ** \file location.hh
1253 ** Define the location class.
1256 #ifndef BISON_LOCATION_HH
1257 # define BISON_LOCATION_HH
1259 # include <iostream>
1261 # include "position.hh"
1266 /// Abstract a location.
1269 /** \name Ctor & dtor.
1272 /// Construct a location.
1281 /** \name Line and Column related manipulators
1284 /// Reset initial location to final location.
1290 /// Extend the current location to the COUNT next columns.
1291 inline void columns (unsigned int count
= 1)
1296 /// Extend the current location to the COUNT next lines.
1297 inline void lines (unsigned int count
= 1)
1305 /// Beginning of the located region.
1307 /// End of the located region.
1311 /// Join two location objects to create a location.
1312 inline const location
operator+ (const location
& begin
, const location
& end
)
1314 location res
= begin
;
1319 /// Add two location objects.
1320 inline const location
operator+ (const location
& begin
, unsigned int width
)
1322 location res
= begin
;
1323 res
.columns (width
);
1327 /// Add and assign a location.
1328 inline location
& operator+= (location
& res
, unsigned int width
)
1330 res
.columns (width
);
1334 /** \brief Intercept output stream redirection.
1335 ** \param ostr the destination output stream
1336 ** \param loc a reference to the location to redirect
1338 ** Avoid duplicate information.
1340 inline std::ostream
& operator<< (std::ostream
& ostr
, const location
& loc
)
1342 position last
= loc
.end
- 1;
1345 && (!loc
.begin
.filename
1346 || *loc
.begin
.filename
!= *last
.filename
))
1347 ostr
<< '-' << last
;
1348 else if (loc
.begin
.line
!= last
.line
)
1349 ostr
<< '-' << last
.line
<< '.' << last
.column
;
1350 else if (loc
.begin
.column
!= last
.column
)
1351 ostr
<< '-' << last
.column
;
1357 #endif // not BISON_LOCATION_HH]