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