def interactive_eval(txt, module):
    stream, result, parse = sexp_parser.SExpGrammer().parse(txt)
    if not result or stream.position != len(txt):
        print " " * (stream.position + 2) + "^"
        print "Parse error at position: %i" % stream.position
        return None

    module, error_text = add_parse_to_module(parse, module)
    if not module:
        print "Could not interpret syntax:"
        print error_text
        return None

    if INTERACTIVE_MAIN not in module:
        return module

    try:
        prog = expression_tree.Prog(module, main=INTERACTIVE_MAIN)
        instrs, jumps = prog.compile()
    except Exception as e:
        print "Compile error: " + str(e)
        return None

    try:
        print vm.run_program(instrs, jumps)
    except vm.RuntimeException as e:
        print "Runtime error: " + str(e)
        return None

    del module[INTERACTIVE_MAIN]
    return module
def interactive_eval(txt, module):
    stream, result, parse = sexp_parser.SExpGrammer().parse(txt)
    if not result or stream.position != len(txt):
        print " " * (stream.position + 2) + "^"
        print "Parse error at position: %i" % stream.position
        return None

    module, error_text = add_parse_to_module(parse, module)
    if not module:
        print "Could not interpret syntax:"
        print error_text
        return None
    
    if INTERACTIVE_MAIN not in module:
        return module
    
    try:
        prog = expression_tree.Prog(module, main=INTERACTIVE_MAIN)
        instrs, jumps = prog.compile()
    except Exception as e:
        print "Compile error: " + str(e)
        return None
    
    try:
        print vm.run_program(instrs, jumps)
    except vm.RuntimeException as e:
        print "Runtime error: " + str(e)
        return None
    
    del module[INTERACTIVE_MAIN]
    return module
def static_eval(txt):
    stream, result, parse = sexp_parser.SExpGrammer().parse(txt)
    if not result or stream.position != len(txt):
        print " " * (stream.position + 2) + "^"
        print "Parse error at position: %i" % stream.position
        return
    
    try:
        module = sexp_to_cps.convert_parse_to_cps(parse, False)
    except Exception as e:
        print "Could not interpret syntax: " + str(e)
        return

    try:
        prog = expression_tree.Prog(module)
        instrs, jumps = prog.compile()
    except Exception as e:
        print "Compile error: " + str(e)
        return
    
    try:
        print "Program output: " + str(vm.run_program(instrs, jumps))
    except vm.RuntimeException as e:
        print "Runtime error: " + str(e)
        return
def static_eval(txt):
    stream, result, parse = sexp_parser.SExpGrammer().parse(txt)
    if not result or stream.position != len(txt):
        print " " * (stream.position + 2) + "^"
        print "Parse error at position: %i" % stream.position
        return

    try:
        module = sexp_to_cps.convert_parse_to_cps(parse, False)
    except Exception as e:
        print "Could not interpret syntax: " + str(e)
        return

    try:
        prog = expression_tree.Prog(module)
        instrs, jumps = prog.compile()
    except Exception as e:
        print "Compile error: " + str(e)
        return

    try:
        print "Program output: " + str(vm.run_program(instrs, jumps))
    except vm.RuntimeException as e:
        print "Runtime error: " + str(e)
        return