diff --git a/code.txt b/code.txt index 2aa4dee..a360497 100755 --- a/code.txt +++ b/code.txt @@ -13,3 +13,4 @@ Set Prefix To BeginText Hi there, EndText EndSet Set Greeting To Prefix Append Name EndSet System Print Greeting Done +System Exit Done diff --git a/interp.py b/interp.py index d3ad996..b1571e1 100644 --- a/interp.py +++ b/interp.py @@ -2,6 +2,7 @@ # Copyright 2021 Jookia import ast_types +import sys class Text: def __init__(self, value): @@ -35,6 +36,9 @@ def verb_Read(self, args): return Text(input()) + def verb_Exit(self, args): + sys.exit(0) + class InterpreterError(BaseException): def __init__(self, error): self.error = error @@ -88,10 +92,9 @@ raise InterpreterError("Unknown command type %s" % (ast.__class__.__name__)) def run(self, ast): - ret = None - for command in ast: - ret = self.run_command(command) - return ret + while True: + for command in ast: + ret = self.run_command(command) def run_ast(ast): env = {