def run_animation_mode(argv): env = Environment() # 1. create env. file_name_str, solution_file_name_str = read_input_string(argv, 1) # 2. read filenames ast_string, error = file_to_AST_str_no_print(file_name_str) # 3. parse input-file to string if error: print error #env.set_search_dir(file_name_str) root = str_ast_to_python_ast(ast_string) # 4. parse string to python ast TODO: JSON # uncomment for profiling (e.g. performance tests) #import cProfile #cProfile.run('mch = interpret(root, env)','pyB_profile_out.txt') solution_file_present = not solution_file_name_str=="" #if solution_file_present: # 5. parse solution-file and write to env. # read_solution_file(env, solution_file_name_str) # The concreate solution values are added at # the bmachine object-init time to the respective mch # 6. replace defs and extern-functions inside mch and solution-file (if present) parse_object = remove_defs_and_parse_ast(root, env) # 7. which kind of ast? if not isinstance(parse_object, BMachine): is_ppu = isinstance(parse_object, PredicateParseUnit) is_epu = isinstance(parse_object, ExpressionParseUnit) assert is_ppu or is_epu result = interpret(parse_object.root, env) # eval predicate or expression print result # TODO: print_values_b_style needs symbolic set impl #print print_values_b_style(result) return 0 assert isinstance(parse_object, BMachine) # 8. typecheck mch = parse_object type_check_root_bmch(root, env, mch) # also checks all included, seen, used and extend # TODO: Check with B spec # 9. animate if ops are present # DO-WHILE Loop while True: next_states = __calc_states_and_print_ui(root, env, mch, solution_file_present) if next_states==[]: # BUG: no enabled ops doesnt mean there are none (deadlock-state) pass undo_possible = not env.state_space.empty() number_of_options = len(next_states) if undo_possible: number_of_options = number_of_options + 1 input_str = "Input (0-"+str(number_of_options)+"):" #number = raw_input(input_str) # XXXX number = number_of_options number = int(number) # quit if number == number_of_options: print "goodbye" break elif undo_possible and number == number_of_options-1: x = env.state_space.get_stack_size() x = x-1 # BUGFIX: empty state on stack if 2==x and env.init_state_on_stack and env.set_up_state_on_stack: env.init_state_on_stack==False env.init_done = False elif 1==x and env.init_state_on_stack and env.set_up_state_on_stack==False: env.init_state_on_stack==False env.init_done = False elif 1==x and env.set_up_state_on_stack: env.set_up_done = False env.set_up_state_on_stack = False env.set_up_bmachines_names = [] env.state_space.undo() elif not env.set_up_done: env.set_up_done = True env.set_up_state_on_stack = True bstate = next_states[number] env.state_space.add_state(bstate) elif not env.init_done: env.init_done = True env.init_state_on_stack = True bstate = next_states[number] env.state_space.add_state(bstate) # init and set_up done. Exec operation: elif len(next_states)>number and number >= 0: # switch state ( bstate = next_states[number] env.state_space.add_state(bstate) else: print "Error! Wrong input:", number return 0