-
Notifications
You must be signed in to change notification settings - Fork 0
/
bool0.py
executable file
·144 lines (116 loc) · 4.01 KB
/
bool0.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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
from Value_Assigning import*
from MyExceptions import *
from arith import *
from Value_Assigning import *
PI=3.14159
pi=3.14159
e=2.71828
class bool:
def check(self,inp): #This function will check if a==b is true or not
self.inp=inp
ind=self.inp.find('==') # checking if '==' is there and dividing the strings before and after it
str1=self.inp[:ind]
str2=self.inp[ind+2:]
while str1[-1] is " ":
str1=str1[:-1]
while str2[0] is " ":
str2=str2[1:]
if str1 in var_names.keys():
if str2 in var_names.keys():
if var_names[str1]==var_names[str2]: # if both strings are equal returns True
return True
else:
return False
else:
raise invalid_variable # checking if variable is valid
else:
raise invalid_variable
class increment: #This class will define a+=2 as a=a+2
def check(self,inp):
self.inp=inp
ind=self.inp.find('+=') #checking if there is any "+=" in the input
str1=self.inp[:ind]
str2=self.inp[ind+2:]
while str1[-1] is " ": #removing spaces
str1=str1[:-1]
while str2[0] is " ":
str2=str2[1:]
if str1 in var_names.keys():
a=preparing_arithmetic()
self.inp=a.insert_spaces(str1+'+'+str2) #Now an arthimatic expression will be created with spaces required
errors(self.inp)
a=variable_names() #checking for errors in variable names
self.command=a.names(self.inp)
a=solving()
var_names[str1]=a.postfix(self.inp) # passing newly constucted sting to postfix expression
else:
raise invalid_variable
class decrement: #This class will define a-=2 as a=a-2
def check(self,inp):
self.inp=inp
ind=self.inp.find('-=') #checking if there is any "-=" in the input
str1=self.inp[:ind]
str2=self.inp[ind+2:]
while str1[-1] is " ": #removing spaces
str1=str1[:-1]
while str2[0] is " ":
str2=str2[1:]
if str1 in var_names.keys():
a=preparing_arithmetic()
self.inp=a.insert_spaces(str1+'-'+str2) #Now an arthematic expression will be created with spaces required
errors(self.inp)
a=variable_names() #checking for errors in variable names
self.command=a.names(self.inp)
a=solving()
var_names[str1]=a.postfix(self.inp) # passing newly constucted sting to postfix expression
else:
raise invalid_variable
class multiply: #This class will define a*=2 as a=a*2
def check(self,inp):
self.inp=inp
ind=self.inp.find('*=') #checking if there is any "*=" in the input
str1=self.inp[:ind]
str2=self.inp[ind+2:]
while str1[-1] is " ": #removing spaces
str1=str1[:-1]
while str2[0] is " ":
str2=str2[1:]
if str1 in var_names.keys():
a=preparing_arithmetic()
self.inp=a.insert_spaces(str1+'*'+str2) #Now an arthimatic expression will be created with spaces required
errors(self.inp)
a=variable_names() #checking for errors in variable names
self.command=a.names(self.inp)
a=solving()
var_names[str1]=a.postfix(self.inp) # passing newly constucted string to postfix expression
else:
raise invalid_variable
class divide: #This class will define a/=2 as a=a/2
def check(self,inp):
self.inp=inp
ind=self.inp.find('/=') #checking if there is any "/=" in the input
str1=self.inp[:ind]
str2=self.inp[ind+2:]
while str1[-1] is " ": #removing spaces
str1=str1[:-1]
while str2[0] is " ":
str2=str2[1:]
if str1 in var_names.keys():
a=preparing_arithmetic()
self.inp=a.insert_spaces(str1+'/'+str2) #Now an arthimatic expression will be created with spaces required
errors(self.inp)
a=variable_names() #checking for errors in variable names
self.command=a.names(self.inp)
a=solving()
var_names[str1]=a.postfix(self.inp) # passing newly constucted sting to postfix expression
else:
raise invalid_variable
class var:
def check(self,inp):
self.inp=inp
while self.inp[-1] is " ":
self.inp=self.inp[:-1]
if self.inp in var_names.keys():
return var_names[self.inp]
else:
raise invalid_variable