]>
Commit | Line | Data |
---|---|---|
60491a94 | 1 | # C++ skeleton for Bison |
b4721715 | 2 | |
34136e65 | 3 | # Copyright (C) 2002-2012 Free Software Foundation, Inc. |
60491a94 | 4 | |
f16b0819 | 5 | # This program is free software: you can redistribute it and/or modify |
60491a94 | 6 | # it under the terms of the GNU General Public License as published by |
f16b0819 | 7 | # the Free Software Foundation, either version 3 of the License, or |
60491a94 | 8 | # (at your option) any later version. |
f16b0819 | 9 | # |
60491a94 AD |
10 | # This program is distributed in the hope that it will be useful, |
11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
13 | # GNU General Public License for more details. | |
f16b0819 | 14 | # |
60491a94 | 15 | # You should have received a copy of the GNU General Public License |
f16b0819 | 16 | # along with this program. If not, see <http://www.gnu.org/licenses/>. |
60491a94 | 17 | |
cf147260 | 18 | m4_include(b4_pkgdatadir/[c++.m4]) |
7eb8a0bc | 19 | |
2ea7730c | 20 | |
ba206cf4 AD |
21 | # b4_integral_parser_table_declare(TABLE-NAME, CONTENT, COMMENT) |
22 | # -------------------------------------------------------------- | |
0fddb3d5 | 23 | # Declare "parser::yy<TABLE-NAME>_" which contents is CONTENT. |
ba206cf4 | 24 | m4_define([b4_integral_parser_table_declare], |
15f66669 | 25 | [m4_ifval([$3], [b4_comment([$3], [ ]) |
6ab1adbe AD |
26 | ])dnl |
27 | static const b4_int_type_for([$2]) yy$1_[[]];dnl | |
0fddb3d5 AD |
28 | ]) |
29 | ||
ba206cf4 | 30 | # b4_integral_parser_table_define(TABLE-NAME, CONTENT, COMMENT) |
2b08bceb | 31 | # ------------------------------------------------------------- |
8901f32e | 32 | # Define "parser::yy<TABLE-NAME>_" which contents is CONTENT. |
ba206cf4 | 33 | m4_define([b4_integral_parser_table_define], |
6ab1adbe | 34 | [ const b4_int_type_for([$2]) |
8901f32e AD |
35 | b4_parser_class_name::yy$1_[[]] = |
36 | { | |
37 | $2 | |
6ab1adbe AD |
38 | };dnl |
39 | ]) | |
40 | ||
a9ce3f54 | 41 | |
5de9c593 AD |
42 | # b4_symbol_value_template(VAL, [TYPE]) |
43 | # ------------------------------------- | |
507aa0e2 AD |
44 | # Same as b4_symbol_value, but used in a template method. It makes |
45 | # a difference when using variants. | |
5de9c593 AD |
46 | m4_copy([b4_symbol_value], [b4_symbol_value_template]) |
47 | ||
5ab8c47b | 48 | |
e1f93869 AD |
49 | # b4_lhs_value([TYPE]) |
50 | # -------------------- | |
51 | # Expansion of $<TYPE>$. | |
52 | m4_define([b4_lhs_value], | |
507aa0e2 | 53 | [b4_symbol_value([yylhs.value], [$1])]) |
e1f93869 AD |
54 | |
55 | ||
56 | # b4_lhs_location() | |
57 | # ----------------- | |
58 | # Expansion of @$. | |
59 | m4_define([b4_lhs_location], | |
507aa0e2 | 60 | [yylhs.location]) |
e1f93869 AD |
61 | |
62 | ||
33c195cc AD |
63 | # b4_rhs_data(RULE-LENGTH, NUM) |
64 | # ----------------------------- | |
65 | # Return the data corresponding to the symbol #NUM, where the current | |
66 | # rule has RULE-LENGTH symbols on RHS. | |
67 | m4_define([b4_rhs_data], | |
3204049e | 68 | [yystack_@{b4_subtract($@)@}]) |
33c195cc AD |
69 | |
70 | ||
71 | # b4_rhs_state(RULE-LENGTH, NUM) | |
51bacae6 | 72 | # ------------------------------ |
33c195cc AD |
73 | # The state corresponding to the symbol #NUM, where the current |
74 | # rule has RULE-LENGTH symbols on RHS. | |
75 | m4_define([b4_rhs_state], | |
76 | [b4_rhs_data([$1], [$2]).state]) | |
77 | ||
78 | ||
8901f32e AD |
79 | # b4_rhs_value(RULE-LENGTH, NUM, [TYPE]) |
80 | # -------------------------------------- | |
81 | # Expansion of $<TYPE>NUM, where the current rule has RULE-LENGTH | |
82 | # symbols on RHS. | |
83 | m4_define([b4_rhs_value], | |
33c195cc AD |
84 | [b4_symbol_value([b4_rhs_data([$1], [$2]).value], [$3])]) |
85 | ||
8901f32e AD |
86 | |
87 | # b4_rhs_location(RULE-LENGTH, NUM) | |
88 | # --------------------------------- | |
89 | # Expansion of @NUM, where the current rule has RULE-LENGTH symbols | |
90 | # on RHS. | |
91 | m4_define([b4_rhs_location], | |
33c195cc | 92 | [b4_rhs_data([$1], [$2]).location]) |
8901f32e | 93 | |
507aa0e2 | 94 | |
2bde9113 AD |
95 | # b4_symbol_action(SYMBOL-NUM, KIND) |
96 | # ---------------------------------- | |
97 | # Run the action KIND (destructor or printer) for SYMBOL-NUM. | |
c4585f1e | 98 | # Same as in C, but using references instead of pointers. |
2bde9113 AD |
99 | m4_define([b4_symbol_action], |
100 | [b4_symbol_if([$1], [has_$2], | |
4323e0da AD |
101 | [m4_pushdef([b4_symbol_value], m4_defn([b4_symbol_value_template]))[]dnl |
102 | b4_dollar_pushdef([yysym.value], | |
103 | b4_symbol_if([$1], [has_type], | |
104 | [m4_dquote(b4_symbol([$1], [type]))]), | |
105 | [yysym.location])dnl | |
fb7c5b1f | 106 | b4_symbol_case_([$1]) |
2bde9113 AD |
107 | b4_syncline([b4_symbol([$1], [$2_line])], ["b4_symbol([$1], [$2_file])"]) |
108 | b4_symbol([$1], [$2]) | |
c4585f1e AD |
109 | b4_syncline([@oline@], [@ofile@]) |
110 | break; | |
2bde9113 | 111 | |
4323e0da AD |
112 | m4_popdef([b4_symbol_value])[]dnl |
113 | b4_dollar_popdef[]dnl | |
2bde9113 AD |
114 | ])]) |
115 | ||
2873fdf8 | 116 | |
8901f32e | 117 | m4_pushdef([b4_copyright_years], |
34136e65 | 118 | [2002-2012]) |
8901f32e | 119 | |
6afc30cc | 120 | m4_define([b4_parser_class_name], |
a4e25e1d | 121 | [b4_percent_define_get([[parser_class_name]])]) |
34376418 | 122 | |
bcd80897 | 123 | b4_bison_locations_if([# Backward compatibility. |
c547693a | 124 | m4_define([b4_location_constructors]) |
bcd80897 | 125 | m4_include(b4_pkgdatadir/[location.cc])]) |
51bacae6 | 126 | m4_include(b4_pkgdatadir/[stack.hh]) |
507aa0e2 | 127 | b4_variant_if([m4_include(b4_pkgdatadir/[variant.hh])]) |
a5eb1ed2 | 128 | |
d27c5e65 AD |
129 | # b4_shared_declarations |
130 | # ---------------------- | |
131 | # Declaration that might either go into the header (if --defines) | |
132 | # or open coded in the parser body. | |
133 | m4_define([b4_shared_declarations], | |
134 | [b4_percent_code_get([[requires]])[ | |
ff348970 | 135 | ]b4_parse_assert_if([# include <cassert>])[ |
5de5b987 | 136 | # include <deque> |
ff348970 | 137 | # include <iostream> |
5de5b987 AD |
138 | # include <stdexcept> |
139 | # include <string>]b4_defines_if([[ | |
ff348970 | 140 | # include "stack.hh" |
bcd80897 | 141 | ]b4_bison_locations_if([[# include "location.hh"]])])[ |
35f70d16 | 142 | ]b4_variant_if([b4_variant_includes])[ |
5de5b987 AD |
143 | |
144 | ]b4_YYDEBUG_define[ | |
50997c6e | 145 | |
93549bcd | 146 | ]b4_namespace_open[ |
4162fa07 | 147 | |
5de5b987 AD |
148 | ]b4_defines_if([], |
149 | [b4_stack_define | |
bcd80897 AD |
150 | b4_bison_locations_if([b4_position_define |
151 | b4_location_define])])[ | |
69e2658b | 152 | |
93549bcd | 153 | ]b4_variant_if([b4_variant_define])[ |
3f3eed27 | 154 | |
efeed023 | 155 | /// A Bison parser. |
07fed891 | 156 | class ]b4_parser_class_name[ |
2b548aa6 | 157 | { |
fb9712a9 | 158 | public: |
4f84717d | 159 | ]b4_public_types_declare[ |
efeed023 | 160 | /// Build a parser object. |
98ae9643 AD |
161 | ]b4_parser_class_name[ (]b4_parse_param_decl[); |
162 | virtual ~]b4_parser_class_name[ (); | |
2b548aa6 | 163 | |
f69a4142 AD |
164 | /// Parse. |
165 | /// \returns 0 iff parsing succeeded. | |
e019c247 | 166 | virtual int parse (); |
2b548aa6 | 167 | |
5f108727 | 168 | #if ]b4_api_PREFIX[DEBUG |
f69a4142 | 169 | /// The current debugging stream. |
9a1e9989 AD |
170 | std::ostream& debug_stream () const; |
171 | /// Set the current debugging stream. | |
172 | void set_debug_stream (std::ostream &); | |
173 | ||
a3cb6248 AD |
174 | /// Type for debugging levels. |
175 | typedef int debug_level_type; | |
176 | /// The current debugging level. | |
177 | debug_level_type debug_level () const; | |
178 | /// Set the current debugging level. | |
179 | void set_debug_level (debug_level_type l); | |
52cbbe84 | 180 | #endif |
a3cb6248 | 181 | |
34904c57 AD |
182 | /// Report a syntax error.]b4_locations_if([[ |
183 | /// \param loc where the syntax error is found.]])[ | |
efeed023 | 184 | /// \param msg a description of the syntax error. |
34904c57 | 185 | virtual void error (]b4_locations_if([[const location_type& loc, ]])[const std::string& msg); |
efeed023 | 186 | |
a6552c5d AD |
187 | /// Report a syntax error. |
188 | void error (const syntax_error& err); | |
189 | ||
49572920 | 190 | private: |
e019c247 | 191 | /// State numbers. |
f479c6c6 | 192 | typedef int state_type; |
2b548aa6 | 193 | |
ceb8b8e6 AD |
194 | /// Generate an error message. |
195 | /// \param yystate the state where the error occurred. | |
196 | /// \param yytoken the lookahead token. | |
197 | virtual std::string yysyntax_error_ (state_type yystate, int yytoken); | |
198 | ||
7580c379 AD |
199 | /// Compute post-reduction state. |
200 | /// \param yystate the current state | |
201 | /// \param yylhs the nonterminal to push on the stack | |
202 | state_type yy_lr_goto_state_ (state_type yystate, int yylhs); | |
203 | ||
f2b30bdf JD |
204 | /// Whether the given \c yypact_ value indicates a defaulted state. |
205 | /// \param yyvalue the value to check | |
206 | static bool yy_pact_value_is_default_ (int yyvalue); | |
207 | ||
208 | /// Whether the given \c yytable_ value indicates a syntax error. | |
209 | /// \param yyvalue the value to check | |
210 | static bool yy_table_value_is_error_ (int yyvalue); | |
211 | ||
e019c247 | 212 | /// Internal symbol numbers. |
f479c6c6 | 213 | typedef ]b4_int_type_for([b4_translate])[ token_number_type; |
617a8f12 | 214 | static const ]b4_int_type(b4_pact_ninf, b4_pact_ninf)[ yypact_ninf_; |
617a8f12 | 215 | static const ]b4_int_type(b4_table_ninf, b4_table_ninf)[ yytable_ninf_; |
efeed023 | 216 | |
7aaaad6c AD |
217 | // Tables. |
218 | ]b4_parser_tables_declare[]b4_error_verbose_if([ | |
9e0876fb | 219 | |
9e0876fb | 220 | /// Convert the symbol name \a n to a form suitable for a diagnostic. |
422c18f4 | 221 | static std::string yytnamerr_ (const char *n);])[ |
2b548aa6 | 222 | |
5f108727 | 223 | ]b4_token_table_if([], [[#if ]b4_api_PREFIX[DEBUG]])[ |
258cddbc AD |
224 | /// For a symbol, its name in clear. |
225 | static const char* const yytname_[]; | |
5f108727 | 226 | ]b4_token_table_if([[#if ]b4_api_PREFIX[DEBUG]])[ |
ba206cf4 AD |
227 | ]b4_integral_parser_table_declare([rline], [b4_rline], |
228 | [YYRLINE[YYN] -- Source line where rule number YYN was defined.])[ | |
efeed023 | 229 | /// Report on the debug stream that the rule \a r is going to be reduced. |
d1ff7a7c | 230 | virtual void yy_reduce_print_ (int r); |
efeed023 | 231 | /// Print the state stack on the debug stream. |
f69a4142 | 232 | virtual void yystack_print_ (); |
fa7b79c0 | 233 | |
7aaaad6c | 234 | // Debugging. |
fa7b79c0 PE |
235 | int yydebug_; |
236 | std::ostream* yycdebug_; | |
ccdc1577 | 237 | #endif // ]b4_api_PREFIX[DEBUG |
2b548aa6 | 238 | |
32c96bd7 | 239 | /// Convert a scanner token number \a t to a symbol number. |
e36ec1f4 | 240 | static inline token_number_type yytranslate_ (]b4_token_ctor_if([token_type], [int])[ t); |
f69a4142 | 241 | |
ccdc1577 | 242 | #if ]b4_api_PREFIX[DEBUG |
1f7d007b AD |
243 | /// \brief Display a symbol type, value and location. |
244 | /// \param yyo The output stream. | |
245 | /// \param yysym The symbol. | |
5de9c593 AD |
246 | template <typename Exact> |
247 | void yy_print_ (std::ostream& yyo, | |
248 | const symbol_base_type<Exact>& yysym) const; | |
57295d14 AD |
249 | #endif |
250 | ||
1f7d007b AD |
251 | /// \brief Reclaim the memory associated to a symbol. |
252 | /// \param yymsg Why this token is reclaimed. | |
253 | /// If null, print nothing. | |
254 | /// \param s The symbol. | |
5de9c593 AD |
255 | template <typename Exact> |
256 | inline void yy_destroy_ (const char* yymsg, | |
257 | symbol_base_type<Exact>& yysym) const; | |
1f7d007b | 258 | |
2873fdf8 | 259 | private: |
1f7d007b | 260 | /// Element of the stack: a state and its attributes. |
5de9c593 | 261 | struct stack_symbol_type : symbol_base_type<stack_symbol_type> |
1f7d007b | 262 | { |
5de9c593 AD |
263 | /// The parent class. |
264 | typedef symbol_base_type<stack_symbol_type> super_type; | |
265 | ||
1f7d007b | 266 | /// Default constructor. |
d3be4f6d | 267 | inline stack_symbol_type (); |
1f7d007b AD |
268 | |
269 | /// Constructor. | |
710c4a65 | 270 | inline stack_symbol_type (]b4_join([state_type s], |
2ea7730c AD |
271 | [const semantic_type& v], |
272 | b4_locations_if([const location_type& l]))[); | |
1f7d007b AD |
273 | |
274 | /// The state. | |
275 | state_type state; | |
57295d14 | 276 | |
2b08bceb | 277 | /// The type (corresponding to \a state). |
5de9c593 | 278 | inline int type_get_ () const; |
1f7d007b | 279 | }; |
57295d14 | 280 | |
8901f32e | 281 | /// Stack type. |
bc0b0477 | 282 | typedef stack<stack_symbol_type> stack_type; |
8901f32e AD |
283 | |
284 | /// The stack. | |
285 | stack_type yystack_; | |
286 | ||
7dedf26e | 287 | /// Push a new state on the stack. |
9380cfd0 AD |
288 | /// \param m a debug message to display |
289 | /// if null, no trace is output. | |
e9b0834e AD |
290 | /// \param s the symbol |
291 | /// \warning the contents of \a s.value is stolen. | |
bc0b0477 | 292 | inline void yypush_ (const char* m, stack_symbol_type& s); |
7dedf26e | 293 | |
1f7d007b AD |
294 | /// Push a new look ahead token on the state on the stack. |
295 | /// \param m a debug message to display | |
296 | /// if null, no trace is output. | |
297 | /// \param s the state | |
298 | /// \param sym the symbol (for its value and location). | |
299 | /// \warning the contents of \a s.value is stolen. | |
300 | inline void yypush_ (const char* m, state_type s, symbol_type& sym); | |
301 | ||
52d5733f | 302 | /// Pop \a n symbols the three stacks. |
f69a4142 | 303 | inline void yypop_ (unsigned int n = 1); |
52d5733f | 304 | |
ac826bc4 | 305 | // Constants. |
914202bd AD |
306 | enum |
307 | { | |
308 | yyeof_ = 0, | |
309 | yylast_ = ]b4_last[, //< Last index in yytable_. | |
310 | yynnts_ = ]b4_nterms_number[, //< Number of nonterminal symbols. | |
311 | yyempty_ = -2, | |
312 | yyfinal_ = ]b4_final_state_number[, //< Termination state number. | |
313 | yyterror_ = 1, | |
314 | yyerrcode_ = 256, | |
f3bd3f78 | 315 | yyntokens_ = ]b4_tokens_number[ //< Number of tokens. |
914202bd AD |
316 | }; |
317 | ||
caf37a36 | 318 | ]b4_parse_param_vars[ |
2b548aa6 | 319 | }; |
1c4af381 | 320 | |
e36ec1f4 | 321 | ]b4_token_ctor_if([b4_yytranslate_define |
0623bacc | 322 | b4_public_types_define])[ |
793fbca5 | 323 | ]b4_namespace_close[ |
2b548aa6 | 324 | |
592d0b1e | 325 | ]b4_percent_define_flag_if([[global_tokens_and_yystype]], |
6687da34 | 326 | [b4_token_defines |
fb9712a9 | 327 | |
4b3847c3 | 328 | #ifndef ]b4_api_PREFIX[STYPE |
ac826bc4 | 329 | // Redirection for backward compatibility. |
4b3847c3 | 330 | # define ]b4_api_PREFIX[STYPE b4_namespace_ref::b4_parser_class_name::semantic_type |
fb9712a9 | 331 | #endif |
22172d47 AD |
332 | ])[ |
333 | ]b4_percent_code_get([[provides]])[ | |
d27c5e65 AD |
334 | ]]) |
335 | ||
85f0b29e | 336 | b4_defines_if( |
eaf690a7 | 337 | [b4_output_begin([b4_spec_defines_file]) |
d27c5e65 AD |
338 | b4_copyright([Skeleton interface for Bison LALR(1) parsers in C++]) |
339 | [ | |
340 | /** | |
341 | ** \file ]b4_spec_defines_file[ | |
342 | ** Define the ]b4_namespace_ref[::parser class. | |
343 | */ | |
344 | ||
ac826bc4 | 345 | // C++ LALR(1) parser skeleton written by Akim Demaille. |
d27c5e65 AD |
346 | |
347 | ]b4_cpp_guard_open([b4_spec_defines_file])[ | |
348 | ]b4_shared_declarations[ | |
22172d47 | 349 | ]b4_cpp_guard_close([b4_spec_defines_file]) |
1c7ec959 | 350 | b4_output_end() |
85f0b29e AD |
351 | ]) |
352 | ||
353 | ||
1c7ec959 | 354 | b4_output_begin([b4_parser_file_name]) |
a9ce3f54 | 355 | b4_copyright([Skeleton implementation for Bison LALR(1) parsers in C++]) |
a4e25e1d | 356 | b4_percent_code_get([[top]])[]dnl |
aa08666d | 357 | m4_if(b4_prefix, [yy], [], |
c5b95ccf AD |
358 | [ |
359 | // Take the name prefix into account. | |
9bc0dd67 JD |
360 | #define yylex b4_prefix[]lex])[ |
361 | ||
28427f57 | 362 | // First part of user declarations. |
c944f7f2 | 363 | ]b4_user_pre_prologue[ |
9bc0dd67 | 364 | |
28427f57 AD |
365 | ]b4_null_define[ |
366 | ||
85f0b29e AD |
367 | ]b4_defines_if([[#include "@basename(]b4_spec_defines_file[@)"]], |
368 | [b4_shared_declarations])[ | |
50997c6e | 369 | |
ac826bc4 | 370 | // User implementation prologue. |
771dc643 AD |
371 | ]b4_user_post_prologue[ |
372 | ]b4_percent_code_get[ | |
373 | ||
771dc643 | 374 | #ifndef YY_ |
ae93128c | 375 | # if defined YYENABLE_NLS && YYENABLE_NLS |
30757c8c | 376 | # if ENABLE_NLS |
ac826bc4 | 377 | # include <libintl.h> // FIXME: INFRINGES ON USER NAME SPACE. |
30757c8c PE |
378 | # define YY_(msgid) dgettext ("bison-runtime", msgid) |
379 | # endif | |
380 | # endif | |
381 | # ifndef YY_ | |
382 | # define YY_(msgid) msgid | |
383 | # endif | |
989b5b8e AD |
384 | #endif |
385 | ||
38435078 | 386 | ]b4_locations_if([dnl |
ccdc1577 AD |
387 | [#define YYRHSLOC(Rhs, K) ((Rhs)[K].location) |
388 | ]b4_yylloc_default_define])[ | |
38435078 | 389 | |
ac826bc4 AD |
390 | // Suppress unused-variable warnings by "using" E. |
391 | #define YYUSE(E) ((void) (E)) | |
2a4647a3 | 392 | |
ac826bc4 | 393 | // Enable debugging if requested. |
5f108727 | 394 | #if ]b4_api_PREFIX[DEBUG |
284acc8b | 395 | |
ac826bc4 | 396 | // A pseudo ostream that takes yydebug_ into account. |
fa7b79c0 PE |
397 | # define YYCDEBUG if (yydebug_) (*yycdebug_) |
398 | ||
1f7d007b | 399 | # define YY_SYMBOL_PRINT(Title, Symbol) \ |
57295d14 AD |
400 | do { \ |
401 | if (yydebug_) \ | |
402 | { \ | |
403 | *yycdebug_ << Title << ' '; \ | |
1f7d007b | 404 | yy_print_ (*yycdebug_, Symbol); \ |
57295d14 AD |
405 | *yycdebug_ << std::endl; \ |
406 | } \ | |
8901f32e | 407 | } while (false) |
284acc8b | 408 | |
e9690142 JD |
409 | # define YY_REDUCE_PRINT(Rule) \ |
410 | do { \ | |
8901f32e | 411 | if (yydebug_) \ |
e9690142 | 412 | yy_reduce_print_ (Rule); \ |
8901f32e | 413 | } while (false) |
284acc8b | 414 | |
e9690142 JD |
415 | # define YY_STACK_PRINT() \ |
416 | do { \ | |
8901f32e AD |
417 | if (yydebug_) \ |
418 | yystack_print_ (); \ | |
419 | } while (false) | |
284acc8b | 420 | |
ac826bc4 | 421 | #else // !]b4_api_PREFIX[DEBUG |
284acc8b | 422 | |
a36b333c | 423 | # define YYCDEBUG if (false) std::cerr |
beadb220 | 424 | # define YY_SYMBOL_PRINT(Title, Symbol) YYUSE(Symbol) |
1f7d007b AD |
425 | # define YY_REDUCE_PRINT(Rule) static_cast<void>(0) |
426 | # define YY_STACK_PRINT() static_cast<void>(0) | |
284acc8b | 427 | |
ac826bc4 | 428 | #endif // !]b4_api_PREFIX[DEBUG |
2b548aa6 | 429 | |
39be9022 AD |
430 | #define yyerrok (yyerrstatus_ = 0) |
431 | #define yyclearin (yyempty = true) | |
98e26a92 | 432 | |
39be9022 AD |
433 | #define YYACCEPT goto yyacceptlab |
434 | #define YYABORT goto yyabortlab | |
435 | #define YYERROR goto yyerrorlab | |
98e26a92 | 436 | #define YYRECOVERING() (!!yyerrstatus_) |
60a777aa | 437 | |
422c18f4 | 438 | ]b4_namespace_open[]b4_error_verbose_if([[ |
9e0876fb | 439 | |
aa08666d AD |
440 | /* Return YYSTR after stripping away unnecessary quotes and |
441 | backslashes, so that it's suitable for yyerror. The heuristic is | |
442 | that double-quoting is unnecessary unless the string contains an | |
443 | apostrophe, a comma, or backslash (other than backslash-backslash). | |
444 | YYSTR is taken from yytname. */ | |
445 | std::string | |
446 | ]b4_parser_class_name[::yytnamerr_ (const char *yystr) | |
447 | { | |
448 | if (*yystr == '"') | |
449 | { | |
450 | std::string yyr = ""; | |
451 | char const *yyp = yystr; | |
193d7c70 | 452 | |
aa08666d AD |
453 | for (;;) |
454 | switch (*++yyp) | |
455 | { | |
456 | case '\'': | |
457 | case ',': | |
458 | goto do_not_strip_quotes; | |
193d7c70 | 459 | |
aa08666d AD |
460 | case '\\': |
461 | if (*++yyp != '\\') | |
462 | goto do_not_strip_quotes; | |
ac826bc4 | 463 | // Fall through. |
aa08666d AD |
464 | default: |
465 | yyr += *yyp; | |
466 | break; | |
193d7c70 | 467 | |
aa08666d AD |
468 | case '"': |
469 | return yyr; | |
470 | } | |
471 | do_not_strip_quotes: ; | |
472 | } | |
193d7c70 | 473 | |
aa08666d AD |
474 | return yystr; |
475 | } | |
422c18f4 | 476 | ]])[ |
9e0876fb | 477 | |
98ae9643 | 478 | /// Build a parser object. |
fa7b79c0 PE |
479 | ]b4_parser_class_name::b4_parser_class_name[ (]b4_parse_param_decl[)]m4_ifset([b4_parse_param], [ |
480 | :])[ | |
5f108727 | 481 | #if ]b4_api_PREFIX[DEBUG |
fa7b79c0 PE |
482 | ]m4_ifset([b4_parse_param], [ ], [ :])[yydebug_ (false), |
483 | yycdebug_ (&std::cerr)]m4_ifset([b4_parse_param], [,])[ | |
484 | #endif]b4_parse_param_cons[ | |
98ae9643 AD |
485 | { |
486 | } | |
a0e68930 | 487 | |
98ae9643 AD |
488 | ]b4_parser_class_name::~b4_parser_class_name[ () |
489 | { | |
490 | } | |
a0e68930 | 491 | |
a0e68930 | 492 | |
1f7d007b AD |
493 | /*---------------. |
494 | | Symbol types. | | |
495 | `---------------*/ | |
496 | ||
e36ec1f4 | 497 | ]b4_token_ctor_if([], [b4_public_types_define])[ |
2873fdf8 | 498 | |
1f7d007b AD |
499 | // stack_symbol_type. |
500 | ]b4_parser_class_name[::stack_symbol_type::stack_symbol_type () | |
5de9c593 AD |
501 | : super_type () |
502 | , state () | |
1f7d007b AD |
503 | { |
504 | } | |
505 | ||
710c4a65 | 506 | ]b4_parser_class_name[::stack_symbol_type::stack_symbol_type (]b4_join( |
2ea7730c AD |
507 | [state_type s], |
508 | [const semantic_type& v], | |
509 | b4_locations_if([const location_type& l]))[) | |
510 | : super_type (v]b4_locations_if([, l])[) | |
5de9c593 | 511 | , state (s) |
1f7d007b AD |
512 | { |
513 | } | |
514 | ||
515 | int | |
5de9c593 | 516 | ]b4_parser_class_name[::stack_symbol_type::type_get_ () const |
1f7d007b AD |
517 | { |
518 | return yystos_[state]; | |
519 | } | |
520 | ||
521 | ||
5de9c593 | 522 | template <typename Exact> |
98ae9643 | 523 | void |
5de9c593 AD |
524 | ]b4_parser_class_name[::yy_destroy_ (const char* yymsg, |
525 | symbol_base_type<Exact>& yysym) const | |
98ae9643 | 526 | { |
8901f32e | 527 | if (yymsg) |
1f7d007b | 528 | YY_SYMBOL_PRINT (yymsg, yysym); |
98ae9643 | 529 | |
8901f32e | 530 | // User destructor. |
c5026327 | 531 | int yytype = yysym.type_get (); |
98ae9643 AD |
532 | switch (yytype) |
533 | { | |
e3c52a63 | 534 | ]b4_symbol_foreach([b4_symbol_destructor])dnl |
2bde9113 AD |
535 | [ default: |
536 | break; | |
8901f32e AD |
537 | }]b4_variant_if([ |
538 | ||
539 | // Type destructor. | |
4c3cc7da | 540 | b4_symbol_variant([[yytype]], [[yysym.value]], [[template destroy]])])[ |
8901f32e AD |
541 | } |
542 | ||
ccdc1577 | 543 | #if ]b4_api_PREFIX[DEBUG |
5de9c593 | 544 | template <typename Exact> |
1f7d007b | 545 | void |
5de9c593 AD |
546 | ]b4_parser_class_name[::yy_print_ (std::ostream& yyo, |
547 | const symbol_base_type<Exact>& yysym) const | |
8901f32e | 548 | { |
c5026327 AD |
549 | std::ostream& yyoutput = yyo; |
550 | YYUSE (yyoutput); | |
1f7d007b AD |
551 | int yytype = yysym.type_get (); |
552 | yyo << (yytype < yyntokens_ ? "token" : "nterm") | |
2ea7730c AD |
553 | << ' ' << yytname_[yytype] << " ("]b4_locations_if([ |
554 | << yysym.location << ": "])[; | |
1f7d007b AD |
555 | switch (yytype) |
556 | { | |
e3c52a63 | 557 | ]b4_symbol_foreach([b4_symbol_printer])dnl |
2bde9113 | 558 | [ default: |
e9690142 | 559 | break; |
1f7d007b AD |
560 | } |
561 | yyo << ')'; | |
8901f32e | 562 | } |
1f7d007b | 563 | #endif |
8901f32e | 564 | |
1f7d007b AD |
565 | void |
566 | ]b4_parser_class_name[::yypush_ (const char* m, state_type s, | |
567 | symbol_type& sym) | |
8901f32e | 568 | { |
1f7d007b AD |
569 | if (m) |
570 | YY_SYMBOL_PRINT (m, sym); | |
571 | ]b4_variant_if( | |
710c4a65 | 572 | [[ yystack_.push (stack_symbol_type (]b4_join( |
2ea7730c AD |
573 | [s], |
574 | [semantic_type()], | |
575 | b4_locations_if([sym.location]))[)); | |
1f7d007b AD |
576 | ]b4_symbol_variant([[yystos_[s]]], [[yystack_[0].value]], |
577 | [build], [sym.value])], | |
710c4a65 | 578 | [[ yystack_.push (stack_symbol_type (]b4_join( |
2ea7730c AD |
579 | [s], |
580 | [sym.value], | |
581 | b4_locations_if([sym.location]))[));]])[ | |
98ae9643 | 582 | } |
60a777aa | 583 | |
7dedf26e | 584 | void |
bc0b0477 | 585 | ]b4_parser_class_name[::yypush_ (const char* m, stack_symbol_type& s) |
7dedf26e | 586 | { |
9380cfd0 | 587 | if (m) |
1f7d007b | 588 | YY_SYMBOL_PRINT (m, s); |
8901f32e | 589 | ]b4_variant_if( |
710c4a65 | 590 | [[ yystack_.push (stack_symbol_type (]b4_join( |
2ea7730c AD |
591 | [s.state], |
592 | [semantic_type()], | |
593 | b4_locations_if([s.location]))[)); | |
1f7d007b | 594 | ]b4_symbol_variant([[yystos_[s.state]]], [[yystack_[0].value]], |
e9b0834e AD |
595 | [build], [s.value])], |
596 | [ yystack_.push (s);])[ | |
7dedf26e AD |
597 | } |
598 | ||
98ae9643 AD |
599 | void |
600 | ]b4_parser_class_name[::yypop_ (unsigned int n) | |
601 | { | |
8901f32e | 602 | yystack_.pop (n); |
98ae9643 | 603 | } |
52d5733f | 604 | |
5f108727 | 605 | #if ]b4_api_PREFIX[DEBUG |
98ae9643 AD |
606 | std::ostream& |
607 | ]b4_parser_class_name[::debug_stream () const | |
608 | { | |
609 | return *yycdebug_; | |
610 | } | |
9a1e9989 | 611 | |
98ae9643 AD |
612 | void |
613 | ]b4_parser_class_name[::set_debug_stream (std::ostream& o) | |
614 | { | |
615 | yycdebug_ = &o; | |
616 | } | |
9a1e9989 AD |
617 | |
618 | ||
98ae9643 AD |
619 | ]b4_parser_class_name[::debug_level_type |
620 | ]b4_parser_class_name[::debug_level () const | |
621 | { | |
622 | return yydebug_; | |
623 | } | |
a3cb6248 | 624 | |
98ae9643 AD |
625 | void |
626 | ]b4_parser_class_name[::set_debug_level (debug_level_type l) | |
627 | { | |
628 | yydebug_ = l; | |
629 | } | |
ccdc1577 | 630 | #endif // ]b4_api_PREFIX[DEBUG |
a3cb6248 | 631 | |
7580c379 AD |
632 | inline ]b4_parser_class_name[::state_type |
633 | ]b4_parser_class_name[::yy_lr_goto_state_ (state_type yystate, int yylhs) | |
634 | { | |
635 | int yyr = yypgoto_[yylhs - yyntokens_] + yystate; | |
636 | if (0 <= yyr && yyr <= yylast_ && yycheck_[yyr] == yystate) | |
637 | return yytable_[yyr]; | |
638 | else | |
639 | return yydefgoto_[yylhs - yyntokens_]; | |
640 | } | |
641 | ||
f2b30bdf JD |
642 | inline bool |
643 | ]b4_parser_class_name[::yy_pact_value_is_default_ (int yyvalue) | |
644 | { | |
645 | return yyvalue == yypact_ninf_; | |
646 | } | |
647 | ||
648 | inline bool | |
649 | ]b4_parser_class_name[::yy_table_value_is_error_ (int yyvalue) | |
650 | { | |
aa0cb40d | 651 | return yyvalue == yytable_ninf_; |
f2b30bdf JD |
652 | } |
653 | ||
98ae9643 AD |
654 | int |
655 | ]b4_parser_class_name[::parse () | |
656 | { | |
39be9022 AD |
657 | /// Whether yyla contains a lookahead. |
658 | bool yyempty = true; | |
d4fb5e3c | 659 | |
b720fedf | 660 | // State. |
98ae9643 | 661 | int yyn; |
a85284cf | 662 | int yylen = 0; |
d4fb5e3c | 663 | |
b720fedf | 664 | // Error handling. |
98ae9643 AD |
665 | int yynerrs_ = 0; |
666 | int yyerrstatus_ = 0; | |
dbcdae2d | 667 | |
6082531a | 668 | /// The lookahead symbol. |
2ea7730c | 669 | symbol_type yyla;]b4_locations_if([[ |
6082531a | 670 | |
98ae9643 | 671 | /// The locations where the error started and ended. |
44c2b42d | 672 | stack_symbol_type yyerror_range[3];]])[ |
dbcdae2d | 673 | |
e1f93869 | 674 | /// $$ and @@$. |
bc0b0477 | 675 | stack_symbol_type yylhs; |
dbcdae2d | 676 | |
ff348970 | 677 | /// The return value of parse (). |
98ae9643 | 678 | int yyresult; |
ad745863 | 679 | |
7e1fabbe AD |
680 | // FIXME: This shoud be completely indented. It is not yet to |
681 | // avoid gratuitous conflicts when merging into the master branch. | |
682 | try | |
683 | { | |
98ae9643 | 684 | YYCDEBUG << "Starting parse" << std::endl; |
451364ed | 685 | |
451364ed | 686 | ]m4_ifdef([b4_initial_action], [ |
4323e0da | 687 | b4_dollar_pushdef([yyla.value], [], [yyla.location])dnl |
ac826bc4 | 688 | // User initialization code. |
8ec0a172 | 689 | b4_user_initial_action |
cd735a8c | 690 | b4_dollar_popdef])[]dnl |
451364ed | 691 | |
8901f32e | 692 | [ /* Initialize the stack. The initial state will be set in |
98ae9643 AD |
693 | yynewstate, since the latter expects the semantical and the |
694 | location values to have been already stored, initialize these | |
695 | stacks with a primary value. */ | |
8901f32e | 696 | yystack_ = stack_type (0); |
eeaf1dc6 | 697 | yypush_ (YY_NULL, 0, yyla); |
98ae9643 | 698 | |
7580c379 | 699 | // A new symbol was pushed on the stack. |
98ae9643 | 700 | yynewstate: |
7580c379 | 701 | YYCDEBUG << "Entering state " << yystack_[0].state << std::endl; |
868d2d96 | 702 | |
ac826bc4 | 703 | // Accept? |
7580c379 | 704 | if (yystack_[0].state == yyfinal_) |
868d2d96 JD |
705 | goto yyacceptlab; |
706 | ||
98ae9643 AD |
707 | goto yybackup; |
708 | ||
ac826bc4 | 709 | // Backup. |
98ae9643 AD |
710 | yybackup: |
711 | ||
ac826bc4 | 712 | // Try to take a decision without lookahead. |
7580c379 | 713 | yyn = yypact_[yystack_[0].state]; |
f2b30bdf | 714 | if (yy_pact_value_is_default_ (yyn)) |
98ae9643 AD |
715 | goto yydefault; |
716 | ||
ac826bc4 | 717 | // Read a lookahead token. |
39be9022 | 718 | if (yyempty) |
98ae9643 | 719 | { |
09277875 | 720 | YYCDEBUG << "Reading a token: "; |
a6552c5d | 721 | try |
77a1a208 | 722 | { |
e36ec1f4 | 723 | ]b4_token_ctor_if( |
7be08dfb AD |
724 | [ symbol_type yylookahead = b4_function_call([yylex], [symbol_type], |
725 | m4_ifdef([b4_lex_param], b4_lex_param)); | |
726 | yyla.move(yylookahead);], | |
727 | [ yyla.type = yytranslate_ (b4_function_call([yylex], [int], | |
728 | [b4_api_PREFIX[STYPE*], [&yyla.value]][]dnl | |
6082531a | 729 | b4_locations_if([, [[location*], [&yyla.location]]])dnl |
09277875 | 730 | m4_ifdef([b4_lex_param], [, ]b4_lex_param)));])[ |
77a1a208 | 731 | } |
a6552c5d | 732 | catch (const syntax_error& yyexc) |
77a1a208 AD |
733 | { |
734 | error (yyexc); | |
735 | goto yyerrlab1; | |
736 | } | |
39be9022 | 737 | yyempty = false; |
98ae9643 | 738 | } |
aba12ad1 | 739 | YY_SYMBOL_PRINT ("Next token is", yyla); |
98ae9643 | 740 | |
1f7d007b AD |
741 | /* If the proper action on seeing token YYLA.TYPE is to reduce or |
742 | to detect an error, take that action. */ | |
743 | yyn += yyla.type; | |
744 | if (yyn < 0 || yylast_ < yyn || yycheck_[yyn] != yyla.type) | |
98ae9643 AD |
745 | goto yydefault; |
746 | ||
ac826bc4 | 747 | // Reduce or error. |
98ae9643 AD |
748 | yyn = yytable_[yyn]; |
749 | if (yyn <= 0) | |
750 | { | |
e9690142 JD |
751 | if (yy_table_value_is_error_ (yyn)) |
752 | goto yyerrlab; | |
753 | yyn = -yyn; | |
754 | goto yyreduce; | |
98ae9643 AD |
755 | } |
756 | ||
ac826bc4 | 757 | // Discard the token being shifted. |
39be9022 | 758 | yyempty = true; |
98ae9643 | 759 | |
ac826bc4 | 760 | // Count tokens shifted since error; after three, turn off error status. |
98ae9643 AD |
761 | if (yyerrstatus_) |
762 | --yyerrstatus_; | |
763 | ||
ac826bc4 | 764 | // Shift the lookahead token. |
7580c379 | 765 | yypush_ ("Shifting", yyn, yyla); |
98ae9643 AD |
766 | goto yynewstate; |
767 | ||
768 | /*-----------------------------------------------------------. | |
769 | | yydefault -- do the default action for the current state. | | |
770 | `-----------------------------------------------------------*/ | |
771 | yydefault: | |
7580c379 | 772 | yyn = yydefact_[yystack_[0].state]; |
98ae9643 AD |
773 | if (yyn == 0) |
774 | goto yyerrlab; | |
775 | goto yyreduce; | |
776 | ||
777 | /*-----------------------------. | |
778 | | yyreduce -- Do a reduction. | | |
779 | `-----------------------------*/ | |
780 | yyreduce: | |
c4dc4c46 | 781 | yylen = yyr2_[yyn]; |
7580c379 | 782 | yylhs.state = yy_lr_goto_state_(yystack_[yylen].state, yyr1_[yyn]);]b4_variant_if([ |
5ab8c47b | 783 | /* Variants are always initialized to an empty instance of the |
3eead995 AD |
784 | correct type. The default $$=$1 action is NOT applied when using |
785 | variants. */ | |
c4dc4c46 | 786 | b4_symbol_variant([[yyr1_@{yyn@}]], [yylhs.value], [build])],[ |
a85284cf | 787 | /* If YYLEN is nonzero, implement the default value of the action: |
98ae9643 AD |
788 | `$$ = $1'. Otherwise, use the top of the stack. |
789 | ||
e1f93869 | 790 | Otherwise, the following line sets YYLHS.VALUE to garbage. |
98ae9643 AD |
791 | This behavior is undocumented and Bison |
792 | users should not rely upon it. */ | |
793 | if (yylen) | |
e1f93869 | 794 | yylhs.value = yystack_@{yylen - 1@}.value; |
98ae9643 | 795 | else |
e1f93869 | 796 | yylhs.value = yystack_@{0@}.value;])[ |
2ea7730c AD |
797 | ]b4_locations_if([dnl |
798 | [ | |
8901f32e | 799 | // Compute the default @@$. |
2b548aa6 | 800 | { |
bc0b0477 | 801 | slice<stack_symbol_type, stack_type> slice (yystack_, yylen); |
e1f93869 | 802 | YYLLOC_DEFAULT (yylhs.location, slice, yylen); |
2ea7730c | 803 | }]])[ |
8901f32e AD |
804 | |
805 | // Perform the reduction. | |
98ae9643 | 806 | YY_REDUCE_PRINT (yyn); |
ff601366 | 807 | try |
98ae9643 | 808 | { |
77a1a208 AD |
809 | switch (yyn) |
810 | { | |
30bb2edc | 811 | ]b4_user_actions[ |
77a1a208 AD |
812 | default: |
813 | break; | |
814 | } | |
98ae9643 | 815 | } |
ff601366 | 816 | catch (const syntax_error& yyexc) |
77a1a208 AD |
817 | { |
818 | error (yyexc); | |
819 | YYERROR; | |
820 | } | |
1f7d007b | 821 | YY_SYMBOL_PRINT ("-> $$ =", yylhs); |
8901f32e | 822 | ]b4_variant_if([[ |
9c6a8966 | 823 | // Destroy the rhs symbols. |
8901f32e | 824 | for (int i = 0; i < yylen; ++i) |
9c6a8966 AD |
825 | // Destroy a variant which value may have been swapped with |
826 | // yylhs.value (for instance if the action was "std::swap($$, | |
827 | // $1)"). The value of yylhs.value (hence possibly one of these | |
5237cd1a | 828 | // rhs symbols) depends on the default construction for this |
9c6a8966 AD |
829 | // type. In the case of pointers for instance, no |
830 | // initialization is done, so the value is junk. Therefore do | |
831 | // not try to report the value of symbols about to be destroyed | |
832 | // in the debug trace, it's possibly junk. Hence yymsg = 0. | |
833 | // Besides, that keeps exactly the same traces as with the other | |
834 | // Bison skeletons. | |
eeaf1dc6 | 835 | yy_destroy_ (YY_NULL, yystack_[i]);]])[ |
98ae9643 AD |
836 | |
837 | yypop_ (yylen); | |
a85284cf | 838 | yylen = 0; |
98ae9643 | 839 | YY_STACK_PRINT (); |
98ae9643 | 840 | |
ac826bc4 | 841 | // Shift the result of the reduction. |
eeaf1dc6 | 842 | yypush_ (YY_NULL, yylhs); |
98ae9643 AD |
843 | goto yynewstate; |
844 | ||
9c6a8966 AD |
845 | /*--------------------------------------. |
846 | | yyerrlab -- here on detecting error. | | |
847 | `--------------------------------------*/ | |
98ae9643 | 848 | yyerrlab: |
ac826bc4 | 849 | // If not already recovering from an error, report this error. |
98ae9643 AD |
850 | if (!yyerrstatus_) |
851 | { | |
e9690142 | 852 | ++yynerrs_; |
710c4a65 | 853 | error (]b4_join(b4_locations_if([yyla.location]), |
d2060f06 JD |
854 | [[yysyntax_error_ (yystack_[0].state, |
855 | yyempty ? yyempty_ : yyla.type)]])[); | |
98ae9643 AD |
856 | } |
857 | ||
2ea7730c | 858 | ]b4_locations_if([[ |
44c2b42d | 859 | yyerror_range[1].location = yyla.location;]])[ |
98ae9643 AD |
860 | if (yyerrstatus_ == 3) |
861 | { | |
e9690142 | 862 | /* If just tried and failed to reuse lookahead token after an |
27cb5b59 AD |
863 | error, discard it. */ |
864 | ||
ac826bc4 | 865 | // Return failure if at end of input. |
aba12ad1 | 866 | if (yyla.type == yyeof_) |
27cb5b59 | 867 | YYABORT; |
d59beda0 | 868 | else if (!yyempty) |
39be9022 | 869 | { |
27cb5b59 | 870 | yy_destroy_ ("Error: discarding", yyla); |
39be9022 | 871 | yyempty = true; |
e9690142 | 872 | } |
98ae9643 AD |
873 | } |
874 | ||
ac826bc4 | 875 | // Else will try to reuse lookahead token after shifting the error token. |
98ae9643 AD |
876 | goto yyerrlab1; |
877 | ||
878 | ||
879 | /*---------------------------------------------------. | |
880 | | yyerrorlab -- error raised explicitly by YYERROR. | | |
881 | `---------------------------------------------------*/ | |
882 | yyerrorlab: | |
883 | ||
884 | /* Pacify compilers like GCC when the user code never invokes | |
885 | YYERROR and the label yyerrorlab therefore never appears in user | |
886 | code. */ | |
887 | if (false) | |
c4dc4c46 | 888 | goto yyerrorlab;]b4_locations_if([[ |
44c2b42d | 889 | yyerror_range[1].location = yystack_[yylen - 1].location;]])b4_variant_if([[ |
c4dc4c46 AD |
890 | /* $$ was initialized before running the user action. */ |
891 | yy_destroy_ ("Error: discarding", yylhs);]])[ | |
a85284cf | 892 | /* Do not reclaim the symbols of the rule which action triggered |
9d9b8b70 | 893 | this YYERROR. */ |
98ae9643 | 894 | yypop_ (yylen); |
a85284cf | 895 | yylen = 0; |
98ae9643 AD |
896 | goto yyerrlab1; |
897 | ||
898 | /*-------------------------------------------------------------. | |
899 | | yyerrlab1 -- common code for both syntax error and YYERROR. | | |
900 | `-------------------------------------------------------------*/ | |
901 | yyerrlab1: | |
ac826bc4 | 902 | yyerrstatus_ = 3; // Each real token shifted decrements this. |
e1f93869 | 903 | { |
bc0b0477 | 904 | stack_symbol_type error_token; |
e1f93869 AD |
905 | for (;;) |
906 | { | |
7580c379 | 907 | yyn = yypact_[yystack_[0].state]; |
f2b30bdf | 908 | if (!yy_pact_value_is_default_ (yyn)) |
e1f93869 AD |
909 | { |
910 | yyn += yyterror_; | |
911 | if (0 <= yyn && yyn <= yylast_ && yycheck_[yyn] == yyterror_) | |
912 | { | |
913 | yyn = yytable_[yyn]; | |
914 | if (0 < yyn) | |
915 | break; | |
916 | } | |
917 | } | |
98ae9643 | 918 | |
e1f93869 AD |
919 | // Pop the current state because it cannot handle the error token. |
920 | if (yystack_.size () == 1) | |
921 | YYABORT; | |
2ea7730c | 922 | ]b4_locations_if([[ |
44c2b42d | 923 | yyerror_range[1].location = yystack_[0].location;]])[ |
1f7d007b | 924 | yy_destroy_ ("Error: popping", yystack_[0]); |
e1f93869 | 925 | yypop_ (); |
e1f93869 AD |
926 | YY_STACK_PRINT (); |
927 | } | |
2ea7730c | 928 | ]b4_locations_if([[ |
44c2b42d JD |
929 | yyerror_range[2].location = yyla.location; |
930 | YYLLOC_DEFAULT (error_token.location, yyerror_range, 2);]])[ | |
e1f93869 | 931 | |
ac826bc4 | 932 | // Shift the error token. |
7580c379 | 933 | error_token.state = yyn; |
e9b0834e | 934 | yypush_ ("Shifting", error_token); |
e1f93869 | 935 | } |
98ae9643 AD |
936 | goto yynewstate; |
937 | ||
ac826bc4 | 938 | // Accept. |
98ae9643 AD |
939 | yyacceptlab: |
940 | yyresult = 0; | |
941 | goto yyreturn; | |
942 | ||
ac826bc4 | 943 | // Abort. |
98ae9643 AD |
944 | yyabortlab: |
945 | yyresult = 1; | |
946 | goto yyreturn; | |
947 | ||
948 | yyreturn: | |
39be9022 | 949 | if (!yyempty) |
1f7d007b | 950 | yy_destroy_ ("Cleanup: discarding lookahead", yyla); |
98ae9643 | 951 | |
a85284cf | 952 | /* Do not reclaim the symbols of the rule which action triggered |
9d9b8b70 | 953 | this YYABORT or YYACCEPT. */ |
a85284cf | 954 | yypop_ (yylen); |
23d13411 | 955 | while (1 < yystack_.size ()) |
98ae9643 | 956 | { |
e9690142 JD |
957 | yy_destroy_ ("Cleanup: popping", yystack_[0]); |
958 | yypop_ (); | |
98ae9643 AD |
959 | } |
960 | ||
961 | return yyresult; | |
962 | } | |
7e1fabbe AD |
963 | catch (...) |
964 | { | |
25a6ad2f AD |
965 | YYCDEBUG << "Exception caught: cleaning lookahead and stack" |
966 | << std::endl; | |
967 | // Do not try to display the values of the reclaimed symbols, | |
968 | // as their printer might throw an exception. | |
23d13411 AD |
969 | if (!yyempty) |
970 | yy_destroy_ (YY_NULL, yyla); | |
7e1fabbe | 971 | |
23d13411 | 972 | while (1 < yystack_.size ()) |
7e1fabbe | 973 | { |
23d13411 | 974 | yy_destroy_ (YY_NULL, yystack_[0]); |
7e1fabbe AD |
975 | yypop_ (); |
976 | } | |
977 | throw; | |
978 | } | |
98ae9643 | 979 | } |
2b548aa6 | 980 | |
a6552c5d AD |
981 | void |
982 | ]b4_parser_class_name[::error (const syntax_error& yyexc) | |
983 | { | |
710c4a65 | 984 | error (]b4_join(b4_locations_if([yyexc.location]), |
a6552c5d AD |
985 | [[yyexc.what()]])[); |
986 | } | |
987 | ||
98ae9643 AD |
988 | // Generate an error message. |
989 | std::string | |
422c18f4 | 990 | ]b4_parser_class_name[::yysyntax_error_ (]dnl |
ceb8b8e6 | 991 | b4_error_verbose_if([state_type yystate, int yytoken], |
422c18f4 | 992 | [int, int])[) |
25a648d8 JD |
993 | {]b4_error_verbose_if([[ |
994 | std::string yyres; | |
d2060f06 JD |
995 | // Number of reported tokens (one for the "unexpected", one per |
996 | // "expected"). | |
997 | size_t yycount = 0; | |
998 | // Its maximum. | |
999 | enum { YYERROR_VERBOSE_ARGS_MAXIMUM = 5 }; | |
1000 | // Arguments of yyformat. | |
1001 | char const *yyarg[YYERROR_VERBOSE_ARGS_MAXIMUM]; | |
1002 | ||
1003 | /* There are many possibilities here to consider: | |
1004 | - If this state is a consistent state with a default action, then | |
1005 | the only way this function was invoked is if the default action | |
1006 | is an error action. In that case, don't check for expected | |
1007 | tokens because there are none. | |
1008 | - The only way there can be no lookahead present (in yytoken) is | |
1009 | if this state is a consistent state with a default action. | |
1010 | Thus, detecting the absence of a lookahead is sufficient to | |
1011 | determine that there is no unexpected or expected token to | |
1012 | report. In that case, just report a simple "syntax error". | |
1013 | - Don't assume there isn't a lookahead just because this state is | |
1014 | a consistent state with a default action. There might have | |
1015 | been a previous inconsistent state, consistent state with a | |
1016 | non-default action, or user semantic action that manipulated | |
1017 | yyla. (However, yyla is currently not documented for users.) | |
1018 | - Of course, the expected token list depends on states to have | |
1019 | correct lookahead information, and it depends on the parser not | |
1020 | to perform extra reductions after fetching a lookahead from the | |
1021 | scanner and before detecting a syntax error. Thus, state | |
1022 | merging (from LALR or IELR) and default reductions corrupt the | |
1023 | expected token list. However, the list is correct for | |
1024 | canonical LR with one exception: it will still contain any | |
1025 | token that will not be accepted due to an error action in a | |
1026 | later state. | |
1027 | */ | |
1028 | if (yytoken != yyempty_) | |
98ae9643 | 1029 | { |
d2060f06 JD |
1030 | yyarg[yycount++] = yytname_[yytoken]; |
1031 | int yyn = yypact_[yystate]; | |
1032 | if (!yy_pact_value_is_default_ (yyn)) | |
1033 | { | |
b4bbc4a0 JD |
1034 | /* Start YYX at -YYN if negative to avoid negative indexes in |
1035 | YYCHECK. In other words, skip the first -YYN actions for | |
1036 | this state because they are default actions. */ | |
1037 | int yyxbegin = yyn < 0 ? -yyn : 0; | |
ac826bc4 | 1038 | // Stay within bounds of both yycheck and yytname. |
b4bbc4a0 JD |
1039 | int yychecklim = yylast_ - yyn + 1; |
1040 | int yyxend = yychecklim < yyntokens_ ? yychecklim : yyntokens_; | |
b4bbc4a0 JD |
1041 | for (int yyx = yyxbegin; yyx < yyxend; ++yyx) |
1042 | if (yycheck_[yyx + yyn] == yyx && yyx != yyterror_ | |
1043 | && !yy_table_value_is_error_ (yytable_[yyx + yyn])) | |
1044 | { | |
1045 | if (yycount == YYERROR_VERBOSE_ARGS_MAXIMUM) | |
1046 | { | |
1047 | yycount = 1; | |
1048 | break; | |
1049 | } | |
1050 | else | |
1051 | yyarg[yycount++] = yytname_[yyx]; | |
1052 | } | |
d2060f06 JD |
1053 | } |
1054 | } | |
a0ffc175 | 1055 | |
ef51bfa7 | 1056 | char const* yyformat = YY_NULL; |
b4bbc4a0 JD |
1057 | switch (yycount) |
1058 | { | |
1059 | #define YYCASE_(N, S) \ | |
1060 | case N: \ | |
1061 | yyformat = S; \ | |
1062 | break | |
d2060f06 | 1063 | YYCASE_(0, YY_("syntax error")); |
b4bbc4a0 JD |
1064 | YYCASE_(1, YY_("syntax error, unexpected %s")); |
1065 | YYCASE_(2, YY_("syntax error, unexpected %s, expecting %s")); | |
1066 | YYCASE_(3, YY_("syntax error, unexpected %s, expecting %s or %s")); | |
1067 | YYCASE_(4, YY_("syntax error, unexpected %s, expecting %s or %s or %s")); | |
1068 | YYCASE_(5, YY_("syntax error, unexpected %s, expecting %s or %s or %s or %s")); | |
a0ffc175 | 1069 | #undef YYCASE_ |
98ae9643 | 1070 | } |
d2060f06 | 1071 | |
b4bbc4a0 JD |
1072 | // Argument number. |
1073 | size_t yyi = 0; | |
1074 | for (char const* yyp = yyformat; *yyp; ++yyp) | |
1075 | if (yyp[0] == '%' && yyp[1] == 's' && yyi < yycount) | |
1076 | { | |
1077 | yyres += yytnamerr_ (yyarg[yyi++]); | |
1078 | ++yyp; | |
1079 | } | |
1080 | else | |
1081 | yyres += *yyp; | |
25a648d8 JD |
1082 | return yyres;]], [[ |
1083 | return YY_("syntax error");]])[ | |
98ae9643 | 1084 | } |
a08460b0 | 1085 | |
5348bfbe | 1086 | |
98ae9643 | 1087 | const ]b4_int_type(b4_pact_ninf, b4_pact_ninf) b4_parser_class_name::yypact_ninf_ = b4_pact_ninf[; |
2b548aa6 | 1088 | |
0fddb3d5 AD |
1089 | const ]b4_int_type(b4_table_ninf, b4_table_ninf) b4_parser_class_name::yytable_ninf_ = b4_table_ninf[; |
1090 | ||
ba206cf4 | 1091 | ]b4_parser_tables_define[ |
2b548aa6 | 1092 | |
5f108727 | 1093 | ]b4_token_table_if([], [[#if ]b4_api_PREFIX[DEBUG]])[ |
ac826bc4 AD |
1094 | // YYTNAME[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM. |
1095 | // First, the terminals, then, starting at \a yyntokens_, nonterminals. | |
98ae9643 AD |
1096 | const char* |
1097 | const ]b4_parser_class_name[::yytname_[] = | |
1098 | { | |
8901f32e | 1099 | ]b4_tname[ |
98ae9643 | 1100 | }; |
2b548aa6 | 1101 | |
5f108727 | 1102 | ]b4_token_table_if([[#if ]b4_api_PREFIX[DEBUG]])[ |
ba206cf4 | 1103 | ]b4_integral_parser_table_define([rline], [b4_rline])[ |
5348bfbe | 1104 | |
98ae9643 AD |
1105 | // Print the state stack on the debug stream. |
1106 | void | |
1107 | ]b4_parser_class_name[::yystack_print_ () | |
1108 | { | |
1109 | *yycdebug_ << "Stack now"; | |
8901f32e AD |
1110 | for (stack_type::const_iterator |
1111 | i = yystack_.begin (), | |
1112 | i_end = yystack_.end (); | |
e9690142 | 1113 | i != i_end; ++i) |
8901f32e | 1114 | *yycdebug_ << ' ' << i->state; |
98ae9643 AD |
1115 | *yycdebug_ << std::endl; |
1116 | } | |
25f66e1a | 1117 | |
98ae9643 AD |
1118 | // Report on the debug stream that the rule \a yyrule is going to be reduced. |
1119 | void | |
d1ff7a7c | 1120 | ]b4_parser_class_name[::yy_reduce_print_ (int yyrule) |
98ae9643 AD |
1121 | { |
1122 | unsigned int yylno = yyrline_[yyrule]; | |
d1ff7a7c | 1123 | int yynrhs = yyr2_[yyrule]; |
ac826bc4 | 1124 | // Print the symbols being reduced, and their result. |
98ae9643 | 1125 | *yycdebug_ << "Reducing stack by rule " << yyrule - 1 |
e9690142 | 1126 | << " (line " << yylno << "):" << std::endl; |
ac826bc4 | 1127 | // The symbols being reduced. |
d1ff7a7c AD |
1128 | for (int yyi = 0; yyi < yynrhs; yyi++) |
1129 | YY_SYMBOL_PRINT (" $" << yyi + 1 << " =", | |
1f7d007b | 1130 | ]b4_rhs_data(yynrhs, yyi + 1)[); |
98ae9643 | 1131 | } |
5f108727 | 1132 | #endif // ]b4_api_PREFIX[DEBUG |
69e2658b | 1133 | |
e36ec1f4 | 1134 | ]b4_token_ctor_if([], [b4_yytranslate_define])[ |
793fbca5 | 1135 | ]b4_namespace_close[ |
8901f32e | 1136 | ]b4_epilogue[]dnl |
1c7ec959 | 1137 | b4_output_end() |
064e42b0 AD |
1138 | |
1139 | ||
a9ce3f54 | 1140 | m4_popdef([b4_copyright_years])dnl |