git @ Cat's Eye Technologies Exanoke / 91634cf
But it can run simple programs without crashing. Chris Pressey 7 years ago
3 changed file(s) with 12 addition(s) and 18 deletion(s). Raw diff Collapse all Expand all
0 cons(:hi, cons(:there, :nil))
0 def double(#)
1 cons(#, #)
2 def quadruple(#)
3 double(double(#))
4
5 quadruple(:meow)
338338
339339
340340 class SExpr(object):
341 pass
341 def __repr__(self):
342 return "SExpr()"
342343
343344
344345 class Atom(SExpr):
349350 return self.text
350351
351352 def __repr__(self):
352 return "Atom(%r)" % self.text
353 return "Atom('%s')" % self.text
353354
354355 def __eq__(self, other):
355356 return isinstance(other, Atom) and self.text == other.text
364365 return "(%s %s)" % (self.head, self.tail)
365366
366367 def __repr__(self):
367 return "Cons(%r, %r)" % (self.head, self.tail)
368 return "Cons(%s, %s)" % (self.head.__repr__(), self.tail.__repr__())
368369
369370 def __eq__(self, other):
370371 return False # isinstance(other, Cons) and self.head == other.head and self.tail == other.tail
500501 os.close(fd)
501502 return text
502503
503 def rpython_input():
504 accum = ''
505 done = False
506 while not done:
507 s = os.read(1, 1)
508 if not s:
509 done = True
510 accum += s
511 return accum
512
513504 def rpython_main(argv):
514 #inp = rpython_input()
515 #if not inp:
516 # inp = 'ifeq'
517505 text = rpython_load(argv[1])
518506 p = Parser(text)
519507 prog = p.program()
520 print "%r" % prog
521508 ev = Evaluator(prog)
522509 result = ev.eval(prog)
523 print "%r" % result
510 print result.__repr__()
524511 return 0
525512
526513 return rpython_main, None