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 virtual ANTLRTokenType
erraction();
126 DLGInputStream
*input
;
129 DLGChar
*_lextext
; /* text of most recently matched token */
130 DLGChar
*_begexpr
; /* beginning of last reg expr recogn. */
131 DLGChar
*_endexpr
; /* beginning of last reg expr recogn. */
132 int _bufsize
; /* number of characters in lextext */
133 int _begcol
; /* column that first character of token is in*/
134 int _endcol
; /* column that last character of token is in */
135 int _line
; /* line current token is on */
136 int ch
; /* character to determine next state */
137 int bufovf
; /* indicates that buffer too small for text */
139 DLGChar
*nextpos
; /* points to next available position in lextext*/
144 _ANTLRTokenPtr token_to_fill
;
146 int debugLexerFlag
; // MR1
147 ANTLRParser
*parser
; // MR1
149 virtual _ANTLRTokenPtr
getToken(); // MR12 public
150 virtual void advance(void) = 0;
151 void skip(void); /* erase lextext, look for antoher token */
152 void more(void); /* keep lextext, look for another token */
153 void mode(int k
); /* switch to automaton 'k' */
154 void saveState(DLGState
*);
155 void restoreState(DLGState
*);
156 virtual ANTLRTokenType
nextTokenType(void)=0;/* get next token */
157 void replchar(DLGChar c
); /* replace last recognized reg. expr. with
159 void replstr(const DLGChar
*s
); /* replace last recognized reg. expr. with
160 a string */ /* MR20 const */
161 virtual int err_in(); // MR1
162 virtual void errstd(const char *); // MR1 MR20 const
163 int line() { return _line
; }
164 void set_line(int newValue
) { _line
=newValue
; }; // MR1
165 virtual void newline() { _line
++; }
166 DLGChar
*lextext() { return _lextext
; }
168 int begcol() { return _begcol
; }
169 int endcol() { return _endcol
; }
170 void set_begcol(int a
) { _begcol
=a
; }
171 void set_endcol(int a
) { _endcol
=a
; }
172 DLGChar
*begexpr() { return _begexpr
; }
173 DLGChar
*endexpr() { return _endexpr
; }
174 int bufsize() { return _bufsize
; }
176 void setToken(ANTLRAbstractToken
*t
) { token_to_fill
= t
; }
178 void setInputStream(DLGInputStream
*);
179 DLGLexerBase(DLGInputStream
*in
,
180 unsigned bufsize
=2000,
182 int track_columns
=0);
183 void reset(); // MR19
184 virtual ~DLGLexerBase() { delete [] _lextext
; }
185 virtual void panic(const char *msg
); // MR1 MR20 const
186 void trackColumns() {
191 virtual ANTLRParser
*setParser(ANTLRParser
*p
); // MR1
192 virtual ANTLRParser
*getParser(); // MR1
193 virtual int debugLexer(int value
); // MR1
194 int lexErrCount
; // MR12
195 virtual int printMessage(FILE* pFile
, const char* pFormat
, ...); // MR23