ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/lsys/antlr/ATokenBuffer.h
Revision: 1.1
Committed: Thu Nov 6 14:31:25 2008 UTC (15 years, 6 months ago) by root
Content type: text/plain
Branch: MAIN
CVS Tags: HEAD
Log Message:
*** empty log message ***

File Contents

# User Rev Content
1 root 1.1 /* ANTLRTokenBuffer.h
2     *
3     * SOFTWARE RIGHTS
4     *
5     * We reserve no LEGAL rights to the Purdue Compiler Construction Tool
6     * Set (PCCTS) -- PCCTS is in the public domain. An individual or
7     * company may do whatever they wish with source code distributed with
8     * PCCTS or the code generated by PCCTS, including the incorporation of
9     * PCCTS, or its output, into commerical software.
10     *
11     * We encourage users to develop software with PCCTS. However, we do ask
12     * that credit is given to us for developing PCCTS. By "credit",
13     * we mean that if you incorporate our source code into one of your
14     * programs (commercial product, research project, or otherwise) that you
15     * acknowledge this fact somewhere in the documentation, research report,
16     * etc... If you like PCCTS and have developed a nice tool with the
17     * output, please mention that you developed it using PCCTS. In
18     * addition, we ask that this header remain intact in our source code.
19     * As long as these guidelines are kept, we expect to continue enhancing
20     * this system and expect to make other tools available as they are
21     * completed.
22     *
23     * ANTLR 1.33
24     * Terence Parr
25     * Parr Research Corporation
26     * with Purdue University and AHPCRC, University of Minnesota
27     * 1989-2000
28     */
29    
30     #ifndef ATOKENBUFFER_H_GATE
31     #define ATOKENBUFFER_H_GATE
32    
33     #include "pcctscfg.h"
34    
35     #include "pccts_stdlib.h"
36    
37     PCCTS_NAMESPACE_STD
38    
39     #include ATOKEN_H
40     #include ATOKENSTREAM_H
41    
42     /*
43     * The parser is "attached" to an ANTLRTokenBuffer via interface
44     * functions: getToken() and bufferedToken(). The object that actually
45     * consumes characters and constructs tokens is connected to the
46     * ANTLRTokenBuffer via interface function ANTLRTokenStream::getToken();
47     * where ANTLRTokenStream is really just a behavior (class with no data).
48     * C++ does not have this abstraction and hence we simply have come up
49     * with a fancy name for "void *". See the note in ANTLRTokenStream.h on
50     * the "behavior" of ANTLRTokenStream.
51     */
52    
53     class ANTLRParser; // MR1
54    
55     class DllExportPCCTS ANTLRTokenBuffer {
56     protected:
57     ANTLRTokenStream *input; // where do I get tokens
58     int buffer_size;
59     int chunk_size;
60     int num_markers;
61     int k; // Need at least this many tokens in buffer
62     _ANTLRTokenPtr *buffer; // buffer used for arbitrary lookahead
63     _ANTLRTokenPtr *tp; // pts into buffer; current token ptr
64     _ANTLRTokenPtr *last; // pts to last valid token in buffer
65     _ANTLRTokenPtr *next; // place to put token from getANTLRToken()
66     _ANTLRTokenPtr *end_of_buffer;
67     /* when you try to write a token past this and there are no markers
68     set, then move k-1 tokens back to the beginning of the buffer.
69     We want to stay away from the end of the buffer because we have
70     to extend it if a marker is set and we reach the end (we cannot
71     move tokens to the beginning of the buffer in this case).
72     */
73     _ANTLRTokenPtr *threshold;
74     unsigned char _deleteTokens;
75    
76     // This function is filled in by the subclass; it initiates fetch of input
77     virtual _ANTLRTokenPtr getANTLRToken() { return input->getToken(); }
78     void makeRoom();
79     void extendBuffer();
80    
81     public:
82     ANTLRTokenBuffer(ANTLRTokenStream *in, int k=1, int chksz=50);
83     virtual ~ANTLRTokenBuffer();
84     virtual _ANTLRTokenPtr getToken();
85     virtual void rewind(int pos);
86     virtual int mark();
87     virtual _ANTLRTokenPtr bufferedToken(int i);
88    
89     void noGarbageCollectTokens() { _deleteTokens=0; }
90     void garbageCollectTokens() { _deleteTokens=1; }
91    
92     virtual int bufferSize() { return buffer_size; }
93     virtual int minTokens() { return k; }
94     virtual void setMinTokens(int k_new) { k = k_new; }
95    
96     virtual void panic(const char *msg); /* MR20 const */
97    
98     virtual int printMessage(FILE* pFile, const char* pFormat, ...); // MR23
99    
100     protected: // MR1
101     ANTLRParser *parser; // MR1
102     public: // MR1
103     ANTLRParser *setParser(ANTLRParser *p); // MR1
104     ANTLRParser *getParser(); // MR1
105     ANTLRTokenStream *getLexer() const { // MR12
106     return input;} // MR12
107     };
108    
109     #endif