]> git.saurik.com Git - bison.git/blame - data/glr.cc
* src/output.c (output_skeleton): Don't hard wire the inclusion of
[bison.git] / data / glr.cc
CommitLineData
42249483
AD
1m4_divert(-1) -*- C -*-
2
3# C++ GLR skeleton for Bison
3953ed88 4# Copyright (C) 2002, 2003, 2004, 2005, 2006 Free Software Foundation, Inc.
42249483
AD
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.
22m4_define([b4_location_flag], [1])
23m4_define([b4_pure], [1])
24
25m4_include(b4_pkgdatadir/[c++.m4])
26m4_include(b4_pkgdatadir/[location.cc])
27
28
c4d497a0
AD
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.
33m4_define([b4_yy_symbol_print_generate],
42249483
AD
34[b4_c_ansi_function_decl([yyerror],
35 [static void],
36 [[yy::b4_parser_class_name::location_type *yylocationp], [yylocationp]],
37 b4_parse_param,
38 [[const char* msg], [msg]])[
39
c4d497a0
AD
40/*--------------------.
41| Print this symbol. |
42`--------------------*/
42249483 43
c4d497a0 44]b4_c_ansi_function_def([yy_symbol_print],
42249483 45 [static void],
c4d497a0 46 [[FILE *], []],
42249483
AD
47 [[int yytype], [yytype]],
48 [[const yy::b4_parser_class_name::semantic_type *yyvaluep],
49 [yyvaluep]][]dnl
50b4_location_if([,
51 [[const yy::b4_parser_class_name::location_type *yylocationp],
52 [yylocationp]]])[]dnl
53m4_ifset([b4_parse_param], [, b4_parse_param]))[
54{
613d8952 55]b4_parse_param_use[]dnl
c4d497a0 56[ yyparser.yy_symbol_print_ (yytype, yyvaluep]b4_location_if([, yylocationp])[);
42249483
AD
57}
58]])
59
60m4_prepend([b4_epilogue],
61[[
62/*------------------.
63| Report an error. |
64`------------------*/
65
66]b4_c_ansi_function_def([yyerror],
67 [static void],
68 [[yy::b4_parser_class_name::location_type *yylocationp], [yylocationp]],
69 b4_parse_param,
70 [[const char* msg], [msg]])[
71{
613d8952 72]b4_parse_param_use[]dnl
c4d497a0 73[ yyparser.error (*yylocationp, msg);
42249483
AD
74}
75
76
77namespace yy
78{
79]dnl Restore the actual parser params.
80m4_popdef([b4_parse_param])dnl
81[
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[
85 {
86 }
87
88 ]b4_parser_class_name::~b4_parser_class_name[ ()
89 {
90 }
91
92 int
93 ]b4_parser_class_name[::parse ()
94 {
95 return ::yyparse (*this]b4_user_args[);
96 }
97
98#if YYDEBUG
c4d497a0
AD
99 /*--------------------.
100 | Print this symbol. |
101 `--------------------*/
42249483 102
c4d497a0
AD
103 inline void
104 ]b4_parser_class_name[::yy_symbol_value_print_ (int yytype,
42249483
AD
105 const semantic_type* yyvaluep, const location_type* yylocationp)
106 {
107 /* Pacify ``unused variable'' warnings. */
613d8952
AD
108 YYUSE (yyvaluep);
109 YYUSE (yylocationp);
42249483
AD
110 switch (yytype)
111 {
112 ]m4_map([b4_symbol_actions], m4_defn([b4_symbol_printers]))dnl
113[ default:
114 break;
115 }
c4d497a0
AD
116 }
117
118
119 void
120 ]b4_parser_class_name[::yy_symbol_print_ (int yytype,
121 const semantic_type* yyvaluep, const location_type* yylocationp)
122 {
123 *yycdebug_ << (yytype < YYNTOKENS ? "token" : "nterm")
124 << ' ' << yytname[yytype] << " ("
125 << *yylocationp << ": ";
126 yy_symbol_value_print_ (yytype, yyvaluep, yylocationp);
42249483
AD
127 *yycdebug_ << ')';
128 }
129
130 std::ostream&
131 ]b4_parser_class_name[::debug_stream () const
132 {
133 return *yycdebug_;
134 }
135
136 void
137 ]b4_parser_class_name[::set_debug_stream (std::ostream& o)
138 {
139 yycdebug_ = &o;
140 }
141
142
143 ]b4_parser_class_name[::debug_level_type
144 ]b4_parser_class_name[::debug_level () const
145 {
146 return ::yydebug;
147 }
148
149 void
150 ]b4_parser_class_name[::set_debug_level (debug_level_type l)
151 {
152 ::yydebug = l;
153 }
154
155#endif /* ! YYDEBUG */
156
157} // namespace yy
158
159]])
160
161# Let glr.c believe that the user arguments are only the parser itself.
162m4_pushdef([b4_parse_param],
163 [[yy::b4_parser_class_name& yyparser, yyparser],]
164 m4_defn([b4_parse_param]))
165m4_include(b4_pkgdatadir/[glr.c])
166@output @output_header_name@
167b4_copyright([C++ Skeleton parser for GLALR(1) parsing with Bison],
168 [2002, 2003, 2004, 2005])[
af3412cd 169
af3412cd
PE
170/* C++ GLR parser skeleton written by Akim Demaille. */
171
42249483
AD
172#ifndef PARSER_HEADER_H
173# define PARSER_HEADER_H
174
175#include <string>
176#include <iostream>
177
178/* Using locations. */
179#define YYLSP_NEEDED ]b4_locations_flag[
180
181namespace yy
182{
183 class position;
184 class location;
185}
186
187/* Copy the first part of user declarations. */
188]b4_pre_prologue[
189
190]/* Line __line__ of glr.cc. */
191b4_syncline([@oline@], [@ofile@])[
192
42249483
AD
193#include "location.hh"
194
195/* Enabling traces. */
196#ifndef YYDEBUG
197# define YYDEBUG ]b4_debug[
198#endif
199
200/* Enabling verbose error messages. */
201#ifdef YYERROR_VERBOSE
202# undef YYERROR_VERBOSE
203# define YYERROR_VERBOSE 1
204#else
205# define YYERROR_VERBOSE ]b4_error_verbose[
206#endif
207
208/* Enabling the token table. */
209#ifndef YYTOKEN_TABLE
210# define YYTOKEN_TABLE ]b4_token_table[
211#endif
212
213#if 0
214/* Copy the second part of user declarations. */
215]b4_post_prologue[
216
217]/* Line __line__ of glr.cc. */
218
219b4_syncline([@oline@], [@ofile@])[
220#endif
221
222/* YYLLOC_DEFAULT -- Set CURRENT to span from RHS[1] to RHS[N].
223 If N is 0, then set CURRENT to the empty location which ends
224 the previous symbol: RHS[0] (always defined). */
225
226#ifndef YYLLOC_DEFAULT
227# define YYLLOC_DEFAULT(Current, Rhs, N) \
228 do \
229 if (N) \
230 { \
231 (Current).begin = YYRHSLOC (Rhs, 1).begin; \
232 (Current).end = YYRHSLOC (Rhs, N).end; \
233 } \
234 else \
235 { \
236 (Current).begin = (Current).end = YYRHSLOC (Rhs, 0).end; \
237 } \
c4d497a0 238 while (/*CONSTCOND*/ 0)
42249483
AD
239#endif
240
241namespace yy
242{
243 /// A Bison parser.
244 class ]b4_parser_class_name[
245 {
246 public:
247 /// Symbol semantic values.
248#if ! defined (YYSTYPE)
249]m4_ifdef([b4_stype],
250[b4_syncline([b4_stype_line], [b4_file_name])
251 union semantic_type b4_stype;
252/* Line __line__ of lalr1.cc. */
253b4_syncline([@oline@], [@ofile@])],
254[ typedef int semantic_type;])[
255#else
256 typedef YYSTYPE semantic_type;
257#endif
258 /// Symbol locations.
259 typedef ]b4_location_type[ location_type;
260 /// Tokens.
261 struct token
262 {
263 ]b4_token_enums(b4_tokens)[
264 };
265
266 /// Build a parser object.
267 ]b4_parser_class_name[ (]b4_parse_param_decl[);
268 virtual ~]b4_parser_class_name[ ();
269
270 /// Parse.
271 /// \returns 0 iff parsing succeeded.
272 virtual int parse ();
273
274 /// The current debugging stream.
275 std::ostream& debug_stream () const;
276 /// Set the current debugging stream.
277 void set_debug_stream (std::ostream &);
278
279 /// Type for debugging levels.
280 typedef int debug_level_type;
281 /// The current debugging level.
282 debug_level_type debug_level () const;
283 /// Set the current debugging level.
284 void set_debug_level (debug_level_type l);
285
286 private:
287
288 public:
289 /// Report a syntax error.
290 /// \param loc where the syntax error is found.
291 /// \param msg a description of the syntax error.
292 virtual void error (const location_type& loc, const std::string& msg);
293 private:
294
295#if YYDEBUG
296 public:
c4d497a0
AD
297 /// \brief Report a symbol value on the debug stream.
298 /// \param yytype The token type.
299 /// \param yyvaluep Its semantic value.
300 /// \param yylocationp Its location.
301 virtual void yy_symbol_value_print_ (int yytype,
302 const semantic_type* yyvaluep,
303 const location_type* yylocationp);
42249483
AD
304 /// \brief Report a symbol on the debug stream.
305 /// \param yytype The token type.
306 /// \param yyvaluep Its semantic value.
307 /// \param yylocationp Its location.
c4d497a0
AD
308 virtual void yy_symbol_print_ (int yytype,
309 const semantic_type* yyvaluep,
310 const location_type* yylocationp);
42249483
AD
311 private:
312#endif /* ! YYDEBUG */
313
314
315 /// \brief Reclaim the memory associated to a symbol.
316 /// \param yymsg Why this token is reclaimed.
317 /// \param yytype The symbol type.
318 /// \param yyvaluep Its semantic value.
319 /// \param yylocationp Its location.
320 inline void yydestruct_ (const char* yymsg,
321 int yytype,
322 semantic_type* yyvaluep,
323 location_type* yylocationp);
324
325 /* Debugging. */
326 std::ostream* yycdebug_;
327]b4_parse_param_vars[
328 };
329
330]dnl Redirections for glr.c.
331[#define YYSTYPE yy::]b4_parser_class_name[::semantic_type
332#define YYLTYPE yy::]b4_parser_class_name[::location_type
333
334}
335
336#endif /* ! defined PARSER_HEADER_H */]