-
Notifications
You must be signed in to change notification settings - Fork 1
/
ep.go
56 lines (45 loc) · 1.01 KB
/
ep.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
package main
import(
"fmt"
"bufio"
"os"
)
func main() {
for {
// Prompt
fmt.Printf("ep> ")
// Tokenize it here
input, _ := bufio.NewReader(os.Stdin).ReadString('\n')
terms := split(chomp(input))
// Dispatch it here
for _, term := range terms {
switch term {
case "foo": foo()
case "bar": bar()
}
}
}
}
// A term is a label plus a part of speech
// For bootstrapping purposes, no name collisions
type term struct {
label string
pos *partOfSpeech
}
func (t *term) String() string {
return fmt.Sprintf("label: %s, arity: %d", t.label, t.pos.Arity())
}
func foo() {
// two senses of foo, foo1 and foo2
foo1 := &term{label: "foo", pos: &partOfSpeech{label: "one", arity: 1} }
foo2 := &term{label: "foo", pos: &partOfSpeech{label: "two", arity: 2} }
switch {
// decide which foo
case foo1 != nil: fmt.Println(foo1, foo1.pos)
case foo2 != nil: fmt.Println(foo2)
}
}
func bar() {
bar1 := &term{label: "bar", pos: &partOfSpeech{label: "one", arity: 1} }
fmt.Println(bar1, bar1.pos)
}