]> git.saurik.com Git - bison.git/blob - data/glr.cc
"Use" parse parameters.
[bison.git] / data / glr.cc
1 m4_divert(-1) -*- C -*-
2
3 # C++ GLR skeleton for Bison
4 # Copyright (C) 2002, 2003, 2004, 2005 Free Software Foundation, Inc.
5
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.
10
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.
15
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
19 # 02110-1301 USA
20
21 # We require a pure interface using locations.
22 m4_define([b4_location_flag], [1])
23 m4_define([b4_pure], [1])
24
25 m4_include(b4_pkgdatadir/[c++.m4])
26 m4_include(b4_pkgdatadir/[location.cc])
27
28
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],
36 [static void],
37 [[yy::b4_parser_class_name::location_type *yylocationp], [yylocationp]],
38 b4_parse_param,
39 [[const char* msg], [msg]])[
40
41 /*--------------------------------.
42 | Print this symbol on YYOUTPUT. |
43 `--------------------------------*/
44
45 ]$1([yysymprint],
46 [static void],
47 [[FILE *yyoutput], [yyoutput]],
48 [[int yytype], [yytype]],
49 [[const yy::b4_parser_class_name::semantic_type *yyvaluep],
50 [yyvaluep]][]dnl
51 b4_location_if([,
52 [[const yy::b4_parser_class_name::location_type *yylocationp],
53 [yylocationp]]])[]dnl
54 m4_ifset([b4_parse_param], [, b4_parse_param]))[
55 {
56 YYUSE (yyoutput);
57 ]b4_parse_param_use[]dnl
58 [
59 yyparser.yysymprint_ (yytype, yyvaluep]b4_location_if([, yylocationp])[);
60 }
61 ]])
62
63 m4_prepend([b4_epilogue],
64 [[
65 /*------------------.
66 | Report an error. |
67 `------------------*/
68
69 ]b4_c_ansi_function_def([yyerror],
70 [static void],
71 [[yy::b4_parser_class_name::location_type *yylocationp], [yylocationp]],
72 b4_parse_param,
73 [[const char* msg], [msg]])[
74 {
75 ]b4_parse_param_use[]dnl
76 [
77 yyparser.error (*yylocationp, msg);
78 }
79
80
81 namespace yy
82 {
83 ]dnl Restore the actual parser params.
84 m4_popdef([b4_parse_param])dnl
85 [
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[
89 {
90 }
91
92 ]b4_parser_class_name::~b4_parser_class_name[ ()
93 {
94 }
95
96 int
97 ]b4_parser_class_name[::parse ()
98 {
99 return ::yyparse (*this]b4_user_args[);
100 }
101
102 #if YYDEBUG
103
104 /*--------------------------------.
105 | Print this symbol on YYOUTPUT. |
106 `--------------------------------*/
107
108 void
109 ]b4_parser_class_name[::yysymprint_ (int yytype,
110 const semantic_type* yyvaluep, const location_type* yylocationp)
111 {
112 /* Pacify ``unused variable'' warnings. */
113 YYUSE (yyvaluep);
114 YYUSE (yylocationp);
115 /* Backward compatibility, but should be removed eventually. */
116 std::ostream& cdebug_ = *yycdebug_;
117 YYUSE (cdebug_);
118
119 *yycdebug_ << (yytype < YYNTOKENS ? "token" : "nterm")
120 << ' ' << yytname[yytype] << " ("
121 << *yylocationp << ": ";
122 switch (yytype)
123 {
124 ]m4_map([b4_symbol_actions], m4_defn([b4_symbol_printers]))dnl
125 [ default:
126 break;
127 }
128 *yycdebug_ << ')';
129 }
130
131 std::ostream&
132 ]b4_parser_class_name[::debug_stream () const
133 {
134 return *yycdebug_;
135 }
136
137 void
138 ]b4_parser_class_name[::set_debug_stream (std::ostream& o)
139 {
140 yycdebug_ = &o;
141 }
142
143
144 ]b4_parser_class_name[::debug_level_type
145 ]b4_parser_class_name[::debug_level () const
146 {
147 return ::yydebug;
148 }
149
150 void
151 ]b4_parser_class_name[::set_debug_level (debug_level_type l)
152 {
153 ::yydebug = l;
154 }
155
156 #endif /* ! YYDEBUG */
157
158 } // namespace yy
159
160 ]])
161
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
172
173 #include <string>
174 #include <iostream>
175
176 /* Using locations. */
177 #define YYLSP_NEEDED ]b4_locations_flag[
178
179 namespace yy
180 {
181 class position;
182 class location;
183 }
184
185 /* Copy the first part of user declarations. */
186 ]b4_pre_prologue[
187
188 ]/* Line __line__ of glr.cc. */
189 b4_syncline([@oline@], [@ofile@])[
190
191 #include "stack.hh"
192 #include "location.hh"
193
194 /* Enabling traces. */
195 #ifndef YYDEBUG
196 # define YYDEBUG ]b4_debug[
197 #endif
198
199 /* Enabling verbose error messages. */
200 #ifdef YYERROR_VERBOSE
201 # undef YYERROR_VERBOSE
202 # define YYERROR_VERBOSE 1
203 #else
204 # define YYERROR_VERBOSE ]b4_error_verbose[
205 #endif
206
207 /* Enabling the token table. */
208 #ifndef YYTOKEN_TABLE
209 # define YYTOKEN_TABLE ]b4_token_table[
210 #endif
211
212 #if 0
213 /* Copy the second part of user declarations. */
214 ]b4_post_prologue[
215
216 ]/* Line __line__ of glr.cc. */
217
218 b4_syncline([@oline@], [@ofile@])[
219 #endif
220
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). */
224
225 #ifndef YYLLOC_DEFAULT
226 # define YYLLOC_DEFAULT(Current, Rhs, N) \
227 do \
228 if (N) \
229 { \
230 (Current).begin = YYRHSLOC (Rhs, 1).begin; \
231 (Current).end = YYRHSLOC (Rhs, N).end; \
232 } \
233 else \
234 { \
235 (Current).begin = (Current).end = YYRHSLOC (Rhs, 0).end; \
236 } \
237 while (/*CONSTCOND*/ 0)
238 #endif
239
240 namespace yy
241 {
242 /// A Bison parser.
243 class ]b4_parser_class_name[
244 {
245 public:
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;])[
254 #else
255 typedef YYSTYPE semantic_type;
256 #endif
257 /// Symbol locations.
258 typedef ]b4_location_type[ location_type;
259 /// Tokens.
260 struct token
261 {
262 ]b4_token_enums(b4_tokens)[
263 };
264
265 /// Build a parser object.
266 ]b4_parser_class_name[ (]b4_parse_param_decl[);
267 virtual ~]b4_parser_class_name[ ();
268
269 /// Parse.
270 /// \returns 0 iff parsing succeeded.
271 virtual int parse ();
272
273 /// The current debugging stream.
274 std::ostream& debug_stream () const;
275 /// Set the current debugging stream.
276 void set_debug_stream (std::ostream &);
277
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);
284
285 private:
286
287 public:
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);
292 private:
293
294 #if YYDEBUG
295 public:
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);
303 private:
304 #endif /* ! YYDEBUG */
305
306
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,
313 int yytype,
314 semantic_type* yyvaluep,
315 location_type* yylocationp);
316
317 /* Debugging. */
318 std::ostream* yycdebug_;
319 ]b4_parse_param_vars[
320 };
321
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
325
326 }
327
328 #endif /* ! defined PARSER_HEADER_H */]