Implemented logical && and ||

This commit is contained in:
2022-08-23 05:07:17 +01:00
parent 6939b216a9
commit 4f70bea808
5 changed files with 70 additions and 5 deletions

View File

@@ -96,7 +96,6 @@ typedef enum {
PREC_TERNARY,
PREC_OR,
PREC_AND,
// PREC_EQUALITY,
PREC_COMPARISON,
PREC_TERM,
PREC_FACTOR,
@@ -382,6 +381,16 @@ static Opcode binary(Parser* parser, Node** nodeHandle) {
return OP_COMPARE_GREATER_EQUAL;
}
case TOKEN_AND: {
parsePrecedence(parser, nodeHandle, PREC_COMPARISON);
return OP_AND;
}
case TOKEN_OR: {
parsePrecedence(parser, nodeHandle, PREC_COMPARISON);
return OP_OR;
}
default:
error(parser, parser->previous, "Unexpected token passed to binary precedence rule");
return OP_EOF;
@@ -689,8 +698,8 @@ ParseRule parseRules[] = { //must match the token types
{NULL, binary, PREC_COMPARISON},// TOKEN_GREATER,
{NULL, binary, PREC_COMPARISON},// TOKEN_LESS_EQUAL,
{NULL, binary, PREC_COMPARISON},// TOKEN_GREATER_EQUAL,
{NULL, NULL, PREC_NONE},// TOKEN_AND,
{NULL, NULL, PREC_NONE},// TOKEN_OR,
{NULL, binary, PREC_AND},// TOKEN_AND,
{NULL, binary, PREC_OR},// TOKEN_OR,
//other operators
{NULL, NULL, PREC_NONE},// TOKEN_COLON,