This commit is contained in:
2018-05-14 00:08:25 +02:00
commit 3386ec0c4b
19 changed files with 7149 additions and 0 deletions

44
ast/ast.go Normal file
View File

@@ -0,0 +1,44 @@
package ast
import (
"fmt"
"strings"
)
type AST struct {
Tag Tag
Val interface{}
}
type Tag int8
const (
Symbol Tag = iota
List
String
Num
Bool
)
func (tag Tag) String() string {
names := []string{
"Symbol",
"List",
"String",
"Num",
"Bool",
}
return names[tag]
}
func (ast AST) Pretty() string {
if ast.Tag == List {
var agg []string
for _, elem := range(ast.Val.([]AST)) {
agg = append(agg, elem.Pretty())
}
return "(" + strings.Join(agg, " ") + ")"
}
return fmt.Sprintf("%v", ast.Val)
}