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