Beispiel #1
0
def gotoCommand(script='', location=''):
    line = -1

    # if SCRIPT is essl command:
    if isinstance(location, list):
        interpreter.execute([location])
        for tag in script:

            # if TAG starts with sharp and TAG value is SCRIPT:
            if tag[0] == '#' and tag[1] == getVar('ret').value:

                # execute SCRIPT starting at LINE:
                return script[line:]

            # increase LINE by 1:
            line += 1
            #evaluatedScript.remove(code)

    # if SCRIPT is not essl command:
    else:
        for tag in script:

            # if TAG starts with sharp and TAG value is SCRIPT:
            if tag[0] == '#' and tag[1] == location:

                # execute SCRIPT starting at LINE:
                return script[line:]

            # increase LINE by 1:
            line += 1
Beispiel #2
0
def inCommand(stream=''):
    if stream:

        # if STREAM is essl command:
        if isinstance(stream, list):
            interpreter.execute([stream])
            getVar('ret').value = open(getVar('ret'), 'r+').read()

        # if STREAM is not essl command:
        else:

            # if STREAM is var:
            if stream[0] == '%':

                # set STDIN to value of STREAM given as file:
                getVar('ret').value = open(getVar(stream[1:]).value, 'r+').read()

            # if STREAM is not var:
            else:

                # set STDIN to INFILE:
                getVar('ret').value = open(value[1], 'r+').read()

    # if STREAM is not specified:
    else:

        # set STDIN to INPUT:
        getVar('ret').value = input()
Beispiel #3
0
def execute(code, code_input=None):
    ''' Method for execute code onde
        :param code: raw code to be executed
        '''
    try:
        interpreter.execute(code, code_input)
    except FinishExecution:
        pass
Beispiel #4
0
def outCommand(value='', value2=''):

    # if STREAM is not supplied:
    if value and not value2:

        # if VALUE is var:
        if value[0] == '%':

            # print variable value:
            print(getVar(value[1:]).value)

        # if VALUE is not var:
        else:

            # return VALUE:
            print(value)

    # if VALUE2 is specified:
    elif value and value2:

        # if VALUE2 is essl command:
        if isinstance(value2, list):

            # if VALUE is var:
            if value[0] == '%':
                interpreter.execute([value2])
                getVar(value[1:]).value = getVar('ret').value

            # print error:
            else:
                print('Error: Value must be variable.')
                sys.exit(1)

        # if VALUE2 is not essl command:
        else:

            #if VALUE is var:
            if value[0] == '%':

                # if VALUE and VALUE2 is var:
                if value2[0] == '%':
                    getVar(value[1:]).value = getVar(value2[1:]).value

                # if VALUE is var and VALUE2 is not var:
                else:

                    # set VALUE value to VALUE2:
                    getVar(value[1:]).value = value2
Beispiel #5
0
    def interp_enum(self, clauses, target, max_depth=1):

        # Given a good candidate of a partial program, exploit the clauses
        program = self.clauses2prog(clauses)  # Time consuming
        state = execute(
            self.interpreter, program,
            is_uncertain=cmd_args.prob_dataset)  # Not using execute function
        prog = synthesize(self.interpreter,
                          target,
                          state,
                          is_uncertain=False,
                          max_depth=max_depth)

        if type(prog) == type(None):
            return

        new_prog = []
        for clause in prog.clauses:
            new_clause = clause.to_tuple()
            if len(new_clause) == 2:
                op = get_attr_operation(new_clause[0], self.config)
                new_clause = [op, new_clause[0], new_clause[1]]
            new_prog.append(new_clause)

        return new_prog
Beispiel #6
0
    def fast_query(self, clauses):

        program = self.clauses2prog(clauses)  # Time consuming
        state = execute(
            self.interpreter, program,
            is_uncertain=cmd_args.prob_dataset)  # Not using execute function

        bindings = self.interpreter.get_marginal_bindings(
            state, is_uncertain=cmd_args.prob_dataset)
        binding_dict = self.process_binding_to_dict(bindings.marginal_binding)

        # print(bindings.marginal_binding)
        return binding_dict
Beispiel #7
0
 def _run(self, cls, instance, args, context, *, call):
     variables = {param: arg
                  for arg, (param, _) in zip(args, self.parameters)}
     generic_classes = dict(Generic.fill_generic(
         [pt for _, pt in self.parameters], [arg.type for arg in args]))
     scope = instance.scope
     description = self.description
     context = interpreter.Scope(description, scope,
                                 generic_classes, variables)
     context.stack.enter(interpreter.Frame(description, call))
     if cls.base:
         if self._super_arguments:
             arguments = [interpreter.evaluate(argument, scope)
                          for argument in self._super_arguments]
             cls.base.run_constructor(instance, arguments,
                                      context, call=call)
         else:
             cls.base.run_constructor(instance, (), scope, call=call)
     try:
         interpreter.execute(self._statements, context)
     except Return:
         pass
     scope.stack.exit()
Beispiel #8
0
def root():
    context = {
        'dados': interpreter.get_dados(),
        'registradores': interpreter.get_registradores(),
        'cache': interpreter.get_cache(),
        'cache_dec': interpreter.get_cache_decimal(),
        'cache_size': interpreter.cache_size,
        'original_instruction': None
    }

    if request.method == 'POST':
        if 'instruction' in request.form:
            command = {
                'instruction': request.form['instruction'],
                'register_1': request.form['register_1'],
                'register_2': request.form['register_2']
            }

            interpreter.execute(**command)
            context['original_instruction'] = command
            context['cache_dec'] = interpreter.get_cache_decimal()
        elif 'load' in request.form:
            interpreter.update_dados([
                request.form['D0'], request.form['D1'], request.form['D2'],
                request.form['D3'], request.form['D4'], request.form['D5'],
                request.form['D6'], request.form['D7']
            ])

            context['dados'] = interpreter.get_dados()
        elif 'save' in request.form:
            interpreter.save_dados()
        else:
            print('Invalid post request')

        return render_template('page.html', **context)
    else:
        return render_template('page.html', **context)
Beispiel #9
0
def multipledraw(data: List) -> Expr:
    """
    Args:
        data: List<List<Vect>>>
    """
    if data == nil:
        return nil

    data_list_form = interpreter.execute(data.display())
    print(data_list_form)

    print('-' * 60)
    for dots in data_list_form[0]:
        draw(dots)
        print('-' * 60)
    return data
Beispiel #10
0
def _execute_file(code_file, env, print_results=False):
    """Execute some lisp.

    Args:
       code_file: An iterator over lines of Lisp text.
       env: The base environment.
       print_results: Whether to print the value of each top-level expression.
    """

    tokens = lexer.TokenSupply(lexer.lisp_tokens(code_file))
    # Are there useful ways to clean up a parse tree before we start
    # calling it an AST?
    # TODO(jasonpr): Investigate.
    for ast in parser.parse_trees(tokens):
        evaluation = interpreter.execute(ast, env)
        if print_results and evaluation is not None:
            print formatter.lisp_format(evaluation)
Beispiel #11
0
def _execute_file(code_file, env, print_results=False):
    """Execute some lisp.

    Args:
       code_file: An iterator over lines of Lisp text.
       env: The base environment.
       print_results: Whether to print the value of each top-level expression.
    """

    tokens = lexer.TokenSupply(lexer.lisp_tokens(code_file))
    # Are there useful ways to clean up a parse tree before we start
    # calling it an AST?
    # TODO(jasonpr): Investigate.
    for ast in parser.parse_trees(tokens):
        evaluation = interpreter.execute(ast, env)
        if print_results and evaluation is not None:
            print formatter.lisp_format(evaluation)
Beispiel #12
0
def interpreter(input_path: str):
    print_tokens = False
    print_nodes = False

    with open(input_path, "r") as f:
        tokens = lexer(f.read())

    if print_tokens:
        for token in tokens:
            print(token)

    nodes = parse(tokens)

    if print_nodes:
        for node in nodes:
            print(node)

    memory, mp = execute(nodes)
Beispiel #13
0
 def _run(self, cls, instance, args, context, *, call):
     variables = {param: arg
                  for arg, (param, _) in zip(args, self.parameters)}
     types = dict(Generic.fill_generic(
         [pt for _, pt in self.parameters], [arg.type for arg in args]))
     if instance:
         scope = instance.scope
     else:
         scope = cls.scope
     description = self.description
     context = interpreter.Scope(description, scope, types, variables,
                                 stack=scope.stack)
     context.stack.enter(interpreter.Frame(description, call))
     try:
         value = interpreter.execute(self._statements, context)
     except Return as e:
         value = e.value
     scope.stack.exit()
     return value
Beispiel #14
0
def SEND_TO_ALIEN_PROXY(data):
    url = server_url + '/aliens/send'
    print(f"url: {url}")
    print(f"data: {data}")
    print(data.display())
    modulated_data = interpreter.execute("ap mod " + data.display())
    modulated_data_str = "".join([str(bit) for bit in modulated_data])

    res = requests.post(url, data=modulated_data_str)
    if res.status_code != 200:
        print('Unexpected server response:')
        print('HTTP code:', res.status_code)
        print('Response body:', res.text)
        exit(1)

    print('Server response:', res.text)
    return res.text

    # return [Atom(0)]
    return [Atom(1), Atom(67425)]
Beispiel #15
0
from config import keywords, literals, primitives
from interpreter import execute, stdin
from lexer import *
from parser import *
from ply.lex import lex
from ply.yacc import yacc
tokens = keywords + primitives
tokenizer = lex(debug=0)
compiler = yacc()
compiler.error = 0
print("oply >>>")
program = compiler.parse(stdin(), debug=0)
print
execute(program)
print
raw_input("exit")
Beispiel #16
0
def lex(code):
    code = code.strip().split("\n")
    for x in range(code.count("")):
        code.remove("")
    code.append("")
    execute(parse(code))
Beispiel #17
0
from config import keywords, literals, primitives
from interpreter import execute, stdin
from lexer import *
from parser import *
from ply.lex import lex
from ply.yacc import yacc
tokens = keywords + primitives
tokenizer = lex( debug=0 )
compiler = yacc()
compiler.error = 0
print( "oply >>>" )
program = compiler.parse( stdin(), debug=0 )
print
execute( program )
print
raw_input( "exit" )
Beispiel #18
0
 def test_numeric_expression(self):
     for expression, result in calculator_test_cases:
         self.assertAlmostEqual(execute(expression), result)
Beispiel #19
0
    variable = commands.Variable(str(i))
    variable.value = arg
    args.append(variable)
    i += 1

# if argument count is greater than 1:
if len(sys.argv) > 2:

    # if 2nd argument is 'run':
    if sys.argv[1] == 'run':

        # if ESSLFILE should be read from STDIN:
        if sys.argv[2][0] == '-':

            # parse and execute 3rd argument:
            interpreter.execute(parser.parse(sys.argv[2][1:]), args)

        # if ESSLFILE should not be read from STDIN:
        else:

            # set ESSLFILE to file given in 3rd argument:
            esslFile = open(sys.argv[2], 'r+')

            # parse and execute ESSLFILE:
            interpreter.execute(parser.parse(esslFile.read()), args)

    # if 2nd argument is not a recognized action:
    else:

        # print error:
        print('Action ' + sys.argv[1] + ' not found.')