lox-rs icon indicating copy to clipboard operation
lox-rs copied to clipboard

Parse left paren has stack overflow error

Open ahabhgk opened this issue 3 years ago • 3 comments

cargo run and input this will reproduction the error

(1 + 1);

ahabhgk avatar Jun 20 '21 16:06 ahabhgk

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?

in fn primary

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),
                }
            }

jcos1 avatar Jan 14 '22 15:01 jcos1

Oh interesting. Thanks. I'll take a look!

jeschkies avatar Jan 14 '22 16:01 jeschkies

At the moment, I modified consume to use peek instead of advance. That makes the check for the closing ) work again.

jcos1 avatar Jan 14 '22 23:01 jcos1