]> git.saurik.com Git - bison.git/blob - data/bison.c++
* src/conflicts.c (log_resolution): Argument `resolution' is const.
[bison.git] / data / bison.c++
1 m4_divert(-1)
2
3 # b4_token_defines(TOKEN-NAME, TOKEN-NUMBER)
4 # ------------------------------------------
5 # Output the definition of this token as #define.
6 m4_define([b4_token_define],
7 [#define $1 $2
8 ])
9
10
11 # b4_token_defines(LIST-OF-PAIRS-TOKEN-NAME-TOKEN-NUMBER)
12 # -------------------------------------------------------
13 # Output the definition of the tokens as #define.
14 m4_define([b4_token_defines],
15 [m4_map([b4_token_define], [$@])])
16
17 m4_define_default([b4_input_suffix], [.y])
18
19 m4_define_default([b4_output_parser_suffix],
20 [m4_translit(b4_input_suffix, [yY], [cC])])
21
22 m4_define_default([b4_output_parser_name],
23 [b4_output_prefix[]b4_output_infix[]b4_output_parser_suffix[]])
24
25
26 m4_define_default([b4_output_header_suffix],
27 [m4_translit(b4_input_suffix, [yY], [hH])])
28
29 m4_define_default([b4_output_header_name],
30 [b4_output_prefix[]b4_output_infix[]b4_output_header_suffix[]])
31
32 m4_define_default([b4_header_guard],
33 [m4_bpatsubst(m4_toupper([BISON_]b4_output_header_name),
34 [[^ABCDEFGHIJKLMNOPQRSTUVWXYZ]], [_])])
35
36 m4_define([b4_inherit],
37 [m4_ifdef([b4_root],
38 [: public b4_root
39 ],
40 [])])
41
42 m4_define([b4_param],
43 [m4_ifdef([b4_root],
44 [,
45 const Param& param],
46 [])])
47
48 m4_define([b4_constructor],
49 [m4_ifdef([b4_root],
50 [b4_root (param),
51 ],
52 [])])
53
54 m4_define([b4_copyright],
55 [/* -*- C++ -*- */
56 /* A Bison parser, made from b4_filename,
57 by GNU bison b4_version. */
58
59 /* Skeleton output parser for bison,
60 Copyright 2002 Free Software Foundation, Inc.
61
62 This program is free software; you can redistribute it and/or modify
63 it under the terms of the GNU General Public License as published by
64 the Free Software Foundation; either version 2, or (at your option)
65 any later version.
66
67 This program is distributed in the hope that it will be useful,
68 but WITHOUT ANY WARRANTY; without even the implied warranty of
69 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
70 GNU General Public License for more details.
71
72 You should have received a copy of the GNU General Public License
73 along with this program; if not, write to the Free Software
74 Foundation, Inc., 59 Temple Place - Suite 330,
75 Boston, MA 02111-1307, USA. */
76
77 /* As a special exception, when this file is copied by Bison into a
78 Bison output file, you may use that output file without restriction.
79 This special exception was added by the Free Software Foundation
80 in version 1.24 of Bison. */])
81
82 m4_divert(0)dnl
83 #output "b4_output_header_name"
84 b4_copyright
85 #ifndef b4_header_guard
86 # define b4_header_guard
87
88 #include "stack.hh"
89 #include "location.hh"
90
91 #include <string>
92
93 /* Using locations. */
94 #define YYLSP_NEEDED b4_locations_flag
95
96 b4_prologue
97
98 /* Tokens. */
99 b4_token_defines(b4_tokens)
100
101 /* Enabling traces. */
102 #ifndef YYDEBUG
103 # define YYDEBUG b4_debug
104 #endif
105
106 /* Enabling verbose error message. */
107 #ifndef YYERROR_VERBOSE
108 # define YYERROR_VERBOSE b4_error_verbose
109 #endif
110
111 #ifndef YYSTYPE
112 m4_ifdef([b4_stype_line],
113 [#line b4_stype_line "b4_filename"
114 ])dnl
115 typedef b4_stype
116 yystype;
117 # define YYSTYPE yystype
118 #endif
119
120 #ifndef YYLLOC_DEFAULT
121 # define YYLLOC_DEFAULT(Current, Rhs, N) \
122 Current.last_line = Rhs[[N]].last_line; \
123 Current.last_column = Rhs[[N]].last_column;
124 #endif
125
126 m4_if(b4_locations_flag, [0], [],
127 [#ifndef YYLTYPE
128 typedef struct yyltype
129 {
130 int first_line;
131 int first_column;
132 int last_line;
133 int last_column;
134 } yyltype;
135 # define YYLTYPE yyltype
136 #endif])
137
138 namespace yy
139 {
140 class b4_name;
141
142 template < typename P >
143 struct Traits
144 {
145 };
146
147 template < >
148 struct Traits< b4_name >
149 {
150 typedef int StateType;
151 typedef yystype SemanticType;
152 typedef b4_ltype LocationType;
153 };
154 }
155
156 namespace yy
157 {
158 class b4_name b4_inherit
159 {
160 public:
161
162 typedef Traits< b4_name >::StateType StateType;
163 typedef Traits< b4_name >::SemanticType SemanticType;
164 typedef Traits< b4_name >::LocationType LocationType;
165
166 typedef Stack< StateType > StateStack;
167 typedef Stack< SemanticType > SemanticStack;
168 typedef Stack< LocationType > LocationStack;
169
170 #if YYLSP_NEEDED
171 b4_name (bool debug,
172 LocationType initlocation[]b4_param) :
173 b4_constructor[]debug_ (debug),
174 initlocation_ (initlocation)
175 #else
176 b4_name (bool debug[]b4_param) :
177 b4_constructor[]debug_ (debug)
178 #endif
179 {
180 }
181
182 virtual ~b4_name ()
183 {
184 }
185
186 virtual int parse ();
187
188 private:
189
190 virtual void lex_ ();
191 virtual void error_ ();
192 virtual void print_ ();
193
194 /* Stacks. */
195 StateStack state_stack_;
196 SemanticStack semantic_stack_;
197 LocationStack location_stack_;
198
199 /* Tables. */
200 static const short pact_[[]];
201 static const short defact_[[]];
202 static const short pgoto_[[]];
203 static const short defgoto_[[]];
204 static const short table_[[]];
205 static const short check_[[]];
206 static const short r1_[[]];
207 static const short r2_[[]];
208
209 #if YYDEBUG || YYERROR_VERBOSE
210 static const char* const name_[[]];
211 #endif
212
213 /* More tables, for debugging. */
214 #if YYDEBUG
215 static const short rhs_[[]];
216 static const short prhs_[[]];
217 static const short rline_[[]];
218 #endif
219
220 /* Even more tables. */
221 static inline char translate_ (int token);
222
223 /* Constants. */
224 static const int eof_;
225 static const int last_;
226 static const int flag_;
227 static const int nnts_;
228 static const int nsym_;
229 static const int empty_;
230 static const int final_;
231 static const int terror_;
232 static const int errcode_;
233 static const int ntokens_;
234 static const int initdepth_;
235 static const unsigned maxtok_;
236
237 /* State. */
238 int n_;
239 int len_;
240 int debug_;
241 int state_;
242
243 /* Lookahead and lookahead in internal form. */
244 int looka_;
245 int ilooka_;
246
247 /* Message. */
248 std::string message;
249
250 /* Semantic value and location of lookahead token. */
251 SemanticType value;
252 LocationType location;
253
254 /* @$ and $$. */
255 SemanticType yyval;
256 LocationType yyloc;
257
258 /* Initial location. */
259 LocationType initlocation_;
260 };
261 }
262
263 #endif /* not b4_header_guard */
264
265 #output "b4_output_prefix[]b4_output_infix[].cc"
266 b4_copyright
267
268 #include "b4_output_header_name"
269
270 /* Enable debugging if requested. */
271 #if YYDEBUG
272 # include <cstdio>
273 # define YYFPRINTF std::fprintf
274 # define YYDPRINTF(Args) \
275 do { \
276 if (debug_) \
277 YYFPRINTF Args; \
278 } while (0)
279 #else /* !YYDEBUG */
280 # define YYDPRINTF(Args)
281 #endif /* !YYDEBUG */
282
283 int
284 yy::b4_name::parse ()
285 {
286 int nerrs = 0;
287 int errstatus = 0;
288
289 /* Initialize stack. */
290 state_stack_ = StateStack (0);
291 semantic_stack_ = SemanticStack (1);
292 location_stack_ = LocationStack (1);
293
294 /* Reserve initial space. The C parser needed that, but is it really
295 useful here? */
296 state_stack_.reserve (initdepth_);
297 semantic_stack_.reserve (initdepth_);
298 location_stack_.reserve (initdepth_);
299
300 /* Start. */
301 state_ = 0;
302 looka_ = empty_;
303 #if YYLSP_NEEDED
304 location = initlocation_;
305 #endif
306 YYDPRINTF ((stderr, "Starting parse\n"));
307
308 /* New state. */
309 yynewstate:
310 state_stack_.push (state_);
311 YYDPRINTF ((stderr, "Entering state %d\n", state_));
312 goto yybackup;
313
314 /* Backup. */
315 yybackup:
316
317 /* Try to take a decision without lookahead. */
318 n_ = pact_[[state_]];
319 if (n_ == flag_)
320 goto yydefault;
321
322 /* Read a lookahead token. */
323 if (looka_ == empty_)
324 {
325 YYDPRINTF ((stderr, "Reading a token: "));
326 lex_ ();
327 }
328
329 /* Convert token to internal form. */
330 if (looka_ <= 0)
331 {
332 looka_ = eof_;
333 ilooka_ = 0;
334 YYDPRINTF ((stderr, "Now at end of input.\n"));
335 }
336 else
337 {
338 ilooka_ = translate_ (looka_);
339 #if YYDEBUG
340 if (debug_)
341 {
342 YYFPRINTF (stderr, "Next token is %d (%s", looka_, name_[[ilooka_]]);
343 print_ ();
344 YYFPRINTF (stderr, ")\n");
345 }
346 #endif
347 }
348
349 n_ += ilooka_;
350 if (n_ < 0 || n_ > last_ || check_[[n_]] != ilooka_)
351 goto yydefault;
352
353 /* Reduce or error. */
354 n_ = table_[[n_]];
355 if (n_ < 0)
356 {
357 if (n_ == flag_)
358 goto yyerrlab;
359 else
360 {
361 n_ = -n_;
362 goto yyreduce;
363 }
364 }
365 else if (n_ == 0)
366 goto yyerrlab;
367
368 /* Accept? */
369 if (n_ == final_)
370 goto yyacceptlab;
371
372 /* Shift the lookahead token. */
373 YYDPRINTF ((stderr, "Shifting token %d (%s), ", looka_, name_[[ilooka_]]));
374
375 /* Discard the token being shifted unless it is eof. */
376 if (looka_ != eof_)
377 looka_ = empty_;
378
379 semantic_stack_.push (value);
380 location_stack_.push (location);
381
382 /* Count tokens shifted since error; after three, turn off error
383 status. */
384 if (errstatus)
385 --errstatus;
386
387 state_ = n_;
388 goto yynewstate;
389
390 /* Default action. */
391 yydefault:
392 n_ = defact_[[state_]];
393 if (n_ == 0)
394 goto yyerrlab;
395 goto yyreduce;
396
397 /* Reduce. */
398 yyreduce:
399 len_ = r2_[[n_]];
400 if (len_)
401 {
402 yyval = semantic_stack_[[1 - len_]];
403 yyloc = location_stack_[[1 - len_]];
404 }
405 else
406 {
407 yyval = semantic_stack_[[0]];
408 yyloc = location_stack_[[0]];
409 }
410
411 #if YYDEBUG
412 if (debug_)
413 {
414 YYFPRINTF (stderr, "Reducing via rule %d (line %d), ", n_ - 1, rline_[[n_]]);
415 for (unsigned i = prhs_[[n_]];
416 rhs_[[i]] >= 0; ++i)
417 YYFPRINTF (stderr, "%s ", name_[[rhs_[i]]]);
418 YYFPRINTF (stderr, "-> %s\n", name_[[r1_[n_]]]);
419 }
420 #endif
421
422 if (len_)
423 {
424 Slice< LocationType, LocationStack > slice (location_stack_, len_);
425 YYLLOC_DEFAULT (yyloc, slice, len_);
426 }
427
428 {
429 SemanticStack& yyvsp (semantic_stack_);
430 LocationStack& yylsp (location_stack_);
431
432 switch (n_)
433 {
434 b4_actions
435 }
436 }
437
438 state_stack_.pop (len_);
439 semantic_stack_.pop (len_);
440 location_stack_.pop (len_);
441
442 #if YYDEBUG
443 if (debug_)
444 {
445 YYFPRINTF (stderr, "state stack now");
446 for (StateStack::ConstIterator i = state_stack_.begin ();
447 i != state_stack_.end (); ++i)
448 YYFPRINTF (stderr, " %d", *i);
449 YYFPRINTF (stderr, "\n");
450 }
451 #endif
452
453 semantic_stack_.push (yyval);
454 location_stack_.push (yyloc);
455
456 /* Shift the result of the reduction. */
457 n_ = r1_[[n_]];
458 state_ = pgoto_[[n_ - ntokens_]] + state_stack_[[0]];
459 if (state_ >= 0 && state_ <= last_ && check_[[state_]] == state_stack_[[0]])
460 state_ = table_[[state_]];
461 else
462 state_ = defgoto_[[n_ - ntokens_]];
463 goto yynewstate;
464
465 /* Report and recover from errors. This is very incomplete. */
466 yyerrlab:
467 /* If not already recovering from an error, report this error. */
468 if (!errstatus)
469 {
470 ++nerrs;
471
472 #if YYERROR_VERBOSE
473 n_ = pact_[[state_]];
474 if (n_ > flag_ && n_ < last_)
475 {
476 message = "parse error, unexpected ";
477 message += name_[[ilooka_]];
478 {
479 int count = 0;
480 for (int x = (n_ < 0 ? -n_ : 0); x < ntokens_ + nnts_; ++x)
481 if (check_[[x + n_]] == x)
482 ++count;
483 if (count < 5)
484 {
485 count = 0;
486 for (int x = (n_ < 0 ? -n_ : 0); x < ntokens_ + nnts_; ++x)
487 if (check_[[x + n_]] == x)
488 {
489 message += (!count++) ? ", expecting " : " or ";
490 message += name_[[x]];
491 }
492 }
493 }
494 }
495 else
496 #endif
497 message = "parse error";
498 error_ ();
499 }
500 goto yyerrlab1;
501
502 /* Error raised explicitly by an action. */
503 yyerrlab1:
504 if (errstatus == 3)
505 {
506 /* If just tried and failed to reuse lookahead token after an
507 error, discard it. */
508
509 /* Return failure if at end of input. */
510 if (looka_ == eof_)
511 goto yyabortlab;
512 YYDPRINTF ((stderr, "Discarding token %d (%s).\n", looka_, name_[[ilooka_]]));
513 looka_ = empty_;
514 }
515
516 /* Else will try to reuse lookahead token after shifting the error
517 token. */
518
519 errstatus = 3;
520 goto yyerrhandle;
521
522 /* Pop the current state because it cannot handle the error token. */
523 yyerrdefault:
524 yyerrpop:
525 if (!state_stack_.height ())
526 goto yyabortlab;
527 state_ = (state_stack_.pop (), state_stack_[[0]]);
528 semantic_stack_.pop ();
529 location_stack_.pop ();;
530
531 #if YYDEBUG
532 if (debug_)
533 {
534 YYFPRINTF (stderr, "Error: state stack now");
535 for (StateStack::ConstIterator i = state_stack_.begin ();
536 i != state_stack_.end (); ++i)
537 YYFPRINTF (stderr, " %d", *i);
538 YYFPRINTF (stderr, "\n");
539 }
540 #endif
541
542 yyerrhandle:
543 n_ = pact_[[state_]];
544 if (n_ == flag_)
545 goto yyerrdefault;
546
547 n_ += terror_;
548 if (n_ < 0 || n_ > last_ || check_[[n_]] != terror_)
549 goto yyerrdefault;
550
551 n_ = table_[[n_]];
552 if (n_ < 0)
553 {
554 if (n_ == flag_)
555 goto yyerrpop;
556 n_ = -n_;
557 goto yyreduce;
558 }
559 else if (!n_)
560 goto yyerrpop;
561
562 if (n_ == final_)
563 goto yyacceptlab;
564
565 YYDPRINTF ((stderr, "Shifting error token, "));
566
567 semantic_stack_.push (value);
568 location_stack_.push (location);
569
570 state_ = n_;
571 goto yynewstate;
572
573 /* Accept. */
574 yyacceptlab:
575 return 0;
576
577 /* Abort. */
578 yyabortlab:
579 return 1;
580 }
581
582 void
583 yy::b4_name::lex_ ()
584 {
585 #if YYLSP_NEEDED
586 looka_ = yylex (&value, &location);
587 #else
588 looka_ = yylex (&value);
589 #endif
590 }
591
592 /* YYPACT[[STATE-NUM]] -- Index in YYTABLE of the portion describing
593 STATE-NUM. */
594 const short
595 yy::b4_name::pact_[[]] =
596 {
597 b4_pact
598 };
599
600 /* YYDEFACT[[S]] -- default rule to reduce with in state S when YYTABLE
601 doesn't specify something else to do. Zero means the default is an
602 error. */
603 const short
604 yy::b4_name::defact_[[]] =
605 {
606 b4_defact
607 };
608
609 /* YYPGOTO[[NTERM-NUM]]. */
610 const short
611 yy::b4_name::pgoto_[[]] =
612 {
613 b4_pgoto
614 };
615
616 /* YYDEFGOTO[[NTERM-NUM]]. */
617 const short
618 yy::b4_name::defgoto_[[]] =
619 {
620 b4_defgoto
621 };
622
623 /* YYTABLE[[YYPACT[STATE-NUM]]]. What to do in state STATE-NUM. If
624 positive, shift that token. If negative, reduce the rule which
625 number is the opposite. If zero, do what YYDEFACT says. */
626 const short
627 yy::b4_name::table_[[]] =
628 {
629 b4_table
630 };
631
632 /* YYCHECK. */
633 const short
634 yy::b4_name::check_[[]] =
635 {
636 b4_check
637 };
638
639 /* YYR1[[YYN]] -- Symbol number of symbol that rule YYN derives. */
640 const short
641 yy::b4_name::r1_[[]] =
642 {
643 b4_r1
644 };
645
646 /* YYR2[[YYN]] -- Number of symbols composing right hand side of rule YYN. */
647 const short
648 yy::b4_name::r2_[[]] =
649 {
650 b4_r2
651 };
652
653 #if YYDEBUG || YYERROR_VERBOSE
654 /* YYTNAME[[SYMBOL-NUM]] -- String name of the symbol SYMBOL-NUM.
655 First, the terminals, then, starting at YYNTOKENS, nonterminals. */
656 const char*
657 const yy::b4_name::name_[[]] =
658 {
659 b4_tname
660 };
661 #endif
662
663 #if YYDEBUG
664 /* YYRHS -- A `-1'-separated list of the rules' RHS. */
665 const short
666 yy::b4_name::rhs_[[]] =
667 {
668 b4_rhs
669 };
670
671 /* YYPRHS[[YYN]] -- Index of the first RHS symbol of rule number YYN in
672 YYRHS. */
673 const short
674 yy::b4_name::prhs_[[]] =
675 {
676 b4_prhs
677 };
678
679 /* YYRLINE[[YYN]] -- source line where rule number YYN was defined. */
680 const short
681 yy::b4_name::rline_[[]] =
682 {
683 b4_rline
684 };
685 #endif
686
687 /* YYTRANSLATE(YYLEX) -- Bison symbol number corresponding to YYLEX. */
688 char
689 yy::b4_name::translate_ (int token)
690 {
691 static
692 const char
693 translate_[[]] =
694 {
695 b4_translate
696 };
697 return ((unsigned)(token) <= maxtok_ ? translate_[[token]] : nsym_);
698 }
699
700 const int yy::b4_name::eof_ = 0;
701 const int yy::b4_name::last_ = b4_last;
702 const int yy::b4_name::flag_ = b4_flag;
703 const int yy::b4_name::nnts_ = b4_nnts;
704 const int yy::b4_name::nsym_ = b4_nsym;
705 const int yy::b4_name::empty_ = -2;
706 const int yy::b4_name::final_ = b4_final;
707 const int yy::b4_name::terror_ = 1;
708 const int yy::b4_name::errcode_ = 256;
709 const int yy::b4_name::ntokens_ = b4_ntokens;
710 const int yy::b4_name::initdepth_ = b4_initdepth;
711
712 const unsigned yy::b4_name::maxtok_ = b4_maxtok;
713
714 b4_epilogue
715
716 #output "stack.hh"
717 b4_copyright
718
719 #ifndef BISON_STACK_HH
720 # define BISON_STACK_HH
721
722 #include <vector>
723
724 namespace yy
725 {
726 template < class T, class S = std::vector< T > >
727 class Stack
728 {
729 public:
730
731 typedef typename S::iterator Iterator;
732 typedef typename S::const_iterator ConstIterator;
733
734 Stack () : seq_ ()
735 {
736 }
737
738 Stack (unsigned n) : seq_ (n)
739 {
740 }
741
742 inline
743 T&
744 operator [[]] (int index)
745 {
746 return seq_[[height () - 1 + index]];
747 }
748
749 inline
750 const T&
751 operator [[]] (int index) const
752 {
753 return seq_[[height () - 1 + index]];
754 }
755
756 inline
757 void
758 push (const T& t)
759 {
760 seq_.push_back (t);
761 }
762
763 inline
764 void
765 pop (unsigned n = 1)
766 {
767 for (; n; --n)
768 seq_.pop_back ();
769 }
770
771 inline
772 void
773 reserve (unsigned n)
774 {
775 seq_.reserve (n);
776 }
777
778 inline
779 unsigned
780 height () const
781 {
782 return seq_.size ();
783 }
784
785 inline ConstIterator begin () const { return seq_.begin (); }
786 inline ConstIterator end () const { return seq_.end (); }
787
788 private:
789
790 S seq_;
791 };
792
793 template < class T, class S = Stack< T > >
794 class Slice
795 {
796 public:
797
798 Slice (const S& stack,
799 unsigned range) : stack_ (stack),
800 range_ (range)
801 {
802 }
803
804 inline
805 const T&
806 operator [[]] (unsigned index) const
807 {
808 return stack_[[index - range_]];
809 }
810
811 private:
812
813 const S& stack_;
814 unsigned range_;
815 };
816 }
817
818 #endif // not BISON_STACK_HH
819
820 #output "location.hh"
821 b4_copyright
822
823 #ifndef BISON_LOCATION_HH
824 # define BISON_LOCATION_HH
825
826 namespace yy
827 {
828 struct Position
829 {
830 int line;
831 int column;
832 };
833
834 struct Location
835 {
836 Position first;
837 Position last;
838 };
839 }
840
841 #endif // not BISON_LOCATION_HH