-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
52 lines (46 loc) · 1.52 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
import re
conversion_table: dict = {
"⓪": "0",
"①": "1",
"②": "2",
"③": "3",
"④": "4",
"⑤": "5",
"⑥": "6",
"⑦": "7",
"⑧": "8",
"⑨": "9",
"➕": "+",
"➖": "-",
"❌": "*",
"➗": "/",
"㌫": "%",
" ": " ",
"《": "(",
"》": ")",
"“": '"',
}
def replacement(match):
return conversion_table[match.group(0)]
def transpile(source: str, conversion_table: dict) -> str:
result: str = ""
for char in source:
if char in conversion_table.keys():
result += conversion_table[char]
else:
result += char
return result
def convert(source: str) -> str:
return transpile(source, {value: key for key, value in conversion_table.items()})
def check_error(source: str):
if len(re.findall("[1-9]", source)) != 0:
raise SyntaxError("It's not allowed use normal number character. Instead, you can use only circle number character as number expression.")
if len(re.findall(r"\+|\-|\*|\/|\%", source)) != 0:
raise SyntaxError("It's not allowed use normal operator character. Instead, you can use only decorated operator character as operator expression.")
if len(re.findall(r"[a-z]|[A-Z]", source)) != 0:
raise SyntaxError("It's not allowed use normal alphabets character. Instead, you can use cute pictograph")
print("⑨ hard to input esolang calculator")
while True:
code = input("> ")
check_error(code)
print(convert(str(eval(transpile(code, conversion_table)))))