Annotation of parser3/src/include/pa_stack.h, revision 1.2
1.1 paf 1: /*
1.2 ! paf 2: $Id: pa_stack.h,v 1.1 2001/02/21 17:36:30 paf Exp $
1.1 paf 3: */
4:
5: #ifndef PA_STACK_H
6: #define PA_STACK_H
7:
8: #include "pa_array.h"
9:
10: class Stack : public Array {
11: public:
12:
1.2 ! paf 13: Stack(Pool& apool) : Array(apool), ftop(0) {
1.1 paf 14: }
15:
16: void push(Item *item) {
1.2 ! paf 17: if(ftop<size()) // cell is already allocated?
! 18: put(ftop, item); // use it
1.1 paf 19: else
20: *this+=item; // append it
1.2 ! paf 21: ftop++;
1.1 paf 22: }
23: Item *pop() {
1.2 ! paf 24: return get(--ftop);
1.1 paf 25: }
26:
27: Item *operator [] (int top_offset) {
1.2 ! paf 28: return get(ftop-top_offset-1);
1.1 paf 29: }
30:
1.2 ! paf 31: int top() { return ftop; }
! 32:
1.1 paf 33: private:
34:
35: // deepest used index
1.2 ! paf 36: int ftop;
1.1 paf 37:
38: };
39:
40: #endif
E-mail: