Preamble
I have written GLR-parser with error recovery. When it encounters an error it splits into following alternatives:
- Insert the expected element into input (may be the user just missed it) and proceed as usual.
- Replace the erroneous element with expected one (may be the user just made a mistype) and proceed as usual.
- Skip erroneous element and if next element is also erroneous then go to #2.
But if input has a lot of errors (for example, user has by mistake given JPEG file to the parser) a number of alternatives grows exponentially.
Example
Such a parser corresponding to the following grammar:
Program -> Identifier WS Identifier WS '=' WS Identifier
Identifier -> ('a'..'z' | 'A'..'Z' | '0'..'9')*
WS -> ' '*
applied to the following text:
x = "abc\"def"; y = "ghi\"jkl";
fails with "out of memory" on moderately modern desktop computer.
Question
How to reduce number of alternatives in case of errors in input?