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