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