BoldCalc/Stephan
BoldCalc/yervandsargsyan
f1import ref1import re
n2 n
3reVar = re.compile(r"[A-Za-z_]\w*$")2reVar = re.compile(r"[A-Za-z_]\w*$")
4reNam = re.compile(r"([A-Za-z_]\w*)")3reNam = re.compile(r"([A-Za-z_]\w*)")
5reVal = re.compile(r"[\w()%/+*-]+$")4reVal = re.compile(r"[\w()%/+*-]+$")
6reInv = re.compile(r"(?:\b\d+[A-Za-z_])|(?://)|(?:\*\*)|(?:\w\()")5reInv = re.compile(r"(?:\b\d+[A-Za-z_])|(?://)|(?:\*\*)|(?:\w\()")
7SUF = "V_"6SUF = "V_"
8Var = {}7Var = {}
98
109
11def calc(s, Var):10def calc(s, Var):
12    if s.startswith("#"):11    if s.startswith("#"):
13        return12        return
14    *V, H = s.split("=")13    *V, H = s.split("=")
15    if len(V) > 1:14    if len(V) > 1:
16        return "Syntax"15        return "Syntax"
n17 n
18    if V and not reVar.match(V[0]):16    if V and not reVar.match(V[0]):
19        return "Assignment"17        return "Assignment"
n20 n
21    if all((H, reVal.match(H), not reInv.search(H))):18    if all((H, reVal.match(H), not reInv.search(H))):
22        try:19        try:
23            Hr = reNam.sub(rf"{SUF}\1", H).replace("/", "//")20            Hr = reNam.sub(rf"{SUF}\1", H).replace("/", "//")
24            R = eval(Hr, {'__builtins__': {}}, Var)21            R = eval(Hr, {'__builtins__': {}}, Var)
25        except NameError as E:22        except NameError as E:
26            return "Name"23            return "Name"
27        except Exception as E:24        except Exception as E:
28            return "Runtime"25            return "Runtime"
29        else:26        else:
30            if not isinstance(R, int):27            if not isinstance(R, int):
31                return "Syntax"28                return "Syntax"
32    else:29    else:
33        return "Syntax"30        return "Syntax"
t34 t
35    if V:31    if V:
36        Var[SUF+V[0]] = R32        Var[SUF+V[0]] = R
37    else:33    else:
38        return R34        return R
3935
4036
41s = input().strip().replace(' ', '')37s = input().strip().replace(' ', '')
42while s:38while s:
43    R = calc(s, Var)39    R = calc(s, Var)
44    if R is not None:40    if R is not None:
45        print(R if isinstance(R, int) else f"{R} error")41        print(R if isinstance(R, int) else f"{R} error")
46    s = input().strip().replace(' ', '')42    s = input().strip().replace(' ', '')
4743
Legends
Colors
 Added 
Changed
Deleted
Links
(f)irst change
(n)ext change
(t)op