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

Defined functions

tobinary defined in line 64; used 4 times
yylex defined in line 11; never used

Defined struct's

symtab defined in line 20; never used

Defined macros

COFF defined in line 8; used 1 times
  • in line 2
IB defined in line 3; used 1 times
  • in line 2
isid defined in line 2; used 1 times
  • in line 38

Usage of this include

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