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 dnl FIXME
: This is wrong
, we want computed header guards
.
32 dnl FIXME
: I don
\'t know why the macros are missing now
. :(
34 #ifndef PARSER_HEADER_H
35 # define PARSER_HEADER_H
40 #include "location.hh"
42 /* Using locations. */
43 #define YYLSP_NEEDED ]b4_locations_flag[
45 /* First part of user declarations. */
48 ]/* Line __line__ of lalr1.cc. */
49 b4_syncline([@oline@
], [@ofile@
])[
51 /* Enabling traces. */
53 # define YYDEBUG ]b4_debug[
56 /* Enabling verbose error messages. */
57 #ifdef YYERROR_VERBOSE
58 # undef YYERROR_VERBOSE
59 # define YYERROR_VERBOSE 1
61 # define YYERROR_VERBOSE ]b4_error_verbose[
64 /* Enabling the token table. */
66 # define YYTOKEN_TABLE ]b4_token_table[
69 /* YYLLOC_DEFAULT -- Set CURRENT to span from RHS[1] to RHS[N].
70 If N is 0, then set CURRENT to the empty location which ends
71 the previous symbol: RHS[0] (always defined). */
73 #ifndef YYLLOC_DEFAULT
74 # define YYLLOC_DEFAULT(Current, Rhs, N) \
78 (Current).begin = (Rhs)[1].begin; \
79 (Current).end = (Rhs)[N].end; \
83 (Current).begin = (Current).end = (Rhs)[0].end; \
92 class ]b4_parser_class_name
[
95 /// Symbol semantic values.
96 #if ! defined (YYSTYPE)
98 [b4_syncline([b4_stype_line
], [b4_file_name
])
99 union semantic_type b4_stype
;
100 /* Line __line__ of lalr1.cc. */
101 b4_syncline([@oline@
], [@ofile@
])],
102 [ typedef int semantic_type
;])[
104 typedef YYSTYPE semantic_type
;
106 /// Symbol locations.
107 typedef ]b4_location_type
[ location_type
;
111 ]b4_token_enums(b4_tokens
)[
114 /// Build a parser object.
115 ]b4_parser_class_name
[ (]b4_parse_param_decl
[) :
117 yycdebug_ (&std::cerr
)]b4_parse_param_cons
[
121 virtual ~]b4_parser_class_name
[ ()
126 /// \returns 0 iff parsing succeeded.
127 virtual int parse ();
129 /// The current debugging stream.
130 std::ostream
& debug_stream () const;
131 /// Set the current debugging stream.
132 void set_debug_stream (std::ostream
&);
134 /// Type for debugging levels.
135 typedef int debug_level_type
;
136 /// The current debugging level.
137 debug_level_type
debug_level () const;
138 /// Set the current debugging level.
139 void set_debug_level (debug_level_type l
);
142 /// Report a syntax error.
143 /// \param loc where the syntax error is found.
144 /// \param msg a description of the syntax error.
145 virtual void error (const location_type
& loc
, const std::string
& msg
);
147 /// Generate an error message.
148 /// \param state the state where the error occurred.
149 /// \param tok the look-ahead token.
150 virtual std::string
yysyntax_error_ (int yystate
]dnl
151 b4_error_verbose_if([, int tok
])[);
154 /// \brief Report a symbol on the debug stream.
155 /// \param yytype The token type.
156 /// \param yyvaluep Its semantic value.
157 /// \param yylocationp Its location.
158 virtual void yysymprint_ (int yytype
,
159 const semantic_type
* yyvaluep
,
160 const location_type
* yylocationp
);
161 #endif /* ! YYDEBUG */
165 typedef int state_type
;
166 /// State stack type.
167 typedef stack
<state_type
> state_stack_type
;
168 /// Semantic value stack type.
169 typedef stack
<semantic_type
> semantic_stack_type
;
170 /// location stack type.
171 typedef stack
<location_type
> location_stack_type
;
174 state_stack_type yystate_stack_
;
175 /// The semantic value stack.
176 semantic_stack_type yysemantic_stack_
;
177 /// The location stack.
178 location_stack_type yylocation_stack_
;
180 /// Internal symbol numbers.
181 typedef ]b4_int_type_for([b4_translate
])[ token_number_type
;
183 /// For a state, the index in \a yytable_ of its portion.
184 static const ]b4_int_type_for([b4_pact
])[ yypact_
[];
185 static const ]b4_int_type(b4_pact_ninf
, b4_pact_ninf
)[ yypact_ninf_
;
187 /// For a state, default rule to reduce.
188 /// Unless\a yytable_ specifies something else to do.
189 /// Zero means the default is an error.
190 static const ]b4_int_type_for([b4_defact
])[ yydefact_
[];
192 static const ]b4_int_type_for([b4_pgoto
])[ yypgoto_
[];
193 static const ]b4_int_type_for([b4_defgoto
])[ yydefgoto_
[];
195 /// What to do in a state.
196 /// \a yytable_[yypact_[s]]: what to do in state \a s.
197 /// - if positive, shift that token.
198 /// - if negative, reduce the rule which number is the opposite.
199 /// - if zero, do what YYDEFACT says.
200 static const ]b4_int_type_for([b4_table
])[ yytable_
[];
201 static const ]b4_int_type(b4_table_ninf
, b4_table_ninf
)[ yytable_ninf_
;
203 static const ]b4_int_type_for([b4_check
])[ yycheck_
[];
205 /// For a state, its accessing symbol.
206 static const ]b4_int_type_for([b4_stos
])[ yystos_
[];
208 /// For a rule, its LHS.
209 static const ]b4_int_type_for([b4_r1
])[ yyr1_
[];
210 /// For a rule, its RHS length.
211 static const ]b4_int_type_for([b4_r2
])[ yyr2_
[];
213 #if YYDEBUG || YYERROR_VERBOSE || YYTOKEN_TABLE
214 /// For a symbol, its name in clear.
215 static const char* const yytname_
[];
219 /// Convert the symbol name \a n to a form suitable for a diagnostic.
220 virtual std::string
yytnamerr_ (const char *n
);
224 /// A type to store symbol numbers and -1.
225 typedef ]b4_int_type_for([b4_rhs
])[ rhs_number_type
;
226 /// A `-1'-separated list of the rules' RHS.
227 static const rhs_number_type yyrhs_
[];
228 /// For each rule, the index of the first RHS symbol in \a yyrhs_.
229 static const ]b4_int_type_for([b4_prhs
])[ yyprhs_
[];
230 /// For each rule, its source line number.
231 static const ]b4_int_type_for([b4_rline
])[ yyrline_
[];
232 /// For each scanner token number, its symbol number.
233 static const ]b4_int_type_for([b4_toknum
])[ yytoken_number_
[];
234 /// Report on the debug stream that the rule \a r is going to be reduced.
235 virtual void yyreduce_print_ (int r
);
236 /// Print the state stack on the debug stream.
237 virtual void yystack_print_ ();
240 /// Convert a scanner token number to a symbol number.
241 inline token_number_type
yytranslate_ (int token
);
243 /// \brief Reclaim the memory associated to a symbol.
244 /// \param yymsg Why this token is reclaimed.
245 /// \param yytype The symbol type.
246 /// \param yyvaluep Its semantic value.
247 /// \param yylocationp Its location.
248 inline void yydestruct_ (const char* yymsg
,
250 semantic_type
* yyvaluep
,
251 location_type
* yylocationp
);
253 /// Pop \a n symbols the three stacks.
254 inline void yypop_ (unsigned int n
= 1);
257 static const int yyeof_
;
258 /* LAST_ -- Last index in TABLE_. */
259 static const int yylast_
;
260 static const int yynnts_
;
261 static const int yyempty_
;
262 static const int yyfinal_
;
263 static const int yyterror_
;
264 static const int yyerrcode_
;
265 static const int yyntokens_
;
266 static const unsigned int yyuser_token_number_max_
;
267 static const token_number_type yyundef_token_
;
271 std::ostream
* yycdebug_
;
273 ]b4_parse_param_vars
[
277 ]m4_ifset([b4_global_tokens_and_yystype
],
278 [b4_token_defines(b4_tokens
)
281 /* Redirection for backward compatibility. */
282 # define YYSTYPE yy::b4_parser_class_name::semantic_type
285 #endif /* ! defined PARSER_HEADER_H */]
287 @output @output_parser_name@
288 b4_copyright([C
++ Skeleton parser
for LALR(1) parsing with Bison
],
289 [2002, 2003, 2004, 2005])
290 m4_if(b4_prefix
[], [yy
], [],
292 // Take the name prefix into account.
293 #define yylex b4_prefix[]lex])
294 m4_if(b4_defines_flag
, 0, [],
296 #include @output_header_name@])[
298 /* User implementation prologue. */
301 ]/* Line __line__ of lalr1.cc. */
302 b4_syncline([@oline@
], [@ofile@
])[
307 # include <libintl.h> /* FIXME: INFRINGES ON USER NAME SPACE */
308 # define YY_(msgid) dgettext ("bison-runtime", msgid)
312 # define YY_(msgid) msgid
316 /* A pseudo ostream that takes yydebug_ into account. */
318 for (bool yydebugcond_ = yydebug_; yydebugcond_; yydebugcond_ = false) \
321 /* Enable debugging if requested. */
324 # define YY_SYMBOL_PRINT(Title, Type, Value, Location) \
328 *yycdebug_ << (Title) << ' '; \
329 yysymprint_ ((Type), (Value), (Location)); \
330 *yycdebug_ << std::endl; \
334 # define YY_REDUCE_PRINT(Rule) \
337 yyreduce_print_ (Rule); \
340 # define YY_STACK_PRINT() \
348 # define YY_SYMBOL_PRINT(Title, Type, Value, Location)
349 # define YY_REDUCE_PRINT(Rule)
350 # define YY_STACK_PRINT()
352 #endif /* !YYDEBUG */
354 #define YYACCEPT goto yyacceptlab
355 #define YYABORT goto yyabortlab
356 #define YYERROR goto yyerrorlab
360 /* Return YYSTR after stripping away unnecessary quotes and
361 backslashes, so that it's suitable for yyerror. The heuristic is
362 that double-quoting is unnecessary unless the string contains an
363 apostrophe, a comma, or backslash (other than backslash-backslash).
364 YYSTR is taken from yytname. */
366 yy::]b4_parser_class_name
[::yytnamerr_ (const char *yystr
)
370 std::string yyr
= "";
371 char const *yyp
= yystr
;
378 goto do_not_strip_quotes
;
382 goto do_not_strip_quotes
;
391 do_not_strip_quotes
: ;
400 /*--------------------------------.
401 | Print this symbol on YYOUTPUT. |
402 `--------------------------------*/
405 yy::]b4_parser_class_name
[::yysymprint_ (int yytype
,
406 const semantic_type
* yyvaluep
, const location_type
* yylocationp
)
408 /* Pacify ``unused variable'' warnings. */
411 /* Backward compatibility, but should be removed eventually. */
412 std::ostream
& cdebug_
= *yycdebug_
;
415 *yycdebug_
<< (yytype
< yyntokens_
? "token" : "nterm")
416 << ' ' << yytname_
[yytype
] << " ("
417 << *yylocationp
<< ": ";
420 ]m4_map([b4_symbol_actions
], m4_defn([b4_symbol_printers
]))dnl
426 #endif /* ! YYDEBUG */
429 yy::]b4_parser_class_name
[::yydestruct_ (const char* yymsg
,
430 int yytype
, semantic_type
* yyvaluep
, location_type
* yylocationp
)
432 /* Pacify ``unused variable'' warnings. */
437 YY_SYMBOL_PRINT (yymsg
, yytype
, yyvaluep
, yylocationp
);
441 ]m4_map([b4_symbol_actions
], m4_defn([b4_symbol_destructors
]))[
448 yy::]b4_parser_class_name
[::yypop_ (unsigned int n
)
450 yystate_stack_
.pop (n
);
451 yysemantic_stack_
.pop (n
);
452 yylocation_stack_
.pop (n
);
456 yy::]b4_parser_class_name
[::debug_stream () const
462 yy::]b4_parser_class_name
[::set_debug_stream (std::ostream
& o
)
468 yy::]b4_parser_class_name
[::debug_level_type
469 yy::]b4_parser_class_name
[::debug_level () const
475 yy::]b4_parser_class_name
[::set_debug_level (debug_level_type l
)
482 yy::]b4_parser_class_name
[::parse ()
484 /// Look-ahead and look-ahead in internal form.
485 int yychar
= yyempty_
;
493 /* Error handling. */
495 int yyerrstatus_
= 0;
497 /// Semantic value of the look-ahead.
498 semantic_type yylval
;
499 /// Location of the look-ahead.
500 location_type yylloc
;
501 /// The locations where the error started and ended.
502 location yyerror_range
[2];
511 YYCDEBUG
<< "Starting parse" << std::endl
;
513 ]m4_ifdef([b4_initial_action
], [
514 m4_pushdef([b4_at_dollar
], [yylloc
])dnl
515 m4_pushdef([b4_dollar_dollar
], [yylval
])dnl
516 /* User initialization code. */
518 m4_popdef([b4_dollar_dollar
])dnl
519 m4_popdef([b4_at_dollar
])dnl
520 /* Line __line__ of yacc.c. */
521 b4_syncline([@oline@
], [@ofile@
])])dnl
523 [ /* Initialize the stacks. The initial state will be pushed in
524 yynewstate, since the latter expects the semantical and the
525 location values to have been already stored, initialize these
526 stacks with a primary value. */
527 yystate_stack_
= state_stack_type (0);
528 yysemantic_stack_
= semantic_stack_type (0);
529 yylocation_stack_
= location_stack_type (0);
530 yysemantic_stack_
.push (yylval
);
531 yylocation_stack_
.push (yylloc
);
535 yystate_stack_
.push (yystate
);
536 YYCDEBUG
<< "Entering state " << yystate
<< std::endl
;
542 /* Try to take a decision without look-ahead. */
543 yyn
= yypact_
[yystate
];
544 if (yyn
== yypact_ninf_
)
547 /* Read a look-ahead token. */
548 if (yychar
== yyempty_
)
550 YYCDEBUG
<< "Reading a token: ";
551 yychar
= ]b4_c_function_call([yylex
], [int],
552 [[YYSTYPE
*], [&yylval
]][]dnl
553 b4_location_if([, [[location
*], [&yylloc
]]])dnl
554 m4_ifdef([b4_lex_param
], [, ]b4_lex_param
))[;
558 /* Convert token to internal form. */
559 if (yychar
<= yyeof_
)
561 yychar
= yytoken
= yyeof_
;
562 YYCDEBUG
<< "Now at end of input." << std::endl
;
566 yytoken
= yytranslate_ (yychar
);
567 YY_SYMBOL_PRINT ("Next token is", yytoken
, &yylval
, &yylloc
);
570 /* If the proper action on seeing token YYTOKEN is to reduce or to
571 detect an error, take that action. */
573 if (yyn
< 0 || yylast_
< yyn
|| yycheck_
[yyn
] != yytoken
)
576 /* Reduce or error. */
580 if (yyn
== 0 || yyn
== yytable_ninf_
)
590 /* Shift the look-ahead token. */
591 YY_SYMBOL_PRINT ("Shifting", yytoken
, &yylval
, &yylloc
);
593 /* Discard the token being shifted unless it is eof. */
594 if (yychar
!= yyeof_
)
597 yysemantic_stack_
.push (yylval
);
598 yylocation_stack_
.push (yylloc
);
600 /* Count tokens shifted since error; after three, turn off error
608 /*-----------------------------------------------------------.
609 | yydefault -- do the default action for the current state. |
610 `-----------------------------------------------------------*/
612 yyn
= yydefact_
[yystate
];
617 /*-----------------------------.
618 | yyreduce -- Do a reduction. |
619 `-----------------------------*/
622 /* If LEN_ is nonzero, implement the default value of the action:
623 `$$ = $1'. Otherwise, use the top of the stack.
625 Otherwise, the following line sets YYVAL to garbage.
626 This behavior is undocumented and Bison
627 users should not rely upon it. */
629 yyval
= yysemantic_stack_
[yylen
- 1];
631 yyval
= yysemantic_stack_
[0];
634 slice
<location_type
, location_stack_type
> slice (yylocation_stack_
, yylen
);
635 YYLLOC_DEFAULT (yyloc
, slice
, yylen
);
637 YY_REDUCE_PRINT (yyn
);
644 ]/* Line __line__ of lalr1.cc. */
645 b4_syncline([@oline@
], [@ofile@
])[
651 yysemantic_stack_
.push (yyval
);
652 yylocation_stack_
.push (yyloc
);
654 /* Shift the result of the reduction. */
656 yystate
= yypgoto_
[yyn
- yyntokens_
] + yystate_stack_
[0];
657 if (0 <= yystate
&& yystate
<= yylast_
658 && yycheck_
[yystate
] == yystate_stack_
[0])
659 yystate
= yytable_
[yystate
];
661 yystate
= yydefgoto_
[yyn
- yyntokens_
];
664 /*------------------------------------.
665 | yyerrlab -- here on detecting error |
666 `------------------------------------*/
668 /* If not already recovering from an error, report this error. */
672 error (yylloc
, yysyntax_error_ (yystate
]dnl
673 b4_error_verbose_if([, yytoken
])[));
676 yyerror_range
[0] = yylloc
;
677 if (yyerrstatus_
== 3)
679 /* If just tried and failed to reuse look-ahead token after an
680 error, discard it. */
682 if (yychar
<= yyeof_
)
684 /* Return failure if at end of input. */
685 if (yychar
== yyeof_
)
690 yydestruct_ ("Error: discarding", yytoken
, &yylval
, &yylloc
);
695 /* Else will try to reuse look-ahead token after shifting the error
700 /*---------------------------------------------------.
701 | yyerrorlab -- error raised explicitly by YYERROR. |
702 `---------------------------------------------------*/
705 /* Pacify compilers like GCC when the user code never invokes
706 YYERROR and the label yyerrorlab therefore never appears in user
711 yyerror_range
[0] = yylocation_stack_
[yylen
- 1];
713 yystate
= yystate_stack_
[0];
716 /*-------------------------------------------------------------.
717 | yyerrlab1 -- common code for both syntax error and YYERROR. |
718 `-------------------------------------------------------------*/
720 yyerrstatus_
= 3; /* Each real token shifted decrements this. */
724 yyn
= yypact_
[yystate
];
725 if (yyn
!= yypact_ninf_
)
728 if (0 <= yyn
&& yyn
<= yylast_
&& yycheck_
[yyn
] == yyterror_
)
736 /* Pop the current state because it cannot handle the error token. */
737 if (yystate_stack_
.height () == 1)
740 yyerror_range
[0] = yylocation_stack_
[0];
741 yydestruct_ ("Error: popping",
743 &yysemantic_stack_
[0], &yylocation_stack_
[0]);
745 yystate
= yystate_stack_
[0];
752 yyerror_range
[1] = yylloc
;
753 // Using YYLLOC is tempting, but would change the location of
754 // the look-ahead. YYLOC is available though.
755 YYLLOC_DEFAULT (yyloc
, yyerror_range
- 1, 2);
756 yysemantic_stack_
.push (yylval
);
757 yylocation_stack_
.push (yyloc
);
759 /* Shift the error token. */
760 YY_SYMBOL_PRINT ("Shifting", yystos_
[yyn
],
761 &yysemantic_stack_
[0], &yylocation_stack_
[0]);
777 if (yychar
!= yyeof_
&& yychar
!= yyempty_
)
778 yydestruct_ ("Cleanup: discarding lookahead", yytoken
, &yylval
, &yylloc
);
780 while (yystate_stack_
.height () != 1)
782 yydestruct_ ("Cleanup: popping",
783 yystos_
[yystate_stack_
[0]],
784 &yysemantic_stack_
[0],
785 &yylocation_stack_
[0]);
792 // Generate an error message.
794 yy::]b4_parser_class_name
[::yysyntax_error_ (int yystate
]dnl
795 b4_error_verbose_if([, int tok
])[)
799 int yyn
= yypact_
[yystate
];
800 if (yypact_ninf_
< yyn
&& yyn
< yylast_
)
802 /* Start YYX at -YYN if negative to avoid negative indexes in
804 int yyxbegin
= yyn
< 0 ? -yyn
: 0;
806 /* Stay within bounds of both yycheck and yytname. */
807 int yychecklim
= yylast_
- yyn
;
808 int yyxend
= yychecklim
< yyntokens_
? yychecklim
: yyntokens_
;
810 for (int x
= yyxbegin
; x
< yyxend
; ++x
)
811 if (yycheck_
[x
+ yyn
] == x
&& x
!= yyterror_
)
814 // FIXME: This method of building the message is not compatible
815 // with internationalization. It should work like yacc.c does it.
816 // That is, first build a string that looks like this:
817 // "syntax error, unexpected %s or %s or %s"
818 // Then, invoke YY_ on this string.
819 // Finally, use the string as a format to output
820 // yytname_[tok], etc.
821 // Until this gets fixed, this message appears in English only.
822 res
= "syntax error, unexpected ";
823 res
+= yytnamerr_ (yytname_
[tok
]);
827 for (int x
= yyxbegin
; x
< yyxend
; ++x
)
828 if (yycheck_
[x
+ yyn
] == x
&& x
!= yyterror_
)
830 res
+= (!count
++) ? ", expecting " : " or ";
831 res
+= yytnamerr_ (yytname_
[x
]);
837 res
= YY_("syntax error");
842 /* YYPACT[STATE-NUM] -- Index in YYTABLE of the portion describing
844 const ]b4_int_type(b4_pact_ninf
, b4_pact_ninf
) yy::b4_parser_class_name::yypact_ninf_
= b4_pact_ninf
[;
845 const ]b4_int_type_for([b4_pact
])[
846 yy::]b4_parser_class_name
[::yypact_
[] =
851 /* YYDEFACT[S] -- default rule to reduce with in state S when YYTABLE
852 doesn't specify something else to do. Zero means the default is an
854 const ]b4_int_type_for([b4_defact
])[
855 yy::]b4_parser_class_name
[::yydefact_
[] =
860 /* YYPGOTO[NTERM-NUM]. */
861 const ]b4_int_type_for([b4_pgoto
])[
862 yy::]b4_parser_class_name
[::yypgoto_
[] =
867 /* YYDEFGOTO[NTERM-NUM]. */
868 const ]b4_int_type_for([b4_defgoto
])[
869 yy::]b4_parser_class_name
[::yydefgoto_
[] =
874 /* YYTABLE[YYPACT[STATE-NUM]]. What to do in state STATE-NUM. If
875 positive, shift that token. If negative, reduce the rule which
876 number is the opposite. If zero, do what YYDEFACT says. */
877 const ]b4_int_type(b4_table_ninf
, b4_table_ninf
) yy::b4_parser_class_name::yytable_ninf_
= b4_table_ninf
[;
878 const ]b4_int_type_for([b4_table
])[
879 yy::]b4_parser_class_name
[::yytable_
[] =
885 const ]b4_int_type_for([b4_check
])[
886 yy::]b4_parser_class_name
[::yycheck_
[] =
891 /* STOS_[STATE-NUM] -- The (internal number of the) accessing
892 symbol of state STATE-NUM. */
893 const ]b4_int_type_for([b4_stos
])[
894 yy::]b4_parser_class_name
[::yystos_
[] =
900 /* TOKEN_NUMBER_[YYLEX-NUM] -- Internal symbol number corresponding
902 const ]b4_int_type_for([b4_toknum
])[
903 yy::]b4_parser_class_name
[::yytoken_number_
[] =
909 /* YYR1[YYN] -- Symbol number of symbol that rule YYN derives. */
910 const ]b4_int_type_for([b4_r1
])[
911 yy::]b4_parser_class_name
[::yyr1_
[] =
916 /* YYR2[YYN] -- Number of symbols composing right hand side of rule YYN. */
917 const ]b4_int_type_for([b4_r2
])[
918 yy::]b4_parser_class_name
[::yyr2_
[] =
923 #if YYDEBUG || YYERROR_VERBOSE || YYTOKEN_TABLE
924 /* YYTNAME[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM.
925 First, the terminals, then, starting at \a yyntokens_, nonterminals. */
927 const yy::]b4_parser_class_name
[::yytname_
[] =
934 /* YYRHS -- A `-1'-separated list of the rules' RHS. */
935 const yy::]b4_parser_class_name
[::rhs_number_type
936 yy::]b4_parser_class_name
[::yyrhs_
[] =
941 /* YYPRHS[YYN] -- Index of the first RHS symbol of rule number YYN in
943 const ]b4_int_type_for([b4_prhs
])[
944 yy::]b4_parser_class_name
[::yyprhs_
[] =
949 /* YYRLINE[YYN] -- Source line where rule number YYN was defined. */
950 const ]b4_int_type_for([b4_rline
])[
951 yy::]b4_parser_class_name
[::yyrline_
[] =
956 // Print the state stack on the debug stream.
958 yy::]b4_parser_class_name
[::yystack_print_ ()
960 *yycdebug_
<< "Stack now";
961 for (state_stack_type::const_iterator i
= yystate_stack_
.begin ();
962 i
!= yystate_stack_
.end (); ++i
)
963 *yycdebug_
<< ' ' << *i
;
964 *yycdebug_
<< std::endl
;
967 // Report on the debug stream that the rule \a yyrule is going to be reduced.
969 yy::]b4_parser_class_name
[::yyreduce_print_ (int yyrule
)
971 unsigned int yylno
= yyrline_
[yyrule
];
972 /* Print the symbols being reduced, and their result. */
973 *yycdebug_
<< "Reducing stack by rule " << yyrule
- 1
974 << " (line " << yylno
<< "), ";
975 for (]b4_int_type_for([b4_prhs
])[ i
= yyprhs_
[yyrule
];
977 *yycdebug_
<< yytname_
[yyrhs_
[i
]] << ' ';
978 *yycdebug_
<< "-> " << yytname_
[yyr1_
[yyrule
]] << std::endl
;
982 /* YYTRANSLATE(YYLEX) -- Bison symbol number corresponding to YYLEX. */
983 yy::]b4_parser_class_name
[::token_number_type
984 yy::]b4_parser_class_name
[::yytranslate_ (int token
)
987 const token_number_type
992 if ((unsigned int) token
<= yyuser_token_number_max_
)
993 return translate_table
[token
];
995 return yyundef_token_
;
998 const int yy::]b4_parser_class_name
[::yyeof_
= 0;
999 const int yy::]b4_parser_class_name
[::yylast_
= ]b4_last
[;
1000 const int yy::]b4_parser_class_name
[::yynnts_
= ]b4_nterms_number
[;
1001 const int yy::]b4_parser_class_name
[::yyempty_
= -2;
1002 const int yy::]b4_parser_class_name
[::yyfinal_
= ]b4_final_state_number
[;
1003 const int yy::]b4_parser_class_name
[::yyterror_
= 1;
1004 const int yy::]b4_parser_class_name
[::yyerrcode_
= 256;
1005 const int yy::]b4_parser_class_name
[::yyntokens_
= ]b4_tokens_number
[;
1007 const unsigned int yy::]b4_parser_class_name
[::yyuser_token_number_max_
= ]b4_user_token_number_max
[;
1008 const yy::]b4_parser_class_name
[::token_number_type
yy::]b4_parser_class_name
[::yyundef_token_
= ]b4_undef_token_number
[;
1013 b4_copyright([stack handling
for Bison C
++ parsers
], [2002, 2003, 2004, 2005])[
1015 #ifndef BISON_STACK_HH
1016 # define BISON_STACK_HH
1022 template <class T
, class S
= std::deque
<T
> >
1027 // Hide our reversed order.
1028 typedef typename
S::reverse_iterator iterator
;
1029 typedef typename
S::const_reverse_iterator const_iterator
;
1035 stack (unsigned int n
) : seq_ (n
)
1041 operator [] (unsigned int i
)
1048 operator [] (unsigned int i
) const
1057 seq_
.push_front (t
);
1062 pop (unsigned int n
= 1)
1072 return seq_
.size ();
1075 inline const_iterator
begin () const { return seq_
.rbegin (); }
1076 inline const_iterator
end () const { return seq_
.rend (); }
1083 /// Present a slice of the top of a stack.
1084 template <class T
, class S
= stack
<T
> >
1089 slice (const S
& stack
,
1090 unsigned int range
) : stack_ (stack
),
1097 operator [] (unsigned int i
) const
1099 return stack_
[range_
- i
];
1105 unsigned int range_
;
1109 #endif // not BISON_STACK_HH]
1112 b4_copyright([Position
class for Bison C
++ parsers
], [2002, 2003, 2004, 2005])[
1115 ** \file position.hh
1116 ** Define the position class.
1119 #ifndef BISON_POSITION_HH
1120 # define BISON_POSITION_HH
1122 # include <iostream>
1127 /// Abstract a position.
1131 /// Initial column number.
1132 static const unsigned int initial_column
= 0;
1133 /// Initial line number.
1134 static const unsigned int initial_line
= 1;
1136 /** \name Ctor & dtor.
1139 /// Construct a position.
1142 line (initial_line
),
1143 column (initial_column
)
1149 /** \name Line and Column related manipulators
1152 /// (line related) Advance to the COUNT next lines.
1153 inline void lines (int count
= 1)
1155 column
= initial_column
;
1159 /// (column related) Advance to the COUNT next columns.
1160 inline void columns (int count
= 1)
1162 int leftmost
= initial_column
;
1163 int current
= column
;
1164 if (leftmost
<= current
+ count
)
1167 column
= initial_column
;
1172 /// File name to which this position refers.
1173 ]b4_filename_type
[* filename
;
1174 /// Current line number.
1176 /// Current column number.
1177 unsigned int column
;
1180 /// Add and assign a position.
1181 inline const position
&
1182 operator+= (position
& res
, const int width
)
1184 res
.columns (width
);
1188 /// Add two position objects.
1189 inline const position
1190 operator+ (const position
& begin
, const int width
)
1192 position res
= begin
;
1193 return res
+= width
;
1196 /// Add and assign a position.
1197 inline const position
&
1198 operator-= (position
& res
, const int width
)
1200 return res
+= -width
;
1203 /// Add two position objects.
1204 inline const position
1205 operator- (const position
& begin
, const int width
)
1207 return begin
+ -width
;
1210 /** \brief Intercept output stream redirection.
1211 ** \param ostr the destination output stream
1212 ** \param pos a reference to the position to redirect
1214 inline std::ostream
&
1215 operator<< (std::ostream
& ostr
, const position
& pos
)
1218 ostr
<< *pos
.filename
<< ':';
1219 return ostr
<< pos
.line
<< '.' << pos
.column
;
1223 #endif // not BISON_POSITION_HH]
1225 b4_copyright([Location
class for Bison C
++ parsers
], [2002, 2003, 2004, 2005])[
1228 ** \file location.hh
1229 ** Define the location class.
1232 #ifndef BISON_LOCATION_HH
1233 # define BISON_LOCATION_HH
1235 # include <iostream>
1237 # include "position.hh"
1242 /// Abstract a location.
1245 /** \name Ctor & dtor.
1248 /// Construct a location.
1257 /** \name Line and Column related manipulators
1260 /// Reset initial location to final location.
1266 /// Extend the current location to the COUNT next columns.
1267 inline void columns (unsigned int count
= 1)
1272 /// Extend the current location to the COUNT next lines.
1273 inline void lines (unsigned int count
= 1)
1281 /// Beginning of the located region.
1283 /// End of the located region.
1287 /// Join two location objects to create a location.
1288 inline const location
operator+ (const location
& begin
, const location
& end
)
1290 location res
= begin
;
1295 /// Add two location objects.
1296 inline const location
operator+ (const location
& begin
, unsigned int width
)
1298 location res
= begin
;
1299 res
.columns (width
);
1303 /// Add and assign a location.
1304 inline location
& operator+= (location
& res
, unsigned int width
)
1306 res
.columns (width
);
1310 /** \brief Intercept output stream redirection.
1311 ** \param ostr the destination output stream
1312 ** \param loc a reference to the location to redirect
1314 ** Avoid duplicate information.
1316 inline std::ostream
& operator<< (std::ostream
& ostr
, const location
& loc
)
1318 position last
= loc
.end
- 1;
1321 && (!loc
.begin
.filename
1322 || *loc
.begin
.filename
!= *last
.filename
))
1323 ostr
<< '-' << last
;
1324 else if (loc
.begin
.line
!= last
.line
)
1325 ostr
<< '-' << last
.line
<< '.' << last
.column
;
1326 else if (loc
.begin
.column
!= last
.column
)
1327 ostr
<< '-' << last
.column
;
1333 #endif // not BISON_LOCATION_HH]