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