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
36 #include ATOKENSTREAM_H
38 /* must define what a char looks like; can make this a class too */
41 /* Can have it as a class too: (ack this looks weird; is it right?)
46 DLGChar(int ch) { c = ch; }
47 int atom() { return c; }
51 /* user must subclass this */
52 class DLGInputStream {
54 virtual int nextChar() = 0;
57 /* Predefined char stream: Input from FILE */
58 class DLGFileInput : public DLGInputStream {
63 DLGFileInput(FILE *f) { input = f; found_eof = 0; }
66 if ( found_eof ) return EOF;
69 if ( c==EOF ) found_eof = 1;
75 /* Predefined char stream: Input from string */
76 class DLGStringInput : public DLGInputStream {
81 DLGStringInput(DLGChar *s) { input = s; p = &input[0];}
84 if (*p) return (int) *p++;
91 DLGInputStream *input;
100 DLGChar *lextext, *begexpr, *endexpr;
107 /* user must subclass this */
108 class DLGLexerBase : public ANTLRTokenStream {
110 virtual ANTLRTokenType erraction();
113 DLGInputStream *input;
116 DLGChar *_lextext; /* text of most recently matched token */
117 DLGChar *_begexpr; /* beginning of last reg expr recogn. */
118 DLGChar *_endexpr; /* beginning of last reg expr recogn. */
119 int _bufsize; /* number of characters in lextext */
120 int _begcol; /* column that first character of token is in*/
121 int _endcol; /* column that last character of token is in */
122 int _line; /* line current token is on */
123 int ch; /* character to determine next state */
124 int bufovf; /* indicates that buffer too small for text */
126 DLGChar *nextpos; /* points to next available position in lextext*/
131 _ANTLRTokenPtr token_to_fill;
133 virtual _ANTLRTokenPtr getToken();
136 virtual void advance(void) = 0;
137 void skip(void); /* erase lextext, look for antoher token */
138 void more(void); /* keep lextext, look for another token */
139 void mode(int k); /* switch to automaton 'k' */
140 void saveState(DLGState *);
141 void restoreState(DLGState *);
142 virtual ANTLRTokenType nextTokenType(void)=0;/* get next token */
143 void replchar(DLGChar c); /* replace last recognized reg. expr. with
145 void replstr(DLGChar *s); /* replace last recognized reg. expr. with
150 int line() { return _line; }
151 virtual void newline() { _line++; }
152 DLGChar *lextext() { return _lextext; }
154 int begcol() { return _begcol; }
155 int endcol() { return _endcol; }
156 void set_begcol(int a) { _begcol=a; }
157 void set_endcol(int a) { _endcol=a; }
158 DLGChar *begexpr() { return _begexpr; }
159 DLGChar *endexpr() { return _endexpr; }
160 int bufsize() { return _bufsize; }
162 void setToken(ANTLRAbstractToken *t) { token_to_fill = t; }
164 void setInputStream(DLGInputStream *);
165 DLGLexerBase(DLGInputStream *in,
166 unsigned bufsize=2000,
168 int track_columns=0);
169 virtual ~DLGLexerBase() { delete [] _lextext; }
170 void panic(char *msg);
172 void trackColumns() {