lang: realize that WHILE was actually UNTIL

This commit is contained in:
Lephe 2019-10-26 18:26:14 +02:00
parent 32fbcf143a
commit 77404fa61b
Signed by: Lephenixnoir
GPG Key ID: 1BBA026E13FC0495
5 changed files with 15 additions and 15 deletions

View File

@ -42,7 +42,7 @@ class N(enum.IntEnum):
# Flow control
REPEAT = enum.auto()
WHILE = enum.auto()
UNTIL = enum.auto()
IF = enum.auto()
# Expressions

View File

@ -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:

View File

@ -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(

View File

@ -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()

View File

@ -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