goccmack / gocc

Parser / Scanner Generator

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Unexpected behavior with error recovery mode implemented in gocc

shivansh opened this issue · comments

Reference

The aim of this issue is to make an attempt at explaining the behavior (mentioned in the reference above) demonstrated by error recovery implemented in gocc.

Scenario

When testing input a ; b using the error recovery example, the following output is generated -

output: [
Error in S0: INVALID(0,;), Pos(offset=2, line=1, column=3), expected one of: id error
	b
]

The valid terminal a is not available in the final output.

Reasoning

This commit adds a few debug statements demonstrating the recovery behavior. The output generated via go test -v is available here (relevant output starts from here).

When the input reaches symbol ;, the action table does not contain a valid action corresponding to the state of the stack. As a result the recovery mode kicks in and pops all the non-recovery states along with their attributes [1] (in this case a single pop is performed and a is lost [2] along with state 3). The valid recovery state which is now on the top of the stack is 1, and corresponding to this state a shift action is performed pushing the errorAttrib on stack [3] [4]. The parsing resumes normally from here.

I'm not sure whether this is the correct behavior, but this is how things appear to be happening.

I tried a lot today to somehow make the symbol a stay on stack, so that the final output will be a, error, b, but all in vain.
Comments on above are appreciated.