cznic / goyacc

github.com/cznic/goyacc has moved to modernc.org/goyacc
https://godoc.org/modernc.org/goyacc
BSD 3-Clause "New" or "Revised" License
207 stars 24 forks source link

Duplicate index in yyParseTab #26

Closed resinten closed 6 years ago

resinten commented 6 years ago

I have a parser that has the following basic structure:

program
    : statements
    ;
statements
    : statement
    | statement statements
    ;

And I am getting the following error: y.go:348:12: duplicate index in array literal: 5 I opened up y.go and lines 345-349 look like this:

yyParseTab = [83][]uint8{
    // 0
    {4: 46, 14: 50, 49, 25: 47, 32: 48, 45, 44, 36: 43},
    {5: 42, 5: 42, 5: 42, 5: 42, 5: 42},
    {1: 41, 5: 41, 41, 12: 41, 41},
    ...
}

If I'm not mistaken, it looks like the error corresponds to state 1. But I'm not a yacc expert, by any means. Looking at y.output for state 1 gives the following:

state 1 // NAME SEMICOLON [$end]

    0 $accept: program .  [$end, AND, ARROW, LCURLY, OR]

    $end    accept
    AND     accept
    ARROW   accept
    LCURLY  accept
    OR      accept

So, I think I'm reading this correctly as "we just reduced program, so check whether the next token is $end, AND, ARROW, LCURLY, or OR." I'm not sure why it would be checking that though because there is no valid token other than $end that can occur after reducing to program, which is making me think this may be an issue with goyacc. It appears to work if I manually alter the entry to just {5: 42}. Thoughts?

cznic commented 6 years ago

Not sure what's the cause, I hope to look into it in the morning.

resinten commented 6 years ago

I'm playing with it right now and it looks to me like it might have something to do with a %left declaration. I have two associative operators AND and OR, which can occur in one of the types of statements that can occur. Without %left, they have 25 reduce/reduce conflicts, but it does not complain about duplicate indices. Hopefully it's not just me making a silly mistake somewhere :-)

cznic commented 6 years ago

A minimal but self-contained grammar that reproduces the issue seems to be required.

cznic commented 6 years ago

@softero Gentle ping: Please provide an complete example grammar that reproduces the issue, thank you. No real need to minimize it, any .y file that demonstrates the fail is ok.

cznic commented 6 years ago

Timed out, please reopen when having a repro, thanks.