fixed the while and begin..again loops conflicting

This commit is contained in:
IgorCielniak
2025-12-25 20:02:28 +01:00
parent e2b1368899
commit ff72bc8207
2 changed files with 8 additions and 8 deletions

10
main.py
View File

@@ -450,12 +450,12 @@ class Parser:
if lexeme == "next":
self._handle_next_control()
continue
if lexeme == "begin":
self._handle_begin_control()
continue
if lexeme == "while":
self._handle_while_control()
continue
if lexeme == "do":
self._handle_do_control()
continue
if lexeme == "repeat":
self._handle_repeat_control()
continue
@@ -732,13 +732,13 @@ class Parser:
entry = self._pop_control(("for",))
self._append_node(ForNext(loop_label=entry["loop"], end_label=entry["end"]))
def _handle_begin_control(self) -> None:
def _handle_while_control(self) -> None:
begin_label = self._new_label("begin")
end_label = self._new_label("end")
self._append_node(Label(name=begin_label))
self._push_control({"type": "begin", "begin": begin_label, "end": end_label})
def _handle_while_control(self) -> None:
def _handle_do_control(self) -> None:
entry = self._pop_control(("begin",))
self._append_node(BranchZero(target=entry["end"]))
self._push_control(entry)