?? getsym.c
字號(hào):
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') {
lastst = iuconst;
getch();
if (lastch == 'L') {
lastst = luconst;
getch();
}
}
else if (lastch == 'L') {
lastst = iconst;
getch();
if (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') {
if (lastst != rconst) {
rval = ival;
}
lastst = fconst;
getch();
}
else if (lastch == 'L') {
if (lastst != rconst) {
rval = ival;
}
lastst = lrconst;
getch();
}
}
}
int getsym2(void)
/*
* translate character sequences to appropriate token names
*/
{ register int i, j;
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 == ':') {
lastst = classsel;
getch();
}
else
#endif
lastst = colon;
break;
case '=':
getch();
if(lastch == '=') {
getch();
lastst = eq;
}
else lastst = assign;
break;
case '>':
getch();
if(lastch == '=') {
getch();
lastst = geq;
}
else if(lastch == '>') {
getch();
if(lastch == '=') {
getch();
lastst = asrshift;
}
else lastst = rshift;
}
else lastst = gt;
break;
case '<':
getch();
if (incconst) {
for(i = 0;i < MAX_STRLEN;++i) {
if(lastch == '>')
break;
if((j = getsch()) == -1)
break;
else
laststr[i] = j;
}
laststr[i] = 0;
lastst = sconst;
if(lastch != '>')
generror(ERR_NEEDCHAR,'>',0);
else
getch();
} else
if(lastch == '=') {
getch();
lastst = leq;
}
else if(lastch == '<') {
getch();
if(lastch == '=') {
getch();
lastst = aslshift;
}
else lastst = lshift;
}
else lastst = lt;
break;
case '\'':
getch();
ival = getsch(); /* get a string char */
if(lastch != '\'')
generror(ERR_NEEDCHAR,'\'',0);
else
getch();
lastst = cconst;
break;
case 0x2d4:
getch();
i=0;
while (lastch != '\"' && lastch)
i=installphichar(lastch,laststr,i);
if ((lastch & 0x7f) != '\"')
generror(ERR_NEEDCHAR,'\"',0);
else
getch();
size = strlen(laststr);
lastst = sconst;
break;
case '\"':
size = 0;
while (lastch == '\"') {
getch();
for(i = size;i < MAX_STRLEN;++i) {
if(lastch == '\"')
break;
if((j = getsch()) == -1)
break;
else
laststr[i] = j;
}
laststr[i] = 0;
size = i;
lastst = sconst;
if(lastch != '\"')
generror(ERR_NEEDCHAR,'\"',0);
else
getch();
}
break;
case '!':
getch();
if(lastch == '=') {
getch();
lastst = neq;
}
else lastst = not;
break;
case '%':
getch();
if(lastch == '=') {
getch();
lastst = asmodop;
}
else lastst = modop;
break;
case '~':
getch();
lastst = compl;
break;
case '.':
if (isdigit(*lptr))
getnum();
else {
getch();
#ifdef CPLUSPLUS
if (prm_cplusplus && lastch == '*') {
getch();
lastst = dotstar;
}
else
#endif
if (lastch == '.') {
getch();
if (lastch == '.') {
getch();
lastst = ellipse;
break;
}
else {
generror(ERR_ILLCHAR,lastch,0);
}
}
lastst = dot;
}
break;
case ',':
getch();
lastst = comma;
break;
case '&':
getch();
if( lastch == '&') {
lastst = land;
getch();
}
else if( lastch == '=') {
lastst = asand;
getch();
}
else
lastst = and;
break;
case '|':
getch();
if(lastch == '|') {
lastst = lor;
getch();
}
else if( lastch == '=') {
lastst = asor;
getch();
}
else
lastst = or;
break;
case '(':
getch();
lastst = openpa;
break;
case ')':
getch();
lastst = closepa;
break;
case '[':
getch();
lastst = openbr;
break;
case ']':
getch();
lastst = closebr;
break;
case '{':
getch();
lastst = begin;
break;
case '}':
getch();
lastst = end;
break;
case '?':
getch();
lastst = hook;
break;
default:
if (iscommentchar(lastch)) {
do {
getch();
} while (!iscommentchar(lastch) && lastch != '\n');
}
else
generror(ERR_ILLCHAR,lastch,0);
getch();
return 1;
}
return 0;
}
/*
* getsym - get next symbol from input stream.
*
* getsym is the basic lexical analyzer. It builds
* basic tokens out of the characters on the input
* stream and sets the following global variables:
*
* lastch: A look behind buffer.
* lastst: type of last symbol read.
* laststr: last string constant read.
* lastid: last identifier read.
* ival: last integer constant read.
* rval: last real constant read.
*
* getsym should be called for all your input needs...
*/
void getsym(void)
{
if (backupchar != -1) {
lastst = backupchar;
backupchar = -1;
return;
}
if (cantnewline && !*lptr) {
lastst = eol;
return;
}
while(iswhitespacechar(lastch)) {
getch();
if (cantnewline && !*lptr) {
lastst = eol;
return;
}
}
if( lastch == -1)
lastst = eof;
else if(isdigit(lastch))
getnum();
else if(isstartchar(lastch)) {
getid();
searchkw();
}
else getsym2();
}
/*
* when we need specific punctuation, call one of these routines
*/
int needpunc(enum e_sym p, int *skimlist)
{ if( lastst == p) {
getsym();
return(TRUE);
}
else
expecttoken(p,skimlist);
return(FALSE);
}
int needpuncexp(enum e_sym p, int *skimlist)
{ if( lastst == p) {
getsym();
return(TRUE);
}
else
expecttokenexp(p,skimlist);
return(FALSE);
}
/*
* having to back up a character is rare, but sometimes...
*/
void backup(int st)
{
backupchar = lastst;
lastst = st;
}
?? 快捷鍵說(shuō)明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -