fixed the while and begin..again loops conflicting
This commit is contained in:
10
main.py
10
main.py
@@ -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)
|
||||||
|
|||||||
@@ -3,9 +3,9 @@ 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
|
||||||
|
|||||||
Reference in New Issue
Block a user