diff --git a/info4/kapitel-8/Interpreter/interpreter.py b/info4/kapitel-8/Interpreter/interpreter.py index b02139c8cf50d46be2969a131f3631a16dc84689..ff765c57ad213502442b99d2a9a8deeb7649e824 100644 --- a/info4/kapitel-8/Interpreter/interpreter.py +++ b/info4/kapitel-8/Interpreter/interpreter.py @@ -42,7 +42,7 @@ class ErrorHandler: print("Variable " + k + ": " + str(v)) user_input = input("Drücke ENTER zum Fotfahren oder schreibe EXIT zum Beenden:") if user_input.lower() == 'exit': - sys.exit(0) + raise KeyboardInterrupt def process_assignment(value_list, forbidden_identifiers, identifier_token_1): @@ -239,21 +239,24 @@ def next_nonempty_token(current_function, expected_token): def interpret(program): - global error_handler, lex, values - lex = lexer.Lexer(regex_to_token, program) - error_handler = ErrorHandler(program) - values = {} - forbidden_identifiers = [] - current_token = next_token() - while current_token is not None: - current_token, values = process_program(values, forbidden_identifiers, current_token) - if current_token is not None: - if not current_token.k == 'SEMICOLON': - error_handler.handle_error("Semicolon erwartet") - current_token = next_token() - if current_token is None: - error_handler.handle_error("Semikolons werden nur zur Trennung und nicht zum " + - "Abschluss von Programmen verwendet") - if "x0" in values: - return values.get("x0") - return 0 + try: + global error_handler, lex, values + lex = lexer.Lexer(regex_to_token, program) + error_handler = ErrorHandler(program) + values = {} + forbidden_identifiers = [] + current_token = next_token() + while current_token is not None: + current_token, values = process_program(values, forbidden_identifiers, current_token) + if current_token is not None: + if not current_token.k == 'SEMICOLON': + error_handler.handle_error("Semicolon erwartet") + current_token = next_token() + if current_token is None: + error_handler.handle_error("Semikolons werden nur zur Trennung und nicht zum " + + "Abschluss von Programmen verwendet") + if "x0" in values: + return values.get("x0") + return 0 + except KeyboardInterrupt: + return -1