]> pd.if.org Git - pccts/blob - h/DLexer.cpp
auto commit for import
[pccts] / h / DLexer.cpp
1 /* DLexer.c
2  *
3  * SOFTWARE RIGHTS
4  *
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.
10  * 
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
21  * completed.
22  *
23  * ANTLR 1.33
24  * Terence Parr
25  * Parr Research Corporation
26  * with Purdue University and AHPCRC, University of Minnesota
27  * 1989-1995
28  */
29 #define ZZINC {if ( track_columns ) (++_endcol);}
30
31 #define ZZGETC {ch = input->nextChar(); cl = ZZSHIFT(ch);}
32
33 #define ZZNEWSTATE      (newstate = dfa[state][cl])
34
35 #ifndef ZZCOPY
36 #define ZZCOPY  \
37         /* Truncate matching buffer to size (not an error) */   \
38         if (nextpos < lastpos){                         \
39                 *(nextpos++) = ch;                      \
40         }else{                                                  \
41                 bufovf = 1;                                     \
42         }
43 #endif
44
45 void DLGLexer::
46 mode( int m )
47 {
48         /* points to base of dfa table */
49         if (m<MAX_MODE){
50                 automaton = m;
51                 /* have to redo class since using different compression */
52                 cl = ZZSHIFT(ch);
53         }else{
54                 sprintf((char *)ebuf,"Invalid automaton mode = %d ",m);
55                 errstd(ebuf);
56         }
57 }
58
59 ANTLRTokenType DLGLexer::
60 nextTokenType(void)
61 {
62         register int state, newstate;
63         /* last space reserved for the null char */
64         register DLGChar *lastpos;
65         ANTLRTokenType tk;
66
67 skip:
68         bufovf = 0;
69         lastpos = &_lextext[_bufsize-1];
70         nextpos = _lextext;
71         _begcol = _endcol+1;
72 more:
73         _begexpr = nextpos;
74         if ( interactive ) {
75                 /* interactive version of automaton */
76                 /* if there is something in ch, process it */
77                 state = newstate = dfa_base[automaton];
78                 if (charfull){
79                         ZZINC;
80                         ZZCOPY;
81                         ZZNEWSTATE;
82                 }
83                 while (alternatives[newstate]){
84                         state = newstate;
85                         ZZGETC;
86                         ZZINC;
87                         ZZCOPY;
88                         ZZNEWSTATE;
89                 }
90                 /* figure out if last character really part of token */
91                 if ((state != dfa_base[automaton]) && (newstate == DfaStates)){
92                         charfull = 1;
93                         --nextpos;
94                 }else{
95                         charfull = 0;
96                         state = newstate;
97                 }
98                 *(nextpos) = '\0';
99                 /* Able to transition out of start state to some non err state?*/
100                 if ( state == dfa_base[automaton] ){
101                         /* make sure doesn't get stuck */
102                         advance();
103                 }
104         }
105         else { /* non-interactive version of automaton */
106                 if (!charfull)
107                         advance();
108                 else
109                         ZZINC;
110                 state = dfa_base[automaton];
111                 while (ZZNEWSTATE != DfaStates) {
112                         state = newstate;
113                         ZZCOPY;
114                         ZZGETC;
115                         ZZINC;
116                 }
117                 charfull = 1;
118                 if ( state == dfa_base[automaton] ){
119                         if (nextpos < lastpos){
120                                 *(nextpos++) = ch;
121                         }else{
122                                 bufovf = 1;
123                         }
124                         *nextpos = '\0';
125                         /* make sure doesn't get stuck */
126                         advance();
127                 }else{
128                         *nextpos = '\0';
129                 }
130         }
131         if ( track_columns ) _endcol -= charfull;
132         _endexpr = nextpos -1;
133         add_erase = 0;
134 #ifdef OLD
135         tk = (ANTLRTokenType)
136                  (*actions[accepts[state]])(this);      // must pass this manually
137                                                                                         // actions is not a [] of pointers
138                                                                                         // to member functions.
139 #endif
140         tk = (this->*actions[accepts[state]])();
141         switch (add_erase) {
142                 case 1: goto skip;
143                 case 2: goto more;
144         }
145         return tk;
146 }
147
148 void DLGLexer::
149 advance()
150 {
151         if ( input==NULL ) err_in();
152         ZZGETC; charfull = 1; ZZINC;
153 }