Esempio n. 1
0
File: eval.go Progetto: ctliu3/Gosp
func EvalImport(expr string, env *scope.Scope) {
	nodes := parser.ParseFromString(expr)

	for _, node := range nodes {
		node.Eval(env)
	}
}
Esempio n. 2
0
func parse(exprs []string) {
	for _, expr := range exprs {
		nodes := parser.ParseFromString(expr)
		for _, node := range nodes {
			fmt.Println(node.Type())
		}
	}
}
Esempio n. 3
0
File: eval.go Progetto: ctliu3/Gosp
func Eval(expr string) string {
	nodes := parser.ParseFromString(expr)
	fmt.Printf("#AST = %d\n", len(nodes))

	env := scope.NewScope(nil)
	var result []string
	for _, node := range nodes {
		switch node.(type) {
		case *ast.Import:
			expr := node.Eval(env)
			EvalImport(expr.String(), env)
		default:
			if val := node.Eval(env); val != nil {
				result = append(result, val.String())
			}
		}
	}

	return strings.Join(result, " ")
}