3 ms·
The use case of only handling valid input is a very common one, Particularly during compiler construction. But what about the use case of building an Editor (I
by bd82 11y ago
The use case of only handling valid input is a very common one, Particularly during compiler construction.
But what about the use case of building an Editor (IDE) ?
In this context it would highly beneficial to be able to handle invalid inputs as the user would still expect outline/navigation/formatting/.../ to work even when there
are syntax errors.
Error Recovery algorithms are heuristics, they can never solve all the possible kinds of errors. Automatic error recovery is also not mutually exclusive with expanding the grammar
to support some "tolerable" errors, Both can be used to improve the "robustness" of the grammar when fault tolerance is needed.
Also note that expanding the grammar will work best for simple common errors (missing semicolon), but what about when you need to re-sync an unknown number of tokens and unwind the parser call stack?
Also note these "heuristics" are not "mine", they are based on heuristics used in Antlr 3.
Which is itself based on Academic studies in this topic:
Specifically:
Josef Grosch. Efficient and comfortable error recovery in recursive descent parsers. Structured Programming, 11(3):129–140, 1990.
Rodney W. Topor. A note on error recovery in recursive descent parsers. SIGPLAN Not., 17(2):37–40, 1982.
Niklaus Wirth. Algorithms + Data Structures = Programs. Prentice Hall PTR, Upper Saddle River, NJ, USA, 1978.