示例#1
0
func main() {
	if len(os.Args) != 2 {
		usage()
	}

	fileName := os.Args[1]
	fi, err := os.Open(fileName)
	if err != nil {
		fmt.Printf("Error: %s\n", err.Error())
		os.Exit(2)
	}
	r := bufio.NewReader(fi)
	l, c := lexer.Lex(r)

	libs := lib.Definitions()
	global := scheme.NewGlobalWithData(libs)

	for !l.Done() {
		expr, err := parser.Parse(c)
		if err != nil {
			fmt.Printf("%s\n", err.Error())
		}
		_, err = eval.Eval(global, expr)
		if err != nil {
			fmt.Printf("%s\n", err.Error())
		}
	}
}
示例#2
0
func read(s *scheme.Scope, args []scheme.Sexpr) (scheme.Sexpr, error) {
	if len(args) != 0 {
		return nil, scheme.ProcError("read must have no arguments")
	}

	br := bufio.NewReader(os.Stdin)
	str, err := br.ReadString('\n')

	r := strings.NewReader(str)
	_, c := lexer.Lex(r)
	expr, err := parser.Parse(c)
	if err != nil {
		return nil, err
	}
	return expr, nil
}