- char str[], /* string to return token in */
- int strsize, /* maximum length of token string */
- double *fnum, /* floating point value of number read */
- int *inum /* integer value of number read */
-)
-{
- int c, sp, isSigned;
- double sign, whole, frac, powerof10, exp, expsign;
-
- sp = 0;
- sign = 1.0;
- isSigned = FALSE; /* TRUE if number prefixed by '+' or '-' */
- *fnum = 0.0;
- *inum = 0;
- str[0] = EOS;
-
- c = inchar();
- if (c == HYPHEN) {
- str[sp++] = c;
- isSigned = TRUE;
- sign = -1.0;
- } else if (c == PLUS) {
- str[sp++] = c;
- isSigned = TRUE;
- sign = 1.0;
- } else if (c == PERIOD) {
- if (type(lookchar()) != DIGIT) {
- str[0] = PERIOD;
- str[1] = EOS;
- return (TT_SPECLCHAR);
- } else
- ungetch (PERIOD);
- } else if (type(c) != DIGIT) {
- ungetch (c);
- return (TT_ERROR);
- } else
- ungetch (c);
-
- if (isSigned == TRUE) {
- c = lookchar();
- if (c == PERIOD) {
- inchar(); /* get period */
- c = lookchar(); /* look at character past period */
- ungetch (PERIOD); /* put back period */
- if (type(c) != DIGIT) {
- str[sp] = EOS;
- return (TT_SPECLCHAR);
- }
- } else if (type (c) != DIGIT) {
- str[sp] = EOS;
- return (TT_SPECLCHAR);
- }
- }
-
- whole = 0.0;
- while (type(c = inchar()) == DIGIT) {
- if (sp < strsize)
- str[sp++] = c;
- whole = 10.0 * whole + (c - '0');
- }
- ungetch (c); /* put back non-numeric character */
-
- if (c != PERIOD && tolower(c) != 'e') {
- str[sp] = EOS;
- *fnum = whole * sign;
- if (*fnum < MIN_INT)
- *inum = MIN_INT;
- else if (*fnum > MAX_INT)
- *inum = MAX_INT;
- else
- *inum = (int) *fnum;
- return (TT_INT);
- }
-
- if (lookchar() == PERIOD) {
- inchar();
- if (sp < strsize)
- str[sp++] = PERIOD;
- }
-
- frac = 0.0;
- powerof10 = 10.0;
-
- while (type(c = inchar()) == DIGIT) {
- if (sp < strsize)
- str[sp++] = c;
- frac += (double) (c - '0') / powerof10;
- powerof10 *= 10.0;
- }
- ungetch (c);
-
- exp = 0.0;
- expsign = 1.0;
- c = inchar();
- if (tolower(c) != 'e')
- ungetch (c);
- else {
- if (sp < strsize)
- str[sp++] = c;
- if ((c = inchar()) == PLUS) {
- if (sp < strsize)
- str[sp++] = c;
- expsign = 1.0;
- } else if (c == HYPHEN) {
- if (sp < strsize)
- str[sp++] = c;
- expsign = -1.0;
- } else if (type(c) != DIGIT) {
- --sp; /* erase 'e' */
- ungetch (c);
- ungetch ('e');
- goto getnumexit;
- } else
- ungetch(c);
-
- exp = 0;
- while (type(c = inchar()) == DIGIT) {
- if (sp < strsize)
- str[sp++] = c;
- exp = 10 * exp + (c - '0');
- }
- ungetch (c);
- }
-
-getnumexit:
- str[sp] = EOS;
- *fnum = sign * (whole + frac) * pow (10.0, expsign * exp);
- if (*fnum < MIN_INT)
- *inum = MIN_INT;
- else if (*fnum > MAX_INT)
- *inum = MAX_INT;
- else
- *inum = (int) *fnum;
- return (TT_REAL);
-}
-
-void
-POL::eatline ()
-{
- char term [2];
-
- term[0] = NEWLINE;
- term[1] = EOS;
- skiptok (term);
-}
-
-// return type of ASCII character
-int
-POL::type (int c)
-{
- if (isalpha(c) || c == UNDERLIN)
- return (LETTER);
- else if (isdigit(c))
- return (DIGIT);
- else
- return (c);
-}
-
-/*----------------------------------------------------------------------*/
-/* */
-/* hash table routines. Kernighan & Ritchie */
-/* */
-/*----------------------------------------------------------------------*/
-
-/* inittable (table)
- * clear symbol table
-*/
+ char str[], /* string to return token in */
+ int strsize, /* maximum length of token string */
+ double *fnum, /* floating point value of number read */
+ int *inum /* integer value of number read */
+ )
+{
+ int sp = 0;
+ double sign = 1.0;
+ bool isSigned = false; /* true if number prefixed by '+' or '-' */
+ *fnum = 0.0;
+ *inum = 0;
+ str[0] = EOS;
+
+ int c = inchar();
+ if (c == HYPHEN) {
+ str[sp++] = c;
+ isSigned = true;
+ sign = -1.0;
+ } else if (c == PLUS) {
+ str[sp++] = c;
+ isSigned = true;
+ sign = 1.0;
+ } else if (c == PERIOD) {
+ if (type(lookchar()) != DIGIT) {
+ str[0] = PERIOD;
+ str[1] = EOS;
+ return (TT_SPECLCHAR);
+ } else
+ ungetch (PERIOD);
+ } else if (type(c) != DIGIT) {
+ ungetch (c);
+ return (TT_ERROR);
+ } else
+ ungetch (c);
+
+ if (isSigned) {
+ c = lookchar();
+ if (c == PERIOD) {
+ inchar(); /* get period */
+ c = lookchar(); /* look at character past period */
+ ungetch (PERIOD); /* put back period */
+ if (type(c) != DIGIT) {
+ str[sp] = EOS;
+ return (TT_SPECLCHAR);
+ }
+ } else if (type (c) != DIGIT) {
+ str[sp] = EOS;
+ return (TT_SPECLCHAR);
+ }
+ }