Stage 6 parser definition for conditional expressions looks incorrect.
stevejb71 opened this issue · 3 comments
stevejb71 commented
<exp> ::= <id> "=" <exp> | <conditional-exp>
<conditional-exp> ::= <logical-or-exp> "?" <exp> ":" <conditional-exp>
This looks wrong - it forces every expression to be a conditional.
Something like the below would be better I think:
<conditional-exp> ::= <logical-or-exp> "?" <exp> ":" <conditional-exp> | <logical-or-exp>
nlsandler commented
Thanks for opening this issue! You're correct - this grammar rule would force every expression to be a conditional.
I updated the grammar rule in the blog post to fix this issue:
<conditional-exp> ::= <logical-or-exp> [ "?" <exp> ":" <conditional-exp> ]
Let me know if you'd like me to credit you in the post for catching that mistake!
stevejb71 commented
Yes, a small credit would be very nice. Thank you for offering and also for the great blog series.
nlsandler commented
Credit: https://norasandler.com/2018/02/25/Write-a-Compiler-6.html#fn5
Thanks again for catching that!