In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly explains "how to view go syntax tree", interested friends may wish to have a look. The method introduced in this paper is simple, fast and practical. Let's let Xiaobian take you to learn "how to view go syntax tree"!
We know that golang source code after lexical analysis and syntax analysis, you can get the abstract syntax tree ast, users can traverse the abstract syntax tree to achieve source-level modifications. Many of the golang toolsets are based on syntax trees such as go fmt, goimport, go vet, etc.
For those of you who are not familiar with golang or grammar trees, what does a grammar tree contain? What is the structure of the syntax tree? How each part of the source code corresponds to the syntax tree is a place where everyone has more questions. Therefore, the author built a wheel to visually display the syntax tree, and a key to run directly in the browser to open the generated svg format image. Color distinguishes important grammatical structures. and offer profits.
Examples:
For example, we need to analyze the following source code
package main
import ( "fmt" "github.com/xiazemin/golang/ast/ast_graph/exp/multi")
func main() { a:=1 b:=2 fmt.Println(a+b,add(a,b),multi.Multi(a,b),devide(a,b))
}
func devide(i,j int)int { return i/j}
we can do that
package main
import "github.com/xiazemin/golang/ast/ast_graph/gen"
func main() { path := "/Users/didi/goLang/src/github.com/xiazemin/golang/ast/ast_graph/exp/main.go" dpath := "/Users/didi/goLang/src/github.com/xiazemin/golang/ast/ast_graph/" gen.GenSvg(path, dpath, "tree")}
where path is our source path and dpath is the path to generate images
At this point, I believe everyone has a deeper understanding of "how to view the go syntax tree," so let's actually operate it! Here is the website, more related content can enter the relevant channels for inquiry, pay attention to us, continue to learn!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.