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