-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathalgo
executable file
·78 lines (66 loc) · 2.81 KB
/
algo
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
#!/usr/bin/env python3
from runtime.environment import setup_global_env
from src.parser import *
from src.lexer import *
from sys import argv, exit
from runtime.interpreter import *
"""
sorry for the bad code that i wrote :')
- Rayen Mnif
"""
def main():
dev = False
env = setup_global_env()
if len(argv) not in [2, 1]:
print("Usage: algo [script]")
exit(0)
if len(argv) == 2:
try:
with open(argv[1], "r") as script:
src = script.read()
program = Parser(src).produce_ast()
if dev:
print(program)
print("-----------------------------")
evaluate(program, env)
except FileNotFoundError: Error(f"fichier non valide: on ne peut pas trouver le fichier '{argv[1]}'")
except KeyboardInterrupt: exit(0)
except EOFError: exit(0)
else:
print("""
▄▄▄ ██▓ ▄████ ▒█████
▒████▄ ▓██▒ ██▒ ▀█▒▒██▒ ██▒
▒██ ▀█▄ ▒██░ ▒██░▄▄▄░▒██░ ██▒
░██▄▄▄▄██ ▒██░ ░▓█ ██▓▒██ ██░
▓█ ▓██▒░██████▒░▒▓███▀▒░ ████▓▒░
▒▒ ▓▒█░░ ▒░▓ ░ ░▒ ▒ ░ ▒░▒░▒░
▒ ▒▒ ░░ ░ ▒ ░ ░ ░ ░ ▒ ▒░
░ ▒ ░ ░ ░ ░ ░ ░ ░ ░ ▒
░ ░ ░ ░ ░ ░ ░
Tunisian shitty pseudo/programming language
Type "exit", "quit" to quit
"help", "credits" for more information
Algo v0.0.1 (Beta)
""")
while True:
try:
prompt = input(">> ")
if prompt.upper() in ["EXIT", "QUIT"]: exit()
if prompt.upper() == "CREDITS":
print("project by Rayen Mnif")
exit()
if prompt.upper() == "HELP":
print("the docs are not available at the moment")
exit()
program = Parser(prompt).produce_ast()
if dev:
print(program)
print("------------------------------------")
print(evaluate(program, env))
except KeyboardInterrupt:
exit()
except EOFError:
exit()
if __name__ == "__main__":
main()