Ejemplo n.º 1
0
def run_repl(env):
    utility.touch(settings.get_history_file())
    readline.read_history_file(settings.get_history_file())

    while True:
        try:
            prog_str = input('> ').strip()

            if prog_str.lower() == 'exit':
                break

            if prog_str.startswith(':set'):
                parts = prog_str.split(' ')
                if len(parts) > 1:
                    if parts[1] == 'debug':
                        settings.set_debug_level(1 if settings.get_debug_level() <= 0 else 0)
            else:
                prog = program.from_source(prog_str)
                settings.log(0, lambda: str(prog))
                prog.include_with_restrictions(env)
                env = prog.evaluate()
        except KeyboardInterrupt:
            print('') # newline to go "below" the prompt
            print("Use 'exit' to exit Pecan.")
        except EOFError:
            print('exit')
            break
        except UnexpectedToken as e:
            print(e)
        except Exception as e:
            print('An exception occurred:', e)

    readline.write_history_file(settings.get_history_file())

    return env
Ejemplo n.º 2
0
    def evaluate(self, prog):
        prog.eval_level += 1

        if settings.get_debug_level() > 0:
            start_time = time.time()
            # settings.log(0, lambda: self.indented(prog, 'Evaluating {}'.format(self))

        result = self.evaluate_node(prog)
        if type(result) is tuple:
            result = (self.simplify(prog, result[0]), result[1])
        else:
            result = self.simplify(prog, result)

        prog.eval_level -= 1

        if settings.get_debug_level() > 0:
            if type(result) is tuple:
                sn, en = result[0].num_states(), result[0].num_edges()
            else:
                sn, en = result.num_states(), result.num_edges()
            end_time = time.time()
            settings.log(0, lambda: self.indented(prog, '{} has {} states and {} edges ({:.2f} seconds)'.format(self.get_display_node(prog), sn, en, end_time - start_time)))

        return result
Ejemplo n.º 3
0
def buchi_transform(original_aut, builder):
    # Build a new automata with different edges
    new_aut = spot.make_twa_graph()

    # Set the acceptance condition to be same as the input automata
    acc = original_aut.get_acceptance()
    new_aut.set_acceptance(acc.used_sets().max_set(), acc)
    new_aut.new_states(original_aut.num_states())
    new_aut.set_init_state(original_aut.get_init_state_number())

    builder.pre_build(new_aut)

    ne = original_aut.num_edges()

    if settings.get_debug_level() > 2:
        import sys

        for i, e in enumerate(original_aut.edges()):
            cond = builder.build_cond(e.cond)
            new_aut.new_edge(e.src, e.dst, cond, e.acc)

            if i % 10000 == 0:
                sys.stdout.write('\r{} of {} edges ({:.2f}%)'.format(
                    i, ne, 100 * i / ne))

        print()
    else:
        # TODO: This does the same thing as above, but it just doesn't run the check/print every time.
        #       We could run the same loop and check for debug every time, but this minor overhead
        #       accumulates a fair bit once you get to having millions of edges, so we duplicate it.
        #       It would still be nice to avoid this, though.
        for e in original_aut.edges():
            cond = builder.build_cond(e.cond)
            new_aut.new_edge(e.src, e.dst, cond, e.acc)

    builder.post_build(new_aut)

    return new_aut