Golang grammar definition

Hi Martin,

From what I found, it appears that the Go compiler formerly used Bison, GNU’s yacc replacement, but since version 1.7 now uses a “hand-written” (non-automated) scanner (lexer) and parser.

These may be found in the $GOROOT/src/cmd/compile/internal/syntax directory, in the source files scanner.go and parser.go.

The EBNF specification for the Go language is included in the Go Programming Language Specification (https://golang.org/ref/spec), and you can use that to create the files for lex and yacc yourself if you want.

I haven’t tried, but maybe you can look in the source code for Go version 1.6 or previous versions to get the files you want. Assuming that works, you will still need to look at the Go specification to add in everything that’s been added to Go since then.

1 Like