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[
73 # define YYERROR_VERBOSE_IF(x) x
75 # define YYERROR_VERBOSE_IF(x) /* empty */
78 /* Enabling the token table. */
80 # define YYTOKEN_TABLE ]b4_token_table[
83 #if ! defined (YYSTYPE) && ! defined (YYSTYPE_IS_DECLARED)
85 [b4_syncline([b4_stype_line
], [b4_file_name
])
86 union YYSTYPE b4_stype
;
87 /* Line __line__ of lalr1.cc. */
88 b4_syncline([@oline@
], [@ofile@
])],
89 [typedef int YYSTYPE
;])[
90 # define yystype YYSTYPE /* obsolescent; will be withdrawn */
91 # define YYSTYPE_IS_DECLARED 1
92 # define YYSTYPE_IS_TRIVIAL 1
95 /* Copy the second part of user declarations. */
98 ]/* Line __line__ of lalr1.cc. */
99 b4_syncline([@oline@
], [@ofile@
])[
100 /* YYLLOC_DEFAULT -- Set CURRENT to span from RHS[1] to RHS[N].
101 If N is 0, then set CURRENT to the empty location which ends
102 the previous symbol: RHS[0] (always defined). */
104 #ifndef YYLLOC_DEFAULT
105 # define YYLLOC_DEFAULT(Current, Rhs, N) \
109 (Current).begin = (Rhs)[1].begin; \
110 (Current).end = (Rhs)[N].end; \
114 (Current).begin = (Current).end = (Rhs)[0].end; \
121 class ]b4_parser_class_name
[;
123 template <typename P
>
129 struct traits
<]b4_parser_class_name
[>
131 typedef ]b4_int_type_for([b4_translate
])[ token_number_type
;
132 typedef ]b4_int_type_for([b4_rhs
])[ rhs_number_type
;
133 typedef int state_type
;
134 typedef YYSTYPE semantic_type
;
135 typedef ]b4_location_type
[ location_type
;
142 class ]b4_parser_class_name
[
144 /// Symbol semantic values.
145 typedef traits
<]b4_parser_class_name
[>::semantic_type semantic_type
;
146 /// Symbol locations.
147 typedef traits
<]b4_parser_class_name
[>::location_type location_type
;
150 /// Build a parser object.
151 ]b4_parser_class_name
[ (]b4_parse_param_decl
[) :
153 yycdebug_ (&std::cerr
)]b4_parse_param_cons
[
157 virtual ~]b4_parser_class_name
[ ()
162 /// \returns 0 iff parsing succeeded.
163 virtual int parse ();
165 /// The current debugging stream.
166 std::ostream
& debug_stream () const;
167 /// Set the current debugging stream.
168 void set_debug_stream (std::ostream
&);
170 /// Type for debugging levels.
171 typedef int debug_level_type
;
172 /// The current debugging level.
173 debug_level_type
debug_level () const;
174 /// Set the current debugging level.
175 void set_debug_level (debug_level_type l
);
178 /// Report a syntax error.
179 /// \param loc where the syntax error is found.
180 /// \param msg a description of the syntax error.
181 virtual void error (const location_type
& loc
, const std::string
& msg
);
183 /// Generate an error message.
184 /// \param tok the look-ahead token.
185 virtual std::string
yysyntax_error_ (YYERROR_VERBOSE_IF (int tok
));
188 /// \brief Report a symbol on the debug stream.
189 /// \param yytype The token type.
190 /// \param yyvaluep Its semantic value.
191 /// \param yylocationp Its location.
192 virtual void yysymprint_ (int yytype
,
193 const semantic_type
* yyvaluep
,
194 const location_type
* yylocationp
);
195 #endif /* ! YYDEBUG */
199 typedef traits
<]b4_parser_class_name
[>::state_type state_type
;
200 /// State stack type.
201 typedef stack
<state_type
> state_stack_type
;
202 /// Semantic value stack type.
203 typedef stack
<semantic_type
> semantic_stack_type
;
204 /// location stack type.
205 typedef stack
<location_type
> location_stack_type
;
208 state_stack_type yystate_stack_
;
209 /// The semantic value stack.
210 semantic_stack_type yysemantic_stack_
;
211 /// The location stack.
212 location_stack_type yylocation_stack_
;
214 /// Internal symbol numbers.
215 typedef traits
<]b4_parser_class_name
[>::token_number_type token_number_type
;
217 /// For a state, the index in \a yytable_ of its portion.
218 static const ]b4_int_type_for([b4_pact
])[ yypact_
[];
219 static const ]b4_int_type(b4_pact_ninf
, b4_pact_ninf
)[ yypact_ninf_
;
221 /// For a state, default rule to reduce.
222 /// Unless\a yytable_ specifies something else to do.
223 /// Zero means the default is an error.
224 static const ]b4_int_type_for([b4_defact
])[ yydefact_
[];
226 static const ]b4_int_type_for([b4_pgoto
])[ yypgoto_
[];
227 static const ]b4_int_type_for([b4_defgoto
])[ yydefgoto_
[];
229 /// What to do in a state.
230 /// \a yytable_[yypact_[s]]: what to do in state \a s.
231 /// - if positive, shift that token.
232 /// - if negative, reduce the rule which number is the opposite.
233 /// - if zero, do what YYDEFACT says.
234 static const ]b4_int_type_for([b4_table
])[ yytable_
[];
235 static const ]b4_int_type(b4_table_ninf
, b4_table_ninf
)[ yytable_ninf_
;
237 static const ]b4_int_type_for([b4_check
])[ yycheck_
[];
239 /// For a state, its accessing symbol.
240 static const ]b4_int_type_for([b4_stos
])[ yystos_
[];
242 /// For a rule, its LHS.
243 static const ]b4_int_type_for([b4_r1
])[ yyr1_
[];
244 /// For a rule, its RHS length.
245 static const ]b4_int_type_for([b4_r2
])[ yyr2_
[];
247 #if YYDEBUG || YYERROR_VERBOSE || YYTOKEN_TABLE
248 /// For a symbol, its name in clear.
249 static const char* const yytname_
[];
253 /// Convert the symbol name \a n to a form suitable for a diagnostic.
254 virtual std::string
yytnamerr_ (const char *n
);
258 /// A type to store symbol numbers and -1.
259 typedef traits
<]b4_parser_class_name
[>::rhs_number_type rhs_number_type
;
260 /// A `-1'-separated list of the rules' RHS.
261 static const rhs_number_type yyrhs_
[];
262 /// For each rule, the index of the first RHS symbol in \a yyrhs_.
263 static const ]b4_int_type_for([b4_prhs
])[ yyprhs_
[];
264 /// For each rule, its source line number.
265 static const ]b4_int_type_for([b4_rline
])[ yyrline_
[];
266 /// For each scanner token number, its symbol number.
267 static const ]b4_int_type_for([b4_toknum
])[ yytoken_number_
[];
268 /// Report on the debug stream that the rule \a r is going to be reduced.
269 virtual void yyreduce_print_ (int r
);
270 /// Print the state stack on the debug stream.
271 virtual void yystack_print_ ();
274 /// Convert a scanner token number to a symbol number.
275 inline token_number_type
yytranslate_ (int token
);
277 /// \brief Reclaim the memory associated to a symbol.
278 /// \param yymsg Why this token is reclaimed.
279 /// \param yytype The symbol type.
280 /// \param yyvaluep Its semantic value.
281 /// \param yylocationp Its location.
282 inline void yydestruct_ (const char* yymsg
,
284 semantic_type
* yyvaluep
,
285 location_type
* yylocationp
);
287 /// Pop \a n symbols the three stacks.
288 inline void yypop_ (unsigned int n
= 1);
291 static const int yyeof_
;
292 /* LAST_ -- Last index in TABLE_. */
293 static const int yylast_
;
294 static const int yynnts_
;
295 static const int yyempty_
;
296 static const int yyfinal_
;
297 static const int yyterror_
;
298 static const int yyerrcode_
;
299 static const int yyntokens_
;
300 static const unsigned int yyuser_token_number_max_
;
301 static const token_number_type yyundef_token_
;
308 /* Error handling. */
314 std::ostream
* yycdebug_
;
316 ]b4_parse_param_vars
[
320 #endif /* ! defined PARSER_HEADER_H */]
322 @output @output_parser_name@
323 b4_copyright([C
++ Skeleton parser
for LALR(1) parsing with Bison
],
324 [2002, 2003, 2004, 2005])
325 m4_if(b4_prefix
[], [yy
], [],
327 // Take the name prefix into account.
328 #define yylex b4_prefix[]lex])
329 m4_if(b4_defines_flag
, 0, [],
331 #include @output_header_name@])[
336 # include <libintl.h> /* FIXME: INFRINGES ON USER NAME SPACE */
337 # define YY_(msgid) dgettext ("bison-runtime", msgid)
341 # define YY_(msgid) msgid
345 /* A pseudo ostream that takes yydebug_ into account. */
347 for (bool yydebugcond_ = yydebug_; yydebugcond_; yydebugcond_ = false) \
350 /* Enable debugging if requested. */
353 # define YY_SYMBOL_PRINT(Title, Type, Value, Location) \
357 *yycdebug_ << (Title) << ' '; \
358 yysymprint_ ((Type), (Value), (Location)); \
359 *yycdebug_ << std::endl; \
363 # define YY_REDUCE_PRINT(Rule) \
366 yyreduce_print_ (Rule); \
369 # define YY_STACK_PRINT() \
377 # define YY_SYMBOL_PRINT(Title, Type, Value, Location)
378 # define YY_REDUCE_PRINT(Rule)
379 # define YY_STACK_PRINT()
381 #endif /* !YYDEBUG */
383 #define YYACCEPT goto yyacceptlab
384 #define YYABORT goto yyabortlab
385 #define YYERROR goto yyerrorlab
389 /* Return YYSTR after stripping away unnecessary quotes and
390 backslashes, so that it's suitable for yyerror. The heuristic is
391 that double-quoting is unnecessary unless the string contains an
392 apostrophe, a comma, or backslash (other than backslash-backslash).
393 YYSTR is taken from yytname. */
395 yy::]b4_parser_class_name
[::yytnamerr_ (const char *yystr
)
399 std::string yyr
= "";
400 char const *yyp
= yystr
;
407 goto do_not_strip_quotes
;
411 goto do_not_strip_quotes
;
420 do_not_strip_quotes
: ;
429 /*--------------------------------.
430 | Print this symbol on YYOUTPUT. |
431 `--------------------------------*/
434 yy::]b4_parser_class_name
[::yysymprint_ (int yytype
,
435 const semantic_type
* yyvaluep
, const location_type
* yylocationp
)
437 /* Pacify ``unused variable'' warnings. */
440 /* Backward compatibility, but should be removed eventually. */
441 std::ostream
& cdebug_
= *yycdebug_
;
444 *yycdebug_
<< (yytype
< yyntokens_
? "token" : "nterm")
445 << ' ' << yytname_
[yytype
] << " ("
446 << *yylocationp
<< ": ";
449 ]m4_map([b4_symbol_actions
], m4_defn([b4_symbol_printers
]))dnl
455 #endif /* ! YYDEBUG */
458 yy::]b4_parser_class_name
[::yydestruct_ (const char* yymsg
,
459 int yytype
, semantic_type
* yyvaluep
, location_type
* yylocationp
)
461 /* Pacify ``unused variable'' warnings. */
466 YY_SYMBOL_PRINT (yymsg
, yytype
, yyvaluep
, yylocationp
);
470 ]m4_map([b4_symbol_actions
], m4_defn([b4_symbol_destructors
]))[
477 yy::]b4_parser_class_name
[::yypop_ (unsigned int n
)
479 yystate_stack_
.pop (n
);
480 yysemantic_stack_
.pop (n
);
481 yylocation_stack_
.pop (n
);
485 yy::]b4_parser_class_name
[::debug_stream () const
491 yy::]b4_parser_class_name
[::set_debug_stream (std::ostream
& o
)
497 yy::]b4_parser_class_name
[::debug_level_type
498 yy::]b4_parser_class_name
[::debug_level () const
504 yy::]b4_parser_class_name
[::set_debug_level (debug_level_type l
)
511 yy::]b4_parser_class_name
[::parse ()
513 /* Look-ahead and look-ahead in internal form. */
517 /// Semantic value of the look-ahead.
518 semantic_type yylval
;
519 /// Location of the look-ahead.
520 location_type yylloc
;
521 /// The locations where the error started and ended.
522 location yyerror_range
[2];
531 YYCDEBUG
<< "Starting parse" << std::endl
;
540 ]m4_ifdef([b4_initial_action
], [
541 m4_pushdef([b4_at_dollar
], [yylloc
])dnl
542 m4_pushdef([b4_dollar_dollar
], [yylval
])dnl
543 /* User initialization code. */
545 m4_popdef([b4_dollar_dollar
])dnl
546 m4_popdef([b4_at_dollar
])dnl
547 /* Line __line__ of yacc.c. */
548 b4_syncline([@oline@
], [@ofile@
])])dnl
550 [ /* Initialize the stacks. The initial state will be pushed in
551 yynewstate, since the latter expects the semantical and the
552 location values to have been already stored, initialize these
553 stacks with a primary value. */
554 yystate_stack_
= state_stack_type (0);
555 yysemantic_stack_
= semantic_stack_type (0);
556 yylocation_stack_
= location_stack_type (0);
557 yysemantic_stack_
.push (yylval
);
558 yylocation_stack_
.push (yylloc
);
562 yystate_stack_
.push (yystate_
);
563 YYCDEBUG
<< "Entering state " << yystate_
<< std::endl
;
569 /* Try to take a decision without look-ahead. */
570 yyn_
= yypact_
[yystate_
];
571 if (yyn_
== yypact_ninf_
)
574 /* Read a look-ahead token. */
575 if (yylooka
== yyempty_
)
577 YYCDEBUG
<< "Reading a token: ";
578 yylooka
= ]b4_c_function_call([yylex
], [int],
579 [[YYSTYPE
*], [&yylval
]][]dnl
580 b4_location_if([, [[location
*], [&yylloc
]]])dnl
581 m4_ifdef([b4_lex_param
], [, ]b4_lex_param
))[;
585 /* Convert token to internal form. */
586 if (yylooka
<= yyeof_
)
588 yylooka
= yyilooka
= yyeof_
;
589 YYCDEBUG
<< "Now at end of input." << std::endl
;
593 yyilooka
= yytranslate_ (yylooka
);
594 YY_SYMBOL_PRINT ("Next token is", yyilooka
, &yylval
, &yylloc
);
597 /* If the proper action on seeing token ILOOKA_ is to reduce or to
598 detect an error, take that action. */
600 if (yyn_
< 0 || yylast_
< yyn_
|| yycheck_
[yyn_
] != yyilooka
)
603 /* Reduce or error. */
604 yyn_
= yytable_
[yyn_
];
607 if (yyn_
== yytable_ninf_
)
619 if (yyn_
== yyfinal_
)
622 /* Shift the look-ahead token. */
623 YY_SYMBOL_PRINT ("Shifting", yyilooka
, &yylval
, &yylloc
);
625 /* Discard the token being shifted unless it is eof. */
626 if (yylooka
!= yyeof_
)
629 yysemantic_stack_
.push (yylval
);
630 yylocation_stack_
.push (yylloc
);
632 /* Count tokens shifted since error; after three, turn off error
640 /*-----------------------------------------------------------.
641 | yydefault -- do the default action for the current state. |
642 `-----------------------------------------------------------*/
644 yyn_
= yydefact_
[yystate_
];
649 /*-----------------------------.
650 | yyreduce -- Do a reduction. |
651 `-----------------------------*/
653 yylen_
= yyr2_
[yyn_
];
654 /* If LEN_ is nonzero, implement the default value of the action:
655 `$$ = $1'. Otherwise, use the top of the stack.
657 Otherwise, the following line sets YYVAL to garbage.
658 This behavior is undocumented and Bison
659 users should not rely upon it. */
661 yyval
= yysemantic_stack_
[yylen_
- 1];
663 yyval
= yysemantic_stack_
[0];
666 slice
<location_type
, location_stack_type
> slice (yylocation_stack_
, yylen_
);
667 YYLLOC_DEFAULT (yyloc
, slice
, yylen_
);
669 YY_REDUCE_PRINT (yyn_
);
676 ]/* Line __line__ of lalr1.cc. */
677 b4_syncline([@oline@
], [@ofile@
])[
683 yysemantic_stack_
.push (yyval
);
684 yylocation_stack_
.push (yyloc
);
686 /* Shift the result of the reduction. */
688 yystate_
= yypgoto_
[yyn_
- yyntokens_
] + yystate_stack_
[0];
689 if (0 <= yystate_
&& yystate_
<= yylast_
690 && yycheck_
[yystate_
] == yystate_stack_
[0])
691 yystate_
= yytable_
[yystate_
];
693 yystate_
= yydefgoto_
[yyn_
- yyntokens_
];
696 /*------------------------------------.
697 | yyerrlab -- here on detecting error |
698 `------------------------------------*/
700 /* If not already recovering from an error, report this error. */
704 error (yylloc
, yysyntax_error_ (YYERROR_VERBOSE_IF (yyilooka
)));
707 yyerror_range
[0] = yylloc
;
708 if (yyerrstatus_
== 3)
710 /* If just tried and failed to reuse look-ahead token after an
711 error, discard it. */
713 if (yylooka
<= yyeof_
)
715 /* Return failure if at end of input. */
716 if (yylooka
== yyeof_
)
721 yydestruct_ ("Error: discarding", yyilooka
, &yylval
, &yylloc
);
726 /* Else will try to reuse look-ahead token after shifting the error
731 /*---------------------------------------------------.
732 | yyerrorlab -- error raised explicitly by YYERROR. |
733 `---------------------------------------------------*/
736 /* Pacify compilers like GCC when the user code never invokes
737 YYERROR and the label yyerrorlab therefore never appears in user
742 yyerror_range
[0] = yylocation_stack_
[yylen_
- 1];
744 yystate_
= yystate_stack_
[0];
747 /*-------------------------------------------------------------.
748 | yyerrlab1 -- common code for both syntax error and YYERROR. |
749 `-------------------------------------------------------------*/
751 yyerrstatus_
= 3; /* Each real token shifted decrements this. */
755 yyn_
= yypact_
[yystate_
];
756 if (yyn_
!= yypact_ninf_
)
759 if (0 <= yyn_
&& yyn_
<= yylast_
&& yycheck_
[yyn_
] == yyterror_
)
761 yyn_
= yytable_
[yyn_
];
767 /* Pop the current state because it cannot handle the error token. */
768 if (yystate_stack_
.height () == 1)
771 yyerror_range
[0] = yylocation_stack_
[0];
772 yydestruct_ ("Error: popping",
774 &yysemantic_stack_
[0], &yylocation_stack_
[0]);
776 yystate_
= yystate_stack_
[0];
780 if (yyn_
== yyfinal_
)
783 yyerror_range
[1] = yylloc
;
784 // Using YYLLOC is tempting, but would change the location of
785 // the look-ahead. YYLOC is available though.
786 YYLLOC_DEFAULT (yyloc
, yyerror_range
- 1, 2);
787 yysemantic_stack_
.push (yylval
);
788 yylocation_stack_
.push (yyloc
);
790 /* Shift the error token. */
791 YY_SYMBOL_PRINT ("Shifting", yystos_
[yyn_
],
792 &yysemantic_stack_
[0], &yylocation_stack_
[0]);
808 if (yylooka
!= yyeof_
&& yylooka
!= yyempty_
)
809 yydestruct_ ("Cleanup: discarding lookahead", yyilooka
, &yylval
, &yylloc
);
811 while (yystate_stack_
.height () != 1)
813 yydestruct_ ("Cleanup: popping",
814 yystos_
[yystate_stack_
[0]],
815 &yysemantic_stack_
[0],
816 &yylocation_stack_
[0]);
823 // Generate an error message.
825 yy::]b4_parser_class_name
[::yysyntax_error_ (YYERROR_VERBOSE_IF (int tok
))
829 yyn_
= yypact_
[yystate_
];
830 if (yypact_ninf_
< yyn_
&& yyn_
< yylast_
)
832 /* Start YYX at -YYN if negative to avoid negative indexes in
834 int yyxbegin
= yyn_
< 0 ? -yyn_
: 0;
836 /* Stay within bounds of both yycheck and yytname. */
837 int yychecklim
= yylast_
- yyn_
;
838 int yyxend
= yychecklim
< yyntokens_
? yychecklim
: yyntokens_
;
840 for (int x
= yyxbegin
; x
< yyxend
; ++x
)
841 if (yycheck_
[x
+ yyn_
] == x
&& x
!= yyterror_
)
844 // FIXME: This method of building the message is not compatible
845 // with internationalization. It should work like yacc.c does it.
846 // That is, first build a string that looks like this:
847 // "syntax error, unexpected %s or %s or %s"
848 // Then, invoke YY_ on this string.
849 // Finally, use the string as a format to output
850 // yytname_[tok], etc.
851 // Until this gets fixed, this message appears in English only.
852 res
= "syntax error, unexpected ";
853 res
+= yytnamerr_ (yytname_
[tok
]);
857 for (int x
= yyxbegin
; x
< yyxend
; ++x
)
858 if (yycheck_
[x
+ yyn_
] == x
&& x
!= yyterror_
)
860 res
+= (!count
++) ? ", expecting " : " or ";
861 res
+= yytnamerr_ (yytname_
[x
]);
867 res
= YY_("syntax error");
872 /* YYPACT[STATE-NUM] -- Index in YYTABLE of the portion describing
874 const ]b4_int_type(b4_pact_ninf
, b4_pact_ninf
) yy::b4_parser_class_name::yypact_ninf_
= b4_pact_ninf
[;
875 const ]b4_int_type_for([b4_pact
])[
876 yy::]b4_parser_class_name
[::yypact_
[] =
881 /* YYDEFACT[S] -- default rule to reduce with in state S when YYTABLE
882 doesn't specify something else to do. Zero means the default is an
884 const ]b4_int_type_for([b4_defact
])[
885 yy::]b4_parser_class_name
[::yydefact_
[] =
890 /* YYPGOTO[NTERM-NUM]. */
891 const ]b4_int_type_for([b4_pgoto
])[
892 yy::]b4_parser_class_name
[::yypgoto_
[] =
897 /* YYDEFGOTO[NTERM-NUM]. */
898 const ]b4_int_type_for([b4_defgoto
])[
899 yy::]b4_parser_class_name
[::yydefgoto_
[] =
904 /* YYTABLE[YYPACT[STATE-NUM]]. What to do in state STATE-NUM. If
905 positive, shift that token. If negative, reduce the rule which
906 number is the opposite. If zero, do what YYDEFACT says. */
907 const ]b4_int_type(b4_table_ninf
, b4_table_ninf
) yy::b4_parser_class_name::yytable_ninf_
= b4_table_ninf
[;
908 const ]b4_int_type_for([b4_table
])[
909 yy::]b4_parser_class_name
[::yytable_
[] =
915 const ]b4_int_type_for([b4_check
])[
916 yy::]b4_parser_class_name
[::yycheck_
[] =
921 /* STOS_[STATE-NUM] -- The (internal number of the) accessing
922 symbol of state STATE-NUM. */
923 const ]b4_int_type_for([b4_stos
])[
924 yy::]b4_parser_class_name
[::yystos_
[] =
930 /* TOKEN_NUMBER_[YYLEX-NUM] -- Internal symbol number corresponding
932 const ]b4_int_type_for([b4_toknum
])[
933 yy::]b4_parser_class_name
[::yytoken_number_
[] =
939 /* YYR1[YYN] -- Symbol number of symbol that rule YYN derives. */
940 const ]b4_int_type_for([b4_r1
])[
941 yy::]b4_parser_class_name
[::yyr1_
[] =
946 /* YYR2[YYN] -- Number of symbols composing right hand side of rule YYN. */
947 const ]b4_int_type_for([b4_r2
])[
948 yy::]b4_parser_class_name
[::yyr2_
[] =
953 #if YYDEBUG || YYERROR_VERBOSE || YYTOKEN_TABLE
954 /* YYTNAME[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM.
955 First, the terminals, then, starting at \a yyntokens_, nonterminals. */
957 const yy::]b4_parser_class_name
[::yytname_
[] =
964 /* YYRHS -- A `-1'-separated list of the rules' RHS. */
965 const yy::]b4_parser_class_name
[::rhs_number_type
966 yy::]b4_parser_class_name
[::yyrhs_
[] =
971 /* YYPRHS[YYN] -- Index of the first RHS symbol of rule number YYN in
973 const ]b4_int_type_for([b4_prhs
])[
974 yy::]b4_parser_class_name
[::yyprhs_
[] =
979 /* YYRLINE[YYN] -- Source line where rule number YYN was defined. */
980 const ]b4_int_type_for([b4_rline
])[
981 yy::]b4_parser_class_name
[::yyrline_
[] =
986 // Print the state stack on the debug stream.
988 yy::]b4_parser_class_name
[::yystack_print_ ()
990 *yycdebug_
<< "Stack now";
991 for (state_stack_type::const_iterator i
= yystate_stack_
.begin ();
992 i
!= yystate_stack_
.end (); ++i
)
993 *yycdebug_
<< ' ' << *i
;
994 *yycdebug_
<< std::endl
;
997 // Report on the debug stream that the rule \a yyrule is going to be reduced.
999 yy::]b4_parser_class_name
[::yyreduce_print_ (int yyrule
)
1001 unsigned int yylno
= yyrline_
[yyrule
];
1002 /* Print the symbols being reduced, and their result. */
1003 *yycdebug_
<< "Reducing stack by rule " << yyn_
- 1
1004 << " (line " << yylno
<< "), ";
1005 for (]b4_int_type_for([b4_prhs
])[ i
= yyprhs_
[yyn_
];
1006 0 <= yyrhs_
[i
]; ++i
)
1007 *yycdebug_
<< yytname_
[yyrhs_
[i
]] << ' ';
1008 *yycdebug_
<< "-> " << yytname_
[yyr1_
[yyn_
]] << std::endl
;
1012 /* YYTRANSLATE(YYLEX) -- Bison symbol number corresponding to YYLEX. */
1013 yy::]b4_parser_class_name
[::token_number_type
1014 yy::]b4_parser_class_name
[::yytranslate_ (int token
)
1017 const token_number_type
1022 if ((unsigned int) token
<= yyuser_token_number_max_
)
1023 return translate_table
[token
];
1025 return yyundef_token_
;
1028 const int yy::]b4_parser_class_name
[::yyeof_
= 0;
1029 const int yy::]b4_parser_class_name
[::yylast_
= ]b4_last
[;
1030 const int yy::]b4_parser_class_name
[::yynnts_
= ]b4_nterms_number
[;
1031 const int yy::]b4_parser_class_name
[::yyempty_
= -2;
1032 const int yy::]b4_parser_class_name
[::yyfinal_
= ]b4_final_state_number
[;
1033 const int yy::]b4_parser_class_name
[::yyterror_
= 1;
1034 const int yy::]b4_parser_class_name
[::yyerrcode_
= 256;
1035 const int yy::]b4_parser_class_name
[::yyntokens_
= ]b4_tokens_number
[;
1037 const unsigned int yy::]b4_parser_class_name
[::yyuser_token_number_max_
= ]b4_user_token_number_max
[;
1038 const yy::]b4_parser_class_name
[::token_number_type
yy::]b4_parser_class_name
[::yyundef_token_
= ]b4_undef_token_number
[;
1043 b4_copyright([stack handling
for Bison C
++ parsers
], [2002, 2003, 2004, 2005])[
1045 #ifndef BISON_STACK_HH
1046 # define BISON_STACK_HH
1052 template <class T
, class S
= std::deque
<T
> >
1057 // Hide our reversed order.
1058 typedef typename
S::reverse_iterator iterator
;
1059 typedef typename
S::const_reverse_iterator const_iterator
;
1065 stack (unsigned int n
) : seq_ (n
)
1071 operator [] (unsigned int i
)
1078 operator [] (unsigned int i
) const
1087 seq_
.push_front (t
);
1092 pop (unsigned int n
= 1)
1102 return seq_
.size ();
1105 inline const_iterator
begin () const { return seq_
.rbegin (); }
1106 inline const_iterator
end () const { return seq_
.rend (); }
1113 /// Present a slice of the top of a stack.
1114 template <class T
, class S
= stack
<T
> >
1119 slice (const S
& stack
,
1120 unsigned int range
) : stack_ (stack
),
1127 operator [] (unsigned int i
) const
1129 return stack_
[range_
- i
];
1135 unsigned int range_
;
1139 #endif // not BISON_STACK_HH]
1142 b4_copyright([Position
class for Bison C
++ parsers
], [2002, 2003, 2004, 2005])[
1145 ** \file position.hh
1146 ** Define the position class.
1149 #ifndef BISON_POSITION_HH
1150 # define BISON_POSITION_HH
1152 # include <iostream>
1157 /// Abstract a position.
1161 /// Initial column number.
1162 static const unsigned int initial_column
= 0;
1163 /// Initial line number.
1164 static const unsigned int initial_line
= 1;
1166 /** \name Ctor & dtor.
1169 /// Construct a position.
1172 line (initial_line
),
1173 column (initial_column
)
1179 /** \name Line and Column related manipulators
1182 /// (line related) Advance to the COUNT next lines.
1183 inline void lines (int count
= 1)
1185 column
= initial_column
;
1189 /// (column related) Advance to the COUNT next columns.
1190 inline void columns (int count
= 1)
1192 int leftmost
= initial_column
;
1193 int current
= column
;
1194 if (leftmost
<= current
+ count
)
1197 column
= initial_column
;
1202 /// File name to which this position refers.
1203 ]b4_filename_type
[* filename
;
1204 /// Current line number.
1206 /// Current column number.
1207 unsigned int column
;
1210 /// Add and assign a position.
1211 inline const position
&
1212 operator+= (position
& res
, const int width
)
1214 res
.columns (width
);
1218 /// Add two position objects.
1219 inline const position
1220 operator+ (const position
& begin
, const int width
)
1222 position res
= begin
;
1223 return res
+= width
;
1226 /// Add and assign a position.
1227 inline const position
&
1228 operator-= (position
& res
, const int width
)
1230 return res
+= -width
;
1233 /// Add two position objects.
1234 inline const position
1235 operator- (const position
& begin
, const int width
)
1237 return begin
+ -width
;
1240 /** \brief Intercept output stream redirection.
1241 ** \param ostr the destination output stream
1242 ** \param pos a reference to the position to redirect
1244 inline std::ostream
&
1245 operator<< (std::ostream
& ostr
, const position
& pos
)
1248 ostr
<< *pos
.filename
<< ':';
1249 return ostr
<< pos
.line
<< '.' << pos
.column
;
1253 #endif // not BISON_POSITION_HH]
1255 b4_copyright([Location
class for Bison C
++ parsers
], [2002, 2003, 2004, 2005])[
1258 ** \file location.hh
1259 ** Define the location class.
1262 #ifndef BISON_LOCATION_HH
1263 # define BISON_LOCATION_HH
1265 # include <iostream>
1267 # include "position.hh"
1272 /// Abstract a location.
1275 /** \name Ctor & dtor.
1278 /// Construct a location.
1287 /** \name Line and Column related manipulators
1290 /// Reset initial location to final location.
1296 /// Extend the current location to the COUNT next columns.
1297 inline void columns (unsigned int count
= 1)
1302 /// Extend the current location to the COUNT next lines.
1303 inline void lines (unsigned int count
= 1)
1311 /// Beginning of the located region.
1313 /// End of the located region.
1317 /// Join two location objects to create a location.
1318 inline const location
operator+ (const location
& begin
, const location
& end
)
1320 location res
= begin
;
1325 /// Add two location objects.
1326 inline const location
operator+ (const location
& begin
, unsigned int width
)
1328 location res
= begin
;
1329 res
.columns (width
);
1333 /// Add and assign a location.
1334 inline location
& operator+= (location
& res
, unsigned int width
)
1336 res
.columns (width
);
1340 /** \brief Intercept output stream redirection.
1341 ** \param ostr the destination output stream
1342 ** \param loc a reference to the location to redirect
1344 ** Avoid duplicate information.
1346 inline std::ostream
& operator<< (std::ostream
& ostr
, const location
& loc
)
1348 position last
= loc
.end
- 1;
1351 && (!loc
.begin
.filename
1352 || *loc
.begin
.filename
!= *last
.filename
))
1353 ostr
<< '-' << last
;
1354 else if (loc
.begin
.line
!= last
.line
)
1355 ostr
<< '-' << last
.line
<< '.' << last
.column
;
1356 else if (loc
.begin
.column
!= last
.column
)
1357 ostr
<< '-' << last
.column
;
1363 #endif // not BISON_LOCATION_HH]