Tweaked parser to allow implicit conversion of type checks to bool

This commit is contained in:
Curle 2020-11-24 00:21:08 +00:00
parent 473af8d54e
commit eab4d51f25
Signed by: TheCurle
GPG Key ID: 5942F13718443F79
2 changed files with 6 additions and 2 deletions

View File

@ -138,6 +138,8 @@ enum SyntaxOps {
OP_BITNOT, // Invert a number bitwise OP_BITNOT, // Invert a number bitwise
OP_BOOLNOT, // Invert a statement OP_BOOLNOT, // Invert a statement
OP_BOOLCONV, // Convert an expression to a boolean.s
OP_ADDRESS, // Fetch the address of a var OP_ADDRESS, // Fetch the address of a var
OP_DEREF, // Get the value of the address in a pointer OP_DEREF, // Get the value of the address in a pointer

View File

@ -227,8 +227,9 @@ struct ASTNode* WhileStatement() {
Condition = ParsePrecedenceASTNode(0); Condition = ParsePrecedenceASTNode(0);
if(Condition->Operation < OP_EQUAL || Condition->Operation > OP_GREATE) 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, ")"); VerifyToken(LI_RPARE, ")");
@ -257,7 +258,8 @@ struct ASTNode* ForStatement() {
Condition = ParsePrecedenceASTNode(0); Condition = ParsePrecedenceASTNode(0);
if(Condition->Operation < OP_EQUAL || Condition->Operation > OP_GREATE) 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, ";"); VerifyToken(LI_SEMIC, ";");
Postop = ParseStatement(); Postop = ParseStatement();