1
0

REPEAT~UNTILを実装

This commit is contained in:
otya128
2016-09-02 20:39:31 +09:00
parent 3e2cb7b8a7
commit 2f50fc5ba9
5 changed files with 103 additions and 22 deletions

View File

@@ -79,6 +79,8 @@ class Lexical
reserved["USE"] = TokenType.Use;
reserved["EXEC"] = TokenType.Exec;
reserved["ELSEIF"] = TokenType.Elseif;
reserved["REPEAT"] = TokenType.Repeat;
reserved["UNTIL"] = TokenType.Until;
reserved.rehash();
}
this(wstring input)
@@ -788,6 +790,21 @@ class Parser
lex.popFront();
return statements;
}
Statements repeatStatements()
{
auto statements = new Statements(lex.location);
while(!lex.empty())
{
auto type = lex.front().type;
if(type == TokenType.Until) break;
auto statement = statement();
if(statement != Statement.NOP)
{
statements.addStatement(statement);
}
}
return statements;
}
void syntaxError()
{
stderr.writeln("Syntax error (", lex.getLine(), ')', " Mysterious ", lex.front().type);
@@ -944,6 +961,9 @@ class Parser
case TokenType.While:
node = whileStatement();
break;
case TokenType.Repeat:
node = repeatStatement();
break;
case TokenType.Inc:
case TokenType.Dec:
return incStatement();
@@ -1352,6 +1372,27 @@ class Parser
auto node = new While(expr, statements, lex.location);
return node;
}
RepeatUntil repeatStatement()
{
lex.popFront();
Statements statements = repeatStatements();
auto token = lex.front;
if (token.type != TokenType.Until)
{
//TODO:REPEAT without UNTIL
syntaxError();
return null;
}
lex.popFront();
auto expr = expression();
if(expr is null)
{
syntaxError();
return null;
}
auto node = new RepeatUntil(expr, statements, lex.location);
return node;
}
If if_()
{
lex.popFront();