Yacc errors when generating sql.go from sql.y

Hi folks. I am attempting to make a private fork of some of the content, with some possible grammar changes. My need is only for the parser and the parse-tree, not the full cockroachdb engine.

When attempting to make grammar changes, my first thought is that I want to be able to reproduce the existing sql.go from sql.y
The sql.go generated file has this content:

// Code generated by goyacc. DO NOT EDIT.
// Code generated by goyacc -p sql -o sql.go.tmp sql-gen.y. DO NOT EDIT.

So naturally, I attempted:
goyacc -p sql -o sql.go.tmp sql.y
(there is no file sql-gen.y, so of course, I used sql.y). I end up with this error:
sql.y:459:9: unexpected ‘*’, expected identifier
The line number may be off from what you expect, but I looked at the latest sql.y, and it generally has the same problem:

Line 459 is the first place that we see the ‘*’ operator:
// Non-keyword token types.
%token <*tree.NumVal> ICONST FCONST

It is failing on the <*tree.NumVal>.

What step am I missing in getting goyacc to work with this? I am invoking goyacc directly from the directory containing these files.
Are there environment variables that I am missing?
Is there something special I need to do to let goyacc be aware of pkg/sql/sem/tree?

You should use the Makefile to automate running goyacc. You can run make pkg/sql/parser/sql.go from the top level to generate that file only - you can delete it and run that command and it’ll regenerate it from scratch.

Several steps, in fact. Like Jordan explains, our Makefile owns this process, you can’t use a simple command. There are two things that you need to consider:

  • the sql.y is preprocessed in two stages to produce a valid yacc file, which can then be processed by goyacc.
  • several other go files are generated from sql.y and are also required elsewhere in the build.


Alright; thanks. It helped when I looked at the Makefile to clarify the process.