Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Stage 6 parser definition for conditional expressions looks incorrect. #4

Closed
stevejb71 opened this issue Sep 22, 2018 · 3 comments
Closed

Comments

@stevejb71
Copy link

@stevejb71 stevejb71 commented Sep 22, 2018

<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
Copy link
Owner

@nlsandler nlsandler commented Oct 16, 2018

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
Copy link
Author

@stevejb71 stevejb71 commented Oct 16, 2018

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

@nlsandler
Copy link
Owner

@nlsandler nlsandler commented Oct 17, 2018

Credit: https://norasandler.com/2018/02/25/Write-a-Compiler-6.html#fn5
Thanks again for catching that!

@nlsandler nlsandler closed this Oct 17, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants