diff --git a/src/include/PreProcessor.hpp b/src/include/PreProcessor.hpp index e0bb8f1..9e15e07 100644 --- a/src/include/PreProcessor.hpp +++ b/src/include/PreProcessor.hpp @@ -89,8 +89,8 @@ struct PreProcessor { Result bitwise_AND(); Result bitwise_exclusive_OR(); Result bitwise_inclusive_OR(); - Result logical_AND(); // TODO: - Result logical_OR(); // TODO: + Result logical_AND(); + Result logical_OR(); Result conditional(); // TODO: template diff --git a/src/lib/PreProcessor/Expression.cpp b/src/lib/PreProcessor/Expression.cpp index cd3db3d..062a7ad 100644 --- a/src/lib/PreProcessor/Expression.cpp +++ b/src/lib/PreProcessor/Expression.cpp @@ -107,7 +107,7 @@ PreProcessor::Expression::Result PreProcessor::Expression::relation_op(PreProces } PreProcessor::Expression::Result PreProcessor::Expression::eval(){ - return bitwise_inclusive_OR(); // TODO: + return logical_OR(); // TODO: } PreProcessor::Expression::Result PreProcessor::Expression::primary(){ @@ -390,3 +390,35 @@ PreProcessor::Expression::Result PreProcessor::Expression::bitwise_inclusive_OR( } return res; } + +PreProcessor::Expression::Result PreProcessor::Expression::logical_AND(){ + PreProcessor::Expression::Result res = bitwise_inclusive_OR(); + Line::iterator head = skip_whitespace(cur, end); + cur = head; + if(cur != end && cur->hold()){ + TokenType::Punctuator punct = cur->value(); + if(punct.type == TokenType::Punctuator::DoubleAmp){ + cur = std::next(cur); + PreProcessor::Expression::Result operand = logical_AND(); + implicit_cast(res, operand); + return relation_op(res, operand); + } + } + return res; +} + +PreProcessor::Expression::Result PreProcessor::Expression::logical_OR(){ + PreProcessor::Expression::Result res = logical_AND(); + Line::iterator head = skip_whitespace(cur, end); + cur = head; + if(cur != end && cur->hold()){ + TokenType::Punctuator punct = cur->value(); + if(punct.type == TokenType::Punctuator::DoubleBar){ + cur = std::next(cur); + PreProcessor::Expression::Result operand = logical_OR(); + implicit_cast(res, operand); + return relation_op(res, operand); + } + } + return res; +} \ No newline at end of file