Ejemplo n.º 1
0
 def run_snippet(self, code):
     tokens = OysterScanner(dedent(code)).read_all()
     instructions = OysterParser.parse(tokens).items
     stack = [StackFrame(instructions, self.env)]
     cur = None
     while stack:
         cur = eval(stack, cur)
     return cur
Ejemplo n.º 2
0
 def run_snippet(self, code):
     tokens = OysterScanner(dedent(code)).read_all()
     instructions = OysterParser.parse(tokens).items
     stack = [StackFrame(instructions, self.env)]
     cur = None
     while stack:
         cur = eval(stack, cur)
     return cur
Ejemplo n.º 3
0
 def run_program(self, filename):
     with open(filename) as file:
         tokens = OysterScanner(file.read()).tokenize()
     statements = OysterParser().parse(tokens).items
     instructions = [Instruction(Instruction.CODE, statement)
                     for statement in statements]
     instructions.reverse()
     stack = [StackFrame(instructions, self.env)]
     cur = None
     while stack:
         cur = eval(stack, cur)
     return cur
Ejemplo n.º 4
0
def run_string(string):
    tokens = OysterScanner(string).tokenize()
    statements = OysterParser().parse(tokens)
    instructions = [Instruction(Instruction.CODE, statement)
                    for statement in statements.items]
    instructions.reverse()
    env = populate_globals(Env(None, None))
    stack = [StackFrame(instructions, env)]
    cur = None
    while stack:
        cur = eval(stack, cur)

    print "Result is", cur.__str__()
Ejemplo n.º 5
0
 def run_program(self, filename):
     with open(filename) as file:
         tokens = OysterScanner(file.read()).tokenize()
     statements = OysterParser().parse(tokens).items
     instructions = [
         Instruction(Instruction.CODE, statement)
         for statement in statements
     ]
     instructions.reverse()
     stack = [StackFrame(instructions, self.env)]
     cur = None
     while stack:
         cur = eval(stack, cur)
     return cur
Ejemplo n.º 6
0
def run_string(string):
    tokens = OysterScanner(string).tokenize()
    statements = OysterParser().parse(tokens)
    instructions = [
        Instruction(Instruction.CODE, statement)
        for statement in statements.items
    ]
    instructions.reverse()
    env = populate_globals(Env(None, None))
    stack = [StackFrame(instructions, env)]
    cur = None
    while stack:
        cur = eval(stack, cur)

    print "Result is", cur.__str__()
Ejemplo n.º 7
0
 def run_parsed_code(self, code):
     stack = [StackFrame(code, self.env)]
     cur = None
     while stack:
         cur = eval(stack, cur)
     return cur
Ejemplo n.º 8
0
 def run_parsed_code(self, code):
     stack = [StackFrame(code, self.env)]
     cur = None
     while stack:
         cur = eval(stack, cur)
     return cur