📄 getsym.c
字号:
break;
case '-':
getch();
if (lastch == '-')
{
getch();
lastst = autodec;
}
else if (lastch == '=')
{
getch();
lastst = asminus;
}
else if (lastch == '>')
{
getch();
if (prm_cplusplus && lastch == '*')
{
getch();
lastst = pointstar;
}
else
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();
if (prm_cplusplus && lastch == ':')
{
getch();
if (lastch == '*')
{
getch();
lastst = classselstar;
}
else
lastst = classsel;
}
else
if (lastch == '>')
{
getch();
lastst = closebr;
}
else
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)
{
sys_inc = TRUE;
for (i = 0; i < MAX_STRLEN; ++i)
{
if (lastch == '>')
break;
if ((j = getsch(1)) == INT_MIN)
break;
else
laststr[i] = j;
}
laststr[i] = 0;
lastst = sconst;
laststrlen = i;
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 if (lastch == ':')
{
getch();
lastst = openbr;
}
else if (lastch == '%')
{
getch();
lastst = begin;
}
else
lastst = lt;
break;
case '\'':
getch();
j = 0;
k = 0;
ival = 0;
for (i = 0, j = 0, k = 0; i < 4; i++, k += 8)
{
if (lastch == '\'')
break;
if (i == 1)
ival &= 0xff;
// get rid of sign if this is multibyte
j = getsch(1); /* get a string char */
ival += j << k;
}
if (i == 0)
generror(ERR_CHAR4CHAR, 0, 0);
else
while (lastch != '\'' && lastch != '\n')
getsch(1);
if (lastch != '\'')
generror(ERR_NEEDCHAR, '\'', 0);
else
getch();
if (prm_cplusplus)
lastst = cconst;
else
lastst = iconst;
break;
case 0x2d4:
getch();
i = 0;
lastst = sconst;
while (lastch != '\"' && lastch) {
if (i >= MAX_STRLEN) {
generror(ERR_STRINGTOOBIG,0,0);
break;
}
laststr[i++] = lastch;
}
laststr[i] = 0;
if ((lastch &0x7f) != '\"')
generror(ERR_NEEDCHAR, '\"', 0);
else
getch();
laststrlen = i;
size = i;
break;
case '\"':
size = 0;
while (lastch == '\"')
{
getch();
for (i = size; i < MAX_STRLEN; ++i)
{
if (lastch == '\"')
break;
if ((j = getsch(1)) == INT_MIN)
break;
else
laststr[i] = j;
}
laststr[i] = 0;
laststrlen = 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 if (lastch == '>')
{
getch();
lastst = end;
}
else if (lastch == ':')
{
getch();
lastst = hash;
}
else
lastst = modop;
break;
case '~':
getch();
lastst = compl;
break;
case '.':
if (isdigit(*lptr))
getnum();
else
{
getch();
if (prm_cplusplus && lastch == '*')
{
getch();
lastst = dotstar;
}
else
if (lastch == '.')
{
getch();
if (lastch == '.')
{
getch();
lastst = ellipse;
break;
}
else
{
generror(ERR_ILLCHAR, lastch, 0);
}
}
else
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;
case '#':
getch();
lastst = hash;
break;
// case SYM_ASSIGN :
// getch() ;
// lastst = assign ;
// break ;
// case SYM_SHIFTASSIGN :
// getch() ;
// lastst = lassign ;
// break ;
case '@':
/* @= is same as above */
if (!prm_ansi)
{
getch();
if (lastch == '=')
{
getch();
lastst = lassign;
break;
}
else
lastch = *--lptr;
}
// FALL THROUGH
default:
#ifdef XXXXX
if (iscommentchar(lastch))
{
do
{
getch();
}
while (!iscommentchar(lastch) && lastch != '\n');
}
else
#endif
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)
{
int done;
lastlastst = lastst ;
do
{
done = TRUE;
sym_charindex = lptr - inputline;
errlineno = lineno;
if (backupchar != - 1)
{
lastst = backupchar;
if (lastst == id)
strcpy(lastid, backupid);
backupchar = - 1;
return ;
}
if (cantnewline && ! *lptr)
{
lastst = eol;
return ;
}
while (isspace(lastch))
{
getch();
if (cantnewline && ! *lptr)
{
lastst = eol;
return ;
}
}
if (lastch == - 1)
lastst = eof;
else if (isdigit(lastch))
getnum();
else if (isstartchar(lastch))
{
getid();
searchkw();
if (lastst == kw__Pragma)
{
Compile_Pragma();
done = FALSE;
}
}
else
getsym2();
}
while (!done)
;
}
/*
* 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)
{
if (lastst == id)
strcpy(backupid, lastid);
backupchar = lastst;
lastst = st;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -