From eab4d51f252c44ac7d8818fe9eed493ab276eea6 Mon Sep 17 00:00:00 2001 From: Curle Date: Tue, 24 Nov 2020 00:21:08 +0000 Subject: [PATCH] Tweaked parser to allow implicit conversion of type checks to bool --- include/Defs.h | 2 ++ src/Statements.c | 6 ++++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/include/Defs.h b/include/Defs.h index 08b676a..4052a51 100644 --- a/include/Defs.h +++ b/include/Defs.h @@ -138,6 +138,8 @@ enum SyntaxOps { OP_BITNOT, // Invert a number bitwise OP_BOOLNOT, // Invert a statement + + OP_BOOLCONV, // Convert an expression to a boolean.s OP_ADDRESS, // Fetch the address of a var OP_DEREF, // Get the value of the address in a pointer diff --git a/src/Statements.c b/src/Statements.c index 6e8396c..32a7de9 100644 --- a/src/Statements.c +++ b/src/Statements.c @@ -227,8 +227,9 @@ struct ASTNode* WhileStatement() { Condition = ParsePrecedenceASTNode(0); + if(Condition->Operation < OP_EQUAL || Condition->Operation > OP_GREATE) - Die("Bad Comparison inside while()"); + Condition = ConstructASTBranch(OP_BOOLCONV, Condition->ExprType, Condition, 0); VerifyToken(LI_RPARE, ")"); @@ -257,7 +258,8 @@ struct ASTNode* ForStatement() { Condition = ParsePrecedenceASTNode(0); if(Condition->Operation < OP_EQUAL || Condition->Operation > OP_GREATE) - Die("Bad comparison in for"); + Condition = ConstructASTBranch(OP_BOOLCONV, Condition->ExprType, Condition, 0); + VerifyToken(LI_SEMIC, ";"); Postop = ParseStatement();