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 "pccts_stdlib.h"
40 #include ATOKENSTREAM_H
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.
53 class ANTLRParser
; // MR1
55 class DllExportPCCTS ANTLRTokenBuffer
{
57 ANTLRTokenStream
*input
; // where do I get tokens
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).
73 _ANTLRTokenPtr
*threshold
;
74 unsigned char _deleteTokens
;
76 // This function is filled in by the subclass; it initiates fetch of input
77 virtual _ANTLRTokenPtr
getANTLRToken() { return input
->getToken(); }
82 ANTLRTokenBuffer(ANTLRTokenStream
*in
, int k
=1, int chksz
=50);
83 virtual ~ANTLRTokenBuffer();
84 virtual _ANTLRTokenPtr
getToken();
85 virtual void rewind(int pos
);
87 virtual _ANTLRTokenPtr
bufferedToken(int i
);
89 void noGarbageCollectTokens() { _deleteTokens
=0; }
90 void garbageCollectTokens() { _deleteTokens
=1; }
92 virtual int bufferSize() { return buffer_size
; }
93 virtual int minTokens() { return k
; }
94 virtual void setMinTokens(int k_new
) { k
= k_new
; }
96 virtual void panic(const char *msg
); /* MR20 const */
98 virtual int printMessage(FILE* pFile
, const char* pFormat
, ...); // MR23
101 ANTLRParser
*parser
; // MR1
103 ANTLRParser
*setParser(ANTLRParser
*p
); // MR1
104 ANTLRParser
*getParser(); // MR1
105 ANTLRTokenStream
*getLexer() const { // MR12
106 return input
;} // MR12