3 ms·
> You can report the location where the parse failed, what was recognized before that point, what tokens would have been allowed to follow. This is a garbage '
by chrisseaton 8y ago
> You can report the location where the parse failed, what was recognized before that point, what tokens would have been allowed to follow.
This is a garbage 'computer says no' kind of error message.
It doesn't tell you why those tokens would have been allowed to follow, why it is that those are the only tokens allowed to follow, why the token you used is not one of the allowed one, or what you could have more likely been intending to write to make it correct.
In a recursive descent parser you have the freedom to use more context and logic to generate your error messages.
- jhpriestley 8y agoWhat context or data would constitute a helpful error message in your opinion? Do you have an example of a recursive-descent parser that generates particularly good error messages?
- chrisseaton 8y agoA great example is if you forget to put 'end' at the end of a function at the end of a file in languages that have that. Your idea of a good parser error message is being told that the end of file was unexpected and being given a list of a hundred possible tokens that could start another statement, including 'end' buried somewhere in the list, because that's what's valid there. My idea of a good parser error message would be in a recursive descent parser looking for the 'end' token, not seeing it, seeing that it's end of file instead and saying 'missing 'end' or a new statement at end of file'.
- nicoburns 8y agoSee elm and rust for examples of compilers with good error messages.
- grandmczeb 8y agoOr clang.