Annotation of 42BSD/ingres/source/parser/s_number.c, revision 1.1.1.1

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

unix.superglobalmegacorp.com

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