-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsemanticCube.py
116 lines (111 loc) · 2.02 KB
/
semanticCube.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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
from collections import defaultdict
# Dual-operand type matching cube
dual_cube = {
'int': {
'int': {
'=': 'int',
'+': 'int',
'-': 'int',
'*': 'int',
'/': 'int',
'%': 'int',
'.': 'int',
'<': 'bool',
'<=': 'bool',
'>': 'bool',
'>=': 'bool',
'==': 'bool',
'!=': 'bool'
},
'float': {
'+': 'float',
'-': 'float',
'*': 'float',
'/': 'float',
'.': 'float',
'<': 'bool',
'<=': 'bool',
'>': 'bool',
'>=': 'bool',
'==': 'bool',
'!=': 'bool'
}
},
'float': {
'int': {
'=': 'float',
'+': 'float',
'-': 'float',
'*': 'float',
'/': 'float',
'.': 'float',
'<': 'bool',
'<=': 'bool',
'>': 'bool',
'>=': 'bool',
'==': 'bool',
'!=': 'bool'
},
'float': {
'=': 'float',
'+': 'float',
'-': 'float',
'*': 'float',
'/': 'float',
'.': 'float',
'<': 'bool',
'<=': 'bool',
'>': 'bool',
'>=': 'bool',
'==': 'bool',
'!=': 'bool'
}
},
'char': {
'char': {
'=': 'char',
'==': 'bool',
'!=': 'bool'
}
},
'bool': {
'bool': {
'=': 'bool',
'&': 'bool',
'|': 'bool',
'==': 'bool',
'!=': 'bool'
}
}
}
# Single-operand type matching table
mono_table = {
'int': {
'$': 'int',
'!': 'int',
'?': 'float'
},
'float': {
'$': 'float',
'!': 'float',
'?': 'float'
},
'char': {
'!': 'char'
},
'bool': {
'!': 'bool'
}
}
# Returns result type of a dual-operand operation
def getDuoResultType(left_type, right_type, operator):
try: # Return type from dual_cube
return dual_cube[left_type][right_type][operator]
except: # If no entry exists for combination, return None
return None
# Returns result type of a mono-operand operation
def getMonoResultType(vartype, operator):
try:
return mono_table[vartype][operator]
except:
return None