Mercurial > hg > Members > nobuyasu > myCompiler
comparison Bison-Flex/BasicCompiler-StackBase/stack.hh @ 1:a3ea4c73696b
move files
author | nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp> |
---|---|
date | Tue, 10 May 2011 06:26:08 +0900 |
parents | Bison-Flex/EUC/stack.hh@3f4ade70b4d2 |
children |
comparison
equal
deleted
inserted
replaced
0:3f4ade70b4d2 | 1:a3ea4c73696b |
---|---|
1 /* A Bison parser, made by GNU Bison 2.3. */ | |
2 | |
3 /* Stack handling for Bison parsers in C++ | |
4 | |
5 Copyright (C) 2002, 2003, 2004, 2005, 2006 Free Software Foundation, Inc. | |
6 | |
7 This program is free software; you can redistribute it and/or modify | |
8 it under the terms of the GNU General Public License as published by | |
9 the Free Software Foundation; either version 2, or (at your option) | |
10 any later version. | |
11 | |
12 This program is distributed in the hope that it will be useful, | |
13 but WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
15 GNU General Public License for more details. | |
16 | |
17 You should have received a copy of the GNU General Public License | |
18 along with this program; if not, write to the Free Software | |
19 Foundation, Inc., 51 Franklin Street, Fifth Floor, | |
20 Boston, MA 02110-1301, USA. */ | |
21 | |
22 /* As a special exception, you may create a larger work that contains | |
23 part or all of the Bison parser skeleton and distribute that work | |
24 under terms of your choice, so long as that work isn't itself a | |
25 parser generator using the skeleton or a modified version thereof | |
26 as a parser skeleton. Alternatively, if you modify or redistribute | |
27 the parser skeleton itself, you may (at your option) remove this | |
28 special exception, which will cause the skeleton and the resulting | |
29 Bison output files to be licensed under the GNU General Public | |
30 License without this special exception. | |
31 | |
32 This special exception was added by the Free Software Foundation in | |
33 version 2.2 of Bison. */ | |
34 | |
35 #ifndef BISON_STACK_HH | |
36 # define BISON_STACK_HH | |
37 | |
38 #include <deque> | |
39 | |
40 namespace yy | |
41 { | |
42 template <class T, class S = std::deque<T> > | |
43 class stack | |
44 { | |
45 public: | |
46 | |
47 // Hide our reversed order. | |
48 typedef typename S::reverse_iterator iterator; | |
49 typedef typename S::const_reverse_iterator const_iterator; | |
50 | |
51 stack () : seq_ () | |
52 { | |
53 } | |
54 | |
55 stack (unsigned int n) : seq_ (n) | |
56 { | |
57 } | |
58 | |
59 inline | |
60 T& | |
61 operator [] (unsigned int i) | |
62 { | |
63 return seq_[i]; | |
64 } | |
65 | |
66 inline | |
67 const T& | |
68 operator [] (unsigned int i) const | |
69 { | |
70 return seq_[i]; | |
71 } | |
72 | |
73 inline | |
74 void | |
75 push (const T& t) | |
76 { | |
77 seq_.push_front (t); | |
78 } | |
79 | |
80 inline | |
81 void | |
82 pop (unsigned int n = 1) | |
83 { | |
84 for (; n; --n) | |
85 seq_.pop_front (); | |
86 } | |
87 | |
88 inline | |
89 unsigned int | |
90 height () const | |
91 { | |
92 return seq_.size (); | |
93 } | |
94 | |
95 inline const_iterator begin () const { return seq_.rbegin (); } | |
96 inline const_iterator end () const { return seq_.rend (); } | |
97 | |
98 private: | |
99 | |
100 S seq_; | |
101 }; | |
102 | |
103 /// Present a slice of the top of a stack. | |
104 template <class T, class S = stack<T> > | |
105 class slice | |
106 { | |
107 public: | |
108 | |
109 slice (const S& stack, | |
110 unsigned int range) : stack_ (stack), | |
111 range_ (range) | |
112 { | |
113 } | |
114 | |
115 inline | |
116 const T& | |
117 operator [] (unsigned int i) const | |
118 { | |
119 return stack_[range_ - i]; | |
120 } | |
121 | |
122 private: | |
123 | |
124 const S& stack_; | |
125 unsigned int range_; | |
126 }; | |
127 } | |
128 | |
129 #endif // not BISON_STACK_HH |