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

View File

@@ -3,11 +3,11 @@ import stdlib/io.sl
: main : main
10 10
begin
dup 0 >
while while
dup 0 >
do
dup puti cr dup puti cr
1 - 1 -
repeat repeat
drop drop
; ;