From 4bb4f033ea9774ae04c8fdaf42c34f8b572859db Mon Sep 17 00:00:00 2001 From: acqn Date: Sun, 7 Aug 2022 16:14:45 +0800 Subject: [PATCH] Fixed the bug that C keywords were not simply recognized as identifiers in preprocessing. --- src/cc65/ppexpr.c | 10 ++++++++-- src/cc65/scanner.c | 19 ++++++++++++------- src/cc65/scanner.h | 2 +- 3 files changed, 21 insertions(+), 10 deletions(-) diff --git a/src/cc65/ppexpr.c b/src/cc65/ppexpr.c index af2c1de3b..788fb27d5 100644 --- a/src/cc65/ppexpr.c +++ b/src/cc65/ppexpr.c @@ -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 */ PPEvaluationFailed = 0; PPEvaluationEnabled = 1; - NextLineDisabled = 1; + PPParserRunning = 1; /* Parse */ PPExprInit (Expr); @@ -867,5 +873,5 @@ void ParsePPExprInLine (PPExpr* Expr) } /* Restore parser status */ - NextLineDisabled = 0; + PPParserRunning = 0; } diff --git a/src/cc65/scanner.c b/src/cc65/scanner.c index 9f0498c26..af3ddaab5 100644 --- a/src/cc65/scanner.c +++ b/src/cc65/scanner.c @@ -69,7 +69,7 @@ Token CurTok; /* The current 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 (CurC == '\0') { - /* If reading next line fails or is forbidden, bail out */ - if (NextLineDisabled || PreprocessNextLine () == 0) { + /* If reading next line fails or is disabled with directives, bail + ** out. + */ + if (PPParserRunning || PreprocessNextLine () == 0) { return 0; } } @@ -759,11 +761,14 @@ void NextToken (void) /* Check for keywords and identifiers */ if (IsSym (token)) { - /* Check for a keyword */ - if ((NextTok.Tok = FindKey (token)) != TOK_IDENT) { - /* Reserved word found */ - return; + if (!PPParserRunning) { + /* Check for a keyword */ + if ((NextTok.Tok = FindKey (token)) != TOK_IDENT) { + /* Reserved word found */ + return; + } } + /* No reserved word, check for special symbols */ if (token[0] == '_' && token[1] == '_') { /* Special symbols */ diff --git a/src/cc65/scanner.h b/src/cc65/scanner.h index 2ed59771c..194f27b7c 100644 --- a/src/cc65/scanner.h +++ b/src/cc65/scanner.h @@ -220,7 +220,7 @@ struct Token { extern Token CurTok; /* The current token */ extern Token NextTok; /* The next token */ -extern int NextLineDisabled; /* Disabled to read next line */ +extern int PPParserRunning; /* Is tokenizer used by the preprocessor */