-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsemantic_cube.py
81 lines (79 loc) · 2.5 KB
/
semantic_cube.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
types = {
"int": "Int",
"float": "Float",
"string": "String",
"bool": "Bool"
}
class semantic_cube():
sem_cube = {
# Integer Values
"+#ii": types["int"],
"-#ii": types["int"],
"*#ii": types["int"],
"/#ii": types["int"],
"==#ii": types["bool"],
"=#ii": types["int"],
">#ii": types["bool"],
"<#ii": types["bool"],
">=#ii": types["bool"],
"<=#ii": types["bool"],
"!=#ii": types["bool"],
# Int and Float Values
"+#if": types["float"],
"-#if": types["float"],
"*#if": types["float"],
"/#if": types["float"],
"==#if": types["bool"],
"=#if" : types["int"],
">#if": types["bool"],
"<#if": types["bool"],
">=#if": types["bool"],
"<=#if": types["bool"],
"!=#if": types["bool"],
# Float and Int Values
"+#fi": types["float"],
"-#fi": types["float"],
"*#fi": types["float"],
"/#fi": types["float"],
"==#fi": types["bool"],
"=#fi" : types["float"],
">#fi": types["bool"],
"<#fi": types["bool"],
">=#fi": types["bool"],
"<=#fi": types["bool"],
"!=#fi": types["bool"],
# Float Values
"+#ff": types["float"],
"-#ff": types["float"],
"*#ff": types["float"],
"/#ff": types["float"],
"==#ff": types["bool"],
"=#ff" : types["float"],
">#ff": types["bool"],
"<#ff": types["bool"],
">=#ff": types["bool"],
"<=#ff": types["bool"],
"!=#ff": types["bool"],
# String values
"+#ss": types["string"],
"==#ss": types["bool"],
"=#ss" : types["string"],
"!=#ss": types["bool"],
# Boolean Values
"==#bb": types["bool"],
"=#bb" : types["bool"],
"&&#bb": types["bool"],
"||#bb": types["bool"],
"!=#bb": types["bool"],
}
# We use to get our format so that we can use it later to validate the expression
def format_expression(self, left_op, right_op, operator):
return operator + "#" + left_op[0] + right_op[0]
# We use this to validate the expresion between two operands
def validate_expression(self, left_op, right_op, operator):
formatted_exp = self.format_expression(left_op,right_op,operator)
#print(formatted_exp)
if formatted_exp in self.sem_cube.keys():
return self.sem_cube[formatted_exp]
else:
return "ERROR"