当前位置:网站首页>My first experience of go+ language -- a collection of notes on learning go+ design architecture
My first experience of go+ language -- a collection of notes on learning go+ design architecture
2022-06-25 12:47:00 【Coconut brine Engineer】
Go+ Installation tutorial for
There is a share in front , Through train :https://bbs.csdn.net/topics/603567061
Go+ Overall architecture

The starting point :Go+ Source code
End : An executable file ( Software ) or A bag (package)
The process : Enter the source code , In the middle token flow , experience AST Abstract syntax tree ,Dom Writer It's like a container , You can fill it with things , Finally can form Go The abstract syntax tree of , adopt go The command-line tool converts to an executable file .
The build process :
1)gop/token
- token The concept of compilation principle is similar to the words in natural language
- The source code is a stream of bytes :[]byte
- Need to pass through lex Process becomes token flow :[]token
2)gop/scanner
- scanner In compiling principle lex The process ( Lexical analysis )
- It usually does not require us to actively invoke , It's about using parser call
3)gop/parser
- In compiling principle parser The process ( Syntax analysis ), Responsible for token The circulation is DOM( namely []token => AST)
parser How to use :Go+ And Go It's the same prototype
func(os.FileInfo)bool,mode Mode)(pkgs map[string]*ast.Package,first error) ```
- fset: It is mainly used to record file offset offset And row number line:col The relationship between
- path: The path where the source code is located
- filter: Filter the file path
- mode: Some control parser Process of flags, It can be transmitted 0
- pkgs: Got AST
- first: stay parser When something goes wrong , The first error that occurred
4)gop/ast
- AST The full name of is abstract syntax tree , It's language DOM
- DOM It is a classic pattern in text processing (XML/json And other general documents have their own DOM, This and language have their own AST Essentially the same )
5)gop/cl
- compile ( Syntax analysis ): Responsible for the Go+AST Convert to right gox DOM Writer Call to
- It means cl The implementation is from Go+AST DOM To another DOM Transformation of
cl How to use
*Config)(p *gox.Package,err error) ```
- pkgPath: The target to compile Go+pkg Of import route
- pkg: The target to compile Go+pkg Of AST
- conf: Configuration for compilation
- p: Generated gox DOM Writer, Other interfaces have been called to complete the format conversion
- err: If an error occurs during compilation , All compilation errors are returned
6)gox
- It's a Go Linguistic DOM Writer Components , Used to generate Go AST
- therefore cl+gox It's done Go+AST To Go AST Transformation
gox How to use
Part to cl Irrigation data , To realize format conversion , One part is used to generate Go AST/Source Of
7)go
- With Go AST/Source after , You can use it go tools To compile
gop run . The core processes (hello world Implementation process )
fset:= token.NewFileSet()
pkgGops,err:= parser.ParseDir(fset,".",nil,0)
pfgFox,err:= cl.NewPackage("main",pkgGopx["mian"].nil)
err = gox.WriteFile("gop_autogen.go",pkgGox,false)
err = exec.Command("go","run","gop_autogen.go").Run()
边栏推荐
- 2021-10-21
- Go defer little knowledge
- 又是被Visdom搞崩溃的一夜
- 出手即不凡,这很 Oracle!
- Figure explanation of fiborache sequence
- C program linking SQLSERVER database: instance failed
- Penetration tool environment - installing sqli labs in centos7 environment
- Tp6 exception handling try catch writing method
- First acquaintance with CANopen
- Jenkins Pipeline使用
猜你喜欢

Penetration tool environment - installing sqli labs in centos7 environment

MySQL common interview questions

Total number of MySQL statistics, used and unused

(2) Pyqt5 tutorial -- > using qtdesigner to separate interface code

Elemntui's select+tree implements the search function

Optimal solution for cold start
模块五(微博评论)

QT TCP UDP network communication < theory >

2021-09-02

百度搜索稳定性问题分析的故事
随机推荐
Zhengzheng e-commerce source code -- Zhengzheng advertising e-commerce system development source code sharing
Foreach method of array in JS
Ubuntu uninstalling PHP
PHP parsing QR code content
又是被Visdom搞崩溃的一夜
Optimal solution for cold start
Negative sample image used in yolov5 training
利用cmd(命令提示符)安装mysql&&配置环境
高性能负载均衡架构如何实现?
地理空间搜索 ->R树索引
Baidu search stability analysis story
torch.tensor拼接与list(tensors)
(4) Pyqt5 tutorial -- > Custom signal and slot (super winding...)
JS array de duplication
Methods of strings in JS charat(), charcodeat(), fromcharcode(), concat(), indexof(), split(), slice(), substring()
Qiantang Pingou source code -- Qiantang Pingou app system development source code sharing
(2) Pyqt5 tutorial -- > using qtdesigner to separate interface code
Jenkins Pipeline使用
Embedded software development written examination and interview notes (latest update: February 17, 2022)
QT TCP UDP network communication < theory >