1: /*	@(#)yylex.c	2.2	SCCS id keyword	*/
   2: /* Copyright (c) 1979 Regents of the University of California */
   3: #
   4: /*
   5:  * pi - Pascal interpreter code translator
   6:  *
   7:  * Charles Haley, Bill Joy UCB
   8:  * Version 1.2 November 1978
   9:  *
  10:  *
  11:  * pxp - Pascal execution profiler
  12:  *
  13:  * Bill Joy UCB
  14:  * Version 1.2 November 1978
  15:  */
  16: 
  17: #include "whoami"
  18: #include "0.h"
  19: #include "yy.h"
  20: 
  21: /*
  22:  * Scanner
  23:  */
  24: int yylacnt;
  25: 
  26: #define YYLASIZ 10
  27: 
  28: struct  yytok Yla[YYLASIZ];
  29: 
  30: unyylex(y)
  31:     struct yylex *y;
  32: {
  33: 
  34:     if (yylacnt == YYLASIZ)
  35:         panic("unyylex");
  36:     copy(&Yla[yylacnt], y, sizeof Yla[0]);
  37:     yylacnt++;
  38: 
  39: }
  40: 
  41: yylex()
  42: {
  43:     register c;
  44:     register **ip;
  45:     register char *cp;
  46:     int f;
  47:     char delim;
  48: 
  49:     if (yylacnt != 0) {
  50:         yylacnt--;
  51:         copy(&Y, &Yla[yylacnt], sizeof Y);
  52:         return (yychar);
  53:     }
  54:     if (c = yysavc)
  55:         yysavc = 0;
  56:     else
  57:         c = readch();
  58: #ifdef PXP
  59:     yytokcnt++;
  60: #endif
  61: 
  62: next:
  63:     /*
  64: 	 * skip white space
  65: 	 */
  66: #ifdef PXP
  67:     yywhcnt = 0;
  68: #endif
  69:     while (c == ' ' || c == '\t') {
  70: #ifdef PXP
  71:         if (c == '\t')
  72:             yywhcnt++;
  73:         yywhcnt++;
  74: #endif
  75:         c = readch();
  76:     }
  77:     yyecol = yycol;
  78:     yyeline = yyline;
  79:     yyefile = filename;
  80:     yyeseqid = yyseqid;
  81:     yyseekp = yylinpt;
  82:     cp = token;
  83:     yylval = yyline;
  84:     switch (c) {
  85:         case 'a': case 'b': case 'c': case 'd': case 'e': case 'f': case 'g':
  86:         case 'h': case 'i': case 'j': case 'k': case 'l': case 'm': case 'n':
  87:         case 'o': case 'p': case 'q': case 'r': case 's': case 't': case 'u':
  88:         case 'v': case 'w': case 'x': case 'y': case 'z':
  89:         case 'A': case 'B': case 'C': case 'D': case 'E': case 'F': case 'G':
  90:         case 'H': case 'I': case 'J': case 'K': case 'L': case 'M': case 'N':
  91:         case 'O': case 'P': case 'Q': case 'R': case 'S': case 'T': case 'U':
  92:         case 'V': case 'W': case 'X': case 'Y': case 'Z':
  93:             do {
  94:                 *cp++ = c;
  95:                 c = readch();
  96:             } while (alph(c) || digit(c));
  97:             *cp = 0;
  98:             if (opt('s'))
  99:                 for (cp = token; *cp; cp++)
 100:                     if (*cp >= 'A' && *cp <= 'Z') {
 101:                         *cp |= ' ';
 102:                     }
 103:             yysavc = c;
 104:             ip = hash(0, 1);
 105:             if (*ip < yykey || *ip >= lastkey) {
 106:                 yylval = *ip;
 107:                 return (YID);
 108:             }
 109:             yylval = yyline;
 110:             /*
 111: 			 * For keywords
 112: 			 * the lexical token
 113: 			 * is magically retrieved
 114: 			 * from the keyword table.
 115: 			 */
 116:             return ((*ip)[1]);
 117:         case '0': case '1': case '2': case '3': case '4':
 118:         case '5': case '6': case '7': case '8': case '9':
 119:             f = 0;
 120:             do {
 121:                 *cp++ = c;
 122:                 c = readch();
 123:             } while (digit(c));
 124:             if (c == 'b' || c == 'B') {
 125:                 /*
 126: 				 * nonstandard - octal constants
 127: 				 */
 128:                 if (opt('s')) {
 129:                     standard();
 130:                     yerror("Octal constants are non-standard");
 131:                 }
 132:                 *cp = 0;
 133:                 yylval = copystr(token);
 134:                 return (YBINT);
 135:             }
 136:             if (c == '.') {
 137:                 c = readch();
 138:                 if (c == '.') {
 139:                     *cp = 0;
 140:                     yysavc = YDOTDOT;
 141:                     yylval = copystr(token);
 142:                     return (YINT);
 143:                 }
 144: infpnumb:
 145:                 f++;
 146:                 *cp++ = '.';
 147:                 if (!digit(c)) {
 148:                     yyset();
 149:                     recovered();
 150:                     yerror("Digits required after decimal point");
 151:                     *cp++ = '0';
 152:                 } else
 153:                     while (digit(c)) {
 154:                         *cp++ = c;
 155:                         c = readch();
 156:                     }
 157:             }
 158:             if (c == 'e' || c == 'E') {
 159:                 f++;
 160:                 *cp++ = c;
 161:                 if ((c = yysavc) == 0)
 162:                     c = readch();
 163:                 if (c == '+' || c == '-') {
 164:                     *cp++ = c;
 165:                     c = readch();
 166:                 }
 167:                 if (!digit(c)) {
 168:                     yyset();
 169:                     yerror("Digits required in exponent");
 170:                     *cp++ = '0';
 171:                 } else
 172:                     while (digit(c)) {
 173:                         *cp++ = c;
 174:                         c = readch();
 175:                     }
 176:             }
 177:             *cp = 0;
 178:             yysavc = c;
 179:             yylval = copystr(token);
 180:             if (f)
 181:                 return (YNUMB);
 182:             return (YINT);
 183:         case '"':
 184:         case '`':
 185:             if (!any(bufp + 1, c))
 186:                 goto illch;
 187:             if (!dquote) {
 188:                 recovered();
 189:                 dquote++;
 190:                 yerror("Character/string delimiter is '");
 191:             }
 192:         case '\'':
 193:         case '#':
 194:             delim = c;
 195:             do {
 196:                 do {
 197:                     c = readch();
 198:                     if (c == '\n') {
 199:                         yerror("Unmatched %c for string", delim);
 200:                         if (cp == token)
 201:                             *cp++ = ' ', cp++;
 202:                         break;
 203:                     }
 204:                     *cp++ = c;
 205:                 } while (c != delim);
 206:                 c = readch();
 207:             } while (c == delim);
 208:             *--cp = 0;
 209:             if (cp == token) {
 210:                 yerror("Null string not allowed");
 211:                 *cp++ = ' ';
 212:                 *cp++ = 0;
 213:             }
 214:             yysavc = c;
 215:             yylval = copystr(token);
 216:             return (YSTRING);
 217:         case '.':
 218:             c = readch();
 219:             if (c == '.')
 220:                 return (YDOTDOT);
 221:             if (digit(c)) {
 222:                 recovered();
 223:                 yerror("Digits required before decimal point");
 224:                 *cp++ = '0';
 225:                 goto infpnumb;
 226:             }
 227:             yysavc = c;
 228:             return ('.');
 229:         case '{':
 230:             /*
 231: 			 * { ... } comment
 232: 			 */
 233: #ifdef PXP
 234:             getcm(c);
 235: #endif
 236: #ifdef PI
 237:             c = options();
 238:             while (c != '}') {
 239:                 if (c <= 0)
 240:                     goto nonterm;
 241:                 if (c == '{') {
 242:                     warning();
 243:                     yyset();
 244:                     yerror("{ in a { ... } comment");
 245:                 }
 246:                 c = readch();
 247:             }
 248: #endif
 249:             c = readch();
 250:             goto next;
 251:         case '(':
 252:             if ((c = readch()) == '*') {
 253:                 /*
 254: 				 * (* ... *) comment
 255: 				 */
 256: #ifdef PXP
 257:                 getcm(c);
 258:                 c = readch();
 259:                 goto next;
 260: #endif
 261: #ifdef PI
 262:                 c = options();
 263:                 for (;;) {
 264:                     if (c < 0) {
 265: nonterm:
 266:                         yerror("Comment does not terminate - QUIT");
 267:                         pexit(ERRS);
 268:                     }
 269:                     if (c == '(' && (c = readch()) == '*') {
 270:                         warning();
 271:                         yyset();
 272:                         yerror("(* in a (* ... *) comment");
 273:                     }
 274:                     if (c == '*') {
 275:                         if ((c = readch()) != ')')
 276:                             continue;
 277:                         c = readch();
 278:                         goto next;
 279:                     }
 280:                     c = readch();
 281:                 }
 282: #endif
 283:             }
 284:             yysavc = c;
 285:             c = '(';
 286:         case ';':
 287:         case ',':
 288:         case ':':
 289:         case '=':
 290:         case '*':
 291:         case '+':
 292:         case '/':
 293:         case '-':
 294:         case '|':
 295:         case '&':
 296:         case ')':
 297:         case '[':
 298:         case ']':
 299:         case '<':
 300:         case '>':
 301:         case '~':
 302:         case '^':
 303:             return (c);
 304:         default:
 305:             switch (c) {
 306:                 case YDOTDOT:
 307:                     return (c);
 308:                 case '\n':
 309:                     c = readch();
 310: #ifdef PXP
 311:                     yytokcnt++;
 312: #endif
 313:                     goto next;
 314:                 case '\f':
 315:                     c = readch();
 316:                     goto next;
 317:             }
 318:             if (c <= 0)
 319:                 return (YEOF);
 320: illch:
 321:             do
 322:                 yysavc = readch();
 323:             while (yysavc == c);
 324:             yylval = c;
 325:             return (YILLCH);
 326:     }
 327: }
 328: 
 329: yyset()
 330: {
 331: 
 332:     yyecol = yycol;
 333:     yyeline = yyline;
 334:     yyefile = filename;
 335:     yyseekp = yylinpt;
 336: }
 337: 
 338: /*
 339:  * Setuflg trims the current
 340:  * input line to at most 72 chars
 341:  * for the u option.
 342:  */
 343: setuflg()
 344: {
 345: 
 346:     if (charbuf[71] != '\n') {
 347:         charbuf[72] = '\n';
 348:         charbuf[73] = 0;
 349:     }
 350: }

Defined functions

unyylex defined in line 30; used 5 times
yyset defined in line 329; used 4 times

Defined variables

Yla defined in line 28; used 3 times
yylacnt defined in line 24; used 7 times

Defined macros

YYLASIZ defined in line 26; used 2 times
Last modified: 1986-05-31
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 2840
Valid CSS Valid XHTML 1.0 Strict