Open shivansh opened 6 years ago
Am I understanding correctly that this is an attempt to fix https://github.com/goccmack/gocc/issues/76
I wouldn't call this a heuristic, but rather just a possibly better way to do error recovery.
I am sick though, so I probably missed something.
@goccmack this is probably something worth checking out. What do you think?
Am I understanding correctly that this is an attempt to fix #76
Yes.
I wouldn't call this a heuristic, but rather just a possibly better way to do error recovery.
oic, updating the title and PR message.
I am sick though, so I probably missed something.
Get well soon :)
@shivansh put his finger on one of the aspects of gocc that didn't receive sufficient attention originally. If I remember correctly I tried to implement error recovery according to the dragon book "Error Recovery in LR Parsing" but under time pressure. I think @shivansh is on the right track.
The following steps are performed when an invalid input symbol is encountered -
In case the input reaches an invalid symbol, we save its error attribute and keep discarding all the immediately following error symbols until a valid symbol is found.
If the action corresponding to the found valid symbol is reduce, it is performed. In case it is a shift, it is deferred until the saved error attribute is pushed on the stack.
Once the saved error attribute is pushed on stack, parsing can resume normally.
It should be noted that the current model cannot report multiple errors for invalid symbols occurring one after the other. If such a case arises, the error for only the first invalid symbol is reported. This is also the case with the currently implemented error recovery model in gocc.
Demo for error-recovery example
It should be noted that there might be scope of further refactoring the code in this PR. I'll defer doing it until the proposed heuristic has been verified.