forked from simoneguidi94/gopapageno
/
symbol.go
39 lines (34 loc) · 786 Bytes
/
symbol.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
package xpath
/*
symbol contains a token and its value, a precedence and pointers to build the syntactic tree.
*/
type symbol struct {
Token uint16
Precedence uint16
Value interface{}
Next *symbol
Child *symbol
}
func (s *symbol) printTreeR(level int) {
/*if s == nil {
return
}
fmt.Print("> ")
for i := 0; i < level; i++ {
fmt.Print(" ")
}
fmt.Print(tokenToString(s.Token), ": ")
if s.Token == _PLUS || s.Token == _TIMES || s.Token == _LPAR || s.Token == _RPAR {
fmt.Println(string(s.Value.(int32)))
} else {
fmt.Println(*s.Value.(*int64))
}
s.Child.printTreeR(level + 1)
s.Next.printTreeR(level)*/
}
/*
PrintTreeln prints the syntactic tree using the symbol as the root.
*/
func (root *symbol) PrintTreeln() {
root.printTreeR(0)
}