-
Notifications
You must be signed in to change notification settings - Fork 1
/
skeedgescript.py
91 lines (82 loc) · 2.83 KB
/
skeedgescript.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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
# ================================================================================>
# FILE NAME: skeedgescript.py
#
# PURPOSE:
# SkeedgeScript interpreter written in Python 3.
#
# CREATED DATE: 2022-05-29
# AUTHOR: @hedgenull (hedgefleming@gmail.com)
# ================================================================================>
import argparse
ACCUMULATOR = 0
def interpret(i: str, is_file: bool = False):
"""Interpret SkeedgeScript code."""
global ACCUMULATOR
tokens = i.split()
for o, t in enumerate(tokens):
match t:
case "skeedge":
ACCUMULATOR = 0
case "SKEEDGE":
ACCUMULATOR = 1
case "Skeedge":
ACCUMULATOR += 1
case "skeedgE":
ACCUMULATOR -= 1
case "SKeedge":
ACCUMULATOR += 2
case "skeedGE":
ACCUMULATOR -= 2
case "skeedGe":
ACCUMULATOR = +ACCUMULATOR
case "skeEdge":
print(ACCUMULATOR)
case "SKEeDGE":
print(chr(ACCUMULATOR), end="") if is_file else print(chr(ACCUMULATOR))
case "SkeedgE":
if tokens[o + 1].isdigit():
ACCUMULATOR += int(tokens[o + 1])
case "sKEEDGe":
if tokens[o + 1].isdigit():
ACCUMULATOR -= int(tokens[o + 1])
case "SkEeDgE":
if tokens[o + 1].isdigit():
ACCUMULATOR = int(tokens[o + 1])
case "sKeEdGe":
i = input("")
if i.isdigit():
ACCUMULATOR = int(i)
else:
ACCUMULATOR = ord(i[0])
case "sKeedGe":
if ACCUMULATOR > 0:
ACCUMULATOR = 0
else:
ACCUMULATOR = 1
case "SkEEDgE":
if ACCUMULATOR > 0:
ACCUMULATOR = 1
else:
ACCUMULATOR = 0
case _ as err:
if not is_file:
print(f"Error: Unknown command '{err}'")
if __name__ == "__main__":
ap = argparse.ArgumentParser(description="SkeedgeScript interpreter written in Python")
ap.add_argument("-f", "--file", help="Path to SkeedgeScript source file")
ap.add_argument(
"-i", "--interactive", action="store_true", help="Enable interactive shell mode"
)
args = ap.parse_args()
if args.interactive:
while True:
i = input("SkeedgeScript > ").strip()
interpret(i)
elif args.file:
try:
with open(args.file, "r") as f:
code = f.read()
except FileNotFoundError:
print(f"File not found: {args.file}")
else:
interpret(code, is_file=True)