whileのパースを実装.
This commit is contained in:
@@ -60,6 +60,8 @@ class Lexical
|
||||
reserved["DIM"] = TokenType.Var;
|
||||
reserved["DEF"] = TokenType.Def;
|
||||
reserved["OUT"] = TokenType.Out;
|
||||
reserved["WHILE"] = TokenType.While;
|
||||
reserved["WEND"] = TokenType.WEnd;
|
||||
reserved.rehash();
|
||||
line = 1;
|
||||
}
|
||||
@@ -606,6 +608,22 @@ class Parser
|
||||
lex.popFront();
|
||||
return statements;
|
||||
}
|
||||
Statements whileStatements()
|
||||
{
|
||||
auto statements = new Statements();
|
||||
while(!lex.empty())
|
||||
{
|
||||
auto type = lex.front().type;
|
||||
if(type == TokenType.WEnd) break;
|
||||
auto statement = statement();
|
||||
if(statement != Statement.NOP)
|
||||
{
|
||||
statements.addStatement(statement);
|
||||
}
|
||||
}
|
||||
lex.popFront();
|
||||
return statements;
|
||||
}
|
||||
void syntaxError()
|
||||
{
|
||||
stderr.writeln("Syntax error (", lex.getLine(), ')', " Mysterious ", lex.front().type);
|
||||
@@ -735,6 +753,9 @@ class Parser
|
||||
lex.popFront();
|
||||
node = var();
|
||||
return node;
|
||||
case TokenType.While:
|
||||
node = whileStatement();
|
||||
break;
|
||||
default:
|
||||
syntaxError();
|
||||
break;
|
||||
@@ -900,6 +921,19 @@ class Parser
|
||||
node = new For(init, to, step, statements);
|
||||
return node;
|
||||
}
|
||||
While whileStatement()
|
||||
{
|
||||
lex.popFront();
|
||||
auto expr = expression();
|
||||
if(expr is null)
|
||||
{
|
||||
syntaxError();
|
||||
return null;
|
||||
}
|
||||
Statements statements = whileStatements();
|
||||
auto node = new While(expr, statements);
|
||||
return node;
|
||||
}
|
||||
If if_()
|
||||
{
|
||||
lex.popFront();
|
||||
|
||||
@@ -367,13 +367,22 @@ WHILE 1
|
||||
CL=(CL+1) MOD 16 : VSYNC 2
|
||||
WEND`*/
|
||||
`CLS : CL=0
|
||||
WHILE 1
|
||||
FOR I=0 TO 15
|
||||
LOCATE 9,4+I : COLOR (CL+I) MOD 16
|
||||
PRINT "Ё プチコン3ゴウ Ж"
|
||||
NEXT
|
||||
CL=(CL+1) MOD 16 : VSYNC 1
|
||||
WEND`
|
||||
/*
|
||||
`CLS : CL=0
|
||||
@LOOP
|
||||
FOR I=0 TO 15
|
||||
LOCATE 9,4+I : COLOR (CL+I) MOD 16
|
||||
PRINT "Ё プチコン3ゴウ Ж"
|
||||
NEXT
|
||||
CL=(CL+1) MOD 16 : VSYNC 1
|
||||
GOTO @LOOP`
|
||||
GOTO @LOOP`*/
|
||||
);
|
||||
auto vm = parser.compile();
|
||||
bool running = true;
|
||||
|
||||
@@ -55,7 +55,7 @@ enum TokenType
|
||||
Def,
|
||||
Out,
|
||||
While,
|
||||
Wend,
|
||||
WEnd,
|
||||
}
|
||||
|
||||
struct Token
|
||||
|
||||
Reference in New Issue
Block a user