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