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