Esempio n. 1
0
File: pyB.py Progetto: hhu-stups/pyB
def run_animation_mode(arguments):
    root, env, parse_object, solution_file_present = startup(arguments)
    
    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 print_values_b_style(result)
    else:
        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)
            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
Esempio n. 2
0
 def test_repl_eq(self):
     env = Environment() 
     input = "1+1=2"
     output, err = parse_repl_input(input)
     assert err==None
     assert print_values_b_style(output)=="True"