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