Skip to content

Commit

Permalink
fix: Fixed parser not parsing power expression (x^y)
Browse files Browse the repository at this point in the history
  • Loading branch information
alinalihassan committed May 1, 2023
1 parent 2652777 commit ea0bc42
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
12 changes: 11 additions & 1 deletion src/liblesma/Frontend/Parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -206,8 +206,18 @@ Expression *Parser::ParseCast() {
}

Expression *Parser::ParseMult() {
auto left = ParseCast();
auto left = ParsePower();
while (AdvanceIfMatchAny<TokenType::STAR, TokenType::SLASH, TokenType::MOD>()) {
auto op = Previous()->type;
auto right = ParsePower();
left = new BinaryOp({left->getStart(), right->getEnd()}, left, op, right);
}
return left;
}

Expression *Parser::ParsePower() {
auto left = ParseCast();
while (AdvanceIfMatchAny<TokenType::POWER>()) {
auto op = Previous()->type;
auto right = ParseCast();
left = new BinaryOp({left->getStart(), right->getEnd()}, left, op, right);
Expand Down
1 change: 1 addition & 0 deletions src/liblesma/Frontend/Parser.h
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ namespace lesma {
Expression *ParseCompare();
Expression *ParseAdd();
Expression *ParseMult();
Expression *ParsePower();
Expression *ParseCast();
Expression *ParseUnary();
Expression *ParseTerm();
Expand Down

0 comments on commit ea0bc42

Please sign in to comment.