Ejemplo n.º 1
0
func main() {
	log.SetFlags(log.Lshortfile)
	lambda := 1.0
	TPSolver := tpsolverdefault.Solve
	log.SetOutput(ioutil.Discard)
	resultPrinter := printStandard
	filename := "NOFILENAMECHOSEN"

	for i := 1; i < len(os.Args); i++ {
		if os.Args[i] == "-l" {
			arg := getOrFail(i+1, "expected a float after -l but there was nothing")

			temp, err := strconv.ParseFloat(arg, 64)
			lambda = temp

			if err != nil {
				fail(fmt.Sprintf("expected a float for lambda(-l) but got %s", arg))
			}
			if lambda < 0 || lambda > 1 {
				fail(fmt.Sprintf("invalid lambda value, has to be larger than 0 and less or equal to 1"))
			}

			i++
		} else if os.Args[i] == "-tpsolver" {
			arg := getOrFail(i+1, "expected cplex or default after -tpsolver but there was nothing")

			if arg == "cplex" {
				TPSolver = tpsolvercplex.Solve
			} else if arg != "default" {
				fail(fmt.Sprintf("expected cplex or default after -tpsolver but got %s", arg))
			}

			i++
		} else if os.Args[i] == "-v" {
			log.SetOutput(os.Stdout)
		} else if os.Args[i] == "-h" {
			printdocumentation()
			os.Exit(0)
		} else if os.Args[i] == "-m" {
			resultPrinter = printDistanceMatrix
		} else {
			filename = getOrFail(i, "expected a file but there was nothing")
		}
	}

	if filename == "NOFILENAMECHOSEN" {
		printdocumentation()
		os.Exit(0)
	}

	mc, err := compiler.Parse(filename)

	if err != nil {
		fail(err.Error())
	}

	d := pseudometric.PseudoMetric(mc, lambda, TPSolver)
	resultPrinter(d, mc)
}
Ejemplo n.º 2
0
func main() {
	if len(os.Args) < 4 {
		fmt.Println("usage: go run compiler.go <pascal-file> <reserved-words-file> <output-name>")
		os.Exit(1)
	}
	rpath, e1 := filepath.Abs(os.Args[1])
	check(e1)
	rwords := ReadReservedWordFile(rpath)
	fpath, e0 := filepath.Abs(os.Args[2])
	check(e0)
	listing := ReadSourceFile(fpath)
	tokens, symbols := compiler.Tokenize(listing, rwords)
	OutputTokenFile(tokens, symbols, os.Args[3])
	OutputSymbolFile(symbols, os.Args[3])
	compiler.Parse(listing, tokens, symbols)
	OutputListingFile(listing, os.Args[3])
}