view interps/lambda/lambda.py @ 12518:2d8fe55c6e65 draft default tip

<int-e> learn The password of the month is release incident pilot.
author HackEso <hackeso@esolangs.org>
date Sun, 03 Nov 2024 00:31:02 +0000
parents 859f9b4339e6
children
line wrap: on
line source

#!/usr/bin/python

import parser, tokenizer, evaluator

import sys, pickle
sys.setrecursionlimit(65535) # not too big, but hopefully big enough for some stuff


try:
    line = raw_input()
except EOFError:
    raise SystemExit

# tokenize
try:
    tokens = tokenizer.tokenize(line)
except Exception, line:
    print "Tokenizer error:", line
    raise SystemExit

# Get a pickled environment
try:
    env = pickle.load(open('lambda/defs.pickle'))
except:
    env = {}

# parse
try:
    exp, defs = parser.parse(tokens, env)
except Exception, line:
    print "Parser error:", line
    raise SystemExit

env.update(defs)

# evaluate

try:
    if exp != None:
        evaluator.eval(exp, env)
except Exception, line:
    print "Run-time error:", line
    raise SystemExit

# finally, save the definitions

f = open('lambda/defs.pickle', 'w')
pickle.dump(env, f)