diff options
author | Itamar <itamar8910@gmail.com> | 2021-04-02 10:28:17 +0300 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2021-04-06 21:51:58 +0200 |
commit | 575d6a8ee1e964e5158ee14b32e55d497c401484 (patch) | |
tree | 163acbcaebf7e7062a2156b91f4c5912d6a196d3 /Userland/Libraries/LibCpp | |
parent | 8962581c9c6e7322331ee9553a1ce6a048fe44df (diff) | |
download | serenity-575d6a8ee1e964e5158ee14b32e55d497c401484.zip |
LibCpp: Parse Bitwise & Logical Or & And operators
Diffstat (limited to 'Userland/Libraries/LibCpp')
-rw-r--r-- | Userland/Libraries/LibCpp/AST.cpp | 9 | ||||
-rw-r--r-- | Userland/Libraries/LibCpp/AST.h | 3 | ||||
-rw-r--r-- | Userland/Libraries/LibCpp/Parser.cpp | 17 |
3 files changed, 27 insertions, 2 deletions
diff --git a/Userland/Libraries/LibCpp/AST.cpp b/Userland/Libraries/LibCpp/AST.cpp index 601b689807..f5088dbf5d 100644 --- a/Userland/Libraries/LibCpp/AST.cpp +++ b/Userland/Libraries/LibCpp/AST.cpp @@ -209,6 +209,12 @@ void BinaryExpression::dump(size_t indent) const case BinaryOp::NotEqual: op_string = "!="; break; + case BinaryOp::LogicalOr: + op_string = "||"; + break; + case BinaryOp::LogicalAnd: + op_string = "&&"; + break; } m_lhs->dump(indent + 1); @@ -319,6 +325,9 @@ void UnaryExpression::dump(size_t indent) const case UnaryOp::PlusPlus: op_string = "++"; break; + case UnaryOp::Address: + op_string = "&"; + break; default: op_string = "<invalid>"; } diff --git a/Userland/Libraries/LibCpp/AST.h b/Userland/Libraries/LibCpp/AST.h index a5f1ca356c..04c1247340 100644 --- a/Userland/Libraries/LibCpp/AST.h +++ b/Userland/Libraries/LibCpp/AST.h @@ -420,6 +420,8 @@ enum class BinaryOp { RightShift, EqualsEquals, NotEqual, + LogicalOr, + LogicalAnd, }; class BinaryExpression : public Expression { @@ -582,6 +584,7 @@ enum class UnaryOp { Plus, Minus, PlusPlus, + Address, }; class UnaryExpression : public Expression { diff --git a/Userland/Libraries/LibCpp/Parser.cpp b/Userland/Libraries/LibCpp/Parser.cpp index 2fb02a84eb..49b2f68f80 100644 --- a/Userland/Libraries/LibCpp/Parser.cpp +++ b/Userland/Libraries/LibCpp/Parser.cpp @@ -421,7 +421,8 @@ bool Parser::match_secondary_expression() || type == Token::Type::EqualsEquals || type == Token::Type::AndAnd || type == Token::Type::PipePipe - || type == Token::Type::ExclamationMarkEquals; + || type == Token::Type::ExclamationMarkEquals + || type == Token::Type::PipePipe; } NonnullRefPtr<Expression> Parser::parse_primary_expression(ASTNode& parent) @@ -481,7 +482,8 @@ bool Parser::match_unary_expression() || type == Token::Type::ExclamationMark || type == Token::Type::Tilde || type == Token::Type::Plus - || type == Token::Type::Minus; + || type == Token::Type::Minus + || type == Token::Type::And; } NonnullRefPtr<UnaryExpression> Parser::parse_unary_expression(ASTNode& parent) @@ -505,6 +507,9 @@ NonnullRefPtr<UnaryExpression> Parser::parse_unary_expression(ASTNode& parent) case Token::Type::PlusPlus: op = UnaryOp::PlusPlus; break; + case Token::Type::And: + op = UnaryOp::Address; + break; default: break; } @@ -555,6 +560,14 @@ NonnullRefPtr<Expression> Parser::parse_secondary_expression(ASTNode& parent, No return parse_binary_expression(parent, lhs, BinaryOp::EqualsEquals); case Token::Type::ExclamationMarkEquals: return parse_binary_expression(parent, lhs, BinaryOp::NotEqual); + case Token::Type::And: + return parse_binary_expression(parent, lhs, BinaryOp::BitwiseAnd); + case Token::Type::AndAnd: + return parse_binary_expression(parent, lhs, BinaryOp::LogicalAnd); + case Token::Type::Pipe: + return parse_binary_expression(parent, lhs, BinaryOp::BitwiseOr); + case Token::Type::PipePipe: + return parse_binary_expression(parent, lhs, BinaryOp::LogicalOr); case Token::Type::Equals: return parse_assignment_expression(parent, lhs, AssignmentOp::Assignment); case Token::Type::Dot: { |