def optimize(self, code, expected): tokenizer1 = Tokenizer() tokenizer2 = Tokenizer() tokens1 = tokenizer1.tokenize('var i = ' + code) tokens2 = tokenizer2.tokenize('var i = ' + expected) parser1 = Parser() parser2 = Parser() ast1 = parser1.parse(tokens1) ast2 = parser2.parse(tokens2) optimizer = Optimizer() optimizer.optimize(ast1) self.assertEqual(ast1, ast2)
""" parser = Parser() ast = parser.parse(tokens) """ for a in ast: print a """ """ interpreter = Interpreter() interpreter.interpret(ast) """ optimizer = Optimizer() optimizer.optimize(ast) code_generator = CodeGenerator() code = code_generator.generate(ast) f = open('out.asm', 'w') f.write(code) f.close() os.system('nasm -f elf64 out.asm -o out.o') os.system('gcc out.o -o out') os.system('./out')