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