Run files through clang-format before editing.
This commit is contained in:
parent
bed39e1f4d
commit
788f439a48
|
@ -74,18 +74,19 @@ PopLex()
|
|||
}
|
||||
#endif /* NOPP */
|
||||
|
||||
int
|
||||
LLlex()
|
||||
int LLlex()
|
||||
{
|
||||
/* LLlex() plays the role of Lexical Analyzer for the C parser.
|
||||
The look-ahead and putting aside of tokens are taken into
|
||||
account.
|
||||
*/
|
||||
if (ASIDE) { /* a token is put aside */
|
||||
if (ASIDE)
|
||||
{ /* a token is put aside */
|
||||
dot = aside;
|
||||
ASIDE = 0;
|
||||
}
|
||||
else { /* read ahead and return the old one */
|
||||
else
|
||||
{ /* read ahead and return the old one */
|
||||
#ifdef LINT
|
||||
lint_comment_ahead();
|
||||
#endif /* LINT */
|
||||
|
@ -104,13 +105,10 @@ LLlex()
|
|||
return DOT;
|
||||
}
|
||||
|
||||
|
||||
char* string_token();
|
||||
arith char_constant();
|
||||
|
||||
int
|
||||
GetToken(ptok)
|
||||
register struct token *ptok;
|
||||
int GetToken(ptok) register struct token* ptok;
|
||||
{
|
||||
/* GetToken() is the actual token recognizer. It calls the
|
||||
control line interpreter if it encounters a "\n{w}*#"
|
||||
|
@ -122,7 +120,8 @@ GetToken(ptok)
|
|||
|
||||
token_nmb++;
|
||||
|
||||
if (File_Inserted) {
|
||||
if (File_Inserted)
|
||||
{
|
||||
File_Inserted = 0;
|
||||
goto firstline;
|
||||
}
|
||||
|
@ -138,7 +137,8 @@ go_on: /* rescan, the following character has been read */
|
|||
ptok->tk_file = FileName;
|
||||
ptok->tk_line = LineNumber;
|
||||
|
||||
switch (class(ch)) { /* detect character class */
|
||||
switch (class(ch))
|
||||
{ /* detect character class */
|
||||
case STNL: /* newline, vertical space or formfeed */
|
||||
firstline:
|
||||
LineNumber++; /* also at vs and ff */
|
||||
|
@ -150,25 +150,32 @@ firstline:
|
|||
*/
|
||||
return ptok->tk_symb = EOI;
|
||||
|
||||
while ((ch = GetChar()),
|
||||
(ch == '#'
|
||||
while ((ch = GetChar()), (ch == '#'
|
||||
#ifndef NOPP
|
||||
|| ch == '/'
|
||||
#endif
|
||||
|| class(ch) == STSKIP)) {
|
||||
|| class(ch) == STSKIP))
|
||||
{
|
||||
/* blanks are allowed before hashes */
|
||||
if (ch == '#') {
|
||||
if (ch == '#')
|
||||
{
|
||||
/* a control line follows */
|
||||
domacro();
|
||||
#ifndef NOPP
|
||||
if (File_Inserted) {
|
||||
if (File_Inserted)
|
||||
{
|
||||
File_Inserted = 0;
|
||||
goto firstline;
|
||||
}
|
||||
} else if (ch == '/') {
|
||||
if ((GetChar() == '*') && !InputLevel) {
|
||||
}
|
||||
else if (ch == '/')
|
||||
{
|
||||
if ((GetChar() == '*') && !InputLevel)
|
||||
{
|
||||
skipcomment();
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
UnGetChar();
|
||||
break;
|
||||
}
|
||||
|
@ -186,9 +193,12 @@ firstline:
|
|||
#ifndef NOPP
|
||||
garbage:
|
||||
#endif
|
||||
if (040 < ch && ch < 0177) {
|
||||
if (040 < ch && ch < 0177)
|
||||
{
|
||||
return ptok->tk_symb = ch;
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
lexerror("garbage char \\%03o", ch);
|
||||
}
|
||||
goto again;
|
||||
|
@ -196,7 +206,8 @@ garbage:
|
|||
return ptok->tk_symb = ch;
|
||||
case STCOMP: /* maybe the start of a compound token */
|
||||
nch = GetChar(); /* character lookahead */
|
||||
switch (ch) {
|
||||
switch (ch)
|
||||
{
|
||||
case '!':
|
||||
if (nch == '=')
|
||||
return ptok->tk_symb = NOTEQUAL;
|
||||
|
@ -222,13 +233,14 @@ garbage:
|
|||
return ptok->tk_symb = MINAB;
|
||||
break;
|
||||
case '<':
|
||||
if (AccFileSpecifier) {
|
||||
if (AccFileSpecifier)
|
||||
{
|
||||
UnGetChar(); /* pushback nch */
|
||||
ptok->tk_bts = string_token("file specifier",
|
||||
'>', &(ptok->tk_len));
|
||||
ptok->tk_bts = string_token("file specifier", '>', &(ptok->tk_len));
|
||||
return ptok->tk_symb = FILESPECIFIER;
|
||||
}
|
||||
if (nch == '<') {
|
||||
if (nch == '<')
|
||||
{
|
||||
if ((nch = GetChar()) == '=')
|
||||
return ptok->tk_symb = LEFTAB;
|
||||
UnGetChar();
|
||||
|
@ -244,7 +256,8 @@ garbage:
|
|||
case '>':
|
||||
if (nch == '=')
|
||||
return ptok->tk_symb = GREATEREQ;
|
||||
if (nch == '>') {
|
||||
if (nch == '>')
|
||||
{
|
||||
if ((nch = GetChar()) == '=')
|
||||
return ptok->tk_symb = RIGHTAB;
|
||||
UnGetChar();
|
||||
|
@ -271,7 +284,8 @@ garbage:
|
|||
break;
|
||||
case '/':
|
||||
#ifndef NOPP
|
||||
if (nch == '*' && !InputLevel) {
|
||||
if (nch == '*' && !InputLevel)
|
||||
{
|
||||
skipcomment();
|
||||
goto again;
|
||||
}
|
||||
|
@ -295,12 +309,14 @@ garbage:
|
|||
return ptok->tk_symb = STRING;
|
||||
case STELL: /* wide character constant/string prefix */
|
||||
nch = GetChar();
|
||||
if (nch == '"') {
|
||||
ptok->tk_bts = string_token("wide character string",
|
||||
'"', &(ptok->tk_len));
|
||||
if (nch == '"')
|
||||
{
|
||||
ptok->tk_bts = string_token("wide character string", '"', &(ptok->tk_len));
|
||||
ptok->tk_fund = WCHAR; /* string of wide characters */
|
||||
return ptok->tk_symb = STRING;
|
||||
} else if (nch == '\'') {
|
||||
}
|
||||
else if (nch == '\'')
|
||||
{
|
||||
ptok->tk_ival = char_constant("wide character");
|
||||
ptok->tk_fund = INT;
|
||||
return ptok->tk_symb = INTEGER;
|
||||
|
@ -316,14 +332,18 @@ garbage:
|
|||
#ifndef NOPP
|
||||
int NoExpandNext = 0;
|
||||
|
||||
if (Unstacked) EnableMacros(); /* unstack macro's when allowed. */
|
||||
if (ch == NOEXPM) {
|
||||
if (Unstacked)
|
||||
EnableMacros(); /* unstack macro's when allowed. */
|
||||
if (ch == NOEXPM)
|
||||
{
|
||||
NoExpandNext = 1;
|
||||
ch = GetChar();
|
||||
}
|
||||
#endif
|
||||
do { /* read the identifier */
|
||||
if (++pos < idfsize) {
|
||||
do
|
||||
{ /* read the identifier */
|
||||
if (++pos < idfsize)
|
||||
{
|
||||
*tg++ = ch;
|
||||
}
|
||||
ch = GetChar();
|
||||
|
@ -337,23 +357,23 @@ garbage:
|
|||
idef->id_file = ptok->tk_file;
|
||||
idef->id_line = ptok->tk_line;
|
||||
#ifndef NOPP
|
||||
if (idef->id_macro && ReplaceMacros && !NoExpandNext) {
|
||||
if (idef->id_macro && ReplaceMacros && !NoExpandNext)
|
||||
{
|
||||
if (replace(idef))
|
||||
goto again;
|
||||
}
|
||||
if (UnknownIdIsZero && idef->id_reserved != SIZEOF) {
|
||||
if (UnknownIdIsZero && idef->id_reserved != SIZEOF)
|
||||
{
|
||||
ptok->tk_ival = (arith)0;
|
||||
ptok->tk_fund = INT;
|
||||
return ptok->tk_symb = INTEGER;
|
||||
}
|
||||
#endif /* NOPP */
|
||||
ptok->tk_symb = (
|
||||
idef->id_reserved
|
||||
ptok->tk_symb
|
||||
= (idef->id_reserved
|
||||
? idef->id_reserved
|
||||
: idef->id_def && idef->id_def->df_sc == TYPEDEF
|
||||
? TYPE_IDENTIFIER
|
||||
: IDENTIFIER
|
||||
);
|
||||
: idef->id_def && idef->id_def->df_sc == TYPEDEF ? TYPE_IDENTIFIER
|
||||
: IDENTIFIER);
|
||||
return IDENTIFIER;
|
||||
}
|
||||
case STNUM: /* a numeric constant */
|
||||
|
@ -362,22 +382,27 @@ garbage:
|
|||
register char* np = &buf[0];
|
||||
int flags = 0;
|
||||
|
||||
#define store(ch) if (--siz_left >= 0) \
|
||||
#define store(ch) \
|
||||
if (--siz_left >= 0) \
|
||||
*np++ = ch;
|
||||
|
||||
if (ch == '.') {
|
||||
if (ch == '.')
|
||||
{
|
||||
/* An embarrasing ambiguity. We have either a
|
||||
pp-number, a field operator, an ELLIPSIS or
|
||||
an error (..).
|
||||
*/
|
||||
ch = GetChar();
|
||||
if (!is_dig(ch)) { /* . or ... */
|
||||
if (ch == '.') {
|
||||
if (!is_dig(ch))
|
||||
{ /* . or ... */
|
||||
if (ch == '.')
|
||||
{
|
||||
if ((ch = GetChar()) == '.')
|
||||
return ptok->tk_symb = ELLIPSIS;
|
||||
UnGetChar(); /* not '.' */
|
||||
ChPushBack('.'); /* sigh ... */
|
||||
} else
|
||||
}
|
||||
else
|
||||
UnGetChar(); /* not '.' */
|
||||
return ptok->tk_symb = '.';
|
||||
}
|
||||
|
@ -387,30 +412,36 @@ garbage:
|
|||
}
|
||||
store(ch);
|
||||
ch = GetChar();
|
||||
while(in_idf(ch) || ch == '.') {
|
||||
while (in_idf(ch) || ch == '.')
|
||||
{
|
||||
store(ch);
|
||||
if (ch == '.') flags |= FLG_DOTSEEN;
|
||||
if (ch == 'e' || ch == 'E') {
|
||||
if (ch == '.')
|
||||
flags |= FLG_DOTSEEN;
|
||||
if (ch == 'e' || ch == 'E')
|
||||
{
|
||||
flags |= FLG_ESEEN;
|
||||
ch = GetChar();
|
||||
if (ch == '+' || ch == '-') {
|
||||
if (ch == '+' || ch == '-')
|
||||
{
|
||||
flags |= FLG_DOTSEEN; /* trick */
|
||||
store(ch);
|
||||
ch = GetChar();
|
||||
}
|
||||
} else ch = GetChar();
|
||||
}
|
||||
else
|
||||
ch = GetChar();
|
||||
}
|
||||
store('\0');
|
||||
UnGetChar();
|
||||
|
||||
np = &buf[0];
|
||||
ch = *np++;
|
||||
if (siz_left < 0) {
|
||||
if (siz_left < 0)
|
||||
{
|
||||
lexerror("number too long");
|
||||
if ((flags & FLG_DOTSEEN)
|
||||
|| (flags & FLG_ESEEN
|
||||
&& !(ch == '0'
|
||||
&& (*np == 'x' || *np == 'X')))) {
|
||||
|| (flags & FLG_ESEEN && !(ch == '0' && (*np == 'x' || *np == 'X'))))
|
||||
{
|
||||
ptok->tk_fval = Salloc("0.0", (unsigned)4);
|
||||
ptok->tk_fund = DOUBLE;
|
||||
return ptok->tk_symb = FLOATING;
|
||||
|
@ -421,8 +452,8 @@ garbage:
|
|||
}
|
||||
/* Now, the pp-number must be converted into a token */
|
||||
if ((flags & FLG_DOTSEEN)
|
||||
|| (flags & FLG_ESEEN
|
||||
&& !(ch == '0' && (*np == 'x' || *np == 'X')))) {
|
||||
|| (flags & FLG_ESEEN && !(ch == '0' && (*np == 'x' || *np == 'X'))))
|
||||
{
|
||||
strflt2tok(&buf[0], ptok);
|
||||
return ptok->tk_symb = FLOATING;
|
||||
}
|
||||
|
@ -433,8 +464,10 @@ garbage:
|
|||
return ptok->tk_symb = EOI;
|
||||
#ifndef NOPP
|
||||
case STMSPEC:
|
||||
if (!InputLevel) goto garbage;
|
||||
if (ch == TOKSEP) goto again;
|
||||
if (!InputLevel)
|
||||
goto garbage;
|
||||
if (ch == TOKSEP)
|
||||
goto again;
|
||||
/* fallthrough shouldn't happen */
|
||||
#endif
|
||||
default: /* this cannot happen */
|
||||
|
@ -444,8 +477,7 @@ garbage:
|
|||
}
|
||||
|
||||
#ifndef NOPP
|
||||
void
|
||||
skipcomment()
|
||||
void skipcomment()
|
||||
{
|
||||
/* The last character read has been the '*' of '/_*'. The
|
||||
characters, except NL and EOI, between '/_*' and the first
|
||||
|
@ -462,26 +494,34 @@ skipcomment()
|
|||
NoUnstack++;
|
||||
c = GetChar();
|
||||
#ifdef LINT
|
||||
if (! lint_skip_comment) {
|
||||
if (!lint_skip_comment)
|
||||
{
|
||||
lint_start_comment();
|
||||
lint_comment_char(c);
|
||||
}
|
||||
#endif /* LINT */
|
||||
do {
|
||||
while (c != '*') {
|
||||
if (class(c) == STNL) {
|
||||
do
|
||||
{
|
||||
while (c != '*')
|
||||
{
|
||||
if (class(c) == STNL)
|
||||
{
|
||||
++LineNumber;
|
||||
} else if (c == EOI) {
|
||||
}
|
||||
else if (c == EOI)
|
||||
{
|
||||
NoUnstack--;
|
||||
#ifdef LINT
|
||||
if (! lint_skip_comment) lint_end_comment();
|
||||
if (!lint_skip_comment)
|
||||
lint_end_comment();
|
||||
#endif /* LINT */
|
||||
return;
|
||||
}
|
||||
oldc = c;
|
||||
c = GetChar();
|
||||
#ifdef LINT
|
||||
if (! lint_skip_comment) lint_comment_char(c);
|
||||
if (!lint_skip_comment)
|
||||
lint_comment_char(c);
|
||||
#endif /* LINT */
|
||||
} /* last Character seen was '*' */
|
||||
c = GetChar();
|
||||
|
@ -489,19 +529,19 @@ skipcomment()
|
|||
lexwarning("comment inside comment ?");
|
||||
oldc = '*';
|
||||
#ifdef LINT
|
||||
if (! lint_skip_comment) lint_comment_char(c);
|
||||
if (!lint_skip_comment)
|
||||
lint_comment_char(c);
|
||||
#endif /* LINT */
|
||||
} while (c != '/');
|
||||
#ifdef LINT
|
||||
if (! lint_skip_comment) lint_end_comment();
|
||||
if (!lint_skip_comment)
|
||||
lint_end_comment();
|
||||
#endif /* LINT */
|
||||
NoUnstack--;
|
||||
}
|
||||
#endif /* NOPP */
|
||||
|
||||
arith
|
||||
char_constant(nm)
|
||||
char *nm;
|
||||
arith char_constant(nm) char* nm;
|
||||
{
|
||||
register arith val = 0;
|
||||
register int ch;
|
||||
|
@ -511,15 +551,18 @@ char_constant(nm)
|
|||
if (ch == '\'')
|
||||
lexerror("%s constant too short", nm);
|
||||
else
|
||||
while (ch != '\'') {
|
||||
if (ch == '\n') {
|
||||
while (ch != '\'')
|
||||
{
|
||||
if (ch == '\n')
|
||||
{
|
||||
lexerror("newline in %s constant", nm);
|
||||
LineNumber++;
|
||||
break;
|
||||
}
|
||||
if (ch == '\\')
|
||||
ch = quoted(GetChar());
|
||||
if (ch >= 128) ch -= 256;
|
||||
if (ch >= 128)
|
||||
ch -= 256;
|
||||
if (size < (int)int_size)
|
||||
val |= ch << 8 * size;
|
||||
size++;
|
||||
|
@ -532,9 +575,7 @@ char_constant(nm)
|
|||
return val;
|
||||
}
|
||||
|
||||
char *
|
||||
string_token(nm, stop_char, plen)
|
||||
char *nm;
|
||||
char* string_token(nm, stop_char, plen) char* nm;
|
||||
int* plen;
|
||||
{
|
||||
register int ch;
|
||||
|
@ -543,13 +584,16 @@ string_token(nm, stop_char, plen)
|
|||
register int pos = 0;
|
||||
|
||||
ch = GetChar();
|
||||
while (ch != stop_char) {
|
||||
if (ch == '\n') {
|
||||
while (ch != stop_char)
|
||||
{
|
||||
if (ch == '\n')
|
||||
{
|
||||
lexerror("newline in %s", nm);
|
||||
LineNumber++;
|
||||
break;
|
||||
}
|
||||
if (ch == EOI) {
|
||||
if (ch == EOI)
|
||||
{
|
||||
lexerror("end-of-file inside %s", nm);
|
||||
break;
|
||||
}
|
||||
|
@ -565,16 +609,16 @@ string_token(nm, stop_char, plen)
|
|||
return str;
|
||||
}
|
||||
|
||||
int
|
||||
quoted(ch)
|
||||
register int ch;
|
||||
int quoted(ch) register int ch;
|
||||
{
|
||||
/* quoted() replaces an escaped character sequence by the
|
||||
character meant.
|
||||
*/
|
||||
/* first char after backslash already in ch */
|
||||
if (!is_oct(ch)) { /* a quoted char */
|
||||
switch (ch) {
|
||||
if (!is_oct(ch))
|
||||
{ /* a quoted char */
|
||||
switch (ch)
|
||||
{
|
||||
case 'n':
|
||||
ch = '\n';
|
||||
break;
|
||||
|
@ -601,7 +645,8 @@ quoted(ch)
|
|||
register int hex = 0;
|
||||
register int vch;
|
||||
|
||||
for (;;) {
|
||||
for (;;)
|
||||
{
|
||||
ch = GetChar();
|
||||
if ((vch = hex_val(ch)) == -1)
|
||||
break;
|
||||
|
@ -612,10 +657,12 @@ quoted(ch)
|
|||
}
|
||||
}
|
||||
}
|
||||
else { /* a quoted octal */
|
||||
else
|
||||
{ /* a quoted octal */
|
||||
register int oct = 0, cnt = 0;
|
||||
|
||||
do {
|
||||
do
|
||||
{
|
||||
oct = oct * 8 + (ch - '0');
|
||||
ch = GetChar();
|
||||
} while (is_oct(ch) && ++cnt < 3);
|
||||
|
@ -625,19 +672,12 @@ quoted(ch)
|
|||
return ch & 0377;
|
||||
}
|
||||
|
||||
|
||||
int
|
||||
hex_val(ch)
|
||||
register int ch;
|
||||
int hex_val(ch) register int ch;
|
||||
{
|
||||
return is_dig(ch) ? ch - '0'
|
||||
: is_hex(ch) ? (ch - 'a' + 10) & 017
|
||||
: -1;
|
||||
return is_dig(ch) ? ch - '0' : is_hex(ch) ? (ch - 'a' + 10) & 017 : -1;
|
||||
}
|
||||
|
||||
|
||||
int
|
||||
GetChar()
|
||||
int GetChar()
|
||||
{
|
||||
/* The routines GetChar and trigraph parses the trigraph
|
||||
sequences and removes occurences of \\\n.
|
||||
|
@ -655,9 +695,11 @@ again:
|
|||
ch = trigraph();
|
||||
|
||||
/* \<newline> is removed from the input stream */
|
||||
if (ch == '\\') {
|
||||
if (ch == '\\')
|
||||
{
|
||||
LoadChar(ch);
|
||||
if (ch == '\n') {
|
||||
if (ch == '\n')
|
||||
{
|
||||
++LineNumber;
|
||||
goto again;
|
||||
}
|
||||
|
@ -669,15 +711,16 @@ again:
|
|||
}
|
||||
|
||||
#ifndef NOPP
|
||||
int
|
||||
trigraph()
|
||||
int trigraph()
|
||||
{
|
||||
register int ch;
|
||||
|
||||
LoadChar(ch);
|
||||
if (ch == '?') {
|
||||
if (ch == '?')
|
||||
{
|
||||
LoadChar(ch);
|
||||
switch (ch) { /* its a trigraph */
|
||||
switch (ch)
|
||||
{ /* its a trigraph */
|
||||
case '=':
|
||||
ch = '#';
|
||||
return (ch);
|
||||
|
@ -716,47 +759,62 @@ trigraph()
|
|||
/* strflt2tok only checks the syntax of the floating-point number and
|
||||
* selects the right type for the number.
|
||||
*/
|
||||
strflt2tok(fltbuf, ptok)
|
||||
char fltbuf[];
|
||||
strflt2tok(fltbuf, ptok) char fltbuf[];
|
||||
struct token* ptok;
|
||||
{
|
||||
register char* cp = fltbuf;
|
||||
int malformed = 0;
|
||||
|
||||
while (is_dig(*cp)) cp++;
|
||||
if (*cp == '.') {
|
||||
while (is_dig(*cp))
|
||||
cp++;
|
||||
if (*cp == '.')
|
||||
{
|
||||
cp++;
|
||||
while (is_dig(*cp))
|
||||
cp++;
|
||||
while (is_dig(*cp)) cp++;
|
||||
}
|
||||
if (*cp == 'e' || *cp == 'E') {
|
||||
if (*cp == 'e' || *cp == 'E')
|
||||
{
|
||||
cp++;
|
||||
if (*cp == '+' || *cp == '-')
|
||||
cp++;
|
||||
if (!is_dig(*cp)) malformed++;
|
||||
while (is_dig(*cp)) cp++;
|
||||
if (!is_dig(*cp))
|
||||
malformed++;
|
||||
while (is_dig(*cp))
|
||||
cp++;
|
||||
}
|
||||
if (*cp == 'f' || *cp == 'F') {
|
||||
if (*(cp + 1)) malformed++;
|
||||
if (*cp == 'f' || *cp == 'F')
|
||||
{
|
||||
if (*(cp + 1))
|
||||
malformed++;
|
||||
*cp = '\0';
|
||||
ptok->tk_fund = FLOAT;
|
||||
} else if (*cp == 'l' || *cp == 'L') {
|
||||
if (*(cp + 1)) malformed++;
|
||||
}
|
||||
else if (*cp == 'l' || *cp == 'L')
|
||||
{
|
||||
if (*(cp + 1))
|
||||
malformed++;
|
||||
*cp = '\0';
|
||||
ptok->tk_fund = LNGDBL;
|
||||
} else {
|
||||
if (*cp) malformed++;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (*cp)
|
||||
malformed++;
|
||||
ptok->tk_fund = DOUBLE;
|
||||
}
|
||||
if (malformed) {
|
||||
if (malformed)
|
||||
{
|
||||
lexerror("malformed floating constant");
|
||||
ptok->tk_fval = Salloc("0.0", (unsigned)4);
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
ptok->tk_fval = Salloc(fltbuf, (unsigned)(cp - fltbuf + 1));
|
||||
}
|
||||
}
|
||||
|
||||
strint2tok(intbuf, ptok)
|
||||
char intbuf[];
|
||||
strint2tok(intbuf, ptok) char intbuf[];
|
||||
struct token* ptok;
|
||||
{
|
||||
register char* cp = intbuf;
|
||||
|
@ -766,12 +824,16 @@ struct token *ptok;
|
|||
int fund;
|
||||
|
||||
assert(*cp != '-');
|
||||
if (*cp == '0') {
|
||||
if (*cp == '0')
|
||||
{
|
||||
cp++;
|
||||
if (*cp == 'x' || *cp == 'X') {
|
||||
if (*cp == 'x' || *cp == 'X')
|
||||
{
|
||||
cp++;
|
||||
base = 16;
|
||||
} else base = 8;
|
||||
}
|
||||
else
|
||||
base = 8;
|
||||
}
|
||||
/* The upperbound will be the same as when computed with
|
||||
* max_unsigned_arith / base (since base is even). The problem here
|
||||
|
@ -779,68 +841,99 @@ struct token *ptok;
|
|||
*/
|
||||
ubound = max_arith / (base / 2);
|
||||
|
||||
while (is_hex(*cp)) {
|
||||
while (is_hex(*cp))
|
||||
{
|
||||
dig = hex_val(*cp);
|
||||
if (dig >= base) {
|
||||
if (dig >= base)
|
||||
{
|
||||
malformed++; /* ignore */
|
||||
}
|
||||
else {
|
||||
if (val < 0 || val > ubound) ovfl++;
|
||||
else
|
||||
{
|
||||
if (val < 0 || val > ubound)
|
||||
ovfl++;
|
||||
val *= base;
|
||||
if (val < 0 && val + dig >= 0) ovfl++;
|
||||
if (val < 0 && val + dig >= 0)
|
||||
ovfl++;
|
||||
val += dig;
|
||||
}
|
||||
cp++;
|
||||
}
|
||||
|
||||
while (*cp) {
|
||||
if (*cp == 'l' || *cp == 'L') lng_flg++;
|
||||
else if (*cp == 'u' || *cp == 'U') uns_flg++;
|
||||
else break;
|
||||
while (*cp)
|
||||
{
|
||||
if (*cp == 'l' || *cp == 'L')
|
||||
lng_flg++;
|
||||
else if (*cp == 'u' || *cp == 'U')
|
||||
uns_flg++;
|
||||
else
|
||||
break;
|
||||
cp++;
|
||||
}
|
||||
if (*cp) {
|
||||
if (*cp)
|
||||
{
|
||||
malformed++;
|
||||
}
|
||||
if (malformed) {
|
||||
lexerror("malformed %s integer constant",
|
||||
(base == 10 ? "decimal"
|
||||
: (base == 8 ? "octal"
|
||||
: "hexadecimal")));
|
||||
} else {
|
||||
if (malformed)
|
||||
{
|
||||
lexerror(
|
||||
"malformed %s integer constant",
|
||||
(base == 10 ? "decimal" : (base == 8 ? "octal" : "hexadecimal")));
|
||||
}
|
||||
else
|
||||
{
|
||||
if (lng_flg > 1)
|
||||
lexerror("only one long suffix allowed");
|
||||
if (uns_flg > 1)
|
||||
lexerror("only one unsigned suffix allowed");
|
||||
}
|
||||
if (ovfl) {
|
||||
if (ovfl)
|
||||
{
|
||||
lexwarning("overflow in constant");
|
||||
fund = ULONG;
|
||||
} else if (!lng_flg && (val & full_mask[(int)int_size]) == val) {
|
||||
if (val >= 0 && val <= max_int) {
|
||||
}
|
||||
else if (!lng_flg && (val & full_mask[(int)int_size]) == val)
|
||||
{
|
||||
if (val >= 0 && val <= max_int)
|
||||
{
|
||||
fund = INT;
|
||||
} else if (int_size == long_size) {
|
||||
}
|
||||
else if (int_size == long_size)
|
||||
{
|
||||
fund = UNSIGNED;
|
||||
} else if (base == 10 && !uns_flg)
|
||||
}
|
||||
else if (base == 10 && !uns_flg)
|
||||
fund = LONG;
|
||||
else fund = UNSIGNED;
|
||||
} else if((val & full_mask[(int)long_size]) == val) {
|
||||
if (val >= 0) fund = LONG;
|
||||
else fund = ULONG;
|
||||
} else { /* sizeof(arith) is greater than long_size */
|
||||
else
|
||||
fund = UNSIGNED;
|
||||
}
|
||||
else if ((val & full_mask[(int)long_size]) == val)
|
||||
{
|
||||
if (val >= 0)
|
||||
fund = LONG;
|
||||
else
|
||||
fund = ULONG;
|
||||
}
|
||||
else
|
||||
{ /* sizeof(arith) is greater than long_size */
|
||||
assert(arith_size > long_size);
|
||||
lexwarning("constant too large for target machine");
|
||||
/* cut the size to prevent further complaints */
|
||||
val &= full_mask[(int)long_size];
|
||||
fund = ULONG;
|
||||
}
|
||||
if (lng_flg) {
|
||||
if (lng_flg)
|
||||
{
|
||||
/* fund can't be INT */
|
||||
if (fund == UNSIGNED) fund = ULONG;
|
||||
if (fund == UNSIGNED)
|
||||
fund = ULONG;
|
||||
}
|
||||
if (uns_flg) {
|
||||
if (fund == INT) fund = UNSIGNED;
|
||||
else if (fund == LONG) fund = ULONG;
|
||||
if (uns_flg)
|
||||
{
|
||||
if (fund == INT)
|
||||
fund = UNSIGNED;
|
||||
else if (fund == LONG)
|
||||
fund = ULONG;
|
||||
}
|
||||
ptok->tk_fund = fund;
|
||||
ptok->tk_ival = val;
|
||||
|
|
|
@ -37,16 +37,12 @@ extern arith char_constant();
|
|||
|
||||
void skipcomment();
|
||||
|
||||
int
|
||||
LLlex()
|
||||
int LLlex()
|
||||
{
|
||||
return (DOT != EOF) ? GetToken(&dot) : EOF;
|
||||
}
|
||||
|
||||
|
||||
int
|
||||
GetToken(ptok)
|
||||
register struct token *ptok;
|
||||
int GetToken(ptok) register struct token* ptok;
|
||||
{
|
||||
/* GetToken() is the actual token recognizer. It calls the
|
||||
control line interpreter if it encounters a "\n{w}*#"
|
||||
|
@ -63,7 +59,8 @@ again: /* rescan the input after an error or replacement */
|
|||
fatal("non-ascii '\\%03o' read", ch & 0377);
|
||||
/* keep track of the place of the token in the file */
|
||||
|
||||
switch (class(ch)) { /* detect character class */
|
||||
switch (class(ch))
|
||||
{ /* detect character class */
|
||||
case STNL: /* newline, vertical space or formfeed */
|
||||
LineNumber++;
|
||||
return ptok->tk_symb = EOF;
|
||||
|
@ -80,7 +77,8 @@ garbage:
|
|||
return ptok->tk_symb = ch;
|
||||
case STCOMP: /* maybe the start of a compound token */
|
||||
nch = GetChar(); /* character lookahead */
|
||||
switch (ch) {
|
||||
switch (ch)
|
||||
{
|
||||
case '!':
|
||||
if (nch == '=')
|
||||
return ptok->tk_symb = NOTEQUAL;
|
||||
|
@ -110,17 +108,20 @@ garbage:
|
|||
UnGetChar();
|
||||
return ptok->tk_symb = ch;
|
||||
case '<':
|
||||
if (AccFileSpecifier) {
|
||||
if (AccFileSpecifier)
|
||||
{
|
||||
UnGetChar(); /* pushback nch */
|
||||
ptok->tk_str =
|
||||
string_token("file specifier", '>');
|
||||
ptok->tk_str = string_token("file specifier", '>');
|
||||
return ptok->tk_symb = FILESPECIFIER;
|
||||
} else if (nch == '<') {
|
||||
}
|
||||
else if (nch == '<')
|
||||
{
|
||||
if ((nch = GetChar()) == '=')
|
||||
return ptok->tk_symb = LEFTAB;
|
||||
UnGetChar();
|
||||
return ptok->tk_symb = LEFT;
|
||||
} else if (nch == '=')
|
||||
}
|
||||
else if (nch == '=')
|
||||
return ptok->tk_symb = LESSEQ;
|
||||
UnGetChar();
|
||||
return ptok->tk_symb = ch;
|
||||
|
@ -132,7 +133,8 @@ garbage:
|
|||
case '>':
|
||||
if (nch == '=')
|
||||
return ptok->tk_symb = GREATEREQ;
|
||||
else if (nch == '>') {
|
||||
else if (nch == '>')
|
||||
{
|
||||
if ((nch = GetChar()) == '=')
|
||||
return ptok->tk_symb = RIGHTAB;
|
||||
UnGetChar();
|
||||
|
@ -163,7 +165,8 @@ garbage:
|
|||
UnGetChar();
|
||||
return ptok->tk_symb = ch;
|
||||
case '/':
|
||||
if (nch == '*' && !InputLevel) {
|
||||
if (nch == '*' && !InputLevel)
|
||||
{
|
||||
skipcomment();
|
||||
goto again;
|
||||
}
|
||||
|
@ -183,11 +186,13 @@ garbage:
|
|||
return ptok->tk_symb = STRING;
|
||||
case STELL: /* wide character constant/string prefix */
|
||||
nch = GetChar();
|
||||
if (nch == '"') {
|
||||
ptok->tk_str =
|
||||
string_token("wide character string", '"');
|
||||
if (nch == '"')
|
||||
{
|
||||
ptok->tk_str = string_token("wide character string", '"');
|
||||
return ptok->tk_symb = STRING;
|
||||
} else if (nch == '\'') {
|
||||
}
|
||||
else if (nch == '\'')
|
||||
{
|
||||
ptok->tk_val = char_constant("wide character");
|
||||
return ptok->tk_symb = INTEGER;
|
||||
}
|
||||
|
@ -200,29 +205,53 @@ garbage:
|
|||
register char* maxpos = &buf[idfsize];
|
||||
int NoExpandNext = 0;
|
||||
|
||||
#define tstmac(bx) if (!(bits[ch] & bx)) goto nomac
|
||||
#define tstmac(bx) \
|
||||
if (!(bits[ch] & bx)) \
|
||||
goto nomac
|
||||
#define cpy *tg++ = ch
|
||||
#define load (ch = GetChar()); if (!in_idf(ch)) goto endidf
|
||||
#define load \
|
||||
(ch = GetChar()); \
|
||||
if (!in_idf(ch)) \
|
||||
goto endidf
|
||||
|
||||
if (Unstacked) EnableMacros(); /* unstack macro's when allowed. */
|
||||
if (ch == NOEXPM) {
|
||||
if (Unstacked)
|
||||
EnableMacros(); /* unstack macro's when allowed. */
|
||||
if (ch == NOEXPM)
|
||||
{
|
||||
NoExpandNext = 1;
|
||||
ch = GetChar();
|
||||
}
|
||||
#ifdef DOBITS
|
||||
cpy; tstmac(bit0); load;
|
||||
cpy; tstmac(bit1); load;
|
||||
cpy; tstmac(bit2); load;
|
||||
cpy; tstmac(bit3); load;
|
||||
cpy; tstmac(bit4); load;
|
||||
cpy; tstmac(bit5); load;
|
||||
cpy; tstmac(bit6); load;
|
||||
cpy; tstmac(bit7); load;
|
||||
#endif
|
||||
for(;;) {
|
||||
if (tg < maxpos) {
|
||||
cpy;
|
||||
|
||||
tstmac(bit0);
|
||||
load;
|
||||
cpy;
|
||||
tstmac(bit1);
|
||||
load;
|
||||
cpy;
|
||||
tstmac(bit2);
|
||||
load;
|
||||
cpy;
|
||||
tstmac(bit3);
|
||||
load;
|
||||
cpy;
|
||||
tstmac(bit4);
|
||||
load;
|
||||
cpy;
|
||||
tstmac(bit5);
|
||||
load;
|
||||
cpy;
|
||||
tstmac(bit6);
|
||||
load;
|
||||
cpy;
|
||||
tstmac(bit7);
|
||||
load;
|
||||
#endif
|
||||
for (;;)
|
||||
{
|
||||
if (tg < maxpos)
|
||||
{
|
||||
cpy;
|
||||
}
|
||||
load;
|
||||
}
|
||||
|
@ -230,10 +259,12 @@ garbage:
|
|||
/*if (ch != EOI) UnGetChar();*/
|
||||
UnGetChar();
|
||||
*tg++ = '\0'; /* mark the end of the identifier */
|
||||
if (ReplaceMacros) {
|
||||
if (ReplaceMacros)
|
||||
{
|
||||
register struct idf* idef = findidf(buf);
|
||||
|
||||
if (idef && idef->id_macro && !NoExpandNext) {
|
||||
if (idef && idef->id_macro && !NoExpandNext)
|
||||
{
|
||||
if (replace(idef))
|
||||
goto again;
|
||||
}
|
||||
|
@ -241,15 +272,18 @@ garbage:
|
|||
|
||||
nomac: /* buf can already be null-terminated. soit */
|
||||
ch = GetChar();
|
||||
while (in_idf(ch)) {
|
||||
if (tg < maxpos) *tg++ = ch;
|
||||
while (in_idf(ch))
|
||||
{
|
||||
if (tg < maxpos)
|
||||
*tg++ = ch;
|
||||
ch = GetChar();
|
||||
}
|
||||
UnGetChar();
|
||||
*tg++ = '\0'; /* mark the end of the identifier */
|
||||
|
||||
NoExpandNext = 0;
|
||||
if (UnknownIdIsZero) {
|
||||
if (UnknownIdIsZero)
|
||||
{
|
||||
ptok->tk_val = (arith)0;
|
||||
return ptok->tk_symb = INTEGER;
|
||||
}
|
||||
|
@ -268,46 +302,59 @@ garbage:
|
|||
* nothing to do with ellipsis we just return when the
|
||||
* pp-number starts with a '.'
|
||||
*/
|
||||
if (ch == '.') {
|
||||
if (ch == '.')
|
||||
{
|
||||
return ptok->tk_symb = ch;
|
||||
}
|
||||
if (ch == '0') {
|
||||
if (ch == '0')
|
||||
{
|
||||
ch = GetChar();
|
||||
if (ch == 'x' || ch == 'X') {
|
||||
if (ch == 'x' || ch == 'X')
|
||||
{
|
||||
base = 16;
|
||||
ch = GetChar();
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
base = 8;
|
||||
}
|
||||
|
||||
}
|
||||
while ((vch = val_in_base(ch, base)) >= 0) {
|
||||
if (val < 0 || val > ubound) ovfl++;
|
||||
while ((vch = val_in_base(ch, base)) >= 0)
|
||||
{
|
||||
if (val < 0 || val > ubound)
|
||||
ovfl++;
|
||||
val *= base;
|
||||
if (val < 0 && val + vch >= 0) ovfl++;
|
||||
if (val < 0 && val + vch >= 0)
|
||||
ovfl++;
|
||||
val += vch;
|
||||
ch = GetChar();
|
||||
}
|
||||
ptok->tk_unsigned = 0;
|
||||
if (ch == 'u' || ch == 'U') {
|
||||
if (ch == 'u' || ch == 'U')
|
||||
{
|
||||
ptok->tk_unsigned = 1;
|
||||
ch = GetChar();
|
||||
if (ch == 'l' || ch == 'L') {
|
||||
if (ch == 'l' || ch == 'L')
|
||||
{
|
||||
ch = GetChar();
|
||||
}
|
||||
}
|
||||
else if (ch == 'l' || ch == 'L') {
|
||||
else if (ch == 'l' || ch == 'L')
|
||||
{
|
||||
ch = GetChar();
|
||||
if (ch == 'u' || ch == 'U') {
|
||||
if (ch == 'u' || ch == 'U')
|
||||
{
|
||||
ptok->tk_unsigned = 1;
|
||||
ch = GetChar();
|
||||
}
|
||||
}
|
||||
if (ovfl) {
|
||||
if (ovfl)
|
||||
{
|
||||
warning("overflow in constant");
|
||||
ptok->tk_unsigned = 1;
|
||||
}
|
||||
else if (val < 0) {
|
||||
else if (val < 0)
|
||||
{
|
||||
/* give warning??? */
|
||||
ptok->tk_unsigned = 1;
|
||||
}
|
||||
|
@ -318,8 +365,10 @@ garbage:
|
|||
case STEOI: /* end of text on source file */
|
||||
return ptok->tk_symb = EOF;
|
||||
case STMSPEC:
|
||||
if (!InputLevel) goto garbage;
|
||||
if (ch == TOKSEP) goto again;
|
||||
if (!InputLevel)
|
||||
goto garbage;
|
||||
if (ch == TOKSEP)
|
||||
goto again;
|
||||
/* fallthrough shouldn't happen */
|
||||
default: /* this cannot happen */
|
||||
crash("bad class for char 0%o", ch);
|
||||
|
@ -327,8 +376,7 @@ garbage:
|
|||
/*NOTREACHED*/
|
||||
}
|
||||
|
||||
void
|
||||
skipcomment()
|
||||
void skipcomment()
|
||||
{
|
||||
/* The last character read has been the '*' of '/_*'. The
|
||||
characters, except NL and EOI, between '/_*' and the first
|
||||
|
@ -344,11 +392,16 @@ skipcomment()
|
|||
|
||||
NoUnstack++;
|
||||
c = GetChar();
|
||||
do {
|
||||
while (c != '*') {
|
||||
if (class(c) == STNL) {
|
||||
do
|
||||
{
|
||||
while (c != '*')
|
||||
{
|
||||
if (class(c) == STNL)
|
||||
{
|
||||
++LineNumber;
|
||||
} else if (c == EOI) {
|
||||
}
|
||||
else if (c == EOI)
|
||||
{
|
||||
NoUnstack--;
|
||||
return;
|
||||
}
|
||||
|
@ -359,9 +412,7 @@ skipcomment()
|
|||
NoUnstack--;
|
||||
}
|
||||
|
||||
arith
|
||||
char_constant(nm)
|
||||
char *nm;
|
||||
arith char_constant(nm) char* nm;
|
||||
{
|
||||
register arith val = 0;
|
||||
register int ch;
|
||||
|
@ -371,15 +422,18 @@ char_constant(nm)
|
|||
if (ch == '\'')
|
||||
error("%s constant too short", nm);
|
||||
else
|
||||
while (ch != '\'') {
|
||||
if (ch == '\n') {
|
||||
while (ch != '\'')
|
||||
{
|
||||
if (ch == '\n')
|
||||
{
|
||||
error("newline in %s constant", nm);
|
||||
LineNumber++;
|
||||
break;
|
||||
}
|
||||
if (ch == '\\')
|
||||
ch = quoted(GetChar());
|
||||
if (ch >= 128) ch -= 256;
|
||||
if (ch >= 128)
|
||||
ch -= 256;
|
||||
if (size < sizeof(arith))
|
||||
val |= ch << (8 * size);
|
||||
size++;
|
||||
|
@ -392,9 +446,7 @@ char_constant(nm)
|
|||
return val;
|
||||
}
|
||||
|
||||
char *
|
||||
string_token(nm, stop_char)
|
||||
char *nm;
|
||||
char* string_token(nm, stop_char) char* nm;
|
||||
{
|
||||
register int ch;
|
||||
register int str_size;
|
||||
|
@ -402,13 +454,16 @@ string_token(nm, stop_char)
|
|||
register int pos = 0;
|
||||
|
||||
ch = GetChar();
|
||||
while (ch != stop_char) {
|
||||
if (ch == '\n') {
|
||||
while (ch != stop_char)
|
||||
{
|
||||
if (ch == '\n')
|
||||
{
|
||||
error("newline in %s", nm);
|
||||
LineNumber++;
|
||||
break;
|
||||
}
|
||||
if (ch == EOI) {
|
||||
if (ch == EOI)
|
||||
{
|
||||
error("end-of-file inside %s", nm);
|
||||
break;
|
||||
}
|
||||
|
@ -424,16 +479,16 @@ string_token(nm, stop_char)
|
|||
return str;
|
||||
}
|
||||
|
||||
int
|
||||
quoted(ch)
|
||||
register int ch;
|
||||
int quoted(ch) register int ch;
|
||||
{
|
||||
/* quoted() replaces an escaped character sequence by the
|
||||
character meant.
|
||||
*/
|
||||
/* first char after backslash already in ch */
|
||||
if (!is_oct(ch)) { /* a quoted char */
|
||||
switch (ch) {
|
||||
if (!is_oct(ch))
|
||||
{ /* a quoted char */
|
||||
switch (ch)
|
||||
{
|
||||
case 'n':
|
||||
ch = '\n';
|
||||
break;
|
||||
|
@ -460,7 +515,8 @@ quoted(ch)
|
|||
register int hex = 0;
|
||||
register int vch;
|
||||
|
||||
for (;;) {
|
||||
for (;;)
|
||||
{
|
||||
ch = GetChar();
|
||||
if (vch = val_in_base(ch, 16), vch == -1)
|
||||
break;
|
||||
|
@ -470,10 +526,13 @@ quoted(ch)
|
|||
ch = hex;
|
||||
}
|
||||
}
|
||||
} else { /* a quoted octal */
|
||||
}
|
||||
else
|
||||
{ /* a quoted octal */
|
||||
register int oct = 0, cnt = 0;
|
||||
|
||||
do {
|
||||
do
|
||||
{
|
||||
oct = oct * 8 + (ch - '0');
|
||||
ch = GetChar();
|
||||
} while (is_oct(ch) && ++cnt < 3);
|
||||
|
@ -483,29 +542,23 @@ quoted(ch)
|
|||
return ch & 0377;
|
||||
}
|
||||
|
||||
|
||||
int
|
||||
val_in_base(ch, base)
|
||||
register int ch;
|
||||
int val_in_base(ch, base) register int ch;
|
||||
{
|
||||
switch (base)
|
||||
{
|
||||
switch (base) {
|
||||
case 8:
|
||||
return (is_dig(ch) && ch < '9') ? ch - '0' : -1;
|
||||
case 10:
|
||||
return is_dig(ch) ? ch - '0' : -1;
|
||||
case 16:
|
||||
return is_dig(ch) ? ch - '0'
|
||||
: is_hex(ch) ? (ch - 'a' + 10) & 017
|
||||
: -1;
|
||||
return is_dig(ch) ? ch - '0' : is_hex(ch) ? (ch - 'a' + 10) & 017 : -1;
|
||||
default:
|
||||
fatal("(val_in_base) illegal base value %d", base);
|
||||
/* NOTREACHED */
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
int
|
||||
GetChar()
|
||||
int GetChar()
|
||||
{
|
||||
/* The routines GetChar and trigraph parses the trigraph
|
||||
sequences and removes occurences of \\\n.
|
||||
|
@ -520,9 +573,11 @@ again:
|
|||
ch = trigraph();
|
||||
|
||||
/* \\\n are removed from the input stream */
|
||||
if (ch == '\\') {
|
||||
if (ch == '\\')
|
||||
{
|
||||
LoadChar(ch);
|
||||
if (ch == '\n') {
|
||||
if (ch == '\n')
|
||||
{
|
||||
++LineNumber;
|
||||
goto again;
|
||||
}
|
||||
|
@ -532,16 +587,16 @@ again:
|
|||
return (LexSave = ch);
|
||||
}
|
||||
|
||||
|
||||
int
|
||||
trigraph()
|
||||
int trigraph()
|
||||
{
|
||||
register int ch;
|
||||
|
||||
LoadChar(ch);
|
||||
if (ch == '?') {
|
||||
if (ch == '?')
|
||||
{
|
||||
LoadChar(ch);
|
||||
switch (ch) { /* its a trigraph */
|
||||
switch (ch)
|
||||
{ /* its a trigraph */
|
||||
case '=':
|
||||
ch = '#';
|
||||
return (ch);
|
||||
|
|
Loading…
Reference in a new issue