Exemplo n.º 1
0
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
Exemplo n.º 2
0
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
Exemplo n.º 3
0
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
Exemplo n.º 4
0
 def eval_swndl(self, text):
     l = Lexer(StringIO(text))
     p = Parser(l)
     tree = p.program()
     return self.eval(tree, self.repl_env)