Can parser error recovery be guided automatically by the grammar?

后端 未结 1 1857
清酒与你
清酒与你 2020-12-30 14:58

I\'m writing an LALR parser generator as a pet project.

I\'m using the purple dragon book to help me with the design, and what I gather from it is that there are fo

相关标签:
1条回答
  • 2020-12-30 15:31

    It's way too easy to get lost in a dead-end when you try to blindly follow all available productions. There are things that you know about your language which it would be very difficult for the parser generator to figure out. (Like, for example, that skipping to the next statement delimiter is very likely to allow the parse to recover.)

    That's not to say that automated procedures haven't been tried. There is a long section about it in Parsing Theory (Sippu & Soisalon-Soininen). (Unfortunately, this article is paywalled, but if you have an ACM membership or access to a good library, you can probably find it.)

    On the whole, the yacc strategy has proven to be "not awful", and even "good enough". There is one well-known way of making it better, which is to collect really bad syntax error messages (or failed error recovery), trace them to the state which is active when they occur (which is easy to do), and attach an error recovery procedure to that precise state and lookahead token. See, for example, Russ Cox's approach.

    0 讨论(0)
提交回复
热议问题