Go1编译器如何工作? [英] How does the Go1 compiler work?

查看:146
本文介绍了Go1编译器如何工作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经开始了一个月的学校项目,我注意到了go / ast,go / token,go / parser等包在src / pkg / go文件夹中。但是,gc编译器基于位于src / cmd / gc中的C文件。

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 compiler was based on C files located in src/cmd/gc.

我的问题是Go1中的go命令创建和运行程序:工具依赖于我上面引用的包?例如,如果我向/go/token/token.go添加了一个新令牌,它会被新的go编译器识别?

My question regards the new go command in Go1 that builds and runs programs: does this tool depend on the packages I referenced above? i.e. if I added a new token to /go/token/token.go, would it be recognized by the new go compiler?

推荐答案

p> Go编译器是用纯C编写的,不使用 go / 下的包。在Go源代码树中,它的词典存在于src / cmd / gc / lex.c中,其Bison语法是src / cmd / gc / go.y。

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.

go / 包用于像godoc,gofmt和各种go工具子命令的工具。也许有一天,他们可以用来在Go中编写一个Go编译器,但没有人在那条路上走得很远。

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.

这篇关于Go1编译器如何工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆