Exemplo n.º 1
0
func walk(inputfile string, info os.FileInfo, err error) error {
	if info.IsDir() {
		if inputfile != os.Args[1] {
			return filepath.SkipDir
		}
		return nil
	}

	if filepath.Ext(inputfile) == ".jack" {
		tokens, _ := token.Read(inputfile)
		dir, file := filepath.Split(inputfile)
		base := file[:len(file)-len(filepath.Ext(file))]
		parser.CompileClass(tokens, filepath.Join(dir, base+".vm"))
	}
	return nil
}
Exemplo n.º 2
0
func main() {
	inputInfo, err := os.Stat(os.Args[1])
	if err != nil {
		panic(err)
	}
	if inputInfo.IsDir() {
		filepath.Walk(os.Args[1], walk)
	} else {
		tokens, _ := token.Read(os.Args[1])
		if len(os.Args) > 2 {
			parser.CompileClass(tokens, os.Args[2])
		} else {
			dir, file := filepath.Split(os.Args[1])
			base := file[:len(file)-len(filepath.Ext(file))]
			parser.CompileClass(tokens, filepath.Join(dir, base+".vm"))
		}
	}
}