提交 013ecb93 编写于 作者: chai2010's avatar chai2010

初步支持 global, AST 暂时作为 var 处理

上级 199c5f36
......@@ -54,9 +54,11 @@
```wa
import "fmt"
global year: i32 = 2023
func main {
println("你好,凹语言!")
println(add(40, 2))
println("hello, Wa!")
println(add(40, 2), year)
fmt.Println(1+1)
}
......@@ -71,7 +73,7 @@ func add(a: i32, b: i32) => i32 {
```
$ go run main.go hello.wa
你好,凹语言!
42
42 2023
2
```
......
......@@ -60,9 +60,11 @@ Print rune and call function:
```wa
import "fmt"
global year: i32 = 2023
func main {
println("hello, Wa!")
println(add(40, 2))
println(add(40, 2), year)
fmt.Println(1+1)
}
......@@ -77,7 +79,7 @@ Execute the program:
```
$ go run main.go hello.wa
hello, Wa!
42
42 2023
2
```
......
......@@ -497,9 +497,10 @@ var stmtStart = map[token.Token]bool{
}
var declStart = map[token.Token]bool{
token.CONST: true,
token.TYPE: true,
token.VAR: true,
token.CONST: true,
token.TYPE: true,
token.VAR: true,
token.GLOBAL: true,
}
var exprEnd = map[token.Token]bool{
......@@ -2458,6 +2459,11 @@ func (p *parser) parseGenDecl(keyword token.Token, f parseSpecFunction) *ast.Gen
doc := p.leadComment
pos := p.expect(keyword)
if keyword == token.GLOBAL {
keyword = token.VAR // TODO(chai2010): AST 支持 global
}
var lparen, rparen token.Pos
var list []ast.Spec
if p.tok == token.LPAREN {
......@@ -2564,7 +2570,7 @@ func (p *parser) parseDecl(sync map[token.Token]bool) ast.Decl {
var f parseSpecFunction
switch p.tok {
case token.CONST, token.VAR:
case token.CONST, token.VAR, token.GLOBAL:
f = p.parseValueSpec
case token.TYPE:
......
......@@ -106,6 +106,7 @@ const (
FOR
FUNC
GLOBAL
IF
IMPORT
......@@ -203,6 +204,7 @@ var tokens = [...]string{
FOR: "for",
FUNC: "func",
GLOBAL: "global",
IF: "if",
IMPORT: "import",
......
......@@ -3,9 +3,11 @@
import "fmt"
import "runtime"
global year: i32 = 2023
func main {
println("你好,凹语言!", runtime.WAOS)
println(add(40, 2))
println(add(40, 2), year)
fmt.Println("1+1 =", 1+1)
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册