]>
git.proxmox.com Git - mirror_edk2.git/blob - EdkCompatibilityPkg/Other/Maintained/Tools/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
56 DLGLexerBase(DLGInputStream
*in
,
61 this->_bufsize
= bufsize
;
62 this->_lextext
= new DLGChar
[_bufsize
];
63 if ( this->_lextext
==NULL
) {
64 panic("text buffer is NULL");
66 this->_begexpr
= this->_endexpr
= NULL
;
67 this->ch
= this->bufovf
= 0;
77 this->token_to_fill
= NULL
;
78 this->interactive
= _interactive
;
79 this->track_columns
= _track_columns
;
80 this->debugLexerFlag
= 0; // MR1
81 this->parser
= NULL
; // MR1
82 this->lexErrCount
=0; // MR11
87 void DLGLexerBase::reset()
98 setInputStream( DLGInputStream
*in
)
105 /* saves dlg state, but not what feeds dlg (such as file position) */
107 saveState(DLGState
*state
)
109 state
->input
= input
;
110 state
->interactive
= interactive
;
111 state
->track_columns
= track_columns
;
112 state
->auto_num
= automaton
;
113 state
->add_erase
= add_erase
;
115 state
->char_full
= charfull
;
116 state
->begcol
= _begcol
;
117 state
->endcol
= _endcol
;
119 state
->lextext
= _lextext
;
120 state
->begexpr
= _begexpr
;
121 state
->endexpr
= _endexpr
;
122 state
->bufsize
= _bufsize
;
123 state
->bufovf
= bufovf
;
124 state
->nextpos
= nextpos
;
125 state
->class_num
= cl
;
126 state
->debugLexerFlag
= debugLexerFlag
; // MR1
127 state
->parser
= parser
; // MR1
131 restoreState(DLGState
*state
)
133 input
= state
->input
;
134 interactive
= state
->interactive
;
135 track_columns
= state
->track_columns
;
136 automaton
= state
->auto_num
;
137 add_erase
= state
->add_erase
;
139 charfull
= state
->char_full
;
140 _begcol
= state
->begcol
;
141 _endcol
= state
->endcol
;
143 _lextext
= state
->lextext
;
144 _begexpr
= state
->begexpr
;
145 _endexpr
= state
->endexpr
;
146 _bufsize
= state
->bufsize
;
147 bufovf
= state
->bufovf
;
148 nextpos
= state
->nextpos
;
149 cl
= state
->class_num
;
150 debugLexerFlag
= state
->debugLexerFlag
; // MR1
151 parser
= state
->parser
; // MR1
154 /* erase what is currently in the buffer, and get a new reg. expr */
161 /* don't erase what is in the lextext buffer, add on to it */
168 /* substitute c for the reg. expr last matched and is in the buffer */
172 /* can't allow overwriting null at end of string */
173 if (_begexpr
< &_lextext
[_bufsize
-1]){
175 *(_begexpr
+1) = '\0';
178 nextpos
= _begexpr
+ 1;
181 /* replace the string s for the reg. expr last matched and in the buffer */
184 replstr(const DLGChar
*s
) /* MR20 const */
186 register DLGChar
*l
= &_lextext
[_bufsize
-1];
190 while ((nextpos
<= l
) && (*(nextpos
++) = *(s
++))){
193 /* correct for NULL at end of string */
196 if ((nextpos
<= l
) && (*(--s
) == 0)){
202 _endexpr
= nextpos
- 1;
206 errstd(const char *s
) /* MR20 const */
208 lexErrCount
++; /* MR11 */
210 "%s near line %d (text was '%s')\n",
211 ((s
== NULL
) ? "Lexical error" : s
),
218 fprintf(stderr
,"No input stream, function, or string\n");
219 /* return eof to get out gracefully */
223 ANTLRTokenType
DLGLexerBase::
226 errstd("invalid token");
229 return (ANTLRTokenType
) 0; // bogus, but satisfies compiler
232 _ANTLRTokenPtr
DLGLexerBase::
235 if ( token_to_fill
==NULL
) panic("NULL token_to_fill");
236 ANTLRTokenType tt
= nextTokenType();
237 _ANTLRTokenPtr tk
= token_to_fill
->makeToken(tt
, _lextext
,_line
);
242 panic(const char *msg
) /* MR20 const */
244 fprintf(stderr
, "DLG panic: %s\n", msg
);
248 exit(PCCTS_EXIT_FAILURE
); // MR1
251 ANTLRParser
* DLGLexerBase:: // MR1
252 setParser(ANTLRParser
*p
) { // MR1
253 ANTLRParser
*oldValue
=parser
; // MR1
255 return oldValue
; // MR1
258 ANTLRParser
* DLGLexerBase:: // MR1
260 return parser
; // MR1
263 int DLGLexerBase:: // MR1
264 debugLexer(int newValue
) { // MR1
265 int oldValue
=debugLexerFlag
; // MR1
266 debugLexerFlag
=newValue
; // MR1
267 return oldValue
; // MR1