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
208 stars 24 forks source link

invalid syntax error on $ #22

Closed emicklei closed 8 years ago

emicklei commented 8 years ago

i am trying to consume a large grammer file (postgresql) which is in Bison format. Bison is supposed to be the GNU implementation/extension of Yacc but I think it has some differences since I got a syntax error. I have not spent time to find out the differences between Yacc/Bison related to this. Maybe you can comment on that.

The section that cause the error is

OptSchemaEltList:
            OptSchemaEltList schema_stmt
                {
                    if (@$ < 0)         /* see comments for YYLLOC_DEFAULT */
                        @$ = @2;
                    $$ = lappend($1, $2);
                }
            | /* EMPTY */
                { $$ = NIL; }
        ;

The @$ causes: strconv.ParseInt: parsing "": invalid syntax:

cznic commented 8 years ago

goyacc does not support bison locations. It's probably possible to somehow support this.

However, I suggest to use yy. It will automatically generate a lot of yacc code, AST node types and also compute proper Pos() methods for all of the AST nodes, provided the lexer hands tokens having a .Pos() token.Pos method. For example.

emicklei commented 8 years ago

Thank you for helping me out. I will proceed with yy instead.

cznic commented 8 years ago

@emicklei Glad to hear that. The documentation for yy is a bit brief so please feel free to ask for help if you would need some.