Annotation of 43BSD/ingres/source/equel/number.c, revision 1.1.1.1

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

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.