]> git.saurik.com Git - bison.git/blob - data/lalr1.cc
Remove b4_root related material: failure experiment
[bison.git] / data / lalr1.cc
1 m4_divert(-1)
2 # C++ skeleton for Bison
3 # Copyright (C) 2002, 2003, 2004 Free Software Foundation, Inc.
4
5 # This program is free software; you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation; either version 2 of the License, or
8 # (at your option) any later version.
9
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
14
15 # You should have received a copy of the GNU General Public License
16 # along with this program; if not, write to the Free Software
17 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
18 # 02111-1307 USA
19
20 ## ---------------- ##
21 ## Default values. ##
22 ## ---------------- ##
23
24 # Default Parser class name.
25 m4_define_default([b4_parser_class_name], [Parser])
26
27
28
29 ## ----------------- ##
30 ## Semantic Values. ##
31 ## ----------------- ##
32
33
34 # b4_lhs_value([TYPE])
35 # --------------------
36 # Expansion of $<TYPE>$.
37 m4_define([b4_lhs_value],
38 [yyval[]m4_ifval([$1], [.$1])])
39
40
41 # b4_rhs_value(RULE-LENGTH, NUM, [TYPE])
42 # --------------------------------------
43 # Expansion of $<TYPE>NUM, where the current rule has RULE-LENGTH
44 # symbols on RHS.
45 m4_define([b4_rhs_value],
46 [semantic_stack_@{m4_eval([$1 - $2])@}m4_ifval([$3], [.$3])])
47
48 m4_define_default([b4_location_type], [Location])
49
50 # b4_lhs_location()
51 # -----------------
52 # Expansion of @$.
53 m4_define([b4_lhs_location],
54 [yyloc])
55
56
57 # b4_rhs_location(RULE-LENGTH, NUM)
58 # ---------------------------------
59 # Expansion of @NUM, where the current rule has RULE-LENGTH symbols
60 # on RHS.
61 m4_define([b4_rhs_location],
62 [location_stack_@{m4_eval([$1 - $2])@}])
63
64
65 # b4_parse_param_decl
66 # -------------------
67 # Extra formal arguments of the constructor.
68 # Change the parameter names from "foo" into "foo_yyarg", so that
69 # there is no collision bw the user chosen attribute name, and the
70 # argument name in the constructor.
71 m4_define([b4_parse_param_decl],
72 [m4_ifset([b4_parse_param],
73 [, m4_map_sep([b4_parse_param_decl_1], [, ], [b4_parse_param])])])
74
75 m4_define([b4_parse_param_decl_1],
76 [$1_yyarg])
77
78
79
80 # b4_parse_param_cons
81 # -------------------
82 # Extra initialisations of the constructor.
83 m4_define([b4_parse_param_cons],
84 [m4_ifset([b4_parse_param],
85 [,
86 b4_cc_constructor_calls(b4_parse_param)])])
87 m4_define([b4_cc_constructor_calls],
88 [m4_map_sep([b4_cc_constructor_call], [,
89 ], [$@])])
90 m4_define([b4_cc_constructor_call],
91 [$2 ($2_yyarg)])
92
93 # b4_parse_param_vars
94 # -------------------
95 # Extra instance variables.
96 m4_define([b4_parse_param_vars],
97 [m4_ifset([b4_parse_param],
98 [
99 /* User arguments. */
100 b4_cc_var_decls(b4_parse_param)])])
101 m4_define([b4_cc_var_decls],
102 [m4_map_sep([b4_cc_var_decl], [
103 ], [$@])])
104 m4_define([b4_cc_var_decl],
105 [ $1;])
106
107
108
109 # We do want M4 expansion after # for CPP macros.
110 m4_changecom()
111 m4_divert(0)dnl
112 m4_if(b4_defines_flag, 0, [],
113 [@output @output_header_name@
114 b4_copyright([C++ Skeleton parser for LALR(1) parsing with Bison],
115 [2002, 2003, 2004])[
116 /* FIXME: This is wrong, we want computed header guards.
117 I don't know why the macros are missing now. :( */
118 #ifndef PARSER_HEADER_H
119 # define PARSER_HEADER_H
120
121 #include "stack.hh"
122 #include "location.hh"
123
124 #include <string>
125 #include <iostream>
126
127 /* Using locations. */
128 #define YYLSP_NEEDED ]b4_locations_flag[
129
130 ]b4_token_defines(b4_tokens)[
131
132 /* Copy the first part of user declarations. */
133 ]b4_pre_prologue[
134
135 ]/* Line __line__ of lalr1.cc. */
136 b4_syncline([@oline@], [@ofile@])[
137
138 /* Enabling traces. */
139 #ifndef YYDEBUG
140 # define YYDEBUG ]b4_debug[
141 #endif
142
143 /* Enabling verbose error message. */
144 #ifndef YYERROR_VERBOSE
145 # define YYERROR_VERBOSE ]b4_error_verbose[
146 #endif
147
148 #if ! defined (YYSTYPE) && ! defined (YYSTYPE_IS_DECLARED)
149 ]m4_ifdef([b4_stype],
150 [b4_syncline([b4_stype_line], [b4_filename])
151 union YYSTYPE b4_stype;
152 /* Line __line__ of lalr1.cc. */
153 b4_syncline([@oline@], [@ofile@])],
154 [typedef int YYSTYPE;])[
155 # define yystype YYSTYPE /* obsolescent; will be withdrawn */
156 # define YYSTYPE_IS_DECLARED 1
157 # define YYSTYPE_IS_TRIVIAL 1
158 #endif
159
160 /* Copy the second part of user declarations. */
161 ]b4_post_prologue[
162
163 ]/* Line __line__ of lalr1.cc. */
164 b4_syncline([@oline@], [@ofile@])[
165 /* YYLLOC_DEFAULT -- Set CURRENT to span from RHS[1] to RHS[N].
166 If N is 0, then set CURRENT to the empty location which ends
167 the previous symbol: RHS[0] (always defined). */
168
169 #ifndef YYLLOC_DEFAULT
170 # define YYLLOC_DEFAULT(Current, Rhs, N) \
171 do { \
172 if (N) \
173 { \
174 (Current).begin = (Rhs)[1].begin; \
175 (Current).end = (Rhs)[N].end; \
176 } \
177 else \
178 { \
179 (Current).begin = (Current).end = (Rhs)[0].end; \
180 } \
181 } while (0)
182 #endif
183
184 namespace yy
185 {
186 class ]b4_parser_class_name[;
187
188 template <typename P>
189 struct Traits
190 {
191 };
192
193 template <>
194 struct Traits<]b4_parser_class_name[>
195 {
196 typedef ]b4_int_type_for([b4_translate])[ TokenNumberType;
197 typedef ]b4_int_type_for([b4_rhs])[ RhsNumberType;
198 typedef int StateType;
199 typedef YYSTYPE SemanticType;
200 typedef ]b4_location_type[ LocationType;
201 };
202 }
203
204 namespace yy
205 {
206 class ]b4_parser_class_name[
207 {
208 public:
209
210 typedef Traits<]b4_parser_class_name[>::TokenNumberType TokenNumberType;
211 typedef Traits<]b4_parser_class_name[>::RhsNumberType RhsNumberType;
212 typedef Traits<]b4_parser_class_name[>::StateType StateType;
213 typedef Traits<]b4_parser_class_name[>::SemanticType SemanticType;
214 typedef Traits<]b4_parser_class_name[>::LocationType LocationType;
215
216 typedef Stack<StateType> StateStack;
217 typedef Stack<SemanticType> SemanticStack;
218 typedef Stack<LocationType> LocationStack;
219
220 ]b4_parser_class_name[ (bool debug]b4_parse_param_decl[) :
221 debug_ (debug),
222 yycdebug_ (&std::cerr)]b4_parse_param_cons[
223 {
224 }
225
226 ]b4_parser_class_name[ (bool debug,
227 LocationType]b4_parse_param_decl[) :
228 debug_ (debug),
229 yycdebug_ (&std::cerr)]b4_parse_param_cons[
230 {
231 *yycdebug_ << __FILE__ << ':' << __LINE__
232 << ": this constructor is provided by backward compatibility"
233 << ", but will be removed in the near future."
234 << std::endl;
235 }
236
237 virtual ~]b4_parser_class_name[ ()
238 {
239 }
240
241 virtual int parse ();
242
243 /// Return the current debugging stream.
244 std::ostream& debug_stream () const;
245 /// Set the current debugging stream.
246 void set_debug_stream (std::ostream &);
247
248 private:
249
250 virtual void lex_ ();
251 virtual void error_ ();
252 virtual void report_syntax_error_ ();
253 #if YYDEBUG
254 virtual void symprint_ (int yytype,
255 const SemanticType* yyvaluep,
256 const LocationType* yylocationp);
257 #endif /* ! YYDEBUG */
258
259
260 /* Stacks. */
261 StateStack state_stack_;
262 SemanticStack semantic_stack_;
263 LocationStack location_stack_;
264
265 /* Tables. */
266 static const ]b4_int_type_for([b4_pact])[ pact_[];
267 static const ]b4_int_type(b4_pact_ninf, b4_pact_ninf)[ pact_ninf_;
268 static const ]b4_int_type_for([b4_defact])[ defact_[];
269 static const ]b4_int_type_for([b4_pgoto])[ pgoto_[];
270 static const ]b4_int_type_for([b4_defgoto])[ defgoto_[];
271 static const ]b4_int_type_for([b4_table])[ table_[];
272 static const ]b4_int_type(b4_table_ninf, b4_table_ninf)[ table_ninf_;
273 static const ]b4_int_type_for([b4_check])[ check_[];
274 static const ]b4_int_type_for([b4_stos])[ stos_[];
275 static const ]b4_int_type_for([b4_r1])[ r1_[];
276 static const ]b4_int_type_for([b4_r2])[ r2_[];
277
278 #if YYDEBUG || YYERROR_VERBOSE
279 static const char* const name_[];
280 #endif
281
282 /* More tables, for debugging. */
283 #if YYDEBUG
284 static const RhsNumberType rhs_[];
285 static const ]b4_int_type_for([b4_prhs])[ prhs_[];
286 static const ]b4_int_type_for([b4_rline])[ rline_[];
287 static const ]b4_int_type_for([b4_toknum])[ token_number_[];
288 virtual void reduce_print_ (int yyrule);
289 virtual void stack_print_ ();
290 #endif
291
292 /* Even more tables. */
293 inline TokenNumberType translate_ (int token);
294 inline void destruct_ (const char* yymsg,
295 int yytype,
296 SemanticType* yyvaluep, LocationType* yylocationp);
297
298 /// Pop \a n symbols the three stacks.
299 inline void pop (unsigned int n = 1);
300
301 /* Constants. */
302 static const int eof_;
303 /* LAST_ -- Last index in TABLE_. */
304 static const int last_;
305 static const int nnts_;
306 static const int empty_;
307 static const int final_;
308 static const int terror_;
309 static const int errcode_;
310 static const int ntokens_;
311 static const unsigned int user_token_number_max_;
312 static const TokenNumberType undef_token_;
313
314 /* State. */
315 int n_;
316 int len_;
317 int state_;
318
319 /* Error handling. */
320 int nerrs_;
321 int errstatus_;
322
323 /* Debugging. */
324 int debug_;
325 std::ostream* yycdebug_;
326
327 /* Look-ahead and look-ahead in internal form. */
328 int looka_;
329 int ilooka_;
330
331 /* Message. */
332 std::string message;
333
334 /// Semantic value of the look-ahead.
335 SemanticType value;
336 /// Location of the look-ahead.
337 LocationType location;
338 /// The locations where the error started and ended.
339 Location error_range_[2];
340
341 /// $$.
342 SemanticType yyval;
343 /// @@$.
344 LocationType yyloc;
345 ]b4_parse_param_vars[
346 };
347 }
348
349 #endif /* ! defined PARSER_HEADER_H */]
350 ])dnl
351 @output @output_parser_name@
352 b4_copyright([C++ Skeleton parser for LALR(1) parsing with Bison],
353 [2002, 2003, 2004])
354
355 m4_if(b4_defines_flag, 0, [], [#include @output_header_name@])[
356
357 /* A pseudo ostream that takes debug_ into account. */
358 # define YYCDEBUG \
359 for (bool yydebugcond_ = debug_; yydebugcond_; yydebugcond_ = false) \
360 (*yycdebug_)
361
362 /* Enable debugging if requested. */
363 #if YYDEBUG
364
365 # define YY_SYMBOL_PRINT(Title, Type, Value, Location) \
366 do { \
367 if (debug_) \
368 { \
369 *yycdebug_ << (Title) << ' '; \
370 symprint_ ((Type), (Value), (Location)); \
371 *yycdebug_ << std::endl; \
372 } \
373 } while (0)
374
375 # define YY_REDUCE_PRINT(Rule) \
376 do { \
377 if (debug_) \
378 reduce_print_ (Rule); \
379 } while (0)
380
381 # define YY_STACK_PRINT() \
382 do { \
383 if (debug_) \
384 stack_print_ (); \
385 } while (0)
386
387 #else /* !YYDEBUG */
388
389 # define YY_SYMBOL_PRINT(Title, Type, Value, Location)
390 # define YY_REDUCE_PRINT(Rule)
391 # define YY_STACK_PRINT()
392
393 #endif /* !YYDEBUG */
394
395 #define YYACCEPT goto yyacceptlab
396 #define YYABORT goto yyabortlab
397 #define YYERROR goto yyerrorlab
398
399 #if YYDEBUG
400 /*--------------------------------.
401 | Print this symbol on YYOUTPUT. |
402 `--------------------------------*/
403
404 void
405 yy::]b4_parser_class_name[::symprint_ (int yytype,
406 const SemanticType* yyvaluep, const LocationType* yylocationp)
407 {
408 /* Pacify ``unused variable'' warnings. */
409 (void) yyvaluep;
410 (void) yylocationp;
411 /* Backward compatibility, but should be removed eventually. */
412 std::ostream& cdebug_ = *yycdebug_;
413 (void) cdebug_;
414
415 *yycdebug_ << (yytype < ntokens_ ? "token" : "nterm")
416 << ' ' << name_[yytype] << " ("
417 << *yylocationp << ": ";
418 switch (yytype)
419 {
420 ]m4_map([b4_symbol_actions], m4_defn([b4_symbol_printers]))dnl
421 [ default:
422 break;
423 }
424 *yycdebug_ << ')';
425 }
426 #endif /* ! YYDEBUG */
427
428 void
429 yy::]b4_parser_class_name[::destruct_ (const char* yymsg,
430 int yytype, SemanticType* yyvaluep, LocationType* yylocationp)
431 {
432 /* Pacify ``unused variable'' warnings. */
433 (void) yyvaluep;
434 (void) yylocationp;
435
436 YY_SYMBOL_PRINT (yymsg, yytype, yyvaluep, yylocationp);
437
438 switch (yytype)
439 {
440 ]m4_map([b4_symbol_actions], m4_defn([b4_symbol_destructors]))[
441 default:
442 break;
443 }
444 }
445
446 void
447 yy::]b4_parser_class_name[::pop (unsigned int n)
448 {
449 state_stack_.pop (n);
450 semantic_stack_.pop (n);
451 location_stack_.pop (n);
452 }
453
454 std::ostream&
455 yy::]b4_parser_class_name[::debug_stream () const
456 {
457 return *yycdebug_;
458 }
459
460 void
461 yy::]b4_parser_class_name[::set_debug_stream (std::ostream& o)
462 {
463 yycdebug_ = &o;
464 }
465
466
467 int
468 yy::]b4_parser_class_name[::parse ()
469 {
470 YYCDEBUG << "Starting parse" << std::endl;
471
472 nerrs_ = 0;
473 errstatus_ = 0;
474
475 /* Start. */
476 state_ = 0;
477 looka_ = empty_;
478
479 ]m4_ifdef([b4_initial_action], [
480 m4_pushdef([b4_at_dollar], [location])dnl
481 m4_pushdef([b4_dollar_dollar], [value])dnl
482 /* User initialization code. */
483 b4_initial_action
484 m4_popdef([b4_dollar_dollar])dnl
485 m4_popdef([b4_at_dollar])dnl
486 /* Line __line__ of yacc.c. */
487 b4_syncline([@oline@], [@ofile@])])dnl
488
489 [ /* Initialize the stacks. The initial state will be pushed in
490 yynewstate, since the latter expects the semantical and the
491 location values to have been already stored, initialize these
492 stacks with a primary value. */
493 state_stack_ = StateStack (0);
494 semantic_stack_ = SemanticStack (0);
495 location_stack_ = LocationStack (0);
496 semantic_stack_.push (value);
497 location_stack_.push (location);
498
499 /* New state. */
500 yynewstate:
501 state_stack_.push (state_);
502 YYCDEBUG << "Entering state " << state_ << std::endl;
503 goto yybackup;
504
505 /* Backup. */
506 yybackup:
507
508 /* Try to take a decision without look-ahead. */
509 n_ = pact_[state_];
510 if (n_ == pact_ninf_)
511 goto yydefault;
512
513 /* Read a look-ahead token. */
514 if (looka_ == empty_)
515 {
516 YYCDEBUG << "Reading a token: ";
517 lex_ ();
518 }
519
520 /* Convert token to internal form. */
521 if (looka_ <= eof_)
522 {
523 looka_ = ilooka_ = eof_;
524 YYCDEBUG << "Now at end of input." << std::endl;
525 }
526 else
527 {
528 ilooka_ = translate_ (looka_);
529 YY_SYMBOL_PRINT ("Next token is", ilooka_, &value, &location);
530 }
531
532 /* If the proper action on seeing token ILOOKA_ is to reduce or to
533 detect an error, take that action. */
534 n_ += ilooka_;
535 if (n_ < 0 || last_ < n_ || check_[n_] != ilooka_)
536 goto yydefault;
537
538 /* Reduce or error. */
539 n_ = table_[n_];
540 if (n_ < 0)
541 {
542 if (n_ == table_ninf_)
543 goto yyerrlab;
544 else
545 {
546 n_ = -n_;
547 goto yyreduce;
548 }
549 }
550 else if (n_ == 0)
551 goto yyerrlab;
552
553 /* Accept? */
554 if (n_ == final_)
555 goto yyacceptlab;
556
557 /* Shift the look-ahead token. */
558 YY_SYMBOL_PRINT ("Shifting", ilooka_, &value, &location);
559
560 /* Discard the token being shifted unless it is eof. */
561 if (looka_ != eof_)
562 looka_ = empty_;
563
564 semantic_stack_.push (value);
565 location_stack_.push (location);
566
567 /* Count tokens shifted since error; after three, turn off error
568 status. */
569 if (errstatus_)
570 --errstatus_;
571
572 state_ = n_;
573 goto yynewstate;
574
575 /*-----------------------------------------------------------.
576 | yydefault -- do the default action for the current state. |
577 `-----------------------------------------------------------*/
578 yydefault:
579 n_ = defact_[state_];
580 if (n_ == 0)
581 goto yyerrlab;
582 goto yyreduce;
583
584 /*-----------------------------.
585 | yyreduce -- Do a reduction. |
586 `-----------------------------*/
587 yyreduce:
588 len_ = r2_[n_];
589 /* If LEN_ is nonzero, implement the default value of the action:
590 `$$ = $1'. Otherwise, use the top of the stack.
591
592 Otherwise, the following line sets YYVAL to garbage.
593 This behavior is undocumented and Bison
594 users should not rely upon it. */
595 if (len_)
596 yyval = semantic_stack_[len_ - 1];
597 else
598 yyval = semantic_stack_[0];
599
600 {
601 Slice<LocationType, LocationStack> slice (location_stack_, len_);
602 YYLLOC_DEFAULT (yyloc, slice, len_);
603 }
604 YY_REDUCE_PRINT (n_);
605 switch (n_)
606 {
607 ]b4_actions[
608 }
609
610 ]/* Line __line__ of lalr1.cc. */
611 b4_syncline([@oline@], [@ofile@])[
612
613 pop (len_);
614
615 YY_STACK_PRINT ();
616
617 semantic_stack_.push (yyval);
618 location_stack_.push (yyloc);
619
620 /* Shift the result of the reduction. */
621 n_ = r1_[n_];
622 state_ = pgoto_[n_ - ntokens_] + state_stack_[0];
623 if (0 <= state_ && state_ <= last_ && check_[state_] == state_stack_[0])
624 state_ = table_[state_];
625 else
626 state_ = defgoto_[n_ - ntokens_];
627 goto yynewstate;
628
629 /*------------------------------------.
630 | yyerrlab -- here on detecting error |
631 `------------------------------------*/
632 yyerrlab:
633 /* If not already recovering from an error, report this error. */
634 report_syntax_error_ ();
635
636 error_range_[0] = location;
637 if (errstatus_ == 3)
638 {
639 /* If just tried and failed to reuse look-ahead token after an
640 error, discard it. */
641
642 /* Return failure if at end of input. */
643 if (looka_ <= eof_)
644 {
645 /* If at end of input, pop the error token,
646 then the rest of the stack, then return failure. */
647 if (looka_ == eof_)
648 for (;;)
649 {
650 error_range_[0] = location_stack_[0];
651 pop ();
652 if (state_stack_.height () == 1)
653 YYABORT;
654 destruct_ ("Error: popping",
655 stos_[state_stack_[0]],
656 &semantic_stack_[0],
657 &location_stack_[0]);
658 }
659 }
660 else
661 {
662 destruct_ ("Error: discarding", ilooka_, &value, &location);
663 looka_ = empty_;
664 }
665 }
666
667 /* Else will try to reuse look-ahead token after shifting the error
668 token. */
669 goto yyerrlab1;
670
671
672 /*---------------------------------------------------.
673 | yyerrorlab -- error raised explicitly by YYERROR. |
674 `---------------------------------------------------*/
675 yyerrorlab:
676
677 #ifdef __GNUC__
678 /* Pacify GCC when the user code never invokes YYERROR and the label
679 yyerrorlab therefore never appears in user code. */
680 if (0)
681 goto yyerrorlab;
682 #endif
683
684 error_range_[0] = location_stack_[len_ - 1];
685 pop (len_);
686 state_ = state_stack_[0];
687 goto yyerrlab1;
688
689 /*-------------------------------------------------------------.
690 | yyerrlab1 -- common code for both syntax error and YYERROR. |
691 `-------------------------------------------------------------*/
692 yyerrlab1:
693 errstatus_ = 3; /* Each real token shifted decrements this. */
694
695 for (;;)
696 {
697 n_ = pact_[state_];
698 if (n_ != pact_ninf_)
699 {
700 n_ += terror_;
701 if (0 <= n_ && n_ <= last_ && check_[n_] == terror_)
702 {
703 n_ = table_[n_];
704 if (0 < n_)
705 break;
706 }
707 }
708
709 /* Pop the current state because it cannot handle the error token. */
710 if (state_stack_.height () == 1)
711 YYABORT;
712
713 error_range_[0] = location_stack_[0];
714 destruct_ ("Error: popping",
715 stos_[state_], &semantic_stack_[0], &location_stack_[0]);
716 pop ();
717 state_ = state_stack_[0];
718 YY_STACK_PRINT ();
719 }
720
721 if (n_ == final_)
722 goto yyacceptlab;
723
724 error_range_[1] = location;
725 // Using LOCATION is tempting, but would change the location of
726 // the look-ahead. YYLOC is available though.
727 YYLLOC_DEFAULT (yyloc, error_range_ - 1, 2);
728 semantic_stack_.push (value);
729 location_stack_.push (yyloc);
730
731 /* Shift the error token. */
732 YY_SYMBOL_PRINT ("Shifting", stos_[n_],
733 &semantic_stack_[0], &location_stack_[0]);
734
735 state_ = n_;
736 goto yynewstate;
737
738 /* Accept. */
739 yyacceptlab:
740 return 0;
741
742 /* Abort. */
743 yyabortlab:
744 /* Free the lookahead. */
745 destruct_ ("Error: discarding lookahead", ilooka_, &value, &location);
746 looka_ = empty_;
747 return 1;
748 }
749
750 void
751 yy::]b4_parser_class_name[::lex_ ()
752 {
753 #if YYLSP_NEEDED
754 looka_ = yylex (&value, &location);
755 #else
756 looka_ = yylex (&value);
757 #endif
758 }
759
760 /** Generate an error message, and invoke yyerror. */
761 void
762 yy::]b4_parser_class_name[::report_syntax_error_ ()
763 {
764 /* If not already recovering from an error, report this error. */
765 if (!errstatus_)
766 {
767 ++nerrs_;
768
769 #if YYERROR_VERBOSE
770 n_ = pact_[state_];
771 if (pact_ninf_ < n_ && n_ < last_)
772 {
773 message = "syntax error, unexpected ";
774 message += name_[ilooka_];
775 {
776 int count = 0;
777 for (int x = (n_ < 0 ? -n_ : 0); x < ntokens_ + nnts_; ++x)
778 if (check_[x + n_] == x && x != terror_)
779 ++count;
780 if (count < 5)
781 {
782 count = 0;
783 for (int x = (n_ < 0 ? -n_ : 0); x < ntokens_ + nnts_; ++x)
784 if (check_[x + n_] == x && x != terror_)
785 {
786 message += (!count++) ? ", expecting " : " or ";
787 message += name_[x];
788 }
789 }
790 }
791 }
792 else
793 #endif
794 message = "syntax error";
795 error_ ();
796 }
797 }
798
799
800 /* YYPACT[STATE-NUM] -- Index in YYTABLE of the portion describing
801 STATE-NUM. */
802 const ]b4_int_type(b4_pact_ninf, b4_pact_ninf) yy::b4_parser_class_name::pact_ninf_ = b4_pact_ninf[;
803 const ]b4_int_type_for([b4_pact])[
804 yy::]b4_parser_class_name[::pact_[] =
805 {
806 ]b4_pact[
807 };
808
809 /* YYDEFACT[S] -- default rule to reduce with in state S when YYTABLE
810 doesn't specify something else to do. Zero means the default is an
811 error. */
812 const ]b4_int_type_for([b4_defact])[
813 yy::]b4_parser_class_name[::defact_[] =
814 {
815 ]b4_defact[
816 };
817
818 /* YYPGOTO[NTERM-NUM]. */
819 const ]b4_int_type_for([b4_pgoto])[
820 yy::]b4_parser_class_name[::pgoto_[] =
821 {
822 ]b4_pgoto[
823 };
824
825 /* YYDEFGOTO[NTERM-NUM]. */
826 const ]b4_int_type_for([b4_defgoto])[
827 yy::]b4_parser_class_name[::defgoto_[] =
828 {
829 ]b4_defgoto[
830 };
831
832 /* YYTABLE[YYPACT[STATE-NUM]]. What to do in state STATE-NUM. If
833 positive, shift that token. If negative, reduce the rule which
834 number is the opposite. If zero, do what YYDEFACT says. */
835 const ]b4_int_type(b4_table_ninf, b4_table_ninf) yy::b4_parser_class_name::table_ninf_ = b4_table_ninf[;
836 const ]b4_int_type_for([b4_table])[
837 yy::]b4_parser_class_name[::table_[] =
838 {
839 ]b4_table[
840 };
841
842 /* YYCHECK. */
843 const ]b4_int_type_for([b4_check])[
844 yy::]b4_parser_class_name[::check_[] =
845 {
846 ]b4_check[
847 };
848
849 /* STOS_[STATE-NUM] -- The (internal number of the) accessing
850 symbol of state STATE-NUM. */
851 const ]b4_int_type_for([b4_stos])[
852 yy::]b4_parser_class_name[::stos_[] =
853 {
854 ]b4_stos[
855 };
856
857 #if YYDEBUG
858 /* TOKEN_NUMBER_[YYLEX-NUM] -- Internal token number corresponding
859 to YYLEX-NUM. */
860 const ]b4_int_type_for([b4_toknum])[
861 yy::]b4_parser_class_name[::token_number_[] =
862 {
863 ]b4_toknum[
864 };
865 #endif
866
867 /* YYR1[YYN] -- Symbol number of symbol that rule YYN derives. */
868 const ]b4_int_type_for([b4_r1])[
869 yy::]b4_parser_class_name[::r1_[] =
870 {
871 ]b4_r1[
872 };
873
874 /* YYR2[YYN] -- Number of symbols composing right hand side of rule YYN. */
875 const ]b4_int_type_for([b4_r2])[
876 yy::]b4_parser_class_name[::r2_[] =
877 {
878 ]b4_r2[
879 };
880
881 #if YYDEBUG || YYERROR_VERBOSE
882 /* YYTNAME[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM.
883 First, the terminals, then, starting at NTOKENS_, nonterminals. */
884 const char*
885 const yy::]b4_parser_class_name[::name_[] =
886 {
887 ]b4_tname[
888 };
889 #endif
890
891 #if YYDEBUG
892 /* YYRHS -- A `-1'-separated list of the rules' RHS. */
893 const yy::]b4_parser_class_name[::RhsNumberType
894 yy::]b4_parser_class_name[::rhs_[] =
895 {
896 ]b4_rhs[
897 };
898
899 /* YYPRHS[YYN] -- Index of the first RHS symbol of rule number YYN in
900 YYRHS. */
901 const ]b4_int_type_for([b4_prhs])[
902 yy::]b4_parser_class_name[::prhs_[] =
903 {
904 ]b4_prhs[
905 };
906
907 /* YYRLINE[YYN] -- source line where rule number YYN was defined. */
908 const ]b4_int_type_for([b4_rline])[
909 yy::]b4_parser_class_name[::rline_[] =
910 {
911 ]b4_rline[
912 };
913
914 /** Print the state stack from its BOTTOM up to its TOP (included). */
915
916 void
917 yy::]b4_parser_class_name[::stack_print_ ()
918 {
919 *yycdebug_ << "Stack now";
920 for (StateStack::const_iterator i = state_stack_.begin ();
921 i != state_stack_.end (); ++i)
922 *yycdebug_ << ' ' << *i;
923 *yycdebug_ << std::endl;
924 }
925
926 /** Report that the YYRULE is going to be reduced. */
927
928 void
929 yy::]b4_parser_class_name[::reduce_print_ (int yyrule)
930 {
931 unsigned int yylno = rline_[yyrule];
932 /* Print the symbols being reduced, and their result. */
933 *yycdebug_ << "Reducing stack by rule " << n_ - 1
934 << " (line " << yylno << "), ";
935 for (]b4_int_type_for([b4_prhs])[ i = prhs_[n_];
936 0 <= rhs_[i]; ++i)
937 *yycdebug_ << name_[rhs_[i]] << ' ';
938 *yycdebug_ << "-> " << name_[r1_[n_]] << std::endl;
939 }
940 #endif // YYDEBUG
941
942 /* YYTRANSLATE(YYLEX) -- Bison symbol number corresponding to YYLEX. */
943 yy::]b4_parser_class_name[::TokenNumberType
944 yy::]b4_parser_class_name[::translate_ (int token)
945 {
946 static
947 const TokenNumberType
948 translate_table[] =
949 {
950 ]b4_translate[
951 };
952 if ((unsigned int) token <= user_token_number_max_)
953 return translate_table[token];
954 else
955 return undef_token_;
956 }
957
958 const int yy::]b4_parser_class_name[::eof_ = 0;
959 const int yy::]b4_parser_class_name[::last_ = ]b4_last[;
960 const int yy::]b4_parser_class_name[::nnts_ = ]b4_nterms_number[;
961 const int yy::]b4_parser_class_name[::empty_ = -2;
962 const int yy::]b4_parser_class_name[::final_ = ]b4_final_state_number[;
963 const int yy::]b4_parser_class_name[::terror_ = 1;
964 const int yy::]b4_parser_class_name[::errcode_ = 256;
965 const int yy::]b4_parser_class_name[::ntokens_ = ]b4_tokens_number[;
966
967 const unsigned int yy::]b4_parser_class_name[::user_token_number_max_ = ]b4_user_token_number_max[;
968 const yy::]b4_parser_class_name[::TokenNumberType yy::]b4_parser_class_name[::undef_token_ = ]b4_undef_token_number[;
969
970 ]b4_epilogue
971 dnl
972 @output stack.hh
973 b4_copyright([Stack handling for Bison C++ parsers], [2002, 2003, 2004])[
974
975 #ifndef BISON_STACK_HH
976 # define BISON_STACK_HH
977
978 #include <deque>
979
980 namespace yy
981 {
982 template <class T, class S = std::deque<T> >
983 class Stack
984 {
985 public:
986
987 // Hide our reversed order.
988 typedef typename S::reverse_iterator iterator;
989 typedef typename S::const_reverse_iterator const_iterator;
990
991 Stack () : seq_ ()
992 {
993 }
994
995 Stack (unsigned int n) : seq_ (n)
996 {
997 }
998
999 inline
1000 T&
1001 operator [] (unsigned int i)
1002 {
1003 return seq_[i];
1004 }
1005
1006 inline
1007 const T&
1008 operator [] (unsigned int i) const
1009 {
1010 return seq_[i];
1011 }
1012
1013 inline
1014 void
1015 push (const T& t)
1016 {
1017 seq_.push_front (t);
1018 }
1019
1020 inline
1021 void
1022 pop (unsigned int n = 1)
1023 {
1024 for (; n; --n)
1025 seq_.pop_front ();
1026 }
1027
1028 inline
1029 unsigned int
1030 height () const
1031 {
1032 return seq_.size ();
1033 }
1034
1035 inline const_iterator begin () const { return seq_.rbegin (); }
1036 inline const_iterator end () const { return seq_.rend (); }
1037
1038 private:
1039
1040 S seq_;
1041 };
1042
1043 template <class T, class S = Stack<T> >
1044 class Slice
1045 {
1046 public:
1047
1048 Slice (const S& stack,
1049 unsigned int range) : stack_ (stack),
1050 range_ (range)
1051 {
1052 }
1053
1054 inline
1055 const T&
1056 operator [] (unsigned int i) const
1057 {
1058 return stack_[range_ - i];
1059 }
1060
1061 private:
1062
1063 const S& stack_;
1064 unsigned int range_;
1065 };
1066 }
1067
1068 #endif // not BISON_STACK_HH]
1069 dnl
1070 @output position.hh
1071 b4_copyright([Position class for Bison C++ parsers], [2002, 2003, 2004])[
1072
1073 /**
1074 ** \file position.hh
1075 ** Define the Location class.
1076 */
1077
1078 #ifndef BISON_POSITION_HH
1079 # define BISON_POSITION_HH
1080
1081 # include <iostream>
1082 # include <string>
1083
1084 namespace yy
1085 {
1086 /** \brief Abstract a Position. */
1087 class Position
1088 {
1089 public:
1090 /** \brief Initial column number. */
1091 static const unsigned int initial_column = 0;
1092 /** \brief Initial line number. */
1093 static const unsigned int initial_line = 1;
1094
1095 /** \name Ctor & dtor.
1096 ** \{ */
1097 public:
1098 /** \brief Construct a Position. */
1099 Position () :
1100 filename (),
1101 line (initial_line),
1102 column (initial_column)
1103 {
1104 }
1105 /** \} */
1106
1107
1108 /** \name Line and Column related manipulators
1109 ** \{ */
1110 public:
1111 /** \brief (line related) Advance to the COUNT next lines. */
1112 inline void lines (int count = 1)
1113 {
1114 column = initial_column;
1115 line += count;
1116 }
1117
1118 /** \brief (column related) Advance to the COUNT next columns. */
1119 inline void columns (int count = 1)
1120 {
1121 int leftmost = initial_column;
1122 int current = column;
1123 if (leftmost <= current + count)
1124 column += count;
1125 else
1126 column = initial_column;
1127 }
1128 /** \} */
1129
1130 public:
1131 /** \brief File name to which this position refers. */
1132 std::string filename;
1133 /** \brief Current line number. */
1134 unsigned int line;
1135 /** \brief Current column number. */
1136 unsigned int column;
1137 };
1138
1139 /** \brief Add and assign a Position. */
1140 inline const Position&
1141 operator+= (Position& res, const int width)
1142 {
1143 res.columns (width);
1144 return res;
1145 }
1146
1147 /** \brief Add two Position objects. */
1148 inline const Position
1149 operator+ (const Position& begin, const int width)
1150 {
1151 Position res = begin;
1152 return res += width;
1153 }
1154
1155 /** \brief Add and assign a Position. */
1156 inline const Position&
1157 operator-= (Position& res, const int width)
1158 {
1159 return res += -width;
1160 }
1161
1162 /** \brief Add two Position objects. */
1163 inline const Position
1164 operator- (const Position& begin, const int width)
1165 {
1166 return begin + -width;
1167 }
1168
1169 /** \brief Intercept output stream redirection.
1170 ** \param ostr the destination output stream
1171 ** \param pos a reference to the Position to redirect
1172 */
1173 inline std::ostream&
1174 operator<< (std::ostream& ostr, const Position& pos)
1175 {
1176 if (!pos.filename.empty ())
1177 ostr << pos.filename << ':';
1178 return ostr << pos.line << '.' << pos.column;
1179 }
1180
1181 }
1182 #endif // not BISON_POSITION_HH]
1183 @output location.hh
1184 b4_copyright([Location class for Bison C++ parsers], [2002, 2003, 2004])[
1185
1186 /**
1187 ** \file location.hh
1188 ** Define the Location class.
1189 */
1190
1191 #ifndef BISON_LOCATION_HH
1192 # define BISON_LOCATION_HH
1193
1194 # include <iostream>
1195 # include <string>
1196 # include "position.hh"
1197
1198 namespace yy
1199 {
1200
1201 /** \brief Abstract a Location. */
1202 class Location
1203 {
1204 /** \name Ctor & dtor.
1205 ** \{ */
1206 public:
1207 /** \brief Construct a Location. */
1208 Location (void) :
1209 begin (),
1210 end ()
1211 {
1212 }
1213 /** \} */
1214
1215
1216 /** \name Line and Column related manipulators
1217 ** \{ */
1218 public:
1219 /** \brief Reset initial location to final location. */
1220 inline void step (void)
1221 {
1222 begin = end;
1223 }
1224
1225 /** \brief Extend the current location to the COUNT next columns. */
1226 inline void columns (unsigned int count = 1)
1227 {
1228 end += count;
1229 }
1230
1231 /** \brief Extend the current location to the COUNT next lines. */
1232 inline void lines (unsigned int count = 1)
1233 {
1234 end.lines (count);
1235 }
1236 /** \} */
1237
1238
1239 public:
1240 /** \brief Beginning of the located region. */
1241 Position begin;
1242 /** \brief End of the located region. */
1243 Position end;
1244 };
1245
1246 /** \brief Join two Location objects to create a Location. */
1247 inline const Location operator+ (const Location& begin, const Location& end)
1248 {
1249 Location res = begin;
1250 res.end = end.end;
1251 return res;
1252 }
1253
1254 /** \brief Add two Location objects */
1255 inline const Location operator+ (const Location& begin, unsigned int width)
1256 {
1257 Location res = begin;
1258 res.columns (width);
1259 return res;
1260 }
1261
1262 /** \brief Add and assign a Location */
1263 inline Location& operator+= (Location& res, unsigned int width)
1264 {
1265 res.columns (width);
1266 return res;
1267 }
1268
1269 /** \brief Intercept output stream redirection.
1270 ** \param ostr the destination output stream
1271 ** \param loc a reference to the Location to redirect
1272 **
1273 ** Avoid duplicate information.
1274 */
1275 inline std::ostream& operator<< (std::ostream& ostr, const Location& loc)
1276 {
1277 Position last = loc.end - 1;
1278 ostr << loc.begin;
1279 if (loc.begin.filename != last.filename)
1280 ostr << '-' << last;
1281 else if (loc.begin.line != last.line)
1282 ostr << '-' << last.line << '.' << last.column;
1283 else if (loc.begin.column != last.column)
1284 ostr << '-' << last.column;
1285 return ostr;
1286 }
1287
1288 }
1289
1290 #endif // not BISON_LOCATION_HH]