lang: realize that WHILE was actually UNTIL
This commit is contained in:
parent
32fbcf143a
commit
77404fa61b
|
@ -42,7 +42,7 @@ class N(enum.IntEnum):
|
|||
|
||||
# Flow control
|
||||
REPEAT = enum.auto()
|
||||
WHILE = enum.auto()
|
||||
UNTIL = enum.auto()
|
||||
IF = enum.auto()
|
||||
|
||||
# Expressions
|
||||
|
|
|
@ -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:
|
||||
|
|
|
@ -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(
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue