Skip to content

Commit

Permalink
[PP] Logical AND/OR operator
Browse files Browse the repository at this point in the history
  • Loading branch information
LuisHsu committed Mar 20, 2024
1 parent 58f5952 commit 884b133
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 3 deletions.
4 changes: 2 additions & 2 deletions src/include/PreProcessor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<typename T = void>
Expand Down
34 changes: 33 additions & 1 deletion src/lib/PreProcessor/Expression.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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(){
Expand Down Expand Up @@ -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>()){
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<std::logical_and>(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>()){
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<std::logical_or>(res, operand);
}
}
return res;
}

0 comments on commit 884b133

Please sign in to comment.