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; \
123 class ]b4_parser_class_name
[
125 /// Symbol semantic values.
126 typedef YYSTYPE semantic_type
;
127 /// Symbol locations.
128 typedef ]b4_location_type
[ location_type
;
131 /// Build a parser object.
132 ]b4_parser_class_name
[ (]b4_parse_param_decl
[) :
134 yycdebug_ (&std::cerr
)]b4_parse_param_cons
[
138 virtual ~]b4_parser_class_name
[ ()
143 /// \returns 0 iff parsing succeeded.
144 virtual int parse ();
146 /// The current debugging stream.
147 std::ostream
& debug_stream () const;
148 /// Set the current debugging stream.
149 void set_debug_stream (std::ostream
&);
151 /// Type for debugging levels.
152 typedef int debug_level_type
;
153 /// The current debugging level.
154 debug_level_type
debug_level () const;
155 /// Set the current debugging level.
156 void set_debug_level (debug_level_type l
);
159 /// Report a syntax error.
160 /// \param loc where the syntax error is found.
161 /// \param msg a description of the syntax error.
162 virtual void error (const location_type
& loc
, const std::string
& msg
);
164 /// Generate an error message.
165 /// \param tok the look-ahead token.
166 virtual std::string
yysyntax_error_ (YYERROR_VERBOSE_IF (int tok
));
169 /// \brief Report a symbol on the debug stream.
170 /// \param yytype The token type.
171 /// \param yyvaluep Its semantic value.
172 /// \param yylocationp Its location.
173 virtual void yysymprint_ (int yytype
,
174 const semantic_type
* yyvaluep
,
175 const location_type
* yylocationp
);
176 #endif /* ! YYDEBUG */
180 typedef int state_type
;
181 /// State stack type.
182 typedef stack
<state_type
> state_stack_type
;
183 /// Semantic value stack type.
184 typedef stack
<semantic_type
> semantic_stack_type
;
185 /// location stack type.
186 typedef stack
<location_type
> location_stack_type
;
189 state_stack_type yystate_stack_
;
190 /// The semantic value stack.
191 semantic_stack_type yysemantic_stack_
;
192 /// The location stack.
193 location_stack_type yylocation_stack_
;
195 /// Internal symbol numbers.
196 typedef ]b4_int_type_for([b4_translate
])[ token_number_type
;
198 /// For a state, the index in \a yytable_ of its portion.
199 static const ]b4_int_type_for([b4_pact
])[ yypact_
[];
200 static const ]b4_int_type(b4_pact_ninf
, b4_pact_ninf
)[ yypact_ninf_
;
202 /// For a state, default rule to reduce.
203 /// Unless\a yytable_ specifies something else to do.
204 /// Zero means the default is an error.
205 static const ]b4_int_type_for([b4_defact
])[ yydefact_
[];
207 static const ]b4_int_type_for([b4_pgoto
])[ yypgoto_
[];
208 static const ]b4_int_type_for([b4_defgoto
])[ yydefgoto_
[];
210 /// What to do in a state.
211 /// \a yytable_[yypact_[s]]: what to do in state \a s.
212 /// - if positive, shift that token.
213 /// - if negative, reduce the rule which number is the opposite.
214 /// - if zero, do what YYDEFACT says.
215 static const ]b4_int_type_for([b4_table
])[ yytable_
[];
216 static const ]b4_int_type(b4_table_ninf
, b4_table_ninf
)[ yytable_ninf_
;
218 static const ]b4_int_type_for([b4_check
])[ yycheck_
[];
220 /// For a state, its accessing symbol.
221 static const ]b4_int_type_for([b4_stos
])[ yystos_
[];
223 /// For a rule, its LHS.
224 static const ]b4_int_type_for([b4_r1
])[ yyr1_
[];
225 /// For a rule, its RHS length.
226 static const ]b4_int_type_for([b4_r2
])[ yyr2_
[];
228 #if YYDEBUG || YYERROR_VERBOSE || YYTOKEN_TABLE
229 /// For a symbol, its name in clear.
230 static const char* const yytname_
[];
234 /// Convert the symbol name \a n to a form suitable for a diagnostic.
235 virtual std::string
yytnamerr_ (const char *n
);
239 /// A type to store symbol numbers and -1.
240 typedef ]b4_int_type_for([b4_rhs
])[ rhs_number_type
;
241 /// A `-1'-separated list of the rules' RHS.
242 static const rhs_number_type yyrhs_
[];
243 /// For each rule, the index of the first RHS symbol in \a yyrhs_.
244 static const ]b4_int_type_for([b4_prhs
])[ yyprhs_
[];
245 /// For each rule, its source line number.
246 static const ]b4_int_type_for([b4_rline
])[ yyrline_
[];
247 /// For each scanner token number, its symbol number.
248 static const ]b4_int_type_for([b4_toknum
])[ yytoken_number_
[];
249 /// Report on the debug stream that the rule \a r is going to be reduced.
250 virtual void yyreduce_print_ (int r
);
251 /// Print the state stack on the debug stream.
252 virtual void yystack_print_ ();
255 /// Convert a scanner token number to a symbol number.
256 inline token_number_type
yytranslate_ (int token
);
258 /// \brief Reclaim the memory associated to a symbol.
259 /// \param yymsg Why this token is reclaimed.
260 /// \param yytype The symbol type.
261 /// \param yyvaluep Its semantic value.
262 /// \param yylocationp Its location.
263 inline void yydestruct_ (const char* yymsg
,
265 semantic_type
* yyvaluep
,
266 location_type
* yylocationp
);
268 /// Pop \a n symbols the three stacks.
269 inline void yypop_ (unsigned int n
= 1);
272 static const int yyeof_
;
273 /* LAST_ -- Last index in TABLE_. */
274 static const int yylast_
;
275 static const int yynnts_
;
276 static const int yyempty_
;
277 static const int yyfinal_
;
278 static const int yyterror_
;
279 static const int yyerrcode_
;
280 static const int yyntokens_
;
281 static const unsigned int yyuser_token_number_max_
;
282 static const token_number_type yyundef_token_
;
289 /* Error handling. */
295 std::ostream
* yycdebug_
;
297 ]b4_parse_param_vars
[
301 #endif /* ! defined PARSER_HEADER_H */]
303 @output @output_parser_name@
304 b4_copyright([C
++ Skeleton parser
for LALR(1) parsing with Bison
],
305 [2002, 2003, 2004, 2005])
306 m4_if(b4_prefix
[], [yy
], [],
308 // Take the name prefix into account.
309 #define yylex b4_prefix[]lex])
310 m4_if(b4_defines_flag
, 0, [],
312 #include @output_header_name@])[
317 # include <libintl.h> /* FIXME: INFRINGES ON USER NAME SPACE */
318 # define YY_(msgid) dgettext ("bison-runtime", msgid)
322 # define YY_(msgid) msgid
326 /* A pseudo ostream that takes yydebug_ into account. */
328 for (bool yydebugcond_ = yydebug_; yydebugcond_; yydebugcond_ = false) \
331 /* Enable debugging if requested. */
334 # define YY_SYMBOL_PRINT(Title, Type, Value, Location) \
338 *yycdebug_ << (Title) << ' '; \
339 yysymprint_ ((Type), (Value), (Location)); \
340 *yycdebug_ << std::endl; \
344 # define YY_REDUCE_PRINT(Rule) \
347 yyreduce_print_ (Rule); \
350 # define YY_STACK_PRINT() \
358 # define YY_SYMBOL_PRINT(Title, Type, Value, Location)
359 # define YY_REDUCE_PRINT(Rule)
360 # define YY_STACK_PRINT()
362 #endif /* !YYDEBUG */
364 #define YYACCEPT goto yyacceptlab
365 #define YYABORT goto yyabortlab
366 #define YYERROR goto yyerrorlab
370 /* Return YYSTR after stripping away unnecessary quotes and
371 backslashes, so that it's suitable for yyerror. The heuristic is
372 that double-quoting is unnecessary unless the string contains an
373 apostrophe, a comma, or backslash (other than backslash-backslash).
374 YYSTR is taken from yytname. */
376 yy::]b4_parser_class_name
[::yytnamerr_ (const char *yystr
)
380 std::string yyr
= "";
381 char const *yyp
= yystr
;
388 goto do_not_strip_quotes
;
392 goto do_not_strip_quotes
;
401 do_not_strip_quotes
: ;
410 /*--------------------------------.
411 | Print this symbol on YYOUTPUT. |
412 `--------------------------------*/
415 yy::]b4_parser_class_name
[::yysymprint_ (int yytype
,
416 const semantic_type
* yyvaluep
, const location_type
* yylocationp
)
418 /* Pacify ``unused variable'' warnings. */
421 /* Backward compatibility, but should be removed eventually. */
422 std::ostream
& cdebug_
= *yycdebug_
;
425 *yycdebug_
<< (yytype
< yyntokens_
? "token" : "nterm")
426 << ' ' << yytname_
[yytype
] << " ("
427 << *yylocationp
<< ": ";
430 ]m4_map([b4_symbol_actions
], m4_defn([b4_symbol_printers
]))dnl
436 #endif /* ! YYDEBUG */
439 yy::]b4_parser_class_name
[::yydestruct_ (const char* yymsg
,
440 int yytype
, semantic_type
* yyvaluep
, location_type
* yylocationp
)
442 /* Pacify ``unused variable'' warnings. */
447 YY_SYMBOL_PRINT (yymsg
, yytype
, yyvaluep
, yylocationp
);
451 ]m4_map([b4_symbol_actions
], m4_defn([b4_symbol_destructors
]))[
458 yy::]b4_parser_class_name
[::yypop_ (unsigned int n
)
460 yystate_stack_
.pop (n
);
461 yysemantic_stack_
.pop (n
);
462 yylocation_stack_
.pop (n
);
466 yy::]b4_parser_class_name
[::debug_stream () const
472 yy::]b4_parser_class_name
[::set_debug_stream (std::ostream
& o
)
478 yy::]b4_parser_class_name
[::debug_level_type
479 yy::]b4_parser_class_name
[::debug_level () const
485 yy::]b4_parser_class_name
[::set_debug_level (debug_level_type l
)
492 yy::]b4_parser_class_name
[::parse ()
494 /// Look-ahead and look-ahead in internal form.
498 /// Semantic value of the look-ahead.
499 semantic_type yylval
;
500 /// Location of the look-ahead.
501 location_type yylloc
;
502 /// The locations where the error started and ended.
503 location yyerror_range
[2];
512 YYCDEBUG
<< "Starting parse" << std::endl
;
521 ]m4_ifdef([b4_initial_action
], [
522 m4_pushdef([b4_at_dollar
], [yylloc
])dnl
523 m4_pushdef([b4_dollar_dollar
], [yylval
])dnl
524 /* User initialization code. */
526 m4_popdef([b4_dollar_dollar
])dnl
527 m4_popdef([b4_at_dollar
])dnl
528 /* Line __line__ of yacc.c. */
529 b4_syncline([@oline@
], [@ofile@
])])dnl
531 [ /* Initialize the stacks. The initial state will be pushed in
532 yynewstate, since the latter expects the semantical and the
533 location values to have been already stored, initialize these
534 stacks with a primary value. */
535 yystate_stack_
= state_stack_type (0);
536 yysemantic_stack_
= semantic_stack_type (0);
537 yylocation_stack_
= location_stack_type (0);
538 yysemantic_stack_
.push (yylval
);
539 yylocation_stack_
.push (yylloc
);
543 yystate_stack_
.push (yystate_
);
544 YYCDEBUG
<< "Entering state " << yystate_
<< std::endl
;
550 /* Try to take a decision without look-ahead. */
551 yyn_
= yypact_
[yystate_
];
552 if (yyn_
== yypact_ninf_
)
555 /* Read a look-ahead token. */
556 if (yychar
== yyempty_
)
558 YYCDEBUG
<< "Reading a token: ";
559 yychar
= ]b4_c_function_call([yylex
], [int],
560 [[YYSTYPE
*], [&yylval
]][]dnl
561 b4_location_if([, [[location
*], [&yylloc
]]])dnl
562 m4_ifdef([b4_lex_param
], [, ]b4_lex_param
))[;
566 /* Convert token to internal form. */
567 if (yychar
<= yyeof_
)
569 yychar
= yytoken
= yyeof_
;
570 YYCDEBUG
<< "Now at end of input." << std::endl
;
574 yytoken
= yytranslate_ (yychar
);
575 YY_SYMBOL_PRINT ("Next token is", yytoken
, &yylval
, &yylloc
);
578 /* If the proper action on seeing token ILOOKA_ is to reduce or to
579 detect an error, take that action. */
581 if (yyn_
< 0 || yylast_
< yyn_
|| yycheck_
[yyn_
] != yytoken
)
584 /* Reduce or error. */
585 yyn_
= yytable_
[yyn_
];
588 if (yyn_
== yytable_ninf_
)
600 if (yyn_
== yyfinal_
)
603 /* Shift the look-ahead token. */
604 YY_SYMBOL_PRINT ("Shifting", yytoken
, &yylval
, &yylloc
);
606 /* Discard the token being shifted unless it is eof. */
607 if (yychar
!= yyeof_
)
610 yysemantic_stack_
.push (yylval
);
611 yylocation_stack_
.push (yylloc
);
613 /* Count tokens shifted since error; after three, turn off error
621 /*-----------------------------------------------------------.
622 | yydefault -- do the default action for the current state. |
623 `-----------------------------------------------------------*/
625 yyn_
= yydefact_
[yystate_
];
630 /*-----------------------------.
631 | yyreduce -- Do a reduction. |
632 `-----------------------------*/
634 yylen_
= yyr2_
[yyn_
];
635 /* If LEN_ is nonzero, implement the default value of the action:
636 `$$ = $1'. Otherwise, use the top of the stack.
638 Otherwise, the following line sets YYVAL to garbage.
639 This behavior is undocumented and Bison
640 users should not rely upon it. */
642 yyval
= yysemantic_stack_
[yylen_
- 1];
644 yyval
= yysemantic_stack_
[0];
647 slice
<location_type
, location_stack_type
> slice (yylocation_stack_
, yylen_
);
648 YYLLOC_DEFAULT (yyloc
, slice
, yylen_
);
650 YY_REDUCE_PRINT (yyn_
);
657 ]/* Line __line__ of lalr1.cc. */
658 b4_syncline([@oline@
], [@ofile@
])[
664 yysemantic_stack_
.push (yyval
);
665 yylocation_stack_
.push (yyloc
);
667 /* Shift the result of the reduction. */
669 yystate_
= yypgoto_
[yyn_
- yyntokens_
] + yystate_stack_
[0];
670 if (0 <= yystate_
&& yystate_
<= yylast_
671 && yycheck_
[yystate_
] == yystate_stack_
[0])
672 yystate_
= yytable_
[yystate_
];
674 yystate_
= yydefgoto_
[yyn_
- yyntokens_
];
677 /*------------------------------------.
678 | yyerrlab -- here on detecting error |
679 `------------------------------------*/
681 /* If not already recovering from an error, report this error. */
685 error (yylloc
, yysyntax_error_ (YYERROR_VERBOSE_IF (yytoken
)));
688 yyerror_range
[0] = yylloc
;
689 if (yyerrstatus_
== 3)
691 /* If just tried and failed to reuse look-ahead token after an
692 error, discard it. */
694 if (yychar
<= yyeof_
)
696 /* Return failure if at end of input. */
697 if (yychar
== yyeof_
)
702 yydestruct_ ("Error: discarding", yytoken
, &yylval
, &yylloc
);
707 /* Else will try to reuse look-ahead token after shifting the error
712 /*---------------------------------------------------.
713 | yyerrorlab -- error raised explicitly by YYERROR. |
714 `---------------------------------------------------*/
717 /* Pacify compilers like GCC when the user code never invokes
718 YYERROR and the label yyerrorlab therefore never appears in user
723 yyerror_range
[0] = yylocation_stack_
[yylen_
- 1];
725 yystate_
= yystate_stack_
[0];
728 /*-------------------------------------------------------------.
729 | yyerrlab1 -- common code for both syntax error and YYERROR. |
730 `-------------------------------------------------------------*/
732 yyerrstatus_
= 3; /* Each real token shifted decrements this. */
736 yyn_
= yypact_
[yystate_
];
737 if (yyn_
!= yypact_ninf_
)
740 if (0 <= yyn_
&& yyn_
<= yylast_
&& yycheck_
[yyn_
] == yyterror_
)
742 yyn_
= yytable_
[yyn_
];
748 /* Pop the current state because it cannot handle the error token. */
749 if (yystate_stack_
.height () == 1)
752 yyerror_range
[0] = yylocation_stack_
[0];
753 yydestruct_ ("Error: popping",
755 &yysemantic_stack_
[0], &yylocation_stack_
[0]);
757 yystate_
= yystate_stack_
[0];
761 if (yyn_
== yyfinal_
)
764 yyerror_range
[1] = yylloc
;
765 // Using YYLLOC is tempting, but would change the location of
766 // the look-ahead. YYLOC is available though.
767 YYLLOC_DEFAULT (yyloc
, yyerror_range
- 1, 2);
768 yysemantic_stack_
.push (yylval
);
769 yylocation_stack_
.push (yyloc
);
771 /* Shift the error token. */
772 YY_SYMBOL_PRINT ("Shifting", yystos_
[yyn_
],
773 &yysemantic_stack_
[0], &yylocation_stack_
[0]);
789 if (yychar
!= yyeof_
&& yychar
!= yyempty_
)
790 yydestruct_ ("Cleanup: discarding lookahead", yytoken
, &yylval
, &yylloc
);
792 while (yystate_stack_
.height () != 1)
794 yydestruct_ ("Cleanup: popping",
795 yystos_
[yystate_stack_
[0]],
796 &yysemantic_stack_
[0],
797 &yylocation_stack_
[0]);
804 // Generate an error message.
806 yy::]b4_parser_class_name
[::yysyntax_error_ (YYERROR_VERBOSE_IF (int tok
))
810 yyn_
= yypact_
[yystate_
];
811 if (yypact_ninf_
< yyn_
&& yyn_
< yylast_
)
813 /* Start YYX at -YYN if negative to avoid negative indexes in
815 int yyxbegin
= yyn_
< 0 ? -yyn_
: 0;
817 /* Stay within bounds of both yycheck and yytname. */
818 int yychecklim
= yylast_
- yyn_
;
819 int yyxend
= yychecklim
< yyntokens_
? yychecklim
: yyntokens_
;
821 for (int x
= yyxbegin
; x
< yyxend
; ++x
)
822 if (yycheck_
[x
+ yyn_
] == x
&& x
!= yyterror_
)
825 // FIXME: This method of building the message is not compatible
826 // with internationalization. It should work like yacc.c does it.
827 // That is, first build a string that looks like this:
828 // "syntax error, unexpected %s or %s or %s"
829 // Then, invoke YY_ on this string.
830 // Finally, use the string as a format to output
831 // yytname_[tok], etc.
832 // Until this gets fixed, this message appears in English only.
833 res
= "syntax error, unexpected ";
834 res
+= yytnamerr_ (yytname_
[tok
]);
838 for (int x
= yyxbegin
; x
< yyxend
; ++x
)
839 if (yycheck_
[x
+ yyn_
] == x
&& x
!= yyterror_
)
841 res
+= (!count
++) ? ", expecting " : " or ";
842 res
+= yytnamerr_ (yytname_
[x
]);
848 res
= YY_("syntax error");
853 /* YYPACT[STATE-NUM] -- Index in YYTABLE of the portion describing
855 const ]b4_int_type(b4_pact_ninf
, b4_pact_ninf
) yy::b4_parser_class_name::yypact_ninf_
= b4_pact_ninf
[;
856 const ]b4_int_type_for([b4_pact
])[
857 yy::]b4_parser_class_name
[::yypact_
[] =
862 /* YYDEFACT[S] -- default rule to reduce with in state S when YYTABLE
863 doesn't specify something else to do. Zero means the default is an
865 const ]b4_int_type_for([b4_defact
])[
866 yy::]b4_parser_class_name
[::yydefact_
[] =
871 /* YYPGOTO[NTERM-NUM]. */
872 const ]b4_int_type_for([b4_pgoto
])[
873 yy::]b4_parser_class_name
[::yypgoto_
[] =
878 /* YYDEFGOTO[NTERM-NUM]. */
879 const ]b4_int_type_for([b4_defgoto
])[
880 yy::]b4_parser_class_name
[::yydefgoto_
[] =
885 /* YYTABLE[YYPACT[STATE-NUM]]. What to do in state STATE-NUM. If
886 positive, shift that token. If negative, reduce the rule which
887 number is the opposite. If zero, do what YYDEFACT says. */
888 const ]b4_int_type(b4_table_ninf
, b4_table_ninf
) yy::b4_parser_class_name::yytable_ninf_
= b4_table_ninf
[;
889 const ]b4_int_type_for([b4_table
])[
890 yy::]b4_parser_class_name
[::yytable_
[] =
896 const ]b4_int_type_for([b4_check
])[
897 yy::]b4_parser_class_name
[::yycheck_
[] =
902 /* STOS_[STATE-NUM] -- The (internal number of the) accessing
903 symbol of state STATE-NUM. */
904 const ]b4_int_type_for([b4_stos
])[
905 yy::]b4_parser_class_name
[::yystos_
[] =
911 /* TOKEN_NUMBER_[YYLEX-NUM] -- Internal symbol number corresponding
913 const ]b4_int_type_for([b4_toknum
])[
914 yy::]b4_parser_class_name
[::yytoken_number_
[] =
920 /* YYR1[YYN] -- Symbol number of symbol that rule YYN derives. */
921 const ]b4_int_type_for([b4_r1
])[
922 yy::]b4_parser_class_name
[::yyr1_
[] =
927 /* YYR2[YYN] -- Number of symbols composing right hand side of rule YYN. */
928 const ]b4_int_type_for([b4_r2
])[
929 yy::]b4_parser_class_name
[::yyr2_
[] =
934 #if YYDEBUG || YYERROR_VERBOSE || YYTOKEN_TABLE
935 /* YYTNAME[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM.
936 First, the terminals, then, starting at \a yyntokens_, nonterminals. */
938 const yy::]b4_parser_class_name
[::yytname_
[] =
945 /* YYRHS -- A `-1'-separated list of the rules' RHS. */
946 const yy::]b4_parser_class_name
[::rhs_number_type
947 yy::]b4_parser_class_name
[::yyrhs_
[] =
952 /* YYPRHS[YYN] -- Index of the first RHS symbol of rule number YYN in
954 const ]b4_int_type_for([b4_prhs
])[
955 yy::]b4_parser_class_name
[::yyprhs_
[] =
960 /* YYRLINE[YYN] -- Source line where rule number YYN was defined. */
961 const ]b4_int_type_for([b4_rline
])[
962 yy::]b4_parser_class_name
[::yyrline_
[] =
967 // Print the state stack on the debug stream.
969 yy::]b4_parser_class_name
[::yystack_print_ ()
971 *yycdebug_
<< "Stack now";
972 for (state_stack_type::const_iterator i
= yystate_stack_
.begin ();
973 i
!= yystate_stack_
.end (); ++i
)
974 *yycdebug_
<< ' ' << *i
;
975 *yycdebug_
<< std::endl
;
978 // Report on the debug stream that the rule \a yyrule is going to be reduced.
980 yy::]b4_parser_class_name
[::yyreduce_print_ (int yyrule
)
982 unsigned int yylno
= yyrline_
[yyrule
];
983 /* Print the symbols being reduced, and their result. */
984 *yycdebug_
<< "Reducing stack by rule " << yyn_
- 1
985 << " (line " << yylno
<< "), ";
986 for (]b4_int_type_for([b4_prhs
])[ i
= yyprhs_
[yyn_
];
988 *yycdebug_
<< yytname_
[yyrhs_
[i
]] << ' ';
989 *yycdebug_
<< "-> " << yytname_
[yyr1_
[yyn_
]] << std::endl
;
993 /* YYTRANSLATE(YYLEX) -- Bison symbol number corresponding to YYLEX. */
994 yy::]b4_parser_class_name
[::token_number_type
995 yy::]b4_parser_class_name
[::yytranslate_ (int token
)
998 const token_number_type
1003 if ((unsigned int) token
<= yyuser_token_number_max_
)
1004 return translate_table
[token
];
1006 return yyundef_token_
;
1009 const int yy::]b4_parser_class_name
[::yyeof_
= 0;
1010 const int yy::]b4_parser_class_name
[::yylast_
= ]b4_last
[;
1011 const int yy::]b4_parser_class_name
[::yynnts_
= ]b4_nterms_number
[;
1012 const int yy::]b4_parser_class_name
[::yyempty_
= -2;
1013 const int yy::]b4_parser_class_name
[::yyfinal_
= ]b4_final_state_number
[;
1014 const int yy::]b4_parser_class_name
[::yyterror_
= 1;
1015 const int yy::]b4_parser_class_name
[::yyerrcode_
= 256;
1016 const int yy::]b4_parser_class_name
[::yyntokens_
= ]b4_tokens_number
[;
1018 const unsigned int yy::]b4_parser_class_name
[::yyuser_token_number_max_
= ]b4_user_token_number_max
[;
1019 const yy::]b4_parser_class_name
[::token_number_type
yy::]b4_parser_class_name
[::yyundef_token_
= ]b4_undef_token_number
[;
1024 b4_copyright([stack handling
for Bison C
++ parsers
], [2002, 2003, 2004, 2005])[
1026 #ifndef BISON_STACK_HH
1027 # define BISON_STACK_HH
1033 template <class T
, class S
= std::deque
<T
> >
1038 // Hide our reversed order.
1039 typedef typename
S::reverse_iterator iterator
;
1040 typedef typename
S::const_reverse_iterator const_iterator
;
1046 stack (unsigned int n
) : seq_ (n
)
1052 operator [] (unsigned int i
)
1059 operator [] (unsigned int i
) const
1068 seq_
.push_front (t
);
1073 pop (unsigned int n
= 1)
1083 return seq_
.size ();
1086 inline const_iterator
begin () const { return seq_
.rbegin (); }
1087 inline const_iterator
end () const { return seq_
.rend (); }
1094 /// Present a slice of the top of a stack.
1095 template <class T
, class S
= stack
<T
> >
1100 slice (const S
& stack
,
1101 unsigned int range
) : stack_ (stack
),
1108 operator [] (unsigned int i
) const
1110 return stack_
[range_
- i
];
1116 unsigned int range_
;
1120 #endif // not BISON_STACK_HH]
1123 b4_copyright([Position
class for Bison C
++ parsers
], [2002, 2003, 2004, 2005])[
1126 ** \file position.hh
1127 ** Define the position class.
1130 #ifndef BISON_POSITION_HH
1131 # define BISON_POSITION_HH
1133 # include <iostream>
1138 /// Abstract a position.
1142 /// Initial column number.
1143 static const unsigned int initial_column
= 0;
1144 /// Initial line number.
1145 static const unsigned int initial_line
= 1;
1147 /** \name Ctor & dtor.
1150 /// Construct a position.
1153 line (initial_line
),
1154 column (initial_column
)
1160 /** \name Line and Column related manipulators
1163 /// (line related) Advance to the COUNT next lines.
1164 inline void lines (int count
= 1)
1166 column
= initial_column
;
1170 /// (column related) Advance to the COUNT next columns.
1171 inline void columns (int count
= 1)
1173 int leftmost
= initial_column
;
1174 int current
= column
;
1175 if (leftmost
<= current
+ count
)
1178 column
= initial_column
;
1183 /// File name to which this position refers.
1184 ]b4_filename_type
[* filename
;
1185 /// Current line number.
1187 /// Current column number.
1188 unsigned int column
;
1191 /// Add and assign a position.
1192 inline const position
&
1193 operator+= (position
& res
, const int width
)
1195 res
.columns (width
);
1199 /// Add two position objects.
1200 inline const position
1201 operator+ (const position
& begin
, const int width
)
1203 position res
= begin
;
1204 return res
+= width
;
1207 /// Add and assign a position.
1208 inline const position
&
1209 operator-= (position
& res
, const int width
)
1211 return res
+= -width
;
1214 /// Add two position objects.
1215 inline const position
1216 operator- (const position
& begin
, const int width
)
1218 return begin
+ -width
;
1221 /** \brief Intercept output stream redirection.
1222 ** \param ostr the destination output stream
1223 ** \param pos a reference to the position to redirect
1225 inline std::ostream
&
1226 operator<< (std::ostream
& ostr
, const position
& pos
)
1229 ostr
<< *pos
.filename
<< ':';
1230 return ostr
<< pos
.line
<< '.' << pos
.column
;
1234 #endif // not BISON_POSITION_HH]
1236 b4_copyright([Location
class for Bison C
++ parsers
], [2002, 2003, 2004, 2005])[
1239 ** \file location.hh
1240 ** Define the location class.
1243 #ifndef BISON_LOCATION_HH
1244 # define BISON_LOCATION_HH
1246 # include <iostream>
1248 # include "position.hh"
1253 /// Abstract a location.
1256 /** \name Ctor & dtor.
1259 /// Construct a location.
1268 /** \name Line and Column related manipulators
1271 /// Reset initial location to final location.
1277 /// Extend the current location to the COUNT next columns.
1278 inline void columns (unsigned int count
= 1)
1283 /// Extend the current location to the COUNT next lines.
1284 inline void lines (unsigned int count
= 1)
1292 /// Beginning of the located region.
1294 /// End of the located region.
1298 /// Join two location objects to create a location.
1299 inline const location
operator+ (const location
& begin
, const location
& end
)
1301 location res
= begin
;
1306 /// Add two location objects.
1307 inline const location
operator+ (const location
& begin
, unsigned int width
)
1309 location res
= begin
;
1310 res
.columns (width
);
1314 /// Add and assign a location.
1315 inline location
& operator+= (location
& res
, unsigned int width
)
1317 res
.columns (width
);
1321 /** \brief Intercept output stream redirection.
1322 ** \param ostr the destination output stream
1323 ** \param loc a reference to the location to redirect
1325 ** Avoid duplicate information.
1327 inline std::ostream
& operator<< (std::ostream
& ostr
, const location
& loc
)
1329 position last
= loc
.end
- 1;
1332 && (!loc
.begin
.filename
1333 || *loc
.begin
.filename
!= *last
.filename
))
1334 ostr
<< '-' << last
;
1335 else if (loc
.begin
.line
!= last
.line
)
1336 ostr
<< '-' << last
.line
<< '.' << last
.column
;
1337 else if (loc
.begin
.column
!= last
.column
)
1338 ostr
<< '-' << last
.column
;
1344 #endif // not BISON_LOCATION_HH]