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