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_defines(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_filename
])
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
);
261 /// Call the scanner.
262 virtual void yylex_ ();
264 /// Report a syntax error.
265 /// \param loc where the syntax error is found.
266 /// \param msg a description of the syntax error.
267 virtual void error (const location_type
& loc
, const std::string
& msg
);
269 /// Generate an error message, and invoke error.
270 virtual void yyreport_syntax_error_ ();
273 /// \brief Report a symbol on the debug stream.
274 /// \param yytype The token type.
275 /// \param yyvaluep Its semantic value.
276 /// \param yylocationp Its location.
277 virtual void yysymprint_ (int yytype
,
278 const semantic_type
* yyvaluep
,
279 const location_type
* yylocationp
);
280 #endif /* ! YYDEBUG */
284 typedef traits
<]b4_parser_class_name
[>::state_type state_type
;
285 /// State stack type.
286 typedef stack
<state_type
> state_stack_type
;
287 /// Semantic value stack type.
288 typedef stack
<semantic_type
> semantic_stack_type
;
289 /// location stack type.
290 typedef stack
<location_type
> location_stack_type
;
293 state_stack_type yystate_stack_
;
294 /// The semantic value stack.
295 semantic_stack_type yysemantic_stack_
;
296 /// The location stack.
297 location_stack_type yylocation_stack_
;
299 /// Internal symbol numbers.
300 typedef traits
<]b4_parser_class_name
[>::token_number_type token_number_type
;
302 /// For a state, the index in \a yytable_ of its portion.
303 static const ]b4_int_type_for([b4_pact
])[ yypact_
[];
304 static const ]b4_int_type(b4_pact_ninf
, b4_pact_ninf
)[ yypact_ninf_
;
306 /// For a state, default rule to reduce.
307 /// Unless\a yytable_ specifies something else to do.
308 /// Zero means the default is an error.
309 static const ]b4_int_type_for([b4_defact
])[ yydefact_
[];
311 static const ]b4_int_type_for([b4_pgoto
])[ yypgoto_
[];
312 static const ]b4_int_type_for([b4_defgoto
])[ yydefgoto_
[];
314 /// What to do in a state.
315 /// \a yytable_[yypact_[s]]: what to do in state \a s.
316 /// - if positive, shift that token.
317 /// - if negative, reduce the rule which number is the opposite.
318 /// - if zero, do what YYDEFACT says.
319 static const ]b4_int_type_for([b4_table
])[ yytable_
[];
320 static const ]b4_int_type(b4_table_ninf
, b4_table_ninf
)[ yytable_ninf_
;
322 static const ]b4_int_type_for([b4_check
])[ yycheck_
[];
324 /// For a state, its accessing symbol.
325 static const ]b4_int_type_for([b4_stos
])[ yystos_
[];
327 /// For a rule, its LHS.
328 static const ]b4_int_type_for([b4_r1
])[ yyr1_
[];
329 /// For a rule, its RHS length.
330 static const ]b4_int_type_for([b4_r2
])[ yyr2_
[];
332 #if YYDEBUG || YYERROR_VERBOSE || YYTOKEN_TABLE
333 /// For a symbol, its name in clear.
334 static const char* const yytname_
[];
338 /// Convert the symbol name \a n to a form suitable for a diagnostic.
339 virtual std::string
yytnamerr_ (const char *n
);
343 /// A type to store symbol numbers and -1.
344 typedef traits
<]b4_parser_class_name
[>::rhs_number_type rhs_number_type
;
345 /// A `-1'-separated list of the rules' RHS.
346 static const rhs_number_type yyrhs_
[];
347 /// For each rule, the index of the first RHS symbol in \a yyrhs_.
348 static const ]b4_int_type_for([b4_prhs
])[ yyprhs_
[];
349 /// For each rule, its source line number.
350 static const ]b4_int_type_for([b4_rline
])[ yyrline_
[];
351 /// For each scanner token number, its symbol number.
352 static const ]b4_int_type_for([b4_toknum
])[ yytoken_number_
[];
353 /// Report on the debug stream that the rule \a r is going to be reduced.
354 virtual void yyreduce_print_ (int r
);
355 /// Print the state stack on the debug stream.
356 virtual void yystack_print_ ();
359 /// Convert a scanner token number to a symbol number.
360 inline token_number_type
yytranslate_ (int token
);
362 /// \brief Reclaim the memory associated to a symbol.
363 /// \param yymsg Why this token is reclaimed.
364 /// \param yytype The symbol type.
365 /// \param yyvaluep Its semantic value.
366 /// \param yylocationp Its location.
367 inline void yydestruct_ (const char* yymsg
,
369 semantic_type
* yyvaluep
,
370 location_type
* yylocationp
);
372 /// Pop \a n symbols the three stacks.
373 inline void yypop_ (unsigned int n
= 1);
376 static const int yyeof_
;
377 /* LAST_ -- Last index in TABLE_. */
378 static const int yylast_
;
379 static const int yynnts_
;
380 static const int yyempty_
;
381 static const int yyfinal_
;
382 static const int yyterror_
;
383 static const int yyerrcode_
;
384 static const int yyntokens_
;
385 static const unsigned int yyuser_token_number_max_
;
386 static const token_number_type yyundef_token_
;
393 /* Error handling. */
399 std::ostream
* yycdebug_
;
401 /* Look-ahead and look-ahead in internal form. */
405 /// Semantic value of the look-ahead.
406 semantic_type yylval
;
407 /// Location of the look-ahead.
408 location_type yylloc
;
409 /// The locations where the error started and ended.
410 location yyerror_range_
[2];
416 ]b4_parse_param_vars
[
420 #endif /* ! defined PARSER_HEADER_H */]
422 @output @output_parser_name@
423 b4_copyright([C
++ Skeleton parser
for LALR(1) parsing with Bison
],
424 [2002, 2003, 2004, 2005])
425 m4_if(b4_prefix
[], [yy
], [],
427 // Take the name prefix into account.
428 #define yylex b4_prefix[]lex])
429 m4_if(b4_defines_flag
, 0, [],
431 #include @output_header_name@])[
436 # include <libintl.h> /* FIXME: INFRINGES ON USER NAME SPACE */
437 # define YY_(msgid) dgettext ("bison-runtime", msgid)
441 # define YY_(msgid) msgid
445 /* A pseudo ostream that takes yydebug_ into account. */
447 for (bool yydebugcond_ = yydebug_; yydebugcond_; yydebugcond_ = false) \
450 /* Enable debugging if requested. */
453 # define YY_SYMBOL_PRINT(Title, Type, Value, Location) \
457 *yycdebug_ << (Title) << ' '; \
458 yysymprint_ ((Type), (Value), (Location)); \
459 *yycdebug_ << std::endl; \
463 # define YY_REDUCE_PRINT(Rule) \
466 yyreduce_print_ (Rule); \
469 # define YY_STACK_PRINT() \
477 # define YY_SYMBOL_PRINT(Title, Type, Value, Location)
478 # define YY_REDUCE_PRINT(Rule)
479 # define YY_STACK_PRINT()
481 #endif /* !YYDEBUG */
483 #define YYACCEPT goto yyacceptlab
484 #define YYABORT goto yyabortlab
485 #define YYERROR goto yyerrorlab
489 /* Return YYSTR after stripping away unnecessary quotes and
490 backslashes, so that it's suitable for yyerror. The heuristic is
491 that double-quoting is unnecessary unless the string contains an
492 apostrophe, a comma, or backslash (other than backslash-backslash).
493 YYSTR is taken from yytname. */
495 yy::]b4_parser_class_name
[::yytnamerr_ (const char *yystr
)
499 std::string yyr
= "";
500 char const *yyp
= yystr
;
507 goto do_not_strip_quotes
;
511 goto do_not_strip_quotes
;
520 do_not_strip_quotes
: ;
529 /*--------------------------------.
530 | Print this symbol on YYOUTPUT. |
531 `--------------------------------*/
534 yy::]b4_parser_class_name
[::yysymprint_ (int yytype
,
535 const semantic_type
* yyvaluep
, const location_type
* yylocationp
)
537 /* Pacify ``unused variable'' warnings. */
540 /* Backward compatibility, but should be removed eventually. */
541 std::ostream
& cdebug_
= *yycdebug_
;
544 *yycdebug_
<< (yytype
< yyntokens_
? "token" : "nterm")
545 << ' ' << yytname_
[yytype
] << " ("
546 << *yylocationp
<< ": ";
549 ]m4_map([b4_symbol_actions
], m4_defn([b4_symbol_printers
]))dnl
555 #endif /* ! YYDEBUG */
558 yy::]b4_parser_class_name
[::yydestruct_ (const char* yymsg
,
559 int yytype
, semantic_type
* yyvaluep
, location_type
* yylocationp
)
561 /* Pacify ``unused variable'' warnings. */
566 YY_SYMBOL_PRINT (yymsg
, yytype
, yyvaluep
, yylocationp
);
570 ]m4_map([b4_symbol_actions
], m4_defn([b4_symbol_destructors
]))[
577 yy::]b4_parser_class_name
[::yypop_ (unsigned int n
)
579 yystate_stack_
.pop (n
);
580 yysemantic_stack_
.pop (n
);
581 yylocation_stack_
.pop (n
);
585 yy::]b4_parser_class_name
[::debug_stream () const
591 yy::]b4_parser_class_name
[::set_debug_stream (std::ostream
& o
)
597 yy::]b4_parser_class_name
[::debug_level_type
598 yy::]b4_parser_class_name
[::debug_level () const
604 yy::]b4_parser_class_name
[::set_debug_level (debug_level_type l
)
611 yy::]b4_parser_class_name
[::parse ()
615 YYCDEBUG
<< "Starting parse" << std::endl
;
624 ]m4_ifdef([b4_initial_action
], [
625 m4_pushdef([b4_at_dollar
], [yylloc
])dnl
626 m4_pushdef([b4_dollar_dollar
], [yylval
])dnl
627 /* User initialization code. */
629 m4_popdef([b4_dollar_dollar
])dnl
630 m4_popdef([b4_at_dollar
])dnl
631 /* Line __line__ of yacc.c. */
632 b4_syncline([@oline@
], [@ofile@
])])dnl
634 [ /* Initialize the stacks. The initial state will be pushed in
635 yynewstate, since the latter expects the semantical and the
636 location values to have been already stored, initialize these
637 stacks with a primary value. */
638 yystate_stack_
= state_stack_type (0);
639 yysemantic_stack_
= semantic_stack_type (0);
640 yylocation_stack_
= location_stack_type (0);
641 yysemantic_stack_
.push (yylval
);
642 yylocation_stack_
.push (yylloc
);
646 yystate_stack_
.push (yystate_
);
647 YYCDEBUG
<< "Entering state " << yystate_
<< std::endl
;
653 /* Try to take a decision without look-ahead. */
654 yyn_
= yypact_
[yystate_
];
655 if (yyn_
== yypact_ninf_
)
658 /* Read a look-ahead token. */
659 if (yylooka_
== yyempty_
)
662 /* Convert token to internal form. */
663 if (yylooka_
<= yyeof_
)
665 yylooka_
= yyilooka_
= yyeof_
;
666 YYCDEBUG
<< "Now at end of input." << std::endl
;
670 yyilooka_
= yytranslate_ (yylooka_
);
671 YY_SYMBOL_PRINT ("Next token is", yyilooka_
, &yylval
, &yylloc
);
674 /* If the proper action on seeing token ILOOKA_ is to reduce or to
675 detect an error, take that action. */
677 if (yyn_
< 0 || yylast_
< yyn_
|| yycheck_
[yyn_
] != yyilooka_
)
680 /* Reduce or error. */
681 yyn_
= yytable_
[yyn_
];
684 if (yyn_
== yytable_ninf_
)
696 if (yyn_
== yyfinal_
)
699 /* Shift the look-ahead token. */
700 YY_SYMBOL_PRINT ("Shifting", yyilooka_
, &yylval
, &yylloc
);
702 /* Discard the token being shifted unless it is eof. */
703 if (yylooka_
!= yyeof_
)
706 yysemantic_stack_
.push (yylval
);
707 yylocation_stack_
.push (yylloc
);
709 /* Count tokens shifted since error; after three, turn off error
717 /*-----------------------------------------------------------.
718 | yydefault -- do the default action for the current state. |
719 `-----------------------------------------------------------*/
721 yyn_
= yydefact_
[yystate_
];
726 /*-----------------------------.
727 | yyreduce -- Do a reduction. |
728 `-----------------------------*/
730 yylen_
= yyr2_
[yyn_
];
731 /* If LEN_ is nonzero, implement the default value of the action:
732 `$$ = $1'. Otherwise, use the top of the stack.
734 Otherwise, the following line sets YYVAL to garbage.
735 This behavior is undocumented and Bison
736 users should not rely upon it. */
738 yyval
= yysemantic_stack_
[yylen_
- 1];
740 yyval
= yysemantic_stack_
[0];
743 slice
<location_type
, location_stack_type
> slice (yylocation_stack_
, yylen_
);
744 YYLLOC_DEFAULT (yyloc
, slice
, yylen_
);
746 YY_REDUCE_PRINT (yyn_
);
753 ]/* Line __line__ of lalr1.cc. */
754 b4_syncline([@oline@
], [@ofile@
])[
760 yysemantic_stack_
.push (yyval
);
761 yylocation_stack_
.push (yyloc
);
763 /* Shift the result of the reduction. */
765 yystate_
= yypgoto_
[yyn_
- yyntokens_
] + yystate_stack_
[0];
766 if (0 <= yystate_
&& yystate_
<= yylast_
767 && yycheck_
[yystate_
] == yystate_stack_
[0])
768 yystate_
= yytable_
[yystate_
];
770 yystate_
= yydefgoto_
[yyn_
- yyntokens_
];
773 /*------------------------------------.
774 | yyerrlab -- here on detecting error |
775 `------------------------------------*/
777 /* If not already recovering from an error, report this error. */
778 yyreport_syntax_error_ ();
780 yyerror_range_
[0] = yylloc
;
781 if (yyerrstatus_
== 3)
783 /* If just tried and failed to reuse look-ahead token after an
784 error, discard it. */
786 if (yylooka_
<= yyeof_
)
788 /* Return failure if at end of input. */
789 if (yylooka_
== yyeof_
)
794 yydestruct_ ("Error: discarding", yyilooka_
, &yylval
, &yylloc
);
799 /* Else will try to reuse look-ahead token after shifting the error
804 /*---------------------------------------------------.
805 | yyerrorlab -- error raised explicitly by YYERROR. |
806 `---------------------------------------------------*/
809 /* Pacify compilers like GCC when the user code never invokes
810 YYERROR and the label yyerrorlab therefore never appears in user
815 yyerror_range_
[0] = yylocation_stack_
[yylen_
- 1];
817 yystate_
= yystate_stack_
[0];
820 /*-------------------------------------------------------------.
821 | yyerrlab1 -- common code for both syntax error and YYERROR. |
822 `-------------------------------------------------------------*/
824 yyerrstatus_
= 3; /* Each real token shifted decrements this. */
828 yyn_
= yypact_
[yystate_
];
829 if (yyn_
!= yypact_ninf_
)
832 if (0 <= yyn_
&& yyn_
<= yylast_
&& yycheck_
[yyn_
] == yyterror_
)
834 yyn_
= yytable_
[yyn_
];
840 /* Pop the current state because it cannot handle the error token. */
841 if (yystate_stack_
.height () == 1)
844 yyerror_range_
[0] = yylocation_stack_
[0];
845 yydestruct_ ("Error: popping",
847 &yysemantic_stack_
[0], &yylocation_stack_
[0]);
849 yystate_
= yystate_stack_
[0];
853 if (yyn_
== yyfinal_
)
856 yyerror_range_
[1] = yylloc
;
857 // Using YYLLOC is tempting, but would change the location of
858 // the look-ahead. YYLOC is available though.
859 YYLLOC_DEFAULT (yyloc
, yyerror_range_
- 1, 2);
860 yysemantic_stack_
.push (yylval
);
861 yylocation_stack_
.push (yyloc
);
863 /* Shift the error token. */
864 YY_SYMBOL_PRINT ("Shifting", yystos_
[yyn_
],
865 &yysemantic_stack_
[0], &yylocation_stack_
[0]);
881 if (yylooka_
!= yyeof_
&& yylooka_
!= yyempty_
)
882 yydestruct_ ("Error: discarding lookahead", yyilooka_
, &yylval
, &yylloc
);
884 while (yystate_stack_
.height () != 1)
886 yydestruct_ ("Error: popping",
887 yystos_
[yystate_stack_
[0]],
888 &yysemantic_stack_
[0],
889 &yylocation_stack_
[0]);
897 yy::]b4_parser_class_name
[::yylex_ ()
899 YYCDEBUG
<< "Reading a token: ";
900 yylooka_
= ]b4_c_function_call([yylex
], [int],
901 [[YYSTYPE
*], [&yylval
]][]dnl
902 b4_location_if([, [[location
*], [&yylloc
]]])dnl
903 m4_ifdef([b4_lex_param
], [, ]b4_lex_param
))[;
906 // Generate an error message, and invoke error.
908 yy::]b4_parser_class_name
[::yyreport_syntax_error_ ()
910 /* If not already recovering from an error, report this error. */
916 yyn_
= yypact_
[yystate_
];
917 if (yypact_ninf_
< yyn_
&& yyn_
< yylast_
)
919 /* Start YYX at -YYN if negative to avoid negative indexes in
921 int yyxbegin
= yyn_
< 0 ? -yyn_
: 0;
923 /* Stay within bounds of both yycheck and yytname. */
924 int yychecklim
= yylast_
- yyn_
;
925 int yyxend
= yychecklim
< yyntokens_
? yychecklim
: yyntokens_
;
927 for (int x
= yyxbegin
; x
< yyxend
; ++x
)
928 if (yycheck_
[x
+ yyn_
] == x
&& x
!= yyterror_
)
931 // FIXME: This method of building the message is not compatible
932 // with internationalization. It should work like yacc.c does it.
933 // That is, first build a string that looks like this:
934 // "syntax error, unexpected %s or %s or %s"
935 // Then, invoke YY_ on this string.
936 // Finally, use the string as a format to output
937 // yytname_[yyilooka_], etc.
938 // Until this gets fixed, this message appears in English only.
939 message
= "syntax error, unexpected ";
940 message
+= yytnamerr_ (yytname_
[yyilooka_
]);
944 for (int x
= yyxbegin
; x
< yyxend
; ++x
)
945 if (yycheck_
[x
+ yyn_
] == x
&& x
!= yyterror_
)
947 message
+= (!count
++) ? ", expecting " : " or ";
948 message
+= yytnamerr_ (yytname_
[x
]);
954 message
= YY_("syntax error");
955 error (yylloc
, message
);
960 /* YYPACT[STATE-NUM] -- Index in YYTABLE of the portion describing
962 const ]b4_int_type(b4_pact_ninf
, b4_pact_ninf
) yy::b4_parser_class_name::yypact_ninf_
= b4_pact_ninf
[;
963 const ]b4_int_type_for([b4_pact
])[
964 yy::]b4_parser_class_name
[::yypact_
[] =
969 /* YYDEFACT[S] -- default rule to reduce with in state S when YYTABLE
970 doesn't specify something else to do. Zero means the default is an
972 const ]b4_int_type_for([b4_defact
])[
973 yy::]b4_parser_class_name
[::yydefact_
[] =
978 /* YYPGOTO[NTERM-NUM]. */
979 const ]b4_int_type_for([b4_pgoto
])[
980 yy::]b4_parser_class_name
[::yypgoto_
[] =
985 /* YYDEFGOTO[NTERM-NUM]. */
986 const ]b4_int_type_for([b4_defgoto
])[
987 yy::]b4_parser_class_name
[::yydefgoto_
[] =
992 /* YYTABLE[YYPACT[STATE-NUM]]. What to do in state STATE-NUM. If
993 positive, shift that token. If negative, reduce the rule which
994 number is the opposite. If zero, do what YYDEFACT says. */
995 const ]b4_int_type(b4_table_ninf
, b4_table_ninf
) yy::b4_parser_class_name::yytable_ninf_
= b4_table_ninf
[;
996 const ]b4_int_type_for([b4_table
])[
997 yy::]b4_parser_class_name
[::yytable_
[] =
1003 const ]b4_int_type_for([b4_check
])[
1004 yy::]b4_parser_class_name
[::yycheck_
[] =
1009 /* STOS_[STATE-NUM] -- The (internal number of the) accessing
1010 symbol of state STATE-NUM. */
1011 const ]b4_int_type_for([b4_stos
])[
1012 yy::]b4_parser_class_name
[::yystos_
[] =
1018 /* TOKEN_NUMBER_[YYLEX-NUM] -- Internal symbol number corresponding
1020 const ]b4_int_type_for([b4_toknum
])[
1021 yy::]b4_parser_class_name
[::yytoken_number_
[] =
1027 /* YYR1[YYN] -- Symbol number of symbol that rule YYN derives. */
1028 const ]b4_int_type_for([b4_r1
])[
1029 yy::]b4_parser_class_name
[::yyr1_
[] =
1034 /* YYR2[YYN] -- Number of symbols composing right hand side of rule YYN. */
1035 const ]b4_int_type_for([b4_r2
])[
1036 yy::]b4_parser_class_name
[::yyr2_
[] =
1041 #if YYDEBUG || YYERROR_VERBOSE || YYTOKEN_TABLE
1042 /* YYTNAME[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM.
1043 First, the terminals, then, starting at \a yyntokens_, nonterminals. */
1045 const yy::]b4_parser_class_name
[::yytname_
[] =
1052 /* YYRHS -- A `-1'-separated list of the rules' RHS. */
1053 const yy::]b4_parser_class_name
[::rhs_number_type
1054 yy::]b4_parser_class_name
[::yyrhs_
[] =
1059 /* YYPRHS[YYN] -- Index of the first RHS symbol of rule number YYN in
1061 const ]b4_int_type_for([b4_prhs
])[
1062 yy::]b4_parser_class_name
[::yyprhs_
[] =
1067 /* YYRLINE[YYN] -- Source line where rule number YYN was defined. */
1068 const ]b4_int_type_for([b4_rline
])[
1069 yy::]b4_parser_class_name
[::yyrline_
[] =
1074 // Print the state stack on the debug stream.
1076 yy::]b4_parser_class_name
[::yystack_print_ ()
1078 *yycdebug_
<< "Stack now";
1079 for (state_stack_type::const_iterator i
= yystate_stack_
.begin ();
1080 i
!= yystate_stack_
.end (); ++i
)
1081 *yycdebug_
<< ' ' << *i
;
1082 *yycdebug_
<< std::endl
;
1085 // Report on the debug stream that the rule \a yyrule is going to be reduced.
1087 yy::]b4_parser_class_name
[::yyreduce_print_ (int yyrule
)
1089 unsigned int yylno
= yyrline_
[yyrule
];
1090 /* Print the symbols being reduced, and their result. */
1091 *yycdebug_
<< "Reducing stack by rule " << yyn_
- 1
1092 << " (line " << yylno
<< "), ";
1093 for (]b4_int_type_for([b4_prhs
])[ i
= yyprhs_
[yyn_
];
1094 0 <= yyrhs_
[i
]; ++i
)
1095 *yycdebug_
<< yytname_
[yyrhs_
[i
]] << ' ';
1096 *yycdebug_
<< "-> " << yytname_
[yyr1_
[yyn_
]] << std::endl
;
1100 /* YYTRANSLATE(YYLEX) -- Bison symbol number corresponding to YYLEX. */
1101 yy::]b4_parser_class_name
[::token_number_type
1102 yy::]b4_parser_class_name
[::yytranslate_ (int token
)
1105 const token_number_type
1110 if ((unsigned int) token
<= yyuser_token_number_max_
)
1111 return translate_table
[token
];
1113 return yyundef_token_
;
1116 const int yy::]b4_parser_class_name
[::yyeof_
= 0;
1117 const int yy::]b4_parser_class_name
[::yylast_
= ]b4_last
[;
1118 const int yy::]b4_parser_class_name
[::yynnts_
= ]b4_nterms_number
[;
1119 const int yy::]b4_parser_class_name
[::yyempty_
= -2;
1120 const int yy::]b4_parser_class_name
[::yyfinal_
= ]b4_final_state_number
[;
1121 const int yy::]b4_parser_class_name
[::yyterror_
= 1;
1122 const int yy::]b4_parser_class_name
[::yyerrcode_
= 256;
1123 const int yy::]b4_parser_class_name
[::yyntokens_
= ]b4_tokens_number
[;
1125 const unsigned int yy::]b4_parser_class_name
[::yyuser_token_number_max_
= ]b4_user_token_number_max
[;
1126 const yy::]b4_parser_class_name
[::token_number_type
yy::]b4_parser_class_name
[::yyundef_token_
= ]b4_undef_token_number
[;
1131 b4_copyright([stack handling
for Bison C
++ parsers
], [2002, 2003, 2004, 2005])[
1133 #ifndef BISON_STACK_HH
1134 # define BISON_STACK_HH
1140 template <class T
, class S
= std::deque
<T
> >
1145 // Hide our reversed order.
1146 typedef typename
S::reverse_iterator iterator
;
1147 typedef typename
S::const_reverse_iterator const_iterator
;
1153 stack (unsigned int n
) : seq_ (n
)
1159 operator [] (unsigned int i
)
1166 operator [] (unsigned int i
) const
1175 seq_
.push_front (t
);
1180 pop (unsigned int n
= 1)
1190 return seq_
.size ();
1193 inline const_iterator
begin () const { return seq_
.rbegin (); }
1194 inline const_iterator
end () const { return seq_
.rend (); }
1201 /// Present a slice of the top of a stack.
1202 template <class T
, class S
= stack
<T
> >
1207 slice (const S
& stack
,
1208 unsigned int range
) : stack_ (stack
),
1215 operator [] (unsigned int i
) const
1217 return stack_
[range_
- i
];
1223 unsigned int range_
;
1227 #endif // not BISON_STACK_HH]
1230 b4_copyright([Position
class for Bison C
++ parsers
], [2002, 2003, 2004, 2005])[
1233 ** \file position.hh
1234 ** Define the position class.
1237 #ifndef BISON_POSITION_HH
1238 # define BISON_POSITION_HH
1240 # include <iostream>
1245 /// Abstract a position.
1249 /// Initial column number.
1250 static const unsigned int initial_column
= 0;
1251 /// Initial line number.
1252 static const unsigned int initial_line
= 1;
1254 /** \name Ctor & dtor.
1257 /// Construct a position.
1260 line (initial_line
),
1261 column (initial_column
)
1267 /** \name Line and Column related manipulators
1270 /// (line related) Advance to the COUNT next lines.
1271 inline void lines (int count
= 1)
1273 column
= initial_column
;
1277 /// (column related) Advance to the COUNT next columns.
1278 inline void columns (int count
= 1)
1280 int leftmost
= initial_column
;
1281 int current
= column
;
1282 if (leftmost
<= current
+ count
)
1285 column
= initial_column
;
1290 /// File name to which this position refers.
1291 ]b4_filename_type
[* filename
;
1292 /// Current line number.
1294 /// Current column number.
1295 unsigned int column
;
1298 /// Add and assign a position.
1299 inline const position
&
1300 operator+= (position
& res
, const int width
)
1302 res
.columns (width
);
1306 /// Add two position objects.
1307 inline const position
1308 operator+ (const position
& begin
, const int width
)
1310 position res
= begin
;
1311 return res
+= width
;
1314 /// Add and assign a position.
1315 inline const position
&
1316 operator-= (position
& res
, const int width
)
1318 return res
+= -width
;
1321 /// Add two position objects.
1322 inline const position
1323 operator- (const position
& begin
, const int width
)
1325 return begin
+ -width
;
1328 /** \brief Intercept output stream redirection.
1329 ** \param ostr the destination output stream
1330 ** \param pos a reference to the position to redirect
1332 inline std::ostream
&
1333 operator<< (std::ostream
& ostr
, const position
& pos
)
1336 ostr
<< *pos
.filename
<< ':';
1337 return ostr
<< pos
.line
<< '.' << pos
.column
;
1341 #endif // not BISON_POSITION_HH]
1343 b4_copyright([Location
class for Bison C
++ parsers
], [2002, 2003, 2004, 2005])[
1346 ** \file location.hh
1347 ** Define the location class.
1350 #ifndef BISON_LOCATION_HH
1351 # define BISON_LOCATION_HH
1353 # include <iostream>
1355 # include "position.hh"
1360 /// Abstract a location.
1363 /** \name Ctor & dtor.
1366 /// Construct a location.
1375 /** \name Line and Column related manipulators
1378 /// Reset initial location to final location.
1384 /// Extend the current location to the COUNT next columns.
1385 inline void columns (unsigned int count
= 1)
1390 /// Extend the current location to the COUNT next lines.
1391 inline void lines (unsigned int count
= 1)
1399 /// Beginning of the located region.
1401 /// End of the located region.
1405 /// Join two location objects to create a location.
1406 inline const location
operator+ (const location
& begin
, const location
& end
)
1408 location res
= begin
;
1413 /// Add two location objects.
1414 inline const location
operator+ (const location
& begin
, unsigned int width
)
1416 location res
= begin
;
1417 res
.columns (width
);
1421 /// Add and assign a location.
1422 inline location
& operator+= (location
& res
, unsigned int width
)
1424 res
.columns (width
);
1428 /** \brief Intercept output stream redirection.
1429 ** \param ostr the destination output stream
1430 ** \param loc a reference to the location to redirect
1432 ** Avoid duplicate information.
1434 inline std::ostream
& operator<< (std::ostream
& ostr
, const location
& loc
)
1436 position last
= loc
.end
- 1;
1439 && (!loc
.begin
.filename
1440 || *loc
.begin
.filename
!= *last
.filename
))
1441 ostr
<< '-' << last
;
1442 else if (loc
.begin
.line
!= last
.line
)
1443 ostr
<< '-' << last
.line
<< '.' << last
.column
;
1444 else if (loc
.begin
.column
!= last
.column
)
1445 ostr
<< '-' << last
.column
;
1451 #endif // not BISON_LOCATION_HH]