munificent / craftinginterpreters

Repository for the book "Crafting Interpreters"
http://www.craftinginterpreters.com/
Other
8.79k stars 1.03k forks source link

Precedence confusion #908

Closed MichaelLiuzzi closed 3 years ago

MichaelLiuzzi commented 3 years ago

Hi!

Firstly, thank you so much for this book. It has been a joy to read and work through. I have a question. Is an expression like this forbidden by Lox's grammar?

print 1 + 4 * 6 + 2

I have also tried grouping like so ((2+3) 4) and that will fail. But (2+3) 4 will succeed. Is that also intended? It seems like additional parentheses should be permissible.

mcfriend99 commented 3 years ago

Did you finish the post on expression parsing?? Because that works perfectly in my implementation

munificent commented 3 years ago

Is an expression like this forbidden by Lox's grammar?

print 1 + 4 * 6 + 2

No, that should be allowed and work fine. Probably a bug somewhere in your parser implementation. (Happens to the best of us.) :)