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