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