-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSemanticCube.py
More file actions
96 lines (86 loc) · 2.78 KB
/
SemanticCube.py
File metadata and controls
96 lines (86 loc) · 2.78 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
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
import sys
#OPERATORS
aritmetic = ['+', '-', '*']
aritmeticcomplex = ['pi','%', '/','^']
relational = ['==', '!=', '>', '<', '>=', '<=']
logical = ['&&', '||']
equal = ['=','parametro','return']
#Missing operators
class Operators:
def __init__(self):
self.operator = {
'aritmetic' : {
'sumres': ['+','-'],
'muldiv': ['*','/'],
},
'math' : ['pi','%'],
'relational' : ['==', '!=', '>', '<', '>=', '<='],
'equal' : ['=','parametro'],
'logical' : ['&&', '||']
}
def semantic(left, right, operator):
#CHECAR CASO DEL NOT ANTES QUE CUALQUIER OTRA COMPARACIÓN
#if(right=='bool'):
# if (operator=='!'):
# return bool
if(left == 'int'):
if(right == 'int'):
if(operator in aritmetic or operator in equal):
return 'int'
elif(operator in aritmeticcomplex):
return 'int'
elif(operator in relational):
return 'bool'
else:
return 'errorbadop'
elif(right == 'float'):
if(operator in aritmetic or operator in aritmeticcomplex):
return 'float'
elif(operator in relational):
return 'bool'
else:
return 'errorbadop'
else:
return 'errorbadop'
elif(left == 'float'):
if(right == 'float'):
if(operator in aritmetic or operator in aritmeticcomplex or operator in equal):
return 'float'
elif(operator in relational):
return 'bool'
else:
return 'errorbadop'
elif(right == 'int'):
if(operator in aritmetic or operator in aritmeticcomplex):
return 'float'
elif(operator in relational):
return 'bool'
else:
return 'errorbadop'
else:
return 'errorbadop'
elif(left == 'string'):
if(right == 'string'):
if(operator in equal):
return 'string'
elif(operator == '==' or operator == '!='):
return 'bool'
elif(operator == '+'):
return 'string'
else:
return 'errorbadop'
elif(right == 'int' or right == 'float'):
if(operator == '+'):
return 'string'
else:
return 'errorbadop'
else:
return 'errorbadop'
elif(left == 'bool'):
if(right == 'bool'):
if(operator in relational or operator in logical or operator in equal):
return 'bool'
else:
return 'errorbadop'
else:
return 'errorbadop'