]>
git.proxmox.com Git - mirror_edk2.git/blob - BaseTools/Source/C/VfrCompile/Pccts/h/DLexerBase.cpp
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
32 #include "pccts_stdio.h"
33 #include "pccts_stdlib.h"
37 /* I have to put this here due to C++ limitation
38 * that you can't have a 'forward' decl for enums.
39 * I hate C++!!!!!!!!!!!!!!!
43 // MR1 10-Apr-97 133MR1 Prevent use of varying sizes for the
44 // MR1 ANTLRTokenType enum
47 enum ANTLRTokenType
{ TER_HATES_CPP
=0, ITS_UTTER_GARBAGE
, // MR1
48 WITH_SOME_GOOD_IDEAS
=9999}; // MR1
50 #define ANTLR_SUPPORT_CODE
54 #include APARSER_H // MR23
57 DLGLexerBase(DLGInputStream
*in
,
62 this->_bufsize
= bufsize
;
63 this->_lextext
= new DLGChar
[_bufsize
];
64 if ( this->_lextext
==NULL
) {
65 panic("text buffer is NULL");
67 this->_begexpr
= this->_endexpr
= NULL
;
68 this->ch
= this->bufovf
= 0;
78 this->token_to_fill
= NULL
;
79 this->interactive
= _interactive
;
80 this->track_columns
= _track_columns
;
81 this->debugLexerFlag
= 0; // MR1
82 this->parser
= NULL
; // MR1
83 this->lexErrCount
=0; // MR11
88 void DLGLexerBase::reset()
99 setInputStream( DLGInputStream
*in
)
106 /* saves dlg state, but not what feeds dlg (such as file position) */
108 saveState(DLGState
*state
)
110 state
->input
= input
;
111 state
->interactive
= interactive
;
112 state
->track_columns
= track_columns
;
113 state
->auto_num
= automaton
;
114 state
->add_erase
= add_erase
;
116 state
->char_full
= charfull
;
117 state
->begcol
= _begcol
;
118 state
->endcol
= _endcol
;
120 state
->lextext
= _lextext
;
121 state
->begexpr
= _begexpr
;
122 state
->endexpr
= _endexpr
;
123 state
->bufsize
= _bufsize
;
124 state
->bufovf
= bufovf
;
125 state
->nextpos
= nextpos
;
126 state
->class_num
= cl
;
127 state
->debugLexerFlag
= debugLexerFlag
; // MR1
128 state
->parser
= parser
; // MR1
132 restoreState(DLGState
*state
)
134 input
= state
->input
;
135 interactive
= state
->interactive
;
136 track_columns
= state
->track_columns
;
137 automaton
= state
->auto_num
;
138 add_erase
= state
->add_erase
;
140 charfull
= state
->char_full
;
141 _begcol
= state
->begcol
;
142 _endcol
= state
->endcol
;
144 _lextext
= state
->lextext
;
145 _begexpr
= state
->begexpr
;
146 _endexpr
= state
->endexpr
;
147 _bufsize
= state
->bufsize
;
148 bufovf
= state
->bufovf
;
149 nextpos
= state
->nextpos
;
150 cl
= state
->class_num
;
151 debugLexerFlag
= state
->debugLexerFlag
; // MR1
152 parser
= state
->parser
; // MR1
155 /* erase what is currently in the buffer, and get a new reg. expr */
162 /* don't erase what is in the lextext buffer, add on to it */
169 /* substitute c for the reg. expr last matched and is in the buffer */
173 /* can't allow overwriting null at end of string */
174 if (_begexpr
< &_lextext
[_bufsize
-1]){
176 *(_begexpr
+1) = '\0';
180 nextpos
= _begexpr
+ 1;
183 nextpos
= _begexpr
; /* MR30 Zero terminates string. */
187 /* replace the string s for the reg. expr last matched and in the buffer */
189 #ifdef _MSC_VER // MR23
190 //Turn off "assignment within conditional expression" warning
191 #pragma warning(disable : 4706)
194 replstr(const DLGChar
*s
) /* MR20 const */
196 register DLGChar
*l
= &_lextext
[_bufsize
-1];
200 while ((nextpos
<= l
) && (*(nextpos
++) = *(s
++))){
203 /* correct for NULL at end of string */
206 if ((nextpos
<= l
) && (*(--s
) == 0)){
212 _endexpr
= nextpos
- 1;
214 #ifdef _MSC_VER // MR23
215 #pragma warning(default: 4706)
219 errstd(const char *s
) /* MR20 const */
221 lexErrCount
++; /* MR11 */
222 /* MR23 */ printMessage(stderr
,
223 "%s near line %d (text was '%s')\n",
224 ((s
== NULL
) ? "Lexical error" : s
),
231 /* MR23 */ printMessage(stderr
,"No input stream, function, or string\n");
232 /* return eof to get out gracefully */
236 ANTLRTokenType
DLGLexerBase::
239 errstd("invalid token");
242 return (ANTLRTokenType
) 0; // bogus, but satisfies compiler
245 _ANTLRTokenPtr
DLGLexerBase::
248 if ( token_to_fill
==NULL
) panic("NULL token_to_fill");
249 ANTLRTokenType tt
= nextTokenType();
250 _ANTLRTokenPtr tk
= token_to_fill
->makeToken(tt
, _lextext
,_line
);
255 panic(const char *msg
) /* MR20 const */
258 parser
->panic(msg
); //MR23
261 /* MR23 */ printMessage(stderr
, "DLG panic: %s\n", msg
);
265 exit(PCCTS_EXIT_FAILURE
); // MR1
269 ANTLRParser
* DLGLexerBase:: // MR1
270 setParser(ANTLRParser
*p
) { // MR1
271 ANTLRParser
*oldValue
=parser
; // MR1
273 return oldValue
; // MR1
276 ANTLRParser
* DLGLexerBase:: // MR1
278 return parser
; // MR1
281 int DLGLexerBase:: // MR1
282 debugLexer(int newValue
) { // MR1
283 int oldValue
=debugLexerFlag
; // MR1
284 debugLexerFlag
=newValue
; // MR1
285 return oldValue
; // MR1
289 int DLGLexerBase::printMessage(FILE* pFile
, const char* pFormat
, ...)
292 va_start( marker
, pFormat
);
296 parser
->printMessageV(pFile
, pFormat
, marker
);
298 iRet
= vfprintf(pFile
, pFormat
, marker
);