diff options
author | Alex Auvolat <alex.auvolat@ansys.com> | 2014-06-17 09:48:22 +0200 |
---|---|---|
committer | Alex Auvolat <alex.auvolat@ansys.com> | 2014-06-17 09:48:22 +0200 |
commit | 860ad2752ef0544bc6874d895875a78f91db9084 (patch) | |
tree | 9f366fe801b9ae145338c5859aa70f0a384c2ea1 /main.ml | |
parent | b5fd9598302b3e7ac8ab75c36d5a7290d1ad0d78 (diff) | |
download | scade-analyzer-860ad2752ef0544bc6874d895875a78f91db9084.tar.gz scade-analyzer-860ad2752ef0544bc6874d895875a78f91db9084.zip |
Add AST for logical formula.
Diffstat (limited to 'main.ml')
-rw-r--r-- | main.ml | 71 |
1 files changed, 33 insertions, 38 deletions
@@ -1,6 +1,6 @@ open Ast -module Interpret = Interpret2.I +module Interpret = Interpret.I (* command line options *) let dump = ref false @@ -18,6 +18,36 @@ let options = [ "--test", Arg.Set test, "Simple testing."; ] +let do_test_interpret prog verbose = + let s0 = Interpret.init_state prog "test" in + if verbose then begin + Format.printf "Init state:@."; + Interpret.print_state Format.std_formatter s0; + end; + let rec it i st = + let next_st, out = + Interpret.step st + ["i", Interpret.int_value i] + in + if verbose then begin + Format.printf "@.> Step %d:@." i; + Interpret.print_state Format.std_formatter st; + Format.printf "Outputs:@."; + List.iter + (fun (k, v) -> Format.printf "%s = %s@." + k (Interpret.str_repr_of_val v)) + out; + end else begin + Format.printf "%d. %s %s %s@." i + (Interpret.str_repr_of_val (List.assoc "a" out)) + (Interpret.str_repr_of_val (List.assoc "b" out)) + (Interpret.str_repr_of_val (List.assoc "c" out)); + end; + if not (Interpret.as_bool (List.assoc "exit" out)) then + it (i+1) next_st + in + it 0 s0 + let () = Arg.parse options (fun f -> ifile := f) usage; @@ -33,44 +63,9 @@ let () = let prog = Rename.rename_prog prog in if !dumprn then Ast_printer.print_prog Format.std_formatter prog; - if !vtest then begin - let s0 = Interpret.init_state prog "test" in - Format.printf "Init state:@."; - Interpret.print_state Format.std_formatter s0; - let rec it i st = - let next_st, out = - Interpret.step st - ["i", Interpret.int_value i] - in - Format.printf "@.> Step %d:@." i; - Interpret.print_state Format.std_formatter st; - Format.printf "Outputs:@."; - List.iter - (fun (k, v) -> Format.printf "%s = %s@." - k (Interpret.str_repr_of_val v)) - out; - if not (Interpret.as_bool (List.assoc "exit" out)) then - it (i+1) next_st - in - it 0 s0 - end; + if !vtest then do_test_interpret prog true + else if !test then do_test_interpret prog false; - if !test then begin - let s0 = Interpret.init_state prog "test" in - let rec it i st = - let next_st, outputs = - Interpret.step st - ["i", Interpret.int_value i] - in - Format.printf "%d. %s %s %s@." i - (Interpret.str_repr_of_val (List.assoc "a" outputs)) - (Interpret.str_repr_of_val (List.assoc "b" outputs)) - (Interpret.str_repr_of_val (List.assoc "c" outputs)); - if not (Interpret.as_bool (List.assoc "exit" outputs)) then - it (i+1) next_st - in - it 0 s0 - end with | Util.NoLocError e -> Format.eprintf "Error: %s@." e | Util.LocError(l, e) -> |