]>
Commit | Line | Data |
---|---|---|
60491a94 | 1 | # C++ skeleton for Bison |
b4721715 | 2 | |
cf98343c AD |
3 | # Copyright (C) 2002, 2003, 2004, 2005, 2006, 2007, 2008 |
4 | # Free Software Foundation, Inc. | |
60491a94 | 5 | |
f16b0819 | 6 | # This program is free software: you can redistribute it and/or modify |
60491a94 | 7 | # it under the terms of the GNU General Public License as published by |
f16b0819 | 8 | # the Free Software Foundation, either version 3 of the License, or |
60491a94 | 9 | # (at your option) any later version. |
f16b0819 | 10 | # |
60491a94 AD |
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. | |
f16b0819 | 15 | # |
60491a94 | 16 | # You should have received a copy of the GNU General Public License |
f16b0819 | 17 | # along with this program. If not, see <http://www.gnu.org/licenses/>. |
60491a94 | 18 | |
cf147260 | 19 | m4_include(b4_pkgdatadir/[c++.m4]) |
7eb8a0bc | 20 | |
8901f32e AD |
21 | # b4_table_define(TABLE-NAME, CONTENT) |
22 | # ------------------------------------ | |
23 | # Define "parser::yy<TABLE-NAME>_" which contents is CONTENT. | |
24 | m4_define([b4_table_define], | |
25 | [const b4_int_type_for([$2]) | |
26 | b4_parser_class_name::yy$1_[[]] = | |
27 | { | |
28 | $2 | |
29 | }dnl | |
30 | ]) | |
a9ce3f54 | 31 | |
5ab8c47b AD |
32 | # How the semantic value is extracted when using variants. |
33 | b4_variant_if([ | |
34 | # b4_symbol_value(VAL, [TYPE]) | |
35 | # ---------------------------- | |
36 | m4_define([b4_symbol_value], | |
37 | [m4_ifval([$2], | |
38 | [$1.as<$2>()], | |
39 | [$1])]) | |
40 | ]) # b4_variant_if | |
41 | ||
42 | ||
8901f32e AD |
43 | # b4_assert_if([IF-ASSERTIONS-ARE-USED], [IF-NOT]) |
44 | # ---------------------------------------------------- | |
45 | m4_define([b4_assert_if], | |
46 | [b4_percent_define_ifdef([[assert]], [$1], [$2])]) | |
47 | ||
48 | ||
e1f93869 AD |
49 | # b4_lhs_value([TYPE]) |
50 | # -------------------- | |
51 | # Expansion of $<TYPE>$. | |
52 | m4_define([b4_lhs_value], | |
53 | [b4_symbol_value([yylhs.value], [$1])]) | |
54 | ||
55 | ||
56 | # b4_lhs_location() | |
57 | # ----------------- | |
58 | # Expansion of @$. | |
59 | m4_define([b4_lhs_location], | |
60 | [yylhs.location]) | |
61 | ||
62 | ||
8901f32e AD |
63 | # b4_rhs_value(RULE-LENGTH, NUM, [TYPE]) |
64 | # -------------------------------------- | |
65 | # Expansion of $<TYPE>NUM, where the current rule has RULE-LENGTH | |
66 | # symbols on RHS. | |
67 | m4_define([b4_rhs_value], | |
68 | [b4_symbol_value([yystack_@{($1) - ($2)@}.value], [$3])]) | |
69 | ||
70 | # b4_rhs_location(RULE-LENGTH, NUM) | |
71 | # --------------------------------- | |
72 | # Expansion of @NUM, where the current rule has RULE-LENGTH symbols | |
73 | # on RHS. | |
74 | m4_define([b4_rhs_location], | |
75 | [yystack_@{($1) - ($2)@}.location]) | |
76 | ||
77 | ||
c4585f1e AD |
78 | # b4_symbol_actions(FILENAME, LINENO, |
79 | # SYMBOL-TAG, SYMBOL-NUM, | |
80 | # SYMBOL-ACTION, SYMBOL-TYPENAME) | |
81 | # ------------------------------------------------- | |
82 | # Same as in C, but using references instead of pointers. | |
83 | m4_define([b4_symbol_actions], | |
84 | [m4_pushdef([b4_dollar_dollar], | |
85 | [b4_symbol_value([yyvalue], [$6])])dnl | |
86 | m4_pushdef([b4_at_dollar], [yylocation])dnl | |
87 | case $4: // $3 | |
88 | b4_syncline([$2], [$1]) | |
89 | $5; | |
90 | b4_syncline([@oline@], [@ofile@]) | |
91 | break; | |
92 | m4_popdef([b4_at_dollar])dnl | |
93 | m4_popdef([b4_dollar_dollar])dnl | |
94 | ]) | |
95 | ||
96 | ||
5ab8c47b AD |
97 | # b4_symbol_action_(SYMBOL-TAG, SYMBOL-NUM, SYMBOL-TYPENAME) |
98 | # ---------------------------------------------------------- | |
99 | # Invoke b4_dollar_dollar(SYMBOL_TYPENAME) for each symbol. | |
100 | m4_define([b4_symbol_action_], | |
101 | [m4_ifval($3, | |
102 | [ case $2: // $1 | |
103 | b4_dollar_dollar($@); | |
104 | break; | |
105 | ])]) | |
106 | ||
107 | ||
8901f32e AD |
108 | # b4_symbol_variant(YYTYPE, YYVAL, ACTION, [ARGS]) |
109 | # ------------------------------------------------ | |
5ab8c47b AD |
110 | # Run some ACTION ("build", or "destroy") on YYVAL of symbol type |
111 | # YYTYPE. | |
112 | m4_define([b4_symbol_variant], | |
113 | [m4_pushdef([b4_dollar_dollar], | |
8901f32e | 114 | [$2.$3<$][3>(m4_shift3($@))])dnl |
5ab8c47b AD |
115 | switch ($1) |
116 | { | |
117 | m4_map([b4_symbol_action_], m4_defn([b4_type_names])) | |
118 | default: | |
119 | break; | |
120 | } | |
121 | m4_popdef([b4_dollar_dollar])dnl | |
122 | ]) | |
123 | ||
124 | ||
125 | # _b4_char_sizeof_counter | |
126 | # ----------------------- | |
127 | # A counter used by _b4_char_sizeof_dummy to create fresh symbols. | |
128 | m4_define([_b4_char_sizeof_counter], | |
129 | [0]) | |
130 | ||
131 | # _b4_char_sizeof_dummy | |
132 | # --------------------- | |
133 | # At each call return a new C++ identifier. | |
134 | m4_define([_b4_char_sizeof_dummy], | |
135 | [m4_define([_b4_char_sizeof_counter], m4_incr(_b4_char_sizeof_counter))dnl | |
136 | dummy[]_b4_char_sizeof_counter]) | |
137 | ||
138 | ||
139 | # b4_char_sizeof(SYMBOL-TAG, SYMBOL-NUM, SYMBOL-TYPENAME) | |
140 | # ------------------------------------------------------- | |
141 | # To be mapped on the list of type names to produce: | |
142 | # | |
143 | # char dummy1[sizeof(type_name_1)]; | |
144 | # char dummy2[sizeof(type_name_2)]; | |
145 | # | |
146 | # for defined type names. | |
147 | # $3 is doubly-quoted, do not quote it again. | |
148 | m4_define([b4_char_sizeof], | |
149 | [m4_ifval($3, | |
150 | [ | |
151 | char _b4_char_sizeof_dummy@{sizeof($3)@}; // $1])dnl | |
152 | ]) | |
153 | ||
154 | ||
8901f32e AD |
155 | m4_pushdef([b4_copyright_years], |
156 | [2002, 2003, 2004, 2005, 2006, 2007, 2008]) | |
157 | ||
6afc30cc | 158 | m4_define([b4_parser_class_name], |
a4e25e1d | 159 | [b4_percent_define_get([[parser_class_name]])]) |
34376418 AD |
160 | |
161 | # The header is mandatory. | |
162 | b4_defines_if([], | |
5f340b48 | 163 | [b4_fatal([b4_skeleton[: using %%defines is mandatory]])]) |
34376418 | 164 | |
4626a15d AD |
165 | # Backward compatibility. |
166 | m4_define([b4_location_constructors]) | |
fc695704 | 167 | m4_include(b4_pkgdatadir/[location.cc]) |
a5eb1ed2 | 168 | |
b526ee61 AD |
169 | # We do want M4 expansion after # for CPP macros. |
170 | m4_changecom() | |
08af01c2 | 171 | m4_divert_push(0)dnl |
327afc7c | 172 | b4_defines_if( |
a0d4650a | 173 | [@output(b4_spec_defines_file@)@ |
a9ce3f54 | 174 | b4_copyright([Skeleton interface for Bison LALR(1) parsers in C++]) |
fb9712a9 | 175 | dnl FIXME: This is wrong, we want computed header guards. |
8bb4c753 | 176 | [ |
af3412cd PE |
177 | /* C++ LALR(1) parser skeleton written by Akim Demaille. */ |
178 | ||
c5e3e510 AD |
179 | #ifndef PARSER_HEADER_H |
180 | # define PARSER_HEADER_H | |
2b548aa6 | 181 | |
a4e25e1d | 182 | ]b4_percent_code_get([[requires]])[ |
aef3da86 | 183 | |
8901f32e | 184 | ]b4_assert_if([#include <cassert>])[ |
8d69a1a3 | 185 | #include <string> |
717be197 | 186 | #include <iostream> |
fb9712a9 | 187 | #include "stack.hh" |
50997c6e | 188 | |
793fbca5 | 189 | ]b4_namespace_open[ |
fc695704 AD |
190 | class position; |
191 | class location; | |
8901f32e AD |
192 | ]b4_variant_if( |
193 | [[ | |
5ab8c47b AD |
194 | /// A char[S] buffer to store and retrieve objects. |
195 | /// | |
196 | /// Sort of a variant, but does not keep track of the nature | |
197 | /// of the stored data, since that knowledge is available | |
198 | /// via the current state. | |
199 | template <size_t S> | |
200 | struct variant | |
8901f32e AD |
201 | {]b4_assert_if([ |
202 | /// Whether something is contained. | |
203 | bool built; | |
204 | ||
205 | /// Initially uninitialized. | |
206 | variant () | |
207 | : built(false) | |
208 | {}])[ | |
209 | ||
5ab8c47b AD |
210 | /// Instantiate a \a T in here. |
211 | template <typename T> | |
8901f32e | 212 | inline T& |
5ab8c47b | 213 | build() |
8901f32e AD |
214 | {]b4_assert_if([ |
215 | assert(!built); | |
216 | built = true;])[ | |
217 | return *new (buffer) T; | |
5ab8c47b AD |
218 | } |
219 | ||
220 | /// Accessor to a built \a T. | |
221 | template <typename T> | |
222 | inline T& | |
223 | as() | |
8901f32e AD |
224 | {]b4_assert_if([ |
225 | assert(built);])[ | |
5ab8c47b AD |
226 | return reinterpret_cast<T&>(buffer); |
227 | } | |
228 | ||
229 | /// Const accessor to a built \a T (for %printer). | |
230 | template <typename T> | |
231 | inline const T& | |
232 | as() const | |
8901f32e AD |
233 | {]b4_assert_if([ |
234 | assert(built);])[ | |
5ab8c47b AD |
235 | return reinterpret_cast<const T&>(buffer); |
236 | } | |
237 | ||
8901f32e AD |
238 | /// Swap the content with \a other. |
239 | template <typename T> | |
240 | inline void | |
241 | swap(variant<S>& other) | |
242 | { | |
243 | std::swap(as<T>(), other.as<T>()); | |
244 | } | |
245 | ||
246 | /// Assign the content of \a other to this. | |
247 | /// Destroys \a other. | |
248 | template <typename T> | |
249 | inline void | |
250 | build(variant<S>& other) | |
251 | { | |
252 | build<T>(); | |
253 | swap<T>(other); | |
254 | other.destroy<T>(); | |
255 | } | |
256 | ||
257 | /// Destroy the stored \a T. | |
258 | template <typename T> | |
259 | inline void | |
260 | destroy() | |
261 | { | |
262 | as<T>().~T();]b4_assert_if([ | |
263 | built = false;])[ | |
264 | } | |
265 | ||
5ab8c47b AD |
266 | /// A buffer large enough to store any of the semantic values. |
267 | char buffer[S]; | |
268 | }; | |
269 | ]])[ | |
793fbca5 | 270 | ]b4_namespace_close[ |
4162fa07 | 271 | |
aef3da86 | 272 | #include "location.hh" |
fc695704 | 273 | |
69e2658b RA |
274 | /* Enabling traces. */ |
275 | #ifndef YYDEBUG | |
327afc7c | 276 | # define YYDEBUG ]b4_debug_flag[ |
69e2658b RA |
277 | #endif |
278 | ||
141f5793 PE |
279 | /* Enabling verbose error messages. */ |
280 | #ifdef YYERROR_VERBOSE | |
281 | # undef YYERROR_VERBOSE | |
282 | # define YYERROR_VERBOSE 1 | |
283 | #else | |
327afc7c | 284 | # define YYERROR_VERBOSE ]b4_error_verbose_flag[ |
69e2658b RA |
285 | #endif |
286 | ||
141f5793 PE |
287 | /* Enabling the token table. */ |
288 | #ifndef YYTOKEN_TABLE | |
289 | # define YYTOKEN_TABLE ]b4_token_table[ | |
290 | #endif | |
291 | ||
b4a20338 AD |
292 | /* YYLLOC_DEFAULT -- Set CURRENT to span from RHS[1] to RHS[N]. |
293 | If N is 0, then set CURRENT to the empty location which ends | |
294 | the previous symbol: RHS[0] (always defined). */ | |
3fc16193 | 295 | |
374f5a14 | 296 | #ifndef YYLLOC_DEFAULT |
8901f32e AD |
297 | # define YYLLOC_DEFAULT(Current, Rhs, N) \ |
298 | do { \ | |
299 | if (N) \ | |
300 | { \ | |
301 | (Current).begin = (Rhs)[1].location.begin; \ | |
302 | (Current).end = (Rhs)[N].location.end; \ | |
303 | } \ | |
304 | else \ | |
305 | { \ | |
306 | (Current).begin = (Current).end = (Rhs)[0].location.end; \ | |
307 | } \ | |
2a4647a3 | 308 | } while (false) |
374f5a14 RA |
309 | #endif |
310 | ||
793fbca5 | 311 | ]b4_namespace_open[ |
3f3eed27 | 312 | |
efeed023 | 313 | /// A Bison parser. |
07fed891 | 314 | class ]b4_parser_class_name[ |
2b548aa6 | 315 | { |
fb9712a9 | 316 | public: |
02650b7f | 317 | #ifndef YYSTYPE |
5ab8c47b AD |
318 | ]b4_variant_if( |
319 | [ /// An auxiliary type to compute the largest semantic type. | |
320 | union union_type | |
321 | {]m4_map([b4_char_sizeof], m4_defn([b4_type_names]))[ | |
322 | }; | |
323 | ||
324 | /// Symbol semantic values. | |
325 | typedef variant<sizeof(union_type)> semantic_type;], | |
326 | [ /// Symbol semantic values. | |
327 | m4_ifdef([b4_stype], | |
1221b78a | 328 | [ union semantic_type |
5ab8c47b | 329 | {b4_user_stype |
7ecec4dd | 330 | };], |
ddc8ede1 PE |
331 | [m4_if(b4_tag_seen_flag, 0, |
332 | [[ typedef int semantic_type;]], | |
5ab8c47b | 333 | [[ typedef YYSTYPE semantic_type;]])])])[ |
fb9712a9 | 334 | #else |
f479c6c6 | 335 | typedef YYSTYPE semantic_type; |
fb9712a9 | 336 | #endif |
617a8f12 | 337 | /// Symbol locations. |
a4e25e1d | 338 | typedef ]b4_percent_define_get([[location_type]])[ location_type; |
fb9712a9 AD |
339 | /// Tokens. |
340 | struct token | |
341 | { | |
342 | ]b4_token_enums(b4_tokens)[ | |
343 | }; | |
c095d689 AD |
344 | /// Token type. |
345 | typedef token::yytokentype token_type; | |
2b548aa6 | 346 | |
efeed023 | 347 | /// Build a parser object. |
98ae9643 AD |
348 | ]b4_parser_class_name[ (]b4_parse_param_decl[); |
349 | virtual ~]b4_parser_class_name[ (); | |
2b548aa6 | 350 | |
f69a4142 AD |
351 | /// Parse. |
352 | /// \returns 0 iff parsing succeeded. | |
e019c247 | 353 | virtual int parse (); |
2b548aa6 | 354 | |
52cbbe84 | 355 | #if YYDEBUG |
f69a4142 | 356 | /// The current debugging stream. |
9a1e9989 AD |
357 | std::ostream& debug_stream () const; |
358 | /// Set the current debugging stream. | |
359 | void set_debug_stream (std::ostream &); | |
360 | ||
a3cb6248 AD |
361 | /// Type for debugging levels. |
362 | typedef int debug_level_type; | |
363 | /// The current debugging level. | |
364 | debug_level_type debug_level () const; | |
365 | /// Set the current debugging level. | |
366 | void set_debug_level (debug_level_type l); | |
52cbbe84 | 367 | #endif |
a3cb6248 | 368 | |
2b548aa6 | 369 | private: |
efeed023 AD |
370 | /// Report a syntax error. |
371 | /// \param loc where the syntax error is found. | |
372 | /// \param msg a description of the syntax error. | |
99880de5 | 373 | virtual void error (const location_type& loc, const std::string& msg); |
efeed023 | 374 | |
dbcdae2d | 375 | /// Generate an error message. |
d4fb5e3c | 376 | /// \param state the state where the error occurred. |
742e4900 | 377 | /// \param tok the lookahead token. |
8901f32e | 378 | virtual std::string yysyntax_error_ (int yystate, int tok); |
efeed023 | 379 | |
a5eb1ed2 | 380 | #if YYDEBUG |
a0af42fc AD |
381 | /// \brief Report a symbol value on the debug stream. |
382 | /// \param yytype The token type. | |
c4585f1e AD |
383 | /// \param yyvalue Its semantic value. |
384 | /// \param yylocation Its location. | |
a0af42fc | 385 | virtual void yy_symbol_value_print_ (int yytype, |
c4585f1e AD |
386 | const semantic_type& yyvalue, |
387 | const location_type& yylocation); | |
f69a4142 AD |
388 | /// \brief Report a symbol on the debug stream. |
389 | /// \param yytype The token type. | |
c4585f1e AD |
390 | /// \param yyvalue Its semantic value. |
391 | /// \param yylocation Its location. | |
a0af42fc | 392 | virtual void yy_symbol_print_ (int yytype, |
c4585f1e AD |
393 | const semantic_type& yyvalue, |
394 | const location_type& yylocation); | |
fa7b79c0 | 395 | #endif |
a5eb1ed2 | 396 | |
e019c247 | 397 | /// State numbers. |
f479c6c6 | 398 | typedef int state_type; |
2b548aa6 | 399 | |
e019c247 | 400 | /// Internal symbol numbers. |
f479c6c6 | 401 | typedef ]b4_int_type_for([b4_translate])[ token_number_type; |
2b548aa6 | 402 | /* Tables. */ |
efeed023 | 403 | /// For a state, the index in \a yytable_ of its portion. |
617a8f12 AD |
404 | static const ]b4_int_type_for([b4_pact])[ yypact_[]; |
405 | static const ]b4_int_type(b4_pact_ninf, b4_pact_ninf)[ yypact_ninf_; | |
efeed023 AD |
406 | |
407 | /// For a state, default rule to reduce. | |
408 | /// Unless\a yytable_ specifies something else to do. | |
409 | /// Zero means the default is an error. | |
617a8f12 | 410 | static const ]b4_int_type_for([b4_defact])[ yydefact_[]; |
efeed023 | 411 | |
617a8f12 AD |
412 | static const ]b4_int_type_for([b4_pgoto])[ yypgoto_[]; |
413 | static const ]b4_int_type_for([b4_defgoto])[ yydefgoto_[]; | |
efeed023 AD |
414 | |
415 | /// What to do in a state. | |
416 | /// \a yytable_[yypact_[s]]: what to do in state \a s. | |
417 | /// - if positive, shift that token. | |
418 | /// - if negative, reduce the rule which number is the opposite. | |
419 | /// - if zero, do what YYDEFACT says. | |
617a8f12 AD |
420 | static const ]b4_int_type_for([b4_table])[ yytable_[]; |
421 | static const ]b4_int_type(b4_table_ninf, b4_table_ninf)[ yytable_ninf_; | |
efeed023 | 422 | |
617a8f12 | 423 | static const ]b4_int_type_for([b4_check])[ yycheck_[]; |
efeed023 AD |
424 | |
425 | /// For a state, its accessing symbol. | |
617a8f12 | 426 | static const ]b4_int_type_for([b4_stos])[ yystos_[]; |
efeed023 AD |
427 | |
428 | /// For a rule, its LHS. | |
617a8f12 | 429 | static const ]b4_int_type_for([b4_r1])[ yyr1_[]; |
efeed023 | 430 | /// For a rule, its RHS length. |
617a8f12 | 431 | static const ]b4_int_type_for([b4_r2])[ yyr2_[]; |
69e2658b | 432 | |
141f5793 | 433 | #if YYDEBUG || YYERROR_VERBOSE || YYTOKEN_TABLE |
efeed023 | 434 | /// For a symbol, its name in clear. |
9e0876fb PE |
435 | static const char* const yytname_[]; |
436 | #endif | |
437 | ||
438 | #if YYERROR_VERBOSE | |
439 | /// Convert the symbol name \a n to a form suitable for a diagnostic. | |
440 | virtual std::string yytnamerr_ (const char *n); | |
69e2658b | 441 | #endif |
2b548aa6 | 442 | |
69e2658b | 443 | #if YYDEBUG |
617a8f12 | 444 | /// A `-1'-separated list of the rules' RHS. |
8901f32e | 445 | static const ]b4_int_type_for([b4_rhs])[ yyrhs_[]; |
617a8f12 AD |
446 | /// For each rule, the index of the first RHS symbol in \a yyrhs_. |
447 | static const ]b4_int_type_for([b4_prhs])[ yyprhs_[]; | |
448 | /// For each rule, its source line number. | |
449 | static const ]b4_int_type_for([b4_rline])[ yyrline_[]; | |
450 | /// For each scanner token number, its symbol number. | |
451 | static const ]b4_int_type_for([b4_toknum])[ yytoken_number_[]; | |
efeed023 | 452 | /// Report on the debug stream that the rule \a r is going to be reduced. |
d1ff7a7c | 453 | virtual void yy_reduce_print_ (int r); |
efeed023 | 454 | /// Print the state stack on the debug stream. |
f69a4142 | 455 | virtual void yystack_print_ (); |
fa7b79c0 PE |
456 | |
457 | /* Debugging. */ | |
458 | int yydebug_; | |
459 | std::ostream* yycdebug_; | |
69e2658b | 460 | #endif |
2b548aa6 | 461 | |
32c96bd7 AD |
462 | /// Convert a scanner token number \a t to a symbol number. |
463 | token_number_type yytranslate_ (int t); | |
f69a4142 AD |
464 | |
465 | /// \brief Reclaim the memory associated to a symbol. | |
466 | /// \param yymsg Why this token is reclaimed. | |
8901f32e | 467 | /// If null, nothing is printed at all. |
f69a4142 | 468 | /// \param yytype The symbol type. |
c4585f1e AD |
469 | /// \param yyvalue Its semantic value. |
470 | /// \param yylocation Its location. | |
f69a4142 | 471 | inline void yydestruct_ (const char* yymsg, |
02650b7f | 472 | int yytype, |
c4585f1e AD |
473 | semantic_type& yyvalue, |
474 | location_type& yylocation); | |
2b548aa6 | 475 | |
8901f32e AD |
476 | /// Element of the stack: a state and its attributes. |
477 | struct data_type | |
478 | { | |
479 | /// Default constructor. | |
480 | data_type (); | |
481 | ||
482 | /// Constructor. | |
483 | data_type (state_type s, const semantic_type& v, const location_type& l); | |
484 | ||
485 | /// The state. | |
486 | state_type state; | |
487 | ||
488 | /// The semantic value. | |
489 | semantic_type value; | |
490 | ||
491 | /// The location. | |
492 | location_type location; | |
493 | }; | |
494 | ||
495 | /// Stack type. | |
496 | typedef stack<data_type> stack_type; | |
497 | ||
498 | /// The stack. | |
499 | stack_type yystack_; | |
500 | ||
7dedf26e | 501 | /// Push a new state on the stack. |
9380cfd0 AD |
502 | /// \param m a debug message to display |
503 | /// if null, no trace is output. | |
504 | /// \param s the state entered | |
505 | /// \param v semantic value | |
506 | /// \param l location | |
7dedf26e | 507 | /// \warning the contents of \a v is stolen. |
9380cfd0 | 508 | inline void yypush_ (const char* m, state_type s, |
7dedf26e AD |
509 | semantic_type& v, const location_type& l); |
510 | ||
52d5733f | 511 | /// Pop \a n symbols the three stacks. |
f69a4142 | 512 | inline void yypop_ (unsigned int n = 1); |
52d5733f | 513 | |
762a801e | 514 | /* Constants. */ |
617a8f12 | 515 | static const int yyeof_; |
39912f52 | 516 | /* LAST_ -- Last index in TABLE_. */ |
617a8f12 AD |
517 | static const int yylast_; |
518 | static const int yynnts_; | |
519 | static const int yyempty_; | |
520 | static const int yyfinal_; | |
521 | static const int yyterror_; | |
522 | static const int yyerrcode_; | |
523 | static const int yyntokens_; | |
524 | static const unsigned int yyuser_token_number_max_; | |
99880de5 | 525 | static const token_number_type yyundef_token_; |
caf37a36 | 526 | ]b4_parse_param_vars[ |
2b548aa6 | 527 | }; |
793fbca5 | 528 | ]b4_namespace_close[ |
2b548aa6 | 529 | |
592d0b1e | 530 | ]b4_percent_define_flag_if([[global_tokens_and_yystype]], |
fb9712a9 AD |
531 | [b4_token_defines(b4_tokens) |
532 | ||
533 | #ifndef YYSTYPE | |
9d9b8b70 | 534 | /* Redirection for backward compatibility. */ |
793fbca5 | 535 | # define YYSTYPE b4_namespace_ref::b4_parser_class_name::semantic_type |
fb9712a9 | 536 | #endif |
9bc0dd67 | 537 | ]) |
a4e25e1d | 538 | b4_percent_code_get([[provides]])[]dnl |
9bc0dd67 JD |
539 | |
540 | [#endif /* ! defined PARSER_HEADER_H */] | |
b61c6978 | 541 | ])dnl |
a0d4650a | 542 | @output(b4_parser_file_name@)@ |
a9ce3f54 | 543 | b4_copyright([Skeleton implementation for Bison LALR(1) parsers in C++]) |
a4e25e1d | 544 | b4_percent_code_get([[top]])[]dnl |
aa08666d | 545 | m4_if(b4_prefix, [yy], [], |
c5b95ccf AD |
546 | [ |
547 | // Take the name prefix into account. | |
9bc0dd67 JD |
548 | #define yylex b4_prefix[]lex])[ |
549 | ||
550 | /* First part of user declarations. */ | |
136a0f76 | 551 | ]b4_user_pre_prologue |
9bc0dd67 | 552 | |
bd9d212b JD |
553 | b4_defines_if([[ |
554 | #include "@basename(]b4_spec_defines_file[@)"]])[ | |
50997c6e | 555 | |
fb9712a9 | 556 | /* User implementation prologue. */ |
8e0a5e9e | 557 | ]b4_user_post_prologue |
a4e25e1d | 558 | b4_percent_code_get[]dnl |
fb9712a9 | 559 | |
8e0a5e9e | 560 | [#ifndef YY_ |
30757c8c PE |
561 | # if YYENABLE_NLS |
562 | # if ENABLE_NLS | |
563 | # include <libintl.h> /* FIXME: INFRINGES ON USER NAME SPACE */ | |
564 | # define YY_(msgid) dgettext ("bison-runtime", msgid) | |
565 | # endif | |
566 | # endif | |
567 | # ifndef YY_ | |
568 | # define YY_(msgid) msgid | |
569 | # endif | |
989b5b8e AD |
570 | #endif |
571 | ||
2a4647a3 | 572 | /* Suppress unused-variable warnings by "using" E. */ |
12ce2df6 | 573 | #define YYUSE(e) ((void) (e)) |
2a4647a3 | 574 | |
2b548aa6 | 575 | /* Enable debugging if requested. */ |
50997c6e | 576 | #if YYDEBUG |
284acc8b | 577 | |
fa7b79c0 PE |
578 | /* A pseudo ostream that takes yydebug_ into account. */ |
579 | # define YYCDEBUG if (yydebug_) (*yycdebug_) | |
580 | ||
284acc8b | 581 | # define YY_SYMBOL_PRINT(Title, Type, Value, Location) \ |
8901f32e AD |
582 | do { \ |
583 | if (yydebug_) \ | |
284acc8b | 584 | { \ |
d1ff7a7c | 585 | *yycdebug_ << Title << ' '; \ |
a0af42fc | 586 | yy_symbol_print_ ((Type), (Value), (Location)); \ |
9a1e9989 | 587 | *yycdebug_ << std::endl; \ |
284acc8b | 588 | } \ |
8901f32e | 589 | } while (false) |
284acc8b | 590 | |
5348bfbe | 591 | # define YY_REDUCE_PRINT(Rule) \ |
8901f32e AD |
592 | do { \ |
593 | if (yydebug_) \ | |
594 | yy_reduce_print_ (Rule); \ | |
595 | } while (false) | |
284acc8b | 596 | |
25f66e1a | 597 | # define YY_STACK_PRINT() \ |
8901f32e AD |
598 | do { \ |
599 | if (yydebug_) \ | |
600 | yystack_print_ (); \ | |
601 | } while (false) | |
284acc8b | 602 | |
2b548aa6 | 603 | #else /* !YYDEBUG */ |
284acc8b | 604 | |
a36b333c | 605 | # define YYCDEBUG if (false) std::cerr |
8901f32e AD |
606 | # define YY_SYMBOL_PRINT(Title, Type, Value, Location) static_cast<void>(0) |
607 | # define YY_REDUCE_PRINT(Rule) static_cast<void>(0) | |
608 | # define YY_STACK_PRINT() static_cast<void>(0) | |
284acc8b | 609 | |
2b548aa6 RA |
610 | #endif /* !YYDEBUG */ |
611 | ||
98e26a92 AD |
612 | #define yyerrok (yyerrstatus_ = 0) |
613 | #define yyclearin (yychar = yyempty_) | |
614 | ||
60a777aa AD |
615 | #define YYACCEPT goto yyacceptlab |
616 | #define YYABORT goto yyabortlab | |
47301314 | 617 | #define YYERROR goto yyerrorlab |
98e26a92 | 618 | #define YYRECOVERING() (!!yyerrstatus_) |
60a777aa | 619 | |
793fbca5 | 620 | ]b4_namespace_open[ |
aa08666d | 621 | #if YYERROR_VERBOSE |
9e0876fb | 622 | |
aa08666d AD |
623 | /* Return YYSTR after stripping away unnecessary quotes and |
624 | backslashes, so that it's suitable for yyerror. The heuristic is | |
625 | that double-quoting is unnecessary unless the string contains an | |
626 | apostrophe, a comma, or backslash (other than backslash-backslash). | |
627 | YYSTR is taken from yytname. */ | |
628 | std::string | |
629 | ]b4_parser_class_name[::yytnamerr_ (const char *yystr) | |
630 | { | |
631 | if (*yystr == '"') | |
632 | { | |
633 | std::string yyr = ""; | |
634 | char const *yyp = yystr; | |
193d7c70 | 635 | |
aa08666d AD |
636 | for (;;) |
637 | switch (*++yyp) | |
638 | { | |
639 | case '\'': | |
640 | case ',': | |
641 | goto do_not_strip_quotes; | |
193d7c70 | 642 | |
aa08666d AD |
643 | case '\\': |
644 | if (*++yyp != '\\') | |
645 | goto do_not_strip_quotes; | |
646 | /* Fall through. */ | |
647 | default: | |
648 | yyr += *yyp; | |
649 | break; | |
193d7c70 | 650 | |
aa08666d AD |
651 | case '"': |
652 | return yyr; | |
653 | } | |
654 | do_not_strip_quotes: ; | |
655 | } | |
193d7c70 | 656 | |
aa08666d AD |
657 | return yystr; |
658 | } | |
9e0876fb PE |
659 | |
660 | #endif | |
661 | ||
98ae9643 | 662 | /// Build a parser object. |
fa7b79c0 PE |
663 | ]b4_parser_class_name::b4_parser_class_name[ (]b4_parse_param_decl[)]m4_ifset([b4_parse_param], [ |
664 | :])[ | |
665 | #if YYDEBUG | |
666 | ]m4_ifset([b4_parse_param], [ ], [ :])[yydebug_ (false), | |
667 | yycdebug_ (&std::cerr)]m4_ifset([b4_parse_param], [,])[ | |
668 | #endif]b4_parse_param_cons[ | |
98ae9643 AD |
669 | { |
670 | } | |
a0e68930 | 671 | |
98ae9643 AD |
672 | ]b4_parser_class_name::~b4_parser_class_name[ () |
673 | { | |
674 | } | |
a0e68930 | 675 | |
98ae9643 AD |
676 | #if YYDEBUG |
677 | /*--------------------------------. | |
678 | | Print this symbol on YYOUTPUT. | | |
679 | `--------------------------------*/ | |
a0e68930 | 680 | |
a0af42fc AD |
681 | inline void |
682 | ]b4_parser_class_name[::yy_symbol_value_print_ (int yytype, | |
c4585f1e | 683 | const semantic_type& yyvalue, const location_type& yylocation) |
98ae9643 | 684 | { |
c4585f1e AD |
685 | YYUSE (yylocation); |
686 | YYUSE (yyvalue); | |
98ae9643 AD |
687 | switch (yytype) |
688 | { | |
689 | ]m4_map([b4_symbol_actions], m4_defn([b4_symbol_printers]))dnl | |
690 | [ default: | |
02650b7f | 691 | break; |
98ae9643 | 692 | } |
a0af42fc AD |
693 | } |
694 | ||
695 | ||
696 | void | |
697 | ]b4_parser_class_name[::yy_symbol_print_ (int yytype, | |
c4585f1e | 698 | const semantic_type& yyvalue, const location_type& yylocation) |
a0af42fc AD |
699 | { |
700 | *yycdebug_ << (yytype < yyntokens_ ? "token" : "nterm") | |
02650b7f | 701 | << ' ' << yytname_[yytype] << " (" |
c4585f1e AD |
702 | << yylocation << ": "; |
703 | yy_symbol_value_print_ (yytype, yyvalue, yylocation); | |
98ae9643 AD |
704 | *yycdebug_ << ')'; |
705 | } | |
fa7b79c0 | 706 | #endif |
a0e68930 | 707 | |
98ae9643 AD |
708 | void |
709 | ]b4_parser_class_name[::yydestruct_ (const char* yymsg, | |
c4585f1e | 710 | int yytype, semantic_type& yyvalue, location_type& yylocation) |
98ae9643 | 711 | { |
98ae9643 | 712 | YYUSE (yymsg); |
c4585f1e AD |
713 | YYUSE (yyvalue); |
714 | YYUSE (yylocation); | |
98ae9643 | 715 | |
8901f32e AD |
716 | if (yymsg) |
717 | YY_SYMBOL_PRINT (yymsg, yytype, yyvalue, yylocation); | |
98ae9643 | 718 | |
8901f32e | 719 | // User destructor. |
98ae9643 AD |
720 | switch (yytype) |
721 | { | |
722 | ]m4_map([b4_symbol_actions], m4_defn([b4_symbol_destructors]))[ | |
02650b7f PE |
723 | default: |
724 | break; | |
8901f32e AD |
725 | }]b4_variant_if([ |
726 | ||
727 | // Type destructor. | |
728 | b4_symbol_variant([[yytype]], [[yyvalue]], [[destroy]])])[ | |
729 | } | |
730 | ||
731 | ]b4_parser_class_name[::data_type::data_type () | |
732 | : state() | |
733 | , value() | |
734 | , location() | |
735 | { | |
736 | } | |
737 | ||
738 | ]b4_parser_class_name[::data_type::data_type (state_type s, | |
739 | const semantic_type& v, const location_type& l) | |
740 | : state(s) | |
741 | , value(v) | |
742 | , location(l) | |
743 | { | |
98ae9643 | 744 | } |
60a777aa | 745 | |
7dedf26e | 746 | void |
9380cfd0 | 747 | ]b4_parser_class_name[::yypush_ (const char* m, state_type s, |
7dedf26e AD |
748 | semantic_type& v, const location_type& l) |
749 | { | |
9380cfd0 AD |
750 | if (m) |
751 | YY_SYMBOL_PRINT (m, yystos_[s], v, l); | |
8901f32e AD |
752 | ]b4_variant_if( |
753 | [[ yystack_.push (data_type (s, semantic_type(), l)); | |
754 | ]b4_symbol_variant([[yystos_[s]]], [[yystack_[0].value]], [build], [v])], | |
755 | [ yystack_.push (data_type (s, v, l));])[ | |
7dedf26e AD |
756 | } |
757 | ||
98ae9643 AD |
758 | void |
759 | ]b4_parser_class_name[::yypop_ (unsigned int n) | |
760 | { | |
8901f32e | 761 | yystack_.pop (n); |
98ae9643 | 762 | } |
52d5733f | 763 | |
fa7b79c0 | 764 | #if YYDEBUG |
98ae9643 AD |
765 | std::ostream& |
766 | ]b4_parser_class_name[::debug_stream () const | |
767 | { | |
768 | return *yycdebug_; | |
769 | } | |
9a1e9989 | 770 | |
98ae9643 AD |
771 | void |
772 | ]b4_parser_class_name[::set_debug_stream (std::ostream& o) | |
773 | { | |
774 | yycdebug_ = &o; | |
775 | } | |
9a1e9989 AD |
776 | |
777 | ||
98ae9643 AD |
778 | ]b4_parser_class_name[::debug_level_type |
779 | ]b4_parser_class_name[::debug_level () const | |
780 | { | |
781 | return yydebug_; | |
782 | } | |
a3cb6248 | 783 | |
98ae9643 AD |
784 | void |
785 | ]b4_parser_class_name[::set_debug_level (debug_level_type l) | |
786 | { | |
787 | yydebug_ = l; | |
788 | } | |
fa7b79c0 | 789 | #endif |
a3cb6248 | 790 | |
98ae9643 AD |
791 | int |
792 | ]b4_parser_class_name[::parse () | |
793 | { | |
742e4900 | 794 | /// Lookahead and lookahead in internal form. |
98ae9643 AD |
795 | int yychar = yyempty_; |
796 | int yytoken = 0; | |
d4fb5e3c | 797 | |
98ae9643 AD |
798 | /* State. */ |
799 | int yyn; | |
a85284cf | 800 | int yylen = 0; |
98ae9643 | 801 | int yystate = 0; |
d4fb5e3c | 802 | |
9d9b8b70 | 803 | /* Error handling. */ |
98ae9643 AD |
804 | int yynerrs_ = 0; |
805 | int yyerrstatus_ = 0; | |
dbcdae2d | 806 | |
742e4900 | 807 | /// Semantic value of the lookahead. |
98ae9643 | 808 | semantic_type yylval; |
742e4900 | 809 | /// Location of the lookahead. |
98ae9643 AD |
810 | location_type yylloc; |
811 | /// The locations where the error started and ended. | |
8901f32e | 812 | data_type yyerror_range[2]; |
dbcdae2d | 813 | |
e1f93869 AD |
814 | /// $$ and @@$. |
815 | data_type yylhs; | |
dbcdae2d | 816 | |
e1f93869 | 817 | /// The return value of parse(). |
98ae9643 | 818 | int yyresult; |
ad745863 | 819 | |
98ae9643 | 820 | YYCDEBUG << "Starting parse" << std::endl; |
451364ed | 821 | |
451364ed | 822 | ]m4_ifdef([b4_initial_action], [ |
99880de5 AD |
823 | m4_pushdef([b4_at_dollar], [yylloc])dnl |
824 | m4_pushdef([b4_dollar_dollar], [yylval])dnl | |
9d9b8b70 | 825 | /* User initialization code. */ |
8ec0a172 | 826 | b4_user_initial_action |
451364ed | 827 | m4_popdef([b4_dollar_dollar])dnl |
8ec0a172 | 828 | m4_popdef([b4_at_dollar])])dnl |
451364ed | 829 | |
8901f32e | 830 | [ /* Initialize the stack. The initial state will be set in |
98ae9643 AD |
831 | yynewstate, since the latter expects the semantical and the |
832 | location values to have been already stored, initialize these | |
833 | stacks with a primary value. */ | |
8901f32e | 834 | yystack_ = stack_type (0); |
9380cfd0 | 835 | yypush_ (0, yystate, yylval, yylloc); |
98ae9643 | 836 | |
7dedf26e AD |
837 | // A new state was pushed on the stack. |
838 | // Invariant: yystate == yystack_[0].state, i.e., | |
839 | // yystate was just pushed onto the state stack. | |
98ae9643 | 840 | yynewstate: |
98ae9643 | 841 | YYCDEBUG << "Entering state " << yystate << std::endl; |
868d2d96 JD |
842 | |
843 | /* Accept? */ | |
844 | if (yystate == yyfinal_) | |
845 | goto yyacceptlab; | |
846 | ||
98ae9643 AD |
847 | goto yybackup; |
848 | ||
849 | /* Backup. */ | |
850 | yybackup: | |
851 | ||
742e4900 | 852 | /* Try to take a decision without lookahead. */ |
98ae9643 AD |
853 | yyn = yypact_[yystate]; |
854 | if (yyn == yypact_ninf_) | |
855 | goto yydefault; | |
856 | ||
742e4900 | 857 | /* Read a lookahead token. */ |
98ae9643 AD |
858 | if (yychar == yyempty_) |
859 | { | |
02650b7f PE |
860 | YYCDEBUG << "Reading a token: "; |
861 | yychar = ]b4_c_function_call([yylex], [int], | |
862 | [[YYSTYPE*], [&yylval]][]dnl | |
327afc7c | 863 | b4_locations_if([, [[location*], [&yylloc]]])dnl |
dbcdae2d | 864 | m4_ifdef([b4_lex_param], [, ]b4_lex_param))[; |
98ae9643 AD |
865 | } |
866 | ||
867 | ||
868 | /* Convert token to internal form. */ | |
869 | if (yychar <= yyeof_) | |
870 | { | |
02650b7f PE |
871 | yychar = yytoken = yyeof_; |
872 | YYCDEBUG << "Now at end of input." << std::endl; | |
98ae9643 AD |
873 | } |
874 | else | |
875 | { | |
02650b7f | 876 | yytoken = yytranslate_ (yychar); |
c4585f1e | 877 | YY_SYMBOL_PRINT ("Next token is", yytoken, yylval, yylloc); |
98ae9643 AD |
878 | } |
879 | ||
880 | /* If the proper action on seeing token YYTOKEN is to reduce or to | |
881 | detect an error, take that action. */ | |
882 | yyn += yytoken; | |
34ec3579 | 883 | if (yyn < 0 || yylast_ < yyn || yycheck_[yyn] != yytoken) |
98ae9643 AD |
884 | goto yydefault; |
885 | ||
886 | /* Reduce or error. */ | |
887 | yyn = yytable_[yyn]; | |
888 | if (yyn <= 0) | |
889 | { | |
02650b7f PE |
890 | if (yyn == 0 || yyn == yytable_ninf_) |
891 | goto yyerrlab; | |
892 | yyn = -yyn; | |
893 | goto yyreduce; | |
98ae9643 AD |
894 | } |
895 | ||
868d2d96 JD |
896 | /* Discard the token being shifted. */ |
897 | yychar = yyempty_; | |
98ae9643 AD |
898 | |
899 | /* Count tokens shifted since error; after three, turn off error | |
900 | status. */ | |
901 | if (yyerrstatus_) | |
902 | --yyerrstatus_; | |
903 | ||
9380cfd0 | 904 | /* Shift the lookahead token. */ |
98ae9643 | 905 | yystate = yyn; |
9380cfd0 | 906 | yypush_ ("Shifting", yystate, yylval, yylloc); |
98ae9643 AD |
907 | goto yynewstate; |
908 | ||
909 | /*-----------------------------------------------------------. | |
910 | | yydefault -- do the default action for the current state. | | |
911 | `-----------------------------------------------------------*/ | |
912 | yydefault: | |
913 | yyn = yydefact_[yystate]; | |
914 | if (yyn == 0) | |
915 | goto yyerrlab; | |
916 | goto yyreduce; | |
917 | ||
918 | /*-----------------------------. | |
919 | | yyreduce -- Do a reduction. | | |
920 | `-----------------------------*/ | |
921 | yyreduce: | |
5ab8c47b AD |
922 | yylen = yyr2_[yyn];]b4_variant_if([ |
923 | /* Variants are always initialized to an empty instance of the | |
924 | correct type. The default $$=$1 rule is NOT applied when using | |
925 | variants */ | |
e1f93869 | 926 | ]b4_symbol_variant([[yyr1_@{yyn@}]], [yylhs.value], [build])[],[ |
a85284cf | 927 | /* If YYLEN is nonzero, implement the default value of the action: |
98ae9643 AD |
928 | `$$ = $1'. Otherwise, use the top of the stack. |
929 | ||
e1f93869 | 930 | Otherwise, the following line sets YYLHS.VALUE to garbage. |
98ae9643 AD |
931 | This behavior is undocumented and Bison |
932 | users should not rely upon it. */ | |
933 | if (yylen) | |
e1f93869 | 934 | yylhs.value = yystack_@{yylen - 1@}.value; |
98ae9643 | 935 | else |
e1f93869 | 936 | yylhs.value = yystack_@{0@}.value;])[ |
2b548aa6 | 937 | |
8901f32e | 938 | // Compute the default @@$. |
2b548aa6 | 939 | { |
8901f32e | 940 | slice<data_type, stack_type> slice (yystack_, yylen); |
e1f93869 | 941 | YYLLOC_DEFAULT (yylhs.location, slice, yylen); |
2b548aa6 | 942 | } |
8901f32e AD |
943 | |
944 | // Perform the reduction. | |
98ae9643 AD |
945 | YY_REDUCE_PRINT (yyn); |
946 | switch (yyn) | |
947 | { | |
8ec0a172 | 948 | ]b4_user_actions[ |
cf98343c AD |
949 | default: |
950 | break; | |
98ae9643 | 951 | } |
e1f93869 AD |
952 | // Compute post-reduction state. |
953 | yyn = yyr1_[yyn]; | |
954 | yystate = yypgoto_[yyn - yyntokens_] + yystack_[yylen].state; | |
955 | if (0 <= yystate && yystate <= yylast_ | |
956 | && yycheck_[yystate] == yystack_[yylen].state) | |
957 | yystate = yytable_[yystate]; | |
958 | else | |
959 | yystate = yydefgoto_[yyn - yyntokens_]; | |
960 | yylhs.state = yystate; | |
961 | YY_SYMBOL_PRINT ("-> $$ =", yyn, yylhs.value, yylhs.location); | |
8901f32e AD |
962 | ]b4_variant_if([[ |
963 | // Destroy the lhs symbols. | |
964 | for (int i = 0; i < yylen; ++i) | |
e1f93869 AD |
965 | // Destroy a variant which value may have be swapped with |
966 | // yylhs.value. The value of yylhs.value (hence maybe one of | |
967 | // these lhs symbols) depends on what does the default | |
968 | // contruction for this type. In the case of pointers for | |
969 | // instance, nothing is done, so the value is junk. Therefore | |
970 | // do not try to report the content in the debug trace, it's | |
971 | // junk. Hence yymsg = 0. Besides, that keeps exactly the same | |
972 | // traces as with the other Bison skeletons. | |
8901f32e AD |
973 | yydestruct_ (0, |
974 | yystos_[yystack_[i].state], | |
975 | yystack_[i].value, yystack_[i].location);]])[ | |
98ae9643 AD |
976 | |
977 | yypop_ (yylen); | |
a85284cf | 978 | yylen = 0; |
98ae9643 | 979 | YY_STACK_PRINT (); |
98ae9643 AD |
980 | |
981 | /* Shift the result of the reduction. */ | |
e1f93869 | 982 | yypush_ (0, yylhs.state, yylhs.value, yylhs.location); |
98ae9643 AD |
983 | goto yynewstate; |
984 | ||
985 | /*------------------------------------. | |
986 | | yyerrlab -- here on detecting error | | |
987 | `------------------------------------*/ | |
988 | yyerrlab: | |
989 | /* If not already recovering from an error, report this error. */ | |
990 | if (!yyerrstatus_) | |
991 | { | |
02650b7f | 992 | ++yynerrs_; |
8901f32e | 993 | error (yylloc, yysyntax_error_ (yystate, yytoken)); |
98ae9643 AD |
994 | } |
995 | ||
8901f32e | 996 | yyerror_range[0].location = yylloc; |
98ae9643 AD |
997 | if (yyerrstatus_ == 3) |
998 | { | |
742e4900 | 999 | /* If just tried and failed to reuse lookahead token after an |
02650b7f PE |
1000 | error, discard it. */ |
1001 | ||
1002 | if (yychar <= yyeof_) | |
1003 | { | |
8901f32e AD |
1004 | /* Return failure if at end of input. */ |
1005 | if (yychar == yyeof_) | |
1006 | YYABORT; | |
02650b7f PE |
1007 | } |
1008 | else | |
1009 | { | |
c4585f1e | 1010 | yydestruct_ ("Error: discarding", yytoken, yylval, yylloc); |
02650b7f PE |
1011 | yychar = yyempty_; |
1012 | } | |
98ae9643 AD |
1013 | } |
1014 | ||
742e4900 | 1015 | /* Else will try to reuse lookahead token after shifting the error |
98ae9643 AD |
1016 | token. */ |
1017 | goto yyerrlab1; | |
1018 | ||
1019 | ||
1020 | /*---------------------------------------------------. | |
1021 | | yyerrorlab -- error raised explicitly by YYERROR. | | |
1022 | `---------------------------------------------------*/ | |
1023 | yyerrorlab: | |
1024 | ||
1025 | /* Pacify compilers like GCC when the user code never invokes | |
1026 | YYERROR and the label yyerrorlab therefore never appears in user | |
1027 | code. */ | |
1028 | if (false) | |
1029 | goto yyerrorlab; | |
1030 | ||
8901f32e | 1031 | yyerror_range[0].location = yystack_[yylen - 1].location; |
a85284cf | 1032 | /* Do not reclaim the symbols of the rule which action triggered |
9d9b8b70 | 1033 | this YYERROR. */ |
98ae9643 | 1034 | yypop_ (yylen); |
a85284cf | 1035 | yylen = 0; |
8901f32e | 1036 | yystate = yystack_[0].state; |
98ae9643 AD |
1037 | goto yyerrlab1; |
1038 | ||
1039 | /*-------------------------------------------------------------. | |
1040 | | yyerrlab1 -- common code for both syntax error and YYERROR. | | |
1041 | `-------------------------------------------------------------*/ | |
1042 | yyerrlab1: | |
1043 | yyerrstatus_ = 3; /* Each real token shifted decrements this. */ | |
e1f93869 AD |
1044 | { |
1045 | data_type error_token; | |
1046 | for (;;) | |
1047 | { | |
1048 | yyn = yypact_[yystate]; | |
1049 | if (yyn != yypact_ninf_) | |
1050 | { | |
1051 | yyn += yyterror_; | |
1052 | if (0 <= yyn && yyn <= yylast_ && yycheck_[yyn] == yyterror_) | |
1053 | { | |
1054 | yyn = yytable_[yyn]; | |
1055 | if (0 < yyn) | |
1056 | break; | |
1057 | } | |
1058 | } | |
98ae9643 | 1059 | |
e1f93869 AD |
1060 | // Pop the current state because it cannot handle the error token. |
1061 | if (yystack_.size () == 1) | |
1062 | YYABORT; | |
1063 | ||
1064 | yyerror_range[0].location = yystack_[0].location; | |
1065 | yydestruct_ ("Error: popping", | |
1066 | yystos_[yystate], | |
1067 | yystack_[0].value, yystack_[0].location); | |
1068 | yypop_ (); | |
1069 | yystate = yystack_[0].state; | |
1070 | YY_STACK_PRINT (); | |
1071 | } | |
1072 | ||
1073 | yyerror_range[1].location = yylloc; | |
1074 | YYLLOC_DEFAULT (error_token.location, (yyerror_range - 1), 2); | |
1075 | ||
1076 | /* Shift the error token. */ | |
1077 | yystate = yyn; | |
1078 | yypush_ ("Shifting", yystate, error_token.value, error_token.location); | |
1079 | } | |
98ae9643 AD |
1080 | goto yynewstate; |
1081 | ||
1082 | /* Accept. */ | |
1083 | yyacceptlab: | |
1084 | yyresult = 0; | |
1085 | goto yyreturn; | |
1086 | ||
1087 | /* Abort. */ | |
1088 | yyabortlab: | |
1089 | yyresult = 1; | |
1090 | goto yyreturn; | |
1091 | ||
1092 | yyreturn: | |
868d2d96 | 1093 | if (yychar != yyempty_) |
c4585f1e | 1094 | yydestruct_ ("Cleanup: discarding lookahead", yytoken, yylval, yylloc); |
98ae9643 | 1095 | |
a85284cf | 1096 | /* Do not reclaim the symbols of the rule which action triggered |
9d9b8b70 | 1097 | this YYABORT or YYACCEPT. */ |
a85284cf | 1098 | yypop_ (yylen); |
8901f32e | 1099 | while (yystack_.size () != 1) |
98ae9643 | 1100 | { |
02650b7f | 1101 | yydestruct_ ("Cleanup: popping", |
8901f32e AD |
1102 | yystos_[yystack_[0].state], |
1103 | yystack_[0].value, yystack_[0].location); | |
02650b7f | 1104 | yypop_ (); |
98ae9643 AD |
1105 | } |
1106 | ||
1107 | return yyresult; | |
1108 | } | |
2b548aa6 | 1109 | |
98ae9643 AD |
1110 | // Generate an error message. |
1111 | std::string | |
8901f32e AD |
1112 | ]b4_parser_class_name[::yysyntax_error_ (int yystate, int]dnl |
1113 | b4_error_verbose_if([ tok])[) | |
98ae9643 AD |
1114 | { |
1115 | std::string res; | |
c66dfadd | 1116 | YYUSE (yystate); |
a08460b0 | 1117 | #if YYERROR_VERBOSE |
98ae9643 | 1118 | int yyn = yypact_[yystate]; |
d6645148 | 1119 | if (yypact_ninf_ < yyn && yyn <= yylast_) |
98ae9643 | 1120 | { |
02650b7f PE |
1121 | /* Start YYX at -YYN if negative to avoid negative indexes in |
1122 | YYCHECK. */ | |
1123 | int yyxbegin = yyn < 0 ? -yyn : 0; | |
1124 | ||
1125 | /* Stay within bounds of both yycheck and yytname. */ | |
d6645148 | 1126 | int yychecklim = yylast_ - yyn + 1; |
02650b7f PE |
1127 | int yyxend = yychecklim < yyntokens_ ? yychecklim : yyntokens_; |
1128 | int count = 0; | |
1129 | for (int x = yyxbegin; x < yyxend; ++x) | |
34ec3579 | 1130 | if (yycheck_[x + yyn] == x && x != yyterror_) |
02650b7f PE |
1131 | ++count; |
1132 | ||
1133 | // FIXME: This method of building the message is not compatible | |
1134 | // with internationalization. It should work like yacc.c does it. | |
1135 | // That is, first build a string that looks like this: | |
1136 | // "syntax error, unexpected %s or %s or %s" | |
1137 | // Then, invoke YY_ on this string. | |
1138 | // Finally, use the string as a format to output | |
1139 | // yytname_[tok], etc. | |
1140 | // Until this gets fixed, this message appears in English only. | |
1141 | res = "syntax error, unexpected "; | |
1142 | res += yytnamerr_ (yytname_[tok]); | |
1143 | if (count < 5) | |
1144 | { | |
1145 | count = 0; | |
1146 | for (int x = yyxbegin; x < yyxend; ++x) | |
34ec3579 | 1147 | if (yycheck_[x + yyn] == x && x != yyterror_) |
02650b7f PE |
1148 | { |
1149 | res += (!count++) ? ", expecting " : " or "; | |
1150 | res += yytnamerr_ (yytname_[x]); | |
1151 | } | |
1152 | } | |
98ae9643 AD |
1153 | } |
1154 | else | |
dbcdae2d | 1155 | #endif |
98ae9643 AD |
1156 | res = YY_("syntax error"); |
1157 | return res; | |
1158 | } | |
a08460b0 | 1159 | |
5348bfbe | 1160 | |
98ae9643 AD |
1161 | /* YYPACT[STATE-NUM] -- Index in YYTABLE of the portion describing |
1162 | STATE-NUM. */ | |
1163 | const ]b4_int_type(b4_pact_ninf, b4_pact_ninf) b4_parser_class_name::yypact_ninf_ = b4_pact_ninf[; | |
8901f32e | 1164 | ]b4_table_define([pact], [b4_pact])[; |
2b548aa6 | 1165 | |
98ae9643 AD |
1166 | /* YYDEFACT[S] -- default rule to reduce with in state S when YYTABLE |
1167 | doesn't specify something else to do. Zero means the default is an | |
1168 | error. */ | |
8901f32e | 1169 | ]b4_table_define([defact], [b4_defact])[; |
2b548aa6 | 1170 | |
98ae9643 | 1171 | /* YYPGOTO[NTERM-NUM]. */ |
8901f32e | 1172 | ]b4_table_define([pgoto], [b4_pgoto])[; |
2b548aa6 | 1173 | |
98ae9643 | 1174 | /* YYDEFGOTO[NTERM-NUM]. */ |
8901f32e | 1175 | ]b4_table_define([defgoto], [b4_defgoto])[; |
2b548aa6 | 1176 | |
98ae9643 AD |
1177 | /* YYTABLE[YYPACT[STATE-NUM]]. What to do in state STATE-NUM. If |
1178 | positive, shift that token. If negative, reduce the rule which | |
1179 | number is the opposite. If zero, do what YYDEFACT says. */ | |
1180 | const ]b4_int_type(b4_table_ninf, b4_table_ninf) b4_parser_class_name::yytable_ninf_ = b4_table_ninf[; | |
8901f32e | 1181 | ]b4_table_define([table], [b4_table])[; |
98ae9643 AD |
1182 | |
1183 | /* YYCHECK. */ | |
8901f32e | 1184 | ]b4_table_define([check], [b4_check])[; |
98ae9643 AD |
1185 | |
1186 | /* STOS_[STATE-NUM] -- The (internal number of the) accessing | |
1187 | symbol of state STATE-NUM. */ | |
8901f32e | 1188 | ]b4_table_define([stos], [b4_stos])[; |
769b430f | 1189 | |
45d5982f | 1190 | #if YYDEBUG |
98ae9643 AD |
1191 | /* TOKEN_NUMBER_[YYLEX-NUM] -- Internal symbol number corresponding |
1192 | to YYLEX-NUM. */ | |
8901f32e | 1193 | ]b4_table_define([token_number], [b4_toknum])[; |
769b430f AD |
1194 | #endif |
1195 | ||
98ae9643 | 1196 | /* YYR1[YYN] -- Symbol number of symbol that rule YYN derives. */ |
8901f32e | 1197 | ]b4_table_define([r1], [b4_r1])[; |
2b548aa6 | 1198 | |
98ae9643 | 1199 | /* YYR2[YYN] -- Number of symbols composing right hand side of rule YYN. */ |
8901f32e | 1200 | ]b4_table_define([r2], [b4_r2])[; |
2b548aa6 | 1201 | |
141f5793 | 1202 | #if YYDEBUG || YYERROR_VERBOSE || YYTOKEN_TABLE |
98ae9643 | 1203 | /* YYTNAME[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM. |
9d9b8b70 | 1204 | First, the terminals, then, starting at \a yyntokens_, nonterminals. */ |
98ae9643 AD |
1205 | const char* |
1206 | const ]b4_parser_class_name[::yytname_[] = | |
1207 | { | |
8901f32e | 1208 | ]b4_tname[ |
98ae9643 | 1209 | }; |
69e2658b | 1210 | #endif |
2b548aa6 | 1211 | |
69e2658b | 1212 | #if YYDEBUG |
9d9b8b70 | 1213 | /* YYRHS -- A `-1'-separated list of the rules' RHS. */ |
8901f32e | 1214 | ]b4_table_define([rhs], [b4_rhs])[; |
2b548aa6 | 1215 | |
98ae9643 AD |
1216 | /* YYPRHS[YYN] -- Index of the first RHS symbol of rule number YYN in |
1217 | YYRHS. */ | |
8901f32e | 1218 | ]b4_table_define([prhs], [b4_prhs])[; |
2b548aa6 | 1219 | |
98ae9643 | 1220 | /* YYRLINE[YYN] -- Source line where rule number YYN was defined. */ |
8901f32e | 1221 | ]b4_table_define([rline], [b4_rline])[; |
5348bfbe | 1222 | |
98ae9643 AD |
1223 | // Print the state stack on the debug stream. |
1224 | void | |
1225 | ]b4_parser_class_name[::yystack_print_ () | |
1226 | { | |
1227 | *yycdebug_ << "Stack now"; | |
8901f32e AD |
1228 | for (stack_type::const_iterator |
1229 | i = yystack_.begin (), | |
1230 | i_end = yystack_.end (); | |
1231 | i != i_end; ++i) | |
1232 | *yycdebug_ << ' ' << i->state; | |
98ae9643 AD |
1233 | *yycdebug_ << std::endl; |
1234 | } | |
25f66e1a | 1235 | |
98ae9643 AD |
1236 | // Report on the debug stream that the rule \a yyrule is going to be reduced. |
1237 | void | |
d1ff7a7c | 1238 | ]b4_parser_class_name[::yy_reduce_print_ (int yyrule) |
98ae9643 AD |
1239 | { |
1240 | unsigned int yylno = yyrline_[yyrule]; | |
d1ff7a7c | 1241 | int yynrhs = yyr2_[yyrule]; |
98ae9643 AD |
1242 | /* Print the symbols being reduced, and their result. */ |
1243 | *yycdebug_ << "Reducing stack by rule " << yyrule - 1 | |
7cff04b5 | 1244 | << " (line " << yylno << "):" << std::endl; |
d1ff7a7c AD |
1245 | /* The symbols being reduced. */ |
1246 | for (int yyi = 0; yyi < yynrhs; yyi++) | |
1247 | YY_SYMBOL_PRINT (" $" << yyi + 1 << " =", | |
02650b7f | 1248 | yyrhs_[yyprhs_[yyrule] + yyi], |
c4585f1e AD |
1249 | ]b4_rhs_value(yynrhs, yyi + 1)[, |
1250 | ]b4_rhs_location(yynrhs, yyi + 1)[); | |
98ae9643 | 1251 | } |
5348bfbe | 1252 | #endif // YYDEBUG |
69e2658b | 1253 | |
98ae9643 AD |
1254 | /* YYTRANSLATE(YYLEX) -- Bison symbol number corresponding to YYLEX. */ |
1255 | ]b4_parser_class_name[::token_number_type | |
32c96bd7 | 1256 | ]b4_parser_class_name[::yytranslate_ (int t) |
2b548aa6 | 1257 | { |
98ae9643 AD |
1258 | static |
1259 | const token_number_type | |
1260 | translate_table[] = | |
1261 | { | |
8901f32e | 1262 | ]b4_translate[ |
98ae9643 | 1263 | }; |
32c96bd7 AD |
1264 | if ((unsigned int) t <= yyuser_token_number_max_) |
1265 | return translate_table[t]; | |
98ae9643 AD |
1266 | else |
1267 | return yyundef_token_; | |
1268 | } | |
1269 | ||
1270 | const int ]b4_parser_class_name[::yyeof_ = 0; | |
1271 | const int ]b4_parser_class_name[::yylast_ = ]b4_last[; | |
1272 | const int ]b4_parser_class_name[::yynnts_ = ]b4_nterms_number[; | |
1273 | const int ]b4_parser_class_name[::yyempty_ = -2; | |
1274 | const int ]b4_parser_class_name[::yyfinal_ = ]b4_final_state_number[; | |
1275 | const int ]b4_parser_class_name[::yyterror_ = 1; | |
1276 | const int ]b4_parser_class_name[::yyerrcode_ = 256; | |
1277 | const int ]b4_parser_class_name[::yyntokens_ = ]b4_tokens_number[; | |
1278 | ||
1279 | const unsigned int ]b4_parser_class_name[::yyuser_token_number_max_ = ]b4_user_token_number_max[; | |
1280 | const ]b4_parser_class_name[::token_number_type ]b4_parser_class_name[::yyundef_token_ = ]b4_undef_token_number[; | |
2b548aa6 | 1281 | |
793fbca5 | 1282 | ]b4_namespace_close[ |
2b548aa6 | 1283 | |
8901f32e | 1284 | ]b4_epilogue[]dnl |
a0d4650a | 1285 | @output(b4_dir_prefix[]stack.hh@)@ |
a9ce3f54 | 1286 | b4_copyright([Stack handling for Bison parsers in C++])[ |
98254360 | 1287 | |
2b548aa6 RA |
1288 | #ifndef BISON_STACK_HH |
1289 | # define BISON_STACK_HH | |
1290 | ||
45119f04 | 1291 | #include <deque> |
2b548aa6 | 1292 | |
793fbca5 | 1293 | ]b4_namespace_open[ |
f85a5e6f | 1294 | template <class T, class S = std::deque<T> > |
99880de5 | 1295 | class stack |
2b548aa6 RA |
1296 | { |
1297 | public: | |
1298 | ||
ecfe33e7 AD |
1299 | // Hide our reversed order. |
1300 | typedef typename S::reverse_iterator iterator; | |
1301 | typedef typename S::const_reverse_iterator const_iterator; | |
2b548aa6 | 1302 | |
99880de5 | 1303 | stack () : seq_ () |
2b548aa6 RA |
1304 | { |
1305 | } | |
1306 | ||
99880de5 | 1307 | stack (unsigned int n) : seq_ (n) |
2b548aa6 RA |
1308 | { |
1309 | } | |
1310 | ||
1311 | inline | |
1312 | T& | |
779e7ceb | 1313 | operator [] (unsigned int i) |
2b548aa6 | 1314 | { |
1d4055aa | 1315 | return seq_[i]; |
2b548aa6 RA |
1316 | } |
1317 | ||
1318 | inline | |
1319 | const T& | |
779e7ceb | 1320 | operator [] (unsigned int i) const |
2b548aa6 | 1321 | { |
1d4055aa | 1322 | return seq_[i]; |
2b548aa6 RA |
1323 | } |
1324 | ||
1325 | inline | |
1326 | void | |
1327 | push (const T& t) | |
1328 | { | |
45119f04 | 1329 | seq_.push_front (t); |
2b548aa6 RA |
1330 | } |
1331 | ||
1332 | inline | |
1333 | void | |
779e7ceb | 1334 | pop (unsigned int n = 1) |
2b548aa6 RA |
1335 | { |
1336 | for (; n; --n) | |
45119f04 | 1337 | seq_.pop_front (); |
2b548aa6 RA |
1338 | } |
1339 | ||
762a801e | 1340 | inline |
56017c17 AD |
1341 | typename S::size_type |
1342 | size () const | |
762a801e RA |
1343 | { |
1344 | return seq_.size (); | |
1345 | } | |
1346 | ||
ecfe33e7 | 1347 | inline const_iterator begin () const { return seq_.rbegin (); } |
56017c17 | 1348 | inline const_iterator end () const { return seq_.rend (); } |
2b548aa6 RA |
1349 | |
1350 | private: | |
56017c17 | 1351 | /// The wrapped container. |
2b548aa6 RA |
1352 | S seq_; |
1353 | }; | |
374f5a14 | 1354 | |
e019c247 | 1355 | /// Present a slice of the top of a stack. |
99880de5 AD |
1356 | template <class T, class S = stack<T> > |
1357 | class slice | |
374f5a14 RA |
1358 | { |
1359 | public: | |
1360 | ||
99880de5 | 1361 | slice (const S& stack, |
779e7ceb PE |
1362 | unsigned int range) : stack_ (stack), |
1363 | range_ (range) | |
374f5a14 RA |
1364 | { |
1365 | } | |
1366 | ||
1367 | inline | |
1368 | const T& | |
779e7ceb | 1369 | operator [] (unsigned int i) const |
374f5a14 | 1370 | { |
1d4055aa | 1371 | return stack_[range_ - i]; |
374f5a14 RA |
1372 | } |
1373 | ||
1374 | private: | |
1375 | ||
1376 | const S& stack_; | |
779e7ceb | 1377 | unsigned int range_; |
374f5a14 | 1378 | }; |
793fbca5 | 1379 | ]b4_namespace_close[ |
2b548aa6 | 1380 | |
cf98343c AD |
1381 | #endif // not BISON_STACK_HH[]dnl |
1382 | ] | |
08af01c2 | 1383 | m4_divert_pop(0) |
a9ce3f54 | 1384 | m4_popdef([b4_copyright_years])dnl |