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;
62 /* Predefined char stream: Input from FILE */
63 class DllExportPCCTS DLGFileInput
: public DLGInputStream
{
68 DLGFileInput(FILE *f
) { input
= f
; found_eof
= 0; }
71 if ( found_eof
) return EOF
;
74 if ( c
==EOF
) found_eof
= 1;
78 void DLGFileReset(FILE *f
) {input
=f
; found_eof
= 0; }; // MR11
81 // MR9 Suggested by Bruce Guenter (bruceg@qcc.sk.ca)
82 // MR9 Make DLGStringInput const correct
84 /* Predefined char stream: Input from string */
85 class DllExportPCCTS DLGStringInput
: public DLGInputStream
{
87 const DLGChar
*input
; // MR9
88 const DLGChar
*p
; // MR9
90 DLGStringInput(const DLGChar
*s
) { input
= s
; p
= &input
[0];} // MR9
93 if (*p
) return (int) (unsigned char) *p
++; // MR14
97 void DLGStringReset(const DLGChar
*s
) {input
=s
; p
= &input
[0]; }; // MR11 // MR16
100 class DllExportPCCTS DLGState
{
102 DLGInputStream
*input
;
111 DLGChar
*lextext
, *begexpr
, *endexpr
;
116 int debugLexerFlag
; // MR1
117 ANTLRParser
*parser
; // MR1
120 /* user must subclass this */
121 class DllExportPCCTS DLGLexerBase
: public ANTLRTokenStream
{
123 DLGLexerBase(const DLGLexerBase
&); // Prevent copy-construction
124 DLGLexerBase
& operator=(const DLGLexerBase
&); // Prevent assignment
126 virtual ANTLRTokenType
erraction();
129 DLGInputStream
*input
;
132 DLGChar
*_lextext
; /* text of most recently matched token */
133 DLGChar
*_begexpr
; /* beginning of last reg expr recogn. */
134 DLGChar
*_endexpr
; /* beginning of last reg expr recogn. */
135 int _bufsize
; /* number of characters in lextext */
136 int _begcol
; /* column that first character of token is in*/
137 int _endcol
; /* column that last character of token is in */
138 int _line
; /* line current token is on */
139 int ch
; /* character to determine next state */
140 int bufovf
; /* indicates that buffer too small for text */
142 DLGChar
*nextpos
; /* points to next available position in lextext*/
147 _ANTLRTokenPtr token_to_fill
;
149 int debugLexerFlag
; // MR1
150 ANTLRParser
*parser
; // MR1
152 virtual _ANTLRTokenPtr
getToken(); // MR12 public
153 virtual void advance(void) = 0;
154 void skip(void); /* erase lextext, look for antoher token */
155 void more(void); /* keep lextext, look for another token */
156 void mode(int k
); /* switch to automaton 'k' */
157 void saveState(DLGState
*);
158 void restoreState(DLGState
*);
159 virtual ANTLRTokenType
nextTokenType(void)=0;/* get next token */
160 void replchar(DLGChar c
); /* replace last recognized reg. expr. with
162 void replstr(const DLGChar
*s
); /* replace last recognized reg. expr. with
163 a string */ /* MR20 const */
164 virtual int err_in(); // MR1
165 virtual void errstd(const char *); // MR1 MR20 const
166 int line() { return _line
; }
167 void set_line(int newValue
) { _line
=newValue
; }; // MR1
168 virtual void newline() { _line
++; }
169 DLGChar
*lextext() { return _lextext
; }
171 int begcol() { return _begcol
; }
172 int endcol() { return _endcol
; }
173 void set_begcol(int a
) { _begcol
=a
; }
174 void set_endcol(int a
) { _endcol
=a
; }
175 DLGChar
*begexpr() { return _begexpr
; }
176 DLGChar
*endexpr() { return _endexpr
; }
177 int bufsize() { return _bufsize
; }
179 void setToken(ANTLRAbstractToken
*t
) { token_to_fill
= t
; }
181 void setInputStream(DLGInputStream
*);
182 DLGLexerBase(DLGInputStream
*in
,
183 unsigned bufsize
=2000,
185 int track_columns
=0);
186 void reset(); // MR19
187 virtual ~DLGLexerBase() { delete [] _lextext
; }
188 virtual void panic(const char *msg
); // MR1 MR20 const
189 void trackColumns() {
194 virtual ANTLRParser
*setParser(ANTLRParser
*p
); // MR1
195 virtual ANTLRParser
*getParser(); // MR1
196 virtual int debugLexer(int value
); // MR1
197 int lexErrCount
; // MR12
198 virtual int printMessage(FILE* pFile
, const char* pFormat
, ...); // MR23