-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
56 lines (48 loc) · 842 Bytes
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
package main
import (
"fmt"
"os"
"v8.run/go/conf/script/lexer"
"v8.run/go/conf/script/parser"
"v8.run/go/conf/script/parser/bsr"
)
var testdata = `
func AddOne(x:u64) u64 {
return x + 1;
}
let x:u64 = AddOne(1);
if (x == 1) {
print("AddOne(1) == 1");
} else if (x == 2) {
print("AddOne(1) == 2");
} else {
print("AddOne(1) == something else");
}
`
func Walk(b bsr.BSR, fn func(bsr.BSR)) {
fn(b)
for _, c := range b.GetAllNTChildren() {
for _, nt := range c {
Walk(nt, fn)
}
}
}
func main() {
l := lexer.New([]rune(testdata))
for _, tok := range l.Tokens {
fmt.Printf("%s\n", tok)
}
p, errs := parser.Parse(l)
for _, err := range errs {
fmt.Println("error:", err)
}
if len(errs) > 0 {
os.Exit(1)
return
}
if p.IsAmbiguous() {
fmt.Println("ambiguous")
} else {
fmt.Println("not ambiguous")
}
}