-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSemanticCube.py
102 lines (93 loc) · 6.32 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
# ----------------------------------------------------------- #
# ____ _____ _ #
# / __ \ | __ \ (_) #
# | | | |_ __ ___ _ __ | |__) |___ ___ _ __ _ ___ #
# | | | | '_ \ / _ \ '_ \ | _ // _ \ / _ \| '_ \| |/ _ \ #
# | |__| | |_) | __/ | | | | | \ \ (_) | (_) | | | | | __/ #
# \____/| .__/ \___|_| |_| |_| \_\___/ \___/|_| |_|_|\___| #
# | | #
# |_| #
# #
# Antonio Carlos Vargas Torres A00813182 #
# Rubén Eugenio Cantu Vota A00814298 #
# ----------------------------------------------------------- #
import Enums as Enums
class SemanticCubeClass:
def __init__(self):
self.Enums = Enums.Enums().Instance
self.DataTypes = self.Enums.DataTypes
self.Operations = self.Enums.Operations
self.initCube()
def initCube(self):
# int
# + - * / > < >= <= <> == | & =
self.Cube = [[[ 0, 0, 0, 0, 3, 3, 3, 3, 3, 3, -1, -1, 0], # int
[ 1, 1, 1, 1, 3, 3, 3, 3, 3, 3, -1, -1, 1], # float
[-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1], # char
[-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1], # bool
[-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1], # string
[-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1]], # void
# float
# + - * / > < >= <= <> == | & =
[[ 1, 1, 1, 1, 3, 3, 3, 3, 3, 3, -1, -1, -1], # int
[ 1, 1, 1, 1, 3, 3, 3, 3, 3, 3, -1, -1, 1], # float
[-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1], # char
[-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1], # bool
[-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1], # string
[-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1]], # void
# char
# + - * / > < >= <= <> == | & =
[[-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1], # int
[-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1], # float
[-1, -1, -1, -1, -1, -1, -1, -1, 3, 3, -1, -1, 2], # char
[-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1], # bool
[-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1], # string
[-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1]], # void
# bool
# + - * / > < >= <= <> == | & =
[[-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1], # int
[-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1], # float
[-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1], # char
[-1, -1, -1, -1, -1, -1, -1, -1, 3, 3, 3, 3, 3], # bool
[-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1], # string
[-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1]], # void
# string
# + - * / > < >= <= <> == | & =
[[-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1], # int
[-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1], # float
[-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1], # char
[-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1], # bool
[-1, -1, -1, -1, -1, -1, -1, -1, 3, 3, -1, -1, 4], # string
[-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1]], # void
# void
# + - * / > < >= <= <> == | & =
[[-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1], # int
[-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1], # float
[-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1], # char
[-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1], # bool
[-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1], # string
[-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1]]] # void
return True
def getResultingType(self, tipo1, tipo2, operacion):
try:
IndexTipo1 = self.DataTypes[tipo1]
IndexTipo2 = self.DataTypes[tipo2]
IndexOperacion = self.Operations[operacion]
except ValueError:
IndexTipo1 = -1
IndexTipo2 = -1
IndexOperacion = -1
if IndexTipo1 > -1 and IndexTipo2 > -1 and IndexOperacion > -1 and IndexOperacion <= len(self.Cube[0][0]):
ResType = self.Cube[IndexTipo1][IndexTipo2][IndexOperacion]
if ResType < 0 :
print("\nERROR TYPE MISMATCH. Los tipos:", tipo1, "y", tipo2, "no son compatibles con la operacion:", operacion)
return None
else :
return list(self.DataTypes.keys())[list(self.DataTypes.values()).index(ResType)]
else :
print("\nERROR. Tipos de datos:", tipo1, ",", tipo2, "y/o operacion:", operacion, "desconocidos")
return None
class SemanticCube:
Instance = SemanticCubeClass()
def __init__(self):
pass