-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathbase.go
More file actions
98 lines (84 loc) · 1.64 KB
/
base.go
File metadata and controls
98 lines (84 loc) · 1.64 KB
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
package lisp
import (
"errors"
"fmt"
"github.com/hydra13142/lisp/parser"
)
type Kind int
type Name string
type Gfac func([]Token, *Lisp) (Token, error)
type Hong struct {
Para []Name
Text []Token
Real []Name
}
type Lfac struct {
Para []Name
Text []Token
Make *Lisp
}
const (
Null Kind = iota
Int
Float
String
Chan
Fold
List
Back
Macro
Front
Label
Operator
)
var (
pattern = &parser.Pattern{}
True = Token{Int, int64(1)}
False = Token{List, []Token(nil)}
None = Token{}
Global = &Lisp{env: map[Name]Token{}, dad: nil}
ErrNotOver = errors.New("Cannot scan to the end")
ErrUnquote = errors.New("Quote is unfold")
ErrNotFind = errors.New("Not find this Name")
ErrNotFunc = errors.New("Not a function")
ErrParaNum = errors.New("Wrong parament number")
ErrFitType = errors.New("Lisp type is wrong")
ErrNotName = errors.New("This's not a Name")
ErrIsEmpty = errors.New("Fold is empty")
ErrNotConv = errors.New("Cannot translate")
ErrRefused = errors.New("Can't remove a back function")
ErrIsClose = errors.New("Channel has been closed")
)
func (t Kind) String() string {
switch t {
case Int:
return "int"
case Float:
return "float"
case String:
return "string"
case Chan:
return "channel"
case Fold:
return "fold list"
case List:
return "list"
case Back:
return "go"
case Macro:
return "macro"
case Front:
return "lisp"
case Label:
return "Name"
case Operator:
return "operator"
}
return "unknown"
}
func (m Hong) String() string {
return fmt.Sprintf("{macro : %v | %v => %v}", m.Para, m.Real, m.Text)
}
func (l Lfac) String() string {
return fmt.Sprintf("{front : %v => %v}", l.Para, l.Text)
}