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