1
0
mirror of https://github.com/cc65/cc65.git synced 2025-01-11 11:30:13 +00:00

Fixed the bug that C keywords were not simply recognized as identifiers in preprocessing.

This commit is contained in:
acqn 2022-08-07 16:14:45 +08:00
parent 7a139a800e
commit 4bb4f033ea
3 changed files with 21 additions and 10 deletions

View File

@ -215,6 +215,12 @@ static void PPhie11 (PPExpr* Expr)
} }
} }
/* Check for excessive expressions */
if (!TokIsPunc (&CurTok)) {
PPError ("Missing binary operator");
PPErrorSkipLine ();
}
} }
@ -854,7 +860,7 @@ void ParsePPExprInLine (PPExpr* Expr)
/* Initialize the parser status */ /* Initialize the parser status */
PPEvaluationFailed = 0; PPEvaluationFailed = 0;
PPEvaluationEnabled = 1; PPEvaluationEnabled = 1;
NextLineDisabled = 1; PPParserRunning = 1;
/* Parse */ /* Parse */
PPExprInit (Expr); PPExprInit (Expr);
@ -867,5 +873,5 @@ void ParsePPExprInLine (PPExpr* Expr)
} }
/* Restore parser status */ /* Restore parser status */
NextLineDisabled = 0; PPParserRunning = 0;
} }

View File

@ -69,7 +69,7 @@
Token CurTok; /* The current token */ Token CurTok; /* The current token */
Token NextTok; /* The next token */ Token NextTok; /* The next token */
int NextLineDisabled; /* Disabled to read next line */ int PPParserRunning; /* Is tokenizer used by the preprocessor */
@ -189,8 +189,10 @@ static int SkipWhite (void)
{ {
while (1) { while (1) {
while (CurC == '\0') { while (CurC == '\0') {
/* If reading next line fails or is forbidden, bail out */ /* If reading next line fails or is disabled with directives, bail
if (NextLineDisabled || PreprocessNextLine () == 0) { ** out.
*/
if (PPParserRunning || PreprocessNextLine () == 0) {
return 0; return 0;
} }
} }
@ -759,11 +761,14 @@ void NextToken (void)
/* Check for keywords and identifiers */ /* Check for keywords and identifiers */
if (IsSym (token)) { if (IsSym (token)) {
/* Check for a keyword */ if (!PPParserRunning) {
if ((NextTok.Tok = FindKey (token)) != TOK_IDENT) { /* Check for a keyword */
/* Reserved word found */ if ((NextTok.Tok = FindKey (token)) != TOK_IDENT) {
return; /* Reserved word found */
return;
}
} }
/* No reserved word, check for special symbols */ /* No reserved word, check for special symbols */
if (token[0] == '_' && token[1] == '_') { if (token[0] == '_' && token[1] == '_') {
/* Special symbols */ /* Special symbols */

View File

@ -220,7 +220,7 @@ struct Token {
extern Token CurTok; /* The current token */ extern Token CurTok; /* The current token */
extern Token NextTok; /* The next token */ extern Token NextTok; /* The next token */
extern int NextLineDisabled; /* Disabled to read next line */ extern int PPParserRunning; /* Is tokenizer used by the preprocessor */