comparison zotnet/tws/lexstring.c @ 0:bce86c4163a3

Initial revision
author kono
date Mon, 18 Apr 2005 23:46:02 +0900
parents
children 441a2190cfae
comparison
equal deleted inserted replaced
-1:000000000000 0:bce86c4163a3
1 #include <stdio.h>
2 #include <ctype.h>
3 #ifndef lint
4 static char ident[] = "@(#)$Id$";
5 #endif /* lint */
6
7 #define YYLERR yysvec
8 #define YYTYPE int
9 #define YYLMAX 256
10
11 struct yysvf {
12 #ifndef hpux
13 struct yywork *yystoff;
14 #else /* hpux */
15 int yystoff;
16 #endif /* hpux */
17 struct yysvf *yyother;
18 int *yystops;
19 };
20
21 struct yywork {
22 YYTYPE verify;
23 YYTYPE advance;
24 };
25
26 extern int yyvstop[];
27 extern struct yywork yycrank[];
28 extern struct yysvf yysvec[];
29 extern char yymatch[];
30 extern char yyextra[];
31
32 #ifdef LEXDEBUG
33 static int debug = 0;
34 #endif /* LEXDEBUG */
35
36 #ifdef ONECASE
37 static char case_map[] = {
38 0, 1, 2, 3, 4, 5, 6, 7, 8, 9,
39 10, 11, 12, 13, 14, 15, 16, 17, 18, 19,
40 20, 21, 22, 23, 24, 25, 26, 27, 28, 29,
41 30, 31, 32, 33, 34, 35, 36, 37, 38, 39,
42 40, 41, 42, 43, 44, 45, 46, 47, 48, 49,
43 50, 51, 52, 53, 54, 55, 56, 57, 58, 59,
44 60, 61, 62, 63, 64, 97, 98, 99, 100, 101,
45 102, 103, 104, 105, 106, 107, 108, 109, 110, 111,
46 112, 113, 114, 115, 116, 117, 118, 119, 120, 121,
47 122, 91, 92, 93, 94, 95, 96, 97, 98, 99,
48 100, 101, 102, 103, 104, 105, 106, 107, 108, 109,
49 110, 111, 112, 113, 114, 115, 116, 117, 118, 119,
50 120, 121, 122, 123, 124, 125, 126, 127,
51 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
52 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
53 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
54 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
55 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
56 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
57 0, 0, 0, 0, 0, 0, 0, 0
58 };
59 #endif /* ONECASE */
60
61 lex_string( strptr, start_cond)
62 char **strptr;
63 int start_cond;
64 {
65 register struct yysvf *state, **lsp;
66 register struct yywork *tran;
67 register int statenum;
68 register int ch;
69 register char *cp = *strptr;
70 register int *found;
71 struct yysvf *yylstate[YYLMAX];
72
73 /* start off machines */
74 lsp = yylstate;
75 statenum = 1 + start_cond;
76 state = yysvec + statenum;
77 for (;;){
78 # ifdef LEXDEBUG
79 if (debug) {
80 fprintf(stderr,"%d ",statenum - 1);
81 }
82 # endif
83 #ifndef hpux
84 tran = state->yystoff;
85 #else /* hpux */
86 tran = &yycrank[state->yystoff];
87 #endif /* hpux */
88 if(tran == yycrank)
89 /* may not be any transitions */
90 if (state->yyother == 0 ||
91 #ifndef hpux
92 state->yyother->yystoff == yycrank)
93 #else /* hpux */
94 state->yyother->yystoff == 0)
95 #endif /* hpux */
96 break;
97
98 #ifdef ONECASE
99 ch = case_map[*cp++];
100 #else /* not ONECASE */
101 ch = *cp++;
102 #endif /* ONECASE */
103 # ifdef LEXDEBUG
104 if (debug) {
105 fprintf(stderr,"(");
106 allprint(ch);
107 fprintf(stderr, ")");
108 }
109 # endif
110 tryagain:
111 #ifndef hpux
112 if ( tran > yycrank){
113 #else /* hpux */
114 if ( (int)tran > (int)yycrank){
115 #endif /* hpux */
116 tran += ch;
117 if (tran->verify == statenum){
118 if ((statenum = tran->advance) == 0){
119 /* error transitions */
120 --cp;
121 break;
122 }
123 state = statenum + yysvec;
124 *lsp++ = state;
125 goto contin;
126 }
127
128 #ifndef hpux
129 } else if(tran < yycrank) {
130 #else /* hpux */
131 } else if( (int)tran < (int)yycrank) {
132 #endif /* hpux */
133 tran = yycrank+(yycrank-tran) + ch;
134 # ifdef LEXDEBUG
135 if (debug) {
136 fprintf(stderr," compressed");
137 }
138 # endif
139 if (tran->verify == statenum){
140 if ((statenum = tran->advance) == 0)
141 /* error transitions */
142 break;
143
144 state = statenum + yysvec;
145 *lsp++ = state;
146 goto contin;
147 }
148 tran += (yymatch[ch] - ch);
149 # ifdef LEXDEBUG
150 if (debug) {
151 fprintf(stderr,"(fb ");
152 allprint(yymatch[ch]);
153 fprintf(stderr,")");
154 }
155 # endif
156 if (tran->verify == statenum){
157 if((statenum = tran->advance) == 0)
158 /* error transition */
159 break;
160
161 state = statenum + yysvec;
162 *lsp++ = state;
163 goto contin;
164 }
165 }
166 if ((state = state->yyother) &&
167 #ifndef hpux
168 (tran = state->yystoff) != yycrank){
169 #else /* hpux */
170 (tran = &yycrank[state->yystoff]) != yycrank){
171 #endif /* hpux */
172 statenum = state - yysvec;
173 # ifdef LEXDEBUG
174 if (debug) {
175 fprintf(stderr,"fb %d", statenum - 1);
176 }
177 # endif
178 goto tryagain;
179 } else
180 break;
181
182 contin:
183 # ifdef LEXDEBUG
184 if (debug) {
185 fprintf(stderr,">");
186 }
187 # endif
188 ;
189 }
190 # ifdef LEXDEBUG
191 if (debug) {
192 fprintf(stderr,"\nStopped in state %d (",*(lsp-1)-yysvec-1);
193 allprint(ch);
194 fprintf(stderr, ") ");
195 }
196 # endif
197 while (lsp-- > yylstate){
198 if (*lsp != 0 && (found= (*lsp)->yystops) && *found > 0){
199 if(yyextra[*found]){
200 /* must backup */
201 ch = -*found;
202 do {
203 while (*found && *found++ != ch)
204 ;
205 } while (lsp > yylstate &&
206 (found = (*--lsp)->yystops));
207 }
208 # ifdef LEXDEBUG
209 if (debug) {
210 fprintf(stderr," Match \"");
211 for ( cp = *strptr;
212 cp <= ((*strptr)+(lsp-yylstate));
213 cp++)
214 allprint( *cp );
215 fprintf(stderr,"\" action %d\n",*found);
216 }
217 # endif
218 *strptr += (lsp - yylstate + 1);
219 return(*found);
220 }
221 }
222 /* the string didn't match anything - if we're looking at
223 * eos, just return 0. Otherwise, bump the string pointer
224 * and return -1.
225 */
226 # ifdef LEXDEBUG
227 if (debug) {
228 fprintf(stderr," No match\n");
229 }
230 #endif /* LEXDEBUG */
231 if ( **strptr ) {
232 (*strptr)++;
233 return (-1);
234 }
235 return (0);
236 }
237
238 #ifdef LEXDEBUG
239 allprint(c)
240 char c;
241 {
242 if ( c < 32 ) {
243 putc( '^', stderr );
244 c += 32;
245 } else if ( c == 127 ) {
246 putc( '^', stderr );
247 c = '?';
248 }
249 putc( c, stderr );
250 }
251 #endif /* LEXDEBUG */