1: # include   "../ingres.h"
   2: # include   "../aux.h"
   3: # include   "../scanner.h"
   4: 
   5: /*
   6: ** NUMBER
   7: **	scans numerical constants (both integer and floating).  Each
   8: **	constant is converted from ascii to its numerical representation
   9: **	and is entered into the symbol table, indexed by 'yylval'.
  10: **	A token is returned for the number type.
  11: **
  12: **	due to the current atof in the utility library, floating overflow
  13: **	is not checked.
  14: */
  15: number(chr)
  16: char    chr;
  17: {
  18:     extern char Cmap[];
  19:     extern int  yylval;
  20:     double      ftemp;
  21:     long        ltemp;
  22:     int     itemp;
  23:     char        buf[256];
  24:     register int    lsave;
  25:     register char   *ptr;
  26: 
  27:     lsave = Lcase;
  28:     Lcase = 0;
  29:     ptr = buf;
  30:     if ((*ptr = chr) != '.')
  31:     {
  32:         do
  33:         {
  34:             /* get integer portion */
  35:             if ((ptr - buf) >= 256)
  36:                 /* buffer overflow */
  37:                 yyerror(NUMBUFOFLO, 0);
  38:             *++ptr = gtchar();
  39:         } while (Cmap[*ptr] == NUMBR);
  40:     }
  41: 
  42:     /* do rest of type determination */
  43:     switch (*ptr)
  44:     {
  45:       case '.':
  46:         /* floating point */
  47:         do
  48:         {
  49:             /* fill into ptr with up to next non-digit */
  50:             if ((ptr - buf) >= 256)
  51:                 yyerror(NUMBUFOFLO, 0); /* buf oflo */
  52:             *++ptr = gtchar();
  53:         } while (Cmap[*ptr] == NUMBR);
  54:         if (*ptr != 'e' && *ptr != 'E')
  55:         {
  56:             backup(*ptr);
  57:             *ptr = 0;
  58:             goto convr;
  59:         }
  60: 
  61:       case 'e':
  62:       case 'E':
  63:         if ((ptr - buf) >= 256)
  64:             yyerror(NUMBUFOFLO, 0); /* buf oflo */
  65:         *++ptr = gtchar();
  66:         if (Cmap[*ptr] == NUMBR || *ptr == '-' || *ptr == '+')
  67:         {
  68:             do
  69:             {
  70:                 /* get exponent */
  71:                 if ((ptr - buf) >= 256)
  72:                     yyerror(NUMBUFOFLO, 0); /* buf oflo */
  73:                 *++ptr = gtchar();
  74:             } while (Cmap[*ptr] == NUMBR);
  75:         }
  76:         backup(*ptr);
  77:         *ptr = 0;
  78:     convr:
  79:         if (atof(buf, &ftemp))
  80:             yyerror(FCONSTERR, buf, 0); /* floating conversion error */
  81:         yylval = syment(&ftemp, 8);
  82:         Lastok.toktyp = Tokens.f8const;
  83:         break;
  84: 
  85:       default:
  86:         /* integer */
  87:         backup(*ptr);
  88:         *ptr = 0;
  89:         if (atol(buf, &ltemp))  /* long conversion error */
  90:             goto convr;
  91:         if (ltemp > 32767)
  92:         {
  93:             yylval = syment(&ltemp, 4);
  94:             Lastok.toktyp = Tokens.i4const;
  95:             break;
  96:         }
  97:         itemp = ltemp;
  98:         yylval = syment(&itemp, 2);
  99:         Lastok.toktyp = Tokens.i2const;
 100:         break;
 101:     }
 102:     Lcase = lsave;
 103:     Lastok.tok = (char *) yylval;
 104:     Lastok.tokop = 0;
 105:     return (Lastok.toktyp);
 106: }

Defined functions

Last modified: 1995-02-18
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 2625
Valid CSS Valid XHTML 1.0 Strict