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

Defined functions

tobinary defined in line 69; used 4 times
yylex defined in line 12; never used

Defined struct's

symtab defined in line 21; never used

Defined macros

COFF defined in line 9; used 1 times
  • in line 3
IB defined in line 4; used 1 times
  • in line 3
isid defined in line 3; used 1 times
  • in line 43

Usage of this include

yylex.c used 1 times
Last modified: 1991-08-07
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 2559
Valid CSS Valid XHTML 1.0 Strict