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