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