Commit 7caff8cf authored by Christopher Happe's avatar Christopher Happe
Browse files

Breakpoints möglich gemacht

parent cb48a6e6
......@@ -12,6 +12,7 @@ regex_to_token = [(re.compile(r'\d+'), 'NUMBER'),
(re.compile(r'DO'), 'DO'),
(re.compile(r'END'), 'END'),
(re.compile(r';'), 'SEMICOLON'),
(re.compile(r'BREAK'), 'BREAK'),
(re.compile(r'\n', re.MULTILINE), 'LINEBREAK'),
(re.compile(r'\s+'), 'WHITESPACE'),
(re.compile(r'[^\n]*'), 'UNKNOWN')]
......@@ -26,12 +27,23 @@ class ErrorHandler:
self.line_number = 0
def handle_error(self, message):
msg = ["Fehler in Zeile " + str(self.line_number + 1), self.program.split("\n")[self.line_number], message]
msg = ["Fehler in Zeile " + str(self.line_number + 1),
self.program.split("\n")[self.line_number],
message]
raise SyntaxError("\n".join(msg)) from None
def increase_line(self):
self.line_number += 1
def handle_break(self):
print("BREAK in Zeile " + str(self.line_number))
print("Aktueller Zustand:")
for k,v in values.items():
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)
def process_assignment(value_list, forbidden_identifiers, identifier_token_1):
identifier_1 = identifier_token_1.v
......@@ -207,6 +219,9 @@ def next_token():
new_token = lex.next()
if new_token is None:
return None
elif new_token.k == 'BREAK':
error_handler.handle_break()
return next_token()
elif new_token.k == 'LINEBREAK':
error_handler.increase_line()
return next_token()
......@@ -224,7 +239,7 @@ def next_nonempty_token(current_function, expected_token):
def interpret(program):
global error_handler, lex
global error_handler, lex, values
lex = lexer.Lexer(regex_to_token, program)
error_handler = ErrorHandler(program)
values = {}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment