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

Defined functions

Last modified: 1986-04-17
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 998
Valid CSS Valid XHTML 1.0 Strict