ING_DB
This commit is contained in:
parent
15c928e591
commit
a6e7ba3d6b
|
|
@ -0,0 +1,78 @@
|
||||||
|
# include "gen.h"
|
||||||
|
# include "../h/dbs.h"
|
||||||
|
# include "../h/scanner.h"
|
||||||
|
# include "parser.h"
|
||||||
|
|
||||||
|
/*
|
||||||
|
** NAME
|
||||||
|
** A name is defined to be a sequence of MAXNAME or fewer alphanumeric
|
||||||
|
** characters, starting with an alphabetic (underscore "_" is considered
|
||||||
|
** an alphabetic). If it is not a keyword, each name is entered into
|
||||||
|
** the symbol table, indexed by 'yylval'. A token is then returned for
|
||||||
|
** that name.
|
||||||
|
*/
|
||||||
|
name(chr)
|
||||||
|
char chr;
|
||||||
|
{
|
||||||
|
extern char *yylval;
|
||||||
|
char namebuf[MAXNAME + 1];
|
||||||
|
register int hi;
|
||||||
|
register int lo;
|
||||||
|
register int curr;
|
||||||
|
extern char *syment();
|
||||||
|
|
||||||
|
/* fill in the name */
|
||||||
|
yylval = namebuf;
|
||||||
|
*yylval = chr;
|
||||||
|
do
|
||||||
|
{
|
||||||
|
*++yylval = curr = gtchar();
|
||||||
|
if ((yylval - namebuf) > MAXNAME)
|
||||||
|
{
|
||||||
|
/* name too long */
|
||||||
|
*yylval = '\0';
|
||||||
|
yyerror(NAMELONG, namebuf, (char *) 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
} while (CMAP(curr) == ALPHA || CMAP(curr) == NUMBR);
|
||||||
|
backup(curr);
|
||||||
|
*yylval = '\0';
|
||||||
|
|
||||||
|
/* is it a keyword ? */
|
||||||
|
lo = 0;
|
||||||
|
hi = Keyent - 1;
|
||||||
|
while (lo <= hi)
|
||||||
|
{
|
||||||
|
curr = (lo + hi) / 2;
|
||||||
|
switch (AAscompare(Keyword[curr].term, MAXNAME, namebuf, MAXNAME))
|
||||||
|
{
|
||||||
|
case 1:
|
||||||
|
hi = curr - 1;
|
||||||
|
continue;
|
||||||
|
|
||||||
|
case -1:
|
||||||
|
lo = curr + 1;
|
||||||
|
continue;
|
||||||
|
|
||||||
|
case 0:
|
||||||
|
Lastok.toktyp = Tokens.sconst;
|
||||||
|
Lastok.tok = Keyword[curr].term;
|
||||||
|
Lastok.tokop = Keyword[curr].opcode;
|
||||||
|
yylval = CAST(Keyword[curr].opcode);
|
||||||
|
# ifdef xPTR2
|
||||||
|
AAtTfp(71, 0, "keyword: %s\n", namebuf);
|
||||||
|
# endif
|
||||||
|
return (Keyword[curr].token);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* else, USER DEFINED NAME */
|
||||||
|
# ifdef xPTR2
|
||||||
|
AAtTfp(71, 0, "name: %s\n", namebuf);
|
||||||
|
# endif
|
||||||
|
yylval = syment(namebuf, AAlength(namebuf) + 1);
|
||||||
|
Lastok.tok = yylval;
|
||||||
|
Lastok.toktyp = Tokens.sconst;
|
||||||
|
Lastok.tokop = 0;
|
||||||
|
return (Tokens.name);
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,88 @@
|
||||||
|
# include "gen.h"
|
||||||
|
# include "../h/dbs.h"
|
||||||
|
# include "../h/scanner.h"
|
||||||
|
# include "parser.h"
|
||||||
|
|
||||||
|
/*
|
||||||
|
** STRING
|
||||||
|
** A string is defined as any sequence of MAXSTRING or fewer characters,
|
||||||
|
** surrounded by string delimiters. New-line ;characters are purged
|
||||||
|
** from strings unless preceeded by a '\'; QUOTE's must be similarly
|
||||||
|
** prefixed in order to be correctly inserted within a string. Each
|
||||||
|
** string is entered in the symbol table, indexed by 'yylval'. A
|
||||||
|
** token or the error condition -1 is returned.
|
||||||
|
*/
|
||||||
|
string(op)
|
||||||
|
struct optab *op;
|
||||||
|
{
|
||||||
|
extern char *yylval;
|
||||||
|
extern char *syment();
|
||||||
|
register int esc;
|
||||||
|
register int chr;
|
||||||
|
register char *ptr;
|
||||||
|
register int save;
|
||||||
|
char buf[MAXSTRING + 1];
|
||||||
|
|
||||||
|
/* disable case conversion and fill in string */
|
||||||
|
ptr = buf;
|
||||||
|
save = Lcase;
|
||||||
|
Lcase = 0;
|
||||||
|
do
|
||||||
|
{
|
||||||
|
/* get next character */
|
||||||
|
if ((*ptr = gtchar()) <= 0)
|
||||||
|
{
|
||||||
|
Lcase = save;
|
||||||
|
/* non term string */
|
||||||
|
yyerror(STRTERM, (char *) 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* handle escape characters */
|
||||||
|
esc = (*ptr == '\\');
|
||||||
|
if (*ptr == '\n')
|
||||||
|
{
|
||||||
|
if ((*ptr = gtchar()) <= 0)
|
||||||
|
{
|
||||||
|
Lcase = save;
|
||||||
|
*ptr = 0;
|
||||||
|
/* non term string */
|
||||||
|
yyerror(STRTERM, (char *) 0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (esc == 1)
|
||||||
|
{
|
||||||
|
if ((*++ptr = gtchar()) <= 0)
|
||||||
|
{
|
||||||
|
Lcase = save;
|
||||||
|
*ptr = 0;
|
||||||
|
/* non term string */
|
||||||
|
yyerror(STRTERM, (char *) 0);
|
||||||
|
}
|
||||||
|
if (*ptr == *(op->term))
|
||||||
|
*--ptr = *(op->term);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* check length */
|
||||||
|
if ((ptr - buf) > MAXSTRING - 1)
|
||||||
|
{
|
||||||
|
Lcase = save;
|
||||||
|
/* string too long */
|
||||||
|
yyerror(STRLONG, (char *) 0);
|
||||||
|
}
|
||||||
|
chr = *ptr;
|
||||||
|
if (CMAP(chr) == CNTRL)
|
||||||
|
/* cntrl in string from EQL */
|
||||||
|
yyerror(CNTRLCHR, (char *) 0);
|
||||||
|
} while (*ptr++ != *(op->term) || esc == 1);
|
||||||
|
|
||||||
|
/* restore case conversion and return */
|
||||||
|
*--ptr = '\0';
|
||||||
|
Lcase = save;
|
||||||
|
# ifdef xPTR2
|
||||||
|
AAtTfp(71, 8, "STRING: %s\n", buf);
|
||||||
|
# endif
|
||||||
|
yylval = syment(buf, (ptr - buf) + 1);
|
||||||
|
Lastok.tok = yylval;
|
||||||
|
Lastok.toktyp = Tokens.sconst;
|
||||||
|
return (Tokens.sconst);
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,137 @@
|
||||||
|
# include "gen.h"
|
||||||
|
# include "../h/dbs.h"
|
||||||
|
# include "../h/scanner.h"
|
||||||
|
# include "parser.h"
|
||||||
|
|
||||||
|
struct lastok Lastok;
|
||||||
|
int Pars; /* flag for call getcvar or not */
|
||||||
|
|
||||||
|
/*
|
||||||
|
** YYLEX
|
||||||
|
** This is the control program for the scanner (lexical analyzer).
|
||||||
|
** Each call to yylex() returns a token for the next syntactic unit.
|
||||||
|
** If the object is of type I2CONST, I4CONST, F8CONST, SCONST or NAME, that
|
||||||
|
** object will also be entered in the symbol table, indexed by 'yylval'.
|
||||||
|
** If the object is not one of these types, yylval is the opcode field of
|
||||||
|
** the operator or keyword tables.
|
||||||
|
** The end-of-file token is zero.
|
||||||
|
*/
|
||||||
|
yylex()
|
||||||
|
{
|
||||||
|
register int chr;
|
||||||
|
register int rtval;
|
||||||
|
|
||||||
|
rtval = -1;
|
||||||
|
Lastok.tokop = 0;
|
||||||
|
/* GET NEXT TOKEN */
|
||||||
|
do
|
||||||
|
{
|
||||||
|
if((chr = gtchar()) <= 0)
|
||||||
|
{
|
||||||
|
# ifdef xPTR2
|
||||||
|
AAtTfp(72, 8, "end-of-file\n");
|
||||||
|
# endif
|
||||||
|
rtval = 0;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
switch (CMAP(chr))
|
||||||
|
{
|
||||||
|
case ALPHA:
|
||||||
|
rtval = name(chr);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case NUMBR:
|
||||||
|
rtval = number(chr);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case OPATR:
|
||||||
|
if ((rtval = operator(chr)) == 0)
|
||||||
|
rtval = -1;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case PUNCT:
|
||||||
|
continue;
|
||||||
|
|
||||||
|
case CNTRL:
|
||||||
|
/* already converted number ? */
|
||||||
|
if (Pars)
|
||||||
|
switch (chr)
|
||||||
|
{
|
||||||
|
case CVAR_I2:
|
||||||
|
rtval = getcvar(Tokens.i2const, sizeof (short));
|
||||||
|
break;
|
||||||
|
|
||||||
|
case CVAR_I4:
|
||||||
|
rtval = getcvar(Tokens.i4const, sizeof (long));
|
||||||
|
break;
|
||||||
|
|
||||||
|
case CVAR_F8:
|
||||||
|
rtval = getcvar(Tokens.f8const, sizeof (double));
|
||||||
|
break;
|
||||||
|
|
||||||
|
case CVAR_S:
|
||||||
|
rtval = getcvar(Tokens.sconst, 0);
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
printf("Zeichen 0%o ignoriert\n", chr);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
AAsyserr(20003);
|
||||||
|
}
|
||||||
|
} while (rtval == -1);
|
||||||
|
if (rtval == 0)
|
||||||
|
{
|
||||||
|
Lastok.tokop = GOVAL;
|
||||||
|
Lastok.tok = 0;
|
||||||
|
Lastok.toktyp = 0;
|
||||||
|
}
|
||||||
|
return (rtval);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
getcvar(type, len)
|
||||||
|
register int type;
|
||||||
|
register int len;
|
||||||
|
{
|
||||||
|
register int chr;
|
||||||
|
register int save;
|
||||||
|
char buf[MAXSTRING + 1];
|
||||||
|
extern char *yylval;
|
||||||
|
extern char *syment();
|
||||||
|
|
||||||
|
save = Lcase;
|
||||||
|
Lcase = 0;
|
||||||
|
yylval = buf;
|
||||||
|
if (len)
|
||||||
|
{
|
||||||
|
while ((yylval - buf) < len)
|
||||||
|
*yylval++ = chr = gtchar();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
do
|
||||||
|
{
|
||||||
|
*yylval = chr = gtchar();
|
||||||
|
if ((yylval - buf) > MAXSTRING)
|
||||||
|
{
|
||||||
|
Lcase = save;
|
||||||
|
yyerror(STRLONG, (char *) 0);
|
||||||
|
}
|
||||||
|
if (CMAP(chr) == CNTRL && chr != '\0')
|
||||||
|
{
|
||||||
|
Lcase = save;
|
||||||
|
/* control char in string from EQL */
|
||||||
|
yyerror(CNTRLCHR, (char *) 0);
|
||||||
|
}
|
||||||
|
} while (*yylval++);
|
||||||
|
len = yylval - buf;
|
||||||
|
}
|
||||||
|
Lcase = save;
|
||||||
|
yylval = syment(buf, len);
|
||||||
|
Lastok.tok = yylval;
|
||||||
|
Lastok.toktyp = type;
|
||||||
|
return (type);
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue