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":
|
||||
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)
|
||||
|
||||
@@ -3,9 +3,9 @@ import stdlib/io.sl
|
||||
|
||||
: main
|
||||
10
|
||||
begin
|
||||
dup 0 >
|
||||
while
|
||||
dup 0 >
|
||||
do
|
||||
dup puti cr
|
||||
1 -
|
||||
repeat
|
||||
|
||||
Reference in New Issue
Block a user