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