[project @ 1996-11-15 17:29:21 by sof]
[ghc-hetmet.git] / ghc / utils / ugen / lex.c
1 # include "stdio.h"
2 # define U(x) x
3 # define NLSTATE yyprevious=YYNEWLINE
4 # define BEGIN yybgin = yysvec + 1 +
5 # define INITIAL 0
6 # define YYLERR yysvec
7 # define YYSTATE (yyestate-yysvec-1)
8 # define YYOPTIM 1
9 # define YYLMAX BUFSIZ
10 # define output(c) putc(c,yyout)
11 # define input() (((yytchar=yysptr>yysbuf?U(*--yysptr):getc(yyin))==10?(yylineno++,yytchar):yytchar)==EOF?0:yytchar)
12 # define unput(c) {yytchar= (c);if(yytchar=='\n')yylineno--;*yysptr++=yytchar;}
13 # define yymore() (yymorfg=1)
14 # define ECHO fprintf(yyout, "%s",yytext)
15 # define REJECT { nstr = yyreject(); goto yyfussy;}
16 int yyleng; extern char yytext[];
17 int yymorfg;
18 extern char *yysptr, yysbuf[];
19 int yytchar;
20 FILE *yyin = {stdin}, *yyout = {stdout};
21 extern int yylineno;
22 struct yysvf { 
23         struct yywork *yystoff;
24         struct yysvf *yyother;
25         int *yystops;};
26 struct yysvf *yyestate;
27 extern struct yysvf yysvec[], *yybgin;
28 #define YYSTYPE long
29
30 #ifdef __STDC__
31 #define PROTO(x)        x
32 #else
33 #define PROTO(x)        ()
34 #endif
35
36 # include "syntax.tab.h"
37 # include <stdio.h>
38 # include "id.h"
39 # include "tree.h"
40 # include "funs.h"
41 extern  YYSTYPE yylval;
42 extern  FILE *fc, *fhs;
43 #undef ECHO /* partain */
44 #define ECHO /*fprintf(stderr, "%s", yytext)*/
45
46 # define YYNEWLINE 10
47 yylex(){
48 int nstr; extern int yyprevious;
49 while((nstr = yylook()) >= 0)
50 yyfussy: switch(nstr){
51 case 0:
52 if(yywrap()) return(0); break;
53 case 1:
54                 { ECHO; return(SEMICOL); }
55 break;
56 case 2:
57                 { ECHO; return(COLON); }
58 break;
59 case 3:
60                 { ECHO; return(STDEF); }
61 break;
62 case 4:
63                 { ECHO; return(ENDDEF); }
64 break;
65 case 5:
66                 { ECHO; return(TYPE); }
67 break;
68 case 6:
69                 { ECHO; return(END); }
70 break;
71 case 7:
72 {
73                                 ECHO;
74                                 yylval = (YYSTYPE) installid(yytext);
75                                 return(ID);
76                         }
77 break;
78 case 8:
79                 ECHO;
80 break;
81 case 9:
82                 ECHO;
83 break;
84 case 10:
85 ECHO;
86 break;
87 case 11:
88 { /* partain: for Haskell includes */
89                                 ECHO;
90                                 yytext[yyleng-3] = '\0';
91                                 fprintf(fhs, "\n%s",  &yytext[3]);
92                         }
93 break;
94 case 12:
95 {
96                                 ECHO;
97                                 yytext[yyleng-2] = '\0';
98                                 fprintf(fc, "\n%s",  &yytext[2]);
99                         }
100 break;
101 case -1:
102 break;
103 default:
104 fprintf(yyout,"bad switch yylook %d",nstr);
105 } return(0); }
106 /* end of yylex */
107 int
108 yywrap()
109 {
110         return(1);
111 }
112 int yyvstop[] = {
113 0,
114
115 8,
116 0,
117
118 9,
119 0,
120
121 8,
122 0,
123
124 8,
125 0,
126
127 2,
128 8,
129 0,
130
131 1,
132 8,
133 0,
134
135 3,
136 8,
137 0,
138
139 4,
140 8,
141 0,
142
143 7,
144 8,
145 0,
146
147 7,
148 8,
149 0,
150
151 7,
152 8,
153 0,
154
155 7,
156 0,
157
158 7,
159 0,
160
161 7,
162 0,
163
164 6,
165 7,
166 0,
167
168 7,
169 0,
170
171 12,
172 0,
173
174 10,
175 0,
176
177 5,
178 7,
179 0,
180
181 12,
182 0,
183
184 11,
185 0,
186 0};
187 # define YYTYPE char
188 struct yywork { YYTYPE verify, advance; } yycrank[] = {
189 0,0,    0,0,    1,3,    0,0,    
190 0,0,    0,0,    0,0,    0,0,    
191 0,0,    0,0,    0,0,    1,4,    
192 0,0,    0,0,    0,0,    0,0,    
193 0,0,    0,0,    0,0,    0,0,    
194 0,0,    0,0,    0,0,    0,0,    
195 0,0,    0,0,    0,0,    0,0,    
196 0,0,    0,0,    0,0,    0,0,    
197 0,0,    0,0,    0,0,    0,0,    
198 0,0,    0,0,    1,5,    0,0,    
199 0,0,    0,0,    0,0,    1,3,    
200 6,15,   0,0,    0,0,    15,15,  
201 1,6,    1,3,    20,19,  26,21,  
202 0,0,    0,0,    0,0,    0,0,    
203 15,15,  22,15,  0,0,    1,7,    
204 1,8,    1,9,    22,27,  1,10,   
205 0,0,    0,0,    1,11,   2,7,    
206 2,8,    2,9,    0,0,    2,10,   
207 0,0,    0,0,    0,0,    0,0,    
208 0,0,    0,0,    0,0,    0,0,    
209 0,0,    0,0,    0,0,    15,15,  
210 0,0,    0,0,    0,0,    0,0,    
211 15,22,  0,0,    0,0,    0,0,    
212 0,0,    15,15,  15,15,  0,0,    
213 0,0,    0,0,    0,0,    0,0,    
214 0,0,    0,0,    1,12,   0,0,    
215 0,0,    0,0,    0,0,    0,0,    
216 0,0,    0,0,    2,12,   15,15,  
217 17,23,  24,28,  0,0,    0,0,    
218 0,0,    1,13,   0,0,    0,0,    
219 12,17,  0,0,    0,0,    18,24,  
220 5,14,   2,13,   1,3,    11,16,  
221 11,16,  11,16,  11,16,  11,16,  
222 11,16,  11,16,  11,16,  11,16,  
223 11,16,  13,18,  20,25,  26,29,  
224 29,30,  0,0,    0,0,    0,0,    
225 11,16,  11,16,  11,16,  11,16,  
226 11,16,  11,16,  11,16,  11,16,  
227 11,16,  11,16,  11,16,  11,16,  
228 11,16,  11,16,  11,16,  11,16,  
229 11,16,  11,16,  11,16,  11,16,  
230 11,16,  11,16,  11,16,  11,16,  
231 11,16,  11,16,  0,0,    15,15,  
232 0,0,    0,0,    11,16,  0,0,    
233 11,16,  11,16,  11,16,  11,16,  
234 11,16,  11,16,  11,16,  11,16,  
235 11,16,  11,16,  11,16,  11,16,  
236 11,16,  11,16,  11,16,  11,16,  
237 11,16,  11,16,  11,16,  11,16,  
238 11,16,  11,16,  11,16,  11,16,  
239 11,16,  11,16,  14,19,  0,0,    
240 19,19,  0,0,    21,21,  0,0,    
241 0,0,    0,0,    0,0,    14,19,  
242 0,0,    19,19,  0,0,    21,21,  
243 0,0,    0,0,    0,0,    0,0,    
244 0,0,    0,0,    0,0,    0,0,    
245 0,0,    0,0,    0,0,    0,0,    
246 0,0,    0,0,    0,0,    0,0,    
247 0,0,    0,0,    0,0,    0,0,    
248 0,0,    0,0,    14,20,  0,0,    
249 19,20,  0,0,    21,26,  14,19,  
250 0,0,    19,19,  0,0,    21,21,  
251 14,19,  14,19,  19,19,  19,19,  
252 21,21,  21,21,  0,0,    0,0,    
253 0,0,    0,0,    0,0,    0,0,    
254 0,0,    0,0,    0,0,    0,0,    
255 0,0,    0,0,    14,19,  0,0,    
256 19,19,  0,0,    21,21,  0,0,    
257 0,0,    0,0,    0,0,    0,0,    
258 0,0,    0,0,    0,0,    0,0,    
259 0,0,    0,0,    0,0,    0,0,    
260 0,0,    0,0,    0,0,    0,0,    
261 0,0,    0,0,    0,0,    0,0,    
262 0,0,    0,0,    0,0,    0,0,    
263 0,0,    0,0,    0,0,    0,0,    
264 0,0,    0,0,    0,0,    0,0,    
265 0,0,    0,0,    0,0,    0,0,    
266 0,0,    0,0,    0,0,    0,0,    
267 0,0,    0,0,    0,0,    0,0,    
268 0,0,    0,0,    0,0,    0,0,    
269 0,0,    0,0,    0,0,    0,0,    
270 14,21,  0,0,    14,19,  0,0,    
271 19,19,  0,0,    21,21,  0,0,    
272 0,0};
273 struct yysvf yysvec[] = {
274 0,      0,      0,
275 yycrank+-1,     0,              0,      
276 yycrank+-9,     yysvec+1,       0,      
277 yycrank+0,      0,              yyvstop+1,
278 yycrank+0,      0,              yyvstop+3,
279 yycrank+1,      0,              yyvstop+5,
280 yycrank+2,      0,              yyvstop+7,
281 yycrank+0,      0,              yyvstop+9,
282 yycrank+0,      0,              yyvstop+12,
283 yycrank+0,      0,              yyvstop+15,
284 yycrank+0,      0,              yyvstop+18,
285 yycrank+79,     0,              yyvstop+21,
286 yycrank+10,     yysvec+11,      yyvstop+24,
287 yycrank+16,     yysvec+11,      yyvstop+27,
288 yycrank+-201,   0,              0,      
289 yycrank+-46,    0,              0,      
290 yycrank+0,      yysvec+11,      yyvstop+30,
291 yycrank+12,     yysvec+11,      yyvstop+32,
292 yycrank+11,     yysvec+11,      yyvstop+34,
293 yycrank+-203,   0,              0,      
294 yycrank+-13,    yysvec+19,      0,      
295 yycrank+-205,   0,              0,      
296 yycrank+-15,    yysvec+15,      0,      
297 yycrank+0,      yysvec+11,      yyvstop+36,
298 yycrank+12,     yysvec+11,      yyvstop+39,
299 yycrank+0,      0,              yyvstop+41,
300 yycrank+-14,    yysvec+21,      0,      
301 yycrank+0,      0,              yyvstop+43,
302 yycrank+0,      yysvec+11,      yyvstop+45,
303 yycrank+15,     0,              yyvstop+48,
304 yycrank+0,      0,              yyvstop+50,
305 0,      0,      0};
306 struct yywork *yytop = yycrank+330;
307 struct yysvf *yybgin = yysvec+1;
308 char yymatch[] = {
309 00  ,01  ,01  ,01  ,01  ,01  ,01  ,01  ,
310 01  ,01  ,012 ,01  ,01  ,01  ,01  ,01  ,
311 01  ,01  ,01  ,01  ,01  ,01  ,01  ,01  ,
312 01  ,01  ,01  ,01  ,01  ,01  ,01  ,01  ,
313 01  ,01  ,01  ,01  ,01  ,'%' ,01  ,01  ,
314 01  ,01  ,'*' ,01  ,01  ,01  ,01  ,'/' ,
315 '0' ,'0' ,'0' ,'0' ,'0' ,'0' ,'0' ,'0' ,
316 '0' ,'0' ,01  ,01  ,01  ,01  ,01  ,01  ,
317 01  ,'A' ,'A' ,'A' ,'A' ,'A' ,'A' ,'A' ,
318 'A' ,'A' ,'A' ,'A' ,'A' ,'A' ,'A' ,'A' ,
319 'A' ,'A' ,'A' ,'A' ,'A' ,'A' ,'A' ,'A' ,
320 'A' ,'A' ,'A' ,01  ,01  ,01  ,01  ,'0' ,
321 01  ,'A' ,'A' ,'A' ,'A' ,'A' ,'A' ,'A' ,
322 'A' ,'A' ,'A' ,'A' ,'A' ,'A' ,'A' ,'A' ,
323 'A' ,'A' ,'A' ,'A' ,'A' ,'A' ,'A' ,'A' ,
324 'A' ,'A' ,'A' ,01  ,01  ,'}' ,01  ,01  ,
325 0};
326 char yyextra[] = {
327 0,0,0,0,0,0,0,0,
328 0,0,0,0,0,0,0,0,
329 0};
330 #ifndef lint
331 static  char ncform_sccsid[] = "@(#)ncform 1.6 88/02/08 SMI"; /* from S5R2 1.2 */
332 #endif
333
334 int yylineno =1;
335 # define YYU(x) x
336 # define NLSTATE yyprevious=YYNEWLINE
337 char yytext[YYLMAX];
338 struct yysvf *yylstate [YYLMAX], **yylsp, **yyolsp;
339 char yysbuf[YYLMAX];
340 char *yysptr = yysbuf;
341 int *yyfnd;
342 extern struct yysvf *yyestate;
343 int yyprevious = YYNEWLINE;
344 yylook(){
345         register struct yysvf *yystate, **lsp;
346         register struct yywork *yyt;
347         struct yysvf *yyz;
348         int yych, yyfirst;
349         struct yywork *yyr;
350 # ifdef LEXDEBUG
351         int debug;
352 # endif
353         char *yylastch;
354         /* start off machines */
355 # ifdef LEXDEBUG
356         debug = 0;
357 # endif
358         yyfirst=1;
359         if (!yymorfg)
360                 yylastch = yytext;
361         else {
362                 yymorfg=0;
363                 yylastch = yytext+yyleng;
364                 }
365         for(;;){
366                 lsp = yylstate;
367                 yyestate = yystate = yybgin;
368                 if (yyprevious==YYNEWLINE) yystate++;
369                 for (;;){
370 # ifdef LEXDEBUG
371                         if(debug)fprintf(yyout,"state %d\n",yystate-yysvec-1);
372 # endif
373                         yyt = yystate->yystoff;
374                         if(yyt == yycrank && !yyfirst){  /* may not be any transitions */
375                                 yyz = yystate->yyother;
376                                 if(yyz == 0)break;
377                                 if(yyz->yystoff == yycrank)break;
378                                 }
379                         *yylastch++ = yych = input();
380                         yyfirst=0;
381                 tryagain:
382 # ifdef LEXDEBUG
383                         if(debug){
384                                 fprintf(yyout,"char ");
385                                 allprint(yych);
386                                 putchar('\n');
387                                 }
388 # endif
389                         yyr = yyt;
390                         if ( (int)yyt > (int)yycrank){
391                                 yyt = yyr + yych;
392                                 if (yyt <= yytop && yyt->verify+yysvec == yystate){
393                                         if(yyt->advance+yysvec == YYLERR)       /* error transitions */
394                                                 {unput(*--yylastch);break;}
395                                         *lsp++ = yystate = yyt->advance+yysvec;
396                                         goto contin;
397                                         }
398                                 }
399 # ifdef YYOPTIM
400                         else if((int)yyt < (int)yycrank) {              /* r < yycrank */
401                                 yyt = yyr = yycrank+(yycrank-yyt);
402 # ifdef LEXDEBUG
403                                 if(debug)fprintf(yyout,"compressed state\n");
404 # endif
405                                 yyt = yyt + yych;
406                                 if(yyt <= yytop && yyt->verify+yysvec == yystate){
407                                         if(yyt->advance+yysvec == YYLERR)       /* error transitions */
408                                                 {unput(*--yylastch);break;}
409                                         *lsp++ = yystate = yyt->advance+yysvec;
410                                         goto contin;
411                                         }
412                                 yyt = yyr + YYU(yymatch[yych]);
413 # ifdef LEXDEBUG
414                                 if(debug){
415                                         fprintf(yyout,"try fall back character ");
416                                         allprint(YYU(yymatch[yych]));
417                                         putchar('\n');
418                                         }
419 # endif
420                                 if(yyt <= yytop && yyt->verify+yysvec == yystate){
421                                         if(yyt->advance+yysvec == YYLERR)       /* error transition */
422                                                 {unput(*--yylastch);break;}
423                                         *lsp++ = yystate = yyt->advance+yysvec;
424                                         goto contin;
425                                         }
426                                 }
427                         if ((yystate = yystate->yyother) && (yyt= yystate->yystoff) != yycrank){
428 # ifdef LEXDEBUG
429                                 if(debug)fprintf(yyout,"fall back to state %d\n",yystate-yysvec-1);
430 # endif
431                                 goto tryagain;
432                                 }
433 # endif
434                         else
435                                 {unput(*--yylastch);break;}
436                 contin:
437 # ifdef LEXDEBUG
438                         if(debug){
439                                 fprintf(yyout,"state %d char ",yystate-yysvec-1);
440                                 allprint(yych);
441                                 putchar('\n');
442                                 }
443 # endif
444                         ;
445                         }
446 # ifdef LEXDEBUG
447                 if(debug){
448                         fprintf(yyout,"stopped at %d with ",*(lsp-1)-yysvec-1);
449                         allprint(yych);
450                         putchar('\n');
451                         }
452 # endif
453                 while (lsp-- > yylstate){
454                         *yylastch-- = 0;
455                         if (*lsp != 0 && (yyfnd= (*lsp)->yystops) && *yyfnd > 0){
456                                 yyolsp = lsp;
457                                 if(yyextra[*yyfnd]){            /* must backup */
458                                         while(yyback((*lsp)->yystops,-*yyfnd) != 1 && lsp > yylstate){
459                                                 lsp--;
460                                                 unput(*yylastch--);
461                                                 }
462                                         }
463                                 yyprevious = YYU(*yylastch);
464                                 yylsp = lsp;
465                                 yyleng = yylastch-yytext+1;
466                                 yytext[yyleng] = 0;
467 # ifdef LEXDEBUG
468                                 if(debug){
469                                         fprintf(yyout,"\nmatch ");
470                                         sprint(yytext);
471                                         fprintf(yyout," action %d\n",*yyfnd);
472                                         }
473 # endif
474                                 return(*yyfnd++);
475                                 }
476                         unput(*yylastch);
477                         }
478                 if (yytext[0] == 0  /* && feof(yyin) */)
479                         {
480                         yysptr=yysbuf;
481                         return(0);
482                         }
483                 yyprevious = yytext[0] = input();
484                 if (yyprevious>0)
485                         output(yyprevious);
486                 yylastch=yytext;
487 # ifdef LEXDEBUG
488                 if(debug)putchar('\n');
489 # endif
490                 }
491         }
492 yyback(p, m)
493         int *p;
494 {
495 if (p==0) return(0);
496 while (*p)
497         {
498         if (*p++ == m)
499                 return(1);
500         }
501 return(0);
502 }
503         /* the following are only used in the lex library */
504 yyinput(){
505         return(input());
506         }
507 yyoutput(c)
508   int c; {
509         output(c);
510         }
511 yyunput(c)
512    int c; {
513         unput(c);
514         }