Skip to content

Commit

Permalink
Parse expr according to precedence
Browse files Browse the repository at this point in the history
  • Loading branch information
EricLBuehler committed Jul 7, 2023
1 parent b1d53cc commit 24271fa
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions src/parser/parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ class Parser {
std::unique_ptr<Node> parse_statement() {
switch (this->current.type) {
default: {
return this->expr();
return this->expr(Precedence::LOWEST);
}
}
}
Expand All @@ -79,7 +79,7 @@ class Parser {
}
}

std::unique_ptr<Node> expr() {
std::unique_ptr<Node> expr(Precedence precedence) {
auto atomic = this->atomic();
if (!atomic.has_value()) {
TODO;
Expand All @@ -89,10 +89,15 @@ class Parser {
<< std::endl;

auto left = *std::move(atomic);
while (!this->is_current_eof()) {

std::cout << "Atomic: " << this->current << std::endl;
this->advance();

while (!this->is_current_eof() && precedence < get_precedence()) {
std::cout << "Tok: " << this->current << std::endl;
auto next = this->advance();
std::cout << next << std::endl;
}

return left;
}

Expand Down

0 comments on commit 24271fa

Please sign in to comment.