lox-rs
lox-rs copied to clipboard
Parse left paren has stack overflow error
cargo run
and input this will reproduction the error
(1 + 1);
You need to consume/advance the left parenthese (the match only peeks at it). In parser.rs add
self.consume(TokenType::LeftParen, "Expected '(' before expression.")?;
or maybe just advance?
This still has problems with ((5)) or ((5+2)-3)*7 .. so I also removed the line that consumes the RightParen (not sure where it gets lost)
TokenType::LeftParen => {
self.advance(); // so it doesn't keep finding the same LeftParen
let expr = self.expression()?;
//self.consume(TokenType::RightParen, "Expected ')' after expression.")?; // removed for nested stuff (())
Expr::Grouping {
expression: Box::new(expr),
}
}
Oh interesting. Thanks. I'll take a look!
At the moment, I modified consume to use peek instead of advance.
That makes the check for the closing )
work again.