예제 #1
0
func TransFile(w io.Writer, fname, expr string) {
	f := token.NewFile(fname, expr, 1)
	n := parser.ParseFile(f, expr)

	if f.NumErrors() > 0 {
		f.PrintErrors()
		return
	}

	t := &translator{out: w, file: f, scope: n.Scope}
	t.topComment()
	/* includes will/might eventually reflect the imports from Calc. It's
	 * possible that stdio might be an auto-include if print remains a
	 * built-in function, which is likely won't */
	t.includes() /* temporary */
	t.transFuncSigs(n)
	t.transpile(n, false)

	if f.NumErrors() > 0 {
		f.PrintErrors()
	}

	if t.scope.Lookup("main") == nil {
		fmt.Println("No function \"main\" found!")
	}
	return
}
예제 #2
0
파일: eval.go 프로젝트: rthornton128/gocalc
func EvalFile(fname, expr string) interface{} {
	f := token.NewFile(fname, expr, 1)
	n := parser.ParseFile(f, expr)
	if f.NumErrors() > 0 {
		f.PrintErrors()
		return nil
	}
	e := &evaluator{file: f, scope: n.Scope}
	res := e.eval(n)
	if f.NumErrors() > 0 {
		f.PrintErrors()
		return nil
	}
	return res
}