1 m4_divert(-1) -*- C
-*-
3 # C++ GLR skeleton for Bison
4 # Copyright (C) 2002, 2003, 2004, 2005 Free Software Foundation, Inc.
6 # This program is free software; you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation; either version 2 of the License, or
9 # (at your option) any later version.
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License
17 # along with this program; if not, write to the Free Software
18 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
21 # We require a pure interface using locations.
22 m4_define([b4_location_flag
], [1])
23 m4_define([b4_pure
], [1])
25 m4_include(b4_pkgdatadir
/[c
++.m4
])
26 m4_include(b4_pkgdatadir
/[location
.cc
])
29 # b4_yy_symbol_print_generate
30 # ---------------------------
31 # Bypass the default implementation to generate the "yy_symbol_print"
32 # and "yy_symbol_value_print" functions.
33 m4_define([b4_yy_symbol_print_generate
],
34 [b4_c_ansi_function_decl([yyerror
],
36 [[yy::b4_parser_class_name::location_type
*yylocationp
], [yylocationp
]],
38 [[const char* msg
], [msg
]])[
40 /*--------------------.
41 | Print this symbol. |
42 `--------------------*/
44 ]b4_c_ansi_function_def([yy_symbol_print
],
47 [[int yytype
], [yytype
]],
48 [[const yy::b4_parser_class_name::semantic_type
*yyvaluep
],
51 [[const yy::b4_parser_class_name::location_type
*yylocationp
],
53 m4_ifset([b4_parse_param
], [, b4_parse_param
]))[
55 ]b4_parse_param_use
[]dnl
56 [ yyparser
.yy_symbol_print_ (yytype
, yyvaluep
]b4_location_if([, yylocationp
])[);
60 m4_prepend([b4_epilogue
],
66 ]b4_c_ansi_function_def([yyerror
],
68 [[yy::b4_parser_class_name::location_type
*yylocationp
], [yylocationp
]],
70 [[const char* msg
], [msg
]])[
72 ]b4_parse_param_use
[]dnl
73 [ yyparser
.error (*yylocationp
, msg
);
79 ]dnl Restore the actual parser params
.
80 m4_popdef([b4_parse_param
])dnl
82 /// Build a parser object.
83 ]b4_parser_class_name::b4_parser_class_name
[ (]b4_parse_param_decl
[)
84 : yycdebug_ (&std::cerr
)]b4_parse_param_cons
[
88 ]b4_parser_class_name::~b4_parser_class_name
[ ()
93 ]b4_parser_class_name
[::parse ()
95 return ::yyparse (*this]b4_user_args
[);
99 /*--------------------.
100 | Print this symbol. |
101 `--------------------*/
104 ]b4_parser_class_name
[::yy_symbol_value_print_ (int yytype
,
105 const semantic_type
* yyvaluep
, const location_type
* yylocationp
)
107 /* Pacify ``unused variable'' warnings. */
112 ]m4_map([b4_symbol_actions
], m4_defn([b4_symbol_printers
]))dnl
120 ]b4_parser_class_name
[::yy_symbol_print_ (int yytype
,
121 const semantic_type
* yyvaluep
, const location_type
* yylocationp
)
123 *yycdebug_
<< (yytype
< YYNTOKENS
? "token" : "nterm")
124 << ' ' << yytname
[yytype
] << " ("
125 << *yylocationp
<< ": ";
126 yy_symbol_value_print_ (yytype
, yyvaluep
, yylocationp
);
131 ]b4_parser_class_name
[::debug_stream () const
137 ]b4_parser_class_name
[::set_debug_stream (std::ostream
& o
)
143 ]b4_parser_class_name
[::debug_level_type
144 ]b4_parser_class_name
[::debug_level () const
150 ]b4_parser_class_name
[::set_debug_level (debug_level_type l
)
155 #endif /* ! YYDEBUG */
161 # Let glr.c believe that the user arguments are only the parser itself.
162 m4_pushdef([b4_parse_param
],
163 [[yy::b4_parser_class_name
& yyparser
, yyparser
],]
164 m4_defn([b4_parse_param
]))
165 m4_include(b4_pkgdatadir
/[glr
.c
])
166 @output @output_header_name@
167 b4_copyright([C
++ Skeleton parser
for GLALR(1) parsing with Bison
],
168 [2002, 2003, 2004, 2005])[
170 /* C++ GLR parser skeleton written by Akim Demaille. */
172 #ifndef PARSER_HEADER_H
173 # define PARSER_HEADER_H
178 /* Using locations. */
179 #define YYLSP_NEEDED ]b4_locations_flag[
187 /* Copy the first part of user declarations. */
190 ]/* Line __line__ of glr.cc. */
191 b4_syncline([@oline@
], [@ofile@
])[
194 #include "location.hh"
196 /* Enabling traces. */
198 # define YYDEBUG ]b4_debug[
201 /* Enabling verbose error messages. */
202 #ifdef YYERROR_VERBOSE
203 # undef YYERROR_VERBOSE
204 # define YYERROR_VERBOSE 1
206 # define YYERROR_VERBOSE ]b4_error_verbose[
209 /* Enabling the token table. */
210 #ifndef YYTOKEN_TABLE
211 # define YYTOKEN_TABLE ]b4_token_table[
215 /* Copy the second part of user declarations. */
218 ]/* Line __line__ of glr.cc. */
220 b4_syncline([@oline@
], [@ofile@
])[
223 /* YYLLOC_DEFAULT -- Set CURRENT to span from RHS[1] to RHS[N].
224 If N is 0, then set CURRENT to the empty location which ends
225 the previous symbol: RHS[0] (always defined). */
227 #ifndef YYLLOC_DEFAULT
228 # define YYLLOC_DEFAULT(Current, Rhs, N) \
232 (Current).begin = YYRHSLOC (Rhs, 1).begin; \
233 (Current).end = YYRHSLOC (Rhs, N).end; \
237 (Current).begin = (Current).end = YYRHSLOC (Rhs, 0).end; \
239 while (/*CONSTCOND*/ 0)
245 class ]b4_parser_class_name
[
248 /// Symbol semantic values.
249 #if ! defined (YYSTYPE)
250 ]m4_ifdef([b4_stype
],
251 [b4_syncline([b4_stype_line
], [b4_file_name
])
252 union semantic_type b4_stype
;
253 /* Line __line__ of lalr1.cc. */
254 b4_syncline([@oline@
], [@ofile@
])],
255 [ typedef int semantic_type
;])[
257 typedef YYSTYPE semantic_type
;
259 /// Symbol locations.
260 typedef ]b4_location_type
[ location_type
;
264 ]b4_token_enums(b4_tokens
)[
267 /// Build a parser object.
268 ]b4_parser_class_name
[ (]b4_parse_param_decl
[);
269 virtual ~]b4_parser_class_name
[ ();
272 /// \returns 0 iff parsing succeeded.
273 virtual int parse ();
275 /// The current debugging stream.
276 std::ostream
& debug_stream () const;
277 /// Set the current debugging stream.
278 void set_debug_stream (std::ostream
&);
280 /// Type for debugging levels.
281 typedef int debug_level_type
;
282 /// The current debugging level.
283 debug_level_type
debug_level () const;
284 /// Set the current debugging level.
285 void set_debug_level (debug_level_type l
);
290 /// Report a syntax error.
291 /// \param loc where the syntax error is found.
292 /// \param msg a description of the syntax error.
293 virtual void error (const location_type
& loc
, const std::string
& msg
);
298 /// \brief Report a symbol value on the debug stream.
299 /// \param yytype The token type.
300 /// \param yyvaluep Its semantic value.
301 /// \param yylocationp Its location.
302 virtual void yy_symbol_value_print_ (int yytype
,
303 const semantic_type
* yyvaluep
,
304 const location_type
* yylocationp
);
305 /// \brief Report a symbol on the debug stream.
306 /// \param yytype The token type.
307 /// \param yyvaluep Its semantic value.
308 /// \param yylocationp Its location.
309 virtual void yy_symbol_print_ (int yytype
,
310 const semantic_type
* yyvaluep
,
311 const location_type
* yylocationp
);
313 #endif /* ! YYDEBUG */
316 /// \brief Reclaim the memory associated to a symbol.
317 /// \param yymsg Why this token is reclaimed.
318 /// \param yytype The symbol type.
319 /// \param yyvaluep Its semantic value.
320 /// \param yylocationp Its location.
321 inline void yydestruct_ (const char* yymsg
,
323 semantic_type
* yyvaluep
,
324 location_type
* yylocationp
);
327 std::ostream
* yycdebug_
;
328 ]b4_parse_param_vars
[
331 ]dnl Redirections
for glr
.c
.
332 [#define YYSTYPE yy::]b4_parser_class_name[::semantic_type
333 #define YYLTYPE yy::]b4_parser_class_name[::location_type
337 #endif /* ! defined PARSER_HEADER_H */]