Exemple #1
0
 def _add_fake_builtins(self):
     # TODO: handle this path better
     path = os.path.join(os.path.dirname(os.path.abspath(__file__)), '..',
                         'stdlib', 'fake_builtins.simple')
     with open(path, 'r', encoding='ascii') as file:
         content = file.read()
     tokens = tokenizer.tokenize(content)
     for ast_statement in ast_tree.parse(tokens):
         self.execute(ast_statement, self.builtin_context)
def main():
    parser = argparse.ArgumentParser()
    parser.add_argument('file')
    args = parser.parse_args()

    with open(args.file, 'r') as file:
        content = file.read()

    tokens = tokenizer.tokenize(content)
    ast_statements = ast_tree.parse(tokens)

    interpreter = run.Interpreter()
    try:
        for statement in ast_statements:
            interpreter.execute(statement, interpreter.global_context)
    except objects.ReturnAValue:
        raise ValueError("unexpected return")
 def run(code):
     tokens = list(tokenizer.tokenize(code))
     ast_statements = list(ast_tree.parse(tokens))
     for statement in ast_statements:
         interp.execute(statement, interp.global_context)
Exemple #4
0
def parse(code):
    # list() calls are for fail-fast debuggability
    tokens = list(tokenizer.tokenize(code))
    return list(ast_tree.parse(tokens))
Exemple #5
0
def tokenizelist(code):
    return list(tokenize(code))