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

1.1       root        1: # include      <ingres.h>
                      2: # include      "scanner.h"
                      3: # include      <sccs.h>
                      4: 
                      5: SCCSID(@(#)s_yylex.c   7.2     5/4/83)
                      6: 
                      7: struct special Tokens;                 /* special tokens table */
                      8: struct optab   Optab[];                /* operator table */
                      9: struct optab   Keyword[];              /* keyword table */
                     10: struct lastok  Lastok;
                     11: int            Opcode;                 /* opcode for current token */
                     12: int            Lcase;                  /* UPPER->lower conversion flag */
                     13: int            Pars;                   /* flag for call to getcvar or not */
                     14: int            Newline;                /* set if last char read was a newline */
                     15: int            Cflag;                  /* set if line of C-code recognized */
                     16: int            Keyent;                 /* number of entries in the Keyword table */
                     17: 
                     18: char           Sbuf[SBUFSIZ];          /* symbol table buffer */
                     19: 
                     20: /*
                     21: ** YYLEX
                     22: ** This is the control program for the scanner (lexical analyzer).
                     23: ** Each call to yylex() returns a token for the next syntactic unit.
                     24: ** If the object is of type I2CONST, I4CONST, F8CONST, SCONST or NAME, that
                     25: ** object will also be entered in the symbol table, indexed by 'yylval'.
                     26: ** If the object is not one of these types, yylval is the opcode field of
                     27: ** the operator or keyword tables.
                     28: ** The end-of-file token is zero.
                     29: */
                     30: yylex()
                     31: {
                     32:        register char   chr;
                     33:        register int    rtval;
                     34:        extern char     Cmap[];
                     35: 
                     36:        rtval = -1;
                     37:        Lastok.tokop = 0;
                     38:        /* GET NEXT TOKEN */
                     39:        do
                     40:        {
                     41:                if((chr = get_scan(NORMAL)) <= 0)
                     42:                {
                     43: #                      ifdef   xSTR2
                     44:                        tTfp(72, 8, "end-of-file\n");
                     45: #                      endif
                     46:                        rtval = 0;
                     47:                        break;
                     48:                }
                     49:                switch(Cmap[chr])
                     50:                {
                     51:                  case ALPHA:
                     52:                        rtval = name(chr);
                     53:                        break;
                     54: 
                     55:                  case NUMBR:
                     56:                        rtval = number(chr);
                     57:                        break;
                     58: 
                     59:                  case OPATR:
                     60:                        if ((rtval = operator(chr)) == 0)
                     61:                                rtval = -1;
                     62:                        break;
                     63: 
                     64:                  case PUNCT:
                     65:                        continue;
                     66: 
                     67:                  case CNTRL:
                     68:                        /* already converted number ? */
                     69:                        if (Pars)
                     70:                                switch (chr)
                     71:                                {
                     72:                                  case CVAR_I2:
                     73:                                        rtval = getcvar(Tokens.i2const, 2);
                     74:                                        break;
                     75: 
                     76:                                  case CVAR_I4:
                     77:                                        rtval = getcvar(Tokens.i4const, 4);
                     78:                                        break;
                     79: 
                     80:                                  case CVAR_F8:
                     81:                                        rtval = getcvar(Tokens.f8const, 8);
                     82:                                        break;
                     83: 
                     84:                                  case CVAR_S:
                     85:                                        rtval = getcvar(Tokens.sconst, 0);
                     86:                                        break;
                     87: 
                     88:                                  default:
                     89:                                        printf("funny character 0%o ingnored\n", chr);
                     90:                                        continue;
                     91:                                }
                     92:                        break;
                     93:                  default:
                     94:                        syserr("invalid type in yylex()");
                     95:                }
                     96:        }  while (rtval == -1);
                     97:        if (rtval == 0)
                     98:        {
                     99:                Lastok.tokop = GOVAL;
                    100:                Lastok.tok = 0;
                    101:                Lastok.toktyp = 0;
                    102:        }
                    103:        return (rtval);
                    104: }
                    105: 
                    106: 
                    107: getcvar(type, len)
                    108: int    type;
                    109: int    len;
                    110: {
                    111:        extern char     *yylval;
                    112:        extern char     Cmap[];
                    113:        extern char     *syment();
                    114:        register int    save;
                    115:        char            buf[MAXSTRING + 1];
                    116: 
                    117:        save = Lcase;
                    118:        Lcase = 0;
                    119:        yylval = buf;
                    120:        if (len)
                    121:                while ((yylval - buf) < len)
                    122:                        *yylval++ = get_scan(NORMAL);
                    123:        else
                    124:        {
                    125:                do
                    126:                {
                    127:                        *yylval = get_scan(NORMAL);
                    128:                        if ((yylval - buf) > MAXSTRING)
                    129:                        {
                    130:                                Lcase = save;
                    131:                                par_error(STRLONG, WARN, 0);
                    132:                        }
                    133:                        if (Cmap[*yylval] == CNTRL && *yylval != '\0')
                    134:                        {
                    135:                                Lcase = save;
                    136:                                /* control char in string from equel */
                    137:                                par_error(CNTRLCHR, WARN, 0);
                    138:                        }
                    139:                } while (*yylval++);
                    140:                len = yylval - buf;
                    141:        }
                    142:        Lcase = save;
                    143:        yylval = syment(buf, len);
                    144:        Lastok.tok = yylval;
                    145:        Lastok.toktyp = type;
                    146:        return (type);
                    147: }

unix.superglobalmegacorp.com

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