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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325 | # two array, five and a half function defintions,
# a class definition, and a dream
primes = [2, 3, 5, 7, 11 ,13 ,17, 19]
pounce = ".,;:'" # supports up to 2^65536-1
def barker(numb):
def r(n):
if n < 2: return "0"[:n]
return "0" + "0".join("".join(str(int(d) + 1)
for d in r(e))
for e in bagties(n))
return "".join(pounce[int(c)] for c in r(numb))
def parser(worb):
if len(worb) < 2: return len(worb)
p = 1
worb = worb.split(worb[0])[1:]
for i in range(len(worb)):
try: # lazy
p *= primes[i] ** parser(worb[i])
except IndexError:
p *= eratuto(primes[-1] * 2)[i] ** parser(worb[i])
return p
read_value = lambda x: x if type(x) == int else parser(x)
def eratuto(n):
global primes
primes += [o + 1 for o in range(primes[-1], n)]
i = 0
while i < len(primes) and primes[i] < n ** .5:
for n in primes[i + 1:]:
if n % primes[i] == 0: primes.remove(n)
i += 1
return primes
def bagties(n):
if n > primes[-1]: eratuto(n) # boooo
out = []
for p in primes:
if p > n: return out
c = 0
while n % p == 0:
n /= p
c += 1
out += [c]
return out # booooooo
class YSL:
def __init__(self, bod, gen=0, way=1, stk=[], dic={}, fed=""):
self.bod = bod
self.gen = gen
self.way = way
self.stk = stk.copy()
self.dic = dic.copy()
self.fed = fed
def interpret(self):
pon = -1 if self.way < 0 else 0
going = True
scream = ""
while going:
pon %= len(self.bod)
match self.bod[pon]:
case "+":
if not self.stk: self.stk += [""]
pon = (read_value(self.stk.pop()) - 1) % len(self.bod)
if self.way < 0: pon = len(self.bod) - pon - 1
case "-":
self.way *= -1
pon += self.way
case "*":
if not self.stk: self.stk += [""]
b = self.stk.pop()
if type(b) == int:
raise TypeError(f"Cannot comprehend integer at {barker(
pon)}, level {self.gen}.")
if self.gen:
scream += b
else:
print(b, end="")
pon += self.way
case "/":
b = 0
if self.stk: b = read_value(self.stk[-1])
pon += self.way
if (self.way < 0 and b > 0) or (self.way > 0 and b < 1):
while self.bod[pon % len(self.bod)] != "/":
pon += self.way
pon += self.way
case "&":
pon += self.way
case "|":
pon += self.way
while self.bod[pon % len(self.bod)] != "|":
pon += self.way
pon += self.way
case "=":
going = False
case "(":
if self.way < 0:
raise SyntaxError(f"Mismatched parenthesis at {barker(
pon)}, level {self.gen}.")
pon = (pon + self.way) % len(self.bod)
b, pon = self.find_paren(pon) # has side effects
if b is None: going = False
case ")":
if self.way > 0:
raise SyntaxError(f"Mismatched parenthesis at {barker(
pon)}, level {self.gen}.")
pon = (pon + self.way) % len(self.bod)
b, pon = self.find_paren(pon)
if b is None: going = False
case _:
while self.bod[pon % len(self.bod)] != "&":
pon += self.way
pon += self.way
if self.gen: return scream, self.stk
else: return 0
def find_paren(self, pon):
pon = pon
going = True
inside = False
params = []
present = ""
while going:
pon %= len(self.bod)
if inside:
if self.bod[pon] == "&":
inside = False
params += [present]
present = ""
else:
present += self.bod[pon]
pon += self.way
else:
match self.bod[pon]:
case "+":
if not self.stk: self.stk += [""]
b = self.stk.pop()
params += [b]
pon = (read_value(b) - 1) % len(self.bod)
if self.way < 0: pon = len(self.bod) - pon - 1
case "-":
params += [""]
self.way *= -1
pon += self.way
case "*":
if not self.stk: self.stk += [""]
params += [self.stk.pop()]
pon += self.way
case "/":
b = ""
if self.stk: b = self.stk[-1]
params += [b]
pon += self.way
if ((self.way < 0 and read_value(b) > 0)
or (self.way > 0 and read_value(b) < 1)):
while self.bod[pon % len(self.bod)] != "/":
pon += self.way
pon += self.way
case "&":
params += [""]
pon += self.way
case "|":
if self.way < 0:
params += [len(self.bod) - pon]
else:
params += [pon + 1]
pon += self.way
while self.bod[pon % len(self.bod)] != "|":
pon += self.way
pon += self.way
case "=":
return None, 0
case "(":
pon += self.way
if self.way > 0:
b, pon = self.find_paren(pon)
params += [b]
else:
going = False
case ")":
pon += self.way
if self.way < 0:
b, pon = self.find_paren(pon)
params += [b]
else:
going = False
case _:
inside = True
match params:
case []:
if self.gen:
return self.fed, pon
else:
b = input() # unfortunate limitation of my means
b = "\t".join(b.split("\\t"))
b = "\n".join(b.split("\\n"))
return b, pon
case [one]:
while one in self.dic:
one = self.dic[one]
self.stk += [one]
return one, pon
case [one, two]:
while one in self.dic:
one = self.dic[one]
while two in self.dic:
two = self.dic[two]
s = read_value(one) - 1
if s < 0: s += len(self.bod)
e = read_value(two) - 1
if e < 0: e += len(self.bod)
suede = self.bod[::self.way]
sxtra = 0
extra = 0
if s < e:
while s < 0:
sxtra += 1
s += len(self.bod)
while e > len(self.bod) - 1:
extra += 1
e -= len(self.bod)
if sxtra or extra:
b = suede[s:] + suede * (sxtra + extra - 1) + suede[:e + 1]
else:
b = suede[s:e + 1]
if s > e:
while s > len(self.bod) - 1:
sxtra += 1
s -= len(self.bod)
while e < 0:
extra += 1
e += len(self.bod)
if sxtra or extra:
b = suede[e:] + suede * (sxtra + extra - 1) + suede[:s + 1]
else:
b = suede[e:s + 1]
b = b[::-1]
if s == e:
b = suede[min(s, e)]
return b, pon
case [head, one, two]:
while one in self.dic:
one = self.dic[one]
while two in self.dic:
two = self.dic[two]
match head:
case "ame":
return read_value(one) + read_value(two), pon
case "dom":
return read_value(one) - read_value(two), pon
case "tim":
return read_value(one) * read_value(two), pon
case "spa":
if read_value(two):
return read_value(one) // read_value(two), pon
else:
return "", pon
case "wal":
if type(one) == int:
raise TypeError(f"Cannot comprehend integer at {barker(
pon)}, level {self.gen}.")
baby = YSL(one, self.gen + 1, self.way, self.stk, self.dic, two)
b, t = baby.interpret()
del baby
self.stk = t
return b, pon
case "suc":
# still a mess
# does not cross program edge, so I.P. can be decided
if type(one) == int or type(two) == int:
raise TypeError(f"Cannot comprehend integer at {barker(
pon)}, level {self.gen}.")
if one == two:
return "", pon
first = (self.bod[:pon + 1] if self.way < 0
else self.bod[pon:])[::self.way]
lirst = (self.bod[pon + 1:] if self.way < 0
else self.bod[:pon])[::self.way]
suede = lirst + first
if not one:
self.bod = (lirst + two + first)[::self.way]
if self.way < 0: pon += len(two)
return "", pon
if one in first:
b = first.index(one)
first = first[:b] + two + first[b + len(one):]
self.bod = (lirst + first)[::self.way]
if self.way < 0: pon += len(two) - len(one)
return one, pon
if one in suede:
b = suede.index(one)
suede = suede[:b] + two + suede[b + len(one):]
self.bod = suede[::self.way]
if self.way > 0: pon += len(two) - len(one)
return one, pon
return "", pon
case "dit":
return (two if one == two else ""), pon
case _:
if one == "":
self.dic[head] = two
return two, pon
if two == "":
self.dic[head] = one
return one, pon
if type(one) == int or type(two) == int:
raise TypeError(f"Cannot comprehend integer at {barker(
pon)}, level {self.gen}.")
self.dic[head] = one + two
return one + two, pon
case _:
raise SyntaxError(f"Too many parameters at {barker(
pon)}, level {self.gen}.")
if __name__ == "__main__":
with open("lass.ysl") as prog:
lass = YSL(prog.read())
lass.interpret()
|
post a comment