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 /* I have to put this here due to C++ limitation
33 * that you can't have a 'forward' decl for enums.
34 * I hate C++!!!!!!!!!!!!!!!
36 enum ANTLRTokenType { TER_HATES_CPP, ITS_UTTER_GARBAGE, WITH_SOME_GOOD_IDEAS };
38 #define ANTLR_SUPPORT_CODE
44 DLGLexerBase(DLGInputStream *in,
49 this->_bufsize = bufsize;
50 this->_lextext = new DLGChar[_bufsize];
51 if ( this->_lextext==NULL ) {
52 panic("text buffer is NULL");
54 this->_begexpr = this->_endexpr = NULL;
55 this->ch = this->bufovf = 0;
65 this->token_to_fill = NULL;
66 this->interactive = _interactive;
67 this->track_columns = _track_columns;
71 setInputStream( DLGInputStream *in )
78 /* saves dlg state, but not what feeds dlg (such as file position) */
80 saveState(DLGState *state)
83 state->interactive = interactive;
84 state->track_columns = track_columns;
85 state->auto_num = automaton;
86 state->add_erase = add_erase;
88 state->char_full = charfull;
89 state->begcol = _begcol;
90 state->endcol = _endcol;
92 state->lextext = _lextext;
93 state->begexpr = _begexpr;
94 state->endexpr = _endexpr;
95 state->bufsize = _bufsize;
96 state->bufovf = bufovf;
97 state->nextpos = nextpos;
98 state->class_num = cl;
102 restoreState(DLGState *state)
104 input = state->input;
105 interactive = state->interactive;
106 track_columns = state->track_columns;
107 automaton = state->auto_num;
108 add_erase = state->add_erase;
110 charfull = state->char_full;
111 _begcol = state->begcol;
112 _endcol = state->endcol;
114 _lextext = state->lextext;
115 _begexpr = state->begexpr;
116 _endexpr = state->endexpr;
117 _bufsize = state->bufsize;
118 bufovf = state->bufovf;
119 nextpos = state->nextpos;
120 cl = state->class_num;
123 /* erase what is currently in the buffer, and get a new reg. expr */
130 /* don't erase what is in the lextext buffer, add on to it */
137 /* substitute c for the reg. expr last matched and is in the buffer */
141 /* can't allow overwriting null at end of string */
142 if (_begexpr < &_lextext[_bufsize-1]){
144 *(_begexpr+1) = '\0';
147 nextpos = _begexpr + 1;
150 /* replace the string s for the reg. expr last matched and in the buffer */
152 replstr(register DLGChar *s)
154 register DLGChar *l= &_lextext[_bufsize -1];
158 while ((nextpos <= l) && (*(nextpos++) = *(s++))){
161 /* correct for NULL at end of string */
164 if ((nextpos <= l) && (*(--s) == 0)){
170 _endexpr = nextpos - 1;
177 "%s near line %d (text was '%s')\n",
178 ((s == NULL) ? "Lexical error" : s),
185 fprintf(stderr,"No input stream, function, or string\n");
186 /* return eof to get out gracefully */
190 ANTLRTokenType DLGLexerBase::
193 errstd("invalid token");
196 return (ANTLRTokenType) 0; // bogus, but satisfies compiler
199 _ANTLRTokenPtr DLGLexerBase::
202 if ( token_to_fill==NULL ) panic("NULL token_to_fill");
203 ANTLRTokenType tt = nextTokenType();
204 _ANTLRTokenPtr tk = token_to_fill->makeToken(tt, _lextext,_line);
211 fprintf(stderr, "DLG panic: %s\n", msg);