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