Example #1
0
func main() {
	armList := &fw.ARMList{}

	file := os.Args[1] // index 1 is file path
	b, err := ioutil.ReadFile(file)
	if err != nil {
		fmt.Println(err)
		os.Exit(1)
	}
	s := string(b)
	root, err := parser.ParseFile(file, s)
	if err != nil {
		os.Exit(SYNTAX_ERROR)
	}
	fmt.Println(root)

	errs := root.SemanticCheck()
	if errs != nil {
		for _, str := range errs {
			fmt.Println(str)
		}
		os.Exit(SEMANTIC_ERROR)
	}
	root.SymbolTable.PrintChildren()

	filename := filepath.Base(file)
	ext := filepath.Ext(filename)
	fileARM := filename[0:len(filename)-len(ext)] + ".s"

	codeGen := cg.ConstructCodeGenerator(root, armList, root.SymbolTable)
	codeGen.GenerateCode()
	for _, instr := range *armList {
		fmt.Print(instr)
	}
	armList.WriteToFile(fileARM)

}
Example #2
0
func main() {
	if len(os.Args) < 2 {
		fmt.Printf("Please provide an input filename as an argument\n")
		return
	}

	input := os.Args[1]

	fmt.Printf("Running: %s\n", input)

	u := parser.ParseFile(input)
	if u == nil {
		fmt.Printf("Invalid input file\n")
		return
	}
	s := u.Instantiate()
	r := rand.New(rand.NewSource(rand.Int63()))

	log := s.Now()

	for {
		s.RunSpontaneous(r)

		// Display events
		for {
			log = log.Future()
			if log == nil {
				fmt.Printf("Error or something\n")
			}
			if cause := log.Cause(); cause != nil {
				fmt.Printf("%s\n", cause.Description())
			}
			if log == s.Now() {
				break
			}
		}

		if debug {
			p := s.PossibleTransitions()
			fmt.Printf("[%v can %v]\n", s, p)
		}

		// Have user choose a transition
		choices := s.ChosenTransitions()
		fmt.Fprintf(os.Stdout, "  0. Exit.\n")
		fmt.Fprintf(os.Stderr, "  1. Do nothing.\n")
		for i, t := range choices {
			fmt.Fprintf(os.Stderr, "  %d. %s\n", i+2, t.ChoiceDescription())
		}
		var choice int
		for {
			fmt.Fprintf(os.Stderr, "> ")
			fmt.Scanf("%d", &choice)
			//			n, err := fmt.Scanf("%d", &choice)
			/*			if n < 1 {
						if err.String() == "unexpected newline" || err.String() == "expected integer" {
							// TODO: KLUDGE. What we want here is distinguishing "malformed input" from "I/O error."
							// read again
						} else {
							fmt.Fprintf(os.Stderr, "error reading stdin: %s\n", err.String())
							return
						}
					} else*/if choice < 0 || choice > len(choices) {
				fmt.Printf("Please enter a number between 1 and %d.\n", len(choices))
			} else /* good result */ {
				break
			}
		}
		if choice == 0 {
			return
		}
		if choice != 1 {
			choices[choice-1].Apply(s)
		}
	}
}
Example #3
0
func Test_Parser(t *testing.T) {
	parser.ParseFile("test")
}