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
34 #include "pccts_stdio.h"
39 #include ATOKENSTREAM_H
41 class ANTLRParser
; // MR1
43 /* must define what a char looks like; can make this a class too */
46 /* Can have it as a class too: (ack this looks weird; is it right?)
47 class DllExportPCCTS DLGChar {
51 DLGChar(int ch) { c = ch; }
52 int atom() { return c; }
56 /* user must subclass this */
57 class DllExportPCCTS DLGInputStream
{
59 virtual int nextChar() = 0;
60 virtual ~DLGInputStream() {};
63 /* Predefined char stream: Input from FILE */
64 class DllExportPCCTS DLGFileInput
: public DLGInputStream
{
69 DLGFileInput(FILE *f
) { input
= f
; found_eof
= 0; }
72 if ( found_eof
) return EOF
;
75 if ( c
==EOF
) found_eof
= 1;
79 void DLGFileReset(FILE *f
) {input
=f
; found_eof
= 0; }; // MR11
82 // MR9 Suggested by Bruce Guenter (bruceg@qcc.sk.ca)
83 // MR9 Make DLGStringInput const correct
85 /* Predefined char stream: Input from string */
86 class DllExportPCCTS DLGStringInput
: public DLGInputStream
{
88 const DLGChar
*input
; // MR9
89 const DLGChar
*p
; // MR9
91 DLGStringInput(const DLGChar
*s
) { input
= s
; p
= &input
[0];} // MR9
94 if (*p
) return (int) (unsigned char) *p
++; // MR14
98 void DLGStringReset(const DLGChar
*s
) {input
=s
; p
= &input
[0]; }; // MR11 // MR16
101 class DllExportPCCTS DLGState
{
103 DLGInputStream
*input
;
112 DLGChar
*lextext
, *begexpr
, *endexpr
;
117 int debugLexerFlag
; // MR1
118 ANTLRParser
*parser
; // MR1
121 /* user must subclass this */
122 class DllExportPCCTS DLGLexerBase
: public ANTLRTokenStream
{
124 DLGLexerBase(const DLGLexerBase
&); // Prevent copy-construction
125 DLGLexerBase
& operator=(const DLGLexerBase
&); // Prevent assignment
127 virtual ANTLRTokenType
erraction();
130 DLGInputStream
*input
;
133 DLGChar
*_lextext
; /* text of most recently matched token */
134 DLGChar
*_begexpr
; /* beginning of last reg expr recogn. */
135 DLGChar
*_endexpr
; /* beginning of last reg expr recogn. */
136 int _bufsize
; /* number of characters in lextext */
137 int _begcol
; /* column that first character of token is in*/
138 int _endcol
; /* column that last character of token is in */
139 int _line
; /* line current token is on */
140 int ch
; /* character to determine next state */
141 int bufovf
; /* indicates that buffer too small for text */
143 DLGChar
*nextpos
; /* points to next available position in lextext*/
148 _ANTLRTokenPtr token_to_fill
;
150 int debugLexerFlag
; // MR1
151 ANTLRParser
*parser
; // MR1
153 virtual _ANTLRTokenPtr
getToken(); // MR12 public
154 virtual void advance(void) = 0;
155 void skip(void); /* erase lextext, look for antoher token */
156 void more(void); /* keep lextext, look for another token */
157 void mode(int k
); /* switch to automaton 'k' */
158 void saveState(DLGState
*);
159 void restoreState(DLGState
*);
160 virtual ANTLRTokenType
nextTokenType(void)=0;/* get next token */
161 void replchar(DLGChar c
); /* replace last recognized reg. expr. with
163 void replstr(const DLGChar
*s
); /* replace last recognized reg. expr. with
164 a string */ /* MR20 const */
165 virtual int err_in(); // MR1
166 virtual void errstd(const char *); // MR1 MR20 const
167 int line() { return _line
; }
168 void set_line(int newValue
) { _line
=newValue
; }; // MR1
169 virtual void newline() { _line
++; }
170 DLGChar
*lextext() { return _lextext
; }
172 int begcol() { return _begcol
; }
173 int endcol() { return _endcol
; }
174 void set_begcol(int a
) { _begcol
=a
; }
175 void set_endcol(int a
) { _endcol
=a
; }
176 DLGChar
*begexpr() { return _begexpr
; }
177 DLGChar
*endexpr() { return _endexpr
; }
178 int bufsize() { return _bufsize
; }
180 void setToken(ANTLRAbstractToken
*t
) { token_to_fill
= t
; }
182 void setInputStream(DLGInputStream
*);
183 DLGLexerBase(DLGInputStream
*in
,
184 unsigned bufsize
=2000,
186 int track_columns
=0);
187 void reset(); // MR19
188 virtual ~DLGLexerBase() { delete [] _lextext
; }
189 virtual void panic(const char *msg
); // MR1 MR20 const
190 void trackColumns() {
195 virtual ANTLRParser
*setParser(ANTLRParser
*p
); // MR1
196 virtual ANTLRParser
*getParser(); // MR1
197 virtual int debugLexer(int value
); // MR1
198 int lexErrCount
; // MR12
199 virtual int printMessage(FILE* pFile
, const char* pFormat
, ...); // MR23