|
|
1.1 root 1: #include <stdio.h>
2: #include <ctype.h>
3:
4: #define YYLERR yysvec
5: #define YYTYPE int
6: #define YYLMAX 256
7:
8: struct yysvf {
9: struct yywork *yystoff;
10: struct yysvf *yyother;
11: int *yystops;
12: };
13:
14: struct yywork {
15: YYTYPE verify;
16: YYTYPE advance;
17: };
18:
19: extern int yyvstop[];
20: extern struct yywork yycrank[];
21: extern struct yysvf yysvec[];
22: extern char yymatch[];
23: extern char yyextra[];
24:
25: #ifdef ONECASE
26: static char case_map[] = {
27: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9,
28: 10, 11, 12, 13, 14, 15, 16, 17, 18, 19,
29: 20, 21, 22, 23, 24, 25, 26, 27, 28, 29,
30: 30, 31, 32, 33, 34, 35, 36, 37, 38, 39,
31: 40, 41, 42, 43, 44, 45, 46, 47, 48, 49,
32: 50, 51, 52, 53, 54, 55, 56, 57, 58, 59,
33: 60, 61, 62, 63, 64, 97, 98, 99, 100, 101,
34: 102, 103, 104, 105, 106, 107, 108, 109, 110, 111,
35: 112, 113, 114, 115, 116, 117, 118, 119, 120, 121,
36: 122, 91, 92, 93, 94, 95, 96, 97, 98, 99,
37: 100, 101, 102, 103, 104, 105, 106, 107, 108, 109,
38: 110, 111, 112, 113, 114, 115, 116, 117, 118, 119,
39: 120, 121, 122, 123, 124, 125, 126, 127,
40: 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
41: 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
42: 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
43: 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
44: 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
45: 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
46: 0, 0, 0, 0, 0, 0, 0, 0
47: };
48: #endif ONECASE
49:
50:
51: lex_string( strptr, start_cond)
52: char **strptr;
53: int start_cond;
54: {
55: register struct yysvf *state, **lsp;
56: register struct yywork *tran;
57: register int statenum;
58: register int ch;
59: register char *cp = *strptr;
60: register int *found;
61: struct yysvf *yylstate[YYLMAX];
62:
63: /* start off machines */
64: lsp = yylstate;
65: statenum = 1 + start_cond;
66: state = yysvec + statenum;
67: for (;;){
68: # ifdef LEXDEBUG
69: fprintf(stdout,"%d ",statenum - 1);
70: # endif
71: tran = state->yystoff;
72: if(tran == yycrank)
73: /* may not be any transitions */
74: if (state->yyother == 0 ||
75: state->yyother->yystoff == yycrank)
76: break;
77:
78: #ifdef ONECASE
79: ch = case_map[*cp++];
80: #else not ONECASE
81: ch = *cp++;
82: #endif ONECASE
83: # ifdef LEXDEBUG
84: fprintf(stdout,"(");
85: allprint(ch);
86: fprintf(stdout, ")");
87: # endif
88: tryagain:
89: if ( tran > yycrank){
90: tran += ch;
91: if (tran->verify == statenum){
92: if ((statenum = tran->advance) == 0){
93: /* error transitions */
94: --cp;
95: break;
96: }
97: state = statenum + yysvec;
98: *lsp++ = state;
99: goto contin;
100: }
101:
102: } else if(tran < yycrank) {
103: tran = yycrank+(yycrank-tran) + ch;
104: # ifdef LEXDEBUG
105: fprintf(stdout," compressed");
106: # endif
107: if (tran->verify == statenum){
108: if ((statenum = tran->advance) == 0)
109: /* error transitions */
110: break;
111:
112: state = statenum + yysvec;
113: *lsp++ = state;
114: goto contin;
115: }
116: tran += (yymatch[ch] - ch);
117: # ifdef LEXDEBUG
118: fprintf(stdout,"(fb ");
119: allprint(yymatch[ch]);
120: fprintf(stdout,")");
121: # endif
122: if (tran->verify == statenum){
123: if((statenum = tran->advance) == 0)
124: /* error transition */
125: break;
126:
127: state = statenum + yysvec;
128: *lsp++ = state;
129: goto contin;
130: }
131: }
132: if ((state = state->yyother) &&
133: (tran = state->yystoff) != yycrank){
134: statenum = state - yysvec;
135: # ifdef LEXDEBUG
136: fprintf(stdout,"fb %d",
137: statenum - 1);
138: # endif
139: goto tryagain;
140: } else
141: break;
142:
143: contin:
144: # ifdef LEXDEBUG
145: fprintf(stdout,">");
146: # endif
147: ;
148: }
149: # ifdef LEXDEBUG
150: fprintf(stdout,"\nStopped in state %d (",*(lsp-1)-yysvec-1);
151: allprint(ch);
152: fprintf(stdout, ") ");
153: # endif
154: while (lsp-- > yylstate){
155: if (*lsp != 0 && (found= (*lsp)->yystops) && *found > 0){
156: if(yyextra[*found]){
157: /* must backup */
158: ch = -*found;
159: do {
160: while (*found && *found++ != ch)
161: ;
162: } while (lsp > yylstate &&
163: (found = (*--lsp)->yystops));
164: }
165: # ifdef LEXDEBUG
166: fprintf(stdout," Match \"");
167: for ( cp = *strptr;
168: cp <= ((*strptr)+(lsp-yylstate));
169: cp++)
170: allprint( *cp );
171: fprintf(stdout,"\" action %d\n",*found);
172: # endif
173: *strptr += (lsp - yylstate + 1);
174: return(*found);
175: }
176: }
177: /* the string didn't match anything - if we're looking at
178: * eos, just return 0. Otherwise, bump the string pointer
179: * and return -1.
180: */
181: # ifdef LEXDEBUG
182: fprintf(stdout," No match\n");
183: #endif LEXDEBUG
184: if ( **strptr ) {
185: (*strptr)++;
186: return (-1);
187: }
188: return (0);
189: }
190:
191: #ifdef LEXDEBUG
192: allprint(c)
193: char c;
194: {
195: if ( c < 32 ) {
196: putc( '^', stdout );
197: c += 32;
198: } else if ( c == 127 ) {
199: putc( '^', stdout );
200: c = '?';
201: }
202: putc( c, stdout );
203: }
204: #endif LEXDEBUG
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.