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