-
Notifications
You must be signed in to change notification settings - Fork 2
/
devprint.go
120 lines (110 loc) · 1.92 KB
/
devprint.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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
package main
import (
"fmt"
)
func printTypedEntries() {
for k, v := range typedEntries {
fmt.Println(k, "is a", v)
}
fmt.Print("\n")
}
func printSet(s map[int]*set, getName func(i int) string) {
for i := 0; i < len(s); i++ {
fmt.Print(getName(i), "[")
for j, t := range *s[i] {
if j > 0 {
fmt.Print(",")
}
token := t.(int)
fmt.Print(translateTerm(token))
}
fmt.Print("]\n")
}
fmt.Print("\n")
}
func translateTerm(i int) (output string) {
output = "<NOT FOUND>"
if i == -1 {
output = "$"
}
for k, v := range terms {
if v != i {
continue
}
output = k
if len(output) == 0 {
output = "<E>"
}
break
}
return
}
func translateNonterm(i int) (output string) {
output = "<NOT FOUND>"
for k, v := range nonterms {
if v != i {
continue
}
output = k
break
}
return
}
func translateTerms(s *set) (output string) {
output = "["
for i, v := range *s {
token := v.(int)
if i > 0 {
output += ","
}
output += translateTerm(token)
}
output += "]"
return
}
func printProductions() {
for i, p := range prods {
fmt.Println(i, p)
}
fmt.Println(" ")
}
func printTermMap(terms map[string]int) {
sort := make([]string, len(terms))
for k, v := range terms {
sort[v] = k
}
for i, v := range sort {
fmt.Println(i, v)
}
fmt.Println(" ")
}
func printTable() {
fmt.Print(" ")
for c := 1; c < len(terms); c++ {
fmt.Printf("%6s ", translateTerm(c))
}
fmt.Print("\n")
for r := 0; r < len(nonterms); r++ {
fmt.Printf("%12s ", translateNonterm(r))
for c := 1; c < len(terms); c++ {
fmt.Printf("%6d ", table[r][c])
}
fmt.Print("\n")
}
fmt.Print("\n")
}
func printTableRaw() {
fmt.Print(" ")
for c := 1; c < len(terms); c++ {
fmt.Printf("%6d ", c)
}
fmt.Print("\n")
for r := 0; r < len(nonterms); r++ {
fmt.Printf("%12d ", r)
for c := 1; c < len(terms); c++ {
fmt.Printf("%6d ", table[r][c])
}
fmt.Print("\n")
}
fmt.Print("\n")
}