]> pd.if.org Git - pccts/blob - h/ATokenBuffer.h
auto commit for import
[pccts] / h / ATokenBuffer.h
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-1995
28  */
29
30 #ifndef ATOKENBUFFER_H_GATE
31 #define ATOKENBUFFER_H_GATE
32
33 #include "config.h"
34 #include ATOKEN_H
35 #include ATOKENSTREAM_H
36 #include <stdlib.h>
37
38 /*
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.
47  */
48
49 class ANTLRTokenBuffer {
50 protected:
51         ANTLRTokenStream *input;        // where do I get tokens
52         int buffer_size;
53         int chunk_size;
54         int num_markers;
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).
66          */
67         _ANTLRTokenPtr *threshold;
68         unsigned char _deleteTokens;
69
70         // This function is filled in by the subclass; it initiates fetch of input
71         virtual _ANTLRTokenPtr getANTLRToken() { return input->getToken(); }
72         void makeRoom();
73         void extendBuffer();
74
75 public:
76         ANTLRTokenBuffer(ANTLRTokenStream *in, int k=1, int chksz=50);
77         virtual ~ANTLRTokenBuffer();
78         virtual _ANTLRTokenPtr getToken();
79         virtual void rewind(int pos);
80         virtual int mark();
81         virtual _ANTLRTokenPtr bufferedToken(int i);
82
83         void noGarbageCollectTokens()   { _deleteTokens=0; }
84         void garbageCollectTokens()             { _deleteTokens=1; }
85
86         virtual bufferSize() { return buffer_size; }
87         virtual int minTokens() { return k; }
88         virtual void setMinTokens(int k_new) { k = k_new; }
89
90         virtual void panic(char *msg) { exit(PCCTS_EXIT_FAILURE); }
91 };
92
93 #endif