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_yysymprint_generate(FUNCTION-DECLARATOR)
30 # -------------------------------------------
31 # Generate the "yysymprint" function, which declaration is issued using
32 # FUNCTION-DECLARATOR, which may be "b4_c_ansi_function_def" for ISO C
33 # or "b4_c_function_def" for K&R.
34 m4_define([b4_yysymprint_generate
],
35 [b4_c_ansi_function_decl([yyerror
],
37 [[yy::b4_parser_class_name::location_type
*yylocationp
], [yylocationp
]],
39 [[const char* msg
], [msg
]])[
41 /*--------------------------------.
42 | Print this symbol on YYOUTPUT. |
43 `--------------------------------*/
47 [[FILE *yyoutput
], [yyoutput
]],
48 [[int yytype
], [yytype
]],
49 [[const yy::b4_parser_class_name::semantic_type
*yyvaluep
],
52 [[const yy::b4_parser_class_name::location_type
*yylocationp
],
54 m4_ifset([b4_parse_param
], [, b4_parse_param
]))[
57 ]b4_parse_param_use
[]dnl
59 yyparser
.yysymprint_ (yytype
, yyvaluep
]b4_location_if([, yylocationp
])[);
63 m4_prepend([b4_epilogue
],
69 ]b4_c_ansi_function_def([yyerror
],
71 [[yy::b4_parser_class_name::location_type
*yylocationp
], [yylocationp
]],
73 [[const char* msg
], [msg
]])[
75 ]b4_parse_param_use
[]dnl
77 yyparser
.error (*yylocationp
, msg
);
83 ]dnl Restore the actual parser params
.
84 m4_popdef([b4_parse_param
])dnl
86 /// Build a parser object.
87 ]b4_parser_class_name::b4_parser_class_name
[ (]b4_parse_param_decl
[)
88 : yycdebug_ (&std::cerr
)]b4_parse_param_cons
[
92 ]b4_parser_class_name::~b4_parser_class_name
[ ()
97 ]b4_parser_class_name
[::parse ()
99 return ::yyparse (*this]b4_user_args
[);
104 /*--------------------------------.
105 | Print this symbol on YYOUTPUT. |
106 `--------------------------------*/
109 ]b4_parser_class_name
[::yysymprint_ (int yytype
,
110 const semantic_type
* yyvaluep
, const location_type
* yylocationp
)
112 /* Pacify ``unused variable'' warnings. */
115 /* Backward compatibility, but should be removed eventually. */
116 std::ostream
& cdebug_
= *yycdebug_
;
119 *yycdebug_
<< (yytype
< YYNTOKENS
? "token" : "nterm")
120 << ' ' << yytname
[yytype
] << " ("
121 << *yylocationp
<< ": ";
124 ]m4_map([b4_symbol_actions
], m4_defn([b4_symbol_printers
]))dnl
132 ]b4_parser_class_name
[::debug_stream () const
138 ]b4_parser_class_name
[::set_debug_stream (std::ostream
& o
)
144 ]b4_parser_class_name
[::debug_level_type
145 ]b4_parser_class_name
[::debug_level () const
151 ]b4_parser_class_name
[::set_debug_level (debug_level_type l
)
156 #endif /* ! YYDEBUG */
162 # Let glr.c believe that the user arguments are only the parser itself.
163 m4_pushdef([b4_parse_param
],
164 [[yy::b4_parser_class_name
& yyparser
, yyparser
],]
165 m4_defn([b4_parse_param
]))
166 m4_include(b4_pkgdatadir
/[glr
.c
])
167 @output @output_header_name@
168 b4_copyright([C
++ Skeleton parser
for GLALR(1) parsing with Bison
],
169 [2002, 2003, 2004, 2005])[
170 #ifndef PARSER_HEADER_H
171 # define PARSER_HEADER_H
176 /* Using locations. */
177 #define YYLSP_NEEDED ]b4_locations_flag[
185 /* Copy the first part of user declarations. */
188 ]/* Line __line__ of glr.cc. */
189 b4_syncline([@oline@
], [@ofile@
])[
192 #include "location.hh"
194 /* Enabling traces. */
196 # define YYDEBUG ]b4_debug[
199 /* Enabling verbose error messages. */
200 #ifdef YYERROR_VERBOSE
201 # undef YYERROR_VERBOSE
202 # define YYERROR_VERBOSE 1
204 # define YYERROR_VERBOSE ]b4_error_verbose[
207 /* Enabling the token table. */
208 #ifndef YYTOKEN_TABLE
209 # define YYTOKEN_TABLE ]b4_token_table[
213 /* Copy the second part of user declarations. */
216 ]/* Line __line__ of glr.cc. */
218 b4_syncline([@oline@
], [@ofile@
])[
221 /* YYLLOC_DEFAULT -- Set CURRENT to span from RHS[1] to RHS[N].
222 If N is 0, then set CURRENT to the empty location which ends
223 the previous symbol: RHS[0] (always defined). */
225 #ifndef YYLLOC_DEFAULT
226 # define YYLLOC_DEFAULT(Current, Rhs, N) \
230 (Current).begin = YYRHSLOC (Rhs, 1).begin; \
231 (Current).end = YYRHSLOC (Rhs, N).end; \
235 (Current).begin = (Current).end = YYRHSLOC (Rhs, 0).end; \
237 while (/*CONSTCOND*/ 0)
243 class ]b4_parser_class_name
[
246 /// Symbol semantic values.
247 #if ! defined (YYSTYPE)
248 ]m4_ifdef([b4_stype
],
249 [b4_syncline([b4_stype_line
], [b4_file_name
])
250 union semantic_type b4_stype
;
251 /* Line __line__ of lalr1.cc. */
252 b4_syncline([@oline@
], [@ofile@
])],
253 [ typedef int semantic_type
;])[
255 typedef YYSTYPE semantic_type
;
257 /// Symbol locations.
258 typedef ]b4_location_type
[ location_type
;
262 ]b4_token_enums(b4_tokens
)[
265 /// Build a parser object.
266 ]b4_parser_class_name
[ (]b4_parse_param_decl
[);
267 virtual ~]b4_parser_class_name
[ ();
270 /// \returns 0 iff parsing succeeded.
271 virtual int parse ();
273 /// The current debugging stream.
274 std::ostream
& debug_stream () const;
275 /// Set the current debugging stream.
276 void set_debug_stream (std::ostream
&);
278 /// Type for debugging levels.
279 typedef int debug_level_type
;
280 /// The current debugging level.
281 debug_level_type
debug_level () const;
282 /// Set the current debugging level.
283 void set_debug_level (debug_level_type l
);
288 /// Report a syntax error.
289 /// \param loc where the syntax error is found.
290 /// \param msg a description of the syntax error.
291 virtual void error (const location_type
& loc
, const std::string
& msg
);
296 /// \brief Report a symbol on the debug stream.
297 /// \param yytype The token type.
298 /// \param yyvaluep Its semantic value.
299 /// \param yylocationp Its location.
300 virtual void yysymprint_ (int yytype
,
301 const semantic_type
* yyvaluep
,
302 const location_type
* yylocationp
);
304 #endif /* ! YYDEBUG */
307 /// \brief Reclaim the memory associated to a symbol.
308 /// \param yymsg Why this token is reclaimed.
309 /// \param yytype The symbol type.
310 /// \param yyvaluep Its semantic value.
311 /// \param yylocationp Its location.
312 inline void yydestruct_ (const char* yymsg
,
314 semantic_type
* yyvaluep
,
315 location_type
* yylocationp
);
318 std::ostream
* yycdebug_
;
319 ]b4_parse_param_vars
[
322 ]dnl Redirections
for glr
.c
.
323 [#define YYSTYPE yy::]b4_parser_class_name[::semantic_type
324 #define YYLTYPE yy::]b4_parser_class_name[::location_type
328 #endif /* ! defined PARSER_HEADER_H */]