YREA-SLS/SLS_Python/sls/repl.py

26 lines
734 B
Python

"""Simple REPL for SLS skeleton."""
from .lexer import Lexer
from .parser import Parser
from .interpreter import Interpreter
def repl_loop():
interp = Interpreter()
print("sls-python REPL (very minimal). Type 'quit' or Ctrl-D to exit.")
try:
while True:
src = input("sls> ")
if not src or src.strip() in ("quit", "exit"):
break
# minimal echo behaviour for now
lexer = Lexer(src)
tokens = list(lexer.tokenize())
ast = Parser(tokens).parse()
result = interp.eval(ast)
if result is not None:
print(result)
except (EOFError, KeyboardInterrupt):
print()
print("Bye")