diff --git a/WEGA/contrib/ingres/dbs/src/parser/s_number.c b/WEGA/contrib/ingres/dbs/src/parser/s_number.c new file mode 100644 index 0000000..b860342 --- /dev/null +++ b/WEGA/contrib/ingres/dbs/src/parser/s_number.c @@ -0,0 +1,109 @@ +# include "gen.h" +# include "../h/dbs.h" +# include "../h/aux.h" +# include "../h/scanner.h" +# include "parser.h" + +/* +** NUMBER +** scans numerical constants (both integer and floating). Each +** constant is converted from ascii to its numerical representation +** and is entered into the symbol table, indexed by 'yylval'. +** A token is returned for the number type. +** +** due to the current atof in the utility library, floating overflow +** is not checked. +*/ +number(chr) +char chr; +{ + extern char *yylval; + extern char *syment(); + double ftemp; + long ltemp; + short itemp; + char buf[MAXFIELD]; + register char *ptr; + register int toktyp; + register int save; + + save = Lcase; + Lcase = 0; + ptr = buf; + if ((*ptr = toktyp = chr) != '.') + { + do + { + /* get integer portion */ + if ((ptr - buf) > MAXFIELD) + /* buffer overflow */ + yyerror(NUMBUFOFLO, (char *) 0); + *++ptr = toktyp = gtchar(); + } while (CMAP(toktyp) == NUMBR); + } + + /* do rest of type determination */ + switch (toktyp) + { + case '.': + /* floating point */ + do + { + /* fill into ptr with up to next non-digit */ + if ((ptr - buf) > MAXFIELD) + yyerror(NUMBUFOFLO, (char *) 0); /* buf oflo */ + *++ptr = toktyp = gtchar(); + } while (CMAP(toktyp) == NUMBR); + if (toktyp != 'e' && toktyp != 'E') + { + backup(toktyp); + *ptr = 0; + goto convr; + } + + case 'e': + case 'E': + if ((ptr - buf) > MAXFIELD) + yyerror(NUMBUFOFLO, (char *) 0); /* buf oflo */ + *++ptr = toktyp = gtchar(); + if (CMAP(toktyp) == NUMBR || toktyp == '-' || toktyp == '+') + { + do + { + /* get exponent */ + if ((ptr - buf) > MAXFIELD) + yyerror(NUMBUFOFLO, (char *) 0); /* buf oflo */ + *++ptr = toktyp = gtchar(); + } while (CMAP(toktyp) == NUMBR); + } + backup(toktyp); + *ptr = 0; + convr: + if (AA_atof(buf, &ftemp)) + yyerror(FCONSTERR, buf, (char *) 0); /* floating conversion error */ + yylval = syment(&ftemp, sizeof (double)); + Lastok.toktyp = Tokens.f8const; + break; + + default: + /* integer */ + backup(toktyp); + *ptr = 0; + if (AA_atol(buf, <emp)) /* long conversion error */ + goto convr; + if (ltemp > 32767) + { + yylval = syment(<emp, sizeof (long)); + Lastok.toktyp = Tokens.i4const; + break; + } + itemp = ltemp; + yylval = syment(&itemp, sizeof (short)); + Lastok.toktyp = Tokens.i2const; + break; + } + Lcase = save; + Lastok.tok = yylval; + Lastok.tokop = 0; + return (Lastok.toktyp); +} diff --git a/WEGA/contrib/ingres/dbs/src/parser/s_operator.c b/WEGA/contrib/ingres/dbs/src/parser/s_operator.c new file mode 100644 index 0000000..361789f --- /dev/null +++ b/WEGA/contrib/ingres/dbs/src/parser/s_operator.c @@ -0,0 +1,74 @@ +# include "gen.h" +# include "../h/dbs.h" +# include "../h/scanner.h" +# include "parser.h" + +/* +** OPERATOR +** an operator is defined as any 1-3 character sequence of +** non-alphanumerics. It looks up each operator in 'Optab' +** and returns the appropriate token. +*/ +operator(chr) +char chr; +{ + extern char *yylval; + register struct optab *op; + register int toktyp; + register int save; + char buf[4]; + + /* get lookahead characer */ + save = Lcase; + Lcase = 0; + buf[0] = chr; + buf[1] = toktyp = gtchar(); + buf[2] = gtchar(); + buf[3] = '\0'; + + /* is it a floating fraction without leading zero ? */ + if (buf[0] == '.' && CMAP(toktyp) == NUMBR) + { + Lcase = save; + backup(buf[2]); + backup(toktyp); + return (number(chr)); + } + + /* three character operator ? */ + for (op = &Optab[0]; op->term; op++) + if (AAsequal(op->term, buf)) + break; + if (!op->term) + { + /* two character operator ? */ + backup(buf[2]); + buf[2] = '\0'; + for (op = &Optab[0]; op->term; op++) + if (AAsequal(op->term, buf)) + break; + if (!op->term) + { + backup(toktyp); + buf[1] = '\0'; + for (op = &Optab[0]; op->term; op++) + if (AAsequal(op->term, buf)) + break; + if (!op->term) + { + Lcase = save; + /* invalid operator */ + yyerror (BADOP, 0); + } + } + } + Lcase = save; + if(op->token == Tokens.bgncmnt) + return (comment()); + if(op->token == Tokens.sconst) + return (string(op)); + Lastok.tok = op->term; + Lastok.toktyp = Tokens.sconst; + yylval = CAST(op->opcode); + return (op->token); +}