nlsandler/write_a_c_compiler

Stage 6 parser definition for conditional expressions looks incorrect.

stevejb71 opened this issue · 3 comments

<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>

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!

Yes, a small credit would be very nice. Thank you for offering and also for the great blog series.