1: #
   2: # include   <stdio.h>
   3: 
   4: # include   "constants.h"
   5: # include   "globals.h"
   6: 
   7: /*
   8: **  NUMBER -- process a numeric token
   9: **	Number gets a number as, either floating or integer,
  10: **	with the QUEL format, from inside a quel statement,
  11: **	and adds it to the symbol space.
  12: **
  13: **	Parameters:
  14: **		chr -- the first character of the number
  15: **
  16: **	Returns:
  17: **		The lexical code for the appropriate
  18: **		type of number.
  19: **
  20: **	Side Effects:
  21: **		Adds a token to the symbols space.
  22: **		yylval is set to the node added.
  23: **
  24: **	Called By:
  25: **		yylex()
  26: **		operator()
  27: **
  28: **	Files:
  29: **		globals.h
  30: **		constants.h
  31: **
  32: **	History:
  33: **		4/20/78 -- (marc) plagiarized from rick berman's
  34: **			quel scanner number routine, and modified to
  35: **			handle errors differently.
  36: */
  37: 
  38: 
  39: number(chr)
  40: char    chr;
  41: {
  42:     extern char Cmap [];
  43:     extern int  yylval;
  44:     double      ftemp;
  45:     long        ltemp;
  46:     int     itemp;
  47:     char        buf [256];
  48:     register char   *ptr;
  49:     register int    ret_type;
  50: 
  51:     ptr = buf;
  52:     if ((*ptr = chr) != '.')
  53:     {
  54:         do
  55:         {
  56:             /* get integer portion */
  57:             if ((ptr - buf) >= 256)
  58:             {
  59:                 /* buffer overflow
  60: 				 * return integer 0,
  61: 				 * and signal error.
  62: 				 */
  63: 
  64: bufovflo :
  65:                 *ptr = '\0';
  66:                 yysemerr("numeric too long", buf);
  67:                 yylval = addsym("0");
  68:                 return (Tokens.sp_i2const);
  69:             }
  70: 
  71:             *++ptr = getch();
  72:         }  while (Cmap[*ptr] == NUMBR);
  73:     }
  74: 
  75:     /* do rest of type determination */
  76:     switch (*ptr)
  77:     {
  78:       case '.':
  79:         /* floating point */
  80:         do
  81:         {
  82:             /* fill into ptr with up to next non-digit */
  83:             if ((ptr - buf) >= 256)
  84:                 /* buf oflo */
  85:                 goto bufovflo;
  86:             *++ptr = getch();
  87:         }  while (Cmap[*ptr] == NUMBR);
  88:         if (*ptr != 'e' && *ptr != 'E')
  89:         {
  90:             backup(*ptr);
  91:             *ptr = '\0';
  92:             goto convr;
  93:         }
  94: 
  95:       case 'e':
  96:       case 'E':
  97:         if ((ptr - buf) >= 256)
  98:             /* buf oflo */
  99:             goto bufovflo;
 100:         *++ptr = getch();
 101:         if (Cmap[*ptr] == NUMBR || *ptr == '-' || *ptr == '+')
 102:         {
 103:             do
 104:             {
 105:                 /* get exponent */
 106:                 if ((ptr - buf) >= 256)
 107:                     /* buf oflo */
 108:                     goto bufovflo;
 109:                 *++ptr = getch();
 110:             } while (Cmap[*ptr] == NUMBR);
 111:         }
 112:         backup(*ptr);
 113:         *ptr = '\0';
 114: 
 115: convr:
 116:         if (atof(buf, &ftemp))
 117:         {
 118:             /* floating conversion error */
 119:             yysemerr("numeric ofverflow", buf);
 120:             yylval = addsym("0");
 121:             return (Tokens.sp_f8const);
 122:         }
 123:         yylval = addsym(salloc(buf));
 124:         ret_type = Tokens.sp_f8const;
 125:         break;
 126: 
 127:       default:
 128:         /* integer */
 129:         backup(*ptr);
 130:         *ptr = '\0';
 131: 
 132:         /* long conversion error */
 133:         if (atol(buf, &ltemp) || ltemp > 32767
 134:            || ltemp < -32768)
 135:             goto convr;
 136:         itemp = ltemp;
 137:         yylval = addsym(salloc(buf));
 138:         ret_type = Tokens.sp_i2const;
 139:         break;
 140:     }
 141:     return (ret_type);
 142: }

Defined functions

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