-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathast.go
62 lines (47 loc) · 1005 Bytes
/
ast.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
package glambda
import "fmt"
type node interface {
node()
}
type term interface {
node
term()
}
// Variable
type variableNode struct {
name string
}
func (n variableNode) node() {}
func (n variableNode) term() {}
func (n variableNode) String() string {
return n.name
}
// Abstraction
type abstractionNode struct {
variable variableNode
body term
}
func (n abstractionNode) node() {}
func (n abstractionNode) term() {}
func (n abstractionNode) String() string {
return fmt.Sprintf("(λ %s . %s)", n.variable, n.body)
}
// Application
type applicationNode struct {
left term
right term
}
func (n applicationNode) node() {}
func (n applicationNode) term() {}
func (n applicationNode) String() string {
return fmt.Sprintf("(%s %s)", n.left, n.right)
}
// Definition
type definitionNode struct {
name string
abstraction abstractionNode
}
func (n definitionNode) node() {}
func (n definitionNode) String() string {
return fmt.Sprintf("%s = %s", n.name, n.abstraction)
}