Example #1
0
    Vanilla Scheme interpreter for SICP Chapter 4
    ctrl-d to exit,
    Happy Hacking!!
""")

code_to_eval = []
while True:
    if code_to_eval == []:
        print(PROMPT, end='')
    try:
        code = input()
    except EOFError:
        print('Goodbye!!')
        break
    else:
        code_to_eval.append(code)
        expr = parse(' '.join(code_to_eval))
        # succeeds to parse
        if expr != None:
            try:
                value = vseval(expr, GLOBAL_ENV)
            except UnboundVar as e:
                print('Unbound Variable: ', e)
            except Exception as e:
                print('Error: ', e)
            else:
                print("=> ", end='')
                print(value)
            finally:
                code_to_eval = []
Example #2
0
File: repl.py Project: nalssee/SICP
    ctrl-d to exit,
    Happy Hacking!!
""")


code_to_eval = []
while True:
    if code_to_eval == []:
        print(PROMPT, end='')
    try:
        code = input()
    except EOFError:
        print('Goodbye!!')
        break
    else:
        code_to_eval.append(code)
        expr = parse(' '.join(code_to_eval))
        # succeeds to parse
        if expr != None:
            try:
                value = vseval(expr, GLOBAL_ENV)
            except UnboundVar as e:
                print('Unbound Variable: ', e)
            except Exception as e:
                print('Error: ', e)
            else:
                print("=> ", end='')
                print(value)
            finally:
                code_to_eval = []
Example #3
0
File: test.py Project: nalssee/SICP
def ev(exp, env=GLOBAL_ENV):
    return vseval(parse(exp), env)
Example #4
0
def ev(exp, env=GLOBAL_ENV):
    return vseval(parse(exp), env)