int POL::gettok (TOKEN *tok) { int c, toktype; int inum; double fnum; int toksiz = MAXTOK; /* maximum length of token string */ while ((c = inchar()) == BLANK || c == TAB) ; ungetch (c); c = lookchar(); toktype = type(c); fnum = 0.0; inum = 0; if (c == BLANK || c == TAB) { /* skip white space */ getblank(tok->tokstr, toksiz); toktype = TT_BLANK; } else if (toktype == LETTER) { toktype = getalpha (tok->tokstr, toksiz); } else if (c == meta.str) { /* quoted string */ getquote (tok->tokstr, toksiz); toktype = TT_STRING; } else if (type(c) == DIGIT || c == PLUS || c == HYPHEN || c == PERIOD) { toktype = getnumber (tok->tokstr, toksiz, &fnum, &inum); } else if (c == EOF) { tok->tokstr[0] = EOS; toktype = TT_EOF; } else { c = inchar(); tok->tokstr[0] = c; tok->tokstr[1] = EOS; toktype = TT_SPECLCHAR; } tok->type = toktype; tok->ready = true; if (tok->type == TT_REAL || tok->type == TT_INT) { tok->fnum = fnum; tok->inum = inum; } else { tok->fnum = 0.0; tok->inum = 0; } return (toktype); }
BOOL getword_switch(){ static char ch = ' '; if(EOF == ch){ return FALSE; } getblank(&ch); if(getnumber(&ch)){ return TRUE; } if(getidentify(&ch)){ return TRUE; } getdouble_or_single_token(&ch); return TRUE; }