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