This repository has been archived by the owner on Feb 19, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
77 lines (67 loc) · 2.54 KB
/
main.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
import sys
import re
import math
import datetime
YEAR = datetime.datetime.now().date().year
def ifstmnt():
pass
def polish(line: str):
if 'the square root of ' in line:
lst = list(line.replace('the square root of ', "math.sqrt("))
lst.append(')')
line = ''.join(lst)
return line.replace("divided by", '/'
).replace('times', '*'
).replace('multiplied by', '*'
).replace('to the power of', '**'
).replace('plus', '+'
).replace('minus', '-'
).replace('the value of ', ''
).replace('this year', str(YEAR))
def main(file_lines: list):
for count, line in enumerate(file_lines):
dd = -0
po = polish(line)
if "if value of " in po and " is " in po:
ifstmnt()
elif 'convert' in po:
diction = {
'number': 'int(',
'decimal': 'float(',
'text': 'str('
}
prelist = po.replace('convert ', '').replace('to', '')
for i in diction.keys():
prelist = prelist.replace(i, diction[i])
lst = list(prelist)
if lst[-1] == '\n':
lst.pop(-1)
jj = ((''.join(lst)).replace('int(', '').replace('float(', '').replace('str(', '')).strip()
fin = (''.join(lst)).replace(jj, '')
exec(jj + '=' + fin.lstrip() + jj + ')')
elif "set value of " in po and " to " in po:
po = po.replace("set value of ", "").replace(" to ", "=")
dd = 1
elif "output " in po:
# noinspection PyUnboundLocalVariable
if lst[-1] == '\n':
lst.pop(-1)
lst = list(po.replace("output ", "print("))
lst.append(')')
exec(''.join(lst))
continue
if 'input from user with prompt of ' in line:
lst = list(po.replace('input from user with prompt of ', 'input("'))
if lst[-1] == '\n':
lst.pop(-1)
lst.append('"')
lst.append(')')
exec(''.join(lst))
elif dd ==1:
exec(po)
def stuff():
pass
if len(sys.argv) == 2:
main(open(sys.argv[1]).readlines())
else:
stuff(sys.argv)