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