1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 06:57:44 +00:00

LibCpp: Support parsing binary "==" Operator

This commit is contained in:
Itamar 2021-03-27 19:20:20 +03:00 committed by Andreas Kling
parent 1f9f6ea9d6
commit cbb49f26d9
3 changed files with 8 additions and 1 deletions

View file

@ -203,6 +203,9 @@ void BinaryExpression::dump(size_t indent) const
case BinaryOp::RightShift: case BinaryOp::RightShift:
op_string = ">>"; op_string = ">>";
break; break;
case BinaryOp::EqualsEquals:
op_string = "==";
break;
} }
m_lhs->dump(indent + 1); m_lhs->dump(indent + 1);

View file

@ -371,6 +371,7 @@ enum class BinaryOp {
BitwiseXor, BitwiseXor,
LeftShift, LeftShift,
RightShift, RightShift,
EqualsEquals
}; };
class BinaryExpression : public Expression { class BinaryExpression : public Expression {

View file

@ -309,7 +309,7 @@ NonnullRefPtr<VariableDeclaration> Parser::parse_variable_declaration(ASTNode& p
initial_value = parse_expression(var); initial_value = parse_expression(var);
} }
if(expect_semicolon) if (expect_semicolon)
consume(Token::Type::Semicolon); consume(Token::Type::Semicolon);
var->set_end(position()); var->set_end(position());
@ -372,6 +372,7 @@ bool Parser::match_secondary_expression()
|| type == Token::Type::LessLessEquals || type == Token::Type::LessLessEquals
|| type == Token::Type::GreaterGreater || type == Token::Type::GreaterGreater
|| type == Token::Type::GreaterGreaterEquals || type == Token::Type::GreaterGreaterEquals
|| type == Token::Type::EqualsEquals
|| type == Token::Type::AndAnd || type == Token::Type::AndAnd
|| type == Token::Type::PipePipe; || type == Token::Type::PipePipe;
} }
@ -494,6 +495,8 @@ NonnullRefPtr<Expression> Parser::parse_secondary_expression(ASTNode& parent, No
return parse_binary_expression(parent, lhs, BinaryOp::Addition); return parse_binary_expression(parent, lhs, BinaryOp::Addition);
case Token::Type::Less: case Token::Type::Less:
return parse_binary_expression(parent, lhs, BinaryOp::LessThan); return parse_binary_expression(parent, lhs, BinaryOp::LessThan);
case Token::Type::EqualsEquals:
return parse_binary_expression(parent, lhs, BinaryOp::EqualsEquals);
case Token::Type::Equals: case Token::Type::Equals:
return parse_assignment_expression(parent, lhs, AssignmentOp::Assignment); return parse_assignment_expression(parent, lhs, AssignmentOp::Assignment);
case Token::Type::Dot: { case Token::Type::Dot: {