-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSemanticCube.py
More file actions
71 lines (59 loc) · 1.57 KB
/
SemanticCube.py
File metadata and controls
71 lines (59 loc) · 1.57 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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
from collections import defaultdict
operMap = {
'+' : 0,
'-' : 1,
'*' : 2,
'/' : 3,
'%' : 4,
'=' : 5,
'<' : 6,
'>' : 7,
'<=' : 8,
'>=' : 9,
'!=' : 10,
'==' : 11,
'&&' : 12,
'||' : 13,
'console' : 14,
'+*' : 15}
#Additional
semanticCube = {}
# Return -1 if not possible
semanticCube = defaultdict(lambda: -1, semanticCube)
# Aritmetic
# int _ int : _
# float _ float : _
# int _ float : _
# float _ int : _
for i in range(0,4):
semanticCube[i,0,0] = 0
semanticCube[i,1,1] = 1
semanticCube[i,0,1] = 1
semanticCube[i,1,0] = 1
semanticCube[15,0,0] = 0
# = a a : a
for i in range(0,4):
semanticCube[5, i, i] = i
# = int float: int
semanticCube[5, 0, 1] = 0
semanticCube[5, 1, 0] = 1
# % is always integer
semanticCube[4,0,0] = 0
semanticCube[4,1,1] = 0
semanticCube[4,0,1] = 0
semanticCube[4,1,0] = 0
# "string1" + "string2" = "string1string2"
semanticCube[0,2,2] = 2
#Comparison
# int|float_int|float = bool
for i in range(0,2):
for j in range(0,2):
for k in range(6,12):
semanticCube[k,i,j] = 3
for k in range(6,12):
semanticCube[k,2,2] = 3
#HigherExpression
for i in range(12,14):
semanticCube[i,3,3] = 3
def SearchSemanticCube(operator, operandOne, operandTwo):
return semanticCube[operMap[operator], operandOne, operandTwo];