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