-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDriver.py
More file actions
57 lines (53 loc) · 1.46 KB
/
Driver.py
File metadata and controls
57 lines (53 loc) · 1.46 KB
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
51
52
53
54
55
56
57
from IntLit import *
from Var import *
from ValueExpression import *
from Helpers import *
import os, sys
def walk(root):
for child in os.listdir(root):
fullpath = root + '/' + child
if isDefinition(child):
print(Definition(fullpath))
expressions = os.listdir(root)
expressions.sort()
for child in expressions:
if child.isalpha():
fullpath = root + '/' + child
child = os.listdir(fullpath)[0]
fullpath = fullpath + '/' + child
if isIntLit(child):
code = str(IntLit(fullpath))
print('print("> ' + code + '")')
print('print(' + code + ')')
elif isValueExpression(child):
code = str(ValueExpression(fullpath))
print('print("> ' + code + '")')
print('print(' + code + ')')
elif isFuncCall(child):
code = str(FuncCall(fullpath))
print('print("> ' + code + '")')
print('print(' + code + ')')
elif isLambda(child):
l = Lambda(fullpath)
code = str(l)
print('print("> ' + code + '")')
if l.isCall:
print('print(' + code + ')')
def makeStdLib():
print('count = len')
print('def join(l1, l2): return l1 + l2')
print('def part(l, i, j): return l[i:j]')
print('def first(l): return l[0]')
print('def last(l): return l[-1]')
print('def tail(l): return l[1:]')
print('def map(f, l): return [f(e) for e in l]')
def main():
if len(sys.argv) != 2:
print('usage: ' + argv[0] + ' <program directory>')
return -1
root = sys.argv[1]
makeStdLib()
walk(root)
return 0
if __name__ == "__main__":
main()