]>
Commit | Line | Data |
---|---|---|
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 | ||
171 | /* C++ GLR parser skeleton written by Akim Demaille. */ | |
172 | ||
173 | #ifndef PARSER_HEADER_H | |
174 | # define PARSER_HEADER_H | |
175 | ||
176 | #include <string> | |
177 | #include <iostream> | |
178 | ||
179 | /* Using locations. */ | |
180 | #define YYLSP_NEEDED ]b4_locations_flag[ | |
181 | ||
182 | namespace yy | |
183 | { | |
184 | class position; | |
185 | class location; | |
186 | } | |
187 | ||
188 | /* Copy the first part of user declarations. */ | |
189 | ]b4_pre_prologue[ | |
190 | ||
191 | ]/* Line __line__ of glr.cc. */ | |
192 | b4_syncline([@oline@], [@ofile@])[ | |
193 | ||
194 | #include "stack.hh" | |
195 | #include "location.hh" | |
196 | ||
197 | /* Enabling traces. */ | |
198 | #ifndef YYDEBUG | |
199 | # define YYDEBUG ]b4_debug[ | |
200 | #endif | |
201 | ||
202 | /* Enabling verbose error messages. */ | |
203 | #ifdef YYERROR_VERBOSE | |
204 | # undef YYERROR_VERBOSE | |
205 | # define YYERROR_VERBOSE 1 | |
206 | #else | |
207 | # define YYERROR_VERBOSE ]b4_error_verbose[ | |
208 | #endif | |
209 | ||
210 | /* Enabling the token table. */ | |
211 | #ifndef YYTOKEN_TABLE | |
212 | # define YYTOKEN_TABLE ]b4_token_table[ | |
213 | #endif | |
214 | ||
215 | #if 0 | |
216 | /* Copy the second part of user declarations. */ | |
217 | ]b4_post_prologue[ | |
218 | ||
219 | ]/* Line __line__ of glr.cc. */ | |
220 | ||
221 | b4_syncline([@oline@], [@ofile@])[ | |
222 | #endif | |
223 | ||
224 | /* YYLLOC_DEFAULT -- Set CURRENT to span from RHS[1] to RHS[N]. | |
225 | If N is 0, then set CURRENT to the empty location which ends | |
226 | the previous symbol: RHS[0] (always defined). */ | |
227 | ||
228 | #ifndef YYLLOC_DEFAULT | |
229 | # define YYLLOC_DEFAULT(Current, Rhs, N) \ | |
230 | do \ | |
231 | if (N) \ | |
232 | { \ | |
233 | (Current).begin = YYRHSLOC (Rhs, 1).begin; \ | |
234 | (Current).end = YYRHSLOC (Rhs, N).end; \ | |
235 | } \ | |
236 | else \ | |
237 | { \ | |
238 | (Current).begin = (Current).end = YYRHSLOC (Rhs, 0).end; \ | |
239 | } \ | |
240 | while (0) | |
241 | #endif | |
242 | ||
243 | namespace yy | |
244 | { | |
245 | /// A Bison parser. | |
246 | class ]b4_parser_class_name[ | |
247 | { | |
248 | public: | |
249 | /// Symbol semantic values. | |
250 | #if ! defined (YYSTYPE) | |
251 | ]m4_ifdef([b4_stype], | |
252 | [b4_syncline([b4_stype_line], [b4_file_name]) | |
253 | union semantic_type b4_stype; | |
254 | /* Line __line__ of lalr1.cc. */ | |
255 | b4_syncline([@oline@], [@ofile@])], | |
256 | [ typedef int semantic_type;])[ | |
257 | #else | |
258 | typedef YYSTYPE semantic_type; | |
259 | #endif | |
260 | /// Symbol locations. | |
261 | typedef ]b4_location_type[ location_type; | |
262 | /// Tokens. | |
263 | struct token | |
264 | { | |
265 | ]b4_token_enums(b4_tokens)[ | |
266 | }; | |
267 | ||
268 | /// Build a parser object. | |
269 | ]b4_parser_class_name[ (]b4_parse_param_decl[); | |
270 | virtual ~]b4_parser_class_name[ (); | |
271 | ||
272 | /// Parse. | |
273 | /// \returns 0 iff parsing succeeded. | |
274 | virtual int parse (); | |
275 | ||
276 | /// The current debugging stream. | |
277 | std::ostream& debug_stream () const; | |
278 | /// Set the current debugging stream. | |
279 | void set_debug_stream (std::ostream &); | |
280 | ||
281 | /// Type for debugging levels. | |
282 | typedef int debug_level_type; | |
283 | /// The current debugging level. | |
284 | debug_level_type debug_level () const; | |
285 | /// Set the current debugging level. | |
286 | void set_debug_level (debug_level_type l); | |
287 | ||
288 | private: | |
289 | ||
290 | public: | |
291 | /// Report a syntax error. | |
292 | /// \param loc where the syntax error is found. | |
293 | /// \param msg a description of the syntax error. | |
294 | virtual void error (const location_type& loc, const std::string& msg); | |
295 | private: | |
296 | ||
297 | #if YYDEBUG | |
298 | public: | |
299 | /// \brief Report a symbol on the debug stream. | |
300 | /// \param yytype The token type. | |
301 | /// \param yyvaluep Its semantic value. | |
302 | /// \param yylocationp Its location. | |
303 | virtual void yysymprint_ (int yytype, | |
304 | const semantic_type* yyvaluep, | |
305 | const location_type* yylocationp); | |
306 | private: | |
307 | #endif /* ! YYDEBUG */ | |
308 | ||
309 | ||
310 | /// \brief Reclaim the memory associated to a symbol. | |
311 | /// \param yymsg Why this token is reclaimed. | |
312 | /// \param yytype The symbol type. | |
313 | /// \param yyvaluep Its semantic value. | |
314 | /// \param yylocationp Its location. | |
315 | inline void yydestruct_ (const char* yymsg, | |
316 | int yytype, | |
317 | semantic_type* yyvaluep, | |
318 | location_type* yylocationp); | |
319 | ||
320 | /* Debugging. */ | |
321 | std::ostream* yycdebug_; | |
322 | ]b4_parse_param_vars[ | |
323 | }; | |
324 | ||
325 | ]dnl Redirections for glr.c. | |
326 | [#define YYSTYPE yy::]b4_parser_class_name[::semantic_type | |
327 | #define YYLTYPE yy::]b4_parser_class_name[::location_type | |
328 | ||
329 | } | |
330 | ||
331 | #endif /* ! defined PARSER_HEADER_H */] |