Annotation of researchv9/cmd/cpp/yylex.c, revision 1.1.1.1

1.1       root        1: #define isid(a)  ((fastab+COFF)[a]&IB)
                      2: #define IB 1
                      3: /*     #if '\377' < 0          it would be nice if this worked properly!!!!! */
                      4: #if pdp11 | vax
                      5: #define COFF 128
                      6: #else
                      7: #define COFF 0
                      8: #endif
                      9: 
                     10: yylex() {
                     11:        static int ifdef=0;
                     12:        static char *op2[]={"||",  "&&" , ">>", "<<", ">=", "<=", "!=", "=="};
                     13:        static int  val2[]={OROR, ANDAND,  RS,   LS,   GE,   LE,   NE,   EQ};
                     14:        static char *opc="b\bt\tn\nf\fr\r\\\\";
                     15:        extern char fastab[];
                     16:        extern char *outp,*inp,*newp; extern int flslvl;
                     17:        register char savc, *s; char *skipbl(); int val;
                     18:        register char **p2;
                     19:        struct symtab {
                     20:                char *name;
                     21:                char *value;
                     22:        } *sp, *lookup();
                     23: 
                     24: for (;;) {
                     25:        newp=skipbl(newp);
                     26:        if (*inp=='\n') return(stop);   /* end of #if */
                     27:        savc= *newp; *newp='\0';
                     28:        for (p2=op2+8; --p2>=op2; )     /* check 2-char ops */
                     29:                if (0==strcmp(*p2,inp)) {val=val2[p2-op2]; goto ret;}
                     30:        if (inp[0]=='/' && inp[1]=='*') /* comments */
                     31:            {*newp=savc; outp=inp=newp; continue;}
                     32:        s="+-*/%<>&^|?:!~(),";  /* check 1-char ops */
                     33:        while (*s) if (*s++== *inp) {val= *--s; goto ret;}
                     34:        if (*inp<='9' && *inp>='0') {/* a number */
                     35:                if (*inp=='0') yylval= (inp[1]=='x' || inp[1]=='X') ?
                     36:                        tobinary(inp+2,16) : tobinary(inp+1,8);
                     37:                else yylval=tobinary(inp,10);
                     38:                val=number;
                     39:        } else if (isid(*inp)) {
                     40:                if (0==strcmp(inp,"defined")) {ifdef=1; ++flslvl; val=DEFINED;}
                     41:                else {
                     42:                        sp=lookup(inp,-1); if (ifdef!=0) {ifdef=0; --flslvl;}
                     43:                        yylval= (sp->value==0) ? 0 : 1;
                     44:                        val=number;
                     45:                }
                     46:        } else  if (*inp=='\'') {/* character constant */
                     47:                val=number;
                     48:                if (inp[1]=='\\') {/* escaped */
                     49:                        char c; if (newp[-1]=='\'') newp[-1]='\0';
                     50:                        s=opc;
                     51:                        while (*s) if (*s++!=inp[2]) ++s; else {yylval= *s; goto ret;}
                     52:                        if (inp[2]<='9' && inp[2]>='0') yylval=c=tobinary(inp+2,8);
                     53:                        else yylval=inp[2];
                     54:                } else yylval=inp[1];
                     55:        } else if (0==strcmp("\\\n",inp)) {*newp=savc; continue;}
                     56:        else {
                     57:                *newp=savc; pperror("Illegal character %c in preprocessor if", *inp);
                     58:                continue;
                     59:        }
                     60: ret:
                     61:        *newp=savc; outp=inp=newp; return(val);
                     62: }
                     63: }
                     64: 
                     65: tobinary(st, b) char *st; {
                     66:        int n, c, t;
                     67:        char *s;
                     68:        n=0;
                     69:        s=st;
                     70:        while (c = *s++) {
                     71:        switch(c) {
                     72:                case '0': case '1': case '2': case '3': case '4': 
                     73:                case '5': case '6': case '7': case '8': case '9': 
                     74:                        t = c-'0'; break;
                     75:                case 'a': case 'b': case 'c': case 'd': case 'e': case 'f': 
                     76:                        t = c-'a'+10; if (b>10) break;
                     77:                case 'A': case 'B': case 'C': case 'D': case 'E': case 'F': 
                     78:                        t = c - 'A'+10; if (b>10) break;
                     79:                default:
                     80:                        t = -1;
                     81:                        if ( c=='l' || c=='L') if (*s=='\0') break;
                     82:                        pperror("Illegal number %s", st);
                     83:        }
                     84:        if (t<0) break;
                     85:        n = n*b+t;
                     86:        }
                     87: return(n);
                     88: }

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.