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 ## ---------------- ##
24 ## ---------------- ##
26 # Default parser class name.
27 m4_define_default([b4_parser_class_name
], [parser
])
31 ## ----------------- ##
32 ## Semantic Values. ##
33 ## ----------------- ##
36 # b4_lhs_value([TYPE])
37 # --------------------
38 # Expansion of $<TYPE>$.
39 m4_define([b4_lhs_value
],
40 [(yyval
[]m4_ifval([$
1], [.$
1]))])
43 # b4_rhs_value(RULE-LENGTH, NUM, [TYPE])
44 # --------------------------------------
45 # Expansion of $<TYPE>NUM, where the current rule has RULE-LENGTH
47 m4_define([b4_rhs_value
],
48 [(yysemantic_stack_@
{m4_eval([$
1 - $
2])@
}m4_ifval([$
3], [.$
3]))])
50 m4_define_default([b4_location_type
], [location
])
51 m4_define_default([b4_filename_type
], [std::string
])
56 m4_define([b4_lhs_location
],
60 # b4_rhs_location(RULE-LENGTH, NUM)
61 # ---------------------------------
62 # Expansion of @NUM, where the current rule has RULE-LENGTH symbols
64 m4_define([b4_rhs_location
],
65 [(yylocation_stack_@
{m4_eval([$
1 - $
2])@
})])
70 # Extra formal arguments of the constructor.
71 # Change the parameter names from "foo" into "foo_yyarg", so that
72 # there is no collision bw the user chosen attribute name, and the
73 # argument name in the constructor.
74 m4_define([b4_parse_param_decl
],
75 [m4_ifset([b4_parse_param
],
76 [m4_map_sep([b4_parse_param_decl_1
], [, ], [b4_parse_param
])])])
78 m4_define([b4_parse_param_decl_1
],
85 # Extra initialisations of the constructor.
86 m4_define([b4_parse_param_cons
],
87 [m4_ifset([b4_parse_param
],
89 b4_cc_constructor_calls(b4_parse_param
)])])
90 m4_define([b4_cc_constructor_calls
],
91 [m4_map_sep([b4_cc_constructor_call
], [,
93 m4_define([b4_cc_constructor_call
],
98 # Extra instance variables.
99 m4_define([b4_parse_param_vars
],
100 [m4_ifset([b4_parse_param
],
102 /* User arguments. */
103 b4_cc_var_decls(b4_parse_param
)])])
104 m4_define([b4_cc_var_decls
],
105 [m4_map_sep([b4_cc_var_decl
], [
107 m4_define([b4_cc_var_decl
],
112 # We do want M4 expansion after # for CPP macros.
115 m4_if(b4_defines_flag
, 0, [],
116 [@output @output_header_name@
117 b4_copyright([C
++ Skeleton parser
for LALR(1) parsing with Bison
],
118 [2002, 2003, 2004, 2005])[
119 /* FIXME: This is wrong, we want computed header guards.
120 I don't know why the macros are missing now. :( */
121 #ifndef PARSER_HEADER_H
122 # define PARSER_HEADER_H
127 /* Using locations. */
128 #define YYLSP_NEEDED ]b4_locations_flag[
136 ]b4_token_enums(b4_tokens
)[
138 /* Copy the first part of user declarations. */
141 ]/* Line __line__ of lalr1.cc. */
142 b4_syncline([@oline@
], [@ofile@
])[
145 #include "location.hh"
147 /* Enabling traces. */
149 # define YYDEBUG ]b4_debug[
152 /* Enabling verbose error messages. */
153 #ifdef YYERROR_VERBOSE
154 # undef YYERROR_VERBOSE
155 # define YYERROR_VERBOSE 1
157 # define YYERROR_VERBOSE ]b4_error_verbose[
160 /* Enabling the token table. */
161 #ifndef YYTOKEN_TABLE
162 # define YYTOKEN_TABLE ]b4_token_table[
165 #if ! defined (YYSTYPE) && ! defined (YYSTYPE_IS_DECLARED)
166 ]m4_ifdef([b4_stype
],
167 [b4_syncline([b4_stype_line
], [b4_file_name
])
168 union YYSTYPE b4_stype
;
169 /* Line __line__ of lalr1.cc. */
170 b4_syncline([@oline@
], [@ofile@
])],
171 [typedef int YYSTYPE
;])[
172 # define yystype YYSTYPE /* obsolescent; will be withdrawn */
173 # define YYSTYPE_IS_DECLARED 1
174 # define YYSTYPE_IS_TRIVIAL 1
177 /* Copy the second part of user declarations. */
180 ]/* Line __line__ of lalr1.cc. */
181 b4_syncline([@oline@
], [@ofile@
])[
182 /* YYLLOC_DEFAULT -- Set CURRENT to span from RHS[1] to RHS[N].
183 If N is 0, then set CURRENT to the empty location which ends
184 the previous symbol: RHS[0] (always defined). */
186 #ifndef YYLLOC_DEFAULT
187 # define YYLLOC_DEFAULT(Current, Rhs, N) \
191 (Current).begin = (Rhs)[1].begin; \
192 (Current).end = (Rhs)[N].end; \
196 (Current).begin = (Current).end = (Rhs)[0].end; \
203 class ]b4_parser_class_name
[;
205 template <typename P
>
211 struct traits
<]b4_parser_class_name
[>
213 typedef ]b4_int_type_for([b4_translate
])[ token_number_type
;
214 typedef ]b4_int_type_for([b4_rhs
])[ rhs_number_type
;
215 typedef int state_type
;
216 typedef YYSTYPE semantic_type
;
217 typedef ]b4_location_type
[ location_type
;
224 class ]b4_parser_class_name
[
226 /// Symbol semantic values.
227 typedef traits
<]b4_parser_class_name
[>::semantic_type semantic_type
;
228 /// Symbol locations.
229 typedef traits
<]b4_parser_class_name
[>::location_type location_type
;
232 /// Build a parser object.
233 ]b4_parser_class_name
[ (]b4_parse_param_decl
[) :
235 yycdebug_ (&std::cerr
)]b4_parse_param_cons
[
239 virtual ~]b4_parser_class_name
[ ()
244 /// \returns 0 iff parsing succeeded.
245 virtual int parse ();
247 /// The current debugging stream.
248 std::ostream
& debug_stream () const;
249 /// Set the current debugging stream.
250 void set_debug_stream (std::ostream
&);
252 /// Type for debugging levels.
253 typedef int debug_level_type
;
254 /// The current debugging level.
255 debug_level_type
debug_level () const;
256 /// Set the current debugging level.
257 void set_debug_level (debug_level_type l
);
260 /// Report a syntax error.
261 /// \param loc where the syntax error is found.
262 /// \param msg a description of the syntax error.
263 virtual void error (const location_type
& loc
, const std::string
& msg
);
265 /// Generate an error message.
266 /// \param tok the look-ahead token.
267 virtual std::string
yysyntax_error_ (int tok
);
270 /// \brief Report a symbol on the debug stream.
271 /// \param yytype The token type.
272 /// \param yyvaluep Its semantic value.
273 /// \param yylocationp Its location.
274 virtual void yysymprint_ (int yytype
,
275 const semantic_type
* yyvaluep
,
276 const location_type
* yylocationp
);
277 #endif /* ! YYDEBUG */
281 typedef traits
<]b4_parser_class_name
[>::state_type state_type
;
282 /// State stack type.
283 typedef stack
<state_type
> state_stack_type
;
284 /// Semantic value stack type.
285 typedef stack
<semantic_type
> semantic_stack_type
;
286 /// location stack type.
287 typedef stack
<location_type
> location_stack_type
;
290 state_stack_type yystate_stack_
;
291 /// The semantic value stack.
292 semantic_stack_type yysemantic_stack_
;
293 /// The location stack.
294 location_stack_type yylocation_stack_
;
296 /// Internal symbol numbers.
297 typedef traits
<]b4_parser_class_name
[>::token_number_type token_number_type
;
299 /// For a state, the index in \a yytable_ of its portion.
300 static const ]b4_int_type_for([b4_pact
])[ yypact_
[];
301 static const ]b4_int_type(b4_pact_ninf
, b4_pact_ninf
)[ yypact_ninf_
;
303 /// For a state, default rule to reduce.
304 /// Unless\a yytable_ specifies something else to do.
305 /// Zero means the default is an error.
306 static const ]b4_int_type_for([b4_defact
])[ yydefact_
[];
308 static const ]b4_int_type_for([b4_pgoto
])[ yypgoto_
[];
309 static const ]b4_int_type_for([b4_defgoto
])[ yydefgoto_
[];
311 /// What to do in a state.
312 /// \a yytable_[yypact_[s]]: what to do in state \a s.
313 /// - if positive, shift that token.
314 /// - if negative, reduce the rule which number is the opposite.
315 /// - if zero, do what YYDEFACT says.
316 static const ]b4_int_type_for([b4_table
])[ yytable_
[];
317 static const ]b4_int_type(b4_table_ninf
, b4_table_ninf
)[ yytable_ninf_
;
319 static const ]b4_int_type_for([b4_check
])[ yycheck_
[];
321 /// For a state, its accessing symbol.
322 static const ]b4_int_type_for([b4_stos
])[ yystos_
[];
324 /// For a rule, its LHS.
325 static const ]b4_int_type_for([b4_r1
])[ yyr1_
[];
326 /// For a rule, its RHS length.
327 static const ]b4_int_type_for([b4_r2
])[ yyr2_
[];
329 #if YYDEBUG || YYERROR_VERBOSE || YYTOKEN_TABLE
330 /// For a symbol, its name in clear.
331 static const char* const yytname_
[];
335 /// Convert the symbol name \a n to a form suitable for a diagnostic.
336 virtual std::string
yytnamerr_ (const char *n
);
340 /// A type to store symbol numbers and -1.
341 typedef traits
<]b4_parser_class_name
[>::rhs_number_type rhs_number_type
;
342 /// A `-1'-separated list of the rules' RHS.
343 static const rhs_number_type yyrhs_
[];
344 /// For each rule, the index of the first RHS symbol in \a yyrhs_.
345 static const ]b4_int_type_for([b4_prhs
])[ yyprhs_
[];
346 /// For each rule, its source line number.
347 static const ]b4_int_type_for([b4_rline
])[ yyrline_
[];
348 /// For each scanner token number, its symbol number.
349 static const ]b4_int_type_for([b4_toknum
])[ yytoken_number_
[];
350 /// Report on the debug stream that the rule \a r is going to be reduced.
351 virtual void yyreduce_print_ (int r
);
352 /// Print the state stack on the debug stream.
353 virtual void yystack_print_ ();
356 /// Convert a scanner token number to a symbol number.
357 inline token_number_type
yytranslate_ (int token
);
359 /// \brief Reclaim the memory associated to a symbol.
360 /// \param yymsg Why this token is reclaimed.
361 /// \param yytype The symbol type.
362 /// \param yyvaluep Its semantic value.
363 /// \param yylocationp Its location.
364 inline void yydestruct_ (const char* yymsg
,
366 semantic_type
* yyvaluep
,
367 location_type
* yylocationp
);
369 /// Pop \a n symbols the three stacks.
370 inline void yypop_ (unsigned int n
= 1);
373 static const int yyeof_
;
374 /* LAST_ -- Last index in TABLE_. */
375 static const int yylast_
;
376 static const int yynnts_
;
377 static const int yyempty_
;
378 static const int yyfinal_
;
379 static const int yyterror_
;
380 static const int yyerrcode_
;
381 static const int yyntokens_
;
382 static const unsigned int yyuser_token_number_max_
;
383 static const token_number_type yyundef_token_
;
390 /* Error handling. */
396 std::ostream
* yycdebug_
;
398 ]b4_parse_param_vars
[
402 #endif /* ! defined PARSER_HEADER_H */]
404 @output @output_parser_name@
405 b4_copyright([C
++ Skeleton parser
for LALR(1) parsing with Bison
],
406 [2002, 2003, 2004, 2005])
407 m4_if(b4_prefix
[], [yy
], [],
409 // Take the name prefix into account.
410 #define yylex b4_prefix[]lex])
411 m4_if(b4_defines_flag
, 0, [],
413 #include @output_header_name@])[
418 # include <libintl.h> /* FIXME: INFRINGES ON USER NAME SPACE */
419 # define YY_(msgid) dgettext ("bison-runtime", msgid)
423 # define YY_(msgid) msgid
427 /* A pseudo ostream that takes yydebug_ into account. */
429 for (bool yydebugcond_ = yydebug_; yydebugcond_; yydebugcond_ = false) \
432 /* Enable debugging if requested. */
435 # define YY_SYMBOL_PRINT(Title, Type, Value, Location) \
439 *yycdebug_ << (Title) << ' '; \
440 yysymprint_ ((Type), (Value), (Location)); \
441 *yycdebug_ << std::endl; \
445 # define YY_REDUCE_PRINT(Rule) \
448 yyreduce_print_ (Rule); \
451 # define YY_STACK_PRINT() \
459 # define YY_SYMBOL_PRINT(Title, Type, Value, Location)
460 # define YY_REDUCE_PRINT(Rule)
461 # define YY_STACK_PRINT()
463 #endif /* !YYDEBUG */
465 #define YYACCEPT goto yyacceptlab
466 #define YYABORT goto yyabortlab
467 #define YYERROR goto yyerrorlab
471 /* Return YYSTR after stripping away unnecessary quotes and
472 backslashes, so that it's suitable for yyerror. The heuristic is
473 that double-quoting is unnecessary unless the string contains an
474 apostrophe, a comma, or backslash (other than backslash-backslash).
475 YYSTR is taken from yytname. */
477 yy::]b4_parser_class_name
[::yytnamerr_ (const char *yystr
)
481 std::string yyr
= "";
482 char const *yyp
= yystr
;
489 goto do_not_strip_quotes
;
493 goto do_not_strip_quotes
;
502 do_not_strip_quotes
: ;
511 /*--------------------------------.
512 | Print this symbol on YYOUTPUT. |
513 `--------------------------------*/
516 yy::]b4_parser_class_name
[::yysymprint_ (int yytype
,
517 const semantic_type
* yyvaluep
, const location_type
* yylocationp
)
519 /* Pacify ``unused variable'' warnings. */
522 /* Backward compatibility, but should be removed eventually. */
523 std::ostream
& cdebug_
= *yycdebug_
;
526 *yycdebug_
<< (yytype
< yyntokens_
? "token" : "nterm")
527 << ' ' << yytname_
[yytype
] << " ("
528 << *yylocationp
<< ": ";
531 ]m4_map([b4_symbol_actions
], m4_defn([b4_symbol_printers
]))dnl
537 #endif /* ! YYDEBUG */
540 yy::]b4_parser_class_name
[::yydestruct_ (const char* yymsg
,
541 int yytype
, semantic_type
* yyvaluep
, location_type
* yylocationp
)
543 /* Pacify ``unused variable'' warnings. */
548 YY_SYMBOL_PRINT (yymsg
, yytype
, yyvaluep
, yylocationp
);
552 ]m4_map([b4_symbol_actions
], m4_defn([b4_symbol_destructors
]))[
559 yy::]b4_parser_class_name
[::yypop_ (unsigned int n
)
561 yystate_stack_
.pop (n
);
562 yysemantic_stack_
.pop (n
);
563 yylocation_stack_
.pop (n
);
567 yy::]b4_parser_class_name
[::debug_stream () const
573 yy::]b4_parser_class_name
[::set_debug_stream (std::ostream
& o
)
579 yy::]b4_parser_class_name
[::debug_level_type
580 yy::]b4_parser_class_name
[::debug_level () const
586 yy::]b4_parser_class_name
[::set_debug_level (debug_level_type l
)
593 yy::]b4_parser_class_name
[::parse ()
595 /* Look-ahead and look-ahead in internal form. */
599 /// Semantic value of the look-ahead.
600 semantic_type yylval
;
601 /// Location of the look-ahead.
602 location_type yylloc
;
603 /// The locations where the error started and ended.
604 location yyerror_range
[2];
613 YYCDEBUG
<< "Starting parse" << std::endl
;
622 ]m4_ifdef([b4_initial_action
], [
623 m4_pushdef([b4_at_dollar
], [yylloc
])dnl
624 m4_pushdef([b4_dollar_dollar
], [yylval
])dnl
625 /* User initialization code. */
627 m4_popdef([b4_dollar_dollar
])dnl
628 m4_popdef([b4_at_dollar
])dnl
629 /* Line __line__ of yacc.c. */
630 b4_syncline([@oline@
], [@ofile@
])])dnl
632 [ /* Initialize the stacks. The initial state will be pushed in
633 yynewstate, since the latter expects the semantical and the
634 location values to have been already stored, initialize these
635 stacks with a primary value. */
636 yystate_stack_
= state_stack_type (0);
637 yysemantic_stack_
= semantic_stack_type (0);
638 yylocation_stack_
= location_stack_type (0);
639 yysemantic_stack_
.push (yylval
);
640 yylocation_stack_
.push (yylloc
);
644 yystate_stack_
.push (yystate_
);
645 YYCDEBUG
<< "Entering state " << yystate_
<< std::endl
;
651 /* Try to take a decision without look-ahead. */
652 yyn_
= yypact_
[yystate_
];
653 if (yyn_
== yypact_ninf_
)
656 /* Read a look-ahead token. */
657 if (yylooka
== yyempty_
)
659 YYCDEBUG
<< "Reading a token: ";
660 yylooka
= ]b4_c_function_call([yylex
], [int],
661 [[YYSTYPE
*], [&yylval
]][]dnl
662 b4_location_if([, [[location
*], [&yylloc
]]])dnl
663 m4_ifdef([b4_lex_param
], [, ]b4_lex_param
))[;
667 /* Convert token to internal form. */
668 if (yylooka
<= yyeof_
)
670 yylooka
= yyilooka
= yyeof_
;
671 YYCDEBUG
<< "Now at end of input." << std::endl
;
675 yyilooka
= yytranslate_ (yylooka
);
676 YY_SYMBOL_PRINT ("Next token is", yyilooka
, &yylval
, &yylloc
);
679 /* If the proper action on seeing token ILOOKA_ is to reduce or to
680 detect an error, take that action. */
682 if (yyn_
< 0 || yylast_
< yyn_
|| yycheck_
[yyn_
] != yyilooka
)
685 /* Reduce or error. */
686 yyn_
= yytable_
[yyn_
];
689 if (yyn_
== yytable_ninf_
)
701 if (yyn_
== yyfinal_
)
704 /* Shift the look-ahead token. */
705 YY_SYMBOL_PRINT ("Shifting", yyilooka
, &yylval
, &yylloc
);
707 /* Discard the token being shifted unless it is eof. */
708 if (yylooka
!= yyeof_
)
711 yysemantic_stack_
.push (yylval
);
712 yylocation_stack_
.push (yylloc
);
714 /* Count tokens shifted since error; after three, turn off error
722 /*-----------------------------------------------------------.
723 | yydefault -- do the default action for the current state. |
724 `-----------------------------------------------------------*/
726 yyn_
= yydefact_
[yystate_
];
731 /*-----------------------------.
732 | yyreduce -- Do a reduction. |
733 `-----------------------------*/
735 yylen_
= yyr2_
[yyn_
];
736 /* If LEN_ is nonzero, implement the default value of the action:
737 `$$ = $1'. Otherwise, use the top of the stack.
739 Otherwise, the following line sets YYVAL to garbage.
740 This behavior is undocumented and Bison
741 users should not rely upon it. */
743 yyval
= yysemantic_stack_
[yylen_
- 1];
745 yyval
= yysemantic_stack_
[0];
748 slice
<location_type
, location_stack_type
> slice (yylocation_stack_
, yylen_
);
749 YYLLOC_DEFAULT (yyloc
, slice
, yylen_
);
751 YY_REDUCE_PRINT (yyn_
);
758 ]/* Line __line__ of lalr1.cc. */
759 b4_syncline([@oline@
], [@ofile@
])[
765 yysemantic_stack_
.push (yyval
);
766 yylocation_stack_
.push (yyloc
);
768 /* Shift the result of the reduction. */
770 yystate_
= yypgoto_
[yyn_
- yyntokens_
] + yystate_stack_
[0];
771 if (0 <= yystate_
&& yystate_
<= yylast_
772 && yycheck_
[yystate_
] == yystate_stack_
[0])
773 yystate_
= yytable_
[yystate_
];
775 yystate_
= yydefgoto_
[yyn_
- yyntokens_
];
778 /*------------------------------------.
779 | yyerrlab -- here on detecting error |
780 `------------------------------------*/
782 /* If not already recovering from an error, report this error. */
786 error (yylloc
, yysyntax_error_ (yyilooka
));
789 yyerror_range
[0] = yylloc
;
790 if (yyerrstatus_
== 3)
792 /* If just tried and failed to reuse look-ahead token after an
793 error, discard it. */
795 if (yylooka
<= yyeof_
)
797 /* Return failure if at end of input. */
798 if (yylooka
== yyeof_
)
803 yydestruct_ ("Error: discarding", yyilooka
, &yylval
, &yylloc
);
808 /* Else will try to reuse look-ahead token after shifting the error
813 /*---------------------------------------------------.
814 | yyerrorlab -- error raised explicitly by YYERROR. |
815 `---------------------------------------------------*/
818 /* Pacify compilers like GCC when the user code never invokes
819 YYERROR and the label yyerrorlab therefore never appears in user
824 yyerror_range
[0] = yylocation_stack_
[yylen_
- 1];
826 yystate_
= yystate_stack_
[0];
829 /*-------------------------------------------------------------.
830 | yyerrlab1 -- common code for both syntax error and YYERROR. |
831 `-------------------------------------------------------------*/
833 yyerrstatus_
= 3; /* Each real token shifted decrements this. */
837 yyn_
= yypact_
[yystate_
];
838 if (yyn_
!= yypact_ninf_
)
841 if (0 <= yyn_
&& yyn_
<= yylast_
&& yycheck_
[yyn_
] == yyterror_
)
843 yyn_
= yytable_
[yyn_
];
849 /* Pop the current state because it cannot handle the error token. */
850 if (yystate_stack_
.height () == 1)
853 yyerror_range
[0] = yylocation_stack_
[0];
854 yydestruct_ ("Error: popping",
856 &yysemantic_stack_
[0], &yylocation_stack_
[0]);
858 yystate_
= yystate_stack_
[0];
862 if (yyn_
== yyfinal_
)
865 yyerror_range
[1] = yylloc
;
866 // Using YYLLOC is tempting, but would change the location of
867 // the look-ahead. YYLOC is available though.
868 YYLLOC_DEFAULT (yyloc
, yyerror_range
- 1, 2);
869 yysemantic_stack_
.push (yylval
);
870 yylocation_stack_
.push (yyloc
);
872 /* Shift the error token. */
873 YY_SYMBOL_PRINT ("Shifting", yystos_
[yyn_
],
874 &yysemantic_stack_
[0], &yylocation_stack_
[0]);
890 if (yylooka
!= yyeof_
&& yylooka
!= yyempty_
)
891 yydestruct_ ("Cleanup: discarding lookahead", yyilooka
, &yylval
, &yylloc
);
893 while (yystate_stack_
.height () != 1)
895 yydestruct_ ("Cleanup: popping",
896 yystos_
[yystate_stack_
[0]],
897 &yysemantic_stack_
[0],
898 &yylocation_stack_
[0]);
905 // Generate an error message.
907 yy::]b4_parser_class_name
[::yysyntax_error_ (int tok
)
911 yyn_
= yypact_
[yystate_
];
912 if (yypact_ninf_
< yyn_
&& yyn_
< yylast_
)
914 /* Start YYX at -YYN if negative to avoid negative indexes in
916 int yyxbegin
= yyn_
< 0 ? -yyn_
: 0;
918 /* Stay within bounds of both yycheck and yytname. */
919 int yychecklim
= yylast_
- yyn_
;
920 int yyxend
= yychecklim
< yyntokens_
? yychecklim
: yyntokens_
;
922 for (int x
= yyxbegin
; x
< yyxend
; ++x
)
923 if (yycheck_
[x
+ yyn_
] == x
&& x
!= yyterror_
)
926 // FIXME: This method of building the message is not compatible
927 // with internationalization. It should work like yacc.c does it.
928 // That is, first build a string that looks like this:
929 // "syntax error, unexpected %s or %s or %s"
930 // Then, invoke YY_ on this string.
931 // Finally, use the string as a format to output
932 // yytname_[tok], etc.
933 // Until this gets fixed, this message appears in English only.
934 res
= "syntax error, unexpected ";
935 res
+= yytnamerr_ (yytname_
[tok
]);
939 for (int x
= yyxbegin
; x
< yyxend
; ++x
)
940 if (yycheck_
[x
+ yyn_
] == x
&& x
!= yyterror_
)
942 res
+= (!count
++) ? ", expecting " : " or ";
943 res
+= yytnamerr_ (yytname_
[x
]);
949 res
= YY_("syntax error");
954 /* YYPACT[STATE-NUM] -- Index in YYTABLE of the portion describing
956 const ]b4_int_type(b4_pact_ninf
, b4_pact_ninf
) yy::b4_parser_class_name::yypact_ninf_
= b4_pact_ninf
[;
957 const ]b4_int_type_for([b4_pact
])[
958 yy::]b4_parser_class_name
[::yypact_
[] =
963 /* YYDEFACT[S] -- default rule to reduce with in state S when YYTABLE
964 doesn't specify something else to do. Zero means the default is an
966 const ]b4_int_type_for([b4_defact
])[
967 yy::]b4_parser_class_name
[::yydefact_
[] =
972 /* YYPGOTO[NTERM-NUM]. */
973 const ]b4_int_type_for([b4_pgoto
])[
974 yy::]b4_parser_class_name
[::yypgoto_
[] =
979 /* YYDEFGOTO[NTERM-NUM]. */
980 const ]b4_int_type_for([b4_defgoto
])[
981 yy::]b4_parser_class_name
[::yydefgoto_
[] =
986 /* YYTABLE[YYPACT[STATE-NUM]]. What to do in state STATE-NUM. If
987 positive, shift that token. If negative, reduce the rule which
988 number is the opposite. If zero, do what YYDEFACT says. */
989 const ]b4_int_type(b4_table_ninf
, b4_table_ninf
) yy::b4_parser_class_name::yytable_ninf_
= b4_table_ninf
[;
990 const ]b4_int_type_for([b4_table
])[
991 yy::]b4_parser_class_name
[::yytable_
[] =
997 const ]b4_int_type_for([b4_check
])[
998 yy::]b4_parser_class_name
[::yycheck_
[] =
1003 /* STOS_[STATE-NUM] -- The (internal number of the) accessing
1004 symbol of state STATE-NUM. */
1005 const ]b4_int_type_for([b4_stos
])[
1006 yy::]b4_parser_class_name
[::yystos_
[] =
1012 /* TOKEN_NUMBER_[YYLEX-NUM] -- Internal symbol number corresponding
1014 const ]b4_int_type_for([b4_toknum
])[
1015 yy::]b4_parser_class_name
[::yytoken_number_
[] =
1021 /* YYR1[YYN] -- Symbol number of symbol that rule YYN derives. */
1022 const ]b4_int_type_for([b4_r1
])[
1023 yy::]b4_parser_class_name
[::yyr1_
[] =
1028 /* YYR2[YYN] -- Number of symbols composing right hand side of rule YYN. */
1029 const ]b4_int_type_for([b4_r2
])[
1030 yy::]b4_parser_class_name
[::yyr2_
[] =
1035 #if YYDEBUG || YYERROR_VERBOSE || YYTOKEN_TABLE
1036 /* YYTNAME[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM.
1037 First, the terminals, then, starting at \a yyntokens_, nonterminals. */
1039 const yy::]b4_parser_class_name
[::yytname_
[] =
1046 /* YYRHS -- A `-1'-separated list of the rules' RHS. */
1047 const yy::]b4_parser_class_name
[::rhs_number_type
1048 yy::]b4_parser_class_name
[::yyrhs_
[] =
1053 /* YYPRHS[YYN] -- Index of the first RHS symbol of rule number YYN in
1055 const ]b4_int_type_for([b4_prhs
])[
1056 yy::]b4_parser_class_name
[::yyprhs_
[] =
1061 /* YYRLINE[YYN] -- Source line where rule number YYN was defined. */
1062 const ]b4_int_type_for([b4_rline
])[
1063 yy::]b4_parser_class_name
[::yyrline_
[] =
1068 // Print the state stack on the debug stream.
1070 yy::]b4_parser_class_name
[::yystack_print_ ()
1072 *yycdebug_
<< "Stack now";
1073 for (state_stack_type::const_iterator i
= yystate_stack_
.begin ();
1074 i
!= yystate_stack_
.end (); ++i
)
1075 *yycdebug_
<< ' ' << *i
;
1076 *yycdebug_
<< std::endl
;
1079 // Report on the debug stream that the rule \a yyrule is going to be reduced.
1081 yy::]b4_parser_class_name
[::yyreduce_print_ (int yyrule
)
1083 unsigned int yylno
= yyrline_
[yyrule
];
1084 /* Print the symbols being reduced, and their result. */
1085 *yycdebug_
<< "Reducing stack by rule " << yyn_
- 1
1086 << " (line " << yylno
<< "), ";
1087 for (]b4_int_type_for([b4_prhs
])[ i
= yyprhs_
[yyn_
];
1088 0 <= yyrhs_
[i
]; ++i
)
1089 *yycdebug_
<< yytname_
[yyrhs_
[i
]] << ' ';
1090 *yycdebug_
<< "-> " << yytname_
[yyr1_
[yyn_
]] << std::endl
;
1094 /* YYTRANSLATE(YYLEX) -- Bison symbol number corresponding to YYLEX. */
1095 yy::]b4_parser_class_name
[::token_number_type
1096 yy::]b4_parser_class_name
[::yytranslate_ (int token
)
1099 const token_number_type
1104 if ((unsigned int) token
<= yyuser_token_number_max_
)
1105 return translate_table
[token
];
1107 return yyundef_token_
;
1110 const int yy::]b4_parser_class_name
[::yyeof_
= 0;
1111 const int yy::]b4_parser_class_name
[::yylast_
= ]b4_last
[;
1112 const int yy::]b4_parser_class_name
[::yynnts_
= ]b4_nterms_number
[;
1113 const int yy::]b4_parser_class_name
[::yyempty_
= -2;
1114 const int yy::]b4_parser_class_name
[::yyfinal_
= ]b4_final_state_number
[;
1115 const int yy::]b4_parser_class_name
[::yyterror_
= 1;
1116 const int yy::]b4_parser_class_name
[::yyerrcode_
= 256;
1117 const int yy::]b4_parser_class_name
[::yyntokens_
= ]b4_tokens_number
[;
1119 const unsigned int yy::]b4_parser_class_name
[::yyuser_token_number_max_
= ]b4_user_token_number_max
[;
1120 const yy::]b4_parser_class_name
[::token_number_type
yy::]b4_parser_class_name
[::yyundef_token_
= ]b4_undef_token_number
[;
1125 b4_copyright([stack handling
for Bison C
++ parsers
], [2002, 2003, 2004, 2005])[
1127 #ifndef BISON_STACK_HH
1128 # define BISON_STACK_HH
1134 template <class T
, class S
= std::deque
<T
> >
1139 // Hide our reversed order.
1140 typedef typename
S::reverse_iterator iterator
;
1141 typedef typename
S::const_reverse_iterator const_iterator
;
1147 stack (unsigned int n
) : seq_ (n
)
1153 operator [] (unsigned int i
)
1160 operator [] (unsigned int i
) const
1169 seq_
.push_front (t
);
1174 pop (unsigned int n
= 1)
1184 return seq_
.size ();
1187 inline const_iterator
begin () const { return seq_
.rbegin (); }
1188 inline const_iterator
end () const { return seq_
.rend (); }
1195 /// Present a slice of the top of a stack.
1196 template <class T
, class S
= stack
<T
> >
1201 slice (const S
& stack
,
1202 unsigned int range
) : stack_ (stack
),
1209 operator [] (unsigned int i
) const
1211 return stack_
[range_
- i
];
1217 unsigned int range_
;
1221 #endif // not BISON_STACK_HH]
1224 b4_copyright([Position
class for Bison C
++ parsers
], [2002, 2003, 2004, 2005])[
1227 ** \file position.hh
1228 ** Define the position class.
1231 #ifndef BISON_POSITION_HH
1232 # define BISON_POSITION_HH
1234 # include <iostream>
1239 /// Abstract a position.
1243 /// Initial column number.
1244 static const unsigned int initial_column
= 0;
1245 /// Initial line number.
1246 static const unsigned int initial_line
= 1;
1248 /** \name Ctor & dtor.
1251 /// Construct a position.
1254 line (initial_line
),
1255 column (initial_column
)
1261 /** \name Line and Column related manipulators
1264 /// (line related) Advance to the COUNT next lines.
1265 inline void lines (int count
= 1)
1267 column
= initial_column
;
1271 /// (column related) Advance to the COUNT next columns.
1272 inline void columns (int count
= 1)
1274 int leftmost
= initial_column
;
1275 int current
= column
;
1276 if (leftmost
<= current
+ count
)
1279 column
= initial_column
;
1284 /// File name to which this position refers.
1285 ]b4_filename_type
[* filename
;
1286 /// Current line number.
1288 /// Current column number.
1289 unsigned int column
;
1292 /// Add and assign a position.
1293 inline const position
&
1294 operator+= (position
& res
, const int width
)
1296 res
.columns (width
);
1300 /// Add two position objects.
1301 inline const position
1302 operator+ (const position
& begin
, const int width
)
1304 position res
= begin
;
1305 return res
+= width
;
1308 /// Add and assign a position.
1309 inline const position
&
1310 operator-= (position
& res
, const int width
)
1312 return res
+= -width
;
1315 /// Add two position objects.
1316 inline const position
1317 operator- (const position
& begin
, const int width
)
1319 return begin
+ -width
;
1322 /** \brief Intercept output stream redirection.
1323 ** \param ostr the destination output stream
1324 ** \param pos a reference to the position to redirect
1326 inline std::ostream
&
1327 operator<< (std::ostream
& ostr
, const position
& pos
)
1330 ostr
<< *pos
.filename
<< ':';
1331 return ostr
<< pos
.line
<< '.' << pos
.column
;
1335 #endif // not BISON_POSITION_HH]
1337 b4_copyright([Location
class for Bison C
++ parsers
], [2002, 2003, 2004, 2005])[
1340 ** \file location.hh
1341 ** Define the location class.
1344 #ifndef BISON_LOCATION_HH
1345 # define BISON_LOCATION_HH
1347 # include <iostream>
1349 # include "position.hh"
1354 /// Abstract a location.
1357 /** \name Ctor & dtor.
1360 /// Construct a location.
1369 /** \name Line and Column related manipulators
1372 /// Reset initial location to final location.
1378 /// Extend the current location to the COUNT next columns.
1379 inline void columns (unsigned int count
= 1)
1384 /// Extend the current location to the COUNT next lines.
1385 inline void lines (unsigned int count
= 1)
1393 /// Beginning of the located region.
1395 /// End of the located region.
1399 /// Join two location objects to create a location.
1400 inline const location
operator+ (const location
& begin
, const location
& end
)
1402 location res
= begin
;
1407 /// Add two location objects.
1408 inline const location
operator+ (const location
& begin
, unsigned int width
)
1410 location res
= begin
;
1411 res
.columns (width
);
1415 /// Add and assign a location.
1416 inline location
& operator+= (location
& res
, unsigned int width
)
1418 res
.columns (width
);
1422 /** \brief Intercept output stream redirection.
1423 ** \param ostr the destination output stream
1424 ** \param loc a reference to the location to redirect
1426 ** Avoid duplicate information.
1428 inline std::ostream
& operator<< (std::ostream
& ostr
, const location
& loc
)
1430 position last
= loc
.end
- 1;
1433 && (!loc
.begin
.filename
1434 || *loc
.begin
.filename
!= *last
.filename
))
1435 ostr
<< '-' << last
;
1436 else if (loc
.begin
.line
!= last
.line
)
1437 ostr
<< '-' << last
.line
<< '.' << last
.column
;
1438 else if (loc
.begin
.column
!= last
.column
)
1439 ostr
<< '-' << last
.column
;
1445 #endif // not BISON_LOCATION_HH]