-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmpl_shell.py
More file actions
59 lines (46 loc) · 1.58 KB
/
Copy pathmpl_shell.py
File metadata and controls
59 lines (46 loc) · 1.58 KB
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
"""
mpl_shell.py
====================================
The Interactive Shell (REPL).
Allows the Magi to cast spells directly from the terminal.
"""
import sys
from src.lexer import Lexer
from src.parser import Parser
from src.interpreter import Interpreter
def main():
# Initialize the Runtime Engine
interpreter = Interpreter()
print("========================================")
print("🔮 MPL (Magick Programming Language) v0.2.0")
print(" The Portal is Open.")
print(" Type 'exit' to close the connection.")
print("========================================")
while True:
try:
# 1. OMEN: Read input from the Mage
text = input('mpl> ')
if text.strip() == "exit":
print("Closing portal...")
break
if not text.strip():
continue
# 2. LEXER: Break into tokens
lexer = Lexer(text)
tokens = lexer.scan_tokens()
# Debug: Uncomment to see raw tokens
# print(f"Tokens: {tokens}")
# 3. PARSER: Build the AST
parser = Parser(tokens)
statements = parser.parse()
if not statements:
continue
# 4. INTERPRETER: Execute the Ritual
interpreter.interpret(statements)
except KeyboardInterrupt:
print("\nConnection interrupted.")
break
except Exception as e:
print(f"🌑 Abyss Error: {e}")
if __name__ == '__main__':
main()