f | import re | f | import re |
n | | n | |
| reVar = re.compile(r"[A-Za-z_]\w*$") | | reVar = re.compile(r"[A-Za-z_]\w*$") |
| reNam = re.compile(r"([A-Za-z_]\w*)") | | reNam = re.compile(r"([A-Za-z_]\w*)") |
| reVal = re.compile(r"[\w()%/+*-]+$") | | reVal = re.compile(r"[\w()%/+*-]+$") |
| reInv = re.compile(r"(?:\b\d+[A-Za-z_])|(?://)|(?:\*\*)|(?:\w\()") | | reInv = re.compile(r"(?:\b\d+[A-Za-z_])|(?://)|(?:\*\*)|(?:\w\()") |
| SUF = "V_" | | SUF = "V_" |
| Var = {} | | Var = {} |
| | | |
| | | |
| def calc(s, Var): | | def calc(s, Var): |
| if s.startswith("#"): | | if s.startswith("#"): |
| return | | return |
| *V, H = s.split("=") | | *V, H = s.split("=") |
| if len(V) > 1: | | if len(V) > 1: |
| return "Syntax" | | return "Syntax" |
n | | n | |
| if V and not reVar.match(V[0]): | | if V and not reVar.match(V[0]): |
| return "Assignment" | | return "Assignment" |
n | | n | |
| if all((H, reVal.match(H), not reInv.search(H))): | | if all((H, reVal.match(H), not reInv.search(H))): |
| try: | | try: |
| Hr = reNam.sub(rf"{SUF}\1", H).replace("/", "//") | | Hr = reNam.sub(rf"{SUF}\1", H).replace("/", "//") |
| R = eval(Hr, {'__builtins__': {}}, Var) | | R = eval(Hr, {'__builtins__': {}}, Var) |
| except NameError as E: | | except NameError as E: |
| return "Name" | | return "Name" |
| except Exception as E: | | except Exception as E: |
| return "Runtime" | | return "Runtime" |
| else: | | else: |
| if not isinstance(R, int): | | if not isinstance(R, int): |
| return "Syntax" | | return "Syntax" |
| else: | | else: |
| return "Syntax" | | return "Syntax" |
t | | t | |
| if V: | | if V: |
| Var[SUF+V[0]] = R | | Var[SUF+V[0]] = R |
| else: | | else: |
| return R | | return R |
| | | |
| | | |
| s = input().strip().replace(' ', '') | | s = input().strip().replace(' ', '') |
| while s: | | while s: |
| R = calc(s, Var) | | R = calc(s, Var) |
| if R is not None: | | if R is not None: |
| print(R if isinstance(R, int) else f"{R} error") | | print(R if isinstance(R, int) else f"{R} error") |
| s = input().strip().replace(' ', '') | | s = input().strip().replace(' ', '') |
| | | |