1
0
mirror of https://github.com/cc65/cc65.git synced 2024-08-08 02:29:11 +00:00

Some octal character constants were not working.

The vertical tab '\v' character constant was not accepted.
Added some error recovery in case of illegal character constants.


git-svn-id: svn://svn.cc65.org/cc65/trunk@2425 b7a2c559-68d2-44c3-8de9-860c34a00d81
This commit is contained in:
cuz 2003-08-29 09:16:05 +00:00
parent 2e1db7ae38
commit e6568c9763

View File

@ -243,8 +243,8 @@ static void SetTok (int tok)
static int ParseChar (void) static int ParseChar (void)
/* Parse a character. Converts \n into EOL, etc. */ /* Parse a character. Converts \n into EOL, etc. */
{ {
int i; int I;
unsigned val; unsigned Val;
int C; int C;
/* Check for escape chars */ /* Check for escape chars */
@ -253,51 +253,71 @@ static int ParseChar (void)
switch (CurC) { switch (CurC) {
case 'b': case 'b':
C = '\b'; C = '\b';
break; break;
case 'f': case 'f':
C = '\f'; C = '\f';
break; break;
case 'r': case 'r':
C = '\r'; C = '\r';
break; break;
case 'n': case 'n':
C = '\n'; C = '\n';
break; break;
case 't': case 't':
C = '\t'; C = '\t';
break; break;
case 'v':
C = '\v';
break;
case '\"': case '\"':
C = '\"'; C = '\"';
break; break;
case '\'': case '\'':
C = '\''; C = '\'';
break; break;
case '\\': case '\\':
C = '\\'; C = '\\';
break; break;
case 'x': case 'x':
case 'X': case 'X':
/* Hex character constant */ /* Hex character constant */
NextChar (); NextChar ();
val = HexVal (CurC) << 4; Val = HexVal (CurC) << 4;
NextChar (); NextChar ();
C = val | HexVal (CurC); /* Do not translate */ C = Val | HexVal (CurC); /* Do not translate */
break; break;
case '0': case '0':
case '1': case '1':
case '2': case '2':
case '3': case '3':
case '4':
case '5':
case '6':
case '7':
/* Octal constant */ /* Octal constant */
i = 0; I = 0;
C = CurC - '0'; Val = CurC - '0';
while (NextC >= '0' && NextC <= '7' && i++ < 4) { while (NextC >= '0' && NextC <= '7' && ++I <= 3) {
NextChar (); NextChar ();
C = (C << 3) | (CurC - '0'); Val = (Val << 3) | (CurC - '0');
} }
C = (int) Val;
if (Val >= 256) {
Error ("Character constant out of range");
C = ' ';
}
break; break;
default: default:
Error ("Illegal character constant"); Error ("Illegal character constant");
C = ' '; C = ' ';
/* Try to do error recovery, otherwise the compiler will spit
* out thousands of errors in this place and abort.
*/
if (CurC != '\'' && CurC != '\0') {
while (NextC != '\'' && NextC != '\"' && NextC != '\0') {
NextChar ();
}
}
break; break;
} }
} else { } else {