Skip to content

Commit

Permalink
[PP] Equality expression
Browse files Browse the repository at this point in the history
  • Loading branch information
LuisHsu committed Mar 20, 2024
1 parent 19e4299 commit 3494c64
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/include/PreProcessor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ struct PreProcessor {
Result additive();
Result shift();
Result relational();
Result equality(); // TODO:
Result equality();
Result bitwise_AND(); // TODO:
Result bitwise_exclusive_OR(); // TODO:
Result bitwise_inclusive_OR(); // TODO:
Expand Down
22 changes: 21 additions & 1 deletion src/lib/PreProcessor/Expression.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ PreProcessor::Expression::Result PreProcessor::Expression::relation_op(PreProces
}

PreProcessor::Expression::Result PreProcessor::Expression::eval(){
return relational(); // TODO:
return equality(); // TODO:
}

PreProcessor::Expression::Result PreProcessor::Expression::primary(){
Expand Down Expand Up @@ -310,3 +310,23 @@ PreProcessor::Expression::Result PreProcessor::Expression::relational(){
}
return res;
}

PreProcessor::Expression::Result PreProcessor::Expression::equality(){
PreProcessor::Expression::Result res = relational();
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::DoubleEqual || punct.type == TokenType::Punctuator::ExclamEqual){
cur = std::next(cur);
PreProcessor::Expression::Result operand = equality();
implicit_cast(res, operand);
if(punct.type == TokenType::Punctuator::DoubleEqual){
return relation_op<std::equal_to>(res, operand);
}else{
return relation_op<std::not_equal_to>(res, operand);
}
}
}
return res;
}

0 comments on commit 3494c64

Please sign in to comment.