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; \
117 class ]b4_parser_class_name
[
119 /// Symbol semantic values.
120 typedef YYSTYPE semantic_type
;
121 /// Symbol locations.
122 typedef ]b4_location_type
[ location_type
;
125 /// Build a parser object.
126 ]b4_parser_class_name
[ (]b4_parse_param_decl
[) :
128 yycdebug_ (&std::cerr
)]b4_parse_param_cons
[
132 virtual ~]b4_parser_class_name
[ ()
137 /// \returns 0 iff parsing succeeded.
138 virtual int parse ();
140 /// The current debugging stream.
141 std::ostream
& debug_stream () const;
142 /// Set the current debugging stream.
143 void set_debug_stream (std::ostream
&);
145 /// Type for debugging levels.
146 typedef int debug_level_type
;
147 /// The current debugging level.
148 debug_level_type
debug_level () const;
149 /// Set the current debugging level.
150 void set_debug_level (debug_level_type l
);
153 /// Report a syntax error.
154 /// \param loc where the syntax error is found.
155 /// \param msg a description of the syntax error.
156 virtual void error (const location_type
& loc
, const std::string
& msg
);
158 /// Generate an error message.
159 /// \param state the state where the error occurred.
160 /// \param tok the look-ahead token.
161 virtual std::string
yysyntax_error_ (int yystate
]dnl
162 b4_error_verbose_if([, int tok
])[);
165 /// \brief Report a symbol on the debug stream.
166 /// \param yytype The token type.
167 /// \param yyvaluep Its semantic value.
168 /// \param yylocationp Its location.
169 virtual void yysymprint_ (int yytype
,
170 const semantic_type
* yyvaluep
,
171 const location_type
* yylocationp
);
172 #endif /* ! YYDEBUG */
176 typedef int state_type
;
177 /// State stack type.
178 typedef stack
<state_type
> state_stack_type
;
179 /// Semantic value stack type.
180 typedef stack
<semantic_type
> semantic_stack_type
;
181 /// location stack type.
182 typedef stack
<location_type
> location_stack_type
;
185 state_stack_type yystate_stack_
;
186 /// The semantic value stack.
187 semantic_stack_type yysemantic_stack_
;
188 /// The location stack.
189 location_stack_type yylocation_stack_
;
191 /// Internal symbol numbers.
192 typedef ]b4_int_type_for([b4_translate
])[ token_number_type
;
194 /// For a state, the index in \a yytable_ of its portion.
195 static const ]b4_int_type_for([b4_pact
])[ yypact_
[];
196 static const ]b4_int_type(b4_pact_ninf
, b4_pact_ninf
)[ yypact_ninf_
;
198 /// For a state, default rule to reduce.
199 /// Unless\a yytable_ specifies something else to do.
200 /// Zero means the default is an error.
201 static const ]b4_int_type_for([b4_defact
])[ yydefact_
[];
203 static const ]b4_int_type_for([b4_pgoto
])[ yypgoto_
[];
204 static const ]b4_int_type_for([b4_defgoto
])[ yydefgoto_
[];
206 /// What to do in a state.
207 /// \a yytable_[yypact_[s]]: what to do in state \a s.
208 /// - if positive, shift that token.
209 /// - if negative, reduce the rule which number is the opposite.
210 /// - if zero, do what YYDEFACT says.
211 static const ]b4_int_type_for([b4_table
])[ yytable_
[];
212 static const ]b4_int_type(b4_table_ninf
, b4_table_ninf
)[ yytable_ninf_
;
214 static const ]b4_int_type_for([b4_check
])[ yycheck_
[];
216 /// For a state, its accessing symbol.
217 static const ]b4_int_type_for([b4_stos
])[ yystos_
[];
219 /// For a rule, its LHS.
220 static const ]b4_int_type_for([b4_r1
])[ yyr1_
[];
221 /// For a rule, its RHS length.
222 static const ]b4_int_type_for([b4_r2
])[ yyr2_
[];
224 #if YYDEBUG || YYERROR_VERBOSE || YYTOKEN_TABLE
225 /// For a symbol, its name in clear.
226 static const char* const yytname_
[];
230 /// Convert the symbol name \a n to a form suitable for a diagnostic.
231 virtual std::string
yytnamerr_ (const char *n
);
235 /// A type to store symbol numbers and -1.
236 typedef ]b4_int_type_for([b4_rhs
])[ rhs_number_type
;
237 /// A `-1'-separated list of the rules' RHS.
238 static const rhs_number_type yyrhs_
[];
239 /// For each rule, the index of the first RHS symbol in \a yyrhs_.
240 static const ]b4_int_type_for([b4_prhs
])[ yyprhs_
[];
241 /// For each rule, its source line number.
242 static const ]b4_int_type_for([b4_rline
])[ yyrline_
[];
243 /// For each scanner token number, its symbol number.
244 static const ]b4_int_type_for([b4_toknum
])[ yytoken_number_
[];
245 /// Report on the debug stream that the rule \a r is going to be reduced.
246 virtual void yyreduce_print_ (int r
);
247 /// Print the state stack on the debug stream.
248 virtual void yystack_print_ ();
251 /// Convert a scanner token number to a symbol number.
252 inline token_number_type
yytranslate_ (int token
);
254 /// \brief Reclaim the memory associated to a symbol.
255 /// \param yymsg Why this token is reclaimed.
256 /// \param yytype The symbol type.
257 /// \param yyvaluep Its semantic value.
258 /// \param yylocationp Its location.
259 inline void yydestruct_ (const char* yymsg
,
261 semantic_type
* yyvaluep
,
262 location_type
* yylocationp
);
264 /// Pop \a n symbols the three stacks.
265 inline void yypop_ (unsigned int n
= 1);
268 static const int yyeof_
;
269 /* LAST_ -- Last index in TABLE_. */
270 static const int yylast_
;
271 static const int yynnts_
;
272 static const int yyempty_
;
273 static const int yyfinal_
;
274 static const int yyterror_
;
275 static const int yyerrcode_
;
276 static const int yyntokens_
;
277 static const unsigned int yyuser_token_number_max_
;
278 static const token_number_type yyundef_token_
;
282 std::ostream
* yycdebug_
;
284 ]b4_parse_param_vars
[
288 #endif /* ! defined PARSER_HEADER_H */]
290 @output @output_parser_name@
291 b4_copyright([C
++ Skeleton parser
for LALR(1) parsing with Bison
],
292 [2002, 2003, 2004, 2005])
293 m4_if(b4_prefix
[], [yy
], [],
295 // Take the name prefix into account.
296 #define yylex b4_prefix[]lex])
297 m4_if(b4_defines_flag
, 0, [],
299 #include @output_header_name@])[
304 # include <libintl.h> /* FIXME: INFRINGES ON USER NAME SPACE */
305 # define YY_(msgid) dgettext ("bison-runtime", msgid)
309 # define YY_(msgid) msgid
313 /* A pseudo ostream that takes yydebug_ into account. */
315 for (bool yydebugcond_ = yydebug_; yydebugcond_; yydebugcond_ = false) \
318 /* Enable debugging if requested. */
321 # define YY_SYMBOL_PRINT(Title, Type, Value, Location) \
325 *yycdebug_ << (Title) << ' '; \
326 yysymprint_ ((Type), (Value), (Location)); \
327 *yycdebug_ << std::endl; \
331 # define YY_REDUCE_PRINT(Rule) \
334 yyreduce_print_ (Rule); \
337 # define YY_STACK_PRINT() \
345 # define YY_SYMBOL_PRINT(Title, Type, Value, Location)
346 # define YY_REDUCE_PRINT(Rule)
347 # define YY_STACK_PRINT()
349 #endif /* !YYDEBUG */
351 #define YYACCEPT goto yyacceptlab
352 #define YYABORT goto yyabortlab
353 #define YYERROR goto yyerrorlab
357 /* Return YYSTR after stripping away unnecessary quotes and
358 backslashes, so that it's suitable for yyerror. The heuristic is
359 that double-quoting is unnecessary unless the string contains an
360 apostrophe, a comma, or backslash (other than backslash-backslash).
361 YYSTR is taken from yytname. */
363 yy::]b4_parser_class_name
[::yytnamerr_ (const char *yystr
)
367 std::string yyr
= "";
368 char const *yyp
= yystr
;
375 goto do_not_strip_quotes
;
379 goto do_not_strip_quotes
;
388 do_not_strip_quotes
: ;
397 /*--------------------------------.
398 | Print this symbol on YYOUTPUT. |
399 `--------------------------------*/
402 yy::]b4_parser_class_name
[::yysymprint_ (int yytype
,
403 const semantic_type
* yyvaluep
, const location_type
* yylocationp
)
405 /* Pacify ``unused variable'' warnings. */
408 /* Backward compatibility, but should be removed eventually. */
409 std::ostream
& cdebug_
= *yycdebug_
;
412 *yycdebug_
<< (yytype
< yyntokens_
? "token" : "nterm")
413 << ' ' << yytname_
[yytype
] << " ("
414 << *yylocationp
<< ": ";
417 ]m4_map([b4_symbol_actions
], m4_defn([b4_symbol_printers
]))dnl
423 #endif /* ! YYDEBUG */
426 yy::]b4_parser_class_name
[::yydestruct_ (const char* yymsg
,
427 int yytype
, semantic_type
* yyvaluep
, location_type
* yylocationp
)
429 /* Pacify ``unused variable'' warnings. */
434 YY_SYMBOL_PRINT (yymsg
, yytype
, yyvaluep
, yylocationp
);
438 ]m4_map([b4_symbol_actions
], m4_defn([b4_symbol_destructors
]))[
445 yy::]b4_parser_class_name
[::yypop_ (unsigned int n
)
447 yystate_stack_
.pop (n
);
448 yysemantic_stack_
.pop (n
);
449 yylocation_stack_
.pop (n
);
453 yy::]b4_parser_class_name
[::debug_stream () const
459 yy::]b4_parser_class_name
[::set_debug_stream (std::ostream
& o
)
465 yy::]b4_parser_class_name
[::debug_level_type
466 yy::]b4_parser_class_name
[::debug_level () const
472 yy::]b4_parser_class_name
[::set_debug_level (debug_level_type l
)
479 yy::]b4_parser_class_name
[::parse ()
481 /// Look-ahead and look-ahead in internal form.
482 int yychar
= yyempty_
;
490 /* Error handling. */
492 int yyerrstatus_
= 0;
494 /// Semantic value of the look-ahead.
495 semantic_type yylval
;
496 /// Location of the look-ahead.
497 location_type yylloc
;
498 /// The locations where the error started and ended.
499 location yyerror_range
[2];
508 YYCDEBUG
<< "Starting parse" << std::endl
;
510 ]m4_ifdef([b4_initial_action
], [
511 m4_pushdef([b4_at_dollar
], [yylloc
])dnl
512 m4_pushdef([b4_dollar_dollar
], [yylval
])dnl
513 /* User initialization code. */
515 m4_popdef([b4_dollar_dollar
])dnl
516 m4_popdef([b4_at_dollar
])dnl
517 /* Line __line__ of yacc.c. */
518 b4_syncline([@oline@
], [@ofile@
])])dnl
520 [ /* Initialize the stacks. The initial state will be pushed in
521 yynewstate, since the latter expects the semantical and the
522 location values to have been already stored, initialize these
523 stacks with a primary value. */
524 yystate_stack_
= state_stack_type (0);
525 yysemantic_stack_
= semantic_stack_type (0);
526 yylocation_stack_
= location_stack_type (0);
527 yysemantic_stack_
.push (yylval
);
528 yylocation_stack_
.push (yylloc
);
532 yystate_stack_
.push (yystate
);
533 YYCDEBUG
<< "Entering state " << yystate
<< std::endl
;
539 /* Try to take a decision without look-ahead. */
540 yyn
= yypact_
[yystate
];
541 if (yyn
== yypact_ninf_
)
544 /* Read a look-ahead token. */
545 if (yychar
== yyempty_
)
547 YYCDEBUG
<< "Reading a token: ";
548 yychar
= ]b4_c_function_call([yylex
], [int],
549 [[YYSTYPE
*], [&yylval
]][]dnl
550 b4_location_if([, [[location
*], [&yylloc
]]])dnl
551 m4_ifdef([b4_lex_param
], [, ]b4_lex_param
))[;
555 /* Convert token to internal form. */
556 if (yychar
<= yyeof_
)
558 yychar
= yytoken
= yyeof_
;
559 YYCDEBUG
<< "Now at end of input." << std::endl
;
563 yytoken
= yytranslate_ (yychar
);
564 YY_SYMBOL_PRINT ("Next token is", yytoken
, &yylval
, &yylloc
);
567 /* If the proper action on seeing token YYTOKEN is to reduce or to
568 detect an error, take that action. */
570 if (yyn
< 0 || yylast_
< yyn
|| yycheck_
[yyn
] != yytoken
)
573 /* Reduce or error. */
577 if (yyn
== 0 || yyn
== yytable_ninf_
)
587 /* Shift the look-ahead token. */
588 YY_SYMBOL_PRINT ("Shifting", yytoken
, &yylval
, &yylloc
);
590 /* Discard the token being shifted unless it is eof. */
591 if (yychar
!= yyeof_
)
594 yysemantic_stack_
.push (yylval
);
595 yylocation_stack_
.push (yylloc
);
597 /* Count tokens shifted since error; after three, turn off error
605 /*-----------------------------------------------------------.
606 | yydefault -- do the default action for the current state. |
607 `-----------------------------------------------------------*/
609 yyn
= yydefact_
[yystate
];
614 /*-----------------------------.
615 | yyreduce -- Do a reduction. |
616 `-----------------------------*/
619 /* If LEN_ is nonzero, implement the default value of the action:
620 `$$ = $1'. Otherwise, use the top of the stack.
622 Otherwise, the following line sets YYVAL to garbage.
623 This behavior is undocumented and Bison
624 users should not rely upon it. */
626 yyval
= yysemantic_stack_
[yylen
- 1];
628 yyval
= yysemantic_stack_
[0];
631 slice
<location_type
, location_stack_type
> slice (yylocation_stack_
, yylen
);
632 YYLLOC_DEFAULT (yyloc
, slice
, yylen
);
634 YY_REDUCE_PRINT (yyn
);
641 ]/* Line __line__ of lalr1.cc. */
642 b4_syncline([@oline@
], [@ofile@
])[
648 yysemantic_stack_
.push (yyval
);
649 yylocation_stack_
.push (yyloc
);
651 /* Shift the result of the reduction. */
653 yystate
= yypgoto_
[yyn
- yyntokens_
] + yystate_stack_
[0];
654 if (0 <= yystate
&& yystate
<= yylast_
655 && yycheck_
[yystate
] == yystate_stack_
[0])
656 yystate
= yytable_
[yystate
];
658 yystate
= yydefgoto_
[yyn
- yyntokens_
];
661 /*------------------------------------.
662 | yyerrlab -- here on detecting error |
663 `------------------------------------*/
665 /* If not already recovering from an error, report this error. */
669 error (yylloc
, yysyntax_error_ (yystate
]dnl
670 b4_error_verbose_if([, yytoken
])[));
673 yyerror_range
[0] = yylloc
;
674 if (yyerrstatus_
== 3)
676 /* If just tried and failed to reuse look-ahead token after an
677 error, discard it. */
679 if (yychar
<= yyeof_
)
681 /* Return failure if at end of input. */
682 if (yychar
== yyeof_
)
687 yydestruct_ ("Error: discarding", yytoken
, &yylval
, &yylloc
);
692 /* Else will try to reuse look-ahead token after shifting the error
697 /*---------------------------------------------------.
698 | yyerrorlab -- error raised explicitly by YYERROR. |
699 `---------------------------------------------------*/
702 /* Pacify compilers like GCC when the user code never invokes
703 YYERROR and the label yyerrorlab therefore never appears in user
708 yyerror_range
[0] = yylocation_stack_
[yylen
- 1];
710 yystate
= yystate_stack_
[0];
713 /*-------------------------------------------------------------.
714 | yyerrlab1 -- common code for both syntax error and YYERROR. |
715 `-------------------------------------------------------------*/
717 yyerrstatus_
= 3; /* Each real token shifted decrements this. */
721 yyn
= yypact_
[yystate
];
722 if (yyn
!= yypact_ninf_
)
725 if (0 <= yyn
&& yyn
<= yylast_
&& yycheck_
[yyn
] == yyterror_
)
733 /* Pop the current state because it cannot handle the error token. */
734 if (yystate_stack_
.height () == 1)
737 yyerror_range
[0] = yylocation_stack_
[0];
738 yydestruct_ ("Error: popping",
740 &yysemantic_stack_
[0], &yylocation_stack_
[0]);
742 yystate
= yystate_stack_
[0];
749 yyerror_range
[1] = yylloc
;
750 // Using YYLLOC is tempting, but would change the location of
751 // the look-ahead. YYLOC is available though.
752 YYLLOC_DEFAULT (yyloc
, yyerror_range
- 1, 2);
753 yysemantic_stack_
.push (yylval
);
754 yylocation_stack_
.push (yyloc
);
756 /* Shift the error token. */
757 YY_SYMBOL_PRINT ("Shifting", yystos_
[yyn
],
758 &yysemantic_stack_
[0], &yylocation_stack_
[0]);
774 if (yychar
!= yyeof_
&& yychar
!= yyempty_
)
775 yydestruct_ ("Cleanup: discarding lookahead", yytoken
, &yylval
, &yylloc
);
777 while (yystate_stack_
.height () != 1)
779 yydestruct_ ("Cleanup: popping",
780 yystos_
[yystate_stack_
[0]],
781 &yysemantic_stack_
[0],
782 &yylocation_stack_
[0]);
789 // Generate an error message.
791 yy::]b4_parser_class_name
[::
792 yysyntax_error_ (int yystate
]b4_error_verbose_if([, int tok
])[)
796 int yyn
= yypact_
[yystate
];
797 if (yypact_ninf_
< yyn
&& yyn
< yylast_
)
799 /* Start YYX at -YYN if negative to avoid negative indexes in
801 int yyxbegin
= yyn
< 0 ? -yyn
: 0;
803 /* Stay within bounds of both yycheck and yytname. */
804 int yychecklim
= yylast_
- yyn
;
805 int yyxend
= yychecklim
< yyntokens_
? yychecklim
: yyntokens_
;
807 for (int x
= yyxbegin
; x
< yyxend
; ++x
)
808 if (yycheck_
[x
+ yyn
] == x
&& x
!= yyterror_
)
811 // FIXME: This method of building the message is not compatible
812 // with internationalization. It should work like yacc.c does it.
813 // That is, first build a string that looks like this:
814 // "syntax error, unexpected %s or %s or %s"
815 // Then, invoke YY_ on this string.
816 // Finally, use the string as a format to output
817 // yytname_[tok], etc.
818 // Until this gets fixed, this message appears in English only.
819 res
= "syntax error, unexpected ";
820 res
+= yytnamerr_ (yytname_
[tok
]);
824 for (int x
= yyxbegin
; x
< yyxend
; ++x
)
825 if (yycheck_
[x
+ yyn
] == x
&& x
!= yyterror_
)
827 res
+= (!count
++) ? ", expecting " : " or ";
828 res
+= yytnamerr_ (yytname_
[x
]);
834 res
= YY_("syntax error");
839 /* YYPACT[STATE-NUM] -- Index in YYTABLE of the portion describing
841 const ]b4_int_type(b4_pact_ninf
, b4_pact_ninf
) yy::b4_parser_class_name::yypact_ninf_
= b4_pact_ninf
[;
842 const ]b4_int_type_for([b4_pact
])[
843 yy::]b4_parser_class_name
[::yypact_
[] =
848 /* YYDEFACT[S] -- default rule to reduce with in state S when YYTABLE
849 doesn't specify something else to do. Zero means the default is an
851 const ]b4_int_type_for([b4_defact
])[
852 yy::]b4_parser_class_name
[::yydefact_
[] =
857 /* YYPGOTO[NTERM-NUM]. */
858 const ]b4_int_type_for([b4_pgoto
])[
859 yy::]b4_parser_class_name
[::yypgoto_
[] =
864 /* YYDEFGOTO[NTERM-NUM]. */
865 const ]b4_int_type_for([b4_defgoto
])[
866 yy::]b4_parser_class_name
[::yydefgoto_
[] =
871 /* YYTABLE[YYPACT[STATE-NUM]]. What to do in state STATE-NUM. If
872 positive, shift that token. If negative, reduce the rule which
873 number is the opposite. If zero, do what YYDEFACT says. */
874 const ]b4_int_type(b4_table_ninf
, b4_table_ninf
) yy::b4_parser_class_name::yytable_ninf_
= b4_table_ninf
[;
875 const ]b4_int_type_for([b4_table
])[
876 yy::]b4_parser_class_name
[::yytable_
[] =
882 const ]b4_int_type_for([b4_check
])[
883 yy::]b4_parser_class_name
[::yycheck_
[] =
888 /* STOS_[STATE-NUM] -- The (internal number of the) accessing
889 symbol of state STATE-NUM. */
890 const ]b4_int_type_for([b4_stos
])[
891 yy::]b4_parser_class_name
[::yystos_
[] =
897 /* TOKEN_NUMBER_[YYLEX-NUM] -- Internal symbol number corresponding
899 const ]b4_int_type_for([b4_toknum
])[
900 yy::]b4_parser_class_name
[::yytoken_number_
[] =
906 /* YYR1[YYN] -- Symbol number of symbol that rule YYN derives. */
907 const ]b4_int_type_for([b4_r1
])[
908 yy::]b4_parser_class_name
[::yyr1_
[] =
913 /* YYR2[YYN] -- Number of symbols composing right hand side of rule YYN. */
914 const ]b4_int_type_for([b4_r2
])[
915 yy::]b4_parser_class_name
[::yyr2_
[] =
920 #if YYDEBUG || YYERROR_VERBOSE || YYTOKEN_TABLE
921 /* YYTNAME[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM.
922 First, the terminals, then, starting at \a yyntokens_, nonterminals. */
924 const yy::]b4_parser_class_name
[::yytname_
[] =
931 /* YYRHS -- A `-1'-separated list of the rules' RHS. */
932 const yy::]b4_parser_class_name
[::rhs_number_type
933 yy::]b4_parser_class_name
[::yyrhs_
[] =
938 /* YYPRHS[YYN] -- Index of the first RHS symbol of rule number YYN in
940 const ]b4_int_type_for([b4_prhs
])[
941 yy::]b4_parser_class_name
[::yyprhs_
[] =
946 /* YYRLINE[YYN] -- Source line where rule number YYN was defined. */
947 const ]b4_int_type_for([b4_rline
])[
948 yy::]b4_parser_class_name
[::yyrline_
[] =
953 // Print the state stack on the debug stream.
955 yy::]b4_parser_class_name
[::yystack_print_ ()
957 *yycdebug_
<< "Stack now";
958 for (state_stack_type::const_iterator i
= yystate_stack_
.begin ();
959 i
!= yystate_stack_
.end (); ++i
)
960 *yycdebug_
<< ' ' << *i
;
961 *yycdebug_
<< std::endl
;
964 // Report on the debug stream that the rule \a yyrule is going to be reduced.
966 yy::]b4_parser_class_name
[::yyreduce_print_ (int yyrule
)
968 unsigned int yylno
= yyrline_
[yyrule
];
969 /* Print the symbols being reduced, and their result. */
970 *yycdebug_
<< "Reducing stack by rule " << yyrule
- 1
971 << " (line " << yylno
<< "), ";
972 for (]b4_int_type_for([b4_prhs
])[ i
= yyprhs_
[yyrule
];
974 *yycdebug_
<< yytname_
[yyrhs_
[i
]] << ' ';
975 *yycdebug_
<< "-> " << yytname_
[yyr1_
[yyrule
]] << std::endl
;
979 /* YYTRANSLATE(YYLEX) -- Bison symbol number corresponding to YYLEX. */
980 yy::]b4_parser_class_name
[::token_number_type
981 yy::]b4_parser_class_name
[::yytranslate_ (int token
)
984 const token_number_type
989 if ((unsigned int) token
<= yyuser_token_number_max_
)
990 return translate_table
[token
];
992 return yyundef_token_
;
995 const int yy::]b4_parser_class_name
[::yyeof_
= 0;
996 const int yy::]b4_parser_class_name
[::yylast_
= ]b4_last
[;
997 const int yy::]b4_parser_class_name
[::yynnts_
= ]b4_nterms_number
[;
998 const int yy::]b4_parser_class_name
[::yyempty_
= -2;
999 const int yy::]b4_parser_class_name
[::yyfinal_
= ]b4_final_state_number
[;
1000 const int yy::]b4_parser_class_name
[::yyterror_
= 1;
1001 const int yy::]b4_parser_class_name
[::yyerrcode_
= 256;
1002 const int yy::]b4_parser_class_name
[::yyntokens_
= ]b4_tokens_number
[;
1004 const unsigned int yy::]b4_parser_class_name
[::yyuser_token_number_max_
= ]b4_user_token_number_max
[;
1005 const yy::]b4_parser_class_name
[::token_number_type
yy::]b4_parser_class_name
[::yyundef_token_
= ]b4_undef_token_number
[;
1010 b4_copyright([stack handling
for Bison C
++ parsers
], [2002, 2003, 2004, 2005])[
1012 #ifndef BISON_STACK_HH
1013 # define BISON_STACK_HH
1019 template <class T
, class S
= std::deque
<T
> >
1024 // Hide our reversed order.
1025 typedef typename
S::reverse_iterator iterator
;
1026 typedef typename
S::const_reverse_iterator const_iterator
;
1032 stack (unsigned int n
) : seq_ (n
)
1038 operator [] (unsigned int i
)
1045 operator [] (unsigned int i
) const
1054 seq_
.push_front (t
);
1059 pop (unsigned int n
= 1)
1069 return seq_
.size ();
1072 inline const_iterator
begin () const { return seq_
.rbegin (); }
1073 inline const_iterator
end () const { return seq_
.rend (); }
1080 /// Present a slice of the top of a stack.
1081 template <class T
, class S
= stack
<T
> >
1086 slice (const S
& stack
,
1087 unsigned int range
) : stack_ (stack
),
1094 operator [] (unsigned int i
) const
1096 return stack_
[range_
- i
];
1102 unsigned int range_
;
1106 #endif // not BISON_STACK_HH]
1109 b4_copyright([Position
class for Bison C
++ parsers
], [2002, 2003, 2004, 2005])[
1112 ** \file position.hh
1113 ** Define the position class.
1116 #ifndef BISON_POSITION_HH
1117 # define BISON_POSITION_HH
1119 # include <iostream>
1124 /// Abstract a position.
1128 /// Initial column number.
1129 static const unsigned int initial_column
= 0;
1130 /// Initial line number.
1131 static const unsigned int initial_line
= 1;
1133 /** \name Ctor & dtor.
1136 /// Construct a position.
1139 line (initial_line
),
1140 column (initial_column
)
1146 /** \name Line and Column related manipulators
1149 /// (line related) Advance to the COUNT next lines.
1150 inline void lines (int count
= 1)
1152 column
= initial_column
;
1156 /// (column related) Advance to the COUNT next columns.
1157 inline void columns (int count
= 1)
1159 int leftmost
= initial_column
;
1160 int current
= column
;
1161 if (leftmost
<= current
+ count
)
1164 column
= initial_column
;
1169 /// File name to which this position refers.
1170 ]b4_filename_type
[* filename
;
1171 /// Current line number.
1173 /// Current column number.
1174 unsigned int column
;
1177 /// Add and assign a position.
1178 inline const position
&
1179 operator+= (position
& res
, const int width
)
1181 res
.columns (width
);
1185 /// Add two position objects.
1186 inline const position
1187 operator+ (const position
& begin
, const int width
)
1189 position res
= begin
;
1190 return res
+= width
;
1193 /// Add and assign a position.
1194 inline const position
&
1195 operator-= (position
& res
, const int width
)
1197 return res
+= -width
;
1200 /// Add two position objects.
1201 inline const position
1202 operator- (const position
& begin
, const int width
)
1204 return begin
+ -width
;
1207 /** \brief Intercept output stream redirection.
1208 ** \param ostr the destination output stream
1209 ** \param pos a reference to the position to redirect
1211 inline std::ostream
&
1212 operator<< (std::ostream
& ostr
, const position
& pos
)
1215 ostr
<< *pos
.filename
<< ':';
1216 return ostr
<< pos
.line
<< '.' << pos
.column
;
1220 #endif // not BISON_POSITION_HH]
1222 b4_copyright([Location
class for Bison C
++ parsers
], [2002, 2003, 2004, 2005])[
1225 ** \file location.hh
1226 ** Define the location class.
1229 #ifndef BISON_LOCATION_HH
1230 # define BISON_LOCATION_HH
1232 # include <iostream>
1234 # include "position.hh"
1239 /// Abstract a location.
1242 /** \name Ctor & dtor.
1245 /// Construct a location.
1254 /** \name Line and Column related manipulators
1257 /// Reset initial location to final location.
1263 /// Extend the current location to the COUNT next columns.
1264 inline void columns (unsigned int count
= 1)
1269 /// Extend the current location to the COUNT next lines.
1270 inline void lines (unsigned int count
= 1)
1278 /// Beginning of the located region.
1280 /// End of the located region.
1284 /// Join two location objects to create a location.
1285 inline const location
operator+ (const location
& begin
, const location
& end
)
1287 location res
= begin
;
1292 /// Add two location objects.
1293 inline const location
operator+ (const location
& begin
, unsigned int width
)
1295 location res
= begin
;
1296 res
.columns (width
);
1300 /// Add and assign a location.
1301 inline location
& operator+= (location
& res
, unsigned int width
)
1303 res
.columns (width
);
1307 /** \brief Intercept output stream redirection.
1308 ** \param ostr the destination output stream
1309 ** \param loc a reference to the location to redirect
1311 ** Avoid duplicate information.
1313 inline std::ostream
& operator<< (std::ostream
& ostr
, const location
& loc
)
1315 position last
= loc
.end
- 1;
1318 && (!loc
.begin
.filename
1319 || *loc
.begin
.filename
!= *last
.filename
))
1320 ostr
<< '-' << last
;
1321 else if (loc
.begin
.line
!= last
.line
)
1322 ostr
<< '-' << last
.line
<< '.' << last
.column
;
1323 else if (loc
.begin
.column
!= last
.column
)
1324 ostr
<< '-' << last
.column
;
1330 #endif // not BISON_LOCATION_HH]