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.
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
25 * Parr Research Corporation
26 * with Purdue University and AHPCRC, University of Minnesota
30 #ifndef ATOKENBUFFER_H_GATE
31 #define ATOKENBUFFER_H_GATE
35 #include ATOKENSTREAM_H
39 * The parser is "attached" to an ANTLRTokenBuffer via interface
40 * functions: getToken() and bufferedToken(). The object that actually
41 * consumes characters and constructs tokens is connected to the
42 * ANTLRTokenBuffer via interface function ANTLRTokenStream::getToken();
43 * where ANTLRTokenStream is really just a behavior (class with no data).
44 * C++ does not have this abstraction and hence we simply have come up
45 * with a fancy name for "void *". See the note in ANTLRTokenStream.h on
46 * the "behavior" of ANTLRTokenStream.
49 class ANTLRTokenBuffer {
51 ANTLRTokenStream *input; // where do I get tokens
55 int k; // Need at least this many tokens in buffer
56 _ANTLRTokenPtr *buffer; // buffer used for arbitrary lookahead
57 _ANTLRTokenPtr *tp; // pts into buffer; current token ptr
58 _ANTLRTokenPtr *last; // pts to last valid token in buffer
59 _ANTLRTokenPtr *next; // place to put token from getANTLRToken()
60 _ANTLRTokenPtr *end_of_buffer;
61 /* when you try to write a token past this and there are no markers
62 set, then move k-1 tokens back to the beginning of the buffer.
63 We want to stay away from the end of the buffer because we have
64 to extend it if a marker is set and we reach the end (we cannot
65 move tokens to the beginning of the buffer in this case).
67 _ANTLRTokenPtr *threshold;
68 unsigned char _deleteTokens;
70 // This function is filled in by the subclass; it initiates fetch of input
71 virtual _ANTLRTokenPtr getANTLRToken() { return input->getToken(); }
76 ANTLRTokenBuffer(ANTLRTokenStream *in, int k=1, int chksz=50);
77 virtual ~ANTLRTokenBuffer();
78 virtual _ANTLRTokenPtr getToken();
79 virtual void rewind(int pos);
81 virtual _ANTLRTokenPtr bufferedToken(int i);
83 void noGarbageCollectTokens() { _deleteTokens=0; }
84 void garbageCollectTokens() { _deleteTokens=1; }
86 virtual bufferSize() { return buffer_size; }
87 virtual int minTokens() { return k; }
88 virtual void setMinTokens(int k_new) { k = k_new; }
90 virtual void panic(char *msg) { exit(PCCTS_EXIT_FAILURE); }