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