open Ast (* command line options *) let dump = ref false let ifile = ref "" let usage = "usage: analyzer [options] file.scade" let options = [ "--dump", Arg.Set dump, "Dump program source."; ] let () = Arg.parse options (fun f -> ifile := f) usage; if !ifile = "" then begin Format.eprintf "No input file...@."; exit 1 end; let prog = File_parser.parse_file !ifile in if !dump then Ast_printer.print_prog Format.std_formatter prog; try let s0 = Interpret.program_init_state prog "test" in Format.printf "Init state:@."; Data.print_state s0; let rec it i st = let st, outputs, next_st = Interpret.program_step prog st ["i", Data.VInt i] "test" in Format.printf "@.> Step %d:@." i; Data.print_state st; match List.assoc "exit" outputs with | Data.VBool false -> it (i+1) next_st | _ -> () in it 0 s0 with | Data.Combinatorial_cycle v -> Format.eprintf "Combinatorial cycle (%s)@." v | Data.Type_error e -> Format.eprintf "Typing error: %s@." e | Data.Not_implemented l -> Format.eprintf "Not implemented: %s@." l | Data.No_variable id -> Format.eprintf "No such variable: %s@." id