Pristine Ack-5.5
[Ack-5.5.git] / util / ncgg / scan.l
1 %{
2 /*
3  * (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
4  * See the copyright notice in the ACK home directory, in the file "Copyright".
5  */
6 #ifndef NORCSID
7 static char rcsid2[]= "$Id: scan.l,v 0.6 1994/06/24 10:38:11 ceriel Exp $";
8 #endif
9
10 char *mystrcpy();
11 int   myatoi();
12
13 int lineno=1;
14 extern char *filename;
15 #undef yywrap
16 %}
17
18 %%
19 "/*"                    { char c;
20                           c = input(); if (c=='\n') lineno++;
21                           do {
22                                 while (c!='*') {
23                                         c = input();
24                                         if (c=='\n') lineno++;
25                                 }
26                                 c = input();
27                                 if (c=='\n') lineno++;
28                           } while (c!='/');
29                         }
30 ^\#(line)?[ \t]*[0-9]+[ \t]+\".*\".*$   {
31                           int ind,ind2;
32                           for (ind=0; yytext[ind] < '0' || yytext[ind]>'9'; ind++)
33                                 ;
34                           lineno=atoi(&yytext[ind])-1;
35                           for(;yytext[ind]!='"';ind++)
36                                 ;
37                           for(ind2=ind+1;yytext[ind2]!='"';ind2++)
38                                 ;
39                           yytext[ind2]=0;
40                           if (strcmp(yytext+ind+1,filename)!=0)
41                                 filename=mystrcpy(yytext+ind+1);
42                         }
43 "=="                    return(CMPEQ);
44 "!="                    return(CMPNE);
45 "<"                     return(CMPLT);
46 "<="                    return(CMPLE);
47 ">"                     return(CMPGT);
48 ">="                    return(CMPGE);
49 "||"                    return(OR2);
50 "&&"                    return(AND2);
51 "<<"                    return(LSHIFT);
52 ">>"                    return(RSHIFT);
53 "!"                     return(NOT);
54 "~"                     return(COMP); 
55 ":ro"                   { yylval.yy_int = AD_RO; return(ADORNACCESS);  }
56 ":wo"                   { yylval.yy_int = AD_WO; return(ADORNACCESS);  }
57 ":rw"                   { yylval.yy_int = AD_RW; return(ADORNACCESS);  }
58 ":cc"                   { yylval.yy_int = AD_CC; return(ADORNCC);  }
59 \$[0-9]+                { yylval.yy_int = atoi(yytext+1); return(DOLLAR); }
60 \%[0-9]+                { yylval.yy_int = atoi(yytext+1); return(PERCENT); }
61 \%[a-z]                 { yylval.yy_int = yytext[1]-'a'; return(ALLREG); }
62 [0-9]+|0x[0-9A-Fa-f]+   { yylval.yy_int = myatoi(yytext); return(NUMBER); }
63 [_A-Za-z][_A-Za-z0-9]*  { register symbol *sy_p;
64                           if (yyleng==3 &&
65                               emhere &&
66                               (yylval.yy_int=mlookup(yytext))!=0) {
67                                 return(EMMNEM);
68                           }
69                           if ((sy_p=lookup(yytext,symkeyw,justlooking))!=0)
70                                  return(sy_p->sy_value.syv_keywno); 
71                           yylval.yy_str = mystrcpy(yytext); return(IDENT);
72                         }
73 \%[_A-Za-z][_A-Za-z0-9]* { yylval.yy_str = mystrcpy(yytext+1);
74                            return(PERC_IDENT);
75                          }
76 \"[^"\n]*\"             { yytext[yyleng-1]=0;
77                           yylval.yy_str = mystrcpy(yytext+1);
78                           return(STRING);
79                         }
80 [0-9][bf]               { yytext[2]=0;
81                           yylval.yy_str = mystrcpy(yytext);
82                           return(STRING);
83                         }
84 \n                      { lineno++; }
85 [ \t]*                  ;
86 .                       return(yytext[0]);
87 %%
88 int skipping=0;
89
90 yywrap() {
91
92         if (skipping)
93                 fatal("EOF reached during error recovery");
94         return(1);
95 }
96
97 skipupto(tok,str) char *str; {
98         register i; 
99
100         skipping=1; 
101         while (yylex()!=tok)
102                 ;
103         for(i=strlen(str); i>0; i--)
104                 unput(str[i-1]);
105         skipping=0; 
106 }