def parse_file(source, destination=sys.stdout): if type(source) != str or len(source) == 0: return False try: with open(source) as f: lexer = Lexer(f) parser = Parser(lexer) parser.program() except IOError as e: destination.write(str(e)) destination.write('\n') return False return True
def eval_file(source, argv=sys.argv, destination=sys.stdout): if type(source) != str or len(source) == 0: return False try: with open(source) as f: lexer = Lexer(f) parser = Parser(lexer) tree = parser.program() e = Evaluator(argv) e.eval(tree, e.global_env.env_extend()) except Exception as e: destination.write(str(e)) destination.write("\n") return False return True
def pretty_file(source, destination=sys.stdout): if type(source) != str or len(source) == 0: return False try: with open(source) as f: lexer = Lexer(f) parser = Parser(lexer) tree = parser.program() pretty_string = make_pretty(tree) destination.write(pretty_string) except IOError as e: destination.write(str(e)) destination.write('\n') return False return True
def eval_swndl(self, text): l = Lexer(StringIO(text)) p = Parser(l) tree = p.program() return self.eval(tree, self.repl_env)