📄 getsym.c
字号:
}
if ((lastch &0x7f) != '\"')
generror(ERR_NEEDCHAR, '\"', 0);
else
getch();
*(((short*)(laststr)) + i) = 0;
laststrlen = i;
lastst = lsconst;
return ;
}
}
while (issymchar(lastch))
{
if (i < 100)
i += installphichar(lastch, lastid, i);
getch();
}
if ((lastid[i - 1] &0xf0) == 0x90)
lastid[i - 1] = 0x90;
lastid[i] = '\0';
lastst = ident;
}
/*
* getsch - get a character in a quoted string.
*
* this routine handles all of the escape mechanisms
* for characters in strings and character constants.
*/
int getsch(void) /* return an in-quote character */
{
register int i, j;
if (lastch == '\n')
return - 1;
if (incconst || lastch != '\\')
{
i = lastch;
getch();
return i;
}
getch(); /* get an escaped character */
if (isdigit(lastch))
{
for (i = 0, j = 0; j < 3; ++j)
{
if (lastch <= '7' && lastch >= '0')
i = (i << 3) + lastch - '0';
else
break;
getch();
}
return i;
}
i = lastch;
getch();
switch (i)
{
case '\n':
getch();
return getsch();
case 'a':
return '\a';
case 'b':
return '\b';
case 'f':
return '\f';
case 'n':
return '\n';
case 'r':
return '\r';
case 't':
return '\t';
case '\'':
return '\'';
case '\"':
return '\"';
case '\\':
return '\\';
case 'x':
{
int n = 0, count = 0;
while (isxdigit(lastch))
{
count++;
lastch -= 0x30;
if (lastch > 10)
lastch -= 7;
if (lastch > 15)
lastch -= 32;
n *= 16;
n += lastch;
getch();
}
if (count > 2)
generror(ERR_CONSTTOOLARGE, 0, 0);
return n;
}
default:
if (isdigit(i) && i < '8')
{
int n = 0;
while (isdigit(i) && i < '8')
{
n = n * 8+(lastch - '0');
getch();
}
return n;
}
return i;
}
}
//-------------------------------------------------------------------------
int radix36(char c)
{
if (isdigit(c))
return c - '0';
if (c >= 'a' && c <= 'z')
return c - 'a' + 10;
if (c >= 'A' && c <= 'Z')
return c - 'A' + 10;
return - 1;
}
/*
* getbase - get an integer in any base.
*/
void getbase(int b, char **ptr)
{
register long i, j;
int errd = 0;
i = 0;
while (isalnum(**ptr))
{
if ((j = radix36(*(*ptr)++)) < b)
{
if (i > (ULONG_MAX - j) / b)
if (!errd)
{
generror(ERR_CONSTTOOLARGE, 0, 0);
errd++;
}
i = i * b + j;
}
else
break;
}
ival = i;
lastst = iconst;
}
/*
* getfrac - get fraction part of a floating number.
*/
void getfrac(char **ptr)
{
long double frmul;
frmul = 0.1;
while (isdigit(**ptr))
{
rval += frmul *(*(*ptr)++ - '0');
frmul *= 0.1;
}
}
/*
* getexp - get exponent part of floating number.
*
* this algorithm is primative but usefull. Floating
* exponents are limited to +/-255 but most hardware
* won't support more anyway.
*/
void getexp(char **ptr)
{
long double expo, exmul;
expo = 1.0;
if (lastst != rconst)
rval = ival;
if (**ptr == '-')
{
exmul = 0.1;
(*ptr)++;
}
else
{
exmul = 10.0;
if (**ptr == '+')
(*ptr)++;
}
getbase(10, ptr);
if (ival > 255)
generror(ERR_FPCON, 0, 0);
else
while (ival--)
expo *= exmul;
rval *= expo;
lastst = rconst;
}
/*
* getnum - get a number from input.
*
* getnum handles all of the numeric input. it accepts
* decimal, octal, hexidecimal, and floating point numbers.
*/
void getnum(void)
{
int isfloat = FALSE;
char buf[50], *ptr = buf;
while (isxdigit(lastch) || lastch == 'x' || lastch == 'X')
{
*ptr++ = lastch;
getch();
}
if (lastch == '.')
{
isfloat = TRUE;
*ptr++ = lastch;
getch();
while (isdigit(lastch))
{
*ptr++ = lastch;
getch();
}
}
if (lastch == 'e' || lastch == 'E')
{
isfloat = TRUE;
*ptr++ = lastch;
getch();
if (lastch == '+' || lastch == '-')
{
*ptr++ = lastch;
getch();
}
while (isdigit(lastch))
{
*ptr++ = lastch;
getch();
}
}
if (lastch == 'F')
{
isfloat = TRUE;
}
*ptr = 0;
ptr = buf;
if (!isfloat)
{
if (*ptr == '0')
{
ptr++;
if (*ptr == 'x' || *ptr == 'X')
{
ptr++;
getbase(16, &ptr);
}
else
getbase(8, &ptr);
}
else
getbase(10, &ptr);
if (lastch == 'U' || lastch == 'u')
{
lastst = iuconst;
getch();
if (lastch == 'L' || lastch == 'l')
{
lastst = luconst;
getch();
}
}
else if (lastch == 'L' || lastch == 'l')
{
lastst = iconst;
getch();
if (lastch == 'U' || lastch == 'u')
{
lastst = luconst;
getch();
}
}
}
else
{
getbase(10, &ptr);
if (*ptr == '.')
{
ptr++;
rval = ival; /* float the integer part */
getfrac(&ptr); /* add the fractional part */
lastst = rconst;
}
if (*ptr == 'e' || *ptr == 'E')
{
ptr++;
getexp(&ptr); /* get the exponent */
}
if (lastch == 'F' || lastch == 'f')
{
if (lastst != rconst)
{
rval = ival;
}
lastst = fconst;
getch();
}
else if (lastch == 'L' || lastch == 'l')
{
if (lastst != rconst)
{
rval = ival;
}
lastst = lrconst;
getch();
}
}
}
//-------------------------------------------------------------------------
int getsym2(void)
/*
* translate character sequences to appropriate token names
*/
{
register int i, j, k;
int size;
swlp: switch (lastch)
{
case '+':
getch();
if (lastch == '+')
{
getch();
lastst = autoinc;
}
else if (lastch == '=')
{
getch();
lastst = asplus;
}
else
lastst = plus;
break;
case '-':
getch();
if (lastch == '-')
{
getch();
lastst = autodec;
}
else if (lastch == '=')
{
getch();
lastst = asminus;
}
else if (lastch == '>')
{
getch();
#ifdef CPLUSPLUS
if (prm_cplusplus && lastch == '*')
{
getch();
lastst = pointstar;
}
else
#endif
lastst = pointsto;
}
else
lastst = minus;
break;
case '*':
getch();
if (lastch == '=')
{
getch();
lastst = astimes;
}
else
lastst = star;
break;
case '/':
getch();
if (lastch == '=')
{
getch();
lastst = asdivide;
}
else
lastst = divide;
break;
case '^':
getch();
if (lastch == '=')
{
getch();
lastst = asxor;
}
else
lastst = uparrow;
break;
case ';':
getch();
lastst = semicolon;
break;
case ':':
getch();
#ifdef CPLUSPLUS
if (prm_cplusplus && lastch == ':')
{
getch();
if (lastch == '*')
{
getch();
lastst = classselstar;
}
else
lastst = classsel;
}
else
#endif
lastst = colon;
break;
case '=':
getch();
if (lastch == '=')
{
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -