Skip to content

Conversation

@shivansh
Copy link
Collaborator

@shivansh shivansh commented May 10, 2018

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

=== RUN   TestFail
input: a ; b
output: [
	a
Error in S0: INVALID(0,;), Pos(offset=2, line=1, column=3), expected one of: $ id error 
	b
]
--- PASS: TestFail (0.00s)
PASS
ok  	github.com/goccmack/gocc/example/errorrecovery	0.002s
input: a ; ; b
output: [
	a
Error in S0: INVALID(0,;), Pos(offset=2, line=1, column=3), expected one of: $ id error 
	b
]
--- PASS: TestFail (0.00s)
PASS
ok  	github.com/goccmack/gocc/example/errorrecovery	0.002s
input: a ; b ; c
output: [
	a
Error in S0: INVALID(0,;), Pos(offset=2, line=1, column=3), expected one of: $ id error 
	b
Error in S0: INVALID(0,;), Pos(offset=6, line=1, column=6), expected one of: $ id error 
	c
]
--- PASS: TestFail (0.00s)
PASS
ok  	github.com/goccmack/gocc/example/errorrecovery	0.002s

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.

shivansh added 3 commits May 10, 2018 01:18
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
    performed. In case it is a shift, it is deferred until the error
    attribute is pushed on the stack.

  * It should be noted that the current heuristic 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 heuristic in gocc.

Demo
~~~~

>> go test -v

    === RUN   TestFail
    input: a ; b
    output: [
    	a
    Error in S0: INVALID(0,;), Pos(offset=2, line=1, column=3), expected one of: $ id error
    	b
    ]
    --- PASS: TestFail (0.00s)
    PASS
    ok  	github.com/goccmack/gocc/example/errorrecovery	0.005s

Updates goccmack#76
>> go test -v

    === RUN   TestFail
    input: ; ;
    output: [
    Error in S0: INVALID(0,;), Pos(offset=0, line=1, column=1), expected one of: id error
    ]
    --- PASS: TestFail (0.00s)
    PASS
    ok  	github.com/goccmack/gocc/example/errorrecovery	0.002s
@awalterschulze
Copy link
Collaborator

Am I understanding correctly that this is an attempt to fix #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?

@shivansh
Copy link
Collaborator Author

shivansh commented May 12, 2018

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 shivansh changed the title parser: Update heuristic for error-recovery mode implemented in gocc parser: Update error-recovery mode implemented in gocc May 12, 2018
@goccmack
Copy link
Owner

@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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants