uf-language 1.0.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,8 @@
1
+ Metadata-Version: 2.4
2
+ Name: uf-language
3
+ Version: 1.0.0
4
+ Summary: UF Language Engine with 4 modes (UF, iUF, nUF, dnUF)
5
+ Author-email: Intel <you@example.com>
6
+ License: MIT
7
+ Requires-Python: >=3.9
8
+ Description-Content-Type: text/markdown
File without changes
@@ -0,0 +1,19 @@
1
+ # pyproject.toml
2
+ [project]
3
+ name = "uf-language" # Package name for PyPI
4
+ version = "1.0.0" # Version
5
+ description = "UF Language Engine with 4 modes (UF, iUF, nUF, dnUF)"
6
+ readme = "README.md" # README file
7
+ requires-python = ">=3.9" # Python version
8
+ license = { text = "MIT" } # License
9
+ authors = [
10
+ { name = "Intel", email = "you@example.com" }
11
+ ]
12
+ dependencies = [] # No external dependencies
13
+
14
+ [build-system]
15
+ requires = ["setuptools>=61.0", "wheel"]
16
+ build-backend = "setuptools.build_meta"
17
+
18
+ [project.scripts]
19
+ uf = "uf.cli:main" # CLI entry point: typing `uf` in terminal runs your main()
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
@@ -0,0 +1,570 @@
1
+ # uf/UF.py
2
+ import time
3
+ import random
4
+ import os
5
+ import math
6
+ import string
7
+
8
+ # -----------------------------
9
+ # Simple Tokenizer for all modes
10
+ # -----------------------------
11
+ def tokenize(line):
12
+ tokens = []
13
+ current = ""
14
+ in_string = False
15
+ for char in line:
16
+ if char == '"':
17
+ in_string = not in_string
18
+ current += char
19
+ elif char.isspace() and not in_string:
20
+ if current:
21
+ tokens.append(current)
22
+ current = ""
23
+ else:
24
+ current += char
25
+ if current:
26
+ tokens.append(current)
27
+ return tokens
28
+
29
+ # -----------------------------
30
+ # Base Mode Class
31
+ # -----------------------------
32
+ class BaseMode:
33
+ def __init__(self, variables):
34
+ self.variables = variables
35
+
36
+ def execute(self, tokens):
37
+ raise NotImplementedError("Must implement execute method")
38
+
39
+ def show_commands(self):
40
+ raise NotImplementedError("Must implement show_commands method")
41
+
42
+ # -----------------------------
43
+ # UF Mode (User Friendly / 10S)
44
+ # -----------------------------
45
+ class UFMode(BaseMode):
46
+ def show_commands(self):
47
+ print("\n=== UF Commands ===")
48
+ print("hi -> prints hello world")
49
+ print("hip -> prints hi")
50
+ print("hih {text} -> prints your text")
51
+ print("hid {text} {number} -> repeat text")
52
+ print("set {name} {value} -> assign variable")
53
+ print("get {name} -> get variable value")
54
+ print("add {a} {b} -> addition")
55
+ print("sub {a} {b} -> subtraction")
56
+ print("mul {a} {b} -> multiplication")
57
+ print("div {a} {b} -> division")
58
+ print("rand {min} {max} -> random number")
59
+ print("time -> current time")
60
+ print("sleep {seconds} -> pause execution")
61
+ print("upper {text} -> uppercase")
62
+ print("lower {text} -> lowercase")
63
+ print("len {text} -> length of text")
64
+ print("rev {text} -> reverse text")
65
+ print("clear -> clear screen")
66
+ print("rndchar -> random letter")
67
+ print("==================\n")
68
+
69
+ def execute(self, tokens):
70
+ if not tokens:
71
+ return
72
+ cmd = tokens[0].lower()
73
+
74
+ if cmd == "hi":
75
+ print("hello world")
76
+ elif cmd == "hip":
77
+ print("hi")
78
+ elif cmd == "hih":
79
+ if len(tokens) < 2:
80
+ print("Usage: hih {text}")
81
+ else:
82
+ print(" ".join(tokens[1:]))
83
+ elif cmd == "hid":
84
+ if len(tokens) < 3:
85
+ print("Usage: hid {text} {number}")
86
+ else:
87
+ try:
88
+ times = int(tokens[-1])
89
+ text = " ".join(tokens[1:-1])
90
+ for _ in range(times):
91
+ print(text)
92
+ except:
93
+ print("Last value must be a number.")
94
+ elif cmd == "set":
95
+ try:
96
+ self.variables[tokens[1]] = " ".join(tokens[2:])
97
+ print(f"{tokens[1]} = {self.variables[tokens[1]]}")
98
+ except:
99
+ print("Usage: set {name} {value}")
100
+ elif cmd == "get":
101
+ try:
102
+ print(self.variables.get(tokens[1], "Variable not found"))
103
+ except:
104
+ print("Usage: get {name}")
105
+ elif cmd == "add":
106
+ try:
107
+ print(float(tokens[1]) + float(tokens[2]))
108
+ except:
109
+ print("Usage: add {a} {b}")
110
+ elif cmd == "sub":
111
+ try:
112
+ print(float(tokens[1]) - float(tokens[2]))
113
+ except:
114
+ print("Usage: sub {a} {b}")
115
+ elif cmd == "mul":
116
+ try:
117
+ print(float(tokens[1]) * float(tokens[2]))
118
+ except:
119
+ print("Usage: mul {a} {b}")
120
+ elif cmd == "div":
121
+ try:
122
+ print(float(tokens[1]) / float(tokens[2]))
123
+ except:
124
+ print("Usage: div {a} {b}")
125
+ elif cmd == "rand":
126
+ try:
127
+ print(random.randint(int(tokens[1]), int(tokens[2])))
128
+ except:
129
+ print("Usage: rand {min} {max}")
130
+ elif cmd == "time":
131
+ print(time.ctime())
132
+ elif cmd == "sleep":
133
+ try:
134
+ time.sleep(float(tokens[1]))
135
+ except:
136
+ print("Usage: sleep {seconds}")
137
+ elif cmd == "upper":
138
+ print(" ".join(tokens[1:]).upper())
139
+ elif cmd == "lower":
140
+ print(" ".join(tokens[1:]).lower())
141
+ elif cmd == "len":
142
+ print(len(" ".join(tokens[1:])))
143
+ elif cmd == "rev":
144
+ print(" ".join(tokens[1:])[::-1])
145
+ elif cmd == "clear":
146
+ os.system("cls" if os.name == "nt" else "clear")
147
+ elif cmd == "rndchar":
148
+ print(random.choice(string.ascii_letters))
149
+ else:
150
+ print("Unknown UF command.")
151
+
152
+ # -----------------------------
153
+ # iUF Mode (Intermediate / 7S)
154
+ # -----------------------------
155
+ class iUFMode(BaseMode):
156
+ def show_commands(self):
157
+ print("\n=== iUF Commands ===")
158
+ print("print {text}")
159
+ print("repeat {number} {text}")
160
+ print("set {name} {value}")
161
+ print("get {name}")
162
+ print("add {a} {b}")
163
+ print("sub {a} {b}")
164
+ print("mul {a} {b}")
165
+ print("div {a} {b}")
166
+ print("len {text}")
167
+ print("clear")
168
+ print("upper {text}")
169
+ print("lower {text}")
170
+ print("rand {min} {max}")
171
+ print("time")
172
+ print("rev {text}")
173
+ print("sleep {seconds}")
174
+ print("rndchar")
175
+ print("==================\n")
176
+
177
+ def execute(self, tokens):
178
+ if not tokens:
179
+ return
180
+ cmd = tokens[0].lower()
181
+
182
+ if cmd == "print":
183
+ print(" ".join(tokens[1:]))
184
+ elif cmd == "repeat":
185
+ try:
186
+ times = int(tokens[1])
187
+ text = " ".join(tokens[2:])
188
+ for _ in range(times):
189
+ print(text)
190
+ except:
191
+ print("Usage: repeat {number} {text}")
192
+ elif cmd == "set":
193
+ try:
194
+ self.variables[tokens[1]] = " ".join(tokens[2:])
195
+ print(f"{tokens[1]} = {self.variables[tokens[1]]}")
196
+ except:
197
+ print("Usage: set {name} {value}")
198
+ elif cmd == "get":
199
+ try:
200
+ print(self.variables.get(tokens[1], "Variable not found"))
201
+ except:
202
+ print("Usage: get {name}")
203
+ elif cmd == "add":
204
+ try:
205
+ print(float(tokens[1]) + float(tokens[2]))
206
+ except:
207
+ print("Usage: add {a} {b}")
208
+ elif cmd == "sub":
209
+ try:
210
+ print(float(tokens[1]) - float(tokens[2]))
211
+ except:
212
+ print("Usage: sub {a} {b}")
213
+ elif cmd == "mul":
214
+ try:
215
+ print(float(tokens[1]) * float(tokens[2]))
216
+ except:
217
+ print("Usage: mul {a} {b}")
218
+ elif cmd == "div":
219
+ try:
220
+ print(float(tokens[1]) / float(tokens[2]))
221
+ except:
222
+ print("Usage: div {a} {b}")
223
+ elif cmd == "len":
224
+ print(len(" ".join(tokens[1:])))
225
+ elif cmd == "clear":
226
+ os.system("cls" if os.name == "nt" else "clear")
227
+ elif cmd == "upper":
228
+ print(" ".join(tokens[1:]).upper())
229
+ elif cmd == "lower":
230
+ print(" ".join(tokens[1:]).lower())
231
+ elif cmd == "rand":
232
+ try:
233
+ print(random.randint(int(tokens[1]), int(tokens[2])))
234
+ except:
235
+ print("Usage: rand {min} {max}")
236
+ elif cmd == "time":
237
+ print(time.ctime())
238
+ elif cmd == "rev":
239
+ print(" ".join(tokens[1:])[::-1])
240
+ elif cmd == "sleep":
241
+ try:
242
+ time.sleep(float(tokens[1]))
243
+ except:
244
+ print("Usage: sleep {seconds}")
245
+ elif cmd == "rndchar":
246
+ print(random.choice(string.ascii_letters))
247
+ else:
248
+ print("Unknown iUF command.")
249
+
250
+ # -----------------------------
251
+ # nUF Mode (Advanced / 3.6S)
252
+ # -----------------------------
253
+ class nUFMode(BaseMode):
254
+ def show_commands(self):
255
+ print("\n=== nUF Commands ===")
256
+ print("var x = value")
257
+ print("show")
258
+ print("calc {expression}")
259
+ print("echo {text}")
260
+ print("> {text}")
261
+ print("sqrt {number}")
262
+ print("pow {base} {exp}")
263
+ print("round {number}")
264
+ print("len {text}")
265
+ print("repeatf {times} {text}")
266
+ print("upper {text}")
267
+ print("lower {text}")
268
+ print("rev {text}")
269
+ print("rand {min} {max}")
270
+ print("time")
271
+ print("sleep {seconds}")
272
+ print("sys {command}")
273
+ print("exec {python_code}")
274
+ print("rndchar")
275
+ print("==================\n")
276
+
277
+ def evaluate_expression(self, expr):
278
+ for var in self.variables:
279
+ expr = expr.replace(var, str(self.variables[var]))
280
+ try:
281
+ allowed_names = {"math": math}
282
+ return eval(expr, {"__builtins__": None}, allowed_names)
283
+ except:
284
+ return None
285
+
286
+ def execute(self, tokens):
287
+ if not tokens:
288
+ return
289
+ cmd = tokens[0].lower()
290
+
291
+ if cmd == "var":
292
+ try:
293
+ name = tokens[1]
294
+ if tokens[2] != "=":
295
+ print("Syntax: var x = value")
296
+ return
297
+ value = " ".join(tokens[3:])
298
+ self.variables[name] = value
299
+ print(f"{name} = {value}")
300
+ except:
301
+ print("Syntax: var x = value")
302
+ elif cmd == "show":
303
+ print("Variables:", self.variables)
304
+ elif cmd == "calc":
305
+ expr = " ".join(tokens[1:])
306
+ result = self.evaluate_expression(expr)
307
+ if result is not None:
308
+ print(result)
309
+ else:
310
+ print("Invalid expression.")
311
+ elif cmd in ["echo", ">"]:
312
+ print(" ".join(tokens[1:]))
313
+ elif cmd == "sqrt":
314
+ try:
315
+ print(math.sqrt(float(tokens[1])))
316
+ except:
317
+ print("Usage: sqrt {number}")
318
+ elif cmd == "pow":
319
+ try:
320
+ print(math.pow(float(tokens[1]), float(tokens[2])))
321
+ except:
322
+ print("Usage: pow {base} {exp}")
323
+ elif cmd == "round":
324
+ try:
325
+ print(round(float(tokens[1])))
326
+ except:
327
+ print("Usage: round {number}")
328
+ elif cmd == "len":
329
+ print(len(" ".join(tokens[1:])))
330
+ elif cmd == "repeatf":
331
+ try:
332
+ times = int(tokens[1])
333
+ text = " ".join(tokens[2:])
334
+ for _ in range(times):
335
+ print(text)
336
+ except:
337
+ print("Usage: repeatf {times} {text}")
338
+ elif cmd == "upper":
339
+ print(" ".join(tokens[1:]).upper())
340
+ elif cmd == "lower":
341
+ print(" ".join(tokens[1:]).lower())
342
+ elif cmd == "rev":
343
+ print(" ".join(tokens[1:])[::-1])
344
+ elif cmd == "rand":
345
+ try:
346
+ print(random.randint(int(tokens[1]), int(tokens[2])))
347
+ except:
348
+ print("Usage: rand {min} {max}")
349
+ elif cmd == "time":
350
+ print(time.ctime())
351
+ elif cmd == "sleep":
352
+ try:
353
+ time.sleep(float(tokens[1]))
354
+ except:
355
+ print("Usage: sleep {seconds}")
356
+ elif cmd == "sys":
357
+ os.system(" ".join(tokens[1:]))
358
+ elif cmd == "exec":
359
+ try:
360
+ exec(" ".join(tokens[1:]))
361
+ except Exception as e:
362
+ print("Python error:", e)
363
+ elif cmd == "rndchar":
364
+ print(random.choice(string.ascii_letters))
365
+ else:
366
+ print("Unknown nUF command.")
367
+
368
+ # -----------------------------
369
+ # dnUF Mode (Expert / 1S)
370
+ # -----------------------------
371
+ class dnUFMode(BaseMode):
372
+ def show_commands(self):
373
+ print("\n=== dnUF Commands ===")
374
+ print("let x = value")
375
+ print("vars")
376
+ print("echo {text} (supports $variables)")
377
+ print("calc {expression}")
378
+ print("if {condition} then {command}")
379
+ print("sleep {seconds}")
380
+ print("sys {command}")
381
+ print("exec {python_code}")
382
+ print("len {text}")
383
+ print("read {filename}")
384
+ print("upper {text}")
385
+ print("lower {text}")
386
+ print("rev {text}")
387
+ print("rand {min} {max}")
388
+ print("time")
389
+ print("rndchar")
390
+ print("==================\n")
391
+
392
+ def evaluate_expression(self, expr):
393
+ for var in self.variables:
394
+ expr = expr.replace(var, str(self.variables[var]))
395
+ try:
396
+ return eval(expr, {"__builtins__": None}, {"math": math})
397
+ except:
398
+ return None
399
+
400
+ def execute(self, tokens):
401
+ if not tokens:
402
+ return
403
+ cmd = tokens[0].lower()
404
+
405
+ if cmd == "let":
406
+ try:
407
+ name = tokens[1]
408
+ if tokens[2] != "=":
409
+ print("Syntax: let x = value")
410
+ return
411
+ value = " ".join(tokens[3:])
412
+ self.variables[name] = value
413
+ print(f"[OK] {name} = {value}")
414
+ except:
415
+ print("Syntax: let x = value")
416
+ elif cmd == "vars":
417
+ print("Variables:", self.variables)
418
+ elif cmd == "echo":
419
+ text = " ".join(tokens[1:])
420
+ for var in self.variables:
421
+ text = text.replace(f"${var}", str(self.variables[var]))
422
+ print(text)
423
+ elif cmd == "calc":
424
+ expr = " ".join(tokens[1:])
425
+ result = self.evaluate_expression(expr)
426
+ if result is not None:
427
+ print(result)
428
+ else:
429
+ print("Invalid calculation.")
430
+ elif cmd == "if":
431
+ try:
432
+ then_index = tokens.index("then")
433
+ condition = " ".join(tokens[1:then_index])
434
+ for var in self.variables:
435
+ condition = condition.replace(var, str(self.variables[var]))
436
+ if eval(condition, {"__builtins__": None}, {}):
437
+ action = " ".join(tokens[then_index+1:])
438
+ if action.startswith("echo"):
439
+ print(" ".join(action.split()[1:]))
440
+ except:
441
+ print("Syntax: if condition then ...")
442
+ elif cmd == "sleep":
443
+ try:
444
+ seconds = float(tokens[1])
445
+ time.sleep(seconds)
446
+ print(f"Slept for {seconds} seconds.")
447
+ except:
448
+ print("Usage: sleep {seconds}")
449
+ elif cmd == "sys":
450
+ os.system(" ".join(tokens[1:]))
451
+ elif cmd == "exec":
452
+ try:
453
+ exec(" ".join(tokens[1:]))
454
+ except Exception as e:
455
+ print("Python error:", e)
456
+ elif cmd == "len":
457
+ print(len(" ".join(tokens[1:])))
458
+ elif cmd == "read":
459
+ try:
460
+ filename = tokens[1]
461
+ with open(filename, "r") as f:
462
+ content = f.read()
463
+ print(content)
464
+ except:
465
+ print("Usage: read {filename}")
466
+ elif cmd == "upper":
467
+ print(" ".join(tokens[1:]).upper())
468
+ elif cmd == "lower":
469
+ print(" ".join(tokens[1:]).lower())
470
+ elif cmd == "rev":
471
+ print(" ".join(tokens[1:])[::-1])
472
+ elif cmd == "rand":
473
+ try:
474
+ print(random.randint(int(tokens[1]), int(tokens[2])))
475
+ except:
476
+ print("Usage: rand {min} {max}")
477
+ elif cmd == "time":
478
+ print(time.ctime())
479
+ elif cmd == "rndchar":
480
+ print(random.choice(string.ascii_letters))
481
+ else:
482
+ print("Unknown dnUF command.")
483
+
484
+ # -----------------------------
485
+ # Main UF Engine
486
+ # -----------------------------
487
+ def main():
488
+ print("UF Language Engine v2.0")
489
+ print("Modes available: UF, iUF, nUF, dnUF")
490
+
491
+ mode = ""
492
+ valid_modes = ["uf", "iuf", "nuf", "dnuf"]
493
+ while mode.lower() not in valid_modes:
494
+ mode = input("Select mode (UF / iUF / nUF / dnUF): ").strip().lower()
495
+
496
+ variables = {}
497
+ mode_classes = {
498
+ "uf": UFMode,
499
+ "iuf": iUFMode,
500
+ "nuf": nUFMode,
501
+ "dnuf": dnUFMode
502
+ }
503
+ current_mode = mode_classes[mode](variables)
504
+
505
+ print(f"\nLoaded mode: {mode.upper()}")
506
+ if mode == "uf":
507
+ current_mode.show_commands()
508
+ else:
509
+ print("Tip: Discover commands yourself...")
510
+
511
+ while True:
512
+ try:
513
+ code = input(f"{mode.upper()} > ").strip()
514
+ except EOFError:
515
+ print("\nExiting UF Engine...")
516
+ break
517
+
518
+ if code == "":
519
+ continue
520
+ if code.lower() == "exit":
521
+ print("Exiting UF Engine...")
522
+ break
523
+
524
+ if mode == "iuf" and code.lower() == "help":
525
+ current_mode.show_commands()
526
+ continue
527
+ if mode == "nuf" and code.lower() == "help me":
528
+ current_mode.show_commands()
529
+ continue
530
+ if mode == "dnuf" and code.lower() == "help me please now":
531
+ current_mode.show_commands()
532
+ continue
533
+
534
+ tokens = tokenize(code)
535
+ current_mode.execute(tokens)
536
+
537
+ # -----------------------------
538
+ # Script Execution Support
539
+ # -----------------------------
540
+ def run_file(filename, mode_name="uf"):
541
+ valid_modes = ["uf", "iuf", "nuf", "dnuf"]
542
+ if mode_name not in valid_modes:
543
+ print("Invalid mode for script execution.")
544
+ return
545
+
546
+ variables = {}
547
+ mode_classes = {
548
+ "uf": UFMode,
549
+ "iuf": iUFMode,
550
+ "nuf": nUFMode,
551
+ "dnuf": dnUFMode
552
+ }
553
+ current_mode = mode_classes[mode_name](variables)
554
+
555
+ try:
556
+ with open(filename, "r") as f:
557
+ for line in f:
558
+ line = line.strip()
559
+ if not line or line.startswith("#"):
560
+ continue
561
+ tokens = tokenize(line)
562
+ current_mode.execute(tokens)
563
+ except FileNotFoundError:
564
+ print(f"File not found: {filename}")
565
+
566
+ # -----------------------------
567
+ # Entry Point
568
+ # -----------------------------
569
+ if __name__ == "__main__":
570
+ main()
@@ -0,0 +1,6 @@
1
+ # uf/__init__.py
2
+
3
+ from .engine import UFEngine
4
+ from .cli import main
5
+
6
+ __all__ = ["UFEngine", "main"]
@@ -0,0 +1,26 @@
1
+ # uf/cli.py
2
+ from .engine import UFEngine
3
+
4
+ def main():
5
+ engine = UFEngine()
6
+
7
+ # Register modes
8
+ from .engine import UFMode, iUFMode, nUFMode, dnUFMode
9
+ engine.register_mode("uf", UFMode)
10
+ engine.register_mode("iuf", iUFMode)
11
+ engine.register_mode("nuf", nUFMode)
12
+ engine.register_mode("dnuf", dnUFMode)
13
+
14
+ # Optional: load from command line args (script)
15
+ import sys
16
+ if len(sys.argv) > 1:
17
+ filename = sys.argv[1]
18
+ engine.select_mode() # select mode first
19
+ engine.run_file(filename)
20
+ else:
21
+ # Interactive mode
22
+ engine.select_mode()
23
+ engine.run_repl()
24
+
25
+ if __name__ == "__main__":
26
+ main()
@@ -0,0 +1,101 @@
1
+ # uf/engine.py
2
+ import time
3
+ import random
4
+ import os
5
+ import math
6
+
7
+ # -----------------------------
8
+ # Tokenizer
9
+ # -----------------------------
10
+ def tokenize(line):
11
+ tokens = []
12
+ current = ""
13
+ in_string = False
14
+ for char in line:
15
+ if char == '"':
16
+ in_string = not in_string
17
+ current += char
18
+ elif char.isspace() and not in_string:
19
+ if current:
20
+ tokens.append(current)
21
+ current = ""
22
+ else:
23
+ current += char
24
+ if current:
25
+ tokens.append(current)
26
+ return tokens
27
+
28
+ # -----------------------------
29
+ # Base Mode Class
30
+ # -----------------------------
31
+ class BaseMode:
32
+ def __init__(self, variables):
33
+ self.variables = variables
34
+
35
+ def show_commands(self):
36
+ raise NotImplementedError
37
+
38
+ def execute(self, tokens):
39
+ raise NotImplementedError
40
+
41
+ # -----------------------------
42
+ # UF Engine Class
43
+ # -----------------------------
44
+ class UFEngine:
45
+ def __init__(self):
46
+ self.variables = {}
47
+ self.mode_classes = {}
48
+ self.current_mode = None
49
+ self.mode_name = "uf"
50
+
51
+ def register_mode(self, name, mode_class):
52
+ self.mode_classes[name.lower()] = mode_class
53
+
54
+ def select_mode(self, name=None):
55
+ if name and name.lower() in self.mode_classes:
56
+ self.mode_name = name.lower()
57
+ else:
58
+ # Prompt user
59
+ while True:
60
+ name = input("Select mode (UF / iUF / nUF / dnUF): ").strip().lower()
61
+ if name in self.mode_classes:
62
+ self.mode_name = name
63
+ break
64
+ self.current_mode = self.mode_classes[self.mode_name](self.variables)
65
+ print(f"Loaded mode: {self.mode_name.upper()}")
66
+ if self.mode_name == "uf":
67
+ self.current_mode.show_commands()
68
+
69
+ def execute_line(self, line):
70
+ tokens = tokenize(line)
71
+ if not tokens:
72
+ return
73
+ self.current_mode.execute(tokens)
74
+
75
+ def run_repl(self):
76
+ while True:
77
+ try:
78
+ line = input(f"{self.mode_name.upper()} > ").strip()
79
+ except EOFError:
80
+ print("\nExiting UF Engine...")
81
+ break
82
+ if line.lower() == "exit":
83
+ print("Exiting UF Engine...")
84
+ break
85
+ self.execute_line(line)
86
+
87
+ def run_file(self, filename):
88
+ try:
89
+ with open(filename, "r") as f:
90
+ for line in f:
91
+ line = line.strip()
92
+ if not line or line.startswith("#"):
93
+ continue
94
+ self.execute_line(line)
95
+ except FileNotFoundError:
96
+ print(f"File not found: {filename}")
97
+
98
+ # -----------------------------
99
+ # Mode Classes
100
+ # -----------------------------
101
+ from .modes import UFMode, iUFMode, nUFMode, dnUFMode # We'll create a modes package later
@@ -0,0 +1,268 @@
1
+ # uf/modes.py
2
+ import time
3
+ import random
4
+ import os
5
+ import math
6
+ import string
7
+
8
+ # -----------------------------
9
+ # UF Mode (User Friendly / 10S)
10
+ # -----------------------------
11
+ class UFMode:
12
+ def __init__(self, variables):
13
+ self.variables = variables
14
+
15
+ def show_commands(self):
16
+ print("\n=== UF Commands ===")
17
+ print("hi -> prints hello world")
18
+ print("hip -> prints hi")
19
+ print("hih {text} -> prints your text")
20
+ print("hid {text} {number} -> repeat text")
21
+ print("set {name} {value} -> assign variable")
22
+ print("get {name} -> get variable value")
23
+ print("add {a} {b} -> addition")
24
+ print("sub {a} {b} -> subtraction")
25
+ print("mul {a} {b} -> multiplication")
26
+ print("div {a} {b} -> division")
27
+ print("rand {min} {max} -> random number")
28
+ print("time -> current time")
29
+ print("sleep {seconds} -> pause execution")
30
+ print("upper {text} -> uppercase")
31
+ print("lower {text} -> lowercase")
32
+ print("len {text} -> length of text")
33
+ print("rev {text} -> reverse text")
34
+ print("clear -> clear screen")
35
+ print("rndchar -> random letter")
36
+ print("sqrt {number} -> square root")
37
+ print("pow {a} {b} -> exponentiation")
38
+ print("round {number} -> round number")
39
+ print("repeatf {times} {text} -> repeat text")
40
+ print("exit -> quit REPL")
41
+ print("==================\n")
42
+
43
+ def execute(self, tokens):
44
+ if not tokens:
45
+ return
46
+ cmd = tokens[0].lower()
47
+
48
+ try:
49
+ if cmd == "hi":
50
+ print("hello world")
51
+ elif cmd == "hip":
52
+ print("hi")
53
+ elif cmd == "hih":
54
+ print(" ".join(tokens[1:]))
55
+ elif cmd == "hid":
56
+ times = int(tokens[-1])
57
+ text = " ".join(tokens[1:-1])
58
+ for _ in range(times):
59
+ print(text)
60
+ elif cmd == "set":
61
+ self.variables[tokens[1]] = " ".join(tokens[2:])
62
+ print(f"{tokens[1]} = {self.variables[tokens[1]]}")
63
+ elif cmd == "get":
64
+ print(self.variables.get(tokens[1], "Variable not found"))
65
+ elif cmd == "add":
66
+ print(float(tokens[1]) + float(tokens[2]))
67
+ elif cmd == "sub":
68
+ print(float(tokens[1]) - float(tokens[2]))
69
+ elif cmd == "mul":
70
+ print(float(tokens[1]) * float(tokens[2]))
71
+ elif cmd == "div":
72
+ print(float(tokens[1]) / float(tokens[2]))
73
+ elif cmd == "rand":
74
+ print(random.randint(int(tokens[1]), int(tokens[2])))
75
+ elif cmd == "time":
76
+ print(time.ctime())
77
+ elif cmd == "sleep":
78
+ time.sleep(float(tokens[1]))
79
+ elif cmd == "upper":
80
+ print(" ".join(tokens[1:]).upper())
81
+ elif cmd == "lower":
82
+ print(" ".join(tokens[1:]).lower())
83
+ elif cmd == "len":
84
+ print(len(" ".join(tokens[1:])))
85
+ elif cmd == "rev":
86
+ print(" ".join(tokens[1:])[::-1])
87
+ elif cmd == "clear":
88
+ os.system("cls" if os.name == "nt" else "clear")
89
+ elif cmd == "rndchar":
90
+ print(random.choice(string.ascii_letters))
91
+ elif cmd == "sqrt":
92
+ print(math.sqrt(float(tokens[1])))
93
+ elif cmd == "pow":
94
+ print(math.pow(float(tokens[1]), float(tokens[2])))
95
+ elif cmd == "round":
96
+ print(round(float(tokens[1])))
97
+ elif cmd == "repeatf":
98
+ times = int(tokens[1])
99
+ text = " ".join(tokens[2:])
100
+ for _ in range(times):
101
+ print(text)
102
+ else:
103
+ print("Unknown UF command.")
104
+ except Exception as e:
105
+ print(f"Error: {e}")
106
+
107
+
108
+ # -----------------------------
109
+ # iUF Mode (Intermediate / 7S)
110
+ # -----------------------------
111
+ class iUFMode(UFMode):
112
+ def show_commands(self):
113
+ print("\n=== iUF Commands ===")
114
+ print("print {text}")
115
+ print("repeat {number} {text}")
116
+ print("set {name} {value}")
117
+ print("get {name}")
118
+ print("add/sub/mul/div {a} {b}")
119
+ print("len {text}")
120
+ print("clear")
121
+ print("upper {text}")
122
+ print("lower {text}")
123
+ print("rand {min} {max}")
124
+ print("time")
125
+ print("rev {text}")
126
+ print("sleep {seconds}")
127
+ print("rndchar")
128
+ print("sqrt {number}")
129
+ print("pow {a} {b}")
130
+ print("round {number}")
131
+ print("repeatf {times} {text}")
132
+ print("==================\n")
133
+
134
+ def execute(self, tokens):
135
+ # all commands same as UF but "print" instead of "hi"/"hih"
136
+ if not tokens:
137
+ return
138
+ cmd = tokens[0].lower()
139
+ try:
140
+ if cmd == "print":
141
+ print(" ".join(tokens[1:]))
142
+ else:
143
+ super().execute(tokens)
144
+ except Exception as e:
145
+ print(f"Error: {e}")
146
+
147
+
148
+ # -----------------------------
149
+ # nUF Mode (Advanced / 3.6S)
150
+ # -----------------------------
151
+ class nUFMode(UFMode):
152
+ def show_commands(self):
153
+ print("\n=== nUF Commands ===")
154
+ print("var x = value")
155
+ print("show")
156
+ print("calc {expression}")
157
+ print("echo {text}")
158
+ print("> {text}")
159
+ print("sqrt {number}")
160
+ print("pow {base} {exp}")
161
+ print("round {number}")
162
+ print("len {text}")
163
+ print("repeatf {times} {text}")
164
+ print("upper {text}")
165
+ print("lower {text}")
166
+ print("rev {text}")
167
+ print("rand {min} {max}")
168
+ print("time")
169
+ print("sleep {seconds}")
170
+ print("sys {command}")
171
+ print("exec {python_code}")
172
+ print("rndchar")
173
+ print("==================\n")
174
+
175
+ def evaluate_expression(self, expr):
176
+ for var in self.variables:
177
+ expr = expr.replace(var, str(self.variables[var]))
178
+ try:
179
+ return eval(expr, {"__builtins__": None}, {"math": math})
180
+ except:
181
+ return None
182
+
183
+ def execute(self, tokens):
184
+ if not tokens:
185
+ return
186
+ cmd = tokens[0].lower()
187
+ try:
188
+ if cmd == "var":
189
+ name = tokens[1]
190
+ if tokens[2] != "=":
191
+ print("Syntax: var x = value")
192
+ return
193
+ value = " ".join(tokens[3:])
194
+ self.variables[name] = value
195
+ print(f"{name} = {value}")
196
+ elif cmd == "show":
197
+ print(self.variables)
198
+ elif cmd == "calc":
199
+ expr = " ".join(tokens[1:])
200
+ print(self.evaluate_expression(expr))
201
+ elif cmd in ["echo", ">"]:
202
+ print(" ".join(tokens[1:]))
203
+ elif cmd == "sys":
204
+ os.system(" ".join(tokens[1:]))
205
+ elif cmd == "exec":
206
+ exec(" ".join(tokens[1:]))
207
+ else:
208
+ super().execute(tokens)
209
+ except Exception as e:
210
+ print(f"Error: {e}")
211
+
212
+
213
+ # -----------------------------
214
+ # dnUF Mode (Expert / 1S)
215
+ # -----------------------------
216
+ class dnUFMode(nUFMode):
217
+ def show_commands(self):
218
+ print("\n=== dnUF Commands ===")
219
+ print("let x = value")
220
+ print("vars")
221
+ print("echo {text} (supports $variables)")
222
+ print("calc {expression}")
223
+ print("if {condition} then {command}")
224
+ print("sleep {seconds}")
225
+ print("sys {command}")
226
+ print("exec {python_code}")
227
+ print("len {text}")
228
+ print("read {filename}")
229
+ print("upper {text}")
230
+ print("lower {text}")
231
+ print("rev {text}")
232
+ print("rand {min} {max}")
233
+ print("time")
234
+ print("rndchar")
235
+ print("==================\n")
236
+
237
+ def execute(self, tokens):
238
+ if not tokens:
239
+ return
240
+ cmd = tokens[0].lower()
241
+ try:
242
+ if cmd == "let":
243
+ name = tokens[1]
244
+ if tokens[2] != "=":
245
+ print("Syntax: let x = value")
246
+ return
247
+ value = " ".join(tokens[3:])
248
+ self.variables[name] = value
249
+ print(f"[OK] {name} = {value}")
250
+ elif cmd == "vars":
251
+ print(self.variables)
252
+ elif cmd == "read":
253
+ filename = tokens[1]
254
+ with open(filename, "r") as f:
255
+ print(f.read())
256
+ elif cmd == "if":
257
+ idx = tokens.index("then")
258
+ condition = " ".join(tokens[1:idx])
259
+ for var in self.variables:
260
+ condition = condition.replace(var, str(self.variables[var]))
261
+ if eval(condition, {"__builtins__": None}, {}):
262
+ action = " ".join(tokens[idx + 1:])
263
+ if action.startswith("echo"):
264
+ print(" ".join(action.split()[1:]))
265
+ else:
266
+ super().execute(tokens)
267
+ except Exception as e:
268
+ print(f"Error: {e}")
@@ -0,0 +1,8 @@
1
+ Metadata-Version: 2.4
2
+ Name: uf-language
3
+ Version: 1.0.0
4
+ Summary: UF Language Engine with 4 modes (UF, iUF, nUF, dnUF)
5
+ Author-email: Intel <you@example.com>
6
+ License: MIT
7
+ Requires-Python: >=3.9
8
+ Description-Content-Type: text/markdown
@@ -0,0 +1,12 @@
1
+ README.md
2
+ pyproject.toml
3
+ uf/UF.py
4
+ uf/_init_.py
5
+ uf/cli.py
6
+ uf/engine.py
7
+ uf/modes.py
8
+ uf_language.egg-info/PKG-INFO
9
+ uf_language.egg-info/SOURCES.txt
10
+ uf_language.egg-info/dependency_links.txt
11
+ uf_language.egg-info/entry_points.txt
12
+ uf_language.egg-info/top_level.txt
@@ -0,0 +1,2 @@
1
+ [console_scripts]
2
+ uf = uf.cli:main