yylex(void) { register int c; tbl *tp; begin: while ((c = input()) == ' ' || c == '\n' || c == '\t') ; yylval = c; switch (c) { case EOF: ERROR "unexpected end of input inside equation" WARNING; return(EOF); case '~': return(SPACE); case '^': return(THIN); /* case '\t': return(TAB); */ case '{': return('{'); case '}': return('}'); case '"': for (sp = 0; (c=input())!='"' && c != '\n'; ) { if (c == '\\') if ((c = input()) != '"') token[sp++] = '\\'; token[sp++] = c; if (sp >= SSIZE) ERROR "quoted string %.20s... too long", token FATAL; } token[sp] = '\0'; yylval = (int) &token[0]; if (c == '\n') ERROR "missing \" in %.20s", token WARNING; return(QTEXT); } if (!display && c == righteq) return(EOF); unput(c); getstr(token, SSIZE); dprintf(".\tlex token = |%s|\n", token); if ((tp = lookup(deftbl, token)) != NULL) { /* defined term */ c = input(); unput(c); if (c == '(') /* macro with args */ dodef(tp); else { /* no args */ unput(' '); pbstr(tp->cval); dprintf(".\tfound %s|=%s|\n", token, tp->cval); } goto begin; } if ((tp = lookup(keytbl, token)) == NULL) /* not a keyword */ return CONTIG; switch (tp->ival) { /* some kind of keyword */ case DEFINE: case TDEFINE: case NDEFINE: define(tp->ival); break; case IFDEF: ifdef(); break; case DELIM: delim(); break; case GSIZE: globsize(); break; case GFONT: globfont(); break; case INCLUDE: include(); break; case SPACE: space(); break; case DOTEQ: /* .EQ inside equation -- should warn if at bottom level */ break; case DOTEN: if (curfile == infile) return EOF; /* else ignore nested .EN */ break; default: return tp->ival; } goto begin; }
int yylex(void) { register int c; tbl *tp; extern tbl *keytbl[], *deftbl[]; beg: while ((c=gtc())==' ' || c=='\n') ; yylval.token = c; switch(c) { case EOF: return(EOF); case '~': return(SPACE); case '^': return(THIN); case '\t': return(TAB); case '{': return('{'); case '}': return('}'); case '"': for (sp=0; (c=gtc())!='"' && c != '\n'; ) { if (c == '\\') if ((c = gtc()) != '"') token[sp++] = '\\'; token[sp++] = c; if (sp>=SSIZE) error(FATAL, "quoted string %.20s... too long", token); } token[sp]='\0'; yylval.str = &token[0]; if (c == '\n') error(!FATAL, "missing \" in %.20s", token); return(QTEXT); } if (c==righteq) return(EOF); putbak(c); if (getstr(token, SSIZE)) return EOF; if (dbg)printf(".\tlex token = |%s|\n", token); if ((tp = lookup(deftbl, token, NULL)) != NULL) { putbak(' '); pbstr(tp->defn); putbak(' '); if (dbg) printf(".\tfound %s|=%s|\n", token, tp->defn); } else if ((tp = lookup(keytbl, token, NULL)) == NULL) { if(dbg)printf(".\t%s is not a keyword\n", token); return(CONTIG); } else if ((intptr_t)tp->defn == DEFINE || (intptr_t)tp->defn == NDEFINE || (intptr_t)tp->defn == TDEFINE) define((intptr_t)tp->defn); else if (tp->defn == (char *) DELIM) delim(); else if (tp->defn == (char *) GSIZE) globsize(); else if (tp->defn == (char *) GFONT) globfont(); else if (tp->defn == (char *) INCLUDE) include(); else if (tp->defn == (char *) SPACE) space(); else { return((intptr_t) tp->defn); } goto beg; }