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