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