How does the Go1 compiler work?

前端 未结 3 1800
小鲜肉
小鲜肉 2020-12-02 01:25

I\'ve been dabbling with Go for about a month for a school project and I noticed the go/ast, go/token, go/parser, etc. packages in the src/pkg/go folder. However, the gc com

3条回答
  •  南方客
    南方客 (楼主)
    2020-12-02 01:44

    The Go compiler is written in pure C and does not use the packages under go/. In the Go source tree, its lexer lives in src/cmd/gc/lex.c and its Bison grammar is src/cmd/gc/go.y.

    The go/ packages are used in tools like godoc, gofmt, and various go tool subcommands. Maybe someday they can be used to write a Go compiler in Go as well, but no one's gotten very far on that path yet.

提交回复
热议问题