diff --git a/fx92/ast.py b/fx92/ast.py index 2db8b98..ab8944c 100644 --- a/fx92/ast.py +++ b/fx92/ast.py @@ -42,7 +42,7 @@ class N(enum.IntEnum): # Flow control REPEAT = enum.auto() - WHILE = enum.auto() + UNTIL = enum.auto() IF = enum.auto() # Expressions diff --git a/fx92/interpreter.py b/fx92/interpreter.py index 4a7c215..391e7d7 100644 --- a/fx92/interpreter.py +++ b/fx92/interpreter.py @@ -132,8 +132,8 @@ class Context: for i in range(count): self.run(n.args[1]) - elif n.type == N.WHILE: - while self.run(n.args[0]): + elif n.type == N.UNTIL: + while not self.run(n.args[0]): self.run(n.args[1]) elif n.type == N.IF: diff --git a/fx92/lexer.py b/fx92/lexer.py index 02fabff..9dfef64 100644 --- a/fx92/lexer.py +++ b/fx92/lexer.py @@ -33,8 +33,8 @@ class T(enum.IntEnum): # Flow control REPEAT = 0xF911 REPEAT_END = 0xF912 - WHILE = 0xF913 - WHILE_END = 0xF914 + UNTIL = 0xF913 + UNTIL_END = 0xF914 IF = 0xF915 IF_END = 0xF916 IFELSE = 0xF917 @@ -331,7 +331,7 @@ class TextLexer(LexerBase): RE_STMTS = re.compile( r"NOP|FORWARD|ROTATE|ORIENT|GOTO|PENDOWN|PENUP|SETVAR|INPUT|MESSAGE|" - r"PRINT|STYLE|WAIT|REPEAT_END|REPEAT|WHILE_END|WHILE|IF_END|ELSE|" + r"PRINT|STYLE|WAIT|REPEAT_END|REPEAT|UNTIL_END|UNTIL|IF_END|ELSE|" r"IFELSE_END|IFELSE|IF", re.IGNORECASE) RE_CONST = re.compile( diff --git a/fx92/parser.py b/fx92/parser.py index a678ee1..e72a5ba 100644 --- a/fx92/parser.py +++ b/fx92/parser.py @@ -20,7 +20,7 @@ class Parser: PENDOWN | PENUP | SETVAR arg argvar | INPUT argvar | MESSAGE arg | PRINT arg | STYLE style | WAIT arg | REPEAT arg program REPEAT_END | - WHILE cond PARAM program WHILE_END | + UNTIL cond PARAM program UNTIL_END | IF cond PARAM program IF_END | IFELSE cond PARAM program ELSE program IFELSE_END arg -> expr PARAM @@ -112,7 +112,7 @@ class Parser: valid = [ T.FORWARD, T.ROTATE, T.ORIENT, T.GOTO, T.PENDOWN, T.PENUP, T.SETVAR, T.INPUT, T.MESSAGE, T.PRINT, T.STYLE, T.WAIT, - T.REPEAT, T.WHILE, T.IF, T.IFELSE, + T.REPEAT, T.UNTIL, T.IF, T.IFELSE, ] op = self.expect(*valid, optional=optional) @@ -155,14 +155,14 @@ class Parser: self.expect(T.EOL, optional=True) return Node(N.REPEAT, arg, prg) - if op.type == T.WHILE: + if op.type == T.UNTIL: cond = self.cond() self.expect(T.PARAM) self.expect(T.EOL, optional=True) prg = self.program() - self.expect(T.WHILE_END) + self.expect(T.UNTIL_END) self.expect(T.EOL, optional=True) - return Node(N.WHILE, cond, prg) + return Node(N.UNTIL, cond, prg) if op.type == T.IF: cond = self.cond() diff --git a/tests/line-positive.txt b/tests/line-positive.txt index 3835185..ea75460 100644 --- a/tests/line-positive.txt +++ b/tests/line-positive.txt @@ -1,12 +1,12 @@ setvar 0, A -while A <= 5 +until A=6 setvar 0, B - while B <= 12 + until B=13 penup goto 14*B-90, 7*A-20 pendown goto 15*B-90, 8*A-20 setvar B+1, B - while_end + until_end setvar A+1, A -while_end +until_end