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