-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.py
101 lines (89 loc) · 2.01 KB
/
test.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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
from s1_lexer import *
from s1_parser import *
text = '''nextNumber(num) {
return num + [num];
}
addNumbers(num1, num2) {
ans = num1;
countNum2 = [];
whilene (countNum2 ~ num2) {
countNum2 = nextNumber(countNum2);
ans = nextNumber(ans);
}
return ans;
}
multiplyNumbers(num1, num2) {
ans = [];
countNum2 = [];
whilene (countNum2 ~ num2) {
countNum2 = nextNumber(countNum2);
ans = addNumbers(ans, num1);
}
return ans;
}
test1(a, b) {
return;
}
test2(c) {
}
alpha = [];
beta = [];
beta = addNumbers(alpha, nextNumber(alpha));
gamma = beta;
test1(alpha, beta);
test2(beta);
'''
lexer = Lexer(text)
next_token = lexer.get_next_token()
while next_token.type != 'EOF':
#print(next_token)
next_token = lexer.get_next_token()
lexer.pos = 0
parser = Parser(lexer)
parsed = parser.parse()
#print(parsed)
'''nextNumber(num) {
return num + [num];
}
addNumbers(num1, num2) {
ans = num1;
countNum2 = [];
whilene (countNum2 ~ num2) {
countNum2 = nextNumber(countNum2);
ans = nextNumber(ans);
}
return ans;
}
multiplyNumbers(num1, num2) {
ans = [];
countNum2 = [];
whilene (countNum2 ~ num2) {
countNum2 = nextNumber(countNum2);
ans = addNumbers(ans, num1);
}
return ans;
}'''
'''
0: JumpOp(1, 1000, 1000)
1: something // num
2: ClearOp(3)
3: something
4: AddOp(1, 3) // make 3 = [num]
5: something
6: BinOp(+, 1, 4, 5) // make 5 = num + [num]
7: something // num1
8: something // ans
9: MovOp(7, 8) // make ans = num1
10: something // countNum2
11: ClearOp(10) // countNum2 = []
12: something
13: something // num2
14: BinOp(~, 10, 13, 12) // 12 = countNum2 ~ num2
15: JumpOp(12, 22, 16)
16: nextNumber(10) // ?????????
17: MovOp(16, 11) // countNum2 = nextNumber(counNum2)
18: nextNumber(8) // ??????????
19: MovOp(18, 8) // ans = nextNumber(ans)
20: BinOp(~, 10, 13, 12)
21: JumpOp(12, 22, 16)
'''