-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmain.py
51 lines (37 loc) · 1.21 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#=================================================
# copyright Amin By [http://aminby.net]
# Since 2014-4
#=================================================
from parser import SParser
PRT_FAIL = '\033[91m'
OKBLUE = '\033[94m'
PRT_ENDC = '\033[0m'
def greeting():
print OKBLUE + "Welcome to use pyScheme, it's just a simple project for learning how an interpreter works."
print "I'm Amin By, from China. Here's my homepage: http://aminby.net"
print PRT_ENDC
def helping():
print "the messages for help, it may be a long text."
def goodbye():
print OKBLUE + "Thank you for using pyScheme. Bye!", PRT_ENDC
print
if __name__ == '__main__':
greeting()
psr = SParser()
while True:
code = raw_input("pySchm> ").strip()
if code in ('help', 'documents'):
helping()
continue
if code in ('exit', 'quit'):
goodbye()
break
# get expression and evaluate it
expr = psr.parseAsIScheme(code)
try:
if expr:
print 'pySchm>', expr.evaluate()
except Exception, e:
print PRT_FAIL + 'pySchm>', 'error: %s' % e, PRT_ENDC