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