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