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